Revamping invoice PDF rendering and standardisation work

This commit is contained in:
Deon George
2016-08-10 16:07:00 +10:00
parent a560c5f4fa
commit 24bb4a701b
27 changed files with 229 additions and 475 deletions

View File

@@ -9,7 +9,7 @@
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Invoice_TCPDF_Default extends Invoice_Tcpdf {
class Invoice_Tcpdf_Default extends Invoice_Tcpdf {
// Current line being printed
public $sum_y = 0;
@@ -87,7 +87,7 @@ class Invoice_TCPDF_Default extends Invoice_Tcpdf {
$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');
$this->SetXY($x,$y); $this->Cell(0,0,$this->io->refnum(TRUE),0,0,'R');
// Company Address
// $y = 216;
@@ -142,7 +142,7 @@ class Invoice_TCPDF_Default extends Invoice_Tcpdf {
$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');
$this->SetXY($x,$y); $this->Cell(0,0,$this->io->refnum(TRUE),0,0,'R');
// Invoice number at top of page.
$y += 7;
@@ -261,7 +261,7 @@ class Invoice_TCPDF_Default extends Invoice_Tcpdf {
* Draw previous invoices due
*/
public function drawSummaryInvoicesDue() {
$x = 125; $y = $this->sum_y ? $this->sum_y : 50;
$x = 125; $y = $this->sum_y ? $this->sum_y : 55;
$items = $this->io->account->invoices_due($this->io->date_orig);
@@ -281,7 +281,7 @@ class Invoice_TCPDF_Default extends Invoice_Tcpdf {
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,sprintf('%s %s',$line->display('date_orig'),$line->refnum(TRUE)));
$this->Cell(0,0,$line->due(TRUE),0,0,'R'); $y += 5;
} else {
@@ -442,26 +442,20 @@ class Invoice_TCPDF_Default extends Invoice_Tcpdf {
public function drawDetailLineItems() {
$this->i = 0;
foreach ($this->io->items_periods() as $rs) {
$sids=array();
foreach ($this->io->items_periods($rs) as $iio) {
if (in_array($iio->service_id,$sids))
continue;
array_push($sids,$iio->service_id);
$this->drawLineItem($iio);
foreach ($this->io->items_render() as $key => $items) {
switch ($key) {
case 's':
$this->drawLineItems($items);
break;
}
}
}
/**
* Draws Invoice Detail Item
*
* @todo need to make sure that this pages well, when there are many items (with many sub details).
* Draws Invoice Detail Items
*/
private function drawLineItem($ito) {
private function drawLineItems(array $items) {
$track['rs'] = $track = array();
$x = 10;
if ($this->i == 0 || $this->i%$this->max_lines_page == 0) {
$this->y = 5;
@@ -470,7 +464,7 @@ class Invoice_TCPDF_Default extends Invoice_Tcpdf {
$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');
$this->SetXY($x,$this->y); $this->Cell(0,0,_('Invoice #').$this->io->refnum(TRUE),0,0,'C');
// Draw table headers
$this->y += 10;
@@ -489,68 +483,68 @@ class Invoice_TCPDF_Default extends Invoice_Tcpdf {
$this->SetY($this->y);
}
$this->SetFont('helvetica','',8);
$this->SetX($x);
$this->Cell(0,0,$ito->title());
$this->SetFont('helvetica','',7);
$last = '';
foreach ($items as $iio) {
// So we dont render the same recurring schedule over again
if (! is_null($iio->recurring_schedule) AND ! in_array($iio->recurring_schedule,$track['rs'])) {
array_push($track['rs'],$iio->recurring_schedule);
// echo $iio->display('recurring_schedule');
}
if ($z=$this->io->service_items($ito)) {
foreach ($z as $eiio) {
$this->y += 3;
// If we are rendering a new service, reset the product id tracking
if ($iio->service_id != $last) {
if ($last) {
$this->y += 6;
$this->SetY($this->y);
}
$last = $iio->service_id;
$track['p'] = array();
}
// So we dont render the same product title over again
if (! in_array($iio->product_id,$track['p'])) {
array_push($track['p'],$iio->product_id);
$this->SetFont('helvetica','',8);
$this->SetX($x);
$this->Cell(0,0,sprintf('%s: %s',$iio->service->refnum(TRUE),$iio->name($iio->invoice->account->language)));
$this->SetFont('helvetica','',7);
$this->y += 1;
if ($iio->service->attributes()) {
foreach ($iio->service->attributes() as $k=>$v) {
$this->SetFont('helvetica','I',6);
$this->y += 3;
$this->SetXY($x+10,$this->y); $this->Cell(0,0,$k);
$this->SetFont('helvetica','',6);
$this->SetXY($x+40,$this->y); $this->Cell(0,0,$v);
}
}
$this->y += 2;
$this->SetY($this->y);
$this->SetX($x+10);
$this->Cell(10,0,$eiio->invoice_line());
$this->i++;
}
if ($eiio->price_base) {
$this->SetX($x+160);
$this->Cell(10,0,Currency::display($eiio->price_base),0,0,'R');
}
if ($eiio->quantity) {
$this->SetX($x+130);
$this->Cell(10,0,$eiio->quantity,0,0,'R');
}
$this->y += 3;
$this->SetY($this->y);
$this->SetX($x+10);
$this->Cell(10,0,sprintf('%s: (%s)',$iio->namesub($iio->invoice->account->language),$iio->refnum()));
if ($iio->quantity) {
$this->SetX($x+130);
$this->Cell(0,0,$eiio->total(TRUE),0,0,'R');
$this->Cell(10,0,sprintf('%3.2f',$iio->quantity),0,0,'R');
}
if ($iio->price_base) {
$this->SetX($x+160);
$this->Cell(10,0,Currency::display($iio->price_base),0,0,'R');
}
$this->SetX($x+130);
$this->Cell(0,0,$iio->total(TRUE),0,0,'R');
}
if ($z=$this->io->service_items_extra($ito)) {
foreach ($z as $eiio) {
$this->y += 3;
$this->SetY($this->y);
$this->SetX($x+10);
$this->Cell(10,0,$eiio->invoice_line());
if ($eiio->price_base) {
$this->SetX($x+160);
$this->Cell(10,0,Currency::display($eiio->price_base),0,0,'R');
}
if ($eiio->quantity) {
$this->SetX($x+130);
$this->Cell(10,0,$eiio->quantity,0,0,'R');
}
$this->SetX($x+130);
$this->Cell(0,0,$eiio->total(TRUE),0,0,'R');
}
}
$this->y += 2;
if ($ito->invoice_detail_items())
foreach ($ito->invoice_detail_items() as $k=>$v) {
$this->SetFont('helvetica','I',6);
$this->y += 3;
$this->SetXY($x+10,$this->y); $this->Cell(0,0,$k);
$this->SetFont('helvetica','',6);
$this->SetXY($x+40,$this->y); $this->Cell(0,0,$v);
}
$this->y += 5;
$this->SetY($this->y);
$this->i++;
}
}
?>