Beispiel #1
0
 public function generarPDFQR($data = array(), $accion = array('F'), $update = false)
 {
     if (count($data) > 0) {
         $ci =& get_instance();
         $ci->load->library('mypdf');
         // Creacion del objeto de la clase heredada
         $pdf = new MYpdf('P', 'mm', 'Letter');
         $pdf->show_head = false;
         $pdf->AddPage();
         $pdf->SetFont('Arial', '', 8);
         $y = 40;
         if ($data['info_empresa']->logo != '') {
             $pdf->Image($data['info_empresa']->logo, 8, 12, 35);
         }
         $pdf->SetFont('Arial', 'B', 15);
         $pdf->SetXY(38, $y - 30);
         $pdf->Cell(170, 6, $data['info_empresa']->nombre_fiscal, 0, 0, 'C');
         $dir1 = $data['info_empresa']->calle != '' ? $data['info_empresa']->calle : '';
         $dir1 .= $data['info_empresa']->no_exterior != '' ? ' ' . $data['info_empresa']->no_exterior : '';
         $dir1 .= $data['info_empresa']->no_interior != '' ? '-' . $data['info_empresa']->no_interior : '';
         $dir1 .= $data['info_empresa']->colonia != '' ? ', ' . $data['info_empresa']->colonia : '';
         $dir2 = $data['info_empresa']->municipio != '' ? $data['info_empresa']->municipio : '';
         $dir2 .= $data['info_empresa']->estado != '' ? ', ' . $data['info_empresa']->estado : '';
         $dir2 .= $data['info_empresa']->cp != '' ? ', CP: ' . $data['info_empresa']->cp : '';
         $pdf->SetFont('Arial', '', 11);
         $pdf->SetXY(38, $y - 23);
         $pdf->MultiCell(170, 6, "R.F.C." . $data['info_empresa']->rfc . " \n " . $dir1 . " \n " . $dir2 . " \n " . $data['info_empresa']->regimen_fiscal . " ", 0, 'C', 0);
         $pdf->SetDrawColor(140, 140, 140);
         $pdf->SetFont('Arial', '', 9);
         $pdf->SetXY(8, $y);
         $pdf->SetTextColor(255, 0, 0);
         $pdf->Cell(170, 6, ($data['info_empresa']->telefono != '' ? "Tel. " . $data['info_empresa']->telefono : '') . ($data['info_empresa']->email != '' ? " | Email. " . $data['info_empresa']->email : '') . ($data['info_empresa']->pag_web != '' ? " | " . $data['info_empresa']->pag_web : ''), 0, 0, 'L');
         $pdf->SetTextColor(0, 0, 0);
         // ----------- FOLIO ------------------
         $pdf->SetFont('Arial', '', 13);
         $pdf->SetXY(164, $y);
         $pdf->Cell(38, 7, substr($data['fecha'], 0, 10) < '2012-10-31' ? 'Recibo de honorarios' : 'Factura', 0, 0, 'C');
         $pdf->SetXY(158, $y + 7);
         $pdf->Cell(50, 13, '', 1, 0, 'C');
         $pdf->SetFont('Arial', 'B', 11);
         $pdf->SetTextColor(255, 255, 255);
         $pdf->SetFillColor(140, 140, 140);
         $pdf->SetXY(158, $y + 7);
         $pdf->Cell(50, 5, 'Serie y Folio', 1, 0, 'C', 1);
         $pdf->SetFont('Arial', '', 12);
         $pdf->SetTextColor(255, 0, 0);
         $pdf->SetFillColor(255, 255, 255);
         $pdf->SetXY(158, $y + 12);
         $pdf->Cell(50, 8, ($data['serie'] != '' ? $data['serie'] . '-' : '') . $data['folio'], 0, 0, 'C');
         // ----------- FECHA ------------------
         $pdf->SetXY(158, $y + 21);
         $pdf->Cell(50, 13, '', 1, 0, 'C');
         $pdf->SetFont('Arial', 'B', 11);
         $pdf->SetTextColor(255, 255, 255);
         $pdf->SetFillColor(140, 140, 140);
         $pdf->SetXY(158, $y + 21);
         $pdf->Cell(50, 5, 'Fecha de Expedición', 1, 0, 'C', 1);
         $pdf->SetFont('Arial', '', 12);
         $pdf->SetTextColor(0, 0, 0);
         $pdf->SetFillColor(255, 255, 255);
         $pdf->SetXY(158, $y + 26);
         $pdf->Cell(50, 8, substr($data['fecha'], 0, 10), 1, 0, 'C', 1);
         // ----------- No y Año aprob ------------------
         $pdf->SetXY(158, $y + 35);
         $pdf->Cell(50, 13, '', 1, 0, 'C');
         $pdf->SetFont('Arial', 'B', 11);
         $pdf->SetTextColor(255, 255, 255);
         $pdf->SetFillColor(140, 140, 140);
         $pdf->SetXY(158, $y + 35);
         $pdf->Cell(50, 5, 'No. y Año aprobracion', 1, 0, 'C', 1);
         $pdf->SetFont('Arial', '', 12);
         $pdf->SetTextColor(0, 0, 0);
         $pdf->SetFillColor(255, 255, 255);
         $pdf->SetXY(158, $y + 40);
         $pdf->Cell(50, 8, $data['no_aprobacion'] . '-' . substr($data['ano_aprobacion'], 0, 4), 1, 0, 'C', 1);
         // ----------- No Certificado ------------------
         // $pdf->SetXY(158, ($y+20));
         // $pdf->Cell(50, 13, '' , 1, 0, 'C');
         // $pdf->SetFont('Arial','B',11);
         // $pdf->SetTextColor(255,255,255);
         // $pdf->SetFillColor(140,140,140);
         // $pdf->SetXY(158, ($y+20));
         // $pdf->Cell(50, 5, 'No. Certificado' , 1, 0, 'C',1);
         // $pdf->SetFont('Arial','',12);
         // $pdf->SetTextColor(255,0,0);
         // $pdf->SetFillColor(255,255,255);
         // $pdf->SetXY(158, ($y+25));
         // $pdf->Cell(50, 8, $data['no_certificado'] , 1, 0, 'C',1);
         // ----------- DATOS CLIENTE ------------------
         $pdf->SetXY(8, $y + 7);
         $pdf->Cell(149, 41, '', 1, 0, 'C');
         $pdf->SetFont('Arial', 'B', 9);
         $pdf->SetTextColor(255, 255, 255);
         $pdf->SetFillColor(140, 140, 140);
         $pdf->SetXY(8, $y + 7);
         // BLOQUE DATOS 1
         $pdf->Cell(16, 41, '', 0, 0, 'C', 1);
         $pdf->SetXY(8, $y + 9);
         $pdf->Cell(16, 6, 'R.F.C.', 0, 0, 'L');
         $pdf->SetXY(8, $y + 15);
         $pdf->Cell(16, 6, 'NOMBRE', 0, 0, 'L');
         $pdf->SetXY(8, $y + 21);
         $pdf->Cell(16, 6, 'CALLE', 0, 0, 'L');
         $pdf->SetXY(8, $y + 27);
         $pdf->Cell(16, 6, 'NUMERO', 0, 0, 'L');
         $pdf->SetXY(8, $y + 33);
         $pdf->Cell(16, 6, 'COLONIA', 0, 0, 'L');
         $pdf->SetXY(8, $y + 39);
         $pdf->Cell(16, 6, 'EDO', 0, 0, 'L');
         $pdf->SetXY(70, $y + 27);
         // BLOQUE DATOS 2
         $pdf->Cell(18, 21, '', 0, 0, 'C', 1);
         $pdf->SetXY(70, $y + 27);
         $pdf->Cell(18, 6, 'INT', 0, 0, 'L');
         $pdf->SetXY(70, $y + 33);
         $pdf->Cell(18, 6, 'MUNICIPIO', 0, 0, 'L');
         $pdf->SetXY(70, $y + 39);
         $pdf->Cell(18, 6, 'PAIS', 0, 0, 'L');
         $pdf->SetXY(117, $y + 27);
         // BLOQUE DATOS 3
         $pdf->Cell(16, 14, '', 0, 0, 'C', 1);
         $pdf->SetXY(117, $y + 27);
         $pdf->Cell(18, 6, 'C.P.', 0, 0, 'L');
         $pdf->SetXY(117, $y + 33);
         $pdf->Cell(18, 6, 'CIUDAD', 0, 0, 'L');
         $pdf->SetFont('Arial', '', 7);
         $pdf->SetTextColor(0, 0, 0);
         $pdf->SetXY(25, $y + 9);
         // BLOQUE DATOS 1 INFO
         $pdf->Cell(132, 6, strtoupper($data['crfc']), 0, 0, 'L');
         $pdf->SetXY(25, $y + 15);
         $pdf->Cell(132, 6, strtoupper($data['cnombre']), 0, 0, 'L');
         $pdf->SetXY(25, $y + 21);
         $pdf->Cell(132, 6, strtoupper($data['ccalle']), 0, 0, 'L');
         $pdf->SetXY(25, $y + 27);
         $pdf->Cell(44, 6, strtoupper($data['cno_exterior']), 0, 0, 'L');
         $pdf->SetXY(25, $y + 33);
         $pdf->Cell(44, 6, strtoupper($data['ccolonia']), 0, 0, 'L');
         $pdf->SetXY(25, $y + 39);
         $pdf->Cell(44, 6, strtoupper($data['cestado']), 0, 0, 'L');
         $pdf->SetXY(88, $y + 27);
         // BLOQUE DATOS 2 INFO
         $pdf->Cell(28, 6, strtoupper($data['cno_interior']), 0, 0, 'L');
         $pdf->SetXY(88, $y + 33);
         $pdf->Cell(28, 6, strtoupper($data['cmunicipio']), 0, 0, 'L');
         $pdf->SetXY(88, $y + 39);
         $pdf->Cell(28, 6, strtoupper($data['cpais']), 0, 0, 'L');
         $pdf->SetXY(133, $y + 27);
         // BLOQUE DATOS 3 INFO
         $pdf->Cell(24, 6, strtoupper($data['ccp']), 0, 0, 'L');
         $pdf->SetXY(133, $y + 33);
         $pdf->Cell(24, 6, strtoupper($data['cmunicipio']), 0, 0, 'L');
         // ----------- TABLA CON LOS PRODUCTOS ------------------
         $pdf->SetY($y + 50);
         $aligns = array('C', 'C', 'C', 'C');
         $widths = array(25, 109, 33, 33);
         $header = array('CANTIDAD', 'DESCRIPCION', 'PRECIO UNIT.', 'IMPORTE');
         foreach ($data['productos'] as $key => $item) {
             $band_head = false;
             if ($pdf->GetY() >= 200 || $key == 0) {
                 //salta de pagina si exede el max
                 if ($key > 0) {
                     $pdf->AddPage();
                 }
                 $pdf->SetFont('Arial', 'B', 8);
                 $pdf->SetTextColor(255, 255, 255);
                 $pdf->SetFillColor(140, 140, 140);
                 $pdf->SetX(8);
                 $pdf->SetAligns($aligns);
                 $pdf->SetWidths($widths);
                 $pdf->Row($header, true);
             }
             $pdf->SetFont('Arial', '', 10);
             $pdf->SetTextColor(0, 0, 0);
             $datos = array($item['cantidad'], $item['descripcion'], String::formatoNumero($item['precio_unit']), String::formatoNumero($item['importe']));
             $pdf->SetX(8);
             $pdf->SetAligns($aligns);
             $pdf->SetWidths($widths);
             $pdf->Row($datos, false);
         }
         //------------ SUBTOTAL, IVA ,TOTAL --------------------
         $y = $pdf->GetY();
         $pdf->SetFont('Arial', 'B', 10);
         $pdf->SetTextColor(255, 255, 255);
         $pdf->SetFillColor(140, 140, 140);
         $pdf->SetXY(144, $y + 5);
         $pdf->Cell(31, 6, 'Subtotal', 1, 0, 'C', 1);
         $pdf->SetXY(144, $y + 11);
         $pdf->Cell(31, 6, 'IVA', 1, 0, 'C', 1);
         $pdf->SetXY(144, $y + 17);
         if (isset($data['total_isr'])) {
             $pdf->Cell(31, 6, 'Retencion ISR', 1, 0, 'C', 1);
             $pdf->SetXY(144, $y + 23);
         }
         $pdf->Cell(31, 6, 'Total', 1, 0, 'C', 1);
         $pdf->SetTextColor(0, 0, 0);
         $pdf->SetFillColor(255, 255, 255);
         $pdf->SetXY(175, $y + 5);
         $pdf->Cell(33, 6, String::formatoNumero($data['subtotal'], 2), 1, 0, 'C');
         $pdf->SetXY(175, $y + 11);
         $pdf->Cell(33, 6, String::formatoNumero($data['importe_iva'], 2), 1, 0, 'C');
         $pdf->SetXY(175, $y + 17);
         if (isset($data['total_isr'])) {
             $pdf->Cell(33, 6, isset($data['total_isr']) ? String::formatoNumero($data['total_isr'], 2) : '$0.00', 1, 0, 'C');
             $pdf->SetXY(175, $y + 23);
         }
         $pdf->Cell(33, 6, String::formatoNumero($data['total'], 2), 1, 0, 'C');
         //------------ TOTAL CON LETRA--------------------
         $pdf->SetXY(8, $y + 5);
         $pdf->Cell(134, 24, '', 1, 0, 'C');
         $pdf->SetFont('Arial', 'B', 10);
         $pdf->SetTextColor(255, 255, 255);
         $pdf->SetFillColor(140, 140, 140);
         $pdf->SetXY(8, $y + 5);
         $pdf->Cell(134, 6, '	IMPORTE CON LETRA', 0, 0, 'L', 1);
         $pdf->SetFont('Arial', '', 8);
         $pdf->SetTextColor(0, 0, 0);
         $pdf->SetXY(9, $y + 12);
         $pdf->MultiCell(130, 6, $data['total_letra'], 0, 'L');
         $pdf->SetXY(9, $y + 24);
         $pdf->Cell(130, 6, "Método de Pago: {$data['metodo_pago']}" . ($data['metodo_pago'] == 'efectivo' ? '' : " | No. Cuenta: {$data['no_cuenta_pago']}"), 0, 0, 'L', 0);
         //------------ CADENA ORIGINAL --------------------
         $y += 32;
         $pdf->SetY($y);
         $pdf->SetX(8);
         $pdf->SetFont('Arial', '', 9);
         $pdf->Image($data['img_cbb'], 8, $y, 40);
         $pdf->SetX(58);
         // $pdf->SetFont('Arial','B',10);
         // $pdf->SetTextColor(255,255,255);
         // $pdf->SetFillColor(140,140,140);
         $pdf->SetAligns(array('L'));
         $pdf->SetWidths(array(150));
         $pdf->Row(array($data['leyenda1']), false, false);
         $pdf->SetX(58);
         // $pdf->SetFont('Arial','',9);
         // $pdf->SetTextColor(0,0,0);
         // $pdf->SetFillColor(255,255,255);
         $pdf->SetAligns(array('L'));
         $pdf->SetWidths(array(150));
         $pdf->Row(array($data['leyenda2'] . ' ' . substr($data['fecha'], 0, 10)), false, false);
         $pdf->SetX(58);
         $pdf->Row(array("No. SICOFI " . $data['no_aprobacion']), false, false);
         //------------ SELLO DIGITAL --------------------
         // $y = $pdf->GetY();
         // $pdf->SetY($y+3);
         // $pdf->SetX(8);
         // $pdf->SetFont('Arial','B',10);
         // $pdf->SetTextColor(255,255,255);
         // $pdf->SetFillColor(140,140,140);
         // $pdf->SetAligns(array('L'));
         // $pdf->SetWidths(array(200));
         // $pdf->Row(array('SELLO DIGITAL'), true);
         // $pdf->SetX(8);
         // $pdf->SetFont('Arial','',9);
         // $pdf->SetTextColor(0,0,0);
         // $pdf->SetFillColor(255,255,255);
         // $pdf->SetAligns(array('L'));
         // $pdf->SetWidths(array(200));
         // $pdf->Row(array($data['sello']), false);
         if ($data['fobservaciones'] != '') {
             $y = $pdf->GetY();
             $pdf->SetY($y + 3);
             $pdf->SetX(8);
             $pdf->SetFont('Arial', 'B', 10);
             $pdf->SetTextColor(255, 255, 255);
             $pdf->SetFillColor(140, 140, 140);
             $pdf->SetAligns(array('L'));
             $pdf->SetWidths(array(200));
             $pdf->Row(array('OBSERVACIONES'), true);
             $pdf->SetX(8);
             $pdf->SetFont('Arial', '', 9);
             $pdf->SetTextColor(0, 0, 0);
             $pdf->SetFillColor(255, 255, 255);
             $pdf->SetAligns(array('L'));
             $pdf->SetWidths(array(200));
             $pdf->Row(array($data['fobservaciones']), false);
         }
         // $y = $pdf->GetY();
         // $pdf->SetFont('Arial','',8);
         // $pdf->SetXY(8, $y+2);
         // $pdf->Cell(200,5,'ESTE DOCUMENTO ES UNA IMPRESIÓN DE UN COMPROBANTE FISCAL DIGITAL',0,0,'C');
         //------------ IMAGEN CANDELADO --------------------
         if (isset($data['status'])) {
             if ($data['status'] == 'ca') {
                 $pdf->Image(APPPATH . '/images/cancelado.png', 20, 40, 190, 190, "PNG");
             }
         }
         //-----------------------------------------------------------------------------------
         if (!$update) {
             $dir_anio = $this->validaDir('anio', 'facturasPDF/');
             $dir_mes = $this->validaDir('mes', 'facturasPDF/' . $dir_anio . '/');
         } else {
             $fecha = $this->obtenFechaMes($data['fecha_xml']);
             $dir_anio = $fecha[0];
             $dir_mes = $this->mesToString($fecha[1]);
         }
         if (count($accion) > 0) {
             foreach ($accion as $a) {
                 switch (strtolower($a)) {
                     case 's':
                         // VISUALIZA PDF EN WEB
                         return $pdf->Output($dir_anio . '|' . $dir_mes . '|' . $this->rfc . '-' . $data['serie'] . '-' . $this->acomodarFolio($data['folio']) . '.pdf', 'S');
                         break;
                     case 'f':
                         // GUARDA EN DIRECTORIO facturasPDF
                         $path_guardar = APPPATH . 'media/cfd/facturasPDF/' . $dir_anio . '/' . $dir_mes . '/' . $this->rfc . '-' . $data['serie'] . '-' . $this->acomodarFolio($data['folio']) . '.pdf';
                         $pdf->Output($path_guardar, 'F');
                         break;
                     case 'd':
                         // DESCARGA DIRECTA DEL PDF
                         $pdf->Output($dir_anio . '|' . $dir_mes . '|' . $this->rfc . '-' . $data['serie'] . '-' . $this->acomodarFolio($data['folio']) . '.pdf', 'D');
                         break;
                     default:
                         // VISUALIZA PDF EN WEB
                         $pdf->Output($dir_anio . '|' . $dir_mes . '|' . $this->rfc . '-' . $data['serie'] . '-' . $this->acomodarFolio($data['folio']) . '.pdf', 'I');
                 }
             }
         }
     }
 }