mirror of
https://github.com/itflow-org/itflow
synced 2026-03-11 08:14:52 +00:00
Split out item edits into seperate posts and modals for editing invoice, quote and recurring invoice items
This commit is contained in:
@@ -426,7 +426,7 @@ if (isset($_GET['invoice_id'])) {
|
|||||||
</button>
|
</button>
|
||||||
<div class="dropdown-menu">
|
<div class="dropdown-menu">
|
||||||
<a class="dropdown-item ajax-modal" href="#"
|
<a class="dropdown-item ajax-modal" href="#"
|
||||||
data-modal-url="modals/invoice/item_edit.php?id=<?= $item_id ?>">
|
data-modal-url="modals/invoice/invoice_item_edit.php?id=<?= $item_id ?>">
|
||||||
<i class="fa fa-fw fa-edit mr-2"></i>Edit
|
<i class="fa fa-fw fa-edit mr-2"></i>Edit
|
||||||
</a>
|
</a>
|
||||||
<div class="dropdown-divider"></div>
|
<div class="dropdown-divider"></div>
|
||||||
|
|||||||
107
agent/modals/invoice/invoice_item_edit.php
Normal file
107
agent/modals/invoice/invoice_item_edit.php
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once '../../../includes/modal_header.php';
|
||||||
|
|
||||||
|
$item_id = intval($_GET['id']);
|
||||||
|
|
||||||
|
$sql = mysqli_query($mysqli, "SELECT * FROM invoice_items WHERE item_id = $item_id LIMIT 1");
|
||||||
|
$row = mysqli_fetch_assoc($sql);
|
||||||
|
$item_name = nullable_htmlentities($row['item_name']);
|
||||||
|
$item_description = nullable_htmlentities($row['item_description']);
|
||||||
|
$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();
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="modal-header bg-dark">
|
||||||
|
<h5 class="modal-title"><i class="fas fa-fw fa-edit mr-2"></i>Editing Line Item: <strong><?php echo $item_name; ?></strong></h5>
|
||||||
|
<button type="button" class="close text-white" data-dismiss="modal">
|
||||||
|
<span>×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<form action="post.php" method="post" autocomplete="off">
|
||||||
|
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||||
|
<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">
|
||||||
|
<label>Item <strong class="text-danger">*</strong></label>
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-prepend">
|
||||||
|
<span class="input-group-text"><i class="fa fa-fw fa-box"></i></span>
|
||||||
|
</div>
|
||||||
|
<input type="text" class="form-control" name="name" maxlength="200" value="<?php echo $item_name; ?>" placeholder="Enter item name" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="col-sm">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Quantity <strong class="text-danger">*</strong></label>
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-prepend">
|
||||||
|
<span class="input-group-text"><i class="fa fa-fw fa-balance-scale"></i></span>
|
||||||
|
</div>
|
||||||
|
<input type="text" class="form-control" inputmode="decimal" pattern="[0-9]*\.?[0-9]{0,2}" name="qty" value="<?php echo number_format($item_quantity, 2); ?>" placeholder="0.00" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-sm">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Price <strong class="text-danger">*</strong></label>
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-prepend">
|
||||||
|
<span class="input-group-text"><i class="fa fa-fw fa-dollar-sign"></i></span>
|
||||||
|
</div>
|
||||||
|
<input type="text" class="form-control" inputmode="decimal" pattern="-?[0-9]*\.?[0-9]{0,2}" name="price" value="<?php echo number_format($item_price, 2, '.', ''); ?>" placeholder="0.00" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Description</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<textarea class="form-control" rows="5" name="description" placeholder="Enter a description"><?php echo $item_description; ?></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Tax <strong class="text-danger">*</strong></label>
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-prepend">
|
||||||
|
<span class="input-group-text"><i class="fa fa-fw fa-piggy-bank"></i></span>
|
||||||
|
</div>
|
||||||
|
<select class="form-control select2" name="tax_id" required>
|
||||||
|
<option value="0">No Tax</option>
|
||||||
|
<?php
|
||||||
|
$taxes_sql = mysqli_query($mysqli, "SELECT * FROM taxes WHERE (tax_archived_at > '$item_created_at' OR tax_archived_at IS NULL) ORDER BY tax_name ASC");
|
||||||
|
while ($row = mysqli_fetch_assoc($taxes_sql)) {
|
||||||
|
$tax_id_select = intval($row['tax_id']);
|
||||||
|
$tax_name = nullable_htmlentities($row['tax_name']);
|
||||||
|
$tax_percent = floatval($row['tax_percent']);
|
||||||
|
?>
|
||||||
|
<option <?php if ($tax_id_select == $tax_id) { echo "selected"; } ?> value="<?php echo $tax_id_select; ?>"><?php echo "$tax_name $tax_percent%"; ?></option>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="submit" name="edit_invoice_item" class="btn btn-primary text-bold"><i class="fas fa-check mr-2"></i>Save</button>
|
||||||
|
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fas fa-times mr-2"></i>Cancel</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
require_once '../../../includes/modal_footer.php';
|
||||||
@@ -98,7 +98,7 @@ ob_start();
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="submit" name="edit_item" class="btn btn-primary text-bold"><i class="fas fa-check mr-2"></i>Save</button>
|
<button type="submit" name="edit_quote_item" class="btn btn-primary text-bold"><i class="fas fa-check mr-2"></i>Save</button>
|
||||||
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fas fa-times mr-2"></i>Cancel</button>
|
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fas fa-times mr-2"></i>Cancel</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
107
agent/modals/recurring_invoice/recurring_invoice_item_edit.php
Normal file
107
agent/modals/recurring_invoice/recurring_invoice_item_edit.php
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once '../../../includes/modal_header.php';
|
||||||
|
|
||||||
|
$item_id = intval($_GET['id']);
|
||||||
|
|
||||||
|
$sql = mysqli_query($mysqli, "SELECT * FROM invoice_items WHERE item_id = $item_id LIMIT 1");
|
||||||
|
$row = mysqli_fetch_assoc($sql);
|
||||||
|
$item_name = nullable_htmlentities($row['item_name']);
|
||||||
|
$item_description = nullable_htmlentities($row['item_description']);
|
||||||
|
$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();
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="modal-header bg-dark">
|
||||||
|
<h5 class="modal-title"><i class="fas fa-fw fa-edit mr-2"></i>Editing Line Item: <strong><?php echo $item_name; ?></strong></h5>
|
||||||
|
<button type="button" class="close text-white" data-dismiss="modal">
|
||||||
|
<span>×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<form action="post.php" method="post" autocomplete="off">
|
||||||
|
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||||
|
<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">
|
||||||
|
<label>Item <strong class="text-danger">*</strong></label>
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-prepend">
|
||||||
|
<span class="input-group-text"><i class="fa fa-fw fa-box"></i></span>
|
||||||
|
</div>
|
||||||
|
<input type="text" class="form-control" name="name" maxlength="200" value="<?php echo $item_name; ?>" placeholder="Enter item name" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="col-sm">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Quantity <strong class="text-danger">*</strong></label>
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-prepend">
|
||||||
|
<span class="input-group-text"><i class="fa fa-fw fa-balance-scale"></i></span>
|
||||||
|
</div>
|
||||||
|
<input type="text" class="form-control" inputmode="decimal" pattern="[0-9]*\.?[0-9]{0,2}" name="qty" value="<?php echo number_format($item_quantity, 2); ?>" placeholder="0.00" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-sm">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Price <strong class="text-danger">*</strong></label>
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-prepend">
|
||||||
|
<span class="input-group-text"><i class="fa fa-fw fa-dollar-sign"></i></span>
|
||||||
|
</div>
|
||||||
|
<input type="text" class="form-control" inputmode="decimal" pattern="-?[0-9]*\.?[0-9]{0,2}" name="price" value="<?php echo number_format($item_price, 2, '.', ''); ?>" placeholder="0.00" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Description</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<textarea class="form-control" rows="5" name="description" placeholder="Enter a description"><?php echo $item_description; ?></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Tax <strong class="text-danger">*</strong></label>
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-prepend">
|
||||||
|
<span class="input-group-text"><i class="fa fa-fw fa-piggy-bank"></i></span>
|
||||||
|
</div>
|
||||||
|
<select class="form-control select2" name="tax_id" required>
|
||||||
|
<option value="0">No Tax</option>
|
||||||
|
<?php
|
||||||
|
$taxes_sql = mysqli_query($mysqli, "SELECT * FROM taxes WHERE (tax_archived_at > '$item_created_at' OR tax_archived_at IS NULL) ORDER BY tax_name ASC");
|
||||||
|
while ($row = mysqli_fetch_assoc($taxes_sql)) {
|
||||||
|
$tax_id_select = intval($row['tax_id']);
|
||||||
|
$tax_name = nullable_htmlentities($row['tax_name']);
|
||||||
|
$tax_percent = floatval($row['tax_percent']);
|
||||||
|
?>
|
||||||
|
<option <?php if ($tax_id_select == $tax_id) { echo "selected"; } ?> value="<?php echo $tax_id_select; ?>"><?php echo "$tax_name $tax_percent%"; ?></option>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="submit" name="edit_recurring_invoice_item" class="btn btn-primary text-bold"><i class="fas fa-check mr-2"></i>Save</button>
|
||||||
|
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fas fa-times mr-2"></i>Cancel</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
require_once '../../../includes/modal_footer.php';
|
||||||
@@ -418,7 +418,7 @@ if (isset($_POST['invoice_note'])) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_POST['edit_item'])) {
|
if (isset($_POST['edit_invoice_item'])) {
|
||||||
|
|
||||||
validateCSRFToken($_POST['csrf_token']);
|
validateCSRFToken($_POST['csrf_token']);
|
||||||
|
|
||||||
@@ -446,13 +446,10 @@ if (isset($_POST['edit_item'])) {
|
|||||||
$total = $subtotal + $tax_amount;
|
$total = $subtotal + $tax_amount;
|
||||||
|
|
||||||
// Determine what type of line item
|
// Determine what type of line item
|
||||||
$sql = mysqli_query($mysqli,"SELECT item_invoice_id, item_quote_id, item_recurring_invoice_id FROM invoice_items WHERE item_id = $item_id");
|
$sql = mysqli_query($mysqli,"SELECT item_invoice_id FROM invoice_items WHERE item_id = $item_id");
|
||||||
$row = mysqli_fetch_assoc($sql);
|
$row = mysqli_fetch_assoc($sql);
|
||||||
$invoice_id = intval($row['item_invoice_id']);
|
$invoice_id = intval($row['item_invoice_id']);
|
||||||
$quote_id = intval($row['item_quote_id']);
|
|
||||||
$recurring_invoice_id = intval($row['item_recurring_invoice_id']);
|
|
||||||
|
|
||||||
if ($invoice_id) {
|
|
||||||
//Get Discount Amount
|
//Get Discount Amount
|
||||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoices WHERE invoice_id = $invoice_id");
|
$sql = mysqli_query($mysqli,"SELECT * FROM invoices WHERE invoice_id = $invoice_id");
|
||||||
$row = mysqli_fetch_assoc($sql);
|
$row = mysqli_fetch_assoc($sql);
|
||||||
@@ -460,30 +457,11 @@ if (isset($_POST['edit_item'])) {
|
|||||||
$invoice_number = intval($row['invoice_number']);
|
$invoice_number = intval($row['invoice_number']);
|
||||||
$client_id = intval($row['invoice_client_id']);
|
$client_id = intval($row['invoice_client_id']);
|
||||||
$invoice_discount = floatval($row['invoice_discount_amount']);
|
$invoice_discount = floatval($row['invoice_discount_amount']);
|
||||||
|
|
||||||
enforceClientAccess();
|
enforceClientAccess();
|
||||||
} elseif ($quote_id) {
|
|
||||||
//Get Discount Amount
|
|
||||||
$sql = mysqli_query($mysqli,"SELECT * FROM quotes WHERE quote_id = $quote_id");
|
|
||||||
$row = mysqli_fetch_assoc($sql);
|
|
||||||
$quote_prefix = sanitizeInput($row['quote_prefix']);
|
|
||||||
$quote_number = intval($row['quote_number']);
|
|
||||||
$client_id = intval($row['quote_client_id']);
|
|
||||||
$quote_discount = floatval($row['quote_discount_amount']);
|
|
||||||
enforceClientAccess();
|
|
||||||
} else {
|
|
||||||
//Get Discount Amount
|
|
||||||
$sql = mysqli_query($mysqli,"SELECT * FROM recurring_invoices WHERE recurring_invoice_id = $recurring_invoice_id");
|
|
||||||
$row = mysqli_fetch_assoc($sql);
|
|
||||||
$recurring_invoice_prefix = sanitizeInput($row['recurring_invoice_prefix']);
|
|
||||||
$recurring_invoice_number = intval($row['recurring_invoice_number']);
|
|
||||||
$client_id = intval($row['recurring_invoice_client_id']);
|
|
||||||
$recurring_invoice_discount = floatval($row['recurring_invoice_discount_amount']);
|
|
||||||
enforceClientAccess();
|
|
||||||
}
|
|
||||||
|
|
||||||
mysqli_query($mysqli,"UPDATE 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_tax_id = $tax_id WHERE item_id = $item_id");
|
mysqli_query($mysqli,"UPDATE 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_tax_id = $tax_id WHERE item_id = $item_id");
|
||||||
|
|
||||||
if ($invoice_id) {
|
|
||||||
//Update Invoice Balances by tallying up invoice items
|
//Update Invoice Balances by tallying up invoice items
|
||||||
$sql_invoice_total = mysqli_query($mysqli,"SELECT SUM(item_total) AS invoice_total FROM invoice_items WHERE item_invoice_id = $invoice_id");
|
$sql_invoice_total = mysqli_query($mysqli,"SELECT SUM(item_total) AS invoice_total FROM invoice_items WHERE item_invoice_id = $invoice_id");
|
||||||
$row = mysqli_fetch_assoc($sql_invoice_total);
|
$row = mysqli_fetch_assoc($sql_invoice_total);
|
||||||
@@ -493,29 +471,6 @@ if (isset($_POST['edit_item'])) {
|
|||||||
|
|
||||||
logAction("Invoice", "Edit", "$session_name edited item $name on invoice $invoice_prefix$invoice_number", $client_id, $invoice_id);
|
logAction("Invoice", "Edit", "$session_name edited item $name on invoice $invoice_prefix$invoice_number", $client_id, $invoice_id);
|
||||||
|
|
||||||
} elseif ($quote_id) {
|
|
||||||
//Update Quote Balances by tallying up items
|
|
||||||
$sql_quote_total = mysqli_query($mysqli,"SELECT SUM(item_total) AS quote_total FROM invoice_items WHERE item_quote_id = $quote_id");
|
|
||||||
$row = mysqli_fetch_assoc($sql_quote_total);
|
|
||||||
$new_quote_amount = floatval($row['quote_total']) - $quote_discount;
|
|
||||||
|
|
||||||
mysqli_query($mysqli,"UPDATE quotes SET quote_amount = $new_quote_amount WHERE quote_id = $quote_id");
|
|
||||||
|
|
||||||
logAction("Quote", "Edit", "$session_name edited item $name on quote $quote_prefix$quote_number", $client_id, $quote_id);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
//Update Invoice Balances by tallying up invoice items
|
|
||||||
$sql_recurring_invoice_total = mysqli_query($mysqli,"SELECT SUM(item_total) AS recurring_invoice_total FROM invoice_items WHERE item_recurring_invoice_id = $recurring_invoice_id");
|
|
||||||
$row = mysqli_fetch_assoc($sql_recurring_invoice_total);
|
|
||||||
$new_recurring_invoice_amount = floatval($row['recurring_invoice_total']) - $recurring_invoice_discount;
|
|
||||||
|
|
||||||
mysqli_query($mysqli,"UPDATE recurring_invoices SET recurring_invoice_amount = $new_recurring_invoice_amount WHERE recurring_invoice_id = $recurring_invoice_id");
|
|
||||||
|
|
||||||
// Logging
|
|
||||||
logAction("Recurring Invoice", "Edit", "$session_name edited item $name on recurring invoice $recurring_invoice_prefix$recurring_invoice_number", $client_id, $recurring_invoice_id);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
flash_alert("Item <strong>$name</strong> updated");
|
flash_alert("Item <strong>$name</strong> updated");
|
||||||
|
|
||||||
redirect();
|
redirect();
|
||||||
|
|||||||
@@ -273,6 +273,65 @@ if (isset($_POST['add_quote_item'])) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($_POST['edit_quote_item'])) {
|
||||||
|
|
||||||
|
validateCSRFToken($_POST['csrf_token']);
|
||||||
|
|
||||||
|
enforceUserPermission('module_sales', 2);
|
||||||
|
|
||||||
|
$item_id = intval($_POST['item_id']);
|
||||||
|
$name = sanitizeInput($_POST['name']);
|
||||||
|
$description = sanitizeInput($_POST['description']);
|
||||||
|
$qty = floatval($_POST['qty']);
|
||||||
|
$price = floatval($_POST['price']);
|
||||||
|
$tax_id = intval($_POST['tax_id']);
|
||||||
|
$product_id = intval($_POST['product_id']);
|
||||||
|
|
||||||
|
$subtotal = $price * $qty;
|
||||||
|
|
||||||
|
if ($tax_id > 0) {
|
||||||
|
$sql = mysqli_query($mysqli,"SELECT * FROM taxes WHERE tax_id = $tax_id");
|
||||||
|
$row = mysqli_fetch_assoc($sql);
|
||||||
|
$tax_percent = floatval($row['tax_percent']);
|
||||||
|
$tax_amount = $subtotal * $tax_percent / 100;
|
||||||
|
} else {
|
||||||
|
$tax_amount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$total = $subtotal + $tax_amount;
|
||||||
|
|
||||||
|
// Get Quote ID from Item ID
|
||||||
|
$sql = mysqli_query($mysqli,"SELECT item_quote_id FROM invoice_items WHERE item_id = $item_id");
|
||||||
|
$row = mysqli_fetch_assoc($sql);
|
||||||
|
$quote_id = intval($row['item_quote_id']);
|
||||||
|
|
||||||
|
//Get Discount Amount
|
||||||
|
$sql = mysqli_query($mysqli,"SELECT * FROM quotes WHERE quote_id = $quote_id");
|
||||||
|
$row = mysqli_fetch_assoc($sql);
|
||||||
|
$quote_prefix = sanitizeInput($row['quote_prefix']);
|
||||||
|
$quote_number = intval($row['quote_number']);
|
||||||
|
$client_id = intval($row['quote_client_id']);
|
||||||
|
$quote_discount = floatval($row['quote_discount_amount']);
|
||||||
|
|
||||||
|
enforceClientAccess();
|
||||||
|
|
||||||
|
mysqli_query($mysqli,"UPDATE 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_tax_id = $tax_id WHERE item_id = $item_id");
|
||||||
|
|
||||||
|
//Update Quote Balances by tallying up items
|
||||||
|
$sql_quote_total = mysqli_query($mysqli,"SELECT SUM(item_total) AS quote_total FROM invoice_items WHERE item_quote_id = $quote_id");
|
||||||
|
$row = mysqli_fetch_assoc($sql_quote_total);
|
||||||
|
$new_quote_amount = floatval($row['quote_total']) - $quote_discount;
|
||||||
|
|
||||||
|
mysqli_query($mysqli,"UPDATE quotes SET quote_amount = $new_quote_amount WHERE quote_id = $quote_id");
|
||||||
|
|
||||||
|
logAction("Quote", "Edit", "$session_name edited item $name on quote $quote_prefix$quote_number", $client_id, $quote_id);
|
||||||
|
|
||||||
|
flash_alert("Item <strong>$name</strong> updated");
|
||||||
|
|
||||||
|
redirect();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($_POST['quote_note'])) {
|
if (isset($_POST['quote_note'])) {
|
||||||
|
|
||||||
validateCSRFToken($_POST['csrf_token']);
|
validateCSRFToken($_POST['csrf_token']);
|
||||||
|
|||||||
@@ -255,6 +255,66 @@ if (isset($_POST['add_recurring_invoice_item'])) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($_POST['edit_recurring_invoice_item'])) {
|
||||||
|
|
||||||
|
validateCSRFToken($_POST['csrf_token']);
|
||||||
|
|
||||||
|
enforceUserPermission('module_sales', 2);
|
||||||
|
|
||||||
|
$item_id = intval($_POST['item_id']);
|
||||||
|
$name = sanitizeInput($_POST['name']);
|
||||||
|
$description = sanitizeInput($_POST['description']);
|
||||||
|
$qty = floatval($_POST['qty']);
|
||||||
|
$price = floatval($_POST['price']);
|
||||||
|
$tax_id = intval($_POST['tax_id']);
|
||||||
|
$product_id = intval($_POST['product_id']);
|
||||||
|
|
||||||
|
$subtotal = $price * $qty;
|
||||||
|
|
||||||
|
if ($tax_id > 0) {
|
||||||
|
$sql = mysqli_query($mysqli,"SELECT * FROM taxes WHERE tax_id = $tax_id");
|
||||||
|
$row = mysqli_fetch_assoc($sql);
|
||||||
|
$tax_percent = floatval($row['tax_percent']);
|
||||||
|
$tax_amount = $subtotal * $tax_percent / 100;
|
||||||
|
} else {
|
||||||
|
$tax_amount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$total = $subtotal + $tax_amount;
|
||||||
|
|
||||||
|
// Get Recurring_invoice_id from item_id
|
||||||
|
$sql = mysqli_query($mysqli,"SELECT item_recurring_invoice_id FROM invoice_items WHERE item_id = $item_id");
|
||||||
|
$row = mysqli_fetch_assoc($sql);
|
||||||
|
$recurring_invoice_id = intval($row['item_recurring_invoice_id']);
|
||||||
|
|
||||||
|
//Get Discount Amount
|
||||||
|
$sql = mysqli_query($mysqli,"SELECT * FROM recurring_invoices WHERE recurring_invoice_id = $recurring_invoice_id");
|
||||||
|
$row = mysqli_fetch_assoc($sql);
|
||||||
|
$recurring_invoice_prefix = sanitizeInput($row['recurring_invoice_prefix']);
|
||||||
|
$recurring_invoice_number = intval($row['recurring_invoice_number']);
|
||||||
|
$client_id = intval($row['recurring_invoice_client_id']);
|
||||||
|
$recurring_invoice_discount = floatval($row['recurring_invoice_discount_amount']);
|
||||||
|
|
||||||
|
enforceClientAccess();
|
||||||
|
|
||||||
|
mysqli_query($mysqli,"UPDATE 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_tax_id = $tax_id WHERE item_id = $item_id");
|
||||||
|
|
||||||
|
//Update Invoice Balances by tallying up invoice items
|
||||||
|
$sql_recurring_invoice_total = mysqli_query($mysqli,"SELECT SUM(item_total) AS recurring_invoice_total FROM invoice_items WHERE item_recurring_invoice_id = $recurring_invoice_id");
|
||||||
|
$row = mysqli_fetch_assoc($sql_recurring_invoice_total);
|
||||||
|
$new_recurring_invoice_amount = floatval($row['recurring_invoice_total']) - $recurring_invoice_discount;
|
||||||
|
|
||||||
|
mysqli_query($mysqli,"UPDATE recurring_invoices SET recurring_invoice_amount = $new_recurring_invoice_amount WHERE recurring_invoice_id = $recurring_invoice_id");
|
||||||
|
|
||||||
|
// Logging
|
||||||
|
logAction("Recurring Invoice", "Edit", "$session_name edited item $name on recurring invoice $recurring_invoice_prefix$recurring_invoice_number", $client_id, $recurring_invoice_id);
|
||||||
|
|
||||||
|
flash_alert("Item <strong>$name</strong> updated");
|
||||||
|
|
||||||
|
redirect();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($_POST['recurring_invoice_note'])) {
|
if (isset($_POST['recurring_invoice_note'])) {
|
||||||
|
|
||||||
validateCSRFToken($_POST['csrf_token']);
|
validateCSRFToken($_POST['csrf_token']);
|
||||||
|
|||||||
@@ -337,7 +337,7 @@ if (isset($_GET['quote_id'])) {
|
|||||||
</button>
|
</button>
|
||||||
<div class="dropdown-menu">
|
<div class="dropdown-menu">
|
||||||
<a class="dropdown-item ajax-modal" href="#"
|
<a class="dropdown-item ajax-modal" href="#"
|
||||||
data-modal-url="modals/invoice/item_edit.php?id=<?= $item_id ?>">
|
data-modal-url="modals/quote/quote_item_edit.php?id=<?= $item_id ?>">
|
||||||
<i class="fa fa-fw fa-edit mr-2"></i>Edit
|
<i class="fa fa-fw fa-edit mr-2"></i>Edit
|
||||||
</a>
|
</a>
|
||||||
<div class="dropdown-divider"></div>
|
<div class="dropdown-divider"></div>
|
||||||
|
|||||||
@@ -300,7 +300,7 @@ if (isset($_GET['recurring_invoice_id'])) {
|
|||||||
</button>
|
</button>
|
||||||
<div class="dropdown-menu">
|
<div class="dropdown-menu">
|
||||||
<a class="dropdown-item ajax-modal" href="#"
|
<a class="dropdown-item ajax-modal" href="#"
|
||||||
data-modal-url="modals/invoice/item_edit.php?id=<?= $item_id ?>">
|
data-modal-url="modals/recurring_invoice/recurring_invoice_item_edit.php?id=<?= $item_id ?>">
|
||||||
<i class="fa fa-fw fa-edit mr-2"></i>Edit
|
<i class="fa fa-fw fa-edit mr-2"></i>Edit
|
||||||
</a>
|
</a>
|
||||||
<div class="dropdown-divider"></div>
|
<div class="dropdown-divider"></div>
|
||||||
|
|||||||
Reference in New Issue
Block a user