2014-07-18 12:35:26 +00:00
|
|
|
frappe.provide("erpnext.financial_statements");
|
|
|
|
|
|
|
|
erpnext.financial_statements = {
|
2016-08-19 06:18:58 +00:00
|
|
|
"filters": get_filters(),
|
2018-07-20 09:41:55 +00:00
|
|
|
"formatter": function(value, row, column, data, default_formatter) {
|
|
|
|
if (column.fieldname=="account") {
|
2019-12-04 04:16:42 +00:00
|
|
|
value = data.account_name || value;
|
2014-07-18 12:35:26 +00:00
|
|
|
|
2018-07-20 09:41:55 +00:00
|
|
|
column.link_onclick =
|
|
|
|
"erpnext.financial_statements.open_general_ledger(" + JSON.stringify(data) + ")";
|
|
|
|
column.is_tree = true;
|
2014-07-18 12:35:26 +00:00
|
|
|
}
|
|
|
|
|
2018-07-20 09:41:55 +00:00
|
|
|
value = default_formatter(value, row, column, data);
|
|
|
|
|
|
|
|
if (!data.parent_account) {
|
|
|
|
value = $(`<span>${value}</span>`);
|
2014-07-22 13:32:11 +00:00
|
|
|
|
2014-07-21 10:43:06 +00:00
|
|
|
var $value = $(value).css("font-weight", "bold");
|
2018-07-20 09:41:55 +00:00
|
|
|
if (data.warn_if_negative && data[column.fieldname] < 0) {
|
2014-07-21 10:43:06 +00:00
|
|
|
$value.addClass("text-danger");
|
|
|
|
}
|
|
|
|
|
|
|
|
value = $value.wrap("<p></p>").parent().html();
|
2014-07-18 12:35:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
},
|
2014-07-21 10:43:06 +00:00
|
|
|
"open_general_ledger": function(data) {
|
|
|
|
if (!data.account) return;
|
2017-04-19 12:23:31 +00:00
|
|
|
var project = $.grep(frappe.query_report.filters, function(e){ return e.df.fieldname == 'project'; })
|
2014-07-18 12:35:26 +00:00
|
|
|
|
|
|
|
frappe.route_options = {
|
2014-07-21 10:43:06 +00:00
|
|
|
"account": data.account,
|
2018-07-18 03:58:44 +00:00
|
|
|
"company": frappe.query_report.get_filter_value('company'),
|
2016-02-16 06:26:53 +00:00
|
|
|
"from_date": data.from_date || data.year_start_date,
|
2017-01-24 09:42:24 +00:00
|
|
|
"to_date": data.to_date || data.year_end_date,
|
2017-04-19 12:23:31 +00:00
|
|
|
"project": (project && project.length > 0) ? project[0].$input.val() : ""
|
2014-07-18 12:35:26 +00:00
|
|
|
};
|
|
|
|
frappe.set_route("query-report", "General Ledger");
|
2014-07-22 13:32:11 +00:00
|
|
|
},
|
|
|
|
"tree": true,
|
|
|
|
"name_field": "account",
|
|
|
|
"parent_field": "parent_account",
|
2016-04-18 13:57:36 +00:00
|
|
|
"initial_depth": 3,
|
|
|
|
onload: function(report) {
|
|
|
|
// dropdown for links to other financial statements
|
2016-08-19 06:18:58 +00:00
|
|
|
erpnext.financial_statements.filters = get_filters()
|
|
|
|
|
2016-04-18 13:57:36 +00:00
|
|
|
report.page.add_inner_button(__("Balance Sheet"), function() {
|
|
|
|
var filters = report.get_values();
|
|
|
|
frappe.set_route('query-report', 'Balance Sheet', {company: filters.company});
|
2017-05-26 16:02:51 +00:00
|
|
|
}, __('Financial Statements'));
|
2016-04-18 13:57:36 +00:00
|
|
|
report.page.add_inner_button(__("Profit and Loss"), function() {
|
|
|
|
var filters = report.get_values();
|
|
|
|
frappe.set_route('query-report', 'Profit and Loss Statement', {company: filters.company});
|
2017-05-26 16:02:51 +00:00
|
|
|
}, __('Financial Statements'));
|
2016-04-18 13:57:36 +00:00
|
|
|
report.page.add_inner_button(__("Cash Flow Statement"), function() {
|
|
|
|
var filters = report.get_values();
|
|
|
|
frappe.set_route('query-report', 'Cash Flow', {company: filters.company});
|
2017-05-26 16:02:51 +00:00
|
|
|
}, __('Financial Statements'));
|
2016-05-20 06:14:08 +00:00
|
|
|
}
|
2014-07-18 12:35:26 +00:00
|
|
|
};
|
2016-08-19 06:18:58 +00:00
|
|
|
|
2020-05-26 13:53:45 +00:00
|
|
|
function get_filters() {
|
2019-05-12 13:04:23 +00:00
|
|
|
let filters = [
|
2016-08-19 06:18:58 +00:00
|
|
|
{
|
|
|
|
"fieldname":"company",
|
|
|
|
"label": __("Company"),
|
|
|
|
"fieldtype": "Link",
|
|
|
|
"options": "Company",
|
|
|
|
"default": frappe.defaults.get_user_default("Company"),
|
|
|
|
"reqd": 1
|
|
|
|
},
|
2018-04-22 22:06:02 +00:00
|
|
|
{
|
|
|
|
"fieldname":"finance_book",
|
|
|
|
"label": __("Finance Book"),
|
|
|
|
"fieldtype": "Link",
|
2018-05-09 09:40:29 +00:00
|
|
|
"options": "Finance Book"
|
2018-04-22 22:06:02 +00:00
|
|
|
},
|
2020-04-07 06:46:25 +00:00
|
|
|
{
|
|
|
|
"fieldname":"filter_based_on",
|
|
|
|
"label": __("Filter Based On"),
|
|
|
|
"fieldtype": "Select",
|
|
|
|
"options": ["Fiscal Year", "Date Range"],
|
|
|
|
"default": ["Fiscal Year"],
|
|
|
|
"reqd": 1,
|
|
|
|
on_change: function() {
|
|
|
|
let filter_based_on = frappe.query_report.get_filter_value('filter_based_on');
|
|
|
|
frappe.query_report.toggle_filter_display('from_fiscal_year', filter_based_on === 'Date Range');
|
|
|
|
frappe.query_report.toggle_filter_display('to_fiscal_year', filter_based_on === 'Date Range');
|
|
|
|
frappe.query_report.toggle_filter_display('period_start_date', filter_based_on === 'Fiscal Year');
|
|
|
|
frappe.query_report.toggle_filter_display('period_end_date', filter_based_on === 'Fiscal Year');
|
|
|
|
|
|
|
|
frappe.query_report.refresh();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"fieldname":"period_start_date",
|
|
|
|
"label": __("Start Date"),
|
|
|
|
"fieldtype": "Date",
|
|
|
|
"default": frappe.datetime.nowdate(),
|
|
|
|
"hidden": 1,
|
|
|
|
"reqd": 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"fieldname":"period_end_date",
|
|
|
|
"label": __("End Date"),
|
|
|
|
"fieldtype": "Date",
|
|
|
|
"default": frappe.datetime.add_months(frappe.datetime.nowdate(), 12),
|
|
|
|
"hidden": 1,
|
|
|
|
"reqd": 1
|
|
|
|
},
|
2016-08-19 06:18:58 +00:00
|
|
|
{
|
|
|
|
"fieldname":"from_fiscal_year",
|
2016-08-21 11:44:12 +00:00
|
|
|
"label": __("Start Year"),
|
2016-08-19 06:18:58 +00:00
|
|
|
"fieldtype": "Link",
|
|
|
|
"options": "Fiscal Year",
|
|
|
|
"default": frappe.defaults.get_user_default("fiscal_year"),
|
|
|
|
"reqd": 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"fieldname":"to_fiscal_year",
|
2016-08-21 11:44:12 +00:00
|
|
|
"label": __("End Year"),
|
2016-08-19 06:18:58 +00:00
|
|
|
"fieldtype": "Link",
|
|
|
|
"options": "Fiscal Year",
|
|
|
|
"default": frappe.defaults.get_user_default("fiscal_year"),
|
|
|
|
"reqd": 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"fieldname": "periodicity",
|
|
|
|
"label": __("Periodicity"),
|
|
|
|
"fieldtype": "Select",
|
|
|
|
"options": [
|
|
|
|
{ "value": "Monthly", "label": __("Monthly") },
|
|
|
|
{ "value": "Quarterly", "label": __("Quarterly") },
|
|
|
|
{ "value": "Half-Yearly", "label": __("Half-Yearly") },
|
|
|
|
{ "value": "Yearly", "label": __("Yearly") }
|
|
|
|
],
|
2018-08-30 13:12:35 +00:00
|
|
|
"default": "Yearly",
|
2016-08-19 06:18:58 +00:00
|
|
|
"reqd": 1
|
2018-02-12 09:34:50 +00:00
|
|
|
},
|
|
|
|
// Note:
|
|
|
|
// If you are modifying this array such that the presentation_currency object
|
|
|
|
// is no longer the last object, please make adjustments in cash_flow.js
|
|
|
|
// accordingly.
|
|
|
|
{
|
|
|
|
"fieldname": "presentation_currency",
|
|
|
|
"label": __("Currency"),
|
|
|
|
"fieldtype": "Select",
|
|
|
|
"options": erpnext.get_presentation_currency_list()
|
2019-05-28 06:45:56 +00:00
|
|
|
},
|
|
|
|
{
|
2019-06-19 06:45:37 +00:00
|
|
|
"fieldname": "cost_center",
|
2019-05-28 06:45:56 +00:00
|
|
|
"label": __("Cost Center"),
|
2019-06-19 06:45:37 +00:00
|
|
|
"fieldtype": "MultiSelectList",
|
|
|
|
get_data: function(txt) {
|
|
|
|
return frappe.db.get_link_options('Cost Center', txt, {
|
|
|
|
company: frappe.query_report.get_filter_value("company")
|
2019-05-28 06:45:56 +00:00
|
|
|
});
|
|
|
|
}
|
2016-08-19 06:18:58 +00:00
|
|
|
}
|
|
|
|
]
|
2019-05-12 13:04:23 +00:00
|
|
|
|
|
|
|
return filters;
|
|
|
|
}
|
|
|
|
|
|
|
|
|