2010-07-07 23:18:04 -07:00
|
|
|
<?php
|
|
|
|
|
class DocumentsController extends AppController {
|
|
|
|
|
|
|
|
|
|
var $name = 'Documents';
|
2011-06-19 18:20:44 -07:00
|
|
|
var $helpers = array('Html', 'Form', 'Number', 'Decimal');
|
2010-07-07 23:18:04 -07:00
|
|
|
|
2011-08-08 23:33:21 -07:00
|
|
|
|
|
|
|
|
var $paginate = array(
|
|
|
|
|
|
|
|
|
|
'contain' => false,
|
|
|
|
|
'limit' => 200,
|
|
|
|
|
'order'=>array('Document.id' => 'desc')
|
|
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
2010-07-07 23:18:04 -07:00
|
|
|
function index() {
|
2011-05-19 00:05:01 -07:00
|
|
|
$this->Document->recursive = 0;
|
|
|
|
|
$this->set('documents', $this->paginate());
|
2011-08-08 23:33:21 -07:00
|
|
|
|
|
|
|
|
$this->set('users', $this->Document->User->getUsersList());
|
2010-07-07 23:18:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function view($id = null) {
|
2011-05-19 00:05:01 -07:00
|
|
|
if (!$id) {
|
|
|
|
|
$this->Session->setFlash(__('Invalid Document.', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
}
|
2011-05-24 02:11:07 -07:00
|
|
|
$document = $this->Document->read(null,$id);
|
|
|
|
|
//$document = $this->Document->find('first',array('conditions'=>array('Document.id'=>$id), 'recursive'=>2));
|
2011-05-19 00:05:01 -07:00
|
|
|
$this->set('document', $document);
|
2010-07-07 23:18:04 -07:00
|
|
|
|
2011-05-19 00:05:01 -07:00
|
|
|
$this->data = $document;
|
2011-08-09 01:54:10 -07:00
|
|
|
$docType = $this->Document->getDocType($document);
|
|
|
|
|
$this->set('docType', $docType);
|
|
|
|
|
|
|
|
|
|
$this->set('docTypeFullName', $this->Document->getDocFullName($docType));
|
|
|
|
|
$this->set('users', $this->Document->User->getUsersList());
|
|
|
|
|
|
2011-05-24 02:11:07 -07:00
|
|
|
$this->set('currency', $this->Document->getCurrency($document));
|
|
|
|
|
$this->set('enquiry', $this->Document->getEnquiry($document));
|
2011-08-11 22:46:26 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch($docType) {
|
|
|
|
|
case 'quote':
|
|
|
|
|
$docTypeElement = 'document_quote_view';
|
|
|
|
|
break;
|
|
|
|
|
case 'invoice':
|
|
|
|
|
$docTypeElement = 'document_invoice_view';
|
2011-08-14 23:04:38 -07:00
|
|
|
$this->set('invoice', $this->Document->Invoice->find('first', array('conditions'=>array('Invoice.id'=>$document['Invoice']['id']))));
|
2011-08-11 22:46:26 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'purchaseOrder':
|
|
|
|
|
$docTypeElement = 'document_purchase_order_view';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->set('docTypeElement', $docTypeElement);
|
|
|
|
|
|
2011-05-19 00:05:01 -07:00
|
|
|
// $this->set('principles', $this->Document->LineItem->Product->Principle->find('list'));
|
2011-05-18 16:46:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getProducts($principleID = null) {
|
|
|
|
|
$this->layout = 'ajax';
|
|
|
|
|
|
|
|
|
|
if($principleID == null) {
|
|
|
|
|
echo "INVALID PRINCIPLE ID";
|
|
|
|
|
}
|
2011-05-19 00:05:01 -07:00
|
|
|
else {
|
|
|
|
|
$products = $this->Document->LineItem->Product->find('list', array('conditions'=>array('Product.principle_id'=>$principleID)));
|
|
|
|
|
$this->set('products',$products);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return a JSON object of the Product.
|
|
|
|
|
*/
|
|
|
|
|
function getProductDetails($productID = null) {
|
|
|
|
|
$this->layout = 'ajax';
|
|
|
|
|
|
|
|
|
|
if($productID == null) {
|
|
|
|
|
echo "INVALID PRODUCT ID";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$product = $this->Document->LineItem->Product->find('first',array('conditions'=>array('Product.id'=>$productID)));
|
|
|
|
|
$this->set('product',$product);
|
|
|
|
|
}
|
2010-07-07 23:18:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-08-11 00:30:03 -07:00
|
|
|
/**
|
|
|
|
|
* Create a New Document
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param <type> $type
|
|
|
|
|
* @param <type> $id
|
|
|
|
|
*/
|
2011-08-11 22:46:26 -07:00
|
|
|
function newDocument($type = null, $enquiryid = null, $jobid = 0) {
|
|
|
|
|
if(!$type) {
|
2011-08-11 00:30:03 -07:00
|
|
|
$this->Session->setFlash('Invalid Doc Type or ID');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->Document->create();
|
|
|
|
|
|
|
|
|
|
switch($type) {
|
|
|
|
|
case "quote":
|
|
|
|
|
|
2011-08-11 22:46:26 -07:00
|
|
|
$enquiry = $this->Document->Quote->Enquiry->findById($enquiryid);
|
2011-08-11 00:30:03 -07:00
|
|
|
|
|
|
|
|
if(!$enquiry) {
|
|
|
|
|
$this->Session->setFlash('Invalid Enquiry ID');
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->data['Quote']['enquiry_id'] = $enquiryid;
|
|
|
|
|
$number_of_revisions = $this->Document->Quote->findCount('Quote.enquiry_id ='. $enquiryid);
|
|
|
|
|
$this->data['Document']['revision'] = $number_of_revisions;
|
|
|
|
|
$this->data['Quote']['date_issued'] = date('Y-m-d');
|
|
|
|
|
$this->data['Quote']['currency_id'] = 2; //All new Quotes default to AUD.
|
|
|
|
|
|
|
|
|
|
$this->data['Document']['user_id']= $enquiry['Enquiry']['user_id'];
|
2011-08-11 22:46:26 -07:00
|
|
|
|
2011-08-11 00:30:03 -07:00
|
|
|
$this->data['Document']['type'] = 'quote';
|
|
|
|
|
break;
|
|
|
|
|
case "invoice":
|
2011-08-11 22:46:26 -07:00
|
|
|
|
|
|
|
|
$invoice_number_offset = 4436; //What Invoice number we are up to. Starting at 4500 due to the data loss.
|
|
|
|
|
|
|
|
|
|
$number_of_invoices = $this->Document->Invoice->findCount();
|
|
|
|
|
|
|
|
|
|
$enquiry = $this->Document->Invoice->Enquiry->read(null, $enquiryid);
|
|
|
|
|
if(!$enquiry) {
|
|
|
|
|
$this->Session->setFlash('Invalid Enquiry ID');
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$newInvoiceNumber = $invoice_number_offset + $number_of_invoices;
|
|
|
|
|
$this->data['Invoice']['enquiry_id'] = $enquiryid;
|
|
|
|
|
$this->data['Invoice']['title'] = "CMCIN".$newInvoiceNumber;
|
|
|
|
|
$this->data['Invoice']['job_id'] = $jobid;
|
|
|
|
|
$this->data['Invoice']['customer_id'] = $enquiry['Enquiry']['customer_id'];
|
|
|
|
|
|
|
|
|
|
$this->data['Document']['user_id']= $enquiry['Enquiry']['user_id'];
|
|
|
|
|
//$number_of_revisions = $this->Document->Invoice->findCount('Invoice.enquiry_id ='. $enquiryid);
|
|
|
|
|
$this->data['Document']['revision'] = 0; //No revisions for Invoices. I have decreed it!
|
|
|
|
|
$this->data['Document']['type'] = 'invoice';
|
|
|
|
|
|
|
|
|
|
$this->data['Invoice']['issue_date'] = date('Y-m-d'); //Argh. Quote model uses 'date_issed'.
|
2011-08-14 23:04:38 -07:00
|
|
|
$this->data['Invoice']['due_date'] = date("Y-m-d", strtotime("+30 days"));
|
2011-08-11 22:46:26 -07:00
|
|
|
|
|
|
|
|
|
2011-08-14 23:04:38 -07:00
|
|
|
$this->data['Invoice']['currency_id'] = 2; //All new Invoices default to AUD.
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case "purchaseOrder":
|
2011-08-11 22:46:26 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-11 00:30:03 -07:00
|
|
|
break;
|
|
|
|
|
case "orderAck":
|
2011-08-11 22:46:26 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-11 00:30:03 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->Document->saveAll($this->data)) {
|
|
|
|
|
$newid = $this->Document->id;
|
|
|
|
|
|
|
|
|
|
$this->Session->setFlash(__('The Document has been saved', true));
|
|
|
|
|
$this->redirect(array('action'=>'view',$newid));
|
|
|
|
|
} else {
|
|
|
|
|
$this->Session->setFlash(__('The Document could not be saved. Please, try again.', true));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Revise a Document.
|
|
|
|
|
*
|
|
|
|
|
* @param int $id - the document ID we want to make a new revision of.
|
|
|
|
|
* @return <type>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
function revise($id = null) {
|
|
|
|
|
if(!$id) {
|
|
|
|
|
$this->Session->setFlash('Invalid Document ID');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$document = $this->Document->find('first', array('conditions' => array('Document.id' => $id)));
|
|
|
|
|
|
|
|
|
|
$this->set('document', $document);
|
|
|
|
|
|
|
|
|
|
if(!empty($document['Invoice']['id'])) {
|
|
|
|
|
echo "WE HAVE AN INVOICE";
|
|
|
|
|
}
|
|
|
|
|
else if (!empty($document['Quote']['id'])) {
|
2011-08-11 22:46:26 -07:00
|
|
|
|
|
|
|
|
//First setup the Date and default valid until date. (30 days from today).
|
|
|
|
|
|
|
|
|
|
$today_date = date("Y-m-d");
|
|
|
|
|
$valid_until = date("Y-m-d", strtotime("+30 days"));
|
|
|
|
|
|
|
|
|
|
$newDoc = array();
|
|
|
|
|
|
2011-08-14 23:04:38 -07:00
|
|
|
|
2011-08-11 22:46:26 -07:00
|
|
|
$newDoc['Quote'] = $this->unset_keys($document['Quote'], array('id','created'));
|
|
|
|
|
|
|
|
|
|
$newDoc['Quote']['date_issued'] = $today_date;
|
|
|
|
|
$newDoc['Quote']['days_valid'] = 30;
|
|
|
|
|
$newDoc['Quote']['valid_until'] = $valid_until;
|
|
|
|
|
|
|
|
|
|
$enquiryid = $document['Quote']['enquiry_id'];
|
|
|
|
|
$number_of_revisions = $this->Document->Quote->findCount('Quote.enquiry_id ='. $enquiryid);
|
|
|
|
|
$newDoc['Document']['revision'] = $number_of_revisions;
|
|
|
|
|
$newDoc['Document']['type'] = 'quote';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$newDoc['DocPage'] = $document['DocPage'];
|
|
|
|
|
|
|
|
|
|
foreach($newDoc['DocPage'] as $index => $li) {
|
|
|
|
|
$newDoc['DocPage'][$index]['id'] = null;
|
|
|
|
|
$newDoc['DocPage'][$index]['document_id'] = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-11 00:30:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (!empty($document['PurchaseOrder']['id'])) {
|
|
|
|
|
echo "WE ARE REVISING A PO";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else if (!empty($document['OrderAcknowledgement']['id'])) {
|
|
|
|
|
echo "WE ARE REVISING An ORDER ACK";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-08-11 22:46:26 -07:00
|
|
|
/** Copy the LineItems from this Document. Applies to all of the Document Types */
|
|
|
|
|
if(!empty($document['LineItem'])) {
|
|
|
|
|
$newDoc['LineItem'] = $document['LineItem'];
|
|
|
|
|
foreach($newDoc['LineItem'] as $index => $li) {
|
|
|
|
|
$newDoc['LineItem'][$index]['id'] = null;
|
|
|
|
|
$newDoc['LineItem'][$index]['document_id'] = null;
|
|
|
|
|
$newDoc['LineItem'][$index]['costing_id'] = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->set('newDoc', $newDoc);
|
2011-08-11 00:30:03 -07:00
|
|
|
|
2011-08-11 22:46:26 -07:00
|
|
|
if ($this->Document->saveAll($newDoc)) {
|
|
|
|
|
$newid = $this->Document->id;
|
|
|
|
|
|
|
|
|
|
$this->Session->setFlash(__("Revision {$number_of_revisions} created", true));
|
|
|
|
|
$this->redirect(array('action'=>'view',$newid));
|
|
|
|
|
} else {
|
|
|
|
|
$this->Session->setFlash(__('The Document could not be saved. Please, try again.', true));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2010-07-07 23:18:04 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new Quote, along with its associated Document and the first two pages.
|
|
|
|
|
* @param int $id - the Enquiry ID that this quote belongs to.
|
|
|
|
|
*/
|
|
|
|
|
function newInvoice($id = null) {
|
2011-05-19 00:05:01 -07:00
|
|
|
$enquiryid = $id;
|
|
|
|
|
$this->Document->create();
|
2010-07-07 23:18:04 -07:00
|
|
|
|
2011-05-24 02:11:07 -07:00
|
|
|
$enquiry = $this->Document->Quote->Enquiry->findById($id);
|
2010-07-07 23:18:04 -07:00
|
|
|
|
2011-05-19 00:05:01 -07:00
|
|
|
$this->data['Document']['enquiry_id'] = $enquiryid;
|
2010-07-07 23:18:04 -07:00
|
|
|
|
2011-05-19 00:05:01 -07:00
|
|
|
$this->data['Invoice']['enquiry_id'] = $enquiryid;
|
|
|
|
|
$invoice_number_offset = 4436; //What Invoice number we were up to before the new system.
|
|
|
|
|
$number_of_invoices = $this->Document->Invoice->findCount();
|
2010-07-07 23:18:04 -07:00
|
|
|
|
2011-05-19 00:05:01 -07:00
|
|
|
$newInvoiceNumber = $invoice_number_offset + $number_of_invoices;
|
2010-07-07 23:18:04 -07:00
|
|
|
|
2011-05-19 00:05:01 -07:00
|
|
|
$this->data['Invoice']['title'] = "CMCIN".$newInvoiceNumber;
|
|
|
|
|
$this->data['Document']['user_id']= $enquiry['Enquiry']['user_id'];
|
2011-05-24 02:11:07 -07:00
|
|
|
$this->data['Document']['type'] = 'invoice';
|
2010-07-07 23:18:04 -07:00
|
|
|
|
2011-05-19 00:05:01 -07:00
|
|
|
if ($this->Document->saveAll($this->data)) {
|
|
|
|
|
$newid = $this->Document->id;
|
2010-07-07 23:18:04 -07:00
|
|
|
|
2011-05-19 00:05:01 -07:00
|
|
|
$this->Session->setFlash(__('The Document has been saved', true));
|
|
|
|
|
$this->redirect(array('action'=>'view',$newid));
|
|
|
|
|
} else {
|
|
|
|
|
$this->Session->setFlash(__('The Document could not be saved. Please, try again.', true));
|
|
|
|
|
}
|
2010-07-07 23:18:04 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-18 16:46:22 -07:00
|
|
|
|
|
|
|
|
|
2011-05-24 02:11:07 -07:00
|
|
|
function ajax_edit($id = null) {
|
2011-05-19 00:05:01 -07:00
|
|
|
$this->layout = 'ajax';
|
|
|
|
|
|
|
|
|
|
if (!$id && empty($this->data)) {
|
|
|
|
|
echo 'Invalid Document ID';
|
|
|
|
|
}
|
|
|
|
|
if (!empty($this->data)) {
|
|
|
|
|
$docID = $this->data['Document']['id'];
|
|
|
|
|
$this->Document->DocPage->deleteAll(array('document_id'=>$docID));
|
2011-05-18 16:46:22 -07:00
|
|
|
$this->Document->DocPage->updateCounterCache(array('document_id'=>$docID));
|
2011-05-19 00:05:01 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->Document->saveAll($this->data)) {
|
|
|
|
|
echo 'SUCCESS';
|
|
|
|
|
} else {
|
|
|
|
|
echo 'FAILURE';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
echo 'FAILURE';
|
|
|
|
|
}
|
2010-07-07 23:18:04 -07:00
|
|
|
}
|
|
|
|
|
|
2011-05-24 02:11:07 -07:00
|
|
|
|
|
|
|
|
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;
|
2011-08-08 23:33:21 -07:00
|
|
|
|
2011-05-24 02:11:07 -07:00
|
|
|
$docType = $this->Document->getDocType($document);
|
|
|
|
|
$docTypeFullName = $this->Document->getDocFullName($docType);
|
2011-08-08 23:33:21 -07:00
|
|
|
|
2011-05-24 02:11:07 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
$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']);
|
2011-06-23 00:03:24 -07:00
|
|
|
$this->set('currencySymbol', $currency['Currency']['symbol']);
|
2011-05-24 02:11:07 -07:00
|
|
|
|
|
|
|
|
$gst = $enquiry['Enquiry']['gst'];
|
|
|
|
|
|
|
|
|
|
$this->set('gst', $gst);
|
|
|
|
|
|
|
|
|
|
if($gst == 1) {
|
|
|
|
|
$totalsDescText = array(
|
2011-08-08 23:33:21 -07:00
|
|
|
'subtotal' => 'SUB-TOTAL (EXCLUDING GST)',
|
|
|
|
|
'gst' => 'GST (10%)',
|
|
|
|
|
'total' => 'TOTAL PAYABLE (INCLUDING GST)'
|
2011-05-24 02:11:07 -07:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$totalsDescText = array(
|
2011-08-08 23:33:21 -07:00
|
|
|
'subtotal' => 'SUB-TOTAL',
|
|
|
|
|
'gst' => 'GST (10%)',
|
|
|
|
|
'total' => 'TOTAL PAYABLE'
|
2011-05-24 02:11:07 -07:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$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']);
|
2011-08-15 17:36:48 -07:00
|
|
|
$this->set('states', $this->Document->Invoice->Enquiry->State->find('list'));
|
2011-05-24 02:11:07 -07:00
|
|
|
|
|
|
|
|
|
2011-08-14 23:04:38 -07:00
|
|
|
//Set filename for the document.
|
|
|
|
|
//
|
|
|
|
|
switch($docType) {
|
|
|
|
|
case "quote":
|
|
|
|
|
$filename = $enquiry['Enquiry']['title'];
|
2011-08-15 17:36:48 -07:00
|
|
|
$template_name = 'pdf_quote';
|
2011-08-14 23:04:38 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "invoice":
|
|
|
|
|
$filename = $document['Invoice']['title'];
|
2011-08-15 17:36:48 -07:00
|
|
|
$this->set('job', $this->Document->Invoice->Job->find('first', array('conditions'=>array('Job.id'=>$document['Invoice']['job_id']))));
|
|
|
|
|
$template_name = 'pdf_invoice';
|
2011-08-14 23:04:38 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "purchaseOrder":
|
|
|
|
|
$filename = $document['PurchaseOrder']['title'];
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "orderAck":
|
|
|
|
|
$filename = $document['Job']['title'];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-11 22:46:26 -07:00
|
|
|
if($document['Document']['revision'] > 0) {
|
2011-08-14 23:04:38 -07:00
|
|
|
$filename = $filename.'_'.$document['Document']['revision'].'.pdf';
|
2011-08-08 23:33:21 -07:00
|
|
|
}
|
|
|
|
|
else {
|
2011-08-14 23:04:38 -07:00
|
|
|
$filename = $filename.'.pdf';
|
2011-08-08 23:33:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->set('filename', $filename);
|
|
|
|
|
$document['Document']['pdf_filename'] = $filename;
|
|
|
|
|
$document['Document']['pdf_created_at'] = date('Y-m-d H:i:s');
|
|
|
|
|
$document['Document']['pdf_created_by_user_id'] = $this->getCurrentUserID();
|
|
|
|
|
if($this->Document->save($document)) {
|
2011-08-09 01:54:10 -07:00
|
|
|
//echo "Set pdf_filename attritbute to: ".$filename;
|
2011-08-08 23:33:21 -07:00
|
|
|
}
|
|
|
|
|
else {
|
2011-08-09 01:54:10 -07:00
|
|
|
//echo 'Failed to set pdf_filename to: '.$filename;
|
2011-08-08 23:33:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-05-24 02:11:07 -07:00
|
|
|
$colWidths = array(
|
2011-08-08 23:33:21 -07:00
|
|
|
'item' => '8%',
|
|
|
|
|
'qty' => '8%',
|
|
|
|
|
'desc' => '60%',
|
|
|
|
|
'unit' => '12%',
|
|
|
|
|
'total' => '12%'
|
2011-05-24 02:11:07 -07:00
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->set('colWidths',$colWidths);
|
2011-08-15 17:36:48 -07:00
|
|
|
|
|
|
|
|
$this->render($template_name);
|
2011-05-24 02:11:07 -07:00
|
|
|
}
|
|
|
|
|
|
2011-08-11 00:30:03 -07:00
|
|
|
|
|
|
|
|
//Called via AJAX to generate Quotation First Pages.
|
2011-06-15 01:26:22 -07:00
|
|
|
function generateFirstPage($id = null) {
|
|
|
|
|
$this->layout = 'ajax';
|
|
|
|
|
|
|
|
|
|
if(!$id) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$document = $this->Document->read(null, $id);
|
|
|
|
|
$this->set('document',$document);
|
|
|
|
|
$enquiry = $this->Document->Quote->Enquiry->read(null, $document['Quote']['enquiry_id']);
|
|
|
|
|
$this->set('enquiry', $enquiry);
|
|
|
|
|
}
|
2010-07-07 23:18:04 -07:00
|
|
|
|
2011-08-08 23:33:21 -07:00
|
|
|
|
2010-07-07 23:18:04 -07:00
|
|
|
}
|
|
|
|
|
?>
|