Skip to content

Instantly share code, notes, and snippets.

@cpjeanpaul
Created March 13, 2018 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpjeanpaul/6e2aa4fca77df501ff76e834ca2e2582 to your computer and use it in GitHub Desktop.
Save cpjeanpaul/6e2aa4fca77df501ff76e834ca2e2582 to your computer and use it in GitHub Desktop.
<?php
session_start();
require_once "config.php";
require_once LIB . DIRECTORY_SEPARATOR . "fffff.php";
require_once MOD . DIRECTORY_SEPARATOR . "sag_venta.php";
require_once CPD . DIRECTORY_SEPARATOR . "tcpdf.php";
require_once CPD . DIRECTORY_SEPARATOR . "config/tcpdf_config.php";
require_once LIB . DIRECTORY_SEPARATOR . "numero_a_texto.php";
class MYPDF extends TCPDF {
public function Header() {
$ar = $this->info;
//deb($ar);
$this->Image("../graph/escudoilo.jpg", 12, 12, 20, 19);
$this->SetFont("helvetica", "B", 14);
$this->setXY(35, 14);
$this->Cell( 100 ,4, "MUNICIPALIDAD PROVINCIAL DE ILO", 0, 0, "", false);
$this->SetFont("helvetica", "", 8);
$this->setXY(35, 19);
$this->Cell( 100 ,4, "AV MALECÓN COSTERO MIRAMAR 1200 - 1202 ", 0, 0, "", false);
$this->setXY(35, 22);
$this->Cell( 100 ,4, "ILO - ILO - MOQUEGUA ", 0, 0, "", false);
$this->setXY(35, 25);
$this->Cell( 100 ,4, "CENTRAL TELEFÓNICA: (053) 48 1141 WEB: www.mpi.gob.pe", 0, 0, "", false);
$this->setXY(140, 10);
$this->SetFont("helvetica", "B", 14);
$this->SetFillColor(235, 235, 235);
$this->MultiCell(60, 25, $ar['doc_nombre_ext'], 1, 'C', 1, 0, '', '', true, 0, false, true, 25, 'M');
$this->setXY(140, 11);
$this->SetFont("helvetica", "", 11);
$this->Cell(60 ,4, "RUC: XXXXXXXX", "", 0, "C", false);
$this->setXY(140, 29);
$this->SetFont("helvetica", "", 12);
$this->Cell(60 ,4, $ar['serie_desc'] . "-" . fnCerosIzq($ar['vent_nrodoc'], $ar['docserie_nrodoc_length']), "", 0, "C", false);
$this->SetFont("helvetica", "", 9);
$this->SetFillColor(255, 255, 255);
$this->setXY(10, 38);
$this->MultiCell(128, 24, '', 1, 'C', 1, 0, '', '', true, 0, false, true, 24, 'M');
$this->MultiCell(2, 24, '', 'RL', 'C', 1, 0, '', '', true, 0, false, true, 24, 'M');
$this->MultiCell(60, 24, '', 1, 'C', 1, 0, '', '', true, 0, false, true, 24, 'M');
/*
$ejey = 40; $ejex = 12; $h = 4;
$this->setXY($ejex, $ejey); $ejey += $h;
$this->Cell(20, 4, "SEÑOR(ES)", '', 0, "", false);
$this->Cell(3, 4, ":", "", 0, "", false);
$this->Cell(82, 4, $ar['cli_nombres'], 0, 0, "", false);
$this->setXY($ejex, $ejey); $ejey += $h;
$this->Cell(20, 4, $ar['cli_tipodoc'] == '6' ? "RUC" : "DNI", 0, 0, "", false);
$this->Cell(3, 4, ":", "", 0, "", false);
$this->Cell(82, 4, $ar['cli_nrodoc'], "", 0, "", false);
$this->setXY($ejex, $ejey); $ejey += $h;
$this->Cell(20, 4, "DIRECCIÓN", "", 0, "", false);
$this->Cell(3, 4, ":", "", 0, "", false);
$this->Cell(82, 4, $ar['cli_razon'], "", 0, "", false);
$this->setXY($ejex, $ejey); $ejey += $h;
$this->Cell(20, 4, "E-MAIL", "", 0, "", false);
$this->Cell(3, 4, ":", "", 0, "", false);
$this->Cell(82, 4, "", "", 0, "", false);
$this->setXY($ejex, $ejey); $ejey += $h;
$this->Cell(20, 4, "TELEFONO", "", 0, "", false);
$this->Cell(3, 4, ":", "", 0, "", false);
$this->Cell(82, 4, "", "", 0, "", false);
$ejey = 40; $ejex = 142; $h = 4;
$this->setXY($ejex, $ejey); $ejey += $h;
$this->Cell(35, 4, "FECHA EMISIÓN", '', 0, "", false);
$this->Cell(3, 4, ":", "", 0, "", false);
$this->Cell(92, 4, fnDateDDMMAAAA($ar['vent_fechadoc']), 0, 0, "", false);
$this->setXY($ejex, $ejey); $ejey += $h;
$this->Cell(35, 4, "FECHA VENCIMIENTO", "", 0, "", false);
$this->Cell(3, 4, ":", "", 0, "", false);
$this->Cell(92, 4, fnDateDDMMAAAA($ar['vent_fechaven']), "", 0, "", false);
$this->setXY($ejex, $ejey); $ejey += $h;
$this->Cell(35, 4, "MONEDA", "", 0, "", false);
$this->Cell(3, 4, ":", "", 0, "", false);
$this->Cell(92, 4, $ar['moneda'], "", 0, "", false);
$this->setXY($ejex, $ejey); $ejey += $h;
$this->Cell(35, 4, "RESPONSABLE", "", 0, "", false);
$this->Cell(3, 4, ":", "", 0, "", false);
$this->Cell(92, 4, "", "", 0, "", false);
$this->setXY($ejex, $ejey); $ejey += $h;
$this->Cell(35, 4, "PLACA VEHICULO", "", 0, "", false);
$this->Cell(3, 4, ":", "", 0, "", false);
$this->Cell(92, 4, $ar['placa'], "", 0, "", false);*/
$cn_raz = strlen($ar['cli_nombres']);
$hx = $cn_raz > 48 ? 8 : 4;
$ejey = 40; $ejex = 12; $h = 4;
$this->setXY($ejex, $ejey); $ejey += $hx;
$this->SetFillColor(255, 255, 255);
$this->MultiCell(20, 4, 'SEÑOR(ES)', 0, 'L', 1, 0, '', '', true, 0, false, true, 4, 'M');
$this->MultiCell(5, 4, ':', 0, 'C', 1, 0, '', '', true, 0, false, true, 4, 'M');
$this->MultiCell(100, $hx, $ar['cli_nombres'], 0, 'L', 1, 0, '', '', true, 0, false, true, $hx, 'M');
$this->setXY($ejex, $ejey); $ejey += 4;
$this->SetFillColor(255, 255, 255);
$this->MultiCell(20, 4, $ar['cli_tipodoc'] == '6' ? "RUC" : "DNI", 0, 'L', 1, 0, '', '', true, 0, false, true, 4, 'M');
$this->MultiCell(5, 4, ':', 0, 'C', 1, 0, '', '', true, 0, false, true, 4, 'M');
$this->MultiCell(100, 4, $ar['cli_nrodoc'], 0, 'L', 1, 0, '', '', true, 0, false, true, 4, 'M');
$this->setXY($ejex, $ejey); $ejey += 4;
$this->SetFillColor(255, 255, 255);
$this->MultiCell(20, 4, 'DIRECCION', 0, 'L', 1, 0, '', '', true, 0, false, true, 4, 'M');
$this->MultiCell(5, 4, ':', 0, 'C', 1, 0, '', '', true, 0, false, true, 4, 'M');
$this->MultiCell(100, 4, $ar['cli_razon'], 0, 'L', 1, 0, '', '', true, 0, false, true, 4, 'M');
$this->setXY($ejex, $ejey); $ejey += 4;
$this->SetFillColor(255, 255, 255);
$this->MultiCell(20, 4, 'E-MAIL', 0, 'L', 1, 0, '', '', true, 0, false, true, 4, 'M');
$this->MultiCell(5, 4, ':', 0, 'C', 1, 0, '', '', true, 0, false, true, 4, 'M');
$this->MultiCell(100, 4, '', 0, 'L', 1, 0, '', '', true, 0, false, true, 4, 'M');
if ($hx == 4) {
$this->setXY($ejex, $ejey); $ejey += 4;
$this->SetFillColor(255, 255, 255);
$this->MultiCell(20, 4, 'TELEFONO', 0, 'L', 1, 0, '', '', true, 0, false, true, 4, 'M');
$this->MultiCell(5, 4, ':', 0, 'C', 1, 0, '', '', true, 0, false, true, 4, 'M');
$this->MultiCell(100, 4, '', 0, 'L', 1, 0, '', '', true, 0, false, true, 4, 'M');
}
$ejey = 40; $ejex = 142; $h = 4;
$this->setXY($ejex, $ejey); $ejey += $h;
$this->SetFillColor(255, 255, 255);
$this->MultiCell(30, 4, 'FECHA EMISIÓN', 0, 'L', 1, 0, '', '', true, 0, false, true, 4, 'M');
$this->MultiCell(5, 4, ':', 0, 'C', 1, 0, '', '', true, 0, false, true, 4, 'M');
$this->MultiCell(22, 4, fnDateDDMMAAAA($ar['vent_fechadoc']), 0, 'L', 1, 0, '', '', true, 0, false, true, 4, 'M');
$this->setXY($ejex, $ejey); $ejey += $h;
$this->SetFillColor(255, 255, 255);
$this->MultiCell(30, 4, 'FECHA VENCIMIENTO', 0, 'L', 1, 0, '', '', true, 0, false, true, 4, 'M');
$this->MultiCell(5, 4, ':', 0, 'C', 1, 0, '', '', true, 0, false, true, 4, 'M');
$this->MultiCell(22, 4, fnDateDDMMAAAA($ar['vent_fechaven']), 0, 'L', 1, 0, '', '', true, 0, false, true, 4, 'M');
$this->setXY($ejex, $ejey); $ejey += $h;
$this->SetFillColor(255, 255, 255);
$this->MultiCell(30, 4, 'MONEDA', 0, 'L', 1, 0, '', '', true, 0, false, true, 4, 'M');
$this->MultiCell(5, 4, ':', 0, 'C', 1, 0, '', '', true, 0, false, true, 4, 'M');
$this->MultiCell(22, 4, $ar['moneda'], 0, 'L', 1, 0, '', '', true, 0, false, true, 4, 'M');
$this->setXY($ejex, $ejey); $ejey += $h;
$this->SetFillColor(255, 255, 255);
$this->MultiCell(30, 4, 'RESPONSABLE', 0, 'L', 1, 0, '', '', true, 0, false, true, 4, 'M');
$this->MultiCell(5, 4, ':', 0, 'C', 1, 0, '', '', true, 0, false, true, 4, 'M');
$this->MultiCell(22, 4, "", 0, 'L', 1, 0, '', '', true, 0, false, true, 4, 'M');
$this->setXY($ejex, $ejey); $ejey += $h;
$this->SetFillColor(255, 255, 255);
$this->MultiCell(30, 4, 'PLACA VEHICULO', 0, 'L', 1, 0, '', '', true, 0, false, true, 4, 'M');
$this->MultiCell(5, 4, ':', 0, 'C', 1, 0, '', '', true, 0, false, true, 4, 'M');
$this->MultiCell(22, 4, $ar['placa'], 0, 'L', 1, 0, '', '', true, 0, false, true, 4, 'M');
}
// Page footer
public function Footer() {
// Position at 15 mm from bottom
$this->SetY(-15);
// Set font
$this->SetFont('helvetica', 'I', 8);
// Page number
$this->Cell(0, 0, 'Página '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
}
$ob = new Sag_Venta();
$ob->set_vent_id($_REQUEST['phpVENT_IIDD'] == "" ? '0' : $_REQUEST['phpVENT_IIDD']);
$ob->set_vent_key($_REQUEST['phpVENT_KEY']);
$doc = $ob->registros();
$det = $ob->registros_detalle();
if (count($doc) != 1) {
echo "No se puede generar el PDF";
exit;
}
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->info = $doc[0];
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Municipalidad Provincial de Ilo');
$pdf->SetTitle('XXXXXX' . '-' . $doc[0]['doc_sunat'] . '-' . $doc[0]['serie_desc'] . '-' . $doc[0]['vent_nrodoc']);
$pdf->SetSubject('Facturacion electronica');
$pdf->SetMargins(PDF_MARGIN_LEFT, 55, PDF_MARGIN_RIGHT);
// set font
$pdf->SetFont("helvetica", "B", 8);
// add a page
$pdf->AddPage();
$pdf->SetLineStyle(array('width' => 0.1));
$ejey = 65; $ejex = 10; $h = 4;
$pdf->setXY($ejex, $ejey); $ejey += 8;
$pdf->SetFillColor(235, 235, 235);
$pdf->MultiCell(8, 8, '', 1, 'C', 1, 0, '', '', true, 0, false, true, 8, 'M');
$pdf->MultiCell(20, 8, 'CANTIDAD', 1, 'C', 1, 0, '', '', true, 0, false, true, 8, 'M');
$pdf->MultiCell(10, 8, 'UM', 1, 'C', 1, 0, '', '', true, 0, false, true, 8, 'M');
$pdf->MultiCell(17, 8, 'CODIGO', 1, 'C', 1, 0, '', '', true, 0, false, true, 8, 'M');
$pdf->MultiCell(95, 8, 'DESCRIPCION', 1, 'C', 1, 0, '', '', true, 0, false, true, 8, 'M');
$pdf->MultiCell(20, 8, 'Val. V.', 1, 'C', 1, 0, '', '', true, 0, false, true, 8, 'M');
$pdf->MultiCell(20, 8, 'IMPORTE', 1, 'C', 1, 0, '', '', true, 0, false, true, 8, 'M');
$pdf->setXY($ejex, $ejey);
$pdf->SetFillColor(255, 255, 255);
$pdf->MultiCell(8, 146, '', 1, '', 1, 0, '', '', true, 0, false, true, 146, 'M');
$pdf->MultiCell(20, 146, '', 1, '', 1, 0, '', '', true, 0, false, true, 146, 'M');
$pdf->MultiCell(10, 146, '', 1, '', 1, 0, '', '', true, 0, false, true, 146, 'M');
$pdf->MultiCell(17, 146, '', 1, '', 1, 0, '', '', true, 0, false, true, 146, 'M');
$pdf->MultiCell(95, 146, '', 1, '', 1, 0, '', '', true, 0, false, true, 146, 'M');
$pdf->MultiCell(20, 146, '', 1, '', 1, 0, '', '', true, 0, false, true, 146, 'M');
$pdf->MultiCell(20, 146, '', 1, '', 1, 0, '', '', true, 0, false, true, 146, 'M');
$h = 6; $ejey += 1;
$pdf->SetFillColor(255, 255, 255);
$pdf->SetFont("helvetica", "", 8);
foreach ($det as $k => $val) {
$pdf->setXY($ejex, $ejey); $ejey += $h;
$pdf->MultiCell(8, 6, $k+1, 0, 'C', 0, 0, '', '', true, 0, false, true, 6, 'M');
$pdf->MultiCell(20, 6, fnNume01($val['cantidad']*1,5), 0, 'C', 0, 0, '', '', true, 0, false, true, 6, 'M');
$pdf->MultiCell(10, 6, $val['unimed'], 0, 'C', 0, 0, '', '', true, 0, false, true, 6, 'M');
$pdf->MultiCell(17, 6, $val['codigo'], 0, 'C', 0, 0, '', '', true, 0, false, true, 6, 'M');
$pdf->MultiCell(95, 6, $val['detalle'], 0, 'L', 0, 0, '', '', true, 0, false, true, 6, 'M');
$pdf->MultiCell(20, 6, fnNume01($val['precio_unitario'],4), 0, 'R', 0, 0, '', '', true, 0, false, true, 6, 'M');
$pdf->MultiCell(20, 6, fnNume01($val['suma'],2), 0, 'R', 0, 0, '', '', true, 0, false, true, 6, 'M');
}
// QR
$style = array(
'border' => 2,
'vpadding' => 'auto',
'hpadding' => 'auto',
'fgcolor' => array(0,0,0),
'bgcolor' => false, //array(255,255,255)
'module_width' => 1, // width of a single module in points
'module_height' => 1 // height of a single module in points
);
$dat = array(
'XXXXX',
$doc[0]['doc_sunat'],
$doc[0]['serie_desc'],
$doc[0]['vent_nrodoc'],
$doc[0]['total_igv'],
$doc[0]['total_venta'],
$doc[0]['vent_fechadoc'],
$doc[0]['cli_tipodoc'],
$doc[0]['cli_nrodoc'],
''
);
$qrdat = implode($dat, '|');
$pdf->write2DBarcode($qrdat, 'QRCODE,Q', 10, 222, 38, 38, $style, 'N');
$ejey = 220; $ejex = 51; $h = 6;
$pdf->setXY($ejex, $ejey); $ejey += $h;
$pdf->MultiCell(150, 6, 'SON: ' . convertir_a_letras($doc[0]['total_venta']), 0, '', 1, 0, '', '', true, 0, false, true, 6, 'M');
$ejey = 228; $ejex = 52;
$pdf->SetFont("helvetica", "B", 9);
$pdf->setXY($ejex, $ejey);
$pdf->MultiCell(84, 32, 'OBSERVACIONES:', 1, 'L', 1, 0, '', '', true, 0, false, true, 8, 'M');
$ejey = 234; $ejex = 53;
$pdf->SetFont("helvetica", "", 9);
$pdf->setXY($ejex, $ejey);
$pdf->MultiCell(81, 25, $doc[0]['observ'], 0, 'L', 1, 0, '', '', true, 0, false, true, 25, 'M');
$ejey = 254; $ejex = 140; $h = 6;
$pdf->setXY($ejex, $ejey); $ejey += $h;
$pdf->SetFillColor(235, 235, 235);
$pdf->MultiCell(60, 6, '', 1, '', 1, 0, '', '', true, 0, false, true, 6, 'M');
$pdf->SetFillColor(255, 255, 255);
$pdf->SetFont("helvetica", "", 9);
$ejey = 225; $ejex = 143; $h = 4;
$pdf->setXY($ejex, $ejey); $ejey += $h;
$pdf->Cell(25, 4, "GRAVADAS", 0, 0, "R", false);
$pdf->Cell(8 ,4, ": S/.", "", 0, "", false);
$pdf->Cell(24, 4, $doc[0]['gravadas']*1 == 0 ? "0.00" : fnNume01($doc[0]['gravadas']*1, 2), 0, 0, "R", false);
$pdf->setXY($ejex, $ejey); $ejey += $h;
$pdf->Cell(25, 4, "GRATUITAS", 0, 0, "R", false);
$pdf->Cell(8 ,4, ": S/.", "", 0, "", false);
$pdf->Cell(24, 4, $doc[0]['gratuitas']*1 == 0 ? "0.00" : fnNume01($doc[0]['gratuitas']*1, 2), 0, 0, "R", false);
$pdf->setXY($ejex, $ejey); $ejey += $h;
$pdf->Cell(25, 4, "INAFECTAS", 0, 0, "R", false);
$pdf->Cell(8 ,4, ": S/.", "", 0, "", false);
$pdf->Cell(24, 4, $doc[0]['inafectas']*1 == 0 ? "0.00" : fnNume01($doc[0]['inafectas']*1, 2), 0, 0, "R", false);
$pdf->setXY($ejex, $ejey); $ejey += $h;
$pdf->Cell(25, 4, "EXONERADAS", 0, 0, "R", false);
$pdf->Cell(8 ,4, ": S/.", "", 0, "", false);
$pdf->Cell(24, 4, $doc[0]['exoneradas']*1 == 0 ? "0.00" : fnNume01($doc[0]['exoneradas']*1, 2), 0, 0, "R", false);
$pdf->setXY($ejex, $ejey); $ejey += $h;
$pdf->Cell(25, 4, "DESCUENTOS", 0, 0, "R", false);
$pdf->Cell(8 ,4, ": S/.", "", 0, "", false);
$pdf->Cell(24, 4, $doc[0]['descuentos']*1 == 0 ? "0.00" : fnNume01($doc[0]['descuentos']*1, 2), 0, 0, "R", false);
$pdf->setXY($ejex, $ejey); $ejey += $h;
$pdf->Cell(25, 4, "IGV", 0, 0, "R", false);
$pdf->Cell(8 ,4, ": S/.", "", 0, "", false);
$pdf->Cell(24, 4, $doc[0]['total_igv']*1 == 0 ? "0.00" : fnNume01($doc[0]['total_igv']*1, 2), 0, 0, "R", false);
$pdf->setXY($ejex, $ejey); $ejey += $h;
$pdf->Cell(25, 4, "ISC", 0, 0, "R", false);
$pdf->Cell(8 ,4, ": S/.", "", 0, "", false);
$pdf->Cell(24, 4, $doc[0]['tota_isc']*1 == 0 ? "0.00" : fnNume01($doc[0]['tota_isc']*1, 2), 0, 0, "R", false);
$pdf->SetFont("helvetica", "B", 9);
$pdf->setXY($ejex, $ejey+2);
$pdf->Cell(25, 4, "IMPORTE TOTAL", 0, 0, "R", false);
$pdf->Cell(8 ,4, ": S/.", 0, 0, "", false);
$pdf->Cell(24, 4, $doc[0]['total_venta']*1 == 0 ? "0.00" : fnNume01($doc[0]['total_venta']*1, 2), 0, 0, "R", false);
$ejey = 262; $ejex = 10; $h = 6;
$pdf->SetFont("helvetica", "", 8);
$pdf->setXY($ejex, $ejey); $ejey += $h;
$pdf->MultiCell(190, 8, 'Representación impresa de la boleta de venta electrónica. Autorizado mediante resolución de intendencia N° 112-005-0000138/SUNAT. Para consultar ingrese a www.mpi.gob.pe/cpe', 0, 'C', 1, 0, '', '', true, 0, false, true, 8, 'M');
$ejey = 272; $ejex = 10; $h = 6;
$pdf->SetFont("helvetica", "", 8);
$pdf->setXY($ejex, $ejey); $ejey += $h;
$pdf->MultiCell(190, 4, 'RESUMEN: ' . $doc[0]['hash_resumen'], 0, 'C', 1, 0, '', '', true, 0, false, true, 4, 'M');
//$pdf->Output('xxxxx' . '-' . $doc[0]['doc_sunat'] . '-' . $doc[0]['serie_desc'] . '-' . $doc[0]['vent_nrodoc'] . '.pdf', 'I');
if ($_REQUEST['xxDownload'] == 'OK') {
$pdf->Output('xxxxx' . '-' . $doc[0]['doc_sunat'] . '-' . $doc[0]['serie_desc'] . '-' . $doc[0]['vent_nrodoc'] . '.pdf', 'D');
} else {
$pdf->Output('xxxxx' . '-' . $doc[0]['doc_sunat'] . '-' . $doc[0]['serie_desc'] . '-' . $doc[0]['vent_nrodoc'] . '.pdf', 'I');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment