_isCustomerInvoice) { $this->SetFont('helvetica', 'B', 8); $this->Cell(0, 0,$this->_invoice->reference, 0, 0, 'L'); $this->Ln(); $margins = $this->getMargins(); $this->Line($margins['left'],$this->getY(),$this->getPageWidth()-$margins['right'],$this->getY(),array('width'=>0.3)); } else if ($franchiseName == 'lafoot') { $logoName = '/components/com_vxc/assets/images/lafootinvoiceheader.png'; $src = JPATH_BASE . $logoName; $imagex = 0; $imagey = 10; $this->Image($src,$imagex,$imagey,175,30,'','','',false,300,'L'); } } // Page footer public function Footer() { // Position at 1.5 cm from bottom $franchiseName = SiteOptionsHelper::getFranchiseName(); $this->SetY($this->_isCustomerInvoice?-25:-15); $margins = $this->getMargins(); $this->Line($margins['left'],$this->getY(),$this->getPageWidth()-$margins['right'],$this->getY(),array('width'=>0.3)); if ($this->_isCustomerInvoice) { $arrayInfo2 = array(); $this->SetFont('helvetica','',8); $text = "
".JString::strtoupper($this->_invoice->franchisename)."". " ".$this->_invoice->franchiseaddress. " ".$this->_invoice->franchiseaddress2. " ".JString::strtoupper($this->_invoice->franchisecountry)."
"; $this->writeHTML($text); } $this->SetFont('helvetica', '', 8); $arrayInfo = array(); if ($this->_invoice->franchisetelephone) $arrayInfo[] = JText::_('Telephone').": " . $this->_invoice->franchisetelephone; if ($this->_invoice->franchisemobile) $arrayInfo[] = JText::_('Mobile').": " . $this->_invoice->franchisemobile; if ($this->_invoice->franchisefax) $arrayInfo[] = JText::_('FAX').": " . $this->_invoice->franchisefax; if ($this->_invoice->franchiseemail) $arrayInfo[] = JText::_('E-Mail').": " . $this->_invoice->franchiseemail; if ($this->_invoice->franchisewebsite) $arrayInfo[] = JText::_('Website').": " . $this->_invoice->franchisewebsite; $this->Cell(0, 0, implode(' ',$arrayInfo).' '.JText::_('Page').' '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, 1, 'C'); if ($this->_isCustomerInvoice) { $arrayInfo2 = array(); if ($this->_invoice->franchisevatnumber) $arrayInfo2[] = JText::_('Vat number').': '. $this->_invoice->franchisevatnumber; if ($this->_invoice->franchisecompanynumber) $arrayInfo2[] = JText::_('Company number').': '. $this->_invoice->franchisecompanynumber; if ($this->_invoice->franchiseacctnumber) $arrayInfo2[] = JText::_('Account number').': '. $this->_invoice->franchiseacctnumber; $this->SetFont('helvetica','',8); $this->Cell(0, 0, implode(' ',$arrayInfo2), 0, 0, 'C'); } if ($franchiseName=='tecnoinsole' && $this->_invoice->enduserheaderinfo) { $this->Cell(0, 0,$this->_invoice->enduserheaderinfo, 0, 0, 'L'); } } } class vxcModelInvoice extends JModel { var $_id = 0; var $_lineId = 0; var $_item = null; var $_margin_left = 20; var $_margin_top = 20; var $_margin_right = 20; var $_margin_bottom = 15; var $_margin_header = 10; var $_margin_footer = 10; /** * Constructor * * @access public * @return void */ function __construct() { parent::__construct(); $this->setDBO(VoxelCareDB::getDatabase()); $this->_allLines = true; }//function function SetAllLines($allLines) { $this->_allLines = $allLines; } function SetId($id) { $this->_id = (int)$id; $this->_item = null; $this->_lineId = 0; } function SetLineId($id) { $this->_lineId = (int)$id; } function updateTotals() { $sql = "SELECT i.shipping_cost shipping_cost, SUM(price*amount) subtotal, SUM(price * amount *(discount/100.0)) discounts, SUM(price *amount *(1.0-discount/100.0)*(vat/100.0)) taxes, SUM(price *amount *(1.0-discount/100.0)*(equivalence_charge/100.0)) equiv_charges FROM #__vxc_invoice i LEFT JOIN #__vxc_invoiceline il ON i.id = il.invoice WHERE i.id = ".$this->_id." AND (il.referred_order IS NULL OR il.referred_order = 0) GROUP BY i.id"; $this->_db->setQuery($sql); $result = $this->_db->loadObject(); $data = array(); $data['id'] = $this->_id; $data['taxes'] = $result->taxes; $data['discounts'] = $result->discounts; $data['subtotal'] = $result->subtotal; $data['equiv_charges'] = $result->equiv_charges; $data['total'] = $data['subtotal'] + $result->shipping_cost + $data['taxes'] + $data['equiv_charges'] - $data['discounts']; $this->store($data); } function store(&$data) { $table =& $this->getTable('invoice'); $db =& $this->_db; $table->reset(); $id = (int)$data['id']; $table->load($id); if (!$table->bind($data)) return false; if (!$table->check()) return false; if (!$table->store(true)) return false; $this->SetId($table->id); $data['id'] = $this->_id; return true; } function storeLine(&$data) { $table =& $this->getTable('invoiceline'); $db =& $this->_db; $table->reset(); $id = (int)$data['id']; $table->load($id); if (!$table->bind($data)) return false; if (!$table->check()) return false; if (!$table->store(true)) return false; $data['id'] = $table->id; return true; } function deleteLine($lineId) { $sql = "DELETE FROM #__vxc_invoiceline WHERE id = ".$lineId; $this->_db->Execute($sql); } function getInvoiceLines($all) { $db =& $this->_db; $isEndUserInvoice = ((int)$this->_lineId); if ($all) $where = " il.invoice = " . $this->_id; else { if ($isEndUserInvoice) $where = " il.invoice = ". $this->_id . " AND (il.id = ". $this->_lineId. " OR il.referred_order = (SELECT il2.orderid FROM #__vxc_invoiceline il2 WHERE il2.invoice = ". $this->_id ." AND il2.id = ". $this->_lineId.") )"; else $where = " il.invoice = " . $this->_id . " AND (il.referred_order IS NULL OR il.referred_order = 0)"; } $newModeFields = ''; $newJoins = ''; $oldModeFields =''; if (LegacyHelper::getNewMode()) { $newModeFields = "o.uuid uuid, atfirst.value customername, atlast.value customersurname, atmiddle.value customermiddlename, CONCAT_WS(' ',NULLIF(CONCAT_WS(' ',NULLIF(c.name,''),NULLIF(c.middlename,''),NULLIF(c.surname,'')),''),NULLIF(atfirst.value,''),NULLIF(atmiddle.value,''),NULLIF(atlast.value,'')) customerfullname,"; $newJoins = " LEFT JOIN jos_vxc_attribute atfirst ON atfirst.orderid = o.id AND atfirst.name = 'patient.firstName' LEFT JOIN jos_vxc_attribute atmiddle ON atmiddle.orderid = o.id AND atmiddle.name = 'patient.middleName' LEFT JOIN jos_vxc_attribute atlast ON atlast.orderid = o.id AND atlast.name = 'patient.lastName' "; } else { $oldModeFields = "c.name customername, c.surname customersurname, c.middlename customermiddlename,CONCAT_WS(' ',NULLIF(c.name,''),NULLIF(c.middlename,''),NULLIF(c.surname,'')) customerfullname,"; } $sql = "SELECT il.id id, il.orderid orderid, il.concept concept, il.amount amount, il.price price, il.patient_price patient_price, il.franchise_to_company_fee franchise_to_company_fee, il.voxelcare_to_franchise_fee voxelcare_to_franchise_fee, il.patient_total patient_total, il.discount discount, il.vat vat, il.equivalence_charge equivalence_charge, il.total total, il.referred_order referred_order, o.creationdate ordercreationdate, $newModeFields o.reference orderreference, $oldModeFields c.address customeraddress, c.city customercity, c.province customerprovince, c.pcode customerpcode, c.email customeremail, c.telephone customertelephone, c.mobile customermobile, c.fax customerfax, c.birthdate customerbirthdate, c.country customercountry, t.name customertitlename FROM #__vxc_invoiceline il LEFT JOIN #__vxc_order o ON o.id = il.orderid LEFT JOIN #__vxc_customer c ON c.id = o.customer LEFT JOIN #__vxc_title t ON t.id = c.title $newJoins WHERE ". $where . " ORDER BY il.orderid DESC, o.creationdate ,il.id "; $db->setQuery($sql); return $db->loadObjectList(); } function getData() { if (empty($this->_item)) { $db =& $this->_db; $sql = "SELECT i.id id, i.batch batch, i.reference reference, i.generation_date generation_date, i.subtotal subtotal, i.taxes taxes, i.equiv_charges equiv_charges, i.paid paid, i.returned returned, i.discounts discounts, i.comments comments, i.total total, b.payment_user payment_user, b.equivalence_charge equivalence_charge, i.shipping_cost shipping_cost, pm.name payment_methodname, pm.nameid payment_methodnameid, u.name username, u.email useremail, f.name franchisename, f.address franchiseaddress, f.address2 franchiseaddress2, f.email franchiseemail, f.telephone franchisetelephone, f.mobile franchisemobile, f.fax franchisefax, f.vat_number franchisevatnumber, f.acct_number franchiseacctnumber, f.company_number franchisecompanynumber, f.website franchisewebsite, f.country franchisecountry, f.logo franchiselogo, f.customer_logo franchisecustomerlogo, f.enduserheaderinfo enduserheaderinfo, u.address useraddress, u.city usercity, u.pcode userzipcode, u.country usercountry, u.phone userphone, u.cif uservatnumber FROM #__vxc_invoice i LEFT JOIN #__vxc_batch b ON b.id = i.batch LEFT JOIN #__vxc_user u ON u.id = b.payment_user LEFT JOIN #__vxc_userfranchise uf ON uf.userid = u.id LEFT JOIN #__vxc_franchise f ON f.id = uf.franchise LEFT JOIN #__vxc_paymentmethod pm ON pm.id = b.payment_method WHERE i.id = ".$this->_id; $db->setQuery($sql); $row = $db->loadObject(); if (!$row) { $row = new stdClass(); $row->id = 0; $row->lines = array(); } else { $row->lines =& $this->getInvoiceLines($this->_allLines); } $this->_item = $row; } return $this->_item; } function getNextInvoiceReference(&$date,$userId) { $sql = "SELECT i1.reference reference FROM #__vxc_userfranchise uf1, #__vxc_invoice i1 WHERE uf1.userid = ".$userId. " AND i1.reference =( SELECT MAX(i.reference) FROM #__vxc_invoice i LEFT JOIN #__vxc_batch b ON b.id = i.batch LEFT JOIN #__vxc_paymentmethod pm ON pm.id = b.payment_method LEFT JOIN #__vxc_userfranchise uf2 ON uf2.userid = b.payment_user WHERE uf2.franchise = uf1.franchise AND pm.nameid <> 'BUDGET')"; $this->_db->setQuery($sql); $lastReference = $this->_db->loadResult(); $currentYear = $date->toFormat('%y'); if (!$lastReference) $counter = 1; else { $lastYear = substr($lastReference,3,2); if ($lastYear!=$currentYear) $counter = 1; else { $lastCounter = (int)substr($lastReference,5,5); $counter = $lastCounter +1; } } $reference = sprintf("VCI%s%05d",$currentYear,$counter); return $reference; } function getNextBudgetReference(&$date,$userId) { $sql = "SELECT i1.reference reference FROM #__vxc_invoice i1,#__vxc_userfranchise uf1 WHERE uf1.userid = ".$userId. " AND i1.reference =( SELECT MAX(i.reference) FROM #__vxc_invoice i LEFT JOIN #__vxc_batch b ON b.id = i.batch LEFT JOIN #__vxc_paymentmethod pm ON pm.id = b.payment_method LEFT JOIN #__vxc_userfranchise uf2 ON uf2.userid = b.payment_user WHERE uf2.franchise = uf1.franchise AND pm.nameid = 'BUDGET')"; $this->_db->setQuery($sql); $lastReference = $this->_db->loadResult(); $currentYear = $date->toFormat('%y'); if (!$lastReference) $counter = 1; else { $lastYear = substr($lastReference,3,2); if ($lastYear!=$currentYear) $counter = 1; else { $lastCounter = (int)substr($lastReference,5,5); $counter = $lastCounter +1; } } $reference = sprintf("VCP%s%05d",$currentYear,$counter); return $reference; } function printCustomerPDF(&$pdf) { return $this->_printPDF($pdf,true); } function printPDF(&$pdf) { return $this->_printPDF($pdf,false); } function printCommissionsPDF(&$pdf) { $invoice =& $this->getData(); $lang = &JFactory::getLanguage(); $font = $lang->getPdfFontName(); $font = ($font) ? $font : 'freesans'; $pdf = new InvoicePDF('P', 'mm', 'A4', true, 'UTF-8', false); $pdf->_invoice =& $invoice; $lines =& $invoice->lines; $pdf->SetMargins($this->_margin_left, $this->_margin_top, $this->_margin_right); $pdf->SetAutoPageBreak(TRUE, $this->_margin_bottom); $pdf->setPrintHeader(true); $pdf->setPrintFooter(true); //$pdf->SetFooterMargin($this->_margin_footer); $pdf->SetHeaderMargin($this->_margin_header); $pdf->setRTL($lang->isRTL()); $pdf->setHeaderFont(array($font, '', 10)); $pdf->setFooterFont(array($font, '', 8)); $pdf->AliasNbPages(); $pdf->AddPage(); $pdf->SetFont('helvetica','b',18); $pdf->Cell(0,0,JText::_('Commissions'),0,0); if ($invoice->franchiselogo) { $src = $_SERVER['DOCUMENT_ROOT'] . $invoice->franchiselogo; $imagex = $pdf->getX(); $imagey = 15; $pdf->Image($src,$imagex,$imagey,0,20,'','','',false,72,'R'); } $pdf->Ln(); $pdf->SetFont('helvetica','',12); $pdf->Ln(10); $margins = $pdf->getMargins(); $pdf->Line($margins['left'],$pdf->getY(),$pdf->getPageWidth()-$margins['right'],$pdf->getY(),array('width'=>0.3)); $pdf->Ln(); $pdf->SetFont('helvetica','',12); if ($invoice->generation_date) { $generationDate = new JDate($invoice->generation_date); $generationDate->setOffset(date('Z')/3600.0); $generationDateS = $generationDate->toFormat('%d/%m/%Y'); } else { $generationDateS = JText::_('None'); } $pdf->Cell(0,0,JText::_('Date').": ".$generationDateS,0,1,'R'); $pdf->SetFont('helvetica','',12); // Datos del cliente $pdf->Ln(); $pdf->SetFont('helvetica','bu',14); $pdf->Cell(0,0,JText::_('Company'),0,0); $pdf->Cell(0,0,$invoice->franchisename,0,0,'R'); $pdf->Ln(); $pdf->SetFont('helvetica','',10); $arrayCols = array('L','R'); $arrayCols['L'][] = $invoice->username; if ($invoice->usercompany) $arrayCols['L'][] = $invoice->usercompany; if ($invoice->useraddress) $arrayCols['L'][] = $invoice->useraddress; $aux = array(); if ($invoice->usercity) $aux[] = $invoice->usercity; if ($invoice->userzipcode) $aux[] = "(".$invoice->userzipcode.")"; if ($invoice->usercountry) $aux[] = strtoupper($invoice->usercountry); $moreaddress = implode(' ',$aux); if ($moreaddress) $arrayCols['L'][] = $moreaddress; if ($invoice->useremail) $arrayCols['L'][] = $invoice->useremail; if ($invoice->userphone) $arrayCols['L'][] = $invoice->userphone; if ($invoice->uservatnumber) $arrayCols['L'][] =JText::_('Vat number').': '. $invoice->uservatnumber; if ($invoice->franchiseaddress) $arrayCols['R'][] = $invoice->franchiseaddress; if ($invoice->franchiseaddress2) $arrayCols['R'][] = $invoice->franchiseaddress2; if ($invoice->franchisecountry) $arrayCols['R'][] =JString::strtoupper( $invoice->franchisecountry); if ($invoice->franchisevatnumber) $arrayCols['R'][] = JText::_('Vat number').': '. $invoice->franchisevatnumber; if ($invoice->franchisecompanynumber) $arrayCols['R'][] = JText::_('Company number').': '. $invoice->franchisecompanynumber; for ($k = 0; $k< count($arrayCols['L']) || $k< count($arrayCols['R']); $k++) { $pdf->Cell(0,0,$arrayCols['L'][$k],0,0); $pdf->Cell(0,0,$arrayCols['R'][$k],0,1,'R'); } $pdf->SetFont('helvetica','',12); $pdf->Ln(); $col1W = 90; $col2W = 15; $col3W = 20; $col4W = 20; $col5W = 20; $pdf->SetLineWidth(0.3); $pdf->SetFont('helvetica','b',12); $headerHeight = 7; $pdf->writeHTMLCell($col1W,$headerHeight,'','',JText::_('ITEM'),'TB',0,0,true,'C'); $pdf->writeHTMLCell($col2W,$headerHeight,'','',JText::_('ABB_QUANTITY'),'TB',0,0,true,'C'); $pdf->writeHTMLCell($col3W,$headerHeight,'','',JText::_('Price'),'TB',0,0,true,'C'); $pdf->writeHTMLCell($col4W,$headerHeight,'','',JText::_('VAT'),'TB',0,0,true,'C'); $pdf->writeHTMLCell($col5W,$headerHeight,'','',JText::_('TOTAL'),'TB',0,0,true,'C'); $pdf->SetLineWidth(0.2); $pdf->Ln(); $pdf->SetFont('helvetica','',12); $pdf->SetLineWidth(0.1); $subtotal = 0; $taxes = 0; foreach( $invoice->lines as $line) { $concept2 = ''; if ($line->orderid) { $date = new JDate($line->ordercreationdate); $date->setOffset(date('Z')/3600.0); $dateS = $date->toFormat('%d/%m/%Y'); $concept = JText::_('Order')." ". $line->orderid ." (". $dateS.")"; if ($line->customerfullname) $concept2 = $line->customerfullname; if ($line->orderreference) { if ($concept2) $concept2 .= " / "; $concept2 .= $line->orderreference; } } else if ($line->concept) $concept = $line->concept; else $concept = ""; $amount = $line->amount; $realPrice = $line->franchise_to_company_fee; $price = sprintf("%0.02f",$realPrice). " €"; $vat = sprintf("%0.02f",$line->vat). " %"; $realTotal = ($line->vat+100.0)/100.0*$realPrice; $total = sprintf("%0.02f",$realTotal). " €"; if ($concept2) $border = "T"; else $border = "TB"; $subtotal += $realPrice; $taxes += ($line->vat)/100.0*$realPrice; $pdf->Cell($col1W,0,$concept,$border,0,'L'); $pdf->Cell($col2W,0,$amount,$border,0,'C'); $pdf->Cell($col3W,0,$price,$border,0,'R'); $pdf->Cell($col4W,0,$vat,$border,0,'R'); $pdf->Cell($col5W,0,$total,$border,0,'R'); $pdf->Ln(); if ($concept2) { $pdf->Cell($col1W + $col2W + $col3W + $col4W + $col5W,0,$concept2,'B',0,'L'); $pdf->Ln(); } } $colAncha =$col1W + $col2W + $col3W +$col4W; $pdf->Cell($colAncha + $col5W,0,'','',0,0); $pdf->Ln(); $pdf->SetFont('helvetica','b',12); $pdf->Cell($colAncha,0,JText::_('SUBTOTAL').':','',0,'R'); $pdf->SetFont('helvetica','',12); $pdf->Cell($col5W,0,sprintf("%0.02f",$subtotal). " €",'',0,'R'); $pdf->Ln(); $pdf->SetFont('helvetica','b',12); $pdf->Cell($colAncha,0,JText::_('VAT').":",'',0,'R'); $pdf->SetFont('helvetica','',12); $pdf->Cell($col5W,0,sprintf("%0.02f",round($taxes,2)). " €",'',0,'R'); $pdf->Ln(); $pdf->SetFont('helvetica','b',12); $pdf->Cell($colAncha,0,JText::_('TOTAL').":",'',0,'R'); $pdf->SetFont('helvetica','',12); $pdf->Cell($col5W,0,sprintf("%0.02f",$subtotal + $taxes). " €",'',0,'R'); } function _printPDF(&$pdf,$isCustomerInvoice) { $invoice =& $this->getData(); $lang = &JFactory::getLanguage(); $font = $lang->getPdfFontName(); $font = ($font) ? $font : 'freesans'; $hasEquivalenceCharge = ($invoice->equivalence_charge)!=0; $pdf = new InvoicePDF('P', 'mm', 'A4', true, 'UTF-8', false); $pdf->_isCustomerInvoice = $isCustomerInvoice; $pdf->_invoice =& $invoice; $lines =& $invoice->lines; if ($isCustomerInvoice) $line =& $lines[0]; $isLaFoot = SiteOptionsHelper::getFranchiseName()=='lafoot'; if ($isLaFoot) { $this->_margin_header = 0; $this->_margin_top = 40; } $pdf->SetMargins($this->_margin_left, $this->_margin_top, $this->_margin_right); $pdf->SetAutoPageBreak(TRUE, $this->_margin_bottom); $pdf->setPrintHeader(true); $pdf->setPrintFooter(true); //$pdf->SetFooterMargin($this->_margin_footer); $pdf->SetHeaderMargin($this->_margin_header); $pdf->setRTL($lang->isRTL()); $pdf->setHeaderFont(array($font, '', 10)); $pdf->setFooterFont(array($font, '', 8)); $pdf->AliasNbPages(); $pdf->AddPage(); $pdf->SetFont('helvetica','b',18); if (!$isCustomerInvoice) $pdf->Cell(0,0,$invoice->franchisename,0,1); else { if (!$isLaFoot) { $pdf->SetFont('helvetica','',8); //$pdf->writeHTMLCell(80,0,0,0,$invoice->enduserheaderinfo,0,'L'); $pdf->writeHTML($invoice->enduserheaderinfo,false); } } if ($isCustomerInvoice) { if (!$isLaFoot) { $logoName = $invoice->franchisecustomerlogo; if (!$logoName) $logoName = $invoice->franchiselogo; } } else $logoName = $invoice->franchiselogo; if ($logoName) { $src = $_SERVER['DOCUMENT_ROOT'] . $logoName; $imagex = $pdf->getX(); $imagey = 15; $pdf->Image($src,$imagex,$imagey,0,20,'','','',false,72,'R'); } if (!$isCustomerInvoice) { $pdf->SetFont('helvetica','',12); $pdf->Cell(0,0,$invoice->franchiseaddress,0,1); $pdf->Cell(0,0,$invoice->franchiseaddress2,0,1); $pdf->SetFont('helvetica','bu',12); $pdf->Cell(40,0,JString::strtoupper($invoice->franchisecountry),0,0); $pdf->SetFont('helvetica','',10); $pdf->Cell(0,0,JText::_('Vat number').': '. $invoice->franchisevatnumber,0,0,'R'); if ($invoice->franchisecompanynumber) { $pdf->Ln(); $pdf->Cell(0,0,JText::_('Company number').': '. $invoice->franchisecompanynumber,0,0,'R'); } if ($invoice->franchiseacctnumber) { $pdf->Ln(); $pdf->Cell(0,0,JText::_('Account number').': '. $invoice->franchiseacctnumber,0,0,'R'); } } if (!$isLaFoot || !$isCustomerInvoice) { $pdf->SetFont('helvetica','',12); $pdf->Ln(7); $margins = $pdf->getMargins(); $pdf->Line($margins['left'],$pdf->getY(),$pdf->getPageWidth()-$margins['right'],$pdf->getY(),array('width'=>0.3)); } $pdf->Ln(3); //$pdf->Ln(); $pdf->SetFont('helvetica','bu',12); if ($invoice->payment_methodnameid!='BUDGET') $title = JText::_('Invoice').": ".$invoice->reference; else $title = $invoice->reference; $pdf->Cell(90,0,$title,0,0); $pdf->SetFont('helvetica','',12); if ($invoice->generation_date) { $generationDate = new JDate($invoice->generation_date); $generationDate->setOffset(date('Z')/3600.0); $generationDateS = $generationDate->toFormat('%d/%m/%Y'); } else { $generationDateS = JText::_('None'); } $pdf->Cell(0,0,JText::_('Date').": ".$generationDateS,0,1,'R'); if (!$isCustomerInvoice) { $pdf->SetFont('helvetica','',12); $paymentMethod = ''; switch($invoice->payment_methodnameid) { case 'GIROBANCARIO': $paymentMethod = 'Giro bancario'; break; case 'BUDGET': $paymentMethod = JText::_('Budget'); break; case 'TEST': $paymentMethod = JText::_('Test'); break; case 'SAMPLE': $paymentMethod= JText::_('Sample'); break; case 'PAYPAL': $paymentMethod = 'Paypal'; break; case 'CREDIT': $paymentMethod = JText::_('Credit'); break; case 'CREDITCARD': $paymentMethod = JText::_('Credit card'); break; case 'BYINVOICE': $paymentMethod= JText::_('Pay by invoice'); break; case 'BYRECEIPT': $paymentMethod= JText::_('Pay by receipt'); break; } $pdf->writeHTMLCell(0,0,'','',"".JText::_('Payment method').": ".$paymentMethod,0,1); /* switch($invoice->payment_methodnameid) { case 'GIROBANCARIO': $pdf->writeHTMLCell(0,0,$pdf->GetX(),$pdf->GetY(),"Bank account / Cuenta bancaria: ".$user->acctnumber,0,1); break; } */ } // Datos del cliente $pdf->Ln(); $pdf->SetFont('helvetica','bu',14); if ($isCustomerInvoice) $pdf->Cell(0,0,JText::_('Client'),0,0); else $pdf->Cell(0,0,JText::_('Company'),0,0); $pdf->Ln(); $pdf->SetFont('helvetica','',10); $arrayCols = array('L','R'); if ($isCustomerInvoice) { $nameArray = array(); if ($line->customertitlename) $nameArray[] = JText::_($line->customertitlename); if ($line->customerfullname) $nameArray[] = $line->customerfullname; $arrayCols['L'][] = implode(' ',$nameArray); if ($line->customeraddress) $arrayCols['L'][] = $line->customeraddress; $aux = array(); if ($line->customerpcode) $aux[] = strtoupper($line->customerpcode); if ($line->customercity) $aux[] = strtoupper($line->customercity); $customermoreaddress = implode(' ',$aux); if ($customermoreaddress) $arrayCols['L'][] = $customermoreaddress; if ($line->customercountry) $arrayCols['L'][] = strtoupper($line->customercountry); $aux = array(); if ($line->customertelephone) $aux[] = $line->customertelephone; if ($line->customermobile) $aux[] = $line->customermobile; if ($line->customerfax) $aux[] = $line->customerfax; if ($line->customeremail) $arrayCols['L'][] = $line->customeremail; if ($line->customerbirthdate) { $date = new JDate($line->customerbirthdate); $customermoreinfo = $date->toFormat("%d/%m/%Y"); $arrayCols['L'][] = $customermoreinfo; } } else { $arrayCols['L'][] =$invoice->username; // Mas datos del cliente if ($invoice->usercompany) $arrayCols['L'][] = $invoice->usercompany; if ($invoice->useraddress) $arrayCols['L'][] = $invoice->useraddress; $aux = array(); if ($invoice->usercity) $aux[] = $invoice->usercity; if ($invoice->userzipcode) $aux[] = "(".$invoice->userzipcode.")"; if ($invoice->usercountry) $aux[] = strtoupper($invoice->usercountry); $usermoreaddress = implode(' ',$aux); if ($usermoreaddress) $arrayCols['L'][] = $usermoreaddress; if ($invoice->useremail) $arrayCols['L'][] = $invoice->useremail; if ($invoice->userphone) $arrayCols['L'][] = $invoice->userphone; if ($invoice->uservatnumber) $arrayCols['L'][] = JText::_('Vat Number') . ": ". $invoice->uservatnumber; } for ($k = 0; $k< count($arrayCols['L']) || $k< count($arrayCols['R']); $k++) { $pdf->Cell(0,0,$arrayCols['L'][$k],0,0); $pdf->Cell(0,0,$arrayCols['R'][$k],0,1,'R'); } $pdf->SetFont('helvetica','',12); // Fin de mas datos del cliente $pdf->Ln(); if ($isCustomerInvoice) $col1W = 95; else { $col1W = 65; if ($hasEquivalenceCharge) $col7W = 18; } $col2W = 15; $col3W = 20; $col4W = 20; $col5W = 20; $col6W = 20; $pdf->SetLineWidth(0.3); $pdf->SetFont('helvetica','b',12); $headerHeight = 7; $pdf->writeHTMLCell($col1W,$headerHeight,'','',JText::_('ITEM'),'TB',0,0,true,'C'); $pdf->writeHTMLCell($col2W,$headerHeight,'','',JText::_('ABB_QUANTITY'),'TB',0,0,true,'C'); $pdf->writeHTMLCell($col3W,$headerHeight,'','',JText::_('Price'),'TB',0,0,true,'C'); $pdf->writeHTMLCell($col4W,$headerHeight,'','',JText::_('VAT'),'TB',0,0,true,'C'); if (!$isCustomerInvoice) { if ($hasEquivalenceCharge) $pdf->writeHTMLCell($col7W,$headerHeight,'','',JText::_('ABB_EQUIVALENCE_CHARGE'),'TB',0,0,true,'C'); $pdf->writeHTMLCell($col5W,$headerHeight,'','',JText::_('ABB_DISCOUNT'),'TB',0,0,true,'C'); } $pdf->writeHTMLCell($col6W,$headerHeight,'','',JText::_('TOTAL'),'TB',0,0,true,'C'); $pdf->SetLineWidth(0.2); $pdf->Ln(); $pdf->SetFont('helvetica','',12); $pdf->SetLineWidth(0.1); $endUserSubtotal = 0; $endUserTotal = 0; foreach( $invoice->lines as $line) { $concept = ''; $concept2 = ''; $concept3 = ''; if ($line->orderid) { $concept =JText::_('ORDER_DESCRIPTION'); $date = new JDate($line->ordercreationdate); $date->setOffset(date('Z')/3600.0); $dateS = $date->toFormat('%d/%m/%Y'); $concept2 = JText::_('Order')." ". $line->orderid ." (". $dateS.")"; $nameArray = array(); if ($line->customertitlename) $nameArray[] = JText::_($line->customertitlename); if ($line->customername) { $firstNameArray = explode(' ',$line->customername); for ($i=0;$icustomermiddlename) $nameArray[] = $line->customermiddlename; if ($line->customersurname) $nameArray[] = $line->customersurname; $customerName = implode(' ',$nameArray); if ($customerName) $concept3 .= $customerName; if ($line->orderreference) { if ($concept3) $concept3 .= " / "; $concept3 .= $line->orderreference; } } else if ($line->concept) $concept = $line->concept; else $concept = ""; $amount = $line->amount; if ($isCustomerInvoice) { $price = sprintf("%0.02f",$line->patient_price). " €"; $endUserSubtotal += round($amount*$line->patient_price,2); } else { $price = sprintf("%0.02f",$line->price). " €"; } $equivalence_charge = sprintf("%0.02f",$line->equivalence_charge). " %"; $discount = sprintf("%0.02f",$line->discount). " %"; $vat = sprintf("%0.02f",$line->vat). " %"; if ($isCustomerInvoice) { $total = sprintf("%0.02f",$line->patient_total). " €"; $endUserTotal += $line->patient_total; } else $total = sprintf("%0.02f",$line->total). " €"; if ($concept2) $border = "T"; else $border = "TB"; $pdf->Cell($col1W,0,$concept,$border,0,'L',0,'',1); $pdf->Cell($col2W,0,$amount,$border,0,'C'); $pdf->Cell($col3W,0,$price,$border,0,'R'); $pdf->Cell($col4W,0,$vat,$border,0,'R'); if (!$isCustomerInvoice) { if ($hasEquivalenceCharge) $pdf->Cell($col5W,0,$equivalence_charge,$border,0,'R'); $pdf->Cell($col5W,0,$discount,$border,0,'R'); } $pdf->Cell($col6W,0,$total,$border,0,'R'); if ($isCustomerInvoice) $anchuraConceptos = $col1W + $col2W + $col3W + $col4W + $col6W; else { $anchuraConceptos = $col1W + $col2W + $col3W + $col4W + $col5W + $col6W; if ($hasEquivalenceCharge) $anchuraConceptos += $col7W; } $pdf->Ln(); if ($concept2) { if ($concept3) $border = ''; else $border = 'B'; $pdf->Cell($anchuraConceptos,0,$concept2,$border,0,'L',0,'',1); $pdf->Ln(); } if ($concept3) { $pdf->Cell($anchuraConceptos,0,$concept3,'B',0,'L',0,'',1); $pdf->Ln(); } } if ($isCustomerInvoice) $colAncha =$col1W + $col2W + $col3W +$col4W; else { $colAncha =$col1W + $col2W + $col3W +$col4W+ $col5W; if ($hasEquivalenceCharge) $colAncha += $col7W; } $pdf->Cell($colAncha + $col6W,0,'','',0,0); $pdf->Ln(); $pdf->SetFont('helvetica','b',12); $pdf->Cell($colAncha,0,JText::_('SUBTOTAL').':','',0,'R'); $pdf->SetFont('helvetica','',12); if ($isCustomerInvoice) $pdf->Cell($col5W,0,sprintf("%0.02f",$endUserSubtotal). " €",'',0,'R'); else $pdf->Cell($col5W,0,sprintf("%0.02f",$invoice->subtotal). " €",'',0,'R'); $pdf->Ln(); $pdf->SetFont('helvetica','b',12); $pdf->Cell($colAncha,0,JText::_('VAT').":",'',0,'R'); $pdf->SetFont('helvetica','',12); if ($isCustomerInvoice) $pdf->Cell($col5W,0,sprintf("%0.02f",$endUserTotal - $endUserSubtotal ). " €",'',0,'R'); else $pdf->Cell($col5W,0,sprintf("%0.02f",$invoice->taxes). " €",'',0,'R'); if (!$isCustomerInvoice) { if ($hasEquivalenceCharge) { $pdf->Ln(); $pdf->SetFont('helvetica','b',12); $pdf->Cell($colAncha,0,JText::_('ABB_EQUIVALENCE_CHARGE').":",'',0,'R'); $pdf->SetFont('helvetica','',12); $pdf->Cell($col5W,0,sprintf("%0.02f",$invoice->equiv_charges). " €",'',0,'R'); } if ($invoice->discounts!=0) { $pdf->Ln(); $pdf->SetFont('helvetica','b',12); $pdf->Cell($colAncha,0,JText::_('ABB_DISCOUNT').":",'',0,'R'); $pdf->SetFont('helvetica','',12); $pdf->Cell($col5W,0,sprintf("%0.02f",$invoice->discounts). " €",'',0,'R'); } if ($invoice->shipping_cost>0) { $pdf->Ln(); $pdf->SetFont('helvetica','b',12); $pdf->Cell($colAncha,0,JText::_('Shipping costs').":",'',0,'R'); $pdf->SetFont('helvetica','',12); $pdf->Cell($col5W,0,sprintf("%0.02f",$invoice->shipping_cost). " €",'',0,'R'); } } $pdf->Ln(); $pdf->SetFont('helvetica','b',12); $pdf->Cell($colAncha,0,JText::_('TOTAL').":",'',0,'R'); $pdf->SetFont('helvetica','',12); if (!$isCustomerInvoice) $pdf->Cell($col5W,0,sprintf("%0.02f",$invoice->total). " €",'',0,'R'); else $pdf->Cell($col5W,0,sprintf("%0.02f",$endUserTotal). " €",'',0,'R'); $pdf->Ln(); if (!$isCustomerInvoice&& $invoice->comments) { $pdf->SetFont('helvetica','b',14); $pdf->Cell(0,0,JText::_('Remarks'),0,1); $pdf->SetFont('helvetica','',10); $pdf->writeHTMLCell(0,0,$pdf->getX(),$pdf->getY(), $invoice->comments); } } function getInvoiceByBatch($batchId) { $sql = "SELECT i.id id FROM #__vxc_invoice i WHERE i.batch = ".$batchId; $this->_db->setQuery($sql); return $this->_db->loadObject(); } }// class