blob: e8777376297c6a72a366cfd0252f0e8558e8f844 [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 }
8}
9
10$.extend(erpnext.wiz, {
11 region: {
12 title: __("Region"),
13 icon: "icon-flag",
14 help: __("Select your Country, Time Zone and Currency"),
15 fields: [
16 { fieldname: "country", label: __("Country"), reqd:1,
17 fieldtype: "Select" },
18 { fieldname: "timezone", label: __("Time Zone"), reqd:1,
19 fieldtype: "Select" },
20 { fieldname: "currency", label: __("Currency"), reqd:1,
21 fieldtype: "Select" },
22 ],
23
24 onload: function(slide) {
25 frappe.call({
26 method:"frappe.geo.country_info.get_country_timezone_info",
27 callback: function(data) {
28 erpnext.wiz.region.data = data.message;
29 erpnext.wiz.region.setup_fields(slide);
30 erpnext.wiz.region.bind_events(slide);
31 }
32 });
33 },
34 css_class: "single-column",
35 setup_fields: function(slide) {
36 var data = erpnext.wiz.region.data;
37
38 slide.get_input("country").empty()
39 .add_options([""].concat(keys(data.country_info).sort()));
40
41 slide.get_input("currency").empty()
42 .add_options(frappe.utils.unique([""].concat($.map(data.country_info,
43 function(opts, country) { return opts.currency; }))).sort());
44
45 slide.get_input("timezone").empty()
46 .add_options([""].concat(data.all_timezones));
47
48 if (data.default_country) {
49 slide.set_input("country", data.default_country);
50 }
51 },
52
53 bind_events: function(slide) {
54 slide.get_input("country").on("change", function() {
55 var country = slide.get_input("country").val();
56 var $timezone = slide.get_input("timezone");
57 var data = erpnext.wiz.region.data;
58
59 $timezone.empty();
60
61 // add country specific timezones first
62 if(country) {
63 var timezone_list = data.country_info[country].timezones || [];
64 $timezone.add_options(timezone_list.sort());
65 slide.get_field("currency").set_input(data.country_info[country].currency);
66 slide.get_field("currency").$input.trigger("change");
67 }
68
69 // add all timezones at the end, so that user has the option to change it to any timezone
70 $timezone.add_options([""].concat(data.all_timezones));
71
72 slide.get_field("timezone").set_input($timezone.val());
73
74 // temporarily set date format
75 frappe.boot.sysdefaults.date_format = (data.country_info[country].date_format
76 || "dd-mm-yyyy");
77 });
78
79 slide.get_input("currency").on("change", function() {
80 var currency = slide.get_input("currency").val();
81 if (!currency) return;
82 frappe.model.with_doc("Currency", currency, function() {
83 frappe.provide("locals.:Currency." + currency);
84 var currency_doc = frappe.model.get_doc("Currency", currency);
85 var number_format = currency_doc.number_format;
86 if (number_format==="#.###") {
87 number_format = "#.###,##";
88 } else if (number_format==="#,###") {
89 number_format = "#,###.##"
90 }
91
92 frappe.boot.sysdefaults.number_format = number_format;
93 locals[":Currency"][currency] = $.extend({}, currency_doc);
94 });
95 });
96 }
97 },
98
99 user: {
100 title: __("The First User: You"),
101 icon: "icon-user",
102 fields: [
103 {"fieldname": "first_name", "label": __("First Name"), "fieldtype": "Data",
104 reqd:1},
105 {"fieldname": "last_name", "label": __("Last Name"), "fieldtype": "Data"},
106 {"fieldname": "email", "label": __("Email Address"), "fieldtype": "Data",
107 reqd:1, "description": __("You will use it to Login"), "options":"Email"},
108 {"fieldname": "password", "label": __("Password"), "fieldtype": "Password",
109 reqd:1},
110 {fieldtype:"Attach Image", fieldname:"attach_user",
111 label: __("Attach Your Picture")},
112 ],
113 help: __('The first user will become the System Manager (you can change this later).'),
114 onload: function(slide) {
115 if(user!=="Administrator") {
116 slide.form.fields_dict.password.$wrapper.toggle(false);
117 slide.form.fields_dict.email.$wrapper.toggle(false);
118 slide.form.fields_dict.first_name.set_input(frappe.boot.user.first_name);
119 slide.form.fields_dict.last_name.set_input(frappe.boot.user.last_name);
120
121 var user_image = frappe.get_cookie("user_image");
122 if(user_image) {
123 var $attach_user = slide.form.fields_dict.attach_user.$wrapper;
124 $attach_user.find(".missing-image").toggle(false);
125 $attach_user.find("img").attr("src", decodeURIComponent(user_image)).toggle(true);
126 }
127
128 delete slide.form.fields_dict.email;
129 delete slide.form.fields_dict.password;
130 }
131 },
132 css_class: "single-column"
133 },
134
135 org: {
136 title: __("The Organization"),
137 icon: "icon-building",
138 fields: [
139 {fieldname:'company_name', label: __('Company Name'), fieldtype:'Data', reqd:1,
140 placeholder: __('e.g. "My Company LLC"')},
141 {fieldname:'company_abbr', label: __('Company Abbreviation'), fieldtype:'Data',
142 description: __('Max 5 characters'), placeholder: __('e.g. "MC"'), reqd:1},
143 {fieldname:'company_tagline', label: __('What does it do?'), fieldtype:'Data',
144 placeholder:__('e.g. "Build tools for builders"'), reqd:1},
145 {fieldname:'bank_account', label: __('Bank Account'), fieldtype:'Data',
146 placeholder: __('e.g. "XYZ National Bank"'), reqd:1 },
147 {fieldname:'chart_of_accounts', label: __('Chart of Accounts'),
148 options: "", fieldtype: 'Select'},
149
150 // TODO remove this
151 {fieldtype: "Section Break"},
152 {fieldname:'fy_start_date', label:__('Financial Year Start Date'), fieldtype:'Date',
153 description: __('Your financial year begins on'), reqd:1},
154 {fieldname:'fy_end_date', label:__('Financial Year End Date'), fieldtype:'Date',
155 description: __('Your financial year ends on'), reqd:1},
156 ],
157 help: __('The name of your company for which you are setting up this system.'),
158
159 onload: function(slide) {
160 erpnext.wiz.org.load_chart_of_accounts(slide);
161 erpnext.wiz.org.bind_events(slide);
162 erpnext.wiz.org.set_fy_dates(slide);
163 },
164
165 css_class: "single-column",
166
167 set_fy_dates: function(slide) {
168 var country = slide.wiz.get_values().country;
169
170 if(country) {
171 var fy = erpnext.wiz.fiscal_years[country];
172 var current_year = moment(new Date()).year();
173 var next_year = current_year + 1;
174 if(!fy) {
175 fy = ["01-01", "12-31"];
176 next_year = current_year;
177 }
178
179 slide.get_field("fy_start_date").set_input(current_year + "-" + fy[0]);
180 slide.get_field("fy_end_date").set_input(next_year + "-" + fy[1]);
181 }
182
183 },
184
185 load_chart_of_accounts: function(slide) {
186 var country = slide.wiz.get_values().country;
187
188 if(country) {
189 frappe.call({
190 method: "erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts.get_charts_for_country",
191 args: {"country": country},
192 callback: function(r) {
193 if(r.message) {
194 slide.get_input("chart_of_accounts").empty()
195 .add_options(r.message);
196
197 if (r.message.length===1) {
198 var field = slide.get_field("chart_of_accounts");
199 field.set_value(r.message[0]);
200 field.df.hidden = 1;
201 field.refresh();
202 }
203 }
204 }
205 })
206 }
207 },
208
209 bind_events: function(slide) {
210 slide.get_input("company_name").on("change", function() {
211 var parts = slide.get_input("company_name").val().split(" ");
212 var abbr = $.map(parts, function(p) { return p ? p.substr(0,1) : null }).join("");
213 slide.get_field("company_abbr").set_input(abbr.slice(0, 5).toUpperCase());
214 }).val(frappe.boot.sysdefaults.company_name || "").trigger("change");
215
216 slide.get_input("company_abbr").on("change", function() {
217 if(slide.get_input("company_abbr").val().length > 5) {
218 msgprint("Company Abbreviation cannot have more than 5 characters");
219 slide.get_field("company_abbr").set_input("");
220 }
221 });
222
223 // TODO remove this
224 slide.get_input("fy_start_date").on("change", function() {
225 var year_end_date =
226 frappe.datetime.add_days(frappe.datetime.add_months(
227 frappe.datetime.user_to_obj(slide.get_input("fy_start_date").val()), 12), -1);
228 slide.get_input("fy_end_date").val(frappe.datetime.obj_to_user(year_end_date));
229
230 });
231 }
232 },
233
234 branding: {
235 icon: "icon-bookmark",
236 title: __("The Brand"),
237 help: __('Upload your letter head and logo. (you can edit them later).'),
238 fields: [
239 {fieldtype:"Attach Image", fieldname:"attach_letterhead",
240 label: __("Attach Letterhead"),
241 description: __("Keep it web friendly 900px (w) by 100px (h)")
242 },
243 {fieldtype: "Column Break"},
244 {fieldtype:"Attach Image", fieldname:"attach_logo",
245 label:__("Attach Logo"),
246 description: __("100px by 100px")},
247 ],
248
249 css_class: "two-column"
250 },
251
252 users: {
253 icon: "icon-money",
254 "title": __("Add Users"),
255 "help": __("Add users to your organization, other than yourself"),
256 "fields": [],
257 before_load: function(slide) {
258 slide.fields = [];
259 for(var i=1; i<5; i++) {
260 slide.fields = slide.fields.concat([
261 {fieldtype:"Section Break"},
262 {fieldtype:"Data", fieldname:"user_fullname_"+ i,
263 label:__("Full Name")},
264 {fieldtype:"Data", fieldname:"user_email_" + i,
265 label:__("Email ID"), placeholder:__("user@example.com"),
266 options: "Email"},
267 {fieldtype:"Column Break"},
268 {fieldtype: "Check", fieldname: "user_sales_" + i,
269 label:__("Sales"), default: 1},
270 {fieldtype: "Check", fieldname: "user_purchaser_" + i,
271 label:__("Purchaser"), default: 1},
272 {fieldtype: "Check", fieldname: "user_accountant_" + i,
273 label:__("Accountant"), default: 1},
274 ]);
275 }
276 },
277 css_class: "two-column"
278 },
279
280 taxes: {
281 icon: "icon-money",
282 "title": __("Add Taxes"),
283 "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."),
284 "fields": [],
285 before_load: function(slide) {
286 slide.fields = [];
287 for(var i=1; i<4; i++) {
288 slide.fields = slide.fields.concat([
289 {fieldtype:"Section Break"},
290 {fieldtype:"Data", fieldname:"tax_"+ i, label:__("Tax") + " " + i,
291 placeholder:__("e.g. VAT") + " " + i},
292 {fieldtype:"Column Break"},
293 {fieldtype:"Float", fieldname:"tax_rate_" + i, label:__("Rate (%)"), placeholder:__("e.g. 5")},
294 ]);
295 }
296 },
297 css_class: "two-column"
298 },
299
300 customers: {
301 icon: "icon-group",
302 "title": __("Your Customers"),
303 "help": __("List a few of your customers. They could be organizations or individuals."),
304 "fields": [],
305 before_load: function(slide) {
306 slide.fields = [];
307 for(var i=1; i<6; i++) {
308 slide.fields = slide.fields.concat([
309 {fieldtype:"Section Break"},
310 {fieldtype:"Data", fieldname:"customer_" + i, label:__("Customer") + " " + i,
311 placeholder:__("Customer Name")},
312 {fieldtype:"Column Break"},
313 {fieldtype:"Data", fieldname:"customer_contact_" + i,
314 label:__("Contact Name") + " " + i, placeholder:__("Contact Name")}
315 ])
316 }
317 slide.fields[1].reqd = 1;
318 },
319 css_class: "two-column"
320 },
321
322 suppliers: {
323 icon: "icon-group",
324 "title": __("Your Suppliers"),
325 "help": __("List a few of your suppliers. They could be organizations or individuals."),
326 "fields": [],
327 before_load: function(slide) {
328 slide.fields = [];
329 for(var i=1; i<6; i++) {
330 slide.fields = slide.fields.concat([
331 {fieldtype:"Section Break"},
332 {fieldtype:"Data", fieldname:"supplier_" + i, label:__("Supplier")+" " + i,
333 placeholder:__("Supplier Name")},
334 {fieldtype:"Column Break"},
335 {fieldtype:"Data", fieldname:"supplier_contact_" + i,
336 label:__("Contact Name") + " " + i, placeholder:__("Contact Name")},
337 ])
338 }
339 slide.fields[1].reqd = 1;
340 },
341 css_class: "two-column"
342 },
343
344 items: {
345 icon: "icon-barcode",
346 "title": __("Your Products or Services"),
347 "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."),
348 "fields": [],
349 before_load: function(slide) {
350 slide.fields = [];
351 for(var i=1; i<6; i++) {
352 slide.fields = slide.fields.concat([
353 {fieldtype:"Section Break", show_section_border: true},
354 {fieldtype:"Data", fieldname:"item_" + i, label:__("Item") + " " + i,
355 placeholder:__("A Product or Service")},
356 {fieldtype:"Select", label:__("Group"), fieldname:"item_group_" + i,
357 options:[__("Products"), __("Services"),
358 __("Raw Material"), __("Consumable"), __("Sub Assemblies")],
359 "default": __("Products")},
360 {fieldtype:"Select", fieldname:"item_uom_" + i, label:__("UOM"),
361 options:[__("Unit"), __("Nos"), __("Box"), __("Pair"), __("Kg"), __("Set"),
362 __("Hour"), __("Minute")],
363 "default": __("Unit")},
364 {fieldtype: "Check", fieldname: "is_sales_item_" + i, label:__("We sell this Item"), default: 1},
365 {fieldtype: "Check", fieldname: "is_purchase_item_" + i, label:__("We buy this Item")},
366 {fieldtype:"Column Break"},
367 {fieldtype:"Currency", fieldname:"item_price_" + i, label:__("Rate")},
368 {fieldtype:"Attach Image", fieldname:"item_img_" + i, label:__("Attach Image")},
369 ])
370 }
371 slide.fields[1].reqd = 1;
372
373 // dummy data
374 slide.fields.push({fieldtype: "Section Break"});
375 slide.fields.push({fieldtype: "Check", fieldname: "add_sample_data",
376 label: __("Add a few sample records"), "default": 1});
377 },
378 css_class: "two-column"
379 },
380});
381
382// Source: https://en.wikipedia.org/wiki/Fiscal_year
383// default 1st Jan - 31st Dec
384
385erpnext.wiz.fiscal_years = {
386 "Afghanistan": ["12-20", "12-21"],
387 "Australia": ["07-01", "06-30"],
388 "Bangladesh": ["07-01", "06-30"],
389 "Canada": ["04-01", "03-31"],
390 "Costa Rica": ["10-01", "09-30"],
391 "Egypt": ["07-01", "06-30"],
392 "Hong Kong": ["04-01", "03-31"],
393 "India": ["04-01", "03-31"],
394 "Iran": ["06-23", "06-22"],
395 "Italy": ["07-01", "06-30"],
396 "Myanmar": ["04-01", "03-31"],
397 "New Zealand": ["04-01", "03-31"],
398 "Pakistan": ["07-01", "06-30"],
399 "Singapore": ["04-01", "03-31"],
400 "South Africa": ["03-01", "02-28"],
401 "Thailand": ["10-01", "09-30"],
402 "United Kingdom": ["04-01", "03-31"],
403}
404
405frappe.wiz.on("before_load", function() {
406 frappe.wiz.add_slide(erpnext.wiz.user);
407 frappe.wiz.add_slide(erpnext.wiz.org);
408 frappe.wiz.add_slide(erpnext.wiz.branding);
409 frappe.wiz.add_slide(erpnext.wiz.users);
410 frappe.wiz.add_slide(erpnext.wiz.taxes);
411 frappe.wiz.add_slide(erpnext.wiz.customers);
412 frappe.wiz.add_slide(erpnext.wiz.suppliers);
413 frappe.wiz.add_slide(erpnext.wiz.items);
414 frappe.wiz.welcome_page = "#welcome-to-erpnext";
415});