Files
lelong/app/Jobs/Concerns/ResolvesJanaNotisJumlah.php
T
ismailmasseran e29a5891c8 Bugfix/list clickup issue (#5)
Reviewed-on: #5
Co-authored-by: ISMAIL MASSERAN <ismail@koppkb.com>
Co-committed-by: ISMAIL MASSERAN <ismail@koppkb.com>
2026-10-19 13:30:36 +08:00

61 lines
1.8 KiB
PHP

<?php
namespace App\Jobs\Concerns;
use App\Models\LelongBid;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
trait ResolvesJanaNotisJumlah
{
/**
* Resolve total amount (jumlah) for a SAG, matching PDF jananotis calculation.
*
* @return string|null Formatted amount e.g. "1,234.56"
*/
protected function resolveJanaNotisJumlah($kodcaw, $lelongId, $suratnotis)
{
$lelongBid = LelongBid::where('lelong_id', $lelongId)
->where('norujukan', $suratnotis->norujukan)
->first();
if (! $lelongBid) {
Log::warning('Jana notis jumlah: lelong bid not found', [
'lelong_id' => $lelongId,
'norujukan' => $suratnotis->norujukan,
]);
return null;
}
$tagbaru = (string) $suratnotis->tagbaru;
$jeniskeuntungan = $tagbaru === '1' ? 'onepercent' : 'asal';
$api = Http::get(config('app.api_ujrah_url').'get/upahtawarruqbytarikh', [
'kodcaw' => $kodcaw,
'norujukan' => $suratnotis->norujukan,
'tarikh' => $lelongBid->t_lelong,
'jeniskeuntungan' => $jeniskeuntungan,
])->json();
if (! is_array($api)) {
Log::warning('Jana notis jumlah: API returned null', [
'norujukan' => $suratnotis->norujukan,
'jeniskeuntungan' => $jeniskeuntungan,
]);
return null;
}
$nilaipembiayaan = (float) $lelongBid->pinjaman;
if ($tagbaru === '1') {
$jumlah = $nilaipembiayaan + (float) ($api['pendapatan'] ?? 0);
} else {
$jumlah = $nilaipembiayaan + (float) ($api['upahsemasa'] ?? 0);
}
return number_format($jumlah, 2, '.', ',');
}
}