diff --git a/client_quotes.php b/client_quotes.php
index 60830da7a..cc0387694 100644
--- a/client_quotes.php
+++ b/client_quotes.php
@@ -83,6 +83,7 @@
$quote_status = nullable_htmlentities($row['quote_status']);
$quote_date = nullable_htmlentities($row['quote_date']);
$quote_expire = nullable_htmlentities($row['quote_expire']);
+ $quote_discount = floatval($row['quote_discount_amount']);
$quote_amount = floatval($row['quote_amount']);
$quote_currency_code = nullable_htmlentities($row['quote_currency_code']);
$quote_created_at = nullable_htmlentities($row['quote_created_at']);
diff --git a/client_recurring_invoices.php b/client_recurring_invoices.php
index ab7dc5483..2e4bb9526 100644
--- a/client_recurring_invoices.php
+++ b/client_recurring_invoices.php
@@ -83,6 +83,7 @@
}
$recurring_next_date = nullable_htmlentities($row['recurring_next_date']);
$recurring_amount = floatval($row['recurring_amount']);
+ $recurring_discount = floatval($row['recurring_discount_amount']);
$recurring_currency_code = nullable_htmlentities($row['recurring_currency_code']);
$recurring_created_at = nullable_htmlentities($row['recurring_created_at']);
$category_id = intval($row['category_id']);
@@ -106,9 +107,9 @@
|
|
-
-
-
+
+
+
|
diff --git a/guest_view_quote.php b/guest_view_quote.php
index 22714d8cb..c0049c560 100644
--- a/guest_view_quote.php
+++ b/guest_view_quote.php
@@ -40,6 +40,7 @@
$quote_status = nullable_htmlentities($row['quote_status']);
$quote_date = nullable_htmlentities($row['quote_date']);
$quote_expire = nullable_htmlentities($row['quote_expire']);
+$quote_discount = floatval($row['quote_discount_amount']);
$quote_amount = floatval($row['quote_amount']);
$quote_currency_code = nullable_htmlentities($row['quote_currency_code']);
$quote_note = nullable_htmlentities($row['quote_note']);
@@ -232,6 +233,17 @@
+ 0) {
+ ?>
+
+ Discount |
+ |
+
+
Subtotal |
|
diff --git a/post/invoice.php b/post/invoice.php
index 1684c6e19..4f4131aaf 100644
--- a/post/invoice.php
+++ b/post/invoice.php
@@ -122,6 +122,7 @@
header("Location: invoice.php?invoice_id=$new_invoice_id");
}
+
if (isset($_POST['add_invoice_recurring'])) {
$invoice_id = intval($_POST['invoice_id']);
@@ -172,8 +173,6 @@
}
-
-
if (isset($_POST['add_recurring'])) {
$client = intval($_POST['client']);
@@ -210,8 +209,18 @@
$category = intval($_POST['category']);
$scope = sanitizeInput($_POST['scope']);
$status = intval($_POST['status']);
+ $recurring_discount = floatval($_POST['recurring_discount']);
+
+ //Calculate new total
+ $sql = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE item_recurring_id = $recurring_id");
+ $recurring_amount = 0;
+ while($row = mysqli_fetch_array($sql)) {
+ $item_total = floatval($row['item_total']);
+ $recurring_amount = $recurring_amount + $item_total;
+ }
+ $recurring_amount = $recurring_amount - $recurring_discount;
- mysqli_query($mysqli,"UPDATE recurring SET recurring_scope = '$scope', recurring_frequency = '$frequency', recurring_next_date = '$next_date', recurring_category_id = $category, recurring_status = $status WHERE recurring_id = $recurring_id");
+ mysqli_query($mysqli,"UPDATE recurring SET recurring_scope = '$scope', recurring_frequency = '$frequency', recurring_next_date = '$next_date', recurring_category_id = $category, recurring_discount_amount = $recurring_discount, recurring_amount = $recurring_amount, recurring_status = $status WHERE recurring_id = $recurring_id");
mysqli_query($mysqli,"INSERT INTO history SET history_status = '$status', history_description = 'Recurring modified', history_recurring_id = $recurring_id");
@@ -277,14 +286,23 @@
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_tax_id = $tax_id, item_order = $item_order, item_recurring_id = $recurring_id");
- //Update Recurring Balances
+ //Get Discount
$sql = mysqli_query($mysqli,"SELECT * FROM recurring WHERE recurring_id = $recurring_id");
$row = mysqli_fetch_array($sql);
+ $recurring_discount = floatval($row['recurring_discount_amount']);
- $new_recurring_amount = floatval($row['recurring_amount']) + $total;
- mysqli_query($mysqli,"UPDATE recurring SET recurring_amount = $new_recurring_amount WHERE recurring_id = $recurring_id");
+ //add up all the items
+ $sql = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE item_recurring_id = $recurring_id");
+ $recurring_amount = 0;
+ while($row = mysqli_fetch_array($sql)) {
+ $item_total = floatval($row['item_total']);
+ $recurring_amount = $recurring_amount + $item_total;
+ }
+ $recurring_amount = $recurring_amount - $recurring_discount;
+
+ mysqli_query($mysqli,"UPDATE recurring SET recurring_amount = $recurring_amount WHERE recurring_id = $recurring_id");
$_SESSION['alert_message'] = "Recurring Invoice Updated";
@@ -509,19 +527,28 @@
mysqli_query($mysqli,"UPDATE invoices SET invoice_amount = $new_invoice_amount WHERE invoice_id = $invoice_id");
}elseif ($quote_id > 0) {
+ //Get Discount Amount
+ $sql = mysqli_query($mysqli,"SELECT * FROM quotes WHERE quote_id = $quote_id");
+ $row = mysqli_fetch_array($sql);
+ $quote_discount = floatval($row['quote_discount_amount']);
+
//Update Quote Balances by tallying up items
$sql_quote_total = mysqli_query($mysqli,"SELECT SUM(item_total) AS quote_total FROM invoice_items WHERE item_quote_id = $quote_id");
$row = mysqli_fetch_array($sql_quote_total);
- $new_quote_amount = floatval($row['quote_total']);
+ $new_quote_amount = floatval($row['quote_total']) - $quote_discount;
mysqli_query($mysqli,"UPDATE quotes SET quote_amount = $new_quote_amount WHERE quote_id = $quote_id");
} else {
- //Update Invoice Balances by tallying up invoice items
+ //Get Discount Amount
+ $sql = mysqli_query($mysqli,"SELECT * FROM recurring WHERE recurring_id = $recurring_id");
+ $row = mysqli_fetch_array($sql);
+ $recurring_discount = floatval($row['recurring_discount_amount']);
+ //Update Invoice Balances by tallying up invoice items
$sql_recurring_total = mysqli_query($mysqli,"SELECT SUM(item_total) AS recurring_total FROM invoice_items WHERE item_recurring_id = $recurring_id");
$row = mysqli_fetch_array($sql_recurring_total);
- $new_recurring_amount = floatval($row['recurring_total']);
+ $new_recurring_amount = floatval($row['recurring_total']) - $recurring_discount;
mysqli_query($mysqli,"UPDATE recurring SET recurring_amount = $new_recurring_amount WHERE recurring_id = $recurring_id");
@@ -990,7 +1017,7 @@
header("Location: " . $_SERVER["HTTP_REFERER"]);
-} //End Force Recurring
+}
if (isset($_POST['export_client_invoices_csv'])) {
$client_id = intval($_POST['client_id']);
diff --git a/post/invoice_model.php b/post/invoice_model.php
index 0bf5c2557..b124a486a 100644
--- a/post/invoice_model.php
+++ b/post/invoice_model.php
@@ -2,4 +2,5 @@
$date = sanitizeInput($_POST['date']);
$category = intval($_POST['category']);
$scope = sanitizeInput($_POST['scope']);
-$invoice_discount = floatval($_POST['invoice_discount']);
\ No newline at end of file
+$invoice_discount = floatval($_POST['invoice_discount']);
+$recurring_discount = floatval($_POST['recurring_discount']);
\ No newline at end of file
diff --git a/post/quote.php b/post/quote.php
index 08c77af85..bbd4c3445 100644
--- a/post/quote.php
+++ b/post/quote.php
@@ -143,7 +143,8 @@
}
if (isset($_POST['add_quote_item'])) {
-
+
+ include 'post/quote_model.php';
$quote_id = intval($_POST['quote_id']);
$name = sanitizeInput($_POST['name']);
@@ -168,13 +169,22 @@
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_tax_id = $tax_id, item_order = $item_order, item_quote_id = $quote_id");
- //Update Invoice Balances
-
+ //Get Discount
$sql = mysqli_query($mysqli,"SELECT * FROM quotes WHERE quote_id = $quote_id");
$row = mysqli_fetch_array($sql);
- $new_quote_amount = floatval($row['quote_amount']) + $total;
+ $quote_discount_amount = floatval($row['quote_discount_amount']);
+
+ //add up the total of all items
+ $sql = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE item_quote_id = $quote_id");
+ $quote_amount = 0;
+ while($row = mysqli_fetch_array($sql)) {
+ $item_total = floatval($row['item_total']);
+ $quote_amount = $quote_amount + $item_total;
+ }
+ $new_quote_amount = $quote_amount - $quote_discount_amount;
+
mysqli_query($mysqli,"UPDATE quotes SET quote_amount = $new_quote_amount WHERE quote_id = $quote_id");
$_SESSION['alert_message'] = "Item added";
@@ -203,7 +213,17 @@
$quote_id = intval($_POST['quote_id']);
- mysqli_query($mysqli,"UPDATE quotes SET quote_scope = '$scope', quote_date = '$date', quote_expire = '$expire', quote_category_id = $category WHERE quote_id = $quote_id");
+ //Calculate the new quote amount
+ $sql = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE item_quote_id = $quote_id");
+ $quote_amount = 0;
+ while($row = mysqli_fetch_array($sql)) {
+ $item_total = floatval($row['item_total']);
+ $quote_amount = $quote_amount + $item_total;
+ }
+ $quote_amount = $quote_amount - $quote_discount;
+
+
+ mysqli_query($mysqli,"UPDATE quotes SET quote_scope = '$scope', quote_date = '$date', quote_expire = '$expire', quote_discount_amount = '$quote_discount', quote_amount = '$quote_amount', quote_category_id = $category WHERE quote_id = $quote_id");
//Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Quote', log_action = 'Modify', log_description = '$quote_id', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");
diff --git a/post/quote_model.php b/post/quote_model.php
index 48be970db..061d685a5 100644
--- a/post/quote_model.php
+++ b/post/quote_model.php
@@ -3,3 +3,4 @@
$expire = sanitizeInput($_POST['expire']);
$category = intval($_POST['category']);
$scope = sanitizeInput($_POST['scope']);
+$quote_discount = floatval($_POST['quote_discount']);
diff --git a/quote.php b/quote.php
index 0acb0ad78..3685073d5 100644
--- a/quote.php
+++ b/quote.php
@@ -31,6 +31,7 @@
$quote_date = nullable_htmlentities($row['quote_date']);
$quote_expire = nullable_htmlentities($row['quote_expire']);
$quote_amount = floatval($row['quote_amount']);
+ $quote_discount = floatval($row['quote_discount_amount']);
$quote_currency_code = nullable_htmlentities($row['quote_currency_code']);
$quote_note = nullable_htmlentities($row['quote_note']);
$quote_url_key = nullable_htmlentities($row['quote_url_key']);
@@ -421,6 +422,17 @@
+ 0) {
+ ?>
+
+ Discount |
+ |
+
+
Subtotal |
|
diff --git a/quote_edit_modal.php b/quote_edit_modal.php
index a6a0960fb..5188b69d2 100644
--- a/quote_edit_modal.php
+++ b/quote_edit_modal.php
@@ -47,6 +47,17 @@
+
+
+
|