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 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 3 | frappe.pages["setup-wizard"].on_page_load = function (wrapper) { |
| 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 | { |
Deepesh Garg | 3598bcc | 2023-01-27 14:40:39 +0530 | [diff] [blame] | 16 | // Organization |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 17 | name: "organization", |
Deepesh Garg | 3598bcc | 2023-01-27 14:40:39 +0530 | [diff] [blame] | 18 | title: __("Setup your organization"), |
| 19 | icon: "fa fa-building", |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 20 | fields: [ |
| 21 | { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 22 | fieldname: "company_name", |
| 23 | label: __("Company Name"), |
| 24 | fieldtype: "Data", |
| 25 | reqd: 1, |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 26 | }, |
Bernd Oliver Sünderhauf | bc8d05d | 2023-07-30 19:04:03 +0200 | [diff] [blame] | 27 | { fieldtype: "Column Break" }, |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 28 | { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 29 | fieldname: "company_abbr", |
| 30 | label: __("Company Abbreviation"), |
| 31 | fieldtype: "Data", |
| 32 | reqd: 1, |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 33 | }, |
Bernd Oliver Sünderhauf | bc8d05d | 2023-07-30 19:04:03 +0200 | [diff] [blame] | 34 | { fieldtype: "Section Break" }, |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 35 | { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 36 | fieldname: "chart_of_accounts", |
| 37 | label: __("Chart of Accounts"), |
| 38 | options: "", |
| 39 | fieldtype: "Select", |
Anand Doshi | 1ed8283 | 2015-11-16 12:58:14 +0530 | [diff] [blame] | 40 | }, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 41 | { fieldname: "view_coa", label: __("View Chart of Accounts"), fieldtype: "Button" }, |
| 42 | { fieldname: "fy_start_date", label: __("Financial Year Begins On"), fieldtype: "Date", reqd: 1 }, |
Rushabh Mehta | 2cd41bc | 2020-12-18 13:17:58 +0530 | [diff] [blame] | 43 | // end date should be hidden (auto calculated) |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 44 | { fieldname: "fy_end_date", label: __("End Date"), fieldtype: "Date", reqd: 1, hidden: 1 }, |
Ankush Menat | 3a21c90 | 2023-08-10 15:48:57 +0530 | [diff] [blame] | 45 | { fieldtype: "Section Break" }, |
| 46 | { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 47 | fieldname: "setup_demo", |
| 48 | label: __("Generate Demo Data for Exploration"), |
| 49 | fieldtype: "Check", |
| 50 | description: __( |
| 51 | "If checked, we will create demo data for you to explore the system. This demo data can be erased later." |
| 52 | ), |
Deepesh Garg | 6349b67 | 2023-08-24 17:54:14 +0530 | [diff] [blame] | 53 | }, |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 54 | ], |
| 55 | |
| 56 | onload: function (slide) { |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 57 | this.bind_events(slide); |
Deepesh Garg | 3598bcc | 2023-01-27 14:40:39 +0530 | [diff] [blame] | 58 | this.load_chart_of_accounts(slide); |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 59 | this.set_fy_dates(slide); |
| 60 | }, |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 61 | validate: function () { |
Faris Ansari | aa856c4 | 2018-09-18 10:42:04 +0530 | [diff] [blame] | 62 | if (!this.validate_fy_dates()) { |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 63 | return false; |
| 64 | } |
Zarrar | 441a1e1 | 2018-02-16 14:44:42 +0530 | [diff] [blame] | 65 | |
Deepesh Garg | 3598bcc | 2023-01-27 14:40:39 +0530 | [diff] [blame] | 66 | if ((this.values.company_name || "").toLowerCase() == "company") { |
| 67 | frappe.msgprint(__("Company Name cannot be Company")); |
| 68 | return false; |
| 69 | } |
| 70 | if (!this.values.company_abbr) { |
| 71 | return false; |
| 72 | } |
| 73 | if (this.values.company_abbr.length > 10) { |
| 74 | return false; |
Deepesh Garg | 2908f2e | 2021-06-26 23:49:32 +0530 | [diff] [blame] | 75 | } |
| 76 | |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 77 | return true; |
| 78 | }, |
| 79 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 80 | validate_fy_dates: function () { |
Faris Ansari | aa856c4 | 2018-09-18 10:42:04 +0530 | [diff] [blame] | 81 | // validate fiscal year start and end dates |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 82 | const invalid = |
| 83 | this.values.fy_start_date == "Invalid date" || this.values.fy_end_date == "Invalid date"; |
Faris Ansari | aa856c4 | 2018-09-18 10:42:04 +0530 | [diff] [blame] | 84 | const start_greater_than_end = this.values.fy_start_date > this.values.fy_end_date; |
| 85 | |
| 86 | if (invalid || start_greater_than_end) { |
| 87 | frappe.msgprint(__("Please enter valid Financial Year Start and End Dates")); |
| 88 | return false; |
| 89 | } |
| 90 | |
| 91 | return true; |
| 92 | }, |
| 93 | |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 94 | set_fy_dates: function (slide) { |
| 95 | var country = frappe.wizard.values.country; |
| 96 | |
| 97 | if (country) { |
Deepesh Garg | 3598bcc | 2023-01-27 14:40:39 +0530 | [diff] [blame] | 98 | let fy = erpnext.setup.fiscal_years[country]; |
| 99 | let current_year = moment(new Date()).year(); |
| 100 | let next_year = current_year + 1; |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 101 | if (!fy) { |
Makarand Bauskar | bf66d7e | 2017-07-05 17:26:34 +0530 | [diff] [blame] | 102 | fy = ["01-01", "12-31"]; |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 103 | next_year = current_year; |
Anand Doshi | 5c3469a | 2015-11-24 17:06:54 +0530 | [diff] [blame] | 104 | } |
| 105 | |
Deepesh Garg | 3598bcc | 2023-01-27 14:40:39 +0530 | [diff] [blame] | 106 | let year_start_date = current_year + "-" + fy[0]; |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 107 | if (year_start_date > frappe.datetime.get_today()) { |
Rushabh Mehta | 63b0642 | 2017-07-05 17:56:04 +0530 | [diff] [blame] | 108 | next_year = current_year; |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 109 | current_year -= 1; |
Anand Doshi | 5c3469a | 2015-11-24 17:06:54 +0530 | [diff] [blame] | 110 | } |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 111 | slide.get_field("fy_start_date").set_value(current_year + "-" + fy[0]); |
| 112 | slide.get_field("fy_end_date").set_value(next_year + "-" + fy[1]); |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 113 | } |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 114 | }, |
Anand Doshi | 5c3469a | 2015-11-24 17:06:54 +0530 | [diff] [blame] | 115 | |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 116 | load_chart_of_accounts: function (slide) { |
Deepesh Garg | 3598bcc | 2023-01-27 14:40:39 +0530 | [diff] [blame] | 117 | let country = frappe.wizard.values.country; |
Anand Doshi | 1ed8283 | 2015-11-16 12:58:14 +0530 | [diff] [blame] | 118 | |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 119 | if (country) { |
| 120 | frappe.call({ |
| 121 | method: "erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts.get_charts_for_country", |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 122 | args: { country: country, with_standard: true }, |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 123 | callback: function (r) { |
| 124 | if (r.message) { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 125 | slide.get_input("chart_of_accounts").empty().add_options(r.message); |
Rushabh Mehta | 37b4d75 | 2015-11-09 16:53:11 +0530 | [diff] [blame] | 126 | } |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 127 | }, |
| 128 | }); |
Rushabh Mehta | 37b4d75 | 2015-11-09 16:53:11 +0530 | [diff] [blame] | 129 | } |
| 130 | }, |
Rushabh Mehta | 37b4d75 | 2015-11-09 16:53:11 +0530 | [diff] [blame] | 131 | |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 132 | bind_events: function (slide) { |
Zarrar | 254ce64 | 2018-06-28 14:15:34 +0530 | [diff] [blame] | 133 | let me = this; |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 134 | slide.get_input("fy_start_date").on("change", function () { |
Rushabh Mehta | 63b0642 | 2017-07-05 17:56:04 +0530 | [diff] [blame] | 135 | var start_date = slide.form.fields_dict.fy_start_date.get_value(); |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 136 | var year_end_date = frappe.datetime.add_days(frappe.datetime.add_months(start_date, 12), -1); |
Rushabh Mehta | 63b0642 | 2017-07-05 17:56:04 +0530 | [diff] [blame] | 137 | slide.form.fields_dict.fy_end_date.set_value(year_end_date); |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 138 | }); |
Zarrar | 254ce64 | 2018-06-28 14:15:34 +0530 | [diff] [blame] | 139 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 140 | slide.get_input("view_coa").on("click", function () { |
Zarrar | 254ce64 | 2018-06-28 14:15:34 +0530 | [diff] [blame] | 141 | let chart_template = slide.form.fields_dict.chart_of_accounts.get_value(); |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 142 | if (!chart_template) return; |
Zarrar | 254ce64 | 2018-06-28 14:15:34 +0530 | [diff] [blame] | 143 | |
| 144 | me.charts_modal(slide, chart_template); |
| 145 | }); |
Deepesh Garg | 3598bcc | 2023-01-27 14:40:39 +0530 | [diff] [blame] | 146 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 147 | slide |
| 148 | .get_input("company_name") |
| 149 | .on("input", function () { |
| 150 | let parts = slide.get_input("company_name").val().split(" "); |
| 151 | let abbr = $.map(parts, function (p) { |
| 152 | return p ? p.substr(0, 1) : null; |
| 153 | }).join(""); |
| 154 | slide.get_field("company_abbr").set_value(abbr.slice(0, 10).toUpperCase()); |
| 155 | }) |
| 156 | .val(frappe.boot.sysdefaults.company_name || "") |
| 157 | .trigger("change"); |
Deepesh Garg | 3598bcc | 2023-01-27 14:40:39 +0530 | [diff] [blame] | 158 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 159 | slide |
| 160 | .get_input("company_abbr") |
| 161 | .on("change", function () { |
| 162 | let abbr = slide.get_input("company_abbr").val(); |
| 163 | if (abbr.length > 10) { |
| 164 | frappe.msgprint(__("Company Abbreviation cannot have more than 5 characters")); |
| 165 | abbr = abbr.slice(0, 10); |
| 166 | } |
| 167 | slide.get_field("company_abbr").set_value(abbr); |
| 168 | }) |
| 169 | .val(frappe.boot.sysdefaults.company_abbr || "") |
| 170 | .trigger("change"); |
Zarrar | 254ce64 | 2018-06-28 14:15:34 +0530 | [diff] [blame] | 171 | }, |
| 172 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 173 | charts_modal: function (slide, chart_template) { |
| 174 | let parent = __("All Accounts"); |
Zarrar | 254ce64 | 2018-06-28 14:15:34 +0530 | [diff] [blame] | 175 | |
Deepesh Garg | 3598bcc | 2023-01-27 14:40:39 +0530 | [diff] [blame] | 176 | let dialog = new frappe.ui.Dialog({ |
Zarrar | 254ce64 | 2018-06-28 14:15:34 +0530 | [diff] [blame] | 177 | title: chart_template, |
| 178 | fields: [ |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 179 | { |
| 180 | fieldname: "expand_all", |
| 181 | label: __("Expand All"), |
| 182 | fieldtype: "Button", |
| 183 | click: function () { |
Zarrar | 254ce64 | 2018-06-28 14:15:34 +0530 | [diff] [blame] | 184 | // expand all nodes on button click |
| 185 | coa_tree.load_children(coa_tree.root_node, true); |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 186 | }, |
Zarrar | 254ce64 | 2018-06-28 14:15:34 +0530 | [diff] [blame] | 187 | }, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 188 | { |
| 189 | fieldname: "collapse_all", |
| 190 | label: __("Collapse All"), |
| 191 | fieldtype: "Button", |
| 192 | click: function () { |
Zarrar | 254ce64 | 2018-06-28 14:15:34 +0530 | [diff] [blame] | 193 | // collapse all nodes |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 194 | coa_tree |
| 195 | .get_all_nodes(coa_tree.root_node.data.value, coa_tree.root_node.is_root) |
| 196 | .then((data_list) => { |
| 197 | data_list.map((d) => { |
| 198 | coa_tree.toggle_node(coa_tree.nodes[d.parent]); |
| 199 | }); |
Zarrar | 254ce64 | 2018-06-28 14:15:34 +0530 | [diff] [blame] | 200 | }); |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 201 | }, |
| 202 | }, |
| 203 | ], |
Zarrar | 254ce64 | 2018-06-28 14:15:34 +0530 | [diff] [blame] | 204 | }); |
| 205 | |
| 206 | // render tree structure in the dialog modal |
| 207 | let coa_tree = new frappe.ui.Tree({ |
| 208 | parent: $(dialog.body), |
| 209 | label: parent, |
| 210 | expandable: true, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 211 | method: "erpnext.accounts.utils.get_coa", |
Zarrar | 254ce64 | 2018-06-28 14:15:34 +0530 | [diff] [blame] | 212 | args: { |
| 213 | chart: chart_template, |
| 214 | parent: parent, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 215 | doctype: "Account", |
Zarrar | 254ce64 | 2018-06-28 14:15:34 +0530 | [diff] [blame] | 216 | }, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 217 | onclick: function (node) { |
Zarrar | 254ce64 | 2018-06-28 14:15:34 +0530 | [diff] [blame] | 218 | parent = node.value; |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 219 | }, |
Zarrar | 254ce64 | 2018-06-28 14:15:34 +0530 | [diff] [blame] | 220 | }); |
| 221 | |
| 222 | // add class to show buttons side by side |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 223 | const form_container = $(dialog.body).find("form"); |
| 224 | const buttons = $(form_container).find(".frappe-control"); |
| 225 | form_container.addClass("flex"); |
Zarrar | c1225a8 | 2018-07-03 10:35:31 +0530 | [diff] [blame] | 226 | buttons.map((index, button) => { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 227 | $(button).css({ "margin-right": "1em" }); |
| 228 | }); |
Zarrar | 254ce64 | 2018-06-28 14:15:34 +0530 | [diff] [blame] | 229 | |
| 230 | dialog.show(); |
| 231 | coa_tree.load_children(coa_tree.root_node, true); // expand all node trigger |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 232 | }, |
| 233 | }, |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 234 | ]; |
Anand Doshi | 3177138 | 2016-07-05 21:34:21 +0530 | [diff] [blame] | 235 | |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 236 | // Source: https://en.wikipedia.org/wiki/Fiscal_year |
| 237 | // default 1st Jan - 31st Dec |
Rushabh Mehta | 20038ad | 2016-07-21 16:01:59 +0530 | [diff] [blame] | 238 | |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 239 | erpnext.setup.fiscal_years = { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 240 | Afghanistan: ["12-21", "12-20"], |
| 241 | Australia: ["07-01", "06-30"], |
| 242 | Bangladesh: ["07-01", "06-30"], |
| 243 | Canada: ["04-01", "03-31"], |
Makarand Bauskar | bf66d7e | 2017-07-05 17:26:34 +0530 | [diff] [blame] | 244 | "Costa Rica": ["10-01", "09-30"], |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 245 | Egypt: ["07-01", "06-30"], |
Makarand Bauskar | bf66d7e | 2017-07-05 17:26:34 +0530 | [diff] [blame] | 246 | "Hong Kong": ["04-01", "03-31"], |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 247 | India: ["04-01", "03-31"], |
| 248 | Iran: ["06-23", "06-22"], |
| 249 | Myanmar: ["04-01", "03-31"], |
Makarand Bauskar | bf66d7e | 2017-07-05 17:26:34 +0530 | [diff] [blame] | 250 | "New Zealand": ["04-01", "03-31"], |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 251 | Pakistan: ["07-01", "06-30"], |
| 252 | Singapore: ["04-01", "03-31"], |
Makarand Bauskar | bf66d7e | 2017-07-05 17:26:34 +0530 | [diff] [blame] | 253 | "South Africa": ["03-01", "02-28"], |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 254 | Thailand: ["10-01", "09-30"], |
Makarand Bauskar | bf66d7e | 2017-07-05 17:26:34 +0530 | [diff] [blame] | 255 | "United Kingdom": ["04-01", "03-31"], |
Prateeksha Singh | 5e4c8ec | 2017-07-03 18:23:57 +0530 | [diff] [blame] | 256 | }; |