vendredi 20 septembre 2019

A non well formed numeric value encountered in laravel 5.5

I have this code

private function calculateDefferedRevenue($price, $sub)
{
    $defferedrevenue = '0.00';

    if ($sub->has('fulfillment') && is_object($sub->fulfillment)) {
        $fulfillments = $sub->fulfillment;

        foreach ($fulfillments as $key => $fulfillment) {
            if ($fulfillment->has('shipments') && !is_null($fulfillment->shipments)) {
                $counts = self::countShipments($fulfillment->shipments);

                if (!empty($price) && $counts['shipmentCount'] > 0) {
                    $shippingFee        = self::getShippingFee($sub);
                    $shippingFees       = $counts['unshippedCount'] * $shippingFee;
                    $price              = self::deductUsingCoupon($price, $sub);
                    $eachShipmentAmount = $price / $counts['shipmentCount'];
                    $revenue            = $eachShipmentAmount * $counts['unshippedCount'];
                    $revenue            = $revenue + $shippingFees;
                    $defferedrevenue    = $defferedrevenue + $revenue;
                    $defferedrevenue    = number_format($defferedrevenue, 2);
                }
            }
        }
    }

    return $defferedrevenue;
}

and these are the set of values return from sentry after running lines aboove in the laravel queue jobs

{
counts: {
shipmentCount: 4, 
shippedCount: 1, 
unshippedCount: 3
}, 
defferedrevenue: 1,049.25, 
eachShipmentAmount: 349.75, 
key: 1, 
price: 1399.00, 
revenue: 1049.25, 
shippingFee: 0.00, 
shippingFees: 0, 
sub: Object Subscription
}

Why php is saying A non well formed numeric value encountered on this line

$defferedrevenue    = $defferedrevenue + $revenue;


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire