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

@@ -44,7 +44,6 @@ if(isset($_GET['invoice_id'])){
$contact_mobile = formatPhoneNumber($row['contact_mobile']);
$client_website = $row['client_website'];
$client_currency_code = $row['client_currency_code'];
$client_currency_symbol = get_currency_symbol($client_currency_code);
$client_net_terms = $row['client_net_terms'];
if($client_net_terms == 0){
$client_net_terms = $config_default_net_terms;
@@ -280,9 +279,9 @@ if(isset($_GET['invoice_id'])){
<td><?php echo $item_name; ?></td>
<td><div style="white-space:pre-line"><?php echo $item_description; ?></div></td>
<td class="text-center"><?php echo $item_quantity; ?></td>
<td class="text-right"><?php echo $client_currency_symbol; ?> <?php echo number_format($item_price,2); ?></td>
<td class="text-right"><?php echo $client_currency_symbol; ?> <?php echo number_format($item_tax,2); ?></td>
<td class="text-right"><?php echo $client_currency_symbol; ?><?php echo number_format($item_total,2); ?></td>
<td class="text-right"><?php echo numfmt_format_currency($currency_format, $item_price, $invoice_currency_code); ?></td>
<td class="text-right"><?php echo numfmt_format_currency($currency_format, $item_tax, $invoice_currency_code); ?></td>
<td class="text-right"><?php echo numfmt_format_currency($currency_format, $item_total, $invoice_currency_code); ?></td>
</tr>
<?php
@@ -354,23 +353,23 @@ if(isset($_GET['invoice_id'])){
<tbody>
<tr class="border-bottom">
<td>Subtotal</td>
<td class="text-right"><?php echo $client_currency_symbol; ?> <?php echo number_format($sub_total,2); ?></td>
<td class="text-right"><?php echo numfmt_format_currency($currency_format, $sub_total, $invoice_currency_code); ?></td>
</tr>
<?php if($total_tax > 0){ ?>
<tr class="border-bottom">
<td>Tax</td>
<td class="text-right"><?php echo $client_currency_symbol; ?> <?php echo number_format($total_tax,2); ?></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){ ?>
<tr class="border-bottom">
<td><div class="text-success">Paid to Date</div></td>
<td class="text-right text-success"><?php echo $client_currency_symbol; ?> <?php echo number_format($amount_paid,2); ?></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 Due</strong></td>
<td class="text-right"><strong><?php echo $client_currency_symbol; ?> <?php echo number_format($balance,2); ?></strong></td>
<td class="text-right"><strong><?php echo numfmt_format_currency($currency_format, $invoice_amount, $invoice_currency_code); ?></strong></td>
</tr>
</tbody>
</table>
@@ -461,13 +460,14 @@ if(isset($_GET['invoice_id'])){
$payment_id = $row['payment_id'];
$payment_date = $row['payment_date'];
$payment_amount = $row['payment_amount'];
$payment_currency_code = $row['payment_currency_code'];
$payment_reference = $row['payment_reference'];
$account_name = $row['account_name'];
?>
<tr>
<td><?php echo $payment_date; ?></td>
<td class=" text-right"><?php echo $client_currency_symbol; ?> <?php echo number_format($payment_amount,2); ?></td>
<td class="text-right"><?php echo numfmt_format_currency($currency_format, $invoice_amount, $payment_currency_code); ?></td>
<td><?php echo $payment_reference; ?></td>
<td><?php echo $account_name; ?></td>
<td class="text-center"><a class="btn btn-danger btn-sm" href="post.php?delete_payment=<?php echo $payment_id; ?>"><i class="fa fa-trash"></i></a></td>
@@ -518,7 +518,7 @@ include("footer.php");
});
</script>
<script src='plugins/pdfmake/pdfmake.js'></script>
<script src='plugins/pdfmake/pdfmake.min.js'></script>
<script src='plugins/pdfmake/vfs_fonts.js'></script>
<script>
@@ -696,15 +696,15 @@ var docDefinition = {
style:'itemQty'
},
{
text:'<?php echo $client_currency_symbol; ?> <?php echo number_format($item_price,2); ?>',
text:'<?php echo numfmt_format_currency($currency_format, $item_price, $invoice_currency_code); ?>',
style:'itemNumber'
},
{
text:'<?php echo $client_currency_symbol; ?> <?php echo number_format($item_tax,2); ?>',
text:'<?php echo numfmt_format_currency($currency_format, $item_tax, $invoice_currency_code); ?>',
style:'itemNumber'
},
{
text: '<?php echo $client_currency_symbol; ?> <?php echo number_format($item_total,2); ?>',
text: '<?php echo numfmt_format_currency($currency_format, $item_total, $invoice_currency_code); ?>',
style:'itemNumber'
}
],
@@ -746,7 +746,7 @@ var docDefinition = {
style:'itemsFooterSubTitle'
},
{
text:'<?php echo $client_currency_symbol; ?> <?php echo number_format($sub_total,2); ?>',
text:'<?php echo numfmt_format_currency($currency_format, $sub_total, $invoice_currency_code); ?>',
style:'itemsFooterSubValue'
}
],
@@ -757,7 +757,7 @@ var docDefinition = {
style:'itemsFooterSubTitle'
},
{
text: '<?php echo $client_currency_symbol; ?> <?php echo number_format($total_tax,2); ?>',
text: '<?php echo numfmt_format_currency($currency_format, $total_tax, $invoice_currency_code); ?>',
style:'itemsFooterSubValue'
}
],
@@ -768,7 +768,7 @@ var docDefinition = {
style:'itemsFooterSubTitle'
},
{
text: '<?php echo $client_currency_symbol; ?> <?php echo number_format($invoice_amount,2); ?>',
text: '<?php echo numfmt_format_currency($currency_format, $invoice_amount, $invoice_currency_code); ?>',
style:'itemsFooterSubValue'
}
],
@@ -779,7 +779,7 @@ var docDefinition = {
style:'itemsFooterSubTitle'
},
{
text: '<?php echo $client_currency_symbol; ?> <?php echo number_format($amount_paid,2); ?>',
text: '<?php echo numfmt_format_currency($currency_format, $amount_paid, $invoice_currency_code); ?>',
style:'itemsFooterSubValue'
}
],
@@ -790,7 +790,7 @@ var docDefinition = {
style:'itemsFooterTotalTitle'
},
{
text: '<?php echo $client_currency_symbol; ?> <?php echo number_format($balance,2); ?>',
text: '<?php echo numfmt_format_currency($currency_format, $balance, $invoice_currency_code); ?>',
style:'itemsFooterTotalTitle'
}