blob: b2f7afe53f3a354da05aefe3fef7b21c4d50ba0b [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;
Rohit Waghchaure019501e2017-04-19 17:53:31 +053031 var 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 };
40 frappe.set_route("query-report", "General Ledger");
Anand Doshicb86d592014-07-22 19:02:11 +053041 },
42 "tree": true,
43 "name_field": "account",
44 "parent_field": "parent_account",
Rushabh Mehta05253872016-04-18 19:27:36 +053045 "initial_depth": 3,
46 onload: function(report) {
47 // dropdown for links to other financial statements
Rohit Waghchaure4275c302016-08-19 11:48:58 +053048 erpnext.financial_statements.filters = get_filters()
49
Deepesh Garg1f3fe592020-05-28 18:36:21 +053050 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
Shivam Mishrab6fb1322020-07-09 16:51:36 +053060 const views_menu = report.page.add_custom_button_group(__('Financial Statements'));
61
62 report.page.add_custom_menu_item(views_menu, __("Balance Sheet"), function() {
Rushabh Mehta05253872016-04-18 19:27:36 +053063 var filters = report.get_values();
64 frappe.set_route('query-report', 'Balance Sheet', {company: filters.company});
Shivam Mishrab6fb1322020-07-09 16:51:36 +053065 });
66
67 report.page.add_custom_menu_item(views_menu, __("Profit and Loss"), function() {
Rushabh Mehta05253872016-04-18 19:27:36 +053068 var filters = report.get_values();
69 frappe.set_route('query-report', 'Profit and Loss Statement', {company: filters.company});
Shivam Mishrab6fb1322020-07-09 16:51:36 +053070 });
71
72 report.page.add_custom_menu_item(views_menu, __("Cash Flow Statement"), function() {
Rushabh Mehta05253872016-04-18 19:27:36 +053073 var filters = report.get_values();
74 frappe.set_route('query-report', 'Cash Flow', {company: filters.company});
Shivam Mishrab6fb1322020-07-09 16:51:36 +053075 });
Nabin Hait44c1b8e2016-05-20 11:44:08 +053076 }
Anand Doshi825d0142014-07-18 18:05:26 +053077};
Rohit Waghchaure4275c302016-08-19 11:48:58 +053078
Deepesh Garg11ea0b12020-05-26 19:23:45 +053079function get_filters() {
deepeshgarg007d83cf652019-05-12 18:34:23 +053080 let filters = [
Rohit Waghchaure4275c302016-08-19 11:48:58 +053081 {
82 "fieldname":"company",
83 "label": __("Company"),
84 "fieldtype": "Link",
85 "options": "Company",
86 "default": frappe.defaults.get_user_default("Company"),
87 "reqd": 1
88 },
89 {
Gaurav Naik8cbbdfd2018-04-23 03:36:02 +053090 "fieldname":"finance_book",
91 "label": __("Finance Book"),
92 "fieldtype": "Link",
Nabin Haitb9fed2a2018-05-09 15:10:29 +053093 "options": "Finance Book"
Gaurav Naik8cbbdfd2018-04-23 03:36:02 +053094 },
95 {
Deepesh Garg24a2c9b2020-04-07 12:16:25 +053096 "fieldname":"filter_based_on",
97 "label": __("Filter Based On"),
98 "fieldtype": "Select",
99 "options": ["Fiscal Year", "Date Range"],
100 "default": ["Fiscal Year"],
101 "reqd": 1,
102 on_change: function() {
103 let filter_based_on = frappe.query_report.get_filter_value('filter_based_on');
104 frappe.query_report.toggle_filter_display('from_fiscal_year', filter_based_on === 'Date Range');
105 frappe.query_report.toggle_filter_display('to_fiscal_year', filter_based_on === 'Date Range');
106 frappe.query_report.toggle_filter_display('period_start_date', filter_based_on === 'Fiscal Year');
107 frappe.query_report.toggle_filter_display('period_end_date', filter_based_on === 'Fiscal Year');
108
109 frappe.query_report.refresh();
110 }
111 },
112 {
113 "fieldname":"period_start_date",
114 "label": __("Start Date"),
115 "fieldtype": "Date",
Deepesh Garg24a2c9b2020-04-07 12:16:25 +0530116 "hidden": 1,
117 "reqd": 1
118 },
119 {
120 "fieldname":"period_end_date",
121 "label": __("End Date"),
122 "fieldtype": "Date",
Deepesh Garg24a2c9b2020-04-07 12:16:25 +0530123 "hidden": 1,
124 "reqd": 1
125 },
126 {
Rohit Waghchaure4275c302016-08-19 11:48:58 +0530127 "fieldname":"from_fiscal_year",
Rohit Waghchaure26b646f2016-08-21 17:14:12 +0530128 "label": __("Start Year"),
Rohit Waghchaure4275c302016-08-19 11:48:58 +0530129 "fieldtype": "Link",
130 "options": "Fiscal Year",
131 "default": frappe.defaults.get_user_default("fiscal_year"),
132 "reqd": 1
133 },
134 {
135 "fieldname":"to_fiscal_year",
Rohit Waghchaure26b646f2016-08-21 17:14:12 +0530136 "label": __("End Year"),
Rohit Waghchaure4275c302016-08-19 11:48:58 +0530137 "fieldtype": "Link",
138 "options": "Fiscal Year",
139 "default": frappe.defaults.get_user_default("fiscal_year"),
140 "reqd": 1
141 },
142 {
143 "fieldname": "periodicity",
144 "label": __("Periodicity"),
145 "fieldtype": "Select",
146 "options": [
147 { "value": "Monthly", "label": __("Monthly") },
148 { "value": "Quarterly", "label": __("Quarterly") },
149 { "value": "Half-Yearly", "label": __("Half-Yearly") },
150 { "value": "Yearly", "label": __("Yearly") }
151 ],
Nabin Haitf6b784e2018-08-30 18:42:35 +0530152 "default": "Yearly",
Rohit Waghchaure4275c302016-08-19 11:48:58 +0530153 "reqd": 1
tundebabzyc8978252018-02-12 10:34:50 +0100154 },
155 // Note:
156 // If you are modifying this array such that the presentation_currency object
157 // is no longer the last object, please make adjustments in cash_flow.js
158 // accordingly.
159 {
160 "fieldname": "presentation_currency",
161 "label": __("Currency"),
162 "fieldtype": "Select",
163 "options": erpnext.get_presentation_currency_list()
deepeshgarg007f5b6ee92019-05-28 12:15:56 +0530164 },
165 {
Faris Ansari26321072019-06-19 12:15:37 +0530166 "fieldname": "cost_center",
deepeshgarg007f5b6ee92019-05-28 12:15:56 +0530167 "label": __("Cost Center"),
Faris Ansari26321072019-06-19 12:15:37 +0530168 "fieldtype": "MultiSelectList",
169 get_data: function(txt) {
170 return frappe.db.get_link_options('Cost Center', txt, {
171 company: frappe.query_report.get_filter_value("company")
deepeshgarg007f5b6ee92019-05-28 12:15:56 +0530172 });
deepeshgarg007f5b6ee92019-05-28 12:15:56 +0530173 }
Rohit Waghchaure4275c302016-08-19 11:48:58 +0530174 }
175 ]
deepeshgarg007d83cf652019-05-12 18:34:23 +0530176
deepeshgarg007d83cf652019-05-12 18:34:23 +0530177 return filters;
178}
179
deepeshgarg007d83cf652019-05-12 18:34:23 +0530180