![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/inventory.corals.io/Corals/modules/Inventory/Transformers/ |
<?php namespace Corals\Modules\Inventory\Transformers; use Corals\Foundation\Transformers\BaseTransformer; use Corals\Modules\Inventory\Models\Order; use Corals\Modules\Payment\Facades\Payments; use Throwable; class OrderTransformer extends BaseTransformer { public function __construct($extras = []) { $this->resource_url = config('inventory.models.order.resource_url'); parent::__construct($extras); } /** * @param Order $order * @return array * @throws Throwable */ public function transform(Order $order) { $levels = [ 'pending' => 'info', 'submitted' => 'info', 'processing' => 'success', 'completed' => 'primary', 'failed' => 'danger', 'cancelled' => 'warning' ]; $payment_levels = [ 'pending' => 'info', 'paid' => 'success', 'cancelled' => 'danger', 'refunded' => 'danger', 'partial_refund' => 'warning', 'failed' => 'danger', ]; $payment_status = $order->billing['payment_status'] ?? ''; if ($order->user) { if (user() && user()->can('view', $order->user)) { $user_id = "<a href='" . url('inv/customers/' . $order->user->hashed_id) . "'> {$order->user->full_name}</a>"; } else { $user_id = $order->user->full_name; } } else { $user_id = '-'; } if ($order->invoice) { $invoice = "<a target='_blank' href='" . url('invoices/' . $order->invoice->hashed_id) . "'> {$order->invoice->code}</a>"; } else { $invoice = '-'; } if ($order->supplier) { $supplier = "<a target='_blank' href='" . url('inv/suppliers/' . $order->supplier->hashed_id) . "'> {$order->supplier->name}</a>"; } else { $supplier = '-'; } $currency = strtoupper($order->currency); $transformedArray = [ 'id' => $order->id, 'inventory' => optional($order->inventory)->name, 'customer' => optional($order->customer)->name, 'supplier_id' => $supplier, 'number' => HtmlElement('a', ['href' => $order->getShowURL()], $order->number), 'status' => formatStatusAsLabels($order->status, ['level' => $levels[$order->status], 'text' => trans('Inventory::status.order.' . $order->status)]), 'sub_total' => Payments::currency_convert($order->sub_total, null, $currency, true), 'discount_total' => Payments::currency_convert($order->discount_total, null, $currency, true), 'tax_total' => Payments::currency_convert($order->tax_total, null, $currency, true), 'total' => Payments::currency_convert($order->total, null, $currency, true), 'currency' => $order->currency, 'currency_exchange' => $order->currency_exchange, 'notes' => $order->notes, 'user_id' => $user_id, 'properties' => $order->properties, 'payment_status' => $payment_status ? formatStatusAsLabels($payment_status, [ 'level' => $payment_levels[$payment_status], 'text' => trans('Inventory::status.payment.' . $payment_status) ]) : ' - ', 'invoice' => $invoice, 'shipping' => $order->shipping, 'type' => data_get(trans('Inventory::attributes.order.order_types'), $order->type, $order->type), 'created_at' => format_date($order->created_at), 'updated_at' => format_date($order->updated_at), 'action' => $this->actions($order) ]; return parent::transformResponse($transformedArray); } }