This topic is locked
[SOLVED]

 Tender amount & change due

2/18/2017 6:23:37 PM
Invoice template support forum
mtpocket author

Hi,
I'm playing with PHPRunner 9.6(Eval) with invoice template & battling to include amount tendered & change due. I know it must occur @ events Add Page, Javascript on load event. This is the original sample:
Runner.pages.constants.CANCEL_GIF = "remove";

Runner.lang.constants.TEXT_CANCEL = "Delete Item";
Runner.Invoice.initInvoiceButtons();

Runner.Invoice.initShortCuts();

Runner.Invoice.initSortableGrid();
var ctrlInvNum = Runner.getControl(pageid, "invoice_number"),

ctrlbiBuyerInfo = Runner.getControl(pageid, "buyer_info"),

ctrlCompanyName = Runner.getControl(pageid, "company_name"),

ctrlDate = Runner.getControl(pageid, 'date'),

url = Runner.pages.getUrl( pageObj.tName, pageObj.pageType );
Runner.Invoice.initInvoiceNumberAdjustment( ctrlInvNum, url );
if ( typeof ctrlbiBuyerInfo.doAutoCompleteFields === "function" ) {

ctrlbiBuyerInfo.doAutoCompleteFields();

}
if ( ctrlCompanyName ) {

ctrlCompanyName.addStyle('font-size: 32px; line-height: normal;');

}
if ( ctrlDate ) {

ctrlDate.setValue( Runner.Invoice.refineDate( new Date() ) );

ctrlDate.addStyle('text-align: right; vertical-align: bottom;');

}
Runner.Invoice.prepareField(pageid, "buyer_info");

Runner.Invoice.prepareField(pageid, "buyer_address");

Runner.Invoice.prepareField(pageid, "seller_info");

Runner.Invoice.prepareField(pageid, "company_name");

Runner.Invoice.prepareField(pageid, "date");
var currency = proxy.currency,

ctrlSubtotal = Runner.getControl(pageid, 'subtotal'),

ctrlTotal = Runner.getControl(pageid, 'total'),

ctrlTax = Runner.getControl(pageid, 'tax'),

$hiddenSubtotal = $("div.hidden-subtotal"),

$hiddenTotal = $("div.hidden-total"),

$calcTaxCont = $("div.calc-tax"),

calcTax = 0;
$hiddenSubtotal.html( ctrlSubtotal.getValue() );

$hiddenTotal.html( ctrlTotal.getValue() );

$calcTaxCont.html( Runner.Invoice.currencyFormat(calcTax.toFixed(2), currency) );
// Calculating Subtotal if Tax is changed

ctrlTax.on('keyup', function() {

var tax = Runner.Invoice.getCommaReplacedValue( this.getValue() ),

subTotal = parseFloat( $hiddenSubtotal.html() ),

total = subTotal (1 + tax / 100),

calcTax = subTotal
tax / 100;
ctrlTotal.setValue( Runner.Invoice.currencyFormat(total.toFixed(2), currency) );

$hiddenTotal.html( total.toFixed(2) );

$calcTaxCont.html( Runner.Invoice.currencyFormat(calcTax.toFixed(2), currency) );

});
this.on('beforeSave', function( formObj, fieldControlsArr, pageObj ) {

formObj.baseParams['subtotal'] = parseFloat( $hiddenSubtotal.html() );

formObj.baseParams['total'] = parseFloat( $hiddenTotal.html() );

});
And this is what I've added:
//calculating Tender Amount & Change

var ctrlTender_Amount = Runner.getControl(pageid,'Tender_Amount');

var ctrlChange_Due = Runner.getControl(pageid,'Change_Due');

function func() {

ctrlChange_Due.setValue(Number(ctrlTender_Amount.getValue())-(Number(ctrlTotal.getValue())));

};

ctrlTender_Amount.on('keyup',func);

ctrlChange_Due.on('keyup',func);
Somehow it just doesn't want to display the change due... I've tried numerous ways to get the bottom of "(Number(ctrlTotal.getValue())))" with no success.

When I replace "(Number(ctrlTotal.getValue())))" with a static number it does the calculation.

What should the "ctrlTotal.getvalue" be?
Thanks

mtpocket author 2/22/2017

SOLVED.
This is what it looks like now.
var ctrlTender_Amount = Runner.getControl(pageid,'Tender_Amount');

var ctrlChange_Due = Runner.getControl(pageid,'Change_Due');

function func() {

ctrlChange_Due.setValue(Number(ctrlTender_Amount.getValue())-(Number(parseFloat( $hiddenTotal.html() ))));

};

ctrlTender_Amount.on('keyup',func);

ctrlChange_Due.on('keyup',func);