DONE: bsas integration first stage
This commit is contained in:
@@ -55,4 +55,122 @@ class KomuditiController extends Controller
|
||||
|
||||
return redirect()->route('komuditi');
|
||||
}
|
||||
|
||||
/**
|
||||
* Dummy BSAS eCert layout preview (2-page A4).
|
||||
*/
|
||||
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',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
return view('print.bsas_ecert', [
|
||||
'cert' => $cert,
|
||||
'isDummy' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Live BSAS eCert from stored bsas_orders.ecert_response.
|
||||
*/
|
||||
public function showBsasEcert($uuid)
|
||||
{
|
||||
$response = Http::withOptions(['verify' => config('app.api_verify')])
|
||||
->get(config('api.url') . '/api/komuditi/bsas/order/' . urlencode($uuid) . '/ecert');
|
||||
|
||||
if ($response->status() === 404) {
|
||||
abort(404, $response->json('message') ?: 'eCert tidak dijumpai.');
|
||||
}
|
||||
|
||||
if (!$response->successful()) {
|
||||
abort(502, 'Gagal memuatkan eCert BSAS.');
|
||||
}
|
||||
|
||||
$payload = $response->json();
|
||||
$ecert = $payload['ecert'] ?? null;
|
||||
|
||||
if (!is_array($ecert) || empty($ecert)) {
|
||||
abort(404, 'eCert belum tersedia untuk order ini.');
|
||||
}
|
||||
|
||||
return view('print.bsas_ecert', [
|
||||
'cert' => $this->mapBsasEcertToView($ecert, $payload),
|
||||
'isDummy' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Map stored otcXML / eCert JSON into print view fields.
|
||||
*/
|
||||
protected function mapBsasEcertToView(array $ecert, array $orderMeta = []): array
|
||||
{
|
||||
$reporting = trim((string) ($ecert['REPORTINGTIMEDATE'] ?? ''));
|
||||
$reportTime = '-';
|
||||
$reportDate = '-';
|
||||
if ($reporting !== '') {
|
||||
$parts = explode(' ', $reporting, 2);
|
||||
$reportTime = $parts[0] ?? '-';
|
||||
$reportDate = isset($parts[1]) ? strtoupper($parts[1]) : '-';
|
||||
}
|
||||
|
||||
$lines = [];
|
||||
foreach (($ecert['LINE'] ?? []) as $line) {
|
||||
if (!is_array($line)) {
|
||||
continue;
|
||||
}
|
||||
$lines[] = [
|
||||
'supplier' => $line['SUPPLIER'] ?? '-',
|
||||
'volume' => $line['VOLUME'] ?? ($ecert['PVOLUME'] ?? '-'),
|
||||
];
|
||||
}
|
||||
|
||||
if (empty($lines)) {
|
||||
$lines[] = [
|
||||
'supplier' => '-',
|
||||
'volume' => $ecert['PVOLUME'] ?? '-',
|
||||
];
|
||||
}
|
||||
|
||||
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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user