<?php
    session_start();
	# Incluyendo librerias necesarias #
    
    require "./code128.php";
    
    require ('../functions/ticket_nota.php');
    
    $id_nota = $_SESSION['cveNota'];
    
    
    $nota = get_nota($id_nota);
    $campo = get_productos_nota($id_nota);
    $no_nota = $nota[0]['CLAVE'];
    $mesero = $nota[1]['NOMBRE'];
    $tipo_venta = $nota[2]['ZONA'];
    $p=$nota[4]['PERSONAS'];  //Personas 
    $m=$nota[3]['MESA']; // Numero de mesa
    $subtotal=$nota[5]["SUBTOTAL"];
    $descuento=$nota[6]["DESCUENTO"];
    $total=$nota[7]["TOTAL"];
    $descuento_total = ($subtotal*$descuento)/100;
    date_default_timezone_set('America/Mexico_City');
    $hoy=new DateTime();

    $pdf = new PDF_Code128('P','mm',array(80,258));
    $pdf->SetMargins(0,10,12);
    $pdf->AddPage();
    
    # Encabezado y datos de la empresa #
    $pdf->SetFont('Arial','B',10);
    $pdf->SetTextColor(0,0,0);
    //$pdf->MultiCell(0,5,utf8_decode(strtoupper("Nombre de empresa")),0,'C',false);
    $pdf->Image('logo.png',5,5, 65, 25);
    $pdf->SetFont('Arial','B',8);
    $pdf->SetTextColor(255,255,255);
    $pdf->Ln(25);
    $pdf->MultiCell(0,5,utf8_decode("NOTA DE VENTA"),0,'C',true);
    $pdf->SetTextColor(0,0,0);
    $pdf->Ln(2);
    $pdf->MultiCell(0,4,utf8_decode("Martha Angélica Samperio Fosado"),0,'C',false);
    $pdf->MultiCell(0,4,utf8_decode("RFC: SAFM780520L77"),0,'C',false);
    $pdf->MultiCell(0,4,utf8_decode("Carretera Federal Pahuca-Tulancingo"),0,'C',false);
    $pdf->MultiCell(0,4,utf8_decode("Kilometro 19.5"),0,'C',false);
    $pdf->MultiCell(0,4,utf8_decode("Teléfono: 7751365015"),0,'C',false);
    $pdf->MultiCell(0,4,utf8_decode("Sitio Web: www.micabanita.mx"),0,'C',false);

    $pdf->Ln(1);
    $pdf->Cell(0,5,utf8_decode("------------------------------------------------------"),0,0,'C');
    $pdf->Ln(5);

    $pdf->MultiCell(0,4,utf8_decode("Fecha: ".$hoy->format('d/m/Y H:i:s')),0,'C',false);
    $pdf->MultiCell(0,4,utf8_decode("$tipo_venta"),0,'C',false);
    $pdf->MultiCell(0,4,utf8_decode("P: $p - M: $m"),0,'C',false);
    $pdf->MultiCell(0,4,utf8_decode("Mesero: $mesero"),0,'C',false);
    $pdf->SetFont('Arial','B',9);
    $pdf->MultiCell(0,4,utf8_decode(strtoupper("No. Nota: $no_nota")),0,'C',false);
    $pdf->SetFont('Arial','',9);

    $pdf->Ln(1);
    $pdf->Cell(0,5,utf8_decode("-------------------------------------------------------------------"),0,0,'C');
    $pdf->Ln(3);
    $pdf->SetFont('Arial','B',9);
    # Tabla de productos #
    $pdf->Cell(10,5,utf8_decode("Cant"),0,0,'C');
    //$pdf->Cell(15,5,utf8_decode("Descripcion"),0,0,'C');
    $pdf->Cell(18,5,utf8_decode("Desc"),0,0,'C');
    $pdf->Cell(20,5,utf8_decode("Precio"),0,0,'C');
    $pdf->Cell(20,5,utf8_decode("Total"),0,0,'C');
    $pdf->SetFont('Arial','',9);
    $pdf->Ln(3);
    $pdf->Cell(72,5,utf8_decode("-------------------------------------------------------------------"),0,0,'C');
    $pdf->Ln(4);

    foreach($campo as $cam) {
    $pro_total = $cam['PRECIO'] *$cam['CANTIDAD'];
    /*----------  Detalles de la tabla  ----------*/
    $pdf->MultiCell(0,4,utf8_decode("$cam[PRO_NOMBRE]"),0,'C',false);
    $pdf->Cell(10,4,utf8_decode("$cam[CANTIDAD]"),0,0,'C');
    $pdf->Cell(19,4,utf8_decode("0 %"),0,0,'C');
    $pdf->Cell(19,4,utf8_decode("$ $cam[PRECIO]"),0,0,'C');
    $pdf->Cell(19,4,utf8_decode("$ $pro_total" ),0,0,'C');
    $pdf->Ln(8);
    /*----------  Fin Detalles de la tabla  ----------*/
   
    }


    $pdf->Cell(72,5,utf8_decode("-------------------------------------------------------------------"),0,0,'C');

        $pdf->Ln(5);

    # Impuestos & totales #
    $pdf->Cell(10,5,utf8_decode(""),0,0,'C');
    $pdf->Cell(22,5,utf8_decode("Subtotal:"),0,0,'R');
    $pdf->SetFont('Arial','B',11);
    $pdf->Cell(32,5,utf8_decode("$ $subtotal"),0,0,'R');
    $pdf->SetFont('Arial','',9);
    $pdf->Ln(5);

    $pdf->Cell(10,5,utf8_decode(""),0,0,'C');
    $pdf->Cell(22,5,utf8_decode("Desc p/Partida:"),0,0,'R');
    $pdf->Cell(32,5,utf8_decode(" $descuento %"),0,0,'R');
    $pdf->Ln(5);

    $pdf->Cell(10,5,utf8_decode(""),0,0,'C');
    $pdf->Cell(22,5,utf8_decode("Desc Gral:"),0,0,'R');
    $pdf->Cell(32,5,utf8_decode("$ $descuento_total"),0,0,'R');
    $pdf->Ln(5);
    
    $pdf->Cell(10,5,utf8_decode(""),0,0,'C');
    $pdf->Cell(22,5,utf8_decode("IVA (16%):"),0,0,'R');
    $pdf->Cell(32,5,utf8_decode("$0.00"),0,0,'R');
    $pdf->Ln(5);

    $pdf->Cell(72,5,utf8_decode("-------------------------------------------------------------------"),0,0,'C');

    $pdf->Ln(5);

    $pdf->Cell(10,5,utf8_decode(""),0,0,'C');
    $pdf->SetFont('Arial','B',12);
    $pdf->Cell(22,5,utf8_decode("TOTAL"),0,0,'R');
    $pdf->Cell(32,5,utf8_decode("$ $total"),0,0,'R');

    $pdf->Ln(5);
    
    /*$pdf->Cell(18,5,utf8_decode(""),0,0,'C');
    $pdf->Cell(22,5,utf8_decode("TOTAL PAGADO"),0,0,'C');
    $pdf->Cell(32,5,utf8_decode("$100.00 USD"),0,0,'C');

    $pdf->Ln(5);

    $pdf->Cell(18,5,utf8_decode(""),0,0,'C');
    $pdf->Cell(22,5,utf8_decode("CAMBIO"),0,0,'C');
    $pdf->Cell(32,5,utf8_decode("$30.00 USD"),0,0,'C');

    $pdf->Ln(5);

    $pdf->Cell(18,5,utf8_decode(""),0,0,'C');
    $pdf->Cell(22,5,utf8_decode("USTED AHORRA"),0,0,'C');
    $pdf->Cell(32,5,utf8_decode("$0.00 USD"),0,0,'C');
*/
    $pdf->Ln(10);

    $pdf->MultiCell(0,5,utf8_decode("¡ Gracias por tu visita !"),0,'C',false);
    $pdf->Ln(1);
    $pdf->SetFont('Arial','B',9);
    $pdf->MultiCell(0,4,utf8_decode("*** Precios de productos incluyen impuestos. Para poder realizar un reclamo o devolución debe de presentar este ticket ***"),0,'C',false);

    $pdf->Ln(9);
/*
    # Codigo de barras #
    $pdf->Code128(3,$pdf->GetY(),"COD000001V0001",65,20);
    $pdf->SetXY(0,$pdf->GetY()+21);
    $pdf->SetFont('Arial','',14);
    $pdf->MultiCell(0,4,utf8_decode("COD000001V0001"),0,'C',false);*/
    
    # Nombre del archivo PDF #
    
    $pdf->Output("I","Ticket_Nro_$no_nota.pdf",true);
