settings = new vxcModelSettings(); $this->SetPrintHeader(TRUE); $this->SetPrintFooter(FALSE); } public function Header() { $margins = $this->getMargins(); // Title $this->SetY(5); $currentDate = new JDate(); $currentDate->setOffset(date('Z')/3600.0); $header =JText::_('Date'). ": " . $currentDate->toFormat("%d/%m/%y %H:%M"); $this->SetFont('helvetica', 'B', 8); $this->SetX(10); $this->Cell(0, 0,$header, 0, 0, 'L'); $this->Ln(); $margins = $this->getMargins(); $this->Line(10,$this->getY(),$this->getPageWidth()-10,$this->getY(),array('width'=>0.3)); } // Page footer public function Footer() { /* // Position at 2.5 cm from bottom $this->SetY(-$this->margin_bottom); $margins = $this->getMargins(); $this->Line($margins['left'],$this->getY(),$this->getPageWidth()-$margins['right'],$this->getY(),array('width'=>0.3)); */ /* $this->SetFont('helvetica','',8); $text = "
"."hola"."
"; $this->Cell(0, 0, implode(' ',$arrayInfo2), 0, 0, 'C'); }*/ } public function generateLabels(&$batches) { $modelSettings = $this->settings; $franchiseName = SiteOptionsHelper::getFranchiseName(); $this->SetMargins(0,0,0); $this->SetHeaderMargin(0); $this->SetFooterMargin(0); $this->SetAutoPageBreak(FALSE); $labelWidth = 97; $labelHeight = 66; $numLabelsPerPage = 8; $sepX = 4.5; $correccionACaponX = 0; $correccionACaponY = 3; $initialOffsetX = (210 - $labelWidth*2 - $sepX*1)*0.5 +$correccionACaponX; $sepY = 2; $initialOffsetY = (297 - $labelHeight*4 - $sepY*3)*0.5 + $correccionACaponY; $this->AliasNbPages(); $html = ""; $senderLabel = new stdClass(); $senderLabel->type = "sender"; $senderLabel->name = $modelSettings->getVar('expLabelsPDF.senderName',''); $senderLabel->address = $modelSettings->getVar('expLabelsPDF.senderAddress',''); $senderLabel->city = $modelSettings->getVar('expLabelsPDF.senderCity',''); $senderLabel->province = $modelSettings->getVar('expLabelsPDF.senderProvince',''); $senderLabel->pcode = $modelSettings->getVar('expLabelsPDF.senderPCode',''); $senderLabel->phone = $modelSettings->getVar('expLabelsPDF.senderPhone',''); $senderLabel->logoPath = $modelSettings->getVar('expLabelsPDF.senderLogoPath',''); // Recorremos los lotes para averiguar cuantas etiquetas de destinatario tenemos que generar $receiverLabels = array(); $oldBatch = -1; if (count($batches)) for ($i=0;$iname = $currentBatch->username; $userAddress->address = $currentBatch->useraddress; $userAddress->city = $currentBatch->usercity ; $userAddress->province = $currentBatch->userprovince; $userAddress->pcode = $currentBatch->userpcode; $userAddress->phone = $currentBatch->userphone; $userAddress->isFullAddress = true; $batchAddress = null; $batchId = $currentBatch->id; $orders = array(); if ($currentBatch->shipping_address) { $batchAddress = new stdclass(); $batchAddress->name = $currentBatch->shipping_address_company; $batchAddress->address = $currentBatch->shipping_address_address; $batchAddress->city = $currentBatch->shipping_address_city; $batchAddress->province = $currentBatch->shipping_address_province; $batchAddress->pcode = $currentBatch->shipping_address_pcode; $batchAddress->phone= $currentBatch->shipping_address_phone; $batchAddress->delivery_schedule = $currentBatch->shipping_address_delivery_schedule; $batchAddress->isFullAddress = true; while($batches[$i]->id == $batchId) { $row =&$batches[$i]; $orders[] = $row->orderid; $i++; } $label = new stdclass(); $label->type = "receiver"; $label->address = $batchAddress; $label->orders = $orders; $label->batch = $batchId; $receiverLabels[] = $label; } else { // Recorremos todos los pedidos del batch generando while($batches[$i]->id == $batchId) { $row =&$batches[$i]; if ($row->specific_address) { $addressInfo =new stdclass(); $addressInfo->address = $row->specific_address; $addressInfo->isFullAddress = false; $label = new stdclass(); $label->type = "receiver"; $label->address = $addressInfo; $label->orders = array($row->orderid); $label->batch = $batchId; $receiverLabels[] = $label; } else { $hasUserAddress = true; $orders[] = $row->orderid; } $i++; } if ($hasUserAddress) { $label = new stdclass(); $label->type = "receiver"; $label->address = $userAddress; $label->orders = $orders; $label->batch = $batchId; $receiverLabels[] = $label; } } } $labels = array(); if (count($receiverLabels)) foreach ($receiverLabels as $label) { $labels[] = $senderLabel; $labels[] = $label; } $i=$numLabelsPerPage; foreach($labels as $label) { if ($i==8) { $this->AddPage(); $offsetX = $initialOffsetX; $offsetY = $initialOffsetY; $i=0; } if ($label->type == 'sender') { $cellOffsetX = $offsetX; $cellOffsetY = $offsetY; $this->SetFont('helvetica','',14); $logoHeight = 28; $imagePaddingY = 1; $colWidth = $labelWidth; if ($label->logoPath) { $rowHeight = $logoHeight+$imagePaddingY; $this->Image(JPATH_BASE. $label->logoPath,$cellOffsetX,$cellOffsetY+$imagePaddingY,$colWidth,$rowHeight,'','','N',false,96,'',false,false,'','CT'); $cellOffsetY += $rowHeight; } else $rowHeight = 0; $rowHeight = $labelHeight - $rowHeight; $texto = JText::_('REMITENTE'). ': '. $label->name . "\n". JText::_('DIRECCIÓN'). ': '.$label->address . "\n". JText::_('LOCALIDAD'). ': '.$label->city . "\n". JText::_('CP'). ': '.$label->pcode . " (". $label->province.")". "\n". JText::_('TELÉFONO'). ': '.$label->phone ; $this->MultiCell($colWidth,$rowHeight,$texto,0,'L',false,1,$cellOffsetX,$cellOffsetY,true,1,false,true,$rowHeight,'T',false); } else { $cellOffsetX = $offsetX; $cellOffsetY = $offsetY; if ($label->address->isFullAddress) { $texto = JText::_('DESTINATARIO'). ': '. $label->address->name . "\n". JText::_('DIRECCIÓN'). ': '.$label->address->address . "\n". JText::_('LOCALIDAD'). ': '.$label->address->city . "\n". JText::_('CP'). ': '.$label->address->pcode; if ($label->address->province) $texto.=" (". $label->address->province.")"; $texto .= "\n". JText::_('TELÉFONO'). ': '.$label->address->phone . "\n"; if ($label->address->delivery_schedule) $texto .= JText::_('Delivery schedule'). ': '.$label->address->delivery_schedule . "\n"; } else { $texto =JText::_('DESTINATARIO'). ': '."\n".$label->address->address . "\n"; } $texto .= JText::_('REFS') .': '. $label->batch .' ('.implode(', ',$label->orders). ')'; $colWidth = $labelWidth; $rowHeight = $labelHeight; $this->MultiCell($colWidth,$rowHeight,$texto,0,'L',false,1,$cellOffsetX,$cellOffsetY,true,1,false,true,$rowHeight,'T',false); } // Reborde //$this->pdf->MultiCell($labelWidth,$labelHeight,'',1,'C',false,0,$offsetX,$offsetY,true,0,false,true,$labelHeight,'M',FALSE); if ($i%2==1) { $offsetX = $initialOffsetX; $offsetY+=$labelHeight+$sepY; } else $offsetX+=$labelWidth+$sepX; $i++; } } public function generateListing(&$batches,$today_date) { $pdf =& $this; $margin_top= $this->settings->getVar("expListPDF.margin_top",15); $margin_bottom=$this->settings->getVar("expListPDF.margin_bottom",12.5); $margin_left=$this->settings->getVar("expListPDF.margin_left",10); $margin_right=$this->settings->getVar("expListPDF.margin_right",5); $pdf->SetAutoPageBreak(TRUE, $margin_bottom); $pdf->SetPrintHeader(TRUE); $pdf->SetPrintFooter(TRUE); $pdf->SetMargins($margin_left, $margin_top, $margin_right); $pdf->AddPage(); $fontSize = $this->settings->getVar('expListPDF.fontSize',14); $pdf->SetFont('helvetica','',$fontSize); $batchIdBackColor = $this->settings->getVar('expListPDF.batchIdBackColor','150, 150, 150'); // Color de fondo de los lotes con fecha de expedición pasada $batchLateBackground = $this->settings->getVar('expListPDF.batchLateBackground','100,100,100'); // Color de fondo de los lotes con fecha de expedición igual a hoy $batchTodayBackground = $this->settings->getVar('expListPDF.batchTodayBackground','150,150,150'); // Color de fondo de los lotes que no entren en ninguna de las dos categorias anteriores $batchNormalBackground = $this->settings->getVar('expListPDF.batchNormalBackground','255,255,255'); $todayBatches = array(); $oldBatches = array(); $normalBatches = array(); foreach($batches as $batch) { $type = 'normal'; if ($batch->est_shipping_date) { $date = new JDate($batch->est_shipping_date); // Calculo el dia estimado de entrega siguiente al dia de hoy $dateNow = new JDate($today_date); // Pasamos las fechas a segundos $timeStampNow = $dateNow->toUnix(); $restSecs = $timeStampNow % 86400; if ($restSecs>0) { $timeStampNow -= $restSecs; // $timeStampNow -= 86400; } $timeStampDate = $date->toUnix(); $restSecs = $timeStampDate % 86400; if ($restSecs>0) { $timeStampDate -= $restSecs; } $difSecs = $timeStampDate-$timeStampNow; $days = $difSecs/86400.0; if ($days ==0) { $type = 'today'; } else if ($days<0) { $type = 'old'; } } $batch->type = $type; switch($type) { case 'today': $todayBatches[] = $batch; break; case 'old': $oldBatches[] = $batch; break; default: $normalBatches[] = $batch; } } $batches = array(); foreach($oldBatches as $batch) $batches[] = $batch; foreach($todayBatches as $batch) $batches[] = $batch; foreach($normalBatches as $batch) $batches[] = $batch; foreach($batches as $batch) { $html ='
'; switch($batch->type) { case 'today': $backGroundColor =$batchTodayBackground; break; case 'old': $backGroundColor =$batchLateBackground; break; default: $backGroundColor = $batchNormalBackground; } if ($batch->est_shipping_date) { $date = new JDate($batch->est_shipping_date); $date->setOffset(date('Z')/3600.0); $dateS = $date->toFormat('%d/%m/%Y'); } else $dateS = ''; $agencytext = ''; if ($batch->agencyname) { $agencytext =JText::_($batch->agencyname); if ($batch->payment_methodnameid == 'CASHONDELIVERY') { $totalPrice = ManuReportHelper::calculateCashOnDelivery($batch); $agencytext .= " R: ". sprintf("%0.2f",$totalPrice). " €"; } } if ($batch->forwarded) $agencytext .= " ". JText::_('ADELANTO'); //NumberToLetterHelper::GetLetterFromId($id) ///'', $patientArray = explode('#',$batch->patient_list); $orderArray = explode('#',$batch->order_list); $matArray = $batch->mat_list; $orderIdBackColor = $this->settings->getVar('expListPDF.orderIdBackColor','150,150,150'); $orderString=''; for ($k=0;$k" . $orderArray[$k] .NumberToLetterHelper::GetLetterFromId($orderArray[$k])." (".$patientArray[$k].")"; $allEqual = true; $equalMat = ''; if (count($matArray[$k])>0) { $equalMat = $matArray[$k][0]; foreach($matArray[$k] as $mat) { if (!$equalMat) $equalMat = $mat; if ($mat != $equalMat) { $allEqual = false; break; } } if ($allEqual) $orderString .= " (". $matArray[$k][0].")"; else $orderString .= " (". implode(',',$matArray[$k]). ")"; } } $html .= ""; $html .= ''; $html.= '
".$batch->username . ' ('.$batch->user.'), ' . $dateS.", L: ".$batch->id." $agencytext
' . JText::_('Orders') . ': '. $orderString .'
'; // output the HTML content $margins = $pdf->getMargins(); $lastY = $pdf->getPageHeight() - $margins['bottom']; $reservedSpaceForLastBatch = $this->settings->getVar('expListPDF.reservedSpaceForLastBatch',40); if ($pdf->getY() + $reservedSpaceForLastBatch > $lastY) $pdf->AddPage(); $pdf->writeHTML($html, true, false, true, false, ''); } } } ?>