invoice PDF generation working. More work still needed

This commit is contained in:
Karl Cordes 2011-08-15 16:04:38 +10:00
parent a92eb939a4
commit e400230c41
10 changed files with 67 additions and 37 deletions

View file

@ -4,6 +4,6 @@
RewriteRule (.*) webroot/$1 [L] RewriteRule (.*) webroot/$1 [L]
</IfModule> </IfModule>
<FilesMatch ".(js|css|txt)$"> <FilesMatch ".(js|css|txt|pf)$">
Header unset Cache-Control Header unset Cache-Control
</FilesMatch> </FilesMatch>

View file

@ -47,6 +47,7 @@ class DocumentsController extends AppController {
break; break;
case 'invoice': case 'invoice':
$docTypeElement = 'document_invoice_view'; $docTypeElement = 'document_invoice_view';
$this->set('invoice', $this->Document->Invoice->find('first', array('conditions'=>array('Invoice.id'=>$document['Invoice']['id']))));
break; break;
case 'purchaseOrder': case 'purchaseOrder':
@ -152,15 +153,17 @@ class DocumentsController extends AppController {
$this->data['Document']['type'] = 'invoice'; $this->data['Document']['type'] = 'invoice';
$this->data['Invoice']['issue_date'] = date('Y-m-d'); //Argh. Quote model uses 'date_issed'. $this->data['Invoice']['issue_date'] = date('Y-m-d'); //Argh. Quote model uses 'date_issed'.
$this->data['Invoice']['due_date'] = date("Y-m-d", strtotime("+30 days"));
$this->data['Document']['currency_id'] = 2; //All new Invoices default to AUD.
$this->data['Invoice']['currency_id'] = 2; //All new Invoices default to AUD.
break; break;
case "purchaseOrder": case "purchaseOrder":
break; break;
case "orderAck": case "orderAck":
@ -435,15 +438,32 @@ class DocumentsController extends AppController {
$this->set('products', $document['LineItem']); $this->set('products', $document['LineItem']);
//If this is a quote, set the filename //Set filename for the document.
//@TODO FIX THIS FOR OTHER DOCTYPES //
if($document['Document']['revision'] > 0) { switch($docType) {
$filename = $enquiry['Enquiry']['title'].'_'.$document['Document']['revision'].'.pdf'; case "quote":
} $filename = $enquiry['Enquiry']['title'];
else { break;
$filename = $enquiry['Enquiry']['title'].'.pdf';
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); $this->set('filename', $filename);
$document['Document']['pdf_filename'] = $filename; $document['Document']['pdf_filename'] = $filename;

View file

@ -82,7 +82,6 @@ class InvoicesController extends AppController {
$this->redirect(array('action'=>'index')); $this->redirect(array('action'=>'index'));
} }
} }
} }
/* function edit($id = null) { /* function edit($id = null) {

View file

@ -114,17 +114,12 @@ class Document extends AppModel {
function getCMCReferenceNumber($document, $type) { function getCMCReferenceNumber($document, $type) {
switch($type) { switch($type) {
case 'quote': case 'quote':
break; break;
case 'invoice': case 'invoice':
break; break;
case 'purchaseOrder': case 'purchaseOrder':
break; break;
case 'orderAck': case 'orderAck':
break; break;
} }
return $fullName; return $fullName;

View file

@ -5,17 +5,6 @@ echo $javascript->link('ckeditor/adapters/jquery');
echo $javascript->link('document_add_edit'); echo $javascript->link('document_add_edit');
?> ?>
<h2><?=$docTypeFullName?>: <?=$html->link($enquiry['Enquiry']['title'], array('controller'=>'enquiries','action'=>'view',$enquiry['Enquiry']['id']));?>
<?
if($document['Document']['revision'] > 0) {
echo "Revision {$document['Document']['revision']} ";
}
?>
for
<?=$html->link($enquiry['Customer']['name'], array('controller'=>'customers','action'=>'view',$enquiry['Customer']['id']));?>
</h2>
<?=$this->element('pdf_created_message'); ?> <?=$this->element('pdf_created_message'); ?>
<? <?
@ -57,4 +46,4 @@ echo $this->element($docTypeElement);
<?php //debug($enquiry);?> <?php //debug($enquiry);?>
<?php debug($document);?> <?php // debug($document);?>

View file

@ -1,5 +1,5 @@
<h2>Invoice: <?=$document['Invoice']['title']?></h2> <h2>Invoice: <?=$document['Invoice']['title']?> for <?=$html->link($enquiry['Customer']['name'], '/customers/view/'.$enquiry['Customer']['id']);?></h2>
<h2>Job: <?=$html->link($invoice['Job']['title'], array('controller'=>'jobs', 'action'=>'view', $invoice['Job']['id']));?></h2>
<? <?
echo $form->create('Document',array('type'=>'post','action'=>'edit', 'default'=>false)); echo $form->create('Document',array('type'=>'post','action'=>'edit', 'default'=>false));
@ -7,7 +7,10 @@ echo $form->input('Document.id');
?> ?>
<div class="docButtons"> <div class="docButtons">
<button id="generateFirstPage">(re)Generate First Page</button>
<button id="addPage">Add Content Page</button>
<button id="editQuoteDetails">View/Edit Quote Details</button>
<?=$html->link('Generate PDF of this Quote', '/documents/pdf/'.$document['Document']['id']);?>
</div> </div>
<div id="flashMessage" class="message"> <div id="flashMessage" class="message">
@ -19,3 +22,5 @@ echo $form->input('Document.id');
<? //debug($enquiry);?> <? //debug($enquiry);?>
<?php //debug($document);?> <?php //debug($document);?>
<?php //debug($docType);?> <?php //debug($docType);?>
<? //debug($invoice); ?>

View file

@ -1,4 +1,14 @@
<h2><?=$docTypeFullName?>: <?=$html->link($enquiry['Enquiry']['title'], array('controller'=>'enquiries','action'=>'view',$enquiry['Enquiry']['id']));?>
<?
if($document['Document']['revision'] > 0) {
echo "Revision {$document['Document']['revision']} ";
}
?>
for
<?=$html->link($enquiry['Customer']['name'], array('controller'=>'customers','action'=>'view',$enquiry['Customer']['id']));?>
</h2>
<? <?
echo $form->create('Document',array('type'=>'post','action'=>'edit', 'default'=>false)); echo $form->create('Document',array('type'=>'post','action'=>'edit', 'default'=>false));

View file

@ -239,6 +239,11 @@
</div> </div>
<ul id="jobsList" style="display: none;">
<? foreach($jobs as $job):?>
<li id="<?=$job['Job']['id'];?>"><?=$html->link($job['Job']['title'], "/documents/newDocument/invoice/{$job['Job']['enquiry_id']}/{$job['Job']['id']}");?></li>
<? endforeach;?>
</ul>
<div class="related"> <div class="related">
<h3><?php __($enquiry['Enquiry']['invoice_count'].' Invoices for this Enquiry');?></h3> <h3><?php __($enquiry['Enquiry']['invoice_count'].' Invoices for this Enquiry');?></h3>
@ -304,8 +309,6 @@
<td class="actions"> <td class="actions">
<?php echo $html->link(__('View', true), array('controller'=>'documents', 'action' => 'view', $invoice['Invoice']['document_id'])); ?> <?php echo $html->link(__('View', true), array('controller'=>'documents', 'action' => 'view', $invoice['Invoice']['document_id'])); ?>
<?php echo $html->link(__('Edit', true), array('controller'=>'invoices','action' => 'edit', $invoice['Invoice']['id'])); ?>
</td> </td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
@ -318,6 +321,7 @@
<li><?php //echo $html->link(__('New Invoice', true), array('controller'=>'invoices', 'action' => 'add/enquiryid:'.$enquiry['Enquiry']['id'])); ?> <li><?php //echo $html->link(__('New Invoice', true), array('controller'=>'invoices', 'action' => 'add/enquiryid:'.$enquiry['Enquiry']['id'])); ?>
</li> </li>
<li><?php echo $html->link(__('New Invoice', true), array('controller'=>'documents', 'action' => 'newDocument/invoice/'.$enquiry['Enquiry']['id'])); ?></li> <li><?php echo $html->link(__('New Invoice', true), array('controller'=>'documents', 'action' => 'newDocument/invoice/'.$enquiry['Enquiry']['id'])); ?></li>
<li><button class="addInvoice" id="<?=$enquiry['Enquiry']['id'];?>">New Invoice</button></li>
</ul> </ul>
</div> </div>

View file

@ -1615,6 +1615,6 @@ div.pdfGeneratedMessage {
margin-bottom: 1em; margin-bottom: 1em;
padding: 0.5em; padding: 0.5em;
border: 2px dashed; border: 2px dashed;
width: 50%; width: 45em;
font-size: 120%; font-size: 120%;
} }

View file

@ -58,6 +58,14 @@ $(function() {
window.location = '/documents/newDocument/quote/'+$( this ).attr('id'); 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();
}
});
}); });