PDF Quote generation pretty much done. Disabled AJAX pagination of enquiries to fix principle view

This commit is contained in:
Karl Cordes 2011-05-24 19:11:07 +10:00
parent d75eeb28de
commit 8aeac9cc9e
45 changed files with 1993 additions and 1183 deletions

View file

@ -75,7 +75,32 @@ class AppController extends Controller {
return false; return false;
} }
} }
function calculateTotals($document, $gst) {
$totals = array('subtotal'=>0, 'gst'=>0, 'total'=>0);
foreach($document['LineItem'] as $lineitem) {
if($lineitem['option'] == 1) {
$totals['subtotal'] = 'TBA';
$totals['total'] = 'TBA';
$totals['gst'] = 'TBA';
return $totals;
}
else {
$totals['subtotal'] += $lineitem['net_price'];
}
}
if($gst == 1) {
$totals['gst'] = 0.1*$totals['subtotal'];
}
$totals['total'] = $totals['gst'] + $totals['subtotal'];
return $totals;
}

View file

@ -2,7 +2,7 @@
class DocumentsController extends AppController { class DocumentsController extends AppController {
var $name = 'Documents'; var $name = 'Documents';
var $helpers = array('Html', 'Form'); var $helpers = array('Html', 'Form', 'Number');
function index() { function index() {
$this->Document->recursive = 0; $this->Document->recursive = 0;
@ -14,28 +14,14 @@ class DocumentsController extends AppController {
$this->Session->setFlash(__('Invalid Document.', true)); $this->Session->setFlash(__('Invalid Document.', true));
$this->redirect(array('action'=>'index')); $this->redirect(array('action'=>'index'));
} }
$document = $this->Document->read(null, $id); $document = $this->Document->read(null,$id);
//$document = $this->Document->find('first',array('conditions'=>array('Document.id'=>$id), 'recursive'=>2));
$this->set('document', $document); $this->set('document', $document);
$docType = "";
if(!empty($document['Invoice']['id'])) {
$docType = "invoice";
}
elseif(!empty($document['Quote']['id'])) {
$docType = "quote";
$enquiry = $this->Document->Quote->Enquiry->read(null, $document['Quote']['enquiry_id']);
$this->set('enquiry',$enquiry);
}
elseif(!empty($document['PurchaseOrder']['id'])) {
$docType = "purchaseOrder";
}
$this->data = $document; $this->data = $document;
$this->set('docType',$docType); $this->set('docType',$this->Document->getDocType($document));
$this->set('currency', $this->Document->getCurrency($document));
$this->set('enquiry', $this->Document->getEnquiry($document));
// $this->set('principles', $this->Document->LineItem->Product->Principle->find('list')); // $this->set('principles', $this->Document->LineItem->Product->Principle->find('list'));
} }
@ -87,8 +73,8 @@ class DocumentsController extends AppController {
$this->data['Quote']['revision'] = $number_of_revisions; $this->data['Quote']['revision'] = $number_of_revisions;
$this->data['Document']['user_id']= $enquiry['Enquiry']['user_id']; $this->data['Document']['user_id']= $enquiry['Enquiry']['user_id'];
$this->data['Document']['enquiry_id'] = $enquiryid;
$this->data['Document']['type'] = 'quote';
if ($this->Document->saveAll($this->data)) { if ($this->Document->saveAll($this->data)) {
@ -113,7 +99,7 @@ class DocumentsController extends AppController {
$enquiryid = $id; $enquiryid = $id;
$this->Document->create(); $this->Document->create();
$enquiry = $this->Document->Enquiry->findById($id); $enquiry = $this->Document->Quote->Enquiry->findById($id);
$this->data['Document']['enquiry_id'] = $enquiryid; $this->data['Document']['enquiry_id'] = $enquiryid;
@ -124,13 +110,8 @@ class DocumentsController extends AppController {
$newInvoiceNumber = $invoice_number_offset + $number_of_invoices; $newInvoiceNumber = $invoice_number_offset + $number_of_invoices;
$this->data['Invoice']['title'] = "CMCIN".$newInvoiceNumber; $this->data['Invoice']['title'] = "CMCIN".$newInvoiceNumber;
$this->data['Document']['customer_id'] = $enquiry['Enquiry']['customer_id'];
$this->data['Document']['user_id']= $enquiry['Enquiry']['user_id']; $this->data['Document']['user_id']= $enquiry['Enquiry']['user_id'];
$this->data['Document']['contact_id']= $enquiry['Enquiry']['contact_id']; $this->data['Document']['type'] = 'invoice';
$this->data['Page'][0]['page_number'] = 1;
$this->data['Page'][0]['contentPage'] = 0;
if ($this->Document->saveAll($this->data)) { if ($this->Document->saveAll($this->data)) {
$newid = $this->Document->id; $newid = $this->Document->id;
@ -172,7 +153,7 @@ class DocumentsController extends AppController {
} }
function ajax_edit($id=null) { function ajax_edit($id = null) {
$this->layout = 'ajax'; $this->layout = 'ajax';
if (!$id && empty($this->data)) { if (!$id && empty($this->data)) {
@ -195,6 +176,122 @@ class DocumentsController extends AppController {
} }
} }
function pdf($id = null) {
//Configure::write('debug',0);
if(!$id) {
$this->Session->setFlash(__('Invalid Document', true));
$this->redirect(array('controller'=>'documents', 'action'=>'index'));
}
$document = $this->Document->read(null,$id);
$this->set('document', $document);
$this->data = $document;
$docType = $this->Document->getDocType($document);
$docTypeFullName = $this->Document->getDocFullName($docType);
$currency = $this->Document->getCurrency($document);
$enquiry = $this->Document->getEnquiry($document);
$this->set('docType', $docType);
$this->set('docTypeFullName',strtoupper($docTypeFullName));
$this->set('currency',$currency);
$this->set('currencyCode', $currency['Currency']['iso4217']);
$gst = $enquiry['Enquiry']['gst'];
$this->set('gst', $gst);
if($gst == 1) {
$totalsDescText = array(
'subtotal' => 'SUB-TOTAL (EXCLUDING GST)',
'gst' => 'GST (10%)',
'total' => 'TOTAL PAYABLE (INCLUDING GST)'
);
}
else {
$totalsDescText = array(
'subtotal' => 'SUB-TOTAL',
'gst' => 'GST (10%)',
'total' => 'TOTAL PAYABLE'
);
}
$totals = $this->calculateTotals($document, $gst);
$this->set('totals',$totals);
$this->set('totalsDescText',$totalsDescText);
/**
* Call the commercial Comments. Need to have already figured out what page to do this on..
*
* * Passing a data structure in the following format.
*
* $details = array(
* 'deliveryTime' => (String) eg. 2-3
* 'paymentTerms => (String) eg. 100% PAYMENT WITH ORDER || NET 30 DAYS FOR APPROVED ACCOUNTS
* 'dateIssued' => (String) eg. 2009-05-20
* 'daysValid' => (Int) eg. 30
* 'deliveryPoint' => (String) eg. EX-CMC Technologies, NSW. || EX-SUPPLIER NAME
* 'exchangeRate' => (String) eg. FIXED
* 'customsDuty' => (String) eg. NIL || 5%
* 'gst' => (String) eg. 10% EXTRA || Not Applicable for Export
* 'salesEngineer' => (String) eg. Karl Cordes || Con Carpis || Kenan Fernandes etc
* );
*
*
*/
if($enquiry['Enquiry']['gst'] == 1) {
$gstPhrase = "10% EXTRA";
}
else {
$gstPhrase = "Not Applicable for Export";
}
$commercialDetails = array (
'deliveryTime' => strtoupper($document['Quote']['delivery_time']),
'paymentTerms' => strtoupper($document['Quote']['payment_terms']),
'dateIssued' => $document['Quote']['date_issued'],
'validFor' => $document['Quote']['days_valid'],
'deliveryPoint' => strtoupper($document['Quote']['delivery_point']),
'exchangeRate' => strtoupper($document['Quote']['exchange_rate']),
'customsDuty' => strtoupper($document['Quote']['customs_duty']),
'gst' => strtoupper($gstPhrase),
'salesEngineer' => strtoupper($document['User']['first_name'].' '.$document['User']['last_name'])
);
$this->set('commercialDetails', $commercialDetails);
//debug($quote);
//debug($commercialDetails);
$this->set('currency', $currency);
$this->set('enquiry', $enquiry);
$this->set('principlesList', $this->Document->LineItem->Product->Principle->find('list'));
$this->set('products', $document['LineItem']);
$colWidths = array(
'item' => '8%',
'qty' => '8%',
'desc' => '60%',
'unit' => '12%',
'total' => '12%'
);
$this->set('colWidths',$colWidths);
}
/*function delete($id = null) { /*function delete($id = null) {
if (!$id) { if (!$id) {
$this->Session->setFlash(__('Invalid id for Document', true)); $this->Session->setFlash(__('Invalid id for Document', true));

View file

@ -62,7 +62,6 @@ class EnquiriesController extends AppController {
$this->pageTitle = "Enquiry: ".$enquiry['Enquiry']['title']; $this->pageTitle = "Enquiry: ".$enquiry['Enquiry']['title'];
$this->set('number_of_quotes', $this->Enquiry->Quote->find('count', array('conditions'=>array('Quote.enquiry_id'=>$id))));
//$this->set('number_of_files', $this->Enquiry->EnquiryFile->find('count', array('conditions' => array('EnquiryFile.enquiry_id'=>$id)))); //$this->set('number_of_files', $this->Enquiry->EnquiryFile->find('count', array('conditions' => array('EnquiryFile.enquiry_id'=>$id))));
$this->set('principle_emails', $this->Enquiry->Principle->PrincipleContact->findAllByPrincipleId($enquiry['Enquiry']['principle_id'])); $this->set('principle_emails', $this->Enquiry->Principle->PrincipleContact->findAllByPrincipleId($enquiry['Enquiry']['principle_id']));

View file

@ -2,7 +2,7 @@
class LineItemsController extends AppController { class LineItemsController extends AppController {
var $name = 'LineItems'; var $name = 'LineItems';
var $helpers = array('Html', 'Form', 'Javascript'); var $helpers = array('Html', 'Form', 'Javascript', 'Number');
var $components = array('RequestHandler'); var $components = array('RequestHandler');
@ -13,7 +13,27 @@ class LineItemsController extends AppController {
if(!empty($this->data)) { if(!empty($this->data)) {
$this->LineItem->create($this->data); $this->LineItem->create($this->data);
if ($this->LineItem->saveAll($this->data)) { if ($this->LineItem->save($this->data)) {
echo "SUCCESS";
}
else {
echo "FAILURE";
//print_r($this->data);
}
}
else {
echo "NO-DATA";
}
}
function ajax_edit() {
$this->layout = 'ajax';
if(!empty($this->data)) {
if ($this->LineItem->save($this->data)) {
echo "SUCCESS"; echo "SUCCESS";
} }
else { else {
@ -27,6 +47,21 @@ class LineItemsController extends AppController {
} }
function ajax_delete($id = null) {
$this->layout = 'ajax';
if($id == null) {
echo "FAILURE";
}
else {
if ($this->LineItem->del($id)) {
echo "SUCCESS";
}
else {
echo "FAILURE";
}
}
}
function getTable($documentID = null) { function getTable($documentID = null) {
$this->layout = 'ajax'; $this->layout = 'ajax';
if($documentID == null) { if($documentID == null) {
@ -36,19 +71,35 @@ class LineItemsController extends AppController {
$document = $this->LineItem->Document->find('first',array('conditions'=>array('Document.id'=>$documentID))); $document = $this->LineItem->Document->find('first',array('conditions'=>array('Document.id'=>$documentID)));
$this->set('document',$document); $this->set('document',$document);
$currencies = $this->LineItem->Document->Quote->Currency->find('list', array('fields'=>array('Currency.id','Currency.iso4217'))); $enquiry = $this->LineItem->Document->getEnquiry($document);
$this->set('currencies',$currencies);
$gst = $this->LineItem->Document->gstApplies($enquiry);
$this->set('gst',$gst);
$this->set('totals', $this->calculateTotals($document, $gst));
$currency = $this->LineItem->Document->getCurrency($document);
$this->set('currencyCode', $currency['Currency']['iso4217']);
$this->set('currencySymbol', $currency['Currency']['symbol']);
} }
} }
function edit($id = null) { function edit($id = null) {
$this->layout = 'ajax';
$this->data = $this->LineItem->read(null,$id);
$this->set('yesNo', array(0=>'No', 1=>'Yes'));
$this->set('principles', $this->LineItem->Product->Principle->find('list'));
} }
function add($documentID = null) { function add($documentID = null) {
$this->layout = 'ajax';
$document = $this->LineItem->Document->read(null, $documentID); $document = $this->LineItem->Document->read(null, $documentID);
$this->set('document', $document); $this->set('document', $document);
$this->set('yesNo', array(0=>'No', 1=>'Yes'));
$this->set('principles', $this->LineItem->Product->Principle->find('list')); $this->set('principles', $this->LineItem->Product->Principle->find('list'));
} }

View file

@ -1,214 +0,0 @@
<?php
class QuotePagesController extends AppController {
var $name = 'QuotePages';
var $helpers = array('Html', 'Form', 'Ajax', 'Number', 'Fck');
var $components = array('RequestHandler');
function index() {
$this->QuotePage->recursive = 0;
$this->set('quotePages', $this->paginate());
}
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid QuotePage.', true));
$this->redirect(array('action'=>'index'));
}
$this->set('quotePage', $this->QuotePage->read(null, $id));
}
function add($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid Quote ID', true));
$this->redirect(array('controller' => 'quotes', 'action'=>'index'));
}
if (!empty($this->data)) {
$this->QuotePage->create();
if ($this->QuotePage->save($this->data)) {
$this->Session->setFlash(__('The Quote Page has been saved', true));
$this->redirect(array('controller'=>'quotes', 'action'=>'view/'.$this->data['QuotePage']['quote_id']));
} else {
$this->Session->setFlash(__('The Quote Page could not be saved. Please, try again.', true));
}
}
$quotes = $this->QuotePage->Quote->find('list');
$this->set(compact('quotes'));
$this->set('quoteid', $id);
$number_of_pages = $this->QuotePage->find('count', array('conditions' => array('QuotePage.quote_id'=>$id)));
$number_of_pages++;
$this->set('pagenumber', $number_of_pages);
}
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid QuotePage', true));
$this->redirect(array('action'=>'index'));
}
if (!empty($this->data)) {
if ($this->QuotePage->save($this->data)) {
$this->Session->setFlash(__('The QuotePage has been saved', true));
$id = $this->data['QuotePage']['quote_id'];
$this->redirect(array('controller' => 'quotes', 'action'=>'view/'.$id));
} else {
$this->Session->setFlash(__('The QuotePage could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->QuotePage->read(null, $id);
$this->set('content', $this->data['QuotePage']['content']);
}
$quotes = $this->QuotePage->Quote->find('list');
$this->set(compact('quotes'));
}
function delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for QuotePage', true));
$this->redirect(array('action'=>'index'));
}
$quotepage = $this->QuotePage->findById($id);
$quoteid = $quotepage['QuotePage']['quote_id'];
if ($this->QuotePage->del($id)) {
$this->Session->setFlash(__('Quote Page deleted', true));
$this->redirect(array('controller' => 'quotes' , 'action'=>'view', $quoteid));
}
}
function show($id = null) {
$this->layout = 'ajax';
$this->set('quotePage', $this->QuotePage->read(null, $id));
}
function frame($id = null) {
$this->layout = 'ajax';
$this->set('id', $id);
}
function regeneratePage($id = null) {
if(!$id) {
$this->Session->setFlash(__('Invalid id for QuotePage', true));
$this->redirect(array('action'=>'index'));
}
else {
$quotePage = $this->QuotePage->read(null, $id);
//$enquiry = $this->QuotePage->Quote->Enquiry->find('all', array('conditions' => array('Enquiry.id' => $quotePage['Quote']['enquiry_id'])));
$enquiry = $this->QuotePage->Quote->Enquiry->read(null, $quotePage['Quote']['enquiry_id']);
// $quote = $this->QuotePage->Quote->find('all', array('conditions' => array('Quote.id' => $quotePage['Quote']['id'])));
$quoteProducts = $this->QuotePage->Quote->LineItem->find('all', array('recursive' => 0, 'conditions' =>
array('LineItem.quote_id' => $quotePage['Quote']['id']),
'order' => array('LineItem.item_number ASC'))
);
$contactFirstName = $enquiry['Contact']['first_name'];
$salesEngineerName = $enquiry['User']['first_name'].' '.$enquiry['User']['last_name'];
$productRows = "";
foreach($quoteProducts as $quoteproduct) {
$itemNumber = $quoteproduct['LineItem']['item_number'];
$title = $quoteproduct['LineItem']['title'];
if($quoteproduct['LineItem']['option'] == 1) {
$optionText = "Option ";
}
else {
$optionText = "";
}
$productRows .= <<<ENDROW
<tr>
<td>
$optionText
$itemNumber
</td>
<td>
$title
</td>
</tr>
ENDROW;
}
$this->data['QuotePage']['content'] = <<<ENDCONTENT
<p>Dear $contactFirstName, </p>
<p>&nbsp;</p>
<p> Thank for your recent enquiry. Please see the following quotation for: </p>
<table border="0" cellpadding="1" cellspacing="1" style="width: 100%; ">
<tbody>
<tr>
<th><b>Item</b></th>
<th><b>Product</b></th>
</tr>
$productRows
</tbody>
</table
<p> &nbsp;</p>
<p>Regards, </p>
<p>$salesEngineerName</p>
ENDCONTENT;
if (!empty($this->data)) {
if ($this->QuotePage->save($this->data)) {
$this->Session->setFlash(__('The QuotePage has been saved', true));
$id = $quotePage['Quote']['id'];
$this->redirect(array('controller' => 'quotes', 'action'=>'view/'.$id));
} else {
$this->Session->setFlash(__('The QuotePage could not be saved. Please, try again.', true));
}
}
debug($quotePage);
echo "<hr>";
debug ($quoteProducts);
}
}
}
?>

View file

@ -7,181 +7,200 @@ class QuotesController extends AppController {
var $components = array('RequestHandler'); var $components = array('RequestHandler');
function index() { function index() {
$this->Quote->recursive = 0; $this->Quote->recursive = 0;
$this->set('quotes', $this->paginate()); $this->set('quotes', $this->paginate());
} }
function view($id = null) { function view($id = null) {
if (!$id) { if (!$id) {
$this->Session->setFlash(__('Invalid Quote.', true)); $this->Session->setFlash(__('Invalid Quote.', true));
$this->redirect(array('action'=>'index')); $this->redirect(array('action'=>'index'));
} }
if (empty($this->data)) { if (empty($this->data)) {
$quote = $this->Quote->read(null, $id); $quote = $this->Quote->read(null, $id);
$this->data = $quote; $this->data = $quote;
$this->set('quote', $quote); $this->set('quote', $quote);
} }
$this->set('customer', $this->Quote->Enquiry->Customer->read(null, $quote['Enquiry']['customer_id'])); $this->set('customer', $this->Quote->Enquiry->Customer->read(null, $quote['Enquiry']['customer_id']));
$currencies = $this->Quote->Currency->find('list'); $currencies = $this->Quote->Currency->find('list');
$this->set('currencies', $currencies); $this->set('currencies', $currencies);
$this->set('principles', $this->Quote->Enquiry->Principle->find('list')); $this->set('principles', $this->Quote->Enquiry->Principle->find('list'));
} }
function ajax_edit() {
$this->layout = 'ajax';
if(!empty($this->data)) {
if ($this->Quote->save($this->data)) {
echo "SUCCESS";
}
else {
echo "FAILURE";
}
}
else {
echo "NO-DATA";
}
}
function add() { function add() {
if(isset($this->params['named']['enquiryid'])) { if(isset($this->params['named']['enquiryid'])) {
$enquiryid = $this->params['named']['enquiryid']; $enquiryid = $this->params['named']['enquiryid'];
$this->Quote->create(); $this->Quote->create();
$number_of_revisions = $this->Quote->findCount('Quote.enquiry_id ='. $enquiryid); $number_of_revisions = $this->Quote->findCount('Quote.enquiry_id ='. $enquiryid);
$this->data['Quote']['revision'] = $number_of_revisions; $this->data['Quote']['revision'] = $number_of_revisions;
$this->data['Quote']['enquiry_id'] = $enquiryid; $this->data['Quote']['enquiry_id'] = $enquiryid;
$this->data['Quote']['date_issued'] = date('Y-m-d'); $this->data['Quote']['date_issued'] = date('Y-m-d');
$this->data['Quote']['currency_id'] = 2; $this->data['Quote']['currency_id'] = 2;
if ($this->Quote->save($this->data)) {
if ($this->Quote->save($this->data)) {
$quoteid = $this->Quote->id; $quoteid = $this->Quote->id;
//$this->data['Document'][''] //$this->data['Document']['']
$this->Session->setFlash(__('The Quote has been saved', true)); $this->Session->setFlash(__('The Quote has been saved', true));
$this->redirect(array('action'=>'view/'.$quoteid)); $this->redirect(array('action'=>'view/'.$quoteid));
} }
else { else {
$this->Session->setFlash(__('The Quote was not saved. Something has gone wrong.', true)); $this->Session->setFlash(__('The Quote was not saved. Something has gone wrong.', true));
$this->redirect(array('action'=>'index')); $this->redirect(array('action'=>'index'));
} }
} }
else { else {
$this->Session->setFlash(__('Invalid Enquiry ID', true)); $this->Session->setFlash(__('Invalid Enquiry ID', true));
$this->redirect(array('controller'=>'enquiries','action'=>'index')); $this->redirect(array('controller'=>'enquiries','action'=>'index'));
} }
} }
function edit($id = null) { function edit($id = null) {
if (!$id && empty($this->data)) { $this->layout = 'ajax';
$this->Session->setFlash(__('Invalid Quote', true));
$this->redirect(array('action'=>'index'));
}
if (!empty($this->data)) {
$issuedate = $this->data['Quote']['date_issued'];
$issuedate = $issuedate['year'].'-'.$issuedate['month'].'-'.$issuedate['day'];
$validUntilDate = strtotime($issuedate."+ ".$this->data['Quote']['days_valid']." days"); if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid Quote', true));
$this->redirect(array('action'=>'index'));
}
if (!empty($this->data)) {
$issuedate = $this->data['Quote']['date_issued'];
$issuedate = $issuedate['year'].'-'.$issuedate['month'].'-'.$issuedate['day'];
$this->data['Quote']['valid_until'] = date('Y-m-d', $validUntilDate); $validUntilDate = strtotime($issuedate."+ ".$this->data['Quote']['days_valid']." days");
$this->data['Quote']['valid_until'] = date('Y-m-d', $validUntilDate);
if ($this->Quote->save($this->data)) { if ($this->Quote->save($this->data)) {
$this->Session->setFlash(__('The Quote has been saved', true)); $this->Session->setFlash(__('The Quote has been saved', true));
$thisquote = $this->Quote->id; $thisquote = $this->Quote->id;
$this->redirect(array('action' =>'view/'.$id), null, false); $this->redirect(array('action' =>'view/'.$id), null, false);
} else { } else {
$this->Session->setFlash(__('The Quote could not be saved. Please, try again.', true)); $this->Session->setFlash(__('The Quote could not be saved. Please, try again.', true));
} }
} }
if (empty($this->data)) { if (empty($this->data)) {
$quote = $this->Quote->read(null, $id); $quote = $this->Quote->read(null, $id);
$this->data = $quote; $this->data = $quote;
} }
$enquiry = $this->Quote->Enquiry->findById($quote['Quote']['enquiry_id']); $enquiry = $this->Quote->Enquiry->findById($quote['Quote']['enquiry_id']);
$currencies = $this->Quote->Currency->find('list'); $currencies = $this->Quote->Currency->find('list');
$this->set(compact('enquiry', 'quote', 'currencies')); $this->set('yesNo', array(0=>'No', 1=>'Yes'));
$this->set(compact('enquiry', 'quote', 'currencies'));
} }
function pdf($id = null) { function pdf($id = null) {
//Configure::write('debug',0); //Configure::write('debug',0);
if(!$id) { if(!$id) {
$this->Session->setFlash(__('Invalid Quote', true)); $this->Session->setFlash(__('Invalid Quote', true));
$this->redirect(array('controller'=>'enquiries', 'action'=>'index')); $this->redirect(array('controller'=>'enquiries', 'action'=>'index'));
} }
$quote = $this->Quote->findById($id); $quote = $this->Quote->findById($id);
//$customer = $this->Quote->Enquiry->Customer->read(null, $quote['Enquiry']['customer_id']); //$customer = $this->Quote->Enquiry->Customer->read(null, $quote['Enquiry']['customer_id']);
$enquiry = $this->Quote->Enquiry->find('first', array('conditions' => array('Enquiry.id' => $quote['Quote']['enquiry_id']))); $enquiry = $this->Quote->Enquiry->find('first', array('conditions' => array('Enquiry.id' => $quote['Quote']['enquiry_id'])));
$quoteProducts = $this->Quote->Document->LineItem->find('all', array('recursive' => 0, 'conditions' => array('LineItem.quote_id' => $id), $quoteProducts = $this->Quote->Document->LineItem->find('all', array('recursive' => 0, 'conditions' => array('LineItem.quote_id' => $id),
'order' => array('LineItem.item_number ASC')) 'order' => array('LineItem.item_number ASC'))
); );
$user = $this->Quote->Enquiry->User->find('first', array('conditions' => array('User.id' => $enquiry['Enquiry']['user_id']))); $user = $this->Quote->Enquiry->User->find('first', array('conditions' => array('User.id' => $enquiry['Enquiry']['user_id'])));
/** /**
* Call the commercial Comments. Need to have already figured out what page to do this on.. * Call the commercial Comments. Need to have already figured out what page to do this on..
* *
* * Passing a data structure in the following format. * * Passing a data structure in the following format.
* *
* $details = array( * $details = array(
* 'deliveryTime' => (String) eg. 2-3 * 'deliveryTime' => (String) eg. 2-3
* 'paymentTerms => (String) eg. 100% PAYMENT WITH ORDER || NET 30 DAYS FOR APPROVED ACCOUNTS * 'paymentTerms => (String) eg. 100% PAYMENT WITH ORDER || NET 30 DAYS FOR APPROVED ACCOUNTS
* 'dateIssued' => (String) eg. 2009-05-20 * 'dateIssued' => (String) eg. 2009-05-20
* 'daysValid' => (Int) eg. 30 * 'daysValid' => (Int) eg. 30
* 'deliveryPoint' => (String) eg. EX-CMC Technologies, NSW. || EX-SUPPLIER NAME * 'deliveryPoint' => (String) eg. EX-CMC Technologies, NSW. || EX-SUPPLIER NAME
* 'exchangeRate' => (String) eg. FIXED * 'exchangeRate' => (String) eg. FIXED
* 'customsDuty' => (String) eg. NIL || 5% * 'customsDuty' => (String) eg. NIL || 5%
* 'gst' => (String) eg. 10% EXTRA || Not Applicable for Export * 'gst' => (String) eg. 10% EXTRA || Not Applicable for Export
* 'salesEngineer' => (String) eg. Karl Cordes || Con Carpis || Kenan Fernandes etc * 'salesEngineer' => (String) eg. Karl Cordes || Con Carpis || Kenan Fernandes etc
* ); * );
* *
* *
*/ */
if($enquiry['Enquiry']['gst'] == 1) { if($enquiry['Enquiry']['gst'] == 1) {
$gstPhrase = "10% EXTRA"; $gstPhrase = "10% EXTRA";
} }
else { else {
$gstPhrase = "Not Applicable for Export"; $gstPhrase = "Not Applicable for Export";
} }
$commercialDetails = array ( $commercialDetails = array (
'deliveryTime' => strtoupper($quote['Quote']['delivery_time']), 'deliveryTime' => strtoupper($quote['Quote']['delivery_time']),
'paymentTerms' => strtoupper($quote['Quote']['payment_terms']), 'paymentTerms' => strtoupper($quote['Quote']['payment_terms']),
'dateIssued' => $quote['Quote']['date_issued'], 'dateIssued' => $quote['Quote']['date_issued'],
'validFor' => $quote['Quote']['days_valid'], 'validFor' => $quote['Quote']['days_valid'],
'deliveryPoint' => strtoupper($quote['Quote']['delivery_point']), 'deliveryPoint' => strtoupper($quote['Quote']['delivery_point']),
'exchangeRate' => strtoupper($quote['Quote']['exchange_rate']), 'exchangeRate' => strtoupper($quote['Quote']['exchange_rate']),
'customsDuty' => strtoupper($quote['Quote']['customs_duty']), 'customsDuty' => strtoupper($quote['Quote']['customs_duty']),
'gst' => strtoupper($gstPhrase), 'gst' => strtoupper($gstPhrase),
'salesEngineer' => strtoupper($user['User']['first_name'].' '.$user['User']['last_name']) 'salesEngineer' => strtoupper($user['User']['first_name'].' '.$user['User']['last_name'])
); );
$this->set('commercialDetails', $commercialDetails); $this->set('commercialDetails', $commercialDetails);
//debug($quote); //debug($quote);
//debug($commercialDetails); //debug($commercialDetails);
$this->set('quote', $quote); $this->set('quote', $quote);
$this->set('enquiry', $enquiry); $this->set('enquiry', $enquiry);
$this->set('principlesList', $this->Quote->Enquiry->Principle->find('list')); $this->set('principlesList', $this->Quote->Enquiry->Principle->find('list'));
$this->set('products', $quoteProducts); $this->set('products', $quoteProducts);
@ -189,86 +208,86 @@ class QuotesController extends AppController {
function ajaxpdf($id = null) { function ajaxpdf($id = null) {
//Configure::write('debug',0); //Configure::write('debug',0);
if(empty($this->data)) { if(empty($this->data)) {
$this->Session->setFlash(__('Invalid Quote', true)); $this->Session->setFlash(__('Invalid Quote', true));
$this->redirect(array('controller'=>'enquiries', 'action'=>'index')); $this->redirect(array('controller'=>'enquiries', 'action'=>'index'));
} }
else { else {
$id = $this->data['Quote']['id']; $id = $this->data['Quote']['id'];
$quote = $this->Quote->findById($id); $quote = $this->Quote->findById($id);
//$customer = $this->Quote->Enquiry->Customer->read(null, $quote['Enquiry']['customer_id']); //$customer = $this->Quote->Enquiry->Customer->read(null, $quote['Enquiry']['customer_id']);
$enquiry = $this->Quote->Enquiry->find('first', array('conditions' => array('Enquiry.id' => $quote['Quote']['enquiry_id']))); $enquiry = $this->Quote->Enquiry->find('first', array('conditions' => array('Enquiry.id' => $quote['Quote']['enquiry_id'])));
$quoteProducts = $this->Quote->LineItem->find('all', array('recursive' => 1, 'conditions' => array('LineItem.quote_id' => $id), $quoteProducts = $this->Quote->LineItem->find('all', array('recursive' => 1, 'conditions' => array('LineItem.quote_id' => $id),
'order' => array('LineItem.item_number ASC')) 'order' => array('LineItem.item_number ASC'))
); );
$user = $this->Quote->Enquiry->User->find('first', array('conditions' => array('User.id' => $enquiry['Enquiry']['user_id']))); $user = $this->Quote->Enquiry->User->find('first', array('conditions' => array('User.id' => $enquiry['Enquiry']['user_id'])));
/**
* Call the commercial Comments. Need to have already figured out what page to do this on..
*
* * Passing a data structure in the following format.
*
* $details = array(
* 'deliveryTime' => (String) eg. 2-3
* 'paymentTerms => (String) eg. 100% PAYMENT WITH ORDER || NET 30 DAYS FOR APPROVED ACCOUNTS
* 'dateIssued' => (String) eg. 2009-05-20
* 'daysValid' => (Int) eg. 30
* 'deliveryPoint' => (String) eg. EX-CMC Technologies, NSW. || EX-SUPPLIER NAME
* 'exchangeRate' => (String) eg. FIXED
* 'customsDuty' => (String) eg. NIL || 5%
* 'gst' => (String) eg. 10% EXTRA || Not Applicable for Export
* 'salesEngineer' => (String) eg. Karl Cordes || Con Carpis || Kenan Fernandes etc
* );
*
*
*/
if($enquiry['Enquiry']['gst'] == 1) {
$gstPhrase = "10% EXTRA";
}
else {
$gstPhrase = "Not Applicable for Export";
}
$commercialDetails = array ( /**
'deliveryTime' => strtoupper($quote['Quote']['delivery_time']), * Call the commercial Comments. Need to have already figured out what page to do this on..
'paymentTerms' => strtoupper($quote['Quote']['payment_terms']), *
'dateIssued' => $quote['Quote']['date_issued'], * * Passing a data structure in the following format.
'validFor' => $quote['Quote']['days_valid'], *
'deliveryPoint' => strtoupper($quote['Quote']['delivery_point']), * $details = array(
'exchangeRate' => strtoupper($quote['Quote']['exchange_rate']), * 'deliveryTime' => (String) eg. 2-3
'customsDuty' => strtoupper($quote['Quote']['customs_duty']), * 'paymentTerms => (String) eg. 100% PAYMENT WITH ORDER || NET 30 DAYS FOR APPROVED ACCOUNTS
'gst' => strtoupper($gstPhrase), * 'dateIssued' => (String) eg. 2009-05-20
'salesEngineer' => strtoupper($user['User']['first_name'].' '.$user['User']['last_name']) * 'daysValid' => (Int) eg. 30
* 'deliveryPoint' => (String) eg. EX-CMC Technologies, NSW. || EX-SUPPLIER NAME
* 'exchangeRate' => (String) eg. FIXED
* 'customsDuty' => (String) eg. NIL || 5%
* 'gst' => (String) eg. 10% EXTRA || Not Applicable for Export
* 'salesEngineer' => (String) eg. Karl Cordes || Con Carpis || Kenan Fernandes etc
* );
*
*
*/
if($enquiry['Enquiry']['gst'] == 1) {
$gstPhrase = "10% EXTRA";
}
else {
$gstPhrase = "Not Applicable for Export";
}
$commercialDetails = array (
'deliveryTime' => strtoupper($quote['Quote']['delivery_time']),
'paymentTerms' => strtoupper($quote['Quote']['payment_terms']),
'dateIssued' => $quote['Quote']['date_issued'],
'validFor' => $quote['Quote']['days_valid'],
'deliveryPoint' => strtoupper($quote['Quote']['delivery_point']),
'exchangeRate' => strtoupper($quote['Quote']['exchange_rate']),
'customsDuty' => strtoupper($quote['Quote']['customs_duty']),
'gst' => strtoupper($gstPhrase),
'salesEngineer' => strtoupper($user['User']['first_name'].' '.$user['User']['last_name'])
); );
$this->set('commercialDetails', $commercialDetails); $this->set('commercialDetails', $commercialDetails);
//debug($quote); //debug($quote);
//debug($commercialDetails); //debug($commercialDetails);
$this->set('quote', $quote); $this->set('quote', $quote);
$this->set('enquiry', $enquiry); $this->set('enquiry', $enquiry);
$this->set('products', $quoteProducts); $this->set('products', $quoteProducts);
} }
} }
@ -291,53 +310,48 @@ class QuotesController extends AppController {
*/ */
function revise($id) { function revise($id) {
if(!$id) { if(!$id) {
$this->Session->setFlash(__('Invalid Quote', true)); $this->Session->setFlash(__('Invalid Quote', true));
$this->redirect(array('controller'=>'enquiries', 'action'=>'index')); $this->redirect(array('controller'=>'enquiries', 'action'=>'index'));
} }
else { else {
$quoteid = $id; $quoteid = $id;
$quote = $this->Quote->read(null,$id); $quote = $this->Quote->read(null,$id);
$enquiryid = $quote['Quote']['enquiry_id']; $enquiryid = $quote['Quote']['enquiry_id'];
$number_of_revisions = $this->Quote->findCount('Quote.enquiry_id ='. $enquiryid); $number_of_revisions = $this->Quote->findCount('Quote.enquiry_id ='. $enquiryid);
$number_of_revisions++; $number_of_revisions++;
//debug($quote); //debug($quote);
// $this->Quote->create(); // $this->Quote->create();
$this->data['Quote'] = $quote['Quote']; $this->data['Quote'] = $quote['Quote'];
$this->data['Quote']['id'] = null; $this->data['Quote']['id'] = null;
$this->data['Quote']['created'] = null; $this->data['Quote']['created'] = null;
$this->data['Quote']['modified'] = null; $this->data['Quote']['modified'] = null;
$this->data['Quote']['revision'] = $number_of_revisions; $this->data['Quote']['revision'] = $number_of_revisions;
$this->data['Quote']['enquiry_id'] = $enquiryid; $this->data['Quote']['enquiry_id'] = $enquiryid;
foreach($quote['LineItem'] as $item) { foreach($quote['LineItem'] as $item) {
$item['id'] = null; $item['id'] = null;
$item['quote_id'] = null; $item['quote_id'] = null;
$this->data['LineItem'][] = $item; $this->data['LineItem'][] = $item;
} }
foreach($quote['QuotePage'] as $page) {
$page['id'] = null; //debug($this->data);
$page['quote_id'] = null;
$this->data['QuotePage'][] = $page;
}
//debug($this->data); if ($this->Quote->saveAll($this->data)) {
$quoteid = $this->Quote->id;
if ($this->Quote->saveAll($this->data)) { $this->Session->setFlash(__('Created Quote Revision '.$number_of_revisions, true));
$quoteid = $this->Quote->id; $this->redirect(array('action'=>'view/'.$quoteid));
$this->Session->setFlash(__('Created Quote Revision '.$number_of_revisions, true)); }
$this->redirect(array('action'=>'view/'.$quoteid));
}
} }
} }

View file

@ -133,7 +133,7 @@ class ShipmentsController extends AppController {
if ($this->Shipment->saveAll($this->data)) { if ($this->Shipment->saveAll($this->data)) {
$this->Shipment->Box->updateCounterCache(array('shipment_id'=>$shipment_id)); $this->Shipment->Box->updateCounterCache(array('shipment_id'=>$shipment_id));
$this->Shipment->ShipmentInvoice->updateCounterCache(array('shipment_id'=>$shipment_id)); $this->Shipment->ShipmentInvoice->updateCounterCache(array('shipment_id'=>$shipment_id));
@ -184,7 +184,7 @@ class ShipmentsController extends AppController {
if ($this->Shipment->saveAll($this->data)) { if ($this->Shipment->saveAll($this->data)) {
echo "SUCCESS"; echo "SUCCESS";
} }
else { else {
echo "FAILURE"; echo "FAILURE";
@ -199,6 +199,9 @@ class ShipmentsController extends AppController {
} }
function markJobsSent() { function markJobsSent() {
} }

View file

@ -1,51 +1,155 @@
<?php <?php
class Document extends AppModel { class Document extends AppModel {
var $name = 'Document'; var $name = 'Document';
//The Associations below have been created with all possible keys, those that are not needed can be removed //The Associations below have been created with all possible keys, those that are not needed can be removed
var $belongsTo = array( var $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
var $hasMany = array(
'LineItem' => array(
'className' => 'LineItem',
'foreignKey' => 'document_id',
'order' => 'LineItem.item_number ASC'
),
'DocPage' => array(
'className'=> 'DocPage',
'foreignKey' => 'document_id',
'order' => 'DocPage.page_number ASC'
)
);
var $hasOne = array(
'Invoice' => array(
'className' => 'Invoice',
'foreignKey'=> 'document_id'
),
'Quote' => array(
'className'=>'Quote',
'foriegnKey'=>'document_id'
),
'PurchaseOrder' => array(
'className'=>'PurchaseOrder',
'foreignKey'=>'document_id'
)
);
function getCurrency($document) {
if(!empty($document['Invoice']['id'])) {
$currencyID = $document['Invoice']['currency_id'];
$conditions = $this->__getCurrencyConditions($currencyID);
return $this->Invoice->Currency->find('first',$conditions);
}
elseif(!empty($document['Quote']['id'])) {
$currencyID = $document['Quote']['currency_id'];
$conditions = $this->__getCurrencyConditions($currencyID);
return $this->Quote->Currency->find('first',$conditions);
}
elseif(!empty($document['PurchaseOrder']['id'])) {
$currencyID = $document['PurchaseOrder']['currency_id'];
$conditions = $this->__getCurrencyConditions($currencyID);
return $this->PurchaseOrder->Currency->find('first',$conditions);
}
}
function __getCurrencyConditions($currencyID) {
return array('recursive'=>0, 'conditions'=>array('Currency.id'=>$currencyID));
}
function getDocType($document) {
return $document['Document']['type'];
}
function getDocFullName($type) {
switch($type) {
case 'quote':
$fullName = 'Quotation';
break;
case 'invoice':
$fullName = 'Invoice';
break;
case 'purchaseOrder':
$fullName = 'Purchase Order';
break;
case 'orderAck':
$fullName = 'Order Acknowledgement';
break;
}
return $fullName;
}
/**
* Depending on the type of document. Return the CMC reference
* ie. Enquiry Number (Quote)
* Invoice Number (Invoice)
* @param <type> $document
* @param <type> $type
*/
function getCMCReferenceNumber($document, $type) {
switch($type) {
case 'quote':
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
); break;
case 'invoice':
var $hasMany = array(
'LineItem' => array( break;
'className' => 'LineItem', case 'purchaseOrder':
'foreignKey' => 'document_id',
'order' => 'LineItem.item_number ASC' break;
), case 'orderAck':
'DocPage' => array( break;
'className'=> 'DocPage', }
'foreignKey' => 'document_id', return $fullName;
'order' => 'DocPage.page_number ASC' }
)
);
var $hasOne = array( function getEnquiry($document) {
'Invoice' => array( if(!empty($document['Invoice']['id'])) {
'className' => 'Invoice', return $this->Invoice->Enquiry->find('first',array('conditions'=>array('Enquiry.id'=>$document['Invoice']['enquiry_id'])));
'foreignKey'=> 'document_id' }
), elseif(!empty($document['Quote']['id'])) {
'Quote' => array( return $this->Quote->Enquiry->find('first',array('conditions'=>array('Enquiry.id'=>$document['Quote']['enquiry_id'])));
'className'=>'Quote', }
'foriegnKey'=>'document_id' elseif(!empty($document['PurchaseOrder']['id'])) {
), return $this->PurchaseOrder->Enquiry->find('first',array('conditions'=>array('Enquiry.id'=>$document['Invoice']['enquiry_id'])));
}
}
/**
* Does GST apply on this document. Based on the Enquiry GST TinyInt.
* @param <type> $enquiry
* @return Bool
*/
function gstApplies($enquiry) {
if ($enquiry['Enquiry']['gst'] == 0) {
return false;
}
else {
return true;
}
}
'PurchaseOrder' => array(
'className'=>'PurchaseOrder',
'foreignKey'=>'document_id'
)
);
} }
?> ?>

View file

@ -38,7 +38,15 @@ class Invoice extends AppModel {
'Job' => array( 'Job' => array(
'className' => 'Job', 'className' => 'Job',
'foreignKey' => 'job_id' 'foreignKey' => 'job_id'
) ),
'Currency' => array(
'className' => 'Currency',
'foreignKey' => 'currency_id'
),
'Document' => array(
'className' => 'Document',
'foreignKey' => 'document_id'
)
); );

View file

@ -17,7 +17,8 @@ class Quote extends AppModel {
'foreignKey' => 'enquiry_id', 'foreignKey' => 'enquiry_id',
'conditions' => '', 'conditions' => '',
'fields' => '', 'fields' => '',
'order' => '' 'order' => '',
'counterCache'=>true
), ),
'Currency' => array('className' => 'Currency', 'foreignKey' => 'currency_id'), 'Currency' => array('className' => 'Currency', 'foreignKey' => 'currency_id'),

View file

@ -1,8 +1,8 @@
<?php <?php
// //
// FPDI - Version 1.3.2 // FPDI - Version 1.4.1
// //
// Copyright 2004-2010 Setasign - Jan Slabon // Copyright 2004-2011 Setasign - Jan Slabon
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -26,8 +26,7 @@ if (!defined('ORD_u'))
if (!defined('ORD_tilde')) if (!defined('ORD_tilde'))
define('ORD_tilde', ord('~')); define('ORD_tilde', ord('~'));
$__tmp = version_compare(phpversion(), "5") == -1 ? array('FilterASCII85') : array('FilterASCII85', false); if (!class_exists('FilterASCII85', false)) {
if (!call_user_func_array('class_exists', $__tmp)) {
class FilterASCII85 { class FilterASCII85 {
@ -100,5 +99,3 @@ if (!call_user_func_array('class_exists', $__tmp)) {
} }
} }
} }
unset($__tmp);

View file

@ -1,8 +1,8 @@
<?php <?php
// //
// FPDI - Version 1.3.2 // FPDI - Version 1.4.1
// //
// Copyright 2004-2010 Setasign - Jan Slabon // Copyright 2004-2011 Setasign - Jan Slabon
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -23,7 +23,7 @@ class FilterASCII85_FPDI extends FilterASCII85 {
var $fpdi; var $fpdi;
function FPDI_FilterASCII85(&$fpdi) { function FilterASCII85_FPDI(&$fpdi) {
$this->fpdi =& $fpdi; $this->fpdi =& $fpdi;
} }

View file

@ -1,8 +1,8 @@
<?php <?php
// //
// FPDI - Version 1.3.2 // FPDI - Version 1.4.1
// //
// Copyright 2004-2010 Setasign - Jan Slabon // Copyright 2004-2011 Setasign - Jan Slabon
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -17,8 +17,7 @@
// limitations under the License. // limitations under the License.
// //
$__tmp = version_compare(phpversion(), "5") == -1 ? array('FilterLZW') : array('FilterLZW', false); if (!class_exists('FilterLZW', false)) {
if (!call_user_func_array('class_exists', $__tmp)) {
class FilterLZW { class FilterLZW {
@ -156,5 +155,3 @@ if (!call_user_func_array('class_exists', $__tmp)) {
} }
} }
} }
unset($__tmp);

View file

@ -1,8 +1,8 @@
<?php <?php
// //
// FPDI - Version 1.3.2 // FPDI - Version 1.4.1
// //
// Copyright 2004-2010 Setasign - Jan Slabon // Copyright 2004-2011 Setasign - Jan Slabon
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.

View file

@ -1,6 +1,6 @@
<?php <?php
// //
// FPDF_TPL - Version 1.1.4 // FPDF_TPL - Version 1.2
// //
// Copyright 2004-2010 Setasign - Jan Slabon // Copyright 2004-2010 Setasign - Jan Slabon
// //
@ -73,7 +73,12 @@ class FPDF_TPL extends FPDF {
* @param int $h The height given in user-unit * @param int $h The height given in user-unit
* @return int The ID of new created Template * @return int The ID of new created Template
*/ */
function beginTemplate($x=null, $y=null, $w=null, $h=null) { function beginTemplate($x = null, $y = null, $w = null, $h = null) {
if (is_subclass_of($this, 'TCPDF')) {
$this->Error('This method is only usable with FPDF. Use TCPDF methods startTemplate() instead.');
return;
}
if ($this->page <= 0) if ($this->page <= 0)
$this->error("You have to add a page to fpdf first!"); $this->error("You have to add a page to fpdf first!");
@ -113,8 +118,8 @@ class FPDF_TPL extends FPDF {
$this->w = $w; $this->w = $w;
$this->_intpl = true; $this->_intpl = true;
$this->SetXY($x+$this->lMargin, $y+$this->tMargin); $this->SetXY($x + $this->lMargin, $y + $this->tMargin);
$this->SetRightMargin($this->w-$w+$this->rMargin); $this->SetRightMargin($this->w - $w + $this->rMargin);
return $this->tpl; return $this->tpl;
} }
@ -127,6 +132,11 @@ class FPDF_TPL extends FPDF {
* @return mixed If a template is opened, the ID is returned. If not a false is returned. * @return mixed If a template is opened, the ID is returned. If not a false is returned.
*/ */
function endTemplate() { function endTemplate() {
if (is_subclass_of($this, 'TCPDF')) {
$args = func_get_args();
return call_user_func_array(array($this, 'TCPDF::endTemplate'), $args);
}
if ($this->_intpl) { if ($this->_intpl) {
$this->_intpl = false; $this->_intpl = false;
$tpl =& $this->tpls[$this->tpl]; $tpl =& $this->tpls[$this->tpl];
@ -161,12 +171,12 @@ class FPDF_TPL extends FPDF {
* @param int $_h The new height of the template * @param int $_h The new height of the template
* @retrun array The height and width of the template * @retrun array The height and width of the template
*/ */
function useTemplate($tplidx, $_x=null, $_y=null, $_w=0, $_h=0) { function useTemplate($tplidx, $_x = null, $_y = null, $_w = 0, $_h = 0) {
if ($this->page <= 0) if ($this->page <= 0)
$this->error("You have to add a page to fpdf first!"); $this->error('You have to add a page first!');
if (!isset($this->tpls[$tplidx])) if (!isset($this->tpls[$tplidx]))
$this->error("Template does not exist!"); $this->error('Template does not exist!');
if ($this->_intpl) { if ($this->_intpl) {
$this->_res['tpl'][$this->tpl]['tpls'][$tplidx] =& $this->tpls[$tplidx]; $this->_res['tpl'][$this->tpl]['tpls'][$tplidx] =& $this->tpls[$tplidx];
@ -193,19 +203,26 @@ class FPDF_TPL extends FPDF {
'y' => $this->y, 'y' => $this->y,
'w' => $_w, 'w' => $_w,
'h' => $_h, 'h' => $_h,
'scaleX' => ($_w/$w), 'scaleX' => ($_w / $w),
'scaleY' => ($_h/$h), 'scaleY' => ($_h / $h),
'tx' => $_x, 'tx' => $_x,
'ty' => ($this->h-$_y-$_h), 'ty' => ($this->h - $_y - $_h),
'lty' => ($this->h-$_y-$_h) - ($this->h-$h) * ($_h/$h) 'lty' => ($this->h - $_y - $_h) - ($this->h - $h) * ($_h / $h)
); );
$this->_out(sprintf("q %.4F 0 0 %.4F %.4F %.4F cm", $tData['scaleX'], $tData['scaleY'], $tData['tx']*$this->k, $tData['ty']*$this->k)); // Translate $this->_out(sprintf('q %.4F 0 0 %.4F %.4F %.4F cm', $tData['scaleX'], $tData['scaleY'], $tData['tx'] * $this->k, $tData['ty'] * $this->k)); // Translate
$this->_out(sprintf('%s%d Do Q', $this->tplprefix, $tplidx)); $this->_out(sprintf('%s%d Do Q', $this->tplprefix, $tplidx));
// reset font in the outer graphic state
if ($this->FontFamily) {
$family = $this->FontFamily;
$this->FontFamily = '';
$this->SetFont($family);
}
$this->lastUsedTemplateData = $tData; $this->lastUsedTemplateData = $tData;
return array("w" => $_w, "h" => $_h); return array('w' => $_w, 'h' => $_h);
} }
/** /**
@ -218,7 +235,7 @@ class FPDF_TPL extends FPDF {
* @param int $_h The height of the template * @param int $_h The height of the template
* @return array The height and width of the template * @return array The height and width of the template
*/ */
function getTemplateSize($tplidx, $_w=0, $_h=0) { function getTemplateSize($tplidx, $_w = 0, $_h = 0) {
if (!$this->tpls[$tplidx]) if (!$this->tpls[$tplidx])
return false; return false;
@ -231,10 +248,10 @@ class FPDF_TPL extends FPDF {
$_h = $h; $_h = $h;
} }
if($_w==0) if($_w == 0)
$_w = $_h*$w/$h; $_w = $_h * $w / $h;
if($_h==0) if($_h == 0)
$_h = $_w*$h/$w; $_h = $_w * $h / $w;
return array("w" => $_w, "h" => $_h); return array("w" => $_w, "h" => $_h);
} }
@ -242,19 +259,21 @@ class FPDF_TPL extends FPDF {
/** /**
* See FPDF/TCPDF-Documentation ;-) * See FPDF/TCPDF-Documentation ;-)
*/ */
function SetFont($family, $style='', $size=0, $fontfile='') { public function SetFont($family, $style = '', $size = 0) {
if (!is_subclass_of($this, 'TCPDF') && func_num_args() > 3) { if (is_subclass_of($this, 'TCPDF')) {
$this->Error('More than 3 arguments for the SetFont method are only available in TCPDF.'); $args = func_get_args();
return call_user_func_array(array($this, 'TCPDF::SetFont'), $args);
} }
/** /**
* force the resetting of font changes in a template * force the resetting of font changes in a template
*/ */
if ($this->_intpl) if ($this->_intpl)
$this->FontFamily = ''; $this->FontFamily = '';
parent::SetFont($family, $style, $size, $fontfile); parent::SetFont($family, $style, $size);
$fontkey = $this->FontFamily.$this->FontStyle; $fontkey = $this->FontFamily . $this->FontStyle;
if ($this->_intpl) { if ($this->_intpl) {
$this->_res['tpl'][$this->tpl]['fonts'][$fontkey] =& $this->fonts[$fontkey]; $this->_res['tpl'][$this->tpl]['fonts'][$fontkey] =& $this->fonts[$fontkey];
@ -266,17 +285,20 @@ class FPDF_TPL extends FPDF {
/** /**
* See FPDF/TCPDF-Documentation ;-) * See FPDF/TCPDF-Documentation ;-)
*/ */
function Image($file, $x, $y, $w=0, $h=0, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='', $ismask=false, $imgmask=false, $border=0, $fitbox = false, $hidden = false) { function Image($file, $x = null, $y = null, $w = 0, $h = 0, $type = '', $link = '') {
if (!is_subclass_of($this, 'TCPDF') && func_num_args() > 7) { if (is_subclass_of($this, 'TCPDF')) {
$this->Error('More than 7 arguments for the Image method are only available in TCPDF.'); $args = func_get_args();
return call_user_func_array(array($this, 'TCPDF::Image'), $args);
} }
parent::Image($file, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $ismask, $imgmask, $border, $fitbox, $hidden); $ret = parent::Image($file, $x, $y, $w, $h, $type, $link);
if ($this->_intpl) { if ($this->_intpl) {
$this->_res['tpl'][$this->tpl]['images'][$file] =& $this->images[$file]; $this->_res['tpl'][$this->tpl]['images'][$file] =& $this->images[$file];
} else { } else {
$this->_res['page'][$this->page]['images'][$file] =& $this->images[$file]; $this->_res['page'][$this->page]['images'][$file] =& $this->images[$file];
} }
return $ret;
} }
/** /**
@ -284,32 +306,50 @@ class FPDF_TPL extends FPDF {
* *
* AddPage is not available when you're "in" a template. * AddPage is not available when you're "in" a template.
*/ */
function AddPage($orientation='', $format='') { function AddPage($orientation = '', $format = '') {
if (is_subclass_of($this, 'TCPDF')) {
$args = func_get_args();
return call_user_func_array(array($this, 'TCPDF::AddPage'), $args);
}
if ($this->_intpl) if ($this->_intpl)
$this->Error('Adding pages in templates isn\'t possible!'); $this->Error('Adding pages in templates isn\'t possible!');
parent::AddPage($orientation, $format); parent::AddPage($orientation, $format);
} }
/** /**
* Preserve adding Links in Templates ...won't work * Preserve adding Links in Templates ...won't work
*/ */
function Link($x, $y, $w, $h, $link, $spaces=0) { function Link($x, $y, $w, $h, $link) {
if (!is_subclass_of($this, 'TCPDF') && func_num_args() > 5) { if (is_subclass_of($this, 'TCPDF')) {
$this->Error('More than 5 arguments for the Image method are only available in TCPDF.'); $args = func_get_args();
return call_user_func_array(array($this, 'TCPDF::Link'), $args);
} }
if ($this->_intpl) if ($this->_intpl)
$this->Error('Using links in templates aren\'t possible!'); $this->Error('Using links in templates aren\'t possible!');
parent::Link($x, $y, $w, $h, $link, $spaces);
parent::Link($x, $y, $w, $h, $link);
} }
function AddLink() { function AddLink() {
if (is_subclass_of($this, 'TCPDF')) {
$args = func_get_args();
return call_user_func_array(array($this, 'TCPDF::AddLink'), $args);
}
if ($this->_intpl) if ($this->_intpl)
$this->Error('Adding links in templates aren\'t possible!'); $this->Error('Adding links in templates aren\'t possible!');
return parent::AddLink(); return parent::AddLink();
} }
function SetLink($link, $y=0, $page=-1) { function SetLink($link, $y = 0, $page = -1) {
if (is_subclass_of($this, 'TCPDF')) {
$args = func_get_args();
return call_user_func_array(array($this, 'TCPDF::SetLink'), $args);
}
if ($this->_intpl) if ($this->_intpl)
$this->Error('Setting links in templates aren\'t possible!'); $this->Error('Setting links in templates aren\'t possible!');
parent::SetLink($link, $y, $page); parent::SetLink($link, $y, $page);
@ -331,18 +371,18 @@ class FPDF_TPL extends FPDF {
$this->_out('/FormType 1'); $this->_out('/FormType 1');
$this->_out(sprintf('/BBox [%.2F %.2F %.2F %.2F]', $this->_out(sprintf('/BBox [%.2F %.2F %.2F %.2F]',
// llx // llx
$tpl['x']*$this->k, $tpl['x'] * $this->k,
// lly // lly
-$tpl['y']*$this->k, -$tpl['y'] * $this->k,
// urx // urx
($tpl['w']+$tpl['x'])*$this->k, ($tpl['w'] + $tpl['x']) * $this->k,
// ury // ury
($tpl['h']-$tpl['y'])*$this->k ($tpl['h'] - $tpl['y']) * $this->k
)); ));
if ($tpl['x'] != 0 || $tpl['y'] != 0) { if ($tpl['x'] != 0 || $tpl['y'] != 0) {
$this->_out(sprintf('/Matrix [1 0 0 1 %.5F %.5F]', $this->_out(sprintf('/Matrix [1 0 0 1 %.5F %.5F]',
-$tpl['x']*$this->k*2, $tpl['y']*$this->k*2 -$tpl['x'] * $this->k * 2, $tpl['y'] * $this->k * 2
)); ));
} }
@ -352,7 +392,7 @@ class FPDF_TPL extends FPDF {
if (isset($this->_res['tpl'][$tplidx]['fonts']) && count($this->_res['tpl'][$tplidx]['fonts'])) { if (isset($this->_res['tpl'][$tplidx]['fonts']) && count($this->_res['tpl'][$tplidx]['fonts'])) {
$this->_out('/Font <<'); $this->_out('/Font <<');
foreach($this->_res['tpl'][$tplidx]['fonts'] as $font) foreach($this->_res['tpl'][$tplidx]['fonts'] as $font)
$this->_out('/F'.$font['i'].' '.$font['n'].' 0 R'); $this->_out('/F' . $font['i'] . ' ' . $font['n'] . ' 0 R');
$this->_out('>>'); $this->_out('>>');
} }
if(isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images']) || if(isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images']) ||
@ -361,17 +401,17 @@ class FPDF_TPL extends FPDF {
$this->_out('/XObject <<'); $this->_out('/XObject <<');
if (isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images'])) { if (isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images'])) {
foreach($this->_res['tpl'][$tplidx]['images'] as $image) foreach($this->_res['tpl'][$tplidx]['images'] as $image)
$this->_out('/I'.$image['i'].' '.$image['n'].' 0 R'); $this->_out('/I' . $image['i'] . ' ' . $image['n'] . ' 0 R');
} }
if (isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls'])) { if (isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls'])) {
foreach($this->_res['tpl'][$tplidx]['tpls'] as $i => $tpl) foreach($this->_res['tpl'][$tplidx]['tpls'] as $i => $tpl)
$this->_out($this->tplprefix.$i.' '.$tpl['n'].' 0 R'); $this->_out($this->tplprefix . $i . ' ' . $tpl['n'] . ' 0 R');
} }
$this->_out('>>'); $this->_out('>>');
} }
$this->_out('>>'); $this->_out('>>');
$this->_out('/Length '.strlen($p).' >>'); $this->_out('/Length ' . strlen($p) . ' >>');
$this->_putstream($p); $this->_putstream($p);
$this->_out('endobj'); $this->_out('endobj');
} }
@ -400,8 +440,8 @@ class FPDF_TPL extends FPDF {
* Private Method * Private Method
*/ */
function _out($s) { function _out($s) {
if ($this->state==2 && $this->_intpl) { if ($this->state == 2 && $this->_intpl) {
$this->tpls[$this->tpl]['buffer'] .= $s."\n"; $this->tpls[$this->tpl]['buffer'] .= $s . "\n";
} else { } else {
parent::_out($s); parent::_out($s);
} }

160
vendors/fpdi/fpdi.php vendored
View file

@ -1,8 +1,8 @@
<?php <?php
// //
// FPDI - Version 1.3.2 // FPDI - Version 1.4.1
// //
// Copyright 2004-2010 Setasign - Jan Slabon // Copyright 2004-2011 Setasign - Jan Slabon
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -17,14 +17,12 @@
// limitations under the License. // limitations under the License.
// //
define('FPDI_VERSION','1.3.2'); define('FPDI_VERSION', '1.4.1');
// Check for TCPDF and remap TCPDF to FPDF // Check for TCPDF and remap TCPDF to FPDF
$__tmp = version_compare(phpversion(), "5") == -1 ? array('TCPDF') : array('TCPDF', false); if (class_exists('TCPDF', false)) {
if (call_user_func_array('class_exists', $__tmp)) {
require_once('fpdi2tcpdf_bridge.php'); require_once('fpdi2tcpdf_bridge.php');
} }
unset($__tmp);
require_once('fpdf_tpl.php'); require_once('fpdf_tpl.php');
require_once('fpdi_pdf_parser.php'); require_once('fpdi_pdf_parser.php');
@ -73,9 +71,12 @@ class FPDI extends FPDF_TPL {
*/ */
var $lastUsedPageBox; var $lastUsedPageBox;
/**
* Cache for imported pages/template ids
* @var array
*/
var $_importedPages = array(); var $_importedPages = array();
/** /**
* Set a source-file * Set a source-file
* *
@ -84,30 +85,57 @@ class FPDI extends FPDF_TPL {
*/ */
function setSourceFile($filename) { function setSourceFile($filename) {
$this->current_filename = $filename; $this->current_filename = $filename;
$fn =& $this->current_filename;
if (!isset($this->parsers[$fn]))
$this->parsers[$fn] = new fpdi_pdf_parser($fn, $this);
$this->current_parser =& $this->parsers[$fn];
return $this->parsers[$fn]->getPageCount(); if (!isset($this->parsers[$filename]))
$this->parsers[$filename] = $this->_getPdfParser($filename);
$this->current_parser =& $this->parsers[$filename];
return $this->parsers[$filename]->getPageCount();
} }
/**
* Returns a PDF parser object
*
* @param string $filename
* @return fpdi_pdf_parser
*/
function _getPdfParser($filename) {
return new fpdi_pdf_parser($filename, $this);
}
/**
* Get the current PDF version
*
* @return string
*/
function getPDFVersion() {
return $this->PDFVersion;
}
/**
* Set the PDF version
*
* @return string
*/
function setPDFVersion($version = '1.3') {
$this->PDFVersion = $version;
}
/** /**
* Import a page * Import a page
* *
* @param int $pageno pagenumber * @param int $pageno pagenumber
* @return int Index of imported page - to use with fpdf_tpl::useTemplate() * @return int Index of imported page - to use with fpdf_tpl::useTemplate()
*/ */
function importPage($pageno, $boxName='/CropBox') { function importPage($pageno, $boxName = '/CropBox') {
if ($this->_intpl) { if ($this->_intpl) {
return $this->error('Please import the desired pages before creating a new template.'); return $this->error('Please import the desired pages before creating a new template.');
} }
$fn =& $this->current_filename; $fn = $this->current_filename;
// check if page already imported // check if page already imported
$pageKey = $fn.((int)$pageno).$boxName; $pageKey = $fn . '-' . ((int)$pageno) . $boxName;
if (isset($this->_importedPages[$pageKey])) if (isset($this->_importedPages[$pageKey]))
return $this->_importedPages[$pageKey]; return $this->_importedPages[$pageKey];
@ -116,7 +144,7 @@ class FPDI extends FPDF_TPL {
if (!in_array($boxName, $parser->availableBoxes)) if (!in_array($boxName, $parser->availableBoxes))
return $this->Error(sprintf('Unknown box: %s', $boxName)); return $this->Error(sprintf('Unknown box: %s', $boxName));
$pageboxes = $parser->getPageBoxes($pageno); $pageboxes = $parser->getPageBoxes($pageno, $this->k);
/** /**
* MediaBox * MediaBox
@ -155,14 +183,17 @@ class FPDI extends FPDF_TPL {
$rotation = $parser->getPageRotation($pageno); $rotation = $parser->getPageRotation($pageno);
$tpl['_rotationAngle'] = 0; $tpl['_rotationAngle'] = 0;
if (isset($rotation[1]) && ($angle = $rotation[1] % 360) != 0) { if (isset($rotation[1]) && ($angle = $rotation[1] % 360) != 0) {
$steps = $angle / 90; $steps = $angle / 90;
$_w = $tpl['w']; $_w = $tpl['w'];
$_h = $tpl['h']; $_h = $tpl['h'];
$tpl['w'] = $steps % 2 == 0 ? $_w : $_h; $tpl['w'] = $steps % 2 == 0 ? $_w : $_h;
$tpl['h'] = $steps % 2 == 0 ? $_h : $_w; $tpl['h'] = $steps % 2 == 0 ? $_h : $_w;
$tpl['_rotationAngle'] = $angle*-1; if ($angle < 0)
$angle += 360;
$tpl['_rotationAngle'] = $angle * -1;
} }
$this->_importedPages[$pageKey] = $this->tpl; $this->_importedPages[$pageKey] = $this->tpl;
@ -174,24 +205,29 @@ class FPDI extends FPDF_TPL {
return $this->lastUsedPageBox; return $this->lastUsedPageBox;
} }
function useTemplate($tplidx, $_x=null, $_y=null, $_w=0, $_h=0, $adjustPageSize=false) { function useTemplate($tplidx, $_x = null, $_y = null, $_w = 0, $_h = 0, $adjustPageSize = false) {
if ($adjustPageSize == true && is_null($_x) && is_null($_y)) { if ($adjustPageSize == true && is_null($_x) && is_null($_y)) {
$size = $this->getTemplateSize($tplidx, $_w, $_h); $size = $this->getTemplateSize($tplidx, $_w, $_h);
$format = array($size['w'], $size['h']); $format = array($size['w'], $size['h']);
if ($format[0]!=$this->CurPageFormat[0] || $format[1]!=$this->CurPageFormat[1]) { if (is_subclass_of($this, 'TCPDF')) {
$this->w=$format[0]; $this->setPageFormat($format, $format[0] > $format[1] ? 'L' : 'P');
$this->h=$format[1]; } else {
$this->wPt=$this->w*$this->k; if ($format[0] != $this->CurPageFormat[0] || $format[1] != $this->CurPageFormat[1]) {
$this->hPt=$this->h*$this->k; $this->w = $format[0];
$this->PageBreakTrigger=$this->h-$this->bMargin; $this->h = $format[1];
$this->CurPageFormat=$format; $this->wPt = $this->w * $this->k;
$this->PageSizes[$this->page]=array($this->wPt, $this->hPt); $this->hPt = $this->h * $this->k;
} $this->PageBreakTrigger = $this->h - $this->bMargin;
$this->CurPageFormat = $format;
$this->PageSizes[$this->page] = array($this->wPt, $this->hPt);
}
}
} }
$this->_out('q 0 J 1 w 0 j 0 G 0 g'); // reset standard values $this->_out('q 0 J 1 w 0 j 0 G 0 g'); // reset standard values
$s = parent::useTemplate($tplidx, $_x, $_y, $_w, $_h); $s = parent::useTemplate($tplidx, $_x, $_y, $_w, $_h);
$this->_out('Q'); $this->_out('Q');
return $s; return $s;
} }
@ -204,14 +240,14 @@ class FPDI extends FPDF_TPL {
$this->current_parser =& $this->parsers[$filename]; $this->current_parser =& $this->parsers[$filename];
if (isset($this->_obj_stack[$filename]) && is_array($this->_obj_stack[$filename])) { if (isset($this->_obj_stack[$filename]) && is_array($this->_obj_stack[$filename])) {
while(($n = key($this->_obj_stack[$filename])) !== null) { while(($n = key($this->_obj_stack[$filename])) !== null) {
$nObj = $this->current_parser->pdf_resolve_object($this->current_parser->c,$this->_obj_stack[$filename][$n][1]); $nObj = $this->current_parser->pdf_resolve_object($this->current_parser->c, $this->_obj_stack[$filename][$n][1]);
$this->_newobj($this->_obj_stack[$filename][$n][0]); $this->_newobj($this->_obj_stack[$filename][$n][0]);
if ($nObj[0] == PDF_TYPE_STREAM) { if ($nObj[0] == PDF_TYPE_STREAM) {
$this->pdf_write_value ($nObj); $this->pdf_write_value($nObj);
} else { } else {
$this->pdf_write_value ($nObj[1]); $this->pdf_write_value($nObj[1]);
} }
$this->_out('endobj'); $this->_out('endobj');
@ -237,15 +273,15 @@ class FPDI extends FPDF_TPL {
$cN = $this->n; // TCPDF/Protection: rem current "n" $cN = $this->n; // TCPDF/Protection: rem current "n"
$this->tpls[$tplidx]['n'] = $this->n; $this->tpls[$tplidx]['n'] = $this->n;
$this->_out('<<'.$filter.'/Type /XObject'); $this->_out('<<' . $filter . '/Type /XObject');
$this->_out('/Subtype /Form'); $this->_out('/Subtype /Form');
$this->_out('/FormType 1'); $this->_out('/FormType 1');
$this->_out(sprintf('/BBox [%.2F %.2F %.2F %.2F]', $this->_out(sprintf('/BBox [%.2F %.2F %.2F %.2F]',
(isset($tpl['box']['llx']) ? $tpl['box']['llx'] : $tpl['x'])*$this->k, (isset($tpl['box']['llx']) ? $tpl['box']['llx'] : $tpl['x']) * $this->k,
(isset($tpl['box']['lly']) ? $tpl['box']['lly'] : -$tpl['y'])*$this->k, (isset($tpl['box']['lly']) ? $tpl['box']['lly'] : -$tpl['y']) * $this->k,
(isset($tpl['box']['urx']) ? $tpl['box']['urx'] : $tpl['w'] + $tpl['x'])*$this->k, (isset($tpl['box']['urx']) ? $tpl['box']['urx'] : $tpl['w'] + $tpl['x']) * $this->k,
(isset($tpl['box']['ury']) ? $tpl['box']['ury'] : $tpl['h']-$tpl['y'])*$this->k (isset($tpl['box']['ury']) ? $tpl['box']['ury'] : $tpl['h'] - $tpl['y']) * $this->k
)); ));
$c = 1; $c = 1;
@ -272,7 +308,7 @@ class FPDI extends FPDF_TPL {
$ty = $tpl['box']['ury']; $ty = $tpl['box']['ury'];
break; break;
case -270: case -270:
$tx = $tpl['box']['ury']; $tx = $tpl['box']['ury'];
$ty = -$tpl['box']['llx']; $ty = -$tpl['box']['llx'];
break; break;
} }
@ -301,7 +337,7 @@ class FPDI extends FPDF_TPL {
if (isset($this->_res['tpl'][$tplidx]['fonts']) && count($this->_res['tpl'][$tplidx]['fonts'])) { if (isset($this->_res['tpl'][$tplidx]['fonts']) && count($this->_res['tpl'][$tplidx]['fonts'])) {
$this->_out('/Font <<'); $this->_out('/Font <<');
foreach($this->_res['tpl'][$tplidx]['fonts'] as $font) foreach($this->_res['tpl'][$tplidx]['fonts'] as $font)
$this->_out('/F'.$font['i'].' '.$font['n'].' 0 R'); $this->_out('/F' . $font['i'] . ' ' . $font['n'] . ' 0 R');
$this->_out('>>'); $this->_out('>>');
} }
if(isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images']) || if(isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images']) ||
@ -310,11 +346,11 @@ class FPDI extends FPDF_TPL {
$this->_out('/XObject <<'); $this->_out('/XObject <<');
if (isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images'])) { if (isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images'])) {
foreach($this->_res['tpl'][$tplidx]['images'] as $image) foreach($this->_res['tpl'][$tplidx]['images'] as $image)
$this->_out('/I'.$image['i'].' '.$image['n'].' 0 R'); $this->_out('/I' . $image['i'] . ' ' . $image['n'] . ' 0 R');
} }
if (isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls'])) { if (isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls'])) {
foreach($this->_res['tpl'][$tplidx]['tpls'] as $i => $tpl) foreach($this->_res['tpl'][$tplidx]['tpls'] as $i => $tpl)
$this->_out($this->tplprefix.$i.' '.$tpl['n'].' 0 R'); $this->_out($this->tplprefix . $i . ' ' . $tpl['n'] . ' 0 R');
} }
$this->_out('>>'); $this->_out('>>');
} }
@ -323,7 +359,7 @@ class FPDI extends FPDF_TPL {
$nN = $this->n; // TCPDF: rem new "n" $nN = $this->n; // TCPDF: rem new "n"
$this->n = $cN; // TCPDF: reset to current "n" $this->n = $cN; // TCPDF: reset to current "n"
$this->_out('/Length '.strlen($p).' >>'); $this->_out('/Length ' . strlen($p) . ' >>');
$this->_putstream($p); $this->_putstream($p);
$this->_out('endobj'); $this->_out('endobj');
$this->n = $nN; // TCPDF: reset to new "n" $this->n = $nN; // TCPDF: reset to new "n"
@ -335,7 +371,7 @@ class FPDI extends FPDF_TPL {
/** /**
* Rewritten to handle existing own defined objects * Rewritten to handle existing own defined objects
*/ */
function _newobj($obj_id=false,$onlynewobj=false) { function _newobj($obj_id = false, $onlynewobj = false) {
if (!$obj_id) { if (!$obj_id) {
$obj_id = ++$this->n; $obj_id = ++$this->n;
} }
@ -343,9 +379,10 @@ class FPDI extends FPDF_TPL {
//Begin a new object //Begin a new object
if (!$onlynewobj) { if (!$onlynewobj) {
$this->offsets[$obj_id] = is_subclass_of($this, 'TCPDF') ? $this->bufferlen : strlen($this->buffer); $this->offsets[$obj_id] = is_subclass_of($this, 'TCPDF') ? $this->bufferlen : strlen($this->buffer);
$this->_out($obj_id.' 0 obj'); $this->_out($obj_id . ' 0 obj');
$this->_current_obj_id = $obj_id; // for later use with encryption $this->_current_obj_id = $obj_id; // for later use with encryption
} }
return $obj_id; return $obj_id;
} }
@ -363,19 +400,19 @@ class FPDI extends FPDF_TPL {
switch ($value[0]) { switch ($value[0]) {
case PDF_TYPE_TOKEN : case PDF_TYPE_TOKEN:
$this->_straightOut($value[1] . ' '); $this->_straightOut($value[1] . ' ');
break; break;
case PDF_TYPE_NUMERIC : case PDF_TYPE_NUMERIC:
case PDF_TYPE_REAL : case PDF_TYPE_REAL:
if (is_float($value[1]) && $value[1] != 0) { if (is_float($value[1]) && $value[1] != 0) {
$this->_straightOut(rtrim(rtrim(sprintf('%F', $value[1]), '0'), '.') .' '); $this->_straightOut(rtrim(rtrim(sprintf('%F', $value[1]), '0'), '.') . ' ');
} else { } else {
$this->_straightOut($value[1] . ' '); $this->_straightOut($value[1] . ' ');
} }
break; break;
case PDF_TYPE_ARRAY : case PDF_TYPE_ARRAY:
// An array. Output the proper // An array. Output the proper
// structure and move on. // structure and move on.
@ -388,7 +425,7 @@ class FPDI extends FPDF_TPL {
$this->_out(']'); $this->_out(']');
break; break;
case PDF_TYPE_DICTIONARY : case PDF_TYPE_DICTIONARY:
// A dictionary. // A dictionary.
$this->_straightOut('<<'); $this->_straightOut('<<');
@ -403,30 +440,30 @@ class FPDI extends FPDF_TPL {
$this->_straightOut('>>'); $this->_straightOut('>>');
break; break;
case PDF_TYPE_OBJREF : case PDF_TYPE_OBJREF:
// An indirect object reference // An indirect object reference
// Fill the object stack if needed // Fill the object stack if needed
$cpfn =& $this->current_parser->filename; $cpfn =& $this->current_parser->filename;
if (!isset($this->_don_obj_stack[$cpfn][$value[1]])) { if (!isset($this->_don_obj_stack[$cpfn][$value[1]])) {
$this->_newobj(false,true); $this->_newobj(false, true);
$this->_obj_stack[$cpfn][$value[1]] = array($this->n, $value); $this->_obj_stack[$cpfn][$value[1]] = array($this->n, $value);
$this->_don_obj_stack[$cpfn][$value[1]] = array($this->n, $value); // Value is maybee obsolete!!! $this->_don_obj_stack[$cpfn][$value[1]] = array($this->n, $value); // Value is maybee obsolete!!!
} }
$objid = $this->_don_obj_stack[$cpfn][$value[1]][0]; $objid = $this->_don_obj_stack[$cpfn][$value[1]][0];
$this->_out($objid.' 0 R'); $this->_out($objid . ' 0 R');
break; break;
case PDF_TYPE_STRING : case PDF_TYPE_STRING:
// A string. // A string.
$this->_straightOut('('.$value[1].')'); $this->_straightOut('(' . $value[1] . ')');
break; break;
case PDF_TYPE_STREAM : case PDF_TYPE_STREAM:
// A stream. First, output the // A stream. First, output the
// stream dictionary, then the // stream dictionary, then the
@ -436,15 +473,16 @@ class FPDI extends FPDF_TPL {
$this->_out($value[2][1]); $this->_out($value[2][1]);
$this->_out('endstream'); $this->_out('endstream');
break; break;
case PDF_TYPE_HEX :
$this->_straightOut('<'.$value[1].'>'); case PDF_TYPE_HEX:
$this->_straightOut('<' . $value[1] . '>');
break; break;
case PDF_TYPE_BOOLEAN : case PDF_TYPE_BOOLEAN:
$this->_straightOut($value[1] ? 'true ' : 'false '); $this->_straightOut($value[1] ? 'true ' : 'false ');
break; break;
case PDF_TYPE_NULL : case PDF_TYPE_NULL:
// The null object. // The null object.
$this->_straightOut('null '); $this->_straightOut('null ');
@ -468,7 +506,7 @@ class FPDI extends FPDF_TPL {
// puts data before page footer // puts data before page footer
$page = substr($this->getPageBuffer($this->page), 0, -$this->footerlen[$this->page]); $page = substr($this->getPageBuffer($this->page), 0, -$this->footerlen[$this->page]);
$footer = substr($this->getPageBuffer($this->page), -$this->footerlen[$this->page]); $footer = substr($this->getPageBuffer($this->page), -$this->footerlen[$this->page]);
$this->setPageBuffer($this->page, $page.' '.$s."\n".$footer); $this->setPageBuffer($this->page, $page . ' ' . $s . "\n" . $footer);
} else { } else {
$this->setPageBuffer($this->page, $s, true); $this->setPageBuffer($this->page, $s, true);
} }

View file

@ -1,8 +1,8 @@
<?php <?php
// //
// FPDI - Version 1.3.2 // FPDI - Version 1.4.1
// //
// Copyright 2004-2010 Setasign - Jan Slabon // Copyright 2004-2011 Setasign - Jan Slabon
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -28,29 +28,21 @@
*/ */
class FPDF extends TCPDF { class FPDF extends TCPDF {
function __get($name) { function _putstream($s) {
switch ($name) { $this->_out($this->_getstream($s));
case 'PDFVersion': }
return $this->PDFVersion;
case 'k': function _getxobjectdict() {
return $this->k; $out = parent::_getxobjectdict();
default: if (count($this->tpls)) {
// Error handling foreach($this->tpls as $tplidx => $tpl) {
$this->Error('Cannot access protected property '.get_class($this).':$'.$name.' / Undefined property: '.get_class($this).'::$'.$name); $out .= sprintf('%s%d %d 0 R', $this->tplprefix, $tplidx, $tpl['n']);
}
} }
return $out;
} }
function __set($name, $value) {
switch ($name) {
case 'PDFVersion':
$this->PDFVersion = $value;
break;
default:
// Error handling
$this->Error('Cannot access protected property '.get_class($this).':$'.$name.' / Undefined property: '.get_class($this).'::$'.$name);
}
}
/** /**
* Encryption of imported data by FPDI * Encryption of imported data by FPDI
* *
@ -58,7 +50,7 @@ class FPDF extends TCPDF {
*/ */
function pdf_write_value(&$value) { function pdf_write_value(&$value) {
switch ($value[0]) { switch ($value[0]) {
case PDF_TYPE_STRING : case PDF_TYPE_STRING:
if ($this->encrypted) { if ($this->encrypted) {
$value[1] = $this->_unescape($value[1]); $value[1] = $this->_unescape($value[1]);
$value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]); $value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]);
@ -66,13 +58,13 @@ class FPDF extends TCPDF {
} }
break; break;
case PDF_TYPE_STREAM : case PDF_TYPE_STREAM:
if ($this->encrypted) { if ($this->encrypted) {
$value[2][1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[2][1]); $value[2][1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[2][1]);
} }
break; break;
case PDF_TYPE_HEX : case PDF_TYPE_HEX:
if ($this->encrypted) { if ($this->encrypted) {
$value[1] = $this->hex2str($value[1]); $value[1] = $this->hex2str($value[1]);
$value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]); $value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]);

View file

@ -1,8 +1,8 @@
<?php <?php
// //
// FPDI - Version 1.3.2 // FPDI - Version 1.4.1
// //
// Copyright 2004-2010 Setasign - Jan Slabon // Copyright 2004-2011 Setasign - Jan Slabon
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -167,7 +167,7 @@ class fpdi_pdf_parser extends pdf_parser {
if (isset($this->pages[$this->pageno][1][1]['/Contents'])) { if (isset($this->pages[$this->pageno][1][1]['/Contents'])) {
$contents = $this->_getPageContent($this->pages[$this->pageno][1][1]['/Contents']); $contents = $this->_getPageContent($this->pages[$this->pageno][1][1]['/Contents']);
foreach($contents AS $tmp_content) { foreach($contents AS $tmp_content) {
$buffer .= $this->_rebuildContentStream($tmp_content).' '; $buffer .= $this->_rebuildContentStream($tmp_content) . ' ';
} }
} }
@ -213,6 +213,11 @@ class fpdi_pdf_parser extends pdf_parser {
if (isset($obj[1][1]['/Filter'])) { if (isset($obj[1][1]['/Filter'])) {
$_filter = $obj[1][1]['/Filter']; $_filter = $obj[1][1]['/Filter'];
if ($_filter[0] == PDF_TYPE_OBJREF) {
$tmpFilter = $this->pdf_resolve_object($this->c, $_filter);
$_filter = $tmpFilter[1];
}
if ($_filter[0] == PDF_TYPE_TOKEN) { if ($_filter[0] == PDF_TYPE_TOKEN) {
$filters[] = $_filter; $filters[] = $_filter;
} else if ($_filter[0] == PDF_TYPE_ARRAY) { } else if ($_filter[0] == PDF_TYPE_ARRAY) {
@ -225,13 +230,18 @@ class fpdi_pdf_parser extends pdf_parser {
foreach ($filters AS $_filter) { foreach ($filters AS $_filter) {
switch ($_filter[1]) { switch ($_filter[1]) {
case '/FlateDecode': case '/FlateDecode':
if (function_exists('gzuncompress')) { case '/Fl':
// $stream .= "\x0F\x0D"; // in an errorious stream this suffix could work
// $stream .= "\x0A";
// $stream .= "\x0D";
if (function_exists('gzuncompress')) {
$stream = (strlen($stream) > 0) ? @gzuncompress($stream) : ''; $stream = (strlen($stream) > 0) ? @gzuncompress($stream) : '';
} else { } else {
$this->error(sprintf('To handle %s filter, please compile php with zlib support.',$_filter[1])); $this->error(sprintf('To handle %s filter, please compile php with zlib support.',$_filter[1]));
} }
if ($stream === false) { if ($stream === false) {
$this->error('Error while decompressing stream.'); $this->error('Error while decompressing stream.');
} }
break; break;
case '/LZWDecode': case '/LZWDecode':
@ -262,52 +272,60 @@ class fpdi_pdf_parser extends pdf_parser {
* *
* @param array $page a /Page * @param array $page a /Page
* @param string $box_index Type of Box @see $availableBoxes * @param string $box_index Type of Box @see $availableBoxes
* @param float Scale factor from user space units to points
* @return array * @return array
*/ */
function getPageBox($page, $box_index) { function getPageBox($page, $box_index, $k) {
$page = $this->pdf_resolve_object($this->c,$page); $page = $this->pdf_resolve_object($this->c, $page);
$box = null; $box = null;
if (isset($page[1][1][$box_index])) if (isset($page[1][1][$box_index]))
$box =& $page[1][1][$box_index]; $box =& $page[1][1][$box_index];
if (!is_null($box) && $box[0] == PDF_TYPE_OBJREF) { if (!is_null($box) && $box[0] == PDF_TYPE_OBJREF) {
$tmp_box = $this->pdf_resolve_object($this->c,$box); $tmp_box = $this->pdf_resolve_object($this->c, $box);
$box = $tmp_box[1]; $box = $tmp_box[1];
} }
if (!is_null($box) && $box[0] == PDF_TYPE_ARRAY) { if (!is_null($box) && $box[0] == PDF_TYPE_ARRAY) {
$b =& $box[1]; $b =& $box[1];
return array('x' => $b[0][1]/$this->fpdi->k, return array('x' => $b[0][1]/$k,
'y' => $b[1][1]/$this->fpdi->k, 'y' => $b[1][1]/$k,
'w' => abs($b[0][1]-$b[2][1])/$this->fpdi->k, 'w' => abs($b[0][1]-$b[2][1])/$k,
'h' => abs($b[1][1]-$b[3][1])/$this->fpdi->k, 'h' => abs($b[1][1]-$b[3][1])/$k,
'llx' => min($b[0][1], $b[2][1])/$this->fpdi->k, 'llx' => min($b[0][1], $b[2][1])/$k,
'lly' => min($b[1][1], $b[3][1])/$this->fpdi->k, 'lly' => min($b[1][1], $b[3][1])/$k,
'urx' => max($b[0][1], $b[2][1])/$this->fpdi->k, 'urx' => max($b[0][1], $b[2][1])/$k,
'ury' => max($b[1][1], $b[3][1])/$this->fpdi->k, 'ury' => max($b[1][1], $b[3][1])/$k,
); );
} else if (!isset ($page[1][1]['/Parent'])) { } else if (!isset ($page[1][1]['/Parent'])) {
return false; return false;
} else { } else {
return $this->getPageBox($this->pdf_resolve_object($this->c, $page[1][1]['/Parent']), $box_index); return $this->getPageBox($this->pdf_resolve_object($this->c, $page[1][1]['/Parent']), $box_index, $k);
} }
} }
function getPageBoxes($pageno) { /**
return $this->_getPageBoxes($this->pages[$pageno-1]); * Get all page boxes by page no
*
* @param int The page number
* @param float Scale factor from user space units to points
* @return array
*/
function getPageBoxes($pageno, $k) {
return $this->_getPageBoxes($this->pages[$pageno-1], $k);
} }
/** /**
* Get all Boxes from /Page * Get all boxes from /Page
* *
* @param array a /Page * @param array a /Page
* @return array * @return array
*/ */
function _getPageBoxes($page) { function _getPageBoxes($page, $k) {
$boxes = array(); $boxes = array();
foreach($this->availableBoxes AS $box) { foreach($this->availableBoxes AS $box) {
if ($_box = $this->getPageBox($page,$box)) { if ($_box = $this->getPageBox($page, $box, $k)) {
$boxes[$box] = $_box; $boxes[$box] = $_box;
} }
} }
@ -325,7 +343,7 @@ class fpdi_pdf_parser extends pdf_parser {
return $this->_getPageRotation($this->pages[$pageno-1]); return $this->_getPageRotation($this->pages[$pageno-1]);
} }
function _getPageRotation ($obj) { // $obj = /Page function _getPageRotation($obj) { // $obj = /Page
$obj = $this->pdf_resolve_object($this->c, $obj); $obj = $this->pdf_resolve_object($this->c, $obj);
if (isset ($obj[1][1]['/Rotate'])) { if (isset ($obj[1][1]['/Rotate'])) {
$res = $this->pdf_resolve_object($this->c, $obj[1][1]['/Rotate']); $res = $this->pdf_resolve_object($this->c, $obj[1][1]['/Rotate']);
@ -351,7 +369,7 @@ class fpdi_pdf_parser extends pdf_parser {
* @param array /Pages * @param array /Pages
* @param array the result-array * @param array the result-array
*/ */
function read_pages (&$c, &$pages, &$result) { function read_pages(&$c, &$pages, &$result) {
// Get the kids dictionary // Get the kids dictionary
$_kids = $this->pdf_resolve_object ($c, $pages[1][1]['/Kids']); $_kids = $this->pdf_resolve_object ($c, $pages[1][1]['/Kids']);
@ -369,7 +387,7 @@ class fpdi_pdf_parser extends pdf_parser {
if ($pg[1][1]['/Type'][1] === '/Pages') { if ($pg[1][1]['/Type'][1] === '/Pages') {
// If one of the kids is an embedded // If one of the kids is an embedded
// /Pages array, resolve it as well. // /Pages array, resolve it as well.
$this->read_pages ($c, $pg, $result); $this->read_pages($c, $pg, $result);
} else { } else {
$result[] = $pg; $result[] = $pg;
} }
@ -385,7 +403,7 @@ class fpdi_pdf_parser extends pdf_parser {
*/ */
function getPDFVersion() { function getPDFVersion() {
parent::getPDFVersion(); parent::getPDFVersion();
$this->fpdi->PDFVersion = max($this->fpdi->PDFVersion, $this->pdfVersion); $this->fpdi->setPDFVersion(max($this->fpdi->getPDFVersion(), $this->pdfVersion));
} }
} }

View file

@ -1,8 +1,8 @@
<?php <?php
// //
// FPDI - Version 1.3.2 // FPDI - Version 1.4.1
// //
// Copyright 2004-2010 Setasign - Jan Slabon // Copyright 2004-2011 Setasign - Jan Slabon
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -17,8 +17,7 @@
// limitations under the License. // limitations under the License.
// //
$__tmp = version_compare(phpversion(), "5") == -1 ? array('pdf_context') : array('pdf_context', false); if (!class_exists('pdf_context', false)) {
if (!call_user_func_array('class_exists', $__tmp)) {
class pdf_context { class pdf_context {
@ -83,21 +82,23 @@ if (!call_user_func_array('class_exists', $__tmp)) {
// Forcefully read more data into the buffer // Forcefully read more data into the buffer
function increase_length($l=100) { function increase_length($l = 100) {
if ($this->_mode == 0 && feof($this->file)) { if ($this->_mode == 0 && feof($this->file)) {
return false; return false;
} else if ($this->_mode == 0) { } else if ($this->_mode == 0) {
$totalLength = $this->length + $l; $totalLength = $this->length + $l;
do { do {
$this->buffer .= fread($this->file, $totalLength-$this->length); $toRead = $totalLength - $this->length;
} while ((($this->length = strlen($this->buffer)) != $totalLength) && !feof($this->file)); if ($toRead < 1)
break;
return true;
} else { $this->buffer .= fread($this->file, $toRead);
return false; } while ((($this->length = strlen($this->buffer)) != $totalLength) && !feof($this->file));
}
} return true;
} else {
return false;
}
}
} }
} }
unset($__tmp);

View file

@ -1,8 +1,8 @@
<?php <?php
// //
// FPDI - Version 1.3.2 // FPDI - Version 1.4.1
// //
// Copyright 2004-2010 Setasign - Jan Slabon // Copyright 2004-2011 Setasign - Jan Slabon
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -46,8 +46,7 @@ if (!defined ('PDF_TYPE_REAL'))
require_once('pdf_context.php'); require_once('pdf_context.php');
$__tmp = version_compare(phpversion(), "5") == -1 ? array('pdf_parser') : array('pdf_parser', false); if (!class_exists('pdf_parser', false)) {
if (!call_user_func_array('class_exists', $__tmp)) {
class pdf_parser { class pdf_parser {
@ -87,6 +86,13 @@ if (!call_user_func_array('class_exists', $__tmp)) {
*/ */
var $pdfVersion; var $pdfVersion;
/**
* For reading encrypted documents and xref/objectstreams are in use
*
* @var boolean
*/
var $readPlain = true;
/** /**
* Constructor * Constructor
* *
@ -139,7 +145,7 @@ if (!call_user_func_array('class_exists', $__tmp)) {
*/ */
function getEncryption() { function getEncryption() {
if (isset($this->xref['trailer'][1]['/Encrypt'])) { if (isset($this->xref['trailer'][1]['/Encrypt'])) {
$this->error('File is encrypted!'); $this->error('File is encrypted!');
} }
} }
@ -206,8 +212,8 @@ if (!call_user_func_array('class_exists', $__tmp)) {
* @param integer $offset of xref-table * @param integer $offset of xref-table
*/ */
function pdf_read_xref(&$result, $offset) { function pdf_read_xref(&$result, $offset) {
$o_pos = $offset-min(20, $offset);
fseek($this->f, $o_pos = $offset-20); // set some bytes backwards to fetch errorious docs fseek($this->f, $o_pos); // set some bytes backwards to fetch errorious docs
$data = fread($this->f, 100); $data = fread($this->f, 100);
@ -452,7 +458,7 @@ if (!call_user_func_array('class_exists', $__tmp)) {
} else { } else {
$length = $this->actual_obj[1][1]['/Length'][1]; $length = $this->actual_obj[1][1]['/Length'][1];
} }
if ($length > 0) { if ($length > 0) {
$c->reset($startpos+$e,$length); $c->reset($startpos+$e,$length);
$v = $c->buffer; $v = $c->buffer;
@ -542,7 +548,14 @@ if (!call_user_func_array('class_exists', $__tmp)) {
$header = $this->pdf_read_value($c); $header = $this->pdf_read_value($c);
if ($header[0] != PDF_TYPE_OBJDEC || $header[1] != $obj_spec[1] || $header[2] != $obj_spec[2]) { if ($header[0] != PDF_TYPE_OBJDEC || $header[1] != $obj_spec[1] || $header[2] != $obj_spec[2]) {
$this->error("Unable to find object ({$obj_spec[1]}, {$obj_spec[2]}) at expected location"); $toSearchFor = $obj_spec[1].' '.$obj_spec[2].' obj';
if (preg_match('/'.$toSearchFor.'/', $c->buffer)) {
$c->offset = strpos($c->buffer, $toSearchFor) + strlen($toSearchFor);
// reset stack
$c->stack = array();
} else {
$this->error("Unable to find object ({$obj_spec[1]}, {$obj_spec[2]}) at expected location");
}
} }
// If we're being asked to store all the information // If we're being asked to store all the information
@ -704,5 +717,3 @@ if (!call_user_func_array('class_exists', $__tmp)) {
} }
} }
} }
unset($__tmp);

View file

@ -1,3 +1,17 @@
5.9.082 (2011-05-22)
- Bug item #3305592 "Setting fill color <> text color breaks text clipping" was fixed.
5.9.081 (2011-05-18)
- Method resetHeaderTemplate() was added to reset the xobject template used by Header() method.
- Method setHeaderTemplateAutoreset() was added to automatically reset the xobject template used by Header() method at each page.
5.9.080 (2011-05-17)
- A problem related to file path calculation for images was fixed.
- A problem related to unsupressed getimagesize() error was fixed.
5.9.079 (2011-05-16)
- Footer() method was changed to use C128 barcode as default (instead of the previous C128B).
5.9.078 (2011-05-12) 5.9.078 (2011-05-12)
- Bug item #3300878 "wrong rendering for html bullet list in some case" was fixed. - Bug item #3300878 "wrong rendering for html bullet list in some case" was fixed.
- Bug item #3301017 "Emphasized vs. font-weight" was fixed. - Bug item #3301017 "Emphasized vs. font-weight" was fixed.

View file

@ -8,8 +8,8 @@ http://sourceforge.net/donate/index.php?group_id=128076
------------------------------------------------------------ ------------------------------------------------------------
Name: TCPDF Name: TCPDF
Version: 5.9.078 Version: 5.9.082
Release date: 2011-05-12 Release date: 2011-05-22
Author: Nicola Asuni Author: Nicola Asuni
Copyright (c) 2002-2011: Copyright (c) 2002-2011:
@ -72,8 +72,8 @@ License
TCPDF is free software: you can redistribute it and/or modify it TCPDF is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version. Additionally, License, or (at your option) any later version. Additionally,
YOU CAN'T REMOVE ANY TCPDF COPYRIGHT NOTICE OR LINK FROM THE YOU CAN'T REMOVE ANY TCPDF COPYRIGHT NOTICE OR LINK FROM THE
GENERATED PDF DOCUMENTS. GENERATED PDF DOCUMENTS.
TCPDF is distributed in the hope that it will be useful, but TCPDF is distributed in the hope that it will be useful, but

View file

@ -1,9 +1,9 @@
<?php <?php
//============================================================+ //============================================================+
// File name : tcpdf.php // File name : tcpdf.php
// Version : 5.9.078 // Version : 5.9.082
// Begin : 2002-08-03 // Begin : 2002-08-03
// Last Update : 2011-05-12 // Last Update : 2011-05-22
// Author : Nicola Asuni - Tecnick.com S.r.l - Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com // Author : Nicola Asuni - Tecnick.com S.r.l - Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
// License : http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT GNU-LGPLv3 + YOU CAN'T REMOVE ANY TCPDF COPYRIGHT NOTICE OR LINK FROM THE GENERATED PDF DOCUMENTS. // License : http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT GNU-LGPLv3 + YOU CAN'T REMOVE ANY TCPDF COPYRIGHT NOTICE OR LINK FROM THE GENERATED PDF DOCUMENTS.
// ------------------------------------------------------------------- // -------------------------------------------------------------------
@ -134,7 +134,7 @@
* Tools to encode your unicode fonts are on fonts/utils directory.</p> * Tools to encode your unicode fonts are on fonts/utils directory.</p>
* @package com.tecnick.tcpdf * @package com.tecnick.tcpdf
* @author Nicola Asuni * @author Nicola Asuni
* @version 5.9.078 * @version 5.9.082
*/ */
// Main configuration file. Define the K_TCPDF_EXTERNAL_CONFIG constant to skip this file. // Main configuration file. Define the K_TCPDF_EXTERNAL_CONFIG constant to skip this file.
@ -146,7 +146,7 @@ require_once(dirname(__FILE__).'/config/tcpdf_config.php');
* TCPDF project (http://www.tcpdf.org) has been originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.<br> * TCPDF project (http://www.tcpdf.org) has been originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.<br>
* @package com.tecnick.tcpdf * @package com.tecnick.tcpdf
* @brief PHP class for generating PDF documents without requiring external extensions. * @brief PHP class for generating PDF documents without requiring external extensions.
* @version 5.9.078 * @version 5.9.082
* @author Nicola Asuni - info@tecnick.com * @author Nicola Asuni - info@tecnick.com
*/ */
class TCPDF { class TCPDF {
@ -157,7 +157,7 @@ class TCPDF {
* Current TCPDF version. * Current TCPDF version.
* @private * @private
*/ */
private $tcpdf_version = '5.9.078'; private $tcpdf_version = '5.9.082';
// Protected properties // Protected properties
@ -571,6 +571,12 @@ class TCPDF {
* @protected * @protected
*/ */
protected $header_xobjid = -1; protected $header_xobjid = -1;
/**
* If true reset the Header Xobject template at each page
* @protected
*/
protected $header_xobj_autoreset = false;
/** /**
* Minimum distance between header and top page margin. * Minimum distance between header and top page margin.
@ -1912,6 +1918,7 @@ class TCPDF {
$this->file_id = md5($this->getRandomSeed('TCPDF'.$orientation.$unit.$format.$encoding)); $this->file_id = md5($this->getRandomSeed('TCPDF'.$orientation.$unit.$format.$encoding));
// get default graphic vars // get default graphic vars
$this->default_graphic_vars = $this->getGraphicVars(); $this->default_graphic_vars = $this->getGraphicVars();
$this->header_xobj_autoreset = false;
} }
/** /**
@ -4003,6 +4010,23 @@ class TCPDF {
return $this->img_rb_y; return $this->img_rb_y;
} }
/**
* Reset the xobject template used by Header() method.
* @public
*/
public function resetHeaderTemplate() {
$this->header_xobjid = -1;
}
/**
* Set a flag to automatically reset the xobject template used by Header() method at each page.
* @param $val (boolean) set to true to reset Header xobject template at each page, false otherwise.
* @public
*/
public function setHeaderTemplateAutoreset($val=true) {
$this->header_xobj_autoreset = $val;
}
/** /**
* This method is used to render the page header. * This method is used to render the page header.
* It is automatically called by AddPage() and could be overwritten in your own inherited class. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
@ -4074,6 +4098,10 @@ class TCPDF {
$x = 0 + $dx; $x = 0 + $dx;
} }
$this->printTemplate($this->header_xobjid, $x, 0, 0, 0, '', '', false); $this->printTemplate($this->header_xobjid, $x, 0, 0, 0, '', '', false);
if ($this->header_xobj_autoreset) {
// reset header xobject template at each page
$this->header_xobjid = -1;
}
} }
/** /**
@ -4104,7 +4132,7 @@ class TCPDF {
'bgcolor' => false, 'bgcolor' => false,
'text' => false 'text' => false
); );
$this->write1DBarcode($barcode, 'C128B', '', $cur_y + $line_width, '', (($this->footer_margin / 3) - $line_width), 0.3, $style, ''); $this->write1DBarcode($barcode, 'C128', '', $cur_y + $line_width, '', (($this->footer_margin / 3) - $line_width), 0.3, $style, '');
} }
if (empty($this->pagegroups)) { if (empty($this->pagegroups)) {
$pagenumtxt = $this->l['w_page'].' '.$this->getAliasNumPage().' / '.$this->getAliasNbPages(); $pagenumtxt = $this->l['w_page'].' '.$this->getAliasNumPage().' / '.$this->getAliasNbPages();
@ -5694,7 +5722,7 @@ class TCPDF {
// increase/decrease font spacing // increase/decrease font spacing
$rs .= sprintf('BT %.2F Tc ET ', ($this->font_spacing * $this->k)); $rs .= sprintf('BT %.2F Tc ET ', ($this->font_spacing * $this->k));
} }
if ($this->ColorFlag) { if ($this->ColorFlag AND ($this->textrendermode < 4)) {
$s .= 'q '.$this->TextColor.' '; $s .= 'q '.$this->TextColor.' ';
} }
// rendering mode // rendering mode
@ -5801,7 +5829,7 @@ class TCPDF {
if ($this->overline) { if ($this->overline) {
$s .= ' '.$this->_dooverlinew($xdx, $basefonty, $width); $s .= ' '.$this->_dooverlinew($xdx, $basefonty, $width);
} }
if ($this->ColorFlag) { if ($this->ColorFlag AND ($this->textrendermode < 4)) {
$s .= ' Q'; $s .= ' Q';
} }
if ($link) { if ($link) {
@ -7261,8 +7289,12 @@ class TCPDF {
// encode spaces on filename (file is probably an URL) // encode spaces on filename (file is probably an URL)
$file = str_replace(' ', '%20', $file); $file = str_replace(' ', '%20', $file);
} }
// get image dimensions if (@file_exists($file)) {
$imsize = @getimagesize($file); // get image dimensions
$imsize = @getimagesize($file);
} else {
$imsize = false;
}
if ($imsize === FALSE) { if ($imsize === FALSE) {
if (function_exists('curl_init')) { if (function_exists('curl_init')) {
// try to get remote file data using cURL // try to get remote file data using cURL
@ -20967,7 +20999,11 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value:
if (($tag['attribute']['src'][0] == '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) { if (($tag['attribute']['src'][0] == '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
$findroot = strpos($tag['attribute']['src'], $_SERVER['DOCUMENT_ROOT']); $findroot = strpos($tag['attribute']['src'], $_SERVER['DOCUMENT_ROOT']);
if (($findroot === false) OR ($findroot > 1)) { if (($findroot === false) OR ($findroot > 1)) {
$tag['attribute']['src'] = $_SERVER['DOCUMENT_ROOT'].$tag['attribute']['src']; if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
$tag['attribute']['src'] = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$tag['attribute']['src'];
} else {
$tag['attribute']['src'] = $_SERVER['DOCUMENT_ROOT'].$tag['attribute']['src'];
}
} }
} }
$tag['attribute']['src'] = urldecode($tag['attribute']['src']); $tag['attribute']['src'] = urldecode($tag['attribute']['src']);
@ -26371,11 +26407,14 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value:
// replace relative path with full server path // replace relative path with full server path
$img = $this->svgdir.'/'.$img; $img = $this->svgdir.'/'.$img;
} }
if (($img{0} == '/') AND ($_SERVER['DOCUMENT_ROOT'] != '/')) { if (($img[0] == '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
$findroot = strpos($img, $_SERVER['DOCUMENT_ROOT']); $findroot = strpos($img, $_SERVER['DOCUMENT_ROOT']);
if (($findroot === false) OR ($findroot > 1)) { if (($findroot === false) OR ($findroot > 1)) {
// replace relative path with full server path if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
$img = $_SERVER['DOCUMENT_ROOT'].$img; $img = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$img;
} else {
$img = $_SERVER['DOCUMENT_ROOT'].$img;
}
} }
} }
$img = urldecode($img); $img = urldecode($img);

3
vendors/xfpdi.php vendored
View file

@ -1,5 +1,6 @@
<? <?
//App::import('Vendor', 'tcpdf/tcpdf'); App::import('Vendor', 'tcpdf/tcpdf');
App::import('Vendor', 'fpdi/fpdi'); App::import('Vendor', 'fpdi/fpdi');
class XFPDI extends FPDI { class XFPDI extends FPDI {

726
vendors/xtcpdf.php vendored
View file

@ -11,46 +11,46 @@ class XTCPDF extends TCPDF {
var $xfooterfont = PDF_FONT_NAME_MAIN ; var $xfooterfont = PDF_FONT_NAME_MAIN ;
var $xfooterfontsize = 8 ; var $xfooterfontsize = 8 ;
function Page1Header() { function Page1Header() {
list($r, $b, $g) = $this->xheadercolor; list($r, $b, $g) = $this->xheadercolor;
//$this->setY(10); // shouldn't be needed due to page margin, but helas, otherwise it's at the page top //$this->setY(10); // shouldn't be needed due to page margin, but helas, otherwise it's at the page top
$this->SetFillColor(255, 255, 255); $this->SetFillColor(255, 255, 255);
$this->SetTextColor(0 , 0, 152); //Set the Text Color to Blue $this->SetTextColor(0 , 0, 152); //Set the Text Color to Blue
// $this->Image($file, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $ismask, $imgmask, $border, $fitbox, $hidden) // $this->Image($file, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $ismask, $imgmask, $border, $fitbox, $hidden)
$this->Image(K_PATH_IMAGES.'cmclogosmall.jpg', 10, 10, 30, 0, null, 'http://www.cmctechnologies.com.au', null, false, null, 'L'); $this->Image(K_PATH_IMAGES.'cmclogosmall.jpg', 10, 10, 30, 0, null, 'http://www.cmctechnologies.com.au', null, false, null, 'L');
$this->Cell(30); $this->Cell(30);
$this->SetFont('times', 'B'); $this->SetFont('times', 'B');
$this->SetFontSize(30); $this->SetFontSize(30);
$this->Cell(0,0, $this->xheadertext, 0,1,'C', 1); $this->Cell(0,0, $this->xheadertext, 0,1,'C', 1);
$this->SetFontSize(10); $this->SetFontSize(10);
$this->SetY(22); $this->SetY(22);
$this->Cell(30); $this->Cell(30);
$this->Cell(0,0, "PTY LIMITED ACN: 47 085 991 224 ABN: 47 085 991 224", 0, 1, 'C', 1); $this->Cell(0,0, "PTY LIMITED ACN: 47 085 991 224 ABN: 47 085 991 224", 0, 1, 'C', 1);
$this->Rect($this->GetX()+33, $this->GetY()+2, 157, 2, 'DF', array('width'=>0), array(0, 0, 0)); $this->Rect($this->GetX()+33, $this->GetY()+2, 157, 2, 'DF', array('width'=>0), array(0, 0, 0));
/* Start the contact details */ /* Start the contact details */
$this->SetTextColor(0); //Set the Text Color to Black $this->SetTextColor(0); //Set the Text Color to Black
$this->MultiCell(18, 0, "Phone:\nFax:\nEmail:\nWeb Site:\n", 0, 'L', 0, 0, 45, 32); $this->MultiCell(18, 0, "Phone:\nFax:\nEmail:\nWeb Site:\n", 0, 'L', 0, 0, 45, 32);
$this->MultiCell(50, 0, "+61 2 9669 4000<br>+61 2 9669 4111<br><a href=\"mailto:sales@cmctechnologies.com.au\">sales@cmctechnologies.com.au</a> $this->MultiCell(50, 0, "+61 2 9669 4000<br>+61 2 9669 4111<br><a href=\"mailto:sales@cmctechnologies.com.au\">sales@cmctechnologies.com.au</a>
<br><a href=\"http://www.cmctechnologies.com.au\">www.cmctechnologies.com.au</a><br>", 0, 'L', 0, 0, 65, null, true, 0, true); <br><a href=\"http://www.cmctechnologies.com.au\">www.cmctechnologies.com.au</a><br>", 0, 'L', 0, 0, 65, null, true, 0, true);
$this->MultiCell(50, 0, "Unit 19, 77 Bourke Rd\nAlexandria\nNSW 2015\nAUSTRALIA\n", 0, 'L', 0, 0, 150, null); $this->MultiCell(50, 0, "Unit 19, 77 Bourke Rd\nAlexandria\nNSW 2015\nAUSTRALIA\n", 0, 'L', 0, 0, 150, null);
$this->SetTextColor(0 , 0, 152); //Set the Text Color to Blue $this->SetTextColor(0 , 0, 152); //Set the Text Color to Blue
$this->SetFont('times', 'B'); $this->SetFont('times', 'B');
$this->MultiCell(30, 20, "Engineering &\nIndustrial\nInstrumentation", 0, 'L', 0, 1, 10,37); $this->MultiCell(30, 20, "Engineering &\nIndustrial\nInstrumentation", 0, 'L', 0, 1, 10,37);
@ -63,20 +63,22 @@ class XTCPDF extends TCPDF {
* $fpdf->xfootertext = 'Copyright © %d YOUR ORGANIZATION. All rights reserved.'; * $fpdf->xfootertext = 'Copyright © %d YOUR ORGANIZATION. All rights reserved.';
*/ */
function Page1Footer() { function Page1Footer() {
$this->SetY(-30); $this->SetY(-30);
//$this->Image(K_PATH_IMAGES.'cmcfooter.jpg', null, 255, 200, 0, null, 'http://www.cmctechnologies.com.au', null, false, null, 'C'); /*//$this->Image(K_PATH_IMAGES.'cmcfooter.jpg', null, 255, 200, 0, null, 'http://www.cmctechnologies.com.au', null, false, null, 'C');
$this->MultiCell(0, 2, "<hr>", 0, 'C', null, 1, null, null, true, 0, true, false); $this->MultiCell(0, 2, "<hr>", 0, 'C', null, 1, null, null, true, 0, true, false);
// $this->MultiCell(0, 2, "PROVIDING SOLUTIONS IN", 0, 'C', null, 1, null, null, true, 0, true, false); // $this->MultiCell(0, 2, "PROVIDING SOLUTIONS IN", 0, 'C', null, 1, null, null, true, 0, true, false);
//$this->ln(); //$this->ln();
//$this->ln(); //$this->ln();
$this->SetFontSize(12); $this->SetFontSize(10);
$this->MultiCell(120, 2, "<span style=\"color: #DF0101; font-weight: bold\">EXPLOSION PREVENTION</span>", 0, 'L', null, 0, null, null, true, 0, true, false); $this->MultiCell(120, 2, "<span style=\"color: #DF0101; font-weight: bold\">EXPLOSION PREVENTION</span>", 0, 'L', null, 0, null, null, true, 0, true, false);
$this->MultiCell(0, 2, "<span style=\"color: #DF0101; font-weight: bold\">PRESSURE RELIEF</span>", 0, 'R', null, 1, null, null, true, 0, true, false); $this->MultiCell(0, 2, "<span style=\"color: #DF0101; font-weight: bold\">PRESSURE RELIEF</span>", 0, 'R', null, 1, null, null, true, 0, true, false);
$this->MultiCell(120, 2, "<span style=\"color: #088A4B; font-weight: bold\">EXPLOSION PROTECTION</span>", 0, 'L', null, 0, null, null, true, 0, true, false); $this->MultiCell(120, 2, "<span style=\"color: #088A4B; font-weight: bold\">EXPLOSION PROTECTION</span>", 0, 'L', null, 0, null, null, true, 0, true, false);
$this->MultiCell(0, 2, "<span style=\"color: #088A4B; font-weight: bold\">VISION IN THE PROCESS</span>", 0, 'R', null, 1, null, null, true, 0, true, false); $this->MultiCell(0, 2, "<span style=\"color: #088A4B; font-weight: bold\">VISION IN THE PROCESS</span>", 0, 'R', null, 1, null, null, true, 0, true, false);
// $this->ln(); // $this->ln();
$this->MultiCell(80, 2, "<span style=\"color: #0000FF; font-weight: bold\">FLOW MEASUREMENT</span>", 0, 'L', null, 0, null, null, true, 0, true, false); $this->MultiCell(80, 2, "<span style=\"color: #0000FF; font-weight: bold\">FLOW MEASUREMENT</span>", 0, 'L', null, 0, null, null, true, 0, true, false);
$this->MultiCell(0, 2, "<span style=\"color: #0000FF; font-weight: bold\">PROCESS INSTRUMENTATION</span>", 0, 'R', null, 1, null, null, true, 0, true, false); $this->MultiCell(0, 2, "<span style=\"color: #0000FF; font-weight: bold\">PROCESS INSTRUMENTATION</span>", 0, 'R', null, 1, null, null, true, 0, true, false);
*/
} }
@ -86,76 +88,76 @@ class XTCPDF extends TCPDF {
*/ */
function DetailsBox($companyName, $emailTo, $attention, $fromName, $fromEmail, $enquiryNumber, $your_reference, $issuedate) { function DetailsBox($companyName, $emailTo, $attention, $fromName, $fromEmail, $enquiryNumber, $your_reference, $issuedate) {
$this->SetTextColor(0); //Black Text $this->SetTextColor(0); //Black Text
$boxYstart = 45; $boxYstart = 45;
$boxXstart = 10; $boxXstart = 10;
$firstColWidth = 40; $firstColWidth = 40;
$secondColWidth = 70; $secondColWidth = 70;
$thirdColWidth = 30; $thirdColWidth = 30;
$fourthColWidth = -10; $fourthColWidth = -10;
$pageNo = $this->PageNoFormatted(); $pageNo = $this->PageNoFormatted();
$this->SetXY($boxXstart, 55); $this->SetXY($boxXstart, 55);
$heightNeeded = $this->getNumLines($companyName, $secondColWidth); $heightNeeded = $this->getNumLines($companyName, $secondColWidth);
$lineHeight = 6.40997; //Size of a single line of text. If the company name is more, multiply this by the number of lines it needs. $lineHeight = 6.40997; //Size of a single line of text. If the company name is more, multiply this by the number of lines it needs.
$this->MultiCell($firstColWidth, $lineHeight*$heightNeeded, "QUOTATION TO:", 'LTR', 'L', 0, 0); $this->MultiCell($firstColWidth, $lineHeight*$heightNeeded, "QUOTATION TO:", 'LTR', 'L', 0, 0);
$this->MultiCell($secondColWidth, $lineHeight*$heightNeeded, $companyName, 'LTR', 'L', 0, 0); $this->MultiCell($secondColWidth, $lineHeight*$heightNeeded, $companyName, 'LTR', 'L', 0, 0);
$this->MultiCell($thirdColWidth, $lineHeight*$heightNeeded, "FROM:", 'LT', 'L', 0, 0); $this->MultiCell($thirdColWidth, $lineHeight*$heightNeeded, "FROM:", 'LT', 'L', 0, 0);
$this->MultiCell($fourthColWidth, $lineHeight*$heightNeeded, "<a href=\"mailto:$fromEmail\">$fromName</a>", 'TR', 'L', 0, 1, null,null, true,0,true); //Start a new line after this. $this->MultiCell($fourthColWidth, $lineHeight*$heightNeeded, "<a href=\"mailto:$fromEmail\">$fromName</a>", 'TR', 'L', 0, 1, null,null, true,0,true); //Start a new line after this.
$this->MultiCell($firstColWidth, 0, "EMAIL TO:", 'LR', 'L', 0, 0); $this->MultiCell($firstColWidth, 0, "EMAIL TO:", 'LR', 'L', 0, 0);
$this->MultiCell($secondColWidth, 0, "<a href=\"mailto:$emailTo\">$emailTo</a>", 'LR','L', 0, 0, null, null, true, 0, true); $this->MultiCell($secondColWidth, 0, "<a href=\"mailto:$emailTo\">$emailTo</a>", 'LR','L', 0, 0, null, null, true, 0, true);
$this->MultiCell($thirdColWidth, 0, "CMC REF#:", 'L', 'L', 0, 0); $this->MultiCell($thirdColWidth, 0, "CMC REF#:", 'L', 'L', 0, 0);
$this->MultiCell($fourthColWidth, 0, $enquiryNumber, 'R', 'L', 0, 1); //Start a new line after thi $this->MultiCell($fourthColWidth, 0, $enquiryNumber, 'R', 'L', 0, 1); //Start a new line after thi
$this->MultiCell($firstColWidth, 0, "ATTENTION:", 'LRB', 'L', 0, 0); $this->MultiCell($firstColWidth, 0, "ATTENTION:", 'LRB', 'L', 0, 0);
$this->MultiCell($secondColWidth, 0, $attention, 'LRB', 'L', 0, 0); $this->MultiCell($secondColWidth, 0, $attention, 'LRB', 'L', 0, 0);
$this->MultiCell($thirdColWidth, 0, "PAGE: ", 'LB', 'L', 0, 0); $this->MultiCell($thirdColWidth, 0, "PAGE: ", 'LB', 'L', 0, 0);
$this->MultiCell($fourthColWidth, 0, "$pageNo of {nb}", 'BR', 'L', 0, 1); $this->MultiCell($fourthColWidth, 0, "$pageNo of {nb}", 'BR', 'L', 0, 1);
$todayPHPdate = strtotime($issuedate); $todayPHPdate = strtotime($issuedate);
$todaysDateString = date('l, j F Y', $todayPHPdate); $todaysDateString = date('l, j F Y', $todayPHPdate);
$this->MultiCell($firstColWidth + $secondColWidth, 0, "DATE: $todaysDateString", 'LRB', 'L', 0, 0); $this->MultiCell($firstColWidth + $secondColWidth, 0, "DATE: $todaysDateString", 'LRB', 'L', 0, 0);
$this->MultiCell($thirdColWidth, 0, "YOUR REF: ", 'LB', 'L', 0, 0); $this->MultiCell($thirdColWidth, 0, "YOUR REF: ", 'LB', 'L', 0, 0);
$this->MultiCell($fourthColWidth, 0, $your_reference, 'BR', 'L', 0, 1); $this->MultiCell($fourthColWidth, 0, $your_reference, 'BR', 'L', 0, 1);
$this->SetFontSize(6); $this->SetFontSize(6);
//Kinda lame that I cant seem to wrap this text nicer. But Whatever. //Kinda lame that I cant seem to wrap this text nicer. But Whatever.
$this->MultiCell(0, 0, 'The information in this document is confidential and may be privileged. If you are not the indended recipient then access, disclosure, copying or other dissemination of the contents of t his message is unauthorised and may be unlawful. Please inform the sender immediately if you are not the intended addressee.', $this->MultiCell(0, 0, 'The information in this document is confidential and may be privileged. If you are not the indended recipient then access, disclosure, copying or other dissemination of the contents of t his message is unauthorised and may be unlawful. Please inform the sender immediately if you are not the intended addressee.',
'', 'L' '', 'L'
); );
} }
function continuedHeader($cmcRef) { function continuedHeader($cmcRef) {
$this->Image(K_PATH_IMAGES.'cmclogosmall.jpg', 10, 10, 15, 13.6, null, 'http://www.cmctechnologies.com.au', null, false, null, 'L'); $this->Image(K_PATH_IMAGES.'cmclogosmall.jpg', 10, 10, 15, 13.6, null, 'http://www.cmctechnologies.com.au', null, false, null, 'L');
$this->SetFontSize(10); $this->SetFontSize(10);
$pageNo = $this->PageNoFormatted(); $pageNo = $this->PageNoFormatted();
$currentX = $this->GetX(); $currentX = $this->GetX();
$this->SetX($currentX + 40); $this->SetX($currentX + 40);
$this->MultiCell(100, 13.6, $cmcRef." CONTINUES", '','C', 0, 0); $this->MultiCell(100, 13.6, $cmcRef." CONTINUES", '','C', 0, 0);
$this->MultiCell(0,13.6, "PAGE $pageNo OF {nb}", '', 'R'); $this->MultiCell(0,13.6, "PAGE $pageNo OF {nb}", '', 'R');
//$this->MultiCell($w, $h, $txt, $border, $align, $fill, $ln, $x, $y, $reseth, $stretch, $ishtml) //$this->MultiCell($w, $h, $txt, $border, $align, $fill, $ln, $x, $y, $reseth, $stretch, $ishtml)
//$this->Image($file, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi) //$this->Image($file, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi)
} }
@ -171,106 +173,113 @@ class XTCPDF extends TCPDF {
* @param <type> $docType * @param <type> $docType
* @param <type> $commercialDetails * @param <type> $commercialDetails
*/ */
function calculateProductPage($currency,$gst, $products ,$docType, $commercialDetails) { function calculateProductPage($currency,$gst, $products, $commercialDetails) {
$itemColwidth = 12; $itemColwidth = 12;
$qtyColwidth = 10; $qtyColwidth = 10;
$descColwidth = 120; $descColwidth = 120;
$unitpriceColwidth = 25; $unitpriceColwidth = 25;
$totalPricColwidth = -10; $totalPricColwidth = -10;
//$availableHeight = 253; //$availableHeight = 253;
$availableHeight = 230; $availableHeight = 230;
$heightLeft = $availableHeight; //height left on this particular page. $heightLeft = $availableHeight; //height left on this particular page.
$pagesRequired = 1; $pagesRequired = 1;
foreach ($products as $product) { foreach ($products as $product) {
$this->startTransaction(); $this->startTransaction();
$fullDesc = "<b>".$principlesList[$product[$docType]['principle_id']]."</b><br>"."<b>".$product[$docType]['title'].'</b><br>'.$product[$docType]['description']; $fullDesc = "<b>".$product['title'].'</b><br>'.$product['description'];
$this->MultiCell($descColwidth, 0, $fullDesc, 1, "L", 0, 0, null, null, true, 0, true);
$lasth = $this->getLastH(); //$this->MultiCell($descColwidth, 0, $fullDesc, 1, "L", 0, 0, null, null, true, 0, true, true, 0, 'T', false);
$this->rollbackTransaction($this); // die($fullDesc);
//echo "Last height needed for item: ".$product[$docType]['item_number']." was: ".$lasth."<br>";
//$this->MultiCell($descColwidth, 0, $fullDesc, 1, 'L', false, 1, 0, 0, true, 0, true, true);
$lasth = $this->getLastH();
$this->rollbackTransaction($this);
//echo "Last height needed for item: ".$product[$docType]['item_number']." was: ".$lasth."<br>";
//echo $product[$docType]['id']." needs ".$lasth." has $heightLeft left<br>";
$itemno = $product['item_number'];
if($heightLeft - $lasth <= 0) {
// echo "<br>OUT OF SPACE ON PAGE $pagesRequired making a new one<br>";
$pagesRequired++;
$heightLeft = $availableHeight; //Start checking the next page;
// echo "<br>remaining height on new one = ".$heightLeft."<br>";
$heightLeft -= $lasth;
$itemno = $product['item_number'];
// echo "<br>Using $lasth for $itemno so now have $heightLeft left<br>";
$pageProducts[$pagesRequired][] = $product['id'];
}
else {
$heightLeft -= $lasth;
$pageProducts[$pagesRequired][] = $product['id'];
}
}
//echo $product[$docType]['id']." needs ".$lasth." has $heightLeft left<br>";
$itemno = $product[$docType]['item_number'];
if($heightLeft - $lasth <= 0) {
// echo "<br>OUT OF SPACE ON PAGE $pagesRequired making a new one<br>";
$pagesRequired++;
$heightLeft = $availableHeight; //Start checking the next page;
// echo "<br>remaining height on new one = ".$heightLeft."<br>";
$heightLeft -= $lasth;
$itemno = $product[$docType]['item_number'];
// echo "<br>Using $lasth for $itemno so now have $heightLeft left<br>";
$pageProducts[$pagesRequired][] = $product[$docType]['id'];
}
else {
$heightLeft -= $lasth;
$pageProducts[$pagesRequired][] = $product[$docType]['id'];
}
}
/* Reached the last product in this Product Table.
* Need to see if we still have enough room to print the totals, if not will need to put the last item on a new page.
*/
/* Reached the last product in this Product Table. $this->startTransaction();
* Need to see if we still have enough room to print the totals, if not will need to put the last item on a new page. $subtotal = 0;
*/
//$totalsHeight = $this->totals($currency, $subtotal, 1);
$commDetailsHeight = $this->commercialComments($commercialDetails);
echo "WOTOTOTO1111T";
$this->rollbackTransaction($this);
//echo "Currently have $heightLeft Comm details height is ".$commDetailsHeight." totals height is: ".$totalsHeight."<br>";
$heightLeft -= $totalsHeight;
if($heightLeft <= 0) {
// echo "<br>Need a new page for last item and totals";
//array_pop($pageProducts[$pagesRequired]);
$pagesRequired++;
$heightLeft = $availableHeight;
$heightLeft -= $totalsHeight;
//$pageProducts[$pagesRequired][] = $product[$docType]['id'];
}
echo "Height left before commDetails is:".$heightLeft;
echo "Comm Details Height is:".$commDetailsHeight;
$heightLeft -= $commDetailsHeight;
echo "Heigh Left is now:".$heightLeft;
if($heightLeft <= 0) {
$pagesRequired++;
}
$this->startTransaction(); debug($pageProducts);
$subtotal = 0; print_r($pageProducts);
$totalsHeight = $this->totals($currency, $subtotal, 1); return $pageProducts;
$commDetailsHeight = $this->commercialComments($commercialDetails);
$this->rollbackTransaction($this);
//echo "Currently have $heightLeft Comm details height is ".$commDetailsHeight." totals height is: ".$totalsHeight."<br>";
$heightLeft -= $totalsHeight;
if($heightLeft <= 0) {
// echo "<br>Need a new page for last item and totals";
//array_pop($pageProducts[$pagesRequired]);
$pagesRequired++;
$heightLeft = $availableHeight;
$heightLeft -= $totalsHeight;
//$pageProducts[$pagesRequired][] = $product[$docType]['id'];
}
echo "Height left before commDetails is:".$heightLeft;
echo "Comm Details Height is:".$commDetailsHeight;
$heightLeft -= $commDetailsHeight;
echo "Heigh Left is now:".$heightLeft;
if($heightLeft <= 0) {
$pagesRequired++;
}
debug($pageProducts);
return $pageProducts;
} }
/** /**
* *
* @param Map $principles - list of principles. A hack so we can show a products principle name on it, without rewriting * @param Map $principles - list of principles. A hack so we can show a products principle name on it, without rewriting
* lots of code. * lots of code.
* @param <type> $currency * @param <type> $currency
* @param int $gst - 0 or 1 if GST is applicable. * @param int $gst - 0 or 1 if GST is applicable.
* @param <type> $products * @param <type> $products
@ -280,175 +289,174 @@ class XTCPDF extends TCPDF {
function productPage($currency,$gst, $products ,$docType, $commercialDetails, $pageProducts) { function productPage($currency,$gst, $products ,$docType, $commercialDetails, $pageProducts) {
$this->SetFontSize(10); $this->SetFontSize(10);
$lineHeight = 5; //Size of a single line of text. If the company name is more, $lineHeight = 5; //Size of a single line of text. If the company name is more,
// multiply this by the number of lines it needs // multiply this by the number of lines it needs
$itemColwidth = 12; $itemColwidth = 12;
$qtyColwidth = 10; $qtyColwidth = 10;
$descColwidth = 120; $descColwidth = 120;
$unitpriceColwidth = 25; $unitpriceColwidth = 25;
$totalPricColwidth = -10; $totalPricColwidth = -10;
$this->SetFillColor(240); $this->SetFillColor(240);
$subTotal = 0; $subTotal = 0;
$options = 0; //Toggled to 1 when we encounter an Optional product. Stops the totals being printed. $options = 0; //Toggled to 1 when we encounter an Optional product. Stops the totals being printed.
print_r($principlesList[0]); foreach ($pageProducts as $page) {
foreach ($pageProducts as $page) {
$this->AddPage(); $this->AddPage();
//Draw Header Rows //Draw Header Rows
$this->setFontSize(12); $this->setFontSize(12);
$pageNo = $this->PageNoFormatted(); $pageNo = $this->PageNoFormatted();
$this->MultiCell(0, 0, "PAGE $pageNo OF {nb}", 0, "R", 0, 1); $this->MultiCell(0, 0, "PAGE $pageNo OF {nb}", 0, "R", 0, 1);
$this->MultiCell(0, 0, "PRICING & SPECIFICATIONS", 0, "C", 0, 1); $this->MultiCell(0, 0, "PRICING & SPECIFICATIONS", 0, "C", 0, 1);
$this->setFontSize(10); $this->setFontSize(10);
$this->MultiCell($itemColwidth, 0, "ITEM NO.", 1, "C", 1, 0); $this->MultiCell($itemColwidth, 0, "ITEM NO.", 1, "C", 1, 0);
$heightNeeded = $this->getLastH(); $heightNeeded = $this->getLastH();
/** /**
* @todo this seems like a cleaner way of doing it than I did in the detailsBox(). Revise at some point * @todo this seems like a cleaner way of doing it than I did in the detailsBox(). Revise at some point
*/ */
$this->MultiCell($qtyColwidth, $heightNeeded, "QTY", 1, "C", 1, 0); $this->MultiCell($qtyColwidth, $heightNeeded, "QTY", 1, "C", 1, 0);
$this->MultiCell($descColwidth, $heightNeeded, "DESCRIPTION", 1, "C", 1, 0); $this->MultiCell($descColwidth, $heightNeeded, "DESCRIPTION", 1, "C", 1, 0);
$this->MultiCell($unitpriceColwidth, $heightNeeded, "UNIT\nPRICE", 1, "C", 1, 0); $this->MultiCell($unitpriceColwidth, $heightNeeded, "UNIT\nPRICE", 1, "C", 1, 0);
$this->MultiCell($totalPricColwidth, $heightNeeded, "TOTAL\nPRICE", 1, "C", 1, 1); $this->MultiCell($totalPricColwidth, $heightNeeded, "TOTAL\nPRICE", 1, "C", 1, 1);
//Header Line 2 //Header Line 2
$this->MultiCell($itemColwidth, 0, "", 1, "C", 1, 0); $this->MultiCell($itemColwidth, 0, "", 1, "C", 1, 0);
$heightNeeded = $this->getLastH(); $heightNeeded = $this->getLastH();
$this->MultiCell($qtyColwidth, $heightNeeded, "", 1, "C", 1, 0); $this->MultiCell($qtyColwidth, $heightNeeded, "", 1, "C", 1, 0);
$this->MultiCell($descColwidth, $heightNeeded, "", 1, "C", 1, 0); //Principle Name used to go here. $this->MultiCell($descColwidth, $heightNeeded, "", 1, "C", 1, 0); //Principle Name used to go here.
$this->MultiCell($unitpriceColwidth, $heightNeeded, $currency['iso4217'], 1, "C", 1, 0); $this->MultiCell($unitpriceColwidth, $heightNeeded, $currency['iso4217'], 1, "C", 1, 0);
$this->MultiCell($totalPricColwidth, $heightNeeded, $currency['iso4217'], 1, "C", 1, 1); $this->MultiCell($totalPricColwidth, $heightNeeded, $currency['iso4217'], 1, "C", 1, 1);
// echo "<h2>$pageNo</h2>"; // echo "<h2>$pageNo</h2>";
// print_r($page); // print_r($page);
//Start Printing Product cells, until we run out of room. Then continue on the next page //Start Printing Product cells, until we run out of room. Then continue on the next page
foreach($page as $productID) { foreach($page as $productID) {
$product = array_shift($products); $product = array_shift($products);
if($product['Principle']['id'] != null) { if($product['Principle']['id'] != null) {
$fullDesc = "<b>".$product['Principle']['name']."</b><br>"."<b>".$product[$docType]['title'].'</b><br>'.$product[$docType]['description']; $fullDesc = "<b>".$product['Principle']['name']."</b><br>"."<b>".$product[$docType]['title'].'</b><br>'.$product[$docType]['description'];
} }
else { else {
$fullDesc = "<b>".$product[$docType]['title'].'</b><br>'.$product[$docType]['description']; $fullDesc = "<b>".$product[$docType]['title'].'</b><br>'.$product[$docType]['description'];
} }
if($product[$docType]['option'] == 1) { if($product[$docType]['option'] == 1) {
$options = 1; $options = 1;
} }
$currentX = $this->GetX(); $currentX = $this->GetX();
$currentY = $this->GetY(); $currentY = $this->GetY();
$this->SetX($currentX + $itemColwidth + $qtyColwidth); $this->SetX($currentX + $itemColwidth + $qtyColwidth);
$this->MultiCell($descColwidth, 0, $fullDesc, 1, "L", 0, 0, null, null, true, 0, true); $this->MultiCell($descColwidth, 0, $fullDesc, 1, "L", 0, 0, null, null, true, 0, true);
$endOfDesc = $this->GetX(); $endOfDesc = $this->GetX();
$heightNeeded = $this->getLastH(); $heightNeeded = $this->getLastH();
$this->SetX($currentX); $this->SetX($currentX);
$this->MultiCell($itemColwidth, $heightNeeded, number_format($product[$docType]['item_number'], 1, '.', ''), 1, "C", 0, 0); $this->MultiCell($itemColwidth, $heightNeeded, number_format($product[$docType]['item_number'], 1, '.', ''), 1, "C", 0, 0);
$this->MultiCell($qtyColwidth, $heightNeeded, $product[$docType]['quantity'], 1, "C", 0, 0); $this->MultiCell($qtyColwidth, $heightNeeded, $product[$docType]['quantity'], 1, "C", 0, 0);
$this->SetX($endOfDesc); $this->SetX($endOfDesc);
if($product[$docType]['discount_percent'] != 0) { if($product[$docType]['discount_percent'] != 0) {
$percentage = number_format($product[$docType]['discount_percent'], 2);
$unitPriceString = $this->formatCurrency($currency['symbol'], $product[$docType]['unit_price']);
$unitPriceString .= "<br>less ".$percentage."% discount<br>(-"
.$this->formatCurrency($currency['symbol'], $product[$docType]['discount_amount_each']).")<br>=<br>";
$unitPriceString .= $this->formatCurrency($currency['symbol'], $product[$docType]['net_price_each']);
$totalPriceString = $this->formatCurrency($currency['symbol'], $product[$docType]['gross_price']); $percentage = number_format($product[$docType]['discount_percent'], 2);
$totalPriceString .= "<br>less ".$percentage."% discount<br>(-"
.$this->formatCurrency($currency['symbol'], $product[$docType]['total_discount_amount']).")<br>=<br>";
$totalPriceString .= $this->formatCurrency($currency['symbol'], $product[$docType]['net_price']);
} $unitPriceString = $this->formatCurrency($currency['symbol'], $product[$docType]['unit_price']);
else { $unitPriceString .= "<br>less ".$percentage."% discount<br>(-"
$unitPriceString = $this->formatCurrency($currency['symbol'], $product[$docType]['unit_price']); .$this->formatCurrency($currency['symbol'], $product[$docType]['discount_amount_each']).")<br>=<br>";
$totalPriceString = $this->formatCurrency($currency['symbol'], $product[$docType]['net_price']); $unitPriceString .= $this->formatCurrency($currency['symbol'], $product[$docType]['net_price_each']);
} $totalPriceString = $this->formatCurrency($currency['symbol'], $product[$docType]['gross_price']);
$totalPriceString .= "<br>less ".$percentage."% discount<br>(-"
.$this->formatCurrency($currency['symbol'], $product[$docType]['total_discount_amount']).")<br>=<br>";
$totalPriceString .= $this->formatCurrency($currency['symbol'], $product[$docType]['net_price']);
//Unit Price Column }
$this->MultiCell($unitpriceColwidth, $heightNeeded, $unitPriceString , 1, "C", 0, 0, null, null, true, 0, true); else {
$unitPriceString = $this->formatCurrency($currency['symbol'], $product[$docType]['unit_price']);
$totalPriceString = $this->formatCurrency($currency['symbol'], $product[$docType]['net_price']);
}
//Unit Price Column
$this->MultiCell($unitpriceColwidth, $heightNeeded, $unitPriceString , 1, "C", 0, 0, null, null, true, 0, true);
//Net Price Column //Net Price Column
$this->MultiCell($totalPricColwidth, $heightNeeded, $totalPriceString, 1, "C", 0, 1, null, null, true, 0, true); $this->MultiCell($totalPricColwidth, $heightNeeded, $totalPriceString, 1, "C", 0, 1, null, null, true, 0, true);
$subTotal += $product[$docType]['net_price']; $subTotal += $product[$docType]['net_price'];
$lastY = $this->GetY(); $lastY = $this->GetY();
$lastX = $this->GetX(); $lastX = $this->GetX();
//echo $product[$docType]['item_number']." Last X is $lastX, Last Y is $lastY <br>"; //echo $product[$docType]['item_number']." Last X is $lastX, Last Y is $lastY <br>";
} }
//debug($products); //debug($products);
//End Page For //End Page For
} }
/** /**
* Call the commercial Comments. Need to have already figured out what page to do this on.. * Call the commercial Comments. Need to have already figured out what page to do this on..
* *
* * Passing a data structure in the following format. * * Passing a data structure in the following format.
* *
* $details = array( * $details = array(
* 'deliveryTime' => (String) eg. 2-3 * 'deliveryTime' => (String) eg. 2-3
* 'timeScale' => (String) eg. WORKING DAYS || WEEKS || MONTHS * 'timeScale' => (String) eg. WORKING DAYS || WEEKS || MONTHS
* 'paymentTerms => (String) eg. 100% PAYMENT WITH ORDER || NET 30 DAYS FOR APPROVED ACCOUNTS * 'paymentTerms => (String) eg. 100% PAYMENT WITH ORDER || NET 30 DAYS FOR APPROVED ACCOUNTS
* 'validFor' => (String) eg. 30 Days * 'validFor' => (String) eg. 30 Days
* 'deliveryPoint' => (String) eg. EX-CMC Technologies, NSW. || EX-SUPPLIER NAME * 'deliveryPoint' => (String) eg. EX-CMC Technologies, NSW. || EX-SUPPLIER NAME
* 'exchangeRate' => (String) eg. FIXED * 'exchangeRate' => (String) eg. FIXED
* 'customsDuty' => (String) eg. NIL || 5% * 'customsDuty' => (String) eg. NIL || 5%
* 'gst' => (String) eg. 10% EXTRA || Not Applicable for Export * 'gst' => (String) eg. 10% EXTRA || Not Applicable for Export
* 'salesEngineer' => (String) eg. Karl Cordes || Con Carpis || Kenan Fernandes etc * 'salesEngineer' => (String) eg. Karl Cordes || Con Carpis || Kenan Fernandes etc
* ); * );
* *
* *
*/ */
$this->totals($currency, $subTotal, $gst, $options); $this->totals($currency, $subTotal, $gst, $options);
$this->commercialComments($commercialDetails); $this->commercialComments($commercialDetails);
$this->AliasNbPages(); $this->AliasNbPages();
$this->lastPage(); $this->lastPage();
} }
@ -461,14 +469,14 @@ class XTCPDF extends TCPDF {
* @param $number * @param $number
*/ */
function formatCurrency($symbol, $number) { function formatCurrency($symbol, $number) {
list($int, $dec) = explode('.', $number); //Creates an Undefined Offset notice. Fix eventually. list($int, $dec) = explode('.', $number); //Creates an Undefined Offset notice. Fix eventually.
if($dec > 0) { if($dec > 0) {
return $symbol.number_format($number, 2, '.', ','); return $symbol.number_format($number, 2, '.', ',');
} }
else { else {
return $symbol.number_format($number, 0, '.', ','); return $symbol.number_format($number, 0, '.', ',');
} }
} }
@ -494,16 +502,16 @@ class XTCPDF extends TCPDF {
*/ */
function commercialComments($details) { function commercialComments($details) {
$totalHeight = 0; $totalHeight = 0;
$this->MultiCell(0, 0, "<b><u>Commercial Comments:</u></b>", 0, 'L', 0, 1, null, null, 1, null, true); //$this->MultiCell(0, 0, "<b><u>Commercial Comments:</u></b>", 0, 'L', 0, 1, null, null, 1, null, true);
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();
$validUntilDate = strtotime($details["dateIssued"]. ' + '.$details["validFor"].' days'); $validUntilDate = strtotime($details["dateIssued"]. ' + '.$details["validFor"].' days');
$niceValidUntilDate = strtoupper(date('l j F Y',$validUntilDate)); $niceValidUntilDate = strtoupper(date('l j F Y',$validUntilDate));
$listHtmlContents = <<<ENDHTMLCONTENTS $listHtmlContents = <<<ENDHTMLCONTENTS
<ol> <ol>
<li><b>DELIVERY</b> IS ESTIMATED AT {$details["deliveryTime"]} ({$details["deliveryPoint"]}) FROM RECEIPT OF YOUR TECHNICALLY AND COMMERCIALLY CLEAR ORDER.</li> <li><b>DELIVERY</b> IS ESTIMATED AT {$details["deliveryTime"]} ({$details["deliveryPoint"]}) FROM RECEIPT OF YOUR TECHNICALLY AND COMMERCIALLY CLEAR ORDER.</li>
<li><b>PAYMENT TERMS:</b> {$details["paymentTerms"]}.</li> <li><b>PAYMENT TERMS:</b> {$details["paymentTerms"]}.</li>
@ -518,18 +526,18 @@ ANY VARIATIONS ON ITEMS 5. TO 7. WILL BE TO YOUR ACCOUNT. THIS QUOTATION IS BASE
IS SUBJECT TO CHANGE IF QUANTITIES VARY. IS SUBJECT TO CHANGE IF QUANTITIES VARY.
<br> <br>
ENDHTMLCONTENTS; ENDHTMLCONTENTS;
//$commlines = $this->getNumLines($listHtmlContents); //$commlines = $this->getNumLines($listHtmlContents);
//echo "lines required for commercial comments: ".$commlines; //echo "lines required for commercial comments: ".$commlines;
$this->MultiCell(0, 0, $listHtmlContents, 0, 'L', 0, 1, null, null, 1, null, true); //$this->MultiCell(0, 0, $listHtmlContents, 0, 'L', 0, 1, null, null, 1, null, true);
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();
$this->MultiCell(0, 0, "Signed: ____________________________", 0, 'L'); //$this->MultiCell(0, 0, "Signed: ____________________________", 0, 'L');
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();
$this->MultiCell(0, 0, " ".$details["salesEngineer"], 0, 'L'); //$this->MultiCell(0, 0, " ".$details["salesEngineer"], 0, 'L');
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();
return $totalHeight; return $totalHeight;
} }
@ -537,86 +545,86 @@ ENDHTMLCONTENTS;
function totals($currency, $subTotal, $gst, $options) { function totals($currency, $subTotal, $gst, $options) {
$itemColwidth = 12; $itemColwidth = 12;
$qtyColwidth = 10; $qtyColwidth = 10;
$descColwidth = 120; $descColwidth = 120;
$unitpriceColwidth = 25; $unitpriceColwidth = 25;
$totalPricColwidth = -10; $totalPricColwidth = -10;
$totalHeight = 0; $totalHeight = 0;
// echo "desc col wdith : ".$descColwidth; // echo "desc col wdith : ".$descColwidth;
$this->MultiCell($itemColwidth, 6, "", 1, 'C', 0, 0); $this->MultiCell($itemColwidth, 6, "", 1, 'C', 0, 0);
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();
$this->MultiCell($qtyColwidth, 6, "", 1, 'C', 0, 0); $this->MultiCell($qtyColwidth, 6, "", 1, 'C', 0, 0);
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();
$this->MultiCell($descColwidth, 6, "SUB-TOTAL (EXCLUDING GST)", 1, 'L', 0, 0); $this->MultiCell($descColwidth, 6, "SUB-TOTAL (EXCLUDING GST)", 1, 'L', 0, 0);
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();
$this->MultiCell($unitpriceColwidth, 6, "", 1, 'C', 0, 0); $this->MultiCell($unitpriceColwidth, 6, "", 1, 'C', 0, 0);
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();
if($options == 1) { if($options == 1) {
$this->MultiCell($totalPricColwidth, 6, $currency['symbol']. "TBA", 1, 'C', 0, 1); $this->MultiCell($totalPricColwidth, 6, $currency['symbol']. "TBA", 1, 'C', 0, 1);
} }
else { else {
$this->MultiCell($totalPricColwidth, 6, $this->formatCurrency($currency['symbol'], $subTotal), 1, 'C', 0, 1); $this->MultiCell($totalPricColwidth, 6, $this->formatCurrency($currency['symbol'], $subTotal), 1, 'C', 0, 1);
} }
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();
$this->MultiCell($itemColwidth, 6, "", 1, 'C', 0, 0); $this->MultiCell($itemColwidth, 6, "", 1, 'C', 0, 0);
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();
$this->MultiCell($qtyColwidth, 6, "", 1, 'C', 0, 0); $this->MultiCell($qtyColwidth, 6, "", 1, 'C', 0, 0);
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();
$this->MultiCell($descColwidth, 6, "GST (10%)", 1, 'L', 0, 0); $this->MultiCell($descColwidth, 6, "GST (10%)", 1, 'L', 0, 0);
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();
$this->MultiCell($unitpriceColwidth, 6, "", 1, 'C', 0, 0); $this->MultiCell($unitpriceColwidth, 6, "", 1, 'C', 0, 0);
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();
if($options == 1) { if($options == 1) {
$this->MultiCell($totalPricColwidth, 6, $currency['symbol']. "TBA", 1, 'C', 0, 1); $this->MultiCell($totalPricColwidth, 6, $currency['symbol']. "TBA", 1, 'C', 0, 1);
} }
else { else {
if($gst == 1) { if($gst == 1) {
$gstAmount = 0.1*$subTotal; $gstAmount = 0.1*$subTotal;
$this->MultiCell($totalPricColwidth, 6, $this->formatCurrency($currency['symbol'], $gstAmount), 1 , 'C', 0, 1); $this->MultiCell($totalPricColwidth, 6, $this->formatCurrency($currency['symbol'], $gstAmount), 1 , 'C', 0, 1);
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();
} }
else { else {
$this->MultiCell($totalPricColwidth, 6, "N/A", 1 , 'C', 0, 1); $this->MultiCell($totalPricColwidth, 6, "N/A", 1 , 'C', 0, 1);
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();
} }
} }
$this->MultiCell($itemColwidth, 6, "", 1, 'C', 0, 0); $this->MultiCell($itemColwidth, 6, "", 1, 'C', 0, 0);
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();
$this->MultiCell($qtyColwidth, 6, "", 1, 'C', 0, 0); $this->MultiCell($qtyColwidth, 6, "", 1, 'C', 0, 0);
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();
$this->MultiCell($descColwidth, 6, "TOTAL PAYABLE", 1, 'L', 0, 0); $this->MultiCell($descColwidth, 6, "TOTAL PAYABLE", 1, 'L', 0, 0);
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();
$this->MultiCell($unitpriceColwidth, 6, "", 1, 'C', 0, 0); $this->MultiCell($unitpriceColwidth, 6, "", 1, 'C', 0, 0);
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();
if($options == 1) { if($options == 1) {
$this->MultiCell($totalPricColwidth, 6, $currency['symbol']. "TBA", 1, 'C', 0, 1); $this->MultiCell($totalPricColwidth, 6, $currency['symbol']. "TBA", 1, 'C', 0, 1);
} }
else { else {
if($gst == 1) { if($gst == 1) {
$totalPrice = $subTotal * 1.1; $totalPrice = $subTotal * 1.1;
} }
else { else {
$totalPrice = $subTotal; $totalPrice = $subTotal;
} }
$this->MultiCell($totalPricColwidth, 6, $this->formatCurrency($currency['symbol'], $totalPrice), 1, 'C', 0, 1); $this->MultiCell($totalPricColwidth, 6, $this->formatCurrency($currency['symbol'], $totalPrice), 1, 'C', 0, 1);
} }
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();
return $totalHeight; return $totalHeight;
} }

109
views/documents/pdf.ctp Executable file
View file

@ -0,0 +1,109 @@
<?php
App::import('Vendor','pdfdoc');
$pdfdoc = new PDFDOC();
$pdfdoc->SetPrintHeader(false);
$pdfdoc->SetPrintFooter(false);
$firstPageDone = false;
$companyName = $enquiry['Customer']['name'];
$emailTo = $enquiry['Contact']['email'];
$attention = $enquiry['Contact']['first_name'].' '.$enquiry['Contact']['last_name'];
$fromName = $enquiry['User']['first_name'].' '.$enquiry['User']['last_name'];
$fromEmail = $enquiry['User']['email'];
$enquiryNumber = $enquiry['Enquiry']['title'];
$your_reference = 'Enquiry '.$enquiry['Enquiry']['created'];
$issue_date = $document['Quote']['date_issued'];
$pdfdoc->docRef = $enquiryNumber;
foreach($document['DocPage'] as $page) {
$pdfdoc->AddPage();
$pdfdoc->Page1Header();
if($firstPageDone == false) {
$pdfdoc->DetailsBox($docTypeFullName, $companyName, $emailTo, $attention, $fromName,
$fromEmail, $enquiryNumber, $your_reference, $issue_date);
$firstPageDone = true;
}
$pdfdoc->pageContent($page['content']);
$pdfdoc->Page1Footer();
}
$LineItemTable = $this->element('line_items_table');
echo $LineItemTable;
$pdfdoc->SetHeaderMargin(30);
$pdfdoc->SetFooterMargin(30);
$pdfdoc->SetPrintHeader(true);
$pdfdoc->AddPage();
//$pdfdoc->MultiCell($w, $h, $txt, $border, $align, $fill, $ln, $x, $y, $reseth, $stretch, $ishtml)
$pdfdoc->MultiCell(0, 0, 'PRICING & SPECIFICATIONS', 0, 'C', false, 1, null, null, true, false, false);
$pdfdoc->pageContent($LineItemTable);
$pdfdoc->lastPage();
if($docType == 'quote') {
$commercialComments = '<div nobr="true">'.$document['Quote']['commercial_comments'].'</div>';
$pdfdoc->pageContent($commercialComments);
}
$output_dir = '/Users/karlcordes/Sites/quotenik/app/webroot/pdf/';
$debuglevel = Configure::read('debug');
if($debuglevel == 0) {
$output_dir = '/var/www/cakephp/app/webroot/pdf/';
}
if($document['Quote']['revision'] > 0) {
$filename = $enquiry['Enquiry']['title'].'rev'.$document['Quote']['revision'].'.pdf';
}
else {
$filename = $enquiry['Enquiry']['title'].'.pdf';
}
$pdfdoc->Output($output_dir.$filename, 'F');
echo "<br> Wrote: ".$output_dir.$filename;
//$tcpdf->Output('cmcquote.pdf', 'D');
App::import('Vendor', 'xfpdi');
//$newpdf = new concat_pdf();
$newpdf = new XFPDI();
$newpdf->SetMargins(2, 2);
$newpdf->setPrintHeader(false);
$newpdf->setPrintFooter(false);
$newpdf->setFiles(array($output_dir.$filename, $output_dir.'CMC_terms_and_conditions2006_A4.pdf'));
$newpdf->concat();
$newpdf->Output($output_dir.$filename, "F");
//$pdfdoc->Output($output_dir = '/Users/karlcordes/Sites/quotenik/app/webroot/pdf/'.'example_060.pdf', 'F');
?>

View file

@ -11,7 +11,7 @@ switch($docType) {
break; break;
case 'invoice': case 'invoice':
echo "INVOICE!!"; echo $this->element('document_invoice_view');
break; break;
case 'purchaseOrder': case 'purchaseOrder':
@ -34,7 +34,26 @@ switch($docType) {
</div> </div>
<div id="lineItemModal" title="Add Line Item"> <div id="addLineItemModal" title="Add Line Item">
</div> </div>
<span id="documentID"><?=$document['Document']['id']?></span> <div id="editLineItemModal" title="Edit Line Item">
</div>
<div id="QuoteDetails">
</div>
<div id="InvoiceDetails">
</div>
<span id="documentID" style="display:none;"><?=$document['Document']['id']?></span>
<?php // debug($currency);?>
<?php //debug($docType);?>
<?php //debug($enquiry);?>
<?php debug($document);?>

View file

@ -5,13 +5,28 @@
<div id="lineItemDetails"> <div id="lineItemDetails">
<? <?
echo $form->create('LineItem', array('default'=>false)); echo $form->create('LineItem', array('default'=>false));
echo $form->input('LineItem.id');
echo $form->input('LineItem.document_id', array('type'=>'hidden', 'value'=>$document['Document']['id'])); echo $form->input('LineItem.document_id', array('type'=>'hidden', 'value'=>$document['Document']['id']));
echo $form->input('LineItem.item_number'); echo $form->input('LineItem.item_number', array('class'=>'number_input'));
echo $form->input('LineItem.option'); echo $form->input('LineItem.option', array('type'=>'select','options'=>$yesNo));
echo $form->input('LineItem.quantity'); echo $form->input('LineItem.quantity', array('class'=>'number_input quickpricing'));
echo $form->input('LineItem.title'); echo $form->input('LineItem.title');
echo $form->input('LineItem.description'); echo $form->input('LineItem.description');
echo $form->input('LineItem.product_id', array('type'=>'hidden')); echo $form->input('LineItem.product_id', array('type'=>'hidden'));
?>
<div id="noCosting">
<?
echo $form->input('gross_unit_price', array('class'=>'number_input quickpricing'));
echo $form->input('discount_percent', array('class'=>'number_input quickpricing'));
echo $form->input('discount_amount_unit', array('class'=>'number_input quickpricing'));
echo $form->input('net_unit_price', array('class'=>'number_input quickpricing'));
echo $form->input('gross_price', array('class'=>'number_input quickpricing'));
echo $form->input('discount_amount_total', array('class'=>'number_input quickpricing'));
echo $form->input('net_price', array('class'=>'number_input quickpricing'));
?>
</div>
<?
echo $form->end(); echo $form->end();
?> ?>

View file

@ -0,0 +1,21 @@
<h2>Invoice: <?=$document['Invoice']['title']?></h2>
<?
echo $form->create('Document',array('type'=>'post','action'=>'edit', 'default'=>false));
echo $form->input('Document.id');
?>
<div class="docButtons">
<button id="addLineItem">Add Line Item</button>
</div>
<div id="flashMessage" class="message">
</div>
<span id="invoiceID" style="display: none;"><?=$document['Invoice']['id']?></span>
<? //debug($this->data);?>
<? //debug($enquiry);?>
<?php //debug($document);?>
<?php //debug($docType);?>

View file

@ -1,9 +1,13 @@
<h2>Quote: <?=$enquiry['Enquiry']['title']?> <? <h2>Quote: <?=$html->link($enquiry['Enquiry']['title'], array('controller'=>'enquiries','action'=>'view',$enquiry['Enquiry']['id']));?> <?
if($document['Quote']['revision'] > 0) { if($document['Quote']['revision'] > 0) {
echo "Revision {$document['Quote']['revision']}"; echo "Revision {$document['Quote']['revision']}";
} }
?> ?>
for
<?=$html->link($enquiry['Customer']['name'], array('controller'=>'customers','action'=>'view',$enquiry['Customer']['id']));?>
</h2> </h2>
<? <?
echo $form->create('Document',array('type'=>'post','action'=>'edit', 'default'=>false)); echo $form->create('Document',array('type'=>'post','action'=>'edit', 'default'=>false));
@ -13,6 +17,7 @@ echo $form->input('Document.id');
<div class="docButtons"> <div class="docButtons">
<button id="addPage">Add Content Page</button> <button id="addPage">Add Content Page</button>
<button id="addLineItem">Add Line Item</button> <button id="addLineItem">Add Line Item</button>
<button id="editQuoteDetails">View/Edit Quote Details</button>
</div> </div>
<div id="flashMessage" class="message"> <div id="flashMessage" class="message">
@ -33,6 +38,15 @@ echo $form->input('Document.id');
<div class="input submit"><button id="savePages">Save Pages</button></div> <div class="input submit"><button id="savePages">Save Pages</button></div>
<?=$form->end();?> <?=$form->end();?>
<span id="quoteID" style="display: none;"><?=$document['Quote']['id']?></span>
<div id="commCommentsInitialString" style="display:none;">
<u>Commercial Comments:</u><br />
<span style="font-size: small;">The prices quoted are subject to our Standard Terms and Conditions of Sale dated 1/7/06 that is attached and remain firm unless specifically varied in writing. The prices above are based on the following:</span>
<ol class="commList">
</ol>
<span style="font-size: small;">ANY VARIATIONS ON ITEMS 5. TO 7. WILL BE TO YOUR ACCOUNT. THIS QUOTATION IS BASED ON QUANTITIES STATED AND IS SUBJECT TO CHANGE IF QUANTITIES VARY.</span>
</div>
<? //debug($this->data);?> <? //debug($this->data);?>
<? //debug($enquiry);?> <? //debug($enquiry);?>

View file

@ -1,6 +1,6 @@
<?php echo $javascript->link('jquery.jeditable.mini'); ?> <?php echo $javascript->link('jquery.jeditable.mini'); ?>
<?=$javascript->link('ajax_pagination_enquiry'); ?> <? //$javascript->link('ajax_pagination_enquiry'); ?>
<?php echo $paginator->options(array('url'=>$this->passedArgs)); ?> <?php echo $paginator->options(array('url'=>$this->passedArgs)); ?>

View file

@ -0,0 +1,85 @@
<table border="1" cellpadding="2" cellspacing="0" >
<thead>
<tr bgcolor="#f2f2f2">
<th width="<?=$colWidths['item'];?>" align="center">ITEM<br />NO.</th>
<th width="<?=$colWidths['qty'];?>" align="center">QTY</th>
<th width="<?=$colWidths['desc'];?>" align="center">DESCRIPTION</th>
<th width="<?=$colWidths['unit'];?>" align="center">UNIT<br>PRICE</th>
<th width="<?=$colWidths['total'];?>" align="center">TOTAL<br>PRICE</th>
</tr>
<tr>
<th></th>
<th></th>
<th></th>
<th align="center"><?=$currencyCode?></th>
<th align="center"><?=$currencyCode?></th>
</tr>
</thead>
<tbody>
<?foreach($document['LineItem'] as $li):?>
<tr nobr="true">
<td width="<?=$colWidths['item'];?>" align="center">
<? if($li['option'] == 1) {
echo 'Option<br>';
}
?>
<?=$li['item_number'];?></td>
<td width="<?=$colWidths['qty'];?>" align="center"><?=$li['quantity'];?></td>
<td width="<?=$colWidths['desc'];?>"><?=$li['title'];?>
<?=$li['description'];?>
</td>
<td width="<?=$colWidths['unit'];?>" align="center">
<?=$number->currency($li['gross_unit_price'], $currencyCode);?>
<? if($li['discount_percent']):?>
<br>less<br><?=$li['discount_percent']?>%<br>
discount*<br>
(-<?=$number->currency($li['discount_amount_unit'], $currencyCode);?>)<br>
=<br>
<?=$number->currency($li['net_unit_price'], $currencyCode);?>
<?endif;?>
</td>
<td width="<?=$colWidths['total'];?>" align="center">
<?=$number->currency($li['gross_price'], $currencyCode);?>
<? if($li['discount_percent']):?>
<br>less<br><?=$li['discount_percent']?>%<br>
discount*<br>
(<?=$number->currency($li['discount_amount_total'], $currencyCode);?>)<br>
=<br>
<?=$number->currency($li['net_price'], $currencyCode);?>
<?endif;?>
</td>
</tr>
<?endforeach;?>
<tr>
<td width="<?=$colWidths['item'];?>"></td>
<td width="<?=$colWidths['qty'];?>"></td>
<td width="<?=$colWidths['desc'];?>"><?=$totalsDescText['subtotal']?></td>
<td width="<?=$colWidths['unit'];?>"></td>
<td width="<?=$colWidths['total'];?>" align="center"><?=$number->currency($totals['subtotal'], $currencyCode);?></td>
</tr>
<tr>
<td width="<?=$colWidths['item'];?>"></td>
<td width="<?=$colWidths['qty'];?>"></td>
<td width="<?=$colWidths['desc'];?>"><?=$totalsDescText['gst'];?></td>
<td width="<?=$colWidths['unit'];?>"></td>
<td width="<?=$colWidths['total'];?>" align="center"><?
if($gst ==1) {
echo $number->currency($totals['gst'], $currencyCode);
}
else {
echo 'N/A';
}?>
</td>
</tr>
<tr>
<td width="<?=$colWidths['item'];?>"></td>
<td width="<?=$colWidths['qty'];?>"></td>
<td width="<?=$colWidths['desc'];?>"><?=$totalsDescText['total'];?></td>
<td width="<?=$colWidths['unit'];?>" align="center"><?=$currencyCode?></td>
<td width="<?=$colWidths['total'];?>" align="center"><?=$number->currency($totals['total'], $currencyCode);?></td>
</tr>
</tbody>
</table>

View file

@ -26,7 +26,7 @@
<td><?php echo $time->nice($quote['Quote']['created']);?></td> <td><?php echo $time->nice($quote['Quote']['created']);?></td>
<td class="actions"> <td class="actions">
<?php echo $html->link(__('View', true), array('controller'=> 'quotes', 'action'=>'view', $quote['Quote']['id'])); ?> <?php echo $html->link(__('View', true), array('controller'=> 'documents', 'action'=>'view', $quote['Quote']['document_id'])); ?>
<?php echo $html->link(__('Revise', true), array('controller'=>'quotes', 'action'=>'revise', $quote['Quote']['id'])); ?> <?php echo $html->link(__('Revise', true), array('controller'=>'quotes', 'action'=>'revise', $quote['Quote']['id'])); ?>

View file

@ -1,8 +1,8 @@
<div id="ajaxLoad" style="display:none;"><?php echo $html->image('ajax-loader.gif'); ?></div> <div id="ajaxLoad" style="display:none;"><?php echo $html->image('ajax-loader.gif'); ?></div>
<div id="enquiryTable">
<div class="enquiriesindex">
<h2><?php __('Master Enquiry Register');?></h2>
<div id="enquiryTable">
<h2><?php __('Master Enquiry Register');?></h2>
<div class="enquiriesindex">
<? echo $this->element('enquiry_table', $enquiries, $status_list); ?> <? echo $this->element('enquiry_table', $enquiries, $status_list); ?>
</div> </div>
</div> </div>

View file

@ -123,7 +123,14 @@ $class = ' class="altrow"';?>
*/?> */?>
<div class="related"> <div class="related">
<h3><?php __($number_of_quotes.' Quotes in this Enquiry');?></h3> <h3><?php if($enquiry['Enquiry']['quote_count'] > 1) {
echo $enquiry['Enquiry']['quote_count'].' Quotes for this Enquiry';
}
else {
echo $enquiry['Enquiry']['quote_count'].' Quote for this Enquiry';
}?>
</h3>
<?php echo $this->element('quote_table', $quotes); ?> <?php echo $this->element('quote_table', $quotes); ?>
</div> </div>
@ -310,5 +317,5 @@ $class = ' class="altrow"';?>
</div> </div>
<?php // debug($enquiry);?>
<?php debug($emails); ?> <?php //debug($emails); ?>

View file

View file

View file

@ -1,8 +1,8 @@
<script type="text/javascript"> <script type="text/javascript">
$(function() { $(function() {
$('button').button(); $('button').button();
}); });
</script> </script>
@ -13,7 +13,7 @@ $(function() {
<th>ITEM<br>NO.</th> <th>ITEM<br>NO.</th>
<th>QTY</th> <th>QTY</th>
<th>DESCRIPTION</th> <th>DESCRIPTION</th>
<th>UNIT<br.PRICE</th> <th>UNIT<br>PRICE</th>
<th>TOTAL<br>PRICE</th> <th>TOTAL<br>PRICE</th>
<th>ACTIONS</th> <th>ACTIONS</th>
</tr> </tr>
@ -21,30 +21,76 @@ $(function() {
<th></th> <th></th>
<th></th> <th></th>
<th></th> <th></th>
<th><?=$currencies[$document['Quote']['currency_id']]?></th> <th><?=$currencyCode?></th>
<th><?=$currencies[$document['Quote']['currency_id']]?></th> <th><?=$currencyCode?></th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?foreach($document['LineItem'] as $li):?> <?foreach($document['LineItem'] as $li):?>
<tr> <tr class="lineItem">
<td><?=$li['item_number'];?></td> <td>
<? if($li['option'] == 1) {
echo 'Option<br>';
}
?>
<?=$li['item_number'];?></td>
<td><?=$li['quantity'];?></td> <td><?=$li['quantity'];?></td>
<td class="description"><?=$li['title'];?> <td class="description"><?=$li['title'];?>
<?=$li['description'];?> <?=$li['description'];?>
</td> </td>
<td> <td class="price">
<?=$li['unit_price'];?>
<?=$number->currency($li['gross_unit_price'], $currencyCode);?>
<? if($li['discount_percent']):?>
<br>less<br><?=$li['discount_percent']?>%<br>
discount<br>
(-<?=$number->currency($li['discount_amount_unit'], $currencyCode);?>)<br>
=<br>
<?=$number->currency($li['net_unit_price'], $currencyCode);?>
<?endif;?>
</td> </td>
<td> <td class="price">
<?=$li['gross_price'];?> <?=$number->currency($li['gross_price'], $currencyCode);?>
<? if($li['discount_percent']):?>
<br>less<br><?=$li['discount_percent']?>%<br>
discount<br>
<?=$number->currency($li['discount_amount_total'], $currencyCode);?>)<br>
=<br>
<?=$number->currency($li['net_price'], $currencyCode);?>
<?endif;?>
</td> </td>
<td> <td id="<?=$li['id'];?>">
<button class="editLineItem">Edit</button><br> <button class="editLineItem">Edit</button><br>
<button class="removeLineItem">Remove</button> <button class="removeLineItem">Remove</button>
</td> </td>
</tr> </tr>
<?endforeach;?> <?endforeach;?>
</tbody> </tbody>
</table> <tfoot>
<tr>
<td></td>
<td></td>
<td class="leftAlign">SUB-TOTAL (Excluding GST)</td>
<td></td>
<td><?=$number->currency($totals['subtotal'], $currencyCode);?></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td class="leftAlign">GST (10%)</td>
<td></td>
<td><?=$number->currency($totals['gst'], $currencyCode);?></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td class="leftAlign">TOTAL PAYABLE (INCLUDING GST)</td>
<td></td>
<td><?=$number->currency($totals['total'], $currencyCode);?></td>
<td></td>
</tr>
</tfoot>
</table>

View file

@ -66,9 +66,10 @@
<div class="related"> <div class="related">
<h3><?php __('Related Enquiries');?></h3> <h3><?php __('Related Enquiries');?></h3>
<?php if (!empty($principle['Enquiry'])):?>
<div id="enquiryTable">
<? echo $this->element('enquiry_table', $enquiries); ?> <? echo $this->element('enquiry_table', $enquiries); ?>
<?php endif; ?> </div>
<div class="actions"> <div class="actions">
<ul> <ul>
@ -117,8 +118,8 @@
</div> </div>
</div> </div>
<? echo $javascript->link('add_user'); ?> <? //echo $javascript->link('add_user'); ?>
<div id="addUserDiv"> <div id="addUserDiv" style="display: none;">
<?php echo $form->create('User');?> <?php echo $form->create('User');?>
@ -141,4 +142,4 @@
</div> </div>
<?php debug($principleContacts); ?> <?php debug($principle); ?>

View file

View file

@ -1,34 +1,26 @@
<div class="quotes form"> <script type="text/javascript">
<?php echo $form->create('Quote');?> $(function() {
<fieldset> $("button").button();
<legend><?php __('Edit Quote');?></legend> });
<?php
echo $form->input('id'); </script>
echo $form->input('enquiry_id'); <?php
echo $form->input('currency_id'); echo $form->create('Quote',array('default'=>false));
echo $form->input('revision');
echo $form->input('delivery_time'); echo $form->input('id');
echo $form->input('payment_terms'); echo $form->input('enquiry_id', array('type'=>'hidden'));
echo $form->input('days_valid'); echo $form->input('currency_id');
echo $form->input('date_issued'); echo $form->input('revision', array('type'=>'hidden'));
echo $form->input('valid_until'); echo $form->input('delivery_time');
echo $form->input('delivery_point'); echo $form->input('payment_terms');
echo $form->input('exchange_rate'); echo $form->input('days_valid');
echo $form->input('customs_duty'); echo $form->input('date_issued');
echo $form->input('document_id'); echo $form->input('valid_until');
?> echo $form->input('delivery_point');
</fieldset> echo $form->input('exchange_rate');
<?php echo $form->end('Submit');?> echo $form->input('customs_duty');
</div> echo $form->input('document_id',array('type'=>'hidden'));
<div class="actions"> echo $form->input('commercial_comments', array('between'=>'<button class="generateCommercialComments">(re)Generate Commercial Comments</button>'));
<ul>
<li><?php echo $html->link(__('Delete', true), array('action' => 'delete', $form->value('Quote.id')), null, sprintf(__('Are you sure you want to delete # %s?', true), $form->value('Quote.id'))); ?></li> echo $form->end();
<li><?php echo $html->link(__('List Quotes', true), array('action' => 'index'));?></li> ?>
<li><?php echo $html->link(__('List Enquiries', true), array('controller' => 'enquiries', 'action' => 'index')); ?> </li>
<li><?php echo $html->link(__('New Enquiry', true), array('controller' => 'enquiries', 'action' => 'add')); ?> </li>
<li><?php echo $html->link(__('List Currencies', true), array('controller' => 'currencies', 'action' => 'index')); ?> </li>
<li><?php echo $html->link(__('New Currency', true), array('controller' => 'currencies', 'action' => 'add')); ?> </li>
<li><?php echo $html->link(__('List Documents', true), array('controller' => 'documents', 'action' => 'index')); ?> </li>
<li><?php echo $html->link(__('New Document', true), array('controller' => 'documents', 'action' => 'add')); ?> </li>
</ul>
</div>

View file

@ -56,7 +56,7 @@ foreach ($quote['QuotePage'] as $page) {
} }
$tcpdf->DetailsBox($enquiry['Customer']['name'], $enquiry['Contact']['email'], $enquiry['Contact']['first_name'].' '.$enquiry['Contact']['last_name'], $tcpdf->DetailsBox($docTypeFullName, $enquiry['Customer']['name'], $enquiry['Contact']['email'], $enquiry['Contact']['first_name'].' '.$enquiry['Contact']['last_name'],
$enquiry['User']['first_name'].' '.$enquiry['User']['last_name'], $enquiry['User']['email'], $cmcRef, $enquiry['User']['first_name'].' '.$enquiry['User']['last_name'], $enquiry['User']['email'], $cmcRef,
$enquiry['Enquiry']['customer_reference'], $quote['Quote']['date_issued']); $enquiry['Enquiry']['customer_reference'], $quote['Quote']['date_issued']);

View file

@ -786,6 +786,10 @@ input#searchbox {
} }
input.number_input {
width: 80px;
}
select { select {
clear: both; clear: both;
font-size: 120%; font-size: 120%;
@ -1232,7 +1236,7 @@ span.addLineItem {
table .jobsTable { table .jobsTable {
} }
table.jobsTable tr th { table.jobsTable tr th {
@ -1365,7 +1369,7 @@ select.shipmentCategories {
/* CSS for the Job Reporting */ /* CSS for the Job Reporting */
#yearMonths { #yearMonths {
float: left; float: left;
margin-right: 4em; margin-right: 4em;
} }
@ -1472,7 +1476,7 @@ table.shipments {
.invForm { .invForm {
border: 1px solid; border: 1px solid;
margin-top: 1em; margin-top: 1em;
} }
@ -1496,7 +1500,7 @@ div.address span {
position: absolute; position: absolute;
left: 50%; left: 50%;
top: 50%; top: 50%;
} }
.pages { .pages {
@ -1533,4 +1537,15 @@ table.lineItems tr th {
table.lineItems tr td.description { table.lineItems tr td.description {
text-align: left; text-align: left;
padding: 0.5em; padding: 0.5em;
}
table.lineItems tr td.leftAlign {
text-align: left;
}
table.lineItems tr td.price {
padding-left: 0.5em;
padding-right: 0.5em;
white-space: nowrap;
} }

View file

@ -1,4 +1,11 @@
/**
* Could (should) tidy this up to move the Quote/Invoice etc Specific
* functionality into seperate files.
*
* Will do this at some point. Today I just need to hammer this out.
*
* Karl - 20/5/2011
*/
$(function() { $(function() {
@ -11,18 +18,15 @@ $(function() {
$("#lineItemDetails").hide(); $("#lineItemDetails").hide();
$( "#lineItemModal" ).dialog({ $( "#addLineItemModal" ).dialog({
autoOpen: false, autoOpen: false,
height: 900, height: 900,
width: 600, width: 600,
modal: true, modal: true,
buttons: { buttons: {
"Add Line Item": function() { "Add Line Item": function() {
/*for ( instance in CKEDITOR.instances ) {
CKEDITOR.instances[instance].updateElement(); $('#QuoteCommercialComments').ckeditor(function() {
CKEDITOR.instances[instance].destroy();
}*/
$('#LineItemDescription').ckeditor(function() {
this.updateElement(); this.updateElement();
this.destroy(); this.destroy();
}); });
@ -31,14 +35,14 @@ $(function() {
var thisLineItemInputs = $('#LineItemAddForm').find('input,select,textarea'); var thisLineItemInputs = $('#LineItemAddForm').find('input,select,textarea');
$.post('/line_items/ajax_add', thisLineItemInputs, function(data) { $.post('/line_items/ajax_add', thisLineItemInputs, function(data) {
$( "#lineItemModal" ).dialog('close'); $( "#addLineItemModal" ).dialog('close');
loadLineItems();
}); });
}, },
Cancel: function() { Cancel: function() {
$( this ).dialog( "close" ); $( this ).dialog( "close" );
loadLineItems();
} }
}, },
close: function() { close: function() {
@ -47,9 +51,73 @@ $(function() {
} }
}); });
$( "#editLineItemModal" ).dialog({
autoOpen: false,
height: 900,
width: 600,
modal: true,
buttons: {
"Edit Line Item": function() {
$('#LineItemDescription').ckeditor(function() {
this.updateElement();
this.destroy();
});
var thisLineItemInputs = $('#LineItemEditForm').find('input,select,textarea');
$.post('/line_items/ajax_edit', thisLineItemInputs, function(data) {
$( "#editLineItemModal" ).dialog('close');
});
},
Cancel: function() {
$( "#editLineItemModal" ).dialog('close');
}
},
close: function() {
loadLineItems();
}
});
$( "#QuoteDetails" ).dialog({
autoOpen: false,
height: 900,
width: 600,
modal: true,
buttons: {
"Edit Quote Details": function() {
$('#QuoteCommercialComments').ckeditor(function() {
this.updateElement();
this.destroy();
});
var quoteInputs = $('#QuoteEditForm').find('input,select,textarea');
$.post('/quotes/ajax_edit', quoteInputs, function(data) {
$( "#QuoteDetails" ).dialog('close');
});
},
Cancel: function() {
$( this ).dialog( "close" );
}
},
close: function() {
loadLineItems();
}
});
$("#pageContentFactory").hide(); $("#pageContentFactory").hide();
@ -98,13 +166,29 @@ $(function() {
//Open the LineItem dialog //Open the LineItem dialog
$("#addLineItem").button().click(function() { $("#addLineItem").button().click(function() {
var docID = $('#documentID').html(); var docID = $('#documentID').html();
$('#LineItemDescription').ckeditor(function() {
this.destroy();
});
$("#editLineItemModal").empty();
var nextItemNo = $(".lineItem").length;
nextItemNo++;
$.get('/line_items/add/'+docID, function(data) { $.get('/line_items/add/'+docID, function(data) {
$("#lineItemModal").html(data); $("#addLineItemModal").html(data);
$("#LineItemItemNumber").val(nextItemNo); //Auto fill in the next Item No
$("#productDetails").hide(); $("#productDetails").hide();
$('#LineItemDescription').ckeditor(config); $('#LineItemDescription').ckeditor(config);
$( "#lineItemModal" ).dialog('open'); $( "#addLineItemModal" ).dialog('open');
}); });
@ -112,6 +196,25 @@ $(function() {
}); });
$(".editLineItem").live('click', function() {
$('#LineItemDescription').ckeditor(function() {
this.destroy();
});
$("#addLineItemModal").empty();
var thisLineItemID = $(this).parent('td').attr('id');
$.get('/line_items/edit/'+thisLineItemID, function(data) {
$("#editLineItemModal").html(data);
$("#productDetails").hide();
$('#LineItemDescription').ckeditor(config);
$( "#editLineItemModal" ).dialog('open');
});
});
$("#principleSelect").live('change',function() { $("#principleSelect").live('change',function() {
@ -183,9 +286,75 @@ $(function() {
}); });
$(".quickpricing").live('change', function() {
calculateQuickPrices();
});
$('.removeLineItem').live('click', function() {
var thisLineItemID = $(this).parent('td').attr('id');
$.post('/line_items/ajax_delete/'+thisLineItemID, function(data) {
loadLineItems();
});
});
$("#editQuoteDetails").click(function() {
var quoteID = $("#quoteID").html();
$('#QuoteCommercialComments').ckeditor(function() {
this.destroy();
});
$.get('/quotes/edit/'+quoteID, function(data) {
$("#QuoteDetails").html(data);
$('#QuoteCommercialComments').ckeditor(config);
$("#QuoteDetails").dialog('open');
});
});
}); });
$('.generateCommercialComments').live('click', function(event) {
event.preventDefault();
var deliveryTime = $("#QuoteDeliveryTime").val();
var paymentTerms = $("#QuotePaymentTerms").val();
var daysValid = $("#QuoteDaysValid").val();
var deliveryPoint = $("#QuoteDeliveryPoint").val();
var exchangeRate = $("#QuoteExchangeRate").val();
var customsDuty = $("#QuoteCustomsDuty").val();
deliveryTime = deliveryTime.toUpperCase();
paymentTerms = paymentTerms.toUpperCase();
deliveryPoint = deliveryPoint.toUpperCase();
var commComments = $("#commCommentsInitialString").clone();
var commList = commComments.find('ol');
commList.append('<li>DELIVERY IS ESTIMATED AT '+deliveryTime+ 'FROM RECEIPT OF YOUR TECHNICALLY AND COMMERCIALLY CLEAR ORDER');
commList.append('<li>PAYMENT TERMS:'+paymentTerms+'</li>');
commList.append('<li>QUOTATION IS VALID <u>FOR '+daysValid+' DAYS</li>');
commList.append('<li>ALL PRICES ARE <u>'+deliveryPoint+'</u></li>');
commList.append('<li>EXCHANGE RATE:'+exchangeRate+'</u></li>');
commList.append('<li>CUSTOMS DUTY INCLUDED AT: '+customsDuty+'</li>');
commList.append('<li>GST 10% EXTRA</li>');
commList.append('<li>WHEN PAYMENTS ARE MADE INTO OUR BANK ACCOUNT, BANK CHARGES ARE YOUR RESPONSIBILITY</li>');
$('#QuoteCommercialComments').val(commComments.html());
});
function loadLineItems() { function loadLineItems() {
var documentID = $("#documentID").html(); var documentID = $("#documentID").html();
@ -194,4 +363,77 @@ function loadLineItems() {
$("#lineItems").html(data); $("#lineItems").html(data);
}); });
}
function calculateQuickPrices() {
var quantity = $('#LineItemQuantity').val();
var gross_unit_price = $("#LineItemGrossUnitPrice").val();
var net_unit_price = $("#LineItemNetUnitPrice").val();
var discount_percent = $("#LineItemDiscountPercent").val();
var discount_amount_unit = $("#LineItemDiscountAmountUnit").val();
var discount_amount_total = $("#LineItemDiscountAmountTotal").val();
var gross_price = $("#LineItemGrossPrice").val();
var net_price = $("#LineItemNetPrice").val();
gross_price = quantity * gross_unit_price;
$("#LineItemGrossPrice").val(gross_price);
discount_amount_unit = (discount_percent/100) * gross_unit_price;
discount_amount_unit = discount_amount_unit.toFixed(2);
discount_amount_total = (discount_percent/100) * gross_price;
discount_amount_total = discount_amount_total.toFixed(2);
$("#LineItemDiscountAmountTotal").val(discount_amount_total);
net_price = gross_price - discount_amount_total;
$("#LineItemNetPrice").val(net_price);
$("#LineItemDiscountAmountUnit").val(discount_amount_unit);
net_unit_price = gross_unit_price - discount_amount_unit;
$("#LineItemNetUnitPrice").val(net_unit_price);
}
function calcNetPrice() {
var discountPercent = $("#discountPercent").val();
var unitPrice = $('#unitPrice').val();
var quantity = $('#LineItemQuantity').val();
var grossSellPrice = quantity * unitPrice;
//Calculate the Sale Discount amount.
var UnitDiscountAmount = (discountPercent/100) * unitPrice;
var TotalDiscountAmount = (discountPercent/100) * grossSellPrice;
UnitDiscountAmount = UnitDiscountAmount.toFixed(2);
TotalDiscountAmount = TotalDiscountAmount.toFixed(2);
$('#total_discountAmount').val(TotalDiscountAmount);
$('#discountAmountEach').val(UnitDiscountAmount);
$('#net_price_each').val(unitPrice - UnitDiscountAmount);
$('#grossPrice').val(grossSellPrice);
var netPrice = grossSellPrice - TotalDiscountAmount;
$('#netPrice').val(netPrice);
}
function checkNaN(value) {
if( isNaN(value) == true) {
return 0;
}
else {
return value;
}
} }

View file

@ -59,7 +59,7 @@ var config = {
['Image','Table','HorizontalRule','SpecialChar'], ['Image','Table','HorizontalRule','SpecialChar'],
'/', '/',
['Styles','Format'], ['Styles','Format'],
['Bold','Italic','Strike'], ['Bold','Italic','Strike','Underline'],
['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'], ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
['Link','Unlink'], ['Link','Unlink'],
['Maximize','-','About'] ['Maximize','-','About']