blob: 73e04c0ff0ef3389908263ce1a21fde6281a8556 [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) {
6 if (column.fieldname=="account") {
7 value = data.account_name;
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
Faris Ansari5986d592018-07-20 15:11:55 +053016 if (!data.parent_account) {
17 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
Rushabh Mehta05253872016-04-18 19:27:36 +053050 report.page.add_inner_button(__("Balance Sheet"), function() {
51 var filters = report.get_values();
52 frappe.set_route('query-report', 'Balance Sheet', {company: filters.company});
Francisco Roldán44c1a612017-05-26 13:02:51 -030053 }, __('Financial Statements'));
Rushabh Mehta05253872016-04-18 19:27:36 +053054 report.page.add_inner_button(__("Profit and Loss"), function() {
55 var filters = report.get_values();
56 frappe.set_route('query-report', 'Profit and Loss Statement', {company: filters.company});
Francisco Roldán44c1a612017-05-26 13:02:51 -030057 }, __('Financial Statements'));
Rushabh Mehta05253872016-04-18 19:27:36 +053058 report.page.add_inner_button(__("Cash Flow Statement"), function() {
59 var filters = report.get_values();
60 frappe.set_route('query-report', 'Cash Flow', {company: filters.company});
Francisco Roldán44c1a612017-05-26 13:02:51 -030061 }, __('Financial Statements'));
Nabin Hait44c1b8e2016-05-20 11:44:08 +053062 }
Anand Doshi825d0142014-07-18 18:05:26 +053063};
Rohit Waghchaure4275c302016-08-19 11:48:58 +053064
65function get_filters(){
deepeshgarg007d83cf652019-05-12 18:34:23 +053066 let filters = [
Rohit Waghchaure4275c302016-08-19 11:48:58 +053067 {
68 "fieldname":"company",
69 "label": __("Company"),
70 "fieldtype": "Link",
71 "options": "Company",
72 "default": frappe.defaults.get_user_default("Company"),
73 "reqd": 1
74 },
75 {
Gaurav Naik8cbbdfd2018-04-23 03:36:02 +053076 "fieldname":"finance_book",
77 "label": __("Finance Book"),
78 "fieldtype": "Link",
Nabin Haitb9fed2a2018-05-09 15:10:29 +053079 "options": "Finance Book"
Gaurav Naik8cbbdfd2018-04-23 03:36:02 +053080 },
81 {
Rohit Waghchaure4275c302016-08-19 11:48:58 +053082 "fieldname":"from_fiscal_year",
Rohit Waghchaure26b646f2016-08-21 17:14:12 +053083 "label": __("Start Year"),
Rohit Waghchaure4275c302016-08-19 11:48:58 +053084 "fieldtype": "Link",
85 "options": "Fiscal Year",
86 "default": frappe.defaults.get_user_default("fiscal_year"),
87 "reqd": 1
88 },
89 {
90 "fieldname":"to_fiscal_year",
Rohit Waghchaure26b646f2016-08-21 17:14:12 +053091 "label": __("End Year"),
Rohit Waghchaure4275c302016-08-19 11:48:58 +053092 "fieldtype": "Link",
93 "options": "Fiscal Year",
94 "default": frappe.defaults.get_user_default("fiscal_year"),
95 "reqd": 1
96 },
97 {
98 "fieldname": "periodicity",
99 "label": __("Periodicity"),
100 "fieldtype": "Select",
101 "options": [
102 { "value": "Monthly", "label": __("Monthly") },
103 { "value": "Quarterly", "label": __("Quarterly") },
104 { "value": "Half-Yearly", "label": __("Half-Yearly") },
105 { "value": "Yearly", "label": __("Yearly") }
106 ],
Nabin Haitf6b784e2018-08-30 18:42:35 +0530107 "default": "Yearly",
Rohit Waghchaure4275c302016-08-19 11:48:58 +0530108 "reqd": 1
tundebabzyc8978252018-02-12 10:34:50 +0100109 },
110 // Note:
111 // If you are modifying this array such that the presentation_currency object
112 // is no longer the last object, please make adjustments in cash_flow.js
113 // accordingly.
114 {
115 "fieldname": "presentation_currency",
116 "label": __("Currency"),
117 "fieldtype": "Select",
118 "options": erpnext.get_presentation_currency_list()
deepeshgarg007f5b6ee92019-05-28 12:15:56 +0530119 },
120 {
121 "fieldname":"cost_center",
122 "label": __("Cost Center"),
123 "fieldtype": "MultiSelect",
124 get_data: function() {
125 var cost_centers = frappe.query_report.get_filter_value("cost_center") || "";
126
127 const values = cost_centers.split(/\s*,\s*/).filter(d => d);
128 const txt = cost_centers.match(/[^,\s*]*$/)[0] || '';
129 let data = [];
130
131 frappe.call({
132 type: "GET",
133 method:'frappe.desk.search.search_link',
134 async: false,
135 no_spinner: true,
136 args: {
137 doctype: "Cost Center",
138 txt: txt,
139 filters: {
140 "company": frappe.query_report.get_filter_value("company"),
141 "name": ["not in", values]
142 }
143 },
144 callback: function(r) {
145 data = r.results;
146 }
147 });
148 return data;
149 }
Rohit Waghchaure4275c302016-08-19 11:48:58 +0530150 }
151 ]
deepeshgarg007d83cf652019-05-12 18:34:23 +0530152
deepeshgarg007a8cb00f2019-05-28 16:03:08 +0530153 let dimension_filters = erpnext.get_dimension_filters();
deepeshgarg007d83cf652019-05-12 18:34:23 +0530154
155 dimension_filters.then((dimensions) => {
156 dimensions.forEach((dimension) => {
157 filters.push({
158 "fieldname": dimension["fieldname"],
159 "label": __(dimension["label"]),
160 "fieldtype": "Link",
161 "options": dimension["document_type"]
162 });
163 });
164 });
165
166 return filters;
167}
168
deepeshgarg007d83cf652019-05-12 18:34:23 +0530169