blob: 711520530a97c88f1589002e288c710dbf65ca45 [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(),
Anand Doshicb86d592014-07-22 19:02:11 +05305 "formatter": function(row, cell, value, columnDef, dataContext, default_formatter) {
Anand Doshi825d0142014-07-18 18:05:26 +05306 if (columnDef.df.fieldname=="account") {
Anand Doshicb86d592014-07-22 19:02:11 +05307 value = dataContext.account_name;
Anand Doshi825d0142014-07-18 18:05:26 +05308
Anand Doshi561e6cd2016-02-16 11:56:53 +05309 columnDef.df.link_onclick =
Nabin Haitbd7f48c2016-02-02 19:05:30 +053010 "erpnext.financial_statements.open_general_ledger(" + JSON.stringify(dataContext) + ")";
Anand Doshicb86d592014-07-22 19:02:11 +053011 columnDef.df.is_tree = true;
Anand Doshi825d0142014-07-18 18:05:26 +053012 }
13
Anand Doshicb86d592014-07-22 19:02:11 +053014 value = default_formatter(row, cell, value, columnDef, dataContext);
15
Anand Doshi825d0142014-07-18 18:05:26 +053016 if (!dataContext.parent_account) {
Anand Doshi5f0459c2014-07-21 16:13:06 +053017 var $value = $(value).css("font-weight", "bold");
Anand Doshicb86d592014-07-22 19:02:11 +053018 if (dataContext.warn_if_negative && dataContext[columnDef.df.fieldname] < 0) {
Anand Doshi5f0459c2014-07-21 16:13:06 +053019 $value.addClass("text-danger");
20 }
21
22 value = $value.wrap("<p></p>").parent().html();
Anand Doshi825d0142014-07-18 18:05:26 +053023 }
24
25 return value;
26 },
Anand Doshi5f0459c2014-07-21 16:13:06 +053027 "open_general_ledger": function(data) {
28 if (!data.account) return;
Anand Doshi825d0142014-07-18 18:05:26 +053029
30 frappe.route_options = {
Anand Doshi5f0459c2014-07-21 16:13:06 +053031 "account": data.account,
Rushabh Mehtab2f09202016-09-01 17:53:19 +053032 "company": frappe.query_report_filters_by_name.company.get_value(),
Anand Doshi561e6cd2016-02-16 11:56:53 +053033 "from_date": data.from_date || data.year_start_date,
Ricardo Johann34354232017-01-24 06:42:24 -030034 "to_date": data.to_date || data.year_end_date,
35 "project": $.grep(frappe.query_report.filters, function(e){ return e.df.fieldname == 'project'; })[0].$input.val()
Anand Doshi825d0142014-07-18 18:05:26 +053036 };
37 frappe.set_route("query-report", "General Ledger");
Anand Doshicb86d592014-07-22 19:02:11 +053038 },
39 "tree": true,
40 "name_field": "account",
41 "parent_field": "parent_account",
Rushabh Mehta05253872016-04-18 19:27:36 +053042 "initial_depth": 3,
43 onload: function(report) {
44 // dropdown for links to other financial statements
Rohit Waghchaure4275c302016-08-19 11:48:58 +053045 erpnext.financial_statements.filters = get_filters()
46
Rushabh Mehta05253872016-04-18 19:27:36 +053047 report.page.add_inner_button(__("Balance Sheet"), function() {
48 var filters = report.get_values();
49 frappe.set_route('query-report', 'Balance Sheet', {company: filters.company});
50 }, 'Financial Statements');
51 report.page.add_inner_button(__("Profit and Loss"), function() {
52 var filters = report.get_values();
53 frappe.set_route('query-report', 'Profit and Loss Statement', {company: filters.company});
54 }, 'Financial Statements');
55 report.page.add_inner_button(__("Cash Flow Statement"), function() {
56 var filters = report.get_values();
57 frappe.set_route('query-report', 'Cash Flow', {company: filters.company});
58 }, 'Financial Statements');
Nabin Hait44c1b8e2016-05-20 11:44:08 +053059 }
Anand Doshi825d0142014-07-18 18:05:26 +053060};
Rohit Waghchaure4275c302016-08-19 11:48:58 +053061
62function get_filters(){
63 return [
64 {
65 "fieldname":"company",
66 "label": __("Company"),
67 "fieldtype": "Link",
68 "options": "Company",
69 "default": frappe.defaults.get_user_default("Company"),
70 "reqd": 1
71 },
72 {
73 "fieldname":"from_fiscal_year",
Rohit Waghchaure26b646f2016-08-21 17:14:12 +053074 "label": __("Start Year"),
Rohit Waghchaure4275c302016-08-19 11:48:58 +053075 "fieldtype": "Link",
76 "options": "Fiscal Year",
77 "default": frappe.defaults.get_user_default("fiscal_year"),
78 "reqd": 1
79 },
80 {
81 "fieldname":"to_fiscal_year",
Rohit Waghchaure26b646f2016-08-21 17:14:12 +053082 "label": __("End Year"),
Rohit Waghchaure4275c302016-08-19 11:48:58 +053083 "fieldtype": "Link",
84 "options": "Fiscal Year",
85 "default": frappe.defaults.get_user_default("fiscal_year"),
86 "reqd": 1
87 },
88 {
89 "fieldname": "periodicity",
90 "label": __("Periodicity"),
91 "fieldtype": "Select",
92 "options": [
93 { "value": "Monthly", "label": __("Monthly") },
94 { "value": "Quarterly", "label": __("Quarterly") },
95 { "value": "Half-Yearly", "label": __("Half-Yearly") },
96 { "value": "Yearly", "label": __("Yearly") }
97 ],
98 "default": "Monthly",
99 "reqd": 1
100 }
101 ]
102}