Files
aso/app/Console/Commands/UpdateNoSjp.php
2025-09-22 09:04:00 +07:00

48 lines
1.8 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Models\OLDLMS\Livechat;
use Carbon\Carbon;
use Illuminate\Console\Command;
use GuzzleHttp\Client;
class UpdateNoSJP extends Command {
protected $signature = 'update:no-sjp';
protected $description = 'Cek data Livechat yang sNoSpj kosong lalu generate SJP lewat API';
public function handle() {
$this->info('Checking Data ...');
$client = new Client([ 'base_uri' => 'https://api.linksehat.dev', 'headers' => ['Content-Type' => 'application/json'], 'timeout' => 10, ]);
$liveChats = Livechat::query()
->join('tx_livechat_summary', 'tx_livechat_summary.nIDLiveChat', '=', 'tx_livechat.nID')
->whereNull('tx_livechat.sNoSpj')
->whereDate('tx_livechat.dCreateOn', Carbon::today())
->select('tx_livechat.nID', 'tx_livechat_summary.nID as summary_id')
->get();
foreach ($liveChats as $row) {
try {
$prescriptionData = [
'nIDLivechats' => [$row->nID]
];
$response = $client->post('/api/rujukan-dan-sjp', [
'json' => $prescriptionData,
]);
$body = json_decode($response->getBody()->getContents(), true);
$this->info('Jumlah Livechat dikirim: ' . $liveChats->count());
$this->info("Nomor SJP berhasil dibuat untuk Livechat {$row->nID}");
} catch (\Exception $e) {
$this->error("Gagal generate Nomor SJP Livechat {$row->nID}: " . $e->getMessage());
}
}
$this->info('Proses selesai.');
return Command::SUCCESS;
}
}