From fbfc0a95431435a41d0091d01604caabef5991d7 Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Thu, 27 Jun 2013 00:03:24 +1000 Subject: [PATCH] Added primary contact to send emails to --- app/controllers/documents_controller.php | 29 ++++++++++++++++--- .../15_6_2013_add_extra_po_fields.sql | 2 +- app/vendors/pdfdoc.php | 8 ++--- app/views/documents/pdf_po.ctp | 3 +- .../elements/document_purchase_order_view.ctp | 13 ++++----- app/views/elements/line_items_table_po.ctp | 21 ++++++++++++++ app/views/principle_contacts/add.ctp | 1 + app/views/principle_contacts/edit.ctp | 1 + app/views/users/add_edit.ctp | 5 ++-- app/webroot/js/document_add_edit.js | 5 ++++ 10 files changed, 68 insertions(+), 20 deletions(-) diff --git a/app/controllers/documents_controller.php b/app/controllers/documents_controller.php index 039f0dcc..e6117c62 100755 --- a/app/controllers/documents_controller.php +++ b/app/controllers/documents_controller.php @@ -16,7 +16,6 @@ class DocumentsController extends AppController { function index() { $this->Document->recursive = 0; $this->set('documents', $this->paginate()); - $this->set('users', $this->Document->User->getUsersList()); } @@ -697,14 +696,27 @@ ENDINSTRUCTIONS; break; case "purchaseOrder": + $principle = $this->Document->LineItem->Product->Principle->find('first', array('conditions'=>array('Principle.id' => $document['PurchaseOrder']['principle_id']))); + $this->set('principle', $principle); + $purchase_order = $this->Document->PurchaseOrder->find('first', + array('conditions'=>array('PurchaseOrder.id' => $document['PurchaseOrder']['id']))); + $this->set('purchase_order', $purchase_order); + $totalsDescText = array( 'subtotal' => 'SUBTOTAL', - 'gst' => '', + 'gst' => 'GST', 'total' => 'ORDER TOTAL' ); //No GST for POs for now. - $totals = $this->calculateTotals($document, 0); + if($principle['Country']['id'] == 1) { + $totals = $this->calculateTotals($document, 1); + } + else { + $totalsDescText['gst'] = ''; + $totals = $this->calculateTotals($document, 0); + } + $this->set('totals',$totals); $this->set('totalsDescText',$totalsDescText); @@ -852,7 +864,16 @@ ENDINSTRUCTIONS; $this->set('invoice', $this->Document->Invoice->find('first', array('conditions'=>array('Invoice.id'=>$document['Invoice']['id'])))); break; case 'purchaseOrder': - $this->set('job', $this->Document->PurchaseOrder->Job->find('first', array('conditions'=>array('Job.id'=>$document['OrderAcknowledgement']['job_id'])))); + $primary_contact = $this->Document->User->find('first', array('conditions'=>array('User.principle_id' => $document['PurchaseOrder']['principle_id'],'User.primary_contact' => 1))); + if(empty($primary_contact)) { + + $this->Session->setFlash(__('Unable to sent. No primary Principle Contact', true)); + $this->redirect(array('action'=>'view/'.$id), null, false); + return; + } + + $this->Email->to = $primary_contact['User']['email']; + $this->set('job', $this->Document->PurchaseOrder->Job->find('first', array('conditions'=>array('Job.id'=>$document['OrderAcknowledgement']['job_id'])))); break; case 'orderAck': $this->set('job', $this->Document->OrderAcknowledgement->Job->find('first', array('conditions'=>array('Job.id'=>$document['OrderAcknowledgement']['job_id'])))); diff --git a/app/migrations/15_6_2013_add_extra_po_fields.sql b/app/migrations/15_6_2013_add_extra_po_fields.sql index 936fd112..ae915ba5 100644 --- a/app/migrations/15_6_2013_add_extra_po_fields.sql +++ b/app/migrations/15_6_2013_add_extra_po_fields.sql @@ -2,4 +2,4 @@ ALTER TABLE `purchase_orders` ADD `currency_id` INT NOT NULL; ALTER TABLE `purchase_orders` ADD `ordered_from` TEXT NOT NULL, ADD `description` TEXT NOT NULL, ADD `dispatch_by` VARCHAR(255) NOT NULL, ADD `deliver_to` TEXT NOT NULL, ADD `shipping_instructions` TEXT NOT NULL; - +ALTER TABLE `purchase_orders` ADD `jobs_text` VARCHAR( 512 ) NOT NULL diff --git a/app/vendors/pdfdoc.php b/app/vendors/pdfdoc.php index 6cdbadfc..e45541bf 100755 --- a/app/vendors/pdfdoc.php +++ b/app/vendors/pdfdoc.php @@ -15,11 +15,11 @@ class PDFDOC extends FPDI { function pageContent($content) { - $this->SetTextColor(0); - $this->SetFontSize(11); //Changed from 12 - $this->SetFont('times', ''); + $this->SetTextColor(0); + $this->SetFontSize(11); //Changed from 12 + $this->SetFont('times', ''); - $this->writeHTML($content, true, false, false, false, ''); + $this->writeHTML($content, true, false, false, false, ''); } diff --git a/app/views/documents/pdf_po.ctp b/app/views/documents/pdf_po.ctp index 04f9a71c..a977dd8a 100755 --- a/app/views/documents/pdf_po.ctp +++ b/app/views/documents/pdf_po.ctp @@ -6,6 +6,7 @@ $pdfdoc = new PDFDOC(); $pdfdoc->SetPrintHeader(false); $pdfdoc->SetPrintFooter(false); +$pdfdoc->SetPrintHeader(true); $pdfdoc->AddPage(); $pdfdoc->Page1Header(); @@ -19,9 +20,7 @@ $pageNo = $pdfdoc->PageNoFormatted(); $totalCount = $pdfdoc->getAliasNbPages(); $pdfdoc->AddPage(); - $LineItemTable = $this->element('line_items_table_po'); //Because fuck it. -$pdfdoc->SetPrintHeader(true); $pdfdoc->pageContent($LineItemTable); diff --git a/app/views/elements/document_purchase_order_view.ctp b/app/views/elements/document_purchase_order_view.ctp index 25600124..e06988d4 100755 --- a/app/views/elements/document_purchase_order_view.ctp +++ b/app/views/elements/document_purchase_order_view.ctp @@ -4,28 +4,25 @@
- +
- create('Document',array('type'=>'post','action'=>'edit', 'default'=>false)); echo $form->input('Document.id'); echo $form->input('PurchaseOrder.id'); echo $form->input('PurchaseOrder.principle_id'); echo $form->input('PurchaseOrder.principle_reference'); + echo $form->input('PurchaseOrder.description', array('type'=>'text')); ?>
input('job', array('id'=>'job_autocomplete', array('label'=>'Job (start typing and select from the list)'))); ?> - Items from the OA for this Job will be added automatically to the PO. + All Items from the OA for this Job will be added automatically to the PO.
    @@ -39,7 +36,9 @@
input('PurchaseOrder.jobs_text');?> + Jobs added above will appear in this field automatically.
You can add other things like CMC STOCK.
+input('PurchaseOrder.currency_id'); echo $form->input('PurchaseOrder.dispatch_date'); echo $form->input('PurchaseOrder.date_arrived'); //ARGH. Really Karl? diff --git a/app/views/elements/line_items_table_po.ctp b/app/views/elements/line_items_table_po.ctp index 1a81a6fe..5d9fac4d 100755 --- a/app/views/elements/line_items_table_po.ctp +++ b/app/views/elements/line_items_table_po.ctp @@ -1,3 +1,20 @@ +

+CONTRACT SUMMARY +

+ + + +

+ + + + + + +
CMC REF: + +
+

@@ -96,6 +113,10 @@
currency($totals['gst'], $currencyCode); + } } else { echo $currencySymbol.'TBA'; diff --git a/app/views/principle_contacts/add.ctp b/app/views/principle_contacts/add.ctp index ac0366ca..01c08ea8 100755 --- a/app/views/principle_contacts/add.ctp +++ b/app/views/principle_contacts/add.ctp @@ -12,6 +12,7 @@ echo $form->input('phone'); echo $form->input('fax'); echo $form->input('notes'); + echo $form->input('email_purchase_orders'); ?> end('Submit');?> diff --git a/app/views/principle_contacts/edit.ctp b/app/views/principle_contacts/edit.ctp index 069ae202..8c467435 100755 --- a/app/views/principle_contacts/edit.ctp +++ b/app/views/principle_contacts/edit.ctp @@ -12,6 +12,7 @@ echo $form->input('phone'); echo $form->input('fax'); echo $form->input('notes'); + echo $form->input('email_purchase_orders'); ?> end('Submit');?> diff --git a/app/views/users/add_edit.ctp b/app/views/users/add_edit.ctp index b7b865f0..7fc3cf39 100755 --- a/app/views/users/add_edit.ctp +++ b/app/views/users/add_edit.ctp @@ -52,8 +52,9 @@ switch ($type) { break; case 'principle': - echo $form->input('principle_id', array('type' => 'hidden', 'value' => $principle_id)); + echo $form->input('principle_id', array('type' => 'hidden', 'value' => $principle_id)); $buttonStr = 'Principle Contact'; + echo $form->input('primary_contact'); case 'user': $buttonStr = 'User'; @@ -77,4 +78,4 @@ switch ($action) { echo $form->submit($actionStr . ' ' . $buttonStr, array('id' => 'submitUserButton')); -?> \ No newline at end of file +?> diff --git a/app/webroot/js/document_add_edit.js b/app/webroot/js/document_add_edit.js index 2f9b05d5..595d9194 100755 --- a/app/webroot/js/document_add_edit.js +++ b/app/webroot/js/document_add_edit.js @@ -481,12 +481,17 @@ $(function() { if($('#JobID_'+ui.item.id).length == 0) { //This Job is not already in the List. addToList('Job', ui.item.id, ui.item.value, $('#jobsList')); + + var jobs_val = $("#PurchaseOrderJobsText").val(); + + $("#PurchaseOrderJobsText").val(jobs_val +', '+ ui.item.value) console.log(ui.item.id); console.log(ui.item.value); //POST the job ID to a method on the documents controller to add the LineItems $.post('/documents/add_job_items_to_po/'+ui.item.id+'/'+$("#DocumentId").val(), function(data) { loadLineItems(); + saveDocument('Purchase Order'); });