DONE: add certs 1 and certs 3 endpoint ~ bid,otc,stb

This commit is contained in:
2026-10-22 10:10:44 +08:00
parent 060f7a22cd
commit f804e4211e
4 changed files with 232 additions and 157 deletions
+205 -62
View File
@@ -57,43 +57,69 @@ class KomuditiController extends Controller
}
/**
* Dummy BSAS eCert layout preview (2-page A4).
* Dummy BSAS eCert layout preview (bid, OTC, STB, then one commodity schedule).
*/
public function previewBsasEcert()
{
$cert = [
'ecert_no' => 'CPO13OCT26-0000136-025',
'seller' => 'KOPERASI PERMODALAN KELANTAN BERHAD',
'buyer' => 'WAN MOHAMAD AIMAN',
'bid_no' => '1',
'report_time' => '13:39:23.751',
'report_date' => '13 OCTOBER 2026',
'value_date' => '13 OCTOBER 2026',
'product' => 'CPO-MSIA-09',
'unit' => 'Tonnage',
'volume' => '.72562358',
'currency' => 'MYR',
'price' => '5,256.72',
'price_myr' => '5,256.72',
'value' => '3,200.00',
'txn_type' => '-',
'murabaha' => '3,814.40',
'lines' => [
[
'supplier' => 'POA RESOURCES BERHAD',
'volume' => '.72562358',
],
],
$line = [
['SUPPLIER' => 'FGV TRADING SDN BHD', 'VOLUME' => '0.75276406'],
];
return view('print.bsas_ecert', [
'cert' => $cert,
'isDummy' => true,
]);
return view('print.bsas_ecert', $this->presentBsasCertificates([
'e_cert_no' => 'CPO21OCT26-0000031-000',
'serial_number' => '1',
'otc_counter_party' => 'ALI BIN ABU',
'otc_murabaha_value' => '3,814.40',
'product_code' => 'CPO-MSIA-09',
'bid_ecert' => [
'ECERTNO' => 'CPO21OCT26-0000031-000',
'BUYER' => 'KOPERASI PERMODALAN KELANTAN BERHAD',
'OWNER' => 'KOPERASI PERMODALAN KELANTAN BERHAD',
'BIDNO' => '8',
'TOTALVALUE' => '3,200.00',
'CURRENCY' => 'MYR',
'PRICE' => '4,251.00',
'PRICE_MYR_EQUIVALENT' => '4,251.00',
'PURCHASETIMEDATE' => '15:11:53.316 21 Oct 2026',
'VALUEDATE' => '21 Oct 2026',
'PNAME' => 'CPO-MSIA-09',
'PVOLUME' => '0.75276406',
'LINE' => $line,
],
'otc_ecert' => [
'ECERTNO' => 'CPO21OCT26-0000031-000',
'SELLER' => 'KOPERASI PERMODALAN KELANTAN BERHAD',
'BUYER' => 'ALI BIN ABU',
'REPORTINGTIMEDATE' => '15:11:53.320 21 Oct 2026',
'VALUEDATE' => '21 Oct 2026',
'PNAME' => 'CPO-MSIA-09',
'PVOLUME' => '0.75276406',
'CURRENCY' => 'MYR',
'PRICE' => '4,251.00',
'PRICE_MYR_EQUIVALENT' => '4,251.00',
'TOTALVALUE' => '3,200.00',
'MURABAHAVALUE' => '3,814.40',
'LINE' => $line,
],
'stb_ecert' => [
'ECERTNO' => 'CPO21OCT26-0000031-000',
'SELLER' => 'ALI BIN ABU',
'BUYER' => 'BURSA MALAYSIA ISLAMIC SERVICES',
'TOTALVALUE' => '3,200.00',
'CURRENCY' => 'MYR',
'PRICE' => '4,251.00',
'PRICE_MYR_EQUIVALENT' => '4,251.00',
'SELLINGTIMEDATE' => '15:11:53.325 21 Oct 2026',
'VALUEDATE' => '21 Oct 2026',
'PNAME' => 'CPO-MSIA-09',
'PVOLUME' => '0.75276406',
'LINE' => $line,
],
], true));
}
/**
* Live BSAS eCert from stored bsas_orders.ecert_response.
* Live BSAS eCerts from stored bid, OTC and STB payloads.
*/
public function showBsasEcert($uuid)
{
@@ -109,32 +135,152 @@ class KomuditiController extends Controller
}
$payload = $response->json();
$ecert = $payload['ecert'] ?? null;
if (!is_array($payload)) {
abort(502, 'Gagal memuatkan eCert BSAS.');
}
if (!is_array($ecert) || empty($ecert)) {
$presented = $this->presentBsasCertificates($payload, false);
if ($presented['certificates'] === []) {
abort(404, 'eCert belum tersedia untuk order ini.');
}
return view('print.bsas_ecert', [
'cert' => $this->mapBsasEcertToView($ecert, $payload),
'isDummy' => false,
]);
return view('print.bsas_ecert', $presented);
}
/**
* Map stored otcXML / eCert JSON into print view fields.
* Bid, OTC and STB pages, plus one shared commodity schedule.
*/
protected function mapBsasEcertToView(array $ecert, array $orderMeta = []): array
protected function presentBsasCertificates(array $payload, bool $isDummy): array
{
$reporting = trim((string) ($ecert['REPORTINGTIMEDATE'] ?? ''));
$reportTime = '-';
$reportDate = '-';
if ($reporting !== '') {
$parts = explode(' ', $reporting, 2);
$reportTime = $parts[0] ?? '-';
$reportDate = isset($parts[1]) ? strtoupper($parts[1]) : '-';
$certificates = [];
$bid = $payload['bid_ecert'] ?? null;
if (is_array($bid) && $bid !== []) {
$certificates[] = $this->mapBidCertificate($bid, $payload);
}
$otc = $payload['otc_ecert'] ?? null;
if (is_array($otc) && $otc !== []) {
$certificates[] = $this->mapOtcCertificate($otc, $payload);
}
$stb = $payload['stb_ecert'] ?? null;
if (is_array($stb) && $stb !== []) {
$certificates[] = $this->mapStbCertificate($stb, $payload);
}
$scheduleSource = [];
if (is_array($otc) && $otc !== []) {
$scheduleSource = $otc;
} elseif (is_array($bid) && $bid !== []) {
$scheduleSource = $bid;
} elseif (is_array($stb) && $stb !== []) {
$scheduleSource = $stb;
}
$ecertNo = $scheduleSource['ECERTNO'] ?? ($payload['e_cert_no'] ?? '-');
return [
'certificates' => $certificates,
'ecert_no' => $ecertNo,
'lines' => $this->mapBsasLines($scheduleSource),
'isDummy' => $isDummy,
];
}
protected function mapBidCertificate(array $ecert, array $orderMeta): array
{
[$time, $date] = $this->splitBsasDateTime((string) ($ecert['PURCHASETIMEDATE'] ?? ''));
return $this->certificatePage(
'Certificate of Bid',
'This is to certify that the following bid transaction has been executed<br>through the Bursa Suq Al-Sila\' in accordance with the<br>Rules of Bursa Suq Al-Sila\'.',
'Generated for Ar-Rahn / Koperasi Permodalan Kelantan Berhad · BSAS Bid Certificate',
$ecert,
$orderMeta,
array_merge([
['label' => 'Buyer', 'value' => $ecert['BUYER'] ?? '-'],
['label' => 'Owner', 'value' => $ecert['OWNER'] ?? '-'],
['label' => 'Bid No', 'value' => $ecert['BIDNO'] ?? ($orderMeta['serial_number'] ?? '-')],
['label' => 'Purchase Time / Date', 'value' => $time . ' / ' . $date],
], $this->commodityDetailRows($ecert, $orderMeta))
);
}
protected function mapOtcCertificate(array $ecert, array $orderMeta): array
{
[$time, $date] = $this->splitBsasDateTime((string) ($ecert['REPORTINGTIMEDATE'] ?? ''));
$page = $this->certificatePage(
'Certificate of Purchase',
'This is to certify that the following transaction has been executed<br>through the Bursa Suq Al-Sila\' in accordance with the<br>Rules of Bursa Suq Al-Sila\'.',
'Generated for Ar-Rahn / Koperasi Permodalan Kelantan Berhad · BSAS OTC Certificate',
$ecert,
$orderMeta,
array_merge([
['label' => 'Seller', 'value' => $ecert['SELLER'] ?? 'KOPERASI PERMODALAN KELANTAN BERHAD'],
['label' => 'Buyer', 'value' => $ecert['BUYER'] ?? ($orderMeta['otc_counter_party'] ?? '-')],
['label' => 'Bid No', 'value' => $orderMeta['serial_number'] ?? '1'],
['label' => 'Reporting Time / Date', 'value' => $time . ' / ' . $date],
], $this->commodityDetailRows($ecert, $orderMeta), [
['label' => 'Transaction Type', 'value' => '-'],
])
);
$page['show_murabaha'] = true;
$page['murabaha'] = $ecert['MURABAHAVALUE'] ?? ($orderMeta['otc_murabaha_value'] ?? '-');
return $page;
}
protected function mapStbCertificate(array $ecert, array $orderMeta): array
{
[$time, $date] = $this->splitBsasDateTime((string) ($ecert['SELLINGTIMEDATE'] ?? ''));
return $this->certificatePage(
'Certificate of Sale',
'This is to certify that the following sale transaction has been executed<br>through the Bursa Suq Al-Sila\' in accordance with the<br>Rules of Bursa Suq Al-Sila\'.',
'Generated for Ar-Rahn / Koperasi Permodalan Kelantan Berhad · BSAS STB Certificate',
$ecert,
$orderMeta,
array_merge([
['label' => 'Seller', 'value' => $ecert['SELLER'] ?? ($orderMeta['otc_counter_party'] ?? '-')],
['label' => 'Buyer', 'value' => $ecert['BUYER'] ?? '-'],
['label' => 'Selling Time / Date', 'value' => $time . ' / ' . $date],
], $this->commodityDetailRows($ecert, $orderMeta))
);
}
protected function certificatePage(string $title, string $statement, string $footerNote, array $ecert, array $orderMeta, array $rows): array
{
return [
'title' => $title,
'statement' => $statement,
'footer_note' => $footerNote,
'ecert_no' => $ecert['ECERTNO'] ?? ($orderMeta['e_cert_no'] ?? '-'),
'currency' => $ecert['CURRENCY'] ?? 'MYR',
'rows' => $rows,
'show_murabaha' => false,
'murabaha' => null,
];
}
protected function commodityDetailRows(array $ecert, array $orderMeta): array
{
return [
['label' => 'Value Date', 'value' => isset($ecert['VALUEDATE']) ? strtoupper((string) $ecert['VALUEDATE']) : '-'],
['label' => 'Product Code / Description', 'value' => $ecert['PNAME'] ?? ($orderMeta['product_code'] ?? '-')],
['label' => 'Unit', 'value' => 'Tonnage'],
['label' => 'Volume', 'value' => $ecert['PVOLUME'] ?? '-'],
['label' => 'Currency', 'value' => $ecert['CURRENCY'] ?? 'MYR'],
['label' => 'Price (MYR)', 'value' => $ecert['PRICE'] ?? '-'],
['label' => 'Price (MYR Equivalent)', 'value' => $ecert['PRICE_MYR_EQUIVALENT'] ?? ($ecert['PRICE'] ?? '-')],
['label' => 'Value', 'value' => $ecert['TOTALVALUE'] ?? '-'],
];
}
protected function mapBsasLines(array $ecert): array
{
$lines = [];
foreach (($ecert['LINE'] ?? []) as $line) {
if (!is_array($line)) {
@@ -146,31 +292,28 @@ class KomuditiController extends Controller
];
}
if (empty($lines)) {
if ($lines === []) {
$lines[] = [
'supplier' => '-',
'volume' => $ecert['PVOLUME'] ?? '-',
];
}
return $lines;
}
protected function splitBsasDateTime(string $value): array
{
$value = trim($value);
if ($value === '') {
return ['-', '-'];
}
$parts = explode(' ', $value, 2);
return [
'ecert_no' => $ecert['ECERTNO'] ?? ($orderMeta['e_cert_no'] ?? '-'),
'seller' => $ecert['SELLER'] ?? 'KOPERASI PERMODALAN KELANTAN BERHAD',
'buyer' => $ecert['BUYER'] ?? ($orderMeta['otc_counter_party'] ?? '-'),
'bid_no' => $orderMeta['serial_number'] ?? '1',
'report_time' => $reportTime,
'report_date' => $reportDate,
'value_date' => isset($ecert['VALUEDATE']) ? strtoupper((string) $ecert['VALUEDATE']) : '-',
'product' => $ecert['PNAME'] ?? ($orderMeta['product_code'] ?? '-'),
'unit' => 'Tonnage',
'volume' => $ecert['PVOLUME'] ?? '-',
'currency' => $ecert['CURRENCY'] ?? 'MYR',
'price' => $ecert['PRICE'] ?? '-',
'price_myr' => $ecert['PRICE_MYR_EQUIVALENT'] ?? ($ecert['PRICE'] ?? '-'),
'value' => $ecert['TOTALVALUE'] ?? '-',
'txn_type' => '-',
'murabaha' => $ecert['MURABAHAVALUE'] ?? ($orderMeta['otc_murabaha_value'] ?? '-'),
'lines' => $lines,
$parts[0] ?? '-',
isset($parts[1]) ? strtoupper($parts[1]) : '-',
];
}
}
+2 -2
View File
@@ -1579,7 +1579,7 @@
'</li>' +
'<li id="bsas-step-3" class="mb-2 small text-muted" data-state="pending">' +
'<span class="bsas-step-icon mr-1">○</span>' +
'<strong>3.</strong> Mengambil e-Cert &amp; simpan gadai' +
'<strong>3.</strong> Mengambil e-Cert bid, OTC dan STB &amp; simpan gadai' +
'<div class="bsas-step-remark text-muted" style="margin-left:1.25rem;"></div>' +
'</li>' +
'</ol>' +
@@ -1652,7 +1652,7 @@
});
setBsasStep(2, 'done', 'Keputusan diterima.');
setBsasStep(3, 'active', 'Mengambil e-Cert & menyimpan gadai...');
setBsasStep(3, 'active', 'Mengambil e-Cert bid, OTC dan STB & menyimpan gadai...');
await delayMs(1000);
setBsasStep(3, 'done', 'Selesai.');
await delayMs(600);
@@ -490,7 +490,7 @@
function bsasEcertAction(row) {
var ecertNo = row['e_cert_no'] || '';
var hasEcert = !!row['has_ecert'];
var hasEcert = !!(row['has_bid_ecert'] || row['has_otc_ecert'] || row['has_stb_ecert']);
var uuid = row['uuid'] || '';
if (!hasEcert || !uuid) {
@@ -520,7 +520,7 @@
$.each(rekod, function (index, row) {
bilcount++;
var ecertNo = row['e_cert_no'] || '-';
if (row['has_ecert'] && row['uuid']) {
if ((row['has_bid_ecert'] || row['has_otc_ecert'] || row['has_stb_ecert']) && row['uuid']) {
ecertNo = '<a href="{{ url('/komoditi/bsas/ecert') }}/' + encodeURIComponent(row['uuid']) + '" target="_blank">' +
(row['e_cert_no'] || 'eCert') +
'</a>';
+23 -91
View File
@@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BSAS eCert — {{ $cert['ecert_no'] ?? 'Preview' }}</title>
<title>BSAS eCert — {{ $ecert_no ?? 'Preview' }}</title>
<style>
:root {
--ink: #1a2332;
@@ -240,38 +240,18 @@
</head>
<body>
@php
$cert = $cert ?? [];
$ecertNo = $cert['ecert_no'] ?? 'CPO13OCT26-0000136-025';
$seller = $cert['seller'] ?? 'KOPERASI PERMODALAN KELANTAN BERHAD';
$buyer = $cert['buyer'] ?? 'WAN MOHAMAD AIMAN';
$bidNo = $cert['bid_no'] ?? '1';
$reportTime = $cert['report_time'] ?? '13:39:23.751';
$reportDate = $cert['report_date'] ?? '13 OCTOBER 2026';
$valueDate = $cert['value_date'] ?? '13 OCTOBER 2026';
$product = $cert['product'] ?? 'CPO-MSIA-09';
$unit = $cert['unit'] ?? 'Tonnage';
$volume = $cert['volume'] ?? '.72562358';
$currency = $cert['currency'] ?? 'MYR';
$price = $cert['price'] ?? '5,256.72';
$priceMyr = $cert['price_myr'] ?? '5,256.72';
$value = $cert['value'] ?? '3,200.00';
$txnType = $cert['txn_type'] ?? '-';
$murabaha = $cert['murabaha'] ?? '3,814.40';
$lines = $cert['lines'] ?? [];
if (empty($lines)) {
$lines = [[
'supplier' => $cert['supplier'] ?? '-',
'volume' => $cert['supplier_volume'] ?? ($cert['volume'] ?? '-'),
]];
}
$isDummy = $isDummy ?? true;
$certificates = $certificates ?? [];
$lines = $lines ?? [];
$ecertNo = $ecert_no ?? 'CPO21OCT26-0000031-000';
$isDummy = $isDummy ?? false;
$pageTotal = count($certificates) + 1;
@endphp
<div class="preview-bar">
<div>
@if($isDummy)
<span class="badge">DUMMY PREVIEW</span>
&nbsp; BSAS e-Certificate layout — 2 pages A4
&nbsp; BSAS e-Certificate layout — {{ $pageTotal }} pages A4
@else
BSAS e-Certificate — {{ $ecertNo }}
@endif
@@ -282,7 +262,7 @@
</div>
<div class="sheet-stack">
{{-- PAGE 1 --}}
@foreach($certificates as $index => $certificate)
<section class="page">
<x-print.bsas.watermark />
@@ -290,89 +270,41 @@
<x-print.bsas.header />
<div class="page-body">
<h1 class="cert-title">Certificate of Purchase</h1>
<div class="cert-no">Certificate Number: <strong>{{ $ecertNo }}</strong></div>
<h1 class="cert-title">{{ $certificate['title'] }}</h1>
<div class="cert-no">Certificate Number: <strong>{{ $certificate['ecert_no'] ?? $ecertNo }}</strong></div>
<div class="gold-rule"></div>
<p class="statement">
This is to certify that the following transaction has been executed<br>
through the Bursa Suq Al-Sila' in accordance with the<br>
Rules of Bursa Suq Al-Sila'.
</p>
<p class="statement">{!! $certificate['statement'] !!}</p>
<h2 class="section-label">Detail</h2>
<div class="detail-panel">
<table class="detail-grid">
@foreach($certificate['rows'] as $row)
<tr>
<td class="label">Seller</td>
<td class="value">{{ $seller }}</td>
</tr>
<tr>
<td class="label">Buyer</td>
<td class="value">{{ $buyer }}</td>
</tr>
<tr>
<td class="label">Bid No</td>
<td class="value">{{ $bidNo }}</td>
</tr>
<tr>
<td class="label">Reporting Time / Date</td>
<td class="value">{{ $reportTime }} / {{ $reportDate }}</td>
</tr>
<tr>
<td class="label">Value Date</td>
<td class="value">{{ $valueDate }}</td>
</tr>
<tr>
<td class="label">Product Code / Description</td>
<td class="value">{{ $product }}</td>
</tr>
<tr>
<td class="label">Unit</td>
<td class="value">{{ $unit }}</td>
</tr>
<tr>
<td class="label">Volume</td>
<td class="value">{{ $volume }}</td>
</tr>
<tr>
<td class="label">Currency</td>
<td class="value">{{ $currency }}</td>
</tr>
<tr>
<td class="label">Price (MYR)</td>
<td class="value">{{ $price }}</td>
</tr>
<tr>
<td class="label">Price (MYR Equivalent)</td>
<td class="value">{{ $priceMyr }}</td>
</tr>
<tr>
<td class="label">Value</td>
<td class="value">{{ $value }}</td>
</tr>
<tr>
<td class="label">Transaction Type</td>
<td class="value">{{ $txnType }}</td>
<td class="label">{{ $row['label'] }}</td>
<td class="value">{{ $row['value'] }}</td>
</tr>
@endforeach
</table>
@if(!empty($certificate['show_murabaha']))
<div class="murabaha-box">
<span class="k">Murabaha Value</span>
<span class="v">{{ $currency }} {{ $murabaha }}</span>
<span class="v">{{ $certificate['currency'] ?? 'MYR' }} {{ $certificate['murabaha'] }}</span>
</div>
@endif
</div>
</div>
<x-print.bsas.footer
note="Generated for Ar-Rahn / Koperasi Permodalan Kelantan Berhad · BSAS OTC Certificate"
:page="1"
:total="2"
:note="$certificate['footer_note'] ?? ''"
:page="$index + 1"
:total="$pageTotal"
/>
</div>
</section>
@endforeach
{{-- PAGE 2 --}}
<section class="page">
<x-print.bsas.watermark />
@@ -405,7 +337,7 @@
</div>
</div>
<x-print.bsas.footer :page="2" :total="2">
<x-print.bsas.footer :page="$pageTotal" :total="$pageTotal">
This schedule forms part of Certificate No. {{ $ecertNo }}
</x-print.bsas.footer>
</div>