Some updates to invoice

This commit is contained in:
Deon George 2013-06-11 14:30:13 +10:00
parent 0ba1177c87
commit ec4c976ac8
6 changed files with 273 additions and 316 deletions

View File

@ -44,10 +44,13 @@ class Auth_OSB extends Auth_ORM {
if ($mmto->loaded()) { if ($mmto->loaded()) {
// Check that the token is for this URI // Check that the token is for this URI
$mo = ORM::factory('Module',array('name'=>Request::current()->controller())); $mo = ORM::factory('Module',array('name'=>Request::current()->controller()));
$mmo = ORM::factory('Module_Method',array( $mmo = $mo->module_method
'module_id'=>$mo->id, ->where_open()
'name'=>strtolower(Request::current()->directory() ? sprintf('%s:%s',Request::current()->directory(),Request::current()->action()) : Request::current()->action()) ->where('name','=',strtolower(Request::current()->directory() ? sprintf('%s:%s',Request::current()->directory(),Request::current()->action()) : Request::current()->action()))
)); // @todo No longer required after all method names have been colon delimited
->or_where('name','=',strtolower(Request::current()->directory() ? sprintf('%s_%s',Request::current()->directory(),Request::current()->action()) : Request::current()->action()))
->where_close()
->find();
// Ignore the token if this is not the right method. // Ignore the token if this is not the right method.
if ($mmo->id == $mmto->method_id) { if ($mmo->id == $mmto->method_id) {

View File

@ -10,129 +10,5 @@
* @license http://dev.osbill.net/license.html * @license http://dev.osbill.net/license.html
*/ */
class Controller_Invoice extends Controller_TemplateDefault { class Controller_Invoice extends Controller_TemplateDefault {
protected $secure_actions = array(
'download'=>TRUE,
'list'=>TRUE,
'view'=>TRUE,
);
/**
* Show a list of invoices
*/
public function action_list() {
Block::add(array(
'title'=>sprintf('%s: %s - %s',_('Invoices For'),$this->ao->accnum(),$this->ao->name(TRUE)),
'body'=>Table::display(
$this->ao->invoice->find_all(),
25,
array(
'id'=>array('label'=>'ID','url'=>URL::link('user','invoice/view/')),
'date_orig'=>array('label'=>'Date Issued'),
'due_date'=>array('label'=>'Date Due'),
'total(TRUE)'=>array('label'=>'Total','class'=>'right'),
'total_credits(TRUE)'=>array('label'=>'Credits','class'=>'right'),
'payments_total(TRUE)'=>array('label'=>'Payments','class'=>'right'),
'due(TRUE)'=>array('label'=>'Still Due','class'=>'right'),
),
array(
'page'=>TRUE,
'type'=>'select',
'form'=>URL::link('user','invoice/view'),
)),
));
}
/**
* View an Invoice
*/
public function action_view() {
list($id,$output) = Table::page(__METHOD__);
$io = ORM::factory('Invoice',$id);
if (! $io->loaded() OR ! Auth::instance()->authorised($io->account)) {
$this->template->content = 'Unauthorised or doesnt exist?';
return FALSE;
}
$output .= View::factory($this->viewpath())
->set('mediapath',Route::get('default/media'))
->set('io',$io);
if ($io->due() AND ! $io->cart_exists()) {
$output .= View::factory($this->viewpath().'/pay')
->set('mid',$io->mid())
->set('o',$io);
}
if (! $io->status) {
// Add a gribber popup
// @todo Make a gribber popup a class on its own.
Style::add(array(
'type'=>'file',
'data'=>'css/jquery.gritter.css',
'media'=>'screen',
));
Script::add(array(
'type'=>'file',
'data'=>'js/jquery.gritter-1.5.js',
));
Script::add(array(
'type'=>'stdin',
'data'=>sprintf(
'$(document).ready(function() {
$.extend($.gritter.options, {
fade_in_speed: "medium",
fade_out_speed: 2000,
time: "3000",
sticky: false,
});
$.gritter.add({
title: "%s",
text: "%s",
image: "%s",
});});',
'Cancelled','Invoice CANCELLED',URL::site().SystemMessage::image('info',true)
)
));
Style::add(array(
'type'=>'stdin',
'data'=>'
#watermark {
color: #800000;
font-size: 4em;
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
position: absolute;
width: 100%;
height: 100%;
margin: 0;
z-index: 1;
left:250px;
top:-20px;
}
'));
$output .= '<div id="watermark"><p>Invoice CANCELLED.</p></div>';
}
Block::add(array(
'title'=>sprintf('%s: %s - %s',_('Invoice'),$io->refnum(),$io->account->name()),
'body'=>$output,
));
}
/**
* Download an invoice
*/
public function action_download() {
$io = ORM::factory('Invoice',$this->request->param('id'));
$this->response->body(Invoice::instance($io)->pdf()->Output(sprintf('%s.pdf',$io->refnum()),'D'));
$this->response->headers(array('Content-Type' => 'application/pdf'));
$this->auto_render = FALSE;
}
} }
?> ?>

View File

@ -10,5 +10,80 @@
* @license http://dev.osbill.net/license.html * @license http://dev.osbill.net/license.html
*/ */
class Controller_User_Invoice extends Controller_Invoice { class Controller_User_Invoice extends Controller_Invoice {
protected $secure_actions = array(
'download'=>TRUE,
'list'=>TRUE,
'view'=>TRUE,
);
/**
* Download an invoice
*/
public function action_download() {
$io = ORM::factory('Invoice',$this->request->param('id'));
$this->response->body(Invoice::instance($io)->pdf()->Output(sprintf('%s.pdf',$io->refnum()),'D'));
$this->response->headers(array('Content-Type' => 'application/pdf'));
$this->auto_render = FALSE;
}
/**
* Show a list of invoices
*/
public function action_list() {
Block::factory()
->title(sprintf('Invoices for Account: %s',$this->ao->accnum()))
->title_icon('icon-th-list')
->body(Table::factory()
->jssort('invoices')
->data($this->ao->invoice->find_all())
->columns(array(
'id'=>'ID',
'date_orig'=>'Date Issued',
'due_date'=>'Date Due',
'total(TRUE)'=>'Total',
'total_credits(TRUE)'=>'Credits',
'payments_total(TRUE)'=>'Payments',
'due(TRUE)'=>'Still Due',
))
->prepend(array(
'id'=>array('url'=>URL::link('user','invoice/view/')),
))
);
}
/**
* View an Invoice
*/
public function action_view() {
list($id,$output) = Table::page(__METHOD__);
$io = ORM::factory('Invoice',$id);
if (! $io->loaded() OR ! Auth::instance()->authorised($io->account))
throw HTTP_Exception::factory(403,'Service either doesnt exist, or you are not authorised to see it');
$output .= View::factory('invoice/user/view')
->set('mediapath',Route::get('default/media'))
->set('o',$io);
if ($io->due() AND ! $io->cart_exists())
$output .= View::factory('/invoice/user/view/pay')
->set('mid',$io->mid())
->set('o',$io);
if (! $io->status) {
Style::factory()
->type('file')
->data('media/css/pages/invoice.css');
$output .= '<div id="watermark">Invoice CANCELLED.</div>';
}
Block::factory()
->title(sprintf('%s: %s - %s',_('Invoice'),$io->refnum(),$io->account->name()))
->title_icon('icon-list-alt')
->body($output);
}
} }
?> ?>

View File

@ -0,0 +1,13 @@
#watermark {
color: #800000;
font-size: 4em;
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
position: absolute;
width: 100%;
height: 100%;
margin: 0;
z-index: 1;
left:350px;
top:-50px;
}

View File

@ -1,12 +1,12 @@
<!-- @todo NEED to translate this --> <div class="row">
<table class="box-left" border="0"> <div class="span11">
<div class="span5">
<div class="row">
<table>
<tr> <tr>
<td style="vertical-align: top"> <td style="vertical-align: top"><?php echo HTML::image('http://www.gth.bgo.co/logo-blue'); ?></td>
<table class="company_details" border="0"> <td style="text-align: right; font-weight: bold">
<tr> <?php echo Company::instance()->name(); ?><br/>
<td class="logo"><?php echo Company::instance()->logo(); ?></td>
<td class="address">
<span class="company_name"><?php echo Company::instance()->name(); ?></span><br/>
<?php echo Company::instance()->taxid(); ?><br/> <?php echo Company::instance()->taxid(); ?><br/>
<br/> <br/>
<?php echo Company::instance()->address(); ?><br/> <?php echo Company::instance()->address(); ?><br/>
@ -15,70 +15,61 @@
</td> </td>
</tr> </tr>
</table> </table>
</td> </div> <!-- /row -->
<td>&nbsp;</td> </div> <!-- /span -->
<td>
<table class="invoice_summary" border="0"> <div class="span5">
<tr> <div class="row">
<td>TAX INVOICE</td> <div class="dl-horizontal">
<td class="bold-right"><?php echo $io->id(); ?></td> <dt>Tax Invoice</dt>
</tr> <dd><?php echo $o->id(); ?></dd>
<tr> <dt>Issue Date</dt>
<td>Issue Date</td> <dd><?php echo $o->display('date_orig'); ?></dd>
<td class="bold-right"><?php echo $io->display('date_orig'); ?></td> <dt>Due Date</dt>
</tr> <dd><?php echo $o->display('due_date'); ?></dd>
<tr> <dt>Current Charges</dt>
<td>Due Date</td> <dd><?php echo $o->total_charges(TRUE); ?></dd>
<td class="bold-right"><?php echo $io->display('due_date'); ?></td> <dt>Payments Recieved</dt>
</tr> <dd><?php echo $o->payments_total(TRUE); ?></dd>
<tr> <dt>Credits Applied</dt>
<td>Current Charges</td> <dd><?php echo $o->total_credits(TRUE); ?></dd>
<td class="bold-right"><?php echo $io->total_charges(TRUE); ?></td> <dt>Still Due</dt>
</tr> <dd><?php echo $o->due(TRUE); ?></dd>
<tr> </div>
<td>Payments Received to Date</td> </div> <!-- /row -->
<td class="bold-right"><?php echo $io->payments_total(TRUE); ?></td> </div> <!-- /span -->
</tr> </div> <!-- /span -->
<tr> </div>
<td>Credits Applied to Date</td>
<td class="bold-right"><?php echo $io->total_credits(TRUE); ?></td> <div class="row">
</tr> <div class="span11">
<tr> <h4>Charge Details</h4>
<td>Total Charges Due This Invoice</td>
<td class="bold-right"><?php echo $io->due(TRUE); ?></td> <div class="accordion" id="charges">
</tr> <div class="accordion-group">
</table>
</td> <?php foreach ($o->items_index('period') as $rs => $items) : ?>
</tr> <div class="accordion-heading">
<tr><td class="spacer" colspan="3">&nbsp;</td></tr> <a class="accordion-toggle" data-toggle="collapse" data-parent="#charges" data-target="#collapse_<?php echo $rs; ?>">
<tr> <?php if ($rs) :
<td colspan="3"> printf('%s - %s service(s)',StaticList_RecurSchedule::get($rs),count($items));
<table border="0"> else :
<tr> echo 'Other Items';
<td class="head" colspan="4">Charges Detail:</td> endif ?>
</tr> </a>
<?php foreach ($io->items_index('period') as $rs => $items) { ?> </div>
<tr>
<td><div id="toggle_<?php echo $rs; ?>"><?php echo HTML::image($mediapath->uri(array('file'=>'img/toggle-closed.png')),array('alt'=>'+')); ?></div><script type="text/javascript">$("#toggle_<?php echo $rs; ?>").click(function() {$('#detail_toggle_<?php echo $rs; ?>').toggle();});</script></td> <?php if ($items) : ?>
<?php if ($rs) { ?> <div id="collapse_<?php echo $rs; ?>" class="accordion-body collapse in">
<td><?php echo StaticList_RecurSchedule::get($rs); ?></td> <table>
<td><?php printf('%s Service(s)',count($items)); ?></td>
<td>&nbsp;</td> <?php
<?php } else { ?> foreach ($items as $k=>$service_id) :
<td colspan="3">Other Items</td>
<?php } ?>
</tr>
<tr>
<td>&nbsp;</td>
<td colspan="2">
<div id="detail_toggle_<?php echo $rs; ?>">
<table class="box-full" border="0">
<?php if ($items) {
foreach ($items as $k=>$service_id) {
$i = 0; $i = 0;
$lp = NULL; $lp = NULL;
$ito_tax = NULL; $ito_tax = NULL;
foreach ($io->items_service($service_id) as $ito) {
foreach ($o->items_service($service_id) as $ito) {
$ito_tax = $ito; $ito_tax = $ito;
// Our first line we show the Service Details // Our first line we show the Service Details
if ($ito->item_type == 0 AND $ito->product_id != $lp) { if ($ito->item_type == 0 AND $ito->product_id != $lp) {
@ -87,7 +78,7 @@
<tr class="head"> <tr class="head">
<td><?php echo HTML::anchor(URL::link('user','service/view/'.$ito->service_id),$ito->service->id()); ?></td> <td><?php echo HTML::anchor(URL::link('user','service/view/'.$ito->service_id),$ito->service->id()); ?></td>
<td colspan="5"><?php printf('%s - %s',$ito->product->title(),$ito->service->name()); ?> (<?php echo $ito->product_id; ?>)</td> <td colspan="5"><?php printf('%s - %s',$ito->product->title(),$ito->service->name()); ?> (<?php echo $ito->product_id; ?>)</td>
<td class="right"><?php echo ($i++==0 ? Currency::display($io->items_service_total($ito->service_id)) : '&nbsp;');?></td> <td class="right"><?php echo ($i++==0 ? Currency::display($o->items_service_total($ito->service_id)) : '&nbsp;');?></td>
</tr> </tr>
<!-- END Product Information --> <!-- END Product Information -->
<?php } ?> <?php } ?>
@ -106,40 +97,37 @@
<tr> <tr>
<td colspan="4">&nbsp;</td> <td colspan="4">&nbsp;</td>
<td><?php echo _('Discounts'); ?></td> <td><?php echo _('Discounts'); ?></td>
<td class="right">(<?php echo Currency::display($io->items_service_discount($ito->service_id));?>)</td> <td class="right">(<?php echo Currency::display($o->items_service_discount($ito->service_id));?>)</td>
</tr> </tr>
<?php } ?> <?php } ?>
<!-- END Service Discount Information --> <!-- END Service Discount Information -->
<?php } ?> <?php } ?>
<?php if ($ito_tax) { ?> <?php if ($ito_tax) { ?>
<!-- Product Sub Items Tax --> <!-- Product Sub Items Tax -->
<tr> <tr>
<td colspan="4">&nbsp;</td> <td colspan="4">&nbsp;</td>
<td><?php echo _('Taxes'); ?></td> <td><?php echo _('Taxes'); ?></td>
<td class="right"><?php echo Currency::display($io->items_service_tax($ito->service_id));?>&nbsp;</td> <td class="right"><?php echo Currency::display($o->items_service_tax($ito->service_id));?>&nbsp;</td>
</tr> </tr>
<!-- END Product Sub Items Tax --> <!-- END Product Sub Items Tax -->
<?php } ?> <?php } ?>
<?php } ?> <?php endforeach ?>
<?php } ?> <?php endif ?>
</table> </table>
</div> </div>
</td> <?php endforeach ?>
<td>&nbsp;</td>
</tr> <?php if ($o->items_index('account')) : ?>
<?php } ?> <div class="accordion-heading">
<?php if ($io->items_index('account')) { ?> <a class="accordion-toggle" data-toggle="collapse" data-parent="#charges" data-target="#collapse_other">Other Items</a>
<tr> </div>
<td><?php echo HTML::image($mediapath->uri(array('file'=>'img/toggle-closed.png')),array('alt'=>'+')); ?></td>
<td colspan="2">Other Invoice Items</td> <div id="collapse_<?php echo $rs; ?>" class="accordion-body collapse">
<td>&nbsp;</td> <table>
</tr>
<tr> <?php foreach ($o->items_index('account') as $id => $ito) : ?>
<td>&nbsp;</td>
<td colspan="2">
<div id="detail_toggle_other">
<table class="box-full" border="0">
<?php foreach ($io->items_index('account') as $id => $ito) { ?>
<tr> <tr>
<td>&nbsp;</td> <td>&nbsp;</td>
<td><?php echo $ito->trannum();?></td> <td><?php echo $ito->trannum();?></td>
@ -152,67 +140,69 @@
<tr> <tr>
<td colspan="4">&nbsp;</td> <td colspan="4">&nbsp;</td>
<td><?php echo _('Taxes'); ?></td> <td><?php echo _('Taxes'); ?></td>
<td class="right"><?php echo Currency::display($io->items_service_tax($ito->service_id));?>&nbsp;</td> <td class="right"><?php echo Currency::display($o->items_service_tax($ito->service_id));?>&nbsp;</td>
</tr> </tr>
<!-- Product End Sub Items Tax --> <!-- Product End Sub Items Tax -->
<?php } ?> <?php endforeach ?>
</table> </table>
</div> </div>
</td> <?php endif ?>
<td>&nbsp;</td>
</tr> </div>
<?php } ?> </div>
<!-- Invoice Sub Total -->
<tr> </div> <!-- /span -->
<td class="head" colspan="2">Sub Total of Items:</td> </div>
<td class="bold-right" colspan="2"><?php echo $io->subtotal(TRUE); ?></td>
</tr> <div class="row">
<div class="span11">
<div class="span5">
</div> <!-- /span -->
<div class="span5">
<div class="row">
<div class="dl-horizontal">
<!-- Sub Total -->
<dt>Sub Total</dt>
<dd><?php echo $o->subtotal(TRUE); ?></dd>
<!-- END Invoice Sub Total --> <!-- END Invoice Sub Total -->
<?php if ($io->total_credits()) { ?>
<!-- Invoice Credits --> <!-- Invoice Credits -->
<tr> <?php if ($o->total_credits()) : ?>
<td class="head" colspan="2">Credits Received:</td> <dt>Credits</dt>
<td class="bold-right" colspan="2"><?php echo $io->total_credits(TRUE); ?></td> <dd><?php echo $o->total_credits(TRUE); ?></dd>
</tr> <?php endif ?>
<!-- END Invoice Credits --> <!-- END Invoice Credits -->
<?php } ?>
<?php if ($io->total_discounts()) { ?>
<!-- Invoice Discounts Total --> <!-- Invoice Discounts Total -->
<tr> <?php if ($o->total_discounts()) : ?>
<td class="head" colspan="2">Discounts:</td> <dt>Discounts</dt>
<td class="bold-right" colspan="2">(<?php echo $io->total_discounts(TRUE); ?>)</td> <dd><?php echo $o->total_discounts(TRUE); ?></dd>
</tr> <?php endif ?>
<!-- END Invoice Discounts Total --> <!-- END Invoice Discounts Total -->
<?php } ?>
<!-- Invoice Taxes Total --> <!-- Invoice Taxes Total -->
<tr> <dt>Taxes Included:</dt>
<td class="head" colspan="4">Taxes Included:</td> <?php foreach ($o->tax_summary() as $tid => $amount) :
</tr>
<?php foreach ($io->tax_summary() as $tid => $amount) {
$m = ORM::factory('Tax',$tid); ?> $m = ORM::factory('Tax',$tid); ?>
<tr> <dd><?php printf('%s (%s)',Currency::display($amount),$m->description); ?><dd>
<td>&nbsp;</td> <?php endforeach ?>
<td><?php echo $m->description; ?></td>
<td class="bold-right" colspan="2"><?php echo Currency::display($amount); ?></td>
</tr>
<?php }?>
<!-- END Invoice Taxes Total --> <!-- END Invoice Taxes Total -->
<!-- Invoice Total --> <!-- Invoice Total -->
<tr> <dt>Total This Invoice:</dt>
<td class="head" colspan="2">Total This Invoice:</td> <dd><?php echo $o->total(TRUE); ?></dd>
<td class="bold-right" colspan="2"><?php echo $io->total(TRUE); ?></td>
</tr>
<!-- END Invoice Total --> <!-- END Invoice Total -->
<!-- Account Total Due --> <!-- Account Total Due -->
<tr> <dt>Total Outstanding This Account:</dt>
<td class="head" colspan="2">Total Outstanding This Account:</td> <dd><?php echo $o->account->invoices_due_total(NULL,TRUE); ?></dd>
<td class="bold-right" colspan="2"><?php echo $io->account->invoices_due_total(NULL,TRUE); ?></td>
</tr>
<!-- END Account Total Due --> <!-- END Account Total Due -->
</table>
</td> </div>
</tr> </div> <!-- /row -->
<tr> </div> <!-- /span -->
<td><?php echo HTML::anchor(URL::link('user','invoice/download/'.$io->id),'Download detailed invoice'); ?></td> </div> <!-- /span -->
</tr> </div>
</table>
<?php echo Form::button(URL::link('user','invoice/download/'.$o->id),'Download detailed invoice',array('class'=>'btn btn-primary pull-right')); ?></td>