mirror of https://github.com/itflow-org/itflow
More invoice work completed invoice payment module
This commit is contained in:
parent
64cbe6a016
commit
408b1fa7cb
|
|
@ -0,0 +1,88 @@
|
|||
<div class="modal fade" id="addInvoicePaymentModal" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><i class="fa fa-money-bill-alt"></i> New Payment</h5>
|
||||
<button type="button" class="close" data-dismiss="modal">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="invoice_id" value="<?php echo $invoice_id; ?>">
|
||||
<div class="modal-body">
|
||||
<div class="form-row">
|
||||
<div class="form-group col">
|
||||
<label>Date</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-calendar"></i></span>
|
||||
</div>
|
||||
<input type="date" class="form-control" name="date" value="<?php echo date("Y-m-d"); ?>" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col">
|
||||
<label>Amount</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-dollar-sign"></i></span>
|
||||
</div>
|
||||
<input type="number" class="form-control" step="0.01" min="0" name="amount" value="<?php echo $invoice_amount; ?>" required>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group col">
|
||||
<label>Account</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-university"></i></span>
|
||||
</div>
|
||||
<select class="form-control" name="account" required>
|
||||
<option value="">- Account -</option>
|
||||
<?php
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM accounts");
|
||||
while($row = mysqli_fetch_array($sql)){
|
||||
$account_id = $row['account_id'];
|
||||
$account_name = $row['account_name'];
|
||||
?>
|
||||
<option value="<?php echo $account_id; ?>"><?php echo "$account_name"; ?></option>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col">
|
||||
<label>Payment Method</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-money-check-alt"></i></span>
|
||||
</div>
|
||||
<select class="form-control" name="payment_method" required>
|
||||
<option value="">- Payment Method -</option>
|
||||
<?php
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM categories WHERE category_type = 'Payment Method'");
|
||||
while($row = mysqli_fetch_array($sql)){
|
||||
$category_name = $row['category_name'];
|
||||
?>
|
||||
<option><?php echo "$category_name"; ?></option>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
|
||||
<button type="submit" name="add_invoice_payment" class="btn btn-primary">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
<div class="modal fade" id="addInvoicePaymentModal" tabindex="-1">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><i class="fa fa-piggy-bank"></i> New Account</h5>
|
||||
<button type="button" class="close" data-dismiss="modal">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="invoice_id" value="<?php echo $invoice_id; ?>">
|
||||
<div class="modal-body">
|
||||
<div class="form-row">
|
||||
<div class="form-group col-sm-8">
|
||||
<label>Date</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-calendar"></i></span>
|
||||
</div>
|
||||
<input type="date" class="form-control" name="date" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-sm-4">
|
||||
<label>Amount</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-usd"></i></span>
|
||||
</div>
|
||||
<input type="number" class="form-control" step="0.01" min="0" name="amount" value="<?php echo $invoice_amount; ?>" required>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group col">
|
||||
<label>Account</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-university"></i></span>
|
||||
</div>
|
||||
<select class="form-control" name="account" required>
|
||||
<option value="">- Account -</option>
|
||||
<?php
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM accounts");
|
||||
while($row = mysqli_fetch_array($sql)){
|
||||
$account_id = $row['account_id'];
|
||||
$account_name = $row['account_name'];
|
||||
?>
|
||||
<option value="<?php echo $account_id; ?>"><?php echo "$account_name"; ?></option>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col">
|
||||
<label>Payment Method</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-university"></i></span>
|
||||
</div>
|
||||
<select class="form-control" name="payment_method" required>
|
||||
<option value="">- Payment Method -</option>
|
||||
<?php
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM categories WHERE category_type = 'Payment Method'");
|
||||
while($row = mysqli_fetch_array($sql)){
|
||||
$category_id = $row['category_id'];
|
||||
$category_name = $row['category_name'];
|
||||
?>
|
||||
<option value="<?php echo $category_id; ?>"><?php echo "$category_name"; ?></option>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
|
||||
<button type="submit" name="add_invoice_payment" class="btn btn-primary">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
<i class="fas fa-ellipsis-h"></i>
|
||||
</button>
|
||||
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#editcategoryModal<?php echo $category_id; ?>">Edit</a>
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#editCategoryModal<?php echo $category_id; ?>">Edit</a>
|
||||
<a class="dropdown-item" href="#">Delete</a>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -82,7 +82,8 @@
|
|||
|
||||
$category_types_array = array(
|
||||
'Expense',
|
||||
'Income'
|
||||
'Income',
|
||||
'Payment Method'
|
||||
);
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
<div class="modal fade" id="editCategoryModal<?php echo $category_id; ?>" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><i class="fa fa-modify"></i> Modify Category</h5>
|
||||
<button type="button" class="close" data-dismiss="modal">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label>Name</label>
|
||||
<input type="text" class="form-control" name="name" value="<?php echo $category_name; ?>" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Type</label>
|
||||
<select class="form-control" name="type" required>
|
||||
<?php foreach($category_types_array as $category_type => $category_type) { ?>
|
||||
<option <?php if($category_type == $category_type) { echo "selected"; } ?>><?php echo $category_type; ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
|
||||
<button type="submit" name="add_category" class="btn btn-primary">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<div class="modal fade" id="editCategoryModal<?php echo $category_id; ?>" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><i class="fa fa-modify"></i> Modify Category</h5>
|
||||
<button type="button" class="close" data-dismiss="modal">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label>Name</label>
|
||||
<input type="text" class="form-control" name="name" value="<?php echo $category_name; ?>" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Type</label>
|
||||
<select class="form-control" name="type" required>
|
||||
<?php foreach($category_types_array as $category_type2 => $category_type2) { ?>
|
||||
<option <?php if($category_type == $category_type2) { echo "selected"; } ?>><?php echo $category_type2; ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
|
||||
<button type="submit" name="add_category" class="btn btn-primary">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
85
invoice.php
85
invoice.php
|
|
@ -20,7 +20,12 @@ if(isset($_GET['invoice_id'])){
|
|||
$invoice_status = $row['invoice_status'];
|
||||
$invoice_date = $row['invoice_date'];
|
||||
$invoice_due = $row['invoice_due'];
|
||||
$invoice_amount = $row['invoice_amount'];
|
||||
$invoice_subtotal = $row['invoice_subtotal'];
|
||||
$invoice_discount = $row['invoice_discount'];
|
||||
$invoice_tax = $row['invoice_tax'];
|
||||
$invoice_total = $row['invoice_total'];
|
||||
$invoice_paid = $row['invoice_paid'];
|
||||
$invoice_balance = $row['invoice_balance'];
|
||||
$client_id = $row['client_id'];
|
||||
$client_name = $row['client_name'];
|
||||
$client_address = $row['client_address'];
|
||||
|
|
@ -34,6 +39,9 @@ if(isset($_GET['invoice_id'])){
|
|||
}
|
||||
$client_website = $row['client_website'];
|
||||
|
||||
$sql2 = mysqli_query($mysqli,"SELECT * FROM invoice_history WHERE invoice_id = $invoice_id ORDER BY invoice_history_id DESC");
|
||||
$sql3 = mysqli_query($mysqli,"SELECT * FROM invoice_payments, accounts WHERE invoice_payments.account_id = accounts.account_id AND invoice_payments.invoice_id = $invoice_id ORDER BY invoice_payments.invoice_payment_id DESC");
|
||||
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="col-md-11">
|
||||
|
|
@ -51,7 +59,7 @@ if(isset($_GET['invoice_id'])){
|
|||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#editinvoiceModal<?php echo $invoice_id; ?>">Edit</a>
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#addinvoiceCopyModal<?php echo $invoice_id; ?>">Copy</a>
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#addinvoiceCopyModal<?php echo $invoice_id; ?>">Send Email</a>
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#addinvoiceCopyModal<?php echo $invoice_id; ?>">Add Payment</a>
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#addInvoicePaymentModal">Add Payment</a>
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#addinvoiceCopyModal<?php echo $invoice_id; ?>">Print</a>
|
||||
<a class="dropdown-item" href="#">Delete</a>
|
||||
</div>
|
||||
|
|
@ -101,7 +109,7 @@ if(isset($_GET['invoice_id'])){
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<?php $sql2 = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE invoice_id = $invoice_id ORDER BY invoice_item_id DESC"); ?>
|
||||
<?php $sql4 = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE invoice_id = $invoice_id ORDER BY invoice_item_id ASC"); ?>
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-12">
|
||||
|
|
@ -113,41 +121,38 @@ if(isset($_GET['invoice_id'])){
|
|||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Product</th>
|
||||
<th>Description</th>
|
||||
<th class="text-center">Qty</th>
|
||||
<th class="text-right">Price</th>
|
||||
<th class="text-right">Tax</th>
|
||||
<th class="text-right">Total</th>
|
||||
<th class="text-center"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
|
||||
while($row = mysqli_fetch_array($sql2)){
|
||||
while($row = mysqli_fetch_array($sql4)){
|
||||
$invoice_item_id = $row['invoice_item_id'];
|
||||
$invoice_item_name = $row['invoice_item_name'];
|
||||
$invoice_item_description = $row['invoice_item_description'];
|
||||
$invoice_item_quantity = $row['invoice_item_quantity'];
|
||||
$invoice_item_price = $row['invoice_item_price'];
|
||||
$invoice_item_subtotal = $row['invoice_item_price'];
|
||||
$invoice_item_tax = $row['invoice_item_tax'];
|
||||
$invoice_item_total = $row['invoice_item_total'];
|
||||
|
||||
$invoice_subtotal = $invoice_subtotal + $invoice_item_price * $invoice_item_quantity;
|
||||
$invoice_tax = $invoice_tax + $invoice_item_tax;
|
||||
$invoice_total = $invoice_total + $invoice_item_total;
|
||||
|
||||
?>
|
||||
|
||||
<tr>
|
||||
<td class="text-center"><a class="btn btn-danger btn-sm" href="post.php?delete_invoice_item=<?php echo $invoice_item_id; ?>"><i class="fa fa-trash"></i></a></td>
|
||||
<td><?php echo $invoice_item_name; ?></td>
|
||||
<td><?php echo $invoice_item_description; ?></td>
|
||||
<td class="text-center"><?php echo $invoice_item_quantity; ?></td>
|
||||
<td class="text-right"><?php echo "$ $invoice_item_price"; ?></td>
|
||||
<td class="text-right"><?php echo "$ $invoice_item_tax"; ?></td>
|
||||
<td class="text-right"><?php echo "$ $invoice_item_total"; ?></td>
|
||||
<td class="text-center"><a class="btn btn-danger btn-sm" href="post.php?delete_invoice_item=<?php echo $invoice_item_id; ?>"><i class="fa fa-trash"></i></a></td>
|
||||
<td class="text-right"><?php echo "$ $invoice_item_total"; ?></td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
|
|
@ -158,6 +163,7 @@ if(isset($_GET['invoice_id'])){
|
|||
|
||||
<tr>
|
||||
<form action="post.php" method="post">
|
||||
<td class="text-center"><button type="submit" class="btn btn-primary btn-sm" name="add_invoice_item"><i class="fa fa-check"></i></button></td>
|
||||
<input type="hidden" name="invoice_id" value="<?php echo $invoice_id; ?>">
|
||||
<td><input type="text" class="form-control" name="name"></td>
|
||||
<td><textarea class="form-control" rows="1" name="description"></textarea></td>
|
||||
|
|
@ -169,27 +175,28 @@ if(isset($_GET['invoice_id'])){
|
|||
<option value="0.07">State Tax 7%</option>
|
||||
</select>
|
||||
</td>
|
||||
<td class="text-right">$ 0.00</td>
|
||||
<td class="text-center"><button type="submit" class="btn btn-primary btn-sm" name="add_invoice_item"><i class="fa fa-check"></i></button></td>
|
||||
<td class="text-right">$ 0.00</td>
|
||||
</form>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="4"></td>
|
||||
<td colspan="5"></td>
|
||||
<td><strong>SubTotal</strong></td>
|
||||
<td class="text-right">$<?php echo $invoice_subtotal; ?></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="4"></td>
|
||||
<td colspan="5"></td>
|
||||
<td><strong>Discount</strong></td>
|
||||
<td class="text-right">$<?php echo $invoice_discount; ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"></td>
|
||||
<td><strong>Tax</strong></td>
|
||||
<td class="text-right">$<?php echo $invoice_tax; ?></td>
|
||||
<td></td>
|
||||
<td class="text-right">$<?php echo $invoice_tax; ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="4"></td>
|
||||
<td colspan="5"></td>
|
||||
<td><strong>Total</strong></td>
|
||||
<td class="text-right">$<?php echo $invoice_total; ?></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
@ -246,6 +253,23 @@ if(isset($_GET['invoice_id'])){
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
|
||||
while($row = mysqli_fetch_array($sql2)){
|
||||
$invoice_history_date = $row['invoice_history_date'];
|
||||
$invoice_history_status = $row['invoice_history_status'];
|
||||
$invoice_history_description = $row['invoice_history_description'];
|
||||
|
||||
?>
|
||||
<tr>
|
||||
<td><?php echo $invoice_history_date; ?></td>
|
||||
<td><?php echo $invoice_history_status; ?></td>
|
||||
<td><?php echo $invoice_history_description; ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
|
@ -267,6 +291,25 @@ if(isset($_GET['invoice_id'])){
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
|
||||
while($row = mysqli_fetch_array($sql3)){
|
||||
$invoice_payment_id = $row['invoice_payment_id'];
|
||||
$invoice_payment_date = $row['invoice_payment_date'];
|
||||
$invoice_payment_amount = $row['invoice_payment_amount'];
|
||||
$account_name = $row['account_name'];
|
||||
|
||||
|
||||
?>
|
||||
<tr>
|
||||
<td><?php echo $invoice_payment_date; ?></td>
|
||||
<td><?php echo $invoice_payment_amount; ?></td>
|
||||
<td><?php echo $account_name; ?></td>
|
||||
<td class="text-center"><a class="btn btn-danger btn-sm" href="post.php?delete_invoice_payment=<?php echo $invoice_payment_id; ?>"><i class="fa fa-trash"></i></a></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
|
@ -274,6 +317,8 @@ if(isset($_GET['invoice_id'])){
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<?php include("add_invoice_payment_modal.php"); ?>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
<?php include("footer.php");
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
$invoice_status = $row['invoice_status'];
|
||||
$invoice_date = $row['invoice_date'];
|
||||
$invoice_due = $row['invoice_due'];
|
||||
$invoice_amount = $row['invoice_amount'];
|
||||
$invoice_balance = $row['invoice_balance'];
|
||||
$client_id = $row['client_id'];
|
||||
$client_name = $row['client_name'];
|
||||
|
||||
|
|
@ -44,7 +44,7 @@
|
|||
<tr>
|
||||
<td><a href="invoice.php?invoice_id=<?php echo $invoice_id; ?>">INV-<?php echo "$invoice_number"; ?></a></td>
|
||||
<td><a href="client.php?client_id=<?php echo $client_id; ?>"><?php echo "$client_name"; ?></a></td>
|
||||
<td class="text-right text-monospace">$<?php echo "$invoice_amount"; ?></td>
|
||||
<td class="text-right text-monospace">$<?php echo "$invoice_balance"; ?></td>
|
||||
<td><?php echo "$invoice_date"; ?></td>
|
||||
<td><?php echo "$invoice_due"; ?></td>
|
||||
<td><?php echo "$invoice_status"; ?></td>
|
||||
|
|
|
|||
81
post.php
81
post.php
|
|
@ -268,13 +268,25 @@ if(isset($_POST['add_invoice_item'])){
|
|||
$price = $_POST['price'];
|
||||
$tax = $_POST['tax'];
|
||||
|
||||
$sub_total = $price * $qty;
|
||||
$tax = $sub_total * $tax;
|
||||
$total = $sub_total + $tax;
|
||||
$subtotal = $price * $qty;
|
||||
$tax = $subtotal * $tax;
|
||||
$total = $subtotal + $tax;
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO invoice_items SET invoice_item_name = '$name', invoice_item_description = '$description', invoice_item_quantity = $qty, invoice_item_price = '$price', invoice_item_tax = '$tax', invoice_item_total = '$total', invoice_id = $invoice_id");
|
||||
mysqli_query($mysqli,"INSERT INTO invoice_items SET invoice_item_name = '$name', invoice_item_description = '$description', invoice_item_quantity = $qty, invoice_item_price = '$price', invoice_item_subtotal = '$subtotal', invoice_item_tax = '$tax', invoice_item_total = '$total', invoice_id = $invoice_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Invoice added";
|
||||
//Update Invoice Balances
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoices WHERE invoice_id = $invoice_id");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
|
||||
$invoice_subtotal = $row['invoice_subtotal'] + $subtotal;
|
||||
$invoice_tax = $row['invoice_tax'] + $tax;
|
||||
$invoice_total = $row['invoice_total'] + $total;
|
||||
$invoice_balance = $row['invoice_balance'] + $total;
|
||||
|
||||
mysqli_query($mysqli,"UPDATE invoices SET invoice_subtotal = '$invoice_subtotal', invoice_tax = '$invoice_tax', invoice_total = '$invoice_total', invoice_balance = '$invoice_balance' WHERE invoice_id = $invoice_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Item added";
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
|
||||
|
|
@ -283,6 +295,22 @@ if(isset($_POST['add_invoice_item'])){
|
|||
if(isset($_GET['delete_invoice_item'])){
|
||||
$invoice_item_id = intval($_GET['delete_invoice_item']);
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE invoice_item_id = $invoice_item_id");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
$invoice_id = $row['invoice_id'];
|
||||
$invoice_item_subtotal = $row['invoice_item_subtotal'];
|
||||
$invoice_item_tax = $row['invoice_item_tax'];
|
||||
$invoice_item_total = $row['invoice_item_total'];
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoices WHERE invoice_id = $invoice_id");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
$invoice_balance = $row['invoice_balance'] - $invoice_item_total;
|
||||
$invoice_subtotal = $row['invoice_subtotal'] - $invoice_item_subtotal;
|
||||
$invoice_tax = $row['invoice_tax'] - $invoice_item_tax;
|
||||
$invoice_total = $row['invoice_total'] - $invoice_item_total;
|
||||
|
||||
mysqli_query($mysqli,"UPDATE invoices SET invoice_subtotal = '$invoice_subtotal', invoice_tax = '$invoice_tax', invoice_total = '$invoice_total', invoice_balance = '$invoice_balance' WHERE invoice_id = $invoice_id");
|
||||
|
||||
mysqli_query($mysqli,"DELETE FROM invoice_items WHERE invoice_item_id = $invoice_item_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Item deleted";
|
||||
|
|
@ -291,6 +319,49 @@ if(isset($_GET['delete_invoice_item'])){
|
|||
|
||||
}
|
||||
|
||||
if(isset($_POST['add_invoice_payment'])){
|
||||
|
||||
$invoice_id = intval($_POST['invoice_id']);
|
||||
$date = strip_tags(mysqli_real_escape_string($mysqli,$_POST['date']));
|
||||
$amount = $_POST['amount'];
|
||||
$account = intval($_POST['account']);
|
||||
$payment_method = strip_tags(mysqli_real_escape_string($mysqli,$_POST['payment_method']));
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoices WHERE invoice_id = $invoice_id");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
$invoice_balance = $row['invoice_balance'] - $amount;
|
||||
$invoice_paid = $row['invoice_paid'] + $paid;
|
||||
|
||||
mysqli_query($mysqli,"UPDATE invoices SET invoice_balance = '$invoice_balance', invoice_paid = '$invoice_paid' WHERE invoice_id = $invoice_id");
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO invoice_payments SET invoice_payment_date = '$date', invoice_payment_amount = '$amount', account_id = $account, invoice_payment_method = '$payment_method', invoice_id = $invoice_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Payment added";
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
|
||||
}
|
||||
|
||||
if(isset($_GET['delete_invoice_payment'])){
|
||||
$invoice_payment_id = intval($_GET['delete_invoice_payment']);
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoice_payments WHERE invoice_payment_id = $invoice_id");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
$invoice_id = $row['invoice_id'];
|
||||
$invoice_payment_amount = $row['invoice_payment_amount'];
|
||||
|
||||
$invoice_balance = $row['invoice_balance'] - $invoice_payment_amount;
|
||||
|
||||
mysqli_query($mysqli,"UPDATE invoices SET invoice_balance = '$invoice_balance' WHERE invoice_id = $invoice_id");
|
||||
|
||||
mysqli_query($mysqli,"DELETE FROM invoice_payments WHERE invoice_payment_id = $invoice_payment_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Payment deleted";
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
|
||||
}
|
||||
|
||||
if(isset($_POST['add_user'])){
|
||||
$email = strip_tags(mysqli_real_escape_string($mysqli,$_POST['email']));
|
||||
$password = mysqli_real_escape_string($mysqli,$_POST['password']);
|
||||
|
|
|
|||
Loading…
Reference in New Issue