2013-06-10 02:27:23 -07:00
|
|
|
<?php
|
2026-01-12 03:00:48 -08:00
|
|
|
// Generate the Packing List PDF by calling the Go service instead of TCPDF/FPDI.
|
|
|
|
|
|
|
|
|
|
$goBaseUrl = AppController::getGoBaseUrlOrFail();
|
|
|
|
|
$goEndpoint = $goBaseUrl . '/go/pdf/generate-packinglist';
|
|
|
|
|
|
|
|
|
|
$outputDir = Configure::read('pdf_directory');
|
|
|
|
|
|
|
|
|
|
$lineItems = array();
|
|
|
|
|
foreach ($document['LineItem'] as $li) {
|
|
|
|
|
$lineItems[] = array(
|
|
|
|
|
'item_number' => $li['item_number'],
|
|
|
|
|
'quantity' => $li['quantity'],
|
|
|
|
|
'title' => $li['title'],
|
|
|
|
|
'unit_price' => floatval($li['gross_unit_price']),
|
|
|
|
|
'total_price' => floatval($li['gross_price'])
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$payload = array(
|
|
|
|
|
'document_id' => intval($document['Document']['id']),
|
|
|
|
|
'customer_name' => $enquiry['Customer']['name'],
|
|
|
|
|
'currency_symbol' => $currencySymbol,
|
|
|
|
|
'show_gst' => (bool)$gst,
|
|
|
|
|
'line_items' => $lineItems,
|
|
|
|
|
'output_dir' => $outputDir
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$ch = curl_init($goEndpoint);
|
|
|
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
|
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
|
|
|
|
|
|
|
|
|
|
$response = curl_exec($ch);
|
|
|
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
|
|
$curlErr = curl_error($ch);
|
|
|
|
|
curl_close($ch);
|
|
|
|
|
|
|
|
|
|
if ($httpCode < 200 || $httpCode >= 300) {
|
|
|
|
|
echo "<p>Failed to generate Packing List PDF via Go service (HTTP $httpCode).";
|
|
|
|
|
if ($curlErr) {
|
|
|
|
|
echo " Error: $curlErr";
|
|
|
|
|
}
|
|
|
|
|
echo "</p>";
|
|
|
|
|
exit;
|
|
|
|
|
}
|
2013-06-10 02:27:23 -07:00
|
|
|
?>
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
window.location.replace("/documents/view/<?=$document['Document']['id']?>");
|
|
|
|
|
</script>
|
|
|
|
|
|