Guest User

Untitled

a guest
May 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.32 KB | None | 0 0
  1. if (isset($_POST['submit'])) {
  2. $invoiceId = $_POST['invoiceId'];
  3. $client = $_POST['Client'];
  4. $address = $_POST['Address'];
  5. $Date = $_POST['Date'];
  6. $suBTotal = $_POST['subTotal'];
  7.  
  8. foreach($_POST['data'] as $key => $value) {
  9. $invoiceItemId = intval($value['invoiceItemId']);
  10. $itemId = intval($value['ItemId']);
  11. $item = strip_tags(trim(strval($value['item'])));
  12. $QTY = intval($value['QTY']);
  13. $addedQTY = intval($value['addedQTY']);
  14. $subtractedQty = intval($value['subtractedQty']);
  15. $Price = is_numeric($value['price']) ? $value['price'] : false;
  16. $Total = is_numeric($value['total']) ? $value['total'] : false;
  17.  
  18. try {
  19.  
  20. $updateInvoice = $db - > prepare(" UPDATE `invoices` SET
  21. client = : client,
  22. Address = : Address,
  23. Date = : Date,
  24. subTotal = : subTotal WHERE `invoiceId` = : invoiceId ");
  25.  
  26. $updateInvoice - > bindparam(':client', $client); $updateInvoice - > bindparam(':Address', $address); $updateInvoice - > bindparam(':Date', $Date); $updateInvoice - > bindparam(':subTotal', $suBTotal); $updateInvoice - > bindparam(':invoiceId', $invoiceId);
  27.  
  28. $invoiceUpdate = $updateInvoice - > execute();
  29.  
  30.  
  31. if ($invoiceItemId === 0) {
  32.  
  33.  
  34. $insertNewItems = $db - > prepare(" INSERT INTO `invoiceItems` (`invoiceId`,`ItemId`,`Item`,`qty`,`Price`,`Total`)
  35. values(: invoiceId, : ItemId, : item, : qty, : Price, : Total)
  36. ");
  37.  
  38. $insertNewItems - > execute(array(':invoiceId' => $invoiceId, ':ItemId' => $itemId, ':item' => $item, ':qty' => $QTY, ':Price' => $Price, ':Total' => $Total));
  39.  
  40. $updateItems = $db - > prepare("UPDATE items SET QTY = QTY - :QTY where id= :iId ");
  41.  
  42. $updateItems - > execute(array(':iId' => $itemId, ':QTY' => $QTY));
  43.  
  44. }
  45. elseif($addedQTY > 0) {
  46. $updateInvoiceAddedItems = $db - > prepare("UPDATE `invoiceItems` SET
  47. qty = qty + : addedQTY,
  48. addedQty = addedQty + : addingQTY where id = : Iid ");
  49.  
  50. $updateInvoiceAddedItems - > execute(array(':Iid' => $itemId, ':addedQTY' => $addedQTY, ':addingQTY' => $addedQty));
  51.  
  52. $updateItemsAfterAddition = $db - > prepare("UPDATE items SET QTY = QTY - :addedQTY where id= :iIid");
  53.  
  54. $updateItemsAfterAddition - > execute(array(':iIid' => $ProId, ':addedQTY' => $addedQty));
  55.  
  56.  
  57. }
  58. elseif($subtractedQty > 0) {
  59. $updateInvoiceSubtractedItems = $db - > prepare("UPDATE `invoiceItems` SET
  60. qty = qty - : subtractedQty,
  61. subtractedQty = subtractedQty + : subtractingQty where id = : iiId ");
  62.  
  63. $sub_invoiceItems - > execute(array(':iiId' => $itemId, ':subtractedQty' => $subtractedQty, ':subtractingQty' => $subtractedQty));
  64.  
  65. $updateItemsAfterSubtraction = $db - > prepare("UPDATE Items SET QTY = QTY + :subtractedQTY where id= :iID ");
  66.  
  67. $update_subproducts - > execute(array(':iID' => $itemId, ':subtractedQTY' => $subtractedQty));
  68.  
  69.  
  70. }
  71.  
  72. if ($updateInvoice AND $insertNewItems AND $updateInvoiceAddedItems AND $updateInvoiceSubtractedItems) {
  73. echo ' <script> alert("success") </script>';
  74. exit;
  75.  
  76. } else {
  77. echo ' <script> alert("Error") </script>';
  78. }
  79. } catch (PDOException $e) {
  80. echo 'Connection failed: '.$e - > getMessage();
  81. }
  82. }
  83. }
Add Comment
Please, Sign In to add comment