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)); } // Page footer public function Footer() { // Position at 1.5 cm from bottom $franchiseName = SiteOptionsHelper::getFranchiseName(); $this->SetY(-25); $margins = $this->getMargins(); $this->Line($margins['left'],$this->getY(),$this->getPageWidth()-$margins['right'],$this->getY(),array('width'=>0.3)); $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'); $this->Cell(0, 0, implode(' ',$arrayInfo), 0, 1, 'C'); $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, 1, 'C'); if ($franchiseName=='tecnoinsole' && $this->_invoice->enduserheaderinfo) { $this->Cell(0, 0,$this->_invoice->enduserheaderinfo, 0, 0, 'L'); } } } class vxcModelCustomerInvoice extends JModel { var $_id = 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()); }//function function SetId($id) { $this->_id = (int)$id; $this->_item = null; } function store(&$data) { $table =& $this->getTable('customerinvoice'); $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 getData() { if (empty($this->_item)) { $db =& $this->_db; $newModeFields = ''; $newJoins = ''; $oldModeFields =''; if (LegacyHelper::getNewMode()) { $newModeFields = "o.uuid uuid, 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 = "CONCAT_WS(' ',NULLIF(c.name,''),NULLIF(c.middlename,''),NULLIF(c.surname,'')) customerfullname,"; } $sql = "SELECT i.id id, i.orderid orderid, i.reference reference, i.generation_date generation_date, i.taxes taxes, $oldModeFields i.paid paid, $newModeFields i.returned returned, i.comments comments, i.price price, i.vat vat, i.total total, b.payment_user payment_user, 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, o.creationdate ordercreationdate, o.reference orderreference, c.name customername, c.surname customersurname, c.middlename customermiddlename, 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, c.dni customerdni FROM #__vxc_customerinvoice i LEFT JOIN #__vxc_order o ON o.id = i.orderid LEFT JOIN #__vxc_customer c ON o.customer = c.id LEFT JOIN #__vxc_batch b ON b.id = o.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 LEFT JOIN #__vxc_title t ON t.id = c.title $newJoins WHERE i.id = ".$this->_id; $db->setQuery($sql); $row = $db->loadObject(); if (!$row) { $row = new stdClass(); $row->id = 0; } $this->_item = $row; } return $this->_item; } function getNextInvoiceReference(&$date,$userId) { $sql = "SELECT uf.franchise FROM #__vxc_userfranchise uf WHERE uf.userid = $userId "; $this->_db->setQuery($sql); $franchiseId = $this->_db->loadResult(); if (!$franchiseId) return ''; $sql = "SELECT MAX(i.id) FROM #__vxc_customerinvoice i LEFT JOIN #__vxc_order o ON o.id = i.orderid LEFT JOIN #__vxc_batch b ON b.id = o.batch LEFT JOIN #__vxc_paymentmethod pm ON pm.id = b.payment_method LEFT JOIN #__vxc_userfranchise uf ON uf.userid = b.payment_user WHERE uf.franchise = $franchiseId AND pm.nameid <> 'BUDGET'"; $this->_db->setQuery($sql); $lastId = $this->_db->loadResult(); if (!$lastId) return ''; $sql = "SELECT i1.reference reference FROM #__vxc_customerinvoice i1 LEFT JOIN #__vxc_userfranchise uf1 ON uf1.userid = ".$userId. " WHERE i1.id = $lastId"; $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("TII%s%05d",$currentYear,$counter); return $reference; } function getNextBudgetReference(&$date,$userId) { $sql = "SELECT i1.reference reference FROM #__vxc_customerinvoice i1 LEFT JOIN #__vxc_userfranchise uf1 ON uf1.userid = ".$userId. " WHERE i1.id =(SELECT MAX(i.id) FROM #__vxc_customerinvoice i LEFT JOIN #__vxc_order o ON o.id = i.orderid LEFT JOIN #__vxc_batch b ON b.id = o.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("TIP%s%05d",$currentYear,$counter); return $reference; } function printPDF(&$pdf,$addToPdf=false) { $invoice =& $this->getData(); $lang = &JFactory::getLanguage(); $font = $lang->getPdfFontName(); $font = ($font) ? $font : 'freesans'; $franchiseName = SiteOptionsHelper::getFranchiseName(); if (!$addToPdf) $pdf = new CustomerInvoicePDF('P', 'mm', 'A4', true, 'UTF-8', false); $pdf->_invoice =& $invoice; $pdf->SetMargins($this->_margin_left, $this->_margin_top, $this->_margin_right); $pdf->SetAutoPageBreak(TRUE, $this->_margin_bottom); $pdf->setPrintHeader(true); $pdf->setPrintFooter(true); $pdf->SetHeaderMargin($this->_margin_header); $pdf->setRTL($lang->isRTL()); $pdf->setHeaderFont(array($font, '', 10)); $pdf->setFooterFont(array($font, '', 8)); $pdf->AliasNbPages(); $pdf->AddPage(); if ($franchiseName!='tecnoinsole') { $pdf->SetFont('helvetica','',8); $pdf->writeHTML($invoice->enduserheaderinfo,false); } $logoName = $invoice->franchisecustomerlogo; if (!$logoName) $logoName = $invoice->franchiselogo; if ($logoName) { $src = $_SERVER['DOCUMENT_ROOT'] . $logoName; $imagex = $pdf->getX(); $imagey = 15; $pdf->Image($src,$imagex,$imagey,0,20,'','','',false,72,'L'); } $pdf->SetFont('helvetica','',12); $pdf->Ln(13); $margins = $pdf->getMargins(); $pdf->Line($margins['left'],$pdf->getY(),$pdf->getPageWidth()-$margins['right'],$pdf->getY(),array('width'=>0.3)); $pdf->Ln(3); $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'); // Datos del cliente $pdf->Ln(); $pdf->SetFont('helvetica','bu',14); $pdf->Cell(0,0,JText::_('Client'),0,0); $pdf->Ln(); $pdf->SetFont('helvetica','',10); $arrayCols = array('L','R'); $nameArray = array(); if ($invoice->customertitlename) $nameArray[] = JText::_($invoice->customertitlename); if ($invoice->customerfullname) $nameArray[] = $invoice->customerfullname; $arrayCols['L'][] = implode(' ',$nameArray); if ($invoice->customerdni) $arrayCols['L'][] = $invoice->customerdni; if ($invoice->customeraddress) $arrayCols['L'][] = $invoice->customeraddress; $aux = array(); if ($invoice->customerpcode) $aux[] = strtoupper($invoice->customerpcode); if ($invoice->customercity) $aux[] = strtoupper($invoice->customercity); $customermoreaddress = implode(' ',$aux); if ($customermoreaddress) $arrayCols['L'][] = $customermoreaddress; if ($invoice->customercountry) $arrayCols['L'][] = strtoupper($invoice->customercountry); $aux = array(); if ($invoice->customertelephone) $aux[] = $invoice->customertelephone; if ($invoice->customermobile) $aux[] = $invoice->customermobile; if ($invoice->customerfax) $aux[] = $invoice->customerfax; if ($invoice->customeremail) $arrayCols['L'][] = $invoice->customeremail; if ($invoice->customerbirthdate) { $date = new JDate($invoice->customerbirthdate); $customermoreinfo = $date->toFormat("%d/%m/%Y"); $arrayCols['L'][] = $customermoreinfo; } 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(); $col1W = 95; $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'); $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; $concept = ''; $concept2 = ''; $concept3 = ''; if ($invoice->orderid) { $concept =JText::_('ORDER_DESCRIPTION'); $date = new JDate($invoice->ordercreationdate); $date->setOffset(date('Z')/3600.0); $dateS = $date->toFormat('%d/%m/%Y'); $concept2 = JText::_('Order')." ". $invoice->orderid ." (". $dateS.")"; $nameArray = array(); if ($invoice->customertitlename) $nameArray[] = JText::_($invoice->customertitlename); if ($invoice->customername) { $firstNameArray = explode(' ',$invoice->customername); for ($i=0;$icustomermiddlename) $nameArray[] = $invoice->customermiddlename; if ($invoice->customersurname) $nameArray[] = $invoice->customersurname; $customerName = implode(' ',$nameArray); if ($customerName) $concept3 .= $customerName; if ($invoice->orderreference) { if ($concept3) $concept3 .= " / "; $concept3 .= $invoice->orderreference; } } else if ($invoice->concept) $concept = $invoice->concept; else $concept = ""; $amount = $invoice->amount; if ($amount===null) $amount = 1; $price = sprintf("%0.02f",$invoice->price). " €"; $endUserSubtotal += $amount*$invoice->price; $discount = sprintf("%0.02f",$invoice->discount). " %"; $vat = sprintf("%0.02f",$invoice->vat). " %"; $total = sprintf("%0.02f",$invoice->total). " €"; $endUserTotal += $invoice->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'); $pdf->Cell($col6W,0,$total,$border,0,'R'); $anchuraConceptos = $col1W + $col2W + $col3W + $col4W + $col6W; $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(); } $colAncha =$col1W + $col2W + $col3W +$col4W; $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); $pdf->Cell($col5W,0,sprintf("%0.02f",$endUserSubtotal). " €",'',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",$endUserTotal - $endUserSubtotal ). " €",'',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",$endUserTotal). " €",'',0,'R'); $pdf->Ln(); if ($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 getInvoiceByOrderId($orderId) { $sql = "SELECT i.id id FROM #__vxc_customerinvoice i WHERE i.orderid = ".$orderId; $this->_db->setQuery($sql); return $this->_db->loadObject(); } }// class