PageRenderTime 118ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/public/admin/endpoints/orders/createScreen.php

http://flumpshop.googlecode.com/
PHP | 614 lines | 506 code | 64 blank | 44 comment | 82 complexity | 784b8511c95d71ce8f965ff7eee2d4e4 MD5 | raw file
  1. <?php
  2. /*
  3. @todo This form currently does not validate postcodes, as the validation method does not seem to work correctly.
  4. */
  5. $noPreValidate = true; //Disables the .validate() method being called in the header.
  6. $USR_REQUIREMENT = 'can_create_orders';
  7. require_once "../header.php";
  8. loadClass('FormHelper');
  9. $formHelper = new FormHelper();
  10. if (isset($_GET['id'])) {
  11. die('<div class="ui-state-error">Sorry! This form currently cannot edit orders. We\'re working on adding this functionality soon.</div>');
  12. }
  13. ?><style type="text/css">
  14. td label, legend, #itemsSummaryTable td, #orderItemsTable td{color:#000!important}
  15. input:focus {
  16. color: #FFF;
  17. font-weight:bolder
  18. }
  19. .ui-autocomplete{width:500px!important}
  20. </style>
  21. <h1>Create an Order</h1>
  22. <div id="errors" class="ui-state-highlight" style="display:none">
  23. <span class='ui-icon ui-icon-alert'></span><strong>I found the following issues with the order:</strong><br />
  24. <ul id="errorContent">
  25. </ul>
  26. </div>
  27. <form action="javascript:" id="orderFormMain" method="POST">
  28. <table style="width:100%">
  29. <tr>
  30. <td>
  31. <fieldset>
  32. <legend>Order Details</legend>
  33. <div id='orderItemsContainer'>
  34. Preparing the Flumpshop Ordering Platform...
  35. </div>
  36. </fieldset>
  37. <fieldset>
  38. <legend>Other Details</legend>
  39. <table id="otherDetailsTable">
  40. <tr>
  41. <td><input type="checkbox" name="vatExempt" id="vatExempt" onclick="updatePrices()" /></td>
  42. <td colspan="3"><label for="vatExempt">This customer does not need to pay VAT</label></td>
  43. </tr>
  44. <tr>
  45. <td><input type="checkbox" name="mailingList" id="mailingList" checked="checked" /></td>
  46. <td colspan="3"><label for="mailingList">Add this customer's email address to the mailing list</label></td>
  47. </tr>
  48. <tr>
  49. <td colspan="4"><a href="javascript:" onclick="addCouponCode();">Add a voucher to this order...</a>
  50. </tr>
  51. <tr>
  52. <td><label for="orderStatus">Order Status</label></td>
  53. <td colspan="3"><?php echo $formHelper->orderStatusSelector("orderStatus");?></td>
  54. </tr>
  55. </table>
  56. </fieldset>
  57. </td>
  58. <td><fieldset>
  59. <legend>Billing Details [<a href='javascript:' onclick='addressFinder("Billing");'>Load Data...</a>]</legend>
  60. <table>
  61. <tr>
  62. <td><label for="billingID">Customer Number: </label></td>
  63. <td><input type='text' class='ui-state-disabled' readonly="readonly" value="New" name="billingID" id="billingID" /></td>
  64. </tr>
  65. <tr>
  66. <td><label for="customerBillingName">Customer Name: </label></td>
  67. <td><input type="text" class="ui-state-active required" name="customerBillingName" id="customerBillingName" /></td>
  68. </tr>
  69. <tr>
  70. <td><label for="customerBillingAddress1">Billing Address 1: </label></td>
  71. <td><input type="text" class="ui-state-active required" name="customerBillingAddress1" id="customerBillingAddress1" /></td>
  72. </tr>
  73. <tr>
  74. <td><label for="customerBillingAddress2">Billing Address 2: </label></td>
  75. <td><input type="text" class="ui-state-active" name="customerBillingAddress2" id="customerBillingAddress2" /></td>
  76. </tr>
  77. <tr>
  78. <td><label for="customerBillingAddress3">Billing Address 3: </label></td>
  79. <td><input type="text" class="ui-state-active" name="customerBillingAddress3" id="customerBillingAddress3" /></td>
  80. </tr>
  81. <tr>
  82. <td><label for="customerBillingPostcode">Billing Address Postcode: </label></td>
  83. <td><input type="text" class="ui-state-active required" name="customerBillingPostcode" id="customerBillingPostcode" /></td>
  84. </tr>
  85. <tr>
  86. <td><label for="customerBillingCountry">Billing Address Country: </label></td>
  87. <td><?php
  88. echo $formHelper->countrySelector("customerBillingCountry",false);
  89. ?></td>
  90. </tr>
  91. <tr>
  92. <td><label for="customerBillingEmail">Email Address (Optional): </label></td>
  93. <td><input type="text" class="ui-state-active email" name="customerBillingEmail" id="customerBillingEmail" /></td>
  94. </tr>
  95. </table>
  96. </fieldset>
  97. <fieldset>
  98. <legend>Shipping Details [<a href='javascript:' onclick='addressFinder("Shipping");'>Load Data...</a>]</legend>
  99. <table>
  100. <tr>
  101. <td><label for="noShipping">Same as Billing: </label></td>
  102. <td><input type="checkbox" name="noShipping" id="noShipping" style="width:auto" class="ui-state-default" onchange="toggleShippingFields();" checked="checked" /></td>
  103. </tr>
  104. <tr class="ui-helper-hidden">
  105. <td><label for="shippingID">Customer Number: </label></td>
  106. <td><input type='text' class='ui-state-disabled ui-helper-hidden' readonly="readonly" value="New" name="shippingID" id="shippingID" /></td>
  107. </tr>
  108. <tr class="ui-helper-hidden">
  109. <td><label for="customerShippingName">Customer Name: </label></td>
  110. <td><input type="text" class="ui-state-active" name="customerShippingName" id="customerShippingName" /></td>
  111. </tr>
  112. <tr class="ui-helper-hidden">
  113. <td><label for="customerShippingAddress1">Shipping Address 1: </label></td>
  114. <td><input type="text" class="ui-state-active" name="customerShippingAddress1" id="customerShippingAddress1" /></td>
  115. </tr>
  116. <tr class="ui-helper-hidden">
  117. <td><label for="customerShippingAddress2">Shipping Address 2: </label></td>
  118. <td><input type="text" class="ui-state-active" name="customerShippingAddress2" id="customerShippingAddress2" /></td>
  119. </tr>
  120. <tr class="ui-helper-hidden">
  121. <td><label for="customerShippingAddress3">Shipping Address 3: </label></td>
  122. <td><input type="text" class="ui-state-active" name="customerShippingAddress3" id="customerShippingAddress3" /></td>
  123. </tr>
  124. <tr class="ui-helper-hidden">
  125. <td><label for="customerShippingPostcode">Shipping Address Postcode: </label></td>
  126. <td><input type="text" class="ui-state-active" name="customerShippingPostcode" id="customerShippingPostcode" /></td>
  127. </tr>
  128. <tr class="ui-helper-hidden">
  129. <td><label for="customerShippingCountry">Shipping Address Country: </label></td>
  130. <td><?php
  131. echo $formHelper->countrySelector("customerShippingCountry",false);
  132. ?></td>
  133. </tr>
  134. </table>
  135. </fieldset>
  136. </td>
  137. </tr>
  138. <tr>
  139. <td colspan="2">
  140. <button onclick="buildProforma();">Generate a Proforma Invoice</button>
  141. <input type="submit" value="Confirm Order" />
  142. </td>
  143. </tr>
  144. </table>
  145. </form>
  146. <script type="text/javascript">
  147. /*Declare Variables*/
  148. window.nextOrderItemID = 1;
  149. window.prices = new Array();
  150. window.orderItemStock = new Array();
  151. window.itemDeliveryCosts = new Array();
  152. window.nextCouponCodeID = 1;
  153. window.couponActions = new Array();
  154. /*Validation Rules*/
  155. var validObject = {
  156. errorContainer:'#errors',
  157. errorLabelContainer:'#errorContent',
  158. wrapper:'li',
  159. errorClass:'errorDetails',
  160. messages:{
  161. customerBillingName: "Please enter the Customer Name in the billing address section.",
  162. customerBillingAddress1: "Please fill in Billing Address 1.",
  163. customerBillingPostcode: {
  164. required: "Please fill in the Billing Address Postcode.",
  165. postcode: "Please enter a valid Billing Address Postcode."
  166. },
  167. customerBillingCountry: "Please fill in the Billing Address Country.",
  168. customerShippingName: "Please enter the Customer Name in the shipping address section.",
  169. customerShippingAddress1: "Please fill in Shipping Address 1.",
  170. customerShippingPostcode: {
  171. required: "Please fill in the Shipping Address Postcode.",
  172. postcode: "Please enter a valid Shipping Address Postcode."
  173. },
  174. customerShippingCountry: "Please fill in the Shipping Address Country.",
  175. item1ID:{
  176. required:"Please enter at least one item in the order details section."
  177. },
  178. orderStatus: "Please set the order status."
  179. },
  180. rules:{
  181. item1ID:"required",
  182. customerShippingName: {
  183. required: "#noShipping:not(#noShipping:checked)"
  184. },
  185. customerShippingAddress1: {
  186. required: "#noShipping:not(#noShipping:checked)"
  187. },
  188. customerShippingPostcode: {
  189. required: "#noShipping:not(#noShipping:checked)"
  190. //postcode:true
  191. },
  192. customerShippingCountry: {
  193. required: "#noShipping:not(#noShipping:checked)"
  194. },
  195. customerBillingPostcode: {
  196. //postcode:true
  197. },
  198. orderStatus:"required"
  199. }
  200. };
  201. //Create the order form
  202. $(document).ready(function() {
  203. $('td').each(function() {$(this).css('vertical-align','top')});
  204. $('#orderItemsContainer').html("<table id='orderItemsTable'><tr><th>&nbsp;</th><th>Product Code</th><th>Product Name</th><th>Quantity</th><th>Price</th></tr></table>");
  205. $('#orderItemsContainer').append("<table id='itemsSummaryTable' style='width:100%;text-align:right'></table>");
  206. $('#itemsSummaryTable').append("<tr><th>Subtotal</th><td style='width:80px' id='subTotal'>Ł0.00</td><td rowspan='500' style='width:85px'></td></tr>");
  207. $('#itemsSummaryTable').append("<tr id='discountRow' style='display:none'><th>Discounts</th><td id='discounts'>Ł0.00</td></tr>");
  208. $('#itemsSummaryTable').append("<tr id='vatRow'><th>VAT @ <?php echo $config->getNode('site','vat');?>%</th><td id='vat'>Ł0.00</td></tr>");
  209. $('#itemsSummaryTable').append("<tr><th>Shipping & Handling</th><td id='shipping'>Ł0.00</td></tr>");
  210. $('#itemsSummaryTable').append("<tr><th>Total</th><td id='total'>Ł0.00</td></tr>");
  211. newOrderRow();
  212. $('#orderFormMain').validate(validObject);
  213. //Sets up custom messages (dirty I know, but couldn't get it to work any other way)
  214. $('#errorContent').bind("DOMSubtreeModified",function() {
  215. $('#errorContent li label').each(function (index,element) {
  216. var regex = new RegExp(/item[0-9]+ID/);
  217. if (regex.test($(this).attr("for")) && $(this).html() == "Please enter a valid number.") {
  218. //Product code not a number
  219. $(this).html("The product code on row "+$(this).attr("for").replace("item","").replace("ID","")+" is incorrect. Please enter a number.")
  220. }
  221. var regex = new RegExp(/item[0-9]+Qty/);
  222. if (regex.test($(this).attr("for")) && $(this).html() == "Please enter a valid number.") {
  223. //Not enough Stock
  224. $(this).html("Please enter a number for the quantity field on row "+$(this).attr("for").replace("item","").replace("Qty","")+".")
  225. } else if (regex.test($(this).attr("for")) && $(this).html() == "<?php echo str_replace('"','\"',$config->getNode('messages','formFieldRequired'));?>") {
  226. //No quantity entered
  227. $(this).html("Please enter a quantity on row "+$(this).attr("for").replace("item","").replace("Qty","")+".")
  228. }
  229. });
  230. });
  231. });
  232. //Adds a row to the order items
  233. function newOrderRow() {
  234. newID = window.nextOrderItemID;
  235. if (newID != 1) {
  236. newDisplayID = parseInt($('#orderItemsTable tr:visible:last td strong').html())+1;
  237. } else {newDisplayID = 1}
  238. newRow = "<tr id='orderRow"+(newID)+"'>";
  239. newRow = newRow+"<td>";
  240. if (newID != 1) {newRow = newRow+"<a href='javascript:' onclick='hideRow("+newID+");' title='Delete Row'><span class='ui-icon ui-icon-close'></span></a>";}
  241. newRow = newRow+"<strong>"+newDisplayID+"</strong></td>";
  242. newRow = newRow+"<td><input type='text' name='item"+newID+"ID' id='item"+newID+"ID' class='ui-state-default positiveInt itemIDField' onkeyup='idKeyPress(this.id);' style='width:100px' unique='itemIDField' maxlength='11' /></td>";
  243. newRow = newRow+"<td><input type='text' disabled='disabled' class='orderItemName' id='item"+newID+"Name' style='width:300px;color:#000' /></td>";
  244. newRow = newRow+"<td><input type='text' name='item"+newID+"Qty' id='item"+newID+"Qty' class='ui-state-default positiveInt' onkeyup='quantityKeyPress(this.id);' onkeypress='document.lastQty = this.value;' style='width:65px' value='1' checkOrderQuantity='"+newID+"' required='$(\"item"+newID+"ID\").html() == \"\"' /></td>";
  245. newRow = newRow+"<td><input type='text' readonly='readonly' id='item"+newID+"Price' name='item"+newID+"Price' style='width:80px;' /></td>";
  246. newRow = newRow+"<td><a href='javascript:' onclick='findItem("+newID+");'>More...</a></td>";
  247. newRow = newRow+"</tr>";
  248. $('#orderItemsTable').append(newRow);
  249. $('#orderRow'+newID).effect('highlight',{},1000);
  250. window.nextOrderItemID++;
  251. }
  252. function idKeyPress(id,dialog) {
  253. if (!dialog) dialog = false;
  254. idNumber = parseInt(id.replace("item","").replace("ID",""));
  255. if (idNumber+1 == window.nextOrderItemID || $('#orderItemsTable tr:visible:last').attr('id') == 'orderRow'+idNumber) {
  256. newOrderRow();
  257. }
  258. if ($('#'+id).val() == "") return;
  259. //Find name
  260. $('#item'+idNumber+'Name, #item'+idNumber+'Price').val(' Checking...').css('background','url("../../../images/loading.gif") no-repeat');
  261. $.ajax({
  262. url:'../orders/ajax/itemName.php?id='+$('#'+id).val()+'&dialog='+dialog.toString()+'&rowID='+idNumber,
  263. dataType:'json',
  264. success:function(data) {
  265. if (dialog) {
  266. $('#item'+data[2]+'Name').val(data[0]).css('background','none');
  267. //Use prices from the dialog, not the Ajax Request
  268. $('#item'+data[2]+'Price').val("Ł"+parseFloat($('#morePrice').val()).toFixed(2))
  269. .css('background','none');
  270. $('#item'+data[2]+'Qty').val($('#morePriceUnits').val());
  271. window.prices[data[2]] = $('#morePrice').val()/$('#morePriceUnits').val();
  272. window.orderItemStock[data[2]] = data[1];
  273. window.itemDeliveryCosts[data[2]] = $('#moreDelivery').val()/$('#moreDeliveryUnits').val();
  274. //This function was called by the dialog box
  275. //The dialog is only hidden at the moment so data could be grabbed
  276. $('#dialog').dialog('destroy');
  277. } else {
  278. $('#item'+data[4]+'Name').val(data[0]).css('background','none');
  279. //Directly entered - use full Ajax data
  280. $('#item'+data[4]+'Price').val("Ł"+(data[1]*$('#item'+data[4]+'Qty').val()).toFixed(2)).css('background','none');
  281. window.prices[data[4]] = data[1];
  282. window.orderItemStock[data[4]] = parseInt(data[2]);
  283. window.itemDeliveryCosts[data[4]] = data[3];
  284. }
  285. updatePrices();
  286. },
  287. cache:true
  288. });
  289. }
  290. function quantityKeyPress(id) {
  291. idNumber = parseInt(id.replace("item","").replace("Qty",""));
  292. if (idNumber+1 == window.nextOrderItemID || $('#orderItemsTable tr:visible:last').attr('id') == 'orderRow'+idNumber) {
  293. newOrderRow();
  294. }
  295. originalPrice = window.prices[idNumber];
  296. if (parseInt($('#'+id).val()) <= 0) newVal = "0.00"; else
  297. newVal = (originalPrice*$('#'+id).val()).toFixed(2);
  298. $('#item'+idNumber+'Price').val("Ł"+newVal);
  299. window.lastQty = 0;
  300. updatePrices();
  301. }
  302. function loadCustomer() {
  303. loader('Not Implemented.');
  304. }
  305. //Find Item Dialog
  306. function findItem(id) {
  307. window.tempFindItemId = id;
  308. $('#dialog').html("<img src='../../../images/loading.gif' />Loading Content...").attr('title','Advanced Item Select');
  309. $('#dialog').dialog({width:600,height:400});
  310. $('#dialog').load('../orders/ajax/findItem.php?id='+id, function(var1,var2,var3) { //Loaded Function
  311. //Load Item if already entered
  312. if ($('#item'+window.tempFindItemId+'ID').val() != "" &&
  313. $('#item'+window.tempFindItemId+'Name').val() != "Invalid Item. [Doesn't Exist]" &&
  314. $('#item'+window.tempFindItemId+'Name').val() != "Invalid Item. [No longer available]") {
  315. $('#findItemName').val($('#item'+window.tempFindItemId+'Name').val());
  316. itemSummary($('#item'+window.tempFindItemId+'ID').val());
  317. }
  318. //Initialise the new form
  319. $('#findItemName').autocomplete({
  320. source:'../orders/ajax/itemSuggest.php',
  321. select: function(event, ui) {
  322. $('#findItemName').val(ui.item[1]);
  323. itemSummary(ui.item[0]);
  324. return false;
  325. }
  326. })
  327. .data("autocomplete")._renderItem = function(ul, item) { //This is one of those WTF Lines
  328. return $( "<li></li>")
  329. .data("item.autocomplete", item)
  330. .append("<a>"+item[1]+"</a>")
  331. .appendTo(ul);
  332. }
  333. });
  334. }
  335. function itemSummary(id) {
  336. $('#findItemDetails').html("<img src='../../../images/loading.gif' />Loading Content...")
  337. .load("../orders/ajax/itemSummary.php?id="+id, function() {$('#dialogItemData').validate()});
  338. }
  339. function updatePrices() {
  340. //Updates the totals
  341. var total = 0;
  342. for (n=1;n<window.nextOrderItemID;n++) {
  343. //Calculate Total Price
  344. if ($('#item'+n+'Price').val() != "") {
  345. //Set the price to 0 if it is ŁNaN
  346. if ($('#item'+n+'Price').val() == 'ŁNaN') $('#item'+n+'Price').val('Ł0.00');
  347. //Skip if the price is still being loaded
  348. if (!$('#item'+n+'Price').val().match(/ *Checking/))
  349. total += parseFloat($('#item'+n+'Price').val().replace('Ł',''));
  350. }
  351. }
  352. $('#subTotal').html('&pound;'+(total.toFixed(2)));
  353. var shipping = 0;
  354. for (n=1;n<window.nextOrderItemID;n++) {
  355. //Calculate Total Delivery
  356. if ($('#item'+n+'ID').val() != "" && window.itemDeliveryCosts[n]) {
  357. shipping += parseFloat(window.itemDeliveryCosts[n]*$('#item'+n+'Qty').val());
  358. }
  359. }
  360. $('#shipping').html('&pound;'+(shipping.toFixed(2)));
  361. //Calculate Vouchers
  362. var totalAdjustment = 0;
  363. for (n=1;n<window.nextCouponCodeID;n++) {
  364. var action = window.couponActions[n];
  365. //Affects Basket Final Total
  366. if (action.match(/BasketTotal_/) !== null) {
  367. action = action.replace("BasketTotal_","");
  368. if (action.match(/[0-9\-]%/) !== null) {
  369. adjustment = parseFloat(action.replace("%",""))/100;
  370. adjustment = total*adjustment;
  371. $('#coupon'+n+'PriceAdjust').val(('Ł'+adjustment.toFixed(2)).replace("Ł-","-Ł"));
  372. totalAdjustment += adjustment;
  373. }
  374. }
  375. //Affects the price of a single item
  376. else if (action.match(/Item[0-9]*Price_/) !== null) {
  377. var item_id = action.replace(/Item/,"").replace(/Price_.*/,"");
  378. var newPrice = parseFloat(action.replace(/Item[0-9]*Price_/,""));
  379. //Find the item ID if its set, and adjust price based on quantity if so
  380. for (i=1;i<window.nextOrderItemID;i++) {
  381. if ($('#item'+i+'ID').val() == item_id) {
  382. //Found the item
  383. var oldPrice = parseFloat($('#item'+i+'Price').val().replace('Ł',''));
  384. var adjustment = (newPrice*$('#item'+i+'Qty').val())-oldPrice;
  385. $('#coupon'+n+'PriceAdjust').val(('Ł'+adjustment.toFixed(2)).replace("Ł-","-Ł"));
  386. totalAdjustment += adjustment;
  387. //Don't need to do anything with VAT - it's calculated afterwards anyway
  388. }
  389. }
  390. }
  391. //No action to current basket
  392. $('#coupon'+n+'PriceAdjust').val('Ł0.00');
  393. }
  394. //Finalize Coupons
  395. $('#discounts').html(('&pound;'+totalAdjustment.toFixed(2)).replace("&pound;-","-&pound;"));
  396. if (totalAdjustment == 0 && $('#discountRow:visible').length != 0) {
  397. $('#discountRow').hide('highlight');
  398. } else if (totalAdjustment != 0 && $('#discountRow:visible').length == 0) {
  399. $('#discountRow').show('highlight');
  400. }
  401. total+=totalAdjustment;
  402. //Calculate VAT
  403. if ($('#vatExempt:checked').val() == null) {
  404. var vatRate = <?php echo $config->getNode('site','vat')/100;?>;
  405. if ($('#vatRow:visible').length == 0) $('#vatRow').show('highlight');
  406. } else {
  407. var vatRate = 0;
  408. if ($('#vatRow:visible').length == 1) $('#vatRow').hide('highlight');
  409. }
  410. $('#vat').html('&pound;'+(total*vatRate).toFixed(2));
  411. total = total*(1+vatRate);
  412. //Add shipping afterwards so VAT doesn't affect it
  413. total += shipping;
  414. $('#total').html('&pound;'+total.toFixed(2));
  415. }
  416. function addCouponCode() {
  417. newID = window.nextCouponCodeID;
  418. newRow = "<tr id='couponRow"+newID+"'>";
  419. newRow = newRow+"<td><a href='javascript:' onclick='hideCoupon("+newID+");' title='Delete Row'><span class='ui-icon ui-icon-close'></span></a><strong>"+newID+"</strong></td>";
  420. newRow = newRow+"<td><input type='text' name='coupon"+newID+"Key' id='coupon"+newID+"Key' class='ui-state-default couponKey' onkeyup='couponKeyPress(this.id);' style='width:100px' unique='couponKey' maxlength='32' /></td>";
  421. newRow = newRow+"<td><input type='text' disabled='disabled' class='couponDetails' id='coupon"+newID+"Action' style='width:300px;color:#000' /></td>";
  422. newRow = newRow+"<td><input type='text' disabled='disabled' id='coupon"+newID+"PriceAdjust' style='width:80px;' /></td>";
  423. newRow = newRow+"</tr>";
  424. $('#otherDetailsTable').append(newRow);
  425. $('#couponRow'+newID).effect('highlight',{},1000);
  426. window.nextCouponCodeID++;
  427. }
  428. function couponKeyPress(id) {
  429. idNumber = parseInt(id.replace("coupon","").replace("Key",""));
  430. if ($('#'+id).val() == "") return;
  431. //Find name
  432. $('#coupon'+idNumber+'Action, #coupon'+idNumber+'PriceAdjust').val(' Checking...').css('background','url("../../../images/loading.gif") no-repeat');
  433. $.ajax({
  434. url:'../orders/ajax/couponAction.php?id='+$('#'+id).val(),
  435. dataType:'json',
  436. success:function(data) {
  437. $('#coupon'+idNumber+'Action').val(data[0]).css('background','none');
  438. //Calculate the effect the coupon has on the total
  439. window.couponActions[idNumber] = data[1];
  440. $('#coupon'+idNumber+'PriceAdjust').css('background','none');
  441. updatePrices();
  442. },
  443. cache:true
  444. });
  445. }
  446. function addressFinder(prefix) {
  447. $('#dialog').html("<img src='../../../images/loading.gif' />Loading Content...").attr('title',prefix+' Address Finder');
  448. $('#dialog').dialog({width:600,height:400});
  449. $('#dialog').load('../orders/ajax/findAddress.php?pre='+prefix, function(var1,var2,var3) { //Loaded Function
  450. //Load Address if already entered
  451. if ($('#'+prefix.toLowerCase()+'ID').val() != "New") {
  452. $('#findAddressTerm').val($('#'+prefix.toLowerCase()+'ID').val());
  453. addressSummary($('#'+prefix.toLowerCase()+'ID').val());
  454. }
  455. //Initialise the new form
  456. $('#dialog form').validate();
  457. $('#findAddressTerm').autocomplete({
  458. source:'../orders/ajax/addressSuggest.php',
  459. select: function(event, ui) {
  460. $('#findAddressTerm').val(ui.item[0]);
  461. addressSummary(ui.item[0],prefix);
  462. return false;
  463. }
  464. })
  465. .data("autocomplete")._renderItem = function(ul, item) { //This is one of those WTF Lines
  466. return $( "<li></li>")
  467. .data("item.autocomplete", item)
  468. .append("<a>"+item[1]+" "+item[3]+" "+item[4]+" "+item[6]+"</a>")
  469. .appendTo(ul);
  470. }
  471. });
  472. }
  473. function hideRow(id) {
  474. $('#item'+id+'Price').val("0.00");
  475. $('#item'+id+'Qty').val("0.00");
  476. $('#orderRow'+id).hide('highlight');
  477. updatePrices();
  478. }
  479. function hideCoupon(id) {
  480. $('#couponRow'+id).hide('highlight',{},1000);
  481. $('#coupon'+id+'Key').val("");
  482. window.couponActions[id] = "__DELETED__";
  483. updatePrices();
  484. }
  485. function addressSummary(id,prefix) {
  486. $('#findAddressDetails').html("<img src='../../../images/loading.gif' />Loading Content...")
  487. .load("../orders/ajax/addressSummary.php?id="+id+"&pre="+prefix, function() {$('#dialogAddressData').validate()});
  488. }
  489. function applyAddress(prefix) {
  490. $('#'+prefix.toLowerCase()+'ID').val($('#findAddressTerm').val());
  491. $('#customer'+prefix+'Name').val($('#dialog .fs-customer-name').html());
  492. $('#customer'+prefix+'Address1').val($('#dialog .fs-customer-address1').html());
  493. $('#customer'+prefix+'Address2').val($('#dialog .fs-customer-address2').html());
  494. $('#customer'+prefix+'Address3').val($('#dialog .fs-customer-address3').html());
  495. $('#customer'+prefix+'Postcode').val($('#dialog .fs-customer-postcode').html());
  496. $('#customer'+prefix+'Country').val($('#dialog .fs-customer-countrycode').html());
  497. if (prefix === 'Billing') {
  498. $('#customerBillingEmail').val($('#dialog .fs-customer-email').html());
  499. }
  500. }
  501. function toggleShippingFields() {
  502. if ($('#noShipping:checked').length == 0) {
  503. //Same as shipping
  504. $('#shippingID, #customerShippingName, #customerShippingAddress1, #customerShippingAddress2, #customerShippingAddress3, #customerShippingPostcode, #customerShippingCountry').parent().parent().show('highlight');
  505. } else {
  506. //Different to shipping
  507. $('#shippingID, #customerShippingName, #customerShippingAddress1, #customerShippingAddress2, #customerShippingAddress3, #customerShippingPostcode, #customerShippingCountry').parent().parent().hide('highlight');
  508. }
  509. }
  510. function buildProforma() {
  511. $('#dialog').html('The order is being checked and processed. Please wait...').attr('title','Generating Proforma Invoice');
  512. $('#dialog').dialog();
  513. if ($('#orderFormMain').valid()) {
  514. if ($('#billingID').val() === "New") {
  515. //Save the billing details
  516. commitBilling();
  517. }
  518. if ($('#shippingID').val() === "New" && $('#noShipping').attr('checked') === "checked") {
  519. //Save the shipping details
  520. commitShipping();
  521. }
  522. $('#orderFormMain').attr('action','proforma.php').attr('target','_blank');
  523. }
  524. $('#dialog').dialog('destroy');
  525. }
  526. //commitBilling sends an Ajax request to store the customer data in the database and update the form accordingly
  527. function commitBilling() {
  528. $.ajax({
  529. url:'ajax/commitBilling.php',
  530. data:'name='+$('#customerBillingName').val()+'&address1='+$('#customerBillingAddress1').val()+'&address2='+$('#customerBillingAddress2').val()+'&address3='+$('#customerBillingAddress3').val()+'&postcode='+$('#customerBillingPostcode').val()+'&country='+$('#customerBillingCountry').val()+'&email='+$('#customerBillingEmail').val()+'&contact='+$('#mailingList').val(),
  531. type:'post',
  532. success: function(data) {$('#billingID').val(data)}
  533. });
  534. }
  535. $('#dialog').css('display','block');
  536. //Test Function - Creates a large number of order items
  537. function testlib_largeOrder() {
  538. for (i=1;i<=300;i++) {
  539. setTimeout("$('#item"+i+"ID').val("+i+");idKeyPress('item"+i+"ID');",5*i);
  540. }
  541. return "Executing Command...";
  542. }
  543. function testlib_largeQuantity() {
  544. for (i=1;i<window.nextOrderItemID;i++) {
  545. setTimeout("$('#item"+i+"Qty').val(200);quantityKeyPress('item"+i+"Qty');",5*i);
  546. }
  547. return "Executing Command...";
  548. }
  549. </script></body></html>