blob: ded7cae91d6498dc9c228c44d84160841074d1f5 [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" },
Vishal397a8762017-11-20 17:45:24 +053028 { "label": __("Education (beta)"), "value": "Education" },
29 {"label": __("Healthcare (beta)"), "value": "Healthcare"},
30 {"label": __("Non Profit (beta)"), "value": "Non Profit"}
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053031 ], reqd: 1
Rushabh Mehta20038ad2016-07-21 16:01:59 +053032 },
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053033 ],
Prateeksha Singh95d8fd32017-09-04 11:14:04 +053034 // help: __('Select the nature of your business.'),
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053035 onload: function (slide) {
36 slide.get_input("domain").on("change", function () {
37 frappe.setup.domain = $(this).val();
38 frappe.wizard.refresh_slides();
39 });
Rushabh Mehta20038ad2016-07-21 16:01:59 +053040 },
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053041 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +053042
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053043 {
44 // Brand
45 name: 'brand',
46 domains: ["all"],
47 icon: "fa fa-bookmark",
48 title: __("The Brand"),
Prateeksha Singh95d8fd32017-09-04 11:14:04 +053049 // help: __('Upload your letter head and logo. (you can edit them later).'),
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053050 fields: [
51 {
52 fieldtype: "Attach Image", fieldname: "attach_logo",
53 label: __("Attach Logo"),
54 description: __("100px by 100px"),
Makarand Bauskar1d9fd9a2017-07-26 18:19:41 +053055 is_private: 0,
56 align: 'center'
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053057 },
58 {
59 fieldname: 'company_name',
60 label: frappe.setup.domain === 'Education' ?
61 __('Institute Name') : __('Company Name'),
Makarand Bauskar1d9fd9a2017-07-26 18:19:41 +053062 fieldtype: 'Data',
63 reqd: 1
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053064 },
65 {
66 fieldname: 'company_abbr',
67 label: frappe.setup.domain === 'Education' ?
68 __('Institute Abbreviation') : __('Company Abbreviation'),
69 fieldtype: 'Data'
70 }
71 ],
72 onload: function(slide) {
73 this.bind_events(slide);
74 },
75 bind_events: function (slide) {
76 slide.get_input("company_name").on("change", function () {
77 var parts = slide.get_input("company_name").val().split(" ");
78 var abbr = $.map(parts, function (p) { return p ? p.substr(0, 1) : null }).join("");
Makarand Bauskar30f2bcb2017-07-11 12:36:57 +053079 slide.get_field("company_abbr").set_value(abbr.slice(0, 5).toUpperCase());
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053080 }).val(frappe.boot.sysdefaults.company_name || "").trigger("change");
Rushabh Mehta37b4d752015-11-09 16:53:11 +053081
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053082 slide.get_input("company_abbr").on("change", function () {
83 if (slide.get_input("company_abbr").val().length > 5) {
84 frappe.msgprint("Company Abbreviation cannot have more than 5 characters");
Makarand Bauskar30f2bcb2017-07-11 12:36:57 +053085 slide.get_field("company_abbr").set_value("");
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053086 }
87 });
Prateeksha Singh95d8fd32017-09-04 11:14:04 +053088 },
89 validate: function() {
Makarand Bauskarb1bf5022017-10-02 11:38:03 +053090 if ((this.values.company_name || "").toLowerCase() == "company") {
91 frappe.msgprint(__("Company Name cannot be Company"));
92 return false;
93 }
Prateeksha Singh95d8fd32017-09-04 11:14:04 +053094 if (!this.values.company_abbr) {
95 return false;
96 }
97 return true;
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +053098 }
99 },
100 {
101 // Organisation
102 name: 'organisation',
103 domains: ["all"],
104 title: __("Your Organization"),
105 icon: "fa fa-building",
Prateeksha Singh95d8fd32017-09-04 11:14:04 +0530106 // help: (frappe.setup.domain === 'Education' ?
107 // __('The name of the institute for which you are setting up this system.') :
108 // __('The name of your company for which you are setting up this system.')),
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530109 fields: [
110 {
111 fieldname: 'company_tagline',
112 label: __('What does it do?'),
113 fieldtype: 'Data',
114 placeholder: frappe.setup.domain === 'Education' ?
115 __('e.g. "Primary School" or "University"') :
116 __('e.g. "Build tools for builders"'),
117 reqd: 1
118 },
119 { fieldname: 'bank_account', label: __('Bank Name'), fieldtype: 'Data', reqd: 1 },
120 {
121 fieldname: 'chart_of_accounts', label: __('Chart of Accounts'),
122 options: "", fieldtype: 'Select'
Anand Doshi1ed82832015-11-16 12:58:14 +0530123 },
124
strixaluco372a8812017-07-17 14:36:25 +0800125 { fieldtype: "Section Break", label: __('Financial Year') },
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530126 { fieldname: 'fy_start_date', label: __('Start Date'), fieldtype: 'Date', reqd: 1 },
127 { fieldtype: "Column Break" },
128 { fieldname: 'fy_end_date', label: __('End Date'), fieldtype: 'Date', reqd: 1 },
129 ],
130
131 onload: function (slide) {
132 this.load_chart_of_accounts(slide);
133 this.bind_events(slide);
134 this.set_fy_dates(slide);
135 },
136
137 validate: function () {
138 // validate fiscal year start and end dates
139 if (this.values.fy_start_date == 'Invalid date' || this.values.fy_end_date == 'Invalid date') {
140 frappe.msgprint(__("Please enter valid Financial Year Start and End Dates"));
141 return false;
142 }
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530143 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 }
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530166 },
Anand Doshi5c3469a2015-11-24 17:06:54 +0530167
Anand Doshi1ed82832015-11-16 12:58:14 +0530168
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530169 load_chart_of_accounts: function (slide) {
170 var country = frappe.wizard.values.country;
Anand Doshi1ed82832015-11-16 12:58:14 +0530171
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530172 if (country) {
173 frappe.call({
174 method: "erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts.get_charts_for_country",
175 args: { "country": country },
176 callback: function (r) {
177 if (r.message) {
178 slide.get_input("chart_of_accounts").empty()
179 .add_options(r.message);
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530180
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530181 if (r.message.length === 1) {
182 var field = slide.get_field("chart_of_accounts");
183 field.set_value(r.message[0]);
184 field.df.hidden = 1;
185 field.refresh();
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530186 }
187 }
Anand Doshi1ed82832015-11-16 12:58:14 +0530188 }
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530189 })
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530190 }
191 },
Rushabh Mehta37b4d752015-11-09 16:53:11 +0530192
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530193 bind_events: function (slide) {
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530194 slide.get_input("fy_start_date").on("change", function () {
Rushabh Mehta63b06422017-07-05 17:56:04 +0530195 var start_date = slide.form.fields_dict.fy_start_date.get_value();
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530196 var year_end_date =
Rushabh Mehta63b06422017-07-05 17:56:04 +0530197 frappe.datetime.add_days(frappe.datetime.add_months(start_date, 12), -1);
198 slide.form.fields_dict.fy_end_date.set_value(year_end_date);
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530199 });
200 }
Anand Doshi31771382016-07-05 21:34:21 +0530201 }
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530202];
Anand Doshi31771382016-07-05 21:34:21 +0530203
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530204// Source: https://en.wikipedia.org/wiki/Fiscal_year
205// default 1st Jan - 31st Dec
Rushabh Mehta20038ad2016-07-21 16:01:59 +0530206
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530207erpnext.setup.fiscal_years = {
Makarand Bauskarbf66d7e2017-07-05 17:26:34 +0530208 "Afghanistan": ["12-20", "12-21"],
209 "Australia": ["07-01", "06-30"],
210 "Bangladesh": ["07-01", "06-30"],
211 "Canada": ["04-01", "03-31"],
212 "Costa Rica": ["10-01", "09-30"],
213 "Egypt": ["07-01", "06-30"],
214 "Hong Kong": ["04-01", "03-31"],
215 "India": ["04-01", "03-31"],
216 "Iran": ["06-23", "06-22"],
217 "Italy": ["07-01", "06-30"],
218 "Myanmar": ["04-01", "03-31"],
219 "New Zealand": ["04-01", "03-31"],
220 "Pakistan": ["07-01", "06-30"],
221 "Singapore": ["04-01", "03-31"],
222 "South Africa": ["03-01", "02-28"],
223 "Thailand": ["10-01", "09-30"],
224 "United Kingdom": ["04-01", "03-31"],
Prateeksha Singh5e4c8ec2017-07-03 18:23:57 +0530225};