blob: ec70bbb62b4f93e791fbc3b2b82cdf19d53afb38 [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, {
12 region: {
13 title: __("Region"),
14 icon: "icon-flag",
15 help: __("Select your Country, Time Zone and Currency"),
16 fields: [
17 { fieldname: "country", label: __("Country"), reqd:1,
18 fieldtype: "Select" },
19 { fieldname: "timezone", label: __("Time Zone"), reqd:1,
20 fieldtype: "Select" },
21 { fieldname: "currency", label: __("Currency"), reqd:1,
22 fieldtype: "Select" },
23 ],
Rushabh Mehta37b4d752015-11-09 16:53:11 +053024
Anand Doshi1ed82832015-11-16 12:58:14 +053025 onload: function(slide) {
26 frappe.call({
27 method:"frappe.geo.country_info.get_country_timezone_info",
28 callback: function(data) {
29 erpnext.wiz.region.data = data.message;
30 erpnext.wiz.region.setup_fields(slide);
31 erpnext.wiz.region.bind_events(slide);
32 }
33 });
34 },
35 css_class: "single-column",
36 setup_fields: function(slide) {
Rushabh Mehta37b4d752015-11-09 16:53:11 +053037 var data = erpnext.wiz.region.data;
38
Anand Doshi1ed82832015-11-16 12:58:14 +053039 slide.get_input("country").empty()
40 .add_options([""].concat(keys(data.country_info).sort()));
Rushabh Mehta37b4d752015-11-09 16:53:11 +053041
Anand Doshi1ed82832015-11-16 12:58:14 +053042 slide.get_input("currency").empty()
43 .add_options(frappe.utils.unique([""].concat($.map(data.country_info,
44 function(opts, country) { return opts.currency; }))).sort());
45
46 slide.get_input("timezone").empty()
47 .add_options([""].concat(data.all_timezones));
48
49 if (data.default_country) {
50 slide.set_input("country", data.default_country);
Rushabh Mehta37b4d752015-11-09 16:53:11 +053051 }
Anand Doshi1ed82832015-11-16 12:58:14 +053052 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +053053
Anand Doshi1ed82832015-11-16 12:58:14 +053054 bind_events: function(slide) {
55 slide.get_input("country").on("change", function() {
56 var country = slide.get_input("country").val();
57 var $timezone = slide.get_input("timezone");
58 var data = erpnext.wiz.region.data;
Rushabh Mehta37b4d752015-11-09 16:53:11 +053059
Anand Doshi1ed82832015-11-16 12:58:14 +053060 $timezone.empty();
Rushabh Mehta37b4d752015-11-09 16:53:11 +053061
Anand Doshi1ed82832015-11-16 12:58:14 +053062 // add country specific timezones first
63 if(country) {
64 var timezone_list = data.country_info[country].timezones || [];
65 $timezone.add_options(timezone_list.sort());
66 slide.get_field("currency").set_input(data.country_info[country].currency);
67 slide.get_field("currency").$input.trigger("change");
Rushabh Mehta37b4d752015-11-09 16:53:11 +053068 }
69
Anand Doshi1ed82832015-11-16 12:58:14 +053070 // add all timezones at the end, so that user has the option to change it to any timezone
71 $timezone.add_options([""].concat(data.all_timezones));
72
73 slide.get_field("timezone").set_input($timezone.val());
74
75 // temporarily set date format
76 frappe.boot.sysdefaults.date_format = (data.country_info[country].date_format
77 || "dd-mm-yyyy");
Rushabh Mehta37b4d752015-11-09 16:53:11 +053078 });
Rushabh Mehta37b4d752015-11-09 16:53:11 +053079
Anand Doshi1ed82832015-11-16 12:58:14 +053080 slide.get_input("currency").on("change", function() {
81 var currency = slide.get_input("currency").val();
82 if (!currency) return;
83 frappe.model.with_doc("Currency", currency, function() {
84 frappe.provide("locals.:Currency." + currency);
85 var currency_doc = frappe.model.get_doc("Currency", currency);
86 var number_format = currency_doc.number_format;
87 if (number_format==="#.###") {
88 number_format = "#.###,##";
89 } else if (number_format==="#,###") {
90 number_format = "#,###.##"
91 }
Rushabh Mehta37b4d752015-11-09 16:53:11 +053092
Anand Doshi1ed82832015-11-16 12:58:14 +053093 frappe.boot.sysdefaults.number_format = number_format;
94 locals[":Currency"][currency] = $.extend({}, currency_doc);
95 });
96 });
Rushabh Mehta37b4d752015-11-09 16:53:11 +053097 }
98 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +053099
Anand Doshi1ed82832015-11-16 12:58:14 +0530100 user: {
101 title: __("The First User: You"),
102 icon: "icon-user",
103 fields: [
104 {"fieldname": "first_name", "label": __("First Name"), "fieldtype": "Data",
105 reqd:1},
106 {"fieldname": "last_name", "label": __("Last Name"), "fieldtype": "Data"},
107 {"fieldname": "email", "label": __("Email Address"), "fieldtype": "Data",
108 reqd:1, "description": __("You will use it to Login"), "options":"Email"},
109 {"fieldname": "password", "label": __("Password"), "fieldtype": "Password",
110 reqd:1},
111 {fieldtype:"Attach Image", fieldname:"attach_user",
Anand Doshi2af44ff2015-12-09 17:28:51 +0530112 label: __("Attach Your Picture"), is_private: 0},
Anand Doshi1ed82832015-11-16 12:58:14 +0530113 ],
114 help: __('The first user will become the System Manager (you can change this later).'),
115 onload: function(slide) {
116 if(user!=="Administrator") {
117 slide.form.fields_dict.password.$wrapper.toggle(false);
118 slide.form.fields_dict.email.$wrapper.toggle(false);
119 slide.form.fields_dict.first_name.set_input(frappe.boot.user.first_name);
120 slide.form.fields_dict.last_name.set_input(frappe.boot.user.last_name);
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530121
Anand Doshi1ed82832015-11-16 12:58:14 +0530122 var user_image = frappe.get_cookie("user_image");
123 if(user_image) {
124 var $attach_user = slide.form.fields_dict.attach_user.$wrapper;
125 $attach_user.find(".missing-image").toggle(false);
126 $attach_user.find("img").attr("src", decodeURIComponent(user_image)).toggle(true);
127 }
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530128
Anand Doshi1ed82832015-11-16 12:58:14 +0530129 delete slide.form.fields_dict.email;
130 delete slide.form.fields_dict.password;
131 }
132 },
133 css_class: "single-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530134 },
135
Anand Doshi1ed82832015-11-16 12:58:14 +0530136 org: {
137 title: __("The Organization"),
138 icon: "icon-building",
139 fields: [
140 {fieldname:'company_name', label: __('Company Name'), fieldtype:'Data', reqd:1,
141 placeholder: __('e.g. "My Company LLC"')},
142 {fieldname:'company_abbr', label: __('Company Abbreviation'), fieldtype:'Data',
143 description: __('Max 5 characters'), placeholder: __('e.g. "MC"'), reqd:1},
144 {fieldname:'company_tagline', label: __('What does it do?'), fieldtype:'Data',
145 placeholder:__('e.g. "Build tools for builders"'), reqd:1},
146 {fieldname:'bank_account', label: __('Bank Account'), fieldtype:'Data',
147 placeholder: __('e.g. "XYZ National Bank"'), reqd:1 },
148 {fieldname:'chart_of_accounts', label: __('Chart of Accounts'),
149 options: "", fieldtype: 'Select'},
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530150
Anand Doshi1ed82832015-11-16 12:58:14 +0530151 // TODO remove this
152 {fieldtype: "Section Break"},
153 {fieldname:'fy_start_date', label:__('Financial Year Start Date'), fieldtype:'Date',
154 description: __('Your financial year begins on'), reqd:1},
155 {fieldname:'fy_end_date', label:__('Financial Year End Date'), fieldtype:'Date',
156 description: __('Your financial year ends on'), reqd:1},
157 ],
158 help: __('The name of your company for which you are setting up this system.'),
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530159
Anand Doshi1ed82832015-11-16 12:58:14 +0530160 onload: function(slide) {
161 erpnext.wiz.org.load_chart_of_accounts(slide);
162 erpnext.wiz.org.bind_events(slide);
163 erpnext.wiz.org.set_fy_dates(slide);
164 },
165
Anand Doshi5c3469a2015-11-24 17:06:54 +0530166 validate: function() {
167 // validate fiscal year start and end dates
168 if (this.values.fy_start_date=='Invalid date' || this.values.fy_end_date=='Invalid date') {
169 msgprint(__("Please enter valid Financial Year Start and End Dates"));
170 return false;
171 }
172
173 if ((this.values.company_name || "").toLowerCase() == "company") {
174 msgprint(__("Company Name cannot be Company"));
175 return false;
176 }
177
178 return true;
179 },
180
Anand Doshi1ed82832015-11-16 12:58:14 +0530181 css_class: "single-column",
182
183 set_fy_dates: function(slide) {
184 var country = slide.wiz.get_values().country;
185
186 if(country) {
187 var fy = erpnext.wiz.fiscal_years[country];
188 var current_year = moment(new Date()).year();
189 var next_year = current_year + 1;
190 if(!fy) {
191 fy = ["01-01", "12-31"];
192 next_year = current_year;
193 }
194
195 slide.get_field("fy_start_date").set_input(current_year + "-" + fy[0]);
196 slide.get_field("fy_end_date").set_input(next_year + "-" + fy[1]);
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530197 }
198
Anand Doshi1ed82832015-11-16 12:58:14 +0530199 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530200
Anand Doshi1ed82832015-11-16 12:58:14 +0530201 load_chart_of_accounts: function(slide) {
202 var country = slide.wiz.get_values().country;
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530203
Anand Doshi1ed82832015-11-16 12:58:14 +0530204 if(country) {
205 frappe.call({
206 method: "erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts.get_charts_for_country",
207 args: {"country": country},
208 callback: function(r) {
209 if(r.message) {
210 slide.get_input("chart_of_accounts").empty()
211 .add_options(r.message);
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530212
Anand Doshi1ed82832015-11-16 12:58:14 +0530213 if (r.message.length===1) {
214 var field = slide.get_field("chart_of_accounts");
215 field.set_value(r.message[0]);
216 field.df.hidden = 1;
217 field.refresh();
218 }
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530219 }
220 }
Anand Doshi1ed82832015-11-16 12:58:14 +0530221 })
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530222 }
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530223 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530224
Anand Doshi1ed82832015-11-16 12:58:14 +0530225 bind_events: function(slide) {
226 slide.get_input("company_name").on("change", function() {
227 var parts = slide.get_input("company_name").val().split(" ");
228 var abbr = $.map(parts, function(p) { return p ? p.substr(0,1) : null }).join("");
229 slide.get_field("company_abbr").set_input(abbr.slice(0, 5).toUpperCase());
230 }).val(frappe.boot.sysdefaults.company_name || "").trigger("change");
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530231
Anand Doshi1ed82832015-11-16 12:58:14 +0530232 slide.get_input("company_abbr").on("change", function() {
233 if(slide.get_input("company_abbr").val().length > 5) {
234 msgprint("Company Abbreviation cannot have more than 5 characters");
235 slide.get_field("company_abbr").set_input("");
236 }
237 });
238
239 // TODO remove this
240 slide.get_input("fy_start_date").on("change", function() {
241 var year_end_date =
242 frappe.datetime.add_days(frappe.datetime.add_months(
243 frappe.datetime.user_to_obj(slide.get_input("fy_start_date").val()), 12), -1);
244 slide.get_input("fy_end_date").val(frappe.datetime.obj_to_user(year_end_date));
245
246 });
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530247 }
248 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530249
Anand Doshi1ed82832015-11-16 12:58:14 +0530250 branding: {
251 icon: "icon-bookmark",
252 title: __("The Brand"),
253 help: __('Upload your letter head and logo. (you can edit them later).'),
254 fields: [
255 {fieldtype:"Attach Image", fieldname:"attach_letterhead",
256 label: __("Attach Letterhead"),
Anand Doshi2af44ff2015-12-09 17:28:51 +0530257 description: __("Keep it web friendly 900px (w) by 100px (h)"),
258 is_private: 0
Anand Doshi1ed82832015-11-16 12:58:14 +0530259 },
260 {fieldtype: "Column Break"},
261 {fieldtype:"Attach Image", fieldname:"attach_logo",
262 label:__("Attach Logo"),
Anand Doshi2af44ff2015-12-09 17:28:51 +0530263 description: __("100px by 100px"),
264 is_private: 0
265 },
Anand Doshi1ed82832015-11-16 12:58:14 +0530266 ],
267
268 css_class: "two-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530269 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530270
Anand Doshi1ed82832015-11-16 12:58:14 +0530271 users: {
272 icon: "icon-money",
273 "title": __("Add Users"),
274 "help": __("Add users to your organization, other than yourself"),
275 "fields": [],
276 before_load: function(slide) {
277 slide.fields = [];
278 for(var i=1; i<5; i++) {
279 slide.fields = slide.fields.concat([
280 {fieldtype:"Section Break"},
281 {fieldtype:"Data", fieldname:"user_fullname_"+ i,
282 label:__("Full Name")},
283 {fieldtype:"Data", fieldname:"user_email_" + i,
284 label:__("Email ID"), placeholder:__("user@example.com"),
285 options: "Email"},
286 {fieldtype:"Column Break"},
287 {fieldtype: "Check", fieldname: "user_sales_" + i,
288 label:__("Sales"), default: 1},
289 {fieldtype: "Check", fieldname: "user_purchaser_" + i,
290 label:__("Purchaser"), default: 1},
291 {fieldtype: "Check", fieldname: "user_accountant_" + i,
292 label:__("Accountant"), default: 1},
293 ]);
294 }
295 },
296 css_class: "two-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530297 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530298
Anand Doshi1ed82832015-11-16 12:58:14 +0530299 taxes: {
300 icon: "icon-money",
301 "title": __("Add Taxes"),
302 "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."),
303 "fields": [],
304 before_load: function(slide) {
305 slide.fields = [];
306 for(var i=1; i<4; i++) {
307 slide.fields = slide.fields.concat([
308 {fieldtype:"Section Break"},
309 {fieldtype:"Data", fieldname:"tax_"+ i, label:__("Tax") + " " + i,
310 placeholder:__("e.g. VAT") + " " + i},
311 {fieldtype:"Column Break"},
312 {fieldtype:"Float", fieldname:"tax_rate_" + i, label:__("Rate (%)"), placeholder:__("e.g. 5")},
313 ]);
314 }
315 },
316 css_class: "two-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530317 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530318
Anand Doshi1ed82832015-11-16 12:58:14 +0530319 customers: {
320 icon: "icon-group",
321 "title": __("Your Customers"),
322 "help": __("List a few of your customers. They could be organizations or individuals."),
323 "fields": [],
324 before_load: function(slide) {
325 slide.fields = [];
326 for(var i=1; i<6; i++) {
327 slide.fields = slide.fields.concat([
328 {fieldtype:"Section Break"},
329 {fieldtype:"Data", fieldname:"customer_" + i, label:__("Customer") + " " + i,
330 placeholder:__("Customer Name")},
331 {fieldtype:"Column Break"},
332 {fieldtype:"Data", fieldname:"customer_contact_" + i,
333 label:__("Contact Name") + " " + i, placeholder:__("Contact Name")}
334 ])
335 }
336 slide.fields[1].reqd = 1;
337 },
338 css_class: "two-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530339 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530340
Anand Doshi1ed82832015-11-16 12:58:14 +0530341 suppliers: {
342 icon: "icon-group",
343 "title": __("Your Suppliers"),
344 "help": __("List a few of your suppliers. They could be organizations or individuals."),
345 "fields": [],
346 before_load: function(slide) {
347 slide.fields = [];
348 for(var i=1; i<6; i++) {
349 slide.fields = slide.fields.concat([
350 {fieldtype:"Section Break"},
351 {fieldtype:"Data", fieldname:"supplier_" + i, label:__("Supplier")+" " + i,
352 placeholder:__("Supplier Name")},
353 {fieldtype:"Column Break"},
354 {fieldtype:"Data", fieldname:"supplier_contact_" + i,
355 label:__("Contact Name") + " " + i, placeholder:__("Contact Name")},
356 ])
357 }
358 slide.fields[1].reqd = 1;
359 },
360 css_class: "two-column"
361 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530362
Anand Doshi1ed82832015-11-16 12:58:14 +0530363 items: {
364 icon: "icon-barcode",
365 "title": __("Your Products or Services"),
366 "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."),
367 "fields": [],
368 before_load: function(slide) {
369 slide.fields = [];
370 for(var i=1; i<6; i++) {
371 slide.fields = slide.fields.concat([
372 {fieldtype:"Section Break", show_section_border: true},
373 {fieldtype:"Data", fieldname:"item_" + i, label:__("Item") + " " + i,
374 placeholder:__("A Product or Service")},
375 {fieldtype:"Select", label:__("Group"), fieldname:"item_group_" + i,
376 options:[__("Products"), __("Services"),
377 __("Raw Material"), __("Consumable"), __("Sub Assemblies")],
378 "default": __("Products")},
379 {fieldtype:"Select", fieldname:"item_uom_" + i, label:__("UOM"),
380 options:[__("Unit"), __("Nos"), __("Box"), __("Pair"), __("Kg"), __("Set"),
381 __("Hour"), __("Minute")],
382 "default": __("Unit")},
383 {fieldtype: "Check", fieldname: "is_sales_item_" + i, label:__("We sell this Item"), default: 1},
384 {fieldtype: "Check", fieldname: "is_purchase_item_" + i, label:__("We buy this Item")},
385 {fieldtype:"Column Break"},
386 {fieldtype:"Currency", fieldname:"item_price_" + i, label:__("Rate")},
Anand Doshi2af44ff2015-12-09 17:28:51 +0530387 {fieldtype:"Attach Image", fieldname:"item_img_" + i, label:__("Attach Image"), is_private: 0},
Anand Doshi1ed82832015-11-16 12:58:14 +0530388 ])
389 }
390 slide.fields[1].reqd = 1;
391
392 // dummy data
393 slide.fields.push({fieldtype: "Section Break"});
394 slide.fields.push({fieldtype: "Check", fieldname: "add_sample_data",
395 label: __("Add a few sample records"), "default": 1});
396 },
397 css_class: "two-column"
398 },
399 });
400
401 // Source: https://en.wikipedia.org/wiki/Fiscal_year
402 // default 1st Jan - 31st Dec
403
404 erpnext.wiz.fiscal_years = {
405 "Afghanistan": ["12-20", "12-21"],
406 "Australia": ["07-01", "06-30"],
407 "Bangladesh": ["07-01", "06-30"],
408 "Canada": ["04-01", "03-31"],
409 "Costa Rica": ["10-01", "09-30"],
410 "Egypt": ["07-01", "06-30"],
411 "Hong Kong": ["04-01", "03-31"],
412 "India": ["04-01", "03-31"],
413 "Iran": ["06-23", "06-22"],
414 "Italy": ["07-01", "06-30"],
415 "Myanmar": ["04-01", "03-31"],
416 "New Zealand": ["04-01", "03-31"],
417 "Pakistan": ["07-01", "06-30"],
418 "Singapore": ["04-01", "03-31"],
419 "South Africa": ["03-01", "02-28"],
420 "Thailand": ["10-01", "09-30"],
421 "United Kingdom": ["04-01", "03-31"],
422 };
423};
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530424
425frappe.wiz.on("before_load", function() {
Anand Doshi1ed82832015-11-16 12:58:14 +0530426 load_erpnext_slides();
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530427 frappe.wiz.add_slide(erpnext.wiz.user);
428 frappe.wiz.add_slide(erpnext.wiz.org);
429 frappe.wiz.add_slide(erpnext.wiz.branding);
430 frappe.wiz.add_slide(erpnext.wiz.users);
431 frappe.wiz.add_slide(erpnext.wiz.taxes);
432 frappe.wiz.add_slide(erpnext.wiz.customers);
433 frappe.wiz.add_slide(erpnext.wiz.suppliers);
434 frappe.wiz.add_slide(erpnext.wiz.items);
435 frappe.wiz.welcome_page = "#welcome-to-erpnext";
436});