blob: b2693b9cae4f83fbb1023a086da2d41ddce86dc4 [file] [log] [blame]
Rushabh Mehta37b4d752015-11-09 16:53:11 +05301frappe.provide("erpnext.wiz");
2
3frappe.pages['setup-wizard'].on_page_load = function(wrapper) {
4 if(sys_defaults.company) {
5 frappe.set_route("desk");
6 return;
7 }
Anand Doshi1ed82832015-11-16 12:58:14 +05308};
Rushabh Mehta37b4d752015-11-09 16:53:11 +05309
Anand Doshi1ed82832015-11-16 12:58:14 +053010function load_erpnext_slides() {
11 $.extend(erpnext.wiz, {
Anand Doshi1ed82832015-11-16 12:58:14 +053012 org: {
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +053013 app_name: "erpnext",
Anand Doshi1ed82832015-11-16 12:58:14 +053014 title: __("The Organization"),
15 icon: "icon-building",
16 fields: [
17 {fieldname:'company_name', label: __('Company Name'), fieldtype:'Data', reqd:1,
18 placeholder: __('e.g. "My Company LLC"')},
19 {fieldname:'company_abbr', label: __('Company Abbreviation'), fieldtype:'Data',
20 description: __('Max 5 characters'), placeholder: __('e.g. "MC"'), reqd:1},
21 {fieldname:'company_tagline', label: __('What does it do?'), fieldtype:'Data',
22 placeholder:__('e.g. "Build tools for builders"'), reqd:1},
23 {fieldname:'bank_account', label: __('Bank Account'), fieldtype:'Data',
24 placeholder: __('e.g. "XYZ National Bank"'), reqd:1 },
25 {fieldname:'chart_of_accounts', label: __('Chart of Accounts'),
26 options: "", fieldtype: 'Select'},
Rushabh Mehta37b4d752015-11-09 16:53:11 +053027
Anand Doshi1ed82832015-11-16 12:58:14 +053028 // TODO remove this
29 {fieldtype: "Section Break"},
30 {fieldname:'fy_start_date', label:__('Financial Year Start Date'), fieldtype:'Date',
31 description: __('Your financial year begins on'), reqd:1},
32 {fieldname:'fy_end_date', label:__('Financial Year End Date'), fieldtype:'Date',
33 description: __('Your financial year ends on'), reqd:1},
34 ],
35 help: __('The name of your company for which you are setting up this system.'),
Rushabh Mehta37b4d752015-11-09 16:53:11 +053036
Anand Doshi1ed82832015-11-16 12:58:14 +053037 onload: function(slide) {
38 erpnext.wiz.org.load_chart_of_accounts(slide);
39 erpnext.wiz.org.bind_events(slide);
40 erpnext.wiz.org.set_fy_dates(slide);
41 },
42
Anand Doshi5c3469a2015-11-24 17:06:54 +053043 validate: function() {
44 // validate fiscal year start and end dates
45 if (this.values.fy_start_date=='Invalid date' || this.values.fy_end_date=='Invalid date') {
46 msgprint(__("Please enter valid Financial Year Start and End Dates"));
47 return false;
48 }
49
50 if ((this.values.company_name || "").toLowerCase() == "company") {
51 msgprint(__("Company Name cannot be Company"));
52 return false;
53 }
54
55 return true;
56 },
57
Anand Doshi1ed82832015-11-16 12:58:14 +053058 css_class: "single-column",
59
60 set_fy_dates: function(slide) {
61 var country = slide.wiz.get_values().country;
62
63 if(country) {
64 var fy = erpnext.wiz.fiscal_years[country];
65 var current_year = moment(new Date()).year();
66 var next_year = current_year + 1;
67 if(!fy) {
68 fy = ["01-01", "12-31"];
69 next_year = current_year;
70 }
71
72 slide.get_field("fy_start_date").set_input(current_year + "-" + fy[0]);
73 slide.get_field("fy_end_date").set_input(next_year + "-" + fy[1]);
Rushabh Mehta37b4d752015-11-09 16:53:11 +053074 }
75
Anand Doshi1ed82832015-11-16 12:58:14 +053076 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +053077
Anand Doshi1ed82832015-11-16 12:58:14 +053078 load_chart_of_accounts: function(slide) {
79 var country = slide.wiz.get_values().country;
Rushabh Mehta37b4d752015-11-09 16:53:11 +053080
Anand Doshi1ed82832015-11-16 12:58:14 +053081 if(country) {
82 frappe.call({
83 method: "erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts.get_charts_for_country",
84 args: {"country": country},
85 callback: function(r) {
86 if(r.message) {
87 slide.get_input("chart_of_accounts").empty()
88 .add_options(r.message);
Rushabh Mehta37b4d752015-11-09 16:53:11 +053089
Anand Doshi1ed82832015-11-16 12:58:14 +053090 if (r.message.length===1) {
91 var field = slide.get_field("chart_of_accounts");
92 field.set_value(r.message[0]);
93 field.df.hidden = 1;
94 field.refresh();
95 }
Rushabh Mehta37b4d752015-11-09 16:53:11 +053096 }
97 }
Anand Doshi1ed82832015-11-16 12:58:14 +053098 })
Rushabh Mehta37b4d752015-11-09 16:53:11 +053099 }
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530100 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530101
Anand Doshi1ed82832015-11-16 12:58:14 +0530102 bind_events: function(slide) {
103 slide.get_input("company_name").on("change", function() {
104 var parts = slide.get_input("company_name").val().split(" ");
105 var abbr = $.map(parts, function(p) { return p ? p.substr(0,1) : null }).join("");
106 slide.get_field("company_abbr").set_input(abbr.slice(0, 5).toUpperCase());
107 }).val(frappe.boot.sysdefaults.company_name || "").trigger("change");
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530108
Anand Doshi1ed82832015-11-16 12:58:14 +0530109 slide.get_input("company_abbr").on("change", function() {
110 if(slide.get_input("company_abbr").val().length > 5) {
111 msgprint("Company Abbreviation cannot have more than 5 characters");
112 slide.get_field("company_abbr").set_input("");
113 }
114 });
115
116 // TODO remove this
117 slide.get_input("fy_start_date").on("change", function() {
118 var year_end_date =
119 frappe.datetime.add_days(frappe.datetime.add_months(
120 frappe.datetime.user_to_obj(slide.get_input("fy_start_date").val()), 12), -1);
121 slide.get_input("fy_end_date").val(frappe.datetime.obj_to_user(year_end_date));
122
123 });
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530124 }
125 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530126
Anand Doshi1ed82832015-11-16 12:58:14 +0530127 branding: {
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530128 app_name: "erpnext",
Anand Doshi1ed82832015-11-16 12:58:14 +0530129 icon: "icon-bookmark",
130 title: __("The Brand"),
131 help: __('Upload your letter head and logo. (you can edit them later).'),
132 fields: [
133 {fieldtype:"Attach Image", fieldname:"attach_letterhead",
134 label: __("Attach Letterhead"),
Anand Doshi2af44ff2015-12-09 17:28:51 +0530135 description: __("Keep it web friendly 900px (w) by 100px (h)"),
136 is_private: 0
Anand Doshi1ed82832015-11-16 12:58:14 +0530137 },
138 {fieldtype: "Column Break"},
139 {fieldtype:"Attach Image", fieldname:"attach_logo",
140 label:__("Attach Logo"),
Anand Doshi2af44ff2015-12-09 17:28:51 +0530141 description: __("100px by 100px"),
142 is_private: 0
143 },
Anand Doshi1ed82832015-11-16 12:58:14 +0530144 ],
145
146 css_class: "two-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530147 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530148
Anand Doshi1ed82832015-11-16 12:58:14 +0530149 users: {
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530150 app_name: "erpnext",
Anand Doshi1ed82832015-11-16 12:58:14 +0530151 icon: "icon-money",
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530152 title: __("Add Users"),
153 help: __("Add users to your organization, other than yourself"),
154 fields: [],
Anand Doshi1ed82832015-11-16 12:58:14 +0530155 before_load: function(slide) {
156 slide.fields = [];
157 for(var i=1; i<5; i++) {
158 slide.fields = slide.fields.concat([
159 {fieldtype:"Section Break"},
160 {fieldtype:"Data", fieldname:"user_fullname_"+ i,
161 label:__("Full Name")},
162 {fieldtype:"Data", fieldname:"user_email_" + i,
163 label:__("Email ID"), placeholder:__("user@example.com"),
164 options: "Email"},
165 {fieldtype:"Column Break"},
166 {fieldtype: "Check", fieldname: "user_sales_" + i,
167 label:__("Sales"), default: 1},
168 {fieldtype: "Check", fieldname: "user_purchaser_" + i,
169 label:__("Purchaser"), default: 1},
170 {fieldtype: "Check", fieldname: "user_accountant_" + i,
171 label:__("Accountant"), default: 1},
172 ]);
173 }
174 },
175 css_class: "two-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530176 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530177
Anand Doshi1ed82832015-11-16 12:58:14 +0530178 taxes: {
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530179 app_name: "erpnext",
Anand Doshi1ed82832015-11-16 12:58:14 +0530180 icon: "icon-money",
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530181 title: __("Add Taxes"),
182 help: __("List your tax heads (e.g. VAT, Customs etc; they should have unique names) and their standard rates. This will create a standard template, which you can edit and add more later."),
Anand Doshi1ed82832015-11-16 12:58:14 +0530183 "fields": [],
184 before_load: function(slide) {
185 slide.fields = [];
186 for(var i=1; i<4; i++) {
187 slide.fields = slide.fields.concat([
188 {fieldtype:"Section Break"},
189 {fieldtype:"Data", fieldname:"tax_"+ i, label:__("Tax") + " " + i,
190 placeholder:__("e.g. VAT") + " " + i},
191 {fieldtype:"Column Break"},
192 {fieldtype:"Float", fieldname:"tax_rate_" + i, label:__("Rate (%)"), placeholder:__("e.g. 5")},
193 ]);
194 }
195 },
196 css_class: "two-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530197 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530198
Anand Doshi1ed82832015-11-16 12:58:14 +0530199 customers: {
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530200 app_name: "erpnext",
Anand Doshi1ed82832015-11-16 12:58:14 +0530201 icon: "icon-group",
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530202 title: __("Your Customers"),
203 help: __("List a few of your customers. They could be organizations or individuals."),
204 fields: [],
Anand Doshi1ed82832015-11-16 12:58:14 +0530205 before_load: function(slide) {
206 slide.fields = [];
207 for(var i=1; i<6; i++) {
208 slide.fields = slide.fields.concat([
209 {fieldtype:"Section Break"},
210 {fieldtype:"Data", fieldname:"customer_" + i, label:__("Customer") + " " + i,
211 placeholder:__("Customer Name")},
212 {fieldtype:"Column Break"},
213 {fieldtype:"Data", fieldname:"customer_contact_" + i,
214 label:__("Contact Name") + " " + i, placeholder:__("Contact Name")}
215 ])
216 }
217 slide.fields[1].reqd = 1;
218 },
219 css_class: "two-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530220 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530221
Anand Doshi1ed82832015-11-16 12:58:14 +0530222 suppliers: {
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530223 app_name: "erpnext",
Anand Doshi1ed82832015-11-16 12:58:14 +0530224 icon: "icon-group",
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530225 title: __("Your Suppliers"),
226 help: __("List a few of your suppliers. They could be organizations or individuals."),
227 fields: [],
Anand Doshi1ed82832015-11-16 12:58:14 +0530228 before_load: function(slide) {
229 slide.fields = [];
230 for(var i=1; i<6; i++) {
231 slide.fields = slide.fields.concat([
232 {fieldtype:"Section Break"},
233 {fieldtype:"Data", fieldname:"supplier_" + i, label:__("Supplier")+" " + i,
234 placeholder:__("Supplier Name")},
235 {fieldtype:"Column Break"},
236 {fieldtype:"Data", fieldname:"supplier_contact_" + i,
237 label:__("Contact Name") + " " + i, placeholder:__("Contact Name")},
238 ])
239 }
240 slide.fields[1].reqd = 1;
241 },
242 css_class: "two-column"
243 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530244
Anand Doshi1ed82832015-11-16 12:58:14 +0530245 items: {
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530246 app_name: "erpnext",
Anand Doshi1ed82832015-11-16 12:58:14 +0530247 icon: "icon-barcode",
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530248 title: __("Your Products or Services"),
249 help: __("List your products or services that you buy or sell. Make sure to check the Item Group, Unit of Measure and other properties when you start."),
250 fields: [],
Anand Doshi1ed82832015-11-16 12:58:14 +0530251 before_load: function(slide) {
252 slide.fields = [];
253 for(var i=1; i<6; i++) {
254 slide.fields = slide.fields.concat([
255 {fieldtype:"Section Break", show_section_border: true},
256 {fieldtype:"Data", fieldname:"item_" + i, label:__("Item") + " " + i,
257 placeholder:__("A Product or Service")},
258 {fieldtype:"Select", label:__("Group"), fieldname:"item_group_" + i,
259 options:[__("Products"), __("Services"),
260 __("Raw Material"), __("Consumable"), __("Sub Assemblies")],
261 "default": __("Products")},
262 {fieldtype:"Select", fieldname:"item_uom_" + i, label:__("UOM"),
263 options:[__("Unit"), __("Nos"), __("Box"), __("Pair"), __("Kg"), __("Set"),
264 __("Hour"), __("Minute")],
265 "default": __("Unit")},
266 {fieldtype: "Check", fieldname: "is_sales_item_" + i, label:__("We sell this Item"), default: 1},
267 {fieldtype: "Check", fieldname: "is_purchase_item_" + i, label:__("We buy this Item")},
268 {fieldtype:"Column Break"},
269 {fieldtype:"Currency", fieldname:"item_price_" + i, label:__("Rate")},
Anand Doshi2af44ff2015-12-09 17:28:51 +0530270 {fieldtype:"Attach Image", fieldname:"item_img_" + i, label:__("Attach Image"), is_private: 0},
Anand Doshi1ed82832015-11-16 12:58:14 +0530271 ])
272 }
273 slide.fields[1].reqd = 1;
274
275 // dummy data
276 slide.fields.push({fieldtype: "Section Break"});
277 slide.fields.push({fieldtype: "Check", fieldname: "add_sample_data",
278 label: __("Add a few sample records"), "default": 1});
279 },
280 css_class: "two-column"
281 },
282 });
283
284 // Source: https://en.wikipedia.org/wiki/Fiscal_year
285 // default 1st Jan - 31st Dec
286
287 erpnext.wiz.fiscal_years = {
288 "Afghanistan": ["12-20", "12-21"],
289 "Australia": ["07-01", "06-30"],
290 "Bangladesh": ["07-01", "06-30"],
291 "Canada": ["04-01", "03-31"],
292 "Costa Rica": ["10-01", "09-30"],
293 "Egypt": ["07-01", "06-30"],
294 "Hong Kong": ["04-01", "03-31"],
295 "India": ["04-01", "03-31"],
296 "Iran": ["06-23", "06-22"],
297 "Italy": ["07-01", "06-30"],
298 "Myanmar": ["04-01", "03-31"],
299 "New Zealand": ["04-01", "03-31"],
300 "Pakistan": ["07-01", "06-30"],
301 "Singapore": ["04-01", "03-31"],
302 "South Africa": ["03-01", "02-28"],
303 "Thailand": ["10-01", "09-30"],
304 "United Kingdom": ["04-01", "03-31"],
305 };
306};
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530307
308frappe.wiz.on("before_load", function() {
Anand Doshi1ed82832015-11-16 12:58:14 +0530309 load_erpnext_slides();
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530310 frappe.wiz.add_slide(erpnext.wiz.org);
311 frappe.wiz.add_slide(erpnext.wiz.branding);
312 frappe.wiz.add_slide(erpnext.wiz.users);
313 frappe.wiz.add_slide(erpnext.wiz.taxes);
314 frappe.wiz.add_slide(erpnext.wiz.customers);
315 frappe.wiz.add_slide(erpnext.wiz.suppliers);
316 frappe.wiz.add_slide(erpnext.wiz.items);
317 frappe.wiz.welcome_page = "#welcome-to-erpnext";
318});