cmc-sales/php/app/views/documents/pdf_orderack.ctp

53 lines
1.5 KiB
PHP
Executable file

<?php
// Generate the Order Acknowledgement PDF by calling the Go service instead of TCPDF/FPDI.
$goBaseUrl = AppController::getGoBaseUrlOrFail();
$goEndpoint = $goBaseUrl . '/go/pdf/generate-orderack';
$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 Order Acknowledgement PDF via Go service (HTTP $httpCode).";
if ($curlErr) {
echo " Error: $curlErr";
}
echo "</p>";
exit;
}
?>
<script type="text/javascript">
window.location.replace("/documents/view/<?=$document['Document']['id']?>");
</script>