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

62 lines
2.2 KiB
Plaintext
Raw Normal View History

<?php
2026-01-12 03:00:48 -08:00
// Generate the Quote PDF by calling the Go service instead of TCPDF/FPDI.
$goBaseUrl = AppController::getGoBaseUrlOrFail();
$goEndpoint = $goBaseUrl . '/go/pdf/generate-quote';
$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'])
);
}
2026-01-12 03:00:48 -08:00
$payload = array(
'document_id' => intval($document['Document']['id']),
'cmc_reference' => $enquiry['Enquiry']['title'],
'revision' => intval($document['Document']['revision']),
'created_date' => date('Y-m-d', strtotime($enquiry['Enquiry']['created'])),
'customer_name' => $enquiry['Customer']['name'],
'contact_email' => $enquiry['Contact']['email'],
'contact_name' => $enquiry['Contact']['first_name'].' '.$enquiry['Contact']['last_name'],
'user_first_name' => $enquiry['User']['first_name'],
'user_last_name' => $enquiry['User']['last_name'],
'user_email' => $enquiry['User']['email'],
'currency_symbol' => $currencySymbol,
'show_gst' => (bool)$gst,
'commercial_comments' => isset($document['Quote']['commercial_comments']) ? $document['Quote']['commercial_comments'] : '',
'line_items' => $lineItems,
'pages' => array_map(function($p) { return $p['content']; }, $document['DocPage']),
'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 Quote PDF via Go service (HTTP $httpCode).";
if ($curlErr) {
echo " Error: $curlErr";
}
2026-01-12 03:00:48 -08:00
echo "</p>";
exit;
}
?>
2011-05-24 02:43:26 -07:00
<script type="text/javascript">
2011-09-11 22:20:41 -07:00
window.location.replace("/documents/view/<?=$document['Document']['id']?>");
</script>