diff --git a/controllers/documents_controller.php b/controllers/documents_controller.php index c53ba0cf..24f66078 100755 --- a/controllers/documents_controller.php +++ b/controllers/documents_controller.php @@ -47,12 +47,19 @@ class DocumentsController extends AppController { break; case 'invoice': $docTypeElement = 'document_invoice_view'; + + $this->set('currencies', $this->Document->Invoice->Currency->find('list')); $this->set('invoice', $this->Document->Invoice->find('first', array('conditions'=>array('Invoice.id'=>$document['Invoice']['id'])))); break; case 'purchaseOrder': $docTypeElement = 'document_purchase_order_view'; break; + + case 'orderAck': + $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'; } $this->set('docTypeElement', $docTypeElement); @@ -161,13 +168,16 @@ class DocumentsController extends AppController { break; case "purchaseOrder": - - - break; case "orderAck": - + $enquiry = $this->Document->OrderAcknowledgement->Enquiry->read(null, $enquiryid); + $this->data['OrderAcknowledgement']['job_id'] = $jobid; + $this->data['OrderAcknowledgement']['enquiry_id'] = $enquiryid; + $this->data['OrderAcknowledgement']['currency_id'] = 2; //Default to AUD. + $this->data['Document']['user_id']= $enquiry['Enquiry']['user_id']; + $this->data['Document']['revision'] = 0; //No revisions for Order Acks. I have decreed it! + $this->data['Document']['type'] = 'orderAck'; break; @@ -179,7 +189,7 @@ class DocumentsController extends AppController { $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)); + $this->Session->setFlash(__('The Document could not be saved. Something went wrong! Ensure all fields are entered correctly.', true)); } @@ -276,41 +286,6 @@ class DocumentsController extends AppController { } - /** - * 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) { - $enquiryid = $id; - $this->Document->create(); - - $enquiry = $this->Document->Quote->Enquiry->findById($id); - - $this->data['Document']['enquiry_id'] = $enquiryid; - - $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(); - - $newInvoiceNumber = $invoice_number_offset + $number_of_invoices; - - $this->data['Invoice']['title'] = "CMCIN".$newInvoiceNumber; - $this->data['Document']['user_id']= $enquiry['Enquiry']['user_id']; - $this->data['Document']['type'] = 'invoice'; - - 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)); - } - - - } - - function ajax_edit($id = null) { $this->layout = 'ajax'; @@ -369,14 +344,14 @@ class DocumentsController extends AppController { if($gst == 1) { $totalsDescText = array( - 'subtotal' => 'SUB-TOTAL (EXCLUDING GST)', + 'subtotal' => 'SUBTOTAL', 'gst' => 'GST (10%)', - 'total' => 'TOTAL PAYABLE (INCLUDING GST)' + 'total' => 'TOTAL DUE' ); } else { $totalsDescText = array( - 'subtotal' => 'SUB-TOTAL', + 'subtotal' => 'SUBTOTAL', 'gst' => 'GST (10%)', 'total' => 'TOTAL PAYABLE' ); @@ -386,49 +361,6 @@ class DocumentsController extends AppController { $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); @@ -449,7 +381,14 @@ class DocumentsController extends AppController { case "invoice": $filename = $document['Invoice']['title']; + $this->set('docTitle', $document['Invoice']['title']); $this->set('job', $this->Document->Invoice->Job->find('first', array('conditions'=>array('Job.id'=>$document['Invoice']['job_id'])))); + $this->set('issue_date_string', date('d F Y', strtotime($document['Invoice']['issue_date']))); + + $this->set('ship_via', $document['Invoice']['ship_via']); + $this->set('fob', $document['Invoice']['fob']); + + $template_name = 'pdf_invoice'; break; @@ -458,7 +397,21 @@ class DocumentsController extends AppController { break; case "orderAck": - $filename = $document['Job']['title']; + + $job = $this->Document->OrderAcknowledgement->Job->find('first', array('conditions'=>array('Job.id'=>$document['OrderAcknowledgement']['job_id']))); + + $filename = $job['Job']['title'].'_OrderAcknowledgement'; + $this->set('docTitle', $job['Job']['title']); + + $this->set('docTypeFullName', 'JOB'); //So it doesnt say CMC order Ack # in the pdf_shipping_billing_box. This string is too long + $this->set('job', $job); + $this->set('issue_date_string', date('d F Y', strtotime($document['OrderAcknowledgement']['issue_date']))); + + $this->set('ship_via', $document['OrderAcknowledgement']['ship_via']); + $this->set('fob', $document['OrderAcknowledgement']['fob']); + $this->set('estimated_delivery', $document['OrderAcknowledgement']['estimated_delivery']); + + $template_name = 'pdf_orderack'; break; } @@ -482,11 +435,11 @@ class DocumentsController extends AppController { $colWidths = array( - 'item' => '8%', - 'qty' => '8%', - 'desc' => '60%', - 'unit' => '12%', - 'total' => '12%' + 'item' => '7%', + 'qty' => '7%', + 'desc' => '56%', + 'unit' => '15%', + 'total' => '15%' ); diff --git a/controllers/invoices_controller.php b/controllers/invoices_controller.php index 307e071b..64a15db1 100755 --- a/controllers/invoices_controller.php +++ b/controllers/invoices_controller.php @@ -44,47 +44,9 @@ class InvoicesController extends AppController { - function add() { //No longer creating invoices directly. Done through the Documents Controller + - if (!empty($this->data)) { - $this->Invoice->create(); - - $invoice_number_offset = 4436; //What Invoice number we are up to. Starting at 4500 due to the data loss. - - $number_of_invoices = $this->Invoice->findCount(); - - $newInvoiceNumber = $invoice_number_offset + $number_of_invoices; - - $this->data['Invoice']['title'] = "CMCIN".$newInvoiceNumber; - - $enqid = $this->data['Invoice']['enquiry_id']; - - - if ($this->Invoice->save($this->data)) { - $this->Session->setFlash(__('The Invoice has been saved', true)); - $this->redirect(array('controller'=>'enquiries', 'action'=>'view/'.$enqid)); - } else { - $this->Session->setFlash(__('The Invoice could not be saved. Please, try again.', true)); - } - } - else { - if(isset($this->params['named']['enquiryid'])) { - $enquiryid = $this->params['named']['enquiryid']; - $enquiry = $this->Invoice->Enquiry->findById($enquiryid); - - $jobs = $this->Invoice->Job->find('list', array('conditions'=>array('Job.enquiry_id'=>$enquiryid))); - - $user = $this->Auth->user(); - $this->set(compact('enquiry', 'user','jobs')); - } - else { - $this->Session->setFlash(__('Invalid Enquiry ID', true)); - $this->redirect(array('action'=>'index')); - } - } - } - - /* function edit($id = null) { + /*function edit($id = null) { if (!$id && empty($this->data)) { $this->Session->setFlash(__('Invalid Invoice', true)); $this->redirect(array('action'=>'index')); diff --git a/models/address.php b/models/address.php index d0f698c7..342e85a4 100755 --- a/models/address.php +++ b/models/address.php @@ -1,73 +1,73 @@ array( - 'rule' => array('notEmpty'), - 'message' => 'Please Enter the Addess', - 'required' => true, - 'allowEmpty' => false - ), - - 'city' => array( - 'rule' => array('notEmpty'), - 'message' => 'Please Enter the City', - 'required' => true, - 'allowEmpty' => false - ), - 'state_id' => array( - 'rule' => array('notEmpty'), - 'message' => 'Please select the State', - 'required' => true, - 'allowEmpty' => false - ), - 'postcode' => array( - 'rule' => array('notEmpty'), - 'message' => 'Please enter the Post Code', - 'required' => true, - 'allowEmpty' => false - ), - 'country_id' => array( - 'rule' => array('notEmpty'), - 'message' => 'Please select the Country', - 'required' => true, - 'allowEmpty' => false - ), - 'type' => array( - 'rule' => array('notEmpty'), - 'message' => 'Please select the Type of Address', - 'required' => true, - 'allowEmpty' => false - ), - ); - - + var $validate = array( + 'address' => array( + 'rule' => array('notEmpty'), + 'message' => 'Please Enter the Addess', + 'required' => true, + 'allowEmpty' => false + ), - //The Associations below have been created with all possible keys, those that are not needed can be removed - var $belongsTo = array( - 'Customer' => array('className' => 'Customer', - 'foreignKey' => 'customer_id', - 'conditions' => '', - 'fields' => '', - 'order' => '' - ), - - 'State' => array('className' => 'State', - 'foreignKey' => 'state_id', - 'conditions' => '', - 'fields' => '', - 'order' => ''), - - 'Country' => array('className' => 'Country', - 'foreignKey' => 'country_id', - 'conditions' => '', - 'fields' => '', - 'order' => '' - - - )); + 'city' => array( + 'rule' => array('notEmpty'), + 'message' => 'Please Enter the City', + 'required' => true, + 'allowEmpty' => false + ), + 'state_id' => array( + 'rule' => array('notEmpty'), + 'message' => 'Please select the State', + 'required' => true, + 'allowEmpty' => false + ), + 'postcode' => array( + 'rule' => array('notEmpty'), + 'message' => 'Please enter the Post Code', + 'required' => true, + 'allowEmpty' => false + ), + 'country_id' => array( + 'rule' => array('notEmpty'), + 'message' => 'Please select the Country', + 'required' => true, + 'allowEmpty' => false + ), + 'type' => array( + 'rule' => array('notEmpty'), + 'message' => 'Please select the Type of Address', + 'required' => true, + 'allowEmpty' => false + ), + ); + + + + //The Associations below have been created with all possible keys, those that are not needed can be removed + var $belongsTo = array( + 'Customer' => array('className' => 'Customer', + 'foreignKey' => 'customer_id', + 'conditions' => '', + 'fields' => '', + 'order' => '' + ), + + 'State' => array('className' => 'State', + 'foreignKey' => 'state_id', + 'conditions' => '', + 'fields' => '', + 'order' => ''), + + 'Country' => array('className' => 'Country', + 'foreignKey' => 'country_id', + 'conditions' => '', + 'fields' => '', + 'order' => '' + + + )); } ?> diff --git a/models/document.php b/models/document.php index 6a2b11e7..81b31c16 100755 --- a/models/document.php +++ b/models/document.php @@ -53,6 +53,8 @@ class Document extends AppModel { ) ); + + //So much refactoring possible on this. function getCurrency($document) { if(!empty($document['Invoice']['id'])) { @@ -73,6 +75,11 @@ class Document extends AppModel { $conditions = $this->__getCurrencyConditions($currencyID); return $this->PurchaseOrder->Currency->find('first',$conditions); } + elseif(!empty($document['OrderAcknowledgement']['id'])) { + $currencyID = $document['OrderAcknowledgement']['currency_id']; + $conditions = $this->__getCurrencyConditions($currencyID); + return $this->OrderAcknowledgement->Currency->find('first',$conditions); + } } @@ -136,6 +143,10 @@ class Document extends AppModel { elseif(!empty($document['PurchaseOrder']['id'])) { return $this->PurchaseOrder->Enquiry->find('first',array('conditions'=>array('Enquiry.id'=>$document['Invoice']['enquiry_id']))); } + elseif(!empty($document['OrderAcknowledgement']['id'])) { + return $this->OrderAcknowledgement->Enquiry->find('first',array('conditions'=>array('Enquiry.id'=>$document['OrderAcknowledgement']['enquiry_id']))); + + } } /** * Does GST apply on this document. Based on the Enquiry GST TinyInt. diff --git a/models/enquiry.php b/models/enquiry.php index a9b99710..6ac82308 100755 --- a/models/enquiry.php +++ b/models/enquiry.php @@ -177,6 +177,10 @@ class Enquiry extends AppModel { 'Job' => array('className' => 'Job', 'foreignKey' =>'enquiry_id'), + 'OrderAcknowledgement' => array('className'=>'OrderAcknowledgement', 'foreignKey'=>'enquiry_id') + + + ); diff --git a/models/order_acknowledgement.php b/models/order_acknowledgement.php new file mode 100755 index 00000000..53705524 --- /dev/null +++ b/models/order_acknowledgement.php @@ -0,0 +1,33 @@ + array('numeric'), + 'revision' => array('alphanumeric'), + 'deliverytime' => array('alphanumeric'), + 'paymentterms' => array('alphanumeric'), + 'daysvalid' => 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', + 'conditions' => '', + 'fields' => '', + 'order' => '', + 'counterCache'=>true + ), + + 'Currency' => array('className' => 'Currency', 'foreignKey' => 'currency_id'), + + 'Document' => array('className'=>'Document', 'foreignKey'=>'document_id'), + + 'Job' => array('className'=>'Job', 'foreignKey'=>'job_id') + ); + + +} +?> \ No newline at end of file diff --git a/views/documents/pdf_invoice.ctp b/views/documents/pdf_invoice.ctp index f0bdecd0..0c536569 100644 --- a/views/documents/pdf_invoice.ctp +++ b/views/documents/pdf_invoice.ctp @@ -14,22 +14,23 @@ $pageTitle = "
| ITEM NO. |
QTY | DESCRIPTION | diff --git a/views/elements/line_items_table_with_shipping.ctp b/views/elements/line_items_table_with_shipping.ctp new file mode 100644 index 00000000..23a2234a --- /dev/null +++ b/views/elements/line_items_table_with_shipping.ctp @@ -0,0 +1,101 @@ +|||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ITEM NO. |
+ QTY | +DESCRIPTION | +UNIT PRICE |
+ TOTAL PRICE |
+
|---|---|---|---|---|
| + | + | + | =$currencyCode?> | +=$currencyCode?> | +
|
+ if($li['option'] == 1) {
+ echo 'Option '; + $hasOptions = true; + } + ?> + =$li['item_number'];?> + |
+ =$decimal->formatDecimal($li['quantity']);?> | +=$li['title'];?> =$li['description'];?> |
+
+
+ =$number->currency($li['gross_unit_price'], $currencyCode);?>
+ if($li['discount_percent']):?>
+ less =$li['discount_percent']?>% + discount* + (-=$number->currency($li['discount_amount_unit'], $currencyCode);?>) + = + =$number->currency($li['net_unit_price'], $currencyCode);?> + + |
+
+ =$number->currency($li['gross_price'], $currencyCode);?>
+ if($li['discount_percent']):?>
+ less =$li['discount_percent']?>% + discount* + (=$number->currency($li['discount_amount_total'], $currencyCode);?>) + = + =$number->currency($li['net_price'], $currencyCode);?> + + |
+
| SHIPPING DETAILS: + | +=$totalsDescText['subtotal']?> | ++ + if(!$hasOptions) { + echo $number->currency($totals['subtotal'], $currencyCode); + } + else { + echo $currencySymbol.'TBA'; + } + ?> | +||
| =$document['Document']['shipping_details'];?> | +=$totalsDescText['gst'];?> | ++ + if(!$hasOptions) { + echo $number->currency($totals['gst'], $currencyCode); + } + else { + echo $currencySymbol.'TBA'; + } + + ?> + | +||
| =$totalsDescText['total'];?> =$currencyCode?> |
+ + + if(!$hasOptions) { + echo $number->currency($totals['total'], $currencyCode); + } + else { + echo $currencySymbol.'TBA'; + } + ?> | +|||
| CUSTOMER ORDER NO | +CUSTOMER ORDER NO | CMC JOB # | FOB | SHIP VIA | @@ -49,9 +59,10 @@ $col3width = '30%';|||
| =$job['Job']['customer_order_number'];?> | =$job['Job']['title'];?> | -?? | -?? | +=$fob;?> | +=$ship_via;?> | =$job['Customer']['payment_terms'];?> | =$this->element('abn', array('abn'=>$job['Customer']['abn']));?> |
| Shipping Details | +
| =$document['Document']['shipping_details'];?> | +
| + |