This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/modules/invoice/PDF/pdf_invoice_itemised-tcpdf.inc.php

674 lines
22 KiB
PHP
Raw Normal View History

2009-08-03 04:10:16 +00:00
<?php
/**
* Graytech Hosting - Highly detailed PDF invoice
*/
require_once PATH_MODULES.'invoice/invoice_base_tcpdf.inc.php';
class pdf_invoice_overview extends pdf_invoice_base {
var $v, $i, $y;
# Current line being printed
public $sum_y = 0;
/**
* Draw the logo
*/
public function drawCompanyLogo() {
$x = 9; $y = 7;
$size = 25;
$logo = sprintf('%s/%s',PATH_THEMES.DEFAULT_THEME,'invoice/invoice-logo.png');
if (is_file($logo))
$this->Image($logo,$x,$y,$size);
}
/**
* Draw the Company Address
*/
public function drawCompanyAddress($inv) {
# 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,$inv->print['site']['NAME']); $y += 4;
$this->SetFont('helvetica','',10);
$this->SetXY($x,$y); $this->Cell(0,0,$inv->print['site']['TAXID']); $y += 6;
$this->SetXY($x,$y); $this->Cell(0,0,$inv->print['site']['ADDRESS']); $y += 4;
$this->SetXY($x,$y); $this->Cell(0,0,sprintf('%s, %s %s',$inv->print['site']['CITY'],$inv->print['site']['STATE'],$inv->print['site']['ZIP'])); $y += 4;
$y += 2;
$this->SetXY($x,$y); $this->Cell(0,0,'Phone:'); $this->SetXY($x+16,$y); $this->Cell(0,0,$inv->print['site']['PHONE']); $y += 4;
$this->SetXY($x,$y); $this->Cell(0,0,'Fax:'); $this->SetXY($x+16,$y); $this->Cell(0,0,$inv->print['site']['FAX']); $y += 4;
$this->SetXY($x,$y); $this->Cell(0,0,'Web:'); $this->SetXY($x+16,$y); $this->addHtmlLink($inv->print['site']['URL'],$inv->print['site']['URL']); $y += 4;
}
public function drawRemittenceStub($inv) {
# Draw the remittance line
$this->Line(9,195,200,195);
$x = 18; $y = 200;
$this->SetFont('helvetica','B',13);
2010-11-29 22:41:08 +00:00
$this->SetXY($x,$y); $this->Cell(0,0,_('Payment Remittence')); $y +=5;
2009-08-03 04:10:16 +00:00
$this->SetFont('helvetica','',8);
2010-11-29 22:41:08 +00:00
$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').' '.$inv->print['site']['NAME']);
2009-08-03 04:10:16 +00:00
# Due Date
$x = 110; $y = 200;
$this->SetFont('helvetica','',10);
2010-11-29 22:41:08 +00:00
$this->SetXY($x,$y); $this->Cell(0,0,_('Issue Date'));
2009-08-03 04:10:16 +00:00
$this->SetFont('helvetica','B',11);
$this->SetXY($x,$y); $this->Cell(0,0,date(UNIX_DATE_FORMAT,$inv->print['invoice']['date_orig']),0,0,'R');
# Account ID
$y = 205;
$this->SetFont('helvetica','',10);
2010-11-29 22:41:08 +00:00
$this->SetXY($x,$y); $this->Cell(0,0,_('Account Number'));
2009-08-03 04:10:16 +00:00
$this->SetFont('helvetica','B',11);
$this->SetXY($x,$y); $this->Cell(0,0,sprintf('%06s',$inv->print['account']['id']),0,0,'R');
# Invoice number
$y = 210;
$this->SetFont('helvetica','',10);
2010-11-29 22:41:08 +00:00
$this->SetXY($x,$y); $this->Cell(0,0,_('Invoice Number'));
2009-08-03 04:10:16 +00:00
$this->SetFont('helvetica','B',11);
2010-11-29 22:41:08 +00:00
$this->SetXY($x,$y); $this->Cell(0,0,sprintf('%06s',$inv->getPrintInvoiceNum()),0,0,'R');
2009-08-03 04:10:16 +00:00
# Company Address
$y = 216;
$this->SetFont('helvetica','',10);
$this->SetXY(18,$y); $this->Cell(0,0,$inv->print['site']['NAME']); $y += 4;
$this->SetXY(18,$y); $this->Cell(0,0,$inv->print['site']['ADDRESS']); $y += 4;
$this->SetXY(18,$y); $this->Cell(0,0,sprintf('%s, %s %s',$inv->print['site']['CITY'],$inv->print['site']['STATE'],$inv->print['site']['ZIP'])); $y += 4;
# Previous Due
$y = 215;
$this->SetFont('helvetica','',9);
2010-11-29 22:41:08 +00:00
$this->SetXY($x,$y); $this->Cell(0,0,_('Previous Due'));
$this->SetXY($x,$y); $this->Cell(0,0,$this->_currency($inv->sPreviousBalance()),0,0,'R');
2009-08-03 04:10:16 +00:00
$y = 219;
$this->SetFont('helvetica','',9);
2010-11-29 22:41:08 +00:00
$this->SetXY($x,$y); $this->Cell(0,0,_('Amount Due').' '.date(UNIX_DATE_FORMAT,$inv->print['invoice']['due_date']));
$this->SetXY($x,$y); $this->Cell(0,0,$this->_currency($inv->print['invoice']['total_amt']-$inv->print['invoice']['billed_amt']-$inv->print['invoice']['credit_amt']),0,0,'R');
2009-08-03 04:10:16 +00:00
# Total Due
$y = 224;
$this->SetFont('helvetica','B',10);
2010-11-29 22:41:08 +00:00
$this->SetXY($x,$y); $this->Cell(0,0,_('Total Due'));
$this->SetXY($x,$y); $this->Cell(0,0,$this->_currency($inv->sPreviousBalance()+$inv->print['invoice']['total_amt']-$inv->print['invoice']['billed_amt']-$inv->print['invoice']['credit_amt']),0,0,'R');
2009-08-03 04:10:16 +00:00
# Draw the Customers Address
$x = 25; $y = 248;
$this->SetFont('helvetica','B',12);
if ($this->billToCompany && ! empty($inv->print['account']['company']))
$name = $inv->print['account']['company'];
else
$name = sprintf('%s %s',$inv->print['account']['first_name'],$inv->print['account']['last_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 ',$inv->print['account']['address1'],$inv->print['account']['address2'])); $y += 5;
$this->SetXY($x,$y); $this->Cell(0,0,sprintf('%s, %s %s',$inv->print['account']['city'],$inv->print['account']['state'],$inv->print['account']['zip'])); $y += 5;
}
public function drawInvoiceHeader($inv) {
$x = 125; $y = 10;
# Draw a box.
$this->SetFillColor(245);
2010-11-29 22:41:08 +00:00
$this->SetXY($x-1,$y-1); $this->Cell(0,35+($inv->print['invoice']['billed_amt'] ? 5 : 0)+($inv->print['invoice']['credit_amt'] ? 5 : 0),'',1,0,'',1);
2009-08-03 04:10:16 +00:00
# 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);
2010-11-29 22:41:08 +00:00
$this->SetXY($x,$y); $this->Cell(0,0,sprintf('%06s',$inv->getPrintInvoiceNum()),0,0,'R');
2009-08-03 04:10:16 +00:00
# Invoice number at top of page.
$y += 7;
$this->SetFont('helvetica','',10);
2010-11-29 22:41:08 +00:00
$this->SetXY($x,$y); $this->Cell(0,0,_('Issue Date')); $y += 5;
$this->SetXY($x,$y); $this->Cell(0,0,_('Amount Due'));
2009-08-03 04:10:16 +00:00
$y -= 5;
$this->SetFont('helvetica','B',11);
$this->SetXY($x,$y); $this->Cell(0,0,date(UNIX_DATE_FORMAT,$inv->print['invoice']['date_orig']),0,0,'R'); $y += 5;
$this->SetXY($x,$y); $this->Cell(0,0,date(UNIX_DATE_FORMAT,$inv->print['invoice']['due_date']),0,0,'R');
$y += 5;
$this->SetFont('helvetica','',10);
2010-11-29 22:41:08 +00:00
$this->SetXY($x,$y); $this->Cell(0,0,_('Previous Due'));
2009-08-03 04:10:16 +00:00
$this->SetFont('helvetica','B',11);
2010-11-29 22:41:08 +00:00
$this->SetXY($x+55,$y); $this->Cell(0,0,$this->_currency($inv->sPreviousBalance()),0,0,'R');
2009-08-03 04:10:16 +00:00
$y += 5;
$this->SetFont('helvetica','',10);
2010-11-29 22:41:08 +00:00
$this->SetXY($x,$y); $this->Cell(0,0,_('Current Charges'));
2009-08-03 04:10:16 +00:00
$this->SetFont('helvetica','B',11);
$this->SetXY($x+55,$y); $this->Cell(0,0,$this->_currency($inv->print['invoice']['total_amt']),0,0,'R');
if ($inv->print['invoice']['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->_currency($inv->print['invoice']['billed_amt']),0,0,'R');
}
2010-11-29 22:41:08 +00:00
if ($inv->print['invoice']['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->_currency($inv->print['invoice']['credit_amt']),0,0,'R');
}
2009-08-03 04:10:16 +00:00
$y += 5;
$this->SetFont('helvetica','',10);
$this->SetXY($x,$y); $this->Cell(0,0,'Total Payable');
$this->SetFont('helvetica','B',11);
2010-11-29 22:41:08 +00:00
$this->SetXY($x+55,$y); $this->Cell(0,0,$this->_currency($inv->sPreviousBalance()+$inv->print['invoice']['total_amt']-$inv->print['invoice']['billed_amt']-$inv->print['invoice']['credit_amt']),0,0,'R');
2009-08-03 04:10:16 +00:00
}
#@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($inv) {
2010-11-29 22:41:08 +00:00
$x = 120; $y = 242;
2009-08-03 04:10:16 +00:00
# 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;
2010-11-29 22:41:08 +00:00
# Direct Credit
$logo = sprintf('%s/%s','/afs/local/home/gh/.web/au.net.graytech.www/osb/modules/invoice/media/img/','invoice-payment-dd.png');
2009-08-03 04:10:16 +00:00
$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,'633-000'); $y += 3;
$this->SetXY($x+30,$y); $this->Cell(0,0,'120 440 821'); $y += 3;
2010-11-29 22:41:08 +00:00
$this->SetXY($x+30,$y); $this->Cell(0,0,$inv->getPrintInvoiceID()); $y += 3;
2009-08-03 04:10:16 +00:00
2010-11-29 22:41:08 +00:00
/*
2009-08-03 04:10:16 +00:00
# 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);
2010-11-29 22:41:08 +00:00
$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 = sprintf('%s/%s',PATH_THEMES.DEFAULT_THEME,'invoice/invoice-payment-pp.png');
$logo = sprintf('%s/%s','/afs/local/home/gh/.web/au.net.graytech.www/osb/modules/invoice/media/img/','invoice-payment-pp.png');
2010-11-29 22:41:08 +00:00
$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($inv->print['site']['URL'].'?_page=invoice:user_view&id='.$inv->getPrintInvoiceNum(),$inv->print['site']['URL']); $y += 3;
2009-08-03 04:10:16 +00:00
}
/**
* Draw previous invoices due
*/
public function drawSummaryInvoicesDue($items) {
$x = 125; $y = $this->sum_y ? $this->sum_y : 50;
# 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);
2010-11-29 22:41:08 +00:00
$this->SetXY($x,$y); $this->Cell(0,0,_('Previous Invoices due')); $y += 5;
2009-08-03 04:10:16 +00:00
$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 #%06s',date(UNIX_DATE_FORMAT,$line['date_orig']),$line['id']));
$this->Cell(0,0,$this->_currency($line['total_amt']-$line['billed_amt']),0,0,'R'); $y += 5;
} else {
$sum_total += $line['total_amt']-$line['billed_amt'];
}
}
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,$this->_currency($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_pre($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 drawLineItems($db,$line,$invnum) {
switch($this->iteration) {
case 0:
$this->drawLineItems_0($db,$line,$invnum);
break;
case 1:
$this->drawLineItems_1($db,$line,$invnum);
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($db,$line,$invnum) {
2010-11-29 22:41:08 +00:00
if ($line['price_type'] == 0 && $line['item_type'] == 5)
2009-08-03 04:10:16 +00:00
return;
$x = 10;
if ($this->i == 0 || $this->i%51 == 0) {
$this->y = 5;
$this->AddPage();
$this->SetFont('helvetica','B',12);
2010-11-29 22:41:08 +00:00
$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');
2009-08-03 04:10:16 +00:00
# Draw table headers
$this->y += 10;
$this->SetFont('helvetica','B',8);
$this->SetXY($x,$this->y);
2010-11-29 22:41:08 +00:00
$this->Cell(0,0,_('Description'));
2009-08-03 04:10:16 +00:00
$this->SetX($x+135);
2010-11-29 22:41:08 +00:00
$this->Cell(0,0,_('Quantity'));
2009-08-03 04:10:16 +00:00
$this->SetX($x+160);
2010-11-29 22:41:08 +00:00
$this->Cell(10,0,_('Unit Cost'),0,0,'R');
2009-08-03 04:10:16 +00:00
$this->SetX($x+135);
2010-11-29 22:41:08 +00:00
$this->Cell(0,0,_('Amount'),0,0,'R');
2009-08-03 04:10:16 +00:00
$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');
}
2010-11-29 22:41:08 +00:00
$this->SetX($x+130);
2009-08-03 04:10:16 +00:00
$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;
2010-11-29 22:41:08 +00:00
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;
2009-08-03 04:10:16 +00:00
$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++;
}
/**
* Draws the Item Detail for Iteration 1.
*/
private function drawLineItems_1($db,$line,$invnum) {
global $C_translate;
if ($this->show_itemized != 1) return;
if ($line['price_type'] != 0 || $line['item_type'] != 5)
return;
$x = 10; $this->y = 5;
if ($this->i == 0 || $this->i%51 == 0) {
$this->AddPage();
$this->SetFont('helvetica','B',12);
$this->SetXY($x,$this->y); $this->Cell(0,0,$C_translate->translate('pdf_itemized_calls','setup_invoice'));
$this->Cell(0,0,$C_translate->translate('pdf_page','setup_invoice').$this->PageNo(),0,0,'R');
$this->SetXY($x,$this->y); $this->Cell(0,0,$C_translate->translate('pdf_invoice_number_small','setup_invoice').$invnum,0,0,'C');
# Draw table headers
$this->SetFont('helvetica','B',8);
$this->SetXY($x,$this->y);
$this->Cell(0,0,$C_translate->translate('pdf_item_from','setup_invoice'));
$this->SetX(69);
$this->Cell(0,0,$C_translate->translate('pdf_item_to','setup_invoice'));
$this->SetX(119);
$this->Cell(0,0,'Date & Time');
$this->SetX(160);
$this->Cell(10,0,'Seconds' /*$C_translate->translate('pdf_item_min','setup_invoice')*/,0,0,'R');
$this->SetX($x+135);
$this->Cell(0,0,$C_translate->translate('pdf_item_amount','setup_invoice'),0,0,'R');
$this->Line($x,$this->y+4,200,$this->y+4);
$this->y += 5;
$this->SetY($this->y);
}
if ($line['price_type'] != 0) {
$this->SetFont('helvetica','I',6);
} else {
$this->SetFont('helvetica','',6);
}
$val = $line['name'];
if (strlen($line['attr'])) {
$val = "";
$atrs = preg_split("/\r\n/", str_replace('\r\n',"\r\n",$line['attr']));
foreach ($atrs as $a) {
$parts = preg_split("/==/", $a);
switch ($parts[0]) {
case "Destination":
$this->SetX(69);
$this->Cell(0,0,$parts[1]);
$cc = ""; $npa = ""; $nxx = ""; $e164 = "";
if ($this->v->e164($parts[1], $e164, $cc, $npa, $nxx)) {
$this->SetX(89);
$this->Cell(0,0,substr($this->v->where_is($db, $cc, $npa, $nxx), 0, 20));
}
break;
case "Source":
$this->SetX(9);
$this->Cell(0,0,$parts[1]);
$cc = ""; $npa = ""; $nxx = ""; $e164 = "";
if ($this->v->e164($parts[1], $e164, $cc, $npa, $nxx)) {
$this->SetX(29);
$this->Cell(0,0,substr($this->v->where_is($db, $cc, $npa, $nxx), 0, 20));
}
break;
case "parent_service_id":
$sql = sqlSelect($db,"service","prod_attr","id=::".$parts[1]."::");
$rstmp = $db->Execute($sql);
$atrs2 = split("\r\n", $rstmp->fields['prod_attr']);
foreach ($atrs2 as $a2) {
$parts2 = split("==", $a2);
switch ($parts2[0]) {
case "station":
case "ported":
$val = $line['name']." for ".$parts2[1];
break;
default:
break;
}
}
break;
case "station":
case "ported":
$val = $line['name']." for ".$parts[1];
break;
case "date_orig":
$this->SetX(119);
$this->Cell(0,0,date(UNIX_DATE_FORMAT." H:i:s",$parts[1]));
break;
case "voip_cdr_id":
$sql = "SELECT billsec, amount FROM ".AGILE_DB_PREFIX."voip_cdr WHERE site_id=".DEFAULT_SITE." AND id=".$parts[1];
$row = $db->GetRow($sql);
$this->SetX(160);
$this->Cell(10,0,$row[0],0,0,'R');
$this->SetX(160);
$this->Cell(0,0,$this->_currency($row[1]),0,0,'R');
$val = "";
default:
break;
}
}
}
$this->SetX(9);
$this->Cell(0,0, $val);
if ($line['price_type'] == 0) {
$this->SetX(160);
//$this->Cell(10,0, $line['qty']." M",0,0,'R');
} else {
$q = $line['qty'];
if(empty($q)) $q = 1;
$this->SetX(160);
$this->Cell(10,0, $line['qty'],0,0,'R');
2010-11-29 22:41:08 +00:00
$this->SetX($x+135);
2009-08-03 04:10:16 +00:00
$this->Cell(0,0, $this->_currency($line['amount']), 0,0,'R');
}
$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($inv) {
if (! $this->show_itemized)
return;
2010-11-29 22:41:08 +00:00
$items = $inv->sInvoiceItemsSummary();
2009-08-03 04:10:16 +00:00
# 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);
2010-11-29 22:41:08 +00:00
$this->SetXY($x-1,$y-1); $this->Cell(0,5*(
1+1+1+3+($inv->print['invoice']['discount_amt'] ? 1 : 0)+($inv->print['invoice']['billed_amt'] ? 1 : 0)+($inv->print['invoice']['credit_amt'] ? 1 : 0)+$box
)+1,'',1,0,'',1);
2009-08-03 04:10:16 +00:00
$this->SetFont('helvetica','B',11);
2010-11-29 22:41:08 +00:00
$this->SetXY($x,$y); $this->Cell(0,0,_('Current Charges Summary for')); $y += 5;
2009-08-03 04:10:16 +00:00
$this->SetY($y);
$this->SetFont('helvetica','',9);
$i=0;
if (is_array($items)) {
foreach($items as $line) {
$this->SetX($x);
$q = $line['quantity'];
if (empty($q))
$q = 1;
$this->Cell(0,0,$q);
$this->SetX($x+8);
2010-11-29 22:41:08 +00:00
$this->Cell(0,0,sprintf('%s (%s)',$line['product_name'],$this->_currency($line['price_base'])));
$this->SetX($x+135);
$this->Cell(0,0,$this->_currency($line['price_base']*$line['quantity']+$line['price_setup']),0,0,'R');
2009-08-03 04:10:16 +00:00
$y += 5;
$this->SetY($y);
$i++;
if ($i > $this->itemsSummaryMax) {
$this->SetFont('helvetica','B',11);
$this->SetX($x);
2010-11-29 22:41:08 +00:00
$this->Cell(0,0,_('The above is just a summary. To view a detailed list of charges, please visit our website.'));
2009-08-03 04:10:16 +00:00
break;
}
}
# Calculate our rounding error
$subtotal = 0;
foreach($items as $line)
2010-11-29 22:41:08 +00:00
$subtotal += $line['price_base']*$line['quantity']+$line['price_setup'];
2009-08-03 04:10:16 +00:00
2010-11-29 22:41:08 +00:00
$subtotal -= $inv->print['invoice']['discount_amt'];
2009-08-03 04:10:16 +00:00
$subtotal = round($subtotal,2);
if (round($inv->print['invoice']['total_amt']-$inv->print['invoice']['tax_amt'],2) != $subtotal) {
$this->SetFont('helvetica','',9);
$this->SetX($x);
$this->Cell(0,0,'Rounding');
2010-11-29 22:41:08 +00:00
$this->SetX($x+135);
$this->Cell(0,0,
$this->_currency($inv->print['invoice']['total_amt']-$inv->print['invoice']['tax_amt']-$subtotal),0,0,'R');
2009-08-03 04:10:16 +00:00
$y += 5;
$this->SetY($y);
}
2010-11-29 22:41:08 +00:00
# Draw Discounts.
if ($inv->print['invoice']['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,$this->_currency(-$inv->print['invoice']['discount_amt']),0,0,'R');
}
2009-08-03 04:10:16 +00:00
# Sub total and tax.
$y += 5;
$this->SetY($y);
$this->SetFont('helvetica','B',9);
$this->SetX($x+8);
$this->Cell(0,0,'Sub Total');
2010-11-29 22:41:08 +00:00
$this->SetX($x+135);
2009-08-03 04:10:16 +00:00
$this->Cell(0,0,$this->_currency($inv->print['invoice']['total_amt']-$inv->print['invoice']['tax_amt']),0,0,'R');
$y += 5;
$this->SetY($y);
$this->SetX($x+8);
$this->Cell(0,0,'Taxes');
2010-11-29 22:41:08 +00:00
$this->SetX($x+135);
2009-08-03 04:10:16 +00:00
$this->Cell(0,0,$this->_currency($inv->print['invoice']['tax_amt']),0,0,'R');
$y += 5;
$this->SetY($y);
$this->SetX($x+8);
$this->Cell(0,0,'Total Charges');
2010-11-29 22:41:08 +00:00
$this->SetX($x+135);
2009-08-03 04:10:16 +00:00
$this->Cell(0,0,$this->_currency($inv->print['invoice']['total_amt']),0,0,'R');
2010-11-29 22:41:08 +00:00
# Show payments already received for this invoice
if ($inv->print['invoice']['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,$this->_currency($inv->print['invoice']['billed_amt']),0,0,'R');
}
if ($inv->print['invoice']['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,$this->_currency(-$inv->print['invoice']['credit_amt']),0,0,'R');
}
2009-08-03 04:10:16 +00:00
$y += 5;
$this->SetY($y);
$this->SetX($x+8);
$this->Cell(0,0,'Balance Due');
2010-11-29 22:41:08 +00:00
$this->SetX($x+135);
$this->Cell(0,0,$this->_currency($inv->print['invoice']['total_amt']-$inv->print['invoice']['billed_amt']-$inv->print['invoice']['credit_amt']),0,0,'R');
2009-08-03 04:10:16 +00:00
}
}
}
?>