From 3f1c37057d82ce42372419d465f8aeba36017c20 Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Sat, 15 Jun 2013 18:32:14 +1000 Subject: [PATCH] Implemented PO first page. Added extra PO field migration --- app/controllers/documents_controller.php | 40 +++++- .../15_6_2013_add_extra_po_fields.sql | 5 + app/views/documents/pdf_po.ctp | 13 +- .../elements/document_purchase_order_view.ctp | 20 ++- app/views/elements/line_items_table_po.ctp | 123 ++++++++++++++++++ app/views/elements/pdf_po_first_page.ctp | 74 +++++++++++ app/views/layouts/default.ctp | 3 +- app/views/purchase_orders/index.ctp | 31 ++--- app/webroot/js/document_add_edit.js | 64 +++++---- 9 files changed, 309 insertions(+), 64 deletions(-) create mode 100644 app/migrations/15_6_2013_add_extra_po_fields.sql create mode 100755 app/views/elements/line_items_table_po.ctp create mode 100644 app/views/elements/pdf_po_first_page.ctp diff --git a/app/controllers/documents_controller.php b/app/controllers/documents_controller.php index 0fc891fd..2096220f 100755 --- a/app/controllers/documents_controller.php +++ b/app/controllers/documents_controller.php @@ -269,16 +269,40 @@ class DocumentsController extends AppController { $enquiry = $this->Document->OrderAcknowledgement->Enquiry->read(null, $enquiryid); $count = $this->Document->PurchaseOrder->findCount(); $count++; - $offset = 2060; $count += $offset; $newPOnumber = "CMCPO".$count; $this->data['PurchaseOrder']['title'] = $newPOnumber; $this->data['PurchaseOrder']['issue_date'] = date('Y-m-d'); + + $this->data['PurchaseOrder']['deliver_to'] = << +Unit 19, 77 Bourke Road
+Alexandria NSW 2015 AUSTRALIA
+ENDDELIVER; + + //Fuck it all. + $this->data['PurchaseOrder']['shipping_instructions'] = <<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
+ENDINSTRUCTIONS; + + + + $this->data['Document']['user_id']= $enquiry['Enquiry']['user_id']; $this->data['Document']['revision'] = 0; //No revisions for POs. I have decreed it! $this->data['Document']['type'] = 'purchaseOrder'; break; + + case "orderAck": $enquiry = $this->Document->OrderAcknowledgement->Enquiry->read(null, $enquiryid); $this->data['OrderAcknowledgement']['job_id'] = $jobid; @@ -642,7 +666,21 @@ class DocumentsController extends AppController { break; case "purchaseOrder": + + $totalsDescText = array( + 'subtotal' => 'SUBTOTAL', + 'gst' => '', + 'total' => 'ORDER TOTAL' + ); + //No GST for POs for now. + $totals = $this->calculateTotals($document, 0); + $this->set('totals',$totals); + $this->set('totalsDescText',$totalsDescText); + $filename = $document['PurchaseOrder']['title']; + + $issue_date = date('l, j F Y', strtotime($document['PurchaseOrder']['issue_date'])); + $this->set('issue_date', $issue_date); $template_name = 'pdf_po'; break; diff --git a/app/migrations/15_6_2013_add_extra_po_fields.sql b/app/migrations/15_6_2013_add_extra_po_fields.sql new file mode 100644 index 00000000..936fd112 --- /dev/null +++ b/app/migrations/15_6_2013_add_extra_po_fields.sql @@ -0,0 +1,5 @@ +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; + + diff --git a/app/views/documents/pdf_po.ctp b/app/views/documents/pdf_po.ctp index 13f14ce9..04f9a71c 100755 --- a/app/views/documents/pdf_po.ctp +++ b/app/views/documents/pdf_po.ctp @@ -10,20 +10,17 @@ $pdfdoc->SetPrintFooter(false); $pdfdoc->AddPage(); $pdfdoc->Page1Header(); -$pageTitle = "

PURCHASE ORDER

"; -$pdfdoc->writeHTML($pageTitle, true, false, false, false, 'C'); + +$first_page = $this->element('pdf_po_first_page'); +$pdfdoc->pageContent($first_page); $pdfdoc->SetTextColor(0); - $pageNo = $pdfdoc->PageNoFormatted(); $totalCount = $pdfdoc->getAliasNbPages(); +$pdfdoc->AddPage(); -$shippingBillingBox = $this->element('pdf_shipping_billing_box', array('pageNo'=>$pageNo, 'totalCount'=>$totalCount)); - -$pdfdoc->writeHTML($shippingBillingBox, false); - -$LineItemTable = $this->element('line_items_table_with_shipping'); +$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 9553f491..c90e8447 100755 --- a/app/views/elements/document_purchase_order_view.ctp +++ b/app/views/elements/document_purchase_order_view.ctp @@ -1,10 +1,9 @@

Purchase Order:

-

Job: link($invoice['Job']['title'], array('controller'=>'jobs', 'action'=>'view', $invoice['Job']['id']));?>

+

Job:

-
@@ -26,18 +25,15 @@ echo $form->input('PurchaseOrder.dispatch_date'); echo $form->input('PurchaseOrder.date_arrived'); //ARGH. Really Karl? - echo $form->input('billing_address_id', array('div' => 'addressradio', 'legend' => 'Select Billing Address', 'options' => $billing_addresses_list, 'type' => 'radio', 'class'=>'billing_address')); - echo $form->input('Document.bill_to'); - - - echo $form->input('shipping_address_id', array('div' => 'addressradio','legend' => 'Select Shipping Address', 'options' => $shipping_addresses_list, 'type' => 'radio', 'class' => 'shipping_address')); - echo $form->input('Document.ship_to'); + echo $form->input('PurchaseOrder.ordered_from'); + echo $form->input('PurchaseOrder.description'); + + echo $form->input('PurchaseOrder.dispatch_by'); + + echo $form->input('PurchaseOrder.deliver_to'); + echo $form->input('PurchaseOrder.shipping_instructions'); - - echo $form->input('PurchaseOrder.ship_via'); - echo $form->input('PurchaseOrder.fob'); - echo $form->input('Document.shipping_details', array('id'=>'shippingDetails')); echo $form->end(array('label'=>'Save PurchaseOrder Details', 'id'=>'savePurchaseOrderButton')); ?> diff --git a/app/views/elements/line_items_table_po.ctp b/app/views/elements/line_items_table_po.ctp new file mode 100755 index 00000000..1a81a6fe --- /dev/null +++ b/app/views/elements/line_items_table_po.ctp @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ITEM
NO.
QTYDESCRIPTIONUNIT
PRICE
TOTAL
PRICE
+ '; + $hasOptions = true; + } + ?> + + formatDecimal($li['quantity']);?>
+ +
+ + + currency($li['gross_unit_price'], $currencyCode);?> + +
less
%
+ discount
+ (-currency($li['discount_amount_unit'], $currencyCode);?>)
+ =
+ currency($li['net_unit_price'], $currencyCode);?> + + +
+ + + currency($li['gross_price'], $currencyCode);?> + +
less
%
+ discount*
+ (-currency($li['discount_amount_total'], $currencyCode);?>)
+ =
+ currency($li['net_price'], $currencyCode);?> + + +
+ currency($totals['subtotal'], $currencyCode); + } + else { + echo $currencySymbol.'TBA'; + } + ?>
+ +
+ currency($totals['total'], $currencyCode); + } + else { + echo $currencySymbol.'TBA'; + } + ?>
diff --git a/app/views/elements/pdf_po_first_page.ctp b/app/views/elements/pdf_po_first_page.ctp new file mode 100644 index 00000000..e35d7788 --- /dev/null +++ b/app/views/elements/pdf_po_first_page.ctp @@ -0,0 +1,74 @@ + + + + + + +
PURCHASE ORDER NO:Date:
+


+ + + + + +
ORDERED FROM:
+ +


+ + + + + + + + + + + + + + + +
ReferenceDescriptionOrder Total
+ currency($totals['total'], $currencyCode); ?> +
+ +

+ + + + + + + + +
DISPATCH EX-WORKS BY:


+ + + + + +
DELIVER TO:


+ + + + + + + + + + +
SHIPPING INSTRUCTIONS:
+
+
+

+ + + + + +
I HEREBY CERTIFY THAT CMC TECHNOLOGIES IS REGISTERED FOR GST AND OUR REGISTRATION # IS 47 085 991 224.

+CON CARPIS
+ + diff --git a/app/views/layouts/default.ctp b/app/views/layouts/default.ctp index ad390ca1..e5d09f9a 100755 --- a/app/views/layouts/default.ctp +++ b/app/views/layouts/default.ctp @@ -106,8 +106,7 @@ if ($currentuser['User']['access_level'] == 'manager' || $currentuser['User']['a
  • link('POs', '/purchase_orders/index'); ?>
      -
    • link('PO Index', '/purchase_orders/index'); ?>
    • -
    • link('New PO', '/purchase_orders/add'); ?>
    • +
    • link('PO Index', '/purchase_orders/index'); ?>
  • diff --git a/app/views/purchase_orders/index.ctp b/app/views/purchase_orders/index.ctp index f707bfc4..abf811ca 100755 --- a/app/views/purchase_orders/index.ctp +++ b/app/views/purchase_orders/index.ctp @@ -1,5 +1,9 @@

    + +

    counter(array( @@ -17,7 +21,7 @@ echo $paginator->counter(array( sort('principle_id');?> sort('principle_reference');?> sort('document_id');?> */?> - + Document link($purchaseOrder['Document']['id'], array('controller' => 'documents', 'action' => 'view', $purchaseOrder['Document']['id'])); ?> */ ?> - - link(__('View', true), array('action' => 'view', $purchaseOrder['PurchaseOrder']['id'])); ?> - link(__('Edit', true), array('action' => 'edit', $purchaseOrder['PurchaseOrder']['id'])); ?> - - + + 0) { ?> + View + + + +

    @@ -71,18 +77,6 @@ foreach ($purchaseOrders as $purchaseOrder): | numbers();?> next(__('next', true).' >>', array(), null, array('class' => 'disabled'));?> -
    -
      -
    • link(__('New PurchaseOrder', true), array('action' => 'add')); ?>
    • -
    • link(__('List Principles', true), array('controller' => 'principles', 'action' => 'index')); ?>
    • -
    • link(__('New Principle', true), array('controller' => 'principles', 'action' => 'add')); ?>
    • -
    • link(__('List Documents', true), array('controller' => 'documents', 'action' => 'index')); ?>
    • -
    • link(__('New Document', true), array('controller' => 'documents', 'action' => 'add')); ?>
    • -
    • link(__('List Jobs', true), array('controller' => 'jobs', 'action' => 'index')); ?>
    • -
    • link(__('New Job', true), array('controller' => 'jobs', 'action' => 'add')); ?>
    • -
    -
    - - \ 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 56aef3d4..dd45a138 100755 --- a/app/webroot/js/document_add_edit.js +++ b/app/webroot/js/document_add_edit.js @@ -40,7 +40,7 @@ $(function() { } else { alert("Line Item could not be saved") - $('#LineItemDescription').ckeditor(config); + $('#LineItemDescription').ckeditor(config); } }); @@ -75,7 +75,7 @@ $(function() { } else { alert("Line Item could not be saved") - $('#LineItemDescription').ckeditor(config); + $('#LineItemDescription').ckeditor(config); } }); @@ -353,12 +353,12 @@ $(function() { var confirmed = confirm("This will overwrite any changes you have made to the first page"); } - if(confirmed) { - $.get('/documents/generateFirstPage/'+docID, function(data) { - $(".firstPage").val(data); - savePages(); - }); - } + if(confirmed) { + $.get('/documents/generateFirstPage/'+docID, function(data) { + $(".firstPage").val(data); + savePages(); + }); + } }); @@ -386,21 +386,34 @@ $(function() { //OA View. $("#saveOAButton").click(function() { saveDocument('Order Acknowledgement'); - //if the job has changed, the create invoice button wont work properly. + //if the job has changed, the create invoice button wont work properly. window.location.reload(true); $('.job-title').html($("#OrderAcknowledgementJobId :selected").text()); }); - + + //This is fucked beyond all words. + $("#PurchaseOrderDeliverTo").ckeditor(config); + $("#PurchaseOrderOrderedFrom").ckeditor(config); + $("#PurchaseOrderShippingInstructions").ckeditor(config); + $("#PurchaseOrderDescription").ckeditor(config); + //PackingList View. Damn you past Karl. $("#savePackingListButton").click(function() { saveDocument('Packing List'); - //if the job has changed, the create invoice button wont work properly. + //if the job has changed, the create invoice button wont work properly. window.location.reload(true); $('.job-title').html($("#PackingListJobId :selected").text()); }); + //PurchaseOrder View. Damn you past Karl. + $("#savePurchaseOrderButton").click(function() { + saveDocument('Purchase Order'); + }); + + + $("#createOA").click(function() { $("#addJobConfirmation").dialog('open'); @@ -472,8 +485,8 @@ function saveDocument(documentName) { else { $("#flashMessage").html("Unable to save "+documentName); } - $("#flashMessage").show(); - loadLineItems(); + $("#flashMessage").show(); + loadLineItems(); }); } @@ -505,17 +518,24 @@ function showHideTextPrices() { } +//I am a much better programmer now. +//FUCK YEAH!! function updateTextFields() { - $('#shippingDetails').ckeditor(function() { - this.updateElement(); - }); + var fields = [ + '#shippingDetails', + "#DocumentBillTo", + "#DocumentShipTo", + "#PurchaseOrderDeliverTo", + "#PurchaseOrderOrderedFrom", + "#PurchaseOrderShippingInstructions", + "#PurchaseOrderDescription" + ]; - $("#DocumentBillTo").ckeditor(function() { - this.updateElement(); - }); - $("#DocumentShipTo").ckeditor(function() { - this.updateElement(); - }); + for (i in fields) { + $(fields[i]).ckeditor(function() { + this.updateElement(); + }); + } }