diff --git a/app/config/core.php b/app/config/core.php index d3eb62bd..cd9d2ab4 100644 --- a/app/config/core.php +++ b/app/config/core.php @@ -42,7 +42,7 @@ */ Configure::write('debug', 0); -Configure::write('version', '0.9.8'); +Configure::write('version', '0.9.9'); $host = $_SERVER['HTTP_HOST']; diff --git a/app/controllers/documents_controller.php b/app/controllers/documents_controller.php index d746d712..0fc891fd 100755 --- a/app/controllers/documents_controller.php +++ b/app/controllers/documents_controller.php @@ -82,9 +82,12 @@ class DocumentsController extends AppController { $this->set('currencies', $this->Document->OrderAcknowledgement->Currency->find('list')); $this->set('job', $this->Document->OrderAcknowledgement->Job->find('first', array('conditions'=>array('Job.id'=>$document['OrderAcknowledgement']['job_id'])))); $docTypeElement = 'document_orderack_view'; + break; case 'packingList': $docTypeElement = 'document_packinglist_view'; + $this->set('currencies', $this->Document->Invoice->Currency->find('list')); + $this->set('packing_list', $this->Document->PackingList->find('first', array('conditions'=>array('PackingList.id'=>$document['PackingList']['id'])))); break; } @@ -288,6 +291,60 @@ class DocumentsController extends AppController { case "packingList"; + $this->data['Document']['type'] = 'packingList'; + + + $packing_number_offset = 6500; //What PL number we are up to. Starting at 6500 to avoid conflicts + + $number_of_packinglists = $this->Document->PackingList->findCount(); + + $enquiry = $this->Document->PackingList->Enquiry->read(null, $enquiryid); + if(!$enquiry) { + $this->Session->setFlash('Invalid Enquiry ID'); + $this->redirect(array('action'=>'index')); + return; + } + + $newPackingNumber = $packing_number_offset + $number_of_packinglists; + $this->data['PackingList']['enquiry_id'] = $enquiryid; + $this->data['PackingList']['title'] = "CMCPL".$newPackingNumber; + $this->data['PackingList']['job_id'] = $jobid; + $this->data['PackingList']['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'] = 'packingList'; + + $this->data['PackingList']['issue_date'] = date('Y-m-d'); //Argh. Quote model uses 'date_issed'. + + + + + if(isset($source_document_id)) { + //This is not ideal. But nothing else is either. + $sourceDoc = $this->Document->find('first', array('conditions' => array('Document.id' => $source_document_id))); + + $source_attribues = array( + 'ship_via', + 'fob', + 'estimated_delivery' + ); + + if($sourceDoc['Document']['type'] == 'orderAck') { + foreach($oa_attribues as $attr) { + $this->data['PackingList'][$attr] = $sourceDoc['OrderAcknowledgement'][$attr]; + } + } + if($sourceDoc['Document']['type'] == 'invoice') { + foreach($oa_attribues as $attr) { + $this->data['PackingList'][$attr] = $sourceDoc['Invoice'][$attr]; + } + } + + + } + break; @@ -581,8 +638,6 @@ class DocumentsController extends AppController { $this->set('ship_via', $document['Invoice']['ship_via']); $this->set('fob', $document['Invoice']['fob']); - - $template_name = 'pdf_invoice'; break; @@ -609,6 +664,18 @@ class DocumentsController extends AppController { $template_name = 'pdf_orderack'; break; + case "packingList": + $filename = $document['PackingList']['title']; + $this->set('docTitle', $document['PackingList']['title']); + $this->set('job', $this->Document->PackingList->Job->find('first', array('conditions'=>array('Job.id'=>$document['PackingList']['job_id'])))); + $this->set('issue_date_string', date('d F Y', strtotime($document['PackingList']['issue_date']))); + + $this->set('ship_via', $document['PackingList']['ship_via']); + $this->set('fob', $document['PackingList']['fob']); + $template_name = 'pdf_packinglist'; + + break; + } if($document['Document']['revision'] > 0) { diff --git a/app/migrations/10_6_2013_add_packing_list.sql b/app/migrations/10_6_2013_add_packing_list.sql new file mode 100644 index 00000000..a6449866 --- /dev/null +++ b/app/migrations/10_6_2013_add_packing_list.sql @@ -0,0 +1,17 @@ + + CREATE TABLE `quotenik`.`packing_lists` ( `id` int( 11 ) NOT NULL AUTO_INCREMENT , + `currency_id` int( 11 ) DEFAULT NULL , + `created` datetime NOT NULL , + `issue_date` date NOT NULL , + `due_date` date NOT NULL , + `title` varchar( 255 ) NOT NULL COMMENT 'CMC Invoice Number String', + `paid` tinyint( 1 ) NOT NULL DEFAULT '0' COMMENT 'PAID or UNPAID', + `payment_received_date` date NOT NULL , + `ship_via` varchar( 255 ) NOT NULL , + `fob` varchar( 255 ) NOT NULL , + `enquiry_id` int( 11 ) NOT NULL , + `job_id` int( 11 ) NOT NULL , + `user_id` int( 11 ) NOT NULL , + `document_id` int( 11 ) DEFAULT NULL , + `customer_id` int( 11 ) NOT NULL , + UNIQUE KEY `id` ( `id` ) ) ENGINE = MyISAM DEFAULT CHARSET = latin1; diff --git a/app/14_11_2011_add_myob_fields_to_products.sql b/app/migrations/14_11_2011_add_myob_fields_to_products.sql similarity index 100% rename from app/14_11_2011_add_myob_fields_to_products.sql rename to app/migrations/14_11_2011_add_myob_fields_to_products.sql diff --git a/app/27_9_2011_shipment_invoices.sql b/app/migrations/27_9_2011_shipment_invoices.sql similarity index 100% rename from app/27_9_2011_shipment_invoices.sql rename to app/migrations/27_9_2011_shipment_invoices.sql diff --git a/app/models/document.php b/app/models/document.php index 29fa542e..ee477c80 100755 --- a/app/models/document.php +++ b/app/models/document.php @@ -57,6 +57,10 @@ class Document extends AppModel { 'OrderAcknowledgement' => array( 'className' => 'OrderAcknowledgement', 'foreignKey' => 'document_id' + ), + 'PackingList' => array( + 'className' => 'PackingList', + 'foreignKey' => 'document_id' ) ); @@ -113,6 +117,9 @@ class Document extends AppModel { case 'orderAck': $fullName = 'Order Acknowledgement'; break; + case 'packingList': + $fullName = 'Packing List'; + break; } return $fullName; } @@ -146,6 +153,9 @@ class Document extends AppModel { elseif(!empty($document['Quote']['id'])) { return $this->Quote->Enquiry->find('first',array('conditions'=>array('Enquiry.id'=>$document['Quote']['enquiry_id']))); } + elseif(!empty($document['PackingList']['id'])) { + return $this->PackingList->Enquiry->find('first',array('conditions'=>array('Enquiry.id'=>$document['PackingList']['enquiry_id']))); + } elseif(!empty($document['PurchaseOrder']['id'])) { //No enquiries for POs. We want the Jobs. return; diff --git a/app/models/packing_list.php b/app/models/packing_list.php new file mode 100755 index 00000000..d40c7d5c --- /dev/null +++ b/app/models/packing_list.php @@ -0,0 +1,41 @@ + array('date'), + 'title' => array('notempty'), + 'enquiry_id' => array('numeric'), + 'user_id' => array('numeric') + ); + + //The Associations below have been created with all possible keys, those that are not needed can be removed + var $belongsTo = array( + 'Enquiry' => array( + 'className' => 'Enquiry', + 'foreignKey' => 'enquiry_id', + 'counterCache'=> true + ), + 'Customer' => array( + 'className' => 'Customer', + 'foreignKey' => 'customer_id' + ), + 'Job' => array( + 'className' => 'Job', + 'foreignKey' => 'job_id' + ), + 'Currency' => array( + 'className' => 'Currency', + 'foreignKey' => 'currency_id' + ), + 'Document' => array( + 'className' => 'Document', + 'foreignKey' => 'document_id' + ) + ); + +} +?> diff --git a/app/views/documents/pdf_packinglist.ctp b/app/views/documents/pdf_packinglist.ctp new file mode 100755 index 00000000..6f5a8841 --- /dev/null +++ b/app/views/documents/pdf_packinglist.ctp @@ -0,0 +1,38 @@ +SetPrintHeader(false); +$pdfdoc->SetPrintFooter(false); + + +$pdfdoc->AddPage(); +$pdfdoc->Page1Header(); + +$pageTitle = "
| ITEM NO. |
+ QTY | +DESCRIPTION | ++ | + |
|---|---|---|---|---|
| + | + | + | =$currencyCode?> | +=$currencyCode?> | +
|
+ if($li['option'] == 1) {
+ echo 'Option '; + $hasOptions = true; + } + ?> + =$li['item_number'];?> + |
+ =$decimal->formatDecimal($li['quantity']);?> | +=$li['title'];?> =$li['description'];?> |
+ + + | ++ | +
| FREIGHT DETAILS: + | ++ | + | +||
| =$document['Document']['shipping_details'];?> | ++ | + | +||
| + | ++ | +|||