<?php
session_start();
require('code39.php');
require('fpdi/fpdi.php');
require('conexion.php');

function getSubString($string, $length=NULL)
{
    //Si no se especifica la longitud por defecto es 50
    if ($length == NULL)
        $length = 30;
    //Primero eliminamos las etiquetas html y luego cortamos el string
    $stringDisplay = substr(strip_tags($string), 0, $length);
    //Si el texto es mayor que la longitud se agrega puntos suspensivos
    if (strlen(strip_tags($string)) > $length)
        $stringDisplay .= ' ...';
    return $stringDisplay;
}

function num2letras($num, $fem = false, $dec = true) { 
   $matuni[2]  = "dos"; 
   $matuni[3]  = "tres"; 
   $matuni[4]  = "cuatro"; 
   $matuni[5]  = "cinco"; 
   $matuni[6]  = "seis"; 
   $matuni[7]  = "siete"; 
   $matuni[8]  = "ocho"; 
   $matuni[9]  = "nueve"; 
   $matuni[10] = "diez"; 
   $matuni[11] = "once"; 
   $matuni[12] = "doce"; 
   $matuni[13] = "trece"; 
   $matuni[14] = "catorce"; 
   $matuni[15] = "quince"; 
   $matuni[16] = "dieciseis"; 
   $matuni[17] = "diecisiete"; 
   $matuni[18] = "dieciocho"; 
   $matuni[19] = "diecinueve"; 
   $matuni[20] = "veinte"; 
   $matunisub[2] = "dos"; 
   $matunisub[3] = "tres"; 
   $matunisub[4] = "cuatro"; 
   $matunisub[5] = "quin"; 
   $matunisub[6] = "seis"; 
   $matunisub[7] = "sete"; 
   $matunisub[8] = "ocho"; 
   $matunisub[9] = "nove"; 

   $matdec[2] = "veint"; 
   $matdec[3] = "treinta"; 
   $matdec[4] = "cuarenta"; 
   $matdec[5] = "cincuenta"; 
   $matdec[6] = "sesenta"; 
   $matdec[7] = "setenta"; 
   $matdec[8] = "ochenta"; 
   $matdec[9] = "noventa"; 
   $matsub[3]  = 'mill'; 
   $matsub[5]  = 'bill'; 
   $matsub[7]  = 'mill'; 
   $matsub[9]  = 'trill'; 
   $matsub[11] = 'mill'; 
   $matsub[13] = 'bill'; 
   $matsub[15] = 'mill'; 
   $matmil[4]  = 'millones'; 
   $matmil[6]  = 'billones'; 
   $matmil[7]  = 'de billones'; 
   $matmil[8]  = 'millones de billones'; 
   $matmil[10] = 'trillones'; 
   $matmil[11] = 'de trillones'; 
   $matmil[12] = 'millones de trillones'; 
   $matmil[13] = 'de trillones'; 
   $matmil[14] = 'billones de trillones'; 
   $matmil[15] = 'de billones de trillones'; 
   $matmil[16] = 'millones de billones de trillones'; 
   
   //Zi hack
   $float=explode('.',$num);
   $num=$float[0];

   $num = trim((string)@$num); 
   if ($num[0] == '-') { 
      $neg = 'menos '; 
      $num = substr($num, 1); 
   }else 
      $neg = ''; 
   while ($num[0] == '0') $num = substr($num, 1); 
   if ($num[0] < '1' or $num[0] > 9) $num = '0' . $num; 
   $zeros = true; 
   $punt = false; 
   $ent = ''; 
   $fra = ''; 
   for ($c = 0; $c < strlen($num); $c++) { 
      $n = $num[$c]; 
      if (! (strpos(".,'''", $n) === false)) { 
         if ($punt) break; 
         else{ 
            $punt = true; 
            continue; 
         } 

      }elseif (! (strpos('0123456789', $n) === false)) { 
         if ($punt) { 
            if ($n != '0') $zeros = false; 
            $fra .= $n; 
         }else 

            $ent .= $n; 
      }else 

         break; 

   } 
   $ent = '     ' . $ent; 
   if ($dec and $fra and ! $zeros) { 
      $fin = ' coma'; 
      for ($n = 0; $n < strlen($fra); $n++) { 
         if (($s = $fra[$n]) == '0') 
            $fin .= ' cero'; 
         elseif ($s == '1') 
            $fin .= $fem ? ' una' : ' un'; 
         else 
            $fin .= ' ' . $matuni[$s]; 
      } 
   }else 
      $fin = ''; 
   if ((int)$ent === 0) return 'Cero ' . $fin; 
   $tex = ''; 
   $sub = 0; 
   $mils = 0; 
   $neutro = false; 
   while ( ($num = substr($ent, -3)) != '   ') { 
      $ent = substr($ent, 0, -3); 
      if (++$sub < 3 and $fem) { 
         $matuni[1] = 'una'; 
         $subcent = 'as'; 
      }else{ 
         $matuni[1] = $neutro ? 'un' : 'uno'; 
         $subcent = 'os'; 
      } 
      $t = ''; 
      $n2 = substr($num, 1); 
      if ($n2 == '00') { 
      }elseif ($n2 < 21) 
         $t = ' ' . $matuni[(int)$n2]; 
      elseif ($n2 < 30) { 
         $n3 = $num[2]; 
         if ($n3 != 0) $t = 'i' . $matuni[$n3]; 
         $n2 = $num[1]; 
         $t = ' ' . $matdec[$n2] . $t; 
      }else{ 
         $n3 = $num[2]; 
         if ($n3 != 0) $t = ' y ' . $matuni[$n3]; 
         $n2 = $num[1]; 
         $t = ' ' . $matdec[$n2] . $t; 
      } 
      $n = $num[0]; 
      if ($n == 1) { 
         $t = ' ciento' . $t; 
      }elseif ($n == 5){ 
         $t = ' ' . $matunisub[$n] . 'ient' . $subcent . $t; 
      }elseif ($n != 0){ 
         $t = ' ' . $matunisub[$n] . 'cient' . $subcent . $t; 
      } 
      if ($sub == 1) { 
      }elseif (! isset($matsub[$sub])) { 
         if ($num == 1) { 
            $t = ' mil'; 
         }elseif ($num > 1){ 
            $t .= ' mil'; 
         } 
      }elseif ($num == 1) { 
         $t .= ' ' . $matsub[$sub] . '?n'; 
      }elseif ($num > 1){ 
         $t .= ' ' . $matsub[$sub] . 'ones'; 
      }   
      if ($num == '000') $mils ++; 
      elseif ($mils != 0) { 
         if (isset($matmil[$sub])) $t .= ' ' . $matmil[$sub]; 
         $mils = 0; 
      } 
      $neutro = true; 
      $tex = $t . $tex; 
   } 
   $tex = $neg . substr($tex, 1) . $fin; 
   //Zi hack --> return ucfirst($tex);
   $end_num=ucfirst($tex).' pesos '.$float[1].'/100 M.N.';
   return $end_num; 
}

$nom = $_SESSION['nom_admin'];
$iduser = $_SESSION['id_user'];
$suc = $_SESSION['IdSuc'];
$tipou= $_SESSION['tipouser'];



if($suc == 1){
    $sucn = 'SUCURSAL CULIACAN';
}else if ($suc == 2){
    $sucn = 'SUCURSAL MAZATLAN';
}else if($suc == 3){
    $sucn = 'SUCURSAL HERMOSILLO';
}

$serie = $_GET['serie'];
$folio = $_GET['folio'];



$gasto = mysqli_query($conexion,"SELECT * FROM Ventas WHERE FolioVenta = '$folio' AND Serie = '$serie' AND Activo = 1");
$v = mysqli_fetch_array($gasto);




$tipoord = $v['TipoOrden'];
if($tipoord == 1){
  $tip = 'Orden';
}else if($tipoord == 2){
  $tip = 'Cotizacion';
}
$idu = $v['IdVendedor'];
$nombrea = mysqli_query($conexion,"SELECT * FROM Usuarios WHERE IdUsuario = '$idu' ");
$usu = mysqli_fetch_array($nombrea);

$usuario = $usu['Nombre'].' '.$usu['Apellidos'];
$tipofolio = $v['TipoFolio'];
$fechaventa = $v['FechaVenta'];
$idsuc = $v['IdSucursal'];
if($idsuc == 1){
    $sucn = 'SUCURSAL CULIACAN';
}else if ($idsuc == 2){
    $sucn = 'SUCURSAL MAZATLAN';
}else if($idsuc == 3){
    $sucn = 'SUCURSAL HERMOSILLO';
}
$idc = $v['IdCliente'];
$cl = mysqli_query($conexion,"SELECT * FROM Clientes WHERE IdCliente = '$idc'");
$c = mysqli_fetch_array($cl);

$nomC = $c['Nombre'];
$domC = $c['Domicilio'];
$rfcC = $c['RFC'];
$celC = $c['Celular'];
$telC = $c['Telefono'];
$ciuC = $c['Ciudad'];
$sucC = $c['IdSucursal'];
$tipoC = $c['TipoCliente'];
if($tipoC == 1){
  $tipoCliente = 'Mostrador';
}else if($tipoC == 2){
  $tipoCliente = 'Fotografo';
}

$subt = $v['Subtotal'];
$dcto = $v['Descuento'];
$total = $v['Total'];
$anti = $v['Anticipo'];
$saldo = $v['Saldo'];
$obs = $v['Obs'];
$hrent = $v['HoraEntrega'];
$fechaent = $v['FechaEntrega'];

$pdf = new PDF_Code39('P','mm',array(311,396));
$pdf->AddPage();

// PARTE DE INFORMACION
$pdf->SetFont('Arial', '', 9);
$pdf->Image('imagenes/logo.jpg' , 10 ,10, 70 , 45,'JPG');
$pdf->SetDrawColor(0,0,0);

$pdf->SetFont('Arial', 'B', 16);
$pdf->SetY(25);
$pdf->Cell(170, 8, utf8_decode($sucn), 0,0,R);
$pdf->SetFont('Arial', 'U', 20);
$pdf->Cell(110, 8, 'FOLIO: '.$serie.' '.$folio, 0,0,R);
$pdf->SetFont('Arial', 'B', 16);
$pdf->Ln(8);
$pdf->Cell(280, 8, 'Vendedor: '.utf8_decode($usuario), 0,0,R);
$pdf->Ln(6);
$pdf->Cell(280, 8, $fechaventa, 0,0,R);
$pdf->Ln(11);
$pdf->Cell(280, 8, $tipoCliente, 0,0,R);
$pdf->Line(10,60,295,60);
$pdf->Line(10,62,295,62);
$pdf->SetY(62);
$pdf->Cell(285, 8, 'Cliente:', 1,0,L);
$pdf->Ln(13);
$pdf->Cell(30, 8, 'Nombre:', 0,0,L);
$pdf->Cell(170, 8, utf8_decode($nomC), 0,0,L);
$pdf->Cell(25, 8, 'Tel. / Cel. : ', 0,0,R);
$pdf->Cell(60, 8, $telC.'/'.$celC, 0,0,R);

$pdf->Ln(13);
$pdf->Cell(30, 8, 'Domicilio: ', 0,0,L);
$pdf->Cell(170, 8, utf8_decode($domC), 0,0,L);
$pdf->Cell(25, 8, 'RFC : ', 0,0,R);
$pdf->Cell(60, 8, utf8_decode($rfcC), 0,0,R);

$pdf->SetY(100);
$pdf->Cell(20, 8, '#', 1,0,C);
$pdf->Cell(40, 8, 'MEDIDAS', 1,0,C);
$pdf->Cell(100, 8, 'PRODUCTO', 1,0,C);
$pdf->Cell(80, 8, 'OBSERVACIONES', 1,0,C);
$pdf->Cell(45, 8, 'PRECIO', 1,0,C);
$pdf->Ln(8);


$ga  = mysqli_query($conexion,"SELECT * FROM VentasDetalle WHERE IdVenta = '$folio' AND Serie = '$serie' AND Activo = 1");
while($vd = mysqli_fetch_array($ga)){
  $cant = $vd['Cantidad'];
  $largo = $vd['Largo'];
  $ancho = $vd['Ancho'];
  $umed = $vd['Umed'];
  if($umed == 1){
    $med = 'CM';
  }else if($umed == 2){
    $med = 'IN';
  }
  $prod = $vd['CodProd'];
  $cm = $vd['CrisN'];
  $ca = $vd['CrisA'];
  $ml = $vd['Ml'];
  $res = $vd['Res'];
  $pap = $vd['PapF'];
  $text = $vd['Text'];
  $canva = $vd['Canva'];
  $acri = $vd['Acrilico'];
  $dobcar = $vd['DobleCara'];
  $obspro = $vd['ObsProd'];
  $preciomold = $vd['PrecioMold'];
  $preciocrisn = $vd['PrecioCrisN'];
  $preciocrisa = $vd['PrecioCrisA'];
  $precioml = $vd['PrecioMl'];
  $preciores = $vd['PrecioRes'];
  $preciopap = $vd['PrecioPapel'];
  $preciotext = $vd['PrecioText'];
  $preciomaq = $vd['PrecioMaq'];
  $preciocanva = $vd['PrecioCanva'];
  $precioacr = $vd['PrecioAcrilico'];
  $preciodobc = $vd['PrecioDobleCara'];
  $preciotot = $vd['PrecioTotal'];

  if($cm ==1){
    $cris = 'CNS';
  }else if($cm == 2){
    $cris = 'CND';
  }
  if($ca == 1){
    $crisa = 'CA';
  }
  if($ml == 1){
    $mlu = 'MLS';
  }else if($ml== 2){
    $mlu = 'MLD';
  }
  if($res == 1){
    $resp = 'MACO3MM';
  }else if($res == 2){
    $resp = 'FB5MM';
  }else if($res == 3){
    $resp = 'PVC';
  }else if($res == 4){
    $resp = 'ALU';
  }else if($res == 5){
    $resp = 'MACO6MM';
  }else if($res == 6){
    $resp = 'MACO9MM';
  }

  if($pap == 1){
    $pape = 'EVE';
  }else if($pap == 2){
    $pape = 'MATE';
  }else if($pap == 3){
    $pape = 'PREM';
  }else if($pap == 4){
    $pape = 'ART';
  }else if($pap == 5){
    $pape = 'PERL';
  }

  if($text == 1){
    $te = 'PIEL';
  }else if($text == 2){
    $te = 'LINO';
  }else if($text == 3){
    $te = 'SAND';
  }

  if($canva == 1){
    $can = 'CANVA';
  }

  if($acri == 1){
    $ac = 'ACR';
  }

  if($dobcar == 1){
    $do = 'DC';
  }
  $n = mysqli_query($conexion,"SELECT * FROM Productos Where Codigo = '$prod'");
  $q = mysqli_fetch_array($n);
  $nom = $q['Nombre'];
  $p = $nom." ".$m." ".$cris." ".$crisa." ".$mlu." ".$resp." ".$pape." ".$te." ".$can." ".$ac." ".$do;
  $pdf->SetFontSize(16);
  $pdf->Cell(20, 8, $cant, 1,0,C);
  $pdf->Cell(40, 8, $largo.'*'.$ancho.' '.$med, 1,0,C);
  $pdf->SetFontSize(10);
  $pdf->Cell(100, 8, $p, 1,0,C);
 
  $pdf->Cell(80, 8, utf8_decode($obspro), 1,0,C);
   $pdf->SetFontSize(16);
  $preciotot = number_format($preciotot,2,'.',',');
  $pdf->Cell(45, 8, '$ '.$preciotot, 1,0,R);
  $pdf->Ln(8);
}
$pdf->SetY(242);
$pdf->Cell(285, 8, utf8_decode('Observaciones: '.$obs), 1,0,L);

$pdf->SetY(250);
$pdf->Line(10,250,295,250);
$pdf->Cell(100, 8, 'Firma del cliente', 0,0,C);
$pdf->Cell(100, 8, 'Fecha de entrega: '.$fechaent, 0,0,C);
$subt = number_format($subt,2,'.',',');
$pdf->Cell(40, 8, 'Subtotal: ', 1,0,R);
$pdf->Cell(45, 8, '$ '.$subt, 1,0,R);
$pdf->Ln(8);
if($dcto <= 0){
  $pdf->Cell(100, 8, ' ', 0,0,C);
  $pdf->Cell(100, 8, 'Hora de entrega: '.$hrent, 0,0,C);
  $total = number_format($total,2,'.',',');
  $pdf->Cell(40, 8, 'Total: ', 1,0,R);
  $pdf->Cell(45, 8, '$ '.$total, 1,0,R);
  $pdf->Ln(8);
  $pdf->Cell(100, 8, ' ', 0,0,C);
  $pdf->Cell(100, 8, ' ', 0,0,C);
  $anti = number_format($anti,2,'.',',');
  $pdf->Cell(40, 8, 'Anticipo: ', 1,0,R);
  $pdf->Cell(45, 8, '$ '.$anti, 1,0,R);
  $pdf->Ln(8);
  $pdf->Cell(100, 8, ' ', 0,0,C);
  $pdf->Cell(100, 8, ' ', 0,0,C);
  $saldo = number_format($saldo,2,'.',',');
  $pdf->Cell(40, 8, 'Saldo: ', 1,0,R);
  $pdf->Cell(45, 8, '$ '.$saldo, 1,0,R);
}else if($dcto >0){
  $pdf->Cell(100, 8, ' ', 0,0,C);
  $pdf->Cell(100, 8, 'Hora de entrega: '.$hrent, 0,0,C);
  $dc = number_format($dcto);
  $pdf->Cell(40, 8, 'Descuento: ', 1,0,R);
  $pdf->Cell(45, 8, '% '.$dc, 1,0,R);
  $pdf->Ln(8);
  $pdf->Cell(100, 8, ' ', 0,0,C);
  $pdf->Cell(100, 8, ' ', 0,0,C);
  $total = number_format($total,2,'.',',');
  $pdf->Cell(40, 8, 'Total: ', 1,0,R);
  $pdf->Cell(45, 8, '$ '.$total, 1,0,R);
  $pdf->Ln(8);
  $pdf->Cell(100, 8, ' ', 0,0,C);
  $pdf->Cell(100, 8, ' ', 0,0,C);
  $anti = number_format($anti,2,'.',',');
  $pdf->Cell(40, 8, 'Anticipo: ', 1,0,R);
  $pdf->Cell(45, 8, '$ '.$anti, 1,0,R);
  $pdf->Ln(8);
  $pdf->Cell(100, 8, ' ', 0,0,C);
  $pdf->Cell(100, 8, ' ', 0,0,C);
  $saldo = number_format($saldo,2,'.',',');
  $pdf->Cell(40, 8, 'Saldo: ', 1,0,R);
  $pdf->Cell(45, 8, '$ '.$saldo, 1,0,R);

}
$pdf->Line(10,290,295,290);
$pdf->Line(100,250,100,290);
$pdf->Line(210,250,210,290);
$pdf->SetY(315);
$pdf->SetFontSize(12);
if($suc == 1){
$pdf->Cell(295, 8, 'Expedido en: Juan Jose Rios No. 37 Ote. Col. Jorge Almada', 0,0,C);
}else if($suc == 2){
$pdf->Cell(295, 8, 'Expedido en: Av. Rafael Buelna 204-D, Hacienda las Cruces, 82126', 0,0,C);
}
$pdf->Ln(8);
if($suc == 1){
$pdf->Cell(295, 8, utf8_decode('Culiacan, Sinaloa. Tel. 712-50-05'), 0,0,C);
}else if($suc == 2){
$pdf->Cell(295, 8, utf8_decode('Mazatlán, Sinaloa. Tel. 669-112-1438'), 0,0,C);
}
$pdf->Ln(16);
$pdf->Cell(295, 8, utf8_decode('Eduardo Lee Cañedo R.F.C. LECE671223-V83'), 0,0,C);
$pdf->Ln(8);
$pdf->Cell(295, 8, utf8_decode('Juan José Rios No. 37 Ote. Col. Jorge Almada Culiacán, Sinaloa. Tel. (667) 712-50-05'), 0,0,C);
$pdf->Line(10,360,295,360);


/*
$pdf->MultiCell(80,5,'Cliente: '.$nombrec,0);
$pdf->SetX(20);
$pdf->Cell(105, 8, getSubString('Chofer: '.$nombrechofer,80), 0,0,L);
$pdf->Ln(5);
$pdf->SetX(20);
$pdf->Cell(105, 8, $nombanco.' '.$cuenta, 0,0,L);
$pdf->Ln(5);
$pdf->SetX(20);
$pdf->Cell(105, 8, 'Carro '.$carro.' Caja '.$caja, 0,0,L);
$pdf->Ln(10);
$pdf->Cell(90, 8, 'Total Gastos: $'.$totalg, 0,0,R);
$pdf->Ln(5);
$pdf->Cell(90, 8, 'Total Descuentos: $'.$totald, 0,0,R);
$pdf->Ln(5);
$pdf->Cell(90, 8, 'Total: $'.$total, 0,0,R);
$pdf->Ln(10);
$pdf->Cell(105, 8, 'Fact.: '.$factv, 0,0,L);
$pdf->Ln(6);
$pdf->Cell(105, 8, 'Fact. reg: '.$factr, 0,0,L);
$pdf->Ln(6);
$pdf->Cell(105, 8, 'Pago hecho en: '.$pago, 0,0,L);
$pdf->Ln(6);
$pdf->MultiCell(90,5,'Observaciones: '.$obs,0);
$pdf->Ln(5);

$pdf->Line(30,135,90,135);
$pdf->SetY(135);
$pdf->Cell(100, 8, getSubString($nombrechofer,80), 0,0,C);
$pdf->SetY(125);
$pdf->SetY(130);
$pdf->SetX(105);
$pdf->Cell(90, 8, getSubString('SEMANA: '.$nums.', '.$ano,80), 0,0,R);
$pdf->SetY(135);
$pdf->SetX(105);
$pdf->Cell(90, 8, getSubString('Liquidacion hecha por: '.$prueba,80), 0,0,R);

//PARTE DE GASTOS
$pdf->Line(105,35,105,140);
$pdf->SetXY(105,30);
$pdf->SetFont('Arial', 'U', 10);
$pdf->Cell(40, 8, getSubString('GASTOS',40), 0,0,C);
$pdf->SetFont('Arial', 'B', 10);
$y = 35;
if($sueldo != 0){
  $sueldo = number_format($sueldo,2,'.',',');
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Sueldo: $'.$sueldo,40), 0,0,R);
  $y = $y + 5;

}
if($casetas != 0){
  $casetas = number_format($casetas,2,'.',',');
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Casetas: $'.$casetas,40), 0,0,R);
  $y = $y + 5;
}
if($desponche != 0){
  $desponche = number_format($desponche,2,'.',',');
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Desponche: $'.$desponche,40), 0,0,R);
  $y = $y + 5;
}
if($lavcaja != 0){
  $lavcaja = number_format($lavcaja,2,'.',',');
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Lav. caja: $'.$lavcaja,40), 0,0,R);
  $y = $y + 5;
}
if($fito != 0){
  $fito = number_format($fito,2,'.',',');
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Fitosanitaria: $'.$fito,40), 0,0,R);
  $y = $y + 5;
}
if($guia != 0){
  $guia = number_format($guia,2,'.',',');
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Guia: $'.$guia,40), 0,0,R);
  $y = $y + 5;
}
if($estancia != 0){
  $estancia = number_format($estancia,2,'.',',');
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Estancia: $'.$estancia,40), 0,0,R);
  $y = $y + 5;
}
if($regcarg != 0){
  $regcarg = number_format($regcarg,2,'.',',');
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Regreso Carg.: $'.$regcarg,40), 0,0,R);
  $y = $y + 5;
}
if($pension != 0){
  $pension = number_format($pension,2,'.',',');
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Pension: $'.$pension,40), 0,0,R);
  $y = $y + 5;
}
if($comision != 0){
  $comision = number_format($comision,2,'.',',');
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Comision: $'.$comision,40), 0,0,R);
  $y = $y + 5;
}
if($bonotemp != 0){
  $bonotemp = number_format($bonotemp,2,'.',',');
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Bono temp.: $'.$bonotemp,40), 0,0,R);
  $y = $y + 5;
}
if($bonoreten != 0){
  $bonoreten = number_format($bonoreten,2,'.',',');
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Bono reten: $'.$bonoreten,40), 0,0,R);
  $y = $y + 5;
}
if($cruce != 0){
  $cruce = number_format($cruce,2,'.',',');
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Cruce: $'.$cruce,40), 0,0,R);
  $y = $y + 5;
}
if($fumi != 0){
  $fumi = number_format($fumi,2,'.',',');
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Fumigacion: $'.$fumi,40), 0,0,R);
  $y = $y + 5;
}
if($basc != 0){
  $basc = number_format($basc,2,'.',',');
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Bascula: $'.$basc,40), 0,0,R);
  $y = $y + 5;
}
if($carga != 0){
  $carga = number_format($carga,2,'.',',');
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Carga: $'.$carga,40), 0,0,R);
  $y = $y + 5;
}
if($descarga != 0){
  $descarga = number_format($descarga,2,'.',',');
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Descarga: $'.$descarga,40), 0,0,R);
  $y = $y + 5;
}
if($embarque != 0){
  $embarque = number_format($embarque,2,'.',',');
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Embarque: $'.$embarque,40), 0,0,R);
  $y = $y + 5;
}
if($permsani != 0){
  $permsani = number_format($permsani,2,'.',',');
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Perm. Sanitario: $'.$permsani,40), 0,0,R);
  $y = $y + 5;
}
if($otrosmascant != 0){
  $otrosmascant = number_format($otrosmascant,2,'.',',');
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString($otrosmas.': $'.$otrosmascant,40), 0,0,R);
  $y = $y + 5;
}


//PARTE DE GASTOS
$infonavit = $g['Infonavit'];
$prestamo = $g['Prestamo'];
$fonacot = $g['Fonacot'];
$comidas = $g['Comidas'];
$otrosmenos = $g['OtrosMenos'];
$otrosmenoscant = $g['OtrosMenosCant'];
$gastos = $g['Gastos'];
$gastosadc = $g['Gastosadic'];
$obs = $g['Obs'];

$iduser = $g['IdUsuario'];
$pdf->Line(150,35,150,110);
$pdf->SetXY(150,30);
$pdf->SetFont('Arial', 'U', 10);
$pdf->Cell(45, 8, getSubString('DESCUENTOS',40), 0,0,C);
$pdf->SetFont('Arial', 'B', 10);
$y = 35;
if($gastos != 0){
  $gastos = number_format($gastos,2,'.',',');
  $pdf->SetXY(150,$y);
  $pdf->Cell(45, 8, getSubString('Viaticos: $'.$gastos,40), 0,0,R);
  $y = $y + 5;
}
if($gastosadc != 0){
  $gastosadc = number_format($gastosadc,2,'.',',');
  $pdf->SetXY(150,$y);
  $pdf->Cell(45, 8, getSubString('Viaticos adic.: $'.$gastosadc,40), 0,0,R);
  $y = $y + 5;
}
if($infonavit != 0){
  $infonavit = number_format($infonavit,2,'.',',');
  $pdf->SetXY(150,$y);
  $pdf->Cell(45, 8, getSubString('INFONAVIT: $'.$infonavit,40), 0,0,R);
  $y = $y + 5;
}
if($prestamo != 0){
  $prestamo = number_format($prestamo,2,'.',',');
  $pdf->SetXY(150,$y);
  $pdf->Cell(45, 8, getSubString('Prestamo: $'.$prestamo,40), 0,0,R);
  $y = $y + 5;
}
if($fonacot != 0){
  $fonacot = number_format($fonacot,2,'.',',');
  $pdf->SetXY(150,$y);
  $pdf->Cell(45, 8, getSubString('FONACOT: $'.$fonacot,40), 0,0,R);
  $y = $y + 5;
}
if($comidas != 0){
  $comidas = number_format($comidas,2,'.',',');
  $pdf->SetXY(150,$y);
  $pdf->Cell(45, 8, getSubString('Comidas: $'.$comidas,40), 0,0,R);
  $y = $y + 5;
}
if($otrosmenoscant != 0){
  $otrosmenoscant = number_format($otrosmenoscant,2,'.',',');
  $pdf->SetXY(150,$y);
  $pdf->Cell(45, 8, getSubString($otrosmenos.': $'.$otrosmenoscant,40), 0,0,R);
  $y = $y + 5;
}





//DIVISION
$pdf->Line(10,148.5,200,148.5);
//DIVISION
// PARTE DE INFORMACION
$pdf->SetFont('Arial', '', 9);
$pdf->Image('../img/logo.jpg' , 10 ,155, 55 , 20,'JPG');
$pdf->SetDrawColor(0,0,0);
$pdf->SetXY(10,155);
$pdf->SetFont('Arial', 'U', 16);
$pdf->SetY(150);
$pdf->Cell(110, 8, 'CHOFER', 0,0,R);
$pdf->Cell(75, 8, 'Num. '.$id, 0,0,R);
$pdf->SetY(155);
$pdf->SetXY(10,160);
$pdf->SetFont('Arial', 'B', 14);
$pdf->Cell(120, 8, 'Bueno por: $'.$total, 0,0,R);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(65, 8, 'Fecha del viaje: '.$fechav, 0,0,R);
$pdf->SetXY(10,165);
$pdf->Cell(185, 8, 'Fecha del pago: '.$fechap, 0,0,R);
$pdf->SetXY(10,175);
$pdf->Cell(105, 8, 'Recibi(mos) de: Transportes Reasa Logist SA de CV ', 0,0,L);
$pdf->SetXY(10,180);
$pdf->Cell(105, 8, 'Por concepto de:', 0,0,L);
$pdf->SetXY(20,186);
$pdf->MultiCell(80,5,'Cliente: '.$nombrec,0);
$ydos = $pdf->GetY();
$pdf->SetXY(20,$ydos);
$pdf->Cell(105, 8, getSubString('Chofer: '.$nombrechofer,80), 0,0,L);
$ydos = $ydos + 5;
$pdf->SetXY(20,$ydos);
$pdf->Cell(105, 8, $nombanco.' '.$cuenta, 0,0,L);
$ydos = $ydos + 5;
$pdf->SetXY(20,$ydos);
$pdf->Cell(105, 8, 'Carro '.$carro.' Caja '.$caja, 0,0,L);
$ydos = $ydos + 4;
$pdf->SetXY(10,$ydos);
$pdf->Cell(90, 8, 'Total Gastos: $'.$totalg, 0,0,R);
$ydos = $ydos + 4;
$pdf->SetXY(10,$ydos);
$pdf->Cell(90, 8, 'Total Descuentos: $'.$totald, 0,0,R);
$ydos = $ydos + 4;
$pdf->SetXY(10,$ydos);
$pdf->Cell(90, 8, 'Total: $'.$total, 0,0,R);
$ydos = $ydos + 3;
$pdf->SetXY(10,$ydos);
$pdf->Cell(105, 8, 'Fact.: '.$factv, 0,0,L);
$ydos = $ydos + 4;
$pdf->SetXY(10,$ydos);
$pdf->Cell(105, 8, 'Fact. reg: '.$factr, 0,0,L);
$ydos = $ydos + 4;
$pdf->SetXY(10,$ydos);
$pdf->Cell(105, 8, 'Pago hecho en: '.$pago, 0,0,L);
$ydos = $ydos + 5;
$pdf->SetXY(10,$ydos);
$pdf->MultiCell(90,5,'Observaciones: '.$obs,0);
$ydos = $ydos + 24;
$ydos = $ydos + 6;
$pdf->Line(30,$ydos,90,$ydos);

$pdf->SetXY(10,$ydos);
$pdf->Cell(100, 8, getSubString($nombrechofer,80), 0,0,C);
$ydos = $ydos - 5;
$pdf->SetXY(105,$ydos);
$pdf->Cell(90, 8, getSubString('SEMANA: '.$nums.', '.$ano,80), 0,0,R);
$ydos = $ydos + 5;
$pdf->SetXY(105,$ydos);
$pdf->Cell(90, 8, getSubString('Liquidacion hecha por: '.$prueba,80), 0,0,R);

//PARTE DE GASTOS
$pdf->Line(105,175,105,275);
$pdf->SetXY(105,175);
$pdf->SetFont('Arial', 'U', 10);
$pdf->Cell(40, 8, getSubString('GASTOS',40), 0,0,C);
$pdf->SetFont('Arial', 'B', 10);
$y = 180;
if($sueldo != 0){
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Sueldo: $'.$sueldo,40), 0,0,R);
  $y = $y + 5;

}
if($casetas != 0){

  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Casetas: $'.$casetas,40), 0,0,R);
  $y = $y + 5;
}
if($desponche != 0){

  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Desponche: $'.$desponche,40), 0,0,R);
  $y = $y + 5;
}
if($lavcaja != 0){
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Lav. caja: $'.$lavcaja,40), 0,0,R);
  $y = $y + 5;
}
if($fito != 0){
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Fitosanitaria: $'.$fito,40), 0,0,R);
  $y = $y + 5;
}
if($guia != 0){
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Guia: $'.$guia,40), 0,0,R);
  $y = $y + 5;
}
if($estancia != 0){
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Estancia: $'.$estancia,40), 0,0,R);
  $y = $y + 5;
}
if($regcarg != 0){
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Regreso Carg.: $'.$regcarg,40), 0,0,R);
  $y = $y + 5;
}
if($pension != 0){
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Pension: $'.$pension,40), 0,0,R);
  $y = $y + 5;
}
if($comision != 0){
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Comision: $'.$comision,40), 0,0,R);
  $y = $y + 5;
}
if($bonotemp != 0){
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Bono temp.: $'.$bonotemp,40), 0,0,R);
  $y = $y + 5;
}
if($bonoreten != 0){
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Bono reten: $'.$bonoreten,40), 0,0,R);
  $y = $y + 5;
}
if($cruce != 0){
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Cruce: $'.$cruce,40), 0,0,R);
  $y = $y + 5;
}
if($fumi != 0){
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Fumigacion: $'.$fumi,40), 0,0,R);
  $y = $y + 5;
}
if($basc != 0){
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Bascula: $'.$basc,40), 0,0,R);
  $y = $y + 5;
}
if($carga != 0){
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Carga: $'.$carga,40), 0,0,R);
  $y = $y + 5;
}
if($descarga != 0){
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Descarga: $'.$descarga,40), 0,0,R);
  $y = $y + 5;
}
if($embarque != 0){
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Embarque: $'.$embarque,40), 0,0,R);
  $y = $y + 5;
}
if($permsani != 0){
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString('Perm. Sanitario: $'.$permsani,40), 0,0,R);
  $y = $y + 5;
}
if($otrosmascant != 0){
  $pdf->SetXY(105,$y);
  $pdf->Cell(44, 8, getSubString($otrosmas.': $'.$otrosmascant,40), 0,0,R);
  $y = $y + 5;
}



$pdf->Line(150,180,150,255);
$pdf->SetXY(150,175);
$pdf->SetFont('Arial', 'U', 10);
$pdf->Cell(45, 8, getSubString('DESCUENTOS',40), 0,0,C);
$pdf->SetFont('Arial', 'B', 10);
$y = 180;
if($gastos != 0){
  $pdf->SetXY(150,$y);
  $pdf->Cell(45, 8, getSubString('Viaticos: $'.$gastos,40), 0,0,R);
  $y = $y + 5;
}
if($gastosadc != 0){
  $pdf->SetXY(150,$y);
  $pdf->Cell(45, 8, getSubString('Viaticos adic.: $'.$gastosadc,40), 0,0,R);
  $y = $y + 5;
}
if($infonavit != 0){
  $pdf->SetXY(150,$y);
  $pdf->Cell(45, 8, getSubString('INFONAVIT: $'.$infonavit,40), 0,0,R);
  $y = $y + 5;
}
if($prestamo != 0){
  $pdf->SetXY(150,$y);
  $pdf->Cell(45, 8, getSubString('Prestamo: $'.$prestamo,40), 0,0,R);
  $y = $y + 5;
}
if($fonacot != 0){
  $pdf->SetXY(150,$y);
  $pdf->Cell(45, 8, getSubString('FONACOT: $'.$fonacot,40), 0,0,R);
  $y = $y + 5;
}
if($comidas != 0){
  $pdf->SetXY(150,$y);
  $pdf->Cell(45, 8, getSubString('Comidas: $'.$comidas,40), 0,0,R);
  $y = $y + 5;
}
if($otrosmenoscant != 0){
  $pdf->SetXY(150,$y);
  $pdf->Cell(45, 8, getSubString($otrosmenos.': $'.$otrosmenoscant,40), 0,0,R);
  $y = $y + 5;
}
*/

$pdf->Output($serie.' '.$num.'.pdf','I');
?>