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

83 lines
3.1 KiB
PHP
Executable file

<?
App::import('Vendor','pagecounter');
$pagecounter = new PageCounter();
?>
<p>Dear <?=$enquiry['Contact']['first_name']?>,</p>
<p>Thank you for your enquiry. The following quotation is for:</p>
<table>
<tr>
<td width="10%"><u><b>Item</b></u></td>
<td width="80%"><u><b>Description</b></u></td>
<td width="10%"><u><b>Quantity</b></u></td>
</tr>
<? foreach($document['LineItem'] as $li):?>
<tr>
<td valign="top" width="10%"><? if($li['option'] == 1) {
echo 'Option<br>';
}
?><?=$li['item_number']?></td>
<td width="80%"><?=$li['title'];?></td>
<td valign="top" width="10%"><?=$decimal->formatDecimal($li['quantity']);?></td>
</tr>
<? endforeach;?>
</table>
<p></p>
<p>If you have any further queries, please contact us at our office for assistance.</p>
<p>We look forward to your reply.</p>
<p>Regards,</p>
<?=$enquiry['User']['first_name'].' '.$enquiry['User']['last_name'];?><br />
<?=$enquiry['User']['job_title'];?><br />
<br />
<p>
Note: The manufacturer guarantees that the selected materials are mechanically suitable for the specifications stated and that the correct grade/ specification of materials will be used to fulfill an order. It is ultimately the customer's / client's responsibility to confirm the process compatibility of these materials with all their relevant process conditions. The quoted prices are only valid if the exact quantity of items quoted is purchased and that any quantity deviations may result in a change in the unit price.</p>
<br />
<u><b>Attachments:</b></u><br />
CMC Technologies Terms & Conditions of Sale 1/7/06 (attached)<br>
<?php foreach($attachments as $attachment) { ?>
<?php
// Debug log for page counter paths/results
$debugPath = APP.'webroot/pdf/pagecounter_debug.txt';
// Normalize attachment path: handle double slashes and ensure correct base path
$rawPath = $attachment['Attachment']['file'];
// Log the raw path from database
file_put_contents($debugPath, "Attachment: {$attachment['Attachment']['name']}\nRaw DB path: {$rawPath}\n", FILE_APPEND);
// If path starts with /webroot, prefix with APP; otherwise use as-is
if (strpos($rawPath, '/webroot/') === 0 || strpos($rawPath, '//webroot/') === 0) {
$attachmentPath = APP . ltrim($rawPath, '/');
} elseif (strpos($rawPath, APP) === 0) {
// Already has full APP path, use as-is
$attachmentPath = $rawPath;
} else {
// Default: prefix with APP
$attachmentPath = APP . ltrim($rawPath, '/');
}
// Remove any double slashes
$attachmentPath = preg_replace('#/+#', '/', $attachmentPath);
$exists = file_exists($attachmentPath) ? 'yes' : 'no';
$readable = is_readable($attachmentPath) ? 'yes' : 'no';
file_put_contents($debugPath, "Computed path: {$attachmentPath}\nExists: {$exists}, Readable: {$readable}\n", FILE_APPEND);
$pagecount = '';
if($attachment['Attachment']['type'] == 'application/pdf') {
$count = $pagecounter->count($attachmentPath);
$pagecount = '('.$count.' pages)';
file_put_contents($debugPath, "Count result: {$count}\n---\n", FILE_APPEND);
} else {
file_put_contents($debugPath, "Skipped (non-pdf)\n---\n", FILE_APPEND);
}
?>
<?= $attachment['Attachment']['name']; ?> <?= $pagecount ?><br>
<?php
} ?>