/
var
/
www
/
html
/
back
/
app
/
Http
/
Resources
/
Upload File
HOME
<?php namespace App\Http\Resources; use App\Domain\Article\Enums\ArticleTypeEnum; use App\Domain\Payment\Enums\PaymentStatusEnum; use App\Domain\Payment\Enums\PaymentTypeEnum; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; class ProjectWithoutGroupsResource extends JsonResource { /** * Transform the resource into an array. * * @return array<string, mixed> */ public function toArray(Request $request): array { $creditAmount = 0; $debitAmount = 0; $totalCountPaymentStatusNotFinal = 0; $totalAmountPayment = 0; if (isset($this->paymentDistributions) && is_iterable($this->paymentDistributions)) { $countPayment = 0; $amountPayment = 0; foreach ($this->paymentDistributions as $distribution) { if (($distribution->payment->payment_type == PaymentTypeEnum::PAYMENT_TYPE_RECEPTION) || (($distribution->payment->payment_type == PaymentTypeEnum::PAYMENT_TYPE_RECEPTION_FROM_1C))) { $creditAmount = (float)$distribution->amount; } else { $debitAmount = (float)$distribution->amount; } if ((($distribution->payment->payment_type == PaymentTypeEnum::PAYMENT_TYPE_PAYMENT->value) || ($distribution->payment->payment_type == PaymentTypeEnum::PAYMENT_TYPE_ISSUEANCE->value) || ($distribution->payment->payment_type == PaymentTypeEnum::PAYMENT_TYPE_MOVING->value)) && (($distribution->payment->status != PaymentStatusEnum::STATUS_PAID->value) && ($distribution->payment->status != PaymentStatusEnum::STATUS_ISSUED->value) && ($distribution->payment->status != PaymentStatusEnum::STATUS_RECEIVED->value))) { $countPayment += 1; $amountPayment += $distribution->amount; } } $totalCountPaymentStatusNotFinal += $countPayment; $totalAmountPayment += $amountPayment; } return [ 'id' => $this->id, 'status' => $this->status, 'description' => $this->description, 'short_description' => $this->short_description, 'offer_number' => $this->offer_number, 'object_address' => $this->object_address, 'project_limits' => [ 'credit' => $this->project_limits_debit, 'debit' => $this->project_limits_credit, ], 'project_amounts' => [ 'credit' => $creditAmount, 'debit' => $debitAmount, ], 'total_payments' => [ 'in_process' => $totalCountPaymentStatusNotFinal, 'total_amount_payment' => $totalAmountPayment, ], ]; } }