mirror of https://github.com/itflow-org/itflow
commit
56b91f3278
|
|
@ -82,6 +82,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
|||
$invoice_status = nullable_htmlentities($row['invoice_status']);
|
||||
$invoice_date = nullable_htmlentities($row['invoice_date']);
|
||||
$invoice_due = nullable_htmlentities($row['invoice_due']);
|
||||
$invoice_discount = floatval($row['invoice_discount_amount']);
|
||||
$invoice_amount = floatval($row['invoice_amount']);
|
||||
$invoice_currency_code = nullable_htmlentities($row['invoice_currency_code']);
|
||||
$invoice_created_at = nullable_htmlentities($row['invoice_created_at']);
|
||||
|
|
|
|||
|
|
@ -1460,7 +1460,17 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) {
|
|||
// Then, update the database to the next sequential version
|
||||
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.9.0'");
|
||||
}
|
||||
//
|
||||
|
||||
if (CURRENT_DATABASE_VERSION == '0.9.1') {
|
||||
// Insert queries here required to update to DB version 0.9.2
|
||||
mysqli_query($mysqli, "ALTER TABLE `invoices` ADD `invoice_discount_amount` DECIMAL(15,2) NOT NULL DEFAULT 0.00 AFTER `invoice_due`");
|
||||
mysqli_query($mysqli, "ALTER TABLE `recurring` ADD `recurring_discount_amount` DECIMAL(15,2) NOT NULL DEFAULT 0.00 AFTER `recurring_status`");
|
||||
mysqli_query($mysqli, "ALTER TABLE `quotes` ADD `quote_discount_amount` DECIMAL(15,2) NOT NULL DEFAULT 0.00 AFTER `quote_status`");
|
||||
|
||||
// Then update the database to the next sequential version
|
||||
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.9.2'");
|
||||
|
||||
}
|
||||
|
||||
// Be sure to change database_version.php to reflect the version you are updating to here
|
||||
// Please add this same comment block to the bottom of this file, and update the version number.
|
||||
|
|
|
|||
|
|
@ -5,4 +5,5 @@
|
|||
* It is used in conjunction with database_updates.php
|
||||
*/
|
||||
|
||||
DEFINE("LATEST_DATABASE_VERSION", "0.9.1");
|
||||
DEFINE("LATEST_DATABASE_VERSION", "0.9.2");
|
||||
|
||||
|
|
|
|||
3
db.sql
3
db.sql
|
|
@ -715,6 +715,7 @@ CREATE TABLE `invoices` (
|
|||
`invoice_status` varchar(200) NOT NULL,
|
||||
`invoice_date` date NOT NULL,
|
||||
`invoice_due` date NOT NULL,
|
||||
`invoice_discount_amount` decimal(15,2) NOT NULL DEFAULT 0.00,
|
||||
`invoice_amount` decimal(15,2) NOT NULL DEFAULT 0.00,
|
||||
`invoice_currency_code` varchar(200) NOT NULL,
|
||||
`invoice_note` text DEFAULT NULL,
|
||||
|
|
@ -939,6 +940,7 @@ CREATE TABLE `quotes` (
|
|||
`quote_status` varchar(200) NOT NULL,
|
||||
`quote_date` date NOT NULL,
|
||||
`quote_expire` date DEFAULT NULL,
|
||||
`quote_discount_amount` decimal(15,2) NOT NULL DEFAULT 0.00,
|
||||
`quote_amount` decimal(15,2) NOT NULL DEFAULT 0.00,
|
||||
`quote_currency_code` varchar(200) NOT NULL,
|
||||
`quote_note` text DEFAULT NULL,
|
||||
|
|
@ -989,6 +991,7 @@ CREATE TABLE `recurring` (
|
|||
`recurring_last_sent` date DEFAULT NULL,
|
||||
`recurring_next_date` date NOT NULL,
|
||||
`recurring_status` int(1) NOT NULL,
|
||||
`recurring_discount_amount` decimal(15,2) NOT NULL DEFAULT 0.00,
|
||||
`recurring_amount` decimal(15,2) NOT NULL DEFAULT 0.00,
|
||||
`recurring_currency_code` varchar(200) NOT NULL,
|
||||
`recurring_note` text DEFAULT NULL,
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ if (isset($_GET['invoice_id'], $_GET['url_key']) && !isset($_GET['payment_intent
|
|||
$invoice_status = nullable_htmlentities($row['invoice_status']);
|
||||
$invoice_date = nullable_htmlentities($row['invoice_date']);
|
||||
$invoice_due = nullable_htmlentities($row['invoice_due']);
|
||||
$invoice_discount = floatval($row['invoice_discount_amount']);
|
||||
$invoice_amount = floatval($row['invoice_amount']);
|
||||
$invoice_currency_code = nullable_htmlentities($row['invoice_currency_code']);
|
||||
$client_id = intval($row['client_id']);
|
||||
|
|
@ -120,12 +121,17 @@ if (isset($_GET['invoice_id'], $_GET['url_key']) && !isset($_GET['payment_intent
|
|||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<br>
|
||||
<i><?php if ($invoice_discount > 0){ echo "Discount: " . numfmt_format_currency($currency_format, $invoice_discount, $invoice_currency_code); } ?>
|
||||
</i>
|
||||
<br>
|
||||
<i><?php if (intval($amount_paid) > 0) { ?> Already paid: <?php echo numfmt_format_currency($currency_format, $amount_paid, $invoice_currency_code); } ?></i>
|
||||
</div>
|
||||
<!-- End invoice details-->
|
||||
|
||||
<!-- Show Stripe payment form -->
|
||||
<div class="col-sm offset-sm-1">
|
||||
<h1>Payment Total:</h1>
|
||||
<form id="payment-form">
|
||||
<h1><?php echo numfmt_format_currency($currency_format, $balance_to_pay, $invoice_currency_code); ?></h1>
|
||||
<input type="hidden" id="stripe_publishable_key" value="<?php echo $config_stripe_publishable ?>">
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ $invoice_number = intval($row['invoice_number']);
|
|||
$invoice_status = nullable_htmlentities($row['invoice_status']);
|
||||
$invoice_date = nullable_htmlentities($row['invoice_date']);
|
||||
$invoice_due = nullable_htmlentities($row['invoice_due']);
|
||||
$invoice_discount = floatval($row['invoice_discount_amount']);
|
||||
$invoice_amount = floatval($row['invoice_amount']);
|
||||
$invoice_currency_code = nullable_htmlentities($row['invoice_currency_code']);
|
||||
$invoice_note = nullable_htmlentities($row['invoice_note']);
|
||||
|
|
@ -254,6 +255,18 @@ $sql_invoice_items = mysqli_query($mysqli, "SELECT * FROM invoice_items WHERE it
|
|||
<div class="col-sm-3 offset-sm-2">
|
||||
<table class="table table-borderless">
|
||||
<tbody>
|
||||
<?php
|
||||
if ($invoice_discount > 0) {
|
||||
?>
|
||||
<tr class="border-bottom">
|
||||
<td>Discount</td>
|
||||
<td class="text-right"><?php echo numfmt_format_currency($currency_format, $invoice_discount, $invoice_currency_code); ?></td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
$sub_total = $sub_total - $invoice_discount;
|
||||
}
|
||||
?>
|
||||
<tr class="border-bottom">
|
||||
<td>Subtotal</td>
|
||||
<td class="text-right"><?php echo numfmt_format_currency($currency_format, $sub_total, $invoice_currency_code); ?></td>
|
||||
|
|
|
|||
19
invoice.php
19
invoice.php
|
|
@ -30,6 +30,7 @@ if (isset($_GET['invoice_id'])) {
|
|||
$invoice_date = nullable_htmlentities($row['invoice_date']);
|
||||
$invoice_due = nullable_htmlentities($row['invoice_due']);
|
||||
$invoice_amount = floatval($row['invoice_amount']);
|
||||
$invoice_discount = floatval($row['invoice_discount_amount']);
|
||||
$invoice_currency_code = nullable_htmlentities($row['invoice_currency_code']);
|
||||
$invoice_note = nullable_htmlentities($row['invoice_note']);
|
||||
$invoice_url_key = nullable_htmlentities($row['invoice_url_key']);
|
||||
|
|
@ -424,6 +425,19 @@ if (isset($_GET['invoice_id'])) {
|
|||
<div class="col-sm-3 offset-sm-2">
|
||||
<table class="table table-borderless">
|
||||
<tbody>
|
||||
|
||||
<?php
|
||||
if ($invoice_discount > 0) {
|
||||
?>
|
||||
<tr class="border-bottom">
|
||||
<td>Discount</td>
|
||||
<td class="text-right"><?php echo numfmt_format_currency($currency_format, $invoice_discount, $invoice_currency_code); ?></td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
$sub_total = $sub_total - $invoice_discount;
|
||||
}
|
||||
?>
|
||||
<tr class="border-bottom">
|
||||
<td>Subtotal</td>
|
||||
<td class="text-right"><?php echo numfmt_format_currency($currency_format, $sub_total, $invoice_currency_code); ?></td>
|
||||
|
|
@ -433,13 +447,14 @@ if (isset($_GET['invoice_id'])) {
|
|||
<td>Tax</td>
|
||||
<td class="text-right"><?php echo numfmt_format_currency($currency_format, $total_tax, $invoice_currency_code); ?></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<?php if ($amount_paid > 0) { ?>
|
||||
<?php }
|
||||
if ($amount_paid > 0) { ?>
|
||||
<tr class="border-bottom">
|
||||
<td><div class="text-success">Paid</div></td>
|
||||
<td class="text-right text-success"><?php echo numfmt_format_currency($currency_format, $amount_paid, $invoice_currency_code); ?></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
|
||||
<tr class="border-bottom">
|
||||
<td><strong>Balance</strong></td>
|
||||
<td class="text-right"><strong><?php echo numfmt_format_currency($currency_format, $balance, $invoice_currency_code); ?></strong></td>
|
||||
|
|
|
|||
|
|
@ -44,10 +44,12 @@
|
|||
|
||||
$sql_income_category = mysqli_query($mysqli, "SELECT * FROM categories WHERE category_type = 'Income' AND (category_archived_at > '$invoice_created_at' OR category_archived_at IS NULL) ORDER BY category_name ASC");
|
||||
while ($row = mysqli_fetch_array($sql_income_category)) {
|
||||
$category_id_select= intval($row['category_id']);
|
||||
$category_id_select = intval($row['category_id']);
|
||||
$category_name_select = nullable_htmlentities($row['category_name']);
|
||||
?>
|
||||
<option <?php if ($category_id == $category_id_select) { echo "selected"; } ?> value="<?php echo $category_id_select; ?>"><?php echo $category_name_select; ?></option>
|
||||
<option <?php if ($category_id == $category_id_select) {
|
||||
echo "selected";
|
||||
} ?> value="<?php echo $category_id_select; ?>"><?php echo $category_name_select; ?></option>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
|
@ -59,6 +61,16 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class='form-group'>
|
||||
<label>Discount Amount</label>
|
||||
<div class='input-group'>
|
||||
<div class='input-group-prepend'>
|
||||
<span class='input-group-text'><i class='fa fa-fw fa-dollar-sign'></i></span>
|
||||
</div>
|
||||
<input type='number' class='form-control' name='invoice_discount' placeholder='Discount Amount' value='<?php echo $invoice_discount; ?>'>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Scope</label>
|
||||
<div class="input-group">
|
||||
|
|
|
|||
|
|
@ -232,6 +232,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
|||
$invoice_status = nullable_htmlentities($row['invoice_status']);
|
||||
$invoice_date = nullable_htmlentities($row['invoice_date']);
|
||||
$invoice_due = nullable_htmlentities($row['invoice_due']);
|
||||
$invoice_discount = floatval($row['invoice_discount_amount']);
|
||||
$invoice_amount = floatval($row['invoice_amount']);
|
||||
$invoice_currency_code = nullable_htmlentities($row['invoice_currency_code']);
|
||||
$invoice_created_at = nullable_htmlentities($row['invoice_created_at']);
|
||||
|
|
|
|||
|
|
@ -43,7 +43,18 @@ if (isset($_POST['edit_invoice'])) {
|
|||
$invoice_id = intval($_POST['invoice_id']);
|
||||
$due = sanitizeInput($_POST['due']);
|
||||
|
||||
mysqli_query($mysqli,"UPDATE invoices SET invoice_scope = '$scope', invoice_date = '$date', invoice_due = '$due', invoice_category_id = $category WHERE invoice_id = $invoice_id");
|
||||
//Calculate new total
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE item_invoice_id = $invoice_id");
|
||||
$invoice_amount = 0;
|
||||
while($row = mysqli_fetch_array($sql)) {
|
||||
$item_total = floatval($row['item_total']);
|
||||
$invoice_amount = $invoice_amount + $item_total;
|
||||
}
|
||||
$invoice_amount = $invoice_amount - $invoice_discount;
|
||||
|
||||
|
||||
mysqli_query($mysqli,"UPDATE invoices SET invoice_scope = '$scope', invoice_date = '$date', invoice_due = '$due', invoice_category_id = $category, invoice_discount_amount = '$invoice_discount', invoice_amount = '$invoice_amount' WHERE invoice_id = $invoice_id");
|
||||
|
||||
|
||||
//Logging
|
||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Invoice', log_action = 'Modify', log_description = '$invoice_id', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");
|
||||
|
|
@ -414,12 +425,24 @@ if (isset($_POST['add_invoice_item'])) {
|
|||
|
||||
mysqli_query($mysqli,"INSERT INTO invoice_items SET item_name = '$name', item_description = '$description', item_quantity = $qty, item_price = $price, item_subtotal = $subtotal, item_tax = $tax_amount, item_total = $total, item_order = $item_order, item_tax_id = $tax_id, item_invoice_id = $invoice_id");
|
||||
|
||||
//Update Invoice Balances
|
||||
//Get Discount
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoices WHERE invoice_id = $invoice_id");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
if($invoice_id > 0){
|
||||
$invoice_discount = floatval($row['invoice_discount_amount']);
|
||||
} else {
|
||||
$invoice_discount = 0;
|
||||
}
|
||||
|
||||
$new_invoice_amount = floatval($row['invoice_amount']) + $total;
|
||||
//add up all line items
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE item_invoice_id = $invoice_id");
|
||||
$invoice_total = 0;
|
||||
while($row = mysqli_fetch_array($sql)) {
|
||||
$item_total = floatval($row['item_total']);
|
||||
$invoice_total = $invoice_total + $item_total;
|
||||
}
|
||||
$new_invoice_amount = $invoice_total - $invoice_discount;
|
||||
|
||||
mysqli_query($mysqli,"UPDATE invoices SET invoice_amount = $new_invoice_amount WHERE invoice_id = $invoice_id");
|
||||
|
||||
|
|
@ -471,10 +494,15 @@ if (isset($_POST['edit_item'])) {
|
|||
mysqli_query($mysqli,"UPDATE invoice_items SET item_name = '$name', item_description = '$description', item_quantity = $qty, item_price = $price, item_subtotal = $subtotal, item_tax = $tax_amount, item_total = $total, item_tax_id = $tax_id WHERE item_id = $item_id");
|
||||
|
||||
if ($invoice_id > 0) {
|
||||
//Get Discount Amount
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoices WHERE invoice_id = $invoice_id");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
$invoice_discount = floatval($row['invoice_discount_amount']);
|
||||
|
||||
//Update Invoice Balances by tallying up invoice items
|
||||
$sql_invoice_total = mysqli_query($mysqli,"SELECT SUM(item_total) AS invoice_total FROM invoice_items WHERE item_invoice_id = $invoice_id");
|
||||
$row = mysqli_fetch_array($sql_invoice_total);
|
||||
$new_invoice_amount = floatval($row['invoice_total']);
|
||||
$new_invoice_amount = floatval($row['invoice_total']) - $invoice_discount;
|
||||
|
||||
mysqli_query($mysqli,"UPDATE invoices SET invoice_amount = $new_invoice_amount WHERE invoice_id = $invoice_id");
|
||||
|
||||
|
|
|
|||
|
|
@ -2,3 +2,4 @@
|
|||
$date = sanitizeInput($_POST['date']);
|
||||
$category = intval($_POST['category']);
|
||||
$scope = sanitizeInput($_POST['scope']);
|
||||
$invoice_discount = floatval($_POST['invoice_discount']);
|
||||
Loading…
Reference in New Issue