blob: 5e16dd89d25ccea3a19d815e4e2d199447344405 [file] [log] [blame]
Rushabh Mehta37b4d752015-11-09 16:53:11 +05301frappe.provide("erpnext.wiz");
2
3frappe.pages['setup-wizard'].on_page_load = function(wrapper) {
4 if(sys_defaults.company) {
5 frappe.set_route("desk");
6 return;
7 }
Anand Doshi1ed82832015-11-16 12:58:14 +05308};
Rushabh Mehta37b4d752015-11-09 16:53:11 +05309
Anand Doshi1ed82832015-11-16 12:58:14 +053010function load_erpnext_slides() {
11 $.extend(erpnext.wiz, {
Anand Doshi1ed82832015-11-16 12:58:14 +053012 org: {
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +053013 app_name: "erpnext",
Anand Doshi1ed82832015-11-16 12:58:14 +053014 title: __("The Organization"),
15 icon: "icon-building",
16 fields: [
17 {fieldname:'company_name', label: __('Company Name'), fieldtype:'Data', reqd:1,
18 placeholder: __('e.g. "My Company LLC"')},
19 {fieldname:'company_abbr', label: __('Company Abbreviation'), fieldtype:'Data',
20 description: __('Max 5 characters'), placeholder: __('e.g. "MC"'), reqd:1},
21 {fieldname:'company_tagline', label: __('What does it do?'), fieldtype:'Data',
22 placeholder:__('e.g. "Build tools for builders"'), reqd:1},
23 {fieldname:'bank_account', label: __('Bank Account'), fieldtype:'Data',
24 placeholder: __('e.g. "XYZ National Bank"'), reqd:1 },
Neil Trini Lasrado342895c2016-03-04 15:41:27 +053025 {fieldname:'domain', label: __('Domain'), fieldtype:'Select',
Neil Trini Lasrado1b03e0a2016-03-07 16:57:05 +053026 options: [
Anand Doshi01792422016-03-09 16:31:53 +053027 {"label": __("Distribution"), "value": "Distribution"},
28 {"label": __("Manufacturing"), "value": "Manufacturing"},
29 {"label": __("Retail"), "value": "Retail"},
30 {"label": __("Services"), "value": "Services"},
31 {"label": __("Education"), "value": "Education"},
32 {"label": __("Other"), "value": "Other"},
Neil Trini Lasrado1b03e0a2016-03-07 16:57:05 +053033 ], reqd:1},
Anand Doshi1ed82832015-11-16 12:58:14 +053034 {fieldname:'chart_of_accounts', label: __('Chart of Accounts'),
35 options: "", fieldtype: 'Select'},
Rushabh Mehta37b4d752015-11-09 16:53:11 +053036
Anand Doshi1ed82832015-11-16 12:58:14 +053037 // TODO remove this
38 {fieldtype: "Section Break"},
39 {fieldname:'fy_start_date', label:__('Financial Year Start Date'), fieldtype:'Date',
40 description: __('Your financial year begins on'), reqd:1},
41 {fieldname:'fy_end_date', label:__('Financial Year End Date'), fieldtype:'Date',
42 description: __('Your financial year ends on'), reqd:1},
43 ],
44 help: __('The name of your company for which you are setting up this system.'),
Rushabh Mehta37b4d752015-11-09 16:53:11 +053045
Anand Doshi1ed82832015-11-16 12:58:14 +053046 onload: function(slide) {
47 erpnext.wiz.org.load_chart_of_accounts(slide);
48 erpnext.wiz.org.bind_events(slide);
49 erpnext.wiz.org.set_fy_dates(slide);
50 },
51
Anand Doshi5c3469a2015-11-24 17:06:54 +053052 validate: function() {
53 // validate fiscal year start and end dates
54 if (this.values.fy_start_date=='Invalid date' || this.values.fy_end_date=='Invalid date') {
55 msgprint(__("Please enter valid Financial Year Start and End Dates"));
56 return false;
57 }
58
59 if ((this.values.company_name || "").toLowerCase() == "company") {
60 msgprint(__("Company Name cannot be Company"));
61 return false;
62 }
63
64 return true;
65 },
66
Anand Doshi1ed82832015-11-16 12:58:14 +053067 css_class: "single-column",
68
69 set_fy_dates: function(slide) {
70 var country = slide.wiz.get_values().country;
71
72 if(country) {
73 var fy = erpnext.wiz.fiscal_years[country];
74 var current_year = moment(new Date()).year();
75 var next_year = current_year + 1;
76 if(!fy) {
77 fy = ["01-01", "12-31"];
78 next_year = current_year;
79 }
80
81 slide.get_field("fy_start_date").set_input(current_year + "-" + fy[0]);
82 slide.get_field("fy_end_date").set_input(next_year + "-" + fy[1]);
Rushabh Mehta37b4d752015-11-09 16:53:11 +053083 }
84
Anand Doshi1ed82832015-11-16 12:58:14 +053085 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +053086
Anand Doshi1ed82832015-11-16 12:58:14 +053087 load_chart_of_accounts: function(slide) {
88 var country = slide.wiz.get_values().country;
Rushabh Mehta37b4d752015-11-09 16:53:11 +053089
Anand Doshi1ed82832015-11-16 12:58:14 +053090 if(country) {
91 frappe.call({
92 method: "erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts.get_charts_for_country",
93 args: {"country": country},
94 callback: function(r) {
95 if(r.message) {
96 slide.get_input("chart_of_accounts").empty()
97 .add_options(r.message);
Rushabh Mehta37b4d752015-11-09 16:53:11 +053098
Anand Doshi1ed82832015-11-16 12:58:14 +053099 if (r.message.length===1) {
100 var field = slide.get_field("chart_of_accounts");
101 field.set_value(r.message[0]);
102 field.df.hidden = 1;
103 field.refresh();
104 }
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530105 }
106 }
Anand Doshi1ed82832015-11-16 12:58:14 +0530107 })
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530108 }
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530109 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530110
Anand Doshi1ed82832015-11-16 12:58:14 +0530111 bind_events: function(slide) {
112 slide.get_input("company_name").on("change", function() {
113 var parts = slide.get_input("company_name").val().split(" ");
114 var abbr = $.map(parts, function(p) { return p ? p.substr(0,1) : null }).join("");
115 slide.get_field("company_abbr").set_input(abbr.slice(0, 5).toUpperCase());
116 }).val(frappe.boot.sysdefaults.company_name || "").trigger("change");
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530117
Anand Doshi1ed82832015-11-16 12:58:14 +0530118 slide.get_input("company_abbr").on("change", function() {
119 if(slide.get_input("company_abbr").val().length > 5) {
120 msgprint("Company Abbreviation cannot have more than 5 characters");
121 slide.get_field("company_abbr").set_input("");
122 }
123 });
124
125 // TODO remove this
126 slide.get_input("fy_start_date").on("change", function() {
127 var year_end_date =
128 frappe.datetime.add_days(frappe.datetime.add_months(
129 frappe.datetime.user_to_obj(slide.get_input("fy_start_date").val()), 12), -1);
130 slide.get_input("fy_end_date").val(frappe.datetime.obj_to_user(year_end_date));
131
132 });
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530133 }
134 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530135
Anand Doshi1ed82832015-11-16 12:58:14 +0530136 branding: {
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530137 app_name: "erpnext",
Anand Doshi1ed82832015-11-16 12:58:14 +0530138 icon: "icon-bookmark",
139 title: __("The Brand"),
140 help: __('Upload your letter head and logo. (you can edit them later).'),
141 fields: [
142 {fieldtype:"Attach Image", fieldname:"attach_letterhead",
143 label: __("Attach Letterhead"),
Anand Doshi2af44ff2015-12-09 17:28:51 +0530144 description: __("Keep it web friendly 900px (w) by 100px (h)"),
145 is_private: 0
Anand Doshi1ed82832015-11-16 12:58:14 +0530146 },
147 {fieldtype: "Column Break"},
148 {fieldtype:"Attach Image", fieldname:"attach_logo",
149 label:__("Attach Logo"),
Anand Doshi2af44ff2015-12-09 17:28:51 +0530150 description: __("100px by 100px"),
151 is_private: 0
152 },
Anand Doshi1ed82832015-11-16 12:58:14 +0530153 ],
154
155 css_class: "two-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530156 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530157
Anand Doshi1ed82832015-11-16 12:58:14 +0530158 users: {
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530159 app_name: "erpnext",
Anand Doshi1ed82832015-11-16 12:58:14 +0530160 icon: "icon-money",
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530161 title: __("Add Users"),
162 help: __("Add users to your organization, other than yourself"),
163 fields: [],
Anand Doshi1ed82832015-11-16 12:58:14 +0530164 before_load: function(slide) {
165 slide.fields = [];
166 for(var i=1; i<5; i++) {
167 slide.fields = slide.fields.concat([
168 {fieldtype:"Section Break"},
169 {fieldtype:"Data", fieldname:"user_fullname_"+ i,
170 label:__("Full Name")},
171 {fieldtype:"Data", fieldname:"user_email_" + i,
172 label:__("Email ID"), placeholder:__("user@example.com"),
173 options: "Email"},
174 {fieldtype:"Column Break"},
175 {fieldtype: "Check", fieldname: "user_sales_" + i,
176 label:__("Sales"), default: 1},
177 {fieldtype: "Check", fieldname: "user_purchaser_" + i,
178 label:__("Purchaser"), default: 1},
179 {fieldtype: "Check", fieldname: "user_accountant_" + i,
180 label:__("Accountant"), default: 1},
181 ]);
182 }
183 },
184 css_class: "two-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530185 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530186
Anand Doshi1ed82832015-11-16 12:58:14 +0530187 taxes: {
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530188 app_name: "erpnext",
Anand Doshi1ed82832015-11-16 12:58:14 +0530189 icon: "icon-money",
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530190 title: __("Add Taxes"),
191 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."),
Anand Doshi1ed82832015-11-16 12:58:14 +0530192 "fields": [],
193 before_load: function(slide) {
194 slide.fields = [];
195 for(var i=1; i<4; i++) {
196 slide.fields = slide.fields.concat([
197 {fieldtype:"Section Break"},
198 {fieldtype:"Data", fieldname:"tax_"+ i, label:__("Tax") + " " + i,
199 placeholder:__("e.g. VAT") + " " + i},
200 {fieldtype:"Column Break"},
201 {fieldtype:"Float", fieldname:"tax_rate_" + i, label:__("Rate (%)"), placeholder:__("e.g. 5")},
202 ]);
203 }
204 },
205 css_class: "two-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530206 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530207
Anand Doshi1ed82832015-11-16 12:58:14 +0530208 customers: {
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530209 app_name: "erpnext",
Anand Doshi1ed82832015-11-16 12:58:14 +0530210 icon: "icon-group",
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530211 title: __("Your Customers"),
212 help: __("List a few of your customers. They could be organizations or individuals."),
213 fields: [],
Anand Doshi1ed82832015-11-16 12:58:14 +0530214 before_load: function(slide) {
215 slide.fields = [];
216 for(var i=1; i<6; i++) {
217 slide.fields = slide.fields.concat([
218 {fieldtype:"Section Break"},
219 {fieldtype:"Data", fieldname:"customer_" + i, label:__("Customer") + " " + i,
220 placeholder:__("Customer Name")},
221 {fieldtype:"Column Break"},
222 {fieldtype:"Data", fieldname:"customer_contact_" + i,
223 label:__("Contact Name") + " " + i, placeholder:__("Contact Name")}
224 ])
225 }
226 slide.fields[1].reqd = 1;
227 },
228 css_class: "two-column"
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530229 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530230
Anand Doshi1ed82832015-11-16 12:58:14 +0530231 suppliers: {
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530232 app_name: "erpnext",
Anand Doshi1ed82832015-11-16 12:58:14 +0530233 icon: "icon-group",
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530234 title: __("Your Suppliers"),
235 help: __("List a few of your suppliers. They could be organizations or individuals."),
236 fields: [],
Anand Doshi1ed82832015-11-16 12:58:14 +0530237 before_load: function(slide) {
238 slide.fields = [];
239 for(var i=1; i<6; i++) {
240 slide.fields = slide.fields.concat([
241 {fieldtype:"Section Break"},
242 {fieldtype:"Data", fieldname:"supplier_" + i, label:__("Supplier")+" " + i,
243 placeholder:__("Supplier Name")},
244 {fieldtype:"Column Break"},
245 {fieldtype:"Data", fieldname:"supplier_contact_" + i,
246 label:__("Contact Name") + " " + i, placeholder:__("Contact Name")},
247 ])
248 }
249 slide.fields[1].reqd = 1;
250 },
251 css_class: "two-column"
252 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530253
Anand Doshi1ed82832015-11-16 12:58:14 +0530254 items: {
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530255 app_name: "erpnext",
Anand Doshi1ed82832015-11-16 12:58:14 +0530256 icon: "icon-barcode",
Neil Trini Lasrado3c0d5cb2016-02-24 15:58:25 +0530257 title: __("Your Products or Services"),
258 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."),
259 fields: [],
Anand Doshi1ed82832015-11-16 12:58:14 +0530260 before_load: function(slide) {
261 slide.fields = [];
262 for(var i=1; i<6; i++) {
263 slide.fields = slide.fields.concat([
264 {fieldtype:"Section Break", show_section_border: true},
265 {fieldtype:"Data", fieldname:"item_" + i, label:__("Item") + " " + i,
266 placeholder:__("A Product or Service")},
267 {fieldtype:"Select", label:__("Group"), fieldname:"item_group_" + i,
268 options:[__("Products"), __("Services"),
269 __("Raw Material"), __("Consumable"), __("Sub Assemblies")],
270 "default": __("Products")},
271 {fieldtype:"Select", fieldname:"item_uom_" + i, label:__("UOM"),
272 options:[__("Unit"), __("Nos"), __("Box"), __("Pair"), __("Kg"), __("Set"),
273 __("Hour"), __("Minute")],
274 "default": __("Unit")},
275 {fieldtype: "Check", fieldname: "is_sales_item_" + i, label:__("We sell this Item"), default: 1},
276 {fieldtype: "Check", fieldname: "is_purchase_item_" + i, label:__("We buy this Item")},
277 {fieldtype:"Column Break"},
278 {fieldtype:"Currency", fieldname:"item_price_" + i, label:__("Rate")},
Anand Doshi2af44ff2015-12-09 17:28:51 +0530279 {fieldtype:"Attach Image", fieldname:"item_img_" + i, label:__("Attach Image"), is_private: 0},
Anand Doshi1ed82832015-11-16 12:58:14 +0530280 ])
281 }
282 slide.fields[1].reqd = 1;
283
284 // dummy data
285 slide.fields.push({fieldtype: "Section Break"});
286 slide.fields.push({fieldtype: "Check", fieldname: "add_sample_data",
287 label: __("Add a few sample records"), "default": 1});
288 },
289 css_class: "two-column"
290 },
291 });
292
293 // Source: https://en.wikipedia.org/wiki/Fiscal_year
294 // default 1st Jan - 31st Dec
295
296 erpnext.wiz.fiscal_years = {
297 "Afghanistan": ["12-20", "12-21"],
298 "Australia": ["07-01", "06-30"],
299 "Bangladesh": ["07-01", "06-30"],
300 "Canada": ["04-01", "03-31"],
301 "Costa Rica": ["10-01", "09-30"],
302 "Egypt": ["07-01", "06-30"],
303 "Hong Kong": ["04-01", "03-31"],
304 "India": ["04-01", "03-31"],
305 "Iran": ["06-23", "06-22"],
306 "Italy": ["07-01", "06-30"],
307 "Myanmar": ["04-01", "03-31"],
308 "New Zealand": ["04-01", "03-31"],
309 "Pakistan": ["07-01", "06-30"],
310 "Singapore": ["04-01", "03-31"],
311 "South Africa": ["03-01", "02-28"],
312 "Thailand": ["10-01", "09-30"],
313 "United Kingdom": ["04-01", "03-31"],
314 };
315};
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530316
317frappe.wiz.on("before_load", function() {
Anand Doshi1ed82832015-11-16 12:58:14 +0530318 load_erpnext_slides();
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530319 frappe.wiz.add_slide(erpnext.wiz.org);
320 frappe.wiz.add_slide(erpnext.wiz.branding);
321 frappe.wiz.add_slide(erpnext.wiz.users);
322 frappe.wiz.add_slide(erpnext.wiz.taxes);
323 frappe.wiz.add_slide(erpnext.wiz.customers);
324 frappe.wiz.add_slide(erpnext.wiz.suppliers);
325 frappe.wiz.add_slide(erpnext.wiz.items);
326 frappe.wiz.welcome_page = "#welcome-to-erpnext";
327});