mirror of https://github.com/itflow-org/itflow
Combined edit invoice, quote and recurring item into 1 edit item
This commit is contained in:
parent
3c63dfe7e0
commit
4a291486ce
|
|
@ -1,4 +1,4 @@
|
|||
<div class="modal" id="editInvoiceItemModal<?php echo $item_id; ?>" tabindex="-1">
|
||||
<div class="modal" id="editItemModal<?php echo $item_id; ?>" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content bg-dark">
|
||||
<div class="modal-header">
|
||||
|
|
@ -8,7 +8,14 @@
|
|||
</button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="invoice_id" value="<?php echo $invoice_id; ?>">
|
||||
<?php if(isset($invoice_id)){ ?>
|
||||
<input type="hidden" name="invoice_id" value="<?php echo $invoice_id; ?>">
|
||||
<?php }elseif(isset($quote_id)){ ?>
|
||||
<input type="hidden" name="quote_id" value="<?php echo $quote_id; ?>">
|
||||
<?php }else{ ?>
|
||||
<input type="hidden" name="recurring_id" value="<?php echo $recurring_id; ?>">
|
||||
<?php } ?>
|
||||
|
||||
<input type="hidden" name="item_id" value="<?php echo $item_id; ?>">
|
||||
<div class="modal-body bg-white">
|
||||
|
||||
|
|
@ -89,7 +96,7 @@
|
|||
</div>
|
||||
<div class="modal-footer bg-white">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
|
||||
<button type="submit" name="edit_invoice_item" class="btn btn-primary">Save</button>
|
||||
<button type="submit" name="edit_item" class="btn btn-primary">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
<div class="modal" id="editQuoteItemModal<?php echo $item_id; ?>" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content bg-dark">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-edit mr-2"></i>Edit Line Item: <?php echo $item_name; ?></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="quote_id" value="<?php echo $quote_id; ?>">
|
||||
<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" value="<?php echo $item_name; ?>" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Description</label>
|
||||
<div class="input-group">
|
||||
<textarea class="form-control" rows="5" name="description"><?php echo $item_description; ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
|
||||
<div class="col">
|
||||
|
||||
<div class="form-group">
|
||||
<label>QTY <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="number" class="form-control" step="0.01" min="0" name="qty" value="<?php echo $item_quantity; ?>" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="col">
|
||||
|
||||
<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="number" class="form-control" step="0.01" min="0" name="price" value="<?php echo $item_price; ?>" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</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">None</option>
|
||||
<?php
|
||||
|
||||
$taxes_sql = mysqli_query($mysqli,"SELECT * FROM taxes WHERE (tax_archived_at > '$item_created_at' OR tax_archived_at IS NULL) AND company_id = $session_company_id ORDER BY tax_name ASC");
|
||||
while($row = mysqli_fetch_array($taxes_sql)){
|
||||
$tax_id_select = $row['tax_id'];
|
||||
$tax_name = $row['tax_name'];
|
||||
$tax_percent = $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="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
|
||||
<button type="submit" name="edit_quote_item" class="btn btn-primary">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
<div class="modal" id="editRecurringItemModal<?php echo $item_id; ?>" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content bg-dark">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-edit"></i> Edit Line Item: <?php echo $item_name; ?></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="recurring_id" value="<?php echo $recurring_id; ?>">
|
||||
<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" value="<?php echo $item_name; ?>" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Description</label>
|
||||
<div class="input-group">
|
||||
<textarea class="form-control" rows="5" name="description"><?php echo $item_description; ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
|
||||
<div class="col">
|
||||
|
||||
<div class="form-group">
|
||||
<label>QTY <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="number" class="form-control" step="0.01" min="0" name="qty" value="<?php echo $item_quantity; ?>" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="col">
|
||||
|
||||
<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="number" class="form-control" step="0.01" min="0" name="price" value="<?php echo $item_price; ?>" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</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.00">None</option>
|
||||
<?php
|
||||
|
||||
$taxes_sql = mysqli_query($mysqli,"SELECT * FROM taxes WHERE (tax_archived_at > '$item_created_at' OR tax_archived_at IS NULL) AND company_id = $session_company_id ORDER BY tax_name ASC");
|
||||
while($row = mysqli_fetch_array($taxes_sql)){
|
||||
$tax_id_select = $row['tax_id'];
|
||||
$tax_name = $row['tax_name'];
|
||||
$tax_percent = $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="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
|
||||
<button type="submit" name="edit_recurring_item" class="btn btn-primary">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -260,7 +260,7 @@ if(isset($_GET['invoice_id'])){
|
|||
|
||||
<tr>
|
||||
<td class="text-center d-print-none">
|
||||
<a class="text-secondary" href="#" data-toggle="modal" data-target="#editInvoiceItemModal<?php echo $item_id; ?>"><i class="fa fa-fw fa-edit"></i></a>
|
||||
<a class="text-secondary" href="#" data-toggle="modal" data-target="#editItemModal<?php echo $item_id; ?>"><i class="fa fa-fw fa-edit"></i></a>
|
||||
<a class="text-danger" href="post.php?delete_invoice_item=<?php echo $item_id; ?>"><i class="fa fa-fw fa-trash-alt"></i></a>
|
||||
</td>
|
||||
<td><?php echo $item_name; ?></td>
|
||||
|
|
@ -273,7 +273,7 @@ if(isset($_GET['invoice_id'])){
|
|||
|
||||
<?php
|
||||
|
||||
include("edit_invoice_item_modal.php");
|
||||
include("edit_item_modal.php");
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
113
post.php
113
post.php
|
|
@ -1853,45 +1853,6 @@ if(isset($_POST['quote_note'])){
|
|||
|
||||
}
|
||||
|
||||
if(isset($_POST['edit_quote_item'])){
|
||||
|
||||
$quote_id = intval($_POST['quote_id']);
|
||||
$item_id = intval($_POST['item_id']);
|
||||
$name = strip_tags(mysqli_real_escape_string($mysqli,$_POST['name']));
|
||||
$description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description']));
|
||||
$qty = floatval($_POST['qty']);
|
||||
$price = floatval($_POST['price']);
|
||||
$tax_id = intval($_POST['tax_id']);
|
||||
|
||||
$subtotal = $price * $qty;
|
||||
|
||||
if($tax_id > 0){
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM taxes WHERE tax_id = $tax_id");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
$tax_percent = $row['tax_percent'];
|
||||
$tax_amount = $subtotal * $tax_percent / 100;
|
||||
}else{
|
||||
$tax_amount = 0;
|
||||
}
|
||||
|
||||
$total = $subtotal + $tax_amount;
|
||||
|
||||
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', tax_id = $tax_id WHERE item_id = $item_id");
|
||||
|
||||
//Update Invoice Balances by tallying up invoice items
|
||||
|
||||
$sql_quote_total = mysqli_query($mysqli,"SELECT SUM(item_total) AS quote_total FROM invoice_items WHERE quote_id = $quote_id AND company_id = $session_company_id");
|
||||
$row = mysqli_fetch_array($sql_quote_total);
|
||||
$new_quote_amount = $row['quote_total'];
|
||||
|
||||
mysqli_query($mysqli,"UPDATE quotes SET quote_amount = '$new_quote_amount', quote_updated_at = NOW() WHERE quote_id = $quote_id AND company_id = $session_company_id");
|
||||
|
||||
$_SESSION['alert_message'] = "<i class='fa fa-2x fa-check-circle'></i> Item updated";
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
|
||||
}
|
||||
|
||||
if(isset($_POST['edit_quote'])){
|
||||
|
||||
$quote_id = intval($_POST['quote_id']);
|
||||
|
|
@ -2440,7 +2401,7 @@ if(isset($_POST['add_recurring_item'])){
|
|||
|
||||
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_created_at = NOW(), tax_id = $tax_id, recurring_id = $recurring_id, company_id = $session_company_id");
|
||||
|
||||
//Update Invoice Balances
|
||||
//Update Recurring Balances
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM recurring WHERE recurring_id = $recurring_id AND company_id = $session_company_id");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
|
|
@ -2468,45 +2429,6 @@ if(isset($_POST['recurring_note'])){
|
|||
|
||||
}
|
||||
|
||||
if(isset($_POST['edit_recurring_item'])){
|
||||
|
||||
$recurring_id = intval($_POST['recurring_id']);
|
||||
$item_id = intval($_POST['item_id']);
|
||||
$name = strip_tags(mysqli_real_escape_string($mysqli,$_POST['name']));
|
||||
$description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description']));
|
||||
$qty = floatval($_POST['qty']);
|
||||
$price = floatval($_POST['price']);
|
||||
$tax_id = intval($_POST['tax_id']);
|
||||
|
||||
$subtotal = $price * $qty;
|
||||
|
||||
if($tax_id > 0){
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM taxes WHERE tax_id = $tax_id");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
$tax_percent = $row['tax_percent'];
|
||||
$tax_amount = $subtotal * $tax_percent / 100;
|
||||
}else{
|
||||
$tax_amount = 0;
|
||||
}
|
||||
|
||||
$total = $subtotal + $tax_amount;
|
||||
|
||||
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', tax_id = $tax_id WHERE item_id = $item_id");
|
||||
|
||||
//Update Invoice Balances by tallying up invoice items
|
||||
|
||||
$sql_recurring_total = mysqli_query($mysqli,"SELECT SUM(item_total) AS recurring_total FROM invoice_items WHERE recurring_id = $recurring_id AND company_id = $session_company_id");
|
||||
$row = mysqli_fetch_array($sql_recurring_total);
|
||||
$new_recurring_amount = $row['recurring_total'];
|
||||
|
||||
mysqli_query($mysqli,"UPDATE recurring SET recurring_amount = '$new_recurring_amount', recurring_updated_at = NOW() WHERE recurring_id = $recurring_id AND company_id = $session_company_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Item updated";
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
|
||||
}
|
||||
|
||||
if(isset($_GET['delete_recurring_item'])){
|
||||
$item_id = intval($_GET['delete_recurring_item']);
|
||||
|
||||
|
|
@ -2657,9 +2579,11 @@ if(isset($_POST['invoice_note'])){
|
|||
|
||||
}
|
||||
|
||||
if(isset($_POST['edit_invoice_item'])){
|
||||
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 = strip_tags(mysqli_real_escape_string($mysqli,$_POST['name']));
|
||||
$description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description']));
|
||||
|
|
@ -2682,13 +2606,32 @@ if(isset($_POST['edit_invoice_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', tax_id = $tax_id WHERE item_id = $item_id");
|
||||
|
||||
//Update Invoice Balances by tallying up invoice items
|
||||
if($invoice_id > 0){
|
||||
//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 invoice_id = $invoice_id AND company_id = $session_company_id");
|
||||
$row = mysqli_fetch_array($sql_invoice_total);
|
||||
$new_invoice_amount = $row['invoice_total'];
|
||||
|
||||
$sql_invoice_total = mysqli_query($mysqli,"SELECT SUM(item_total) AS invoice_total FROM invoice_items WHERE invoice_id = $invoice_id AND company_id = $session_company_id");
|
||||
$row = mysqli_fetch_array($sql_invoice_total);
|
||||
$new_invoice_amount = $row['invoice_total'];
|
||||
mysqli_query($mysqli,"UPDATE invoices SET invoice_amount = '$new_invoice_amount', invoice_updated_at = NOW() WHERE invoice_id = $invoice_id AND company_id = $session_company_id");
|
||||
|
||||
}elseif($quote_id > 0){
|
||||
//Update Quote Balances by tallying up items
|
||||
$sql_quote_total = mysqli_query($mysqli,"SELECT SUM(item_total) AS quote_total FROM invoice_items WHERE quote_id = $quote_id AND company_id = $session_company_id");
|
||||
$row = mysqli_fetch_array($sql_quote_total);
|
||||
$new_quote_amount = $row['quote_total'];
|
||||
|
||||
mysqli_query($mysqli,"UPDATE invoices SET invoice_amount = '$new_invoice_amount', invoice_updated_at = NOW() WHERE invoice_id = $invoice_id AND company_id = $session_company_id");
|
||||
mysqli_query($mysqli,"UPDATE quotes SET quote_amount = '$new_quote_amount', quote_updated_at = NOW() WHERE quote_id = $quote_id AND company_id = $session_company_id");
|
||||
|
||||
}else{
|
||||
//Update Invoice Balances by tallying up invoice items
|
||||
|
||||
$sql_recurring_total = mysqli_query($mysqli,"SELECT SUM(item_total) AS recurring_total FROM invoice_items WHERE recurring_id = $recurring_id AND company_id = $session_company_id");
|
||||
$row = mysqli_fetch_array($sql_recurring_total);
|
||||
$new_recurring_amount = $row['recurring_total'];
|
||||
|
||||
mysqli_query($mysqli,"UPDATE recurring SET recurring_amount = '$new_recurring_amount', recurring_updated_at = NOW() WHERE recurring_id = $recurring_id AND company_id = $session_company_id");
|
||||
|
||||
}
|
||||
|
||||
$_SESSION['alert_message'] = "Item updated";
|
||||
|
||||
|
|
|
|||
|
|
@ -224,7 +224,7 @@ if(isset($_GET['quote_id'])){
|
|||
|
||||
<tr>
|
||||
<td class="text-center d-print-none">
|
||||
<a class="text-secondary" href="#" data-toggle="modal" data-target="#editQuoteItemModal<?php echo $item_id; ?>"><i class="fa fa-fw fa-edit"></i></a>
|
||||
<a class="text-secondary" href="#" data-toggle="modal" data-target="#editItemModal<?php echo $item_id; ?>"><i class="fa fa-fw fa-edit"></i></a>
|
||||
<a class="text-danger" href="post.php?delete_quote_item=<?php echo $item_id; ?>"><i class="fa fa-fw fa-trash-alt"></i></a>
|
||||
</td>
|
||||
<td><?php echo $item_name; ?></td>
|
||||
|
|
@ -237,7 +237,7 @@ if(isset($_GET['quote_id'])){
|
|||
|
||||
<?php
|
||||
|
||||
include("edit_quote_item_modal.php");
|
||||
include("edit_item_modal.php");
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -204,7 +204,7 @@ if(isset($_GET['recurring_id'])){
|
|||
|
||||
<tr>
|
||||
<td class="text-center d-print-none">
|
||||
<a class="text-secondary" href="#" data-toggle="modal" data-target="#editRecurringItemModal<?php echo $item_id; ?>"><i class="fa fa-fw fa-edit"></i></a>
|
||||
<a class="text-secondary" href="#" data-toggle="modal" data-target="#editItemModal<?php echo $item_id; ?>"><i class="fa fa-fw fa-edit"></i></a>
|
||||
<a class="text-danger" href="post.php?delete_recurring_item=<?php echo $item_id; ?>"><i class="fa fa-fw fa-trash-alt"></i></a>
|
||||
</td>
|
||||
<td><?php echo $item_name; ?></td>
|
||||
|
|
@ -217,7 +217,7 @@ if(isset($_GET['recurring_id'])){
|
|||
|
||||
<?php
|
||||
|
||||
include("edit_recurring_item_modal.php");
|
||||
include("edit_item_modal.php");
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue