mirror of https://github.com/itflow-org/itflow
Updates to recurring invoices
This commit is contained in:
parent
9b8f48794f
commit
3a3cd4ac47
|
|
@ -0,0 +1,37 @@
|
|||
<div class="modal" id="addInvoiceRecurringModal<?php echo $invoice_id; ?>" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content bg-dark">
|
||||
<div class="modal-header text-white">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-copy mr-2"></i>Make INV-<?php echo $invoice_number; ?> Recurring</h5>
|
||||
<button type="button" class="close text-white" 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 bg-white">
|
||||
|
||||
<div class="form-group">
|
||||
<label>Frequency</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-clock"></i></span>
|
||||
</div>
|
||||
<select class="form-control" name="frequency" required>
|
||||
<option value="">- Frequency -</option>
|
||||
<option value="week">Weekly</option>
|
||||
<option value="month">Monthly</option>
|
||||
<option value="year">Yearly</option>
|
||||
</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="add_invoice_recurring" class="btn btn-primary">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -162,7 +162,7 @@
|
|||
<option value="">- Vendor -</option>
|
||||
<?php
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM vendors");
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM vendors WHERE client_id = 0 ORDER BY vendor_name ASC");
|
||||
while($row = mysqli_fetch_array($sql)){
|
||||
$vendor_id = $row['vendor_id'];
|
||||
$vendor_name = $row['vendor_name'];
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ if(isset($_GET['client_id'])){
|
|||
$row = mysqli_fetch_assoc(mysqli_query($mysqli,"SELECT COUNT('quote_id') AS num FROM quotes WHERE client_id = $client_id"));
|
||||
$num_quotes = $row['num'];
|
||||
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli,"SELECT COUNT('recurring_id') AS num FROM recurring, invoices WHERE recurring.invoice_id = invoices.invoice_id AND invoices.client_id = $client_id"));
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli,"SELECT COUNT('recurring_id') AS num FROM recurring WHERE client_id = $client_id"));
|
||||
$num_recurring = $row['num'];
|
||||
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli,"SELECT COUNT('payment_id') AS num FROM payments, invoices WHERE payments.invoice_id = invoices.invoice_id AND invoices.client_id = $client_id"));
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM recurring, invoices, categories
|
||||
WHERE invoices.invoice_id = recurring.invoice_id
|
||||
AND invoices.client_id = $client_id
|
||||
AND invoices.category_id = categories.category_id
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM recurring, categories
|
||||
WHERE recurring.client_id = $client_id
|
||||
AND recurring.category_id = categories.category_id
|
||||
ORDER BY recurring.recurring_id DESC");
|
||||
?>
|
||||
|
||||
|
|
@ -19,7 +18,6 @@
|
|||
<thead>
|
||||
<tr>
|
||||
<th>Frequency</th>
|
||||
<th>Start Date</th>
|
||||
<th>Last Sent</th>
|
||||
<th>Next Date</th>
|
||||
<th>Status</th>
|
||||
|
|
@ -33,7 +31,6 @@
|
|||
$recurring_id = $row['recurring_id'];
|
||||
$recurring_frequency = $row['recurring_frequency'];
|
||||
$recurring_status = $row['recurring_status'];
|
||||
$recurring_start_date = $row['recurring_start_date'];
|
||||
$recurring_last_sent = $row['recurring_last_sent'];
|
||||
if($recurring_last_sent == 0){
|
||||
$recurring_last_sent = "-";
|
||||
|
|
@ -41,7 +38,6 @@
|
|||
$recurring_next_date = $row['recurring_next_date'];
|
||||
$category_id = $row['category_id'];
|
||||
$category_name = $row['category_name'];
|
||||
$invoice_id = $row['invoice_id'];
|
||||
if($recurring_status == 1){
|
||||
$status = "Active";
|
||||
$status_badge_color = "success";
|
||||
|
|
@ -54,7 +50,6 @@
|
|||
|
||||
<tr>
|
||||
<td><?php echo ucwords($recurring_frequency); ?>ly</td>
|
||||
<td><?php echo $recurring_start_date; ?></td>
|
||||
<td><?php echo $recurring_last_sent; ?></td>
|
||||
<td><?php echo $recurring_next_date; ?></td>
|
||||
<td><?php echo $category_name; ?></td>
|
||||
|
|
@ -75,7 +70,7 @@
|
|||
<?php }else{ ?>
|
||||
<a class="dropdown-item" href="post.php?recurring_activate=<?php echo $recurring_id; ?>">Activate</a>
|
||||
<?php } ?>
|
||||
<a class="dropdown-item" href="post.php?delete_invoice=<?php echo $invoice_id; ?>">Delete</a>
|
||||
<a class="dropdown-item" href="post.php?delete_recurring=<?php echo $recurring_id; ?>">Delete</a>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
|
|
|
|||
17
cron.php
17
cron.php
|
|
@ -88,7 +88,7 @@ while($row = mysqli_fetch_array($sql)){
|
|||
|
||||
//Send Recurring Invoices that match todays date and are active
|
||||
|
||||
$sql_recurring = mysqli_query($mysqli,"SELECT * FROM recurring, clients, invoices WHERE clients.client_id = invoices.client_id AND invoices.invoice_id = recurring.invoice_id AND recurring.recurring_next_date = CURDATE() AND recurring.recurring_status = 1");
|
||||
$sql_recurring = mysqli_query($mysqli,"SELECT * FROM recurring, clients WHERE clients.client_id = recurring.client_id AND recurring.recurring_next_date = CURDATE() AND recurring.recurring_status = 1");
|
||||
|
||||
while($row = mysqli_fetch_array($sql_recurring)){
|
||||
$recurring_id = $row['recurring_id'];
|
||||
|
|
@ -97,11 +97,9 @@ while($row = mysqli_fetch_array($sql_recurring)){
|
|||
$recurring_start_date = $row['recurring_start_date'];
|
||||
$recurring_last_sent = $row['recurring_last_sent'];
|
||||
$recurring_next_date = $row['recurring_next_date'];
|
||||
$invoice_id = $row['invoice_id'];
|
||||
$invoice_status = $row['invoice_status'];
|
||||
$invoice_amount = $row['invoice_amount'];
|
||||
$invoice_note = $row['invoice_note'];
|
||||
$invoice_category_id = $row['category_id'];
|
||||
$recurring_amount = $row['recurring_amount'];
|
||||
$recurring_note = $row['recurring_note'];
|
||||
$category_id = $row['category_id'];
|
||||
$client_id = $row['client_id'];
|
||||
$client_name = $row['client_name'];
|
||||
$client_net_terms = $row['client_net_terms'];
|
||||
|
|
@ -111,13 +109,12 @@ while($row = mysqli_fetch_array($sql_recurring)){
|
|||
$row = mysqli_fetch_array($sql_invoice_number);
|
||||
$new_invoice_number = $row['invoice_number'] + 1;
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO invoices SET invoice_number = $new_invoice_number, invoice_date = CURDATE(), invoice_due = DATE_ADD(CURDATE(), INTERVAL $client_net_terms day) , invoice_amount = '$invoice_amount', invoice_note = '$invoice_note', category_id = $invoice_category_id, invoice_status = 'Sent', client_id = $client_id");
|
||||
mysqli_query($mysqli,"INSERT INTO invoices SET invoice_number = $new_invoice_number, invoice_date = CURDATE(), invoice_due = DATE_ADD(CURDATE(), INTERVAL $client_net_terms day) , invoice_amount = '$recurring_amount', invoice_note = '$recurring_note', category_id = $category_id, invoice_status = 'Sent', client_id = $client_id");
|
||||
|
||||
$new_invoice_id = mysqli_insert_id($mysqli);
|
||||
|
||||
|
||||
//Copy Items from original invoice to new invoice
|
||||
$sql_invoice_items = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE invoice_id = $invoice_id ORDER BY item_id ASC");
|
||||
$sql_invoice_items = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE recurring = $recurring_id ORDER BY item_id ASC");
|
||||
|
||||
while($row = mysqli_fetch_array($sql_invoice_items)){
|
||||
$item_id = $row['item_id'];
|
||||
|
|
@ -132,7 +129,7 @@ while($row = mysqli_fetch_array($sql_recurring)){
|
|||
mysqli_query($mysqli,"INSERT INTO invoice_items SET item_name = '$item_name', item_description = '$item_description', item_quantity = $item_quantity, item_price = '$item_price', item_subtotal = '$item_subtotal', item_tax = '$item_tax', item_total = '$item_total', invoice_id = $new_invoice_id");
|
||||
}
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO invoice_history SET invoice_history_date = CURDATE(), invoice_history_status = 'Draft', invoice_history_description = 'INVOICE added!', invoice_id = $new_invoice_id");
|
||||
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Sent', history_description = 'INVOICE Generated from Recurring!', invoice_id = $new_invoice_id");
|
||||
|
||||
//update the recurring invoice with the new dates
|
||||
mysqli_query($mysqli,"UPDATE recurring SET recurring_last_sent = CURDATE(), recurring_next_date = DATE_ADD(CURDATE(), INTERVAL 1 $recurring_frequency) , invoice_id = $new_invoice_id WHERE recurring_id = $recurring_id");
|
||||
|
|
|
|||
|
|
@ -346,7 +346,7 @@ var myPieChart = new Chart(ctx, {
|
|||
data: {
|
||||
labels: [
|
||||
<?php
|
||||
$sql_categories = mysqli_query($mysqli,"SELECT DISTINCT category_name FROM categories, expenses WHERE expenses.category_id = categories.category_id AND YEAR(expense_date) = $year");
|
||||
$sql_categories = mysqli_query($mysqli,"SELECT category_name FROM categories, expenses WHERE expenses.category_id = categories.category_id AND YEAR(expense_date) = $year ORDER BY categories.category_name ASC");
|
||||
while($row = mysqli_fetch_array($sql_categories)){
|
||||
$category_name = $row['category_name'];
|
||||
echo "\"$category_name\",";
|
||||
|
|
|
|||
|
|
@ -18,38 +18,48 @@ if(isset($_GET['search'])){
|
|||
|
||||
<?php $sql = mysqli_query($mysqli,"SELECT * FROM clients WHERE client_name LIKE '%$search%' $orderby $order LIMIT 10"); ?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<h6 class="ml-3"><i class="fa fa-users mr-2"></i>Clients</h6>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<div class="row">
|
||||
<form>
|
||||
<div class="col-2">
|
||||
|
||||
|
||||
<form>
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-3">
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" placeholder="Search clients..." name="search">
|
||||
<input type="text" class="form-control form-control-sm" placeholder="Search clients..." name="search">
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-dark" type="submit"><i class="fa fa-search"></i></button>
|
||||
<button class="btn btn-sm btn-primary" type="submit"><i class="fa fa-search"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-2">
|
||||
|
||||
<div class="form-group col-md-2">
|
||||
<div class="input-group">
|
||||
<select class="form-control" name="orderby">
|
||||
<option>Sort By</option>
|
||||
<select class="form-control form-control-sm" name="orderby">
|
||||
<option>- Sort By -</option>
|
||||
<option value="client_name">Client Name</option>
|
||||
</select>
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-dark" type="submit" name="sort" value="ASC"><i class="fa fa-arrow-down"></i></button>
|
||||
<button class="btn btn-sm btn-secondary" type="submit" name="sort" value="ASC"><i class="fa fa-arrow-down"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="col-8">
|
||||
<button type="button" class="btn btn-primary mr-auto float-right" data-toggle="modal" data-target="#addClientModal"><i class="fas fa-plus"></i></button>
|
||||
<div class="col-md-7">
|
||||
<button type="button" class="btn btn-sm btn-primary float-right" data-toggle="modal" data-target="#addClientModal"><i class="fas fa-fw fa-user-plus"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
<div class="card-body">
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-borderless table-hover">
|
||||
<thead>
|
||||
|
|
@ -140,7 +150,7 @@ if(isset($_GET['search'])){
|
|||
</nav>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<?php include("add_client_modal.php"); ?>
|
||||
|
|
|
|||
19
invoice.php
19
invoice.php
|
|
@ -33,7 +33,7 @@ if(isset($_GET['invoice_id'])){
|
|||
}
|
||||
$client_website = $row['client_website'];
|
||||
|
||||
$sql_invoice_history = mysqli_query($mysqli,"SELECT * FROM invoice_history WHERE invoice_id = $invoice_id ORDER BY invoice_history_id DESC");
|
||||
$sql_history = mysqli_query($mysqli,"SELECT * FROM history WHERE invoice_id = $invoice_id ORDER BY history_id DESC");
|
||||
|
||||
$sql_payments = mysqli_query($mysqli,"SELECT * FROM payments, accounts WHERE payments.account_id = accounts.account_id AND payments.invoice_id = $invoice_id ORDER BY payments.payment_id DESC");
|
||||
|
||||
|
|
@ -91,7 +91,7 @@ if(isset($_GET['invoice_id'])){
|
|||
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
|
||||
<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; ?>">Recurring</a>
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#addInvoiceRecurringModal<?php echo $invoice_id; ?>">Recurring</a>
|
||||
<a class="dropdown-item" href="post.php?email_invoice=<?php echo $invoice_id; ?>">Send</a>
|
||||
<?php if($invoice_status == 'Draft'){ ?><a class="dropdown-item" href="post.php?mark_invoice_sent=<?php echo $invoice_id; ?>">Mark Sent</a><?php } ?>
|
||||
<?php if($invoice_status !== 'Paid' and $invoice_status !== 'Cancelled'){ ?><a class="dropdown-item" href="#" data-toggle="modal" data-target="#addPaymentModal">Add Payment</a><?php } ?>
|
||||
|
|
@ -299,16 +299,16 @@ if(isset($_GET['invoice_id'])){
|
|||
<tbody>
|
||||
<?php
|
||||
|
||||
while($row = mysqli_fetch_array($sql_invoice_history)){
|
||||
$invoice_history_date = $row['invoice_history_date'];
|
||||
$invoice_history_status = $row['invoice_history_status'];
|
||||
$invoice_history_description = $row['invoice_history_description'];
|
||||
while($row = mysqli_fetch_array($sql_history)){
|
||||
$history_date = $row['history_date'];
|
||||
$history_status = $row['history_status'];
|
||||
$history_description = $row['history_description'];
|
||||
|
||||
?>
|
||||
<tr>
|
||||
<td><?php echo $invoice_history_date; ?></td>
|
||||
<td><?php echo $invoice_history_status; ?></td>
|
||||
<td><?php echo $invoice_history_description; ?></td>
|
||||
<td><?php echo $history_date; ?></td>
|
||||
<td><?php echo $history_status; ?></td>
|
||||
<td><?php echo $history_description; ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
|
@ -364,6 +364,7 @@ if(isset($_GET['invoice_id'])){
|
|||
<?php include("add_payment_modal.php"); ?>
|
||||
<?php include("edit_invoice_modal.php"); ?>
|
||||
<?php include("add_invoice_copy_modal.php"); ?>
|
||||
<?php include("add_invoice_recurring_modal.php"); ?>
|
||||
<?php } ?>
|
||||
|
||||
<?php include("footer.php"); ?>
|
||||
|
|
|
|||
25
invoices.php
25
invoices.php
|
|
@ -52,6 +52,17 @@
|
|||
?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xl-3 col-sm-6 mb-3">
|
||||
<div class="card text-white bg-secondary o-hidden">
|
||||
<div class="card-body">
|
||||
<div class="card-body-icon">
|
||||
<i class="fas fa-fw fa-pencil-ruler"></i>
|
||||
</div>
|
||||
<div class="mr-5"><?php echo $draft_count; ?> Draft <h1>$<?php echo number_format($total_draft,2); ?></h1></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-xl-3 col-sm-6 mb-3">
|
||||
<div class="card text-white bg-warning o-hidden">
|
||||
<div class="card-body">
|
||||
|
|
@ -62,6 +73,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-xl-3 col-sm-6 mb-3">
|
||||
<div class="card text-white bg-primary o-hidden">
|
||||
<div class="card-body">
|
||||
|
|
@ -72,21 +84,12 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xl-3 col-sm-6 mb-3">
|
||||
<div class="card text-white bg-secondary o-hidden">
|
||||
<div class="card-body">
|
||||
<div class="card-body-icon">
|
||||
<i class="fas fa-fw fa-pencil-ruler"></i>
|
||||
</div>
|
||||
<div class="mr-5"><?php echo $draft_count; ?> Draft <h1>$<?php echo number_format($total_draft,2); ?></h1></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-xl-3 col-sm-6 mb-3">
|
||||
<div class="card text-white bg-danger o-hidden">
|
||||
<div class="card-body">
|
||||
<div class="card-body-icon">
|
||||
<i class="fas fa-fw fa-skull-crossbones"></i>
|
||||
<i class="fas fa-fw fa-ban"></i>
|
||||
</div>
|
||||
<div class="mr-5"><?php echo $cancelled_count; ?> Cancelled <h1>$<?php echo number_format($total_cancelled,2); ?></h1></div>
|
||||
</div>
|
||||
|
|
|
|||
181
post.php
181
post.php
|
|
@ -755,7 +755,7 @@ if(isset($_POST['add_invoice'])){
|
|||
$invoice_number = $row['invoice_number'] + 1;
|
||||
mysqli_query($mysqli,"INSERT INTO invoices SET invoice_number = $invoice_number, invoice_date = '$date', invoice_due = '$due', category_id = $category, invoice_status = 'Draft', client_id = $client");
|
||||
$invoice_id = mysqli_insert_id($mysqli);
|
||||
mysqli_query($mysqli,"INSERT INTO invoice_history SET invoice_history_date = CURDATE(), invoice_history_status = 'Draft', invoice_history_description = 'INVOICE added!', invoice_id = $invoice_id");
|
||||
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Draft', history_description = 'INVOICE added!', invoice_id = $invoice_id");
|
||||
$_SESSION['alert_message'] = "Invoice added";
|
||||
|
||||
header("Location: invoice.php?invoice_id=$invoice_id");
|
||||
|
|
@ -798,7 +798,7 @@ if(isset($_POST['add_invoice_copy'])){
|
|||
|
||||
$new_invoice_id = mysqli_insert_id($mysqli);
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO invoice_history SET invoice_history_date = CURDATE(), invoice_history_status = 'Draft', invoice_history_description = 'INVOICE added!', invoice_id = $new_invoice_id");
|
||||
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Draft', history_description = 'INVOICE added!', invoice_id = $new_invoice_id");
|
||||
|
||||
$sql_items = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE invoice_id = $invoice_id");
|
||||
while($row = mysqli_fetch_array($sql_items)){
|
||||
|
|
@ -820,6 +820,43 @@ if(isset($_POST['add_invoice_copy'])){
|
|||
|
||||
}
|
||||
|
||||
if(isset($_POST['add_invoice_recurring'])){
|
||||
|
||||
$invoice_id = intval($_POST['invoice_id']);
|
||||
$recurring_frequency = strip_tags(mysqli_real_escape_string($mysqli,$_POST['frequency']));
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoices WHERE invoice_id = $invoice_id");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
$invoice_date = $row['invoice_date'];
|
||||
$invoice_amount = $row['invoice_amount'];
|
||||
$invoice_note = $row['invoice_note'];
|
||||
$client_id = $row['client_id'];
|
||||
$category_id = $row['category_id'];
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO recurring SET recurring_frequency = '$recurring_frequency', recurring_start_date = DATE_ADD('$invoice_date', INTERVAL 1 $recurring_frequency), recurring_next_date = DATE_ADD('$invoice_date', INTERVAL 1 $recurring_frequency), recurring_status = 1, recurring_amount = '$invoice_amount', recurring_note = '$invoice_note', recurring_created_at = NOW(), category_id = $category_id, client_id = $client_id");
|
||||
|
||||
$recurring_id = mysqli_insert_id($mysqli);
|
||||
|
||||
$sql_items = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE invoice_id = $invoice_id");
|
||||
while($row = mysqli_fetch_array($sql_items)){
|
||||
$item_id = $row['item_id'];
|
||||
$item_name = $row['item_name'];
|
||||
$item_description = $row['item_description'];
|
||||
$item_quantity = $row['item_quantity'];
|
||||
$item_price = $row['item_price'];
|
||||
$item_subtotal = $row['item_subtotal'];
|
||||
$item_tax = $row['item_tax'];
|
||||
$item_total = $row['item_total'];
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO invoice_items SET item_name = '$item_name', item_description = '$item_description', item_quantity = $item_quantity, item_price = '$item_price', item_subtotal = '$item_subtotal', item_tax = '$item_tax', item_total = '$item_total', recurring_id = $recurring_id");
|
||||
}
|
||||
|
||||
$_SESSION['alert_message'] = "Created recurring Invoice from this Invoice";
|
||||
|
||||
header("Location: recurring.php?recurring_id=$recurring_id");
|
||||
|
||||
}
|
||||
|
||||
if(isset($_POST['add_quote'])){
|
||||
|
||||
$client = intval($_POST['client']);
|
||||
|
|
@ -839,7 +876,7 @@ if(isset($_POST['add_quote'])){
|
|||
|
||||
$quote_id = mysqli_insert_id($mysqli);
|
||||
|
||||
//mysqli_query($mysqli,"INSERT INTO invoice_history SET invoice_history_date = CURDATE(), invoice_history_status = 'Draft', invoice_history_description = 'INVOICE added!', invoice_id = $invoice_id");
|
||||
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Draft', history_description = 'Quote created!', quote_id = $quote_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Quote added";
|
||||
|
||||
|
|
@ -874,10 +911,10 @@ if(isset($_GET['delete_quote'])){
|
|||
}
|
||||
|
||||
//Delete History Associated with the Quote
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoice_history WHERE quote_id = $quote_id");
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM history WHERE quote_id = $quote_id");
|
||||
while($row = mysqli_fetch_array($sql)){;
|
||||
$invoice_history_id = $row['invoice_history_id'];
|
||||
mysqli_query($mysqli,"DELETE FROM invoice_history WHERE invoice_history_id = $invoice_history_id");
|
||||
$history_id = $row['history_id'];
|
||||
mysqli_query($mysqli,"DELETE FROM history WHERE history_id = $history_id");
|
||||
}
|
||||
|
||||
$_SESSION['alert_message'] = "Quotes deleted";
|
||||
|
|
@ -907,7 +944,7 @@ if(isset($_POST['add_quote_copy'])){
|
|||
|
||||
$new_quote_id = mysqli_insert_id($mysqli);
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO invoice_history SET invoice_history_date = CURDATE(), invoice_history_status = 'Draft', invoice_history_description = 'Quote copied!', quote_id = $new_quote_id");
|
||||
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Draft', history_description = 'Quote copied!', quote_id = $new_quote_id");
|
||||
|
||||
$sql_items = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE quote_id = $quote_id");
|
||||
while($row = mysqli_fetch_array($sql_items)){
|
||||
|
|
@ -951,7 +988,7 @@ if(isset($_POST['add_quote_to_invoice'])){
|
|||
|
||||
$new_invoice_id = mysqli_insert_id($mysqli);
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO invoice_history SET invoice_history_date = CURDATE(), invoice_history_status = 'Draft', invoice_history_description = 'Quote copied to Invoice!', invoice_id = $new_invoice_id");
|
||||
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Draft', history_description = 'Quote copied to Invoice!', invoice_id = $new_invoice_id");
|
||||
|
||||
$sql_items = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE quote_id = $quote_id");
|
||||
while($row = mysqli_fetch_array($sql_items)){
|
||||
|
|
@ -1047,7 +1084,7 @@ if(isset($_GET['approve_quote'])){
|
|||
|
||||
mysqli_query($mysqli,"UPDATE quotes SET quote_status = 'Approved' WHERE quote_id = $quote_id");
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO invoice_history SET invoice_history_date = CURDATE(), invoice_history_status = 'Approved', invoice_history_description = 'Quote approved!', quote_id = $quote_id");
|
||||
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Approved', history_description = 'Quote approved!', quote_id = $quote_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Quote approved";
|
||||
|
||||
|
|
@ -1061,7 +1098,7 @@ if(isset($_GET['cancel_quote'])){
|
|||
|
||||
mysqli_query($mysqli,"UPDATE quotes SET quote_status = 'Cancelled' WHERE quote_id = $quote_id");
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO invoice_history SET invoice_history_date = CURDATE(), invoice_history_status = 'Cancelled', invoice_history_description = 'Quote cancelled!', quote_id = $quote_id");
|
||||
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Cancelled', history_description = 'Quote cancelled!', quote_id = $quote_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Quote cancelled";
|
||||
|
||||
|
|
@ -1447,7 +1484,7 @@ if(isset($_GET['email_quote'])){
|
|||
$mail->send();
|
||||
echo 'Message has been sent';
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO invoice_history SET invoice_history_date = CURDATE(), invoice_history_status = 'Sent', invoice_history_description = 'Emailed Quote!', quote_id = $quote_id");
|
||||
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Sent', history_description = 'Emailed Quote!', quote_id = $quote_id");
|
||||
|
||||
//Don't change the status to sent if the status is anything but draft
|
||||
if($quote_status == 'Draft'){
|
||||
|
|
@ -1474,13 +1511,11 @@ if(isset($_POST['add_recurring'])){
|
|||
$start_date = strip_tags(mysqli_real_escape_string($mysqli,$_POST['start_date']));
|
||||
$category = intval($_POST['category']);
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO invoices SET category_id = $category, invoice_status = 'Draft', client_id = $client");
|
||||
mysqli_query($mysqli,"INSERT INTO recurring SET recurring_frequency = '$frequency', recurring_next_date = '$start_date', category_id = $category, recurring_status = 1, client_id = $client");
|
||||
|
||||
$invoice_id = mysqli_insert_id($mysqli);
|
||||
$recurring_id = mysqli_insert_id($mysqli);
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO recurring SET recurring_frequency = '$frequency', recurring_start_date = '$start_date', recurring_next_date = '$start_date', recurring_status = 1, invoice_id = $invoice_id");
|
||||
|
||||
$recurring_invoice_id = mysqli_insert_id($mysqli);
|
||||
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_description = 'Reccuring Invoice created!', recurring_id = $recurring_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Recurring Invoice added";
|
||||
|
||||
|
|
@ -1488,6 +1523,44 @@ if(isset($_POST['add_recurring'])){
|
|||
|
||||
}
|
||||
|
||||
if(isset($_GET['delete_recurring'])){
|
||||
$recurring_id = intval($_GET['delete_recurring']);
|
||||
|
||||
mysqli_query($mysqli,"DELETE FROM recurring WHERE recurring_id = $recurring_id");
|
||||
|
||||
//Delete Items Associated with the Recurring
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE recurring_id = $recurring_id");
|
||||
while($row = mysqli_fetch_array($sql)){;
|
||||
$item_id = $row['item_id'];
|
||||
mysqli_query($mysqli,"DELETE FROM invoice_items WHERE item_id = $item_id");
|
||||
}
|
||||
|
||||
//Delete History Associated with the Invoice
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM history WHERE recurring_id = $recurring_id");
|
||||
while($row = mysqli_fetch_array($sql)){;
|
||||
$history_id = $row['history_id'];
|
||||
mysqli_query($mysqli,"DELETE FROM history WHERE history_id = $history_id");
|
||||
}
|
||||
|
||||
$_SESSION['alert_message'] = "Recurring Invoice deleted";
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
|
||||
}
|
||||
|
||||
if(isset($_POST['edit_recurring_note'])){
|
||||
|
||||
$recurring_id = intval($_POST['recurring_id']);
|
||||
$recurring_note = strip_tags(mysqli_real_escape_string($mysqli,$_POST['recurring_note']));
|
||||
|
||||
mysqli_query($mysqli,"UPDATE recurring SET recurring_note = '$recurring_note' WHERE recurring_id = $recurring_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Notes added";
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
|
||||
}
|
||||
|
||||
if(isset($_GET['recurring_activate'])){
|
||||
|
||||
$recurring_id = intval($_GET['recurring_activate']);
|
||||
|
|
@ -1512,13 +1585,69 @@ if(isset($_GET['recurring_deactivate'])){
|
|||
|
||||
}
|
||||
|
||||
if(isset($_POST['add_recurring_item'])){
|
||||
|
||||
$recurring_id = intval($_POST['recurring_id']);
|
||||
$name = strip_tags(mysqli_real_escape_string($mysqli,$_POST['name']));
|
||||
$description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description']));
|
||||
$qty = $_POST['qty'];
|
||||
$price = $_POST['price'];
|
||||
$tax = $_POST['tax'];
|
||||
|
||||
$subtotal = $price * $qty;
|
||||
$tax = $subtotal * $tax;
|
||||
$total = $subtotal + $tax;
|
||||
|
||||
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', item_total = '$total', recurring_id = $recurring_id");
|
||||
|
||||
//Update Invoice Balances
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM recurring WHERE recurring_id = $recurring_id");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
|
||||
$new_recurring_amount = $row['recurring_amount'] + $total;
|
||||
|
||||
mysqli_query($mysqli,"UPDATE recurring SET recurring_amount = '$new_recurring_amount' WHERE recurring_id = $recurring_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Item added";
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
|
||||
}
|
||||
|
||||
if(isset($_GET['delete_recurring_item'])){
|
||||
$item_id = intval($_GET['delete_recurring_item']);
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE item_id = $item_id");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
$recurring_id = $row['recurring_id'];
|
||||
$item_subtotal = $row['item_subtotal'];
|
||||
$item_tax = $row['item_tax'];
|
||||
$item_total = $row['item_total'];
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM recurring WHERE recurring_id = $recurring_id");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
|
||||
$new_recurring_amount = $row['recurring_amount'] - $item_total;
|
||||
|
||||
mysqli_query($mysqli,"UPDATE recurring SET recurring_amount = '$new_recurring_amount' WHERE recurring_id = $recurring_id");
|
||||
|
||||
mysqli_query($mysqli,"DELETE FROM invoice_items WHERE item_id = $item_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Item deleted";
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(isset($_GET['mark_invoice_sent'])){
|
||||
|
||||
$invoice_id = intval($_GET['mark_invoice_sent']);
|
||||
|
||||
mysqli_query($mysqli,"UPDATE invoices SET invoice_status = 'Sent' WHERE invoice_id = $invoice_id");
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO invoice_history SET invoice_history_date = CURDATE(), invoice_history_status = 'Sent', invoice_history_description = 'INVOICE marked sent', invoice_id = $invoice_id");
|
||||
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Sent', history_description = 'INVOICE marked sent', invoice_id = $invoice_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Invoice marked sent";
|
||||
|
||||
|
|
@ -1532,7 +1661,7 @@ if(isset($_GET['cancel_invoice'])){
|
|||
|
||||
mysqli_query($mysqli,"UPDATE invoices SET invoice_status = 'Cancelled' WHERE invoice_id = $invoice_id");
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO invoice_history SET invoice_history_date = CURDATE(), invoice_history_status = 'Cancelled', invoice_history_description = 'INVOICE cancelled!', invoice_id = $invoice_id");
|
||||
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Cancelled', history_description = 'INVOICE cancelled!', invoice_id = $invoice_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Invoice cancelled";
|
||||
|
||||
|
|
@ -1553,10 +1682,10 @@ if(isset($_GET['delete_invoice'])){
|
|||
}
|
||||
|
||||
//Delete History Associated with the Invoice
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoice_history WHERE invoice_id = $invoice_id");
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM history WHERE invoice_id = $invoice_id");
|
||||
while($row = mysqli_fetch_array($sql)){;
|
||||
$invoice_history_id = $row['invoice_history_id'];
|
||||
mysqli_query($mysqli,"DELETE FROM invoice_history WHERE invoice_history_id = $invoice_history_id");
|
||||
$history_id = $row['history_id'];
|
||||
mysqli_query($mysqli,"DELETE FROM history WHERE history_id = $history_id");
|
||||
}
|
||||
|
||||
//Delete Payments Associated with the Invoice
|
||||
|
|
@ -1697,7 +1826,7 @@ if(isset($_POST['add_payment'])){
|
|||
$mail->send();
|
||||
echo 'Message has been sent';
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO invoice_history SET invoice_history_date = CURDATE(), invoice_history_status = 'Sent', invoice_history_description = 'Emailed Receipt!', invoice_id = $invoice_id");
|
||||
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Sent', history_description = 'Emailed Receipt!', invoice_id = $invoice_id");
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
|
||||
|
|
@ -1737,7 +1866,7 @@ if(isset($_POST['add_payment'])){
|
|||
$mail->send();
|
||||
echo 'Message has been sent';
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO invoice_history SET invoice_history_date = CURDATE(), invoice_history_status = 'Sent', invoice_history_description = 'Emailed Receipt!', invoice_id = $invoice_id");
|
||||
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Sent', history_description = 'Emailed Receipt!', invoice_id = $invoice_id");
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
|
||||
|
|
@ -1750,7 +1879,7 @@ if(isset($_POST['add_payment'])){
|
|||
mysqli_query($mysqli,"UPDATE invoices SET invoice_status = '$invoice_status' WHERE invoice_id = $invoice_id");
|
||||
|
||||
//Add Payment to History
|
||||
mysqli_query($mysqli,"INSERT INTO invoice_history SET invoice_history_date = CURDATE(), invoice_history_status = '$invoice_status', invoice_history_description = 'INVOICE payment added', invoice_id = $invoice_id");
|
||||
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = '$invoice_status', history_description = 'INVOICE payment added', invoice_id = $invoice_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Payment added";
|
||||
|
||||
|
|
@ -1790,7 +1919,7 @@ if(isset($_GET['delete_payment'])){
|
|||
mysqli_query($mysqli,"UPDATE invoices SET invoice_status = '$invoice_status' WHERE invoice_id = $invoice_id");
|
||||
|
||||
//Add Payment to History
|
||||
mysqli_query($mysqli,"INSERT INTO invoice_history SET invoice_history_date = CURDATE(), invoice_history_status = '$invoice_status', invoice_history_description = 'INVOICE payment deleted', invoice_id = $invoice_id");
|
||||
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = '$invoice_status', history_description = 'INVOICE payment deleted', invoice_id = $invoice_id");
|
||||
|
||||
mysqli_query($mysqli,"DELETE FROM payments WHERE payment_id = $payment_id");
|
||||
|
||||
|
|
@ -2032,7 +2161,7 @@ if(isset($_GET['email_invoice'])){
|
|||
$mail->send();
|
||||
echo 'Message has been sent';
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO invoice_history SET invoice_history_date = CURDATE(), invoice_history_status = 'Sent', invoice_history_description = 'Emailed Invoice!', invoice_id = $invoice_id");
|
||||
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Sent', history_description = 'Emailed Invoice!', invoice_id = $invoice_id");
|
||||
|
||||
//Don't chnage the status to sent if the status is anything but draf
|
||||
if($invoice_status == 'Draft'){
|
||||
|
|
|
|||
16
quote.php
16
quote.php
|
|
@ -32,7 +32,7 @@ if(isset($_GET['quote_id'])){
|
|||
}
|
||||
$client_website = $row['client_website'];
|
||||
|
||||
$sql_invoice_history = mysqli_query($mysqli,"SELECT * FROM invoice_history WHERE quote_id = $quote_id ORDER BY invoice_history_id DESC");
|
||||
$sql_history = mysqli_query($mysqli,"SELECT * FROM history WHERE quote_id = $quote_id ORDER BY history_id DESC");
|
||||
|
||||
//Set Badge color based off of quote status
|
||||
if($quote_status == "Sent"){
|
||||
|
|
@ -267,16 +267,16 @@ if(isset($_GET['quote_id'])){
|
|||
<tbody>
|
||||
<?php
|
||||
|
||||
while($row = mysqli_fetch_array($sql_invoice_history)){
|
||||
$invoice_history_date = $row['invoice_history_date'];
|
||||
$invoice_history_status = $row['invoice_history_status'];
|
||||
$invoice_history_description = $row['invoice_history_description'];
|
||||
while($row = mysqli_fetch_array($sql_history)){
|
||||
$history_date = $row['history_date'];
|
||||
$history_status = $row['history_status'];
|
||||
$history_description = $row['history_description'];
|
||||
|
||||
?>
|
||||
<tr>
|
||||
<td><?php echo $invoice_history_date; ?></td>
|
||||
<td><?php echo $invoice_history_status; ?></td>
|
||||
<td><?php echo $invoice_history_description; ?></td>
|
||||
<td><?php echo $history_date; ?></td>
|
||||
<td><?php echo $history_status; ?></td>
|
||||
<td><?php echo $history_description; ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,9 @@
|
|||
|
||||
<?php
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM recurring, invoices, clients, categories
|
||||
WHERE invoices.client_id = clients.client_id
|
||||
AND invoices.invoice_id = recurring.invoice_id
|
||||
AND invoices.category_id = categories.category_id
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM recurring, clients, categories
|
||||
WHERE recurring.client_id = clients.client_id
|
||||
AND recurring.category_id = categories.category_id
|
||||
ORDER BY recurring.recurring_id DESC");
|
||||
?>
|
||||
|
||||
|
|
@ -21,7 +20,6 @@
|
|||
<tr>
|
||||
<th>Frequency</th>
|
||||
<th>Client</th>
|
||||
<th>Start Date</th>
|
||||
<th>Last Sent</th>
|
||||
<th>Next Date</th>
|
||||
<th>Category</th>
|
||||
|
|
@ -36,7 +34,6 @@
|
|||
$recurring_id = $row['recurring_id'];
|
||||
$recurring_frequency = $row['recurring_frequency'];
|
||||
$recurring_status = $row['recurring_status'];
|
||||
$recurring_start_date = $row['recurring_start_date'];
|
||||
$recurring_last_sent = $row['recurring_last_sent'];
|
||||
if($recurring_last_sent == 0){
|
||||
$recurring_last_sent = "-";
|
||||
|
|
@ -44,7 +41,6 @@
|
|||
$recurring_next_date = $row['recurring_next_date'];
|
||||
$client_id = $row['client_id'];
|
||||
$client_name = $row['client_name'];
|
||||
$invoice_id = $row['invoice_id'];
|
||||
$category_id = $row['category_id'];
|
||||
$category_name = $row['category_name'];
|
||||
if($recurring_status == 1){
|
||||
|
|
@ -55,13 +51,11 @@
|
|||
$status_badge_color = "secondary";
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
<tr>
|
||||
<td><?php echo ucwords($recurring_frequency); ?>ly</td>
|
||||
<td><a href="client.php?client_id=<?php echo $client_id; ?>"><?php echo $client_name; ?></a></td>
|
||||
<td><?php echo $recurring_start_date; ?></td>
|
||||
<td><?php echo $recurring_last_sent; ?></td>
|
||||
<td><?php echo $recurring_next_date; ?></td>
|
||||
<td><?php echo $category_name; ?></td>
|
||||
|
|
@ -83,7 +77,7 @@
|
|||
<?php }else{ ?>
|
||||
<a class="dropdown-item" href="post.php?recurring_activate=<?php echo $recurring_id; ?>">Activate</a>
|
||||
<?php } ?>
|
||||
<a class="dropdown-item" href="post.php?delete_invoice=<?php echo $invoice_id; ?>">Delete</a>
|
||||
<a class="dropdown-item" href="post.php?delete_recurring=<?php echo $recurring_id; ?>">Delete</a>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
|
|
|
|||
|
|
@ -6,9 +6,8 @@ if(isset($_GET['recurring_id'])){
|
|||
|
||||
$recurring_id = intval($_GET['recurring_id']);
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoices, clients, recurring
|
||||
WHERE invoices.client_id = clients.client_id
|
||||
AND invoices.invoice_id = recurring.invoice_id
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM clients, recurring
|
||||
WHERE recurring.client_id = clients.client_id
|
||||
AND recurring.recurring_id = $recurring_id"
|
||||
);
|
||||
|
||||
|
|
@ -22,11 +21,9 @@ if(isset($_GET['recurring_id'])){
|
|||
$recurring_last_sent = '-';
|
||||
}
|
||||
$recurring_next_date = $row['recurring_next_date'];
|
||||
$invoice_id = $row['invoice_id'];
|
||||
$invoice_status = $row['invoice_status'];
|
||||
$invoice_amount = $row['invoice_amount'];
|
||||
$invoice_note = $row['invoice_note'];
|
||||
$invoice_category_id = $row['category_id'];
|
||||
$recurring_amount = $row['recurring_amount'];
|
||||
$recurring_note = $row['recurring_note'];
|
||||
$category_id = $row['category_id'];
|
||||
$client_id = $row['client_id'];
|
||||
$client_name = $row['client_name'];
|
||||
$client_address = $row['client_address'];
|
||||
|
|
@ -49,16 +46,7 @@ if(isset($_GET['recurring_id'])){
|
|||
$status_badge_color = "secondary";
|
||||
}
|
||||
|
||||
$sql_invoice_history = mysqli_query($mysqli,"SELECT * FROM invoice_history WHERE invoice_id = $invoice_id ORDER BY invoice_history_id ASC");
|
||||
|
||||
$sql_payments = mysqli_query($mysqli,"SELECT * FROM payments, accounts WHERE payments.account_id = accounts.account_id AND payments.invoice_id = $invoice_id ORDER BY payments.payment_id DESC");
|
||||
|
||||
//Add up all the payments for the invoice and get the total amount paid to the invoice
|
||||
$sql_amount_paid = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS amount_paid FROM payments WHERE invoice_id = $invoice_id");
|
||||
$row = mysqli_fetch_array($sql_amount_paid);
|
||||
$amount_paid = $row['amount_paid'];
|
||||
|
||||
$balance = $invoice_amount - $amount_paid;
|
||||
$sql_history = mysqli_query($mysqli,"SELECT * FROM history WHERE recurring_id = $recurring_id ORDER BY history_id DESC");
|
||||
|
||||
?>
|
||||
|
||||
|
|
@ -83,7 +71,7 @@ if(isset($_GET['recurring_id'])){
|
|||
<?php }else{ ?>
|
||||
<a class="dropdown-item" href="post.php?recurring_activate=<?php echo $recurring_id; ?>">Activate</a>
|
||||
<?php } ?>
|
||||
<a class="dropdown-item" href="#">Delete</a>
|
||||
<a class="dropdown-item" href="post.php?delete_recurring=<?php echo $recurring_id; ?>">Delete</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -140,7 +128,7 @@ if(isset($_GET['recurring_id'])){
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<?php $sql_items = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE invoice_id = $invoice_id ORDER BY item_id ASC"); ?>
|
||||
<?php $sql_items = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE recurring_id = $recurring_id ORDER BY item_id ASC"); ?>
|
||||
|
||||
<div class="row mb-4">
|
||||
<div class="col-md-12">
|
||||
|
|
@ -179,7 +167,7 @@ if(isset($_GET['recurring_id'])){
|
|||
?>
|
||||
|
||||
<tr>
|
||||
<td class="text-center d-print-none"><a class="btn btn-danger btn-sm" href="post.php?delete_invoice_item=<?php echo $item_id; ?>"><i class="fa fa-trash"></i></a></td>
|
||||
<td class="text-center d-print-none"><a class="btn btn-danger btn-sm" href="post.php?delete_recurring_item=<?php echo $item_id; ?>"><i class="fa fa-trash"></i></a></td>
|
||||
<td><?php echo $item_name; ?></td>
|
||||
<td><?php echo $item_description; ?></td>
|
||||
<td class="text-right">$<?php echo number_format($item_price,2); ?></td>
|
||||
|
|
@ -196,8 +184,8 @@ if(isset($_GET['recurring_id'])){
|
|||
|
||||
<tr class="d-print-none">
|
||||
<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 class="text-center"><button type="submit" class="btn btn-primary btn-sm" name="add_recurring_item"><i class="fa fa-check"></i></button></td>
|
||||
<input type="hidden" name="recurring_id" value="<?php echo $recurring_id; ?>">
|
||||
<td><input type="text" class="form-control" name="name"></td>
|
||||
<td><textarea class="form-control" rows="1" name="description"></textarea></td>
|
||||
<td><input type="text" class="form-control" style="text-align: right;" name="price"></td>
|
||||
|
|
@ -224,11 +212,11 @@ if(isset($_GET['recurring_id'])){
|
|||
Notes
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="d-none d-print-block"><?php echo $invoice_note; ?></div>
|
||||
<div class="d-none d-print-block"><?php echo $recurring_note; ?></div>
|
||||
<form class="d-print-none" action="post.php" method="post">
|
||||
<input type="hidden" name="invoice_id" value="<?php echo $invoice_id; ?>">
|
||||
<textarea rows="6" class="form-control mb-2" name="invoice_note"><?php echo $invoice_note; ?></textarea>
|
||||
<button class="btn btn-primary btn-sm float-right" type="submit" name="edit_invoice_note"><i class="fa fa-fw fa-check"></i></button>
|
||||
<input type="hidden" name="recurring_id" value="<?php echo $recurring_id; ?>">
|
||||
<textarea rows="6" class="form-control mb-2" name="recurring_note"><?php echo $recurring_note; ?></textarea>
|
||||
<button class="btn btn-primary btn-sm float-right" type="submit" name="edit_recurring_note"><i class="fa fa-fw fa-check"></i></button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -252,15 +240,9 @@ if(isset($_GET['recurring_id'])){
|
|||
<td class="text-right">$<?php echo number_format($total_tax,2); ?></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<?php if($amount_paid > 0){ ?>
|
||||
<tr class="border-bottom">
|
||||
<td><div class="text-success">Paid to Date</div></td>
|
||||
<td class="text-right text-success">$<?php echo number_format($amount_paid,2); ?></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<tr class="border-bottom">
|
||||
<td><strong>Balance Due</strong></td>
|
||||
<td class="text-right"><strong>$<?php echo number_format($balance,2); ?></strong></td>
|
||||
<td><strong>Amount</strong></td>
|
||||
<td class="text-right"><strong>$<?php echo number_format($recurring_amount,2); ?></strong></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
@ -277,22 +259,22 @@ if(isset($_GET['recurring_id'])){
|
|||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Date Sent</th>
|
||||
<th>Invoice Number</th>
|
||||
<th>Date</th>
|
||||
<th>Event</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
|
||||
while($row = mysqli_fetch_array($sql_invoice_history)){
|
||||
$invoice_history_date = $row['invoice_history_date'];
|
||||
$invoice_history_status = $row['invoice_history_status'];
|
||||
$invoice_history_description = $row['invoice_history_description'];
|
||||
while($row = mysqli_fetch_array($sql_history)){
|
||||
$history_date = $row['history_date'];
|
||||
$history_status = $row['history_status'];
|
||||
$history_description = $row['history_description'];
|
||||
|
||||
?>
|
||||
<tr>
|
||||
<td><?php echo $invoice_history_date; ?></td>
|
||||
<td><?php echo $invoice_history_description; ?></td>
|
||||
<td><?php echo $history_date; ?></td>
|
||||
<td><?php echo $history_description; ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
|
@ -305,7 +287,7 @@ if(isset($_GET['recurring_id'])){
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<?php include("edit_invoice_modal.php"); ?>
|
||||
<?php include("edit_recurring_modal.php"); ?>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue