mirror of
https://github.com/itflow-org/itflow
synced 2026-02-28 02:44:53 +00:00
Added Tax ID to each line item, also if tax % changes the new recurring will automatically get updated and sent with the right tax rate DB Structure updated
This commit is contained in:
38
cron.php
38
cron.php
@@ -167,6 +167,7 @@ while($row = mysqli_fetch_array($sql_companies)){
|
|||||||
|
|
||||||
//Send Recurring Invoices that match todays date and are active
|
//Send Recurring Invoices that match todays date and are active
|
||||||
|
|
||||||
|
//Loop through all recurring that match today's date and is active
|
||||||
$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 AND recurring.company_id = $company_id");
|
$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 AND recurring.company_id = $company_id");
|
||||||
|
|
||||||
while($row = mysqli_fetch_array($sql_recurring)){
|
while($row = mysqli_fetch_array($sql_recurring)){
|
||||||
@@ -199,7 +200,7 @@ while($row = mysqli_fetch_array($sql_companies)){
|
|||||||
|
|
||||||
$new_invoice_id = mysqli_insert_id($mysqli);
|
$new_invoice_id = mysqli_insert_id($mysqli);
|
||||||
|
|
||||||
//Copy Items from original invoice to new invoice
|
//Copy Items from original recurring invoice to new invoice
|
||||||
$sql_invoice_items = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE recurring_id = $recurring_id ORDER BY item_id ASC");
|
$sql_invoice_items = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE recurring_id = $recurring_id ORDER BY item_id ASC");
|
||||||
|
|
||||||
while($row = mysqli_fetch_array($sql_invoice_items)){
|
while($row = mysqli_fetch_array($sql_invoice_items)){
|
||||||
@@ -208,17 +209,40 @@ while($row = mysqli_fetch_array($sql_companies)){
|
|||||||
$item_description = mysqli_real_escape_string($mysqli,$row['item_description']); //SQL Escape incase of ,
|
$item_description = mysqli_real_escape_string($mysqli,$row['item_description']); //SQL Escape incase of ,
|
||||||
$item_quantity = $row['item_quantity'];
|
$item_quantity = $row['item_quantity'];
|
||||||
$item_price = $row['item_price'];
|
$item_price = $row['item_price'];
|
||||||
$item_subtotal = $row['item_price'];
|
$item_subtotal = $row['item_subtotal'];
|
||||||
$item_tax = $row['item_tax'];
|
$tax_id = $row['tax_id'];
|
||||||
$item_total = $row['item_total'];
|
|
||||||
|
//Recalculate Item Tax since Tax percents can change.
|
||||||
|
if($tax_id > 0){
|
||||||
|
$sql = mysqli_query($mysqli,"SELECT * FROM taxes WHERE tax_id = $tax_id AND company_id = $company_id");
|
||||||
|
$row = mysqli_fetch_array($sql);
|
||||||
|
$tax_percent = $row['tax_percent'];
|
||||||
|
$item_tax_amount = $item_subtotal * $tax_percent / 100;
|
||||||
|
}else{
|
||||||
|
$item_tax_amount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$item_total = $item_subtotal + $item_tax_amount;
|
||||||
|
|
||||||
|
//Update Recurring Items with new tax
|
||||||
|
mysqli_query($mysqli,"UPDATE invoice_items SET item_tax = '$item_tax_amount', item_total = '$item_total', item_updated_at = NOW(), tax_id = $tax_id WHERE item_id = $item_id");
|
||||||
|
|
||||||
|
//Insert Items into New Invoice
|
||||||
|
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_amount', item_total = '$item_total', item_created_at = NOW(), tax_id = $tax_id, invoice_id = $new_invoice_id, company_id = $company_id");
|
||||||
|
|
||||||
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', item_created_at = NOW(), invoice_id = $new_invoice_id, company_id = $company_id");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Sent', history_description = 'Invoice Generated from Recurring!', history_created_at = NOW(), invoice_id = $new_invoice_id, company_id = $company_id");
|
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Sent', history_description = 'Invoice Generated from Recurring!', history_created_at = NOW(), invoice_id = $new_invoice_id, company_id = $company_id");
|
||||||
|
|
||||||
//update the recurring invoice with the new dates
|
//Update Recurring Balances by tallying up recurring items also update recurring dates
|
||||||
mysqli_query($mysqli,"UPDATE recurring SET recurring_last_sent = CURDATE(), recurring_next_date = DATE_ADD(CURDATE(), INTERVAL 1 $recurring_frequency), recurring_updated_at = NOW() WHERE recurring_id = $recurring_id");
|
$sql_recurring_total = mysqli_query($mysqli,"SELECT SUM(item_total) AS recurring_total FROM invoice_items WHERE recurring_id = $recurring_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_last_sent = CURDATE(), recurring_next_date = DATE_ADD(CURDATE(), INTERVAL 1 $recurring_frequency), recurring_updated_at = NOW() WHERE recurring_id = $recurring_id");
|
||||||
|
|
||||||
|
//Also update the newly created invoice with the new amounts
|
||||||
|
mysqli_query($mysqli,"UPDATE invoices SET invoice_amount = '$new_recurring_amount' WHERE invoice_id = $new_invoice_id");
|
||||||
|
|
||||||
if($config_recurring_auto_send_invoice == 1){
|
if($config_recurring_auto_send_invoice == 1){
|
||||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoices, clients
|
$sql = mysqli_query($mysqli,"SELECT * FROM invoices, clients
|
||||||
|
|||||||
3
db.sql
3
db.sql
@@ -379,6 +379,7 @@ CREATE TABLE `invoice_items` (
|
|||||||
`item_total` decimal(15,2) NOT NULL,
|
`item_total` decimal(15,2) NOT NULL,
|
||||||
`item_created_at` datetime NOT NULL,
|
`item_created_at` datetime NOT NULL,
|
||||||
`item_updated_at` datetime DEFAULT NULL,
|
`item_updated_at` datetime DEFAULT NULL,
|
||||||
|
`tax_id` int(11) DEFAULT NULL,
|
||||||
`quote_id` int(11) DEFAULT NULL,
|
`quote_id` int(11) DEFAULT NULL,
|
||||||
`recurring_id` int(11) DEFAULT NULL,
|
`recurring_id` int(11) DEFAULT NULL,
|
||||||
`invoice_id` int(11) DEFAULT NULL,
|
`invoice_id` int(11) DEFAULT NULL,
|
||||||
@@ -928,4 +929,4 @@ CREATE TABLE `vendors` (
|
|||||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||||
|
|
||||||
-- Dump completed on 2021-02-04 21:53:53
|
-- Dump completed on 2021-02-06 0:17:15
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<div class="modal" id="editInvoiceItemModal<?php echo $item_id; ?>" tabindex="-1">
|
<div class="modal" id="editInvoiceItemModal<?php echo $item_id; ?>" tabindex="-1">
|
||||||
<div class="modal-dialog">
|
<div class="modal-dialog">
|
||||||
<div class="modal-content bg-dark">
|
<div class="modal-content bg-dark">
|
||||||
<div class="modal-header text-white">
|
<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>
|
<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">
|
<button type="button" class="close text-white" data-dismiss="modal">
|
||||||
<span aria-hidden="true">×</span>
|
<span>×</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<form action="post.php" method="post" autocomplete="off">
|
<form action="post.php" method="post" autocomplete="off">
|
||||||
@@ -66,17 +66,17 @@
|
|||||||
<div class="input-group-prepend">
|
<div class="input-group-prepend">
|
||||||
<span class="input-group-text"><i class="fa fa-fw fa-piggy-bank"></i></span>
|
<span class="input-group-text"><i class="fa fa-fw fa-piggy-bank"></i></span>
|
||||||
</div>
|
</div>
|
||||||
<select class="form-control select2" name="tax" required>
|
<select class="form-control select2" name="tax_id" required>
|
||||||
<option value="0.00">None</option>
|
<option value="0">None</option>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$taxes_sql = mysqli_query($mysqli,"SELECT * FROM taxes WHERE company_id = $session_company_id ORDER BY tax_name ASC");
|
$taxes_sql = mysqli_query($mysqli,"SELECT * FROM taxes WHERE company_id = $session_company_id ORDER BY tax_name ASC");
|
||||||
while($row = mysqli_fetch_array($taxes_sql)){
|
while($row = mysqli_fetch_array($taxes_sql)){
|
||||||
$tax_id = $row['tax_id'];
|
$tax_id_select = $row['tax_id'];
|
||||||
$tax_name = $row['tax_name'];
|
$tax_name = $row['tax_name'];
|
||||||
$tax_percent = $row['tax_percent'];
|
$tax_percent = $row['tax_percent'];
|
||||||
?>
|
?>
|
||||||
<option value="<?php echo "$tax_percent"; ?>"><?php echo "$tax_name $tax_percent%"; ?></option>
|
<option <?php if($tax_id_select == $tax_id){ echo "selected"; } ?> value="<?php echo $tax_id_select; ?>"><?php echo "$tax_name $tax_percent%"; ?></option>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<div class="modal" id="editQuoteItemModal<?php echo $item_id; ?>" tabindex="-1">
|
<div class="modal" id="editQuoteItemModal<?php echo $item_id; ?>" tabindex="-1">
|
||||||
<div class="modal-dialog">
|
<div class="modal-dialog">
|
||||||
<div class="modal-content bg-dark">
|
<div class="modal-content bg-dark">
|
||||||
<div class="modal-header text-white">
|
<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>
|
<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">
|
<button type="button" class="close text-white" data-dismiss="modal">
|
||||||
<span>×</span>
|
<span>×</span>
|
||||||
@@ -67,17 +67,17 @@
|
|||||||
<div class="input-group-prepend">
|
<div class="input-group-prepend">
|
||||||
<span class="input-group-text"><i class="fa fa-fw fa-piggy-bank"></i></span>
|
<span class="input-group-text"><i class="fa fa-fw fa-piggy-bank"></i></span>
|
||||||
</div>
|
</div>
|
||||||
<select class="form-control select2" name="tax" required>
|
<select class="form-control select2" name="tax_id" required>
|
||||||
<option value="0.00">None</option>
|
<option value="0">None</option>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$taxes_sql = mysqli_query($mysqli,"SELECT * FROM taxes WHERE company_id = $session_company_id ORDER BY tax_name ASC");
|
$taxes_sql = mysqli_query($mysqli,"SELECT * FROM taxes WHERE company_id = $session_company_id ORDER BY tax_name ASC");
|
||||||
while($row = mysqli_fetch_array($taxes_sql)){
|
while($row = mysqli_fetch_array($taxes_sql)){
|
||||||
$tax_id = $row['tax_id'];
|
$tax_id_select = $row['tax_id'];
|
||||||
$tax_name = $row['tax_name'];
|
$tax_name = $row['tax_name'];
|
||||||
$tax_percent = $row['tax_percent'];
|
$tax_percent = $row['tax_percent'];
|
||||||
?>
|
?>
|
||||||
<option value="<?php echo "$tax_percent"; ?>"><?php echo "$tax_name $tax_percent%"; ?></option>
|
<option <?php if($tax_id_select == $tax_id){ echo "selected"; } ?> value="<?php echo $tax_id_select; ?>"><?php echo "$tax_name $tax_percent%"; ?></option>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<div class="modal" id="editRecurringItemModal<?php echo $item_id; ?>" tabindex="-1">
|
<div class="modal" id="editRecurringItemModal<?php echo $item_id; ?>" tabindex="-1">
|
||||||
<div class="modal-dialog">
|
<div class="modal-dialog">
|
||||||
<div class="modal-content bg-dark">
|
<div class="modal-content bg-dark">
|
||||||
<div class="modal-header text-white">
|
<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>
|
<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">
|
<button type="button" class="close text-white" data-dismiss="modal">
|
||||||
<span>×</span>
|
<span>×</span>
|
||||||
</button>
|
</button>
|
||||||
@@ -67,17 +67,17 @@
|
|||||||
<div class="input-group-prepend">
|
<div class="input-group-prepend">
|
||||||
<span class="input-group-text"><i class="fa fa-fw fa-piggy-bank"></i></span>
|
<span class="input-group-text"><i class="fa fa-fw fa-piggy-bank"></i></span>
|
||||||
</div>
|
</div>
|
||||||
<select class="form-control select2" name="tax" required>
|
<select class="form-control select2" name="tax_id" required>
|
||||||
<option value="0.00">None</option>
|
<option value="0.00">None</option>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$taxes_sql = mysqli_query($mysqli,"SELECT * FROM taxes WHERE company_id = $session_company_id ORDER BY tax_name ASC");
|
$taxes_sql = mysqli_query($mysqli,"SELECT * FROM taxes WHERE company_id = $session_company_id ORDER BY tax_name ASC");
|
||||||
while($row = mysqli_fetch_array($taxes_sql)){
|
while($row = mysqli_fetch_array($taxes_sql)){
|
||||||
$tax_id = $row['tax_id'];
|
$tax_id_select = $row['tax_id'];
|
||||||
$tax_name = $row['tax_name'];
|
$tax_name = $row['tax_name'];
|
||||||
$tax_percent = $row['tax_percent'];
|
$tax_percent = $row['tax_percent'];
|
||||||
?>
|
?>
|
||||||
<option value="<?php echo "$tax_percent"; ?>"><?php echo "$tax_name $tax_percent%"; ?></option>
|
<option <?php if($tax_id_select == $tax_id){ echo "selected"; } ?> value="<?php echo $tax_id_select; ?>"><?php echo "$tax_name $tax_percent%"; ?></option>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -341,7 +341,7 @@ if(isset($_GET['invoice_id'], $_GET['url_key'])){
|
|||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoices WHERE client_id = $client_id AND invoice_due > CURDATE() AND(invoice_status = 'Sent' OR invoice_status = 'Viewed' OR invoice_status = 'Partial') ORDER BY invoice_date DESC");
|
$sql = mysqli_query($mysqli,"SELECT * FROM invoices WHERE client_id = $client_id AND invoice_due > CURDATE() AND(invoice_status = 'Sent' OR invoice_status = 'Viewed' OR invoice_status = 'Partial') ORDER BY invoice_number DESC");
|
||||||
|
|
||||||
if(mysqli_num_rows($sql) > 1){
|
if(mysqli_num_rows($sql) > 1){
|
||||||
|
|
||||||
@@ -382,7 +382,7 @@ if(isset($_GET['invoice_id'], $_GET['url_key'])){
|
|||||||
<th class="text-center"><a href="guest_view_invoice.php?invoice_id=<?php echo $invoice_id; ?>&url_key=<?php echo $invoice_url_key; ?>"><?php echo $invoice_number; ?></a></th>
|
<th class="text-center"><a href="guest_view_invoice.php?invoice_id=<?php echo $invoice_id; ?>&url_key=<?php echo $invoice_url_key; ?>"><?php echo $invoice_number; ?></a></th>
|
||||||
<td><?php echo $invoice_date; ?></td>
|
<td><?php echo $invoice_date; ?></td>
|
||||||
<td><?php echo $invoice_due; ?> (Due in <?php echo $days; ?> Days)</td>
|
<td><?php echo $invoice_due; ?> (Due in <?php echo $days; ?> Days)</td>
|
||||||
<td class="text-right text-monospace">$<?php echo $invoice_amount; ?></td>
|
<td class="text-right">$<?php echo $invoice_amount; ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|||||||
14
invoice.php
14
invoice.php
@@ -238,6 +238,9 @@ if(isset($_GET['invoice_id'])){
|
|||||||
<tbody>
|
<tbody>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
$total_tax = 0;
|
||||||
|
$sub_total = 0;
|
||||||
|
|
||||||
while($row = mysqli_fetch_array($sql_invoice_items)){
|
while($row = mysqli_fetch_array($sql_invoice_items)){
|
||||||
$item_id = $row['item_id'];
|
$item_id = $row['item_id'];
|
||||||
$item_name = $row['item_name'];
|
$item_name = $row['item_name'];
|
||||||
@@ -247,9 +250,8 @@ if(isset($_GET['invoice_id'])){
|
|||||||
$item_subtotal = $row['item_price'];
|
$item_subtotal = $row['item_price'];
|
||||||
$item_tax = $row['item_tax'];
|
$item_tax = $row['item_tax'];
|
||||||
$item_total = $row['item_total'];
|
$item_total = $row['item_total'];
|
||||||
$total_tax = 0;
|
$tax_id = $row['tax_id'];
|
||||||
$total_tax = $item_tax + $total_tax;
|
$total_tax = $item_tax + $total_tax;
|
||||||
$sub_total = 0;
|
|
||||||
$sub_total = $item_price * $item_quantity + $sub_total;
|
$sub_total = $item_price * $item_quantity + $sub_total;
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@@ -284,9 +286,8 @@ if(isset($_GET['invoice_id'])){
|
|||||||
<td><input type="number" step="0.01" min="0" class="form-control" style="text-align: center;" name="qty" placeholder="QTY"></td>
|
<td><input type="number" step="0.01" min="0" class="form-control" style="text-align: center;" name="qty" placeholder="QTY"></td>
|
||||||
<td><input type="number" step="0.01" class="form-control" style="text-align: right;" name="price" placeholder="Price"></td>
|
<td><input type="number" step="0.01" class="form-control" style="text-align: right;" name="price" placeholder="Price"></td>
|
||||||
<td>
|
<td>
|
||||||
|
<select class="form-control select2" name="tax_id" required>
|
||||||
<select class="form-control select2" name="tax" required>
|
<option value="0">None</option>
|
||||||
<option value="0.00">None</option>
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$taxes_sql = mysqli_query($mysqli,"SELECT * FROM taxes WHERE company_id = $session_company_id ORDER BY tax_name ASC");
|
$taxes_sql = mysqli_query($mysqli,"SELECT * FROM taxes WHERE company_id = $session_company_id ORDER BY tax_name ASC");
|
||||||
@@ -295,13 +296,12 @@ if(isset($_GET['invoice_id'])){
|
|||||||
$tax_name = $row['tax_name'];
|
$tax_name = $row['tax_name'];
|
||||||
$tax_percent = $row['tax_percent'];
|
$tax_percent = $row['tax_percent'];
|
||||||
?>
|
?>
|
||||||
<option value="<?php echo "$tax_percent"; ?>"><?php echo "$tax_name $tax_percent%"; ?></option>
|
<option value="<?php echo $tax_id; ?>"><?php echo "$tax_name $tax_percent%"; ?></option>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<button class="btn btn-link text-success" type="submit" name="add_invoice_item">
|
<button class="btn btn-link text-success" type="submit" name="add_invoice_item">
|
||||||
|
|||||||
23
logs.php
23
logs.php
@@ -17,6 +17,13 @@ if(isset($_GET['q'])){
|
|||||||
$q = "";
|
$q = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($_GET['log'] == "user"){
|
||||||
|
|
||||||
|
$extended_query = "= users.user_id";
|
||||||
|
}else{
|
||||||
|
$extended_query = "IS NULL";
|
||||||
|
}
|
||||||
|
|
||||||
if(!empty($_GET['sb'])){
|
if(!empty($_GET['sb'])){
|
||||||
$sb = mysqli_real_escape_string($mysqli,$_GET['sb']);
|
$sb = mysqli_real_escape_string($mysqli,$_GET['sb']);
|
||||||
}else{
|
}else{
|
||||||
@@ -51,7 +58,7 @@ $url_query_strings_sb = http_build_query(array_merge($_GET,array('sb' => $sb, 'o
|
|||||||
$sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * FROM logs, users
|
$sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * FROM logs, users
|
||||||
WHERE (log_type LIKE '%$q%' OR log_action LIKE '%$q%' OR log_description LIKE '%$q%')
|
WHERE (log_type LIKE '%$q%' OR log_action LIKE '%$q%' OR log_description LIKE '%$q%')
|
||||||
AND DATE(log_created_at) BETWEEN '$dtf' AND '$dtt'
|
AND DATE(log_created_at) BETWEEN '$dtf' AND '$dtt'
|
||||||
AND (logs.user_id = users.user_id AND logs.user_id IS NULL)
|
AND (logs.user_id $extended_query)
|
||||||
ORDER BY $sb $o LIMIT $record_from, $record_to");
|
ORDER BY $sb $o LIMIT $record_from, $record_to");
|
||||||
|
|
||||||
$num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
|
$num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
|
||||||
@@ -60,7 +67,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
|
|||||||
|
|
||||||
<div class="card card-dark">
|
<div class="card card-dark">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h3 class="card-title"><i class="fa fa-fw fa-book"></i> Logs</h3>
|
<h3 class="card-title"><i class="fa fa-fw fa-book"></i> Logs <?php echo $extended_query; ?></h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<form class="mb-4" autocomplete="off">
|
<form class="mb-4" autocomplete="off">
|
||||||
@@ -74,6 +81,12 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-sm-8">
|
||||||
|
<div class="btn-group float-right">
|
||||||
|
<a href="?log=user" class="btn <?php if($log == 'user'){ echo 'btn-primary'; }else{ echo 'btn-default'; } ?>">User</a>
|
||||||
|
<a href="?log=system" class="btn <?php if($log == 'system'){ echo 'btn-primary'; }else{ echo 'btn-default'; } ?>">System</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="collapse mt-3 <?php if(!empty($_GET['dtf'])){ echo "show"; } ?>" id="advancedFilter">
|
<div class="collapse mt-3 <?php if(!empty($_GET['dtf'])){ echo "show"; } ?>" id="advancedFilter">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@@ -113,10 +126,12 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
|
|||||||
$log_action = $row['log_action'];
|
$log_action = $row['log_action'];
|
||||||
$log_description = $row['log_description'];
|
$log_description = $row['log_description'];
|
||||||
$log_created_at = $row['log_created_at'];
|
$log_created_at = $row['log_created_at'];
|
||||||
$user_id = $row['user_id'];
|
$user_id = $row['logs.user_id'];
|
||||||
$name = $row['name'];
|
|
||||||
if($user_id == 0){
|
if($user_id == 0){
|
||||||
$name = "-";
|
$name = "-";
|
||||||
|
}else{
|
||||||
|
$name = $row['name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
160
post.php
160
post.php
@@ -1489,8 +1489,9 @@ if(isset($_POST['add_invoice_copy'])){
|
|||||||
$item_subtotal = $row['item_subtotal'];
|
$item_subtotal = $row['item_subtotal'];
|
||||||
$item_tax = $row['item_tax'];
|
$item_tax = $row['item_tax'];
|
||||||
$item_total = $row['item_total'];
|
$item_total = $row['item_total'];
|
||||||
|
$tax_id = $row['tax_id'];
|
||||||
|
|
||||||
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', item_created_at = NOW(), invoice_id = $new_invoice_id, company_id = $session_company_id");
|
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', item_created_at = NOW(), tax_id = $tax_id, invoice_id = $new_invoice_id, company_id = $session_company_id");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Logging
|
//Logging
|
||||||
@@ -1532,8 +1533,9 @@ if(isset($_POST['add_invoice_recurring'])){
|
|||||||
$item_subtotal = $row['item_subtotal'];
|
$item_subtotal = $row['item_subtotal'];
|
||||||
$item_tax = $row['item_tax'];
|
$item_tax = $row['item_tax'];
|
||||||
$item_total = $row['item_total'];
|
$item_total = $row['item_total'];
|
||||||
|
$tax_id = $row['tax_id'];
|
||||||
|
|
||||||
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', item_created_at = NOW(), recurring_id = $recurring_id, company_id = $session_company_id");
|
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', item_created_at = NOW(), tax_id = $tax_id, recurring_id = $recurring_id, company_id = $session_company_id");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Logging
|
//Logging
|
||||||
@@ -1609,8 +1611,9 @@ if(isset($_POST['add_quote_copy'])){
|
|||||||
$item_subtotal = $row['item_subtotal'];
|
$item_subtotal = $row['item_subtotal'];
|
||||||
$item_tax = $row['item_tax'];
|
$item_tax = $row['item_tax'];
|
||||||
$item_total = $row['item_total'];
|
$item_total = $row['item_total'];
|
||||||
|
$tax_id = $row['tax_id'];
|
||||||
|
|
||||||
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', item_created_at = NOW(), quote_id = $new_quote_id, company_id = $session_company_id");
|
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', item_created_at = NOW(), tax_id = $tax_id, quote_id = $new_quote_id, company_id = $session_company_id");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Logging
|
//Logging
|
||||||
@@ -1660,8 +1663,9 @@ if(isset($_POST['add_quote_to_invoice'])){
|
|||||||
$item_subtotal = $row['item_subtotal'];
|
$item_subtotal = $row['item_subtotal'];
|
||||||
$item_tax = $row['item_tax'];
|
$item_tax = $row['item_tax'];
|
||||||
$item_total = $row['item_total'];
|
$item_total = $row['item_total'];
|
||||||
|
$tax_id = $row['tax_id'];
|
||||||
|
|
||||||
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', item_created_at = NOW(), invoice_id = $new_invoice_id, company_id = $session_company_id");
|
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', item_created_at = NOW(), tax_id = $tax_id, invoice_id = $new_invoice_id, company_id = $session_company_id");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Logging
|
//Logging
|
||||||
@@ -1681,13 +1685,22 @@ if(isset($_POST['add_quote_item'])){
|
|||||||
$description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description']));
|
$description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description']));
|
||||||
$qty = floatval($_POST['qty']);
|
$qty = floatval($_POST['qty']);
|
||||||
$price = floatval($_POST['price']);
|
$price = floatval($_POST['price']);
|
||||||
$tax = floatval($_POST['tax']);
|
$tax_id = intval($_POST['tax_id']);
|
||||||
|
|
||||||
$subtotal = $price * $qty;
|
$subtotal = $price * $qty;
|
||||||
$tax = $subtotal * $tax / 100;
|
|
||||||
$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', item_created_at = NOW(), quote_id = $quote_id, company_id = $session_company_id");
|
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,"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, quote_id = $quote_id, company_id = $session_company_id");
|
||||||
|
|
||||||
//Update Invoice Balances
|
//Update Invoice Balances
|
||||||
|
|
||||||
@@ -1725,13 +1738,22 @@ if(isset($_POST['edit_quote_item'])){
|
|||||||
$description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description']));
|
$description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description']));
|
||||||
$qty = floatval($_POST['qty']);
|
$qty = floatval($_POST['qty']);
|
||||||
$price = floatval($_POST['price']);
|
$price = floatval($_POST['price']);
|
||||||
$tax = floatval($_POST['tax']);
|
$tax_id = intval($_POST['tax_id']);
|
||||||
|
|
||||||
$subtotal = $price * $qty;
|
$subtotal = $price * $qty;
|
||||||
$tax = $subtotal * $tax / 100;
|
|
||||||
$total = $subtotal + $tax;
|
|
||||||
|
|
||||||
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', item_total = '$total' WHERE item_id = $item_id");
|
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
|
//Update Invoice Balances by tallying up invoice items
|
||||||
|
|
||||||
@@ -2278,13 +2300,22 @@ if(isset($_POST['add_recurring_item'])){
|
|||||||
$description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description']));
|
$description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description']));
|
||||||
$qty = floatval($_POST['qty']);
|
$qty = floatval($_POST['qty']);
|
||||||
$price = floatval($_POST['price']);
|
$price = floatval($_POST['price']);
|
||||||
$tax = floatval($_POST['tax']);
|
$tax_id = intval($_POST['tax_id']);
|
||||||
|
|
||||||
$subtotal = $price * $qty;
|
$subtotal = $price * $qty;
|
||||||
$tax = $subtotal * $tax / 100;
|
|
||||||
$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', item_created_at = NOW(), recurring_id = $recurring_id, company_id = $session_company_id");
|
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,"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 Invoice Balances
|
||||||
|
|
||||||
@@ -2322,13 +2353,22 @@ if(isset($_POST['edit_recurring_item'])){
|
|||||||
$description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description']));
|
$description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description']));
|
||||||
$qty = floatval($_POST['qty']);
|
$qty = floatval($_POST['qty']);
|
||||||
$price = floatval($_POST['price']);
|
$price = floatval($_POST['price']);
|
||||||
$tax = floatval($_POST['tax']);
|
$tax_id = intval($_POST['tax_id']);
|
||||||
|
|
||||||
$subtotal = $price * $qty;
|
$subtotal = $price * $qty;
|
||||||
$tax = $subtotal * $tax / 100;
|
|
||||||
$total = $subtotal + $tax;
|
|
||||||
|
|
||||||
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', item_total = '$total' WHERE item_id = $item_id");
|
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
|
//Update Invoice Balances by tallying up invoice items
|
||||||
|
|
||||||
@@ -2448,13 +2488,22 @@ if(isset($_POST['add_invoice_item'])){
|
|||||||
$description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description']));
|
$description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description']));
|
||||||
$qty = floatval($_POST['qty']);
|
$qty = floatval($_POST['qty']);
|
||||||
$price = floatval($_POST['price']);
|
$price = floatval($_POST['price']);
|
||||||
$tax = floatval($_POST['tax']);
|
$tax_id = intval($_POST['tax_id']);
|
||||||
|
|
||||||
$subtotal = $price * $qty;
|
$subtotal = $price * $qty;
|
||||||
$tax = $subtotal * $tax / 100;
|
|
||||||
$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', item_created_at = NOW(), invoice_id = $invoice_id, company_id = $session_company_id");
|
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,"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, invoice_id = $invoice_id, company_id = $session_company_id");
|
||||||
|
|
||||||
//Update Invoice Balances
|
//Update Invoice Balances
|
||||||
|
|
||||||
@@ -2493,13 +2542,22 @@ if(isset($_POST['edit_invoice_item'])){
|
|||||||
$description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description']));
|
$description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description']));
|
||||||
$qty = floatval($_POST['qty']);
|
$qty = floatval($_POST['qty']);
|
||||||
$price = floatval($_POST['price']);
|
$price = floatval($_POST['price']);
|
||||||
$tax = floatval($_POST['tax']);
|
$tax_id = intval($_POST['tax_id']);
|
||||||
|
|
||||||
$subtotal = $price * $qty;
|
$subtotal = $price * $qty;
|
||||||
$tax = $subtotal * $tax / 100;
|
|
||||||
$total = $subtotal + $tax;
|
|
||||||
|
|
||||||
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', item_total = '$total' WHERE item_id = $item_id");
|
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
|
//Update Invoice Balances by tallying up invoice items
|
||||||
|
|
||||||
@@ -3846,21 +3904,43 @@ if(isset($_GET['force_recurring'])){
|
|||||||
$item_description = mysqli_real_escape_string($mysqli,$row['item_description']);
|
$item_description = mysqli_real_escape_string($mysqli,$row['item_description']);
|
||||||
$item_quantity = $row['item_quantity'];
|
$item_quantity = $row['item_quantity'];
|
||||||
$item_price = $row['item_price'];
|
$item_price = $row['item_price'];
|
||||||
$item_subtotal = $row['item_price'];
|
$item_subtotal = $row['item_subtotal'];
|
||||||
$item_tax = $row['item_tax'];
|
$tax_id = $row['tax_id'];
|
||||||
$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', item_created_at = NOW(), invoice_id = $new_invoice_id, company_id = $session_company_id");
|
//Recalculate Item Tax since Tax percents can change.
|
||||||
|
if($tax_id > 0){
|
||||||
|
$sql = mysqli_query($mysqli,"SELECT * FROM taxes WHERE tax_id = $tax_id AND company_id = $session_company_id");
|
||||||
|
$row = mysqli_fetch_array($sql);
|
||||||
|
$tax_percent = $row['tax_percent'];
|
||||||
|
$item_tax_amount = $item_subtotal * $tax_percent / 100;
|
||||||
|
}else{
|
||||||
|
$item_tax_amount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$item_total = $item_subtotal + $item_tax_amount;
|
||||||
|
|
||||||
|
//Update Recurring Items with new tax
|
||||||
|
mysqli_query($mysqli,"UPDATE invoice_items SET item_tax = '$item_tax_amount', item_total = '$item_total', item_updated_at = NOW(), tax_id = $tax_id WHERE item_id = $item_id");
|
||||||
|
|
||||||
|
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_amount', item_total = '$item_total', item_created_at = NOW(), tax_id = $tax_id, invoice_id = $new_invoice_id, company_id = $session_company_id");
|
||||||
}
|
}
|
||||||
|
|
||||||
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Sent', history_description = 'Invoice Generated from Recurring!', history_created_at = NOW(), invoice_id = $new_invoice_id, company_id = $session_company_id");
|
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Sent', history_description = 'Invoice Generated from Recurring!', history_created_at = NOW(), invoice_id = $new_invoice_id, company_id = $session_company_id");
|
||||||
|
|
||||||
//update the recurring invoice with the new dates
|
//Update Recurring Balances by tallying up recurring items also update recurring dates
|
||||||
mysqli_query($mysqli,"UPDATE recurring SET recurring_last_sent = CURDATE(), recurring_next_date = DATE_ADD(CURDATE(), INTERVAL 1 $recurring_frequency), recurring_updated_at = NOW() WHERE recurring_id = $recurring_id AND company_id = $session_company_id");
|
$sql_recurring_total = mysqli_query($mysqli,"SELECT SUM(item_total) AS recurring_total FROM invoice_items WHERE recurring_id = $recurring_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_last_sent = CURDATE(), recurring_next_date = DATE_ADD(CURDATE(), INTERVAL 1 $recurring_frequency), recurring_updated_at = NOW() WHERE recurring_id = $recurring_id");
|
||||||
|
|
||||||
|
//Also update the newly created invoice with the new amounts
|
||||||
|
mysqli_query($mysqli,"UPDATE invoices SET invoice_amount = '$new_recurring_amount' WHERE invoice_id = $new_invoice_id");
|
||||||
|
|
||||||
if($config_recurring_auto_send_invoice == 1){
|
if($config_recurring_auto_send_invoice == 1){
|
||||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoices, clients
|
$sql = mysqli_query($mysqli,"SELECT * FROM invoices, clients, companies
|
||||||
WHERE invoices.client_id = clients.client_id
|
WHERE invoices.client_id = clients.client_id
|
||||||
|
AND invoices.company_id = companies.company_id
|
||||||
AND invoices.invoice_id = $new_invoice_id
|
AND invoices.invoice_id = $new_invoice_id
|
||||||
AND invoices.company_id = $session_company_id"
|
AND invoices.company_id = $session_company_id"
|
||||||
);
|
);
|
||||||
@@ -3883,6 +3963,14 @@ if(isset($_GET['force_recurring'])){
|
|||||||
if(strlen($client_phone)>2){
|
if(strlen($client_phone)>2){
|
||||||
$client_phone = substr($row['client_phone'],0,3)."-".substr($row['client_phone'],3,3)."-".substr($row['client_phone'],6,4);
|
$client_phone = substr($row['client_phone'],0,3)."-".substr($row['client_phone'],3,3)."-".substr($row['client_phone'],6,4);
|
||||||
}
|
}
|
||||||
|
$company_id = $row['company_id'];
|
||||||
|
$company_name = $row['company_name'];
|
||||||
|
$company_phone = $row['company_phone'];
|
||||||
|
if(strlen($company_phone)>2){
|
||||||
|
$company_phone = substr($row['company_phone'],0,3)."-".substr($row['company_phone'],3,3)."-".substr($row['company_phone'],6,4);
|
||||||
|
}
|
||||||
|
$company_email = $row['company_email'];
|
||||||
|
$company_website = $row['company_website'];
|
||||||
$base_url = $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']);
|
$base_url = $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']);
|
||||||
|
|
||||||
$mail = new PHPMailer(true);
|
$mail = new PHPMailer(true);
|
||||||
@@ -3908,7 +3996,7 @@ if(isset($_GET['force_recurring'])){
|
|||||||
$mail->isHTML(true); // Set email format to HTML
|
$mail->isHTML(true); // Set email format to HTML
|
||||||
|
|
||||||
$mail->Subject = "Invoice $invoice_number";
|
$mail->Subject = "Invoice $invoice_number";
|
||||||
$mail->Body = "Hello $client_name,<br><br>Please view the details of the invoice below.<br><br>Invoice: $invoice_number<br>Issue Date: $invoice_date<br>Total: $$invoice_amount<br>Due Date: $invoice_due<br><br><br>To view your invoice online click <a href='https://$base_url/guest_view_invoice.php?invoice_id=$new_invoice_id&url_key=$invoice_url_key'>here</a><br><br><br>~<br>$company_name<br>$config_company_phone";
|
$mail->Body = "Hello $client_name,<br><br>Please view the details of the invoice below.<br><br>Invoice: $invoice_number<br>Issue Date: $invoice_date<br>Total: $$invoice_amount<br>Due Date: $invoice_due<br><br><br>To view your invoice online click <a href='https://$base_url/guest_view_invoice.php?invoice_id=$new_invoice_id&url_key=$invoice_url_key'>here</a><br><br><br>~<br>$company_name<br>$company_phone";
|
||||||
|
|
||||||
$mail->send();
|
$mail->send();
|
||||||
|
|
||||||
|
|||||||
12
quote.php
12
quote.php
@@ -204,6 +204,9 @@ if(isset($_GET['quote_id'])){
|
|||||||
<tbody>
|
<tbody>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
$total_tax = 0;
|
||||||
|
$sub_total = 0;
|
||||||
|
|
||||||
while($row = mysqli_fetch_array($sql_items)){
|
while($row = mysqli_fetch_array($sql_items)){
|
||||||
$item_id = $row['item_id'];
|
$item_id = $row['item_id'];
|
||||||
$item_name = $row['item_name'];
|
$item_name = $row['item_name'];
|
||||||
@@ -213,9 +216,8 @@ if(isset($_GET['quote_id'])){
|
|||||||
$item_subtotal = $row['item_price'];
|
$item_subtotal = $row['item_price'];
|
||||||
$item_tax = $row['item_tax'];
|
$item_tax = $row['item_tax'];
|
||||||
$item_total = $row['item_total'];
|
$item_total = $row['item_total'];
|
||||||
$total_tax = 0;
|
$tax_id = $row['tax_id'];
|
||||||
$total_tax = $item_tax + $total_tax;
|
$total_tax = $item_tax + $total_tax;
|
||||||
$sub_total = 0;
|
|
||||||
$sub_total = $item_price * $item_quantity + $sub_total;
|
$sub_total = $item_price * $item_quantity + $sub_total;
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@@ -250,8 +252,8 @@ if(isset($_GET['quote_id'])){
|
|||||||
<td><input type="number" step="0.01" min="0" class="form-control" style="text-align: center;" name="qty" placeholder="QTY"></td>
|
<td><input type="number" step="0.01" min="0" class="form-control" style="text-align: center;" name="qty" placeholder="QTY"></td>
|
||||||
<td><input type="number" step="0.01" min="0" class="form-control" style="text-align: right;" name="price" placeholder="Price"></td>
|
<td><input type="number" step="0.01" min="0" class="form-control" style="text-align: right;" name="price" placeholder="Price"></td>
|
||||||
<td>
|
<td>
|
||||||
<select class="form-control select2" name="tax" required>
|
<select class="form-control select2" name="tax_id" required>
|
||||||
<option value="0.00">None</option>
|
<option value="0">None</option>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$taxes_sql = mysqli_query($mysqli,"SELECT * FROM taxes WHERE company_id = $session_company_id ORDER BY tax_name ASC");
|
$taxes_sql = mysqli_query($mysqli,"SELECT * FROM taxes WHERE company_id = $session_company_id ORDER BY tax_name ASC");
|
||||||
@@ -260,7 +262,7 @@ if(isset($_GET['quote_id'])){
|
|||||||
$tax_name = $row['tax_name'];
|
$tax_name = $row['tax_name'];
|
||||||
$tax_percent = $row['tax_percent'];
|
$tax_percent = $row['tax_percent'];
|
||||||
?>
|
?>
|
||||||
<option value="<?php echo "$tax_percent"; ?>"><?php echo "$tax_name $tax_percent%"; ?></option>
|
<option value="<?php echo $tax_id; ?>"><?php echo "$tax_name $tax_percent%"; ?></option>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,6 +182,9 @@ if(isset($_GET['recurring_id'])){
|
|||||||
<tbody>
|
<tbody>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
$total_tax = 0;
|
||||||
|
$sub_total = 0;
|
||||||
|
|
||||||
while($row = mysqli_fetch_array($sql_items)){
|
while($row = mysqli_fetch_array($sql_items)){
|
||||||
$item_id = $row['item_id'];
|
$item_id = $row['item_id'];
|
||||||
$item_name = $row['item_name'];
|
$item_name = $row['item_name'];
|
||||||
@@ -191,9 +194,8 @@ if(isset($_GET['recurring_id'])){
|
|||||||
$item_subtotal = $row['item_price'];
|
$item_subtotal = $row['item_price'];
|
||||||
$item_tax = $row['item_tax'];
|
$item_tax = $row['item_tax'];
|
||||||
$item_total = $row['item_total'];
|
$item_total = $row['item_total'];
|
||||||
$total_tax = 0;
|
$tax_id = $row['tax_id'];
|
||||||
$total_tax = $item_tax + $total_tax;
|
$total_tax = $item_tax + $total_tax;
|
||||||
$sub_total = 0;
|
|
||||||
$sub_total = $item_price * $item_quantity + $sub_total;
|
$sub_total = $item_price * $item_quantity + $sub_total;
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@@ -228,8 +230,8 @@ if(isset($_GET['recurring_id'])){
|
|||||||
<td><input type="number" step="0.01" min="0" class="form-control" style="text-align: center;" name="qty" placeholder="QTY"></td>
|
<td><input type="number" step="0.01" min="0" class="form-control" style="text-align: center;" name="qty" placeholder="QTY"></td>
|
||||||
<td><input type="number" step="0.01" min="0" class="form-control" style="text-align: right;" name="price" placeholder="Price"></td>
|
<td><input type="number" step="0.01" min="0" class="form-control" style="text-align: right;" name="price" placeholder="Price"></td>
|
||||||
<td>
|
<td>
|
||||||
<select class="form-control select2" name="tax" required>
|
<select class="form-control select2" name="tax_id" required>
|
||||||
<option value="0.00">None</option>
|
<option value="0">None</option>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$taxes_sql = mysqli_query($mysqli,"SELECT * FROM taxes WHERE company_id = $session_company_id ORDER BY tax_name ASC");
|
$taxes_sql = mysqli_query($mysqli,"SELECT * FROM taxes WHERE company_id = $session_company_id ORDER BY tax_name ASC");
|
||||||
@@ -238,7 +240,7 @@ if(isset($_GET['recurring_id'])){
|
|||||||
$tax_name = $row['tax_name'];
|
$tax_name = $row['tax_name'];
|
||||||
$tax_percent = $row['tax_percent'];
|
$tax_percent = $row['tax_percent'];
|
||||||
?>
|
?>
|
||||||
<option value="<?php echo "$tax_percent"; ?>"><?php echo "$tax_name $tax_percent%"; ?></option>
|
<option value="<?php echo $tax_id; ?>"><?php echo "$tax_name $tax_percent%"; ?></option>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,8 +64,6 @@
|
|||||||
ORDER BY $sb $o LIMIT $record_from, $record_to");
|
ORDER BY $sb $o LIMIT $record_from, $record_to");
|
||||||
|
|
||||||
$num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
|
$num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
|
||||||
$total_found_rows = $num_rows[0];
|
|
||||||
$total_pages = ceil($total_found_rows / 10);
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user