From 26257567d32ecf8de17f0193a6fae176ef20378a Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Fri, 17 Nov 2023 14:26:38 +1100 Subject: [PATCH] Generate shipping instructions on PO views #73 --- app/controllers/documents_controller.php | 62 ++++++++++++++++++- .../generate_shipping_instructions.ctp | 0 .../elements/document_purchase_order_view.ctp | 3 + app/webroot/js/document_add_edit.js | 24 ++++--- run_docker_local.sh | 4 +- 5 files changed, 81 insertions(+), 12 deletions(-) create mode 100644 app/views/documents/generate_shipping_instructions.ctp diff --git a/app/controllers/documents_controller.php b/app/controllers/documents_controller.php index eca617ba..7c86550c 100755 --- a/app/controllers/documents_controller.php +++ b/app/controllers/documents_controller.php @@ -526,8 +526,7 @@ ENDINSTRUCTIONS; //Delete all the existing JobPurchaseOrder relationships for this PO. //Fuck it. @TODO SQL injection potential here. $query = "DELETE FROM jobs_purchase_orders WHERE purchase_order_id =".$this->data['PurchaseOrder']['id']; - $result = $this->Document->query($query); - + $this->Document->query($query); } if(isset($this->data['PurchaseOrder']['Job'])) { @@ -1062,6 +1061,65 @@ EOT; } + // generateShippingReference builds the Shipping Instructions: with the PO number and job titles. + function generateShippingInstructions($document_id) { + $this->layout = 'ajax'; + + $po = $this->Document->PurchaseOrder->find('first', + array('conditions'=> + array('Document.id' => $document_id) + ) + ); + + + // TODO SQL injection risk. Need to rewrite this whole rickety thing.. + $query = 'select j.title as job_title, po.title as po_title from jobs_purchase_orders jpo JOIN jobs j on j.id = jpo.job_id JOIN purchase_orders po ON po.id= jpo.purchase_order_id WHERE jpo.purchase_order_id = '.$po['PurchaseOrder']['id'].';'; + + + + $results = $this->Document->query($query); + //echo "
";
+            //print_r($results);
+            //echo "
"; + + $label = ""; + + if (count($results) == 0) { + return; + } + + if (count($results) > 0) { + $label = $results[0]["po"]["po_title"]; + } + + foreach ($results as $result) { + $label .= " / ". $result["j"]["job_title"]; + } + + echo <<PART SHIPMENT: Not Acceptable - please advise ASAP if production of an Item will Delay the Dispatch of the Complete Order by the Date Required stated above.
+INSURANCE: DO NOT INSURE - Insurance effected by CMC
+SECURITY: It is essential that the cargo is prepared & handled so as not to compromise its security standing.
+SHIPMENT MARKINGS:
+(Please put red fragile stickers on boxing)
+CMC TECHNOLOGIES PTY LTD
+UNIT 19, 77 BOURKE ROAD
+ALEXANDRIA NSW 2015 AUSTRALIA
+REF: $label +ENDINSTRUCTIONS; + +/*if($this->Document->PurchaseOrder->save($po["PurchaseOrder"])) { + echo "SUCCESS"; //THIS IS SO STUPID. + } + else { + echo "FAILURE"; + }*/ + + + + } + function add_job_items_to_po($job_id, $document_id) { $this->layout = 'ajax'; $job = $this->Document->PurchaseOrder->Job->find('first', array('conditions'=>array('Job.id' => $job_id))); diff --git a/app/views/documents/generate_shipping_instructions.ctp b/app/views/documents/generate_shipping_instructions.ctp new file mode 100644 index 00000000..e69de29b diff --git a/app/views/elements/document_purchase_order_view.ctp b/app/views/elements/document_purchase_order_view.ctp index e06988d4..87c02657 100755 --- a/app/views/elements/document_purchase_order_view.ctp +++ b/app/views/elements/document_purchase_order_view.ctp @@ -50,6 +50,9 @@ echo $form->input('PurchaseOrder.deliver_to'); echo $form->input('PurchaseOrder.shipping_instructions'); +?> + +end(array('label'=>'Save PurchaseOrder Details', 'id'=>'savePurchaseOrderButton')); diff --git a/app/webroot/js/document_add_edit.js b/app/webroot/js/document_add_edit.js index 0b473abb..1adceae6 100755 --- a/app/webroot/js/document_add_edit.js +++ b/app/webroot/js/document_add_edit.js @@ -555,16 +555,15 @@ $(function() { var jobs_val = $("#PurchaseOrderJobsText").val(); $("#PurchaseOrderJobsText").val(jobs_val +', '+ ui.item.value) - console.log(ui.item.id); + + 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) { + //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'); - - - }); + loadLineItems(); + saveDocument('Purchase Order'); + }); } @@ -575,6 +574,15 @@ $(function() { }); +$('#generateShippingInstructions').live('click', function(event) { + event.preventDefault(); + $.post('/documents/generateShippingInstructions/'+$("#DocumentId").val(), function(data) { + $('#PurchaseOrderShippingInstructions').val(data); + updateTextFields(); //Update the CKEditor instances. + //$("#PurchaseOrderShippingInstructions").ckeditor(config); + }); + +}); $('.generateCommercialComments').live('click', function(event) { event.preventDefault(); diff --git a/run_docker_local.sh b/run_docker_local.sh index fd242849..1efc97cb 100755 --- a/run_docker_local.sh +++ b/run_docker_local.sh @@ -3,6 +3,6 @@ ID=$(docker ps -qf ancestor='cmc:latest') docker kill $ID sleep 1 docker run -d -p 127.0.0.1:8888:80 \ - --mount type=bind,source=/home/k/projects/cmc-sales/app/webroot/pdf,target=/var/www/cmc-sales/app/webroot/pdf \ - --mount type=bind,source=/home/k/projects/cmc-sales/app/webroot/attachments_files,target=/var/www/cmc-sales/app/webroot/attachments_files \ + --mount type=bind,source=/home/k/src/cmc-sales/app/webroot/pdf,target=/var/www/cmc-sales/app/webroot/pdf \ + --mount type=bind,source=/home/k/src/cmc-sales/app/webroot/attachments_files,target=/var/www/cmc-sales/app/webroot/attachments_files \ cmc:latest