<?php namespace App\Http\Resources\User; use Illuminate\Http\Resources\Json\JsonResource; class OrderResource extends JsonResource { public function toArray($request = null) { $total_items_qty = $this->items->sum('quantity') ?? 0; $total_engraving_fee = $this->items->sum('engraving_fee') ?? 0; $total_price_after_engraving = $this->items->sum('total_price_after_engraving') ?? 0; //Rush order Calculation $grand_total = $total_price_after_engraving + $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).'%', 'payment_status' => $this->payment_status, 'payment_date' => $this->formated_payment_date, 'payment_type' => $this->payment_type, 'cheque_number' => $this->cheque_number, 'purchase_order_number' => $this->purchase_order_number ?? 'N/A', 'purchase_order_copy' => $this->purchase_order_copy_url ?? 'N/A', 'current_status' => $this->current_status?->name, 'total_products' => $total_items_qty, 'engraving_fee' => '$'.number_format($total_engraving_fee, 2), 'sub_total' => '$'.number_format($this->items_total, 2), 'state_sales_tax' => [ 'percentage' => $this->state_sales_tax, 'amount' => number_format($this->sales_tax_amount, 2), ], 'waive_off_sales_tax' => $this->waive_off_sales_tax == 1 ? 'Yes' : 'No', 'shipping_charges' => '$'.number_format($this->shipping_charges, 2), 'grand_total' => '$'.(number_format($grand_total, 2)), 'created_at' => $this->created_at->format('m-d-Y'), ]; } }