From 57b56a0932bf6d9fff2be701a20583de78088020 Mon Sep 17 00:00:00 2001
From: Vladimir Hidalgo <vlad@todosv.com>
Date: Tue, 13 Oct 2009 08:52:31 -0600
Subject: [PATCH 2/2] Add JS calculateExtendedRev()
This patch enable the user to type into the extended field and calculate UnitPrice.
theprice = extended / qty
---
modules/bms/invoices_addedit.php | 2 +-
modules/bms/javascript/invoice.js | 58 +++++++++++++++++++++++++++++++++++-
2 files changed, 57 insertions(+), 3 deletions(-)
diff --git a/modules/bms/invoices_addedit.php b/modules/bms/invoices_addedit.php
index a138bd1..03ceaf7 100644
|
a
|
b
|
|
| 412 | 412 | <td><input name="memo" type="text" id="memo" size="12" maxlength="255" /></td> |
| 413 | 413 | <td align="right" nowrap="nowrap"><input name="price" type="text" id="price" value="<?php echo htmlQuotes(numberToCurrency(0))?>" size="10" maxlength="16" class="fieldCurrency" /></td> |
| 414 | 414 | <td align="center" nowrap="nowrap"><input name="qty" type="text" id="qty" value="1" size="5" maxlength="16" /></td> |
| 415 | | <td align="right" nowrap="nowrap"><input name="extended" type="text" id="extended" class="uneditable fieldCurrency" value="<?php echo htmlQuotes(numberToCurrency(0))?>" size="12" maxlength="16" readonly="readonly" /></td> |
| | 415 | <td align="right" nowrap="nowrap"><input name="extended" type="text" id="extended" class="fieldCurrency" value="<?php echo htmlQuotes(numberToCurrency(0))?>" size="12" maxlength="16" /></td> |
| 416 | 416 | <td nowrap="nowrap" align="left"><button type="button" id="lineitemAddButton" class="graphicButtons buttonPlus" title="Add Line Item"><span>+</span></button></td> |
| 417 | 417 | </tr><?php }//end if |
| 418 | 418 | |
diff --git a/modules/bms/javascript/invoice.js b/modules/bms/javascript/invoice.js
index 03f1155..4f13983 100644
|
a
|
b
|
|
| 747 | 747 | |
| 748 | 748 | tempinput = document.createElement("input"); |
| 749 | 749 | tempinput.id = thetr.id + "Extended"; |
| 750 | | tempinput.className = "uneditable fieldCurrency lineitemExtendeds" |
| 751 | | tempinput.readOnly = true; |
| | 750 | tempinput.className = "fieldCurrency lineitemExtendeds" |
| | 751 | connect(tempinput, "onchange", lineitems.calculateExtendedRev); |
| 752 | 752 | tempinput.value = extended.value; |
| 753 | 753 | temptd.appendChild(tempinput); |
| 754 | 754 | |
| … |
… |
|
| 881 | 881 | |
| 882 | 882 | },//end function |
| 883 | 883 | |
| | 884 | calculateExtendedRev: function(e){ |
| | 885 | |
| | 886 | theTR = e.src().parentNode.parentNode; |
| | 887 | |
| | 888 | lineitems._calculateExtendedRev(theTR) |
| | 889 | |
| | 890 | }, //end function |
| | 891 | |
| | 892 | |
| | 893 | _calculateExtendedRev: function(theTR){ |
| | 894 | |
| | 895 | if(theTR.id == "LIAdd"){ |
| | 896 | |
| | 897 | var thecurrency = getObjectFromID("price"); |
| | 898 | var quantity = getObjectFromID("qty"); |
| | 899 | var extField = getObjectFromID("extended"); |
| | 900 | |
| | 901 | } else { |
| | 902 | |
| | 903 | var thecurrency = getObjectFromID(theTR.id+"UnitPrice"); |
| | 904 | var quantity = getObjectFromID(theTR.id+"Quantity"); |
| | 905 | var extField = getObjectFromID(theTR.id+"Extended"); |
| | 906 | |
| | 907 | }//end if |
| | 908 | |
| | 909 | // Last, figure extended and reformat to dollar |
| | 910 | var extended = currencyToNumber(extField.value); |
| | 911 | extField.value = numberToCurrency(extended); |
| | 912 | |
| | 913 | // Next verify that qty is a number |
| | 914 | var qty = parseFloat(quantity.value); |
| 884 | 915 | |
| | 916 | if(isNaN(qty)) |
| | 917 | qty = 1; |
| | 918 | |
| | 919 | quantity.value = qty; |
| | 920 | |
| | 921 | // Figure out the price and format it |
| | 922 | theprice = roundForCurrency(extended / qty); |
| | 923 | thecurrency.value = theprice; |
| | 924 | |
| | 925 | //if this is a modification, we also need to calculate totals and mark line items changed |
| | 926 | if(theTR.id != "LIAdd"){ |
| | 927 | |
| | 928 | invoice.doAllTotals(); |
| | 929 | lineitems.markChanged(); |
| | 930 | |
| | 931 | }//end if |
| | 932 | |
| | 933 | },//end function |
| | 934 | |
| 885 | 935 | del: function(e){ |
| 886 | 936 | |
| 887 | 937 | var theTR = e.src().parentNode.parentNode.parentNode; |
| … |
… |
|
| 1687 | 1737 | if(unitprice) |
| 1688 | 1738 | connect(unitprice, "onchange", lineitems.calculateExtended) |
| 1689 | 1739 | |
| | 1740 | var unitprice = getObjectFromID("extended"); |
| | 1741 | if(unitprice) |
| | 1742 | connect(unitprice, "onchange", lineitems.calculateExtendedRev) |
| | 1743 | |
| 1690 | 1744 | var quantity = getObjectFromID("qty"); |
| 1691 | 1745 | if(quantity) |
| 1692 | 1746 | connect(quantity, "onchange", lineitems.calculateExtended) |