73 lines
3.2 KiB
PHP
Executable file
73 lines
3.2 KiB
PHP
Executable file
<?php
|
|
// 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();
|
|
if (isset($document['LineItem']) && is_array($document['LineItem'])) {
|
|
foreach ($document['LineItem'] as $li) {
|
|
$lineItems[] = array(
|
|
'item_number' => isset($li['item_number']) ? $li['item_number'] : '',
|
|
'quantity' => isset($li['quantity']) ? $li['quantity'] : '',
|
|
'title' => isset($li['title']) ? $li['title'] : '',
|
|
'description' => isset($li['description']) ? $li['description'] : '',
|
|
'unit_price' => isset($li['gross_unit_price']) ? floatval($li['gross_unit_price']) : 0.0,
|
|
'total_price' => isset($li['gross_price']) ? floatval($li['gross_price']) : 0.0,
|
|
'net_unit_price' => isset($li['net_unit_price']) ? floatval($li['net_unit_price']) : 0.0,
|
|
'net_price' => isset($li['net_price']) ? floatval($li['net_price']) : 0.0,
|
|
'discount_percent' => isset($li['discount_percent']) ? floatval($li['discount_percent']) : 0.0,
|
|
'discount_amount_unit' => isset($li['discount_amount_unit']) ? floatval($li['discount_amount_unit']) : 0.0,
|
|
'discount_amount_total' => isset($li['discount_amount_total']) ? floatval($li['discount_amount_total']) : 0.0,
|
|
'option' => isset($li['option']) ? intval($li['option']) : 0,
|
|
'has_text_prices' => isset($li['has_text_prices']) ? (bool)$li['has_text_prices'] : false,
|
|
'unit_price_string' => isset($li['unit_price_string']) ? $li['unit_price_string'] : '',
|
|
'gross_price_string' => isset($li['gross_price_string']) ? $li['gross_price_string'] : ''
|
|
);
|
|
}
|
|
}
|
|
|
|
$payload = array(
|
|
'document_id' => intval($document['Document']['id']),
|
|
'title' => $document['PackingList']['title'],
|
|
'customer_name' => $enquiry['Customer']['name'],
|
|
'job_title' => isset($job['Job']['title']) ? $job['Job']['title'] : '',
|
|
'issue_date' => $document['PackingList']['issue_date'],
|
|
'issue_date_string' => isset($issue_date_string) ? $issue_date_string : '',
|
|
'ship_via' => $document['PackingList']['ship_via'],
|
|
'fob' => $document['PackingList']['fob'],
|
|
'currency_symbol' => $currencySymbol,
|
|
'currency_code' => isset($currencyCode) ? $currencyCode : 'AUD',
|
|
'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;
|
|
}
|
|
?>
|
|
|
|
<script type="text/javascript">
|
|
window.location.replace("/documents/view/<?=$document['Document']['id']?>");
|
|
</script>
|
|
|