Improved service display
This commit is contained in:
@@ -56,7 +56,9 @@ class Controller_User_Invoice extends Controller_TemplateDefault {
|
||||
public function action_download($id) {
|
||||
$io = ORM::factory('invoice',$id);
|
||||
|
||||
return Invoice::instance()->pdf($io)->Output(sprintf('%s.pdf',$io->refnum()),'D');
|
||||
$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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -14,8 +14,12 @@ class Invoice {
|
||||
// This invoice Object
|
||||
private $io;
|
||||
|
||||
public static function instance() {
|
||||
return new Invoice;
|
||||
public function __construct($io) {
|
||||
$this->io = $io;
|
||||
}
|
||||
|
||||
public static function instance($io) {
|
||||
return new Invoice($io);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,14 +93,10 @@ SELECT i.id AS iid,i.due_date AS due FROM ab_invoice i,ab_invoice_item ii WHERE
|
||||
/**
|
||||
* Generate a PDF invoice
|
||||
*/
|
||||
public function pdf($io) {
|
||||
$invoice_class = sprintf('invoice_pdf_%s',Kohana::config('invoice.driver'));
|
||||
public function pdf() {
|
||||
$invoice_class = sprintf('invoice_tcpdf_%s',Kohana::config('invoice.driver'));
|
||||
|
||||
if (! class_exists($invoice_class))
|
||||
throw new Kohana_Exception('Invoice class :class doesnt exist',array(':class'=>$invoice_class));
|
||||
|
||||
$this->io = $io;
|
||||
$pdf = new $invoice_class($io);
|
||||
$pdf = new $invoice_class($this->io);
|
||||
|
||||
if ($pdf->getTemplate()) {
|
||||
$pagecount = $pdf->setSourceFile($pdf->getTemplate());
|
||||
@@ -125,105 +125,21 @@ SELECT i.id AS iid,i.due_date AS due FROM ab_invoice i,ab_invoice_item ii WHERE
|
||||
$pdf->drawRemittenceStub();
|
||||
$pdf->drawPaymentMethods();
|
||||
|
||||
if ($this->io->billing_status !=1 && $this->io->suspend_billing != 1 && $this->io->due_date <= time())
|
||||
$pdf->drawInvoiceDueNotice();
|
||||
elseif($this->io->billing_status == 1)
|
||||
$pdf->drawInvoicePaidNotice();
|
||||
if ($this->io->billing_status !=1 && $this->io->suspend_billing != 1 && $this->io->due_date <= time())
|
||||
$pdf->drawInvoiceDueNotice();
|
||||
elseif($this->io->billing_status == 1)
|
||||
$pdf->drawInvoicePaidNotice();
|
||||
|
||||
if ($this->io->account->invoices_due_total())
|
||||
$pdf->drawSummaryInvoicesDue();
|
||||
if ($this->io->account->invoices_due_total())
|
||||
$pdf->drawSummaryInvoicesDue();
|
||||
|
||||
$pdf->drawSummaryLineItems();
|
||||
return;
|
||||
#unset($pdf->itemsSummary);
|
||||
$pdf->drawSummaryLineItems();
|
||||
|
||||
# BEGIN loop for enumerating information in multiple ways on the invoice
|
||||
$iteration = 0;
|
||||
while ($pdf->drawLineItems_pre($iteration)) {
|
||||
foreach ($this->sInvoiceItems() as $index => $items) {
|
||||
# Get the date range if set
|
||||
if (! empty($items['date_start']) && ! empty($items['date_stop'])) {
|
||||
global $C_translate;
|
||||
$C_translate->value('invoice','start',date(UNIX_DATE_FORMAT,$items['date_start']));
|
||||
$C_translate->value('invoice','stop',date(UNIX_DATE_FORMAT,$items['date_stop']));
|
||||
}
|
||||
// Next Page
|
||||
$pdf->drawDetailLineItems();
|
||||
|
||||
$line = array(
|
||||
'name'=>$this->sLineItemDesc($index),
|
||||
'domain'=>$items['domain_name'],
|
||||
'amount'=>$items['price_base'],
|
||||
'sku'=>$items['sku'],
|
||||
'qty'=>$items['quantity'],
|
||||
'cost'=>$items['price_base'],
|
||||
'attr'=>$items['product_attr'],
|
||||
'price_type'=>$items['price_type'],
|
||||
'price_base'=>$items['price_base'],
|
||||
'item_type'=>$items['item_type'],
|
||||
'total_amt'=>$items['total_amt']
|
||||
);
|
||||
|
||||
if ($items['date_start'] && $items['date_stop'])
|
||||
if ($items['date_start'] == $items['date_stop'])
|
||||
$line['daterange'] = sprintf('%s',date(UNIX_DATE_FORMAT,$items['date_start']));
|
||||
else
|
||||
$line['daterange'] = sprintf('%s - %s',date(UNIX_DATE_FORMAT,$items['date_start']),date(UNIX_DATE_FORMAT,$items['date_stop']));
|
||||
|
||||
$pdf->drawLineItems($db,$line,$this->getRecordAttr('id'));
|
||||
|
||||
if ($items['price_setup']) {
|
||||
$line = array(
|
||||
'name'=>sprintf('%s - %s',$this->sLineItemDesc($index),_('Setup Charge')),
|
||||
'amount'=>$items['price_setup'],
|
||||
'qty'=>'1',
|
||||
'sku'=>$items['sku'],
|
||||
'cost'=>$items['price_setup'],
|
||||
'price_base'=>$items['price_setup'],
|
||||
'price_type'=>999
|
||||
);
|
||||
|
||||
$pdf->drawLineItems($db,$line,$this->getRecordAttr('id'));
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->print['invoice']['discount_amt']) {
|
||||
$line = array(
|
||||
'name'=>_('Discount'),
|
||||
'amount'=>-($this->print['invoice']['discount_amt']),
|
||||
'qty'=>'1',
|
||||
'cost'=>-($this->print['invoice']['discount_amt']),
|
||||
'price_base'=>-($this->print['invoice']['discount_amt']),
|
||||
'price_type'=>999);
|
||||
|
||||
$pdf->drawLineItems($db,$line,$this->getRecordAttr('id'));
|
||||
}
|
||||
|
||||
if ($this->print['invoice']['tax_amt']) {
|
||||
$rs = $db->Execute(sqlSelect($db,array('invoice_item_tax','tax'),'A.amount,B.description',sprintf('A.tax_id=B.id AND A.invoice_id=%s',$this->getRecordAttr('id'))));
|
||||
if ($rs && $rs->RecordCount()) {
|
||||
$taxes = array();
|
||||
|
||||
while (! $rs->EOF) {
|
||||
if (! isset($taxes[$rs->fields['description']]))
|
||||
$taxes[$rs->fields['description']] = $rs->fields['amount'];
|
||||
else
|
||||
$taxes[$rs->fields['description']] += $rs->fields['amount'];
|
||||
|
||||
$rs->MoveNext();
|
||||
}
|
||||
|
||||
foreach ($taxes as $txds => $txamt) {
|
||||
$line = array('name'=>$txds,'amount'=>$txamt,'total_amt'=>$txamt,'price_type'=>999);
|
||||
$pdf->drawLineItems($db,$line,$this->getRecordAttr('id'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Increment the iteration
|
||||
++$iteration;
|
||||
}
|
||||
|
||||
# Custom functions:
|
||||
$pdf->drawCustom();
|
||||
// Draw any Custom functions:
|
||||
$pdf->drawCustom();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -1,539 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Invoice_PDF_TCPDF extends Invoice_PDF {
|
||||
// Current line being printed
|
||||
public $sum_y = 0;
|
||||
|
||||
/**
|
||||
* Draw the logo
|
||||
*/
|
||||
public function drawCompanyLogo() {
|
||||
$x = 9; $y = 7;
|
||||
$size = 25;
|
||||
$logo = Config::logo_file();
|
||||
|
||||
if (is_file($logo))
|
||||
$this->Image($logo,$x,$y,$size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the Company Address
|
||||
*/
|
||||
public function drawCompanyAddress() {
|
||||
# Add the company address next to the logo
|
||||
$x = 40; $y = 7;
|
||||
|
||||
$this->SetFont('helvetica','B',10);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,Config::sitename()); $y += 4;
|
||||
|
||||
$this->SetFont('helvetica','',10);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,Company::taxid()); $y += 6;
|
||||
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,Company::street()); $y += 4;
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,sprintf('%s, %s %s',Company::city(),Company::state(),Company::pcode())); $y += 4;
|
||||
|
||||
$y += 2;
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,'Phone:'); $this->SetXY($x+16,$y); $this->Cell(0,0,Company::phone()); $y += 4;
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,'Fax:'); $this->SetXY($x+16,$y); $this->Cell(0,0,Company::fax()); $y += 4;
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,'Web:'); $this->SetXY($x+16,$y); $this->addHtmlLink(URL::base(TRUE,TRUE),URL::base(TRUE,TRUE)); $y += 4;
|
||||
}
|
||||
|
||||
public function drawRemittenceStub() {
|
||||
# Draw the remittance line
|
||||
$this->Line(9,195,200,195);
|
||||
|
||||
$x = 18; $y = 200;
|
||||
|
||||
$this->SetFont('helvetica','B',13);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('Payment Remittence')); $y +=5;
|
||||
|
||||
$this->SetFont('helvetica','',8);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('Please return this portion with your cheque or money order')); $y +=3;
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('made payable to').' '.Config::sitename());
|
||||
|
||||
# Due Date
|
||||
$x = 110; $y = 200;
|
||||
$this->SetFont('helvetica','',10);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('Issue Date'));
|
||||
$this->SetFont('helvetica','B',11);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,$this->io->display('date_orig'),0,0,'R');
|
||||
|
||||
# Account ID
|
||||
$y = 205;
|
||||
$this->SetFont('helvetica','',10);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('Account Number'));
|
||||
$this->SetFont('helvetica','B',11);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,$this->io->account->accnum(),0,0,'R');
|
||||
|
||||
# Invoice number
|
||||
$y = 210;
|
||||
$this->SetFont('helvetica','',10);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('Invoice Number'));
|
||||
$this->SetFont('helvetica','B',11);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,$this->io->invnum(),0,0,'R');
|
||||
|
||||
# Company Address
|
||||
$y = 216;
|
||||
$this->SetFont('helvetica','',10);
|
||||
$this->SetXY(18,$y); $this->Cell(0,0,Config::sitename()); $y += 4;
|
||||
$this->SetXY(18,$y); $this->Cell(0,0,Company::street()); $y += 4;
|
||||
$this->SetXY(18,$y); $this->Cell(0,0,sprintf('%s, %s %s',Company::city(),Company::state(),Company::pcode())); $y += 4;
|
||||
|
||||
# Previous Due
|
||||
$y = 215;
|
||||
$this->SetFont('helvetica','',9);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('Previous Due'));
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,$this->io->other_due(TRUE),0,0,'R');
|
||||
|
||||
$y = 219;
|
||||
$this->SetFont('helvetica','',9);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('Amount Due').' '.$this->io->display('due_date'));
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,$this->io->due(TRUE),0,0,'R');
|
||||
|
||||
# Total Due
|
||||
$y = 224;
|
||||
$this->SetFont('helvetica','B',10);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('Total Due'));
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,Currency::display($this->io->due() ? $this->io->account->invoices_due_total() : 0),0,0,'R');
|
||||
|
||||
# Draw the Customers Address
|
||||
$x = 25; $y = 248;
|
||||
|
||||
$this->SetFont('helvetica','B',12);
|
||||
|
||||
if ($this->billToCompany && ! empty($this->io->account->company))
|
||||
$name = $this->io->account->company;
|
||||
else
|
||||
$name = $this->io->account->name();
|
||||
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,html_entity_decode($name,ENT_NOQUOTES)); $y += 5;
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,sprintf('%s %s ',$this->io->account->address1,$this->io->account->address2)); $y += 5;
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,sprintf('%s, %s %s',$this->io->account->city,$this->io->account->state,$this->io->account->zip)); $y += 5;
|
||||
}
|
||||
|
||||
public function drawInvoiceHeader() {
|
||||
$x = 125; $y = 10;
|
||||
|
||||
# Draw a box.
|
||||
$this->SetFillColor(245);
|
||||
$this->SetXY($x-1,$y-1); $this->Cell(0,35+($this->io->billed_amt ? 5 : 0)+($this->io->credit_amt ? 5 : 0),'',1,0,'',1);
|
||||
|
||||
# Draw a box around the invoice due date and amount due.
|
||||
$this->SetFont('helvetica','B',11);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,'TAX INVOICE');
|
||||
$this->SetFont('helvetica','B',11);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,$this->io->invnum(),0,0,'R');
|
||||
|
||||
# Invoice number at top of page.
|
||||
$y += 7;
|
||||
$this->SetFont('helvetica','',10);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('Issue Date')); $y += 5;
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('Amount Due'));
|
||||
|
||||
$y -= 5;
|
||||
$this->SetFont('helvetica','B',11);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,$this->io->display('date_orig'),0,0,'R'); $y += 5;
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,$this->io->display('due_date'),0,0,'R');
|
||||
|
||||
$y += 5;
|
||||
$this->SetFont('helvetica','',10);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('Previous Due'));
|
||||
$this->SetFont('helvetica','B',11);
|
||||
$this->SetXY($x+55,$y); $this->Cell(0,0,$this->io->other_due(TRUE),0,0,'R');
|
||||
|
||||
$y += 5;
|
||||
$this->SetFont('helvetica','',10);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('Current Charges'));
|
||||
$this->SetFont('helvetica','B',11);
|
||||
$this->SetXY($x+55,$y); $this->Cell(0,0,$this->io->total(TRUE),0,0,'R');
|
||||
|
||||
if ($this->io->billed_amt) {
|
||||
$y += 5;
|
||||
$this->SetFont('helvetica','',10);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,'Payments Received');
|
||||
$this->SetFont('helvetica','B',11);
|
||||
$this->SetXY($x+55,$y); $this->Cell(0,0,$this->io->display('billed_amt'),0,0,'R');
|
||||
}
|
||||
|
||||
if ($this->io->credit_amt) {
|
||||
$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');
|
||||
}
|
||||
|
||||
$y += 5;
|
||||
$this->SetFont('helvetica','',10);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,'Total Payable');
|
||||
$this->SetFont('helvetica','B',11);
|
||||
$this->SetXY($x+55,$y); $this->Cell(0,0,Currency::display($this->io->due() ? $this->io->account->invoices_due_total() : 0),0,0,'R');
|
||||
}
|
||||
|
||||
#@todo Limit the size of the news to 6 lines
|
||||
public function drawNews($news) {
|
||||
if (! $news)
|
||||
return;
|
||||
|
||||
$x = 9; $y = 170;
|
||||
|
||||
# Draw a box.
|
||||
$this->SetFillColor(243);
|
||||
$this->SetXY($x-1,$y-1); $this->Cell(0,20,'',1,0,'',1);
|
||||
|
||||
$this->SetFont('helvetica','',8);
|
||||
$this->SetXY($x,$y); $this->MultiCell(0,3,str_replace('\n',"\n",$news),0,'L',0);
|
||||
}
|
||||
|
||||
#@todo make this list dynamic
|
||||
public function drawPaymentMethods() {
|
||||
$x = 120; $y = 242;
|
||||
|
||||
# Draw a box.
|
||||
$this->SetFillColor(235);
|
||||
$this->SetXY($x-1,$y-2); $this->Cell(0,32,'',1,0,'',1);
|
||||
|
||||
$this->SetFont('helvetica','B',8);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,'This invoice can also be paid by:'); $y += 4;
|
||||
|
||||
# Direct Credit
|
||||
$logo = Kohana::find_file('media','img/invoice-payment-dd','png');
|
||||
$this->Image($logo,$x+1,$y,8);
|
||||
$this->SetFont('helvetica','B',8);
|
||||
$this->SetXY($x+10,$y); $this->Cell(0,0,'Direct Credit to our Bank Account'); $y += 3;
|
||||
$this->SetFont('helvetica','',8);
|
||||
$this->SetXY($x+10,$y); $this->Cell(0,0,'BSB:'); $y += 3;
|
||||
$this->SetXY($x+10,$y); $this->Cell(0,0,'ACCOUNT:'); $y += 3;
|
||||
$this->SetXY($x+10,$y); $this->Cell(0,0,'REF:'); $y += 3;
|
||||
|
||||
$y -= 9;
|
||||
$this->SetFont('helvetica','B',8);
|
||||
$this->SetXY($x+30,$y); $this->Cell(0,0,Company::bsb()); $y += 3;
|
||||
$this->SetXY($x+30,$y); $this->Cell(0,0,Company::account()); $y += 3;
|
||||
$this->SetXY($x+30,$y); $this->Cell(0,0,$this->io->refnum()); $y += 3;
|
||||
|
||||
/*
|
||||
# Direct Debit
|
||||
$y += 3;
|
||||
$logo = sprintf('%s/%s',PATH_THEMES.DEFAULT_THEME,'invoice/invoice-payment-dd.png');
|
||||
$this->Image($logo,$x+1,$y,8);
|
||||
$this->SetFont('helvetica','B',8);
|
||||
$this->SetXY($x+10,$y); $this->Cell(0,0,'Direct Debit'); $y += 3;
|
||||
$this->SetFont('helvetica','',8);
|
||||
$this->SetXY($x+10,$y); $this->Cell(0,0,'Please visit '); $this->SetXY($x+30,$y); $this->addHtmlLink($inv->print['site']['URL'].'?_page=invoice:user_view&id='.$inv->getPrintInvoiceNum(),$inv->print['site']['URL']); $y += 3;
|
||||
*/
|
||||
|
||||
# Paypal
|
||||
$y += 3;
|
||||
$logo = Kohana::find_file('media','img/invoice-payment-pp','png');
|
||||
$this->Image($logo,$x+1,$y,8);
|
||||
$this->SetFont('helvetica','B',8);
|
||||
$this->SetXY($x+10,$y); $this->Cell(0,0,'Pay Pal/Credit Card'); $y += 3;
|
||||
$this->SetFont('helvetica','',8);
|
||||
$this->SetXY($x+10,$y); $this->Cell(0,0,'Please visit '); $this->SetXY($x+30,$y); $this->addHtmlLink(URL::base(TRUE,TRUE),URL::base(TRUE,TRUE)); $y += 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw previous invoices due
|
||||
*/
|
||||
public function drawSummaryInvoicesDue() {
|
||||
$x = 125; $y = $this->sum_y ? $this->sum_y : 50;
|
||||
|
||||
$items = $this->io->account->invoices_due();
|
||||
|
||||
# Calculate the box size
|
||||
$box = count($items) < $this->itemsPreviousMax ? count($items) : $this->itemsPreviousMax;
|
||||
|
||||
# Draw a box.
|
||||
$this->SetFillColor(245);
|
||||
$this->SetXY($x-1,$y-1); $this->Cell(0,5*(1+$box)+1,'',1,0,'',1);
|
||||
|
||||
$this->SetFont('helvetica','B',11);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('Previous Invoices due')); $y += 5;
|
||||
|
||||
$this->SetFont('helvetica','',11);
|
||||
$i = 0;
|
||||
$sum_total = 0;
|
||||
foreach ($items as $line) {
|
||||
if (++$i < $this->itemsPreviousMax) {
|
||||
$this->SetXY($x,$y);
|
||||
$this->Cell(0,0,sprintf('%s #%s',$line->display('date_orig'),$line->invnum()));
|
||||
$this->Cell(0,0,$line->due(TRUE),0,0,'R'); $y += 5;
|
||||
|
||||
} else {
|
||||
$sum_total += $line->due();
|
||||
}
|
||||
}
|
||||
|
||||
if ($sum_total) {
|
||||
$this->SetXY($x,$y);
|
||||
$this->SetFont('helvetica','I',11);
|
||||
$this->Cell(0,0,'Other invoices');
|
||||
$this->SetFont('helvetica','',11);
|
||||
$this->Cell(0,0,Currency::display($sum_total),0,0,'R'); $y += 5;
|
||||
}
|
||||
|
||||
$this->sum_y = $y+5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before begining to loop the invoice_item table. Used to set initial values.
|
||||
*/
|
||||
public function drawLineItems($iteration) {
|
||||
$this->iteration = $iteration;
|
||||
if ($iteration>1)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called once per line item to add to the PDF invoice. This function serves to
|
||||
* direct each iteration to a different function which handles a specific piece
|
||||
* of the PDF building puzzle.
|
||||
*/
|
||||
public function drawLineItem($line) {
|
||||
switch($this->iteration) {
|
||||
case 0:
|
||||
$this->drawLineItems_0($line);
|
||||
break;
|
||||
|
||||
default:
|
||||
echo 'Unknown PDF iteration encountered. Halting.';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the non-VoIP related items for iteration 0.
|
||||
* @todo need to make sure that this pages well, when there are many items (with many sub details).
|
||||
* @tood Need to replicate this to the other fpdf files
|
||||
*/
|
||||
private function drawLineItems_0($line) {
|
||||
if ($line['price_type'] == 0 && $line['item_type'] == 5)
|
||||
return;
|
||||
|
||||
$x = 10;
|
||||
if ($this->i == 0 || $this->i%51 == 0) {
|
||||
$this->y = 5;
|
||||
$this->AddPage();
|
||||
|
||||
$this->SetFont('helvetica','B',12);
|
||||
$this->SetXY($x,$this->y); $this->Cell(0,0,_('Itemised Charges'));
|
||||
$this->Cell(0,0,_('Page #').$this->PageNo(),0,0,'R');
|
||||
$this->SetXY($x,$this->y); $this->Cell(0,0,_('Invoice #').$invnum,0,0,'C');
|
||||
|
||||
# Draw table headers
|
||||
$this->y += 10;
|
||||
$this->SetFont('helvetica','B',8);
|
||||
$this->SetXY($x,$this->y);
|
||||
$this->Cell(0,0,_('Description'));
|
||||
$this->SetX($x+135);
|
||||
$this->Cell(0,0,_('Quantity'));
|
||||
$this->SetX($x+160);
|
||||
$this->Cell(10,0,_('Unit Cost'),0,0,'R');
|
||||
$this->SetX($x+135);
|
||||
$this->Cell(0,0,_('Amount'),0,0,'R');
|
||||
$this->Line($x,$this->y+4,200,$this->y+4);
|
||||
$this->y += 5;
|
||||
$this->SetY($this->y);
|
||||
}
|
||||
|
||||
$this->SetFont('helvetica','',8);
|
||||
$this->SetX($x);
|
||||
$this->Cell(0,0,$line['name']);
|
||||
|
||||
if (isset($line['price_base'])) {
|
||||
$this->SetX($x+160);
|
||||
$this->Cell(10,0,$this->_currency($line['price_base']),0,0,'R');
|
||||
}
|
||||
|
||||
if (isset($line['qty'])) {
|
||||
$this->SetX($x+130);
|
||||
$this->Cell(10,0,$line['qty'],0,0,'R');
|
||||
}
|
||||
|
||||
$this->SetX($x+130);
|
||||
$this->Cell(0,0,$this->_currency($line['total_amt']),0,0,'R');
|
||||
|
||||
if ($this->show_service_range && $line['daterange']) {
|
||||
$this->SetFont('helvetica','I',7);
|
||||
$this->y += 3;
|
||||
$this->SetXY($x+10,$this->y); $this->Cell(0,0,'Service Period');
|
||||
$this->SetFont('helvetica','',7);
|
||||
$this->SetXY($x+40,$this->y); $this->Cell(0,0,$line['daterange']);
|
||||
}
|
||||
|
||||
if ($line['domain']) {
|
||||
$this->SetFont('helvetica','I',7);
|
||||
$this->y += 3;
|
||||
$this->SetXY($x+10,$this->y); $this->Cell(0,0,'Domain');
|
||||
$this->SetFont('helvetica','',7);
|
||||
$this->SetXY($x+40,$this->y); $this->Cell(0,0,$line['domain']);
|
||||
}
|
||||
|
||||
if ($line['attr']) {
|
||||
$showchars = 20;
|
||||
if (preg_match('/^a:/',$line['attr']))
|
||||
$a = unserialize($line['attr']);
|
||||
else {
|
||||
$x = explode("\n",$line['attr']);
|
||||
$a = array();
|
||||
foreach ($x as $y)
|
||||
if ($y) {
|
||||
list($c,$d) = explode('==',$y);
|
||||
$a[$c] = $d;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($a as $field=>$value) {
|
||||
|
||||
if (in_array($field,array('service_account_name','service_address')))
|
||||
continue;
|
||||
|
||||
$this->SetFont('helvetica','I',7);
|
||||
$this->y += 3;
|
||||
$this->SetXY(20,$this->y); $this->Cell(0,0,strlen($field) > $showchars ? substr($field,0,$showchars-2).'...' : $field);
|
||||
$this->SetFont('helvetica','',7);
|
||||
$this->SetXY(50,$this->y); $this->Cell(0,0,$value);
|
||||
}
|
||||
}
|
||||
|
||||
$this->y += 5;
|
||||
$this->SetY($this->y);
|
||||
$this->i++;
|
||||
}
|
||||
|
||||
/**
|
||||
* This will draw the Summary Box, with the summary of the items
|
||||
* on the invoice.
|
||||
*/
|
||||
public function drawSummaryLineItems() {
|
||||
if (! $this->show_itemized)
|
||||
return;
|
||||
|
||||
$items = $this->io->items_summary();
|
||||
|
||||
# Calculate the box size
|
||||
$box = count($items) < $this->itemsSummaryMax ? count($items) : $this->itemsSummaryMax;
|
||||
|
||||
$x = 10; $y = $this->sum_y ? $this->sum_y : 55;
|
||||
|
||||
# Draw a box.
|
||||
$this->SetFillColor(245);
|
||||
$this->SetXY($x-1,$y-1); $this->Cell(0,5*(
|
||||
1+1+1+3+($this->io->discount_amt ? 1 : 0)+($this->io->billed_amt ? 1 : 0)+($this->io->credit_amt ? 1 : 0)+$box
|
||||
)+1,'',1,0,'',1);
|
||||
|
||||
$this->SetFont('helvetica','B',11);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('Current Charges Summary for')); $y += 5;
|
||||
|
||||
$this->SetY($y);
|
||||
$this->SetFont('helvetica','',9);
|
||||
|
||||
$i=0;
|
||||
foreach($items as $line) {
|
||||
$this->SetX($x);
|
||||
|
||||
$q = $line->quantity;
|
||||
if (empty($q))
|
||||
$q = 1;
|
||||
|
||||
$this->Cell(0,0,$q);
|
||||
$this->SetX($x+8);
|
||||
$this->Cell(0,0,sprintf('%s (%s)',$line->product->product_translate->find()->name,Currency::display($line->price_base)));
|
||||
$this->SetX($x+135);
|
||||
$this->Cell(0,0,Currency::display($line->price_base*$line->quantity+$line->price_setup),0,0,'R');
|
||||
$y += 5;
|
||||
$this->SetY($y);
|
||||
$i++;
|
||||
if ($i > $this->itemsSummaryMax) {
|
||||
$this->SetFont('helvetica','B',11);
|
||||
$this->SetX($x);
|
||||
$this->Cell(0,0,_('The above is just a summary. To view a detailed list of charges, please visit our website.'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
# Calculate our rounding error
|
||||
$subtotal = 0;
|
||||
foreach($items as $line)
|
||||
$subtotal += $line->price_base*$line->quantity+$line->price_setup;
|
||||
|
||||
$subtotal -= $this->io->discount_amt;
|
||||
$subtotal = round($subtotal,2);
|
||||
|
||||
if (round($this->io->total_amt-$this->io->tax_amt,2) != $subtotal) {
|
||||
$this->SetFont('helvetica','',9);
|
||||
$this->SetX($x);
|
||||
$this->Cell(0,0,'Rounding');
|
||||
$this->SetX($x+135);
|
||||
$this->Cell(0,0,
|
||||
Currency::display($this->io->total_amt-$this->io->tax_amt-$subtotal),0,0,'R');
|
||||
$y += 5;
|
||||
$this->SetY($y);
|
||||
}
|
||||
|
||||
# Draw Discounts.
|
||||
if ($this->io->discount_amt) {
|
||||
$y += 5;
|
||||
$this->SetY($y);
|
||||
$this->SetFont('helvetica','B',9);
|
||||
$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');
|
||||
}
|
||||
|
||||
# Sub total and tax.
|
||||
$y += 5;
|
||||
$this->SetY($y);
|
||||
$this->SetFont('helvetica','B',9);
|
||||
$this->SetX($x+8);
|
||||
$this->Cell(0,0,'Sub Total');
|
||||
$this->SetX($x+135);
|
||||
$this->Cell(0,0,Currency::display($this->io->total_amt-$this->io->tax_amt),0,0,'R');
|
||||
|
||||
$y += 5;
|
||||
$this->SetY($y);
|
||||
$this->SetX($x+8);
|
||||
$this->Cell(0,0,'Taxes');
|
||||
$this->SetX($x+135);
|
||||
$this->Cell(0,0,Currency::display($this->io->tax_amt),0,0,'R');
|
||||
|
||||
$y += 5;
|
||||
$this->SetY($y);
|
||||
$this->SetX($x+8);
|
||||
$this->Cell(0,0,'Total Charges');
|
||||
$this->SetX($x+135);
|
||||
$this->Cell(0,0,Currency::display($this->io->total_amt),0,0,'R');
|
||||
|
||||
# Show payments already received for this invoice
|
||||
if ($this->io->billed_amt) {
|
||||
$y += 5;
|
||||
$this->SetY($y);
|
||||
$this->SetX($x+8);
|
||||
$this->Cell(0,0,'Payments Received');
|
||||
$this->SetX($x+135);
|
||||
$this->Cell(0,0,Currency::display($this->io->billed_amt),0,0,'R');
|
||||
}
|
||||
|
||||
if ($this->io->credit_amt) {
|
||||
$y += 5;
|
||||
$this->SetY($y);
|
||||
$this->SetFont('helvetica','B',9);
|
||||
$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');
|
||||
}
|
||||
|
||||
$y += 5;
|
||||
$this->SetY($y);
|
||||
$this->SetX($x+8);
|
||||
$this->Cell(0,0,'Balance Due');
|
||||
$this->SetX($x+135);
|
||||
$this->Cell(0,0,$this->io->due(TRUE),0,0,'R');
|
||||
}
|
||||
}
|
||||
?>
|
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides invoice PDF rendering capability
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Invoice
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
|
||||
define('FPDF_FONTPATH','includes/tcpdf/fonts/');
|
||||
@@ -8,10 +17,9 @@ require_once('includes/tcpdf/tcpdf.php');
|
||||
/**
|
||||
* PDF Invoice Base
|
||||
*
|
||||
* @package AgileBill
|
||||
* @subpackage Module:Invoice
|
||||
*/
|
||||
abstract class Invoice_PDF extends TCPDF {
|
||||
abstract class Invoice_TCPDF extends TCPDF {
|
||||
// Our invoice object
|
||||
protected $io;
|
||||
|
||||
@@ -45,8 +53,8 @@ abstract class Invoice_PDF extends TCPDF {
|
||||
$this->SetCreator('Open Source Billing');
|
||||
$this->SetAuthor(Config::sitename());
|
||||
$this->SetTitle(sprintf('%s Invoice',Config::sitename()));
|
||||
$this->SetSubject(sprintf('Invoice #%06s',$this->io->invnum()));
|
||||
$this->SetKeywords($this->io->invnum());
|
||||
$this->SetSubject(sprintf('Invoice #%06s',$this->io->id()));
|
||||
$this->SetKeywords($this->io->id());
|
||||
$this->SetAutoPageBreak(TRUE,25);
|
||||
$this->SetHeaderMargin(1);
|
||||
$this->SetFooterMargin(10);
|
||||
@@ -58,20 +66,6 @@ abstract class Invoice_PDF extends TCPDF {
|
||||
abstract public function drawCompanyLogo();
|
||||
abstract public function drawCompanyAddress();
|
||||
abstract public function drawInvoiceHeader();
|
||||
|
||||
/**
|
||||
* Enable re-iteration of the invoices items, so that they can be displayed many ways
|
||||
*/
|
||||
abstract public function drawLineItems($iteration);
|
||||
|
||||
/**
|
||||
* This is called for each line item.
|
||||
*/
|
||||
abstract public function drawLineItem($line);
|
||||
|
||||
/**
|
||||
* Draws the summary on the first page
|
||||
*/
|
||||
abstract public function drawSummaryLineItems();
|
||||
abstract public function drawPaymentMethods();
|
||||
abstract public function drawRemittenceStub();
|
523
modules/invoice/classes/invoice/tcpdf/default.php
Normal file
523
modules/invoice/classes/invoice/tcpdf/default.php
Normal file
@@ -0,0 +1,523 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides invoice rending use TCPDF
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Invoice
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Invoice_TCPDF_Default extends Invoice_TCPDF {
|
||||
// Current line being printed
|
||||
public $sum_y = 0;
|
||||
|
||||
private $max_lines_page = 51;
|
||||
protected $show_service_range = TRUE;
|
||||
|
||||
/**
|
||||
* Draw the logo
|
||||
*/
|
||||
public function drawCompanyLogo() {
|
||||
$x = 9; $y = 7;
|
||||
$size = 25;
|
||||
$logo = Config::logo_file();
|
||||
|
||||
if (is_file($logo))
|
||||
$this->Image($logo,$x,$y,$size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the Company Address
|
||||
*/
|
||||
public function drawCompanyAddress() {
|
||||
// Add the company address next to the logo
|
||||
$x = 40; $y = 7;
|
||||
|
||||
$this->SetFont('helvetica','B',10);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,Config::sitename()); $y += 4;
|
||||
|
||||
$this->SetFont('helvetica','',10);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,Company::taxid()); $y += 6;
|
||||
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,Company::street()); $y += 4;
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,sprintf('%s, %s %s',Company::city(),Company::state(),Company::pcode())); $y += 4;
|
||||
|
||||
$y += 2;
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,'Phone:'); $this->SetXY($x+16,$y); $this->Cell(0,0,Company::phone()); $y += 4;
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,'Fax:'); $this->SetXY($x+16,$y); $this->Cell(0,0,Company::fax()); $y += 4;
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,'Web:'); $this->SetXY($x+16,$y); $this->addHtmlLink(URL::base(TRUE,TRUE),URL::base(TRUE,TRUE)); $y += 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the remmittence stub
|
||||
*/
|
||||
public function drawRemittenceStub() {
|
||||
// Draw the remittance line
|
||||
$this->Line(9,195,200,195);
|
||||
|
||||
$x = 18; $y = 200;
|
||||
|
||||
$this->SetFont('helvetica','B',13);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('Payment Remittence')); $y +=5;
|
||||
|
||||
$this->SetFont('helvetica','',8);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('Please return this portion with your cheque or money order')); $y +=3;
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('made payable to').' '.Config::sitename());
|
||||
|
||||
// Due Date
|
||||
$x = 110; $y = 200;
|
||||
$this->SetFont('helvetica','',10);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('Issue Date'));
|
||||
$this->SetFont('helvetica','B',11);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,$this->io->display('date_orig'),0,0,'R');
|
||||
|
||||
// Account ID
|
||||
$y = 205;
|
||||
$this->SetFont('helvetica','',10);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('Account Number'));
|
||||
$this->SetFont('helvetica','B',11);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,$this->io->account->accnum(),0,0,'R');
|
||||
|
||||
// Invoice number
|
||||
$y = 210;
|
||||
$this->SetFont('helvetica','',10);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('Invoice Number'));
|
||||
$this->SetFont('helvetica','B',11);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,$this->io->id(),0,0,'R');
|
||||
|
||||
// Company Address
|
||||
$y = 216;
|
||||
$this->SetFont('helvetica','',10);
|
||||
$this->SetXY(18,$y); $this->Cell(0,0,Config::sitename()); $y += 4;
|
||||
$this->SetXY(18,$y); $this->Cell(0,0,Company::street()); $y += 4;
|
||||
$this->SetXY(18,$y); $this->Cell(0,0,sprintf('%s, %s %s',Company::city(),Company::state(),Company::pcode())); $y += 4;
|
||||
|
||||
// Previous Due
|
||||
$y = 215;
|
||||
$this->SetFont('helvetica','',9);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('Previous Due'));
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,$this->io->account->invoices_due_total($this->io->date_orig,TRUE),0,0,'R');
|
||||
|
||||
$y = 219;
|
||||
$this->SetFont('helvetica','',9);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('Amount Due').' '.$this->io->display('due_date'));
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,$this->io->due(TRUE),0,0,'R');
|
||||
|
||||
// Total Due
|
||||
$y = 224;
|
||||
$this->SetFont('helvetica','B',10);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('Total Payable'));
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,Currency::display($this->io->due() ? $this->io->total()+$this->io->account->invoices_due_total($this->io->date_orig,TRUE) : 0),0,0,'R');
|
||||
|
||||
// Draw the Customers Address
|
||||
$x = 25; $y = 248;
|
||||
|
||||
$this->SetFont('helvetica','B',12);
|
||||
|
||||
if ($this->billToCompany && ! empty($this->io->account->company))
|
||||
$name = $this->io->account->company;
|
||||
else
|
||||
$name = $this->io->account->name();
|
||||
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,html_entity_decode($name,ENT_NOQUOTES)); $y += 5;
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,sprintf('%s %s ',$this->io->account->address1,$this->io->account->address2)); $y += 5;
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,sprintf('%s, %s %s',$this->io->account->city,$this->io->account->state,$this->io->account->zip)); $y += 5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the invoice header
|
||||
*/
|
||||
public function drawInvoiceHeader() {
|
||||
$x = 125; $y = 10;
|
||||
|
||||
// Draw a box.
|
||||
$this->SetFillColor(245);
|
||||
$this->SetXY($x-1,$y-1); $this->Cell(0,35+($this->io->billed_amt ? 5 : 0)+($this->io->credit_amt ? 5 : 0),'',1,0,'',1);
|
||||
|
||||
// Draw a box around the invoice due date and amount due.
|
||||
$this->SetFont('helvetica','B',11);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,'TAX INVOICE');
|
||||
$this->SetFont('helvetica','B',11);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,$this->io->id(),0,0,'R');
|
||||
|
||||
// Invoice number at top of page.
|
||||
$y += 7;
|
||||
$this->SetFont('helvetica','',10);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('Issue Date')); $y += 5;
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('Amount Due'));
|
||||
|
||||
$y -= 5;
|
||||
$this->SetFont('helvetica','B',11);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,$this->io->display('date_orig'),0,0,'R'); $y += 5;
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,$this->io->display('due_date'),0,0,'R');
|
||||
|
||||
$y += 5;
|
||||
$this->SetFont('helvetica','',10);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('Previous Due'));
|
||||
$this->SetFont('helvetica','B',11);
|
||||
$this->SetXY($x+55,$y); $this->Cell(0,0,$this->io->account->invoices_due_total($this->io->date_orig,TRUE),0,0,'R');
|
||||
|
||||
$y += 5;
|
||||
$this->SetFont('helvetica','',10);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('Current Charges'));
|
||||
$this->SetFont('helvetica','B',11);
|
||||
$this->SetXY($x+55,$y); $this->Cell(0,0,$this->io->total(TRUE),0,0,'R');
|
||||
|
||||
if ($this->io->billed_amt) {
|
||||
$y += 5;
|
||||
$this->SetFont('helvetica','',10);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,'Payments Received');
|
||||
$this->SetFont('helvetica','B',11);
|
||||
$this->SetXY($x+55,$y); $this->Cell(0,0,$this->io->display('billed_amt'),0,0,'R');
|
||||
}
|
||||
|
||||
if ($this->io->credit_amt) {
|
||||
$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');
|
||||
}
|
||||
|
||||
$y += 5;
|
||||
$this->SetFont('helvetica','',10);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,'Total Payable');
|
||||
$this->SetFont('helvetica','B',11);
|
||||
$this->SetXY($x+55,$y); $this->Cell(0,0,Currency::display($this->io->due() ? $this->io->total()+$this->io->account->invoices_due_total($this->io->date_orig) : 0),0,0,'R');
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw any news messages
|
||||
* @todo Limit the size of the news to 6 lines
|
||||
*/
|
||||
public function drawNews($news) {
|
||||
if (! $news)
|
||||
return;
|
||||
|
||||
$x = 9; $y = 170;
|
||||
|
||||
# Draw a box.
|
||||
$this->SetFillColor(243);
|
||||
$this->SetXY($x-1,$y-1); $this->Cell(0,20,'',1,0,'',1);
|
||||
|
||||
$this->SetFont('helvetica','',8);
|
||||
$this->SetXY($x,$y); $this->MultiCell(0,3,str_replace('\n',"\n",$news),0,'L',0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw our available payment methods
|
||||
* @todo make this list dynamic
|
||||
*/
|
||||
public function drawPaymentMethods() {
|
||||
$x = 120; $y = 242;
|
||||
|
||||
# Draw a box.
|
||||
$this->SetFillColor(235);
|
||||
$this->SetXY($x-1,$y-2); $this->Cell(0,32,'',1,0,'',1);
|
||||
|
||||
$this->SetFont('helvetica','B',8);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,'This invoice can be paid by:'); $y += 4;
|
||||
|
||||
# Direct Credit
|
||||
$logo = Kohana::find_file('media','img/invoice-payment-dd','png');
|
||||
$this->Image($logo,$x+1,$y,8);
|
||||
$this->SetFont('helvetica','B',8);
|
||||
$this->SetXY($x+10,$y); $this->Cell(0,0,'Direct Credit to our Bank Account'); $y += 3;
|
||||
$this->SetFont('helvetica','',8);
|
||||
$this->SetXY($x+10,$y); $this->Cell(0,0,'BSB:'); $y += 3;
|
||||
$this->SetXY($x+10,$y); $this->Cell(0,0,'ACCOUNT:'); $y += 3;
|
||||
$this->SetXY($x+10,$y); $this->Cell(0,0,'REF:'); $y += 3;
|
||||
|
||||
$y -= 9;
|
||||
$this->SetFont('helvetica','B',8);
|
||||
$this->SetXY($x+30,$y); $this->Cell(0,0,Company::bsb()); $y += 3;
|
||||
$this->SetXY($x+30,$y); $this->Cell(0,0,Company::account()); $y += 3;
|
||||
$this->SetXY($x+30,$y); $this->Cell(0,0,$this->io->refnum()); $y += 3;
|
||||
|
||||
/*
|
||||
# Direct Debit
|
||||
$y += 3;
|
||||
$logo = sprintf('%s/%s',PATH_THEMES.DEFAULT_THEME,'invoice/invoice-payment-dd.png');
|
||||
$this->Image($logo,$x+1,$y,8);
|
||||
$this->SetFont('helvetica','B',8);
|
||||
$this->SetXY($x+10,$y); $this->Cell(0,0,'Direct Debit'); $y += 3;
|
||||
$this->SetFont('helvetica','',8);
|
||||
$this->SetXY($x+10,$y); $this->Cell(0,0,'Please visit '); $this->SetXY($x+30,$y); $this->addHtmlLink($inv->print['site']['URL'].'?_page=invoice:user_view&id='.$inv->getPrintInvoiceNum(),$inv->print['site']['URL']); $y += 3;
|
||||
*/
|
||||
|
||||
# Paypal
|
||||
$y += 3;
|
||||
$logo = Kohana::find_file('media','img/invoice-payment-pp','png');
|
||||
$this->Image($logo,$x+1,$y,8);
|
||||
$this->SetFont('helvetica','B',8);
|
||||
$this->SetXY($x+10,$y); $this->Cell(0,0,'Pay Pal/Credit Card'); $y += 3;
|
||||
$this->SetFont('helvetica','',8);
|
||||
$this->SetXY($x+10,$y); $this->Cell(0,0,'Please visit '); $this->SetXY($x+30,$y); $this->addHtmlLink(URL::base(TRUE,TRUE),URL::base(TRUE,TRUE)); $y += 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw previous invoices due
|
||||
*/
|
||||
public function drawSummaryInvoicesDue() {
|
||||
$x = 125; $y = $this->sum_y ? $this->sum_y : 50;
|
||||
|
||||
$items = $this->io->account->invoices_due($this->io->date_orig);
|
||||
|
||||
# Calculate the box size
|
||||
$box = count($items) < $this->itemsPreviousMax ? count($items) : $this->itemsPreviousMax;
|
||||
|
||||
# Draw a box.
|
||||
$this->SetFillColor(245);
|
||||
$this->SetXY($x-1,$y-1); $this->Cell(0,5*(1+$box)+1,'',1,0,'',1);
|
||||
|
||||
$this->SetFont('helvetica','B',11);
|
||||
$this->SetXY($x,$y); $this->Cell(0,0,_('Previous Invoices Due')); $y += 5;
|
||||
|
||||
$this->SetFont('helvetica','',11);
|
||||
$i = 0;
|
||||
$sum_total = 0;
|
||||
foreach ($items as $line) {
|
||||
if (++$i < $this->itemsPreviousMax) {
|
||||
$this->SetXY($x,$y);
|
||||
$this->Cell(0,0,sprintf('%s %s',$line->display('date_orig'),$line->id()));
|
||||
$this->Cell(0,0,$line->due(TRUE),0,0,'R'); $y += 5;
|
||||
|
||||
} else {
|
||||
$sum_total += $line->due();
|
||||
}
|
||||
}
|
||||
|
||||
if ($sum_total) {
|
||||
$this->SetXY($x,$y);
|
||||
$this->SetFont('helvetica','I',11);
|
||||
$this->Cell(0,0,'Other invoices');
|
||||
$this->SetFont('helvetica','',11);
|
||||
$this->Cell(0,0,Currency::display($sum_total),0,0,'R'); $y += 5;
|
||||
}
|
||||
|
||||
$this->sum_y = $y+5;
|
||||
}
|
||||
|
||||
/**
|
||||
* This will draw the Summary Box, with the summary of the items
|
||||
* on the invoice.
|
||||
*/
|
||||
public function drawSummaryLineItems() {
|
||||
if (! $this->show_itemized)
|
||||
return;
|
||||
|
||||
$items = $this->io->items_summary();
|
||||
|
||||
// Calculate the box size
|
||||
$box = count($items) < $this->itemsSummaryMax ? count($items) : $this->itemsSummaryMax;
|
||||
|
||||
// Our starting position
|
||||
$x = 10; $y = $this->sum_y ? $this->sum_y : 55;
|
||||
|
||||
// Draw a box.
|
||||
$this->SetFillColor(245);
|
||||
$this->SetXY($x-1,$y-1);
|
||||
$this->Cell(0,5*(
|
||||
1+1+1+3+($this->io->discount_amt ? 1 : 0)+($this->io->billed_amt ? 1 : 0)+($this->io->credit_amt ? 1 : 0)+$box
|
||||
)+1,'',1,0,'',1);
|
||||
|
||||
$this->SetFont('helvetica','B',11);
|
||||
$this->SetXY($x,$y);
|
||||
$this->Cell(0,0,_('Current Charges Summary')); $y += 5;
|
||||
|
||||
$this->SetY($y);
|
||||
$this->SetFont('helvetica','',9);
|
||||
|
||||
$i = $subtotal = 0;
|
||||
foreach ($items as $name => $line) {
|
||||
if ($i < $this->itemsSummaryMax) {
|
||||
$this->SetX($x);
|
||||
$this->Cell(0,0,$line['quantity']);
|
||||
$this->SetX($x+8);
|
||||
$this->Cell(0,0,$name);
|
||||
$this->SetX($x+135);
|
||||
$this->Cell(0,0,Currency::display($line['subtotal']),0,0,'R');
|
||||
|
||||
$y += 5;
|
||||
$this->SetY($y);
|
||||
}
|
||||
|
||||
$i++;
|
||||
if ($i == $this->itemsSummaryMax) {
|
||||
$this->SetFont('helvetica','B',11);
|
||||
$this->SetX($x);
|
||||
$this->Cell(0,0,_('The above is just a summary. To view a detailed list of charges, please visit our website.'));
|
||||
}
|
||||
|
||||
$subtotal += $line['subtotal'];
|
||||
}
|
||||
|
||||
// Calculate our rounding error
|
||||
// @todo This shouldnt be required.
|
||||
$subtotal = round($subtotal-$this->io->discount_amt,Kohana::config('config.currency_format'));
|
||||
|
||||
if (round($this->io->subtotal(),Kohana::config('config.currency_format')) != $subtotal) {
|
||||
$this->SetFont('helvetica','',9);
|
||||
$this->SetX($x);
|
||||
$this->Cell(0,0,'Rounding');
|
||||
$this->SetX($x+135);
|
||||
$this->Cell(0,0,Currency::display($this->io->subtotal()-$subtotal),0,0,'R');
|
||||
|
||||
$y += 5;
|
||||
$this->SetY($y);
|
||||
}
|
||||
|
||||
// Draw Discounts.
|
||||
if ($this->io->discount_amt) {
|
||||
$y += 5;
|
||||
$this->SetY($y);
|
||||
|
||||
$this->SetFont('helvetica','B',9);
|
||||
$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');
|
||||
}
|
||||
|
||||
// Subtotal and tax.
|
||||
$y += 5;
|
||||
$this->SetY($y);
|
||||
|
||||
$this->SetFont('helvetica','B',9);
|
||||
$this->SetX($x+8);
|
||||
$this->Cell(0,0,'Sub Total');
|
||||
$this->SetX($x+135);
|
||||
$this->Cell(0,0,Currency::display($this->io->subtotal()),0,0,'R');
|
||||
|
||||
$y += 5;
|
||||
$this->SetY($y);
|
||||
|
||||
$this->SetX($x+8);
|
||||
$this->Cell(0,0,'Taxes');
|
||||
$this->SetX($x+135);
|
||||
$this->Cell(0,0,Currency::display($this->io->tax()),0,0,'R');
|
||||
|
||||
$y += 5;
|
||||
$this->SetY($y);
|
||||
|
||||
$this->SetX($x+8);
|
||||
$this->Cell(0,0,'Total Charges');
|
||||
$this->SetX($x+135);
|
||||
$this->Cell(0,0,Currency::display($this->io->total()),0,0,'R');
|
||||
|
||||
// Show payments already received for this invoice
|
||||
if ($this->io->billed_amt) {
|
||||
$y += 5;
|
||||
$this->SetY($y);
|
||||
|
||||
$this->SetX($x+8);
|
||||
$this->Cell(0,0,'Payments Received');
|
||||
$this->SetX($x+135);
|
||||
$this->Cell(0,0,Currency::display($this->io->payments()),0,0,'R');
|
||||
}
|
||||
|
||||
if ($this->io->credit_amt) {
|
||||
$y += 5;
|
||||
$this->SetY($y);
|
||||
|
||||
$this->SetFont('helvetica','B',9);
|
||||
$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');
|
||||
}
|
||||
|
||||
$y += 5;
|
||||
$this->SetY($y);
|
||||
$this->SetX($x+8);
|
||||
$this->Cell(0,0,'Balance Due');
|
||||
$this->SetX($x+135);
|
||||
$this->Cell(0,0,$this->io->due(TRUE),0,0,'R');
|
||||
}
|
||||
|
||||
/**
|
||||
* This will draw the Summary Box, with the summary of the items
|
||||
* on the invoice.
|
||||
*/
|
||||
public function drawDetailLineItems() {
|
||||
$this->i = 0;
|
||||
foreach ($this->io->items() as $io)
|
||||
$this->drawLineItem($io);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws Invoice Detail Item
|
||||
*
|
||||
* @todo need to make sure that this pages well, when there are many items (with many sub details).
|
||||
*/
|
||||
private function drawLineItem($ito) {
|
||||
$x = 10;
|
||||
if ($this->i == 0 || $this->i%$this->max_lines_page == 0) {
|
||||
$this->y = 5;
|
||||
$this->AddPage();
|
||||
|
||||
$this->SetFont('helvetica','B',12);
|
||||
$this->SetXY($x,$this->y); $this->Cell(0,0,_('Itemised Charges'));
|
||||
$this->Cell(0,0,_('Page #').$this->PageNo(),0,0,'R');
|
||||
$this->SetXY($x,$this->y); $this->Cell(0,0,_('Invoice #').$this->io->id(),0,0,'C');
|
||||
|
||||
// Draw table headers
|
||||
$this->y += 10;
|
||||
$this->SetFont('helvetica','B',8);
|
||||
$this->SetXY($x,$this->y);
|
||||
$this->Cell(0,0,_('Description'));
|
||||
$this->SetX($x+135);
|
||||
$this->Cell(0,0,_('Quantity'));
|
||||
$this->SetX($x+160);
|
||||
$this->Cell(10,0,_('Unit Cost'),0,0,'R');
|
||||
$this->SetX($x+135);
|
||||
$this->Cell(0,0,_('Amount'),0,0,'R');
|
||||
$this->Line($x,$this->y+4,200,$this->y+4);
|
||||
|
||||
$this->y += 5;
|
||||
$this->SetY($this->y);
|
||||
}
|
||||
|
||||
$this->SetFont('helvetica','',8);
|
||||
$this->SetX($x);
|
||||
$this->Cell(0,0,$ito->service->service_name());
|
||||
|
||||
if ($ito->price_base) {
|
||||
$this->SetX($x+160);
|
||||
$this->Cell(10,0,Currency::display($ito->price_base),0,0,'R');
|
||||
}
|
||||
|
||||
if ($ito->quantity) {
|
||||
$this->SetX($x+130);
|
||||
$this->Cell(10,0,$ito->quantity,0,0,'R');
|
||||
}
|
||||
|
||||
$this->SetX($x+130);
|
||||
$this->Cell(0,0,Currency::display($ito->total_amt),0,0,'R');
|
||||
|
||||
if ($this->show_service_range && $ito->period()) {
|
||||
$this->SetFont('helvetica','I',7);
|
||||
$this->y += 3;
|
||||
$this->SetXY($x+10,$this->y); $this->Cell(0,0,'Service Period');
|
||||
$this->SetFont('helvetica','',7);
|
||||
$this->SetXY($x+40,$this->y); $this->Cell(0,0,$ito->period());
|
||||
}
|
||||
|
||||
if ($ito->invoice_detail_items())
|
||||
foreach ($ito->invoice_detail_items() as $k=>$v) {
|
||||
$this->SetFont('helvetica','I',7);
|
||||
$this->y += 3;
|
||||
$this->SetXY($x+10,$this->y); $this->Cell(0,0,$k);
|
||||
$this->SetFont('helvetica','',7);
|
||||
$this->SetXY($x+40,$this->y); $this->Cell(0,0,$v);
|
||||
}
|
||||
|
||||
$this->y += 5;
|
||||
$this->SetY($this->y);
|
||||
$this->i++;
|
||||
}
|
||||
}
|
||||
?>
|
@@ -37,19 +37,31 @@ class Model_Invoice extends ORMOSB {
|
||||
'tax_amt'=>array('calc_tax'),
|
||||
);
|
||||
|
||||
protected $_formats = array(
|
||||
'date_orig'=>array('Config::date'=>array()),
|
||||
'due_date'=>array('Config::date'=>array()),
|
||||
'billed_amt'=>array('Currency::display'=>array()),
|
||||
'credit_amt'=>array('Currency::display'=>array()),
|
||||
'status'=>array('StaticList_YesNo::display'=>array()),
|
||||
'total_amt'=>array('Currency::display'=>array()),
|
||||
protected $_display_filters = array(
|
||||
'date_orig'=>array(
|
||||
array('Config::date',array(':value')),
|
||||
),
|
||||
'due_date'=>array(
|
||||
array('Config::date',array(':value')),
|
||||
),
|
||||
'billed_amt'=>array(
|
||||
array('Currency::display',array(':value')),
|
||||
),
|
||||
'credit_amt'=>array(
|
||||
array('Currency::display',array(':value')),
|
||||
),
|
||||
'status'=>array(
|
||||
array('StaticList_YesNo::display',array(':value')),
|
||||
),
|
||||
'total_amt'=>array(
|
||||
array('Currency::display',array(':value')),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Display the Invoice Number
|
||||
*/
|
||||
public function invnum() {
|
||||
public function id() {
|
||||
return sprintf('%06s',$this->id);
|
||||
}
|
||||
|
||||
@@ -64,127 +76,115 @@ class Model_Invoice extends ORMOSB {
|
||||
* Display the amount due
|
||||
*/
|
||||
public function due($format=FALSE) {
|
||||
$result = 0;
|
||||
// If the invoice is active calculate the due amount
|
||||
if ($this->status)
|
||||
// @todo This rounding should be a system setting
|
||||
$result = round($this->total_amt-$this->credit_amt-$this->billed_amt,2);
|
||||
$result = $this->status ? round($this->total_amt-$this->credit_amt-$this->billed_amt,Kohana::config('config.currency_format')) : 0;
|
||||
|
||||
if ($format)
|
||||
return Currency::display($result);
|
||||
else
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a total invoices overdue excluding this invoice
|
||||
*/
|
||||
public function other_due($format=FALSE) {
|
||||
$result = $this->account->invoices_due_total()-$this->due();
|
||||
|
||||
if ($format)
|
||||
return Currency::display($result);
|
||||
else
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function subtotal($format=FALSE) {
|
||||
$result = 0;
|
||||
|
||||
foreach ($this->items() as $item)
|
||||
$result += $item->subtotal();
|
||||
|
||||
if ($format)
|
||||
return Currency::display($result);
|
||||
else
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function total($format=FALSE) {
|
||||
$result = 0;
|
||||
|
||||
foreach ($this->items() as $item)
|
||||
$result += $item->total();
|
||||
|
||||
// Reduce any credits
|
||||
$result -= $this->credit_amt;
|
||||
|
||||
if ($format)
|
||||
return Currency::display($result);
|
||||
else
|
||||
return $result;
|
||||
return $format ? Currency::display($result) : $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of invoice items for this invoice.
|
||||
*
|
||||
* We only return the items, if the invoice hasnt been changed.
|
||||
*/
|
||||
public function items() {
|
||||
// Get our invoice items for an existing invoice
|
||||
if ($this->id AND $this->loaded() AND ! $this->_changed)
|
||||
return $this->invoice_item->order_by('service_id,item_type,module_id')->find_all();
|
||||
return ($this->loaded() AND ! $this->_changed) ? $this->invoice_item->order_by('service_id,item_type,module_id')->find_all() : NULL;
|
||||
}
|
||||
|
||||
echo kohana::debug(array('BEFORE'=>$this->invoice_item));
|
||||
if (! $this->invoice_items)
|
||||
$this->invoice_items = $this->invoice_item;
|
||||
/**
|
||||
* Return the subtotal of all items
|
||||
*/
|
||||
public function subtotal($format=FALSE) {
|
||||
$result = 0;
|
||||
|
||||
echo kohana::debug(array('AFTER'=>$this->invoice_items));die();
|
||||
return $this->invoice_items;
|
||||
foreach ($this->items() as $ito)
|
||||
$result += $ito->subtotal();
|
||||
|
||||
return $format ? Currency::display($result) : $result;
|
||||
}
|
||||
|
||||
public function tax($format=FALSE) {
|
||||
$result = 0;
|
||||
|
||||
foreach ($this->items() as $ito)
|
||||
$result += $ito->tax_amt;
|
||||
|
||||
return $format ? Currency::display($result) : $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the total of all items
|
||||
*/
|
||||
public function total($format=FALSE) {
|
||||
$result = 0;
|
||||
|
||||
foreach ($this->items() as $ito)
|
||||
$result += $ito->total();
|
||||
|
||||
// Reduce by any credits
|
||||
$result -= $this->credit_amt;
|
||||
|
||||
return $format ? Currency::display($result) : $result;
|
||||
}
|
||||
|
||||
public function payments() {
|
||||
return ($this->loaded() AND ! $this->_changed) ? $this->payments->find_all() : NULL;
|
||||
}
|
||||
|
||||
public function payments_total($format=FALSE) {
|
||||
$result = 0;
|
||||
|
||||
foreach ($this->payments() as $po)
|
||||
$result += $po->total_amt;
|
||||
|
||||
return $format ? Currency::display($result) : $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of our main invoice items (item_id=0)
|
||||
*/
|
||||
public function items_main() {
|
||||
if ($this->id AND $this->loaded() AND ! $this->_changed)
|
||||
return $this->invoice_item->where('item_type','=',0)->find_all();
|
||||
return ($this->loaded() AND ! $this->_changed) ? $this->invoice_item->where('item_type','=',0)->find_all() : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of our sub invoice items (item_id!=0)
|
||||
*
|
||||
* @param sid int Service ID
|
||||
*/
|
||||
public function items_sub($sid) {
|
||||
if ($this->id AND $this->loaded() AND ! $this->_changed)
|
||||
return $this->invoice_item->where('service_id','=',$sid)->and_where('item_type','<>',0)->find_all();
|
||||
return ($this->loaded() AND ! $this->_changed) ? $this->invoice_item->where('service_id','=',$sid)->and_where('item_type','<>',0)->find_all() : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Summarise the items on an invoice
|
||||
*/
|
||||
public function items_summary() {
|
||||
$sum = array();
|
||||
$result = array();
|
||||
|
||||
foreach ($this->items_main() as $item) {
|
||||
foreach ($this->items_main() as $ito) {
|
||||
$unique = TRUE;
|
||||
|
||||
# Unique line item
|
||||
if (isset($sum[$item->product->sku])) {
|
||||
# Is unique price/attributes?
|
||||
|
||||
foreach ($sum[$item->product->sku] as $sid => $flds) {
|
||||
if ($flds->price_base == $item->price_base &&
|
||||
$flds->price_setup == $item->price_setup) {
|
||||
|
||||
$sum[$item->product->sku][$sid]->quantity += $item->quantity;
|
||||
$unique = FALSE;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
$t = $ito->product->summary();
|
||||
if (! isset($result[$t])) {
|
||||
$result[$t]['quantity'] = 0;
|
||||
$result[$t]['subtotal'] = 0;
|
||||
}
|
||||
|
||||
# Unique line item
|
||||
if ($unique)
|
||||
$sum[$item->product->sku][] = $item;
|
||||
$result[$t]['quantity'] += $ito->quantity;
|
||||
$result[$t]['subtotal'] += $ito->subtotal();
|
||||
}
|
||||
|
||||
if (count($sum)) {
|
||||
$items = array();
|
||||
foreach ($sum as $sku => $item)
|
||||
foreach ($item as $sitem)
|
||||
array_push($items,$sitem);
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
/**
|
||||
* Find all the invoice items relating to a service
|
||||
*
|
||||
* @param int Service ID
|
||||
*/
|
||||
private function items_service($sid) {
|
||||
return $this->invoice_item->where('service_id','=',$sid)->find_all();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -193,8 +193,8 @@ class Model_Invoice extends ORMOSB {
|
||||
public function items_service_total($sid) {
|
||||
$total = 0;
|
||||
|
||||
foreach ($this->invoice_item->where('service_id','=',$sid)->find_all() as $item)
|
||||
$total += $item->total();
|
||||
foreach ($this->items_service($sid) as $ito)
|
||||
$total += $ito->total();
|
||||
|
||||
return $total;
|
||||
}
|
||||
@@ -205,8 +205,8 @@ class Model_Invoice extends ORMOSB {
|
||||
public function items_service_tax($sid) {
|
||||
$total = 0;
|
||||
|
||||
foreach ($this->invoice_item->where('service_id','=',$sid)->find_all() as $item)
|
||||
$total += $item->tax_amt;
|
||||
foreach ($this->items_service($sid) as $ito)
|
||||
$total += $ito->tax_amt;
|
||||
|
||||
return $total;
|
||||
}
|
||||
@@ -217,8 +217,8 @@ class Model_Invoice extends ORMOSB {
|
||||
public function sorted_service_items($index) {
|
||||
$summary = array();
|
||||
|
||||
foreach ($this->items() as $item) {
|
||||
$key = $item->service->$index;
|
||||
foreach ($this->items() as $ito) {
|
||||
$key = $ito->service->$index;
|
||||
|
||||
if (! isset($summary[$key]['items'])) {
|
||||
$summary[$key]['items'] = array();
|
||||
@@ -226,10 +226,10 @@ class Model_Invoice extends ORMOSB {
|
||||
}
|
||||
|
||||
// Only record items with item_type=0
|
||||
if ($item->item_type == 0)
|
||||
array_push($summary[$key]['items'],$item);
|
||||
if ($ito->item_type == 0)
|
||||
array_push($summary[$key]['items'],$ito);
|
||||
|
||||
$summary[$key]['total'] += $item->total();
|
||||
$summary[$key]['total'] += $ito->total();
|
||||
}
|
||||
|
||||
return $summary;
|
||||
@@ -241,8 +241,8 @@ class Model_Invoice extends ORMOSB {
|
||||
public function tax_summary() {
|
||||
$summary = array();
|
||||
|
||||
foreach ($this->items() as $item) {
|
||||
foreach ($item->invoice_item_tax->find_all() as $item_tax) {
|
||||
foreach ($this->items() as $ito) {
|
||||
foreach ($ito->invoice_item_tax->find_all() as $item_tax) {
|
||||
if (! isset($summary[$item_tax->tax_id]))
|
||||
$summary[$item_tax->tax_id] = $item_tax->amount;
|
||||
else
|
||||
@@ -253,6 +253,9 @@ class Model_Invoice extends ORMOSB {
|
||||
return $summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an item to an invoice
|
||||
*/
|
||||
public function add_item() {
|
||||
$c = count($this->invoice_items);
|
||||
|
||||
@@ -299,8 +302,8 @@ class Model_Invoice extends ORMOSB {
|
||||
$array[$field] = 0;
|
||||
|
||||
// @todo Rounding here should come from a global config
|
||||
foreach ($this->invoice_items as $item)
|
||||
$array[$field] += round($item->price_base+$item->price_setup,2);
|
||||
foreach ($this->invoice_items as $ito)
|
||||
$array[$field] += round($ito->price_base+$ito->price_setup,2);
|
||||
|
||||
$this->_changed[$field] = $field;
|
||||
}
|
||||
@@ -311,8 +314,8 @@ class Model_Invoice extends ORMOSB {
|
||||
// @todo Rounding here should come from a global config
|
||||
// @todo tax should be evaluated per item
|
||||
// @todo tax parameters should come from user session
|
||||
foreach ($this->invoice_items as $item)
|
||||
$array[$field] += round(Tax::total(61,NULL,$item->price_base+$item->price_setup),2);
|
||||
foreach ($this->invoice_items as $ito)
|
||||
$array[$field] += round(Tax::total(61,NULL,$ito->price_base+$ito->price_setup),2);
|
||||
|
||||
$this->_changed[$field] = $field;
|
||||
}
|
||||
|
@@ -32,16 +32,14 @@ class Model_Invoice_Item extends ORMOSB {
|
||||
return sprintf('%s: %s',_('Date'),Config::date($this->date_start));
|
||||
|
||||
else
|
||||
return sprintf('%s: %s -> %s',_('Period'),Config::date($this->date_start),Config::date($this->date_stop));
|
||||
return sprintf('%s -> %s',Config::date($this->date_start),Config::date($this->date_stop));
|
||||
}
|
||||
|
||||
/**
|
||||
* On invoices where there are multiple charges for the same item
|
||||
* (eg spanning the next invoice period), this should show the period
|
||||
* range for the additional sub-items.
|
||||
*/
|
||||
public function invoice_display() {
|
||||
return $this->period();
|
||||
public function invoice_detail_items() {
|
||||
if ($this->item_type != 0)
|
||||
return;
|
||||
|
||||
return $this->service->details('invoice');
|
||||
}
|
||||
|
||||
public function subtotal() {
|
||||
|
@@ -14,7 +14,7 @@
|
||||
<table class="invoice_summary" border="0">
|
||||
<tr>
|
||||
<td>TAX INVOICE</td>
|
||||
<td class="bold-right"><?php echo $invoice->invnum(); ?></td>
|
||||
<td class="bold-right"><?php echo $invoice->id(); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Issue Date</td>
|
||||
@@ -61,7 +61,7 @@
|
||||
<?php foreach ($catitems['items'] as $item) {?>
|
||||
<!-- Product Information -->
|
||||
<tr class="head">
|
||||
<td><?php echo HTML::anchor('/user/service/view/'.$item->service->id,$item->service->svcnum()); ?></td>
|
||||
<td><?php echo HTML::anchor('/user/service/view/'.$item->service->id,$item->service->id()); ?></td>
|
||||
<td colspan="3"><?php echo $item->product->product_translate->find()->name; ?> (<?php echo $item->product_id; ?>)</td>
|
||||
<td class="right"><?php echo Currency::display($invoice->items_service_total($item->service_id));?></td>
|
||||
</tr>
|
||||
|
@@ -10,7 +10,7 @@
|
||||
</tr>
|
||||
<?php $i = 0; foreach ($invoices as $invoice) { ?>
|
||||
<tr class="<?php echo ++$i%2 ? 'odd' : 'even'; ?>">
|
||||
<td><?php echo HTML::anchor('/user/invoice/view/'.$invoice->id,$invoice->invnum()); ?></td>
|
||||
<td><?php echo HTML::anchor('/user/invoice/view/'.$invoice->id,$invoice->id()); ?></td>
|
||||
<td><?php echo $invoice->display('total_amt'); ?></td>
|
||||
<td><?php echo $invoice->display('credit_amt'); ?></td>
|
||||
<td class="number"><?php echo $invoice->display('billed_amt'); ?></td>
|
||||
|
Reference in New Issue
Block a user