<?php 

include('../../StoGlobal/include/conexion.php');
include('../../StoGlobal/include/conexion1.php');
include('../../StoGlobal/include/conexion3.php');
error_reporting(0);

require('html_table.php');
// require('fpdf.php');
date_default_timezone_set('America/Santiago');
$fecha=date("d-m-Y");

$id_cot=$_GET['id_cot'];

$query = "select * from sto_cotizacion where id_cotizacion='$id_cot'";
$stmt = $DBcon->prepare( $query );
$stmt->execute();

if($stmt->rowCount() > 0) {
    while($row=$stmt->fetch(PDO::FETCH_ASSOC)) {
        extract($row);
        
        $id_cotizacion=$id_cotizacion;
        $tipo_cotizacion_print=$tipo_cotizacion;
        $direccion=$direccion;
        $contacto=$contacto;


        $pdf=new PDF();
        $pdf->AddPage();
        $pdf->SetFont('Arial','',11);
        $pdf->Image('Logo_PNG.png' , 8 ,6, 25 , 25,'PNG', 'www.stoglobal.cl');
        $pdf->Image('Logo_PNG_Name.png' , 35 ,8, 95 , 20,'PNG', 'www.stoglobal.cl');
        
        $b1=utf8_decode("\n");
        
        
        $pdf->SetFontSize(10);
        $pdf->SetFont('Arial','B');
        $pdf->SetFillColor(255,255,255);
        $pdf->SetTextColor(120,120,120);
        $pdf->SetXY(130, 6);
        $pdf->Multicell(90, 5,utf8_decode("  N° Cotización: $id_cotizacion").$b1.utf8_decode("                  Tipo:  $tipo_cotizacion_print").$b1.utf8_decode("                Fecha: $fecha").$b1.utf8_decode("             Termino: Postfechado 5 Días"),0,0,'L',1);
        
        $pdf->SetFontSize(9);
        $pdf->SetFont('Arial','B');
        $pdf->SetFillColor(255,255,255);
        $pdf->SetTextColor(70,70,70);
        $pdf->SetXY(10, 35);
        $pdf->Multicell(90, 5,utf8_decode("Rut: 77.710.176-5").$b1.utf8_decode("Razón Social: Servicios StoGlobal SpA").$b1.utf8_decode("Dirección: Eduardo Moscoso 873, Copiapó"),0,0,'L',1);
        
        
        
        $pdf->SetFontSize(9);
        $pdf->SetFont('Arial','B');
        $pdf->SetFillColor(255,255,255);
        $pdf->SetTextColor(70,70,70);
        $pdf->SetXY(130, 35);
        $pdf->Multicell(80, 5,utf8_decode("Contacto: $contacto").$b1.utf8_decode("Dirección: $direccion"),0,0,'L',1);
        
        
        
        $pdf->Ln(17);
        
        $pdf->SetFontSize(10);
        $pdf->SetFont('Arial','B');
        $pdf->SetFillColor(255,255,255);
        $pdf->SetTextColor(40,40,40);
        $pdf->SetDrawColor(88,88,88);
        $pdf->Cell(3, 10,'#',0,0,'C',1);
        $pdf->Cell(50, 10,'Tipo Producto',0,0,'C',1);
        $pdf->Cell(82, 10,'Detalle',0,0,'C',1);
        $pdf->Cell(25, 10,'Valor Neto',0,0,'C',1);
        $pdf->Cell(15, 10,'Cantidad',0,0,'C',1);
        $pdf->Cell(20, 10,'Total',0,0,'C',1);
        $pdf->SetDrawColor(61,174,233);
        $pdf->setLineWidth(1);
        $pdf->Line(11,72,204,72);
        $pdf->SetTextColor(0,0,0);
        
        
        $pdf->SetFontSize(8);
        $pdf->SetFont('Arial','B');
        $pdf->setLineWidth(0.2);
        $pdf->SetFillColor(240,240,240);
        $pdf->SetTextColor(40,40,40);
        $pdf->SetDrawColor(255,255,255);
        $pdf->Ln(10);
        
        $cnt=0;
        $total=0;
        $query = "select * from sto_cotizacion_items where id_cotizacion=$id_cotizacion";
        $stmt = $DBcon->prepare( $query );
        $stmt->execute();
        
        if($stmt->rowCount() > 0) {
            while($row=$stmt->fetch(PDO::FETCH_ASSOC)) {
                extract($row);
                $total=$precio_venta*$cantidad;
                $pdf->Cell(3,  10,$num_romano,                 1,0,'C',1);
                    $pdf->SetFontSize(8);
                    $pdf->SetFont('Arial','');
                $pdf->Cell(50, 10,utf8_decode($producto),                1,0,'C',1);
                    $pdf->SetFontSize(6);
                    $pdf->SetFont('Arial','');
                $pdf->Cell(82, 10,utf8_decode($descripcion),                1,0,'J',1);
                    $pdf->SetFontSize(8);
                    $pdf->SetFont('Arial','');
                $pdf->Cell(25, 10,'$'.number_format($precio_venta,0,",","."),            1,0,'C',1);
                $pdf->Cell(15, 10,number_format($cantidad,0,",","."),               1,0,'C',1);
                $pdf->Cell(20, 10,'$'.number_format($total,0,",","."),   1,0,'C',1);
                $pdf->Ln();
                $cnt++;
                $total_final=$total+$total_final;
                
            } 
        }
        
        
        $total_final_print=round($total_final); 
        
        $pdf->SetFontSize(9);
        $pdf->SetFont('Arial','B');
        $pdf->SetTextColor(60,60,60);
        $pdf->SetFillColor(255,255,255);
        $pdf->SetDrawColor(88,88,88);
        $pdf->Cell(20, 10,'',0,0,'C',1);
        $pdf->Cell(30, 10,'',0,0,'C',1);
        $pdf->Cell(50, 10,'',0,0,'C',1);
        $pdf->Cell(50, 10,'',0,0,'C',1);
        $pdf->Cell(15, 10,'Neto: ',0,0,'R',1);
        $pdf->Cell(30, 10,'$'.number_format($total_final_print,0,",","."),0,0,'L',1);
        $pdf->Ln();
        
        $iva=$total_final_print*0.19;
        $iva_print=round($iva); 
        
        $pdf->SetFontSize(9);
        $pdf->SetFont('Arial','B');
        $pdf->SetTextColor(60,60,60);
        $pdf->Cell(20, 2,'',0,0,'C',1);
        $pdf->Cell(30, 2,'',0,0,'C',1);
        $pdf->Cell(50, 2,'',0,0,'C',1);
        $pdf->Cell(50, 2,'',0,0,'C',1);
        $pdf->Cell(15, 2,'IVA: ',0,0,'R',1);
        $pdf->Cell(30, 2,'$'.number_format($iva_print,0,",","."),0,0,'L',1);
        $pdf->Ln(3);
        
        
        $total_bruto=$iva_print+$total_final_print;
        
        
        $total_bruto_print=round($total_bruto); 
        
        
        
        $pdf->SetFontSize(11);
        $pdf->SetFont('Arial','B');
        // $pdf->SetXY(60, 100);
        $pdf->SetTextColor(40,40,40);
        $pdf->Cell(20, 7,'',0,0,'C',1);
        $pdf->Cell(30, 7,'',0,0,'C',1);
        $pdf->Cell(50, 7,'',0,0,'C',1);
        $pdf->Cell(50, 7,'',0,0,'C',1);
        $pdf->Cell(15, 7,'Total: ','T',0,'R');
        $pdf->Cell(30, 7,'$'.number_format($total_bruto_print,0,",","."),'T',0,'L');
        
        $pdf->Output();

    } 
}



?>