mirror of https://github.com/itflow-org/itflow
Migrated Edit Line Item to new AJAX modal function, adjusted the logic to determine line item type (invoice, quote, recurring) in the post instead of the form
This commit is contained in:
parent
f920b8fac9
commit
b9f6871bae
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
require_once '../includes/ajax_header.php';
|
||||
|
||||
$item_id = intval($_GET['id']);
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM invoice_items WHERE item_id = $item_id");
|
||||
$row = mysqli_fetch_array($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']);
|
||||
|
||||
// Generate the HTML form content using output buffering.
|
||||
ob_start();
|
||||
?>
|
||||
|
||||
<div class="modal-header">
|
||||
<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="item_id" value="<?php echo $item_id; ?>">
|
||||
|
||||
<div class="modal-body bg-white">
|
||||
<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="numeric" 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="numeric" 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_array($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 bg-white">
|
||||
<button type="submit" name="edit_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/ajax_footer.php";
|
||||
13
invoice.php
13
invoice.php
|
|
@ -398,7 +398,13 @@ if (isset($_GET['invoice_id'])) {
|
|||
<button class="dropdown-item" type="submit" name="update_invoice_item_order" value="down" <?php echo $down_hidden; ?>><i class="fas fa-fw fa-arrow-down mr-2"></i>Move down</button>
|
||||
</form>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#editItemModal<?php echo $item_id; ?>"><i class="fa fa-fw fa-edit mr-2"></i>Edit</a>
|
||||
<a class="dropdown-item" href="#"
|
||||
data-toggle="ajax-modal"
|
||||
data-ajax-url="ajax/ajax_item_edit.php"
|
||||
data-ajax-id="<?php echo $item_id; ?>"
|
||||
>
|
||||
<i class="fa fa-fw fa-edit mr-2"></i>Edit
|
||||
</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item text-danger confirm-link" href="post.php?delete_invoice_item=<?php echo $item_id; ?>"><i class="fa fa-fw fa-trash mr-2"></i>Delete</a>
|
||||
</div>
|
||||
|
|
@ -414,9 +420,6 @@ if (isset($_GET['invoice_id'])) {
|
|||
<td class="text-right"><?php echo numfmt_format_currency($currency_format, $item_total, $invoice_currency_code); ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
if ($invoice_status !== "Paid" && $invoice_status !== "Cancelled") {
|
||||
require "modals/item_edit_modal.php";
|
||||
}
|
||||
}
|
||||
?>
|
||||
<tr class="d-print-none" <?php if ($invoice_status == "Paid" || $invoice_status == "Cancelled") { echo "hidden"; } ?>>
|
||||
|
|
@ -690,7 +693,6 @@ if (isset($_GET['invoice_id'])) {
|
|||
<?php
|
||||
include_once "modals/invoice_add_ticket_modal.php";
|
||||
include_once "modals/invoice_payment_add_modal.php";
|
||||
include_once "modals/invoice_copy_modal.php";
|
||||
include_once "modals/invoice_recurring_add_modal.php";
|
||||
include_once "modals/invoice_note_modal.php";
|
||||
|
||||
|
|
@ -698,7 +700,6 @@ if (isset($_GET['invoice_id'])) {
|
|||
|
||||
require_once "includes/footer.php";
|
||||
|
||||
|
||||
?>
|
||||
|
||||
<!-- JSON Autocomplete / type ahead -->
|
||||
|
|
|
|||
|
|
@ -599,9 +599,6 @@ if (isset($_POST['invoice_note'])) {
|
|||
|
||||
if (isset($_POST['edit_item'])) {
|
||||
|
||||
$invoice_id = intval($_POST['invoice_id']);
|
||||
$quote_id = intval($_POST['quote_id']);
|
||||
$recurring_id = intval($_POST['recurring_id']);
|
||||
$item_id = intval($_POST['item_id']);
|
||||
$name = sanitizeInput($_POST['name']);
|
||||
$description = sanitizeInput($_POST['description']);
|
||||
|
|
@ -624,6 +621,13 @@ if (isset($_POST['edit_item'])) {
|
|||
|
||||
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");
|
||||
|
||||
// Determine what type of line item
|
||||
$sql = mysqli_query($mysqli,"SELECT item_invoice_id, item_quote_id, item_recurring_id FROM invoice_items WHERE item_id = $item_id");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
$invoice_id = intval($row['item_invoice_id']);
|
||||
$quote_id = intval($row['item_quote_id']);
|
||||
$recurring_id = intval($row['item_recurring_id']);
|
||||
|
||||
if ($invoice_id > 0) {
|
||||
//Get Discount Amount
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoices WHERE invoice_id = $invoice_id");
|
||||
|
|
|
|||
|
|
@ -354,7 +354,11 @@ if (isset($_GET['quote_id'])) {
|
|||
<button class="dropdown-item" type="submit" name="update_quote_item_order" value="down" <?php echo $down_hidden; ?>><i class="fa fa-fw fa-arrow-down mr-2"></i>Move Down</button>
|
||||
</form>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#editItemModal<?php echo $item_id; ?>">
|
||||
<a class="dropdown-item" href="#"
|
||||
data-toggle="ajax-modal"
|
||||
data-ajax-url="ajax/ajax_item_edit.php"
|
||||
data-ajax-id="<?php echo $item_id; ?>"
|
||||
>
|
||||
<i class="fa fa-fw fa-edit mr-2"></i>Edit
|
||||
</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
|
|
@ -375,9 +379,6 @@ if (isset($_GET['quote_id'])) {
|
|||
|
||||
<?php
|
||||
|
||||
if ($quote_status !== "Invoiced" && $quote_status !== "Accepted" && $quote_status !== "Declined") {
|
||||
require "modals/item_edit_modal.php";
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -305,7 +305,13 @@ if (isset($_GET['recurring_id'])) {
|
|||
<button class="dropdown-item" type="submit" name="update_recurring_item_order" value="down" <?php echo $down_hidden; ?>><i class="fa fa-fw fa-arrow-down mr-2"></i> Move Down</button>
|
||||
</form>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#editItemModal<?php echo $item_id; ?>"><i class="fa fa-fw fa-edit mr-2"></i>Edit</a>
|
||||
<a class="dropdown-item" href="#"
|
||||
data-toggle="ajax-modal"
|
||||
data-ajax-url="ajax/ajax_item_edit.php"
|
||||
data-ajax-id="<?php echo $item_id; ?>"
|
||||
>
|
||||
<i class="fa fa-fw fa-edit mr-2"></i>Edit
|
||||
</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item text-danger confirm-link" href="post.php?delete_recurring_item=<?php echo $item_id; ?>"><i class="fa fa-fw fa-trash mr-2"></i>Delete</a>
|
||||
|
||||
|
|
@ -323,9 +329,6 @@ if (isset($_GET['recurring_id'])) {
|
|||
|
||||
<?php
|
||||
|
||||
require "modals/item_edit_modal.php";
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
Loading…
Reference in New Issue