Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (isset($_POST['submit'])) {
- $invoiceId = $_POST['invoiceId'];
- $client = $_POST['Client'];
- $address = $_POST['Address'];
- $Date = $_POST['Date'];
- $suBTotal = $_POST['subTotal'];
- foreach($_POST['data'] as $key => $value) {
- $invoiceItemId = intval($value['invoiceItemId']);
- $itemId = intval($value['ItemId']);
- $item = strip_tags(trim(strval($value['item'])));
- $QTY = intval($value['QTY']);
- $addedQTY = intval($value['addedQTY']);
- $subtractedQty = intval($value['subtractedQty']);
- $Price = is_numeric($value['price']) ? $value['price'] : false;
- $Total = is_numeric($value['total']) ? $value['total'] : false;
- try {
- $updateInvoice = $db - > prepare(" UPDATE `invoices` SET
- client = : client,
- Address = : Address,
- Date = : Date,
- subTotal = : subTotal WHERE `invoiceId` = : invoiceId ");
- $updateInvoice - > bindparam(':client', $client); $updateInvoice - > bindparam(':Address', $address); $updateInvoice - > bindparam(':Date', $Date); $updateInvoice - > bindparam(':subTotal', $suBTotal); $updateInvoice - > bindparam(':invoiceId', $invoiceId);
- $invoiceUpdate = $updateInvoice - > execute();
- if ($invoiceItemId === 0) {
- $insertNewItems = $db - > prepare(" INSERT INTO `invoiceItems` (`invoiceId`,`ItemId`,`Item`,`qty`,`Price`,`Total`)
- values(: invoiceId, : ItemId, : item, : qty, : Price, : Total)
- ");
- $insertNewItems - > execute(array(':invoiceId' => $invoiceId, ':ItemId' => $itemId, ':item' => $item, ':qty' => $QTY, ':Price' => $Price, ':Total' => $Total));
- $updateItems = $db - > prepare("UPDATE items SET QTY = QTY - :QTY where id= :iId ");
- $updateItems - > execute(array(':iId' => $itemId, ':QTY' => $QTY));
- }
- elseif($addedQTY > 0) {
- $updateInvoiceAddedItems = $db - > prepare("UPDATE `invoiceItems` SET
- qty = qty + : addedQTY,
- addedQty = addedQty + : addingQTY where id = : Iid ");
- $updateInvoiceAddedItems - > execute(array(':Iid' => $itemId, ':addedQTY' => $addedQTY, ':addingQTY' => $addedQty));
- $updateItemsAfterAddition = $db - > prepare("UPDATE items SET QTY = QTY - :addedQTY where id= :iIid");
- $updateItemsAfterAddition - > execute(array(':iIid' => $ProId, ':addedQTY' => $addedQty));
- }
- elseif($subtractedQty > 0) {
- $updateInvoiceSubtractedItems = $db - > prepare("UPDATE `invoiceItems` SET
- qty = qty - : subtractedQty,
- subtractedQty = subtractedQty + : subtractingQty where id = : iiId ");
- $sub_invoiceItems - > execute(array(':iiId' => $itemId, ':subtractedQty' => $subtractedQty, ':subtractingQty' => $subtractedQty));
- $updateItemsAfterSubtraction = $db - > prepare("UPDATE Items SET QTY = QTY + :subtractedQTY where id= :iID ");
- $update_subproducts - > execute(array(':iID' => $itemId, ':subtractedQTY' => $subtractedQty));
- }
- if ($updateInvoice AND $insertNewItems AND $updateInvoiceAddedItems AND $updateInvoiceSubtractedItems) {
- echo ' <script> alert("success") </script>';
- exit;
- } else {
- echo ' <script> alert("Error") </script>';
- }
- } catch (PDOException $e) {
- echo 'Connection failed: '.$e - > getMessage();
- }
- }
- }
Add Comment
Please, Sign In to add comment