mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-25 07:54:46 +00:00
[minor] fetch debit/credit based on against JV
This commit is contained in:
@@ -59,6 +59,50 @@ erpnext.accounts.JournalVoucher = wn.ui.form.Controller.extend({
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
against_voucher: function(doc, cdt, cdn) {
|
||||||
|
var d = wn.model.get_doc(cdt, cdn);
|
||||||
|
if (d.against_voucher && !flt(d.debit)) {
|
||||||
|
this.get_outstanding({
|
||||||
|
'doctype': 'Purchase Invoice',
|
||||||
|
'docname': d.against_voucher
|
||||||
|
}, d)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
against_invoice: function(doc, cdt, cdn) {
|
||||||
|
var d = wn.model.get_doc(cdt, cdn);
|
||||||
|
if (d.against_invoice && !flt(d.credit)) {
|
||||||
|
this.get_outstanding({
|
||||||
|
'doctype': 'Sales Invoice',
|
||||||
|
'docname': d.against_invoice
|
||||||
|
}, d)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
against_jv: function(doc, cdt, cdn) {
|
||||||
|
var d = wn.model.get_doc(cdt, cdn);
|
||||||
|
if (d.against_jv && !flt(d.credit) && !flt(d.debit)) {
|
||||||
|
this.get_outstanding({
|
||||||
|
'doctype': 'Journal Voucher',
|
||||||
|
'docname': d.against_jv,
|
||||||
|
'account': d.account
|
||||||
|
}, d)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
get_outstanding: function(args, child) {
|
||||||
|
var me = this;
|
||||||
|
return this.frm.call({
|
||||||
|
child: child,
|
||||||
|
method: "get_outstanding",
|
||||||
|
args: { args: args},
|
||||||
|
callback: function(r) {
|
||||||
|
cur_frm.cscript.update_totals(me.frm.doc);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
cur_frm.script_manager.make(erpnext.accounts.JournalVoucher);
|
cur_frm.script_manager.make(erpnext.accounts.JournalVoucher);
|
||||||
@@ -88,24 +132,6 @@ cur_frm.cscript.is_opening = function(doc, cdt, cdn) {
|
|||||||
if (doc.is_opening == 'Yes') unhide_field('aging_date');
|
if (doc.is_opening == 'Yes') unhide_field('aging_date');
|
||||||
}
|
}
|
||||||
|
|
||||||
cur_frm.cscript.against_voucher = function(doc,cdt,cdn) {
|
|
||||||
var d = locals[cdt][cdn];
|
|
||||||
if (d.against_voucher && !flt(d.debit)) {
|
|
||||||
args = {'doctype': 'Purchase Invoice', 'docname': d.against_voucher }
|
|
||||||
return get_server_fields('get_outstanding',docstring(args),'entries',doc,cdt,cdn,1,function(r,rt) { cur_frm.cscript.update_totals(doc); });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cur_frm.cscript.against_invoice = function(doc,cdt,cdn) {
|
|
||||||
var d = locals[cdt][cdn];
|
|
||||||
if (d.against_invoice && !flt(d.credit)) {
|
|
||||||
args = {'doctype': 'Sales Invoice', 'docname': d.against_invoice }
|
|
||||||
return get_server_fields('get_outstanding',docstring(args),'entries',doc,cdt,cdn,1,function(r,rt) { cur_frm.cscript.update_totals(doc); });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update Totals
|
|
||||||
|
|
||||||
cur_frm.cscript.update_totals = function(doc) {
|
cur_frm.cscript.update_totals = function(doc) {
|
||||||
var td=0.0; var tc =0.0;
|
var td=0.0; var tc =0.0;
|
||||||
var el = getchildren('Journal Voucher Detail', doc.name, 'entries');
|
var el = getchildren('Journal Voucher Detail', doc.name, 'entries');
|
||||||
|
|||||||
@@ -260,15 +260,6 @@ class DocType(AccountsController):
|
|||||||
if gl_map:
|
if gl_map:
|
||||||
make_gl_entries(gl_map, cancel=cancel, adv_adj=adv_adj)
|
make_gl_entries(gl_map, cancel=cancel, adv_adj=adv_adj)
|
||||||
|
|
||||||
def get_outstanding(self, args):
|
|
||||||
args = eval(args)
|
|
||||||
o_s = webnotes.conn.sql("""select outstanding_amount from `tab%s` where name = %s""" %
|
|
||||||
(args['doctype'], '%s'), args['docname'])
|
|
||||||
if args['doctype'] == 'Purchase Invoice':
|
|
||||||
return {'debit': o_s and flt(o_s[0][0]) or 0}
|
|
||||||
if args['doctype'] == 'Sales Invoice':
|
|
||||||
return {'credit': o_s and flt(o_s[0][0]) or 0}
|
|
||||||
|
|
||||||
def get_balance(self):
|
def get_balance(self):
|
||||||
if not getlist(self.doclist,'entries'):
|
if not getlist(self.doclist,'entries'):
|
||||||
msgprint("Please enter atleast 1 entry in 'GL Entries' table")
|
msgprint("Please enter atleast 1 entry in 'GL Entries' table")
|
||||||
@@ -434,4 +425,31 @@ def get_against_jv(doctype, txt, searchfield, start, page_len, filters):
|
|||||||
where jv_detail.parent = jv.name and jv_detail.account = %s and jv.docstatus = 1
|
where jv_detail.parent = jv.name and jv_detail.account = %s and jv.docstatus = 1
|
||||||
and jv.%s like %s order by jv.name desc limit %s, %s""" %
|
and jv.%s like %s order by jv.name desc limit %s, %s""" %
|
||||||
("%s", searchfield, "%s", "%s", "%s"),
|
("%s", searchfield, "%s", "%s", "%s"),
|
||||||
(filters["account"], "%%%s%%" % txt, start, page_len))
|
(filters["account"], "%%%s%%" % txt, start, page_len))
|
||||||
|
|
||||||
|
@webnotes.whitelist()
|
||||||
|
def get_outstanding(args):
|
||||||
|
args = eval(args)
|
||||||
|
if args.get("doctype") == "Journal Voucher" and args.get("account"):
|
||||||
|
against_jv_amount = webnotes.conn.sql("""
|
||||||
|
select sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))
|
||||||
|
from `tabJournal Voucher Detail` where parent=%s and account=%s
|
||||||
|
and ifnull(against_invoice, '')='' and ifnull(against_voucher, '')=''
|
||||||
|
and ifnull(against_jv, '')=''""", (args['docname'], args['account']))
|
||||||
|
|
||||||
|
against_jv_amount = flt(against_jv_amount[0][0]) if against_jv_amount else 0
|
||||||
|
if against_jv_amount > 0:
|
||||||
|
return {"credit": against_jv_amount}
|
||||||
|
else:
|
||||||
|
return {"debit": -1* against_jv_amount}
|
||||||
|
|
||||||
|
elif args.get("doctype") == "Sales Invoice":
|
||||||
|
return {
|
||||||
|
"credit": flt(webnotes.conn.get_value("Sales Invoice", args["docname"],
|
||||||
|
"outstanding_amount"))
|
||||||
|
}
|
||||||
|
elif args.get("doctype") == "Purchase Invoice":
|
||||||
|
return {
|
||||||
|
"debit": flt(webnotes.conn.get_value("Purchase Invoice", args["docname"],
|
||||||
|
"outstanding_amount"))
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) {
|
|||||||
|
|
||||||
wn.provide("erpnext.support");
|
wn.provide("erpnext.support");
|
||||||
// TODO commonify this code
|
// TODO commonify this code
|
||||||
erpnext.support.CustomerIssue = wn.ui.form.Controller.extend({
|
erpnext.support.SupportTicket = wn.ui.form.Controller.extend({
|
||||||
customer: function() {
|
customer: function() {
|
||||||
var me = this;
|
var me = this;
|
||||||
if(this.frm.doc.customer) {
|
if(this.frm.doc.customer) {
|
||||||
@@ -18,7 +18,7 @@ erpnext.support.CustomerIssue = wn.ui.form.Controller.extend({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$.extend(cur_frm.cscript, new erpnext.support.CustomerIssue({frm: cur_frm}));
|
$.extend(cur_frm.cscript, new erpnext.support.SupportTicket({frm: cur_frm}));
|
||||||
|
|
||||||
$.extend(cur_frm.cscript, {
|
$.extend(cur_frm.cscript, {
|
||||||
onload: function(doc, dt, dn) {
|
onload: function(doc, dt, dn) {
|
||||||
|
|||||||
Reference in New Issue
Block a user