blob: 43b45d91bc3930542b7e980909e5c5f5d39218f9 [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("");
71 slide.get_field("company_abbr").set_input(abbr.slice(0, 5).toUpperCase());
72 }).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");
77 slide.get_field("company_abbr").set_input("");
78 }
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
192
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530193 {
194 // Taxes
195 name: 'taxes',
196 domains: ['manufacturing', 'services', 'retail', 'distribution'],
197 icon: "fa fa-money",
198 title: __("Add Taxes"),
199 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."),
200 add_more: 1,
201 max_count: 4,
202 fields: [
203 {fieldtype:"Section Break"},
204 {fieldtype:"Data", fieldname:"tax", label:__("Tax"),
205 placeholder:__("e.g. VAT")},
206 {fieldtype:"Column Break"},
207 {fieldtype:"Float", fieldname:"tax_rate", label:__("Rate (%)"), placeholder:__("e.g. 5")}
208 ]
209 },
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530210
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530211 {
212 // Customers
213 name: 'customers',
214 domains: ['manufacturing', 'services', 'retail', 'distribution'],
215 icon: "fa fa-group",
216 title: __("Add Customers"),
217 help: __("List a few of your customers. They could be organizations or individuals."),
218 add_more: 1,
219 max_count: 6,
220 fields: [
221 {fieldtype:"Section Break"},
222 {fieldtype:"Data", fieldname:"customer", label:__("Customer"),
223 placeholder:__("Customer Name")},
224 {fieldtype:"Column Break"},
225 {fieldtype:"Data", fieldname:"customer_contact",
226 label:__("Contact Name"), placeholder:__("Contact Name")}
227 ],
228 },
Anand Doshi1ed82832015-11-16 12:58:14 +0530229
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530230 {
231 // Suppliers
232 name: 'suppliers',
233 domains: ['manufacturing', 'services', 'retail', 'distribution'],
234 icon: "fa fa-group",
235 title: __("Your Suppliers"),
236 help: __("List a few of your suppliers. They could be organizations or individuals."),
237 add_more: 1,
238 max_count: 6,
239 fields: [
240 {fieldtype:"Section Break"},
241 {fieldtype:"Data", fieldname:"supplier", label:__("Supplier"),
242 placeholder:__("Supplier Name")},
243 {fieldtype:"Column Break"},
244 {fieldtype:"Data", fieldname:"supplier_contact",
245 label:__("Contact Name"), placeholder:__("Contact Name")},
246 ]
247 },
Anand Doshi1ed82832015-11-16 12:58:14 +0530248
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530249 {
250 // Products
251 name: 'products',
252 domains: ['manufacturing', 'services', 'retail', 'distribution'],
253 icon: "fa fa-barcode",
254 title: __("Your Products or Services"),
255 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."),
256 add_more: 1,
257 max_count: 6,
258 fields: [
259 {fieldtype:"Section Break", show_section_border: true},
260 {fieldtype:"Data", fieldname:"item", label:__("Item"),
261 placeholder:__("A Product or Service")},
262 {fieldtype:"Select", label:__("Group"), fieldname:"item_group",
263 options:[__("Products"), __("Services"),
264 __("Raw Material"), __("Consumable"), __("Sub Assemblies")],
265 "default": __("Products")},
266 {fieldtype:"Select", fieldname:"item_uom", label:__("UOM"),
267 options:[__("Unit"), __("Nos"), __("Box"), __("Pair"), __("Kg"), __("Set"),
268 __("Hour"), __("Minute"), __("Litre"), __("Meter"), __("Gram")],
269 "default": __("Unit")},
270 {fieldtype: "Check", fieldname: "is_sales_item", label:__("We sell this Item"), default: 1},
271 {fieldtype: "Check", fieldname: "is_purchase_item", label:__("We buy this Item")},
272 {fieldtype:"Column Break"},
273 {fieldtype:"Currency", fieldname:"item_price", label:__("Rate")},
274 {fieldtype:"Attach Image", fieldname:"item_img", label:__("Attach Image"), is_private: 0},
275 ],
276 get_item_count: function() {
277 return this.item_count;
278 }
279 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530280
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530281 {
282 // Program
283 name: 'program',
284 domains: ["education"],
285 title: __("Program"),
286 help: __("Example: Masters in Computer Science"),
287 add_more: 1,
288 max_count: 6,
289 fields: [
290 {fieldtype:"Section Break", show_section_border: true},
291 {fieldtype:"Data", fieldname:"program", label:__("Program"), placeholder: __("Program Name")},
292 ],
293 },
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530294
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530295 {
296 // Course
297 name: 'course',
298 domains: ["education"],
299 title: __("Course"),
300 help: __("Example: Basic Mathematics"),
301 add_more: 1,
302 max_count: 6,
303 fields: [
304 {fieldtype:"Section Break", show_section_border: true},
305 {fieldtype:"Data", fieldname:"course", label:__("Course"), placeholder: __("Course Name")},
306 ]
307 },
Anand Doshi31771382016-07-05 21:34:21 +0530308
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530309 {
310 // Instructor
311 name: 'instructor',
312 domains: ["education"],
313 title: __("Instructor"),
314 help: __("People who teach at your organisation"),
315 add_more: 1,
316 max_count: 6,
317 fields: [
318 {fieldtype:"Section Break", show_section_border: true},
319 {fieldtype:"Data", fieldname:"instructor", label:__("Instructor"), placeholder: __("Instructor Name")},
320 ]
321 },
322
323 {
324 // Room
325 name: 'room',
326 domains: ["education"],
327 title: __("Room"),
328 help: __("Classrooms/ Laboratories etc where lectures can be scheduled."),
329 add_more: 1,
330 max_count: 4,
331 fields: [
332 {fieldtype:"Section Break", show_section_border: true},
333 {fieldtype:"Data", fieldname:"room", label:__("Room")},
334 {fieldtype:"Column Break"},
335 {fieldtype:"Int", fieldname:"room_capacity", label:__("Room") + " Capacity"},
336 ]
337 },
338
339 {
340 // last slide: Bootstrap
341 name: 'bootstrap',
342 domains: ["all"],
343 title: __("Bootstrap"),
344 fields: [{fieldtype: "Section Break"},
345 {fieldtype: "Check", fieldname: "add_sample_data",
346 label: __("Add a few sample records"), "default": 1},
347 {fieldtype: "Check", fieldname: "setup_website",
348 label: __("Setup a simple website for my organization"), "default": 1}
349 ]
Anand Doshi31771382016-07-05 21:34:21 +0530350 }
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530351];
Anand Doshi31771382016-07-05 21:34:21 +0530352
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530353// Source: https://en.wikipedia.org/wiki/Fiscal_year
354// default 1st Jan - 31st Dec
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530355
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530356erpnext.setup.fiscal_years = {
Makarand Bauskarbf66d7e2017-07-05 17:26:34 +0530357 "Afghanistan": ["12-20", "12-21"],
358 "Australia": ["07-01", "06-30"],
359 "Bangladesh": ["07-01", "06-30"],
360 "Canada": ["04-01", "03-31"],
361 "Costa Rica": ["10-01", "09-30"],
362 "Egypt": ["07-01", "06-30"],
363 "Hong Kong": ["04-01", "03-31"],
364 "India": ["04-01", "03-31"],
365 "Iran": ["06-23", "06-22"],
366 "Italy": ["07-01", "06-30"],
367 "Myanmar": ["04-01", "03-31"],
368 "New Zealand": ["04-01", "03-31"],
369 "Pakistan": ["07-01", "06-30"],
370 "Singapore": ["04-01", "03-31"],
371 "South Africa": ["03-01", "02-28"],
372 "Thailand": ["10-01", "09-30"],
373 "United Kingdom": ["04-01", "03-31"],
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530374};
375
376frappe.setup.on("before_load", function () {
377 erpnext_slides.map(frappe.setup.add_slide);
378
379 // change header brand
380 let $brand = $('header .setup-wizard-brand');
381 if($brand.find('.erpnext-icon').length === 0) {
382 $brand.find('.frappe-icon').hide();
383 $brand.append(`<span>
384 <img src="/assets/erpnext/images/erp-icon.svg" class="brand-icon erpnext-icon"
385 style="width:36px;"><span class="brand-name">ERPNext</span></span>`);
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530386 }
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530387});
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530388
Faris Ansariab74ca72017-05-30 12:54:42 +0530389var test_values_edu = {
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530390 "language": "english",
391 "domain": "Education",
392 "country": "India",
393 "timezone": "Asia/Kolkata",
394 "currency": "INR",
395 "first_name": "Tester",
396 "email": "test@example.com",
397 "password": "test",
398 "company_name": "Hogwarts",
399 "company_abbr": "HS",
400 "company_tagline": "School for magicians",
401 "bank_account": "Gringotts Wizarding Bank",
402 "fy_start_date": "2016-04-01",
403 "fy_end_date": "2017-03-31"
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530404}