feat: add grand total field

This commit is contained in:
Mangesh-Khairnar 2019-06-12 18:18:38 +05:30
parent 444313bdfc
commit a1d354e147
3 changed files with 64 additions and 43 deletions

View File

@ -112,9 +112,6 @@ cur_frm.cscript.calculate_total = function(doc){
doc.total_claimed_amount += d.amount; doc.total_claimed_amount += d.amount;
doc.total_sanctioned_amount += d.sanctioned_amount; doc.total_sanctioned_amount += d.sanctioned_amount;
}); });
refresh_field("total_claimed_amount");
refresh_field('total_sanctioned_amount');
}; };
cur_frm.cscript.calculate_total_amount = function(doc,cdt,cdn){ cur_frm.cscript.calculate_total_amount = function(doc,cdt,cdn){
@ -157,14 +154,14 @@ frappe.ui.form.on("Expense Claim", {
} }
}; };
}); });
// frm.set_query("taxes", "account_head", function(doc) { frm.set_query("account_head", "taxes", function(doc) {
// return { return {
// filters: [ filters: [
// ['docstatus', '=', 1], ['company', '=', doc.company],
// ['company', '=', doc.company] ['account_type', 'in', ["Tax", "Chargeable", "Income Account", "Expenses Included In Valuation"]]
// ] ]
// }; };
// }); });
}, },
onload: function(frm) { onload: function(frm) {
@ -205,6 +202,12 @@ frappe.ui.form.on("Expense Claim", {
} }
}, },
calculate_grand_total: function(frm) {
var grand_total = flt(frm.doc.total_sanctioned_amount) + flt(frm.doc.total_taxes_and_charges) - flt(frm.doc.total_advance_amount);
frm.set_value("grand_total", grand_total);
frm.refresh_fields();
},
make_payment_entry: function(frm) { make_payment_entry: function(frm) {
var method = "erpnext.accounts.doctype.payment_entry.payment_entry.get_payment_entry"; var method = "erpnext.accounts.doctype.payment_entry.payment_entry.get_payment_entry";
if(frm.doc.__onload && frm.doc.__onload.make_payment_via_journal_entry) { if(frm.doc.__onload && frm.doc.__onload.make_payment_via_journal_entry) {
@ -319,6 +322,7 @@ frappe.ui.form.on("Expense Claim Detail", {
var doc = frm.doc; var doc = frm.doc;
cur_frm.cscript.calculate_total(doc,cdt,cdn); cur_frm.cscript.calculate_total(doc,cdt,cdn);
frm.trigger("get_taxes"); frm.trigger("get_taxes");
frm.trigger("calculate_grand_total");
} }
}); });
@ -345,6 +349,7 @@ frappe.ui.form.on("Expense Claim Advance", {
child.advance_paid = r.message[0].paid_amount; child.advance_paid = r.message[0].paid_amount;
child.unclaimed_amount = flt(r.message[0].paid_amount) - flt(r.message[0].claimed_amount); child.unclaimed_amount = flt(r.message[0].paid_amount) - flt(r.message[0].claimed_amount);
child.allocated_amount = flt(r.message[0].paid_amount) - flt(r.message[0].claimed_amount); child.allocated_amount = flt(r.message[0].paid_amount) - flt(r.message[0].claimed_amount);
frm.trigger('calculate_grand_total');
refresh_field("advances"); refresh_field("advances");
} }
} }
@ -370,27 +375,30 @@ frappe.ui.form.on("Expense Taxes and Charges", {
} }
}, },
calculate_total: function(frm, cdt, cdn) { calculate_total_tax: function(frm, cdt, cdn) {
var child = locals[cdt][cdn]; var child = locals[cdt][cdn];
child.total = flt(frm.doc.total_sanctioned_amount) + flt(child.tax_amount); child.total = flt(frm.doc.total_sanctioned_amount) + flt(child.tax_amount);
frm.trigger("calculate_tax_amount", cdt, cdn);
},
refresh_field("taxes"); calculate_tax_amount: function(frm) {
frm.doc.total_taxes_and_charges = 0;
(frm.doc.taxes || []).forEach(function(d) {
frm.doc.total_taxes_and_charges += d.tax_amount;
});
frm.trigger("calculate_grand_total")
}, },
rate: function(frm, cdt, cdn) { rate: function(frm, cdt, cdn) {
var child = locals[cdt][cdn]; var child = locals[cdt][cdn];
if(!child.amount) { if(!child.amount) {
child.tax_amount = flt(frm.doc.total_sanctioned_amount) * (flt(child.rate)/100); child.tax_amount = flt(frm.doc.total_sanctioned_amount) * (flt(child.rate)/100);
refresh_field("taxes");
} }
frm.trigger("calculate_total", cdt, cdn) frm.trigger("calculate_total_tax", cdt, cdn)
}, },
tax_amount: function(frm, cdt, cdn) { tax_amount: function(frm, cdt, cdn) {
var child = locals[cdt][cdn]; frm.trigger("calculate_total_tax", cdt, cdn)
child.rate = flt(child.tax_amount/frm.doc.total_sanctioned_amount) * 100;
frm.trigger("calculate_total", cdt, cdn)
refresh_field("taxes");
} }
}); });

View File

@ -19,10 +19,13 @@
"sb1", "sb1",
"taxes", "taxes",
"transactions_section", "transactions_section",
"total_tax_amount",
"total_amount_reimbursed",
"total_sanctioned_amount", "total_sanctioned_amount",
"total_claimed_amount", "total_claimed_amount",
"total_advance_amount",
"column_break_17",
"total_amount_reimbursed",
"total_taxes_and_charges",
"grand_total",
"section_break_16", "section_break_16",
"posting_date", "posting_date",
"vehicle_log", "vehicle_log",
@ -44,8 +47,7 @@
"status", "status",
"amended_from", "amended_from",
"advance_payments", "advance_payments",
"advances", "advances"
"total_advance_amount"
], ],
"fields": [ "fields": [
{ {
@ -122,7 +124,6 @@
{ {
"fieldname": "total_sanctioned_amount", "fieldname": "total_sanctioned_amount",
"fieldtype": "Currency", "fieldtype": "Currency",
"in_list_view": 1,
"label": "Total Sanctioned Amount", "label": "Total Sanctioned Amount",
"no_copy": 1, "no_copy": 1,
"oldfieldname": "total_sanctioned_amount", "oldfieldname": "total_sanctioned_amount",
@ -337,9 +338,21 @@
"label": "Transactions" "label": "Transactions"
}, },
{ {
"fieldname": "total_tax_amount", "fieldname": "grand_total",
"fieldtype": "Currency", "fieldtype": "Currency",
"label": "Total Tax Amount", "in_list_view": 1,
"label": "Grand Total",
"options": "Company:company:default_currency",
"read_only": 1
},
{
"fieldname": "column_break_17",
"fieldtype": "Column Break"
},
{
"fieldname": "total_taxes_and_charges",
"fieldtype": "Currency",
"label": "Total Taxes and Charges",
"options": "Company:company:default_currency", "options": "Company:company:default_currency",
"read_only": 1 "read_only": 1
} }
@ -347,7 +360,7 @@
"icon": "fa fa-money", "icon": "fa fa-money",
"idx": 1, "idx": 1,
"is_submittable": 1, "is_submittable": 1,
"modified": "2019-06-12 12:32:13.775009", "modified": "2019-06-12 15:35:09.092603",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "HR", "module": "HR",
"name": "Expense Claim", "name": "Expense Claim",

View File

@ -104,15 +104,13 @@ class ExpenseClaim(AccountsController):
gl_entry = [] gl_entry = []
self.validate_account_details() self.validate_account_details()
payable_amount = flt(self.net_total) - flt(self.total_advance_amount)
# payable entry # payable entry
if payable_amount: if self.grand_total:
gl_entry.append( gl_entry.append(
self.get_gl_dict({ self.get_gl_dict({
"account": self.payable_account, "account": self.payable_account,
"credit": payable_amount, "credit": self.grand_total,
"credit_in_account_currency": payable_amount, "credit_in_account_currency": self.grand_total,
"against": ",".join([d.default_account for d in self.expenses]), "against": ",".join([d.default_account for d in self.expenses]),
"party_type": "Employee", "party_type": "Employee",
"party": self.employee, "party": self.employee,
@ -146,15 +144,16 @@ class ExpenseClaim(AccountsController):
"against_voucher": self.name "against_voucher": self.name
}) })
) )
self.add_tax_gl_entries(gl_entry)
if self.is_paid and payable_amount: if self.is_paid and self.grand_total:
# payment entry # payment entry
payment_account = get_bank_cash_account(self.mode_of_payment, self.company).get("account") payment_account = get_bank_cash_account(self.mode_of_payment, self.company).get("account")
gl_entry.append( gl_entry.append(
self.get_gl_dict({ self.get_gl_dict({
"account": payment_account, "account": payment_account,
"credit": payable_amount, "credit": self.grand_total,
"credit_in_account_currency": payable_amount, "credit_in_account_currency": self.grand_total,
"against": self.employee "against": self.employee
}) })
) )
@ -165,15 +164,13 @@ class ExpenseClaim(AccountsController):
"party_type": "Employee", "party_type": "Employee",
"party": self.employee, "party": self.employee,
"against": payment_account, "against": payment_account,
"debit": payable_amount, "debit": self.grand_total,
"debit_in_account_currency": payable_amount, "debit_in_account_currency": self.grand_total,
"against_voucher": self.name, "against_voucher": self.name,
"against_voucher_type": self.doctype, "against_voucher_type": self.doctype,
}) })
) )
self.add_tax_gl_entries(gl_entry)
return gl_entry return gl_entry
def add_tax_gl_entries(self, gl_entries): def add_tax_gl_entries(self, gl_entries):
@ -184,11 +181,12 @@ class ExpenseClaim(AccountsController):
self.get_gl_dict({ self.get_gl_dict({
"account": tax.account_head, "account": tax.account_head,
"debit": tax.tax_amount, "debit": tax.tax_amount,
"debit_in_account_currency": tax.tax_amount,
"against": self.employee, "against": self.employee,
"cost_center": self.cost_center, "cost_center": self.cost_center,
"against_voucher_type": self.doctype, "against_voucher_type": self.doctype,
"against_voucher": self.name "against_voucher": self.name
}, account_currency) })
) )
def validate_account_details(self): def validate_account_details(self):
@ -213,13 +211,15 @@ class ExpenseClaim(AccountsController):
self.total_sanctioned_amount += flt(d.sanctioned_amount) self.total_sanctioned_amount += flt(d.sanctioned_amount)
def calculate_taxes(self): def calculate_taxes(self):
self.total_taxes_and_charges = 0
for tax in self.taxes: for tax in self.taxes:
if tax.rate: if tax.rate:
tax.tax_amount = flt(self.total_sanctioned_amount) * flt(tax.rate/100) tax.tax_amount = flt(self.total_sanctioned_amount) * flt(tax.rate/100)
if tax.tax_amount:
tax.rate = flt(tax.tax_amount)/flt(self.total_sanctioned_amount) * 100
tax.total = flt(tax.tax_amount) + flt(self.total_sanctioned_amount) tax.total = flt(tax.tax_amount) + flt(self.total_sanctioned_amount)
self.net_total += tax.total self.total_taxes_and_charges += flt(tax.tax_amount)
self.grand_total = flt(self.total_sanctioned_amount) + flt(self.total_taxes_and_charges) - flt(self.total_advance_amount)
def update_task(self): def update_task(self):
task = frappe.get_doc("Task", self.task) task = frappe.get_doc("Task", self.task)