purchase discount

This commit is contained in:
Nijil Y 2011-12-13 18:14:15 +05:30
parent fdc7fc62a5
commit 8fb260504a
6 changed files with 104 additions and 253 deletions

View File

@ -77,13 +77,6 @@ cur_frm.cscript.supplier_address = cur_frm.cscript.contact_person = function(doc
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); 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);
} }
cur_frm.fields_dict['supplier_address'].get_query = function(doc, cdt, cdn) {
return 'SELECT name,address_line1,city FROM tabAddress WHERE supplier = "'+ doc.supplier +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50';
}
cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) {
return 'SELECT name,CONCAT(first_name," ",ifnull(last_name,"")) As FullName,department,designation FROM tabContact WHERE supplier = "'+ doc.supplier +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50';
}
cur_frm.fields_dict.supplier_address.on_new = function(dn) { cur_frm.fields_dict.supplier_address.on_new = function(dn) {
@ -111,12 +104,6 @@ cur_frm.cscript.credit_to = function(doc,dt,dn) {
// Get Print Heading
cur_frm.fields_dict['select_print_heading'].get_query = function(doc, cdt, cdn) {
return 'SELECT `tabPrint Heading`.name FROM `tabPrint Heading` WHERE `tabPrint Heading`.docstatus !=2 AND `tabPrint Heading`.name LIKE "%s" ORDER BY `tabPrint Heading`.name ASC LIMIT 50';
}
//Set expense_head and cost center on adding new row //Set expense_head and cost center on adding new row
//---------------------------------------------- //----------------------------------------------
cur_frm.fields_dict['entries'].grid.onrowadd = function(doc, cdt, cdn){ cur_frm.fields_dict['entries'].grid.onrowadd = function(doc, cdt, cdn){
@ -142,18 +129,10 @@ cur_frm.cscript.is_opening = function(doc, dt, dn) {
if (doc.is_opening == 'Yes') unhide_field('aging_date'); if (doc.is_opening == 'Yes') unhide_field('aging_date');
} }
/* ******************************** TRIGGERS **************************************** */
// Conversion Rate
// ----------------
cur_frm.cscript.conversion_rate = function(doc,cdt,cdn) {
cur_frm.cscript.calc_total(doc,cdt,cdn);
}
// Recalculate Button // Recalculate Button
// ------------------- // -------------------
cur_frm.cscript['Recalculate'] = function(doc, dt, dn) { cur_frm.cscript['Recalculate'] = function(doc, dt, dn) {
cur_frm.cscript.calc_total(doc, cdt, cdn); cur_frm.cscript['Calculate Tax'](doc,cdt,cdn);
calc_total_advance(doc,cdt,cdn); calc_total_advance(doc,cdt,cdn);
} }
@ -179,31 +158,16 @@ cur_frm.cscript.item_code = function(doc,cdt,cdn){
} }
} }
// Quantity
// ---------
cur_frm.cscript.qty = function(doc,dt,dn) { cur_frm.cscript.calc_exp_row(doc,dt,dn); }
// Import Rate
// ------------
cur_frm.cscript.import_rate = function(doc,dt,dn) {
var d = locals[dt][dn];
set_multiple('PV Detail', d.name, {'purchase_rate': flt(d.import_rate) * flt(doc.conversion_rate) }, 'entries');
cur_frm.cscript.calc_exp_row(doc,dt,dn)
}
// ============== TDS ===============
// Rate in Deduct Taxes (TDS) // Rate in Deduct Taxes (TDS)
// -------------------------- // --------------------------
cur_frm.cscript.rate = function(doc,dt,dn) { cur_frm.cscript.rate = function(doc,dt,dn) {
//This is done as Purchase tax detail and PV detail both contain the same fieldname 'rate' //This is done as Purchase tax detail and PV detail both contain the same fieldname 'rate'
if(dt != 'Purchase Tax Detail') cur_frm.cscript.calc_exp_row(doc,dt,dn); if(dt != 'Purchase Tax Detail') cur_frm.cscript.calc_amount(doc, 2);
} }
// Amount // Amount
// ------- // -------
cur_frm.cscript.ded_amount = function(doc,dt,dn) { cur_frm.cscript.calc_total(doc); } cur_frm.cscript.ded_amount = function(doc,dt,dn) {calculate_outstanding(doc);}
// Get TDS Button // Get TDS Button
// --------------- // ---------------
@ -211,7 +175,7 @@ cur_frm.cscript['Get TDS'] = function(doc, dt, dn) {
var callback = function(r,rt) { var callback = function(r,rt) {
cur_frm.refresh(); cur_frm.refresh();
refresh_field('ded_amount'); refresh_field('ded_amount');
cur_frm.cscript.calc_total(locals[dt][dn]); //cur_frm.cscript.calc_total(locals[dt][dn]);
} }
$c_obj(make_doclist(dt,dn), 'get_tds', '', callback); $c_obj(make_doclist(dt,dn), 'get_tds', '', callback);
} }
@ -244,6 +208,15 @@ cur_frm.cscript['Make Bank Voucher'] = function(doc, dt, dn) {
/* ***************************** GET QUERY Functions *************************** */ /* ***************************** GET QUERY Functions *************************** */
cur_frm.fields_dict['supplier_address'].get_query = function(doc, cdt, cdn) {
return 'SELECT name,address_line1,city FROM tabAddress WHERE supplier = "'+ doc.supplier +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50';
}
cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) {
return 'SELECT name,CONCAT(first_name," ",ifnull(last_name,"")) As FullName,department,designation FROM tabContact WHERE supplier = "'+ doc.supplier +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50';
}
// Item Code // Item Code
// ---------- // ----------
cur_frm.fields_dict['entries'].grid.get_field("item_code").get_query = function(doc, cdt, cdn) { cur_frm.fields_dict['entries'].grid.get_field("item_code").get_query = function(doc, cdt, cdn) {
@ -277,6 +250,12 @@ cur_frm.fields_dict['purchase_receipt_main'].get_query = function(doc) {
} }
} }
// Get Print Heading
cur_frm.fields_dict['select_print_heading'].get_query = function(doc, cdt, cdn) {
return 'SELECT `tabPrint Heading`.name FROM `tabPrint Heading` WHERE `tabPrint Heading`.docstatus !=2 AND `tabPrint Heading`.name LIKE "%s" ORDER BY `tabPrint Heading`.name ASC LIMIT 50';
}
// ================== PV Details Table =================== // ================== PV Details Table ===================
// Expense Head // Expense Head
// ------------- // -------------
@ -324,28 +303,6 @@ cur_frm.cscript.tax_code = function(doc, dt, dn) {
/* ***************************** UTILITY FUNCTIONS ************************ */ /* ***************************** UTILITY FUNCTIONS ************************ */
// Calculate
// ---------
cur_frm.cscript.calc_total = function(doc) {
// expense
var t_exp = 0.0;
var el = getchildren('PV Detail',doc.name,'entries');
for(var i in el) {
if (flt(el[i].import_rate) > 0){
set_multiple('PV Detail', el[i].name, {'purchase_ref_rate':flt(el[i].import_ref_rate)*flt(doc.conversion_rate)}, 'entries');
set_multiple('PV Detail', el[i].name, {'purchase_rate': flt(doc.conversion_rate) * flt(el[i].import_rate) }, 'entries');
set_multiple('PV Detail', el[i].name, {'import_amount': flt(el[i].qty) * flt(el[i].import_rate) }, 'entries');
}
set_multiple('PV Detail', el[i].name, {'amount': flt(el[i].qty) * flt(el[i].purchase_rate) }, 'entries')
t_exp += flt(el[i].amount);
}
doc.net_total = flt(t_exp);
refresh_field('net_total');
cur_frm.cscript.val_cal_charges(doc, cdt, cdn, cur_frm.cscript.tname, cur_frm.cscript.fname, cur_frm.cscript.other_fname);
}
// Calculate Advance // Calculate Advance
// ------------------ // ------------------
var calc_total_advance = function(doc,cdt,cdn) { var calc_total_advance = function(doc,cdt,cdn) {
@ -366,30 +323,12 @@ var calc_total_advance = function(doc,cdt,cdn) {
refresh_many(['total_advance','outstanding_amount','tds_amount_on_advance', 'total_amount_to_pay']); refresh_many(['total_advance','outstanding_amount','tds_amount_on_advance', 'total_amount_to_pay']);
} }
cur_frm.cscript.calc_exp_row = function(doc,dt,dn) {
var d = locals[dt][dn];
d.amount = flt(d.qty * d.purchase_rate);
refresh_field('amount',dn,'entries');
if (!doc.conversion_rate){ doc.conversion_rate = 1; refresh_field('conversion_rate'); }
set_multiple('PV Detail', dn, {'import_rate': flt(d.purchase_rate) / flt(doc.conversion_rate) }, 'entries');
set_multiple('PV Detail', dn, {'import_amount': flt(d.qty) * flt(d.purchase_rate) / flt(doc.conversion_rate) }, 'entries');
cur_frm.cscript.calc_total(doc)
}
// Make JV // Make JV
// -------- // --------
cur_frm.cscript.make_jv = function(doc, dt, dn, det) { cur_frm.cscript.make_jv = function(doc, dt, dn, det) {
var jv = LocalDB.create('Journal Voucher'); var jv = LocalDB.create('Journal Voucher');
jv = locals['Journal Voucher'][jv]; jv = locals['Journal Voucher'][jv];
jv.voucher_type = 'Bank Voucher'; jv.voucher_type = 'Bank Voucher';
//jv.voucher_series = det.def_bv_series;
//jv.voucher_date = doc.voucher_date;
//jv.posting_date = doc.posting_date;
jv.remark = repl('Payment against voucher %(vn)s for %(rem)s', {vn:doc.name, rem:doc.remarks}); jv.remark = repl('Payment against voucher %(vn)s for %(rem)s', {vn:doc.name, rem:doc.remarks});
jv.total_debit = doc.outstanding_amount; jv.total_debit = doc.outstanding_amount;
jv.total_credit = doc.outstanding_amount; jv.total_credit = doc.outstanding_amount;
@ -400,20 +339,17 @@ cur_frm.cscript.make_jv = function(doc, dt, dn, det) {
var d1 = LocalDB.add_child(jv, 'Journal Voucher Detail', 'entries'); var d1 = LocalDB.add_child(jv, 'Journal Voucher Detail', 'entries');
d1.account = doc.credit_to; d1.account = doc.credit_to;
d1.debit = doc.outstanding_amount; d1.debit = doc.outstanding_amount;
//d1.balance = det.acc_balance;
d1.against_voucher = doc.name; d1.against_voucher = doc.name;
// credit to bank // credit to bank
var d1 = LocalDB.add_child(jv, 'Journal Voucher Detail', 'entries'); var d1 = LocalDB.add_child(jv, 'Journal Voucher Detail', 'entries');
//d1.account = det.def_bank_account;
//d1.balance = det.bank_balance;
d1.credit = doc.outstanding_amount; d1.credit = doc.outstanding_amount;
loaddoc('Journal Voucher', jv.name); loaddoc('Journal Voucher', jv.name);
} }
// ***************** Get project name ***************** // ***************** Get project name *****************
cur_frm.fields_dict['pv_details'].grid.get_field('project_name').get_query = function(doc, cdt, cdn) { cur_frm.fields_dict['entries'].grid.get_field('project_name').get_query = function(doc, cdt, cdn) {
return 'SELECT `tabProject`.name FROM `tabProject` WHERE `tabProject`.status = "Open" AND `tabProject`.name LIKE "%s" ORDER BY `tabProject`.name ASC LIMIT 50'; return 'SELECT `tabProject`.name FROM `tabProject` WHERE `tabProject`.status = "Open" AND `tabProject`.name LIKE "%s" ORDER BY `tabProject`.name ASC LIMIT 50';
} }
@ -427,15 +363,6 @@ cur_frm.cscript.select_print_heading = function(doc,cdt,cdn){
cur_frm.pformat.print_heading = "Purchase Invoice"; cur_frm.pformat.print_heading = "Purchase Invoice";
} }
/* *********************** Client Side Validation **************************** */
// Validate
// ---------
cur_frm.cscript.validate = function(doc, cdt, cdn) {
is_item_table(doc,cdt,cdn);
cur_frm.cscript.calc_total(doc, cdt, cdn);
calc_total_advance(doc, cdt, cdn);
}
/****************** Get Accounting Entry *****************/ /****************** Get Accounting Entry *****************/
cur_frm.cscript['View Ledger Entry'] = function(){ cur_frm.cscript['View Ledger Entry'] = function(){
var callback = function(report){ var callback = function(report){

View File

@ -5,7 +5,7 @@
{ {
'creation': '2010-08-08 17:09:17', 'creation': '2010-08-08 17:09:17',
'docstatus': 0, 'docstatus': 0,
'modified': '2011-12-09 18:46:35', 'modified': '2011-12-13 12:06:35',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'owner': 'Administrator' 'owner': 'Administrator'
}, },
@ -21,7 +21,7 @@
'section_style': 'Tray', 'section_style': 'Tray',
'server_code_error': ' ', 'server_code_error': ' ',
'show_in_menu': 0, 'show_in_menu': 0,
'version': 36 'version': 39
}, },
# These values are common for all DocField # These values are common for all DocField
@ -129,13 +129,14 @@
'fieldname': 'purchase_ref_rate', 'fieldname': 'purchase_ref_rate',
'fieldtype': 'Currency', 'fieldtype': 'Currency',
'label': 'Ref Rate *', 'label': 'Ref Rate *',
'permlevel': 0 'permlevel': 0,
'trigger': 'Client'
}, },
# DocField # DocField
{ {
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'purchase_rate', 'fieldname': 'rate',
'fieldtype': 'Currency', 'fieldtype': 'Currency',
'label': 'Rate *(Default Curr.)', 'label': 'Rate *(Default Curr.)',
'oldfieldname': 'rate', 'oldfieldname': 'rate',
@ -161,12 +162,12 @@
# DocField # DocField
{ {
'default': '0.00',
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'discount_rate', 'fieldname': 'discount_rate',
'fieldtype': 'Currency', 'fieldtype': 'Currency',
'label': 'Discount %', 'label': 'Discount %',
'permlevel': 0 'permlevel': 0,
'trigger': 'Client'
}, },
# DocField # DocField
@ -175,7 +176,8 @@
'fieldname': 'import_ref_rate', 'fieldname': 'import_ref_rate',
'fieldtype': 'Currency', 'fieldtype': 'Currency',
'label': 'Ref Rate ', 'label': 'Ref Rate ',
'permlevel': 0 'permlevel': 0,
'trigger': 'Client'
}, },
# DocField # DocField

View File

@ -5,7 +5,7 @@
{ {
'creation': '2010-08-08 17:09:12', 'creation': '2010-08-08 17:09:12',
'docstatus': 0, 'docstatus': 0,
'modified': '2011-12-08 18:30:54', 'modified': '2011-12-13 13:02:05',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'owner': 'Administrator' 'owner': 'Administrator'
}, },
@ -21,7 +21,7 @@
'section_style': 'Tray', 'section_style': 'Tray',
'server_code_error': ' ', 'server_code_error': ' ',
'show_in_menu': 0, 'show_in_menu': 0,
'version': 58 'version': 59
}, },
# These values are common for all DocField # These values are common for all DocField
@ -104,7 +104,6 @@
# DocField # DocField
{ {
'default': '0.00',
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'qty', 'fieldname': 'qty',
'fieldtype': 'Currency', 'fieldtype': 'Currency',
@ -119,7 +118,6 @@
# DocField # DocField
{ {
'default': '0.00',
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'purchase_rate', 'fieldname': 'purchase_rate',
'fieldtype': 'Currency', 'fieldtype': 'Currency',
@ -144,7 +142,6 @@
# DocField # DocField
{ {
'default': '0.00',
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'amount', 'fieldname': 'amount',
'fieldtype': 'Currency', 'fieldtype': 'Currency',
@ -392,7 +389,6 @@
# DocField # DocField
{ {
'default': '0.00',
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'billed_qty', 'fieldname': 'billed_qty',
'fieldtype': 'Currency', 'fieldtype': 'Currency',

View File

@ -13,14 +13,6 @@ cur_frm.cscript.get_default_schedule_date = function(doc) {
} }
} }
/*
// ======================== Supplier =================================================
cur_frm.cscript.supplier = function(doc, cdt, cdn) {
if(doc.supplier) get_server_fields('get_supplier_details', doc.supplier,'', doc, cdt, cdn, 1);
}
*/
// ======================== Conversion Rate ========================================== // ======================== Conversion Rate ==========================================
cur_frm.cscript.conversion_rate = function(doc,cdt,cdn) { cur_frm.cscript.conversion_rate = function(doc,cdt,cdn) {
@ -54,22 +46,11 @@ cur_frm.cscript.update_stock_qty = function(doc,cdt,cdn){
} }
} }
//==================== Purchase UOM Get Query =======================================================
//cur_frm.fields_dict[fname].grid.get_field("uom").get_query = function(doc, cdt, cdn) {
// var d = locals[this.doctype][this.docname];
// return 'SELECT `tabUOM Conversion Detail`.`uom` FROM `tabUOM Conversion Detail` WHERE `tabUOM Conversion Detail`.`parent` = "' + d.item_code + '" AND `tabUOM Conversion Detail`.uom LIKE "%s"'
//}
//==================== UOM ====================================================================== //==================== UOM ======================================================================
cur_frm.cscript.uom = function(doc, cdt, cdn) { cur_frm.cscript.uom = function(doc, cdt, cdn) {
var d = locals[cdt][cdn]; var d = locals[cdt][cdn];
if (d.item_code && d.uom) { if (d.item_code && d.uom) {
call_back = function(doc, cdt, cdn){ call_back = function(doc, cdt, cdn){
//refresh_field('purchase_rate', d.name, fname);
//refresh_field('qty' , d.name, fname);
//refresh_field('conversion_factor' , d.name, fname);
//var doc = locals[cdt][cdn];
cur_frm.cscript.calc_amount(doc, 2); cur_frm.cscript.calc_amount(doc, 2);
} }
str_arg = {'item_code':d.item_code, 'uom':d.uom, 'stock_qty':flt(d.stock_qty), 'qty': flt(d.qty)} str_arg = {'item_code':d.item_code, 'uom':d.uom, 'stock_qty':flt(d.stock_qty), 'qty': flt(d.qty)}
@ -115,64 +96,27 @@ cur_frm.cscript.qty = function(doc, cdt, cdn) {
//=================== Purchase Rate ============================================================== //=================== Purchase Rate ==============================================================
cur_frm.cscript.purchase_rate = function(doc, cdt, cdn) { cur_frm.cscript.purchase_rate = function(doc, cdt, cdn) {
// Calculate Amount
cur_frm.cscript.calc_amount(doc, 2); cur_frm.cscript.calc_amount(doc, 2);
} }
//==================== Import Rate ================================================================ //==================== Import Rate ================================================================
cur_frm.cscript.import_rate = function(doc, cdt, cdn) { cur_frm.cscript.import_rate = function(doc, cdt, cdn) {
// Calculate Amount
cur_frm.cscript.calc_amount(doc, 1); cur_frm.cscript.calc_amount(doc, 1);
} }
//==================== Discount Rate ================================================================ //==================== Discount Rate ================================================================
cur_frm.cscript.discount_rate = function(doc, cdt, cdn) { cur_frm.cscript.discount_rate = function(doc, cdt, cdn) {
// Calculate Amount
cur_frm.cscript.calc_amount(doc, 4); cur_frm.cscript.calc_amount(doc, 4);
} }
//==================== Purchase Ref Rate ================================================================ //==================== Purchase Ref Rate ================================================================
cur_frm.cscript.purchase_ref_rate = function(doc, cdt, cdn) { cur_frm.cscript.purchase_ref_rate = function(doc, cdt, cdn) {
// Calculate Amount
cur_frm.cscript.calc_amount(doc, 4); cur_frm.cscript.calc_amount(doc, 4);
} }
//==================== Import Ref Rate ================================================================ //==================== Import Ref Rate ================================================================
cur_frm.cscript.import_ref_rate = function(doc, cdt, cdn) { cur_frm.cscript.import_ref_rate = function(doc, cdt, cdn) {
// Calculate Amount
cur_frm.cscript.calc_amount(doc, 5); cur_frm.cscript.calc_amount(doc, 5);
} }
//====================== Calculate Amount ============================================================
/*cur_frm.cscript.calc_amount = function(doc, n) {
// Set defaults
doc = locals[doc.doctype][doc.name]
if (! doc.conversion_rate) doc.conversion_rate = 1;
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++)
{
if(n == 1){
set_multiple(tname, cl[i].name, {'purchase_rate': flt(doc.conversion_rate) * flt(cl[i].import_rate) }, 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);
}
if(n == 2){
set_multiple(tname, cl[i].name, {'amount': flt(flt(cl[i].qty) * flt(cl[i].purchase_rate)), 'import_rate': flt(flt(cl[i].purchase_rate) / flt(doc.conversion_rate)) }, fname);
set_multiple(tname, cl[i].name, {'import_amount': flt(flt(cl[i].qty) * flt(cl[i].purchase_rate) / flt(doc.conversion_rate))}, fname);
}
net_total += flt(flt(cl[i].qty) * flt(cl[i].purchase_rate));
net_total_import += flt(flt(cl[i].qty) * flt(cl[i].import_rate));
}
doc.net_total = flt(net_total) ;
doc.net_total_import = flt(net_total_import) ;
refresh_field('net_total');
refresh_field('net_total_import');
} */
//==================== check if item table is blank ============================================== //==================== check if item table is blank ==============================================
var is_item_table = function(doc,cdt,cdn) { var is_item_table = function(doc,cdt,cdn) {
// Step 1 :=>Get all childrens/ rows from Detail Table // Step 1 :=>Get all childrens/ rows from Detail Table
@ -189,18 +133,11 @@ cur_frm.cscript.validate = function(doc, cdt, cdn) {
is_item_table(doc,cdt,cdn); is_item_table(doc,cdt,cdn);
// Step 2:=> Calculate Amount // Step 2:=> Calculate Amount
cur_frm.cscript.calc_amount(doc, 1); cur_frm.cscript.calc_amount(doc, 1);
// calculate advances if pv
if(doc.doctype == 'Payable Voucher') calc_total_advance(doc, cdt, cdn);
} }
/*cur_frm.cscript.other_fname = "purchase_tax_details";
other_charges ===> purchase_tax_details
RV Tax Detail ===> Purchase Tax Detail
cur_frm.cscript.recalc ===> cur_frm.cscript.calc_amount
export ===> import
other_charges_total ===> total_tax
Other Charges Calculation ===> Tax Calculation*/
// **************** RE-CALCULATE VALUES *************************** // **************** RE-CALCULATE VALUES ***************************
cur_frm.cscript['Re-Calculate Values'] = function(doc, cdt, cdn) { cur_frm.cscript['Re-Calculate Values'] = function(doc, cdt, cdn) {
@ -221,8 +158,7 @@ cur_frm.cscript['Calculate Tax'] = function(doc, cdt, cdn) {
validated = false; validated = false;
} }
} }
if(doc.doctype != 'Payable Voucher') cur_frm.cscript.calc_amount(doc, 1); cur_frm.cscript.calc_amount(doc, 1);
else if(doc.doctype == 'Payable Voucher') cur_frm.cscript.calc_total(doc);
} }
@ -234,10 +170,6 @@ cur_frm.cscript.get_item_wise_tax_detail = function( doc, rate, cl, i, tax, t) {
return detail; return detail;
} }
//if(cur_frm.cscript.custom_recalc)cur_frm.cscript.custom_recalc(doc);
cur_frm.cscript.amount = function(doc, cdt, cdn) { cur_frm.cscript.amount = function(doc, cdt, cdn) {
cur_frm.cscript.calc_amount(doc, 3); cur_frm.cscript.calc_amount(doc, 3);
} }
@ -257,70 +189,56 @@ cur_frm.cscript.calc_amount = function(doc, n) {
for(var i=0;i<cl.length;i++) for(var i=0;i<cl.length;i++)
{ {
var rate_fld = (doc.doctype != 'Payable Voucher') ? 'purchase_rate': 'rate';
var tmp = {};
if(!cl[i].discount_rate) cl[i].discount_rate = 0;
if(n == 1){ 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, {'purchase_ref_rate':flt(cl[i].import_ref_rate)*flt(doc.conversion_rate)}, fname);
set_multiple(tname, cl[i].name, {'discount_rate': flt(flt( flt( flt(cl[i].import_ref_rate) - flt(cl[i].import_rate) ) * 100 )/flt(cl[i].import_ref_rate)) }, fname); set_multiple(tname, cl[i].name, {'discount_rate': flt(flt( flt( flt(cl[i].import_ref_rate) - flt(cl[i].import_rate) ) * 100 )/flt(cl[i].import_ref_rate)) }, fname);
set_multiple(tname, cl[i].name, {'purchase_rate': flt(doc.conversion_rate) * flt(cl[i].import_rate) }, 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, {'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); set_multiple(tname, cl[i].name, {'import_amount': flt(flt(cl[i].qty) * flt(cl[i].import_rate))}, fname);
} }else if(n == 2){
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, {'purchase_ref_rate':flt(cl[i].import_ref_rate)*flt(doc.conversion_rate)}, fname);
set_multiple(tname, cl[i].name, {'discount_rate': flt(flt( flt( flt(cl[i].purchase_ref_rate) - flt(cl[i].purchase_rate) ) * 100 )/flt(cl[i].purchase_ref_rate)) }, fname); set_multiple(tname, cl[i].name, {'discount_rate': flt(flt( flt( flt(cl[i].purchase_ref_rate) - flt(cl[i][rate_fld]) ) * 100 )/flt(cl[i].purchase_ref_rate)) }, fname);
set_multiple(tname, cl[i].name, {'amount': flt(flt(cl[i].qty) * flt(cl[i].purchase_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_rate': flt(flt(cl[i].purchase_rate) / flt(doc.conversion_rate)) }, 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].purchase_rate) / 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){
if(n == 3){ tmp[rate_fld] = flt(flt(cl[i].amount) / flt(cl[i].qty));
set_multiple(tname, cl[i].name, {'purchase_rate': flt(flt(cl[i].amount) / flt(cl[i].qty)) }, fname); set_multiple(tname, cl[i].name, tmp, fname);
set_multiple(tname, cl[i].name, {'import_rate': flt(flt(cl[i].purchase_rate) / flt(doc.conversion_rate))}, 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].purchase_rate) / 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);
}
if( n==4){ }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); set_multiple(tname, cl[i].name, {'import_ref_rate': flt(flt(cl[i].purchase_ref_rate) / flt(doc.conversion_rate))}, fname);
set_multiple(tname, cl[i].name, {'purchase_rate':flt( flt(cl[i].purchase_ref_rate) - flt(flt(cl[i].purchase_ref_rate)*flt(cl[i].discount_rate)/100) )}, fname);
set_multiple(tname, cl[i].name, {'import_rate': flt(flt(cl[i].purchase_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, {'amount':flt(flt(cl[i].qty) * flt(cl[i].purchase_rate))}, fname); set_multiple(tname, cl[i].name, tmp, fname);
set_multiple(tname, cl[i].name, {'import_amount': flt(flt(cl[i].qty) * flt(cl[i].purchase_rate) / flt(doc.conversion_rate))}, 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==5){
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, {'purchase_rate':flt( flt(cl[i].import_ref_rate) - flt(flt(cl[i].import_ref_rate)*flt(cl[i].discount_rate)/100) ) * flt(doc.conversion_rate) }, fname);
set_multiple(tname, cl[i].name, {'import_rate': flt(flt(cl[i].purchase_rate) / flt(doc.conversion_rate))}, fname);
set_multiple(tname, cl[i].name, {'amount':flt(flt(cl[i].qty) * flt(cl[i].purchase_rate))}, fname);
set_multiple(tname, cl[i].name, {'import_amount': flt(flt(cl[i].qty) * flt(cl[i].purchase_rate) / flt(doc.conversion_rate))}, fname);
}
if( n==6){
//set_multiple(tname, cl[i].name, {'import_ref_rate': flt(flt(cl[i].purchase_ref_rate) / flt(doc.conversion_rate))}, fname);
if (cl[i].purchase_ref_rate){
set_multiple(tname, cl[i].name, {'purchase_rate':flt( flt(cl[i].purchase_ref_rate) - flt(flt(cl[i].purchase_ref_rate)*flt(cl[i].discount_rate)/100) )}, fname);
}
else{
set_multiple(tname, cl[i].name, {'purchase_rate': flt(flt(cl[i].import_rate) * flt(doc.conversion_rate))}, fname);
}
if (cl[i].import_ref_rate){
set_multiple(tname, cl[i].name, {'import_rate':flt( flt(cl[i].import_ref_rate) - flt(flt(cl[i].import_ref_rate)*flt(cl[i].discount_rate)/100) )}, fname);
}
else{
set_multiple(tname, cl[i].name, {'import_rate': flt(flt(cl[i].import_rate) * flt(doc.conversion_rate))}, fname);
}
set_multiple(tname, cl[i].name, {'import_rate': flt(flt(cl[i].purchase_rate) / flt(doc.conversion_rate))}, fname);
set_multiple(tname, cl[i].name, {'amount':flt(flt(cl[i].qty) * flt(cl[i].purchase_rate))}, fname);
set_multiple(tname, cl[i].name, {'import_amount': flt(flt(cl[i].qty) * flt(cl[i].purchase_rate) / flt(doc.conversion_rate))}, fname);
}
if (n != 3){ if (n != 3){
net_total += flt(flt(cl[i].qty) * flt(cl[i].purchase_rate)); 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)); net_total_import += flt(flt(cl[i].qty) * flt(cl[i].import_rate));
} } else if(n == 3){
else if(n == 3){
net_total += flt(cl[i].amount); net_total += flt(cl[i].amount);
net_total_import += flt(cl[i].amount) / flt(doc.conversion_rate); net_total_import += flt(cl[i].amount) / flt(doc.conversion_rate);
} }
@ -357,7 +275,7 @@ cur_frm.cscript.val_cal_charges = function(doc, cdt, cdn, tname, fname, other_fn
} }
cur_frm.cscript.calc_doc_values(doc, cdt, cdn, tname, fname, other_fname); // calculates total amounts cur_frm.cscript.calc_doc_values(doc, cdt, cdn, 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']); 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']);
} }
@ -512,21 +430,27 @@ cur_frm.cscript.calc_doc_values = function(doc, cdt, cdn, tname, fname, other_fn
doc.grand_total_import = flt(flt(doc.grand_total) / flt(doc.conversion_rate)); doc.grand_total_import = flt(flt(doc.grand_total) / flt(doc.conversion_rate));
doc.rounded_total_import = Math.round(doc.grand_total_import); doc.rounded_total_import = Math.round(doc.grand_total_import);
refresh_many(['net_total','total_taxes','grand_total']);
if(doc.doctype == 'Payable Voucher'){ if(doc.doctype == 'Payable Voucher'){
var t_tds_tax = 0.0; calculate_outstanding(doc);
doc.total_tds_on_voucher = flt(doc.ded_amount)
// total amount to pay
doc.total_amount_to_pay = flt(flt(net_total) + flt(other_charges_added) - flt(other_charges_deducted) - flt(doc.total_tds_on_voucher));
// outstanding amount
if(doc.docstatus==0) doc.outstanding_amount = flt(doc.net_total) + flt(other_charges_added) - flt(other_charges_deducted) - flt(doc.total_tds_on_voucher) - flt(doc.total_advance);
refresh_many(['net_total','total_taxes','grand_total','total_tds_on_voucher','total_amount_to_pay', 'outstanding_amount']);
} }
} }
var calculate_outstanding = function(doc) {
var t_tds_tax = 0.0;
doc.total_tds_on_voucher = flt(doc.ded_amount);
// total amount to pay
doc.total_amount_to_pay = flt(flt(doc.net_total) + flt(doc.other_charges_added) - flt(doc.other_charges_deducted) - flt(doc.total_tds_on_voucher));
// outstanding amount
if(doc.docstatus==0) doc.outstanding_amount = flt(doc.net_total) + flt(doc.other_charges_added) - flt(doc.other_charges_deducted) - flt(doc.total_tds_on_voucher) - flt(doc.total_advance);
refresh_many(['total_tds_on_voucher','total_amount_to_pay', 'outstanding_amount']);
}
cur_frm.cscript.check_charge_type_and_get_tax_amount = function(doc, tax, t, cl, rate, print_amt) { cur_frm.cscript.check_charge_type_and_get_tax_amount = function(doc, tax, t, cl, rate, print_amt) {
doc = locals[doc.doctype][doc.name]; doc = locals[doc.doctype][doc.name];

View File

@ -120,7 +120,8 @@ class DocType(TransactionBase):
'conversion_factor' : '1', 'conversion_factor' : '1',
'warehouse' : wh, 'warehouse' : wh,
'item_tax_rate' : str(t), 'item_tax_rate' : str(t),
'batch_no' : '' 'batch_no' : '',
'discount_rate' : 0
} }
# get min_order_qty from item # get min_order_qty from item
@ -139,6 +140,8 @@ class DocType(TransactionBase):
# get last purchase rate as per stock uom and default currency for following list of doctypes # get last purchase rate as per stock uom and default currency for following list of doctypes
if obj.doc.doctype in ['Supplier Quotation', 'Purchase Order', 'Purchase Receipt']: if obj.doc.doctype in ['Supplier Quotation', 'Purchase Order', 'Purchase Receipt']:
ret['purchase_ref_rate'] = item and flt(item[0]['last_purchase_rate']) or 0
ret['import_ref_rate'] = flt(item and flt(item[0]['last_purchase_rate']) or 0) / flt(obj.doc.fields.has_key('conversion_rate') and flt(obj.doc.conversion_rate) or 1)
ret['purchase_rate'] = item and flt(item[0]['last_purchase_rate']) or 0 ret['purchase_rate'] = item and flt(item[0]['last_purchase_rate']) or 0
ret['import_rate'] = flt(item and flt(item[0]['last_purchase_rate']) or 0) / flt(obj.doc.fields.has_key('conversion_rate') and flt(obj.doc.conversion_rate) or 1) ret['import_rate'] = flt(item and flt(item[0]['last_purchase_rate']) or 0) / flt(obj.doc.fields.has_key('conversion_rate') and flt(obj.doc.conversion_rate) or 1)
@ -159,8 +162,11 @@ class DocType(TransactionBase):
if uom: if uom:
ret = { ret = {
'conversion_factor' : flt(uom[0]['conversion_factor']), 'conversion_factor' : flt(uom[0]['conversion_factor']),
'qty' : flt(arg['stock_qty']) / flt(uom[0]['conversion_factor']), 'qty' : flt(arg['stock_qty']) / flt(uom[0]['conversion_factor']),
'purchase_rate' : (lpr and flt(lpr[0]['last_purchase_rate']) * flt(uom[0]['conversion_factor'])) or 0 'purchase_ref_rate' : (lpr and flt(lpr[0]['last_purchase_rate']) * flt(uom[0]['conversion_factor'])) or 0,
'purchase_rate' : (lpr and flt(lpr[0]['last_purchase_rate']) * flt(uom[0]['conversion_factor'])) or 0,
'import_ref_rate' : (lpr and flt(lpr[0]['last_purchase_rate']) * flt(uom[0]['conversion_factor'])/flt(self.doc.conversion_rate)) or 0,
'import_rate' : (lpr and flt(lpr[0]['last_purchase_rate']) * flt(uom[0]['conversion_factor'])/flt(self.doc.conversion_rate)) or 0
} }
return ret return ret
@ -170,8 +176,7 @@ class DocType(TransactionBase):
for d in getlist(obj.doclist, obj.fname): for d in getlist(obj.doclist, obj.fname):
if d.item_code: if d.item_code:
rate = sql("select last_purchase_rate from `tabItem` where name = '%s' and (ifnull(end_of_life,'')='' or end_of_life = '0000-00-00' or end_of_life > now())"% cstr(d.item_code), as_dict = 1 ) rate = sql("select last_purchase_rate from `tabItem` where name = '%s' and (ifnull(end_of_life,'')='' or end_of_life = '0000-00-00' or end_of_life > now())"% cstr(d.item_code), as_dict = 1 )
d.purchase_rate = rate and flt(rate[0]['last_purchase_rate']) * flt(d.conversion_factor) or 0 d.purchase_rate = rate and flt(rate[0]['last_purchase_rate']) * flt(d.conversion_factor) or 0
if not rate[0]['last_purchase_rate']: if not rate[0]['last_purchase_rate']:
msgprint("%s has no Last Purchase Rate."% d.item_code) msgprint("%s has no Last Purchase Rate."% d.item_code)

View File

@ -5,7 +5,7 @@
{ {
'creation': '2010-08-08 17:09:16', 'creation': '2010-08-08 17:09:16',
'docstatus': 0, 'docstatus': 0,
'modified': '2011-12-08 18:32:23', 'modified': '2011-12-13 13:03:11',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'owner': 'Administrator' 'owner': 'Administrator'
}, },
@ -21,7 +21,7 @@
'section_style': 'Tray', 'section_style': 'Tray',
'server_code_error': ' ', 'server_code_error': ' ',
'show_in_menu': 0, 'show_in_menu': 0,
'version': 70 'version': 71
}, },
# These values are common for all DocField # These values are common for all DocField
@ -141,7 +141,6 @@
# DocField # DocField
{ {
'colour': 'White:FFF', 'colour': 'White:FFF',
'default': '0.00',
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'purchase_rate', 'fieldname': 'purchase_rate',
'fieldtype': 'Currency', 'fieldtype': 'Currency',
@ -157,7 +156,6 @@
# DocField # DocField
{ {
'default': '0.00',
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'amount', 'fieldname': 'amount',
'fieldtype': 'Currency', 'fieldtype': 'Currency',
@ -199,7 +197,6 @@
# DocField # DocField
{ {
'colour': 'White:FFF', 'colour': 'White:FFF',
'default': '0.00',
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'import_rate', 'fieldname': 'import_rate',
'fieldtype': 'Currency', 'fieldtype': 'Currency',