blob: 1eeb8965f05d4ed2c90c3d6da846d8711349fea1 [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;
Rohit Waghchaure019501e2017-04-19 17:53:31 +053029 var project = $.grep(frappe.query_report.filters, function(e){ return e.df.fieldname == 'project'; })
Anand Doshi825d0142014-07-18 18:05:26 +053030
31 frappe.route_options = {
Anand Doshi5f0459c2014-07-21 16:13:06 +053032 "account": data.account,
Rushabh Mehtab2f09202016-09-01 17:53:19 +053033 "company": frappe.query_report_filters_by_name.company.get_value(),
Anand Doshi561e6cd2016-02-16 11:56:53 +053034 "from_date": data.from_date || data.year_start_date,
Ricardo Johann34354232017-01-24 06:42:24 -030035 "to_date": data.to_date || data.year_end_date,
Rohit Waghchaure019501e2017-04-19 17:53:31 +053036 "project": (project && project.length > 0) ? project[0].$input.val() : ""
Anand Doshi825d0142014-07-18 18:05:26 +053037 };
38 frappe.set_route("query-report", "General Ledger");
Anand Doshicb86d592014-07-22 19:02:11 +053039 },
40 "tree": true,
41 "name_field": "account",
42 "parent_field": "parent_account",
Rushabh Mehta05253872016-04-18 19:27:36 +053043 "initial_depth": 3,
44 onload: function(report) {
45 // dropdown for links to other financial statements
Rohit Waghchaure4275c302016-08-19 11:48:58 +053046 erpnext.financial_statements.filters = get_filters()
47
Rushabh Mehta05253872016-04-18 19:27:36 +053048 report.page.add_inner_button(__("Balance Sheet"), function() {
49 var filters = report.get_values();
50 frappe.set_route('query-report', 'Balance Sheet', {company: filters.company});
Francisco Roldán44c1a612017-05-26 13:02:51 -030051 }, __('Financial Statements'));
Rushabh Mehta05253872016-04-18 19:27:36 +053052 report.page.add_inner_button(__("Profit and Loss"), function() {
53 var filters = report.get_values();
54 frappe.set_route('query-report', 'Profit and Loss Statement', {company: filters.company});
Francisco Roldán44c1a612017-05-26 13:02:51 -030055 }, __('Financial Statements'));
Rushabh Mehta05253872016-04-18 19:27:36 +053056 report.page.add_inner_button(__("Cash Flow Statement"), function() {
57 var filters = report.get_values();
58 frappe.set_route('query-report', 'Cash Flow', {company: filters.company});
Francisco Roldán44c1a612017-05-26 13:02:51 -030059 }, __('Financial Statements'));
Nabin Hait44c1b8e2016-05-20 11:44:08 +053060 }
Anand Doshi825d0142014-07-18 18:05:26 +053061};
Rohit Waghchaure4275c302016-08-19 11:48:58 +053062
63function get_filters(){
64 return [
65 {
66 "fieldname":"company",
67 "label": __("Company"),
68 "fieldtype": "Link",
69 "options": "Company",
70 "default": frappe.defaults.get_user_default("Company"),
71 "reqd": 1
72 },
73 {
74 "fieldname":"from_fiscal_year",
Rohit Waghchaure26b646f2016-08-21 17:14:12 +053075 "label": __("Start Year"),
Rohit Waghchaure4275c302016-08-19 11:48:58 +053076 "fieldtype": "Link",
77 "options": "Fiscal Year",
78 "default": frappe.defaults.get_user_default("fiscal_year"),
79 "reqd": 1
80 },
81 {
82 "fieldname":"to_fiscal_year",
Rohit Waghchaure26b646f2016-08-21 17:14:12 +053083 "label": __("End 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": "periodicity",
91 "label": __("Periodicity"),
92 "fieldtype": "Select",
93 "options": [
94 { "value": "Monthly", "label": __("Monthly") },
95 { "value": "Quarterly", "label": __("Quarterly") },
96 { "value": "Half-Yearly", "label": __("Half-Yearly") },
97 { "value": "Yearly", "label": __("Yearly") }
98 ],
99 "default": "Monthly",
100 "reqd": 1
101 }
102 ]
103}