blob: cb48c2523b52de1fddc04827c52596582fb5caed [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
strixaluco372a8812017-07-17 14:36:25 +0800107 { fieldtype: "Section Break", label: __('Financial Year') },
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530108 { 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 {
Prateeksha Singhe012e242017-07-18 10:35:12 +0530220 // Sales Target
221 name: 'Goals',
222 domains: ['manufacturing', 'services', 'retail', 'distribution'],
223 title: __("Set your Target"),
224 help: __("Set a sales target you'd like to achieve."),
225 fields: [
226 {fieldtype:"Currency", fieldname:"sales_target", label:__("Monthly Sales Target")},
227 ]
228 },
229
230 {
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530231 // Taxes
232 name: 'taxes',
233 domains: ['manufacturing', 'services', 'retail', 'distribution'],
234 icon: "fa fa-money",
235 title: __("Add Taxes"),
236 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."),
237 add_more: 1,
Prateeksha Singh7d885432017-07-11 12:36:34 +0530238 max_count: 3,
239 mandatory_entry: 1,
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530240 fields: [
241 {fieldtype:"Section Break"},
242 {fieldtype:"Data", fieldname:"tax", label:__("Tax"),
243 placeholder:__("e.g. VAT")},
244 {fieldtype:"Column Break"},
245 {fieldtype:"Float", fieldname:"tax_rate", label:__("Rate (%)"), placeholder:__("e.g. 5")}
246 ]
247 },
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530248
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530249 {
250 // Customers
251 name: 'customers',
252 domains: ['manufacturing', 'services', 'retail', 'distribution'],
253 icon: "fa fa-group",
254 title: __("Add Customers"),
255 help: __("List a few of your customers. They could be organizations or individuals."),
256 add_more: 1,
Prateeksha Singh7d885432017-07-11 12:36:34 +0530257 max_count: 5,
258 mandatory_entry: 1,
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530259 fields: [
260 {fieldtype:"Section Break"},
261 {fieldtype:"Data", fieldname:"customer", label:__("Customer"),
262 placeholder:__("Customer Name")},
263 {fieldtype:"Column Break"},
264 {fieldtype:"Data", fieldname:"customer_contact",
265 label:__("Contact Name"), placeholder:__("Contact Name")}
266 ],
267 },
Anand Doshi1ed82832015-11-16 12:58:14 +0530268
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530269 {
270 // Suppliers
271 name: 'suppliers',
272 domains: ['manufacturing', 'services', 'retail', 'distribution'],
273 icon: "fa fa-group",
274 title: __("Your Suppliers"),
275 help: __("List a few of your suppliers. They could be organizations or individuals."),
276 add_more: 1,
Prateeksha Singh7d885432017-07-11 12:36:34 +0530277 max_count: 5,
278 mandatory_entry: 1,
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530279 fields: [
280 {fieldtype:"Section Break"},
281 {fieldtype:"Data", fieldname:"supplier", label:__("Supplier"),
282 placeholder:__("Supplier Name")},
283 {fieldtype:"Column Break"},
284 {fieldtype:"Data", fieldname:"supplier_contact",
285 label:__("Contact Name"), placeholder:__("Contact Name")},
286 ]
287 },
Anand Doshi1ed82832015-11-16 12:58:14 +0530288
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530289 {
290 // Products
291 name: 'products',
292 domains: ['manufacturing', 'services', 'retail', 'distribution'],
293 icon: "fa fa-barcode",
294 title: __("Your Products or Services"),
295 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."),
296 add_more: 1,
Prateeksha Singh7d885432017-07-11 12:36:34 +0530297 max_count: 5,
298 mandatory_entry: 1,
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530299 fields: [
300 {fieldtype:"Section Break", show_section_border: true},
301 {fieldtype:"Data", fieldname:"item", label:__("Item"),
302 placeholder:__("A Product or Service")},
303 {fieldtype:"Select", label:__("Group"), fieldname:"item_group",
304 options:[__("Products"), __("Services"),
305 __("Raw Material"), __("Consumable"), __("Sub Assemblies")],
Prateeksha Singh7d885432017-07-11 12:36:34 +0530306 "default": __("Products"), static: 1},
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530307 {fieldtype:"Select", fieldname:"item_uom", label:__("UOM"),
308 options:[__("Unit"), __("Nos"), __("Box"), __("Pair"), __("Kg"), __("Set"),
309 __("Hour"), __("Minute"), __("Litre"), __("Meter"), __("Gram")],
Prateeksha Singh7d885432017-07-11 12:36:34 +0530310 "default": __("Unit"), static: 1},
311 {fieldtype: "Check", fieldname: "is_sales_item", label:__("We sell this Item"), default: 1, static: 1},
312 {fieldtype: "Check", fieldname: "is_purchase_item", label:__("We buy this Item"), static: 1},
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530313 {fieldtype:"Column Break"},
Prateeksha Singh7d885432017-07-11 12:36:34 +0530314 {fieldtype:"Currency", fieldname:"item_price", label:__("Rate"), static: 1},
315 {fieldtype:"Attach Image", fieldname:"item_img", label:__("Attach Image"), is_private: 0, static: 1},
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530316 ],
317 get_item_count: function() {
318 return this.item_count;
319 }
320 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530321
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530322 {
323 // Program
324 name: 'program',
325 domains: ["education"],
326 title: __("Program"),
327 help: __("Example: Masters in Computer Science"),
328 add_more: 1,
Prateeksha Singh7d885432017-07-11 12:36:34 +0530329 max_count: 5,
330 mandatory_entry: 1,
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530331 fields: [
332 {fieldtype:"Section Break", show_section_border: true},
333 {fieldtype:"Data", fieldname:"program", label:__("Program"), placeholder: __("Program Name")},
334 ],
335 },
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530336
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530337 {
338 // Course
339 name: 'course',
340 domains: ["education"],
341 title: __("Course"),
342 help: __("Example: Basic Mathematics"),
343 add_more: 1,
Prateeksha Singh7d885432017-07-11 12:36:34 +0530344 max_count: 5,
345 mandatory_entry: 1,
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530346 fields: [
347 {fieldtype:"Section Break", show_section_border: true},
348 {fieldtype:"Data", fieldname:"course", label:__("Course"), placeholder: __("Course Name")},
349 ]
350 },
Anand Doshi31771382016-07-05 21:34:21 +0530351
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530352 {
353 // Instructor
354 name: 'instructor',
355 domains: ["education"],
356 title: __("Instructor"),
357 help: __("People who teach at your organisation"),
358 add_more: 1,
Prateeksha Singh7d885432017-07-11 12:36:34 +0530359 max_count: 5,
360 mandatory_entry: 1,
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530361 fields: [
362 {fieldtype:"Section Break", show_section_border: true},
363 {fieldtype:"Data", fieldname:"instructor", label:__("Instructor"), placeholder: __("Instructor Name")},
364 ]
365 },
366
367 {
368 // Room
369 name: 'room',
370 domains: ["education"],
371 title: __("Room"),
372 help: __("Classrooms/ Laboratories etc where lectures can be scheduled."),
373 add_more: 1,
Prateeksha Singh7d885432017-07-11 12:36:34 +0530374 max_count: 3,
375 mandatory_entry: 1,
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530376 fields: [
377 {fieldtype:"Section Break", show_section_border: true},
378 {fieldtype:"Data", fieldname:"room", label:__("Room")},
379 {fieldtype:"Column Break"},
Prateeksha Singh7d885432017-07-11 12:36:34 +0530380 {fieldtype:"Int", fieldname:"room_capacity", label:__("Room") + " Capacity", static: 1},
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530381 ]
382 },
383
384 {
Prateeksha Singh7d885432017-07-11 12:36:34 +0530385 // last slide: Sample Data
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530386 name: 'bootstrap',
387 domains: ["all"],
Prateeksha Singh7d885432017-07-11 12:36:34 +0530388 title: __("Sample Data"),
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530389 fields: [{fieldtype: "Section Break"},
390 {fieldtype: "Check", fieldname: "add_sample_data",
391 label: __("Add a few sample records"), "default": 1},
392 {fieldtype: "Check", fieldname: "setup_website",
393 label: __("Setup a simple website for my organization"), "default": 1}
394 ]
Anand Doshi31771382016-07-05 21:34:21 +0530395 }
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530396];
Anand Doshi31771382016-07-05 21:34:21 +0530397
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530398// Source: https://en.wikipedia.org/wiki/Fiscal_year
399// default 1st Jan - 31st Dec
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530400
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530401erpnext.setup.fiscal_years = {
Makarand Bauskarbf66d7e2017-07-05 17:26:34 +0530402 "Afghanistan": ["12-20", "12-21"],
403 "Australia": ["07-01", "06-30"],
404 "Bangladesh": ["07-01", "06-30"],
405 "Canada": ["04-01", "03-31"],
406 "Costa Rica": ["10-01", "09-30"],
407 "Egypt": ["07-01", "06-30"],
408 "Hong Kong": ["04-01", "03-31"],
409 "India": ["04-01", "03-31"],
410 "Iran": ["06-23", "06-22"],
411 "Italy": ["07-01", "06-30"],
412 "Myanmar": ["04-01", "03-31"],
413 "New Zealand": ["04-01", "03-31"],
414 "Pakistan": ["07-01", "06-30"],
415 "Singapore": ["04-01", "03-31"],
416 "South Africa": ["03-01", "02-28"],
417 "Thailand": ["10-01", "09-30"],
418 "United Kingdom": ["04-01", "03-31"],
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530419};
420
421frappe.setup.on("before_load", function () {
422 erpnext_slides.map(frappe.setup.add_slide);
423
424 // change header brand
425 let $brand = $('header .setup-wizard-brand');
426 if($brand.find('.erpnext-icon').length === 0) {
427 $brand.find('.frappe-icon').hide();
428 $brand.append(`<span>
429 <img src="/assets/erpnext/images/erp-icon.svg" class="brand-icon erpnext-icon"
430 style="width:36px;"><span class="brand-name">ERPNext</span></span>`);
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530431 }
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530432});
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530433
Faris Ansariab74ca72017-05-30 12:54:42 +0530434var test_values_edu = {
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530435 "language": "english",
436 "domain": "Education",
437 "country": "India",
438 "timezone": "Asia/Kolkata",
439 "currency": "INR",
440 "first_name": "Tester",
441 "email": "test@example.com",
442 "password": "test",
443 "company_name": "Hogwarts",
444 "company_abbr": "HS",
445 "company_tagline": "School for magicians",
446 "bank_account": "Gringotts Wizarding Bank",
447 "fy_start_date": "2016-04-01",
448 "fy_end_date": "2017-03-31"
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530449}