blob: bb3d272ac47473d3a5d27006d13957ea302011cf [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
166 css_class: "single-column",
167
168 set_fy_dates: function(slide) {
169 var country = slide.wiz.get_values().country;
170
171 if(country) {
172 var fy = erpnext.wiz.fiscal_years[country];
173 var current_year = moment(new Date()).year();
174 var next_year = current_year + 1;
175 if(!fy) {
176 fy = ["01-01", "12-31"];
177 next_year = current_year;
178 }
179
180 slide.get_field("fy_start_date").set_input(current_year + "-" + fy[0]);
181 slide.get_field("fy_end_date").set_input(next_year + "-" + fy[1]);
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530182 }
183
Anand Doshi1ed82832015-11-16 12:58:14 +0530184 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530185
Anand Doshi1ed82832015-11-16 12:58:14 +0530186 load_chart_of_accounts: function(slide) {
187 var country = slide.wiz.get_values().country;
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530188
Anand Doshi1ed82832015-11-16 12:58:14 +0530189 if(country) {
190 frappe.call({
191 method: "erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts.get_charts_for_country",
192 args: {"country": country},
193 callback: function(r) {
194 if(r.message) {
195 slide.get_input("chart_of_accounts").empty()
196 .add_options(r.message);
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530197
Anand Doshi1ed82832015-11-16 12:58:14 +0530198 if (r.message.length===1) {
199 var field = slide.get_field("chart_of_accounts");
200 field.set_value(r.message[0]);
201 field.df.hidden = 1;
202 field.refresh();
203 }
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530204 }
205 }
Anand Doshi1ed82832015-11-16 12:58:14 +0530206 })
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530207 }
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530208 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530209
Anand Doshi1ed82832015-11-16 12:58:14 +0530210 bind_events: function(slide) {
211 slide.get_input("company_name").on("change", function() {
212 var parts = slide.get_input("company_name").val().split(" ");
213 var abbr = $.map(parts, function(p) { return p ? p.substr(0,1) : null }).join("");
214 slide.get_field("company_abbr").set_input(abbr.slice(0, 5).toUpperCase());
215 }).val(frappe.boot.sysdefaults.company_name || "").trigger("change");
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530216
Anand Doshi1ed82832015-11-16 12:58:14 +0530217 slide.get_input("company_abbr").on("change", function() {
218 if(slide.get_input("company_abbr").val().length > 5) {
219 msgprint("Company Abbreviation cannot have more than 5 characters");
220 slide.get_field("company_abbr").set_input("");
221 }
222 });
223
224 // TODO remove this
225 slide.get_input("fy_start_date").on("change", function() {
226 var year_end_date =
227 frappe.datetime.add_days(frappe.datetime.add_months(
228 frappe.datetime.user_to_obj(slide.get_input("fy_start_date").val()), 12), -1);
229 slide.get_input("fy_end_date").val(frappe.datetime.obj_to_user(year_end_date));
230
231 });
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530232 }
233 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530234
Anand Doshi1ed82832015-11-16 12:58:14 +0530235 branding: {
236 icon: "icon-bookmark",
237 title: __("The Brand"),
238 help: __('Upload your letter head and logo. (you can edit them later).'),
239 fields: [
240 {fieldtype:"Attach Image", fieldname:"attach_letterhead",
241 label: __("Attach Letterhead"),
242 description: __("Keep it web friendly 900px (w) by 100px (h)")
243 },
244 {fieldtype: "Column Break"},
245 {fieldtype:"Attach Image", fieldname:"attach_logo",
246 label:__("Attach Logo"),
247 description: __("100px by 100px")},
248 ],
249
250 css_class: "two-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530251 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530252
Anand Doshi1ed82832015-11-16 12:58:14 +0530253 users: {
254 icon: "icon-money",
255 "title": __("Add Users"),
256 "help": __("Add users to your organization, other than yourself"),
257 "fields": [],
258 before_load: function(slide) {
259 slide.fields = [];
260 for(var i=1; i<5; i++) {
261 slide.fields = slide.fields.concat([
262 {fieldtype:"Section Break"},
263 {fieldtype:"Data", fieldname:"user_fullname_"+ i,
264 label:__("Full Name")},
265 {fieldtype:"Data", fieldname:"user_email_" + i,
266 label:__("Email ID"), placeholder:__("user@example.com"),
267 options: "Email"},
268 {fieldtype:"Column Break"},
269 {fieldtype: "Check", fieldname: "user_sales_" + i,
270 label:__("Sales"), default: 1},
271 {fieldtype: "Check", fieldname: "user_purchaser_" + i,
272 label:__("Purchaser"), default: 1},
273 {fieldtype: "Check", fieldname: "user_accountant_" + i,
274 label:__("Accountant"), default: 1},
275 ]);
276 }
277 },
278 css_class: "two-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530279 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530280
Anand Doshi1ed82832015-11-16 12:58:14 +0530281 taxes: {
282 icon: "icon-money",
283 "title": __("Add Taxes"),
284 "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."),
285 "fields": [],
286 before_load: function(slide) {
287 slide.fields = [];
288 for(var i=1; i<4; i++) {
289 slide.fields = slide.fields.concat([
290 {fieldtype:"Section Break"},
291 {fieldtype:"Data", fieldname:"tax_"+ i, label:__("Tax") + " " + i,
292 placeholder:__("e.g. VAT") + " " + i},
293 {fieldtype:"Column Break"},
294 {fieldtype:"Float", fieldname:"tax_rate_" + i, label:__("Rate (%)"), placeholder:__("e.g. 5")},
295 ]);
296 }
297 },
298 css_class: "two-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530299 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530300
Anand Doshi1ed82832015-11-16 12:58:14 +0530301 customers: {
302 icon: "icon-group",
303 "title": __("Your Customers"),
304 "help": __("List a few of your customers. They could be organizations or individuals."),
305 "fields": [],
306 before_load: function(slide) {
307 slide.fields = [];
308 for(var i=1; i<6; i++) {
309 slide.fields = slide.fields.concat([
310 {fieldtype:"Section Break"},
311 {fieldtype:"Data", fieldname:"customer_" + i, label:__("Customer") + " " + i,
312 placeholder:__("Customer Name")},
313 {fieldtype:"Column Break"},
314 {fieldtype:"Data", fieldname:"customer_contact_" + i,
315 label:__("Contact Name") + " " + i, placeholder:__("Contact Name")}
316 ])
317 }
318 slide.fields[1].reqd = 1;
319 },
320 css_class: "two-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530321 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530322
Anand Doshi1ed82832015-11-16 12:58:14 +0530323 suppliers: {
324 icon: "icon-group",
325 "title": __("Your Suppliers"),
326 "help": __("List a few of your suppliers. They could be organizations or individuals."),
327 "fields": [],
328 before_load: function(slide) {
329 slide.fields = [];
330 for(var i=1; i<6; i++) {
331 slide.fields = slide.fields.concat([
332 {fieldtype:"Section Break"},
333 {fieldtype:"Data", fieldname:"supplier_" + i, label:__("Supplier")+" " + i,
334 placeholder:__("Supplier Name")},
335 {fieldtype:"Column Break"},
336 {fieldtype:"Data", fieldname:"supplier_contact_" + i,
337 label:__("Contact Name") + " " + i, placeholder:__("Contact Name")},
338 ])
339 }
340 slide.fields[1].reqd = 1;
341 },
342 css_class: "two-column"
343 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530344
Anand Doshi1ed82832015-11-16 12:58:14 +0530345 items: {
346 icon: "icon-barcode",
347 "title": __("Your Products or Services"),
348 "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."),
349 "fields": [],
350 before_load: function(slide) {
351 slide.fields = [];
352 for(var i=1; i<6; i++) {
353 slide.fields = slide.fields.concat([
354 {fieldtype:"Section Break", show_section_border: true},
355 {fieldtype:"Data", fieldname:"item_" + i, label:__("Item") + " " + i,
356 placeholder:__("A Product or Service")},
357 {fieldtype:"Select", label:__("Group"), fieldname:"item_group_" + i,
358 options:[__("Products"), __("Services"),
359 __("Raw Material"), __("Consumable"), __("Sub Assemblies")],
360 "default": __("Products")},
361 {fieldtype:"Select", fieldname:"item_uom_" + i, label:__("UOM"),
362 options:[__("Unit"), __("Nos"), __("Box"), __("Pair"), __("Kg"), __("Set"),
363 __("Hour"), __("Minute")],
364 "default": __("Unit")},
365 {fieldtype: "Check", fieldname: "is_sales_item_" + i, label:__("We sell this Item"), default: 1},
366 {fieldtype: "Check", fieldname: "is_purchase_item_" + i, label:__("We buy this Item")},
367 {fieldtype:"Column Break"},
368 {fieldtype:"Currency", fieldname:"item_price_" + i, label:__("Rate")},
369 {fieldtype:"Attach Image", fieldname:"item_img_" + i, label:__("Attach Image")},
370 ])
371 }
372 slide.fields[1].reqd = 1;
373
374 // dummy data
375 slide.fields.push({fieldtype: "Section Break"});
376 slide.fields.push({fieldtype: "Check", fieldname: "add_sample_data",
377 label: __("Add a few sample records"), "default": 1});
378 },
379 css_class: "two-column"
380 },
381 });
382
383 // Source: https://en.wikipedia.org/wiki/Fiscal_year
384 // default 1st Jan - 31st Dec
385
386 erpnext.wiz.fiscal_years = {
387 "Afghanistan": ["12-20", "12-21"],
388 "Australia": ["07-01", "06-30"],
389 "Bangladesh": ["07-01", "06-30"],
390 "Canada": ["04-01", "03-31"],
391 "Costa Rica": ["10-01", "09-30"],
392 "Egypt": ["07-01", "06-30"],
393 "Hong Kong": ["04-01", "03-31"],
394 "India": ["04-01", "03-31"],
395 "Iran": ["06-23", "06-22"],
396 "Italy": ["07-01", "06-30"],
397 "Myanmar": ["04-01", "03-31"],
398 "New Zealand": ["04-01", "03-31"],
399 "Pakistan": ["07-01", "06-30"],
400 "Singapore": ["04-01", "03-31"],
401 "South Africa": ["03-01", "02-28"],
402 "Thailand": ["10-01", "09-30"],
403 "United Kingdom": ["04-01", "03-31"],
404 };
405};
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530406
407frappe.wiz.on("before_load", function() {
Anand Doshi1ed82832015-11-16 12:58:14 +0530408 load_erpnext_slides();
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530409 frappe.wiz.add_slide(erpnext.wiz.user);
410 frappe.wiz.add_slide(erpnext.wiz.org);
411 frappe.wiz.add_slide(erpnext.wiz.branding);
412 frappe.wiz.add_slide(erpnext.wiz.users);
413 frappe.wiz.add_slide(erpnext.wiz.taxes);
414 frappe.wiz.add_slide(erpnext.wiz.customers);
415 frappe.wiz.add_slide(erpnext.wiz.suppliers);
416 frappe.wiz.add_slide(erpnext.wiz.items);
417 frappe.wiz.welcome_page = "#welcome-to-erpnext";
418});