diff --git a/controllers/app_controller.php b/controllers/app_controller.php index a60be457..45c9ffac 100755 --- a/controllers/app_controller.php +++ b/controllers/app_controller.php @@ -75,7 +75,32 @@ class AppController extends Controller { 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; + + } diff --git a/controllers/documents_controller.php b/controllers/documents_controller.php index 11359bf4..598cf2c4 100755 --- a/controllers/documents_controller.php +++ b/controllers/documents_controller.php @@ -2,7 +2,7 @@ class DocumentsController extends AppController { var $name = 'Documents'; - var $helpers = array('Html', 'Form'); + var $helpers = array('Html', 'Form', 'Number'); function index() { $this->Document->recursive = 0; @@ -14,28 +14,14 @@ class DocumentsController extends AppController { $this->Session->setFlash(__('Invalid Document.', true)); $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); - - - $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->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')); } @@ -87,8 +73,8 @@ class DocumentsController extends AppController { $this->data['Quote']['revision'] = $number_of_revisions; $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)) { @@ -113,7 +99,7 @@ class DocumentsController extends AppController { $enquiryid = $id; $this->Document->create(); - $enquiry = $this->Document->Enquiry->findById($id); + $enquiry = $this->Document->Quote->Enquiry->findById($id); $this->data['Document']['enquiry_id'] = $enquiryid; @@ -124,13 +110,8 @@ class DocumentsController extends AppController { $newInvoiceNumber = $invoice_number_offset + $number_of_invoices; $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']['contact_id']= $enquiry['Enquiry']['contact_id']; - $this->data['Page'][0]['page_number'] = 1; - $this->data['Page'][0]['contentPage'] = 0; + $this->data['Document']['type'] = 'invoice'; if ($this->Document->saveAll($this->data)) { $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'; 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) { if (!$id) { $this->Session->setFlash(__('Invalid id for Document', true)); diff --git a/controllers/enquiries_controller.php b/controllers/enquiries_controller.php index e8a0238f..2fa2eaf3 100755 --- a/controllers/enquiries_controller.php +++ b/controllers/enquiries_controller.php @@ -62,7 +62,6 @@ class EnquiriesController extends AppController { $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('principle_emails', $this->Enquiry->Principle->PrincipleContact->findAllByPrincipleId($enquiry['Enquiry']['principle_id'])); diff --git a/controllers/line_items_controller.php b/controllers/line_items_controller.php index 47454cfd..c5a24914 100755 --- a/controllers/line_items_controller.php +++ b/controllers/line_items_controller.php @@ -2,7 +2,7 @@ class LineItemsController extends AppController { var $name = 'LineItems'; - var $helpers = array('Html', 'Form', 'Javascript'); + var $helpers = array('Html', 'Form', 'Javascript', 'Number'); var $components = array('RequestHandler'); @@ -13,7 +13,27 @@ class LineItemsController extends AppController { if(!empty($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"; } 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) { $this->layout = 'ajax'; if($documentID == null) { @@ -36,19 +71,35 @@ class LineItemsController extends AppController { $document = $this->LineItem->Document->find('first',array('conditions'=>array('Document.id'=>$documentID))); $this->set('document',$document); - $currencies = $this->LineItem->Document->Quote->Currency->find('list', array('fields'=>array('Currency.id','Currency.iso4217'))); - $this->set('currencies',$currencies); + $enquiry = $this->LineItem->Document->getEnquiry($document); + + $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) { + $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) { + $this->layout = 'ajax'; $document = $this->LineItem->Document->read(null, $documentID); $this->set('document', $document); + $this->set('yesNo', array(0=>'No', 1=>'Yes')); $this->set('principles', $this->LineItem->Product->Principle->find('list')); } diff --git a/controllers/quote_pages_controller.php b/controllers/quote_pages_controller.php deleted file mode 100755 index aced3045..00000000 --- a/controllers/quote_pages_controller.php +++ /dev/null @@ -1,214 +0,0 @@ -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 .= << - - $optionText - $itemNumber - - - $title - - -ENDROW; - - } - - - $this->data['QuotePage']['content'] = <<Dear $contactFirstName,

-

 

- -

Thank for your recent enquiry. Please see the following quotation for:

- - - - - - - - - - - $productRows - - -
ItemProduct
 

- -

Regards,

- -

$salesEngineerName

- -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 "
"; - debug ($quoteProducts); - - } - - - - } - - - - -} -?> diff --git a/controllers/quotes_controller.php b/controllers/quotes_controller.php index 02775dd0..219eeee8 100755 --- a/controllers/quotes_controller.php +++ b/controllers/quotes_controller.php @@ -7,181 +7,200 @@ class QuotesController extends AppController { var $components = array('RequestHandler'); function index() { - $this->Quote->recursive = 0; - $this->set('quotes', $this->paginate()); + $this->Quote->recursive = 0; + $this->set('quotes', $this->paginate()); } function view($id = null) { - if (!$id) { - $this->Session->setFlash(__('Invalid Quote.', true)); - $this->redirect(array('action'=>'index')); - } + if (!$id) { + $this->Session->setFlash(__('Invalid Quote.', true)); + $this->redirect(array('action'=>'index')); + } - if (empty($this->data)) { - $quote = $this->Quote->read(null, $id); - $this->data = $quote; - $this->set('quote', $quote); - } + if (empty($this->data)) { + $quote = $this->Quote->read(null, $id); + $this->data = $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'); - $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() { - if(isset($this->params['named']['enquiryid'])) { - $enquiryid = $this->params['named']['enquiryid']; - $this->Quote->create(); - $number_of_revisions = $this->Quote->findCount('Quote.enquiry_id ='. $enquiryid); - $this->data['Quote']['revision'] = $number_of_revisions; - $this->data['Quote']['enquiry_id'] = $enquiryid; - $this->data['Quote']['date_issued'] = date('Y-m-d'); + if(isset($this->params['named']['enquiryid'])) { + $enquiryid = $this->params['named']['enquiryid']; + $this->Quote->create(); + $number_of_revisions = $this->Quote->findCount('Quote.enquiry_id ='. $enquiryid); + $this->data['Quote']['revision'] = $number_of_revisions; + $this->data['Quote']['enquiry_id'] = $enquiryid; + $this->data['Quote']['date_issued'] = date('Y-m-d'); - $this->data['Quote']['currency_id'] = 2; - - - - if ($this->Quote->save($this->data)) { + $this->data['Quote']['currency_id'] = 2; + if ($this->Quote->save($this->data)) { $quoteid = $this->Quote->id; //$this->data['Document'][''] - $this->Session->setFlash(__('The Quote has been saved', true)); - $this->redirect(array('action'=>'view/'.$quoteid)); - } - else { - $this->Session->setFlash(__('The Quote was not saved. Something has gone wrong.', true)); - $this->redirect(array('action'=>'index')); - } - } - else { - $this->Session->setFlash(__('Invalid Enquiry ID', true)); - $this->redirect(array('controller'=>'enquiries','action'=>'index')); - } + $this->Session->setFlash(__('The Quote has been saved', true)); + $this->redirect(array('action'=>'view/'.$quoteid)); + } + else { + $this->Session->setFlash(__('The Quote was not saved. Something has gone wrong.', true)); + $this->redirect(array('action'=>'index')); + } + } + else { + $this->Session->setFlash(__('Invalid Enquiry ID', true)); + $this->redirect(array('controller'=>'enquiries','action'=>'index')); + } } function edit($id = null) { - 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->layout = 'ajax'; - $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)); - $thisquote = $this->Quote->id; - $this->redirect(array('action' =>'view/'.$id), null, false); - } else { - $this->Session->setFlash(__('The Quote could not be saved. Please, try again.', true)); - } - } - if (empty($this->data)) { - $quote = $this->Quote->read(null, $id); - $this->data = $quote; - } - $enquiry = $this->Quote->Enquiry->findById($quote['Quote']['enquiry_id']); - $currencies = $this->Quote->Currency->find('list'); - $this->set(compact('enquiry', 'quote', 'currencies')); + $this->Session->setFlash(__('The Quote has been saved', true)); + $thisquote = $this->Quote->id; + $this->redirect(array('action' =>'view/'.$id), null, false); + } else { + $this->Session->setFlash(__('The Quote could not be saved. Please, try again.', true)); + } + } + if (empty($this->data)) { + $quote = $this->Quote->read(null, $id); + $this->data = $quote; + } + $enquiry = $this->Quote->Enquiry->findById($quote['Quote']['enquiry_id']); + $currencies = $this->Quote->Currency->find('list'); + $this->set('yesNo', array(0=>'No', 1=>'Yes')); + $this->set(compact('enquiry', 'quote', 'currencies')); } function pdf($id = null) { - //Configure::write('debug',0); - if(!$id) { - $this->Session->setFlash(__('Invalid Quote', true)); - $this->redirect(array('controller'=>'enquiries', 'action'=>'index')); - } - $quote = $this->Quote->findById($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']))); + //Configure::write('debug',0); + if(!$id) { + $this->Session->setFlash(__('Invalid Quote', true)); + $this->redirect(array('controller'=>'enquiries', 'action'=>'index')); + } + $quote = $this->Quote->findById($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']))); - $quoteProducts = $this->Quote->Document->LineItem->find('all', array('recursive' => 0, 'conditions' => array('LineItem.quote_id' => $id), - 'order' => array('LineItem.item_number ASC')) - ); + $quoteProducts = $this->Quote->Document->LineItem->find('all', array('recursive' => 0, 'conditions' => array('LineItem.quote_id' => $id), + '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 - * ); - * - * - */ + /** + * 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"; - } + 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']) + $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($commercialDetails); + //debug($quote); + //debug($commercialDetails); - $this->set('quote', $quote); - $this->set('enquiry', $enquiry); + $this->set('quote', $quote); + $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) { - //Configure::write('debug',0); - if(empty($this->data)) { - $this->Session->setFlash(__('Invalid Quote', true)); - $this->redirect(array('controller'=>'enquiries', 'action'=>'index')); - } - else { - $id = $this->data['Quote']['id']; + //Configure::write('debug',0); + if(empty($this->data)) { + $this->Session->setFlash(__('Invalid Quote', true)); + $this->redirect(array('controller'=>'enquiries', 'action'=>'index')); + } + else { + $id = $this->data['Quote']['id']; - $quote = $this->Quote->findById($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']))); + $quote = $this->Quote->findById($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']))); - $quoteProducts = $this->Quote->LineItem->find('all', array('recursive' => 1, 'conditions' => array('LineItem.quote_id' => $id), - 'order' => array('LineItem.item_number ASC')) - ); + $quoteProducts = $this->Quote->LineItem->find('all', array('recursive' => 1, 'conditions' => array('LineItem.quote_id' => $id), + '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']), - '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']) + /** + * 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']), + '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($commercialDetails); + //debug($quote); + //debug($commercialDetails); - $this->set('quote', $quote); - $this->set('enquiry', $enquiry); + $this->set('quote', $quote); + $this->set('enquiry', $enquiry); - - - $this->set('products', $quoteProducts); - } + + + $this->set('products', $quoteProducts); + } } @@ -291,53 +310,48 @@ class QuotesController extends AppController { */ function revise($id) { - if(!$id) { - $this->Session->setFlash(__('Invalid Quote', true)); - $this->redirect(array('controller'=>'enquiries', 'action'=>'index')); - } - else { - $quoteid = $id; - $quote = $this->Quote->read(null,$id); - $enquiryid = $quote['Quote']['enquiry_id']; + if(!$id) { + $this->Session->setFlash(__('Invalid Quote', true)); + $this->redirect(array('controller'=>'enquiries', 'action'=>'index')); + } + else { + $quoteid = $id; + $quote = $this->Quote->read(null,$id); + $enquiryid = $quote['Quote']['enquiry_id']; - $number_of_revisions = $this->Quote->findCount('Quote.enquiry_id ='. $enquiryid); - $number_of_revisions++; + $number_of_revisions = $this->Quote->findCount('Quote.enquiry_id ='. $enquiryid); + $number_of_revisions++; - //debug($quote); + //debug($quote); - // $this->Quote->create(); - $this->data['Quote'] = $quote['Quote']; - $this->data['Quote']['id'] = null; - $this->data['Quote']['created'] = null; - $this->data['Quote']['modified'] = null; - $this->data['Quote']['revision'] = $number_of_revisions; - $this->data['Quote']['enquiry_id'] = $enquiryid; + // $this->Quote->create(); + $this->data['Quote'] = $quote['Quote']; + $this->data['Quote']['id'] = null; + $this->data['Quote']['created'] = null; + $this->data['Quote']['modified'] = null; + $this->data['Quote']['revision'] = $number_of_revisions; + $this->data['Quote']['enquiry_id'] = $enquiryid; - foreach($quote['LineItem'] as $item) { - $item['id'] = null; - $item['quote_id'] = null; - $this->data['LineItem'][] = $item; - } + foreach($quote['LineItem'] as $item) { + $item['id'] = null; + $item['quote_id'] = null; + $this->data['LineItem'][] = $item; + } - foreach($quote['QuotePage'] as $page) { - $page['id'] = null; - $page['quote_id'] = null; - $this->data['QuotePage'][] = $page; - } + + //debug($this->data); - //debug($this->data); - - if ($this->Quote->saveAll($this->data)) { - $quoteid = $this->Quote->id; - $this->Session->setFlash(__('Created Quote Revision '.$number_of_revisions, true)); - $this->redirect(array('action'=>'view/'.$quoteid)); - } + if ($this->Quote->saveAll($this->data)) { + $quoteid = $this->Quote->id; + $this->Session->setFlash(__('Created Quote Revision '.$number_of_revisions, true)); + $this->redirect(array('action'=>'view/'.$quoteid)); + } - } + } } diff --git a/controllers/shipments_controller.php b/controllers/shipments_controller.php index 2351cc6a..a64b09a3 100644 --- a/controllers/shipments_controller.php +++ b/controllers/shipments_controller.php @@ -133,7 +133,7 @@ class ShipmentsController extends AppController { if ($this->Shipment->saveAll($this->data)) { - + $this->Shipment->Box->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)) { echo "SUCCESS"; - + } else { echo "FAILURE"; @@ -199,6 +199,9 @@ class ShipmentsController extends AppController { } + + + function markJobsSent() { } diff --git a/models/document.php b/models/document.php index 9115a7a6..77ab57be 100755 --- a/models/document.php +++ b/models/document.php @@ -1,51 +1,155 @@ 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 $document + * @param $type + */ + function getCMCReferenceNumber($document, $type) { + switch($type) { + case 'quote': - 'User' => array( - 'className' => 'User', - 'foreignKey' => 'user_id', - 'conditions' => '', - 'fields' => '', - 'order' => '' - ) - ); - - var $hasMany = array( + break; + case 'invoice': - 'LineItem' => array( - 'className' => 'LineItem', - 'foreignKey' => 'document_id', - 'order' => 'LineItem.item_number ASC' - ), - - 'DocPage' => array( - 'className'=> 'DocPage', - 'foreignKey' => 'document_id', - 'order' => 'DocPage.page_number ASC' - ) - ); + break; + case 'purchaseOrder': + + break; + case 'orderAck': + + break; + } + return $fullName; + } - var $hasOne = array( - 'Invoice' => array( - 'className' => 'Invoice', - 'foreignKey'=> 'document_id' - ), - 'Quote' => array( - 'className'=>'Quote', - 'foriegnKey'=>'document_id' - ), + function getEnquiry($document) { + if(!empty($document['Invoice']['id'])) { + return $this->Invoice->Enquiry->find('first',array('conditions'=>array('Enquiry.id'=>$document['Invoice']['enquiry_id']))); + } + elseif(!empty($document['Quote']['id'])) { + return $this->Quote->Enquiry->find('first',array('conditions'=>array('Enquiry.id'=>$document['Quote']['enquiry_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 $enquiry + * @return Bool + */ + function gstApplies($enquiry) { + if ($enquiry['Enquiry']['gst'] == 0) { + return false; + } + else { + return true; + } + } + - 'PurchaseOrder' => array( - 'className'=>'PurchaseOrder', - 'foreignKey'=>'document_id' - ) - ); } ?> \ No newline at end of file diff --git a/models/invoice.php b/models/invoice.php index de7bb54f..192442e6 100755 --- a/models/invoice.php +++ b/models/invoice.php @@ -38,7 +38,15 @@ class Invoice extends AppModel { 'Job' => array( 'className' => 'Job', 'foreignKey' => 'job_id' - ) + ), + 'Currency' => array( + 'className' => 'Currency', + 'foreignKey' => 'currency_id' + ), + 'Document' => array( + 'className' => 'Document', + 'foreignKey' => 'document_id' + ) ); diff --git a/models/quote.php b/models/quote.php index a02fb6b8..a5e91ac7 100755 --- a/models/quote.php +++ b/models/quote.php @@ -17,7 +17,8 @@ class Quote extends AppModel { 'foreignKey' => 'enquiry_id', 'conditions' => '', 'fields' => '', - 'order' => '' + 'order' => '', + 'counterCache'=>true ), 'Currency' => array('className' => 'Currency', 'foreignKey' => 'currency_id'), diff --git a/vendors/fpdi/filters/FilterASCII85.php b/vendors/fpdi/filters/FilterASCII85.php index 149ccda2..092f3299 100755 --- a/vendors/fpdi/filters/FilterASCII85.php +++ b/vendors/fpdi/filters/FilterASCII85.php @@ -1,8 +1,8 @@ fpdi =& $fpdi; } diff --git a/vendors/fpdi/filters/FilterLZW.php b/vendors/fpdi/filters/FilterLZW.php index dd75de0b..76d303d3 100755 --- a/vendors/fpdi/filters/FilterLZW.php +++ b/vendors/fpdi/filters/FilterLZW.php @@ -1,8 +1,8 @@ Error('This method is only usable with FPDF. Use TCPDF methods startTemplate() instead.'); + return; + } + if ($this->page <= 0) $this->error("You have to add a page to fpdf first!"); @@ -113,8 +118,8 @@ class FPDF_TPL extends FPDF { $this->w = $w; $this->_intpl = true; - $this->SetXY($x+$this->lMargin, $y+$this->tMargin); - $this->SetRightMargin($this->w-$w+$this->rMargin); + $this->SetXY($x + $this->lMargin, $y + $this->tMargin); + $this->SetRightMargin($this->w - $w + $this->rMargin); 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. */ 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) { $this->_intpl = false; $tpl =& $this->tpls[$this->tpl]; @@ -161,12 +171,12 @@ class FPDF_TPL extends FPDF { * @param int $_h The new height 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) - $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])) - $this->error("Template does not exist!"); + $this->error('Template does not exist!'); if ($this->_intpl) { $this->_res['tpl'][$this->tpl]['tpls'][$tplidx] =& $this->tpls[$tplidx]; @@ -193,19 +203,26 @@ class FPDF_TPL extends FPDF { 'y' => $this->y, 'w' => $_w, 'h' => $_h, - 'scaleX' => ($_w/$w), - 'scaleY' => ($_h/$h), + 'scaleX' => ($_w / $w), + 'scaleY' => ($_h / $h), 'tx' => $_x, - 'ty' => ($this->h-$_y-$_h), - 'lty' => ($this->h-$_y-$_h) - ($this->h-$h) * ($_h/$h) + 'ty' => ($this->h - $_y - $_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)); + // reset font in the outer graphic state + if ($this->FontFamily) { + $family = $this->FontFamily; + $this->FontFamily = ''; + $this->SetFont($family); + } + $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 * @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]) return false; @@ -231,10 +248,10 @@ class FPDF_TPL extends FPDF { $_h = $h; } - if($_w==0) - $_w = $_h*$w/$h; - if($_h==0) - $_h = $_w*$h/$w; + if($_w == 0) + $_w = $_h * $w / $h; + if($_h == 0) + $_h = $_w * $h / $w; return array("w" => $_w, "h" => $_h); } @@ -242,19 +259,21 @@ class FPDF_TPL extends FPDF { /** * See FPDF/TCPDF-Documentation ;-) */ - function SetFont($family, $style='', $size=0, $fontfile='') { - if (!is_subclass_of($this, 'TCPDF') && func_num_args() > 3) { - $this->Error('More than 3 arguments for the SetFont method are only available in TCPDF.'); + public function SetFont($family, $style = '', $size = 0) { + if (is_subclass_of($this, 'TCPDF')) { + $args = func_get_args(); + return call_user_func_array(array($this, 'TCPDF::SetFont'), $args); } + /** * force the resetting of font changes in a template */ if ($this->_intpl) $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) { $this->_res['tpl'][$this->tpl]['fonts'][$fontkey] =& $this->fonts[$fontkey]; @@ -266,17 +285,20 @@ class FPDF_TPL extends FPDF { /** * 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) { - if (!is_subclass_of($this, 'TCPDF') && func_num_args() > 7) { - $this->Error('More than 7 arguments for the Image method are only available in TCPDF.'); + function Image($file, $x = null, $y = null, $w = 0, $h = 0, $type = '', $link = '') { + if (is_subclass_of($this, '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) { $this->_res['tpl'][$this->tpl]['images'][$file] =& $this->images[$file]; } else { $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. */ - 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) $this->Error('Adding pages in templates isn\'t possible!'); + parent::AddPage($orientation, $format); } /** * Preserve adding Links in Templates ...won't work */ - function Link($x, $y, $w, $h, $link, $spaces=0) { - if (!is_subclass_of($this, 'TCPDF') && func_num_args() > 5) { - $this->Error('More than 5 arguments for the Image method are only available in TCPDF.'); + function Link($x, $y, $w, $h, $link) { + if (is_subclass_of($this, 'TCPDF')) { + $args = func_get_args(); + return call_user_func_array(array($this, 'TCPDF::Link'), $args); } if ($this->_intpl) $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() { + if (is_subclass_of($this, 'TCPDF')) { + $args = func_get_args(); + return call_user_func_array(array($this, 'TCPDF::AddLink'), $args); + } + if ($this->_intpl) $this->Error('Adding links in templates aren\'t possible!'); 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) $this->Error('Setting links in templates aren\'t possible!'); parent::SetLink($link, $y, $page); @@ -331,18 +371,18 @@ class FPDF_TPL extends FPDF { $this->_out('/FormType 1'); $this->_out(sprintf('/BBox [%.2F %.2F %.2F %.2F]', // llx - $tpl['x']*$this->k, + $tpl['x'] * $this->k, // lly - -$tpl['y']*$this->k, + -$tpl['y'] * $this->k, // urx - ($tpl['w']+$tpl['x'])*$this->k, + ($tpl['w'] + $tpl['x']) * $this->k, // ury - ($tpl['h']-$tpl['y'])*$this->k + ($tpl['h'] - $tpl['y']) * $this->k )); if ($tpl['x'] != 0 || $tpl['y'] != 0) { $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'])) { $this->_out('/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('>>'); } 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 <<'); if (isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images'])) { 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'])) { 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('/Length '.strlen($p).' >>'); + $this->_out('/Length ' . strlen($p) . ' >>'); $this->_putstream($p); $this->_out('endobj'); } @@ -400,8 +440,8 @@ class FPDF_TPL extends FPDF { * Private Method */ function _out($s) { - if ($this->state==2 && $this->_intpl) { - $this->tpls[$this->tpl]['buffer'] .= $s."\n"; + if ($this->state == 2 && $this->_intpl) { + $this->tpls[$this->tpl]['buffer'] .= $s . "\n"; } else { parent::_out($s); } diff --git a/vendors/fpdi/fpdi.php b/vendors/fpdi/fpdi.php index fbcffb84..e4ebb0c3 100755 --- a/vendors/fpdi/fpdi.php +++ b/vendors/fpdi/fpdi.php @@ -1,8 +1,8 @@ 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 * * @param int $pageno pagenumber * @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) { 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 - $pageKey = $fn.((int)$pageno).$boxName; + $pageKey = $fn . '-' . ((int)$pageno) . $boxName; if (isset($this->_importedPages[$pageKey])) return $this->_importedPages[$pageKey]; @@ -116,7 +144,7 @@ class FPDI extends FPDF_TPL { if (!in_array($boxName, $parser->availableBoxes)) return $this->Error(sprintf('Unknown box: %s', $boxName)); - $pageboxes = $parser->getPageBoxes($pageno); + $pageboxes = $parser->getPageBoxes($pageno, $this->k); /** * MediaBox @@ -155,14 +183,17 @@ class FPDI extends FPDF_TPL { $rotation = $parser->getPageRotation($pageno); $tpl['_rotationAngle'] = 0; if (isset($rotation[1]) && ($angle = $rotation[1] % 360) != 0) { - $steps = $angle / 90; + $steps = $angle / 90; $_w = $tpl['w']; $_h = $tpl['h']; $tpl['w'] = $steps % 2 == 0 ? $_w : $_h; $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; @@ -174,24 +205,29 @@ class FPDI extends FPDF_TPL { 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)) { $size = $this->getTemplateSize($tplidx, $_w, $_h); $format = array($size['w'], $size['h']); - if ($format[0]!=$this->CurPageFormat[0] || $format[1]!=$this->CurPageFormat[1]) { - $this->w=$format[0]; - $this->h=$format[1]; - $this->wPt=$this->w*$this->k; - $this->hPt=$this->h*$this->k; - $this->PageBreakTrigger=$this->h-$this->bMargin; - $this->CurPageFormat=$format; - $this->PageSizes[$this->page]=array($this->wPt, $this->hPt); - } + if (is_subclass_of($this, 'TCPDF')) { + $this->setPageFormat($format, $format[0] > $format[1] ? 'L' : 'P'); + } else { + if ($format[0] != $this->CurPageFormat[0] || $format[1] != $this->CurPageFormat[1]) { + $this->w = $format[0]; + $this->h = $format[1]; + $this->wPt = $this->w * $this->k; + $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 $s = parent::useTemplate($tplidx, $_x, $_y, $_w, $_h); $this->_out('Q'); + return $s; } @@ -204,14 +240,14 @@ class FPDI extends FPDF_TPL { $this->current_parser =& $this->parsers[$filename]; if (isset($this->_obj_stack[$filename]) && is_array($this->_obj_stack[$filename])) { 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]); if ($nObj[0] == PDF_TYPE_STREAM) { - $this->pdf_write_value ($nObj); + $this->pdf_write_value($nObj); } else { - $this->pdf_write_value ($nObj[1]); + $this->pdf_write_value($nObj[1]); } $this->_out('endobj'); @@ -237,15 +273,15 @@ class FPDI extends FPDF_TPL { $cN = $this->n; // TCPDF/Protection: rem current "n" $this->tpls[$tplidx]['n'] = $this->n; - $this->_out('<<'.$filter.'/Type /XObject'); + $this->_out('<<' . $filter . '/Type /XObject'); $this->_out('/Subtype /Form'); $this->_out('/FormType 1'); $this->_out(sprintf('/BBox [%.2F %.2F %.2F %.2F]', - (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']['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']['llx']) ? $tpl['box']['llx'] : $tpl['x']) * $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']['ury']) ? $tpl['box']['ury'] : $tpl['h'] - $tpl['y']) * $this->k )); $c = 1; @@ -272,7 +308,7 @@ class FPDI extends FPDF_TPL { $ty = $tpl['box']['ury']; break; case -270: - $tx = $tpl['box']['ury']; + $tx = $tpl['box']['ury']; $ty = -$tpl['box']['llx']; break; } @@ -301,7 +337,7 @@ class FPDI extends FPDF_TPL { if (isset($this->_res['tpl'][$tplidx]['fonts']) && count($this->_res['tpl'][$tplidx]['fonts'])) { $this->_out('/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('>>'); } 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 <<'); if (isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images'])) { 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'])) { 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('>>'); } @@ -323,7 +359,7 @@ class FPDI extends FPDF_TPL { $nN = $this->n; // TCPDF: rem new "n" $this->n = $cN; // TCPDF: reset to current "n" - $this->_out('/Length '.strlen($p).' >>'); + $this->_out('/Length ' . strlen($p) . ' >>'); $this->_putstream($p); $this->_out('endobj'); $this->n = $nN; // TCPDF: reset to new "n" @@ -335,7 +371,7 @@ class FPDI extends FPDF_TPL { /** * Rewritten to handle existing own defined objects */ - function _newobj($obj_id=false,$onlynewobj=false) { + function _newobj($obj_id = false, $onlynewobj = false) { if (!$obj_id) { $obj_id = ++$this->n; } @@ -343,9 +379,10 @@ class FPDI extends FPDF_TPL { //Begin a new object if (!$onlynewobj) { $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 } + return $obj_id; } @@ -363,19 +400,19 @@ class FPDI extends FPDF_TPL { switch ($value[0]) { - case PDF_TYPE_TOKEN : + case PDF_TYPE_TOKEN: $this->_straightOut($value[1] . ' '); break; - case PDF_TYPE_NUMERIC : - case PDF_TYPE_REAL : + case PDF_TYPE_NUMERIC: + case PDF_TYPE_REAL: 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 { $this->_straightOut($value[1] . ' '); } break; - case PDF_TYPE_ARRAY : + case PDF_TYPE_ARRAY: // An array. Output the proper // structure and move on. @@ -388,7 +425,7 @@ class FPDI extends FPDF_TPL { $this->_out(']'); break; - case PDF_TYPE_DICTIONARY : + case PDF_TYPE_DICTIONARY: // A dictionary. $this->_straightOut('<<'); @@ -403,30 +440,30 @@ class FPDI extends FPDF_TPL { $this->_straightOut('>>'); break; - case PDF_TYPE_OBJREF : + case PDF_TYPE_OBJREF: // An indirect object reference // Fill the object stack if needed $cpfn =& $this->current_parser->filename; 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->_don_obj_stack[$cpfn][$value[1]] = array($this->n, $value); // Value is maybee obsolete!!! } $objid = $this->_don_obj_stack[$cpfn][$value[1]][0]; - $this->_out($objid.' 0 R'); + $this->_out($objid . ' 0 R'); break; - case PDF_TYPE_STRING : + case PDF_TYPE_STRING: // A string. - $this->_straightOut('('.$value[1].')'); + $this->_straightOut('(' . $value[1] . ')'); break; - case PDF_TYPE_STREAM : + case PDF_TYPE_STREAM: // A stream. First, output the // stream dictionary, then the @@ -436,15 +473,16 @@ class FPDI extends FPDF_TPL { $this->_out($value[2][1]); $this->_out('endstream'); break; - case PDF_TYPE_HEX : - $this->_straightOut('<'.$value[1].'>'); + + case PDF_TYPE_HEX: + $this->_straightOut('<' . $value[1] . '>'); break; - case PDF_TYPE_BOOLEAN : + case PDF_TYPE_BOOLEAN: $this->_straightOut($value[1] ? 'true ' : 'false '); break; - case PDF_TYPE_NULL : + case PDF_TYPE_NULL: // The null object. $this->_straightOut('null '); @@ -468,7 +506,7 @@ class FPDI extends FPDF_TPL { // puts data before page footer $page = substr($this->getPageBuffer($this->page), 0, -$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 { $this->setPageBuffer($this->page, $s, true); } diff --git a/vendors/fpdi/fpdi2tcpdf_bridge.php b/vendors/fpdi/fpdi2tcpdf_bridge.php index 95994b4c..640700a8 100755 --- a/vendors/fpdi/fpdi2tcpdf_bridge.php +++ b/vendors/fpdi/fpdi2tcpdf_bridge.php @@ -1,8 +1,8 @@ PDFVersion; - case 'k': - return $this->k; - default: - // Error handling - $this->Error('Cannot access protected property '.get_class($this).':$'.$name.' / Undefined property: '.get_class($this).'::$'.$name); + function _putstream($s) { + $this->_out($this->_getstream($s)); + } + + function _getxobjectdict() { + $out = parent::_getxobjectdict(); + if (count($this->tpls)) { + foreach($this->tpls as $tplidx => $tpl) { + $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 * @@ -58,7 +50,7 @@ class FPDF extends TCPDF { */ function pdf_write_value(&$value) { switch ($value[0]) { - case PDF_TYPE_STRING : + case PDF_TYPE_STRING: if ($this->encrypted) { $value[1] = $this->_unescape($value[1]); $value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]); @@ -66,13 +58,13 @@ class FPDF extends TCPDF { } break; - case PDF_TYPE_STREAM : + case PDF_TYPE_STREAM: if ($this->encrypted) { $value[2][1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[2][1]); } break; - case PDF_TYPE_HEX : + case PDF_TYPE_HEX: if ($this->encrypted) { $value[1] = $this->hex2str($value[1]); $value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]); diff --git a/vendors/fpdi/fpdi_pdf_parser.php b/vendors/fpdi/fpdi_pdf_parser.php index 8ace548a..57b8e88f 100755 --- a/vendors/fpdi/fpdi_pdf_parser.php +++ b/vendors/fpdi/fpdi_pdf_parser.php @@ -1,8 +1,8 @@ pages[$this->pageno][1][1]['/Contents'])) { $contents = $this->_getPageContent($this->pages[$this->pageno][1][1]['/Contents']); 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'])) { $_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) { $filters[] = $_filter; } else if ($_filter[0] == PDF_TYPE_ARRAY) { @@ -225,13 +230,18 @@ class fpdi_pdf_parser extends pdf_parser { foreach ($filters AS $_filter) { switch ($_filter[1]) { 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) : ''; } else { $this->error(sprintf('To handle %s filter, please compile php with zlib support.',$_filter[1])); } + if ($stream === false) { - $this->error('Error while decompressing stream.'); + $this->error('Error while decompressing stream.'); } break; case '/LZWDecode': @@ -262,52 +272,60 @@ class fpdi_pdf_parser extends pdf_parser { * * @param array $page a /Page * @param string $box_index Type of Box @see $availableBoxes + * @param float Scale factor from user space units to points * @return array */ - function getPageBox($page, $box_index) { - $page = $this->pdf_resolve_object($this->c,$page); + function getPageBox($page, $box_index, $k) { + $page = $this->pdf_resolve_object($this->c, $page); $box = null; if (isset($page[1][1][$box_index])) $box =& $page[1][1][$box_index]; 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]; } if (!is_null($box) && $box[0] == PDF_TYPE_ARRAY) { $b =& $box[1]; - return array('x' => $b[0][1]/$this->fpdi->k, - 'y' => $b[1][1]/$this->fpdi->k, - 'w' => abs($b[0][1]-$b[2][1])/$this->fpdi->k, - 'h' => abs($b[1][1]-$b[3][1])/$this->fpdi->k, - 'llx' => min($b[0][1], $b[2][1])/$this->fpdi->k, - 'lly' => min($b[1][1], $b[3][1])/$this->fpdi->k, - 'urx' => max($b[0][1], $b[2][1])/$this->fpdi->k, - 'ury' => max($b[1][1], $b[3][1])/$this->fpdi->k, + return array('x' => $b[0][1]/$k, + 'y' => $b[1][1]/$k, + 'w' => abs($b[0][1]-$b[2][1])/$k, + 'h' => abs($b[1][1]-$b[3][1])/$k, + 'llx' => min($b[0][1], $b[2][1])/$k, + 'lly' => min($b[1][1], $b[3][1])/$k, + 'urx' => max($b[0][1], $b[2][1])/$k, + 'ury' => max($b[1][1], $b[3][1])/$k, ); } else if (!isset ($page[1][1]['/Parent'])) { return false; } 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 * @return array */ - function _getPageBoxes($page) { + function _getPageBoxes($page, $k) { $boxes = array(); foreach($this->availableBoxes AS $box) { - if ($_box = $this->getPageBox($page,$box)) { + if ($_box = $this->getPageBox($page, $box, $k)) { $boxes[$box] = $_box; } } @@ -325,7 +343,7 @@ class fpdi_pdf_parser extends pdf_parser { 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); if (isset ($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 the result-array */ - function read_pages (&$c, &$pages, &$result) { + function read_pages(&$c, &$pages, &$result) { // Get the kids dictionary $_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 one of the kids is an embedded // /Pages array, resolve it as well. - $this->read_pages ($c, $pg, $result); + $this->read_pages($c, $pg, $result); } else { $result[] = $pg; } @@ -385,7 +403,7 @@ class fpdi_pdf_parser extends pdf_parser { */ function getPDFVersion() { parent::getPDFVersion(); - $this->fpdi->PDFVersion = max($this->fpdi->PDFVersion, $this->pdfVersion); + $this->fpdi->setPDFVersion(max($this->fpdi->getPDFVersion(), $this->pdfVersion)); } } \ No newline at end of file diff --git a/vendors/fpdi/pdf_context.php b/vendors/fpdi/pdf_context.php index 966fc10c..0cece449 100755 --- a/vendors/fpdi/pdf_context.php +++ b/vendors/fpdi/pdf_context.php @@ -1,8 +1,8 @@ _mode == 0 && feof($this->file)) { - return false; - } else if ($this->_mode == 0) { - $totalLength = $this->length + $l; - do { - $this->buffer .= fread($this->file, $totalLength-$this->length); - } while ((($this->length = strlen($this->buffer)) != $totalLength) && !feof($this->file)); - - return true; - } else { - return false; - } - } + function increase_length($l = 100) { + if ($this->_mode == 0 && feof($this->file)) { + return false; + } else if ($this->_mode == 0) { + $totalLength = $this->length + $l; + do { + $toRead = $totalLength - $this->length; + if ($toRead < 1) + break; + + $this->buffer .= fread($this->file, $toRead); + } while ((($this->length = strlen($this->buffer)) != $totalLength) && !feof($this->file)); + + return true; + } else { + return false; + } + } } -} - -unset($__tmp); \ No newline at end of file +} \ No newline at end of file diff --git a/vendors/fpdi/pdf_parser.php b/vendors/fpdi/pdf_parser.php index 34ea5753..0724152e 100755 --- a/vendors/fpdi/pdf_parser.php +++ b/vendors/fpdi/pdf_parser.php @@ -1,8 +1,8 @@ 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 */ function pdf_read_xref(&$result, $offset) { - - fseek($this->f, $o_pos = $offset-20); // set some bytes backwards to fetch errorious docs + $o_pos = $offset-min(20, $offset); + fseek($this->f, $o_pos); // set some bytes backwards to fetch errorious docs $data = fread($this->f, 100); @@ -452,7 +458,7 @@ if (!call_user_func_array('class_exists', $__tmp)) { } else { $length = $this->actual_obj[1][1]['/Length'][1]; } - + if ($length > 0) { $c->reset($startpos+$e,$length); $v = $c->buffer; @@ -542,7 +548,14 @@ if (!call_user_func_array('class_exists', $__tmp)) { $header = $this->pdf_read_value($c); 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 @@ -704,5 +717,3 @@ if (!call_user_func_array('class_exists', $__tmp)) { } } } - -unset($__tmp); \ No newline at end of file diff --git a/vendors/tcpdf/CHANGELOG.TXT b/vendors/tcpdf/CHANGELOG.TXT index 8e0e7748..98a1ba97 100755 --- a/vendors/tcpdf/CHANGELOG.TXT +++ b/vendors/tcpdf/CHANGELOG.TXT @@ -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) - Bug item #3300878 "wrong rendering for html bullet list in some case" was fixed. - Bug item #3301017 "Emphasized vs. font-weight" was fixed. diff --git a/vendors/tcpdf/README.TXT b/vendors/tcpdf/README.TXT index b72cd5c7..c4f5aec8 100755 --- a/vendors/tcpdf/README.TXT +++ b/vendors/tcpdf/README.TXT @@ -8,8 +8,8 @@ http://sourceforge.net/donate/index.php?group_id=128076 ------------------------------------------------------------ Name: TCPDF -Version: 5.9.078 -Release date: 2011-05-12 +Version: 5.9.082 +Release date: 2011-05-22 Author: Nicola Asuni Copyright (c) 2002-2011: @@ -72,8 +72,8 @@ License TCPDF is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the - License, or (at your option) any later version. Additionally, - YOU CAN'T REMOVE ANY TCPDF COPYRIGHT NOTICE OR LINK FROM THE + License, or (at your option) any later version. Additionally, + YOU CAN'T REMOVE ANY TCPDF COPYRIGHT NOTICE OR LINK FROM THE GENERATED PDF DOCUMENTS. TCPDF is distributed in the hope that it will be useful, but diff --git a/vendors/tcpdf/tcpdf.php b/vendors/tcpdf/tcpdf.php index b2fc510b..87aac872 100755 --- a/vendors/tcpdf/tcpdf.php +++ b/vendors/tcpdf/tcpdf.php @@ -1,9 +1,9 @@ * @package com.tecnick.tcpdf * @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. @@ -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.
* @package com.tecnick.tcpdf * @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 */ class TCPDF { @@ -157,7 +157,7 @@ class TCPDF { * Current TCPDF version. * @private */ - private $tcpdf_version = '5.9.078'; + private $tcpdf_version = '5.9.082'; // Protected properties @@ -571,6 +571,12 @@ class TCPDF { * @protected */ 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. @@ -1912,6 +1918,7 @@ class TCPDF { $this->file_id = md5($this->getRandomSeed('TCPDF'.$orientation.$unit.$format.$encoding)); // get default graphic vars $this->default_graphic_vars = $this->getGraphicVars(); + $this->header_xobj_autoreset = false; } /** @@ -4003,6 +4010,23 @@ class TCPDF { 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. * It is automatically called by AddPage() and could be overwritten in your own inherited class. @@ -4074,6 +4098,10 @@ class TCPDF { $x = 0 + $dx; } $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, '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)) { $pagenumtxt = $this->l['w_page'].' '.$this->getAliasNumPage().' / '.$this->getAliasNbPages(); @@ -5694,7 +5722,7 @@ class TCPDF { // increase/decrease font spacing $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.' '; } // rendering mode @@ -5801,7 +5829,7 @@ class TCPDF { if ($this->overline) { $s .= ' '.$this->_dooverlinew($xdx, $basefonty, $width); } - if ($this->ColorFlag) { + if ($this->ColorFlag AND ($this->textrendermode < 4)) { $s .= ' Q'; } if ($link) { @@ -7261,8 +7289,12 @@ class TCPDF { // encode spaces on filename (file is probably an URL) $file = str_replace(' ', '%20', $file); } - // get image dimensions - $imsize = @getimagesize($file); + if (@file_exists($file)) { + // get image dimensions + $imsize = @getimagesize($file); + } else { + $imsize = false; + } if ($imsize === FALSE) { if (function_exists('curl_init')) { // 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'] != '/')) { $findroot = strpos($tag['attribute']['src'], $_SERVER['DOCUMENT_ROOT']); 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']); @@ -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 $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']); if (($findroot === false) OR ($findroot > 1)) { - // replace relative path with full server path - $img = $_SERVER['DOCUMENT_ROOT'].$img; + if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') { + $img = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$img; + } else { + $img = $_SERVER['DOCUMENT_ROOT'].$img; + } } } $img = urldecode($img); diff --git a/vendors/xfpdi.php b/vendors/xfpdi.php index 3a267846..d129daf5 100755 --- a/vendors/xfpdi.php +++ b/vendors/xfpdi.php @@ -1,5 +1,6 @@ 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->SetTextColor(0 , 0, 152); //Set the Text Color to Blue + $this->SetFillColor(255, 255, 255); + $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->Cell(30); - $this->SetFont('times', 'B'); - $this->SetFontSize(30); - $this->Cell(0,0, $this->xheadertext, 0,1,'C', 1); - $this->SetFontSize(10); - $this->SetY(22); - $this->Cell(30); - $this->Cell(0,0, "PTY LIMITED ACN: 47 085 991 224 ABN: 47 085 991 224", 0, 1, 'C', 1); + $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->SetFont('times', 'B'); + $this->SetFontSize(30); + $this->Cell(0,0, $this->xheadertext, 0,1,'C', 1); + $this->SetFontSize(10); + $this->SetY(22); + $this->Cell(30); + $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)); - /* Start the contact details */ - $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->Rect($this->GetX()+33, $this->GetY()+2, 157, 2, 'DF', array('width'=>0), array(0, 0, 0)); + /* Start the contact details */ + $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(50, 0, "+61 2 9669 4000
+61 2 9669 4111
sales@cmctechnologies.com.au + $this->MultiCell(50, 0, "+61 2 9669 4000
+61 2 9669 4111
sales@cmctechnologies.com.au
www.cmctechnologies.com.au
", 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->SetFont('times', 'B'); - $this->MultiCell(30, 20, "Engineering &\nIndustrial\nInstrumentation", 0, 'L', 0, 1, 10,37); + $this->SetTextColor(0 , 0, 152); //Set the Text Color to Blue + $this->SetFont('times', 'B'); + $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.'; */ function Page1Footer() { - $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->MultiCell(0, 2, "
", 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->SetFontSize(12); - $this->MultiCell(120, 2, "EXPLOSION PREVENTION", 0, 'L', null, 0, null, null, true, 0, true, false); - $this->MultiCell(0, 2, "PRESSURE RELIEF", 0, 'R', null, 1, null, null, true, 0, true, false); - $this->MultiCell(120, 2, "EXPLOSION PROTECTION", 0, 'L', null, 0, null, null, true, 0, true, false); - $this->MultiCell(0, 2, "VISION IN THE PROCESS", 0, 'R', null, 1, null, null, true, 0, true, false); - // $this->ln(); - $this->MultiCell(80, 2, "FLOW MEASUREMENT", 0, 'L', null, 0, null, null, true, 0, true, false); - $this->MultiCell(0, 2, "PROCESS INSTRUMENTATION", 0, 'R', null, 1, null, null, true, 0, true, false); + $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->MultiCell(0, 2, "
", 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->SetFontSize(10); + $this->MultiCell(120, 2, "EXPLOSION PREVENTION", 0, 'L', null, 0, null, null, true, 0, true, false); + $this->MultiCell(0, 2, "PRESSURE RELIEF", 0, 'R', null, 1, null, null, true, 0, true, false); + $this->MultiCell(120, 2, "EXPLOSION PROTECTION", 0, 'L', null, 0, null, null, true, 0, true, false); + $this->MultiCell(0, 2, "VISION IN THE PROCESS", 0, 'R', null, 1, null, null, true, 0, true, false); + // $this->ln(); + $this->MultiCell(80, 2, "FLOW MEASUREMENT", 0, 'L', null, 0, null, null, true, 0, true, false); + $this->MultiCell(0, 2, "PROCESS INSTRUMENTATION", 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) { - $this->SetTextColor(0); //Black Text + $this->SetTextColor(0); //Black Text - $boxYstart = 45; - $boxXstart = 10; - $firstColWidth = 40; - $secondColWidth = 70; - $thirdColWidth = 30; - $fourthColWidth = -10; + $boxYstart = 45; + $boxXstart = 10; + $firstColWidth = 40; + $secondColWidth = 70; + $thirdColWidth = 30; + $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($secondColWidth, $lineHeight*$heightNeeded, $companyName, '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($thirdColWidth, $lineHeight*$heightNeeded, "FROM:", 'LT', 'L', 0, 0); - $this->MultiCell($fourthColWidth, $lineHeight*$heightNeeded, "$fromName", 'TR', 'L', 0, 1, null,null, true,0,true); //Start a new line after this. + $this->MultiCell($thirdColWidth, $lineHeight*$heightNeeded, "FROM:", 'LT', 'L', 0, 0); + $this->MultiCell($fourthColWidth, $lineHeight*$heightNeeded, "$fromName", '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($secondColWidth, 0, "$emailTo", 'LR','L', 0, 0, null, null, true, 0, true); - $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($firstColWidth, 0, "EMAIL TO:", 'LR', 'L', 0, 0); + $this->MultiCell($secondColWidth, 0, "$emailTo", 'LR','L', 0, 0, null, null, true, 0, true); + $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($firstColWidth, 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($fourthColWidth, 0, "$pageNo of {nb}", 'BR', 'L', 0, 1); + $this->MultiCell($firstColWidth, 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($fourthColWidth, 0, "$pageNo of {nb}", 'BR', 'L', 0, 1); - $todayPHPdate = strtotime($issuedate); + $todayPHPdate = strtotime($issuedate); - $todaysDateString = date('l, j F Y', $todayPHPdate); - $this->MultiCell($firstColWidth + $secondColWidth, 0, "DATE: $todaysDateString", 'LRB', 'L', 0, 0); - $this->MultiCell($thirdColWidth, 0, "YOUR REF: ", 'LB', 'L', 0, 0); + $todaysDateString = date('l, j F Y', $todayPHPdate); + $this->MultiCell($firstColWidth + $secondColWidth, 0, "DATE: $todaysDateString", 'LRB', 'L', 0, 0); + $this->MultiCell($thirdColWidth, 0, "YOUR REF: ", 'LB', 'L', 0, 0); - $this->MultiCell($fourthColWidth, 0, $your_reference, 'BR', 'L', 0, 1); - $this->SetFontSize(6); + $this->MultiCell($fourthColWidth, 0, $your_reference, 'BR', 'L', 0, 1); + $this->SetFontSize(6); - //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.', - '', 'L' - ); + //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.', + '', 'L' + ); } 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->SetFontSize(10); - $pageNo = $this->PageNoFormatted(); + $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); + $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(0,13.6, "PAGE $pageNo OF {nb}", '', 'R'); - //$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->MultiCell(100, 13.6, $cmcRef." CONTINUES", '','C', 0, 0); + $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->Image($file, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi) } @@ -171,106 +173,113 @@ class XTCPDF extends TCPDF { * @param $docType * @param $commercialDetails */ - function calculateProductPage($currency,$gst, $products ,$docType, $commercialDetails) { + function calculateProductPage($currency,$gst, $products, $commercialDetails) { - $itemColwidth = 12; - $qtyColwidth = 10; - $descColwidth = 120; - $unitpriceColwidth = 25; - $totalPricColwidth = -10; + $itemColwidth = 12; + $qtyColwidth = 10; + $descColwidth = 120; + $unitpriceColwidth = 25; + $totalPricColwidth = -10; - //$availableHeight = 253; - $availableHeight = 230; + //$availableHeight = 253; + $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 = "".$principlesList[$product[$docType]['principle_id']]."
"."".$product[$docType]['title'].'
'.$product[$docType]['description']; - $this->MultiCell($descColwidth, 0, $fullDesc, 1, "L", 0, 0, null, null, true, 0, true); + $fullDesc = "".$product['title'].'
'.$product['description']; - $lasth = $this->getLastH(); - $this->rollbackTransaction($this); - //echo "Last height needed for item: ".$product[$docType]['item_number']." was: ".$lasth."
"; + //$this->MultiCell($descColwidth, 0, $fullDesc, 1, "L", 0, 0, null, null, true, 0, true, true, 0, 'T', false); + // die($fullDesc); + + //$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."
"; + + + + //echo $product[$docType]['id']." needs ".$lasth." has $heightLeft left
"; + + $itemno = $product['item_number']; + if($heightLeft - $lasth <= 0) { + // echo "
OUT OF SPACE ON PAGE $pagesRequired making a new one
"; + $pagesRequired++; + $heightLeft = $availableHeight; //Start checking the next page; + // echo "
remaining height on new one = ".$heightLeft."
"; + $heightLeft -= $lasth; + $itemno = $product['item_number']; + // echo "
Using $lasth for $itemno so now have $heightLeft left
"; + + $pageProducts[$pagesRequired][] = $product['id']; + + } + else { + $heightLeft -= $lasth; + $pageProducts[$pagesRequired][] = $product['id']; + + } - - //echo $product[$docType]['id']." needs ".$lasth." has $heightLeft left
"; - - $itemno = $product[$docType]['item_number']; - - if($heightLeft - $lasth <= 0) { - // echo "
OUT OF SPACE ON PAGE $pagesRequired making a new one
"; - $pagesRequired++; - $heightLeft = $availableHeight; //Start checking the next page; - // echo "
remaining height on new one = ".$heightLeft."
"; - $heightLeft -= $lasth; - $itemno = $product[$docType]['item_number']; - // echo "
Using $lasth for $itemno so now have $heightLeft left
"; - - $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. - * 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. - */ + $this->startTransaction(); + $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."
"; + + $heightLeft -= $totalsHeight; + + if($heightLeft <= 0) { + // echo "
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(); - $subtotal = 0; - $totalsHeight = $this->totals($currency, $subtotal, 1); - $commDetailsHeight = $this->commercialComments($commercialDetails); - - $this->rollbackTransaction($this); - - //echo "Currently have $heightLeft Comm details height is ".$commDetailsHeight." totals height is: ".$totalsHeight."
"; - - $heightLeft -= $totalsHeight; - - if($heightLeft <= 0) { - // echo "
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; + debug($pageProducts); + print_r($pageProducts); + return $pageProducts; } /** * * @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 $currency * @param int $gst - 0 or 1 if GST is applicable. * @param $products @@ -280,175 +289,174 @@ class XTCPDF extends TCPDF { 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, - // multiply this by the number of lines it needs + $lineHeight = 5; //Size of a single line of text. If the company name is more, + // multiply this by the number of lines it needs - $itemColwidth = 12; - $qtyColwidth = 10; - $descColwidth = 120; - $unitpriceColwidth = 25; - $totalPricColwidth = -10; + $itemColwidth = 12; + $qtyColwidth = 10; + $descColwidth = 120; + $unitpriceColwidth = 25; + $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 - $this->setFontSize(12); - $pageNo = $this->PageNoFormatted(); - $this->MultiCell(0, 0, "PAGE $pageNo OF {nb}", 0, "R", 0, 1); - $this->MultiCell(0, 0, "PRICING & SPECIFICATIONS", 0, "C", 0, 1); - $this->setFontSize(10); - $this->MultiCell($itemColwidth, 0, "ITEM NO.", 1, "C", 1, 0); + //Draw Header Rows + $this->setFontSize(12); + $pageNo = $this->PageNoFormatted(); + $this->MultiCell(0, 0, "PAGE $pageNo OF {nb}", 0, "R", 0, 1); + $this->MultiCell(0, 0, "PRICING & SPECIFICATIONS", 0, "C", 0, 1); + $this->setFontSize(10); + $this->MultiCell($itemColwidth, 0, "ITEM NO.", 1, "C", 1, 0); - $heightNeeded = $this->getLastH(); - /** - * @todo this seems like a cleaner way of doing it than I did in the detailsBox(). Revise at some point - */ + $heightNeeded = $this->getLastH(); + /** + * @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($descColwidth, $heightNeeded, "DESCRIPTION", 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($qtyColwidth, $heightNeeded, "QTY", 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($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(); - $this->MultiCell($qtyColwidth, $heightNeeded, "", 1, "C", 1, 0); - $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($totalPricColwidth, $heightNeeded, $currency['iso4217'], 1, "C", 1, 1); + $heightNeeded = $this->getLastH(); + $this->MultiCell($qtyColwidth, $heightNeeded, "", 1, "C", 1, 0); + $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($totalPricColwidth, $heightNeeded, $currency['iso4217'], 1, "C", 1, 1); - // echo "

$pageNo

"; - // print_r($page); + // echo "

$pageNo

"; + // 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) { - $product = array_shift($products); + foreach($page as $productID) { + $product = array_shift($products); - if($product['Principle']['id'] != null) { - $fullDesc = "".$product['Principle']['name']."
"."".$product[$docType]['title'].'
'.$product[$docType]['description']; - } - else { - $fullDesc = "".$product[$docType]['title'].'
'.$product[$docType]['description']; + if($product['Principle']['id'] != null) { + $fullDesc = "".$product['Principle']['name']."
"."".$product[$docType]['title'].'
'.$product[$docType]['description']; + } + else { + $fullDesc = "".$product[$docType]['title'].'
'.$product[$docType]['description']; - } - - if($product[$docType]['option'] == 1) { - $options = 1; - } + } + + if($product[$docType]['option'] == 1) { + $options = 1; + } - $currentX = $this->GetX(); - $currentY = $this->GetY(); + $currentX = $this->GetX(); + $currentY = $this->GetY(); - $this->SetX($currentX + $itemColwidth + $qtyColwidth); - $this->MultiCell($descColwidth, 0, $fullDesc, 1, "L", 0, 0, null, null, true, 0, true); - $endOfDesc = $this->GetX(); - $heightNeeded = $this->getLastH(); - $this->SetX($currentX); + $this->SetX($currentX + $itemColwidth + $qtyColwidth); + $this->MultiCell($descColwidth, 0, $fullDesc, 1, "L", 0, 0, null, null, true, 0, true); + $endOfDesc = $this->GetX(); + $heightNeeded = $this->getLastH(); + $this->SetX($currentX); - $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($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->SetX($endOfDesc); + $this->SetX($endOfDesc); - if($product[$docType]['discount_percent'] != 0) { - - - $percentage = number_format($product[$docType]['discount_percent'], 2); + if($product[$docType]['discount_percent'] != 0) { - $unitPriceString = $this->formatCurrency($currency['symbol'], $product[$docType]['unit_price']); - $unitPriceString .= "
less ".$percentage."% discount
(-" - .$this->formatCurrency($currency['symbol'], $product[$docType]['discount_amount_each']).")
=
"; - $unitPriceString .= $this->formatCurrency($currency['symbol'], $product[$docType]['net_price_each']); - $totalPriceString = $this->formatCurrency($currency['symbol'], $product[$docType]['gross_price']); - $totalPriceString .= "
less ".$percentage."% discount
(-" - .$this->formatCurrency($currency['symbol'], $product[$docType]['total_discount_amount']).")
=
"; - $totalPriceString .= $this->formatCurrency($currency['symbol'], $product[$docType]['net_price']); + $percentage = number_format($product[$docType]['discount_percent'], 2); - } - else { - $unitPriceString = $this->formatCurrency($currency['symbol'], $product[$docType]['unit_price']); - $totalPriceString = $this->formatCurrency($currency['symbol'], $product[$docType]['net_price']); + $unitPriceString = $this->formatCurrency($currency['symbol'], $product[$docType]['unit_price']); + $unitPriceString .= "
less ".$percentage."% discount
(-" + .$this->formatCurrency($currency['symbol'], $product[$docType]['discount_amount_each']).")
=
"; + $unitPriceString .= $this->formatCurrency($currency['symbol'], $product[$docType]['net_price_each']); - } + $totalPriceString = $this->formatCurrency($currency['symbol'], $product[$docType]['gross_price']); + $totalPriceString .= "
less ".$percentage."% discount
(-" + .$this->formatCurrency($currency['symbol'], $product[$docType]['total_discount_amount']).")
=
"; + $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 - $this->MultiCell($totalPricColwidth, $heightNeeded, $totalPriceString, 1, "C", 0, 1, null, null, true, 0, true); + //Net Price Column + $this->MultiCell($totalPricColwidth, $heightNeeded, $totalPriceString, 1, "C", 0, 1, null, null, true, 0, true); - $subTotal += $product[$docType]['net_price']; - $lastY = $this->GetY(); - $lastX = $this->GetX(); - //echo $product[$docType]['item_number']." Last X is $lastX, Last Y is $lastY
"; + $subTotal += $product[$docType]['net_price']; + $lastY = $this->GetY(); + $lastX = $this->GetX(); + //echo $product[$docType]['item_number']." Last X is $lastX, Last Y is $lastY
"; - } + } - //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.. - * - * * Passing a data structure in the following format. - * - * $details = array( - * 'deliveryTime' => (String) eg. 2-3 - * 'timeScale' => (String) eg. WORKING DAYS || WEEKS || MONTHS - * 'paymentTerms => (String) eg. 100% PAYMENT WITH ORDER || NET 30 DAYS FOR APPROVED ACCOUNTS - * 'validFor' => (String) eg. 30 Days - * '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 - * ); - * - * - */ + /** + * 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 + * 'timeScale' => (String) eg. WORKING DAYS || WEEKS || MONTHS + * 'paymentTerms => (String) eg. 100% PAYMENT WITH ORDER || NET 30 DAYS FOR APPROVED ACCOUNTS + * 'validFor' => (String) eg. 30 Days + * '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 + * ); + * + * + */ - $this->totals($currency, $subTotal, $gst, $options); - $this->commercialComments($commercialDetails); + $this->totals($currency, $subTotal, $gst, $options); + $this->commercialComments($commercialDetails); - $this->AliasNbPages(); - $this->lastPage(); + $this->AliasNbPages(); + $this->lastPage(); } @@ -461,14 +469,14 @@ class XTCPDF extends TCPDF { * @param $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) { - return $symbol.number_format($number, 2, '.', ','); - } - else { - return $symbol.number_format($number, 0, '.', ','); - } + if($dec > 0) { + return $symbol.number_format($number, 2, '.', ','); + } + else { + return $symbol.number_format($number, 0, '.', ','); + } } @@ -494,16 +502,16 @@ class XTCPDF extends TCPDF { */ function commercialComments($details) { - $totalHeight = 0; + $totalHeight = 0; - $this->MultiCell(0, 0, "Commercial Comments:", 0, 'L', 0, 1, null, null, 1, null, true); - $totalHeight += $this->getLastH(); + //$this->MultiCell(0, 0, "Commercial Comments:", 0, 'L', 0, 1, null, null, 1, null, true); + $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 = <<
  • DELIVERY IS ESTIMATED AT {$details["deliveryTime"]} ({$details["deliveryPoint"]}) FROM RECEIPT OF YOUR TECHNICALLY AND COMMERCIALLY CLEAR ORDER.
  • PAYMENT TERMS: {$details["paymentTerms"]}.
  • @@ -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.
    ENDHTMLCONTENTS; - //$commlines = $this->getNumLines($listHtmlContents); - //echo "lines required for commercial comments: ".$commlines; - $this->MultiCell(0, 0, $listHtmlContents, 0, 'L', 0, 1, null, null, 1, null, true); - $totalHeight += $this->getLastH(); + //$commlines = $this->getNumLines($listHtmlContents); + //echo "lines required for commercial comments: ".$commlines; + //$this->MultiCell(0, 0, $listHtmlContents, 0, 'L', 0, 1, null, null, 1, null, true); + $totalHeight += $this->getLastH(); - $this->MultiCell(0, 0, "Signed: ____________________________", 0, 'L'); - $totalHeight += $this->getLastH(); - $this->MultiCell(0, 0, " ".$details["salesEngineer"], 0, 'L'); - $totalHeight += $this->getLastH(); + //$this->MultiCell(0, 0, "Signed: ____________________________", 0, 'L'); + $totalHeight += $this->getLastH(); + //$this->MultiCell(0, 0, " ".$details["salesEngineer"], 0, 'L'); + $totalHeight += $this->getLastH(); - - return $totalHeight; + + return $totalHeight; } @@ -537,86 +545,86 @@ ENDHTMLCONTENTS; function totals($currency, $subTotal, $gst, $options) { - $itemColwidth = 12; - $qtyColwidth = 10; - $descColwidth = 120; - $unitpriceColwidth = 25; - $totalPricColwidth = -10; - $totalHeight = 0; + $itemColwidth = 12; + $qtyColwidth = 10; + $descColwidth = 120; + $unitpriceColwidth = 25; + $totalPricColwidth = -10; + $totalHeight = 0; - // echo "desc col wdith : ".$descColwidth; - $this->MultiCell($itemColwidth, 6, "", 1, 'C', 0, 0); - $totalHeight += $this->getLastH(); - $this->MultiCell($qtyColwidth, 6, "", 1, 'C', 0, 0); - $totalHeight += $this->getLastH(); - $this->MultiCell($descColwidth, 6, "SUB-TOTAL (EXCLUDING GST)", 1, 'L', 0, 0); - $totalHeight += $this->getLastH(); - $this->MultiCell($unitpriceColwidth, 6, "", 1, 'C', 0, 0); - $totalHeight += $this->getLastH(); - if($options == 1) { - $this->MultiCell($totalPricColwidth, 6, $currency['symbol']. "TBA", 1, 'C', 0, 1); - } - else { - $this->MultiCell($totalPricColwidth, 6, $this->formatCurrency($currency['symbol'], $subTotal), 1, 'C', 0, 1); - } + // echo "desc col wdith : ".$descColwidth; + $this->MultiCell($itemColwidth, 6, "", 1, 'C', 0, 0); + $totalHeight += $this->getLastH(); + $this->MultiCell($qtyColwidth, 6, "", 1, 'C', 0, 0); + $totalHeight += $this->getLastH(); + $this->MultiCell($descColwidth, 6, "SUB-TOTAL (EXCLUDING GST)", 1, 'L', 0, 0); + $totalHeight += $this->getLastH(); + $this->MultiCell($unitpriceColwidth, 6, "", 1, 'C', 0, 0); + $totalHeight += $this->getLastH(); + if($options == 1) { + $this->MultiCell($totalPricColwidth, 6, $currency['symbol']. "TBA", 1, 'C', 0, 1); + } + else { + $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); - $totalHeight += $this->getLastH(); - $this->MultiCell($qtyColwidth, 6, "", 1, 'C', 0, 0); - $totalHeight += $this->getLastH(); - $this->MultiCell($descColwidth, 6, "GST (10%)", 1, 'L', 0, 0); - $totalHeight += $this->getLastH(); - $this->MultiCell($unitpriceColwidth, 6, "", 1, 'C', 0, 0); - $totalHeight += $this->getLastH(); + $this->MultiCell($itemColwidth, 6, "", 1, 'C', 0, 0); + $totalHeight += $this->getLastH(); + $this->MultiCell($qtyColwidth, 6, "", 1, 'C', 0, 0); + $totalHeight += $this->getLastH(); + $this->MultiCell($descColwidth, 6, "GST (10%)", 1, 'L', 0, 0); + $totalHeight += $this->getLastH(); + $this->MultiCell($unitpriceColwidth, 6, "", 1, 'C', 0, 0); + $totalHeight += $this->getLastH(); - if($options == 1) { - $this->MultiCell($totalPricColwidth, 6, $currency['symbol']. "TBA", 1, 'C', 0, 1); - } - else { - if($gst == 1) { - $gstAmount = 0.1*$subTotal; - $this->MultiCell($totalPricColwidth, 6, $this->formatCurrency($currency['symbol'], $gstAmount), 1 , 'C', 0, 1); - $totalHeight += $this->getLastH(); + if($options == 1) { + $this->MultiCell($totalPricColwidth, 6, $currency['symbol']. "TBA", 1, 'C', 0, 1); + } + else { + if($gst == 1) { + $gstAmount = 0.1*$subTotal; + $this->MultiCell($totalPricColwidth, 6, $this->formatCurrency($currency['symbol'], $gstAmount), 1 , 'C', 0, 1); + $totalHeight += $this->getLastH(); - } - else { - $this->MultiCell($totalPricColwidth, 6, "N/A", 1 , 'C', 0, 1); - $totalHeight += $this->getLastH(); - } - } + } + else { + $this->MultiCell($totalPricColwidth, 6, "N/A", 1 , 'C', 0, 1); + $totalHeight += $this->getLastH(); + } + } - $this->MultiCell($itemColwidth, 6, "", 1, 'C', 0, 0); - $totalHeight += $this->getLastH(); - $this->MultiCell($qtyColwidth, 6, "", 1, 'C', 0, 0); - $totalHeight += $this->getLastH(); - $this->MultiCell($descColwidth, 6, "TOTAL PAYABLE", 1, 'L', 0, 0); - $totalHeight += $this->getLastH(); - $this->MultiCell($unitpriceColwidth, 6, "", 1, 'C', 0, 0); - $totalHeight += $this->getLastH(); + $this->MultiCell($itemColwidth, 6, "", 1, 'C', 0, 0); + $totalHeight += $this->getLastH(); + $this->MultiCell($qtyColwidth, 6, "", 1, 'C', 0, 0); + $totalHeight += $this->getLastH(); + $this->MultiCell($descColwidth, 6, "TOTAL PAYABLE", 1, 'L', 0, 0); + $totalHeight += $this->getLastH(); + $this->MultiCell($unitpriceColwidth, 6, "", 1, 'C', 0, 0); + $totalHeight += $this->getLastH(); - if($options == 1) { - $this->MultiCell($totalPricColwidth, 6, $currency['symbol']. "TBA", 1, 'C', 0, 1); - } - else { - if($gst == 1) { - $totalPrice = $subTotal * 1.1; - } - else { - $totalPrice = $subTotal; - } - $this->MultiCell($totalPricColwidth, 6, $this->formatCurrency($currency['symbol'], $totalPrice), 1, 'C', 0, 1); - } + if($options == 1) { + $this->MultiCell($totalPricColwidth, 6, $currency['symbol']. "TBA", 1, 'C', 0, 1); + } + else { + if($gst == 1) { + $totalPrice = $subTotal * 1.1; + } + else { + $totalPrice = $subTotal; + } + $this->MultiCell($totalPricColwidth, 6, $this->formatCurrency($currency['symbol'], $totalPrice), 1, 'C', 0, 1); + } - $totalHeight += $this->getLastH(); + $totalHeight += $this->getLastH(); - return $totalHeight; + return $totalHeight; } diff --git a/views/documents/pdf.ctp b/views/documents/pdf.ctp new file mode 100755 index 00000000..ae1f72f6 --- /dev/null +++ b/views/documents/pdf.ctp @@ -0,0 +1,109 @@ +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 = '
    '.$document['Quote']['commercial_comments'].'
    '; + $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 "
    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'); + +?> \ No newline at end of file diff --git a/views/documents/view.ctp b/views/documents/view.ctp index 26e4c94a..e62f8e87 100755 --- a/views/documents/view.ctp +++ b/views/documents/view.ctp @@ -11,7 +11,7 @@ switch($docType) { break; case 'invoice': - echo "INVOICE!!"; + echo $this->element('document_invoice_view'); break; case 'purchaseOrder': @@ -34,7 +34,26 @@ switch($docType) { -
    +
    - \ No newline at end of file +
    +
    + +
    + +
    + + +
    + +
    + + + + + + + + + \ No newline at end of file diff --git a/views/elements/add_edit_line_item.ctp b/views/elements/add_edit_line_item.ctp index b746ab51..29a5a7bd 100644 --- a/views/elements/add_edit_line_item.ctp +++ b/views/elements/add_edit_line_item.ctp @@ -5,13 +5,28 @@
    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.item_number'); - echo $form->input('LineItem.option'); - echo $form->input('LineItem.quantity'); + echo $form->input('LineItem.item_number', array('class'=>'number_input')); + echo $form->input('LineItem.option', array('type'=>'select','options'=>$yesNo)); + echo $form->input('LineItem.quantity', array('class'=>'number_input quickpricing')); echo $form->input('LineItem.title'); echo $form->input('LineItem.description'); echo $form->input('LineItem.product_id', array('type'=>'hidden')); + + ?> +
    + 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')); + ?> +
    + end(); ?> diff --git a/views/elements/document_invoice_view.ctp b/views/elements/document_invoice_view.ctp new file mode 100644 index 00000000..a04d1b3d --- /dev/null +++ b/views/elements/document_invoice_view.ctp @@ -0,0 +1,21 @@ +

    Invoice:

    + +create('Document',array('type'=>'post','action'=>'edit', 'default'=>false)); +echo $form->input('Document.id'); +?> + +
    + +
    + +
    +
    + + + +data);?> + + + diff --git a/views/elements/document_quote_view.ctp b/views/elements/document_quote_view.ctp index 7107897a..a113f2f1 100644 --- a/views/elements/document_quote_view.ctp +++ b/views/elements/document_quote_view.ctp @@ -1,9 +1,13 @@ -

    Quote: Quote: link($enquiry['Enquiry']['title'], array('controller'=>'enquiries','action'=>'view',$enquiry['Enquiry']['id']));?> 0) { echo "Revision {$document['Quote']['revision']}"; } ?> +for +link($enquiry['Customer']['name'], array('controller'=>'customers','action'=>'view',$enquiry['Customer']['id']));?>

    + + create('Document',array('type'=>'post','action'=>'edit', 'default'=>false)); @@ -13,6 +17,7 @@ echo $form->input('Document.id');
    +
    @@ -33,6 +38,15 @@ echo $form->input('Document.id');
    end();?> + + + data);?> diff --git a/views/elements/enquiry_table.ctp b/views/elements/enquiry_table.ctp index 95666126..6fd3c8a6 100755 --- a/views/elements/enquiry_table.ctp +++ b/views/elements/enquiry_table.ctp @@ -1,6 +1,6 @@ link('jquery.jeditable.mini'); ?> -link('ajax_pagination_enquiry'); ?> +link('ajax_pagination_enquiry'); ?> options(array('url'=>$this->passedArgs)); ?> diff --git a/views/elements/line_items_table.ctp b/views/elements/line_items_table.ctp new file mode 100644 index 00000000..d7413e17 --- /dev/null +++ b/views/elements/line_items_table.ctp @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    ITEM
    NO.
    QTYDESCRIPTIONUNIT
    PRICE
    TOTAL
    PRICE
    + '; + } + ?> + + + + + currency($li['gross_unit_price'], $currencyCode);?> + +
    less
    %
    + discount*
    + (-currency($li['discount_amount_unit'], $currencyCode);?>)
    + =
    + currency($li['net_unit_price'], $currencyCode);?> + +
    + currency($li['gross_price'], $currencyCode);?> + +
    less
    %
    + discount*
    + (currency($li['discount_amount_total'], $currencyCode);?>)
    + =
    + currency($li['net_price'], $currencyCode);?> + +
    currency($totals['subtotal'], $currencyCode);?>
    currency($totals['gst'], $currencyCode); + } + else { + echo 'N/A'; + }?> +
    currency($totals['total'], $currencyCode);?>
    diff --git a/views/elements/quote_table.ctp b/views/elements/quote_table.ctp index 81f00d4b..53ad31e9 100755 --- a/views/elements/quote_table.ctp +++ b/views/elements/quote_table.ctp @@ -26,7 +26,7 @@ nice($quote['Quote']['created']);?> - link(__('View', true), array('controller'=> 'quotes', 'action'=>'view', $quote['Quote']['id'])); ?> + link(__('View', true), array('controller'=> 'documents', 'action'=>'view', $quote['Quote']['document_id'])); ?> link(__('Revise', true), array('controller'=>'quotes', 'action'=>'revise', $quote['Quote']['id'])); ?> diff --git a/views/enquiries/index.ctp b/views/enquiries/index.ctp index 6e00bcc7..ea42fd6a 100755 --- a/views/enquiries/index.ctp +++ b/views/enquiries/index.ctp @@ -1,8 +1,8 @@ - -
    -
    -

    + +
    +

    +
    element('enquiry_table', $enquiries, $status_list); ?>
    diff --git a/views/enquiries/view.ctp b/views/enquiries/view.ctp index 388ea88e..e250aaa1 100755 --- a/views/enquiries/view.ctp +++ b/views/enquiries/view.ctp @@ -123,7 +123,14 @@ $class = ' class="altrow"';?> */?> @@ -310,5 +317,5 @@ $class = ' class="altrow"';?>
    - - \ No newline at end of file + + \ No newline at end of file diff --git a/views/line_items/ajax_delete.ctp b/views/line_items/ajax_delete.ctp new file mode 100644 index 00000000..e69de29b diff --git a/views/line_items/ajax_edit.ctp b/views/line_items/ajax_edit.ctp new file mode 100644 index 00000000..e69de29b diff --git a/views/line_items/get_table.ctp b/views/line_items/get_table.ctp index 66187e25..d7c4c574 100644 --- a/views/line_items/get_table.ctp +++ b/views/line_items/get_table.ctp @@ -1,8 +1,8 @@ @@ -13,7 +13,7 @@ $(function() { ITEM
    NO. QTY DESCRIPTION - UNIT + UNIT
    PRICE TOTAL
    PRICE ACTIONS @@ -21,30 +21,76 @@ $(function() { - - + + - - + + + '; + } + ?> + - + - - + + + currency($li['gross_unit_price'], $currencyCode);?> + +
    less
    %
    + discount
    + (-currency($li['discount_amount_unit'], $currencyCode);?>)
    + =
    + currency($li['net_unit_price'], $currencyCode);?> + - - + + currency($li['gross_price'], $currencyCode);?> + +
    less
    %
    + discount
    + currency($li['discount_amount_total'], $currencyCode);?>)
    + =
    + currency($li['net_price'], $currencyCode);?> + - +
    - \ No newline at end of file + + + + + SUB-TOTAL (Excluding GST) + + currency($totals['subtotal'], $currencyCode);?> + + + + + + GST (10%) + + currency($totals['gst'], $currencyCode);?> + + + + + + TOTAL PAYABLE (INCLUDING GST) + + currency($totals['total'], $currencyCode);?> + + + + diff --git a/views/principles/view.ctp b/views/principles/view.ctp index bcef08d7..b2448cfe 100755 --- a/views/principles/view.ctp +++ b/views/principles/view.ctp @@ -66,9 +66,10 @@ -link('add_user'); ?> -
    +link('add_user'); ?> + - \ No newline at end of file + \ No newline at end of file diff --git a/views/quotes/ajax_edit.ctp b/views/quotes/ajax_edit.ctp new file mode 100644 index 00000000..e69de29b diff --git a/views/quotes/edit.ctp b/views/quotes/edit.ctp index 1755e3d3..8213b98f 100755 --- a/views/quotes/edit.ctp +++ b/views/quotes/edit.ctp @@ -1,34 +1,26 @@ -
    -create('Quote');?> -
    - - input('id'); - echo $form->input('enquiry_id'); - echo $form->input('currency_id'); - echo $form->input('revision'); - echo $form->input('delivery_time'); - echo $form->input('payment_terms'); - echo $form->input('days_valid'); - echo $form->input('date_issued'); - echo $form->input('valid_until'); - echo $form->input('delivery_point'); - echo $form->input('exchange_rate'); - echo $form->input('customs_duty'); - echo $form->input('document_id'); - ?> -
    -end('Submit');?> -
    -
    -
      -
    • 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'))); ?>
    • -
    • link(__('List Quotes', true), array('action' => 'index'));?>
    • -
    • link(__('List Enquiries', true), array('controller' => 'enquiries', 'action' => 'index')); ?>
    • -
    • link(__('New Enquiry', true), array('controller' => 'enquiries', 'action' => 'add')); ?>
    • -
    • link(__('List Currencies', true), array('controller' => 'currencies', 'action' => 'index')); ?>
    • -
    • link(__('New Currency', true), array('controller' => 'currencies', 'action' => 'add')); ?>
    • -
    • link(__('List Documents', true), array('controller' => 'documents', 'action' => 'index')); ?>
    • -
    • link(__('New Document', true), array('controller' => 'documents', 'action' => 'add')); ?>
    • -
    -
    + +create('Quote',array('default'=>false)); + +echo $form->input('id'); +echo $form->input('enquiry_id', array('type'=>'hidden')); +echo $form->input('currency_id'); +echo $form->input('revision', array('type'=>'hidden')); +echo $form->input('delivery_time'); +echo $form->input('payment_terms'); +echo $form->input('days_valid'); +echo $form->input('date_issued'); +echo $form->input('valid_until'); +echo $form->input('delivery_point'); +echo $form->input('exchange_rate'); +echo $form->input('customs_duty'); +echo $form->input('document_id',array('type'=>'hidden')); +echo $form->input('commercial_comments', array('between'=>'')); + +echo $form->end(); +?> \ No newline at end of file diff --git a/views/quotes/pdf.ctp b/views/quotes/pdf.ctp index 195762ee..75b88fb9 100755 --- a/views/quotes/pdf.ctp +++ b/views/quotes/pdf.ctp @@ -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['Enquiry']['customer_reference'], $quote['Quote']['date_issued']); diff --git a/webroot/css/quotenik.css b/webroot/css/quotenik.css index 81d07f69..354f0fe3 100755 --- a/webroot/css/quotenik.css +++ b/webroot/css/quotenik.css @@ -786,6 +786,10 @@ input#searchbox { } +input.number_input { + width: 80px; +} + select { clear: both; font-size: 120%; @@ -1232,7 +1236,7 @@ span.addLineItem { table .jobsTable { - + } table.jobsTable tr th { @@ -1365,7 +1369,7 @@ select.shipmentCategories { /* CSS for the Job Reporting */ #yearMonths { - + float: left; margin-right: 4em; } @@ -1472,7 +1476,7 @@ table.shipments { .invForm { border: 1px solid; - + margin-top: 1em; } @@ -1496,7 +1500,7 @@ div.address span { position: absolute; left: 50%; top: 50%; - + } .pages { @@ -1533,4 +1537,15 @@ table.lineItems tr th { table.lineItems tr td.description { text-align: left; 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; } \ No newline at end of file diff --git a/webroot/js/document_add_edit.js b/webroot/js/document_add_edit.js index 8e031c97..e0f3aeb6 100644 --- a/webroot/js/document_add_edit.js +++ b/webroot/js/document_add_edit.js @@ -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() { @@ -11,18 +18,15 @@ $(function() { $("#lineItemDetails").hide(); - $( "#lineItemModal" ).dialog({ + $( "#addLineItemModal" ).dialog({ autoOpen: false, height: 900, width: 600, modal: true, buttons: { "Add Line Item": function() { - /*for ( instance in CKEDITOR.instances ) { - CKEDITOR.instances[instance].updateElement(); - CKEDITOR.instances[instance].destroy(); - }*/ - $('#LineItemDescription').ckeditor(function() { + + $('#QuoteCommercialComments').ckeditor(function() { this.updateElement(); this.destroy(); }); @@ -31,14 +35,14 @@ $(function() { var thisLineItemInputs = $('#LineItemAddForm').find('input,select,textarea'); $.post('/line_items/ajax_add', thisLineItemInputs, function(data) { - $( "#lineItemModal" ).dialog('close'); - loadLineItems(); + $( "#addLineItemModal" ).dialog('close'); + }); }, Cancel: function() { $( this ).dialog( "close" ); - loadLineItems(); + } }, 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(); @@ -98,13 +166,29 @@ $(function() { //Open the LineItem dialog $("#addLineItem").button().click(function() { + + var docID = $('#documentID').html(); + $('#LineItemDescription').ckeditor(function() { + this.destroy(); + }); + + $("#editLineItemModal").empty(); + + var nextItemNo = $(".lineItem").length; + nextItemNo++; + $.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(); $('#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() { @@ -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('
  • DELIVERY IS ESTIMATED AT '+deliveryTime+ 'FROM RECEIPT OF YOUR TECHNICALLY AND COMMERCIALLY CLEAR ORDER'); + commList.append('
  • PAYMENT TERMS:'+paymentTerms+'
  • '); + commList.append('
  • QUOTATION IS VALID FOR '+daysValid+' DAYS
  • '); + commList.append('
  • ALL PRICES ARE '+deliveryPoint+'
  • '); + commList.append('
  • EXCHANGE RATE:'+exchangeRate+'
  • '); + commList.append('
  • CUSTOMS DUTY INCLUDED AT: '+customsDuty+'
  • '); + commList.append('
  • GST 10% EXTRA
  • '); + commList.append('
  • WHEN PAYMENTS ARE MADE INTO OUR BANK ACCOUNT, BANK CHARGES ARE YOUR RESPONSIBILITY
  • '); + $('#QuoteCommercialComments').val(commComments.html()); + + +}); + function loadLineItems() { var documentID = $("#documentID").html(); @@ -194,4 +363,77 @@ function loadLineItems() { $("#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; + } } \ No newline at end of file diff --git a/webroot/js/global.js b/webroot/js/global.js index d171ac6c..9bba2abe 100644 --- a/webroot/js/global.js +++ b/webroot/js/global.js @@ -59,7 +59,7 @@ var config = { ['Image','Table','HorizontalRule','SpecialChar'], '/', ['Styles','Format'], - ['Bold','Italic','Strike'], + ['Bold','Italic','Strike','Underline'], ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'], ['Link','Unlink'], ['Maximize','-','About']