This commit is contained in:
Saurabh 2013-06-21 16:35:50 +05:30
commit d35a69b450
5 changed files with 91 additions and 20 deletions

View File

@ -63,11 +63,21 @@ erpnext.GeneralLedger = wn.views.GridReport.extend({
open_btn: true, open_btn: true,
doctype: "dataContext.voucher_type" doctype: "dataContext.voucher_type"
}}, }},
{id: "against_voucher_type", name: "Against Voucher Type",
field: "against_voucher_type", width: 120},
{id: "against_voucher", name: "Against Voucher",
field: "against_voucher", width: 160,
link_formatter: {
filter_input: "against_voucher",
open_btn: true,
doctype: "dataContext.against_voucher_type"
}},
{id: "remarks", name: "Remarks", field: "remarks", width: 200, {id: "remarks", name: "Remarks", field: "remarks", width: 200,
formatter: this.text_formatter}, formatter: this.text_formatter},
]; ];
}, },
filters: [ filters: [
{fieldtype:"Select", label: "Company", link:"Company", default_value: "Select Company...", {fieldtype:"Select", label: "Company", link:"Company", default_value: "Select Company...",
filter: function(val, item, opts) { filter: function(val, item, opts) {
@ -96,6 +106,7 @@ erpnext.GeneralLedger = wn.views.GridReport.extend({
return dateutil.str_to_obj(val) >= dateutil.str_to_obj(item.posting_date); return dateutil.str_to_obj(val) >= dateutil.str_to_obj(item.posting_date);
}}, }},
{fieldtype: "Check", label: "Group by Ledger"}, {fieldtype: "Check", label: "Group by Ledger"},
{fieldtype: "Check", label: "Group by Voucher"},
{fieldtype:"Button", label: "Refresh", icon:"icon-refresh icon-white", cssClass:"btn-info"}, {fieldtype:"Button", label: "Refresh", icon:"icon-refresh icon-white", cssClass:"btn-info"},
{fieldtype:"Button", label: "Reset Filters"} {fieldtype:"Button", label: "Reset Filters"}
], ],
@ -116,9 +127,14 @@ erpnext.GeneralLedger = wn.views.GridReport.extend({
me.filter_inputs.group_by_ledger me.filter_inputs.group_by_ledger
.parent().toggle(!!(me.account_by_name[$(this).val()] .parent().toggle(!!(me.account_by_name[$(this).val()]
&& me.account_by_name[$(this).val()].group_or_ledger==="Group")); && me.account_by_name[$(this).val()].group_or_ledger==="Group"));
me.filter_inputs.group_by_voucher
.parent().toggle(!!(me.account_by_name[$(this).val()]
&& me.account_by_name[$(this).val()].group_or_ledger==="Ledger"));
}); });
this.trigger_refresh_on_change(["group_by_ledger"]); this.trigger_refresh_on_change(["group_by_ledger"]);
this.trigger_refresh_on_change(["group_by_voucher"]);
}, },
setup_account_filter: function(company_filter) { setup_account_filter: function(company_filter) {
var me = this; var me = this;
@ -139,12 +155,14 @@ erpnext.GeneralLedger = wn.views.GridReport.extend({
init_filter_values: function() { init_filter_values: function() {
this._super(); this._super();
this.filter_inputs.group_by_ledger.parent().toggle(false); this.filter_inputs.group_by_ledger.parent().toggle(false);
this.filter_inputs.group_by_voucher.parent().toggle(false);
this.filter_inputs.company.change(); this.filter_inputs.company.change();
this.filter_inputs.account.change(); this.filter_inputs.account.change();
}, },
apply_filters_from_route: function() { apply_filters_from_route: function() {
this._super(); this._super();
this.filter_inputs.group_by_ledger.parent().toggle(false); this.filter_inputs.group_by_ledger.parent().toggle(false);
this.filter_inputs.group_by_voucher.parent().toggle(false);
this.filter_inputs.company.change(); this.filter_inputs.company.change();
this.filter_inputs.account.change(); this.filter_inputs.account.change();
}, },
@ -196,13 +214,21 @@ erpnext.GeneralLedger = wn.views.GridReport.extend({
if(!grouped_ledgers[item.account]) { if(!grouped_ledgers[item.account]) {
grouped_ledgers[item.account] = { grouped_ledgers[item.account] = {
entries: [], entries: [],
entries_group_by_voucher: {},
opening: me.make_summary_row("Opening", item.account), opening: me.make_summary_row("Opening", item.account),
totals: me.make_summary_row("Totals", item.account), totals: me.make_summary_row("Totals", item.account),
closing: me.make_summary_row("Closing (Opening + Totals)", closing: me.make_summary_row("Closing (Opening + Totals)",
item.account) item.account)
}; };
} }
if(!grouped_ledgers[item.account].entries_group_by_voucher[item.voucher_no]) {
grouped_ledgers[item.account].entries_group_by_voucher[item.voucher_no] = {
entries: [],
totals: me.make_summary_row("Totals", item.voucher_no)
}
}
if(date < from_date || item.is_opening=="Yes") { if(date < from_date || item.is_opening=="Yes") {
opening.debit += item.debit; opening.debit += item.debit;
opening.credit += item.credit; opening.credit += item.credit;
@ -215,6 +241,11 @@ erpnext.GeneralLedger = wn.views.GridReport.extend({
grouped_ledgers[item.account].totals.debit += item.debit; grouped_ledgers[item.account].totals.debit += item.debit;
grouped_ledgers[item.account].totals.credit += item.credit; grouped_ledgers[item.account].totals.credit += item.credit;
grouped_ledgers[item.account].entries_group_by_voucher[item.voucher_no]
.totals.debit += item.debit;
grouped_ledgers[item.account].entries_group_by_voucher[item.voucher_no]
.totals.credit += item.credit;
} }
if(item.account) { if(item.account) {
item.against_account = me.voucher_accounts[item.voucher_type + ":" item.against_account = me.voucher_accounts[item.voucher_type + ":"
@ -224,6 +255,9 @@ erpnext.GeneralLedger = wn.views.GridReport.extend({
if(me.apply_filters(item) && item.is_opening=="No") { if(me.apply_filters(item) && item.is_opening=="No") {
out.push(item); out.push(item);
grouped_ledgers[item.account].entries.push(item); grouped_ledgers[item.account].entries.push(item);
grouped_ledgers[item.account].entries_group_by_voucher[item.voucher_no]
.entries.push(item);
} }
} }
}); });
@ -241,6 +275,11 @@ erpnext.GeneralLedger = wn.views.GridReport.extend({
out = this.group_data_by_ledger(grouped_ledgers); out = this.group_data_by_ledger(grouped_ledgers);
} }
if(this.account_by_name[this.account].group_or_ledger==="Ledger"
&& this.group_by_voucher) {
out = this.group_data_by_voucher(grouped_ledgers);
}
opening = me.get_balance(me.account_by_name[me.account].debit_or_credit, opening) opening = me.get_balance(me.account_by_name[me.account].debit_or_credit, opening)
closing = me.get_balance(me.account_by_name[me.account].debit_or_credit, closing) closing = me.get_balance(me.account_by_name[me.account].debit_or_credit, closing)
@ -283,6 +322,28 @@ erpnext.GeneralLedger = wn.views.GridReport.extend({
return [{id: "_blank_first", _no_format: true, debit: "", credit: ""}].concat(out); return [{id: "_blank_first", _no_format: true, debit: "", credit: ""}].concat(out);
}, },
group_data_by_voucher: function(grouped_ledgers) {
var me = this;
var out = []
$.each(Object.keys(grouped_ledgers).sort(), function(i, account) {
if(grouped_ledgers[account].entries.length) {
$.each(Object.keys(grouped_ledgers[account].entries_group_by_voucher).sort(),
function(j, voucher) {
if(grouped_ledgers[account].entries_group_by_voucher[voucher]
.entries.length) {
out = out.concat(grouped_ledgers[account]
.entries_group_by_voucher[voucher].entries)
.concat([
grouped_ledgers[account].entries_group_by_voucher[voucher]
.totals, {id: "_blank" + j, _no_format: true,
debit: "", credit: ""}]);
}
});
}
});
return [{id: "_blank_first", _no_format: true, debit: "", credit: ""}].concat(out);
},
get_balance: function(debit_or_credit, balance) { get_balance: function(debit_or_credit, balance) {
if(debit_or_credit == "Debit") { if(debit_or_credit == "Debit") {
balance.debit -= balance.credit; balance.credit = 0; balance.debit -= balance.credit; balance.credit = 0;

View File

@ -128,23 +128,27 @@ erpnext.buying.BuyingController = wn.ui.form.Controller.extend({
}, },
currency: function() { currency: function() {
this.set_dynamic_labels(); if(this.frm.doc.currency === this.get_company_currency())
this.frm.set_value("conversion_rate", 1.0);
this.price_list_currency();
}, },
company: function() { company: function() {
this.set_dynamic_labels(); if(this.frm.fields_dict.currency)
this.set_dynamic_labels();
}, },
price_list_currency: function() { price_list_currency: function() {
this.frm.toggle_reqd("plc_conversion_rate", this.frm.toggle_reqd("plc_conversion_rate",
!!(this.frm.doc.price_list_name && this.frm.doc.price_list_currency)); !!(this.frm.doc.price_list_name && this.frm.doc.price_list_currency));
this.set_dynamic_labels();
if(this.frm.doc.price_list_currency === this.get_company_currency()) if(this.frm.doc.price_list_currency === this.get_company_currency())
this.frm.set_value("plc_conversion_rate", 1.0); this.frm.set_value("plc_conversion_rate", 1.0);
else if(this.frm.doc.price_list_currency === this.frm.doc.currency) else if(this.frm.doc.price_list_currency === this.frm.doc.currency)
this.frm.set_value("plc_conversion_rate", this.frm.doc.conversion_rate || 1.0); this.frm.set_value("plc_conversion_rate", this.frm.doc.conversion_rate || 1.0);
this.set_dynamic_labels();
}, },
set_dynamic_labels: function(doc, dt, dn) { set_dynamic_labels: function(doc, dt, dn) {

View File

@ -89,9 +89,10 @@ def get_data(filters, conditions):
row = webnotes.conn.sql("""select DISTINCT(%s) from `tab%s` t1, `tab%s Item` t2 %s row = webnotes.conn.sql("""select DISTINCT(%s) from `tab%s` t1, `tab%s Item` t2 %s
where t2.parent = t1.name and t1.company = %s and t1.fiscal_year = %s where t2.parent = t1.name and t1.company = %s and t1.fiscal_year = %s
and t1.docstatus = 1 and %s = %s and t1.docstatus = 1 and %s = %s
"""%(sel_col, conditions["trans"], conditions["trans"], conditions["addl_tables"], "%s", "%s", """ %
conditions["group_by"], "%s"), (filters.get("company"), filters.get("fiscal_year"), (sel_col, conditions["trans"], conditions["trans"], conditions["addl_tables"],
data1[d][0]), as_list=1) "%s", "%s", conditions["group_by"], "%s"),
(filters.get("company"), filters.get("fiscal_year"), data1[d][0]), as_list=1)
for i in range(len(row)): for i in range(len(row)):
des = ['' for q in range(len(conditions["columns"]))] des = ['' for q in range(len(conditions["columns"]))]
@ -100,9 +101,12 @@ def get_data(filters, conditions):
row1 = webnotes.conn.sql(""" select %s , %s from `tab%s` t1, `tab%s Item` t2 %s row1 = webnotes.conn.sql(""" select %s , %s from `tab%s` t1, `tab%s Item` t2 %s
where t2.parent = t1.name and t1.company = %s and t1.fiscal_year = %s where t2.parent = t1.name and t1.company = %s and t1.fiscal_year = %s
and t1.docstatus = 1 and %s = %s and %s = %s and t1.docstatus = 1 and %s = %s and %s = %s
""" % (sel_col, conditions["period_wise_select"], conditions["trans"], conditions["trans"], """ %
conditions["addl_tables"], "%s", "%s", sel_col, "%s", conditions["group_by"], "%s"), (sel_col, conditions["period_wise_select"], conditions["trans"],
(filters.get("company"), filters.get("fiscal_year"), row[i][0], data1[d][0]), as_list=1) conditions["trans"], conditions["addl_tables"], "%s", "%s", sel_col,
"%s", conditions["group_by"], "%s"),
(filters.get("company"), filters.get("fiscal_year"), row[i][0],
data1[d][0]), as_list=1)
des[ind] = row[i] des[ind] = row[i]
for j in range(1,len(conditions["columns"])-inc): for j in range(1,len(conditions["columns"])-inc):
@ -114,9 +118,10 @@ def get_data(filters, conditions):
where t2.parent = t1.name and t1.company = %s and t1.fiscal_year = %s and where t2.parent = t1.name and t1.company = %s and t1.fiscal_year = %s and
t1.docstatus = 1 %s t1.docstatus = 1 %s
group by %s group by %s
"""%(query_details, conditions["trans"], conditions["trans"], conditions["addl_tables"], "%s", """ %
"%s", cond,conditions["group_by"]), (filters.get("company"), (query_details, conditions["trans"], conditions["trans"], conditions["addl_tables"],
filters.get("fiscal_year")), as_list=1) "%s", "%s", cond,conditions["group_by"]),
(filters.get("company"), filters.get("fiscal_year")), as_list=1)
return data return data
@ -138,7 +143,8 @@ def period_wise_colums_query(filters, trans):
get_period_wise_columns(dt, filters.get("period"), pwc) get_period_wise_columns(dt, filters.get("period"), pwc)
query_details = get_period_wise_query(dt, trans_date, query_details) query_details = get_period_wise_query(dt, trans_date, query_details)
else: else:
pwc = [filters.get("fiscal_year")+" (Qty):Float:120", filters.get("fiscal_year")+" (Amt):Currency:120"] pwc = [filters.get("fiscal_year") + " (Qty):Float:120",
filters.get("fiscal_year") + " (Amt):Currency:120"]
query_details = " SUM(t2.qty), SUM(t1.grand_total)," query_details = " SUM(t2.qty), SUM(t1.grand_total),"
query_details += 'SUM(t2.qty), SUM(t1.grand_total)' query_details += 'SUM(t2.qty), SUM(t1.grand_total)'
@ -153,10 +159,9 @@ def get_period_wise_columns(bet_dates, period, pwc):
get_mon(bet_dates[0]) + "-" + get_mon(bet_dates[1]) + " (Amt):Currency:120"] get_mon(bet_dates[0]) + "-" + get_mon(bet_dates[1]) + " (Amt):Currency:120"]
def get_period_wise_query(bet_dates, trans_date, query_details): def get_period_wise_query(bet_dates, trans_date, query_details):
query_details += """SUM(IF(t1.%(trans_date)s BETWEEN '%(sd)s' AND '%(ed)s', t2.qty, NULL)), query_details += """SUM(IF(t1.%(trans_date)s BETWEEN '%(sd)s' AND '%(ed)s', t2.qty, NULL)),
SUM(IF(t1.%(trans_date)s BETWEEN '%(sd)s' AND '%(ed)s', t1.grand_total, NULL)), SUM(IF(t1.%(trans_date)s BETWEEN '%(sd)s' AND '%(ed)s', t1.grand_total, NULL)),
"""%{"trans_date": trans_date, "sd": bet_dates[0],"ed": bet_dates[1]} """ % {"trans_date": trans_date, "sd": bet_dates[0],"ed": bet_dates[1]}
return query_details return query_details
def get_period_date_ranges(period, fiscal_year): def get_period_date_ranges(period, fiscal_year):

View File

@ -22,7 +22,7 @@ def execute():
i=0 i=0
for d in res: for d in res:
try: try:
update_entries_after({ "item_code": d[0], "warehouse": d[1] }) update_entries_after({ "item_code": d[0], "warehouse": d[1]})
except: except:
pass pass
i += 1 i += 1

View File

@ -47,8 +47,9 @@ data_map = {
"order_by": "lft" "order_by": "lft"
}, },
"GL Entry": { "GL Entry": {
"columns": ["name", "account", "posting_date", "cost_center", "debit", "credit", "is_opening", "columns": ["name", "account", "posting_date", "cost_center", "debit", "credit",
"company", "voucher_type", "voucher_no", "remarks"], "is_opening", "company", "voucher_type", "voucher_no", "remarks",
"against_voucher_type", "against_voucher"],
"conditions": ["ifnull(is_cancelled, 'No')='No'"], "conditions": ["ifnull(is_cancelled, 'No')='No'"],
"order_by": "posting_date, account", "order_by": "posting_date, account",
"links": { "links": {