Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 1 | frappe.provide("erpnext.setup"); |
Rushabh Mehta | 37b4d75 | 2015-11-09 16:53:11 +0530 | [diff] [blame] | 2 | |
| 3 | frappe.pages['setup-wizard'].on_page_load = function(wrapper) { |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 4 | if(frappe.sys_defaults.company) { |
Rushabh Mehta | 37b4d75 | 2015-11-09 16:53:11 +0530 | [diff] [blame] | 5 | frappe.set_route("desk"); |
| 6 | return; |
| 7 | } |
Anand Doshi | 1ed8283 | 2015-11-16 12:58:14 +0530 | [diff] [blame] | 8 | }; |
Rushabh Mehta | 37b4d75 | 2015-11-09 16:53:11 +0530 | [diff] [blame] | 9 | |
Prateeksha Singh | 95d8fd3 | 2017-09-04 11:14:04 +0530 | [diff] [blame] | 10 | frappe.setup.on("before_load", function () { |
| 11 | erpnext.setup.slides_settings.map(frappe.setup.add_slide); |
| 12 | }); |
| 13 | |
| 14 | erpnext.setup.slides_settings = [ |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 15 | { |
| 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 Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 25 | { "label": __("Manufacturing"), "value": "Manufacturing" }, |
| 26 | { "label": __("Retail"), "value": "Retail" }, |
Prateeksha Singh | 95d8fd3 | 2017-09-04 11:14:04 +0530 | [diff] [blame] | 27 | { "label": __("Services"), "value": "Services" }, |
Rushabh Mehta | f056974 | 2017-09-13 12:52:30 +0530 | [diff] [blame] | 28 | { "label": __("Education (beta)"), "value": "Education" }, |
| 29 | {"label": __("Healthcare (beta)"), "value": "Healthcare"} |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 30 | ], reqd: 1 |
Rushabh Mehta | 20038ad | 2016-07-21 16:01:59 +0530 | [diff] [blame] | 31 | }, |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 32 | ], |
Prateeksha Singh | 95d8fd3 | 2017-09-04 11:14:04 +0530 | [diff] [blame] | 33 | // help: __('Select the nature of your business.'), |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 34 | onload: function (slide) { |
| 35 | slide.get_input("domain").on("change", function () { |
| 36 | frappe.setup.domain = $(this).val(); |
| 37 | frappe.wizard.refresh_slides(); |
| 38 | }); |
Rushabh Mehta | 20038ad | 2016-07-21 16:01:59 +0530 | [diff] [blame] | 39 | }, |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 40 | }, |
Rushabh Mehta | 37b4d75 | 2015-11-09 16:53:11 +0530 | [diff] [blame] | 41 | |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 42 | { |
| 43 | // Brand |
| 44 | name: 'brand', |
| 45 | domains: ["all"], |
| 46 | icon: "fa fa-bookmark", |
| 47 | title: __("The Brand"), |
Prateeksha Singh | 95d8fd3 | 2017-09-04 11:14:04 +0530 | [diff] [blame] | 48 | // help: __('Upload your letter head and logo. (you can edit them later).'), |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 49 | fields: [ |
| 50 | { |
| 51 | fieldtype: "Attach Image", fieldname: "attach_logo", |
| 52 | label: __("Attach Logo"), |
| 53 | description: __("100px by 100px"), |
Makarand Bauskar | 1d9fd9a | 2017-07-26 18:19:41 +0530 | [diff] [blame] | 54 | is_private: 0, |
| 55 | align: 'center' |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 56 | }, |
| 57 | { |
| 58 | fieldname: 'company_name', |
| 59 | label: frappe.setup.domain === 'Education' ? |
| 60 | __('Institute Name') : __('Company Name'), |
Makarand Bauskar | 1d9fd9a | 2017-07-26 18:19:41 +0530 | [diff] [blame] | 61 | fieldtype: 'Data', |
| 62 | reqd: 1 |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 63 | }, |
| 64 | { |
| 65 | fieldname: 'company_abbr', |
| 66 | label: frappe.setup.domain === 'Education' ? |
| 67 | __('Institute Abbreviation') : __('Company Abbreviation'), |
| 68 | fieldtype: 'Data' |
| 69 | } |
| 70 | ], |
| 71 | onload: function(slide) { |
| 72 | this.bind_events(slide); |
| 73 | }, |
| 74 | bind_events: function (slide) { |
| 75 | slide.get_input("company_name").on("change", function () { |
| 76 | var parts = slide.get_input("company_name").val().split(" "); |
| 77 | var abbr = $.map(parts, function (p) { return p ? p.substr(0, 1) : null }).join(""); |
Makarand Bauskar | 30f2bcb | 2017-07-11 12:36:57 +0530 | [diff] [blame] | 78 | slide.get_field("company_abbr").set_value(abbr.slice(0, 5).toUpperCase()); |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 79 | }).val(frappe.boot.sysdefaults.company_name || "").trigger("change"); |
Rushabh Mehta | 37b4d75 | 2015-11-09 16:53:11 +0530 | [diff] [blame] | 80 | |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 81 | slide.get_input("company_abbr").on("change", function () { |
| 82 | if (slide.get_input("company_abbr").val().length > 5) { |
| 83 | frappe.msgprint("Company Abbreviation cannot have more than 5 characters"); |
Makarand Bauskar | 30f2bcb | 2017-07-11 12:36:57 +0530 | [diff] [blame] | 84 | slide.get_field("company_abbr").set_value(""); |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 85 | } |
| 86 | }); |
Prateeksha Singh | 95d8fd3 | 2017-09-04 11:14:04 +0530 | [diff] [blame] | 87 | }, |
| 88 | validate: function() { |
Makarand Bauskar | b1bf502 | 2017-10-02 11:38:03 +0530 | [diff] [blame] | 89 | if ((this.values.company_name || "").toLowerCase() == "company") { |
| 90 | frappe.msgprint(__("Company Name cannot be Company")); |
| 91 | return false; |
| 92 | } |
Prateeksha Singh | 95d8fd3 | 2017-09-04 11:14:04 +0530 | [diff] [blame] | 93 | if (!this.values.company_abbr) { |
| 94 | return false; |
| 95 | } |
| 96 | return true; |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 97 | } |
| 98 | }, |
| 99 | { |
| 100 | // Organisation |
| 101 | name: 'organisation', |
| 102 | domains: ["all"], |
| 103 | title: __("Your Organization"), |
| 104 | icon: "fa fa-building", |
Prateeksha Singh | 95d8fd3 | 2017-09-04 11:14:04 +0530 | [diff] [blame] | 105 | // help: (frappe.setup.domain === 'Education' ? |
| 106 | // __('The name of the institute for which you are setting up this system.') : |
| 107 | // __('The name of your company for which you are setting up this system.')), |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 108 | fields: [ |
| 109 | { |
| 110 | fieldname: 'company_tagline', |
| 111 | label: __('What does it do?'), |
| 112 | fieldtype: 'Data', |
| 113 | placeholder: frappe.setup.domain === 'Education' ? |
| 114 | __('e.g. "Primary School" or "University"') : |
| 115 | __('e.g. "Build tools for builders"'), |
| 116 | reqd: 1 |
| 117 | }, |
| 118 | { fieldname: 'bank_account', label: __('Bank Name'), fieldtype: 'Data', reqd: 1 }, |
| 119 | { |
| 120 | fieldname: 'chart_of_accounts', label: __('Chart of Accounts'), |
| 121 | options: "", fieldtype: 'Select' |
Anand Doshi | 1ed8283 | 2015-11-16 12:58:14 +0530 | [diff] [blame] | 122 | }, |
| 123 | |
strixaluco | 372a881 | 2017-07-17 14:36:25 +0800 | [diff] [blame] | 124 | { fieldtype: "Section Break", label: __('Financial Year') }, |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 125 | { fieldname: 'fy_start_date', label: __('Start Date'), fieldtype: 'Date', reqd: 1 }, |
| 126 | { fieldtype: "Column Break" }, |
| 127 | { fieldname: 'fy_end_date', label: __('End Date'), fieldtype: 'Date', reqd: 1 }, |
| 128 | ], |
| 129 | |
| 130 | onload: function (slide) { |
| 131 | this.load_chart_of_accounts(slide); |
| 132 | this.bind_events(slide); |
| 133 | this.set_fy_dates(slide); |
| 134 | }, |
| 135 | |
| 136 | validate: function () { |
| 137 | // validate fiscal year start and end dates |
| 138 | if (this.values.fy_start_date == 'Invalid date' || this.values.fy_end_date == 'Invalid date') { |
| 139 | frappe.msgprint(__("Please enter valid Financial Year Start and End Dates")); |
| 140 | return false; |
| 141 | } |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 142 | return true; |
| 143 | }, |
| 144 | |
| 145 | set_fy_dates: function (slide) { |
| 146 | var country = frappe.wizard.values.country; |
| 147 | |
| 148 | if (country) { |
| 149 | var fy = erpnext.setup.fiscal_years[country]; |
| 150 | var current_year = moment(new Date()).year(); |
| 151 | var next_year = current_year + 1; |
| 152 | if (!fy) { |
Makarand Bauskar | bf66d7e | 2017-07-05 17:26:34 +0530 | [diff] [blame] | 153 | fy = ["01-01", "12-31"]; |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 154 | next_year = current_year; |
Anand Doshi | 5c3469a | 2015-11-24 17:06:54 +0530 | [diff] [blame] | 155 | } |
| 156 | |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 157 | var year_start_date = current_year + "-" + fy[0]; |
| 158 | if (year_start_date > frappe.datetime.get_today()) { |
Rushabh Mehta | 63b0642 | 2017-07-05 17:56:04 +0530 | [diff] [blame] | 159 | next_year = current_year; |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 160 | current_year -= 1; |
Anand Doshi | 5c3469a | 2015-11-24 17:06:54 +0530 | [diff] [blame] | 161 | } |
Rushabh Mehta | 63b0642 | 2017-07-05 17:56:04 +0530 | [diff] [blame] | 162 | slide.get_field("fy_start_date").set_value(current_year + '-' + fy[0]); |
| 163 | slide.get_field("fy_end_date").set_value(next_year + '-' + fy[1]); |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 164 | } |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 165 | }, |
Anand Doshi | 5c3469a | 2015-11-24 17:06:54 +0530 | [diff] [blame] | 166 | |
Anand Doshi | 1ed8283 | 2015-11-16 12:58:14 +0530 | [diff] [blame] | 167 | |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 168 | load_chart_of_accounts: function (slide) { |
| 169 | var country = frappe.wizard.values.country; |
Anand Doshi | 1ed8283 | 2015-11-16 12:58:14 +0530 | [diff] [blame] | 170 | |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 171 | if (country) { |
| 172 | frappe.call({ |
| 173 | method: "erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts.get_charts_for_country", |
| 174 | args: { "country": country }, |
| 175 | callback: function (r) { |
| 176 | if (r.message) { |
| 177 | slide.get_input("chart_of_accounts").empty() |
| 178 | .add_options(r.message); |
Rushabh Mehta | 37b4d75 | 2015-11-09 16:53:11 +0530 | [diff] [blame] | 179 | |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 180 | if (r.message.length === 1) { |
| 181 | var field = slide.get_field("chart_of_accounts"); |
| 182 | field.set_value(r.message[0]); |
| 183 | field.df.hidden = 1; |
| 184 | field.refresh(); |
Rushabh Mehta | 37b4d75 | 2015-11-09 16:53:11 +0530 | [diff] [blame] | 185 | } |
| 186 | } |
Anand Doshi | 1ed8283 | 2015-11-16 12:58:14 +0530 | [diff] [blame] | 187 | } |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 188 | }) |
Rushabh Mehta | 37b4d75 | 2015-11-09 16:53:11 +0530 | [diff] [blame] | 189 | } |
| 190 | }, |
Rushabh Mehta | 37b4d75 | 2015-11-09 16:53:11 +0530 | [diff] [blame] | 191 | |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 192 | bind_events: function (slide) { |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 193 | slide.get_input("fy_start_date").on("change", function () { |
Rushabh Mehta | 63b0642 | 2017-07-05 17:56:04 +0530 | [diff] [blame] | 194 | var start_date = slide.form.fields_dict.fy_start_date.get_value(); |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 195 | var year_end_date = |
Rushabh Mehta | 63b0642 | 2017-07-05 17:56:04 +0530 | [diff] [blame] | 196 | frappe.datetime.add_days(frappe.datetime.add_months(start_date, 12), -1); |
| 197 | slide.form.fields_dict.fy_end_date.set_value(year_end_date); |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 198 | }); |
| 199 | } |
Anand Doshi | 3177138 | 2016-07-05 21:34:21 +0530 | [diff] [blame] | 200 | } |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 201 | ]; |
Anand Doshi | 3177138 | 2016-07-05 21:34:21 +0530 | [diff] [blame] | 202 | |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 203 | // Source: https://en.wikipedia.org/wiki/Fiscal_year |
| 204 | // default 1st Jan - 31st Dec |
Rushabh Mehta | 20038ad | 2016-07-21 16:01:59 +0530 | [diff] [blame] | 205 | |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 206 | erpnext.setup.fiscal_years = { |
Makarand Bauskar | bf66d7e | 2017-07-05 17:26:34 +0530 | [diff] [blame] | 207 | "Afghanistan": ["12-20", "12-21"], |
| 208 | "Australia": ["07-01", "06-30"], |
| 209 | "Bangladesh": ["07-01", "06-30"], |
| 210 | "Canada": ["04-01", "03-31"], |
| 211 | "Costa Rica": ["10-01", "09-30"], |
| 212 | "Egypt": ["07-01", "06-30"], |
| 213 | "Hong Kong": ["04-01", "03-31"], |
| 214 | "India": ["04-01", "03-31"], |
| 215 | "Iran": ["06-23", "06-22"], |
| 216 | "Italy": ["07-01", "06-30"], |
| 217 | "Myanmar": ["04-01", "03-31"], |
| 218 | "New Zealand": ["04-01", "03-31"], |
| 219 | "Pakistan": ["07-01", "06-30"], |
| 220 | "Singapore": ["04-01", "03-31"], |
| 221 | "South Africa": ["03-01", "02-28"], |
| 222 | "Thailand": ["10-01", "09-30"], |
| 223 | "United Kingdom": ["04-01", "03-31"], |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 224 | }; |
| 225 | |
Prateeksha Singh | 95d8fd3 | 2017-09-04 11:14:04 +0530 | [diff] [blame] | 226 | // var test_values_edu = { |
| 227 | // "language": "english", |
| 228 | // "domain": "Education", |
| 229 | // "country": "India", |
| 230 | // "timezone": "Asia/Kolkata", |
| 231 | // "currency": "INR", |
| 232 | // "first_name": "Tester", |
| 233 | // "email": "test@example.com", |
| 234 | // "password": "test", |
| 235 | // "company_name": "Hogwarts", |
| 236 | // "company_abbr": "HS", |
| 237 | // "company_tagline": "School for magicians", |
| 238 | // "bank_account": "Gringotts Wizarding Bank", |
| 239 | // "fy_start_date": "2016-04-01", |
| 240 | // "fy_end_date": "2017-03-31" |
| 241 | // } |