blob: b0082bdb2817283cfebd4662897f1a2933d79061 [file] [log] [blame]
Anand Doshi825d0142014-07-18 18:05:26 +05301frappe.provide("erpnext.financial_statements");
2
3erpnext.financial_statements = {
Rohit Waghchaure4275c302016-08-19 11:48:58 +05304 "filters": get_filters(),
Faris Ansari5986d592018-07-20 15:11:55 +05305 "formatter": function(value, row, column, data, default_formatter) {
Diksha Jadhav09b8caf2020-07-21 17:35:10 +05306 if (data && column.fieldname=="account") {
thefalconx33a639f162019-12-04 09:46:42 +05307 value = data.account_name || value;
Anand Doshi825d0142014-07-18 18:05:26 +05308
Faris Ansari5986d592018-07-20 15:11:55 +05309 column.link_onclick =
10 "erpnext.financial_statements.open_general_ledger(" + JSON.stringify(data) + ")";
11 column.is_tree = true;
Anand Doshi825d0142014-07-18 18:05:26 +053012 }
13
Faris Ansari5986d592018-07-20 15:11:55 +053014 value = default_formatter(value, row, column, data);
Anand Doshicb86d592014-07-22 19:02:11 +053015
Diksha Jadhav09b8caf2020-07-21 17:35:10 +053016 if (data && !data.parent_account) {
Faris Ansari5986d592018-07-20 15:11:55 +053017 value = $(`<span>${value}</span>`);
18
Anand Doshi5f0459c2014-07-21 16:13:06 +053019 var $value = $(value).css("font-weight", "bold");
Faris Ansari5986d592018-07-20 15:11:55 +053020 if (data.warn_if_negative && data[column.fieldname] < 0) {
Anand Doshi5f0459c2014-07-21 16:13:06 +053021 $value.addClass("text-danger");
22 }
23
24 value = $value.wrap("<p></p>").parent().html();
Anand Doshi825d0142014-07-18 18:05:26 +053025 }
26
27 return value;
28 },
Anand Doshi5f0459c2014-07-21 16:13:06 +053029 "open_general_ledger": function(data) {
30 if (!data.account) return;
FinByz Tech Pvt. Ltdc52b41d2022-10-19 23:14:10 +053031 let project = $.grep(frappe.query_report.filters, function(e){ return e.df.fieldname == 'project'; });
Anand Doshi825d0142014-07-18 18:05:26 +053032
33 frappe.route_options = {
Anand Doshi5f0459c2014-07-21 16:13:06 +053034 "account": data.account,
Faris Ansari9e874af2018-07-18 09:28:44 +053035 "company": frappe.query_report.get_filter_value('company'),
Anand Doshi561e6cd2016-02-16 11:56:53 +053036 "from_date": data.from_date || data.year_start_date,
Ricardo Johann34354232017-01-24 06:42:24 -030037 "to_date": data.to_date || data.year_end_date,
Rohit Waghchaure019501e2017-04-19 17:53:31 +053038 "project": (project && project.length > 0) ? project[0].$input.val() : ""
Anand Doshi825d0142014-07-18 18:05:26 +053039 };
FinByz Tech Pvt. Ltdc52b41d2022-10-19 23:14:10 +053040
41 let report = "General Ledger";
42
43 if (["Payable", "Receivable"].includes(data.account_type)) {
44 report = data.account_type == "Payable" ? "Accounts Payable" : "Accounts Receivable";
45 frappe.route_options["party_account"] = data.account;
46 frappe.route_options["report_date"] = data.year_end_date;
47 }
48
49 frappe.set_route("query-report", report);
Anand Doshicb86d592014-07-22 19:02:11 +053050 },
51 "tree": true,
52 "name_field": "account",
53 "parent_field": "parent_account",
Rushabh Mehta05253872016-04-18 19:27:36 +053054 "initial_depth": 3,
55 onload: function(report) {
56 // dropdown for links to other financial statements
Rohit Waghchaure4275c302016-08-19 11:48:58 +053057 erpnext.financial_statements.filters = get_filters()
58
Deepesh Garg1f3fe592020-05-28 18:36:21 +053059 let fiscal_year = frappe.defaults.get_user_default("fiscal_year")
60
61 frappe.model.with_doc("Fiscal Year", fiscal_year, function(r) {
62 var fy = frappe.model.get_doc("Fiscal Year", fiscal_year);
63 frappe.query_report.set_filter_value({
64 period_start_date: fy.year_start_date,
65 period_end_date: fy.year_end_date
66 });
67 });
68
Shivam Mishrab6fb1322020-07-09 16:51:36 +053069 const views_menu = report.page.add_custom_button_group(__('Financial Statements'));
70
71 report.page.add_custom_menu_item(views_menu, __("Balance Sheet"), function() {
Rushabh Mehta05253872016-04-18 19:27:36 +053072 var filters = report.get_values();
73 frappe.set_route('query-report', 'Balance Sheet', {company: filters.company});
Shivam Mishrab6fb1322020-07-09 16:51:36 +053074 });
75
76 report.page.add_custom_menu_item(views_menu, __("Profit and Loss"), function() {
Rushabh Mehta05253872016-04-18 19:27:36 +053077 var filters = report.get_values();
78 frappe.set_route('query-report', 'Profit and Loss Statement', {company: filters.company});
Shivam Mishrab6fb1322020-07-09 16:51:36 +053079 });
80
81 report.page.add_custom_menu_item(views_menu, __("Cash Flow Statement"), function() {
Rushabh Mehta05253872016-04-18 19:27:36 +053082 var filters = report.get_values();
83 frappe.set_route('query-report', 'Cash Flow', {company: filters.company});
Shivam Mishrab6fb1322020-07-09 16:51:36 +053084 });
Nabin Hait44c1b8e2016-05-20 11:44:08 +053085 }
Anand Doshi825d0142014-07-18 18:05:26 +053086};
Rohit Waghchaure4275c302016-08-19 11:48:58 +053087
Deepesh Garg11ea0b12020-05-26 19:23:45 +053088function get_filters() {
deepeshgarg007d83cf652019-05-12 18:34:23 +053089 let filters = [
Rohit Waghchaure4275c302016-08-19 11:48:58 +053090 {
91 "fieldname":"company",
92 "label": __("Company"),
93 "fieldtype": "Link",
94 "options": "Company",
95 "default": frappe.defaults.get_user_default("Company"),
96 "reqd": 1
97 },
98 {
Gaurav Naik8cbbdfd2018-04-23 03:36:02 +053099 "fieldname":"finance_book",
100 "label": __("Finance Book"),
101 "fieldtype": "Link",
Nabin Haitb9fed2a2018-05-09 15:10:29 +0530102 "options": "Finance Book"
Gaurav Naik8cbbdfd2018-04-23 03:36:02 +0530103 },
104 {
Deepesh Garg24a2c9b2020-04-07 12:16:25 +0530105 "fieldname":"filter_based_on",
106 "label": __("Filter Based On"),
107 "fieldtype": "Select",
108 "options": ["Fiscal Year", "Date Range"],
109 "default": ["Fiscal Year"],
110 "reqd": 1,
111 on_change: function() {
112 let filter_based_on = frappe.query_report.get_filter_value('filter_based_on');
113 frappe.query_report.toggle_filter_display('from_fiscal_year', filter_based_on === 'Date Range');
114 frappe.query_report.toggle_filter_display('to_fiscal_year', filter_based_on === 'Date Range');
115 frappe.query_report.toggle_filter_display('period_start_date', filter_based_on === 'Fiscal Year');
116 frappe.query_report.toggle_filter_display('period_end_date', filter_based_on === 'Fiscal Year');
117
118 frappe.query_report.refresh();
119 }
120 },
121 {
122 "fieldname":"period_start_date",
123 "label": __("Start Date"),
124 "fieldtype": "Date",
Deepesh Garg3a6894f2021-10-27 19:39:18 +0530125 "reqd": 1,
126 "depends_on": "eval:doc.filter_based_on == 'Date Range'"
Deepesh Garg24a2c9b2020-04-07 12:16:25 +0530127 },
128 {
129 "fieldname":"period_end_date",
130 "label": __("End Date"),
131 "fieldtype": "Date",
Deepesh Garg3a6894f2021-10-27 19:39:18 +0530132 "reqd": 1,
133 "depends_on": "eval:doc.filter_based_on == 'Date Range'"
Deepesh Garg24a2c9b2020-04-07 12:16:25 +0530134 },
135 {
Rohit Waghchaure4275c302016-08-19 11:48:58 +0530136 "fieldname":"from_fiscal_year",
Rohit Waghchaure26b646f2016-08-21 17:14:12 +0530137 "label": __("Start Year"),
Rohit Waghchaure4275c302016-08-19 11:48:58 +0530138 "fieldtype": "Link",
139 "options": "Fiscal Year",
140 "default": frappe.defaults.get_user_default("fiscal_year"),
Deepesh Garg3a6894f2021-10-27 19:39:18 +0530141 "reqd": 1,
142 "depends_on": "eval:doc.filter_based_on == 'Fiscal Year'"
Rohit Waghchaure4275c302016-08-19 11:48:58 +0530143 },
144 {
145 "fieldname":"to_fiscal_year",
Rohit Waghchaure26b646f2016-08-21 17:14:12 +0530146 "label": __("End Year"),
Rohit Waghchaure4275c302016-08-19 11:48:58 +0530147 "fieldtype": "Link",
148 "options": "Fiscal Year",
149 "default": frappe.defaults.get_user_default("fiscal_year"),
Deepesh Garg3a6894f2021-10-27 19:39:18 +0530150 "reqd": 1,
151 "depends_on": "eval:doc.filter_based_on == 'Fiscal Year'"
Rohit Waghchaure4275c302016-08-19 11:48:58 +0530152 },
153 {
154 "fieldname": "periodicity",
155 "label": __("Periodicity"),
156 "fieldtype": "Select",
157 "options": [
158 { "value": "Monthly", "label": __("Monthly") },
159 { "value": "Quarterly", "label": __("Quarterly") },
160 { "value": "Half-Yearly", "label": __("Half-Yearly") },
161 { "value": "Yearly", "label": __("Yearly") }
162 ],
Nabin Haitf6b784e2018-08-30 18:42:35 +0530163 "default": "Yearly",
Rohit Waghchaure4275c302016-08-19 11:48:58 +0530164 "reqd": 1
tundebabzyc8978252018-02-12 10:34:50 +0100165 },
166 // Note:
167 // If you are modifying this array such that the presentation_currency object
168 // is no longer the last object, please make adjustments in cash_flow.js
169 // accordingly.
170 {
171 "fieldname": "presentation_currency",
172 "label": __("Currency"),
173 "fieldtype": "Select",
174 "options": erpnext.get_presentation_currency_list()
deepeshgarg007f5b6ee92019-05-28 12:15:56 +0530175 },
176 {
Faris Ansari26321072019-06-19 12:15:37 +0530177 "fieldname": "cost_center",
deepeshgarg007f5b6ee92019-05-28 12:15:56 +0530178 "label": __("Cost Center"),
Faris Ansari26321072019-06-19 12:15:37 +0530179 "fieldtype": "MultiSelectList",
180 get_data: function(txt) {
181 return frappe.db.get_link_options('Cost Center', txt, {
182 company: frappe.query_report.get_filter_value("company")
deepeshgarg007f5b6ee92019-05-28 12:15:56 +0530183 });
deepeshgarg007f5b6ee92019-05-28 12:15:56 +0530184 }
Rohit Waghchaure4275c302016-08-19 11:48:58 +0530185 }
186 ]
deepeshgarg007d83cf652019-05-12 18:34:23 +0530187
deepeshgarg007d83cf652019-05-12 18:34:23 +0530188 return filters;
189}