/
var
/
www
/
html
/
back
/
app
/
Http
/
Resources
/
Upload File
HOME
<?php namespace App\Http\Resources; use App\Domain\Payment\Enums\PaymentTypeEnum; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; class ProjectResource extends JsonResource { /** * Transform the resource into an array. * * @return array<string, mixed> */ public function toArray(Request $request): array { $totalCredit = 0; $totalDebit = 0; foreach ($this->paymentDistributions as $distribution) { $amount = (float)$distribution->amount; if (($distribution->payment->payment_type == PaymentTypeEnum::PAYMENT_TYPE_RECEPTION) || (($distribution->payment->payment_type == PaymentTypeEnum::PAYMENT_TYPE_RECEPTION_FROM_1C))) { $totalCredit += $amount; } else { $totalDebit += $amount; } } return [ 'id' => $this->id, 'model_id' => $this->model_id, 'description' => $this->description, 'short_description' => $this->short_description, 'offer_number' => $this->offer_number, 'object_address' => $this->object_address, 'total_credit' => $totalCredit, 'total_debit' => $totalDebit, 'project_group' => $this->projectGroup ? [ 'id' => $this->projectGroup->id, 'model_id' => $this->projectGroup->model_id, 'name' => $this->projectGroup->name, 'description' => $this->projectGroup->description, ] : null, ]; } }