[Enhancement] Added allocate payment amount checkbox in Payment Entry

This commit is contained in:
Rohit Waghchaure 2016-09-28 17:24:02 +05:30
parent f1ad32059f
commit f21f1af0c9
3 changed files with 56 additions and 13 deletions

View File

@ -511,6 +511,18 @@ frappe.ui.form.on('Payment Entry', {
});
},
allocate_payment_amount: function(frm) {
if(frm.doc.payment_type == 'Internal Transfer'){
return
}
if(frm.doc.references.length == 0){
frm.events.get_outstanding_documents(frm);
}
frm.events.allocate_party_amount_against_ref_docs(frm, frm.doc.received_amount);
},
allocate_party_amount_against_ref_docs: function(frm, paid_amount) {
var total_positive_outstanding_including_order = 0;
var total_negative_outstanding = 0;
@ -552,22 +564,24 @@ frappe.ui.form.on('Payment Entry', {
}
$.each(frm.doc.references || [], function(i, row) {
row.allocated_amount = 0
row.allocated_amount = 0 //If allocate payment amount checkbox is unchecked, set zero to allocate amount
if(frm.doc.allocate_payment_amount){
if(row.outstanding_amount > 0 && allocated_positive_outstanding > 0) {
if(row.outstanding_amount >= allocated_positive_outstanding)
row.allocated_amount = allocated_positive_outstanding;
else row.allocated_amount = row.outstanding_amount;
if(row.outstanding_amount > 0 && allocated_positive_outstanding > 0) {
if(row.outstanding_amount >= allocated_positive_outstanding)
row.allocated_amount = allocated_positive_outstanding;
else row.allocated_amount = row.outstanding_amount;
allocated_positive_outstanding -= flt(row.allocated_amount);
} else if (row.outstanding_amount < 0 && allocated_negative_outstanding) {
if(Math.abs(row.outstanding_amount) >= allocated_negative_outstanding)
row.allocated_amount = -1*allocated_negative_outstanding;
else row.allocated_amount = row.outstanding_amount;
allocated_positive_outstanding -= flt(row.allocated_amount);
} else if (row.outstanding_amount < 0 && allocated_negative_outstanding) {
if(Math.abs(row.outstanding_amount) >= allocated_negative_outstanding)
row.allocated_amount = -1*allocated_negative_outstanding;
else row.allocated_amount = row.outstanding_amount;
allocated_negative_outstanding -= Math.abs(flt(row.allocated_amount));
allocated_negative_outstanding -= Math.abs(flt(row.allocated_amount));
}
}
})
frm.refresh_fields()
frm.events.set_total_allocated_amount(frm);
},

View File

@ -772,6 +772,34 @@
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"default": "1",
"depends_on": "eval:in_list(['Pay', 'Receive'], doc.payment_type)",
"fieldname": "allocate_payment_amount",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Allocate Payment Amount",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
@ -1426,7 +1454,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2016-09-05 11:06:18.183458",
"modified": "2016-09-28 18:20:47.625383",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Payment Entry",

View File

@ -669,6 +669,7 @@ def get_payment_entry(dt, dn, party_amount=None, bank_account=None, bank_amount=
pe.paid_to_account_currency = party_account_currency if payment_type=="Pay" else bank.account_currency
pe.paid_amount = paid_amount
pe.received_amount = received_amount
pe.allocate_payment_amount = 1
pe.append("references", {
"reference_doctype": dt,