Commonified sales/purchase taxes and charges master.js code
This commit is contained in:
parent
e7679703cf
commit
ce24512ed7
@ -1,80 +1,11 @@
|
||||
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
||||
// License: GNU General Public License v3. See license.txt
|
||||
|
||||
cur_frm.cscript.tax_table = "Purchase Taxes and Charges";
|
||||
|
||||
{% include "public/js/controllers/accounts.js" %}
|
||||
|
||||
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
|
||||
cur_frm.set_footnote(frappe.markdown(cur_frm.meta.description));
|
||||
}
|
||||
|
||||
// For customizing print
|
||||
cur_frm.pformat.net_total = function(doc) {
|
||||
return '';
|
||||
}
|
||||
|
||||
cur_frm.pformat.grand_total = function(doc) {
|
||||
return '';
|
||||
}
|
||||
|
||||
cur_frm.pformat.in_words = function(doc) {
|
||||
return '';
|
||||
}
|
||||
|
||||
cur_frm.pformat.taxes= function(doc) {
|
||||
|
||||
//function to make row of table
|
||||
var make_row = function(title, val, bold) {
|
||||
var bstart = '<b>'; var bend = '</b>';
|
||||
return '<tr><td style="width:50%;">' + (bold?bstart:'') + title + (bold?bend:'') + '</td>'
|
||||
+ '<td style="width:25%;text-align:right;"></td>'
|
||||
+ '<td style="width:25%;text-align:right;">' + format_currency(val, doc.currency) + '</td>'
|
||||
+ '</tr>';
|
||||
}
|
||||
|
||||
function convert_rate(val) {
|
||||
var new_val = flt(val)/flt(doc.conversion_rate);
|
||||
return new_val;
|
||||
}
|
||||
|
||||
function print_hide(fieldname) {
|
||||
var doc_field = frappe.meta.get_docfield(doc.doctype, fieldname, doc.name);
|
||||
return doc_field.print_hide;
|
||||
}
|
||||
|
||||
var cl = doc.taxes || [];
|
||||
|
||||
// outer table
|
||||
var out='<div><table class="noborder" style="width:100%">\
|
||||
<tr><td style="width: 60%"></td><td>';
|
||||
|
||||
// main table
|
||||
out +='<table class="noborder" style="width:100%">';
|
||||
if(!print_hide('net_total'))
|
||||
out += make_row('Net Total', doc.net_total, 1);
|
||||
|
||||
// add rows
|
||||
if(cl.length){
|
||||
for(var i=0; i<cl.length; i++) {
|
||||
out += make_row(cl[i].description, convert_rate(cl[i].tax_amount), 0);
|
||||
}
|
||||
}
|
||||
|
||||
// grand total
|
||||
if(!print_hide('grand_total'))
|
||||
out += make_row('Grand Total', doc.grand_total, 1);
|
||||
|
||||
if(doc.in_words && !print_hide('in_words')) {
|
||||
out += '</table></td></tr>';
|
||||
out += '<tr><td colspan = "2">';
|
||||
out += '<table><tr><td style="width:25%;"><b>In Words</b></td>';
|
||||
out += '<td style="width:50%;">' + doc.in_words + '</td></tr>';
|
||||
}
|
||||
|
||||
out +='</table></td></tr></table></div>';
|
||||
return out;
|
||||
}
|
||||
|
||||
cur_frm.cscript.add_deduct_tax = function(doc, cdt, cdn) {
|
||||
frappe.ui.form.on("Purchase Taxes and Charges", "add_deduct_tax", function(doc, cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
|
||||
if(!d.category && d.add_deduct_tax) {
|
||||
@ -85,96 +16,5 @@ cur_frm.cscript.add_deduct_tax = function(doc, cdt, cdn) {
|
||||
msgprint(__("Cannot deduct when category is for 'Valuation' or 'Valuation and Total'"));
|
||||
d.add_deduct_tax = '';
|
||||
}
|
||||
}
|
||||
|
||||
cur_frm.cscript.charge_type = function(doc, cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
|
||||
if(!d.category && d.charge_type) {
|
||||
msgprint(__("Please select Category first"));
|
||||
d.charge_type = '';
|
||||
}
|
||||
else if(d.idx == 1 && (d.charge_type == 'On Previous Row Amount' || d.charge_type == 'On Previous Row Total')) {
|
||||
msgprint(__("Cannot select charge type as 'On Previous Row Amount' or 'On Previous Row Total' for first row"));
|
||||
d.charge_type = '';
|
||||
}
|
||||
else if((d.category == 'Valuation' || d.category == 'Valuation and Total') && (d.charge_type == 'On Previous Row Amount' || d.charge_type == 'On Previous Row Total')) {
|
||||
msgprint(__("Cannot select charge type as 'On Previous Row Amount' or 'On Previous Row Total' for valuation. You can select only 'Total' option for previous row amount or previous row total"));
|
||||
d.charge_type = '';
|
||||
}
|
||||
|
||||
validated = false;
|
||||
refresh_field('charge_type', d.name, 'taxes');
|
||||
|
||||
cur_frm.cscript.row_id(doc, cdt, cdn);
|
||||
cur_frm.cscript.rate(doc, cdt, cdn);
|
||||
cur_frm.cscript.tax_amount(doc, cdt, cdn);
|
||||
}
|
||||
|
||||
|
||||
cur_frm.cscript.row_id = function(doc, cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
|
||||
if(!d.charge_type && d.row_id) {
|
||||
msgprint(__("Please select charge type first"));
|
||||
d.row_id = '';
|
||||
}
|
||||
else if((d.charge_type == 'Actual' || d.charge_type == 'On Net Total') && d.row_id) {
|
||||
msgprint(__("Can refer row only if the charge type is 'On Previous Row Amount' or 'Previous Row Total'"));
|
||||
d.row_id = '';
|
||||
}
|
||||
else if((d.charge_type == 'On Previous Row Amount' || d.charge_type == 'On Previous Row Total') && d.row_id) {
|
||||
if(d.row_id >= d.idx){
|
||||
msgprint(__("Cannot refer row number greater than or equal to current row number for this Charge type"));
|
||||
d.row_id = '';
|
||||
}
|
||||
}
|
||||
validated = false;
|
||||
refresh_field('row_id', d.name, 'taxes');
|
||||
}
|
||||
|
||||
cur_frm.set_query("account_head", "taxes", function(doc) {
|
||||
return {
|
||||
query: "erpnext.controllers.queries.tax_account_query",
|
||||
filters: {
|
||||
"account_type": ["Tax", "Chargeable", "Expense Account"],
|
||||
"company": doc.company
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
cur_frm.fields_dict['taxes'].grid.get_field("cost_center").get_query = function(doc) {
|
||||
return {
|
||||
filters: {
|
||||
'company': doc.company,
|
||||
'group_or_ledger': "Ledger"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cur_frm.cscript.rate = function(doc, cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
|
||||
if(!d.charge_type && d.rate) {
|
||||
msgprint(__("Please select Charge Type first"));
|
||||
d.rate = '';
|
||||
}
|
||||
validated = false;
|
||||
refresh_field('rate', d.name, 'taxes');
|
||||
}
|
||||
|
||||
cur_frm.cscript.tax_amount = function(doc, cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
|
||||
if(!d.charge_type && d.tax_amount) {
|
||||
msgprint(__("Please select Charge Type first"));
|
||||
d.tax_amount = '';
|
||||
}
|
||||
else if(d.charge_type && d.tax_amount) {
|
||||
msgprint(__("Cannot directly set amount. For 'Actual' charge type, use the rate field"));
|
||||
d.tax_amount = '';
|
||||
}
|
||||
|
||||
validated = false;
|
||||
refresh_field('tax_amount', d.name, 'taxes');
|
||||
refresh_field('add_deduct_tax', d.name, 'taxes');
|
||||
}
|
||||
|
@ -1,174 +1,11 @@
|
||||
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
||||
// License: GNU General Public License v3. See license.txt
|
||||
|
||||
cur_frm.cscript.tax_table = "Sales Taxes and Charges";
|
||||
|
||||
{% include "public/js/controllers/accounts.js" %}
|
||||
|
||||
cur_frm.cscript.onload = function(doc, cdt, cdn) {
|
||||
if(doc.doctype === "Sales Taxes and Charges Master")
|
||||
erpnext.add_applicable_territory();
|
||||
}
|
||||
|
||||
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
|
||||
cur_frm.set_footnote(frappe.markdown(cur_frm.meta.description));
|
||||
}
|
||||
|
||||
// For customizing print
|
||||
cur_frm.pformat.net_total = function(doc) {
|
||||
return '';
|
||||
}
|
||||
|
||||
cur_frm.pformat.discount_amount = function(doc) {
|
||||
return '';
|
||||
}
|
||||
|
||||
cur_frm.pformat.grand_total = function(doc) {
|
||||
return '';
|
||||
}
|
||||
|
||||
cur_frm.pformat.rounded_total = function(doc) {
|
||||
return '';
|
||||
}
|
||||
|
||||
cur_frm.pformat.in_words = function(doc) {
|
||||
return '';
|
||||
}
|
||||
|
||||
cur_frm.pformat.taxes= function(doc){
|
||||
//function to make row of table
|
||||
var make_row = function(title, val, bold){
|
||||
var bstart = '<b>'; var bend = '</b>';
|
||||
return '<tr><td style="width:50%;">' + (bold?bstart:'') + title + (bold?bend:'') + '</td>'
|
||||
+ '<td style="width:50%;text-align:right;">' + format_currency(val, doc.currency) + '</td>'
|
||||
+ '</tr>';
|
||||
}
|
||||
|
||||
function convert_rate(val) {
|
||||
var new_val = flt(val)/flt(doc.conversion_rate);
|
||||
return new_val;
|
||||
}
|
||||
|
||||
function print_hide(fieldname) {
|
||||
var doc_field = frappe.meta.get_docfield(doc.doctype, fieldname, doc.name);
|
||||
return doc_field.print_hide;
|
||||
}
|
||||
|
||||
out ='';
|
||||
if (!doc.print_without_amount) {
|
||||
var cl = doc.taxes || [];
|
||||
|
||||
// outer table
|
||||
var out='<div><table class="noborder" style="width:100%"><tr><td style="width: 60%"></td><td>';
|
||||
|
||||
// main table
|
||||
|
||||
out +='<table class="noborder" style="width:100%">';
|
||||
|
||||
if(!print_hide('net_total')) {
|
||||
out += make_row('Net Total', doc.net_total, 1);
|
||||
}
|
||||
|
||||
// add rows
|
||||
if(cl.length){
|
||||
for(var i=0;i<cl.length;i++) {
|
||||
if(convert_rate(cl[i].tax_amount)!=0 && !cl[i].included_in_print_rate)
|
||||
out += make_row(cl[i].description, convert_rate(cl[i].tax_amount), 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Discount Amount
|
||||
if(!print_hide('discount_amount') && doc.discount_amount)
|
||||
out += make_row('Discount Amount', doc.discount_amount, 0);
|
||||
|
||||
// grand total
|
||||
if(!print_hide('grand_total'))
|
||||
out += make_row('Grand Total', doc.grand_total, 1);
|
||||
|
||||
if(!print_hide('rounded_total'))
|
||||
out += make_row('Rounded Total', doc.rounded_total, 1);
|
||||
|
||||
if(doc.in_words && !print_hide('in_words')) {
|
||||
out +='</table></td></tr>';
|
||||
out += '<tr><td colspan = "2">';
|
||||
out += '<table><tr><td style="width:25%;"><b>In Words</b></td>';
|
||||
out += '<td style="width:50%;">' + doc.in_words + '</td></tr>';
|
||||
}
|
||||
out += '</table></td></tr></table></div>';
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
cur_frm.cscript.charge_type = function(doc, cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
if(d.idx == 1 && (d.charge_type == 'On Previous Row Amount' || d.charge_type == 'On Previous Row Total')) {
|
||||
msgprint(__("Cannot select charge type as 'On Previous Row Amount' or 'On Previous Row Total' for first row"));
|
||||
d.charge_type = '';
|
||||
}
|
||||
validated = false;
|
||||
refresh_field('charge_type', d.name, 'taxes');
|
||||
cur_frm.cscript.row_id(doc, cdt, cdn);
|
||||
cur_frm.cscript.rate(doc, cdt, cdn);
|
||||
cur_frm.cscript.tax_amount(doc, cdt, cdn);
|
||||
}
|
||||
|
||||
cur_frm.cscript.row_id = function(doc, cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
if(!d.charge_type && d.row_id) {
|
||||
msgprint(__("Please select Charge Type first"));
|
||||
d.row_id = '';
|
||||
}
|
||||
else if((d.charge_type == 'Actual' || d.charge_type == 'On Net Total') && d.row_id) {
|
||||
msgprint(__("Can refer row only if the charge type is 'On Previous Row Amount' or 'Previous Row Total'"));
|
||||
d.row_id = '';
|
||||
}
|
||||
else if((d.charge_type == 'On Previous Row Amount' || d.charge_type == 'On Previous Row Total') && d.row_id) {
|
||||
if(d.row_id >= d.idx){
|
||||
msgprint(__("Cannot refer row number greater than or equal to current row number for this Charge type"));
|
||||
d.row_id = '';
|
||||
}
|
||||
}
|
||||
validated = false;
|
||||
refresh_field('row_id', d.name, 'taxes');
|
||||
}
|
||||
|
||||
/*---------------------- Get rate if account_head has account_type as TAX or CHARGEABLE-------------------------------------*/
|
||||
|
||||
cur_frm.fields_dict['taxes'].grid.get_field("account_head").get_query = function(doc,cdt,cdn) {
|
||||
return{
|
||||
query: "erpnext.controllers.queries.tax_account_query",
|
||||
filters: {
|
||||
"account_type": ["Tax", "Chargeable", "Income Account"],
|
||||
"company": doc.company
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cur_frm.fields_dict['taxes'].grid.get_field("cost_center").get_query = function(doc) {
|
||||
return{
|
||||
'company': doc.company,
|
||||
'group_or_ledger': "Ledger"
|
||||
}
|
||||
}
|
||||
|
||||
cur_frm.cscript.rate = function(doc, cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
if(!d.charge_type && d.rate) {
|
||||
msgprint(__("Please select Charge Type first"));
|
||||
d.rate = '';
|
||||
}
|
||||
validated = false;
|
||||
refresh_field('rate', d.name, 'taxes');
|
||||
}
|
||||
|
||||
cur_frm.cscript.tax_amount = function(doc, cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
if(!d.charge_type && d.tax_amount) {
|
||||
msgprint(__("Please select Charge Type first"));
|
||||
d.tax_amount = '';
|
||||
}
|
||||
// else if(d.charge_type && d.tax_amount) {
|
||||
// msgprint(__("Cannot directly set amount. For 'Actual' charge type, use the rate field"));
|
||||
// d.tax_amount = '';
|
||||
// }
|
||||
validated = false;
|
||||
refresh_field('tax_amount', d.name, 'taxes');
|
||||
};
|
||||
|
@ -90,20 +90,6 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
|
||||
this.price_list_rate(doc, cdt, cdn);
|
||||
},
|
||||
|
||||
rate: function(doc, cdt, cdn) {
|
||||
var item = frappe.get_doc(cdt, cdn);
|
||||
frappe.model.round_floats_in(item, ["rate", "discount_percentage"]);
|
||||
|
||||
if(item.price_list_rate) {
|
||||
item.discount_percentage = flt((1 - item.rate / item.price_list_rate) * 100.0,
|
||||
precision("discount_percentage", item));
|
||||
} else {
|
||||
item.discount_percentage = 0.0;
|
||||
}
|
||||
|
||||
this.calculate_taxes_and_totals();
|
||||
},
|
||||
|
||||
uom: function(doc, cdt, cdn) {
|
||||
var me = this;
|
||||
var item = frappe.get_doc(cdt, cdn);
|
||||
@ -293,3 +279,8 @@ erpnext.buying.get_default_bom = function(frm) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
frappe.ui.form.on("Purchase Taxes and Charges", "rate", function(frm, cdt, cdn) {
|
||||
cur_frm.cscript.calculate_taxes_and_totals();
|
||||
})
|
||||
|
@ -290,6 +290,8 @@ class calculate_taxes_and_totals(object):
|
||||
tax.tax_amount = flt(tax.tax_amount, tax.precision("tax_amount"))
|
||||
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount, tax.precision("tax_amount"))
|
||||
|
||||
self._set_in_company_currency(tax, ["total", "tax_amount", "tax_amount_after_discount_amount"]);
|
||||
|
||||
def adjust_discount_amount_loss(self, tax):
|
||||
discount_amount_loss = self.doc.grand_total - flt(self.doc.discount_amount) - tax.total
|
||||
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount +
|
||||
|
@ -77,7 +77,6 @@ $.extend(cur_frm.cscript, {
|
||||
},
|
||||
callback: function(r) {
|
||||
if(!r.exc) {
|
||||
console.log(r.message)
|
||||
cur_frm.set_value("workstation", r.message)
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,9 @@
|
||||
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
||||
// License: GNU General Public License v3. See license.txt
|
||||
|
||||
frappe.ui.form.on(cur_frm.doctype, "refresh", function(frm) {
|
||||
frm.set_footnote(frappe.markdown(frm.meta.description));
|
||||
}
|
||||
|
||||
// get tax rate
|
||||
cur_frm.cscript.account_head = function(doc, cdt, cdn) {
|
||||
@ -8,7 +14,7 @@ cur_frm.cscript.account_head = function(doc, cdt, cdn) {
|
||||
} else if(d.account_head && d.charge_type!=="Actual") {
|
||||
frappe.call({
|
||||
type:"GET",
|
||||
method: "erpnext.controllers.accounts_controller.get_tax_rate",
|
||||
method: "erpnext.controllers.accounts_controller.get_tax_rate",
|
||||
args: {"account_head":d.account_head},
|
||||
callback: function(r) {
|
||||
frappe.model.set_value(cdt, cdn, "rate", r.message || 0);
|
||||
@ -16,3 +22,139 @@ cur_frm.cscript.account_head = function(doc, cdt, cdn) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var validate_taxes_and_charges = function(cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
if(!d.charge_type && (d.row_id || d.rate || d.tax_amount)) {
|
||||
msgprint(__("Please select Charge Type first"));
|
||||
d.row_id = ""
|
||||
d.rate = d.tax_amount = 0.0
|
||||
} else if((d.charge_type == 'Actual' || d.charge_type == 'On Net Total') && d.row_id) {
|
||||
msgprint(__("Can refer row only if the charge type is 'On Previous Row Amount' or 'Previous Row Total'"));
|
||||
d.row_id = "";
|
||||
} else if((d.charge_type == 'On Previous Row Amount' || d.charge_type == 'On Previous Row Total') && d.row_id) {
|
||||
if (d.idx == 1) {
|
||||
msgprint(__("Cannot select charge type as 'On Previous Row Amount' or 'On Previous Row Total' for first row"));
|
||||
d.charge_type = '';
|
||||
} else if (d.row_i && d.row_id >= d.idx) {
|
||||
msgprint(__("Cannot refer row number greater than or equal to current row number for this Charge type"));
|
||||
d.row_id = "";
|
||||
}
|
||||
}
|
||||
validated = false;
|
||||
refresh_field('row_id', d.name, 'taxes');
|
||||
}
|
||||
|
||||
frappe.ui.form.on(cur_frm.cscript.tax_table, "row_id", function(frm, cdt, cdn) {
|
||||
validate_taxes_and_charges(cdt, cdn);
|
||||
})
|
||||
|
||||
frappe.ui.form.on(cur_frm.cscript.tax_table, "rate", function(frm, cdt, cdn) {
|
||||
validate_taxes_and_charges(cdt, cdn);
|
||||
})
|
||||
|
||||
frappe.ui.form.on(cur_frm.cscript.tax_table, "tax_amount", function(frm, cdt, cdn) {
|
||||
validate_taxes_and_charges(cdt, cdn);
|
||||
})
|
||||
|
||||
frappe.ui.form.on(cur_frm.cscript.tax_table, "charge_type", function(frm, cdt, cdn) {
|
||||
validate_taxes_and_charges(cdt, cdn);
|
||||
})
|
||||
|
||||
|
||||
cur_frm.set_query("account_head", "taxes", function(doc) {
|
||||
if(cur_frm.cscript.tax_table == "Sales Taxes and Charges") {
|
||||
var account_type = ["Tax", "Chargeable", "Expense Account"];
|
||||
} else {
|
||||
var account_type = ["Tax", "Chargeable", "Income Account"];
|
||||
}
|
||||
|
||||
return {
|
||||
query: "erpnext.controllers.queries.tax_account_query",
|
||||
filters: {
|
||||
"account_type": account_type,
|
||||
"company": doc.company
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
cur_frm.set_query("cost_center", "taxes", function(doc) {
|
||||
return {
|
||||
filters: {
|
||||
'company': doc.company,
|
||||
'group_or_ledger': "Ledger"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For customizing print
|
||||
cur_frm.pformat.print_total = function(doc) { return ''; }
|
||||
cur_frm.pformat.discount_amount = function(doc) { return ''; }
|
||||
cur_frm.pformat.grand_total = function(doc) { return ''; }
|
||||
cur_frm.pformat.rounded_total = function(doc) { return ''; }
|
||||
cur_frm.pformat.in_words = function(doc) { return ''; }
|
||||
|
||||
cur_frm.pformat.taxes= function(doc){
|
||||
//function to make row of table
|
||||
var make_row = function(title, val, bold){
|
||||
var bstart = '<b>'; var bend = '</b>';
|
||||
return '<tr><td style="width:50%;">' + (bold?bstart:'') + title + (bold?bend:'') + '</td>'
|
||||
+ '<td style="width:50%;text-align:right;">' + format_currency(val, doc.currency) + '</td>'
|
||||
+ '</tr>';
|
||||
}
|
||||
|
||||
function convert_rate(val) {
|
||||
var new_val = flt(val)/flt(doc.conversion_rate);
|
||||
return new_val;
|
||||
}
|
||||
|
||||
function print_hide(fieldname) {
|
||||
var doc_field = frappe.meta.get_docfield(doc.doctype, fieldname, doc.name);
|
||||
return doc_field.print_hide;
|
||||
}
|
||||
|
||||
out ='';
|
||||
if (!doc.print_without_amount) {
|
||||
var cl = doc.taxes || [];
|
||||
|
||||
// outer table
|
||||
var out='<div><table class="noborder" style="width:100%"><tr><td style="width: 60%"></td><td>';
|
||||
|
||||
// main table
|
||||
|
||||
out +='<table class="noborder" style="width:100%">';
|
||||
|
||||
if(!print_hide('print_total')) {
|
||||
out += make_row('Net Total', doc.print_total, 1);
|
||||
}
|
||||
|
||||
// add rows
|
||||
if(cl.length){
|
||||
for(var i=0;i<cl.length;i++) {
|
||||
if(convert_rate(cl[i].tax_amount)!=0 && !cl[i].included_in_print_rate)
|
||||
out += make_row(cl[i].description, convert_rate(cl[i].tax_amount), 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Discount Amount
|
||||
if(!print_hide('discount_amount') && doc.discount_amount)
|
||||
out += make_row('Discount Amount', doc.discount_amount, 0);
|
||||
|
||||
// grand total
|
||||
if(!print_hide('grand_total'))
|
||||
out += make_row('Grand Total', doc.grand_total, 1);
|
||||
|
||||
if(!print_hide('rounded_total'))
|
||||
out += make_row('Rounded Total', doc.rounded_total, 1);
|
||||
|
||||
if(doc.in_words && !print_hide('in_words')) {
|
||||
out +='</table></td></tr>';
|
||||
out += '<tr><td colspan = "2">';
|
||||
out += '<table><tr><td style="width:25%;"><b>In Words</b></td>';
|
||||
out += '<td style="width:50%;">' + doc.in_words + '</td></tr>';
|
||||
}
|
||||
out += '</table></td></tr></table></div>';
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
@ -67,16 +67,17 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
||||
item.net_amount = item.amount;
|
||||
item.item_tax_amount = 0.0;
|
||||
|
||||
this.set_in_company_currency(item, ["price_list_rate", "rate", "amount", "net_rate", "net_amount"]);
|
||||
me.set_in_company_currency(item, ["price_list_rate", "rate", "amount", "net_rate", "net_amount"]);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
set_in_company_currency: function(doc, fields) {
|
||||
var me = this;
|
||||
$.each(fields, function(i, f) {
|
||||
doc["base_"+f] = flt(flt(doc[f], precision(f, doc)) * me.frm.doc.conversion_rate, precision("base_" + f, doc));
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
initialize_taxes: function() {
|
||||
var me = this;
|
||||
@ -99,6 +100,8 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
||||
},
|
||||
|
||||
determine_exclusive_rate: function() {
|
||||
var me = this;
|
||||
|
||||
var has_inclusive_tax = false;
|
||||
$.each(me.frm.doc["taxes"] || [], function(i, row) {
|
||||
if(cint(row.included_in_print_rate)) has_inclusive_tax = true;
|
||||
@ -106,7 +109,6 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
||||
if(has_inclusive_tax==false || !in_list(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"], this.frm.doc.doctype))
|
||||
return;
|
||||
|
||||
var me = this;
|
||||
$.each(me.frm.doc["items"] || [], function(n, item) {
|
||||
var item_tax_map = me._load_item_tax_rate(item.item_tax_rate);
|
||||
var cumulated_tax_fraction = 0.0;
|
||||
@ -132,7 +134,7 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
||||
|
||||
item.net_rate = flt(item.net_amount / item.qty, precision("net_rate", item));
|
||||
|
||||
this.set_in_company_currency(item, ["net_rate", "net_amount"]);
|
||||
me.set_in_company_currency(item, ["net_rate", "net_amount"]);
|
||||
|
||||
// if(item.discount_percentage == 100) {
|
||||
// item.base_price_list_rate = item.base_rate;
|
||||
@ -295,7 +297,7 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
||||
// store tax breakup for each item
|
||||
var key = item.item_code || item.item_name;
|
||||
var item_wise_tax_amount = current_tax_amount * this.frm.doc.conversion_rate;
|
||||
if (tax.item_wise_tax_detail.get(key))
|
||||
if (tax.item_wise_tax_detail && tax.item_wise_tax_detail[key])
|
||||
item_wise_tax_amount += tax.item_wise_tax_detail[key][1]
|
||||
|
||||
tax.item_wise_tax_detail[key] = [tax_rate,flt(item_wise_tax_amount, precision("base_tax_amount", tax))]
|
||||
@ -305,8 +307,9 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
||||
round_off_totals: function(tax) {
|
||||
tax.total = flt(tax.total, precision("total", tax));
|
||||
tax.tax_amount = flt(tax.tax_amount, precision("tax_amount", tax));
|
||||
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount,
|
||||
precision("tax_amount", tax));
|
||||
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount, precision("tax_amount", tax));
|
||||
|
||||
this.set_in_company_currency(tax, ["total", "tax_amount", "tax_amount_after_discount_amount"]);
|
||||
},
|
||||
|
||||
adjust_discount_amount_loss: function(tax) {
|
||||
@ -330,7 +333,7 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
||||
this.frm.doc.taxes_and_charges_added = this.frm.doc.taxes_and_charges_deducted = 0.0;
|
||||
if(tax_count) {
|
||||
$.each(this.frm.doc["taxes"] || [], function(i, tax) {
|
||||
if in_list(["Valuation and Total", "Total"], tax.category) {
|
||||
if (in_list(["Valuation and Total", "Total"], tax.category)) {
|
||||
if(tax.add_deduct_tax == "Add") {
|
||||
me.frm.doc.taxes_and_charges_added += flt(tax.tax_amount);
|
||||
} else {
|
||||
|
@ -274,8 +274,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
this.apply_pricing_rule(frappe.get_doc(cdt, cdn), true);
|
||||
},
|
||||
|
||||
// tax rate
|
||||
rate: function(doc, cdt, cdn) {
|
||||
tax_amount: function(doc, cdt, cdn) {
|
||||
this.calculate_taxes_and_totals();
|
||||
},
|
||||
|
||||
@ -638,3 +637,16 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
frappe.ui.form.on(cur_frm.doctype + "Item", "rate", function(frm, cdt, cdn) {
|
||||
var item = frappe.get_doc(cdt, cdn);
|
||||
frappe.model.round_floats_in(item, ["rate", "price_list_rate"]);
|
||||
|
||||
if(item.price_list_rate) {
|
||||
item.discount_percentage = flt((1 - item.rate / item.price_list_rate) * 100.0, precision("discount_percentage", item));
|
||||
} else {
|
||||
item.discount_percentage = 0.0;
|
||||
}
|
||||
|
||||
cur_frm.cscript.calculate_taxes_and_totals();
|
||||
})
|
||||
|
@ -151,7 +151,6 @@ cur_frm.cscript['Declare Order Lost'] = function(){
|
||||
})
|
||||
});
|
||||
dialog.show();
|
||||
|
||||
}
|
||||
|
||||
cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
|
||||
|
@ -154,20 +154,6 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
|
||||
}
|
||||
},
|
||||
|
||||
rate: function(doc, cdt, cdn) {
|
||||
var item = frappe.get_doc(cdt, cdn);
|
||||
frappe.model.round_floats_in(item, ["rate", "price_list_rate"]);
|
||||
|
||||
if(item.price_list_rate) {
|
||||
item.discount_percentage = flt((1 - item.rate / item.price_list_rate) * 100.0,
|
||||
precision("discount_percentage", item));
|
||||
} else {
|
||||
item.discount_percentage = 0.0;
|
||||
}
|
||||
|
||||
this.calculate_taxes_and_totals();
|
||||
},
|
||||
|
||||
discount_amount: function() {
|
||||
this.calculate_taxes_and_totals();
|
||||
},
|
||||
@ -432,3 +418,7 @@ frappe.ui.form.on(cur_frm.doctype,"project_name", function(frm) {
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
frappe.ui.form.on("Sales Taxes and Charges", "rate", function(frm, cdt, cdn) {
|
||||
cur_frm.cscript.calculate_taxes_and_totals();
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user