blob: 0228fa193977194677372a965faf55ab1af59961 [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 org: {
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +053013 app_name: "erpnext",
Anand Doshi1ed82832015-11-16 12:58:14 +053014 title: __("The Organization"),
15 icon: "icon-building",
16 fields: [
17 {fieldname:'company_name', label: __('Company Name'), fieldtype:'Data', reqd:1,
18 placeholder: __('e.g. "My Company LLC"')},
19 {fieldname:'company_abbr', label: __('Company Abbreviation'), fieldtype:'Data',
20 description: __('Max 5 characters'), placeholder: __('e.g. "MC"'), reqd:1},
21 {fieldname:'company_tagline', label: __('What does it do?'), fieldtype:'Data',
22 placeholder:__('e.g. "Build tools for builders"'), reqd:1},
Umair Sayyed9a0ff292016-06-14 12:25:10 +053023 {fieldname:'bank_account', label: __('Bank Name'), fieldtype:'Data',
Anand Doshi1ed82832015-11-16 12:58:14 +053024 placeholder: __('e.g. "XYZ National Bank"'), reqd:1 },
Neil Trini Lasrado342895c2016-03-04 15:41:27 +053025 {fieldname:'domain', label: __('Domain'), fieldtype:'Select',
Neil Trini Lasrado1b03e0a2016-03-07 16:57:05 +053026 options: [
Anand Doshi01792422016-03-09 16:31:53 +053027 {"label": __("Distribution"), "value": "Distribution"},
28 {"label": __("Manufacturing"), "value": "Manufacturing"},
29 {"label": __("Retail"), "value": "Retail"},
30 {"label": __("Services"), "value": "Services"},
Anand Doshi01792422016-03-09 16:31:53 +053031 {"label": __("Other"), "value": "Other"},
Neil Trini Lasrado1b03e0a2016-03-07 16:57:05 +053032 ], reqd:1},
Anand Doshi1ed82832015-11-16 12:58:14 +053033 {fieldname:'chart_of_accounts', label: __('Chart of Accounts'),
34 options: "", fieldtype: 'Select'},
Rushabh Mehta37b4d752015-11-09 16:53:11 +053035
Anand Doshi1ed82832015-11-16 12:58:14 +053036 // TODO remove this
37 {fieldtype: "Section Break"},
38 {fieldname:'fy_start_date', label:__('Financial Year Start Date'), fieldtype:'Date',
39 description: __('Your financial year begins on'), reqd:1},
40 {fieldname:'fy_end_date', label:__('Financial Year End Date'), fieldtype:'Date',
41 description: __('Your financial year ends on'), reqd:1},
42 ],
43 help: __('The name of your company for which you are setting up this system.'),
Rushabh Mehta37b4d752015-11-09 16:53:11 +053044
Anand Doshi1ed82832015-11-16 12:58:14 +053045 onload: function(slide) {
46 erpnext.wiz.org.load_chart_of_accounts(slide);
47 erpnext.wiz.org.bind_events(slide);
48 erpnext.wiz.org.set_fy_dates(slide);
49 },
50
Anand Doshi5c3469a2015-11-24 17:06:54 +053051 validate: function() {
52 // validate fiscal year start and end dates
53 if (this.values.fy_start_date=='Invalid date' || this.values.fy_end_date=='Invalid date') {
54 msgprint(__("Please enter valid Financial Year Start and End Dates"));
55 return false;
56 }
57
58 if ((this.values.company_name || "").toLowerCase() == "company") {
59 msgprint(__("Company Name cannot be Company"));
60 return false;
61 }
62
63 return true;
64 },
65
Anand Doshi1ed82832015-11-16 12:58:14 +053066 css_class: "single-column",
67
68 set_fy_dates: function(slide) {
69 var country = slide.wiz.get_values().country;
70
71 if(country) {
72 var fy = erpnext.wiz.fiscal_years[country];
73 var current_year = moment(new Date()).year();
74 var next_year = current_year + 1;
75 if(!fy) {
76 fy = ["01-01", "12-31"];
77 next_year = current_year;
78 }
79
80 slide.get_field("fy_start_date").set_input(current_year + "-" + fy[0]);
81 slide.get_field("fy_end_date").set_input(next_year + "-" + fy[1]);
Rushabh Mehta37b4d752015-11-09 16:53:11 +053082 }
83
Anand Doshi1ed82832015-11-16 12:58:14 +053084 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +053085
Anand Doshi1ed82832015-11-16 12:58:14 +053086 load_chart_of_accounts: function(slide) {
87 var country = slide.wiz.get_values().country;
Rushabh Mehta37b4d752015-11-09 16:53:11 +053088
Anand Doshi1ed82832015-11-16 12:58:14 +053089 if(country) {
90 frappe.call({
91 method: "erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts.get_charts_for_country",
92 args: {"country": country},
93 callback: function(r) {
94 if(r.message) {
95 slide.get_input("chart_of_accounts").empty()
96 .add_options(r.message);
Rushabh Mehta37b4d752015-11-09 16:53:11 +053097
Anand Doshi1ed82832015-11-16 12:58:14 +053098 if (r.message.length===1) {
99 var field = slide.get_field("chart_of_accounts");
100 field.set_value(r.message[0]);
101 field.df.hidden = 1;
102 field.refresh();
103 }
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530104 }
105 }
Anand Doshi1ed82832015-11-16 12:58:14 +0530106 })
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530107 }
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530108 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530109
Anand Doshi1ed82832015-11-16 12:58:14 +0530110 bind_events: function(slide) {
111 slide.get_input("company_name").on("change", function() {
112 var parts = slide.get_input("company_name").val().split(" ");
113 var abbr = $.map(parts, function(p) { return p ? p.substr(0,1) : null }).join("");
114 slide.get_field("company_abbr").set_input(abbr.slice(0, 5).toUpperCase());
115 }).val(frappe.boot.sysdefaults.company_name || "").trigger("change");
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530116
Anand Doshi1ed82832015-11-16 12:58:14 +0530117 slide.get_input("company_abbr").on("change", function() {
118 if(slide.get_input("company_abbr").val().length > 5) {
119 msgprint("Company Abbreviation cannot have more than 5 characters");
120 slide.get_field("company_abbr").set_input("");
121 }
122 });
123
124 // TODO remove this
125 slide.get_input("fy_start_date").on("change", function() {
126 var year_end_date =
127 frappe.datetime.add_days(frappe.datetime.add_months(
128 frappe.datetime.user_to_obj(slide.get_input("fy_start_date").val()), 12), -1);
129 slide.get_input("fy_end_date").val(frappe.datetime.obj_to_user(year_end_date));
130
131 });
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530132 }
133 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530134
Anand Doshi1ed82832015-11-16 12:58:14 +0530135 branding: {
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530136 app_name: "erpnext",
Anand Doshi1ed82832015-11-16 12:58:14 +0530137 icon: "icon-bookmark",
138 title: __("The Brand"),
139 help: __('Upload your letter head and logo. (you can edit them later).'),
140 fields: [
141 {fieldtype:"Attach Image", fieldname:"attach_letterhead",
142 label: __("Attach Letterhead"),
Anand Doshi2af44ff2015-12-09 17:28:51 +0530143 description: __("Keep it web friendly 900px (w) by 100px (h)"),
144 is_private: 0
Anand Doshi1ed82832015-11-16 12:58:14 +0530145 },
146 {fieldtype: "Column Break"},
147 {fieldtype:"Attach Image", fieldname:"attach_logo",
148 label:__("Attach Logo"),
Anand Doshi2af44ff2015-12-09 17:28:51 +0530149 description: __("100px by 100px"),
150 is_private: 0
151 },
Anand Doshi1ed82832015-11-16 12:58:14 +0530152 ],
153
154 css_class: "two-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530155 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530156
Anand Doshi1ed82832015-11-16 12:58:14 +0530157 users: {
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530158 app_name: "erpnext",
Anand Doshi1ed82832015-11-16 12:58:14 +0530159 icon: "icon-money",
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530160 title: __("Add Users"),
161 help: __("Add users to your organization, other than yourself"),
162 fields: [],
Anand Doshi1ed82832015-11-16 12:58:14 +0530163 before_load: function(slide) {
164 slide.fields = [];
165 for(var i=1; i<5; i++) {
166 slide.fields = slide.fields.concat([
167 {fieldtype:"Section Break"},
168 {fieldtype:"Data", fieldname:"user_fullname_"+ i,
169 label:__("Full Name")},
170 {fieldtype:"Data", fieldname:"user_email_" + i,
171 label:__("Email ID"), placeholder:__("user@example.com"),
172 options: "Email"},
173 {fieldtype:"Column Break"},
174 {fieldtype: "Check", fieldname: "user_sales_" + i,
175 label:__("Sales"), default: 1},
176 {fieldtype: "Check", fieldname: "user_purchaser_" + i,
177 label:__("Purchaser"), default: 1},
178 {fieldtype: "Check", fieldname: "user_accountant_" + i,
179 label:__("Accountant"), default: 1},
180 ]);
181 }
182 },
183 css_class: "two-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530184 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530185
Anand Doshi1ed82832015-11-16 12:58:14 +0530186 taxes: {
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530187 app_name: "erpnext",
Anand Doshi1ed82832015-11-16 12:58:14 +0530188 icon: "icon-money",
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530189 title: __("Add Taxes"),
190 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."),
Anand Doshi1ed82832015-11-16 12:58:14 +0530191 "fields": [],
192 before_load: function(slide) {
193 slide.fields = [];
194 for(var i=1; i<4; i++) {
195 slide.fields = slide.fields.concat([
196 {fieldtype:"Section Break"},
197 {fieldtype:"Data", fieldname:"tax_"+ i, label:__("Tax") + " " + i,
198 placeholder:__("e.g. VAT") + " " + i},
199 {fieldtype:"Column Break"},
200 {fieldtype:"Float", fieldname:"tax_rate_" + i, label:__("Rate (%)"), placeholder:__("e.g. 5")},
201 ]);
202 }
203 },
204 css_class: "two-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530205 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530206
Anand Doshi1ed82832015-11-16 12:58:14 +0530207 customers: {
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530208 app_name: "erpnext",
Anand Doshi1ed82832015-11-16 12:58:14 +0530209 icon: "icon-group",
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530210 title: __("Your Customers"),
211 help: __("List a few of your customers. They could be organizations or individuals."),
212 fields: [],
Anand Doshi1ed82832015-11-16 12:58:14 +0530213 before_load: function(slide) {
214 slide.fields = [];
215 for(var i=1; i<6; i++) {
216 slide.fields = slide.fields.concat([
217 {fieldtype:"Section Break"},
218 {fieldtype:"Data", fieldname:"customer_" + i, label:__("Customer") + " " + i,
219 placeholder:__("Customer Name")},
220 {fieldtype:"Column Break"},
221 {fieldtype:"Data", fieldname:"customer_contact_" + i,
222 label:__("Contact Name") + " " + i, placeholder:__("Contact Name")}
223 ])
224 }
225 slide.fields[1].reqd = 1;
226 },
227 css_class: "two-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530228 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530229
Anand Doshi1ed82832015-11-16 12:58:14 +0530230 suppliers: {
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530231 app_name: "erpnext",
Anand Doshi1ed82832015-11-16 12:58:14 +0530232 icon: "icon-group",
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530233 title: __("Your Suppliers"),
234 help: __("List a few of your suppliers. They could be organizations or individuals."),
235 fields: [],
Anand Doshi1ed82832015-11-16 12:58:14 +0530236 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:"supplier_" + i, label:__("Supplier")+" " + i,
242 placeholder:__("Supplier Name")},
243 {fieldtype:"Column Break"},
244 {fieldtype:"Data", fieldname:"supplier_contact_" + i,
245 label:__("Contact Name") + " " + i, placeholder:__("Contact Name")},
246 ])
247 }
248 slide.fields[1].reqd = 1;
249 },
250 css_class: "two-column"
251 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530252
Anand Doshi1ed82832015-11-16 12:58:14 +0530253 items: {
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530254 app_name: "erpnext",
Anand Doshi1ed82832015-11-16 12:58:14 +0530255 icon: "icon-barcode",
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530256 title: __("Your Products or Services"),
257 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."),
258 fields: [],
Anand Doshi1ed82832015-11-16 12:58:14 +0530259 before_load: function(slide) {
260 slide.fields = [];
261 for(var i=1; i<6; i++) {
262 slide.fields = slide.fields.concat([
263 {fieldtype:"Section Break", show_section_border: true},
264 {fieldtype:"Data", fieldname:"item_" + i, label:__("Item") + " " + i,
265 placeholder:__("A Product or Service")},
266 {fieldtype:"Select", label:__("Group"), fieldname:"item_group_" + i,
267 options:[__("Products"), __("Services"),
268 __("Raw Material"), __("Consumable"), __("Sub Assemblies")],
269 "default": __("Products")},
270 {fieldtype:"Select", fieldname:"item_uom_" + i, label:__("UOM"),
271 options:[__("Unit"), __("Nos"), __("Box"), __("Pair"), __("Kg"), __("Set"),
Rushabh Mehtae0686b32016-06-10 12:34:41 +0530272 __("Hour"), __("Minute"), __("Litre"), __("Meter"), __("Gram")],
Anand Doshi1ed82832015-11-16 12:58:14 +0530273 "default": __("Unit")},
274 {fieldtype: "Check", fieldname: "is_sales_item_" + i, label:__("We sell this Item"), default: 1},
275 {fieldtype: "Check", fieldname: "is_purchase_item_" + i, label:__("We buy this Item")},
276 {fieldtype:"Column Break"},
277 {fieldtype:"Currency", fieldname:"item_price_" + i, label:__("Rate")},
Anand Doshi2af44ff2015-12-09 17:28:51 +0530278 {fieldtype:"Attach Image", fieldname:"item_img_" + i, label:__("Attach Image"), is_private: 0},
Anand Doshi1ed82832015-11-16 12:58:14 +0530279 ])
280 }
281 slide.fields[1].reqd = 1;
282
283 // dummy data
284 slide.fields.push({fieldtype: "Section Break"});
285 slide.fields.push({fieldtype: "Check", fieldname: "add_sample_data",
286 label: __("Add a few sample records"), "default": 1});
287 },
288 css_class: "two-column"
289 },
290 });
291
292 // Source: https://en.wikipedia.org/wiki/Fiscal_year
293 // default 1st Jan - 31st Dec
294
295 erpnext.wiz.fiscal_years = {
296 "Afghanistan": ["12-20", "12-21"],
297 "Australia": ["07-01", "06-30"],
298 "Bangladesh": ["07-01", "06-30"],
299 "Canada": ["04-01", "03-31"],
300 "Costa Rica": ["10-01", "09-30"],
301 "Egypt": ["07-01", "06-30"],
302 "Hong Kong": ["04-01", "03-31"],
303 "India": ["04-01", "03-31"],
304 "Iran": ["06-23", "06-22"],
305 "Italy": ["07-01", "06-30"],
306 "Myanmar": ["04-01", "03-31"],
307 "New Zealand": ["04-01", "03-31"],
308 "Pakistan": ["07-01", "06-30"],
309 "Singapore": ["04-01", "03-31"],
310 "South Africa": ["03-01", "02-28"],
311 "Thailand": ["10-01", "09-30"],
312 "United Kingdom": ["04-01", "03-31"],
313 };
314};
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530315
316frappe.wiz.on("before_load", function() {
Anand Doshi1ed82832015-11-16 12:58:14 +0530317 load_erpnext_slides();
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530318 frappe.wiz.add_slide(erpnext.wiz.org);
319 frappe.wiz.add_slide(erpnext.wiz.branding);
Anand Doshi31771382016-07-05 21:34:21 +0530320
321 if (!(frappe.boot.limits && frappe.boot.limits.users===1)) {
322 frappe.wiz.add_slide(erpnext.wiz.users);
323 }
324
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530325 frappe.wiz.add_slide(erpnext.wiz.taxes);
326 frappe.wiz.add_slide(erpnext.wiz.customers);
327 frappe.wiz.add_slide(erpnext.wiz.suppliers);
328 frappe.wiz.add_slide(erpnext.wiz.items);
329 frappe.wiz.welcome_page = "#welcome-to-erpnext";
330});