Anand Doshi | 825d014 | 2014-07-18 18:05:26 +0530 | [diff] [blame] | 1 | frappe.provide("erpnext.financial_statements"); |
| 2 | |
| 3 | erpnext.financial_statements = { |
Rohit Waghchaure | 4275c30 | 2016-08-19 11:48:58 +0530 | [diff] [blame] | 4 | "filters": get_filters(), |
Faris Ansari | 5986d59 | 2018-07-20 15:11:55 +0530 | [diff] [blame] | 5 | "formatter": function(value, row, column, data, default_formatter) { |
| 6 | if (column.fieldname=="account") { |
thefalconx33 | a639f16 | 2019-12-04 09:46:42 +0530 | [diff] [blame] | 7 | value = data.account_name || value; |
Anand Doshi | 825d014 | 2014-07-18 18:05:26 +0530 | [diff] [blame] | 8 | |
Faris Ansari | 5986d59 | 2018-07-20 15:11:55 +0530 | [diff] [blame] | 9 | column.link_onclick = |
| 10 | "erpnext.financial_statements.open_general_ledger(" + JSON.stringify(data) + ")"; |
| 11 | column.is_tree = true; |
Anand Doshi | 825d014 | 2014-07-18 18:05:26 +0530 | [diff] [blame] | 12 | } |
| 13 | |
Faris Ansari | 5986d59 | 2018-07-20 15:11:55 +0530 | [diff] [blame] | 14 | value = default_formatter(value, row, column, data); |
Anand Doshi | cb86d59 | 2014-07-22 19:02:11 +0530 | [diff] [blame] | 15 | |
Faris Ansari | 5986d59 | 2018-07-20 15:11:55 +0530 | [diff] [blame] | 16 | if (!data.parent_account) { |
| 17 | value = $(`<span>${value}</span>`); |
| 18 | |
Anand Doshi | 5f0459c | 2014-07-21 16:13:06 +0530 | [diff] [blame] | 19 | var $value = $(value).css("font-weight", "bold"); |
Faris Ansari | 5986d59 | 2018-07-20 15:11:55 +0530 | [diff] [blame] | 20 | if (data.warn_if_negative && data[column.fieldname] < 0) { |
Anand Doshi | 5f0459c | 2014-07-21 16:13:06 +0530 | [diff] [blame] | 21 | $value.addClass("text-danger"); |
| 22 | } |
| 23 | |
| 24 | value = $value.wrap("<p></p>").parent().html(); |
Anand Doshi | 825d014 | 2014-07-18 18:05:26 +0530 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | return value; |
| 28 | }, |
Anand Doshi | 5f0459c | 2014-07-21 16:13:06 +0530 | [diff] [blame] | 29 | "open_general_ledger": function(data) { |
| 30 | if (!data.account) return; |
Rohit Waghchaure | 019501e | 2017-04-19 17:53:31 +0530 | [diff] [blame] | 31 | var project = $.grep(frappe.query_report.filters, function(e){ return e.df.fieldname == 'project'; }) |
Anand Doshi | 825d014 | 2014-07-18 18:05:26 +0530 | [diff] [blame] | 32 | |
| 33 | frappe.route_options = { |
Anand Doshi | 5f0459c | 2014-07-21 16:13:06 +0530 | [diff] [blame] | 34 | "account": data.account, |
Faris Ansari | 9e874af | 2018-07-18 09:28:44 +0530 | [diff] [blame] | 35 | "company": frappe.query_report.get_filter_value('company'), |
Anand Doshi | 561e6cd | 2016-02-16 11:56:53 +0530 | [diff] [blame] | 36 | "from_date": data.from_date || data.year_start_date, |
Ricardo Johann | 3435423 | 2017-01-24 06:42:24 -0300 | [diff] [blame] | 37 | "to_date": data.to_date || data.year_end_date, |
Rohit Waghchaure | 019501e | 2017-04-19 17:53:31 +0530 | [diff] [blame] | 38 | "project": (project && project.length > 0) ? project[0].$input.val() : "" |
Anand Doshi | 825d014 | 2014-07-18 18:05:26 +0530 | [diff] [blame] | 39 | }; |
| 40 | frappe.set_route("query-report", "General Ledger"); |
Anand Doshi | cb86d59 | 2014-07-22 19:02:11 +0530 | [diff] [blame] | 41 | }, |
| 42 | "tree": true, |
| 43 | "name_field": "account", |
| 44 | "parent_field": "parent_account", |
Rushabh Mehta | 0525387 | 2016-04-18 19:27:36 +0530 | [diff] [blame] | 45 | "initial_depth": 3, |
| 46 | onload: function(report) { |
| 47 | // dropdown for links to other financial statements |
Rohit Waghchaure | 4275c30 | 2016-08-19 11:48:58 +0530 | [diff] [blame] | 48 | erpnext.financial_statements.filters = get_filters() |
| 49 | |
Deepesh Garg | 1f3fe59 | 2020-05-28 18:36:21 +0530 | [diff] [blame] | 50 | let fiscal_year = frappe.defaults.get_user_default("fiscal_year") |
| 51 | |
| 52 | frappe.model.with_doc("Fiscal Year", fiscal_year, function(r) { |
| 53 | var fy = frappe.model.get_doc("Fiscal Year", fiscal_year); |
| 54 | frappe.query_report.set_filter_value({ |
| 55 | period_start_date: fy.year_start_date, |
| 56 | period_end_date: fy.year_end_date |
| 57 | }); |
| 58 | }); |
| 59 | |
Rushabh Mehta | 0525387 | 2016-04-18 19:27:36 +0530 | [diff] [blame] | 60 | report.page.add_inner_button(__("Balance Sheet"), function() { |
| 61 | var filters = report.get_values(); |
| 62 | frappe.set_route('query-report', 'Balance Sheet', {company: filters.company}); |
Francisco Roldán | 44c1a61 | 2017-05-26 13:02:51 -0300 | [diff] [blame] | 63 | }, __('Financial Statements')); |
Rushabh Mehta | 0525387 | 2016-04-18 19:27:36 +0530 | [diff] [blame] | 64 | report.page.add_inner_button(__("Profit and Loss"), function() { |
| 65 | var filters = report.get_values(); |
| 66 | frappe.set_route('query-report', 'Profit and Loss Statement', {company: filters.company}); |
Francisco Roldán | 44c1a61 | 2017-05-26 13:02:51 -0300 | [diff] [blame] | 67 | }, __('Financial Statements')); |
Rushabh Mehta | 0525387 | 2016-04-18 19:27:36 +0530 | [diff] [blame] | 68 | report.page.add_inner_button(__("Cash Flow Statement"), function() { |
| 69 | var filters = report.get_values(); |
| 70 | frappe.set_route('query-report', 'Cash Flow', {company: filters.company}); |
Francisco Roldán | 44c1a61 | 2017-05-26 13:02:51 -0300 | [diff] [blame] | 71 | }, __('Financial Statements')); |
Nabin Hait | 44c1b8e | 2016-05-20 11:44:08 +0530 | [diff] [blame] | 72 | } |
Anand Doshi | 825d014 | 2014-07-18 18:05:26 +0530 | [diff] [blame] | 73 | }; |
Rohit Waghchaure | 4275c30 | 2016-08-19 11:48:58 +0530 | [diff] [blame] | 74 | |
Deepesh Garg | 11ea0b1 | 2020-05-26 19:23:45 +0530 | [diff] [blame] | 75 | function get_filters() { |
deepeshgarg007 | d83cf65 | 2019-05-12 18:34:23 +0530 | [diff] [blame] | 76 | let filters = [ |
Rohit Waghchaure | 4275c30 | 2016-08-19 11:48:58 +0530 | [diff] [blame] | 77 | { |
| 78 | "fieldname":"company", |
| 79 | "label": __("Company"), |
| 80 | "fieldtype": "Link", |
| 81 | "options": "Company", |
| 82 | "default": frappe.defaults.get_user_default("Company"), |
| 83 | "reqd": 1 |
| 84 | }, |
| 85 | { |
Gaurav Naik | 8cbbdfd | 2018-04-23 03:36:02 +0530 | [diff] [blame] | 86 | "fieldname":"finance_book", |
| 87 | "label": __("Finance Book"), |
| 88 | "fieldtype": "Link", |
Nabin Hait | b9fed2a | 2018-05-09 15:10:29 +0530 | [diff] [blame] | 89 | "options": "Finance Book" |
Gaurav Naik | 8cbbdfd | 2018-04-23 03:36:02 +0530 | [diff] [blame] | 90 | }, |
| 91 | { |
Deepesh Garg | 24a2c9b | 2020-04-07 12:16:25 +0530 | [diff] [blame] | 92 | "fieldname":"filter_based_on", |
| 93 | "label": __("Filter Based On"), |
| 94 | "fieldtype": "Select", |
| 95 | "options": ["Fiscal Year", "Date Range"], |
| 96 | "default": ["Fiscal Year"], |
| 97 | "reqd": 1, |
| 98 | on_change: function() { |
| 99 | let filter_based_on = frappe.query_report.get_filter_value('filter_based_on'); |
| 100 | frappe.query_report.toggle_filter_display('from_fiscal_year', filter_based_on === 'Date Range'); |
| 101 | frappe.query_report.toggle_filter_display('to_fiscal_year', filter_based_on === 'Date Range'); |
| 102 | frappe.query_report.toggle_filter_display('period_start_date', filter_based_on === 'Fiscal Year'); |
| 103 | frappe.query_report.toggle_filter_display('period_end_date', filter_based_on === 'Fiscal Year'); |
| 104 | |
| 105 | frappe.query_report.refresh(); |
| 106 | } |
| 107 | }, |
| 108 | { |
| 109 | "fieldname":"period_start_date", |
| 110 | "label": __("Start Date"), |
| 111 | "fieldtype": "Date", |
Deepesh Garg | 24a2c9b | 2020-04-07 12:16:25 +0530 | [diff] [blame] | 112 | "hidden": 1, |
| 113 | "reqd": 1 |
| 114 | }, |
| 115 | { |
| 116 | "fieldname":"period_end_date", |
| 117 | "label": __("End Date"), |
| 118 | "fieldtype": "Date", |
Deepesh Garg | 24a2c9b | 2020-04-07 12:16:25 +0530 | [diff] [blame] | 119 | "hidden": 1, |
| 120 | "reqd": 1 |
| 121 | }, |
| 122 | { |
Rohit Waghchaure | 4275c30 | 2016-08-19 11:48:58 +0530 | [diff] [blame] | 123 | "fieldname":"from_fiscal_year", |
Rohit Waghchaure | 26b646f | 2016-08-21 17:14:12 +0530 | [diff] [blame] | 124 | "label": __("Start Year"), |
Rohit Waghchaure | 4275c30 | 2016-08-19 11:48:58 +0530 | [diff] [blame] | 125 | "fieldtype": "Link", |
| 126 | "options": "Fiscal Year", |
| 127 | "default": frappe.defaults.get_user_default("fiscal_year"), |
| 128 | "reqd": 1 |
| 129 | }, |
| 130 | { |
| 131 | "fieldname":"to_fiscal_year", |
Rohit Waghchaure | 26b646f | 2016-08-21 17:14:12 +0530 | [diff] [blame] | 132 | "label": __("End Year"), |
Rohit Waghchaure | 4275c30 | 2016-08-19 11:48:58 +0530 | [diff] [blame] | 133 | "fieldtype": "Link", |
| 134 | "options": "Fiscal Year", |
| 135 | "default": frappe.defaults.get_user_default("fiscal_year"), |
| 136 | "reqd": 1 |
| 137 | }, |
| 138 | { |
| 139 | "fieldname": "periodicity", |
| 140 | "label": __("Periodicity"), |
| 141 | "fieldtype": "Select", |
| 142 | "options": [ |
| 143 | { "value": "Monthly", "label": __("Monthly") }, |
| 144 | { "value": "Quarterly", "label": __("Quarterly") }, |
| 145 | { "value": "Half-Yearly", "label": __("Half-Yearly") }, |
| 146 | { "value": "Yearly", "label": __("Yearly") } |
| 147 | ], |
Nabin Hait | f6b784e | 2018-08-30 18:42:35 +0530 | [diff] [blame] | 148 | "default": "Yearly", |
Rohit Waghchaure | 4275c30 | 2016-08-19 11:48:58 +0530 | [diff] [blame] | 149 | "reqd": 1 |
tundebabzy | c897825 | 2018-02-12 10:34:50 +0100 | [diff] [blame] | 150 | }, |
| 151 | // Note: |
| 152 | // If you are modifying this array such that the presentation_currency object |
| 153 | // is no longer the last object, please make adjustments in cash_flow.js |
| 154 | // accordingly. |
| 155 | { |
| 156 | "fieldname": "presentation_currency", |
| 157 | "label": __("Currency"), |
| 158 | "fieldtype": "Select", |
| 159 | "options": erpnext.get_presentation_currency_list() |
deepeshgarg007 | f5b6ee9 | 2019-05-28 12:15:56 +0530 | [diff] [blame] | 160 | }, |
| 161 | { |
Faris Ansari | 2632107 | 2019-06-19 12:15:37 +0530 | [diff] [blame] | 162 | "fieldname": "cost_center", |
deepeshgarg007 | f5b6ee9 | 2019-05-28 12:15:56 +0530 | [diff] [blame] | 163 | "label": __("Cost Center"), |
Faris Ansari | 2632107 | 2019-06-19 12:15:37 +0530 | [diff] [blame] | 164 | "fieldtype": "MultiSelectList", |
| 165 | get_data: function(txt) { |
| 166 | return frappe.db.get_link_options('Cost Center', txt, { |
| 167 | company: frappe.query_report.get_filter_value("company") |
deepeshgarg007 | f5b6ee9 | 2019-05-28 12:15:56 +0530 | [diff] [blame] | 168 | }); |
deepeshgarg007 | f5b6ee9 | 2019-05-28 12:15:56 +0530 | [diff] [blame] | 169 | } |
Rohit Waghchaure | 4275c30 | 2016-08-19 11:48:58 +0530 | [diff] [blame] | 170 | } |
| 171 | ] |
deepeshgarg007 | d83cf65 | 2019-05-12 18:34:23 +0530 | [diff] [blame] | 172 | |
deepeshgarg007 | d83cf65 | 2019-05-12 18:34:23 +0530 | [diff] [blame] | 173 | return filters; |
| 174 | } |
| 175 | |
deepeshgarg007 | d83cf65 | 2019-05-12 18:34:23 +0530 | [diff] [blame] | 176 | |