Minor updatess

This commit is contained in:
Deon George
2013-02-26 14:19:32 +11:00
parent 288d974cfa
commit 2cdd130d1a
16 changed files with 117 additions and 50 deletions

View File

@@ -40,16 +40,23 @@ class Controller_Admin_Invoice extends Controller_TemplateDefault_Admin {
* Show a list of invoices
*/
public function action_list() {
$id = $this->request->param('id');
$invs = ORM::factory('Invoice');
if ($id)
$invs->where('account_id','=',$id);
Block::add(array(
'title'=>_('System Customer Invoices'),
'body'=>Table::display(
ORM::factory('Invoice')->find_all(),
$invs->find_all(),
25,
array(
'id'=>array('label'=>'ID','url'=>URL::link('user','invoice/view/')),
'date_orig'=>array('label'=>'Date'),
'total(TRUE)'=>array('label'=>'Total','class'=>'right'),
'credit_amt'=>array('label'=>'Credits','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'),
'account->accnum()'=>array('label'=>'Cust ID'),

View File

@@ -128,7 +128,7 @@ class Controller_Task_Invoice extends Controller_Task {
$et->variables = array(
'DUE'=>$io->due(TRUE),
'DUE_DATE'=>$io->display('due_date'),
'EMAIL'=>Company::email(),
'EMAIL'=>Company::instance()->email(),
'FIRST_NAME'=>$io->account->first_name,
'INV_NUM'=>$io->refnum(),
'INV_URL'=>URL::site(URL::link('user','invoice/view/'.$io->id),'http'),
@@ -299,7 +299,7 @@ class Controller_Task_Invoice extends Controller_Task {
$et->variables = array(
'DUE'=>$io->due(TRUE),
'DUE_DATE'=>$io->display('due_date'),
'EMAIL'=>Company::email(),
'EMAIL'=>Company::instance()->email(),
'FIRST_NAME'=>$io->account->first_name,
'HTML_INVOICE'=>$io->html(),
'INV_NUM'=>$io->refnum(),

View File

@@ -31,7 +31,7 @@ class Controller_User_Invoice extends Controller_TemplateDefault_User {
'date_orig'=>array('label'=>'Date Issued'),
'due_date'=>array('label'=>'Date Due'),
'total(TRUE)'=>array('label'=>'Total','class'=>'right'),
'credit_amt'=>array('label'=>'Credits','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'),
),

View File

@@ -135,7 +135,7 @@ class Invoice_TCPDF_Default extends Invoice_TCPDF {
// Draw a box.
$this->SetFillColor(245);
$this->SetXY($x-1,$y-1); $this->Cell(0,35+5+($this->io->credit_amt ? 5 : 0),'',1,0,'',1);
$this->SetXY($x-1,$y-1); $this->Cell(0,35+5+($this->io->total_credits() ? 5 : 0),'',1,0,'',1);
// Draw a box around the invoice due date and amount due.
$this->SetFont('helvetica','B',11);
@@ -172,12 +172,12 @@ class Invoice_TCPDF_Default extends Invoice_TCPDF {
$this->SetFont('helvetica','B',11);
$this->SetXY($x+55,$y); $this->Cell(0,0,$this->io->payments_total('TRUE'),0,0,'R');
if ($this->io->credit_amt) {
if ($this->io->total_credits()) {
$y += 5;
$this->SetFont('helvetica','',10);
$this->SetXY($x,$y); $this->Cell(0,0,'Credits Received');
$this->SetFont('helvetica','B',11);
$this->SetXY($x+55,$y); $this->Cell(0,0,$this->io->display('credit_amt'),0,0,'R');
$this->SetXY($x+55,$y); $this->Cell(0,0,$this->io->total_credits(TRUE),0,0,'R');
}
$y += 5;
@@ -319,7 +319,7 @@ class Invoice_TCPDF_Default extends Invoice_TCPDF {
$this->SetFillColor(245);
$this->SetXY($x-1,$y-1);
$this->Cell(0,5*(
1+1+1+3+($this->io->discount_amt ? 1 : 0)+1+($this->io->credit_amt ? 1 : 0)+$box
1+1+1+3+($this->io->total_discounts() ? 1 : 0)+1+($this->io->total_credits() ? 1 : 0)+$box
)+1+4,'',1,0,'',1);
$this->SetFont('helvetica','B',11);
@@ -355,7 +355,7 @@ class Invoice_TCPDF_Default extends Invoice_TCPDF {
// Calculate our rounding error
// @todo This shouldnt be required.
$subtotal = Currency::round($subtotal-$this->io->discount_amt);
#$subtotal = Currency::round($subtotal-$this->io->total_discounts());
if (Currency::round($this->io->subtotal()) != $subtotal) {
$this->SetFont('helvetica','',9);
@@ -369,7 +369,7 @@ class Invoice_TCPDF_Default extends Invoice_TCPDF {
}
// Draw Discounts.
if ($this->io->discount_amt) {
if ($this->io->total_discounts()) {
$y += 5;
$this->SetY($y);
@@ -377,7 +377,7 @@ class Invoice_TCPDF_Default extends Invoice_TCPDF {
$this->SetX($x+8);
$this->Cell(0,0,_('Discount'));
$this->SetX($x+135);
$this->Cell(0,0,Currency::display(-$this->io->discount_amt),0,0,'R');
$this->Cell(0,0,Currency::display(-$this->io->total_discounts()),0,0,'R');
}
// Subtotal and tax.
@@ -415,7 +415,7 @@ class Invoice_TCPDF_Default extends Invoice_TCPDF {
$this->SetX($x+135);
$this->Cell(0,0,$this->io->payments_total(TRUE),0,0,'R');
if ($this->io->credit_amt) {
if ($this->io->total_credits()) {
$y += 5;
$this->SetY($y);
@@ -423,7 +423,7 @@ class Invoice_TCPDF_Default extends Invoice_TCPDF {
$this->SetX($x+8);
$this->Cell(0,0,_('Less Credits'));
$this->SetX($x+135);
$this->Cell(0,0,Currency::display(-$this->io->credit_amt),0,0,'R');
$this->Cell(0,0,Currency::display(-$this->io->total_credits()),0,0,'R');
}
$y += 5;
@@ -479,7 +479,7 @@ class Invoice_TCPDF_Default extends Invoice_TCPDF {
$this->SetFont('helvetica','',8);
$this->SetX($x);
$this->Cell(0,0,$ito->service->service_name());
$this->Cell(0,0,sprintf('%s - %s',$ito->product->name(),$ito->service->name()));
if ($ito->price_base) {
$this->SetX($x+160);

View File

@@ -503,12 +503,10 @@ class Model_Invoice extends ORM_OSB implements Cartable {
if ($this->loaded() AND ! count($this->items()))
$this->_load_sub_items();
// This will include charges and credits
foreach ($this->items() as $ito)
$result += $ito->total();
// Reduce by any credits
$result -= $this->credit_amt;
return $format ? Currency::display($result) : Currency::round($result);
}
@@ -524,17 +522,13 @@ class Model_Invoice extends ORM_OSB implements Cartable {
public function total_credits($format=FALSE) {
$result = 0;
// @todo Remove when credit_amt is dropped.
if ($this->credit_amt)
$result = $this->credit_amt;
foreach ($this->items('CREDIT') as $ito)
$result += ($ito->subtotal()+$ito->tax())*-1;
return $format ? Currency::display($result) : Currency::round($result);
}
public function total_discount($format=FALSE) {
public function total_discounts($format=FALSE) {
$result = 0;
foreach ($this->items() as $ito)

View File

@@ -111,10 +111,10 @@
<td class="head" colspan="3">Sub Total of Items:</td>
<td class="bold-right"><?php echo $io->subtotal(TRUE); ?>&nbsp;</td>
</tr>
<?php if ($io->discount()) { ?>
<?php if ($io->total_discounts()) { ?>
<tr>
<td class="head" colspan="3">Discounts:</td>
<td class="bold-right">(<?php echo $io->discount(TRUE); ?>)</td>
<td class="bold-right">(<?php echo $io->total_discounts(TRUE); ?>)</td>
</tr>
<?php } ?>
<tr>

View File

@@ -168,19 +168,19 @@
<td class="bold-right" colspan="2"><?php echo $io->subtotal(TRUE); ?></td>
</tr>
<!-- END Invoice Sub Total -->
<?php if ($io->credit_amt) { ?>
<?php if ($io->total_credits()) { ?>
<!-- Invoice Credits -->
<tr>
<td class="head" colspan="2">Credits Received:</td>
<td class="bold-right" colspan="2"><?php echo $io->display('credit_amt'); ?></td>
<td class="bold-right" colspan="2"><?php echo $io->total_credits(TRUE); ?></td>
</tr>
<!-- END Invoice Credits -->
<?php } ?>
<?php if ($io->total_discount()) { ?>
<?php if ($io->total_discounts()) { ?>
<!-- Invoice Discounts Total -->
<tr>
<td class="head" colspan="2">Discounts:</td>
<td class="bold-right" colspan="2">(<?php echo $io->total_discount(TRUE); ?>)</td>
<td class="bold-right" colspan="2">(<?php echo $io->total_discounts(TRUE); ?>)</td>
</tr>
<!-- END Invoice Discounts Total -->
<?php } ?>