mirror of https://github.com/itflow-org/itflow
Commented out Credit lines as its not ready for next release running into way to many pitfalls will focus more on next release
This commit is contained in:
parent
530a76a9a2
commit
d584c6b1e8
|
|
@ -137,11 +137,12 @@
|
|||
<div class="ml-1 mt-1 text-secondary">Balance
|
||||
<span class="<?php if ($balance > 0) { echo "text-danger"; }else{ echo "text-dark"; } ?> float-right"> <?php echo numfmt_format_currency($currency_format, $balance, $client_currency_code); ?></span>
|
||||
</div>
|
||||
<?php if ($credit_balance) { ?>
|
||||
<?php /* Credit Not Ready 2025-08-27 JQ
|
||||
if ($credit_balance) { ?>
|
||||
<div class="ml-1 mt-1 text-secondary">Credit
|
||||
<span class="text-success float-right"><?php echo numfmt_format_currency($currency_format, $credit_balance, $client_currency_code); ?></span>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php } */?>
|
||||
<div class="ml-1 mt-1 text-secondary">Monthly Recurring
|
||||
<span class="text-dark float-right"> <?php echo numfmt_format_currency($currency_format, $recurring_monthly, $client_currency_code); ?></span>
|
||||
</div>
|
||||
|
|
@ -178,6 +179,6 @@
|
|||
</div>
|
||||
|
||||
<?php
|
||||
require_once "modals/client/client_credit_add.php";
|
||||
// require_once "modals/client/client_credit_add.php"; --Credit Not Ready 2025-08-27
|
||||
require_once "modals/client/client_delete.php";
|
||||
require_once "modals/client/client_download_pdf.php";
|
||||
|
|
|
|||
|
|
@ -4,25 +4,14 @@ require_once '../../../includes/modal_header.php';
|
|||
|
||||
$invoice_id = intval($_GET['id']);
|
||||
|
||||
$sql = mysqli_query(
|
||||
$mysqli,
|
||||
"SELECT * FROM invoices
|
||||
LEFT JOIN clients ON invoice_client_id = client_id
|
||||
LEFT JOIN contacts ON client_id = contact_client_id AND contact_primary = 1
|
||||
WHERE invoice_id = $invoice_id
|
||||
LIMIT 1"
|
||||
);
|
||||
$sql = mysqli_query($mysqli, "SELECT invoice_prefix, invoice_number, invoice_client_id
|
||||
FROM invoices WHERE invoice_id = $invoice_id LIMIT 1
|
||||
");
|
||||
|
||||
$row = mysqli_fetch_array($sql);
|
||||
$invoice_id = intval($row['invoice_id']);
|
||||
$invoice_prefix = nullable_htmlentities($row['invoice_prefix']);
|
||||
$invoice_number = intval($row['invoice_number']);
|
||||
$invoice_amount = floatval($row['invoice_amount']);
|
||||
$client_id = intval($row['client_id']);
|
||||
$client_name = nullable_htmlentities($row['client_name']);
|
||||
$client_currency_code = nullable_htmlentities($row['client_currency_code']);
|
||||
$contact_name = nullable_htmlentities($row['contact_name']);
|
||||
$contact_email = nullable_htmlentities($row['contact_email']);
|
||||
$client_id = intval($row['invoice_client_id']);
|
||||
|
||||
// Get Credit Balance
|
||||
$sql_credit_balance = mysqli_query($mysqli, "SELECT SUM(credit_amount) AS credit_balance FROM credits WHERE credit_client_id = $client_id");
|
||||
|
|
@ -30,27 +19,18 @@ $row = mysqli_fetch_array($sql_credit_balance);
|
|||
|
||||
$credit_balance = floatval($row['credit_balance']);
|
||||
|
||||
//Add up all the payments for the invoice and get the total amount paid to the invoice
|
||||
$sql_amount_paid = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS amount_paid FROM payments WHERE payment_invoice_id = $invoice_id");
|
||||
$row = mysqli_fetch_array($sql_amount_paid);
|
||||
$amount_paid = floatval($row['amount_paid']);
|
||||
|
||||
$invoice_balance = $invoice_amount - $amount_paid;
|
||||
|
||||
// Generate the HTML form content using output buffering.
|
||||
ob_start();
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-wallet mr-2"></i><?php echo "$invoice_prefix$invoice_number"; ?>: Apply Credit (Balance: <?php echo numfmt_format_currency($currency_format, $credit_balance, $client_currency_code); ?>)</h5>
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-wallet mr-2"></i><?php echo "$invoice_prefix$invoice_number"; ?>: Apply Credit (Balance: <?php echo numfmt_format_currency($currency_format, $credit_balance, $session_company_currency); ?>)</h5>
|
||||
<button type="button" class="close text-white" data-dismiss="modal">
|
||||
<span>×</span>
|
||||
</button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="invoice_id" value="<?php echo $invoice_id; ?>">
|
||||
<input type="hidden" name="invoice_balance" value="<?php echo $invoice_balance; ?>">
|
||||
<input type="hidden" name="currency_code" value="<?php echo $client_currency_code; ?>">
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="form-group">
|
||||
|
|
@ -59,22 +39,10 @@ ob_start();
|
|||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-wallet"></i></span>
|
||||
</div>
|
||||
<input type="text" class="form-control" inputmode="numeric" pattern="[0-9]*\.?[0-9]{0,2}" name="amount" value="<?php echo number_format($credit_balance, 2, '.', ''); ?>" placeholder="0.00" required>
|
||||
<input type="text" class="form-control" inputmode="numeric" pattern="[0-9]*\.?[0-9]{0,2}" name="amount_credit_applied" value="<?php echo number_format($credit_balance, 2, '.', ''); ?>" placeholder="0.00" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($config_smtp_host) && !empty($contact_email)) { ?>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Email Receipt</label>
|
||||
<div class="custom-control custom-checkbox">
|
||||
<input type="checkbox" class="custom-control-input" id="customControlAutosizing" name="email_receipt" value="1" checked>
|
||||
<label class="custom-control-label" for="customControlAutosizing"><?php echo $contact_email; ?></label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
|
|
|
|||
|
|
@ -920,29 +920,58 @@ if (isset($_POST['add_payment'])) {
|
|||
|
||||
}
|
||||
|
||||
/*
|
||||
Apply Credit Not ready for use 2025-08-27 - JQ
|
||||
|
||||
if (isset($_POST['apply_credit'])) {
|
||||
|
||||
enforceUserPermission('module_sales', 2);
|
||||
enforceUserPermission('module_financial', 2);
|
||||
|
||||
$invoice_id = intval($_POST['invoice_id']);
|
||||
$amount = floatval($_POST['amount']);
|
||||
$invoice_balance = floatval($_POST['invoice_balance']);
|
||||
$currency_code = sanitizeInput($_POST['currency_code']);
|
||||
$email_receipt = intval($_POST['email_receipt'] ?? 0);
|
||||
$credit_amount_applied = floatval($_POST['credit_amount_applied']);
|
||||
|
||||
$client_id = getFieldByID('invoices',$invoice_id,'invoice_client_id');
|
||||
$invoice_prefix = getFieldByID('invoices',$invoice_id,'invoice_prefix');
|
||||
$invoice_number = getFieldByID('invoices',$invoice_id,'invoice_number');
|
||||
$invoice_status = getFieldByID('invoices',$invoice_id,'invoice_status');
|
||||
$invoice_credit_amount = floatval(getFieldByID('invoices',$invoice_id,'invoice_credit_amount'));
|
||||
$total_credit_amount = $invoice_credit_amount + $amount;
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM invoices LEFT JOIN clients ON invoice_client_id = client_id WHERE invoice_id = $invoice_id");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
|
||||
$invoice_prefix = sanitizeInput($row['invoice_prefix']);
|
||||
$invoice_number = intval($row['invoice_number']);
|
||||
$invoice_status = sanitizeInput($row['invoice_status']);
|
||||
$invoice_credit_amount = floatval($row['invoice_credit_amount']);
|
||||
$invoice_amount = floatval('invoice_amount');
|
||||
$client_id = intval($row['invoice_client_id']);
|
||||
|
||||
//Check to see if amount entered is greater than the balance of the invoice
|
||||
if ($amount > $invoice_balance) {
|
||||
// Get Credit Balance
|
||||
$sql_credit_balance = mysqli_query($mysqli, "SELECT SUM(credit_amount) AS credit_balance FROM credits WHERE credit_client_id = $client_id");
|
||||
$row = mysqli_fetch_array($sql_credit_balance);
|
||||
|
||||
$credit_balance = floatval($row['credit_balance']);
|
||||
|
||||
// Get Invoice Balance
|
||||
$sql_amount_paid = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS amount_paid FROM payments WHERE payment_invoice_id = $invoice_id");
|
||||
$row = mysqli_fetch_array($sql_amount_paid);
|
||||
$amount_paid = floatval($row['amount_paid']);
|
||||
|
||||
$invoice_balance = $invoice_amount - $amount_paid;
|
||||
|
||||
// Get Credit Tally applied to invoice
|
||||
$sql_credit_tally = mysqli_query($mysqli, "SELECT SUM(credit_tally) AS credit_balance FROM credits WHERE credit_invoice_id = $invoice_id");
|
||||
$row = mysqli_fetch_array($sql_credit_tally);
|
||||
|
||||
$credit_tally = floatval($row['credit_tally']);
|
||||
|
||||
// Check to see if amount entered is greater than the balance of the invoice
|
||||
if ($credit_amount_applied > $invoice_balance) {
|
||||
flash_alert("Credit can not be more than the balance", 'alert');
|
||||
redirect();
|
||||
}
|
||||
|
||||
// Check to see if amount entered is greater than the credit balance
|
||||
if ($credit_amount_applied > $credit_balance) {
|
||||
flash_alert("Credit can not be more than the available credit", 'alert');
|
||||
redirect();
|
||||
}
|
||||
|
||||
// Insert a new credit usage record linked to the invoice
|
||||
mysqli_query($mysqli, "
|
||||
INSERT INTO credits SET
|
||||
|
|
@ -953,6 +982,8 @@ if (isset($_POST['apply_credit'])) {
|
|||
credit_invoice_id = $invoice_id
|
||||
");
|
||||
|
||||
$new_invoice_amount = $invoice_amount - $credit_amount_applied;
|
||||
|
||||
// Calculate updated invoice credit sum
|
||||
$result = mysqli_query($mysqli, "
|
||||
SELECT SUM(credit_amount) AS credit_total
|
||||
|
|
@ -996,6 +1027,8 @@ if (isset($_POST['apply_credit'])) {
|
|||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
if (isset($_GET['add_payment_stripe'])) {
|
||||
|
||||
validateCSRFToken($_GET['csrf_token']);
|
||||
|
|
|
|||
Loading…
Reference in New Issue