Refactored Currency Display using PHP numfmt_format_currency() function as this is best practice and will put the right currency symbol in the right place based off locale and currency type

This commit is contained in:
johnnyq
2022-02-17 22:20:59 -05:00
parent 8d8b922ba5
commit a9346845ab
26 changed files with 148 additions and 174 deletions

View File

@@ -3047,7 +3047,6 @@ if(isset($_GET['email_quote'])){
$quote_note = $row['quote_note'];
$quote_url_key = $row['quote_url_key'];
$quote_currency_code = $row['quote_currency_code'];
$quote_currency_symbol = htmlentities(get_currency_symbol($quote_currency_code)); //Needs HTML entities due to encoding (Â was showing up)
$client_id = $row['client_id'];
$client_name = $row['client_name'];
$contact_name = $row['contact_name'];
@@ -3096,7 +3095,7 @@ if(isset($_GET['email_quote'])){
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = "Quote";
$mail->Body = "Hello $contact_name,<br><br>Thank you for your inquiry, we are pleased to provide you with the following estimate.<br><br><br>Total Cost: $quote_currency_symbol$quote_amount<br><br><br>View and accept your estimate online <a href='https://$base_url/guest_view_quote.php?quote_id=$quote_id&url_key=$quote_url_key'>here</a><br><br><br>~<br>$company_name<br>$company_phone";
$mail->Body = "Hello $contact_name,<br><br>Thank you for your inquiry, we are pleased to provide you with the following estimate.<br><br><br>Total Cost: " . numfmt_format_currency($currency_format, $quote_amount, $quote_currency_code) . "<br><br><br>View and accept your estimate online <a href='https://$base_url/guest_view_quote.php?quote_id=$quote_id&url_key=$quote_url_key'>here</a><br><br><br>~<br>$company_name<br>$company_phone";
$mail->send();
echo 'Message has been sent';
@@ -3499,7 +3498,6 @@ if(isset($_POST['add_payment'])){
$amount = floatval($_POST['amount']);
$account = intval($_POST['account']);
$currency_code = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['currency_code'])));
$currency_symbol = htmlentities(get_currency_symbol($currency_code)); //Needs HTML entities due to encoding (Â was showing up)
$payment_method = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['payment_method'])));
$reference = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['reference'])));
$email_receipt = intval($_POST['email_receipt']);
@@ -3531,6 +3529,7 @@ if(isset($_POST['add_payment'])){
$invoice_prefix = $row['invoice_prefix'];
$invoice_number = $row['invoice_number'];
$invoice_url_key = $row['invoice_url_key'];
$invoice_currency_code = $row['invoice_currency_code'];
$client_name = $row['client_name'];
$contact_name = $row['contact_name'];
$contact_email = $row['contact_email'];
@@ -3556,10 +3555,6 @@ if(isset($_POST['add_payment'])){
//Calculate the Invoice balance
$invoice_balance = $invoice_amount - $total_payments_amount;
//Format Amount
$formatted_amount = number_format($amount,2);
$formatted_invoice_balance = number_format($invoice_balance,2);
//Determine if invoice has been paid then set the status accordingly
if($invoice_balance == 0){
@@ -3587,7 +3582,7 @@ if(isset($_POST['add_payment'])){
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = "Payment Recieved - Invoice $invoice_prefix$invoice_number";
$mail->Body = "Hello $contact_name,<br><br>We have recieved your payment in the amount of $currency_symbol$formatted_amount for invoice <a href='https://$base_url/guest_view_invoice.php?invoice_id=$invoice_id&url_key=$invoice_url_key'>$invoice_prefix$invoice_number</a>. Please keep this email as a receipt for your records.<br><br>Amount: $currency_symbol$formatted_amount<br>Balance: $currency_symbol$formatted_invoice_balance<br><br>Thank you for your business!<br><br><br>~<br>$company_name<br>$company_phone";
$mail->Body = "Hello $contact_name,<br><br>We have recieved your payment in the amount of " . numfmt_format_currency($currency_format, $amount, $payment_currency_code) . " for invoice <a href='https://$base_url/guest_view_invoice.php?invoice_id=$invoice_id&url_key=$invoice_url_key'>$invoice_prefix$invoice_number</a>. Please keep this email as a receipt for your records.<br><br>Amount: " . numfmt_format_currency($currency_format, $amount, $payment_currency_code) . "<br>Balance: " . numfmt_format_currency($currency_format, $invoice_balance, $invoice_currency_code) . "<br><br>Thank you for your business!<br><br><br>~<br>$company_name<br>$company_phone";
$mail->send();
echo 'Message has been sent';
@@ -3623,7 +3618,7 @@ if(isset($_POST['add_payment'])){
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = "Partial Payment Recieved - Invoice $invoice_prefix$invoice_number";
$mail->Body = "Hello $contact_name,<br><br>We have recieved partial payment in the amount of $currency_symbol$formatted_amount and it has been applied to invoice <a href='https://$base_url/guest_view_invoice.php?invoice_id=$invoice_id&url_key=$invoice_url_key'>$invoice_prefix$invoice_number</a>. Please keep this email as a receipt for your records.<br><br>Amount: $currency_symbol$formatted_amount<br>Balance: $currency_symbol$formatted_invoice_balance<br><br>Thank you for your business!<br><br><br>~<br>$company_name<br>$company_phone";
$mail->Body = "Hello $contact_name,<br><br>We have recieved partial payment in the amount of " . numfmt_format_currency($currency_format, $amount, $payment_currency_code) . " and it has been applied to invoice <a href='https://$base_url/guest_view_invoice.php?invoice_id=$invoice_id&url_key=$invoice_url_key'>$invoice_prefix$invoice_number</a>. Please keep this email as a receipt for your records.<br><br>Amount: " . numfmt_format_currency($currency_format, $amount, $payment_currency_code) . "<br>Balance: " . numfmt_format_currency($currency_format, $invoice_balance, $invoice_currency_code) . "<br><br>Thank you for your business!<br><br><br>~<br>$company_name<br>$company_phone";
$mail->send();
echo 'Message has been sent';
@@ -3717,7 +3712,6 @@ if(isset($_GET['email_invoice'])){
$invoice_amount = $row['invoice_amount'];
$invoice_url_key = $row['invoice_url_key'];
$invoice_currency_code = $row['invoice_currency_code'];
$invoice_currency_symbol = htmlentities(get_currency_symbol($invoice_currency_code)); //Needs HTML entities due to encoding (Â was showing up)
$client_id = $row['client_id'];
$client_name = $row['client_name'];
$client_name = $row['client_name'];
@@ -3779,7 +3773,7 @@ if(isset($_GET['email_invoice'])){
}else{
$mail->Subject = "Invoice $invoice_prefix$invoice_number";
$mail->Body = "Hello $contact_name,<br><br>Please view the details of the invoice below.<br><br>Invoice: $invoice_prefix$invoice_number<br>Issue Date: $invoice_date<br>Total: $invoice_currency_symbol$invoice_amount<br>Balance Due: $invoice_currency_symbol$balance<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=$invoice_id&url_key=$invoice_url_key'>here</a><br><br><br>~<br>$company_name<br>$company_phone";
$mail->Body = "Hello $contact_name,<br><br>Please view the details of the invoice below.<br><br>Invoice: $invoice_prefix$invoice_number<br>Issue Date: $invoice_date<br>Total: " . numfmt_format_currency($currency_format, $invoice_amount, $invoice_currency_code) . "<br>Balance Due: " . numfmt_format_currency($currency_format, $balance, $invoice_currency_code) . "<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=$invoice_id&url_key=$invoice_url_key'>here</a><br><br><br>~<br>$company_name<br>$company_phone";
//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
}