mirror of https://github.com/itflow-org/itflow
Remove Stock if Inventory item is selected and added to an invoice and return stock when Invoice Item related to a product is deleted
This commit is contained in:
parent
890e166d1c
commit
535c8e9f7b
|
|
@ -12,6 +12,7 @@ $item_quantity = floatval($row['item_quantity']);
|
|||
$item_price = floatval($row['item_price']);
|
||||
$item_created_at = nullable_htmlentities($row['item_created_at']);
|
||||
$tax_id = intval($row['item_tax_id']);
|
||||
$product_id = intval($row['item_product_id']);
|
||||
|
||||
// Generate the HTML form content using output buffering.
|
||||
ob_start();
|
||||
|
|
@ -25,6 +26,7 @@ ob_start();
|
|||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="item_id" value="<?php echo $item_id; ?>">
|
||||
<input type="hidden" name="product_id" value="<?php echo $product_id; ?>">
|
||||
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ if (isset($_GET['invoice_id'])) {
|
|||
$invoice_badge_color = getInvoiceBadgeColor($invoice_status);
|
||||
|
||||
//Product autocomplete
|
||||
$products_sql = mysqli_query($mysqli, "SELECT product_name AS label, product_description AS description, product_price AS price, product_tax_id AS tax FROM products WHERE product_archived_at IS NULL");
|
||||
$products_sql = mysqli_query($mysqli, "SELECT product_name AS label, product_description AS description, product_price AS price, product_tax_id AS tax, product_id AS prod_id FROM products WHERE product_archived_at IS NULL");
|
||||
|
||||
if (mysqli_num_rows($products_sql) > 0) {
|
||||
while ($row = mysqli_fetch_array($products_sql)) {
|
||||
|
|
@ -431,6 +431,7 @@ if (isset($_GET['invoice_id'])) {
|
|||
$item_total = floatval($row['item_total']);
|
||||
$item_created_at = nullable_htmlentities($row['item_created_at']);
|
||||
$tax_id = intval($row['item_tax_id']);
|
||||
$item_product_id = intval($row['item_product_id']);
|
||||
$total_tax = $item_tax + $total_tax;
|
||||
$sub_total = $item_price * $item_quantity + $sub_total;
|
||||
?>
|
||||
|
|
@ -475,7 +476,8 @@ if (isset($_GET['invoice_id'])) {
|
|||
?>
|
||||
<tr class="d-print-none" <?php if ($invoice_status == "Paid" || $invoice_status == "Cancelled" || lookupUserPermission("module_sales") <= 1) { echo "hidden"; } ?>>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="invoice_id" value="<?php echo $invoice_id; ?>">
|
||||
<input type="hidden" name="invoice_id" value="<?= $invoice_id ?>">
|
||||
<input type="hidden" id="product_id" name="product_id" value="<?= $item_product_id ?>">
|
||||
<input type="hidden" name="item_order" value="<?php echo mysqli_num_rows($sql_invoice_items) + 1; ?>">
|
||||
<td></td>
|
||||
<td>
|
||||
|
|
@ -778,6 +780,7 @@ require_once "../includes/footer.php";
|
|||
$("#qty").val(1); // Product quantity field automatically make it a 1
|
||||
$("#price").val(ui.item.price); // Product price field
|
||||
$("#tax").val(ui.item.tax); // Product tax field
|
||||
$("#product_id").val(ui.item.prod_id); // Product ID field
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -518,9 +518,16 @@ if (isset($_POST['add_invoice_item'])) {
|
|||
$price = floatval($_POST['price']);
|
||||
$tax_id = intval($_POST['tax_id']);
|
||||
$item_order = intval($_POST['item_order']);
|
||||
$product_id = intval($_POST['product_id']);
|
||||
|
||||
$subtotal = $price * $qty;
|
||||
|
||||
// Update Product Inventory
|
||||
if ($product_id) {
|
||||
mysqli_query($mysqli,"INSERT INTO product_stock SET stock_qty = -$qty, stock_note = 'QTY $qty - Invoice $invoice_id', stock_product_id = $product_id");
|
||||
}
|
||||
|
||||
// Tax
|
||||
if ($tax_id > 0) {
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM taxes WHERE tax_id = $tax_id");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
|
|
@ -532,7 +539,7 @@ if (isset($_POST['add_invoice_item'])) {
|
|||
|
||||
$total = $subtotal + $tax_amount;
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO invoice_items SET item_name = '$name', item_description = '$description', item_quantity = $qty, item_price = $price, item_subtotal = $subtotal, item_tax = $tax_amount, item_total = $total, item_order = $item_order, item_tax_id = $tax_id, item_invoice_id = $invoice_id");
|
||||
mysqli_query($mysqli,"INSERT INTO invoice_items SET item_name = '$name', item_description = '$description', item_quantity = $qty, item_price = $price, item_subtotal = $subtotal, item_tax = $tax_amount, item_total = $total, item_order = $item_order, item_tax_id = $tax_id, item_product_id = $product_id, item_invoice_id = $invoice_id");
|
||||
|
||||
// Get Discount and Invoice Details
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoices WHERE invoice_id = $invoice_id");
|
||||
|
|
@ -691,6 +698,8 @@ if (isset($_GET['delete_invoice_item'])) {
|
|||
$row = mysqli_fetch_array($sql);
|
||||
$invoice_id = intval($row['item_invoice_id']);
|
||||
$item_name = sanitizeInput($row['item_name']);
|
||||
$item_quantity = floatval($row['item_quantity']);
|
||||
$item_product_id = intval($row['item_product_id']);
|
||||
$item_subtotal = floatval($row['item_subtotal']);
|
||||
$item_tax = floatval($row['item_tax']);
|
||||
$item_total = floatval($row['item_total']);
|
||||
|
|
@ -707,6 +716,11 @@ if (isset($_GET['delete_invoice_item'])) {
|
|||
|
||||
mysqli_query($mysqli,"DELETE FROM invoice_items WHERE item_id = $item_id");
|
||||
|
||||
// Return Product Inventory
|
||||
if ($item_product_id) {
|
||||
mysqli_query($mysqli,"INSERT INTO product_stock SET stock_qty = $item_quantity, stock_note = 'Returned QTY $item_quantity back to stock from Invoice $invoice_id', stock_product_id = $item_product_id");
|
||||
}
|
||||
|
||||
logAction("Invoice", "Delete", "$session_name removed item $item_name from invoice $invoice_prefix$invoice_number", $client_id, $invoice_id);
|
||||
|
||||
flash_alert("Item <strong>$item_name</strong> removed from invoice", 'error');
|
||||
|
|
|
|||
Loading…
Reference in New Issue