From e400230c41a5ae1e05f60d4b51564366634f7af2 Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Mon, 15 Aug 2011 16:04:38 +1000 Subject: [PATCH] invoice PDF generation working. More work still needed --- .htaccess | 2 +- controllers/documents_controller.php | 44 +++++++++++++++++------- controllers/invoices_controller.php | 1 - models/document.php | 5 --- views/documents/view.ctp | 13 +------ views/elements/document_invoice_view.ctp | 11 ++++-- views/elements/document_quote_view.ctp | 10 ++++++ views/enquiries/view.ctp | 8 +++-- webroot/css/quotenik.css | 2 +- webroot/js/view_enquiry.js | 8 +++++ 10 files changed, 67 insertions(+), 37 deletions(-) diff --git a/.htaccess b/.htaccess index 3edd8fc0..d2b6e243 100755 --- a/.htaccess +++ b/.htaccess @@ -4,6 +4,6 @@ RewriteRule (.*) webroot/$1 [L] - + Header unset Cache-Control diff --git a/controllers/documents_controller.php b/controllers/documents_controller.php index 62cd64d6..4bec3a4f 100755 --- a/controllers/documents_controller.php +++ b/controllers/documents_controller.php @@ -47,6 +47,7 @@ class DocumentsController extends AppController { break; case 'invoice': $docTypeElement = 'document_invoice_view'; + $this->set('invoice', $this->Document->Invoice->find('first', array('conditions'=>array('Invoice.id'=>$document['Invoice']['id'])))); break; case 'purchaseOrder': @@ -152,15 +153,17 @@ class DocumentsController extends AppController { $this->data['Document']['type'] = 'invoice'; $this->data['Invoice']['issue_date'] = date('Y-m-d'); //Argh. Quote model uses 'date_issed'. - - $this->data['Document']['currency_id'] = 2; //All new Invoices default to AUD. - - + $this->data['Invoice']['due_date'] = date("Y-m-d", strtotime("+30 days")); + $this->data['Invoice']['currency_id'] = 2; //All new Invoices default to AUD. break; case "purchaseOrder": + + + + break; case "orderAck": @@ -212,7 +215,7 @@ class DocumentsController extends AppController { $newDoc = array(); - + $newDoc['Quote'] = $this->unset_keys($document['Quote'], array('id','created')); $newDoc['Quote']['date_issued'] = $today_date; @@ -435,15 +438,32 @@ class DocumentsController extends AppController { $this->set('products', $document['LineItem']); - //If this is a quote, set the filename - //@TODO FIX THIS FOR OTHER DOCTYPES - if($document['Document']['revision'] > 0) { - $filename = $enquiry['Enquiry']['title'].'_'.$document['Document']['revision'].'.pdf'; - } - else { - $filename = $enquiry['Enquiry']['title'].'.pdf'; + //Set filename for the document. + // + switch($docType) { + case "quote": + $filename = $enquiry['Enquiry']['title']; + break; + + case "invoice": + $filename = $document['Invoice']['title']; + break; + + case "purchaseOrder": + $filename = $document['PurchaseOrder']['title']; + break; + + case "orderAck": + $filename = $document['Job']['title']; + break; } + if($document['Document']['revision'] > 0) { + $filename = $filename.'_'.$document['Document']['revision'].'.pdf'; + } + else { + $filename = $filename.'.pdf'; + } $this->set('filename', $filename); $document['Document']['pdf_filename'] = $filename; diff --git a/controllers/invoices_controller.php b/controllers/invoices_controller.php index 9c70e975..307e071b 100755 --- a/controllers/invoices_controller.php +++ b/controllers/invoices_controller.php @@ -82,7 +82,6 @@ class InvoicesController extends AppController { $this->redirect(array('action'=>'index')); } } - } /* function edit($id = null) { diff --git a/models/document.php b/models/document.php index 6007e15d..6a2b11e7 100755 --- a/models/document.php +++ b/models/document.php @@ -114,17 +114,12 @@ class Document extends AppModel { function getCMCReferenceNumber($document, $type) { switch($type) { case 'quote': - - break; case 'invoice': - break; case 'purchaseOrder': - break; case 'orderAck': - break; } return $fullName; diff --git a/views/documents/view.ctp b/views/documents/view.ctp index 80babe80..6a8e4a8e 100755 --- a/views/documents/view.ctp +++ b/views/documents/view.ctp @@ -5,17 +5,6 @@ echo $javascript->link('ckeditor/adapters/jquery'); echo $javascript->link('document_add_edit'); ?> - -

: link($enquiry['Enquiry']['title'], array('controller'=>'enquiries','action'=>'view',$enquiry['Enquiry']['id']));?> - 0) { - echo "Revision {$document['Document']['revision']} "; - } - ?> - for - link($enquiry['Customer']['name'], array('controller'=>'customers','action'=>'view',$enquiry['Customer']['id']));?> -

- element('pdf_created_message'); ?> element($docTypeElement); - \ No newline at end of file + \ No newline at end of file diff --git a/views/elements/document_invoice_view.ctp b/views/elements/document_invoice_view.ctp index aa614869..f0f76a64 100644 --- a/views/elements/document_invoice_view.ctp +++ b/views/elements/document_invoice_view.ctp @@ -1,5 +1,5 @@ -

Invoice:

- +

Invoice: for link($enquiry['Customer']['name'], '/customers/view/'.$enquiry['Customer']['id']);?>

+

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

create('Document',array('type'=>'post','action'=>'edit', 'default'=>false)); @@ -7,7 +7,10 @@ echo $form->input('Document.id'); ?>
- + + + + link('Generate PDF of this Quote', '/documents/pdf/'.$document['Document']['id']);?>
@@ -19,3 +22,5 @@ echo $form->input('Document.id'); + + \ No newline at end of file diff --git a/views/elements/document_quote_view.ctp b/views/elements/document_quote_view.ctp index 3b553938..a6ba2880 100644 --- a/views/elements/document_quote_view.ctp +++ b/views/elements/document_quote_view.ctp @@ -1,4 +1,14 @@ +

: link($enquiry['Enquiry']['title'], array('controller'=>'enquiries','action'=>'view',$enquiry['Enquiry']['id']));?> + 0) { + echo "Revision {$document['Document']['revision']} "; + } + ?> + for + link($enquiry['Customer']['name'], array('controller'=>'customers','action'=>'view',$enquiry['Customer']['id']));?> +

+ create('Document',array('type'=>'post','action'=>'edit', 'default'=>false)); diff --git a/views/enquiries/view.ctp b/views/enquiries/view.ctp index 29b6addb..781917cc 100755 --- a/views/enquiries/view.ctp +++ b/views/enquiries/view.ctp @@ -239,6 +239,11 @@
+ diff --git a/webroot/css/quotenik.css b/webroot/css/quotenik.css index a24a9562..2acd1b1f 100755 --- a/webroot/css/quotenik.css +++ b/webroot/css/quotenik.css @@ -1615,6 +1615,6 @@ div.pdfGeneratedMessage { margin-bottom: 1em; padding: 0.5em; border: 2px dashed; - width: 50%; + width: 45em; font-size: 120%; } \ No newline at end of file diff --git a/webroot/js/view_enquiry.js b/webroot/js/view_enquiry.js index 531d5384..d61db51e 100644 --- a/webroot/js/view_enquiry.js +++ b/webroot/js/view_enquiry.js @@ -58,6 +58,14 @@ $(function() { window.location = '/documents/newDocument/quote/'+$( this ).attr('id'); }); + $(".addInvoice").click(function() { + if($("#jobsList > li").length == 0) { + alert("Cant add an invoice! Add Invoice must be for a job. No jobs exist"); + } + else { + $("#jobsList").show(); + } + }); }); \ No newline at end of file