How to add paid and outstanding amount in order page

How to add paid and outstanding amount in order page

Sometimes you may need to know how much the current outstanding and paid amount. Especially you accept the preorder and customer only paid deposit on it.

Aslo it is easier to make mistake when you manually add the order thru the backoffice for the offline order like whatsapp, email, phone channel. For the new version of order page, you need to scroll down to the bottom for payment detail. Therefore, an outstanding and paid amount display will be very convenient.

 

Directly edit OrderController.php

I will not recommend this method. Directly modifing the core code will be very dangerous when you need to upgrade. During the version, all of your code will be gone. Our introduction here is only for reference because we don’t want to spend a paragraph to teach how to write a module for that.

The better way is following the below link and override it by a module.
https://devdocs.prestashop.com/1.7/modules/concepts/controllers/admin-controllers/override-decorate-controller/

In order to introduce a fastest solution with few paragraphs, you can follow the below tutorial.

/src/PrestaShopBundle/Controller/Admin/Sell/Order/OrderController.php

 

Add the following content after line 532

// start – edited  by admin @22Jul2022
$paidAmount = 0;
$balanceAmount = 0;
$amountToPay = $orderForViewing->getPrices()->getTotalAmountFormatted();
$amountToPay = floatval(preg_replace(‘/[^\d\.]+/’, ”, $amountToPay));
$paymentArrayAmt = array_values((array)$orderForViewing->getPayments());
 
foreach($paymentArrayAmt[0] as $key){
//echo “<pre>”;
$originvalue = $key->getAmount(); // Adrian
// is negative number
$neg = strpos((string)$originvalue, ‘-‘) !== false;
// remove everything except numbers and dot “.”
$originvalue = preg_replace(“/[^0-9\.]/”, “”, $originvalue);
// Set negative number
if( $neg ) {
$originvalue = ‘-‘.$originvalue;
}
//convert string to float
$originvalue = (float) $originvalue;
// sum all order payment amount
$paidAmount += $originvalue;
}
// calculate from Total Amount substract Paid Amount
$balanceAmount = $amountToPay – $paidAmount;
// verify null value if true store default value 0 and set the price format
if (empty($balanceAmount)) {
$balanceAmount = $this->getContextLocale()->formatPrice(0, $orderCurrency->iso_code);
}else{
$balanceAmount = $this->getContextLocale()->formatPrice($balanceAmount, $orderCurrency->iso_code);
}
if (empty($paidAmount)) {
$paidAmount = $this->getContextLocale()->formatPrice(0, $orderCurrency->iso_code);
} else {
$paidAmount = $this->getContextLocale()->formatPrice($paidAmount, $orderCurrency->iso_code);
}
 
// end – edited by admin @23Jul2022
return$this->render(‘@PrestaShop/Admin/Sell/Order/Order/view.html.twig’, [
// start – edited by admin @@23Jul2022
‘outstandingAmt’ => $balanceAmount,
‘orderPaymentPaidAmt’ => $paidAmount,
// end – edited by admin @@23Jul2022
 
/src/PrestaShopBundle/Resources/views/Admin/Sell/Order/Order/Blocks/View/products.html.twig
 
line 201 after this {% if not orderForViewing.taxIncluded %}
 
{#** edited by admin @23Jul2022 adding Balance amount **#}
<divclass=”col-sm text-center”>
<pclass=”text-muted mb-0″><strong>{{ ‘Outstanding’|trans({}, ‘Admin.Global’) }}</strong></p>
<strongid=”outstandingTotal”>{{ outstandingAmt }}</strong>
</div>

 

{#** edited by admin @23Jul2022 adding Balance amount **#}
<divclass=”col-sm text-center”>
<pclass=”text-muted mb-0″><strong>{{ ‘Paid Amt’|trans({}, ‘Admin.Global’) }}</strong></p>
<strongid=”orderPaymentPaid”>{{ orderPaymentPaidAmt }}</strong>
</div>
 
/src/PrestaShopBundle/Resources/views/Admin/Sell/Order/Order/Blocks/View/payments_alert.html.twig
 
line 29 after this {{ ‘Warning’|trans({}, ‘Admin.Global’) }}
 
{# start – edited by admin @26Sep2022 – replace the right amount for the paidAmount #}
{# <strong>{{ payments.paidAmount }}</strong> #}
{% if orderPaymentPaidAmt is defined %}
<strong>{{ orderPaymentPaidAmt }}</strong>
{% else %}
<strong>{{ ‘Press F5 reload the Paid Amount’|trans({}, ‘Admin.Orderscustomers.Notification’) }}</strong>
{% endif %}
{# end – edited by admin @26Sep2022 – replace the right amount for the paidAmount #}



Start typing and press Enter to search