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