2009-10-08 01:42:23 -07:00
|
|
|
<?php
|
2026-01-12 03:00:48 -08:00
|
|
|
// Generate Quote PDF by calling the Go service instead of TCPDF.
|
|
|
|
|
|
|
|
|
|
$goBaseUrl = AppController::getGoBaseUrlOrFail();
|
|
|
|
|
$goEndpoint = $goBaseUrl . '/go/pdf/generate-quote';
|
|
|
|
|
|
|
|
|
|
$outputDir = Configure::read('pdf_directory');
|
|
|
|
|
|
|
|
|
|
$lineItems = array();
|
|
|
|
|
if (isset($products) && is_array($products)) {
|
|
|
|
|
foreach ($products 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'] : '',
|
|
|
|
|
'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,
|
|
|
|
|
);
|
2009-10-29 23:29:20 -07:00
|
|
|
}
|
2009-10-15 23:43:17 -07:00
|
|
|
}
|
|
|
|
|
|
2026-01-12 03:00:48 -08:00
|
|
|
$payload = array(
|
|
|
|
|
'document_id' => 0,
|
|
|
|
|
'cmc_reference' => $enquiry['Enquiry']['title'],
|
|
|
|
|
'revision' => intval($quote['Quote']['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' => isset($quote['Currency']['symbol']) ? $quote['Currency']['symbol'] : '$',
|
|
|
|
|
'show_gst' => (bool)$enquiry['Enquiry']['gst'],
|
|
|
|
|
'commercial_comments' => isset($commercialDetails) ? $commercialDetails : '',
|
|
|
|
|
'line_items' => $lineItems,
|
|
|
|
|
'pages' => array_map(function($p) { return $p['content']; }, $quote['QuotePage']),
|
|
|
|
|
'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";
|
|
|
|
|
}
|
|
|
|
|
echo "</p>";
|
|
|
|
|
exit;
|
2009-10-15 23:43:17 -07:00
|
|
|
}
|
2026-01-12 03:00:48 -08:00
|
|
|
?>
|
2009-10-15 23:43:17 -07:00
|
|
|
|
2026-01-12 03:00:48 -08:00
|
|
|
<script type="text/javascript">
|
|
|
|
|
window.location.replace("/quotes/view/<?=$quote['Quote']['id']?>");
|
|
|
|
|
</script>
|