<?php 
declare(strict_types=0);
foreach($_GET  as $key => $value){${$key}=trim($value);} 
foreach($_POST as $key => $value){${$key}=trim($value);} 
include_once('lib_main.php');

if(!empty($empr)){$link_data=msql_connect('','','',$empr); $cfg_empr=$empr;}
$user_codigo=$_SESSION['user_codigo'];
$user0=data_maes('user',$user_codigo);
$empr0=data_maes('empr',$cfg_empr);
if(empty($user_codigo)){include('user_login0.php');return;}

$fase1=$fase;

$modu='otbj';
$info='otdet2';
$info_descri='ORDEN TRABAJO';

if(empty($ptov)){$ptov='001001';}
     
if(empty($user0['user_tipo'])){$cost='false';}

if(!mb_stristr2('.sist.supe',$user0['user_tipo']))
{
     $sql_acce='select * from acce1 left join acce2 on idnum1=idnum2 where numero='.$user_codigo.' and docum="COST" and info=1';
     $res_acce=msql_query($sql_acce,$link_data);
     if(msql_num_rows($res_acce)==0){$cost='false';}
}

$docu0=data_maes('docu',$docu);
$enti0=data_maes('enti',$enti);

$plvh=strtoupper($plvh);
$vinn=strtoupper($vinn);

$plvh0=data_maes('plvh',$plvh);
if(!empty($plvh0['plvh_vinn'])){$vinn=$plvh0['plvh_vinn'];}

$vinn0=data_maes('vinn',$vinn);
if(!empty($vinn0['vinn_plvh'])){$plvh=$vinn0['vinn_plvh'];}



$modu=strtolower($modu);
$tabla=$modu;

// if(@mb_stristr2('.otbj',$modu)){$tabla='otbj';}


if(!empty($idnum1))
{
     $sql_docu='select * from '.$tabla.'1 left join '.$tabla.'2 on idnum1=idnum2 where idnum1="'.$idnum1.'" order by iddet desc limit 1';
     $res_docu=msql_query($sql_docu,$link_data);
     $data_docu=msql_fetch_assoc($res_docu);
     foreach($data_docu as $campo => $valor){${$campo}=trim($valor);} 
}


$modu=strtolower($modu);  
$xtitulo='ORDEN TRABAJO';
if($modu=='otbj'){$xtitulo='ORDEN TRABAJO';}


$xtitle='REG.'.$xtitulo;
$xtopcenter=$xtitle;

$fecha0=fecha0($modu);
if(empty($fecha)){$fecha=date('Y-m-d');}
$fecha_min=date('Y-m-d',strtotime('-360 days'));
{$fecha1=date('Y-m-d',strtotime('-360 days'));}
if(empty($fecha2))
{$fecha2=date('Y-m-d');}

$dom = new DOMDocument();
     $dom->encoding = 'utf-8';
     $dom->xmlVersion = '1.0';
     $dom->formatOutput = true;

echo $dom->saveXML();



//  SELECT DB
// if(!empty($plvh))
// echo '===='.$docu;
if(!empty($docu)  and !empty($ptov) and !empty($numero))
{include('sele_info.php');}


if(1==2)
if(!empty($sql_info))
{
     $sql_info=str_replace('order by ','order by fecha desc, idnum1 desc, iddet desc, ',$sql_info);
     $res_info=msql_query($sql_info,$link_data);
     if(msql_num_rows($res_info)==0)
     {
//           if($fecha1!=$fecha2)
//           {
//                $fechax=fechax(7,'hcli','','',$enti);
//                $sql_info=str_replace($fecha1,$fechax,$sql_info);
//                $res_info=msql_query($sql_info,$link_data);
//                $fecha1=$fechax;
//           }
     }
     
     if(msql_num_rows($res_info)==0)
     {
          if($fecha1!=$fecha2)
          {
               $sql_info=str_replace($fecha1,$fecha0,$sql_info);
               $res_info=msql_query($sql_info,$link_data);
          }
     }
     $msgres=number_format(msql_num_rows($res_info)).' Resultado(s)...';
}



if(!empty($sql_info))
{
     $sql_info=str_replace('order by ','order by fecha desc, idnum1 desc, iddet desc, ',$sql_info);
     $sql_info1=$sql_info;
     $sql_info1=str_replace('group by idnum1,iddet','group by idnum1',$sql_info1);
     $sql_info1=str_replace('group by idnum1,iddet','group by idnum1',$sql_info1);
     $res_info1=msql_query($sql_info1,$link_data);
     
     $total=msql_result($res_info1,0,'total');
//      $tiva=msql_result($res_info1,0,'iva');
//      $subt_iva=msql_result($res_info1,0,'subt_iva_hide');
//      $subt_iva0=msql_result($res_info1,0,'subt_iva0_hide');
     
//      $claveacc=msql_result($res_info1,0,'claveacc_hide');
     $iuser=msql_result($res_info1,0,'iuser_hide');
     
     if(msql_num_rows($res_info1)!=0)
     {
//           $subt_iva0=number_format($subt_iva0,2);
//           $subt_iva=number_format($subt_iva,2);
//           $tiva=number_format($tiva,2);
          $total=number_format($total,2);
     }

//      echo '==='.$sql_info;
     
     $res_info=msql_query($sql_info,$link_data);
     if(!empty($numero))
     {
          $idnum1=msql_result($res_info,0,'idnum1_hide');
          $edit=msql_result($res_info,0,'b_o');
          

          $data_head=data_docu($docu,$idnum1);
          foreach($data_head as $key => $value){${$key}=trim($value);} 
          
          $nombre='';
          $email='';
          $wsapp='';
          
     }
}


$fase=$fase1;
// echo '*/*/*'. $sql_info;

// PANTALLA FILTROS
echo '<div id="filtros" noprint >';
{
     echo '<div hide>';     
     {
     echo '<input id="idnum1" value="'.$idnum1.'">';
//      echo '<input id="fecha1" value="'.$fecha1.'">';
//      echo '<input id="fecha2" value="'.$fecha2.'">';
     }
     echo '</div>';     

//      =maes_view('enti');
// $ztabla='enti';
// include('ele_datalist.php');
     
$ztabla='plvh';
include('ele_datalist.php');
     
$ztabla='vinn';
include('ele_datalist.php');
     
$ztabla='docu';
$zwhere='(docu_tabla="otbj")';
include('ele_datalist.php');

     
     
$zobj=2;     
include('ele_break.php');

$zid='btn_nuevo'; 
$zlabel='Nuevo';
$zalign='right';
$zonclick='{fn_nuevo();}';
$zsize=1.5;     
include('ele_button.php');
     
$zid='btn_print'; 
$zsize=1.5;     
$zalign='right';
$zlabel='Imprimir';
$href='?scri=info_docu3&prnt=1&docu='.$docu.'&idnum='.$idnum1.'&formato=';  
$zonclick='{print_url("'.$href.'");}';
if(empty($idnum1)){$zhide=1;}     
include('ele_button.php');
     

     
     
$zid='fecha';
$ztype='date';
$zlabel='Fecha';
$zvalue=$fecha;
$zdefa=date('Y-m-d');
$zmin=$fecha_min;     
$zmax=$fecha2; 
$zreado=2;   
if(!empty($numero)){$zreado=1;}     
$zhide=1;     
include('ele_input.php');  
     
     
     
// $docu='HCLI';    
$zobj=1;
$zsize=1.2;     
$zid='docu';
$ztabla='docu';
$zlabel='Documento';
$zwhere='(docu_tabla="'.$modu.'")';
$zvalue=$docu; 
if(!empty($docu)){$zreado=2;}     
$zonblur='{location.href="?scri='.basename(__FILE__,'.php').'&docu="+document.getElementById("docu").value+"&plvh="+document.getElementById("enti").value;}';
$zonchange=$zonblur;
include('ele_select.php');
     
          
$zid='ptov';
$ztabla='ptov';
$zlabel='Pto.Emi.';
$zvalue=$ptov; 
// $zhide=1;    
$zreado=2;     
include('ele_select.php');     

$zid='numero';
$zlabel='Numero';
$zvalue=$numero;
$zvalue=(int)$numero;
$zclass='numeric-int';
$zmin=1;
$zmax=9999999;     
$zreado=2;     
$zondblclick='{document.getElementById("'.$zid.'").style.width="'.round(7*2/3,2).'em";}';     
// $zonblur='{if(document.getElementById("'.$zid.'").getAttribute("disabled")!=""){document.getElementById("idnum1").value="";}}';
$zonchange='{fn_consulta(event);}';
$zbackcolor='grey';
$zfontcolor='white';
$zsize=1.2;     
// $zhide=1;     
include('ele_input.php');
     
     
     
     
$zobj=2;     
$zsize=1;     
include('ele_break.php');
     
     
$zid='plvh';
$ztabla='plvh';
$zlabel='Placa';
$ztabla='plvh';
$zvalue=$plvh; 
$zonblur='{location.href="?scri='.basename(__FILE__,'.php').'&docu="+document.getElementById("docu").value+"&plvh="+document.getElementById("plvh").value+"&vinn="+document.getElementById("vinn").value;}';
$zonchange=$zonblur;
if(!empty($plvh)){$zreado=2;}     
include('ele_input.php');

     
// $zobj=1;
// $zsize=1;     
// include('ele_break.php');

     
$zid='vinn';
$ztabla='vinn';
$zlabel='🔢 VINN';
$ztabla='vinn';
$zvalue=$vinn; 
$zonblur='{location.href="?scri='.basename(__FILE__,'.php').'&docu="+document.getElementById("docu").value+"&plvh="+document.getElementById("plvh").value+"&vinn="+document.getElementById("vinn").value;}';
$zonchange=$zonblur;
if(!empty($vinn)){$zreado=2;}
include('ele_input.php');

     
     

     
     
     
     
     
     
     
// if(!empty($plvh) )
{
     
$zid='btn_consul'; 
$zlabel='Consultar';
$zalign='right';
$zonclick='{fn_consulta(event);}';
$zhide=1;     
// $zonclick='{document.getElementById("fecha1").value="";document.getElementById("fecha2").value="";fn_consulta(event);}';
include('ele_button.php');

echo '<span style="float:right; white-space:nowrap;">';     
// echo $msgres;
echo '</span>';     
     
     
$zobj=2;     
$zsize=1;     
include('ele_break.php');

     
     
$zlabel='Marca';
$zvalue=$vinn0['vinn_mrca'];
if(empty($zvalue))
{$zvalue=$plvh0['plvh_mrca'];}
$zreado=1;
include('ele_input.php');

$zlabel='Modelo';
$zvalue=$vinn0['vinn_modelo'];
if(empty($zvalue))
{$zvalue=$plvh0['plvh_modelo'];}
$zreado=1;
include('ele_input.php');

$zlabel='Año';
$zvalue=$enti0['vinn_anio'];
if(empty($zvalue))
{$zvalue=$plvh0['plvh_anio'];}
$zmin=1960;
$zmax=date('Y');     
$zreado=1;
include('ele_input.php');

     
     
$zobj=1;     
$zsize=1;     
include('ele_break.php');
     
     
$zid='enti';
$ztabla='enti';
$zlabel='Cliente';
$zvalue=$enti; 
if(!empty($plvh)){$zreado=2;}     
// $zsize=1.5;     
include('ele_input.php');

$zid='tarifa';
$zlabel='Tarifa';
$zoptions='';     
$zoptions.='Cliente;';     
$zoptions.='Interna;';     
$zoptions.='Garantía;';     
$zexact=1;     
// $zsize=1.2;   
// $zalign='right';     
include('ele_select.php');
     
$zid='pmmoo';
$zlabel='P.M.O.';
$ztitle='Precio Mano de Obra';     
$zvalue=$pmmoo;     
$zclass='numeric-dec';
// $zdefa=1;     
$zmin=0;
$zmax=999;
if(!empty($zvalue)){$zreado=2;}     
if(!empty($idnum1))
{
     $zsave=1;
     $zsavei=$idnum1;
     $zsavet=$tabla ;
     $zsavef=$zid;
}
     
include('ele_input.php');
     

     
     
$zid='btn_grabar'; 
$zlabel='Grabar';
$zalign='right';
$zonclick='{save_docu(event);}';
$zsize=1.5;
include('ele_button.php');
     
     
     
$zobj=1;
$zsize=1;     
include('ele_break.php');

     


// if($docu!='OT10')
if(empty($fase))     
{
//      $sql_ot10='select * from otbj1 left join otbj2 on idnum1=idnum2 ';
//      $sql_ot10=calc_fields($tabla,$sql_ot10);
//      $sql_ot10.='where docu="OT10" order by idnum1 desc, idate2 desc limit 1';
//      $res_ot10=msql_query($sql_ot10,$link_data);
//      $ot10=msql_fetch_assoc($res_ot10);     

//      $ufase=msql_result($res_ot10,0,'fase');
//      if(!empty($ufase)){$fase=$ufase;}
}
     
     
$zobj=2;     
include('ele_break.php');

     
     
$zobj=4; 
$zid='fecha1';
$ztype='date';
$zlabel='Fecha';
$zvalue=date('Y-m-d');     
$zdefa=date('Y-m-d');     
$zmin=$fecha_min;     
$zmax=$fecha2; 
$zreado=2;   
include('ele_input.php');  
     
$zobj=4; 
$zid='hora1';
$ztype='time';
$zlabel='Hora';
$zvalue=date('H:i');
$zdefa=date('H:i');
$zmin=date('H:i',strtotime('-500 minutes'));
$zmax=date('H:i',strtotime('+5 minutes'));
$zreado=2;   
include('ele_input.php');

     
     
     
     
     
     
     
if(empty($fase)){$fase='recepcion';}     
$zobj=4; 
$zsize=1.2;     
$zid='fase';
$zlabel='🧑🏼‍🔧 Fase';
$zvalue=$fase;
$zoptions='';     
     
// 🧐🕵🏻‍♂️     🛠️🩺
     
$zoptions.='recepcion,⬇️ Recepción;';
if((int)$numero>0)
{
     $zoptions.='diagnostico,👨‍🔧 Diagnóstico;';
     $zoptions.='trabajo,🧰 Trabajo;';
     $zoptions.='repuesto,🔩 Repuesto;';
     $zoptions.='contrato,📜 Contrato;';
     $zoptions.='calidad,🦺 Calidad;';
     $zoptions.='entrega,⬆️ Entrega;';
}
     
// $zoptions.='recepcion,Recepción;';
// $zoptions.='diagnostico,Diagnóstico;';
// $zoptions.='trabajo,Trabajo;';
// $zoptions.='inspeccion,Inspección;';
// $zoptions.='entrega,Entrega;';
$zexact=1;     
$zonchange='{location.href="?scri='.basename(__FILE__,'.php').'';
$zonchange.='&docu="+document.getElementById("docu").value+"';
$zonchange.='&idnum1="+document.getElementById("idnum1").value+"';
$zonchange.='&numero="+document.getElementById("numero").value+"';
$zonchange.='&plvh="+document.getElementById("plvh").value+"';
$zonchange.='&vinn="+document.getElementById("vinn").value+"';
$zonchange.='&fase="+document.getElementById("fase").value;}';
// $zonblur.='}';
// $zonchange=$zonblur;
include('ele_select.php');     
     
     
     

     
     

// $zobj=1;     
// include('ele_break.php');
     
     
     

     
     
     
     
// $zobj=1;     
// include('ele_break.php');

if($fase=='recepcion')     
{
     $zobj=4;
     $zid='reservorio';
     $zlabel='⛽ Reservorio';
     $zvalue=$reservorio;
     $zoptions='';
     $zoptions.='0.25,1/4;';
     $zoptions.='0.50,1/2;';
     $zoptions.='0.75,3/4;';
     $zoptions.='1,FULL;';
//      $zoptions.='1,1/4;';
//      $zoptions.='2,1/2;';
//      $zoptions.='3,3/4;';
//      $zoptions.='4,FULL;';
     include('ele_select.php');
     
     $zobj=4;
     $zid='odometro';
     $zlabel='🛣️ Odómetro';
     $zvalue=$odometro;
     $zclass='numeric-int';
     $zmin=0;
     $zmax=500000;
     $zstep=10;
     include('ele_input.php');
     
     $zobj=4;
     $zid='horometro';
     $zlabel='🕰️ Horómetro';
     $zvalue=$horometro;
     $zclass='numeric-int';
     $zmin=0;
     $zmax=500000;
     $zstep=10;
     include('ele_input.php');
     
     
     
}     
     
if($fase=='trabajo')     
{
     $ztabla='item';
     $zwhere='(item_lsub like "MMOO%")';
     include('ele_datalist.php');
     
     
     $zobj=4;
     $zid='item';
     $zlabel='🧰 Trabajo';
     $ztabla='item';
     $zvalue='';
     $zvalue=$item;
     include('ele_input.php');
     
     $cant=1;
     $zobj=4;
     $zid='cant';
     $zlabel='Cant.';
     $zvalue=1;
     $zdefa=1;
     $zmin=0;
     $zmax=9999;
     $zclass='numeric-int';
     $zhide=1;
     include('ele_input.php');

     $ztabla='mcnc';
     include('ele_datalist.php');
     
     
     $zobj=4;
     $zid='mcnc';
     $zlabel='👨‍🔧 Mecánico';
     $ztabla='mcnc';
     $zvalue='';
     include('ele_input.php');
     
     
}     

if($fase=='repuesto')     
{
     $ztabla='item';
     $zwhere='(item_lsub not like "MMOO%")';
     include('ele_datalist.php');
     
     
     $zobj=4;
     $zid='item';
     $zlabel='🔩 Repuesto';
     $ztabla='item';
     $zvalue='';
     include('ele_input.php');
     
     $cant=1;
     $zobj=4;
     $zid='cant';
     $zlabel='Cant.';
     $zvalue=1;
     $zdefa=1;
     $zmin=0;
     $zmax=99;
     $zclass='numeric-int';
     $zhide=1;
     include('ele_input.php');

     
     
}     
     
if($fase=='contrato')     
{
     $ztabla='item';
     $zwhere='(item_lsub like "MMOO%")';
     include('ele_datalist.php');
     
     
     $zobj=4;
     $zid='item';
     $zlabel='🧰 Trabajo';
     $ztabla='item';
     $zvalue='';
     include('ele_input.php');
     
     $cant=1;
     $zobj=4;
     $zid='cant';
     $zlabel='Cant.';
     $zvalue=1;
     $zdefa=1;
     $zmin=0;
     $zmax=9999;
     $zclass='numeric-int';
     $zhide=1;
     include('ele_input.php');

     
     $ztabla='prov';
     include('ele_datalist.php');
     
     $zobj=4;
     $zid='prov';
     $zlabel='👨‍🔧 Proveedor';
     $ztabla='prov';
     $zvalue='';
     include('ele_input.php');
     

     $cant=1;
     $zobj=4;
     $zid='porc';
     $zlabel='%';
     $zvalue=1;
     $zdefa=1;
     $zmin=0.00;
     $zmax=99.99;
     $zclass='numeric-dec';
     include('ele_input.php');
     
     
}     

     
     
$zobj=1;     
include('ele_break.php');

     
// if(!mb_stristr2('.vitales.medible.explora.vacunas.medica.examen',$fase))
{
     $zobj=4;
     $zsize=1.2;
     $zid='detalle';
     $zlabel='Notas';
     $zwidth=20;    
     $zrows=2;     
     $zvalue=$detalle;
     include('ele_input.php');

     
     
}

     
     
     
// $zid='examen';
// $zlabel='Examenes';
// $zwidth=25; 
// $ztype='area';     
// $zvalue=$examen;
// // $zrows=4;     
// include('ele_input.php');
     
// $zid='diagnostico';
// $zlabel='Diagnóstico';
// $zwidth=25; 
// $ztype='area';     
// $zvalue=$diagnostico;
// // $zrows=4;     
// include('ele_input.php');
     

}

     
$zobj=2;     
include('ele_break.php');
     
     
// TITULO     
{
// $ztitulo=$xtitulo;     
// include('ele_title.php');
     
//      $zid='orden';
//      $zvalue=$orden;
//      $zlabel='Ordenar X';
//      $zoptions='';
//      if($modu=='inve')     
//      {
//           $zoptions.='Linea;';
//      }     
//      if($modu=='vtas')     
//      {
//           $zoptions.='Zona;';
//           $zoptions.='Linea;';
//      }
//      if($modu=='comp')     
//      {
//           $zoptions.='T.Prov.;';
//           $zoptions.='CAIR;';
//      }
//      $zoptions.='Código;';
//      $zoptions.='Nombre;';


//      $zonchange='{fn_consulta(event);}';
//      $zalign='right';
//      include('ele_select.php');

}
     
     

}     
// include('ele_break.php');
echo '</div>';


// RESULTADO
echo '<div id="main2" >';

$sql_idx=1;

for($idx=1; $idx<=$sql_idx; $idx++)
{
     if(gettype($res_info)!='NULL')
     {
          $zreso=$res_info;
          $zinfo=$info;
          $zname=$zname;
          $zhead=0;
          $zgfsize=0.9;
          $zhidebtns=1;
//           $zblockrows=3;
          $zheightrow='3';
          $zblockidnum=1;
//           $zwidthtable='100%';
          include('ele_grid.php');     
          
//           if($info=='bbkrdx')
//           {if($idx<msql_num_rows($res_krdx)){echo '<div id="pgbreak" style="height:2em;"></div>';}}

     }
}     

echo '</div>';     
echo '<div style="clear:both;">&#127380; : '.$idnum1.'</div>';

?>

<script>
function fn_consulta(event)
{
     var xhref='',dataget;
     xhref=xhref+'?scri=<?php echo basename(__FILE__,'.php');?>';
     
     dataget=new_FormData('filtros','get');
     xhref=xhref+dataget;
     
     document.getElementById("main2").innerHTML='Espere...';
     location.href=xhref;
     
}
</script>

<script>
// function save_docu(event)
// {
// //      var xhref='',datapost;
// //      xhref=xhref+'?scri=<?php //echo basename(__FILE__,'.php');?>';
     
//      var datapost;
//      datapost=new_FormData('filtros','post');
//      datapost.append('script','save_docu');
//      document.getElementById("main2").innerHTML='Espere...';
//      exe_ajax(datapost,'','',true);
//      window.location.reload();
     
// }
</script>

<script>
function fn_nuevo(event)
{
     var enti;
     swal.fire({
          icon:'warning',
          title:'Nuevo Documento',
          text:'Continuar ?',
          confirmButtonText:'Nuevo',
          confirmButtonColor:color1,
          focusCancel:true,
          showCancelButton:true,
          cancelButtonColor: 'darkred',
          timer:60000
     }).then((result) => 
          {
               if(result.isConfirmed)
               {
                    document.getElementById("fecha").value="";
                    document.getElementById("numero").value="";
                    document.getElementById("idnum1").value="";
                    enti=document.getElementById("enti").value;
     //                if(enti.indexOf("9999999999")<0)
                    {document.getElementById("enti").value="";}
                    {document.getElementById("plvh").value="";}
                    {document.getElementById("vinn").value="";}
                    fn_consulta(event);
               }
          })
}     
     
</script>



<script>document.title="<?php echo $xtitle;?>"</script>
<script>document.getElementById('topcenter').innerHTML="<?php echo $xtopcenter;?>"</script>
<!-- <script>opt_list_plan();</script> -->
<!-- <script>set_noback();</script> -->
<!-- <script>window.onbeforeunload = function(){return 'Are you sure you want to leave?';};</script> -->

