Hi guys,
I have a strange situation that I have not encountered before, although I've implemented many similar projects.
I have a table in a form that is populated from a lookup. The lookup value is based on an invoice number, which will then return all valid stock codes for that specific invoice number. This will then populate valid stock codes in the table's "Stock Code" drop down. Then, when the user selects one of the stock codes, it will automatically populate lookup data for "Qty Ordered" and "Total Price". Then, I have some script that calculates the unit price, and upon the user entering the "Qty Returned" value, the script with calculate a subtotal for each line item.
The lookup rules:
The form doing lookups:
Add qty returned:
This all works wonderfully, until I add a new row. Then my table looks like this:
1. the extra row I add does not correctly perform the lookup as it did with the first row. The Total Price lookup value is missing, although the Qty Ordered lookup value is correct.
2. the table row formatting is broken. There's no currency symbol displayed for the Price columns and there's also no "X" button at the end of the row that allows you to remove the row.
The only way I can get the formatting problem fixed is to remove my script and run the form without doing any calculations. Then everything functions fine...but then I have no calculations.
Here's my script:
$(document).ready(function () { //trigger for updating expense table values $('.tblstock').on('change', 'input', sumtotalcredit); $('.tblstock').on('change', 'select', sumtotalcredit); $('.handlingCharge').on('change', 'input', sumtotalcredit); function sumtotalcredit() { var totalcredit = 0; var totalVAT = 0; var subtotalcredit = 0; var handlingCharge = $('.handlingCharge input').val() / 100; var handlingFee = 0; $('.tblstock tbody tr').each(function () { var subtotal = 0; var qtyOrdered = $(this).find('.qtyOrdered input').val() * 1; var qtyReturned = $(this).find('.qtyReturned input').val() * 1; //Check that qty Returned is not more than qtyOrdered if(qtyReturned > qtyOrdered) { alert('The Qty to be returned cannot be more than the Qty Ordered. Please check the value you typed in.'); return; } var unitPrice = 0; var totalPrice = $(this).find('.totalPrice input').val(); unitPrice += totalPrice / qtyOrdered; $(this).find('.unitPrice input').val(unitPrice); subtotal += unitPrice * qtyReturned; subtotal = subtotal.toFixed(2); subtotalcredit += subtotal *1; subtotalcredit = subtotalcredit.toFixed(2); $(this).find('.stock_subtotal input').val(subtotal); });//end for each tblstock function if(handlingCharge > 0) { handlingFee = subtotalcredit * handlingCharge; handlingFee = handlingFee.toFixed(2); }//end if $('.handlingFee input').val(handlingFee); $('.credit_subtotal input').val(subtotalcredit); totalVAT += subtotalcredit * 0.14; totalVAT = totalVAT.toFixed(2); $('.vat input').val(totalVAT); totalcredit += subtotalcredit *1; totalcredit += totalVAT * 1; totalcredit += handlingFee *1; //totalcredit = totalcredit.toFixed(2); $('.totalCredit input').val(totalcredit); }//end sumtotalcredit function });//end ready and end function
I'm really stumped and don't know where I'm going wrong. It all seems to be related to my script, but I'm not 100% convinced, since I've used this method multiple times before. Hopefully somebody can spot my mistake.
FYI, this is running Forms 9.1.1.1517.
Thanks
Sheldon