From 7989dd24ac2bafe34b38cc5af98214d72bf68af5 Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Sat, 17 Sep 2011 17:02:07 +1000 Subject: [PATCH] Prompt for customer Order Number when converting a Quote to Job+OA closes #57 --- controllers/documents_controller.php | 17 +++++++++-------- models/job.php | 6 +++++- views/documents/convert_to_oa.ctp | 0 views/elements/document_quote_view.ctp | 10 ++++++++-- webroot/js/document_add_edit.js | 25 +++++++++++++++++++++++-- 5 files changed, 45 insertions(+), 13 deletions(-) create mode 100644 views/documents/convert_to_oa.ctp diff --git a/controllers/documents_controller.php b/controllers/documents_controller.php index 34275802..f2ca2879 100755 --- a/controllers/documents_controller.php +++ b/controllers/documents_controller.php @@ -314,14 +314,15 @@ class DocumentsController extends AppController { * * Make a new Document (orderack) with the same LineItems as Quote with Document ID #$id * - * @param $id + * */ - function convert_to_oa($id = null) { -//$this->layout = 'ajax'; - if (!$id) { - echo 'Invalid Document ID'; + function convert_to_oa() { + $this->layout = 'ajax'; + if (empty($this->data)) { + echo 'FAILURE'; } else { + $id = $this->data['Document']['id']; $originalDoc = $this->Document->find('first', array('conditions' => array('Document.id' => $id))); @@ -335,7 +336,7 @@ class DocumentsController extends AppController { $this->Document->OrderAcknowledgement->Enquiry->Customer->save($customer); - $job = $this->Document->OrderAcknowledgement->Job->newJob($enquiry); //Only way to know Enquiry ID is if it's a Quote. + $job = $this->Document->OrderAcknowledgement->Job->newJob($enquiry, $this->data['Job']['customer_order_number']); //Only way to know Enquiry ID is if it's a Quote. if($job == false) { echo 'Error: Unable to create Job'; @@ -350,7 +351,7 @@ class DocumentsController extends AppController { $newDoc['Document']['user_id']= $enquiry['Enquiry']['user_id']; $newDoc['Document']['revision'] = 0; //No revisions for Order Acks. I have decreed it! $newDoc['Document']['type'] = 'orderAck'; - + if(isset($enquiry['BillingAddress']['id'])) { $newDoc['Document']['bill_to'] = ''.$customer['Customer']['name'].'
'; $newDoc['Document']['bill_to'] .= $this->Document->OrderAcknowledgement->Enquiry->formatAddress($enquiry['BillingAddress']['id'], 'BillingAddress'); @@ -560,7 +561,7 @@ class DocumentsController extends AppController { $this->set('enquiry', $enquiry); } - + } diff --git a/models/job.php b/models/job.php index 4d6621a1..18bb6759 100755 --- a/models/job.php +++ b/models/job.php @@ -67,7 +67,7 @@ class Job extends AppModel { ); - function newJob($enquiry) { + function newJob($enquiry, $customerOrderNumber = null) { $this->create(); @@ -89,6 +89,10 @@ class Job extends AppModel { $newJob['Job']['enquiry_id'] = $enquiry['Enquiry']['id']; $newJob['Job']['date_order_received'] = date('Y-m-d'); + if(!empty($customerOrderNumber)) { + $newJob['Job']['customer_order_number'] = $customerOrderNumber; + } + if ($this->save($newJob)) { return $this->find('first',array('conditions'=>array('Job.id'=>$this->id))); diff --git a/views/documents/convert_to_oa.ctp b/views/documents/convert_to_oa.ctp new file mode 100644 index 00000000..e69de29b diff --git a/views/elements/document_quote_view.ctp b/views/elements/document_quote_view.ctp index 9c5d6d6a..548165fd 100644 --- a/views/elements/document_quote_view.ctp +++ b/views/elements/document_quote_view.ctp @@ -76,8 +76,14 @@ echo $form->input('Document.id');
This will create a new job and an Order Acknowledgement based on this Quote
- The Enquiry will also be marked as "Job Won - Order Placed"
- Continue? + The Enquiry will also be marked as "Job Won - Order Placed"

+ + create('Document',array('type'=>'post','action'=>'convert_to_oa')); + echo $form->input('Document.id'); + echo $form->input('Job.customer_order_number'); + echo $form->end(); + ?> +
data);?> diff --git a/webroot/js/document_add_edit.js b/webroot/js/document_add_edit.js index fdd52e7c..b48b779d 100644 --- a/webroot/js/document_add_edit.js +++ b/webroot/js/document_add_edit.js @@ -130,7 +130,7 @@ $(function() { $( "#addJobConfirmation" ).dialog({ autoOpen: false, - height: 200, + height: 400, width: 400, modal: true, buttons: { @@ -138,7 +138,28 @@ $(function() { var documentID = $("#documentID").html(); - window.location.href = "/documents/convert_to_oa/"+documentID; + //window.location.href = "/documents/convert_to_oa/"+documentID; + //var newOAform = $('#DocumentConvertToOaForm').find('input'); + var newOAform = $('#DocumentConvertToOaForm'); + newOAform.submit(); + + + + /*$.post('/documents/convert_to_oa', newOAform, function(data) { + if(data =='SUCCESS') { + $("#flashMessage").html("Invoice Saved Successfully"); + } + else { + $("#flashMessage").html("Unable to Save Invoice"); + } + + $("#flashMessage").show(); + + + loadLineItems(); + }); + */ + }, Cancel: function() {