2016-08-24 10:52:30 +00:00
|
|
|
// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
|
|
|
|
// For license information, please see license.txt
|
|
|
|
|
|
|
|
frappe.require("assets/erpnext/js/financial_statements.js", function() {
|
|
|
|
frappe.query_reports["Profitability Analysis"] = {
|
|
|
|
"filters": [
|
|
|
|
{
|
|
|
|
"fieldname": "company",
|
|
|
|
"label": __("Company"),
|
|
|
|
"fieldtype": "Link",
|
|
|
|
"options": "Company",
|
|
|
|
"default": frappe.defaults.get_user_default("Company"),
|
|
|
|
"reqd": 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"fieldname": "based_on",
|
2016-09-23 16:21:51 +00:00
|
|
|
"label": __("Based On"),
|
2016-08-24 10:52:30 +00:00
|
|
|
"fieldtype": "Select",
|
|
|
|
"options": "Cost Center\nProject",
|
|
|
|
"default": "Cost Center",
|
|
|
|
"reqd": 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"fieldname": "fiscal_year",
|
|
|
|
"label": __("Fiscal Year"),
|
|
|
|
"fieldtype": "Link",
|
|
|
|
"options": "Fiscal Year",
|
|
|
|
"default": frappe.defaults.get_user_default("fiscal_year"),
|
|
|
|
"reqd": 1,
|
|
|
|
"on_change": function(query_report) {
|
|
|
|
var fiscal_year = query_report.get_values().fiscal_year;
|
|
|
|
if (!fiscal_year) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
frappe.model.with_doc("Fiscal Year", fiscal_year, function(r) {
|
|
|
|
var fy = frappe.model.get_doc("Fiscal Year", fiscal_year);
|
2018-07-18 03:58:44 +00:00
|
|
|
frappe.query_report.set_filter_value({
|
|
|
|
from_date: fy.year_start_date,
|
|
|
|
to_date: fy.year_end_date
|
|
|
|
});
|
2016-08-24 10:52:30 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"fieldname": "from_date",
|
|
|
|
"label": __("From Date"),
|
|
|
|
"fieldtype": "Date",
|
|
|
|
"default": frappe.defaults.get_user_default("year_start_date"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"fieldname": "to_date",
|
|
|
|
"label": __("To Date"),
|
|
|
|
"fieldtype": "Date",
|
|
|
|
"default": frappe.defaults.get_user_default("year_end_date"),
|
2016-08-24 12:26:09 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"fieldname": "show_zero_values",
|
|
|
|
"label": __("Show zero values"),
|
|
|
|
"fieldtype": "Check"
|
2016-08-24 10:52:30 +00:00
|
|
|
}
|
|
|
|
],
|
2018-07-20 09:41:55 +00:00
|
|
|
"formatter": function(value, row, column, data, default_formatter) {
|
|
|
|
if (column.fieldname=="account") {
|
|
|
|
value = data.account_name;
|
2016-08-24 13:42:14 +00:00
|
|
|
|
2018-07-20 09:41:55 +00:00
|
|
|
column.link_onclick =
|
|
|
|
"frappe.query_reports['Profitability Analysis'].open_profit_and_loss_statement(" + JSON.stringify(data) + ")";
|
|
|
|
column.is_tree = true;
|
2016-08-24 13:42:14 +00:00
|
|
|
}
|
|
|
|
|
2018-07-20 09:41:55 +00:00
|
|
|
value = default_formatter(value, row, column, data);
|
2016-08-24 13:42:14 +00:00
|
|
|
|
2018-07-20 09:41:55 +00:00
|
|
|
if (!data.parent_account && data.based_on != 'project') {
|
|
|
|
value = $(`<span>${value}</span>`);
|
2016-08-24 13:42:14 +00:00
|
|
|
var $value = $(value).css("font-weight", "bold");
|
2018-07-20 11:05:51 +00:00
|
|
|
if (data.warn_if_negative && data[column.fieldname] < 0) {
|
2016-08-24 13:42:14 +00:00
|
|
|
$value.addClass("text-danger");
|
|
|
|
}
|
|
|
|
|
|
|
|
value = $value.wrap("<p></p>").parent().html();
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
},
|
|
|
|
"open_profit_and_loss_statement": function(data) {
|
|
|
|
if (!data.account) return;
|
|
|
|
|
|
|
|
frappe.route_options = {
|
2018-07-18 03:58:44 +00:00
|
|
|
"company": frappe.query_report.get_filter_value('company'),
|
2016-08-24 13:42:14 +00:00
|
|
|
"from_fiscal_year": data.fiscal_year,
|
|
|
|
"to_fiscal_year": data.fiscal_year
|
|
|
|
};
|
|
|
|
|
|
|
|
if(data.based_on == 'cost_center'){
|
|
|
|
frappe.route_options["cost_center"] = data.account
|
|
|
|
} else {
|
|
|
|
frappe.route_options["project"] = data.account
|
|
|
|
}
|
|
|
|
|
|
|
|
frappe.set_route("query-report", "Profit and Loss Statement");
|
|
|
|
},
|
2016-08-24 10:52:30 +00:00
|
|
|
"tree": true,
|
|
|
|
"name_field": "account",
|
|
|
|
"parent_field": "parent_account",
|
|
|
|
"initial_depth": 3
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|