File "CashFlowDebitToMonthResource.php"
Full Path: /var/www/html/back/app/Http/Resources/CashFlowDebitToMonthResource.php
File size: 1.66 KB
MIME-type: text/x-php
Charset: utf-8
<?php
namespace App\Http\Resources;
use App\Domain\Payment\Enums\PaymentTypeEnum;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class CashFlowDebitToMonthResource extends JsonResource
{
public function toArray(Request $request): array
{
$totalCredit = 0;
$totalCash = 0;
$totalExtradition = 0;
if (!$this->total_amount) {
$amount = (float)$this->amount;
if (isset($this->article->article_type)) {
if ($this->article->article_type == 'debit') {
if (($this->payment->payment_type != PaymentTypeEnum::PAYMENT_TYPE_MOVING->value) &&
($this->payment->payment_type != PaymentTypeEnum::PAYMENT_TYPE_ISSUEANCE->value)) {
$totalCredit += $amount;
}
}
}
}
if (isset($this->payment->payment_type)) {
$amount = (float)$this->amount;
if ($this->payment->payment_type == PaymentTypeEnum::PAYMENT_TYPE_RECEPTION->value) {
$totalCash += $amount;
}
}
if ($this->payment->payment_type == PaymentTypeEnum::PAYMENT_TYPE_ISSUEANCE->value) {
$amount = (float)$this->amount;
$totalExtradition += $amount;
}
return [
'id' => $this->article->id,
'name' => $this->article->name,
'type' => $this->article->article_type,
'total_amount' => $this->total_amount ?? $totalCredit,
'total_cash' => $totalCash,
'total_extradition' => $this->total_extradition ?? $totalExtradition,
];
}
}