app\helpers\Utility::totalByStatusOrder PHP Method

totalByStatusOrder() public static method

totalByStatusOrder it stores all the orders totals by type to be used either in a reports view or a simple one.
public static totalByStatusOrder ( $orders ) : [array]
return [array]
    public static function totalByStatusOrder($orders)
    {
        $summary = ['open' => ['qty' => 0, 'total' => 0], 'pending' => ['qty' => 0, 'total' => 0], 'sent' => ['qty' => 0, 'total' => 0], 'closed' => ['qty' => 0, 'total' => 0], 'cancelled' => ['qty' => 0, 'total' => 0]];
        $orders->each(function ($order, $key) use(&$summary) {
            $total = self::totalOrder($order->details);
            switch ($order->status) {
                case 'open':
                    $summary['open']['qty']++;
                    $summary['open']['total'] += $total['total'];
                    break;
                case 'pending':
                    $summary['pending']['qty']++;
                    $summary['pending']['total'] += $total['total'];
                    break;
                case 'sent':
                    $summary['sent']['qty']++;
                    $summary['sent']['total'] += $total['total'];
                    break;
                case 'closed':
                    $summary['closed']['qty']++;
                    $summary['closed']['total'] += $total['total'];
                    break;
                case 'cancelled':
                    $summary['cancelled']['qty']++;
                    $summary['cancelled']['total'] += $total['total'];
                    break;
            }
        });
        return $summary;
    }