blob: 5995a03986581d442ae50ed4f66ce91332a0403a [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"),
49 is_private: 0
50 },
51 {
52 fieldname: 'company_name',
53 label: frappe.setup.domain === 'Education' ?
54 __('Institute Name') : __('Company Name'),
55 fieldtype: 'Data', reqd: 1
56 },
57 {
58 fieldname: 'company_abbr',
59 label: frappe.setup.domain === 'Education' ?
60 __('Institute Abbreviation') : __('Company Abbreviation'),
61 fieldtype: 'Data'
62 }
63 ],
64 onload: function(slide) {
65 this.bind_events(slide);
66 },
67 bind_events: function (slide) {
68 slide.get_input("company_name").on("change", function () {
69 var parts = slide.get_input("company_name").val().split(" ");
70 var abbr = $.map(parts, function (p) { return p ? p.substr(0, 1) : null }).join("");
Makarand Bauskar30f2bcb2017-07-11 12:36:57 +053071 slide.get_field("company_abbr").set_value(abbr.slice(0, 5).toUpperCase());
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053072 }).val(frappe.boot.sysdefaults.company_name || "").trigger("change");
Rushabh Mehta37b4d752015-11-09 16:53:11 +053073
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053074 slide.get_input("company_abbr").on("change", function () {
75 if (slide.get_input("company_abbr").val().length > 5) {
76 frappe.msgprint("Company Abbreviation cannot have more than 5 characters");
Makarand Bauskar30f2bcb2017-07-11 12:36:57 +053077 slide.get_field("company_abbr").set_value("");
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053078 }
79 });
80 }
81 },
82 {
83 // Organisation
84 name: 'organisation',
85 domains: ["all"],
86 title: __("Your Organization"),
87 icon: "fa fa-building",
88 help: (frappe.setup.domain === 'Education' ?
89 __('The name of the institute for which you are setting up this system.') :
90 __('The name of your company for which you are setting up this system.')),
91 fields: [
92 {
93 fieldname: 'company_tagline',
94 label: __('What does it do?'),
95 fieldtype: 'Data',
96 placeholder: frappe.setup.domain === 'Education' ?
97 __('e.g. "Primary School" or "University"') :
98 __('e.g. "Build tools for builders"'),
99 reqd: 1
100 },
101 { fieldname: 'bank_account', label: __('Bank Name'), fieldtype: 'Data', reqd: 1 },
102 {
103 fieldname: 'chart_of_accounts', label: __('Chart of Accounts'),
104 options: "", fieldtype: 'Select'
Anand Doshi1ed82832015-11-16 12:58:14 +0530105 },
106
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530107 { fieldtype: "Section Break", label: "Financial Year" },
108 { fieldname: 'fy_start_date', label: __('Start Date'), fieldtype: 'Date', reqd: 1 },
109 { fieldtype: "Column Break" },
110 { fieldname: 'fy_end_date', label: __('End Date'), fieldtype: 'Date', reqd: 1 },
111 ],
112
113 onload: function (slide) {
114 this.load_chart_of_accounts(slide);
115 this.bind_events(slide);
116 this.set_fy_dates(slide);
117 },
118
119 validate: function () {
120 // validate fiscal year start and end dates
121 if (this.values.fy_start_date == 'Invalid date' || this.values.fy_end_date == 'Invalid date') {
122 frappe.msgprint(__("Please enter valid Financial Year Start and End Dates"));
123 return false;
124 }
125
126 if ((this.values.company_name || "").toLowerCase() == "company") {
127 frappe.msgprint(__("Company Name cannot be Company"));
128 return false;
129 }
130
131 return true;
132 },
133
134 set_fy_dates: function (slide) {
135 var country = frappe.wizard.values.country;
136
137 if (country) {
138 var fy = erpnext.setup.fiscal_years[country];
139 var current_year = moment(new Date()).year();
140 var next_year = current_year + 1;
141 if (!fy) {
Makarand Bauskarbf66d7e2017-07-05 17:26:34 +0530142 fy = ["01-01", "12-31"];
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530143 next_year = current_year;
Anand Doshi5c3469a2015-11-24 17:06:54 +0530144 }
145
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530146 var year_start_date = current_year + "-" + fy[0];
147 if (year_start_date > frappe.datetime.get_today()) {
Rushabh Mehta63b06422017-07-05 17:56:04 +0530148 next_year = current_year;
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530149 current_year -= 1;
Anand Doshi5c3469a2015-11-24 17:06:54 +0530150 }
Rushabh Mehta63b06422017-07-05 17:56:04 +0530151 slide.get_field("fy_start_date").set_value(current_year + '-' + fy[0]);
152 slide.get_field("fy_end_date").set_value(next_year + '-' + fy[1]);
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530153 }
Anand Doshi5c3469a2015-11-24 17:06:54 +0530154
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530155 },
Anand Doshi5c3469a2015-11-24 17:06:54 +0530156
Anand Doshi1ed82832015-11-16 12:58:14 +0530157
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530158 load_chart_of_accounts: function (slide) {
159 var country = frappe.wizard.values.country;
Anand Doshi1ed82832015-11-16 12:58:14 +0530160
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530161 if (country) {
162 frappe.call({
163 method: "erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts.get_charts_for_country",
164 args: { "country": country },
165 callback: function (r) {
166 if (r.message) {
167 slide.get_input("chart_of_accounts").empty()
168 .add_options(r.message);
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530169
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530170 if (r.message.length === 1) {
171 var field = slide.get_field("chart_of_accounts");
172 field.set_value(r.message[0]);
173 field.df.hidden = 1;
174 field.refresh();
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530175 }
176 }
Anand Doshi1ed82832015-11-16 12:58:14 +0530177 }
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530178 })
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530179 }
180 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530181
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530182 bind_events: function (slide) {
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530183 slide.get_input("fy_start_date").on("change", function () {
Rushabh Mehta63b06422017-07-05 17:56:04 +0530184 var start_date = slide.form.fields_dict.fy_start_date.get_value();
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530185 var year_end_date =
Rushabh Mehta63b06422017-07-05 17:56:04 +0530186 frappe.datetime.add_days(frappe.datetime.add_months(start_date, 12), -1);
187 slide.form.fields_dict.fy_end_date.set_value(year_end_date);
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530188 });
189 }
190 },
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530191
Prateeksha Singh7d885432017-07-11 12:36:34 +0530192 {
193 // Users
194 name: 'users',
195 domains: ["all"],
196 title: __("Add Users"),
197 help: __("Add users to your organization, other than yourself"),
198 add_more: 1,
199 max_count: 3,
200 fields: [
201 {fieldtype:"Section Break"},
202 {fieldtype:"Data", fieldname:"user_fullname",
203 label:__("Full Name"), static: 1},
204 {fieldtype:"Data", fieldname:"user_email", label:__("Email ID"),
205 placeholder:__("user@example.com"), options: "Email", static: 1},
206 {fieldtype:"Column Break"},
207 {fieldtype: "Check", fieldname: "user_sales",
208 label:__("Sales"), "default": 1, static: 1,
209 hidden: frappe.setup.domain==='Education' ? 1 : 0},
210 {fieldtype: "Check", fieldname: "user_purchaser",
211 label:__("Purchaser"), "default": 1, static: 1,
212 hidden: frappe.setup.domain==='Education' ? 1 : 0},
213 {fieldtype: "Check", fieldname: "user_accountant",
214 label:__("Accountant"), "default": 1, static: 1,
215 hidden: frappe.setup.domain==='Education' ? 1 : 0},
216 ]
217 },
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530218
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530219 {
220 // Taxes
221 name: 'taxes',
222 domains: ['manufacturing', 'services', 'retail', 'distribution'],
223 icon: "fa fa-money",
224 title: __("Add Taxes"),
225 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."),
226 add_more: 1,
Prateeksha Singh7d885432017-07-11 12:36:34 +0530227 max_count: 3,
228 mandatory_entry: 1,
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530229 fields: [
230 {fieldtype:"Section Break"},
231 {fieldtype:"Data", fieldname:"tax", label:__("Tax"),
232 placeholder:__("e.g. VAT")},
233 {fieldtype:"Column Break"},
234 {fieldtype:"Float", fieldname:"tax_rate", label:__("Rate (%)"), placeholder:__("e.g. 5")}
235 ]
236 },
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530237
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530238 {
239 // Customers
240 name: 'customers',
241 domains: ['manufacturing', 'services', 'retail', 'distribution'],
242 icon: "fa fa-group",
243 title: __("Add Customers"),
244 help: __("List a few of your customers. They could be organizations or individuals."),
245 add_more: 1,
Prateeksha Singh7d885432017-07-11 12:36:34 +0530246 max_count: 5,
247 mandatory_entry: 1,
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530248 fields: [
249 {fieldtype:"Section Break"},
250 {fieldtype:"Data", fieldname:"customer", label:__("Customer"),
251 placeholder:__("Customer Name")},
252 {fieldtype:"Column Break"},
253 {fieldtype:"Data", fieldname:"customer_contact",
254 label:__("Contact Name"), placeholder:__("Contact Name")}
255 ],
256 },
Anand Doshi1ed82832015-11-16 12:58:14 +0530257
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530258 {
259 // Suppliers
260 name: 'suppliers',
261 domains: ['manufacturing', 'services', 'retail', 'distribution'],
262 icon: "fa fa-group",
263 title: __("Your Suppliers"),
264 help: __("List a few of your suppliers. They could be organizations or individuals."),
265 add_more: 1,
Prateeksha Singh7d885432017-07-11 12:36:34 +0530266 max_count: 5,
267 mandatory_entry: 1,
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530268 fields: [
269 {fieldtype:"Section Break"},
270 {fieldtype:"Data", fieldname:"supplier", label:__("Supplier"),
271 placeholder:__("Supplier Name")},
272 {fieldtype:"Column Break"},
273 {fieldtype:"Data", fieldname:"supplier_contact",
274 label:__("Contact Name"), placeholder:__("Contact Name")},
275 ]
276 },
Anand Doshi1ed82832015-11-16 12:58:14 +0530277
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530278 {
279 // Products
280 name: 'products',
281 domains: ['manufacturing', 'services', 'retail', 'distribution'],
282 icon: "fa fa-barcode",
283 title: __("Your Products or Services"),
284 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."),
285 add_more: 1,
Prateeksha Singh7d885432017-07-11 12:36:34 +0530286 max_count: 5,
287 mandatory_entry: 1,
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530288 fields: [
289 {fieldtype:"Section Break", show_section_border: true},
290 {fieldtype:"Data", fieldname:"item", label:__("Item"),
291 placeholder:__("A Product or Service")},
292 {fieldtype:"Select", label:__("Group"), fieldname:"item_group",
293 options:[__("Products"), __("Services"),
294 __("Raw Material"), __("Consumable"), __("Sub Assemblies")],
Prateeksha Singh7d885432017-07-11 12:36:34 +0530295 "default": __("Products"), static: 1},
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530296 {fieldtype:"Select", fieldname:"item_uom", label:__("UOM"),
297 options:[__("Unit"), __("Nos"), __("Box"), __("Pair"), __("Kg"), __("Set"),
298 __("Hour"), __("Minute"), __("Litre"), __("Meter"), __("Gram")],
Prateeksha Singh7d885432017-07-11 12:36:34 +0530299 "default": __("Unit"), static: 1},
300 {fieldtype: "Check", fieldname: "is_sales_item", label:__("We sell this Item"), default: 1, static: 1},
301 {fieldtype: "Check", fieldname: "is_purchase_item", label:__("We buy this Item"), static: 1},
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530302 {fieldtype:"Column Break"},
Prateeksha Singh7d885432017-07-11 12:36:34 +0530303 {fieldtype:"Currency", fieldname:"item_price", label:__("Rate"), static: 1},
304 {fieldtype:"Attach Image", fieldname:"item_img", label:__("Attach Image"), is_private: 0, static: 1},
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530305 ],
306 get_item_count: function() {
307 return this.item_count;
308 }
309 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530310
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530311 {
312 // Program
313 name: 'program',
314 domains: ["education"],
315 title: __("Program"),
316 help: __("Example: Masters in Computer Science"),
317 add_more: 1,
Prateeksha Singh7d885432017-07-11 12:36:34 +0530318 max_count: 5,
319 mandatory_entry: 1,
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530320 fields: [
321 {fieldtype:"Section Break", show_section_border: true},
322 {fieldtype:"Data", fieldname:"program", label:__("Program"), placeholder: __("Program Name")},
323 ],
324 },
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530325
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530326 {
327 // Course
328 name: 'course',
329 domains: ["education"],
330 title: __("Course"),
331 help: __("Example: Basic Mathematics"),
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:"course", label:__("Course"), placeholder: __("Course Name")},
338 ]
339 },
Anand Doshi31771382016-07-05 21:34:21 +0530340
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530341 {
342 // Instructor
343 name: 'instructor',
344 domains: ["education"],
345 title: __("Instructor"),
346 help: __("People who teach at your organisation"),
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:"instructor", label:__("Instructor"), placeholder: __("Instructor Name")},
353 ]
354 },
355
356 {
357 // Room
358 name: 'room',
359 domains: ["education"],
360 title: __("Room"),
361 help: __("Classrooms/ Laboratories etc where lectures can be scheduled."),
362 add_more: 1,
Prateeksha Singh7d885432017-07-11 12:36:34 +0530363 max_count: 3,
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:"room", label:__("Room")},
368 {fieldtype:"Column Break"},
Prateeksha Singh7d885432017-07-11 12:36:34 +0530369 {fieldtype:"Int", fieldname:"room_capacity", label:__("Room") + " Capacity", static: 1},
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530370 ]
371 },
372
373 {
Prateeksha Singh7d885432017-07-11 12:36:34 +0530374 // last slide: Sample Data
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530375 name: 'bootstrap',
376 domains: ["all"],
Prateeksha Singh7d885432017-07-11 12:36:34 +0530377 title: __("Sample Data"),
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530378 fields: [{fieldtype: "Section Break"},
379 {fieldtype: "Check", fieldname: "add_sample_data",
380 label: __("Add a few sample records"), "default": 1},
381 {fieldtype: "Check", fieldname: "setup_website",
382 label: __("Setup a simple website for my organization"), "default": 1}
383 ]
Anand Doshi31771382016-07-05 21:34:21 +0530384 }
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530385];
Anand Doshi31771382016-07-05 21:34:21 +0530386
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530387// Source: https://en.wikipedia.org/wiki/Fiscal_year
388// default 1st Jan - 31st Dec
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530389
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530390erpnext.setup.fiscal_years = {
Makarand Bauskarbf66d7e2017-07-05 17:26:34 +0530391 "Afghanistan": ["12-20", "12-21"],
392 "Australia": ["07-01", "06-30"],
393 "Bangladesh": ["07-01", "06-30"],
394 "Canada": ["04-01", "03-31"],
395 "Costa Rica": ["10-01", "09-30"],
396 "Egypt": ["07-01", "06-30"],
397 "Hong Kong": ["04-01", "03-31"],
398 "India": ["04-01", "03-31"],
399 "Iran": ["06-23", "06-22"],
400 "Italy": ["07-01", "06-30"],
401 "Myanmar": ["04-01", "03-31"],
402 "New Zealand": ["04-01", "03-31"],
403 "Pakistan": ["07-01", "06-30"],
404 "Singapore": ["04-01", "03-31"],
405 "South Africa": ["03-01", "02-28"],
406 "Thailand": ["10-01", "09-30"],
407 "United Kingdom": ["04-01", "03-31"],
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530408};
409
410frappe.setup.on("before_load", function () {
411 erpnext_slides.map(frappe.setup.add_slide);
412
413 // change header brand
414 let $brand = $('header .setup-wizard-brand');
415 if($brand.find('.erpnext-icon').length === 0) {
416 $brand.find('.frappe-icon').hide();
417 $brand.append(`<span>
418 <img src="/assets/erpnext/images/erp-icon.svg" class="brand-icon erpnext-icon"
419 style="width:36px;"><span class="brand-name">ERPNext</span></span>`);
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530420 }
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530421});
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530422
Faris Ansariab74ca72017-05-30 12:54:42 +0530423var test_values_edu = {
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530424 "language": "english",
425 "domain": "Education",
426 "country": "India",
427 "timezone": "Asia/Kolkata",
428 "currency": "INR",
429 "first_name": "Tester",
430 "email": "test@example.com",
431 "password": "test",
432 "company_name": "Hogwarts",
433 "company_abbr": "HS",
434 "company_tagline": "School for magicians",
435 "bank_account": "Gringotts Wizarding Bank",
436 "fy_start_date": "2016-04-01",
437 "fy_end_date": "2017-03-31"
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530438}