2018-02-12 09:34:50 +00:00
|
|
|
// Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors
|
2013-12-06 11:06:23 +00:00
|
|
|
// License: GNU General Public License v3. See license.txt
|
|
|
|
|
2014-02-14 10:17:51 +00:00
|
|
|
frappe.query_reports["General Ledger"] = {
|
2013-12-06 11:06:23 +00:00
|
|
|
"filters": [
|
|
|
|
{
|
|
|
|
"fieldname":"company",
|
2014-04-14 10:55:30 +00:00
|
|
|
"label": __("Company"),
|
2013-12-06 11:06:23 +00:00
|
|
|
"fieldtype": "Link",
|
|
|
|
"options": "Company",
|
2015-12-23 11:07:00 +00:00
|
|
|
"default": frappe.defaults.get_user_default("Company"),
|
2013-12-06 11:06:23 +00:00
|
|
|
"reqd": 1
|
|
|
|
},
|
2018-04-22 20:59:22 +00:00
|
|
|
{
|
|
|
|
"fieldname":"finance_book",
|
|
|
|
"label": __("Finance Book"),
|
|
|
|
"fieldtype": "Link",
|
2018-05-09 09:40:29 +00:00
|
|
|
"options": "Finance Book"
|
2018-04-22 20:59:22 +00:00
|
|
|
},
|
2013-12-06 11:06:23 +00:00
|
|
|
{
|
|
|
|
"fieldname":"from_date",
|
2014-04-14 10:55:30 +00:00
|
|
|
"label": __("From Date"),
|
2013-12-06 11:06:23 +00:00
|
|
|
"fieldtype": "Date",
|
2014-02-14 10:17:51 +00:00
|
|
|
"default": frappe.datetime.add_months(frappe.datetime.get_today(), -1),
|
2013-12-06 11:06:23 +00:00
|
|
|
"reqd": 1,
|
|
|
|
"width": "60px"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"fieldname":"to_date",
|
2014-04-14 10:55:30 +00:00
|
|
|
"label": __("To Date"),
|
2013-12-06 11:06:23 +00:00
|
|
|
"fieldtype": "Date",
|
2014-02-14 10:17:51 +00:00
|
|
|
"default": frappe.datetime.get_today(),
|
2013-12-06 11:06:23 +00:00
|
|
|
"reqd": 1,
|
|
|
|
"width": "60px"
|
2013-12-27 12:03:55 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"fieldname":"account",
|
2014-04-14 10:55:30 +00:00
|
|
|
"label": __("Account"),
|
2013-12-27 12:03:55 +00:00
|
|
|
"fieldtype": "Link",
|
|
|
|
"options": "Account",
|
|
|
|
"get_query": function() {
|
2018-07-18 03:58:44 +00:00
|
|
|
var company = frappe.query_report.get_filter_value('company');
|
2013-12-27 12:03:55 +00:00
|
|
|
return {
|
2015-01-12 06:48:54 +00:00
|
|
|
"doctype": "Account",
|
2013-12-27 12:03:55 +00:00
|
|
|
"filters": {
|
|
|
|
"company": company,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"fieldname":"voucher_no",
|
2014-04-14 10:55:30 +00:00
|
|
|
"label": __("Voucher No"),
|
2013-12-27 12:03:55 +00:00
|
|
|
"fieldtype": "Data",
|
2018-04-19 09:39:46 +00:00
|
|
|
on_change: function() {
|
2018-07-18 03:58:44 +00:00
|
|
|
frappe.query_report.set_filter_value('group_by', "");
|
2018-04-19 09:39:46 +00:00
|
|
|
}
|
2013-12-27 12:03:55 +00:00
|
|
|
},
|
2018-08-27 06:38:53 +00:00
|
|
|
{
|
|
|
|
"fieldname":"cost_center",
|
|
|
|
"label": __("Cost Center"),
|
|
|
|
"fieldtype": "MultiSelect",
|
|
|
|
get_data: function() {
|
|
|
|
var cost_centers = frappe.query_report.get_filter_value("cost_center") || "";
|
|
|
|
|
|
|
|
const values = cost_centers.split(/\s*,\s*/).filter(d => d);
|
|
|
|
const txt = cost_centers.match(/[^,\s*]*$/)[0] || '';
|
|
|
|
let data = [];
|
|
|
|
|
|
|
|
frappe.call({
|
|
|
|
type: "GET",
|
|
|
|
method:'frappe.desk.search.search_link',
|
|
|
|
async: false,
|
|
|
|
no_spinner: true,
|
|
|
|
args: {
|
|
|
|
doctype: "Cost Center",
|
|
|
|
txt: txt,
|
|
|
|
filters: {
|
|
|
|
"company": frappe.query_report.get_filter_value("company"),
|
|
|
|
"name": ["not in", values]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
callback: function(r) {
|
|
|
|
data = r.results;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
},
|
2017-01-24 09:42:24 +00:00
|
|
|
{
|
|
|
|
"fieldname":"project",
|
|
|
|
"label": __("Project"),
|
2018-08-27 06:38:53 +00:00
|
|
|
"fieldtype": "MultiSelect",
|
|
|
|
get_data: function() {
|
|
|
|
var projects = frappe.query_report.get_filter_value("project") || "";
|
|
|
|
|
|
|
|
const values = projects.split(/\s*,\s*/).filter(d => d);
|
|
|
|
const txt = projects.match(/[^,\s*]*$/)[0] || '';
|
|
|
|
let data = [];
|
|
|
|
|
|
|
|
frappe.call({
|
|
|
|
type: "GET",
|
|
|
|
method:'frappe.desk.search.search_link',
|
|
|
|
async: false,
|
|
|
|
no_spinner: true,
|
|
|
|
args: {
|
|
|
|
doctype: "Project",
|
|
|
|
txt: txt,
|
|
|
|
filters: {
|
|
|
|
"name": ["not in", values]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
callback: function(r) {
|
|
|
|
data = r.results;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return data;
|
|
|
|
}
|
2017-01-24 09:42:24 +00:00
|
|
|
},
|
2015-01-12 06:48:54 +00:00
|
|
|
{
|
|
|
|
"fieldtype": "Break",
|
|
|
|
},
|
2015-04-20 11:43:43 +00:00
|
|
|
{
|
|
|
|
"fieldname":"party_type",
|
|
|
|
"label": __("Party Type"),
|
2017-02-01 06:32:08 +00:00
|
|
|
"fieldtype": "Link",
|
|
|
|
"options": "Party Type",
|
2018-03-27 05:59:25 +00:00
|
|
|
"default": "",
|
|
|
|
on_change: function() {
|
2018-07-18 03:58:44 +00:00
|
|
|
frappe.query_report.set_filter_value('party', "");
|
2018-03-27 05:59:25 +00:00
|
|
|
}
|
2015-04-20 11:43:43 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"fieldname":"party",
|
|
|
|
"label": __("Party"),
|
2018-05-03 13:30:43 +00:00
|
|
|
"fieldtype": "MultiSelect",
|
|
|
|
get_data: function() {
|
2018-07-20 11:01:01 +00:00
|
|
|
if (!frappe.query_report.filters) return;
|
2018-07-18 03:58:44 +00:00
|
|
|
var party_type = frappe.query_report.get_filter_value('party_type');
|
|
|
|
var parties = frappe.query_report.get_filter_value('party');
|
2018-05-16 12:00:58 +00:00
|
|
|
if(!party_type) return;
|
2018-05-03 13:30:43 +00:00
|
|
|
|
|
|
|
const values = parties.split(/\s*,\s*/).filter(d => d);
|
|
|
|
const txt = parties.match(/[^,\s*]*$/)[0] || '';
|
|
|
|
let data = [];
|
|
|
|
|
|
|
|
frappe.call({
|
|
|
|
type: "GET",
|
|
|
|
method:'frappe.desk.search.search_link',
|
|
|
|
async: false,
|
|
|
|
no_spinner: true,
|
|
|
|
args: {
|
2018-07-18 03:58:44 +00:00
|
|
|
doctype: frappe.query_report.get_filter_value('party_type'),
|
2018-05-03 13:30:43 +00:00
|
|
|
txt: txt,
|
|
|
|
filters: {
|
|
|
|
"name": ["not in", values]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
callback: function(r) {
|
|
|
|
data = r.results;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return data;
|
2017-05-11 06:08:30 +00:00
|
|
|
},
|
2017-06-27 06:26:30 +00:00
|
|
|
on_change: function() {
|
2018-07-18 03:58:44 +00:00
|
|
|
var party_type = frappe.query_report.get_filter_value('party_type');
|
|
|
|
var parties = frappe.query_report.get_filter_value('party');
|
2018-05-03 13:30:43 +00:00
|
|
|
const values = parties.split(/\s*,\s*/).filter(d => d);
|
|
|
|
|
|
|
|
if(!party_type || !parties || values.length>1) {
|
2018-07-18 03:58:44 +00:00
|
|
|
frappe.query_report.set_filter_value('party_name', "");
|
|
|
|
frappe.query_report.set_filter_value('tax_id', "");
|
2017-05-11 06:08:30 +00:00
|
|
|
return;
|
2018-05-03 13:30:43 +00:00
|
|
|
} else {
|
|
|
|
var party = values[0];
|
|
|
|
var fieldname = erpnext.utils.get_party_name(party_type) || "name";
|
|
|
|
frappe.db.get_value(party_type, party, fieldname, function(value) {
|
2018-07-18 03:58:44 +00:00
|
|
|
frappe.query_report.set_filter_value('party_name', value[fieldname]);
|
2018-03-23 09:34:37 +00:00
|
|
|
});
|
2018-05-03 13:30:43 +00:00
|
|
|
|
|
|
|
if (party_type === "Customer" || party_type === "Supplier") {
|
|
|
|
frappe.db.get_value(party_type, party, "tax_id", function(value) {
|
2018-07-18 03:58:44 +00:00
|
|
|
frappe.query_report.set_filter_value('tax_id', value["tax_id"]);
|
2018-05-03 13:30:43 +00:00
|
|
|
});
|
|
|
|
}
|
2018-03-23 09:34:37 +00:00
|
|
|
}
|
2015-04-20 11:43:43 +00:00
|
|
|
}
|
|
|
|
},
|
2017-05-11 06:08:30 +00:00
|
|
|
{
|
|
|
|
"fieldname":"party_name",
|
|
|
|
"label": __("Party Name"),
|
|
|
|
"fieldtype": "Data",
|
|
|
|
"hidden": 1
|
|
|
|
},
|
2018-04-17 09:42:26 +00:00
|
|
|
{
|
|
|
|
"fieldname":"group_by",
|
|
|
|
"label": __("Group by"),
|
|
|
|
"fieldtype": "Select",
|
2018-11-12 11:28:24 +00:00
|
|
|
"options": ["", __("Group by Voucher"), __("Group by Voucher (Consolidated)"),
|
|
|
|
__("Group by Account"), __("Group by Party")],
|
|
|
|
"default": __("Group by Voucher (Consolidated)")
|
2018-04-17 09:42:26 +00:00
|
|
|
},
|
2018-03-23 09:34:37 +00:00
|
|
|
{
|
|
|
|
"fieldname":"tax_id",
|
|
|
|
"label": __("Tax Id"),
|
|
|
|
"fieldtype": "Data",
|
|
|
|
"hidden": 1
|
|
|
|
},
|
2018-01-18 04:02:43 +00:00
|
|
|
{
|
2018-02-12 09:34:50 +00:00
|
|
|
"fieldname": "presentation_currency",
|
|
|
|
"label": __("Currency"),
|
|
|
|
"fieldtype": "Select",
|
|
|
|
"options": erpnext.get_presentation_currency_list()
|
2013-12-06 11:06:23 +00:00
|
|
|
}
|
|
|
|
]
|
2015-01-12 06:48:54 +00:00
|
|
|
}
|
2019-05-12 13:04:23 +00:00
|
|
|
|
|
|
|
let dimension_filters = get_dimension_filters();
|
|
|
|
|
|
|
|
dimension_filters.then((dimensions) => {
|
|
|
|
dimensions.forEach((dimension) => {
|
|
|
|
frappe.query_reports["General Ledger"].filters.push({
|
|
|
|
"fieldname": dimension["fieldname"],
|
|
|
|
"label": __(dimension["label"]),
|
|
|
|
"fieldtype": "Link",
|
|
|
|
"options": dimension["document_type"]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
async function get_dimension_filters() {
|
|
|
|
let dimensions = await frappe.db.get_list('Accounting Dimension', {
|
|
|
|
fields: ['label', 'fieldname', 'document_type'],
|
|
|
|
});
|
|
|
|
|
|
|
|
return dimensions;
|
|
|
|
}
|