Payment Reconciliation based on party

This commit is contained in:
Nabin Hait 2014-09-12 13:08:10 +05:30
parent 894a1b539a
commit 034ac6b00b
4 changed files with 93 additions and 42 deletions

View File

@ -7,24 +7,32 @@ erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.ext
onload: function() {
var me = this
this.frm.set_query('party_account', function() {
if(!me.frm.doc.company) {
msgprint(__("Please select company first"));
this.frm.set_query('party_type', function() {
return {
filters: {
"name": ["in", ["Customer", "Supplier"]]
}
};
});
this.frm.set_query('receivable_payable_account', function() {
if(!me.frm.doc.company || !me.frm.doc.party_type) {
msgprint(__("Please select Company and Party Type first"));
} else {
return{
filters:[
['Account', 'company', '=', me.frm.doc.company],
['Account', 'group_or_ledger', '=', 'Ledger'],
['Account', 'master_type', 'in', ['Customer', 'Supplier']]
]
filters: {
"company": me.frm.doc.company,
"group_or_ledger": "Ledger",
"account_type": (me.frm.doc.party_type == "Customer" ? "Receivable" : "Payable")
}
};
}
});
this.frm.set_query('bank_cash_account', function() {
if(!me.frm.doc.company) {
msgprint(__("Please select company first"));
msgprint(__("Please select Company first"));
} else {
return{
filters:[
@ -40,7 +48,26 @@ erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.ext
'<ul>' + __("If you are unable to match the exact amount, then amend your Journal Voucher and split rows such that payment amount match the invoice amount.") + '</ul>';
this.frm.set_value("reconcile_help", help_content);
},
party: function() {
var me = this
if(!me.frm.doc.receivable_payable_account && me.frm.doc.party_type && me.frm.doc.party) {
return frappe.call({
method: "erpnext.accounts.party.get_party_account",
args: {
company: me.frm.doc.company,
party_type: me.frm.doc.party_type,
party: me.frm.doc.party
},
callback: function(r) {
if(!r.exc && r.message) {
me.frm.set_value("receivable_payable_account", r.message);
}
}
});
}
},
get_unreconciled_entries: function() {
var me = this;
return this.frm.call({
@ -48,12 +75,12 @@ erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.ext
method: 'get_unreconciled_entries',
callback: function(r, rt) {
var invoices = [];
$.each(me.frm.doc.payment_reconciliation_invoices || [], function(i, row) {
if (row.invoice_number && !inList(invoices, row.invoice_number))
if (row.invoice_number && !inList(invoices, row.invoice_number))
invoices.push(row.invoice_number);
});
frappe.meta.get_docfield("Payment Reconciliation Payment", "invoice_number",
me.frm.doc.name).options = invoices.join("\n");
@ -78,5 +105,3 @@ erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.ext
});
$.extend(cur_frm.cscript, new erpnext.accounts.PaymentReconciliationController({frm: cur_frm}));
cur_frm.add_fetch('party_account', 'master_type', 'party_type')

View File

@ -15,26 +15,35 @@
"reqd": 1
},
{
"depends_on": "",
"fieldname": "party_account",
"fieldname": "party_type",
"fieldtype": "Link",
"hidden": 0,
"in_list_view": 0,
"label": "Party Account",
"options": "Account",
"label": "Party Type",
"options": "DocType",
"permlevel": 0,
"read_only": 0,
"reqd": 1
},
{
"depends_on": "",
"fieldname": "party",
"fieldtype": "Dynamic Link",
"in_list_view": 0,
"label": "Party",
"options": "party_type",
"permlevel": 0,
"reqd": 1,
"search_index": 0
},
{
"fieldname": "party_type",
"fieldtype": "Select",
"hidden": 1,
"in_list_view": 1,
"label": "Party Type",
"options": "\nCustomer\nSupplier",
"fieldname": "receivable_payable_account",
"fieldtype": "Link",
"label": "Receivable / Payable Account",
"options": "Account",
"permlevel": 0,
"read_only": 1,
"reqd": 0
"precision": "",
"reqd": 1
},
{
"fieldname": "bank_cash_account",
@ -130,7 +139,7 @@
"hide_toolbar": 1,
"icon": "icon-resize-horizontal",
"issingle": 1,
"modified": "2014-07-31 05:43:03.410832",
"modified": "2014-09-12 12:18:15.956283",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Payment Reconciliation",

View File

@ -26,13 +26,14 @@ class PaymentReconciliation(Document):
jv_entries = frappe.db.sql("""
select
t1.name as voucher_no, t1.posting_date, t1.remark, t2.account,
t1.name as voucher_no, t1.posting_date, t1.remark,
t2.name as voucher_detail_no, {dr_or_cr} as payment_amount, t2.is_advance
from
`tabJournal Voucher` t1, `tabJournal Voucher Detail` t2
where
t1.name = t2.parent and t1.docstatus = 1 and t2.docstatus = 1
and t2.account = %(party_account)s and {dr_or_cr} > 0
and t2.party_type = %(party_type)s and t2.party = %(party)s
and t2.account = %(account)s and {dr_or_cr} > 0
and ifnull(t2.against_voucher, '')='' and ifnull(t2.against_invoice, '')=''
and ifnull(t2.against_jv, '')='' {cond}
and (CASE
@ -45,7 +46,9 @@ class PaymentReconciliation(Document):
"cond": cond,
"bank_account_condition": bank_account_condition,
}), {
"party_account": self.party_account,
"party_type": self.party_type,
"party": self.party,
"account": self.receivable_payable_account,
"bank_cash_account": "%%%s%%" % self.bank_cash_account
}, as_dict=1)
@ -75,12 +78,17 @@ class PaymentReconciliation(Document):
from
`tabGL Entry`
where
account = %s and {dr_or_cr} > 0 {cond}
party_type = %(party_type)s and party = %(party)s
and account = %(account)s and {dr_or_cr} > 0 {cond}
group by voucher_type, voucher_no
""".format(**{
"cond": cond,
"dr_or_cr": dr_or_cr
}), (self.party_account), as_dict=True)
}), {
"party_type": self.party_type,
"party": self.party,
"account": self.receivable_payable_account,
}, as_dict=True)
for d in invoice_list:
payment_amount = frappe.db.sql("""
@ -89,10 +97,17 @@ class PaymentReconciliation(Document):
from
`tabGL Entry`
where
account = %s and {0} > 0
and against_voucher_type = %s and ifnull(against_voucher, '') = %s
""".format("credit" if self.party_type == "Customer" else "debit"),
(self.party_account, d.voucher_type, d.voucher_no))
party_type = %(party_type)s and party = %(party)s
and account = %(account)s and {0} > 0
and against_voucher_type = %(against_voucher_type)s
and ifnull(against_voucher, '') = %(against_voucher)s
""".format("credit" if self.party_type == "Customer" else "debit"), {
"party_type": self.party_type,
"party": self.party,
"account": self.receivable_payable_account,
"against_voucher_type": d.voucher_type,
"against_voucher": d.voucher_no
})
payment_amount = payment_amount[0][0] if payment_amount else 0
@ -130,7 +145,9 @@ class PaymentReconciliation(Document):
'voucher_detail_no' : e.voucher_detail_number,
'against_voucher_type' : e.invoice_type,
'against_voucher' : e.invoice_number,
'account' : self.party_account,
'account' : self.receivable_payable_account,
'party_type': self.party_type,
'party': self.party,
'is_advance' : e.is_advance,
'dr_or_cr' : dr_or_cr,
'unadjusted_amt' : flt(e.amount),
@ -144,7 +161,7 @@ class PaymentReconciliation(Document):
self.get_unreconciled_entries()
def check_mandatory_to_fetch(self):
for fieldname in ["company", "party_account"]:
for fieldname in ["company", "party_type", "party", "receivable_payable_account"]:
if not self.get(fieldname):
frappe.throw(_("Please select {0} first").format(self.meta.get_label(fieldname)))

View File

@ -95,7 +95,7 @@
}
],
"istable": 1,
"modified": "2014-07-21 16:53:56.206169",
"modified": "2014-09-12 13:05:57.839280",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Payment Reconciliation Payment",