Added Documents index. Provides quick to acces view of recently generated Documents. Closes #15

This commit is contained in:
Karl Cordes 2011-08-09 16:33:21 +10:00
parent fb94915cde
commit aae043b04c
6 changed files with 158 additions and 78 deletions

View file

@ -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) {
@ -281,6 +292,28 @@ 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%',
@ -306,9 +339,8 @@ class DocumentsController extends AppController {
$enquiry = $this->Document->Quote->Enquiry->read(null, $document['Quote']['enquiry_id']);
$this->set('enquiry', $enquiry);
}
}
?>

View file

@ -13,6 +13,7 @@ class Document extends AppModel {
'fields' => '',
'order' => ''
)
);
var $hasMany = array(
@ -155,6 +156,12 @@ class Document extends AppModel {
}
}
function isLatestRevision($enquiry) {
$number_of_revisions = $this->Document->Quote->findCount('Quote.enquiry_id ='. $enquiry);
}
}
?>

View file

@ -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')));
}
}
?>

View file

@ -1,51 +1,82 @@
<div class="documents index">
<h2><?php __('Documents');?></h2>
<p>
<?php
echo $paginator->counter(array(
'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true)
));
?></p>
<table cellpadding="0" cellspacing="0">
<tr>
<th><?php echo $paginator->sort('id');?></th>
<h2><?php __('Documents');?></h2>
<p>
<?php
echo $paginator->counter(array(
'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true)
));
?></p>
<table cellpadding="0" cellspacing="0">
<tr>
<th><?php echo $paginator->sort('created');?></th>
<th>#Pages</th>
<th><?php echo $paginator->sort('user_id');?></th>
<th>Type</th>
<th>#Pages</th>
<th>PDF Filename</th>
<th>PDF Created</th>
<th>PDF Created By</th>
<th class="actions"><?php __('Actions');?></th>
</tr>
<?php
$i = 0;
foreach ($documents as $document):
</tr>
<?php
$i = 0;
foreach ($documents as $document):
$class = null;
if ($i++ % 2 == 0) {
$class = ' class="altrow"';
}
?>
?>
<tr<?php echo $class;?>>
<td>
<?php echo $document['Document']['id']; ?>
</td>
<td>
<?php echo $document['Document']['created']; ?>
</td>
<td>
<?=$document['Document']['doc_page_count'];?>
<?=$time->nice($document['Document']['created']); ?>
</td>
<td>
<?php echo $html->link($document['User']['username'], array('controller' => 'users', 'action' => 'view', $document['User']['id'])); ?>
</td>
<td>
<?=$document['Document']['type'];?>
</td>
<td>
<?=$document['Document']['doc_page_count'];?>
</td>
<td>
<?=$html->link($document['Document']['pdf_filename'], '/pdf/'.$document['Document']['pdf_filename']);?>
</td>
<td>
<?
$pdf_created_at = $document['Document']['pdf_created_at'];
if($pdf_created_at != '0000-00-00 00:00:00') {
echo $time->nice($document['Document']['pdf_created_at']);
}
?>
</td>
<td>
<?
if($document['Document']['pdf_created_by_user_id']) {
$pdf_user_id = $document['Document']['pdf_created_by_user_id'];
echo $html->link($users[$pdf_user_id], '/users/view/'.$pdf_user_id);
}
?>
</td>
<td class="actions">
<?php echo $html->link(__('View', true), array('action' => 'view', $document['Document']['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php endforeach; ?>
</table>
</div>
<div class="paging">
<?php echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?>
| <?php echo $paginator->numbers();?>
<?php echo $paginator->next(__('next', true).' >>', array(), null, array('class' => 'disabled'));?>
</div>
<?php debug($users); ?>

View file

@ -54,6 +54,6 @@ switch($docType) {
<?php // debug($currency);?>
<?php //debug($docType);?>
<?php //debug($enquiry);?>
<?php debug($enquiry);?>
<?php debug($document);?>

View file

@ -67,12 +67,19 @@ if (isset($currentuser) == FALSE) {
</ul>
</li>
<li><?php echo $html->link('Documents', '/documents/index'); ?>
<ul>
<li class="last"><?php echo $html->link('Documents Index', '/documents/index'); ?></li>
</ul>
</li>
<li><?php echo $html->link('Jobs', '/jobs/index'); ?>
<ul>
<?
if ($currentuser['User']['access_level'] == 'manager' || $currentuser['User']['access_level'] == 'admin'):
?>
?>
<li><?= $html->link('Reports', '/jobs/reports'); ?></li>
<? endif; ?>
<li class="last"><?php echo $html->link('Job List', '/jobs/index'); ?></li>