blob: bb13f81a3c4e550e17954b0b107e0028e62d18fc [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,
32 "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,
34 "to_date": data.to_date || data.year_end_date
Anand Doshi825d0142014-07-18 18:05:26 +053035 };
36 frappe.set_route("query-report", "General Ledger");
Anand Doshicb86d592014-07-22 19:02:11 +053037 },
38 "tree": true,
39 "name_field": "account",
40 "parent_field": "parent_account",
Rushabh Mehta05253872016-04-18 19:27:36 +053041 "initial_depth": 3,
42 onload: function(report) {
43 // dropdown for links to other financial statements
Rohit Waghchaure4275c302016-08-19 11:48:58 +053044 erpnext.financial_statements.filters = get_filters()
45
Rushabh Mehta05253872016-04-18 19:27:36 +053046 report.page.add_inner_button(__("Balance Sheet"), function() {
47 var filters = report.get_values();
48 frappe.set_route('query-report', 'Balance Sheet', {company: filters.company});
49 }, 'Financial Statements');
50 report.page.add_inner_button(__("Profit and Loss"), function() {
51 var filters = report.get_values();
52 frappe.set_route('query-report', 'Profit and Loss Statement', {company: filters.company});
53 }, 'Financial Statements');
54 report.page.add_inner_button(__("Cash Flow Statement"), function() {
55 var filters = report.get_values();
56 frappe.set_route('query-report', 'Cash Flow', {company: filters.company});
57 }, 'Financial Statements');
Nabin Hait44c1b8e2016-05-20 11:44:08 +053058 }
Anand Doshi825d0142014-07-18 18:05:26 +053059};
Rohit Waghchaure4275c302016-08-19 11:48:58 +053060
61function get_filters(){
62 return [
63 {
64 "fieldname":"company",
65 "label": __("Company"),
66 "fieldtype": "Link",
67 "options": "Company",
68 "default": frappe.defaults.get_user_default("Company"),
69 "reqd": 1
70 },
71 {
72 "fieldname":"from_fiscal_year",
73 "label": __("Fiscal Year"),
74 "fieldtype": "Link",
75 "options": "Fiscal Year",
76 "default": frappe.defaults.get_user_default("fiscal_year"),
77 "reqd": 1
78 },
79 {
80 "fieldname":"to_fiscal_year",
81 "label": __("Fiscal Year"),
82 "fieldtype": "Link",
83 "options": "Fiscal Year",
84 "default": frappe.defaults.get_user_default("fiscal_year"),
85 "reqd": 1
86 },
87 {
88 "fieldname": "periodicity",
89 "label": __("Periodicity"),
90 "fieldtype": "Select",
91 "options": [
92 { "value": "Monthly", "label": __("Monthly") },
93 { "value": "Quarterly", "label": __("Quarterly") },
94 { "value": "Half-Yearly", "label": __("Half-Yearly") },
95 { "value": "Yearly", "label": __("Yearly") }
96 ],
97 "default": "Monthly",
98 "reqd": 1
99 }
100 ]
101}