blob: 320d871849f54d9b4a34d0acc3de4c035fb7c122 [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 Singh95d8fd32017-09-04 11:14:04 +053010frappe.setup.on("before_load", function () {
11 erpnext.setup.slides_settings.map(frappe.setup.add_slide);
12});
13
14erpnext.setup.slides_settings = [
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053015 {
16 // Domain
17 name: 'domain',
18 domains: ["all"],
19 title: __('Select your Domain'),
20 fields: [
21 {
22 fieldname: 'domain', label: __('Domain'), fieldtype: 'Select',
23 options: [
24 { "label": __("Distribution"), "value": "Distribution" },
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053025 { "label": __("Manufacturing"), "value": "Manufacturing" },
26 { "label": __("Retail"), "value": "Retail" },
Prateeksha Singh95d8fd32017-09-04 11:14:04 +053027 { "label": __("Services"), "value": "Services" },
28 { "label": __("Education"), "value": "Education" }
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053029 ], reqd: 1
Rushabh Mehta20038ad2016-07-21 16:01:59 +053030 },
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053031 ],
Prateeksha Singh95d8fd32017-09-04 11:14:04 +053032 // help: __('Select the nature of your business.'),
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053033 onload: function (slide) {
34 slide.get_input("domain").on("change", function () {
35 frappe.setup.domain = $(this).val();
36 frappe.wizard.refresh_slides();
37 });
Rushabh Mehta20038ad2016-07-21 16:01:59 +053038 },
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053039 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +053040
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053041 {
42 // Brand
43 name: 'brand',
44 domains: ["all"],
45 icon: "fa fa-bookmark",
46 title: __("The Brand"),
Prateeksha Singh95d8fd32017-09-04 11:14:04 +053047 // help: __('Upload your letter head and logo. (you can edit them later).'),
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053048 fields: [
49 {
50 fieldtype: "Attach Image", fieldname: "attach_logo",
51 label: __("Attach Logo"),
52 description: __("100px by 100px"),
Makarand Bauskar1d9fd9a2017-07-26 18:19:41 +053053 is_private: 0,
54 align: 'center'
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053055 },
56 {
57 fieldname: 'company_name',
58 label: frappe.setup.domain === 'Education' ?
59 __('Institute Name') : __('Company Name'),
Makarand Bauskar1d9fd9a2017-07-26 18:19:41 +053060 fieldtype: 'Data',
61 reqd: 1
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053062 },
63 {
64 fieldname: 'company_abbr',
65 label: frappe.setup.domain === 'Education' ?
66 __('Institute Abbreviation') : __('Company Abbreviation'),
67 fieldtype: 'Data'
68 }
69 ],
70 onload: function(slide) {
71 this.bind_events(slide);
72 },
73 bind_events: function (slide) {
74 slide.get_input("company_name").on("change", function () {
75 var parts = slide.get_input("company_name").val().split(" ");
76 var abbr = $.map(parts, function (p) { return p ? p.substr(0, 1) : null }).join("");
Makarand Bauskar30f2bcb2017-07-11 12:36:57 +053077 slide.get_field("company_abbr").set_value(abbr.slice(0, 5).toUpperCase());
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053078 }).val(frappe.boot.sysdefaults.company_name || "").trigger("change");
Rushabh Mehta37b4d752015-11-09 16:53:11 +053079
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053080 slide.get_input("company_abbr").on("change", function () {
81 if (slide.get_input("company_abbr").val().length > 5) {
82 frappe.msgprint("Company Abbreviation cannot have more than 5 characters");
Makarand Bauskar30f2bcb2017-07-11 12:36:57 +053083 slide.get_field("company_abbr").set_value("");
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053084 }
85 });
Prateeksha Singh95d8fd32017-09-04 11:14:04 +053086 },
87 validate: function() {
88 if (!this.values.company_abbr) {
89 return false;
90 }
91 return true;
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053092 }
93 },
94 {
95 // Organisation
96 name: 'organisation',
97 domains: ["all"],
98 title: __("Your Organization"),
99 icon: "fa fa-building",
Prateeksha Singh95d8fd32017-09-04 11:14:04 +0530100 // help: (frappe.setup.domain === 'Education' ?
101 // __('The name of the institute for which you are setting up this system.') :
102 // __('The name of your company for which you are setting up this system.')),
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530103 fields: [
104 {
105 fieldname: 'company_tagline',
106 label: __('What does it do?'),
107 fieldtype: 'Data',
108 placeholder: frappe.setup.domain === 'Education' ?
109 __('e.g. "Primary School" or "University"') :
110 __('e.g. "Build tools for builders"'),
111 reqd: 1
112 },
113 { fieldname: 'bank_account', label: __('Bank Name'), fieldtype: 'Data', reqd: 1 },
114 {
115 fieldname: 'chart_of_accounts', label: __('Chart of Accounts'),
116 options: "", fieldtype: 'Select'
Anand Doshi1ed82832015-11-16 12:58:14 +0530117 },
118
strixaluco372a8812017-07-17 14:36:25 +0800119 { fieldtype: "Section Break", label: __('Financial Year') },
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530120 { fieldname: 'fy_start_date', label: __('Start Date'), fieldtype: 'Date', reqd: 1 },
121 { fieldtype: "Column Break" },
122 { fieldname: 'fy_end_date', label: __('End Date'), fieldtype: 'Date', reqd: 1 },
123 ],
124
125 onload: function (slide) {
126 this.load_chart_of_accounts(slide);
127 this.bind_events(slide);
128 this.set_fy_dates(slide);
129 },
130
131 validate: function () {
132 // validate fiscal year start and end dates
133 if (this.values.fy_start_date == 'Invalid date' || this.values.fy_end_date == 'Invalid date') {
134 frappe.msgprint(__("Please enter valid Financial Year Start and End Dates"));
135 return false;
136 }
137
138 if ((this.values.company_name || "").toLowerCase() == "company") {
139 frappe.msgprint(__("Company Name cannot be Company"));
140 return false;
141 }
142
143 return true;
144 },
145
146 set_fy_dates: function (slide) {
147 var country = frappe.wizard.values.country;
148
149 if (country) {
150 var fy = erpnext.setup.fiscal_years[country];
151 var current_year = moment(new Date()).year();
152 var next_year = current_year + 1;
153 if (!fy) {
Makarand Bauskarbf66d7e2017-07-05 17:26:34 +0530154 fy = ["01-01", "12-31"];
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530155 next_year = current_year;
Anand Doshi5c3469a2015-11-24 17:06:54 +0530156 }
157
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530158 var year_start_date = current_year + "-" + fy[0];
159 if (year_start_date > frappe.datetime.get_today()) {
Rushabh Mehta63b06422017-07-05 17:56:04 +0530160 next_year = current_year;
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530161 current_year -= 1;
Anand Doshi5c3469a2015-11-24 17:06:54 +0530162 }
Rushabh Mehta63b06422017-07-05 17:56:04 +0530163 slide.get_field("fy_start_date").set_value(current_year + '-' + fy[0]);
164 slide.get_field("fy_end_date").set_value(next_year + '-' + fy[1]);
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530165 }
Anand Doshi5c3469a2015-11-24 17:06:54 +0530166
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530167 },
Anand Doshi5c3469a2015-11-24 17:06:54 +0530168
Anand Doshi1ed82832015-11-16 12:58:14 +0530169
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530170 load_chart_of_accounts: function (slide) {
171 var country = frappe.wizard.values.country;
Anand Doshi1ed82832015-11-16 12:58:14 +0530172
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530173 if (country) {
174 frappe.call({
175 method: "erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts.get_charts_for_country",
176 args: { "country": country },
177 callback: function (r) {
178 if (r.message) {
179 slide.get_input("chart_of_accounts").empty()
180 .add_options(r.message);
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530181
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530182 if (r.message.length === 1) {
183 var field = slide.get_field("chart_of_accounts");
184 field.set_value(r.message[0]);
185 field.df.hidden = 1;
186 field.refresh();
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530187 }
188 }
Anand Doshi1ed82832015-11-16 12:58:14 +0530189 }
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530190 })
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530191 }
192 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530193
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530194 bind_events: function (slide) {
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530195 slide.get_input("fy_start_date").on("change", function () {
Rushabh Mehta63b06422017-07-05 17:56:04 +0530196 var start_date = slide.form.fields_dict.fy_start_date.get_value();
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530197 var year_end_date =
Rushabh Mehta63b06422017-07-05 17:56:04 +0530198 frappe.datetime.add_days(frappe.datetime.add_months(start_date, 12), -1);
199 slide.form.fields_dict.fy_end_date.set_value(year_end_date);
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530200 });
201 }
Anand Doshi31771382016-07-05 21:34:21 +0530202 }
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530203];
Anand Doshi31771382016-07-05 21:34:21 +0530204
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530205// Source: https://en.wikipedia.org/wiki/Fiscal_year
206// default 1st Jan - 31st Dec
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530207
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530208erpnext.setup.fiscal_years = {
Makarand Bauskarbf66d7e2017-07-05 17:26:34 +0530209 "Afghanistan": ["12-20", "12-21"],
210 "Australia": ["07-01", "06-30"],
211 "Bangladesh": ["07-01", "06-30"],
212 "Canada": ["04-01", "03-31"],
213 "Costa Rica": ["10-01", "09-30"],
214 "Egypt": ["07-01", "06-30"],
215 "Hong Kong": ["04-01", "03-31"],
216 "India": ["04-01", "03-31"],
217 "Iran": ["06-23", "06-22"],
218 "Italy": ["07-01", "06-30"],
219 "Myanmar": ["04-01", "03-31"],
220 "New Zealand": ["04-01", "03-31"],
221 "Pakistan": ["07-01", "06-30"],
222 "Singapore": ["04-01", "03-31"],
223 "South Africa": ["03-01", "02-28"],
224 "Thailand": ["10-01", "09-30"],
225 "United Kingdom": ["04-01", "03-31"],
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530226};
227
Prateeksha Singh95d8fd32017-09-04 11:14:04 +0530228// var test_values_edu = {
229// "language": "english",
230// "domain": "Education",
231// "country": "India",
232// "timezone": "Asia/Kolkata",
233// "currency": "INR",
234// "first_name": "Tester",
235// "email": "test@example.com",
236// "password": "test",
237// "company_name": "Hogwarts",
238// "company_abbr": "HS",
239// "company_tagline": "School for magicians",
240// "bank_account": "Gringotts Wizarding Bank",
241// "fy_start_date": "2016-04-01",
242// "fy_end_date": "2017-03-31"
243// }