File "OrderDashboardResource.php"

Full Path: /home/clickysoft/public_html/jmapi5.clickysoft.net/app/Http/Resources/Admin/OrderDashboardResource.php
File size: 1.31 KB
MIME-type: text/x-php
Charset: utf-8

<?php

namespace App\Http\Resources\Admin;

use App\Models\SiteSetting;
use Illuminate\Http\Resources\Json\JsonResource;

class OrderDashboardResource extends JsonResource
{
    public function toArray($request)
    {
       $sub_total = $this->items()?->sum('total_price_after_engraving');

        //Rush order Calculation ()
        $grand_total = $sub_total + $this->rush_order_amount + $this->shipping_charges;

        if ($this->waive_off_sales_tax != 1)
            $grand_total += $this->sales_tax_amount;

        return [
            'id' => $this->id,
            'order_number'      => $this->order_number,
            'rush_order'        => $this->rush_order,
            'rush_order_fee'    => ($this->rush_order_fee ?? 0).'%',
            'rush_order_amount' => '$'.number_format($this->rush_order_amount, 2),
            'total_quantity'    =>  $this->items()?->sum('quantity'),
            'sub_total'         => '$'.number_format($sub_total, 2),
            'state_sales_tax'   => [
                'percentage'        => $this->state_sales_tax,
                'amount'            => number_format($this->sales_tax_amount, 2),
            ],
            'shipping_fee'      => '$'.(number_format($this->shipping_charges, 2)),
            'grand_total'       => '$'.(number_format($grand_total, 2)),
        ];
    }
}