From aae043b04c15a605185c47f3d39f0e25aa980955 Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Tue, 9 Aug 2011 16:33:21 +1000 Subject: [PATCH] Added Documents index. Provides quick to acces view of recently generated Documents. Closes #15 --- controllers/documents_controller.php | 64 ++++++++++---- models/document.php | 35 +++++--- models/user.php | 3 + views/documents/index.ctp | 123 +++++++++++++++++---------- views/documents/view.ctp | 2 +- views/layouts/default.ctp | 9 +- 6 files changed, 158 insertions(+), 78 deletions(-) diff --git a/controllers/documents_controller.php b/controllers/documents_controller.php index f1f20a0a..23b253ab 100755 --- a/controllers/documents_controller.php +++ b/controllers/documents_controller.php @@ -4,9 +4,20 @@ class DocumentsController extends AppController { var $name = 'Documents'; var $helpers = array('Html', 'Form', 'Number', 'Decimal'); + + var $paginate = array( + + 'contain' => false, + 'limit' => 200, + 'order'=>array('Document.id' => 'desc') + + ); + function index() { $this->Document->recursive = 0; $this->set('documents', $this->paginate()); + + $this->set('users', $this->Document->User->getUsersList()); } function view($id = null) { @@ -78,7 +89,7 @@ class DocumentsController extends AppController { $this->data['Document']['user_id']= $enquiry['Enquiry']['user_id']; $this->data['Document']['enquiry_id'] = $enquiryid; $this->data['Document']['type'] = 'quote'; - + if ($this->Document->saveAll($this->data)) { $newid = $this->Document->id; @@ -191,10 +202,10 @@ class DocumentsController extends AppController { $this->set('document', $document); $this->data = $document; - + $docType = $this->Document->getDocType($document); $docTypeFullName = $this->Document->getDocFullName($docType); - + $currency = $this->Document->getCurrency($document); @@ -212,16 +223,16 @@ class DocumentsController extends AppController { if($gst == 1) { $totalsDescText = array( - 'subtotal' => 'SUB-TOTAL (EXCLUDING GST)', - 'gst' => 'GST (10%)', - 'total' => 'TOTAL PAYABLE (INCLUDING GST)' + 'subtotal' => 'SUB-TOTAL (EXCLUDING GST)', + 'gst' => 'GST (10%)', + 'total' => 'TOTAL PAYABLE (INCLUDING GST)' ); } else { $totalsDescText = array( - 'subtotal' => 'SUB-TOTAL', - 'gst' => 'GST (10%)', - 'total' => 'TOTAL PAYABLE' + 'subtotal' => 'SUB-TOTAL', + 'gst' => 'GST (10%)', + 'total' => 'TOTAL PAYABLE' ); } @@ -281,12 +292,34 @@ 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['Quote']['revision'] > 0) { + $filename = $enquiry['Enquiry']['title'].'rev'.$document['Quote']['revision'].'.pdf'; + } + else { + $filename = $enquiry['Enquiry']['title'].'.pdf'; + } + + + $this->set('filename', $filename); + $document['Document']['pdf_filename'] = $filename; + $document['Document']['pdf_created_at'] = date('Y-m-d H:i:s'); + $document['Document']['pdf_created_by_user_id'] = $this->getCurrentUserID(); + if($this->Document->save($document)) { + echo "Set pdf_filename attritbute to: ".$filename; + } + else { + echo 'Failed to set pdf_filename to: '.$filename; + } + + $colWidths = array( - 'item' => '8%', - 'qty' => '8%', - 'desc' => '60%', - 'unit' => '12%', - 'total' => '12%' + 'item' => '8%', + 'qty' => '8%', + 'desc' => '60%', + 'unit' => '12%', + 'total' => '12%' ); @@ -306,9 +339,8 @@ class DocumentsController extends AppController { $enquiry = $this->Document->Quote->Enquiry->read(null, $document['Quote']['enquiry_id']); $this->set('enquiry', $enquiry); - - } + } ?> \ No newline at end of file diff --git a/models/document.php b/models/document.php index bd784c34..6007e15d 100755 --- a/models/document.php +++ b/models/document.php @@ -13,6 +13,7 @@ class Document extends AppModel { 'fields' => '', 'order' => '' ) + ); var $hasMany = array( @@ -85,20 +86,20 @@ class Document extends AppModel { function getDocFullName($type) { - + switch($type) { case 'quote': $fullName = 'Quotation'; - break; + break; case 'invoice': $fullName = 'Invoice'; - break; + break; case 'purchaseOrder': $fullName = 'Purchase Order'; - break; + break; case 'orderAck': $fullName = 'Order Acknowledgement'; - break; + break; } return $fullName; } @@ -113,18 +114,18 @@ class Document extends AppModel { function getCMCReferenceNumber($document, $type) { switch($type) { case 'quote': - - break; + + break; case 'invoice': - - break; + + break; case 'purchaseOrder': - - break; + + break; case 'orderAck': - - break; + + break; } return $fullName; } @@ -144,7 +145,7 @@ class Document extends AppModel { /** * Does GST apply on this document. Based on the Enquiry GST TinyInt. * @param $enquiry - * @return Bool + * @return Bool */ function gstApplies($enquiry) { if ($enquiry['Enquiry']['gst'] == 0) { @@ -155,6 +156,12 @@ class Document extends AppModel { } } + function isLatestRevision($enquiry) { + $number_of_revisions = $this->Document->Quote->findCount('Quote.enquiry_id ='. $enquiry); + + + } + } ?> \ No newline at end of file diff --git a/models/user.php b/models/user.php index 356caf44..e2fd333d 100755 --- a/models/user.php +++ b/models/user.php @@ -64,5 +64,8 @@ class User extends AppModel { return $this->find('all', array('conditions'=>array('User.principle_id'=>$principleID))); } + function getUsersList() { + return $this->find('list', array('conditions'=>array('User.type'=>'user'))); + } } ?> \ No newline at end of file diff --git a/views/documents/index.ctp b/views/documents/index.ctp index 23021eb3..5eb4c1f5 100755 --- a/views/documents/index.ctp +++ b/views/documents/index.ctp @@ -1,51 +1,82 @@
-

-

-counter(array( -'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true) -)); -?>

- - - - - - - - - - > - - - - - - - +

+

+ counter(array( + 'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true) + )); + ?>

+
sort('id');?>sort('created');?>#Pagessort('user_id');?>
- - - - - - - link($document['User']['username'], array('controller' => 'users', 'action' => 'view', $document['User']['id'])); ?> - - link(__('View', true), array('action' => 'view', $document['Document']['id'])); ?> -
+ + + + + + + + + - -
sort('created');?>sort('user_id');?>Type#PagesPDF FilenamePDF CreatedPDF Created By
+ + > + + + nice($document['Document']['created']); ?> + + + + link($document['User']['username'], array('controller' => 'users', 'action' => 'view', $document['User']['id'])); ?> + + + + + + + + + + + + link($document['Document']['pdf_filename'], '/pdf/'.$document['Document']['pdf_filename']);?> + + + + nice($document['Document']['pdf_created_at']); + } + ?> + + + + + link($users[$pdf_user_id], '/users/view/'.$pdf_user_id); + } + ?> + + + + link(__('View', true), array('action' => 'view', $document['Document']['id'])); ?> + + + +
- prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?> - | numbers();?> - next(__('next', true).' >>', array(), null, array('class' => 'disabled'));?> + prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?> + | numbers();?> + next(__('next', true).' >>', array(), null, array('class' => 'disabled'));?>
+ + \ No newline at end of file diff --git a/views/documents/view.ctp b/views/documents/view.ctp index d16cc59f..8d595d83 100755 --- a/views/documents/view.ctp +++ b/views/documents/view.ctp @@ -54,6 +54,6 @@ switch($docType) { - + \ No newline at end of file diff --git a/views/layouts/default.ctp b/views/layouts/default.ctp index 8e713311..b46fc8fb 100755 --- a/views/layouts/default.ctp +++ b/views/layouts/default.ctp @@ -67,12 +67,19 @@ if (isset($currentuser) == FALSE) { +
  • link('Documents', '/documents/index'); ?> +
      +
    • link('Documents Index', '/documents/index'); ?>
    • +
    +
  • +
  • link('Jobs', '/jobs/index'); ?>
      + +?>
    • link('Reports', '/jobs/reports'); ?>
    • link('Job List', '/jobs/index'); ?>