/
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 CashFlowCreditToMonthResource extends JsonResource { public function toArray(Request $request): array { $totalCredit = 0; $totalCash = 0; if (!$this->total_amount) { $amount = (float)$this->amount; if (isset($this->article->article_type)) { if ($this->article->article_type === 'credit') { $totalCredit += $amount; } } } if (isset($this->payment->payment_type)) { $amount = (float)$this->amount; if ($this->payment->payment_type == PaymentTypeEnum::PAYMENT_TYPE_RECEPTION->value) { $totalCash += $amount; } } return [ 'id' => $this->article->id, 'name' => $this->article->name, 'type' => $this->article->article_type, 'total_amount' => $this->total_amount ?? $totalCredit, 'total_cash' => $totalCash, ]; } }