/
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 CashFlowQuarterDebitResource extends JsonResource { public function toArray(Request $request): array { $totalDebit = 0; $totalCashIsssueance = 0; $totalCashMoving = 0; foreach ($this->paymentDistributions as $distribution) { $amount = (float)$distribution->amount; if (isset($distribution->article->article_type)) { if ($distribution->article->article_type === 'debit') { $totalDebit += $amount; } } if (isset($distribution->payment->payment_type)) { if ($distribution->payment->payment_type == PaymentTypeEnum::PAYMENT_TYPE_ISSUEANCE->value) { $totalCashIsssueance += $amount; } } if (isset($distribution->payment->payment_type)) { if ($distribution->payment->payment_type == PaymentTypeEnum::PAYMENT_TYPE_MOVING->value) { $totalCashMoving += $amount; } } } return [ 'id' => $this->id, 'name' => $this->name, 'total_amount' => $totalDebit, 'total_cash_isssueance' => $totalCashIsssueance, 'total_cash_moving' => $totalCashMoving, ]; } }