blob: c139f8a7178fc96ce54f8af0eefc6e4f94b55567 [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",
112 label: __("Attach Your Picture")},
113 ],
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"),
257 description: __("Keep it web friendly 900px (w) by 100px (h)")
258 },
259 {fieldtype: "Column Break"},
260 {fieldtype:"Attach Image", fieldname:"attach_logo",
261 label:__("Attach Logo"),
262 description: __("100px by 100px")},
263 ],
264
265 css_class: "two-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530266 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530267
Anand Doshi1ed82832015-11-16 12:58:14 +0530268 users: {
269 icon: "icon-money",
270 "title": __("Add Users"),
271 "help": __("Add users to your organization, other than yourself"),
272 "fields": [],
273 before_load: function(slide) {
274 slide.fields = [];
275 for(var i=1; i<5; i++) {
276 slide.fields = slide.fields.concat([
277 {fieldtype:"Section Break"},
278 {fieldtype:"Data", fieldname:"user_fullname_"+ i,
279 label:__("Full Name")},
280 {fieldtype:"Data", fieldname:"user_email_" + i,
281 label:__("Email ID"), placeholder:__("user@example.com"),
282 options: "Email"},
283 {fieldtype:"Column Break"},
284 {fieldtype: "Check", fieldname: "user_sales_" + i,
285 label:__("Sales"), default: 1},
286 {fieldtype: "Check", fieldname: "user_purchaser_" + i,
287 label:__("Purchaser"), default: 1},
288 {fieldtype: "Check", fieldname: "user_accountant_" + i,
289 label:__("Accountant"), default: 1},
290 ]);
291 }
292 },
293 css_class: "two-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530294 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530295
Anand Doshi1ed82832015-11-16 12:58:14 +0530296 taxes: {
297 icon: "icon-money",
298 "title": __("Add Taxes"),
299 "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."),
300 "fields": [],
301 before_load: function(slide) {
302 slide.fields = [];
303 for(var i=1; i<4; i++) {
304 slide.fields = slide.fields.concat([
305 {fieldtype:"Section Break"},
306 {fieldtype:"Data", fieldname:"tax_"+ i, label:__("Tax") + " " + i,
307 placeholder:__("e.g. VAT") + " " + i},
308 {fieldtype:"Column Break"},
309 {fieldtype:"Float", fieldname:"tax_rate_" + i, label:__("Rate (%)"), placeholder:__("e.g. 5")},
310 ]);
311 }
312 },
313 css_class: "two-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530314 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530315
Anand Doshi1ed82832015-11-16 12:58:14 +0530316 customers: {
317 icon: "icon-group",
318 "title": __("Your Customers"),
319 "help": __("List a few of your customers. They could be organizations or individuals."),
320 "fields": [],
321 before_load: function(slide) {
322 slide.fields = [];
323 for(var i=1; i<6; i++) {
324 slide.fields = slide.fields.concat([
325 {fieldtype:"Section Break"},
326 {fieldtype:"Data", fieldname:"customer_" + i, label:__("Customer") + " " + i,
327 placeholder:__("Customer Name")},
328 {fieldtype:"Column Break"},
329 {fieldtype:"Data", fieldname:"customer_contact_" + i,
330 label:__("Contact Name") + " " + i, placeholder:__("Contact Name")}
331 ])
332 }
333 slide.fields[1].reqd = 1;
334 },
335 css_class: "two-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530336 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530337
Anand Doshi1ed82832015-11-16 12:58:14 +0530338 suppliers: {
339 icon: "icon-group",
340 "title": __("Your Suppliers"),
341 "help": __("List a few of your suppliers. They could be organizations or individuals."),
342 "fields": [],
343 before_load: function(slide) {
344 slide.fields = [];
345 for(var i=1; i<6; i++) {
346 slide.fields = slide.fields.concat([
347 {fieldtype:"Section Break"},
348 {fieldtype:"Data", fieldname:"supplier_" + i, label:__("Supplier")+" " + i,
349 placeholder:__("Supplier Name")},
350 {fieldtype:"Column Break"},
351 {fieldtype:"Data", fieldname:"supplier_contact_" + i,
352 label:__("Contact Name") + " " + i, placeholder:__("Contact Name")},
353 ])
354 }
355 slide.fields[1].reqd = 1;
356 },
357 css_class: "two-column"
358 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530359
Anand Doshi1ed82832015-11-16 12:58:14 +0530360 items: {
361 icon: "icon-barcode",
362 "title": __("Your Products or Services"),
363 "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."),
364 "fields": [],
365 before_load: function(slide) {
366 slide.fields = [];
367 for(var i=1; i<6; i++) {
368 slide.fields = slide.fields.concat([
369 {fieldtype:"Section Break", show_section_border: true},
370 {fieldtype:"Data", fieldname:"item_" + i, label:__("Item") + " " + i,
371 placeholder:__("A Product or Service")},
372 {fieldtype:"Select", label:__("Group"), fieldname:"item_group_" + i,
373 options:[__("Products"), __("Services"),
374 __("Raw Material"), __("Consumable"), __("Sub Assemblies")],
375 "default": __("Products")},
376 {fieldtype:"Select", fieldname:"item_uom_" + i, label:__("UOM"),
377 options:[__("Unit"), __("Nos"), __("Box"), __("Pair"), __("Kg"), __("Set"),
378 __("Hour"), __("Minute")],
379 "default": __("Unit")},
380 {fieldtype: "Check", fieldname: "is_sales_item_" + i, label:__("We sell this Item"), default: 1},
381 {fieldtype: "Check", fieldname: "is_purchase_item_" + i, label:__("We buy this Item")},
382 {fieldtype:"Column Break"},
383 {fieldtype:"Currency", fieldname:"item_price_" + i, label:__("Rate")},
384 {fieldtype:"Attach Image", fieldname:"item_img_" + i, label:__("Attach Image")},
385 ])
386 }
387 slide.fields[1].reqd = 1;
388
389 // dummy data
390 slide.fields.push({fieldtype: "Section Break"});
391 slide.fields.push({fieldtype: "Check", fieldname: "add_sample_data",
392 label: __("Add a few sample records"), "default": 1});
393 },
394 css_class: "two-column"
395 },
396 });
397
398 // Source: https://en.wikipedia.org/wiki/Fiscal_year
399 // default 1st Jan - 31st Dec
400
401 erpnext.wiz.fiscal_years = {
402 "Afghanistan": ["12-20", "12-21"],
403 "Australia": ["07-01", "06-30"],
404 "Bangladesh": ["07-01", "06-30"],
405 "Canada": ["04-01", "03-31"],
406 "Costa Rica": ["10-01", "09-30"],
407 "Egypt": ["07-01", "06-30"],
408 "Hong Kong": ["04-01", "03-31"],
409 "India": ["04-01", "03-31"],
410 "Iran": ["06-23", "06-22"],
411 "Italy": ["07-01", "06-30"],
412 "Myanmar": ["04-01", "03-31"],
413 "New Zealand": ["04-01", "03-31"],
414 "Pakistan": ["07-01", "06-30"],
415 "Singapore": ["04-01", "03-31"],
416 "South Africa": ["03-01", "02-28"],
417 "Thailand": ["10-01", "09-30"],
418 "United Kingdom": ["04-01", "03-31"],
419 };
420};
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530421
422frappe.wiz.on("before_load", function() {
Anand Doshi1ed82832015-11-16 12:58:14 +0530423 load_erpnext_slides();
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530424 frappe.wiz.add_slide(erpnext.wiz.user);
425 frappe.wiz.add_slide(erpnext.wiz.org);
426 frappe.wiz.add_slide(erpnext.wiz.branding);
427 frappe.wiz.add_slide(erpnext.wiz.users);
428 frappe.wiz.add_slide(erpnext.wiz.taxes);
429 frappe.wiz.add_slide(erpnext.wiz.customers);
430 frappe.wiz.add_slide(erpnext.wiz.suppliers);
431 frappe.wiz.add_slide(erpnext.wiz.items);
432 frappe.wiz.welcome_page = "#welcome-to-erpnext";
433});