![]() 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/medad.corals.io/Corals/modules/Medad/Transformers/API/ |
<?php namespace Corals\Modules\Medad\Transformers\API; use Corals\Modules\Medad\Models\Transaction; use Corals\Modules\Utility\Transformers\API\Comment\CommentPresenter; use Corals\User\Transformers\API\UserPresenter; class TransactionTransformer extends CommonAPIBaseTransformer { /** * @param Transaction $transaction * @return array * @throws \Throwable */ public function transform(Transaction $transaction) { $userPresenter = new UserPresenter(); $companyPresenter = new CompanyPresenter(); $branchPresenter = new BranchPresenter(); $commentPresenter = new CommentPresenter(); $transformedArray = [ 'id' => $transaction->id, 'code' => $transaction->code, 'notes' => $transaction->notes ?? null, 'types_count' => $transaction->types_count ?? null, 'total_quantity' => $transaction->total_quantity ?? null, 'amount' => $transaction->amount ?? null, 'status' => apiOptionAsObject($transaction->status, data_get(trans('Medad::attributes.transaction.status_options'), $transaction->status)), 'owner' => $this->presentAPIModel($transaction->owner, $userPresenter), 'customer' => $this->presentAPIModel($transaction->customerCompany, $companyPresenter), 'supplier' => $this->presentAPIModel($transaction->supplierCompany, $companyPresenter), 'customer_branch' => $this->presentAPIModel($transaction->customerBranch, $branchPresenter), 'supplier_branch' => $this->presentAPIModel($transaction->supplierBranch, $branchPresenter), 'invoice_code' => $transaction->invoice->code, 'invoice_id' => $transaction->invoice->id, 'project' => optional($transaction->project)->name ?? null, 'latest_note' => $this->presentAPIModel($transaction->comments()->first(), $commentPresenter), 'attachments' => $this->getAttachmentsList($transaction), 'created_at' => format_date($transaction->created_at), 'updated_at' => format_date($transaction->updated_at), ]; return parent::transformResponse($transformedArray, $transaction); } }