mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-06 21:59:13 +00:00
[selling/buying] [fixes] updated js files of various doctypes related to selling/g/buying
This commit is contained in:
@@ -27,24 +27,34 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
|
||||
var me = this;
|
||||
|
||||
if(this.frm.fields_dict.price_list_name) {
|
||||
this.frm.fields_dict.price_list_name.get_query = function() {
|
||||
this.frm.set_query("price_list_name", function() {
|
||||
return repl("select distinct price_list_name from `tabItem Price` \
|
||||
where buying = 1 and price_list_name like \"%s%%\"");
|
||||
};
|
||||
}
|
||||
|
||||
if(this.frm.fields_dict.price_list_currency) {
|
||||
this.frm.fields_dict.price_list_currency.get_query = function() {
|
||||
});
|
||||
|
||||
this.frm.set_query("price_list_currency", function() {
|
||||
return repl("select distinct ref_currency from `tabItem Price` \
|
||||
where price_list_name=\"%(price_list_name)s\" and buying = 1 \
|
||||
and ref_currency like \"%s%%\"",
|
||||
{price_list_name: me.frm.doc.price_list_name});
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
if(this.frm.fields_dict.supplier) {
|
||||
this.frm.set_query("supplier", erpnext.utils.supplier_query);
|
||||
}
|
||||
|
||||
this.frm.set_query("item_code", this.frm.cscript.fname, function() {
|
||||
if(me.frm.doc.is_subcontracted == "Yes") {
|
||||
return erpnext.queries.item({'ifnull(tabItem.is_sub_contracted_item, "No")': "Yes"});
|
||||
} else {
|
||||
return erpnext.queries.item({'ifnull(tabItem.is_purchase_item, "No")': "Yes"});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
validate: function() {
|
||||
|
||||
this.calculate_taxes_and_totals();
|
||||
},
|
||||
|
||||
supplier: function() {
|
||||
@@ -100,7 +110,7 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
|
||||
},
|
||||
callback: function(r) {
|
||||
if(!r.exc) {
|
||||
me.ref_rate(me.frm.doc, cdt, cdn);
|
||||
me.import_ref_rate(me.frm.doc, cdt, cdn);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -108,13 +118,102 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
|
||||
}
|
||||
},
|
||||
|
||||
price_list_name: function(callback_fn) {
|
||||
price_list_name: function() {
|
||||
this._super("buying");
|
||||
},
|
||||
|
||||
import_ref_rate: function(doc, cdt, cdn) {
|
||||
var item = wn.model.get_doc(cdt, cdn);
|
||||
wn.model.round_floats_in(item, ["import_ref_rate", "discount_rate"]);
|
||||
|
||||
item.import_rate = flt(item.import_ref_rate * (1 - item.discount_rate / 100.0),
|
||||
precision("import_rate", item));
|
||||
|
||||
this.calculate_taxes_and_totals();
|
||||
},
|
||||
|
||||
discount_rate: function(doc, cdt, cdn) {
|
||||
this.import_rate(doc, cdt, cdn);
|
||||
},
|
||||
|
||||
import_rate: function(doc, cdt, cdn) {
|
||||
var item = wn.model.get_doc(cdt, cdn);
|
||||
wn.model.round_floats_in(item, ["import_rate", "discount_rate"]);
|
||||
|
||||
if(item.import_ref_rate) {
|
||||
item.discount_rate = flt((1 - item.import_rate / item.import_ref_rate) * 100.0,
|
||||
precision("discount_rate", item));
|
||||
} else {
|
||||
item.discount_rate = 0.0;
|
||||
}
|
||||
|
||||
this.calculate_taxes_and_totals();
|
||||
},
|
||||
|
||||
uom: function(doc, cdt, cdn) {
|
||||
var me = this;
|
||||
var item = wn.model.get_doc(cdt, cdn);
|
||||
if(item.item_code && item.uom) {
|
||||
this.frm.call({
|
||||
method: "buying.utils.get_conversion_factor",
|
||||
child: item,
|
||||
args: {
|
||||
item_code: item.item_code,
|
||||
uom: item.uom,
|
||||
},
|
||||
callback: function(r) {
|
||||
if(!r.exc) {
|
||||
me.conversion_factor(me.frm.doc, cdt, cdn);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
qty: function(doc, cdt, cdn) {
|
||||
this._super(doc, cdt, cdn);
|
||||
this.conversion_factor(doc, cdt, cdn);
|
||||
},
|
||||
|
||||
conversion_factor: function(doc, cdt, cdn) {
|
||||
if(wn.meta.get_docfield(cdt, "stock_qty", cdn)) {
|
||||
var item = wn.model.get_doc(cdt, cdn);
|
||||
wn.model.round_floats_in(item, ["qty", "conversion_factor"])
|
||||
item.stock_qty = flt(item.qty * item.conversion_factor, precision("stock_qty", item));
|
||||
refresh_field("stock_qty", item.name, item.parentfield);
|
||||
}
|
||||
},
|
||||
|
||||
warehouse: function(doc, cdt, cdn) {
|
||||
var item = wn.model.get_doc(cdt, cdn);
|
||||
if(item.item_code && item.warehouse) {
|
||||
this.frm.call({
|
||||
method: "buying.utils.get_conversion_factor",
|
||||
child: item,
|
||||
args: {
|
||||
item_code: item.item_code,
|
||||
warehouse: item.warehouse,
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
project_name: function(doc, cdt, cdn) {
|
||||
var item = wn.model.get_doc(cdt, cdn);
|
||||
if(item.project_name) {
|
||||
$.each(wn.model.get_doclist(this.frm.doc.doctype, this.frm.doc.name, {parentfield: this.fname}),
|
||||
function(i, other_item) {
|
||||
if(!other_item.project_name) {
|
||||
other_item.project_name = item.project_name;
|
||||
refresh_field("project_name", other_item.name, other_item.parentfield);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
calculate_taxes_and_totals: function() {
|
||||
this._super();
|
||||
this.calculate_outstanding_amount();
|
||||
this.calculate_total_advance();
|
||||
this.frm.refresh_fields();
|
||||
},
|
||||
|
||||
@@ -164,6 +263,7 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
|
||||
this.frm.doc.total_tax = flt(this.frm.doc.grand_total - this.frm.doc.net_total,
|
||||
precision("total_tax"));
|
||||
|
||||
// rounded totals
|
||||
if(wn.meta.get_docfield(this.frm.doc.doctype, "rounded_total", this.frm.doc.name)) {
|
||||
this.frm.doc.rounded_total = Math.round(this.frm.doc.grand_total);
|
||||
}
|
||||
@@ -171,6 +271,22 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
|
||||
if(wn.meta.get_docfield(this.frm.doc.doctype, "rounded_total_import", this.frm.doc.name)) {
|
||||
this.frm.doc.rounded_total_import = Math.round(this.frm.doc.grand_total_import);
|
||||
}
|
||||
|
||||
// other charges added/deducted
|
||||
if(tax_count) {
|
||||
this.frm.doc.other_charges_added = wn.utils.sum($.map(this.frm.tax_doclist,
|
||||
function(tax) { return tax.add_deduct_tax == "Add" ? tax.tax_amount : 0.0; }));
|
||||
|
||||
this.frm.doc.other_charges_deducted = wn.utils.sum($.map(this.frm.tax_doclist,
|
||||
function(tax) { return tax.add_deduct_tax == "Deduct" ? tax.tax_amount : 0.0; }));
|
||||
|
||||
wn.model.round_floats_in(this.frm.doc, ["other_charges_added", "other_charges_deducted"]);
|
||||
|
||||
this.frm.doc.other_charges_added_import = flt(this.frm.doc.other_charges_added / this.frm.doc.conversion_rate,
|
||||
precision("other_charges_added_import"));
|
||||
this.frm.doc.other_charges_deducted_import = flt(this.frm.doc.other_charges_deducted / this.frm.doc.conversion_rate,
|
||||
precision("other_charges_deducted_import"));
|
||||
}
|
||||
},
|
||||
|
||||
_cleanup: function() {
|
||||
@@ -189,9 +305,13 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
|
||||
}
|
||||
},
|
||||
|
||||
calculate_total_advance: function() {
|
||||
this._super("Purchase Invoice", "advance_allocation_details");
|
||||
},
|
||||
|
||||
calculate_outstanding_amount: function() {
|
||||
if(this.frm.doc.doctype == "Purchase Invoice" && this.frm.doc.docstatus < 2) {
|
||||
wn.model.round_floats_in(this.frm.doc, ["total_advance", "write_off_amount"]);
|
||||
wn.model.round_floats_in(this.frm.doc, ["grand_total", "total_advance", "write_off_amount"]);
|
||||
this.frm.doc.total_amount_to_pay = flt(this.frm.doc.grand_total - this.frm.doc.write_off_amount,
|
||||
precision("total_amount_to_pay"));
|
||||
this.frm.doc.outstanding_amount = flt(this.frm.doc.total_amount_to_pay - this.frm.doc.total_advance,
|
||||
@@ -210,6 +330,15 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
|
||||
}
|
||||
},
|
||||
|
||||
show_item_wise_taxes: function() {
|
||||
$(this.get_item_wise_taxes_html())
|
||||
.appendTo($(this.frm.fields_dict.tax_calculation.wrapper).empty());
|
||||
},
|
||||
|
||||
recalculate: function() {
|
||||
this.calculate_taxes_and_totals();
|
||||
},
|
||||
|
||||
set_dynamic_labels: function(doc, dt, dn) {
|
||||
var company_currency = this.get_company_currency();
|
||||
|
||||
@@ -305,6 +434,8 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
|
||||
$wrapper.find('[data-grid-fieldname="'+fname+'"]').text(label);
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
});
|
||||
|
||||
// to save previous state of cur_frm.cscript
|
||||
@@ -319,498 +450,3 @@ $.extend(cur_frm.cscript, prev_cscript);
|
||||
|
||||
var tname = cur_frm.cscript.tname;
|
||||
var fname = cur_frm.cscript.fname;
|
||||
|
||||
//==================== Item Code Get Query =======================================================
|
||||
// Only Is Purchase Item = 'Yes' and Items not moved to trash are allowed.
|
||||
cur_frm.fields_dict[fname].grid.get_field("item_code").get_query = function(doc, cdt, cdn) {
|
||||
if (doc.is_subcontracted =="Yes") {
|
||||
return erpnext.queries.item({
|
||||
'ifnull(tabItem.is_sub_contracted_item, "No")': 'Yes'
|
||||
})
|
||||
} else {
|
||||
return erpnext.queries.item({
|
||||
'ifnull(tabItem.is_purchase_item, "No")': 'Yes'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
//==================== Update Stock Qty ==========================================================
|
||||
cur_frm.cscript.update_stock_qty = function(doc,cdt,cdn){
|
||||
d = locals[cdt][cdn]
|
||||
// Step 1:=> Check if qty , uom, conversion_factor
|
||||
if (d.qty && d.uom && d.conversion_factor){
|
||||
// Step 2:=> Set stock_qty = qty * conversion_factor
|
||||
d.stock_qty = flt(flt(d.qty) * flt(d.conversion_factor));
|
||||
// Step 3:=> Refer stock_qty field a that particular row.
|
||||
refresh_field('stock_qty' , d.name,fname);
|
||||
}
|
||||
}
|
||||
|
||||
//==================== UOM ======================================================================
|
||||
cur_frm.cscript.uom = function(doc, cdt, cdn, args) {
|
||||
if(!args) args = {};
|
||||
|
||||
// args passed can contain conversion_factor
|
||||
var d = locals[cdt][cdn];
|
||||
$.extend(args, {
|
||||
item_code: d.item_code,
|
||||
uom: d.uom,
|
||||
stock_qty: flt(d.stock_qty),
|
||||
});
|
||||
|
||||
if(d.item_code && d.uom) {
|
||||
cur_frm.call({
|
||||
method: "buying.doctype.purchase_common.purchase_common.get_uom_details",
|
||||
args: { args: args },
|
||||
child: d,
|
||||
callback: function(r) {
|
||||
cur_frm.cscript.calc_amount(doc, 2);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//==================== Conversion factor =========================================================
|
||||
cur_frm.cscript.conversion_factor = function(doc, cdt, cdn) {
|
||||
var item = locals[cdt][cdn];
|
||||
|
||||
cur_frm.cscript.uom(doc, cdt, cdn, { conversion_factor: item.conversion_factor });
|
||||
}
|
||||
|
||||
//==================== stock qty ======================================================================
|
||||
cur_frm.cscript.stock_qty = function(doc, cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
if(d.uom && d.qty){
|
||||
d.conversion_factor = flt(d.stock_qty)/flt(d.qty);
|
||||
refresh_field('conversion_factor', d.name, fname);
|
||||
}
|
||||
}
|
||||
|
||||
//==================== Warehouse ================================================================
|
||||
cur_frm.cscript.warehouse = function(doc, cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
if (d.item_code && d.warehouse) {
|
||||
str_arg = "{'item_code':'" + (d.item_code?d.item_code:'') + "', 'warehouse':'" + (d.warehouse?d.warehouse:'') + "'}"
|
||||
get_server_fields('get_bin_details', str_arg, fname, doc, cdt, cdn, 1);
|
||||
}
|
||||
}
|
||||
|
||||
//=================== Quantity ===================================================================
|
||||
cur_frm.cscript.qty = function(doc, cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
// Step 1: => Update Stock Qty
|
||||
cur_frm.cscript.update_stock_qty(doc,cdt,cdn);
|
||||
// Step 2: => Calculate Amount
|
||||
cur_frm.cscript.calc_amount(doc, 2);
|
||||
}
|
||||
|
||||
|
||||
//=================== Purchase Rate ==============================================================
|
||||
cur_frm.cscript.purchase_rate = function(doc, cdt, cdn) {
|
||||
cur_frm.cscript.calc_amount(doc, 2);
|
||||
}
|
||||
|
||||
//==================== Import Rate ================================================================
|
||||
cur_frm.cscript.import_rate = function(doc, cdt, cdn) {
|
||||
cur_frm.cscript.calc_amount(doc, 1);
|
||||
}
|
||||
|
||||
//==================== Discount Rate ================================================================
|
||||
cur_frm.cscript.discount_rate = function(doc, cdt, cdn) {
|
||||
cur_frm.cscript.calc_amount(doc, 4);
|
||||
}
|
||||
//==================== Purchase Ref Rate ================================================================
|
||||
cur_frm.cscript.purchase_ref_rate = function(doc, cdt, cdn) {
|
||||
cur_frm.cscript.calc_amount(doc, 4);
|
||||
}
|
||||
//==================== Import Ref Rate ================================================================
|
||||
cur_frm.cscript.import_ref_rate = function(doc, cdt, cdn) {
|
||||
cur_frm.cscript.calc_amount(doc, 5);
|
||||
}
|
||||
|
||||
//==================== Validate ====================================================================
|
||||
cur_frm.cscript.validate = function(doc, cdt, cdn) {
|
||||
cur_frm.cscript.calc_amount(doc, 1);
|
||||
|
||||
// calculate advances if pv
|
||||
if(doc.docstatus == 0 && doc.doctype == 'Purchase Invoice') calc_total_advance(doc, cdt, cdn);
|
||||
}
|
||||
|
||||
// **************** RE-CALCULATE VALUES ***************************
|
||||
|
||||
cur_frm.cscript.recalculate_values = function(doc, cdt, cdn) {
|
||||
cur_frm.cscript.calculate_tax(doc,cdt,cdn);
|
||||
}
|
||||
|
||||
cur_frm.cscript.calculate_tax = function(doc, cdt, cdn) {
|
||||
var other_fname = cur_frm.cscript.other_fname;
|
||||
|
||||
var cl = getchildren('Purchase Taxes and Charges', doc.name, other_fname, doc.doctype);
|
||||
for(var i = 0; i<cl.length; i++){
|
||||
cl[i].total_tax_amount = 0;
|
||||
cl[i].total_amount = 0;
|
||||
cl[i].tax_amount = 0; // this is done to calculate other charges
|
||||
cl[i].total = 0;
|
||||
if(in_list(['On Previous Row Amount','On Previous Row Total'],cl[i].charge_type) && !cl[i].row_id){
|
||||
alert("Please Enter Row on which amount needs to be calculated for row : "+cl[i].idx);
|
||||
validated = false;
|
||||
}
|
||||
}
|
||||
cur_frm.cscript.calc_amount(doc, 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
cur_frm.cscript.get_item_wise_tax_detail = function( doc, rate, cl, i, tax, t) {
|
||||
doc = locals[doc.doctype][doc.name];
|
||||
var detail = '';
|
||||
detail = cl[i].item_code + " : " + cstr(rate) + NEWLINE;
|
||||
return detail;
|
||||
}
|
||||
|
||||
cur_frm.cscript.amount = function(doc, cdt, cdn) {
|
||||
cur_frm.cscript.calc_amount(doc, 3);
|
||||
}
|
||||
|
||||
|
||||
//====================== Calculate Amount for PO and PR not for PV ============================================================
|
||||
cur_frm.cscript.calc_amount = function(doc, n) {
|
||||
// Set defaults
|
||||
doc = locals[doc.doctype][doc.name]
|
||||
var other_fname = cur_frm.cscript.other_fname;
|
||||
if(!flt(doc.conversion_rate)) { doc.conversion_rate = 1; refresh_field('conversion_rate'); }
|
||||
if(!n) n=0;
|
||||
var net_total = 0;
|
||||
var net_total_import = 0;
|
||||
|
||||
var cl = getchildren(tname, doc.name, fname);
|
||||
|
||||
for(var i=0;i<cl.length;i++)
|
||||
{
|
||||
var rate_fld = (doc.doctype != 'Purchase Invoice') ? 'purchase_rate': 'rate';
|
||||
var tmp = {};
|
||||
if(!cl[i].discount_rate) cl[i].discount_rate = 0;
|
||||
|
||||
if(n == 1){
|
||||
set_multiple(tname, cl[i].name, {'purchase_ref_rate':flt(cl[i].import_ref_rate)*flt(doc.conversion_rate)}, fname);
|
||||
set_multiple(tname, cl[i].name, {
|
||||
'discount_rate': flt(cl[i].import_ref_rate) ?
|
||||
flt(flt( flt( flt(cl[i].import_ref_rate) - flt(cl[i].import_rate) ) * 100 )/
|
||||
flt(cl[i].import_ref_rate)) : 0 }, fname);
|
||||
tmp[rate_fld] = flt(doc.conversion_rate) * flt(cl[i].import_rate);
|
||||
set_multiple(tname, cl[i].name, tmp, fname);
|
||||
|
||||
set_multiple(tname, cl[i].name, {'amount': flt(flt(cl[i].qty) * flt(doc.conversion_rate) * flt(cl[i].import_rate))}, fname);
|
||||
set_multiple(tname, cl[i].name, {'import_amount': flt(flt(cl[i].qty) * flt(cl[i].import_rate))}, fname);
|
||||
|
||||
}else if(n == 2){
|
||||
set_multiple(tname, cl[i].name, {'purchase_ref_rate':flt(cl[i].import_ref_rate)*flt(doc.conversion_rate)}, fname);
|
||||
set_multiple(tname, cl[i].name, {
|
||||
'discount_rate': flt(cl[i].purchase_ref_rate) ?
|
||||
flt(flt( flt( flt(cl[i].purchase_ref_rate) - flt(cl[i][rate_fld]) ) * 100 )/
|
||||
flt(cl[i].purchase_ref_rate)) : 0 }, fname);
|
||||
set_multiple(tname, cl[i].name, {'amount': flt(flt(cl[i].qty) * flt(cl[i][rate_fld])),}, fname);
|
||||
set_multiple(tname, cl[i].name, {'import_rate': flt(flt(cl[i][rate_fld]) / flt(doc.conversion_rate)) }, fname);
|
||||
set_multiple(tname, cl[i].name, {'import_amount': flt(flt(cl[i].qty) * flt(cl[i][rate_fld]) / flt(doc.conversion_rate))}, fname);
|
||||
|
||||
}else if(n == 3){
|
||||
tmp[rate_fld] = flt(flt(cl[i].amount) / flt(cl[i].qty));
|
||||
set_multiple(tname, cl[i].name, tmp, fname);
|
||||
set_multiple(tname, cl[i].name, {'import_rate': flt(flt(cl[i][rate_fld]) / flt(doc.conversion_rate))}, fname);
|
||||
set_multiple(tname, cl[i].name, {'import_amount': flt(flt(cl[i].qty) * flt(cl[i][rate_fld]) / flt(doc.conversion_rate))}, fname);
|
||||
|
||||
}else if( n==4){
|
||||
|
||||
set_multiple(tname, cl[i].name, {'import_ref_rate': flt(flt(cl[i].purchase_ref_rate) / flt(doc.conversion_rate))}, fname);
|
||||
|
||||
tmp[rate_fld] = flt( flt(cl[i].purchase_ref_rate) - flt(flt(cl[i].purchase_ref_rate)*flt(cl[i].discount_rate)/100) )
|
||||
set_multiple(tname, cl[i].name, tmp, fname);
|
||||
set_multiple(tname, cl[i].name, {'import_rate': flt(flt(cl[i][rate_fld]) / flt(doc.conversion_rate))}, fname);
|
||||
set_multiple(tname, cl[i].name, {'amount':flt(flt(cl[i].qty) * flt(cl[i][rate_fld]))}, fname);
|
||||
set_multiple(tname, cl[i].name, {'import_amount': flt(flt(cl[i].qty) * flt(cl[i][rate_fld]) / flt(doc.conversion_rate))}, fname);
|
||||
}else if( n==5){
|
||||
tmp[rate_fld] = flt( flt(cl[i].import_ref_rate) - flt(flt(cl[i].import_ref_rate)*flt(cl[i].discount_rate)/100) ) * flt(doc.conversion_rate);
|
||||
set_multiple(tname, cl[i].name, {'purchase_ref_rate': flt(flt(cl[i].import_ref_rate) * flt(doc.conversion_rate))}, fname);
|
||||
set_multiple(tname, cl[i].name, tmp, fname);
|
||||
set_multiple(tname, cl[i].name, {'import_rate': flt(flt(cl[i][rate_fld]) / flt(doc.conversion_rate))}, fname);
|
||||
set_multiple(tname, cl[i].name, {'amount':flt(flt(cl[i].qty) * flt(cl[i][rate_fld]))}, fname);
|
||||
set_multiple(tname, cl[i].name, {'import_amount': flt(flt(cl[i].qty) * flt(cl[i][rate_fld]) / flt(doc.conversion_rate))}, fname);
|
||||
}
|
||||
|
||||
if (n != 3){
|
||||
net_total += flt(flt(cl[i].qty) * flt(cl[i][rate_fld]));
|
||||
net_total_import += flt(flt(cl[i].qty) * flt(cl[i].import_rate));
|
||||
} else if(n == 3){
|
||||
net_total += flt(cl[i].amount);
|
||||
net_total_import += flt(cl[i].amount) / flt(doc.conversion_rate);
|
||||
}
|
||||
//update stock uom
|
||||
cur_frm.cscript.update_stock_qty(doc, tname, cl[i].name);
|
||||
}
|
||||
doc.net_total = flt(net_total) ;
|
||||
doc.net_total_import = flt(net_total_import) ;
|
||||
refresh_field('net_total');
|
||||
refresh_field('net_total_import');
|
||||
|
||||
cur_frm.cscript.val_cal_charges(doc, tname, fname, other_fname);
|
||||
}
|
||||
|
||||
|
||||
//======== Function was broken away from cur_frm.cscript.calc_amount as PV has fieldname 'rate' instead of 'purchase_rate'===========
|
||||
cur_frm.cscript.val_cal_charges = function(doc, tname, fname, other_fname){
|
||||
|
||||
doc = locals[doc.doctype][doc.name]
|
||||
if(flt(doc.net_total) > 0) {
|
||||
var cl = getchildren('Purchase Taxes and Charges', doc.name, other_fname,doc.doctype);
|
||||
for(var i = 0; i<cl.length; i++){
|
||||
cl[i].total_tax_amount = 0;
|
||||
cl[i].total_amount = 0;
|
||||
cl[i].tax_amount = 0; // this is done to calculate other charges
|
||||
cl[i].total = 0;
|
||||
cl[i].item_wise_tax_detail = "";
|
||||
if(in_list(['On Previous Row Amount','On Previous Row Total'],cl[i].charge_type) && !cl[i].row_id){
|
||||
alert("Please Enter Row on which amount needs to be calculated for row : "+cl[i].idx);
|
||||
validated = false;
|
||||
}
|
||||
}
|
||||
cur_frm.cscript.calc_other_charges(doc , tname , fname , other_fname); // calculate other charges
|
||||
}
|
||||
cur_frm.cscript.calc_doc_values(doc, tname, fname, other_fname); // calculates total amounts
|
||||
|
||||
refresh_many(['net_total', 'grand_total', 'rounded_total', 'grand_total_import', 'rounded_total_import', 'in_words', 'in_words_import', 'purchase_tax_details', 'total_tax', 'other_charges_added', 'other_charges_deducted', 'net_total_import', 'other_charges_added_import', 'other_charges_deducted_import']);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// ******************************* OTHER CHARGES *************************************
|
||||
cur_frm.cscript.calc_other_charges = function(doc , tname , fname , other_fname) {
|
||||
doc = locals[doc.doctype][doc.name];
|
||||
// make display area
|
||||
// ------------------
|
||||
|
||||
|
||||
cur_frm.fields_dict['tax_calculation'].disp_area.innerHTML = '<b style="padding: 8px 0px;">Calculation Details for Taxes, Charges and Landed Cost:</b>';
|
||||
var cl = getchildren(tname, doc.name, fname);
|
||||
var tax = getchildren('Purchase Taxes and Charges', doc.name, other_fname,doc.doctype);
|
||||
// make display table
|
||||
// ------------------
|
||||
var otc = make_table(cur_frm.fields_dict['tax_calculation'].disp_area, cl.length + 1, tax.length + 1, '90%',[],{border:'1px solid #AAA',padding:'2px'});
|
||||
$y(otc,{marginTop:'8px'});
|
||||
|
||||
var tax_desc = {}; var tax_desc_rates = []; var net_total = 0;
|
||||
|
||||
|
||||
for(var i=0;i<cl.length;i++) {
|
||||
var item_tax = 0;
|
||||
if(doc.doctype != 'Purchase Invoice') net_total += flt(flt(cl[i].qty) * flt(cl[i].purchase_rate));
|
||||
else if(doc.doctype == 'Purchase Invoice') net_total += flt(flt(cl[i].qty) * flt(cl[i].rate));
|
||||
|
||||
var prev_total = flt(cl[i].amount);
|
||||
if(cl[i].item_tax_rate) {
|
||||
try {
|
||||
var check_tax = JSON.parse(cl[i].item_tax_rate); //to get in dictionary
|
||||
} catch(exception) {
|
||||
var check_tax = eval('var a='+cl[i].item_tax_rate+';a'); //to get in dictionary
|
||||
}
|
||||
}
|
||||
|
||||
// Add Item Code in new Row
|
||||
//--------------------------
|
||||
$td(otc,i+1,0).innerHTML = cl[i].item_code;
|
||||
|
||||
var total = net_total;
|
||||
for(var t=0;t<tax.length;t++){
|
||||
|
||||
var account = tax[t].account_head;
|
||||
$td(otc,0,t+1).innerHTML = account?account:'';
|
||||
//Check For Rate
|
||||
if(cl[i].item_tax_rate && check_tax[account]!=null) {
|
||||
rate = flt(check_tax[account]);
|
||||
} else {
|
||||
// if particular item doesn't have particular rate it will take other charges rate
|
||||
rate = flt(tax[t].rate);
|
||||
}
|
||||
|
||||
//Check For Rate and get tax amount
|
||||
var tax_amount = cur_frm.cscript.check_charge_type_and_get_tax_amount(doc,tax,t, cl[i], rate);
|
||||
|
||||
//enter item_wise_tax_detail i.e. tax rate on each item
|
||||
|
||||
item_wise_tax_detail = cur_frm.cscript.get_item_wise_tax_detail( doc, rate, cl, i, tax, t);
|
||||
|
||||
|
||||
if(tax[t].add_deduct_tax == 'Add'){
|
||||
// this is calculation part for all types
|
||||
if(tax[t].charge_type != "Actual") tax[t].item_wise_tax_detail += item_wise_tax_detail;
|
||||
tax[t].total_amount = flt(tax_amount); //stores actual tax amount in virtual field
|
||||
tax[t].total_tax_amount = flt(prev_total); //stores total amount in virtual field
|
||||
tax[t].tax_amount += flt(tax_amount);
|
||||
var total_amount = flt(tax[t].tax_amount);
|
||||
total_tax_amount = flt(tax[t].total_tax_amount) + flt(total_amount);
|
||||
if(tax[t].category != "Valuation"){
|
||||
set_multiple('Purchase Taxes and Charges', tax[t].name, { 'item_wise_tax_detail':tax[t].item_wise_tax_detail, 'amount':roundNumber(total_amount, 2), 'total':roundNumber(flt(total)+flt(tax[t].tax_amount), 2)}, other_fname);
|
||||
prev_total += flt(tax[t].total_amount);
|
||||
total += flt(tax[t].tax_amount); // for adding total to previous amount
|
||||
}
|
||||
else{
|
||||
set_multiple('Purchase Taxes and Charges', tax[t].name, { 'item_wise_tax_detail':tax[t].item_wise_tax_detail, 'amount':roundNumber(total_amount, 2), 'total':roundNumber(flt(total), 2)}, other_fname);
|
||||
prev_total = prev_total;
|
||||
}
|
||||
//prev_total += flt(tax[t].total_amount); // for previous row total
|
||||
|
||||
if(tax[t].charge_type == 'Actual')
|
||||
$td(otc,i+1,t+1).innerHTML = format_currency(tax[t].total_amount, erpnext.get_currency(doc.company));
|
||||
else
|
||||
$td(otc,i+1,t+1).innerHTML = '('+fmt_money(rate) + '%) ' +format_currency(tax[t].total_amount, erpnext.get_currency(doc.company));
|
||||
|
||||
if (tax[t].category != "Total"){
|
||||
item_tax += tax[t].total_amount;
|
||||
}
|
||||
}
|
||||
else if(tax[t].add_deduct_tax == 'Deduct'){
|
||||
// this is calculation part for all types
|
||||
if(tax[t].charge_type != "Actual") tax[t].item_wise_tax_detail += item_wise_tax_detail;
|
||||
tax[t].total_amount = flt(tax_amount); //stores actual tax amount in virtual field
|
||||
tax[t].total_tax_amount = flt(prev_total); //stores total amount in virtual field
|
||||
tax[t].tax_amount += flt(tax_amount);
|
||||
var total_amount = flt(tax[t].tax_amount);
|
||||
total_tax_amount = flt(tax[t].total_tax_amount) - flt(total_amount);
|
||||
if(tax[t].category != "Valuation"){
|
||||
set_multiple('Purchase Taxes and Charges', tax[t].name, { 'item_wise_tax_detail':tax[t].item_wise_tax_detail, 'tax_amount':roundNumber(total_amount, 2), 'total':roundNumber(flt(total)-flt(tax[t].tax_amount), 2)}, other_fname);
|
||||
prev_total -= flt(tax[t].total_amount);
|
||||
total -= flt(tax[t].tax_amount); // for adding total to previous amount
|
||||
}
|
||||
else{
|
||||
set_multiple('Purchase Taxes and Charges', tax[t].name, { 'item_wise_tax_detail':tax[t].item_wise_tax_detail, 'tax_amount':roundNumber(total_amount, 2), 'total':roundNumber(flt(total), 2)}, other_fname);
|
||||
prev_total = prev_total;
|
||||
}
|
||||
//prev_total += flt(tax[t].total_amount); // for previous row total
|
||||
|
||||
if(tax[t].charge_type == 'Actual')
|
||||
$td(otc,i+1,t+1).innerHTML = format_currency(tax[t].total_amount, erpnext.get_currency(doc.company));
|
||||
else
|
||||
$td(otc,i+1,t+1).innerHTML = '('+fmt_money(rate) + '%) ' +format_currency(tax[t].total_amount, erpnext.get_currency(doc.company));
|
||||
|
||||
if (tax[t].category != "Total"){
|
||||
item_tax -= tax[t].total_amount;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
set_multiple(tname, cl[i].name, {'item_tax_amount': item_tax }, fname);
|
||||
}
|
||||
for(var t=0;t<tax.length;t++){
|
||||
tax[t].tax_amount = roundNumber(tax[t].tax_amount, 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cur_frm.cscript.check_charge_type_and_get_tax_amount = function(doc, tax, t, cl, rate, print_amt) {
|
||||
doc = locals[doc.doctype][doc.name];
|
||||
|
||||
var tax_amount = 0;
|
||||
if(tax[t].charge_type == 'Actual') {
|
||||
var value = flt(tax[t].rate) / flt(doc.net_total); // this give the ratio in which all items are divided
|
||||
return tax_amount = flt(value) * flt(cl.amount);
|
||||
}
|
||||
else if(tax[t].charge_type == 'On Net Total') {
|
||||
return tax_amount = (flt(rate) * flt(cl.amount) / 100);
|
||||
}
|
||||
else if(tax[t].charge_type == 'On Previous Row Amount'){
|
||||
var row_no = (tax[t].row_id).toString();
|
||||
var row = (row_no).split("+"); // splits the values and stores in an array
|
||||
for(var r = 0;r<row.length;r++){
|
||||
var id = cint(row[r].replace(/^\s+|\s+$/g,""));
|
||||
tax_amount += (flt(rate) * flt(tax[id-1].total_amount) / 100);
|
||||
}
|
||||
var row_id = row_no.indexOf("/");
|
||||
if(row_id != -1) {
|
||||
rate = '';
|
||||
var row = (row_no).split("/"); // splits the values and stores in an array
|
||||
if(row.length>2) alert("You cannot enter more than 2 nos. for division");
|
||||
var id1 = cint(row[0].replace(/^\s+|\s+$/g,""));
|
||||
var id2 = cint(row[1].replace(/^\s+|\s+$/g,""));
|
||||
tax_amount = flt(tax[id1-1].total_amount) / flt(tax[id2-1].total_amount);
|
||||
}
|
||||
return tax_amount
|
||||
}
|
||||
else if(tax[t].charge_type == 'On Previous Row Total') {
|
||||
var row = cint(tax[t].row_id);
|
||||
if(tax[row-1].add_deduct_tax == 'Add'){
|
||||
return tax_amount = flt(rate) * (flt(tax[row-1].total_tax_amount)+flt(tax[row-1].total_amount)) / 100;
|
||||
}
|
||||
else if(tax[row-1].add_deduct_tax == 'Deduct'){
|
||||
return tax_amount = flt(rate) * (flt(tax[row-1].total_tax_amount)-flt(tax[row-1].total_amount)) / 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ******* Calculation of total amounts of document (item amount + other charges)****************
|
||||
cur_frm.cscript.calc_doc_values = function(doc, tname, fname, other_fname) {
|
||||
doc = locals[doc.doctype][doc.name];
|
||||
var net_total = 0; var total_tax = 0; var other_charges_added = 0;
|
||||
var other_charges_deducted = 0;
|
||||
var cl = getchildren(tname, doc.name, fname);
|
||||
for(var i = 0; i<cl.length; i++){
|
||||
net_total += flt(cl[i].amount);
|
||||
}
|
||||
var d = getchildren('Purchase Taxes and Charges', doc.name, other_fname,doc.doctype);
|
||||
for(var j = 0; j<d.length; j++){
|
||||
if(d[j].category != 'Valuation'){
|
||||
|
||||
if(d[j].add_deduct_tax == 'Add'){
|
||||
other_charges_added += flt(d[j].tax_amount);
|
||||
total_tax += flt(d[j].tax_amount);
|
||||
}
|
||||
if(d[j].add_deduct_tax == 'Deduct'){
|
||||
other_charges_deducted += flt(d[j].tax_amount);
|
||||
total_tax -= flt(d[j].tax_amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
doc.net_total = flt(net_total);
|
||||
doc.total_tax = flt(total_tax);
|
||||
|
||||
doc.other_charges_added = roundNumber(flt(other_charges_added), 2);
|
||||
doc.other_charges_deducted = roundNumber(flt(other_charges_deducted), 2);
|
||||
doc.grand_total = roundNumber(flt(flt(net_total) + flt(other_charges_added) - flt(other_charges_deducted)), 2);
|
||||
doc.rounded_total = Math.round(doc.grand_total);
|
||||
doc.net_total_import = roundNumber(flt(flt(net_total) / flt(doc.conversion_rate)), 2);
|
||||
doc.other_charges_added_import = roundNumber(flt(flt(other_charges_added) / flt(doc.conversion_rate)), 2);
|
||||
doc.other_charges_deducted_import = roundNumber(flt(flt(other_charges_deducted) / flt(doc.conversion_rate)), 2);
|
||||
doc.grand_total_import = roundNumber(flt(flt(doc.grand_total) / flt(doc.conversion_rate)), 2);
|
||||
doc.rounded_total_import = Math.round(doc.grand_total_import);
|
||||
|
||||
refresh_many(['net_total','total_taxes','grand_total']);
|
||||
|
||||
|
||||
if(doc.doctype == 'Purchase Invoice'){
|
||||
calculate_outstanding(doc);
|
||||
}
|
||||
}
|
||||
|
||||
var calculate_outstanding = function(doc) {
|
||||
// total amount to pay
|
||||
doc.total_amount_to_pay = flt(doc.grand_total) - flt(doc.write_off_amount);
|
||||
|
||||
// outstanding amount
|
||||
if(doc.docstatus==0) doc.outstanding_amount = doc.total_amount_to_pay - flt(doc.total_advance);
|
||||
|
||||
refresh_many(['total_amount_to_pay', 'outstanding_amount']);
|
||||
}
|
||||
|
||||
|
||||
cur_frm.cscript.project_name = function(doc, cdt, cdn) {
|
||||
var item_doc = locals[cdt][cdn];
|
||||
if (item_doc.project_name) {
|
||||
$.each(getchildren(cur_frm.cscript.tname, doc.name, cur_frm.cscript.fname, doc.doctype),
|
||||
function(i, v) {
|
||||
if (v && !v.project_name) v.project_name = item_doc.project_name;
|
||||
});
|
||||
refresh_field(cur_frm.cscript.fname);
|
||||
}
|
||||
}
|
||||
|
||||
cur_frm.fields_dict.supplier && (cur_frm.fields_dict.supplier.get_query = erpnext.utils.supplier_query);
|
||||
@@ -436,28 +436,4 @@ class DocType(BuyingController):
|
||||
for d in getlist(obj.doclist, obj.fname):
|
||||
if d.prevdoc_doctype and d.prevdoc_docname:
|
||||
dt = sql("select transaction_date from `tab%s` where name = '%s'" % (d.prevdoc_doctype, d.prevdoc_docname))
|
||||
d.prevdoc_date = dt and dt[0][0].strftime('%Y-%m-%d') or ''
|
||||
|
||||
@webnotes.whitelist()
|
||||
def get_uom_details(args=None):
|
||||
"""fetches details on change of UOM"""
|
||||
if not args:
|
||||
return {}
|
||||
|
||||
if isinstance(args, basestring):
|
||||
import json
|
||||
args = json.loads(args)
|
||||
|
||||
uom = webnotes.conn.sql("""select conversion_factor
|
||||
from `tabUOM Conversion Detail` where parent = %s and uom = %s""",
|
||||
(args['item_code'], args['uom']), as_dict=1)
|
||||
|
||||
if not uom: return {}
|
||||
|
||||
conversion_factor = args.get("conversion_factor") or \
|
||||
flt(uom[0]["conversion_factor"])
|
||||
|
||||
return {
|
||||
"conversion_factor": conversion_factor,
|
||||
"qty": flt(args["stock_qty"]) / conversion_factor,
|
||||
}
|
||||
d.prevdoc_date = dt and dt[0][0].strftime('%Y-%m-%d') or ''
|
||||
@@ -21,8 +21,8 @@ cur_frm.cscript.fname = "po_details";
|
||||
cur_frm.cscript.other_fname = "purchase_tax_details";
|
||||
|
||||
wn.require('app/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js');
|
||||
wn.require('app/buying/doctype/purchase_common/purchase_common.js');
|
||||
wn.require('app/utilities/doctype/sms_control/sms_control.js');
|
||||
wn.require('app/buying/doctype/purchase_common/purchase_common.js');
|
||||
|
||||
erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend({
|
||||
refresh: function(doc, cdt, cdn) {
|
||||
@@ -41,10 +41,8 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
|
||||
},
|
||||
});
|
||||
|
||||
var new_cscript = new erpnext.buying.PurchaseOrderController({frm: cur_frm});
|
||||
|
||||
// for backward compatibility: combine new and previous states
|
||||
$.extend(cur_frm.cscript, new_cscript);
|
||||
$.extend(cur_frm.cscript, new erpnext.buying.PurchaseOrderController({frm: cur_frm}));
|
||||
|
||||
cur_frm.cscript.supplier_address = cur_frm.cscript.contact_person = function(doc,dt,dn) {
|
||||
if(doc.supplier) get_server_fields('get_supplier_address', JSON.stringify({supplier: doc.supplier, address: doc.supplier_address, contact: doc.contact_person}),'', doc, dt, dn, 1);
|
||||
|
||||
@@ -33,10 +33,8 @@ erpnext.buying.SupplierQuotationController = erpnext.buying.BuyingController.ext
|
||||
},
|
||||
});
|
||||
|
||||
var new_cscript = new erpnext.buying.SupplierQuotationController({frm: cur_frm});
|
||||
|
||||
// for backward compatibility: combine new and previous states
|
||||
$.extend(cur_frm.cscript, new_cscript);
|
||||
$.extend(cur_frm.cscript, new erpnext.buying.SupplierQuotationController({frm: cur_frm}));
|
||||
|
||||
cur_frm.cscript.make_purchase_order = function() {
|
||||
var new_po_name = wn.model.make_new_doc_and_get_name("Purchase Order");
|
||||
@@ -51,15 +49,6 @@ cur_frm.cscript.make_purchase_order = function() {
|
||||
}, function(r, rt) { loaddoc("Purchase Order", new_po_name) });
|
||||
}
|
||||
|
||||
cur_frm.cscript.supplier = function(doc, dt, dn) {
|
||||
if (doc.supplier) {
|
||||
get_server_fields('get_default_supplier_address',
|
||||
JSON.stringify({ supplier: doc.supplier }), '', doc, dt, dn, 1,
|
||||
function() { cur_frm.refresh(); });
|
||||
cur_frm.cscript.toggle_contact_section(doc);
|
||||
}
|
||||
}
|
||||
|
||||
cur_frm.cscript.uom = function(doc, cdt, cdn) {
|
||||
// no need to trigger updation of stock uom, as this field doesn't exist in supplier quotation
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user