Update Quotes and Recurrings with discounts
This commit is contained in:
@@ -83,6 +83,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
$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']);
|
||||
|
||||
@@ -83,6 +83,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
}
|
||||
$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']);
|
||||
|
||||
@@ -40,6 +40,7 @@ $quote_number = intval($row['quote_number']);
|
||||
$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 @@ if ($quote_status == "Draft" || $quote_status == "Sent" || $quote_status == "Vie
|
||||
<div class="col-sm-3 offset-sm-2">
|
||||
<table class="table table-borderless">
|
||||
<tbody>
|
||||
<?php
|
||||
if ($quote_discount > 0) {
|
||||
?>
|
||||
<tr class="border-bottom">
|
||||
<td>Discount</td>
|
||||
<td class="text-right"><?php echo numfmt_format_currency($currency_format, $quote_discount, $quote_currency_code); ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
$sub_total = $sub_total - $quote_discount;
|
||||
}
|
||||
?>
|
||||
<tr class="border-bottom">
|
||||
<td>Subtotal</td>
|
||||
<td class="text-right"><?php echo numfmt_format_currency($currency_format, $sub_total, $quote_currency_code); ?></td>
|
||||
|
||||
+37
-10
@@ -122,6 +122,7 @@ if (isset($_POST['add_invoice_copy'])) {
|
||||
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_invoice_recurring'])) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (isset($_POST['add_recurring'])) {
|
||||
|
||||
$client = intval($_POST['client']);
|
||||
@@ -210,8 +209,18 @@ if (isset($_POST['edit_recurring'])) {
|
||||
$category = intval($_POST['category']);
|
||||
$scope = sanitizeInput($_POST['scope']);
|
||||
$status = intval($_POST['status']);
|
||||
$recurring_discount = floatval($_POST['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");
|
||||
//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_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 @@ if (isset($_POST['add_recurring_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_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 @@ if (isset($_POST['edit_item'])) {
|
||||
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 @@ if (isset($_GET['force_recurring'])) {
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
|
||||
} //End Force Recurring
|
||||
}
|
||||
|
||||
if (isset($_POST['export_client_invoices_csv'])) {
|
||||
$client_id = intval($_POST['client_id']);
|
||||
|
||||
@@ -3,3 +3,4 @@ $date = sanitizeInput($_POST['date']);
|
||||
$category = intval($_POST['category']);
|
||||
$scope = sanitizeInput($_POST['scope']);
|
||||
$invoice_discount = floatval($_POST['invoice_discount']);
|
||||
$recurring_discount = floatval($_POST['recurring_discount']);
|
||||
+24
-4
@@ -144,6 +144,7 @@ if (isset($_POST['add_quote_to_invoice'])) {
|
||||
|
||||
if (isset($_POST['add_quote_item'])) {
|
||||
|
||||
include 'post/quote_model.php';
|
||||
$quote_id = intval($_POST['quote_id']);
|
||||
|
||||
$name = sanitizeInput($_POST['name']);
|
||||
@@ -168,12 +169,21 @@ if (isset($_POST['add_quote_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_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");
|
||||
|
||||
@@ -203,7 +213,17 @@ if (isset($_POST['edit_quote'])) {
|
||||
|
||||
$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");
|
||||
|
||||
@@ -3,3 +3,4 @@ $date = sanitizeInput($_POST['date']);
|
||||
$expire = sanitizeInput($_POST['expire']);
|
||||
$category = intval($_POST['category']);
|
||||
$scope = sanitizeInput($_POST['scope']);
|
||||
$quote_discount = floatval($_POST['quote_discount']);
|
||||
|
||||
@@ -31,6 +31,7 @@ if (isset($_GET['quote_id'])) {
|
||||
$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']);
|
||||
@@ -426,6 +427,17 @@ if (isset($_GET['quote_id'])) {
|
||||
<div class="col-sm-3 offset-sm-2">
|
||||
<table class="table table-borderless">
|
||||
<tbody>
|
||||
<?php
|
||||
if ($quote_discount > 0) {
|
||||
?>
|
||||
<tr class="border-bottom">
|
||||
<td>Discount</td>
|
||||
<td class="text-right"><?php echo numfmt_format_currency($currency_format, $quote_discount, $quote_currency_code); ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
$sub_total = $sub_total - $quote_discount;
|
||||
}
|
||||
?>
|
||||
<tr class="border-bottom">
|
||||
<td>Subtotal</td>
|
||||
<td class="text-right"><?php echo numfmt_format_currency($currency_format, $sub_total, $quote_currency_code); ?></td>
|
||||
|
||||
@@ -47,6 +47,17 @@
|
||||
</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' step="0.01" name='quote_discount' placeholder='Discount Amount' value='<?php echo $quote_discount; ?>'>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Scope</label>
|
||||
<div class="input-group">
|
||||
|
||||
@@ -110,6 +110,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
$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']);
|
||||
$quote_currency_code = nullable_htmlentities($row['quote_currency_code']);
|
||||
$quote_created_at = nullable_htmlentities($row['quote_created_at']);
|
||||
$client_id = intval($row['client_id']);
|
||||
|
||||
@@ -28,6 +28,7 @@ if (isset($_GET['recurring_id'])) {
|
||||
}
|
||||
$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_note = nullable_htmlentities($row['recurring_note']);
|
||||
$category_id = intval($row['recurring_category_id']);
|
||||
@@ -352,6 +353,18 @@ if (isset($_GET['recurring_id'])) {
|
||||
<div class="col-sm-3 offset-sm-2">
|
||||
<table class="table table-borderless">
|
||||
<tbody>
|
||||
<?php
|
||||
if ($recurring_discount > 0) {
|
||||
?>
|
||||
<tr class="border-bottom">
|
||||
<td>Discount</td>
|
||||
<td class="text-right"><?php echo numfmt_format_currency($currency_format, $recurring_discount, $recurring_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, $recurring_currency_code); ?></td>
|
||||
|
||||
@@ -30,9 +30,15 @@
|
||||
</div>
|
||||
<select class="form-control select2" name="frequency" required>
|
||||
<option value="">- Frequency -</option>
|
||||
<option <?php if ($recurring_frequency == 'week') { echo "selected"; } ?> value="week">Weekly</option>
|
||||
<option <?php if ($recurring_frequency == 'month') { echo "selected"; } ?> value="month">Monthly</option>
|
||||
<option <?php if ($recurring_frequency == 'year') { echo "selected"; } ?> value="year">Yearly</option>
|
||||
<option <?php if ($recurring_frequency == 'week') {
|
||||
echo "selected";
|
||||
} ?> value="week">Weekly</option>
|
||||
<option <?php if ($recurring_frequency == 'month') {
|
||||
echo "selected";
|
||||
} ?> value="month">Monthly</option>
|
||||
<option <?php if ($recurring_frequency == 'year') {
|
||||
echo "selected";
|
||||
} ?> value="year">Yearly</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
@@ -74,6 +80,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='recurring_discount' placeholder='Discount Amount' value='<?php echo $recurring_discount; ?>'>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Status <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
@@ -81,8 +97,12 @@
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-clock"></i></span>
|
||||
</div>
|
||||
<select class="form-control select2" name="status" required>
|
||||
<option <?php if ($recurring_status == 1) { echo "selected"; } ?> value="1">Active</option>
|
||||
<option <?php if ($recurring_status == 0) { echo "selected"; } ?> value="0">InActive</option>
|
||||
<option <?php if ($recurring_status == 1) {
|
||||
echo "selected";
|
||||
} ?> value="1">Active</option>
|
||||
<option <?php if ($recurring_status == 0) {
|
||||
echo "selected";
|
||||
} ?> value="0">InActive</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -105,6 +105,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
$recurring_scope = nullable_htmlentities($row['recurring_scope']);
|
||||
$recurring_frequency = nullable_htmlentities($row['recurring_frequency']);
|
||||
$recurring_status = nullable_htmlentities($row['recurring_status']);
|
||||
$recurring_discount = floatval($row['recurring_discount_amount']);
|
||||
$recurring_last_sent = $row['recurring_last_sent'];
|
||||
if ($recurring_last_sent == 0) {
|
||||
$recurring_last_sent = "-";
|
||||
|
||||
Reference in New Issue
Block a user