blob: d5518857000020fbf6bf6ed9e283cf681816e52b [file] [log] [blame]
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +05301frappe.provide("erpnext.setup");
Rushabh Mehta37b4d752015-11-09 16:53:11 +05302
3frappe.pages['setup-wizard'].on_page_load = function(wrapper) {
Faris Ansariab74ca72017-05-30 12:54:42 +05304 if(frappe.sys_defaults.company) {
Rushabh Mehta37b4d752015-11-09 16:53:11 +05305 frappe.set_route("desk");
6 return;
7 }
Anand Doshi1ed82832015-11-16 12:58:14 +05308};
Rushabh Mehta37b4d752015-11-09 16:53:11 +05309
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053010var erpnext_slides = [
11 {
12 // Domain
13 name: 'domain',
14 domains: ["all"],
15 title: __('Select your Domain'),
16 fields: [
17 {
18 fieldname: 'domain', label: __('Domain'), fieldtype: 'Select',
19 options: [
20 { "label": __("Distribution"), "value": "Distribution" },
21 { "label": __("Education"), "value": "Education" },
22 { "label": __("Manufacturing"), "value": "Manufacturing" },
23 { "label": __("Retail"), "value": "Retail" },
24 { "label": __("Services"), "value": "Services" }
25 ], reqd: 1
Rushabh Mehta20038ad2016-07-21 16:01:59 +053026 },
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053027 ],
28 help: __('Select the nature of your business.'),
29 onload: function (slide) {
30 slide.get_input("domain").on("change", function () {
31 frappe.setup.domain = $(this).val();
32 frappe.wizard.refresh_slides();
33 });
Rushabh Mehta20038ad2016-07-21 16:01:59 +053034 },
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053035 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +053036
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053037 {
38 // Brand
39 name: 'brand',
40 domains: ["all"],
41 icon: "fa fa-bookmark",
42 title: __("The Brand"),
43 help: __('Upload your letter head and logo. (you can edit them later).'),
44 fields: [
45 {
46 fieldtype: "Attach Image", fieldname: "attach_logo",
47 label: __("Attach Logo"),
48 description: __("100px by 100px"),
Makarand Bauskar1d9fd9a2017-07-26 18:19:41 +053049 is_private: 0,
50 align: 'center'
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053051 },
52 {
53 fieldname: 'company_name',
54 label: frappe.setup.domain === 'Education' ?
55 __('Institute Name') : __('Company Name'),
Makarand Bauskar1d9fd9a2017-07-26 18:19:41 +053056 fieldtype: 'Data',
57 reqd: 1
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053058 },
59 {
60 fieldname: 'company_abbr',
61 label: frappe.setup.domain === 'Education' ?
62 __('Institute Abbreviation') : __('Company Abbreviation'),
63 fieldtype: 'Data'
64 }
65 ],
66 onload: function(slide) {
67 this.bind_events(slide);
68 },
69 bind_events: function (slide) {
70 slide.get_input("company_name").on("change", function () {
71 var parts = slide.get_input("company_name").val().split(" ");
72 var abbr = $.map(parts, function (p) { return p ? p.substr(0, 1) : null }).join("");
Makarand Bauskar30f2bcb2017-07-11 12:36:57 +053073 slide.get_field("company_abbr").set_value(abbr.slice(0, 5).toUpperCase());
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053074 }).val(frappe.boot.sysdefaults.company_name || "").trigger("change");
Rushabh Mehta37b4d752015-11-09 16:53:11 +053075
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053076 slide.get_input("company_abbr").on("change", function () {
77 if (slide.get_input("company_abbr").val().length > 5) {
78 frappe.msgprint("Company Abbreviation cannot have more than 5 characters");
Makarand Bauskar30f2bcb2017-07-11 12:36:57 +053079 slide.get_field("company_abbr").set_value("");
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053080 }
81 });
82 }
83 },
84 {
85 // Organisation
86 name: 'organisation',
87 domains: ["all"],
88 title: __("Your Organization"),
89 icon: "fa fa-building",
90 help: (frappe.setup.domain === 'Education' ?
91 __('The name of the institute for which you are setting up this system.') :
92 __('The name of your company for which you are setting up this system.')),
93 fields: [
94 {
95 fieldname: 'company_tagline',
96 label: __('What does it do?'),
97 fieldtype: 'Data',
98 placeholder: frappe.setup.domain === 'Education' ?
99 __('e.g. "Primary School" or "University"') :
100 __('e.g. "Build tools for builders"'),
101 reqd: 1
102 },
103 { fieldname: 'bank_account', label: __('Bank Name'), fieldtype: 'Data', reqd: 1 },
104 {
105 fieldname: 'chart_of_accounts', label: __('Chart of Accounts'),
106 options: "", fieldtype: 'Select'
Anand Doshi1ed82832015-11-16 12:58:14 +0530107 },
108
strixaluco372a8812017-07-17 14:36:25 +0800109 { fieldtype: "Section Break", label: __('Financial Year') },
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530110 { fieldname: 'fy_start_date', label: __('Start Date'), fieldtype: 'Date', reqd: 1 },
111 { fieldtype: "Column Break" },
112 { fieldname: 'fy_end_date', label: __('End Date'), fieldtype: 'Date', reqd: 1 },
113 ],
114
115 onload: function (slide) {
116 this.load_chart_of_accounts(slide);
117 this.bind_events(slide);
118 this.set_fy_dates(slide);
119 },
120
121 validate: function () {
122 // validate fiscal year start and end dates
123 if (this.values.fy_start_date == 'Invalid date' || this.values.fy_end_date == 'Invalid date') {
124 frappe.msgprint(__("Please enter valid Financial Year Start and End Dates"));
125 return false;
126 }
127
128 if ((this.values.company_name || "").toLowerCase() == "company") {
129 frappe.msgprint(__("Company Name cannot be Company"));
130 return false;
131 }
132
133 return true;
134 },
135
136 set_fy_dates: function (slide) {
137 var country = frappe.wizard.values.country;
138
139 if (country) {
140 var fy = erpnext.setup.fiscal_years[country];
141 var current_year = moment(new Date()).year();
142 var next_year = current_year + 1;
143 if (!fy) {
Makarand Bauskarbf66d7e2017-07-05 17:26:34 +0530144 fy = ["01-01", "12-31"];
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530145 next_year = current_year;
Anand Doshi5c3469a2015-11-24 17:06:54 +0530146 }
147
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530148 var year_start_date = current_year + "-" + fy[0];
149 if (year_start_date > frappe.datetime.get_today()) {
Rushabh Mehta63b06422017-07-05 17:56:04 +0530150 next_year = current_year;
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530151 current_year -= 1;
Anand Doshi5c3469a2015-11-24 17:06:54 +0530152 }
Rushabh Mehta63b06422017-07-05 17:56:04 +0530153 slide.get_field("fy_start_date").set_value(current_year + '-' + fy[0]);
154 slide.get_field("fy_end_date").set_value(next_year + '-' + fy[1]);
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530155 }
Anand Doshi5c3469a2015-11-24 17:06:54 +0530156
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530157 },
Anand Doshi5c3469a2015-11-24 17:06:54 +0530158
Anand Doshi1ed82832015-11-16 12:58:14 +0530159
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530160 load_chart_of_accounts: function (slide) {
161 var country = frappe.wizard.values.country;
Anand Doshi1ed82832015-11-16 12:58:14 +0530162
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530163 if (country) {
164 frappe.call({
165 method: "erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts.get_charts_for_country",
166 args: { "country": country },
167 callback: function (r) {
168 if (r.message) {
169 slide.get_input("chart_of_accounts").empty()
170 .add_options(r.message);
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530171
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530172 if (r.message.length === 1) {
173 var field = slide.get_field("chart_of_accounts");
174 field.set_value(r.message[0]);
175 field.df.hidden = 1;
176 field.refresh();
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530177 }
178 }
Anand Doshi1ed82832015-11-16 12:58:14 +0530179 }
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530180 })
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530181 }
182 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530183
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530184 bind_events: function (slide) {
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530185 slide.get_input("fy_start_date").on("change", function () {
Rushabh Mehta63b06422017-07-05 17:56:04 +0530186 var start_date = slide.form.fields_dict.fy_start_date.get_value();
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530187 var year_end_date =
Rushabh Mehta63b06422017-07-05 17:56:04 +0530188 frappe.datetime.add_days(frappe.datetime.add_months(start_date, 12), -1);
189 slide.form.fields_dict.fy_end_date.set_value(year_end_date);
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530190 });
191 }
192 },
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530193
Prateeksha Singh7d885432017-07-11 12:36:34 +0530194 {
195 // Users
196 name: 'users',
197 domains: ["all"],
198 title: __("Add Users"),
199 help: __("Add users to your organization, other than yourself"),
200 add_more: 1,
201 max_count: 3,
202 fields: [
203 {fieldtype:"Section Break"},
204 {fieldtype:"Data", fieldname:"user_fullname",
205 label:__("Full Name"), static: 1},
206 {fieldtype:"Data", fieldname:"user_email", label:__("Email ID"),
207 placeholder:__("user@example.com"), options: "Email", static: 1},
208 {fieldtype:"Column Break"},
209 {fieldtype: "Check", fieldname: "user_sales",
210 label:__("Sales"), "default": 1, static: 1,
211 hidden: frappe.setup.domain==='Education' ? 1 : 0},
212 {fieldtype: "Check", fieldname: "user_purchaser",
213 label:__("Purchaser"), "default": 1, static: 1,
214 hidden: frappe.setup.domain==='Education' ? 1 : 0},
215 {fieldtype: "Check", fieldname: "user_accountant",
216 label:__("Accountant"), "default": 1, static: 1,
217 hidden: frappe.setup.domain==='Education' ? 1 : 0},
218 ]
219 },
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530220
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530221 {
Prateeksha Singhe012e242017-07-18 10:35:12 +0530222 // Sales Target
223 name: 'Goals',
224 domains: ['manufacturing', 'services', 'retail', 'distribution'],
225 title: __("Set your Target"),
226 help: __("Set a sales target you'd like to achieve."),
227 fields: [
228 {fieldtype:"Currency", fieldname:"sales_target", label:__("Monthly Sales Target")},
229 ]
230 },
231
232 {
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530233 // Taxes
234 name: 'taxes',
235 domains: ['manufacturing', 'services', 'retail', 'distribution'],
236 icon: "fa fa-money",
237 title: __("Add Taxes"),
238 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."),
239 add_more: 1,
Prateeksha Singh7d885432017-07-11 12:36:34 +0530240 max_count: 3,
Rushabh Mehtaced14cc2017-07-20 15:55:54 +0530241 mandatory_entry: 0,
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530242 fields: [
243 {fieldtype:"Section Break"},
244 {fieldtype:"Data", fieldname:"tax", label:__("Tax"),
245 placeholder:__("e.g. VAT")},
246 {fieldtype:"Column Break"},
247 {fieldtype:"Float", fieldname:"tax_rate", label:__("Rate (%)"), placeholder:__("e.g. 5")}
248 ]
249 },
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530250
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530251 {
252 // Customers
253 name: 'customers',
254 domains: ['manufacturing', 'services', 'retail', 'distribution'],
255 icon: "fa fa-group",
256 title: __("Add Customers"),
257 help: __("List a few of your customers. They could be organizations or individuals."),
258 add_more: 1,
Prateeksha Singh7d885432017-07-11 12:36:34 +0530259 max_count: 5,
260 mandatory_entry: 1,
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530261 fields: [
262 {fieldtype:"Section Break"},
263 {fieldtype:"Data", fieldname:"customer", label:__("Customer"),
264 placeholder:__("Customer Name")},
265 {fieldtype:"Column Break"},
266 {fieldtype:"Data", fieldname:"customer_contact",
267 label:__("Contact Name"), placeholder:__("Contact Name")}
268 ],
269 },
Anand Doshi1ed82832015-11-16 12:58:14 +0530270
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530271 {
272 // Suppliers
273 name: 'suppliers',
274 domains: ['manufacturing', 'services', 'retail', 'distribution'],
275 icon: "fa fa-group",
276 title: __("Your Suppliers"),
277 help: __("List a few of your suppliers. They could be organizations or individuals."),
278 add_more: 1,
Prateeksha Singh7d885432017-07-11 12:36:34 +0530279 max_count: 5,
280 mandatory_entry: 1,
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530281 fields: [
282 {fieldtype:"Section Break"},
283 {fieldtype:"Data", fieldname:"supplier", label:__("Supplier"),
284 placeholder:__("Supplier Name")},
285 {fieldtype:"Column Break"},
286 {fieldtype:"Data", fieldname:"supplier_contact",
287 label:__("Contact Name"), placeholder:__("Contact Name")},
288 ]
289 },
Anand Doshi1ed82832015-11-16 12:58:14 +0530290
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530291 {
292 // Products
293 name: 'products',
294 domains: ['manufacturing', 'services', 'retail', 'distribution'],
295 icon: "fa fa-barcode",
296 title: __("Your Products or Services"),
297 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."),
298 add_more: 1,
Prateeksha Singh7d885432017-07-11 12:36:34 +0530299 max_count: 5,
300 mandatory_entry: 1,
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530301 fields: [
302 {fieldtype:"Section Break", show_section_border: true},
303 {fieldtype:"Data", fieldname:"item", label:__("Item"),
304 placeholder:__("A Product or Service")},
305 {fieldtype:"Select", label:__("Group"), fieldname:"item_group",
306 options:[__("Products"), __("Services"),
307 __("Raw Material"), __("Consumable"), __("Sub Assemblies")],
Prateeksha Singh7d885432017-07-11 12:36:34 +0530308 "default": __("Products"), static: 1},
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530309 {fieldtype:"Select", fieldname:"item_uom", label:__("UOM"),
310 options:[__("Unit"), __("Nos"), __("Box"), __("Pair"), __("Kg"), __("Set"),
311 __("Hour"), __("Minute"), __("Litre"), __("Meter"), __("Gram")],
Prateeksha Singh7d885432017-07-11 12:36:34 +0530312 "default": __("Unit"), static: 1},
Rushabh Mehta35da7d12017-07-20 15:58:20 +0530313 {fieldtype: "Check", fieldname: "is_sales_item",
314 label:__("We sell this Item"), default: 1, static: 1},
315 {fieldtype: "Check", fieldname: "is_purchase_item",
316 label:__("We buy this Item"), default: 1, static: 1},
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530317 {fieldtype:"Column Break"},
Prateeksha Singh7d885432017-07-11 12:36:34 +0530318 {fieldtype:"Currency", fieldname:"item_price", label:__("Rate"), static: 1},
319 {fieldtype:"Attach Image", fieldname:"item_img", label:__("Attach Image"), is_private: 0, static: 1},
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530320 ],
321 get_item_count: function() {
322 return this.item_count;
323 }
324 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530325
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530326 {
327 // Program
328 name: 'program',
329 domains: ["education"],
330 title: __("Program"),
331 help: __("Example: Masters in Computer Science"),
332 add_more: 1,
Prateeksha Singh7d885432017-07-11 12:36:34 +0530333 max_count: 5,
334 mandatory_entry: 1,
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530335 fields: [
336 {fieldtype:"Section Break", show_section_border: true},
337 {fieldtype:"Data", fieldname:"program", label:__("Program"), placeholder: __("Program Name")},
338 ],
339 },
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530340
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530341 {
342 // Course
343 name: 'course',
344 domains: ["education"],
345 title: __("Course"),
346 help: __("Example: Basic Mathematics"),
347 add_more: 1,
Prateeksha Singh7d885432017-07-11 12:36:34 +0530348 max_count: 5,
349 mandatory_entry: 1,
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530350 fields: [
351 {fieldtype:"Section Break", show_section_border: true},
352 {fieldtype:"Data", fieldname:"course", label:__("Course"), placeholder: __("Course Name")},
353 ]
354 },
Anand Doshi31771382016-07-05 21:34:21 +0530355
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530356 {
357 // Instructor
358 name: 'instructor',
359 domains: ["education"],
360 title: __("Instructor"),
361 help: __("People who teach at your organisation"),
362 add_more: 1,
Prateeksha Singh7d885432017-07-11 12:36:34 +0530363 max_count: 5,
364 mandatory_entry: 1,
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530365 fields: [
366 {fieldtype:"Section Break", show_section_border: true},
367 {fieldtype:"Data", fieldname:"instructor", label:__("Instructor"), placeholder: __("Instructor Name")},
368 ]
369 },
370
371 {
372 // Room
373 name: 'room',
374 domains: ["education"],
375 title: __("Room"),
376 help: __("Classrooms/ Laboratories etc where lectures can be scheduled."),
377 add_more: 1,
Prateeksha Singh7d885432017-07-11 12:36:34 +0530378 max_count: 3,
379 mandatory_entry: 1,
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530380 fields: [
381 {fieldtype:"Section Break", show_section_border: true},
382 {fieldtype:"Data", fieldname:"room", label:__("Room")},
383 {fieldtype:"Column Break"},
Prateeksha Singh7d885432017-07-11 12:36:34 +0530384 {fieldtype:"Int", fieldname:"room_capacity", label:__("Room") + " Capacity", static: 1},
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530385 ]
386 },
387
388 {
Prateeksha Singh7d885432017-07-11 12:36:34 +0530389 // last slide: Sample Data
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530390 name: 'bootstrap',
391 domains: ["all"],
Prateeksha Singh7d885432017-07-11 12:36:34 +0530392 title: __("Sample Data"),
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530393 fields: [{fieldtype: "Section Break"},
394 {fieldtype: "Check", fieldname: "add_sample_data",
395 label: __("Add a few sample records"), "default": 1},
396 {fieldtype: "Check", fieldname: "setup_website",
397 label: __("Setup a simple website for my organization"), "default": 1}
398 ]
Anand Doshi31771382016-07-05 21:34:21 +0530399 }
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530400];
Anand Doshi31771382016-07-05 21:34:21 +0530401
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530402// Source: https://en.wikipedia.org/wiki/Fiscal_year
403// default 1st Jan - 31st Dec
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530404
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530405erpnext.setup.fiscal_years = {
Makarand Bauskarbf66d7e2017-07-05 17:26:34 +0530406 "Afghanistan": ["12-20", "12-21"],
407 "Australia": ["07-01", "06-30"],
408 "Bangladesh": ["07-01", "06-30"],
409 "Canada": ["04-01", "03-31"],
410 "Costa Rica": ["10-01", "09-30"],
411 "Egypt": ["07-01", "06-30"],
412 "Hong Kong": ["04-01", "03-31"],
413 "India": ["04-01", "03-31"],
414 "Iran": ["06-23", "06-22"],
415 "Italy": ["07-01", "06-30"],
416 "Myanmar": ["04-01", "03-31"],
417 "New Zealand": ["04-01", "03-31"],
418 "Pakistan": ["07-01", "06-30"],
419 "Singapore": ["04-01", "03-31"],
420 "South Africa": ["03-01", "02-28"],
421 "Thailand": ["10-01", "09-30"],
422 "United Kingdom": ["04-01", "03-31"],
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530423};
424
425frappe.setup.on("before_load", function () {
426 erpnext_slides.map(frappe.setup.add_slide);
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530427});
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530428
Faris Ansariab74ca72017-05-30 12:54:42 +0530429var test_values_edu = {
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530430 "language": "english",
431 "domain": "Education",
432 "country": "India",
433 "timezone": "Asia/Kolkata",
434 "currency": "INR",
435 "first_name": "Tester",
436 "email": "test@example.com",
437 "password": "test",
438 "company_name": "Hogwarts",
439 "company_abbr": "HS",
440 "company_tagline": "School for magicians",
441 "bank_account": "Gringotts Wizarding Bank",
442 "fy_start_date": "2016-04-01",
443 "fy_end_date": "2017-03-31"
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530444}