blob: 9c6cd03058f9685a6fc98ba2d0f6cc09dc5589e8 [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 user: {
13 title: __("The First User: You"),
14 icon: "icon-user",
15 fields: [
16 {"fieldname": "first_name", "label": __("First Name"), "fieldtype": "Data",
17 reqd:1},
18 {"fieldname": "last_name", "label": __("Last Name"), "fieldtype": "Data"},
19 {"fieldname": "email", "label": __("Email Address"), "fieldtype": "Data",
20 reqd:1, "description": __("You will use it to Login"), "options":"Email"},
21 {"fieldname": "password", "label": __("Password"), "fieldtype": "Password",
22 reqd:1},
23 {fieldtype:"Attach Image", fieldname:"attach_user",
Anand Doshi2af44ff2015-12-09 17:28:51 +053024 label: __("Attach Your Picture"), is_private: 0},
Anand Doshi1ed82832015-11-16 12:58:14 +053025 ],
26 help: __('The first user will become the System Manager (you can change this later).'),
27 onload: function(slide) {
28 if(user!=="Administrator") {
29 slide.form.fields_dict.password.$wrapper.toggle(false);
30 slide.form.fields_dict.email.$wrapper.toggle(false);
31 slide.form.fields_dict.first_name.set_input(frappe.boot.user.first_name);
32 slide.form.fields_dict.last_name.set_input(frappe.boot.user.last_name);
Rushabh Mehta37b4d752015-11-09 16:53:11 +053033
Anand Doshi1ed82832015-11-16 12:58:14 +053034 var user_image = frappe.get_cookie("user_image");
35 if(user_image) {
36 var $attach_user = slide.form.fields_dict.attach_user.$wrapper;
37 $attach_user.find(".missing-image").toggle(false);
38 $attach_user.find("img").attr("src", decodeURIComponent(user_image)).toggle(true);
39 }
Rushabh Mehta37b4d752015-11-09 16:53:11 +053040
Anand Doshi1ed82832015-11-16 12:58:14 +053041 delete slide.form.fields_dict.email;
42 delete slide.form.fields_dict.password;
43 }
44 },
45 css_class: "single-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +053046 },
47
Anand Doshi1ed82832015-11-16 12:58:14 +053048 org: {
49 title: __("The Organization"),
50 icon: "icon-building",
51 fields: [
52 {fieldname:'company_name', label: __('Company Name'), fieldtype:'Data', reqd:1,
53 placeholder: __('e.g. "My Company LLC"')},
54 {fieldname:'company_abbr', label: __('Company Abbreviation'), fieldtype:'Data',
55 description: __('Max 5 characters'), placeholder: __('e.g. "MC"'), reqd:1},
56 {fieldname:'company_tagline', label: __('What does it do?'), fieldtype:'Data',
57 placeholder:__('e.g. "Build tools for builders"'), reqd:1},
58 {fieldname:'bank_account', label: __('Bank Account'), fieldtype:'Data',
59 placeholder: __('e.g. "XYZ National Bank"'), reqd:1 },
60 {fieldname:'chart_of_accounts', label: __('Chart of Accounts'),
61 options: "", fieldtype: 'Select'},
Rushabh Mehta37b4d752015-11-09 16:53:11 +053062
Anand Doshi1ed82832015-11-16 12:58:14 +053063 // TODO remove this
64 {fieldtype: "Section Break"},
65 {fieldname:'fy_start_date', label:__('Financial Year Start Date'), fieldtype:'Date',
66 description: __('Your financial year begins on'), reqd:1},
67 {fieldname:'fy_end_date', label:__('Financial Year End Date'), fieldtype:'Date',
68 description: __('Your financial year ends on'), reqd:1},
69 ],
70 help: __('The name of your company for which you are setting up this system.'),
Rushabh Mehta37b4d752015-11-09 16:53:11 +053071
Anand Doshi1ed82832015-11-16 12:58:14 +053072 onload: function(slide) {
73 erpnext.wiz.org.load_chart_of_accounts(slide);
74 erpnext.wiz.org.bind_events(slide);
75 erpnext.wiz.org.set_fy_dates(slide);
76 },
77
Anand Doshi5c3469a2015-11-24 17:06:54 +053078 validate: function() {
79 // validate fiscal year start and end dates
80 if (this.values.fy_start_date=='Invalid date' || this.values.fy_end_date=='Invalid date') {
81 msgprint(__("Please enter valid Financial Year Start and End Dates"));
82 return false;
83 }
84
85 if ((this.values.company_name || "").toLowerCase() == "company") {
86 msgprint(__("Company Name cannot be Company"));
87 return false;
88 }
89
90 return true;
91 },
92
Anand Doshi1ed82832015-11-16 12:58:14 +053093 css_class: "single-column",
94
95 set_fy_dates: function(slide) {
96 var country = slide.wiz.get_values().country;
97
98 if(country) {
99 var fy = erpnext.wiz.fiscal_years[country];
100 var current_year = moment(new Date()).year();
101 var next_year = current_year + 1;
102 if(!fy) {
103 fy = ["01-01", "12-31"];
104 next_year = current_year;
105 }
106
107 slide.get_field("fy_start_date").set_input(current_year + "-" + fy[0]);
108 slide.get_field("fy_end_date").set_input(next_year + "-" + fy[1]);
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530109 }
110
Anand Doshi1ed82832015-11-16 12:58:14 +0530111 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530112
Anand Doshi1ed82832015-11-16 12:58:14 +0530113 load_chart_of_accounts: function(slide) {
114 var country = slide.wiz.get_values().country;
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530115
Anand Doshi1ed82832015-11-16 12:58:14 +0530116 if(country) {
117 frappe.call({
118 method: "erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts.get_charts_for_country",
119 args: {"country": country},
120 callback: function(r) {
121 if(r.message) {
122 slide.get_input("chart_of_accounts").empty()
123 .add_options(r.message);
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530124
Anand Doshi1ed82832015-11-16 12:58:14 +0530125 if (r.message.length===1) {
126 var field = slide.get_field("chart_of_accounts");
127 field.set_value(r.message[0]);
128 field.df.hidden = 1;
129 field.refresh();
130 }
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530131 }
132 }
Anand Doshi1ed82832015-11-16 12:58:14 +0530133 })
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530134 }
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530135 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530136
Anand Doshi1ed82832015-11-16 12:58:14 +0530137 bind_events: function(slide) {
138 slide.get_input("company_name").on("change", function() {
139 var parts = slide.get_input("company_name").val().split(" ");
140 var abbr = $.map(parts, function(p) { return p ? p.substr(0,1) : null }).join("");
141 slide.get_field("company_abbr").set_input(abbr.slice(0, 5).toUpperCase());
142 }).val(frappe.boot.sysdefaults.company_name || "").trigger("change");
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530143
Anand Doshi1ed82832015-11-16 12:58:14 +0530144 slide.get_input("company_abbr").on("change", function() {
145 if(slide.get_input("company_abbr").val().length > 5) {
146 msgprint("Company Abbreviation cannot have more than 5 characters");
147 slide.get_field("company_abbr").set_input("");
148 }
149 });
150
151 // TODO remove this
152 slide.get_input("fy_start_date").on("change", function() {
153 var year_end_date =
154 frappe.datetime.add_days(frappe.datetime.add_months(
155 frappe.datetime.user_to_obj(slide.get_input("fy_start_date").val()), 12), -1);
156 slide.get_input("fy_end_date").val(frappe.datetime.obj_to_user(year_end_date));
157
158 });
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530159 }
160 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530161
Anand Doshi1ed82832015-11-16 12:58:14 +0530162 branding: {
163 icon: "icon-bookmark",
164 title: __("The Brand"),
165 help: __('Upload your letter head and logo. (you can edit them later).'),
166 fields: [
167 {fieldtype:"Attach Image", fieldname:"attach_letterhead",
168 label: __("Attach Letterhead"),
Anand Doshi2af44ff2015-12-09 17:28:51 +0530169 description: __("Keep it web friendly 900px (w) by 100px (h)"),
170 is_private: 0
Anand Doshi1ed82832015-11-16 12:58:14 +0530171 },
172 {fieldtype: "Column Break"},
173 {fieldtype:"Attach Image", fieldname:"attach_logo",
174 label:__("Attach Logo"),
Anand Doshi2af44ff2015-12-09 17:28:51 +0530175 description: __("100px by 100px"),
176 is_private: 0
177 },
Anand Doshi1ed82832015-11-16 12:58:14 +0530178 ],
179
180 css_class: "two-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530181 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530182
Anand Doshi1ed82832015-11-16 12:58:14 +0530183 users: {
184 icon: "icon-money",
185 "title": __("Add Users"),
186 "help": __("Add users to your organization, other than yourself"),
187 "fields": [],
188 before_load: function(slide) {
189 slide.fields = [];
190 for(var i=1; i<5; i++) {
191 slide.fields = slide.fields.concat([
192 {fieldtype:"Section Break"},
193 {fieldtype:"Data", fieldname:"user_fullname_"+ i,
194 label:__("Full Name")},
195 {fieldtype:"Data", fieldname:"user_email_" + i,
196 label:__("Email ID"), placeholder:__("user@example.com"),
197 options: "Email"},
198 {fieldtype:"Column Break"},
199 {fieldtype: "Check", fieldname: "user_sales_" + i,
200 label:__("Sales"), default: 1},
201 {fieldtype: "Check", fieldname: "user_purchaser_" + i,
202 label:__("Purchaser"), default: 1},
203 {fieldtype: "Check", fieldname: "user_accountant_" + i,
204 label:__("Accountant"), default: 1},
205 ]);
206 }
207 },
208 css_class: "two-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530209 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530210
Anand Doshi1ed82832015-11-16 12:58:14 +0530211 taxes: {
212 icon: "icon-money",
213 "title": __("Add Taxes"),
214 "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."),
215 "fields": [],
216 before_load: function(slide) {
217 slide.fields = [];
218 for(var i=1; i<4; i++) {
219 slide.fields = slide.fields.concat([
220 {fieldtype:"Section Break"},
221 {fieldtype:"Data", fieldname:"tax_"+ i, label:__("Tax") + " " + i,
222 placeholder:__("e.g. VAT") + " " + i},
223 {fieldtype:"Column Break"},
224 {fieldtype:"Float", fieldname:"tax_rate_" + i, label:__("Rate (%)"), placeholder:__("e.g. 5")},
225 ]);
226 }
227 },
228 css_class: "two-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530229 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530230
Anand Doshi1ed82832015-11-16 12:58:14 +0530231 customers: {
232 icon: "icon-group",
233 "title": __("Your Customers"),
234 "help": __("List a few of your customers. They could be organizations or individuals."),
235 "fields": [],
236 before_load: function(slide) {
237 slide.fields = [];
238 for(var i=1; i<6; i++) {
239 slide.fields = slide.fields.concat([
240 {fieldtype:"Section Break"},
241 {fieldtype:"Data", fieldname:"customer_" + i, label:__("Customer") + " " + i,
242 placeholder:__("Customer Name")},
243 {fieldtype:"Column Break"},
244 {fieldtype:"Data", fieldname:"customer_contact_" + i,
245 label:__("Contact Name") + " " + i, placeholder:__("Contact Name")}
246 ])
247 }
248 slide.fields[1].reqd = 1;
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 suppliers: {
254 icon: "icon-group",
255 "title": __("Your Suppliers"),
256 "help": __("List a few of your suppliers. They could be organizations or individuals."),
257 "fields": [],
258 before_load: function(slide) {
259 slide.fields = [];
260 for(var i=1; i<6; i++) {
261 slide.fields = slide.fields.concat([
262 {fieldtype:"Section Break"},
263 {fieldtype:"Data", fieldname:"supplier_" + i, label:__("Supplier")+" " + i,
264 placeholder:__("Supplier Name")},
265 {fieldtype:"Column Break"},
266 {fieldtype:"Data", fieldname:"supplier_contact_" + i,
267 label:__("Contact Name") + " " + i, placeholder:__("Contact Name")},
268 ])
269 }
270 slide.fields[1].reqd = 1;
271 },
272 css_class: "two-column"
273 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530274
Anand Doshi1ed82832015-11-16 12:58:14 +0530275 items: {
276 icon: "icon-barcode",
277 "title": __("Your Products or Services"),
278 "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."),
279 "fields": [],
280 before_load: function(slide) {
281 slide.fields = [];
282 for(var i=1; i<6; i++) {
283 slide.fields = slide.fields.concat([
284 {fieldtype:"Section Break", show_section_border: true},
285 {fieldtype:"Data", fieldname:"item_" + i, label:__("Item") + " " + i,
286 placeholder:__("A Product or Service")},
287 {fieldtype:"Select", label:__("Group"), fieldname:"item_group_" + i,
288 options:[__("Products"), __("Services"),
289 __("Raw Material"), __("Consumable"), __("Sub Assemblies")],
290 "default": __("Products")},
291 {fieldtype:"Select", fieldname:"item_uom_" + i, label:__("UOM"),
292 options:[__("Unit"), __("Nos"), __("Box"), __("Pair"), __("Kg"), __("Set"),
293 __("Hour"), __("Minute")],
294 "default": __("Unit")},
295 {fieldtype: "Check", fieldname: "is_sales_item_" + i, label:__("We sell this Item"), default: 1},
296 {fieldtype: "Check", fieldname: "is_purchase_item_" + i, label:__("We buy this Item")},
297 {fieldtype:"Column Break"},
298 {fieldtype:"Currency", fieldname:"item_price_" + i, label:__("Rate")},
Anand Doshi2af44ff2015-12-09 17:28:51 +0530299 {fieldtype:"Attach Image", fieldname:"item_img_" + i, label:__("Attach Image"), is_private: 0},
Anand Doshi1ed82832015-11-16 12:58:14 +0530300 ])
301 }
302 slide.fields[1].reqd = 1;
303
304 // dummy data
305 slide.fields.push({fieldtype: "Section Break"});
306 slide.fields.push({fieldtype: "Check", fieldname: "add_sample_data",
307 label: __("Add a few sample records"), "default": 1});
308 },
309 css_class: "two-column"
310 },
311 });
312
313 // Source: https://en.wikipedia.org/wiki/Fiscal_year
314 // default 1st Jan - 31st Dec
315
316 erpnext.wiz.fiscal_years = {
317 "Afghanistan": ["12-20", "12-21"],
318 "Australia": ["07-01", "06-30"],
319 "Bangladesh": ["07-01", "06-30"],
320 "Canada": ["04-01", "03-31"],
321 "Costa Rica": ["10-01", "09-30"],
322 "Egypt": ["07-01", "06-30"],
323 "Hong Kong": ["04-01", "03-31"],
324 "India": ["04-01", "03-31"],
325 "Iran": ["06-23", "06-22"],
326 "Italy": ["07-01", "06-30"],
327 "Myanmar": ["04-01", "03-31"],
328 "New Zealand": ["04-01", "03-31"],
329 "Pakistan": ["07-01", "06-30"],
330 "Singapore": ["04-01", "03-31"],
331 "South Africa": ["03-01", "02-28"],
332 "Thailand": ["10-01", "09-30"],
333 "United Kingdom": ["04-01", "03-31"],
334 };
335};
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530336
337frappe.wiz.on("before_load", function() {
Anand Doshi1ed82832015-11-16 12:58:14 +0530338 load_erpnext_slides();
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530339 frappe.wiz.add_slide(erpnext.wiz.user);
340 frappe.wiz.add_slide(erpnext.wiz.org);
341 frappe.wiz.add_slide(erpnext.wiz.branding);
342 frappe.wiz.add_slide(erpnext.wiz.users);
343 frappe.wiz.add_slide(erpnext.wiz.taxes);
344 frappe.wiz.add_slide(erpnext.wiz.customers);
345 frappe.wiz.add_slide(erpnext.wiz.suppliers);
346 frappe.wiz.add_slide(erpnext.wiz.items);
347 frappe.wiz.welcome_page = "#welcome-to-erpnext";
348});