<?php
require_once 'ApiGlobalFunctions.php';

$usuario=$_POST['uid'];
$password=$_POST['key'];
$url=$_POST['url'];
$slot=$_POST['slotcode'];
$include=includec($url);
include ($include);

error_log("SLOTINFO: ".$usuario."--".$password."--".$url."--".$slot."\n", 3, "php.log");


$validate=loginkey($usuario,$password,$url);
if($validate==1){   
    $campo=diccionario($url,'codproduct');    
    mysqli_set_charset($link, "utf8");
    $query=mysqli_query($link, "SELECT bodegas_tks_nombre,secciones_tks_seccion, racks_tks_rack,slotsno, slots_tks_codigo, slots_tks_fechaultimoinventari ,slots_tks_fila, slots_tks_columna,slots_tks_bodega
        FROM vtiger_slots 
        INNER JOIN vtiger_slotscf ON vtiger_slotscf.slotsid=vtiger_slots.slotsid 
        INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_slots.slotsid 
        LEFT JOIN vtiger_racks ON vtiger_racks.racksid=vtiger_slots.slots_tks_rack         
        INNER JOIN vtiger_bodegas ON vtiger_bodegas.bodegasid=vtiger_slots.slots_tks_bodega
        INNER JOIN vtiger_secciones ON vtiger_secciones.seccionesid=vtiger_slots.slots_tks_seccion
        WHERE vtiger_crmentity.deleted='0' AND slots_tks_codigo='$slot'");
    $num=mysqli_num_rows($query);    
    if($num>=1){
       $z=0;                 
        while ($row = mysqli_fetch_array($query)) {           
            $bodega=$row['bodegas_tks_nombre'];            
            $seccion=$row['secciones_tks_seccion'];
            $rack=$row['racks_tks_rack'];
            $fila=$row['slots_tks_fila'];
            $columna=$row['slots_tks_columna'];
            $slotID=$row['slotsno'];
            $slotCOD=$row['slots_tks_codigo'];
            $slots_tks_fechaultimoinventari=$row['slots_tks_fechaultimoinventari'];
            $bodegaid=$row['slots_tks_bodega'];
            
            $docs[$z]=array('Bodega'=>$bodega,'Seccion'=>$seccion,'Rack'=>$rack,'SlotID'=>$slotID,'SlotCOD'=>$slotCOD,'FechaUltimoInv'=>$slots_tks_fechaultimoinventari,'fila'=>$fila,'columna'=>$columna,'Result'=>'1','wID'=>$bodegaid);
            $z++;            
        }
    }else{
            $docs[0]=array('Bodega'=>'','Seccion'=>'','Rack'=>'','SlotID'=>'','SlotCOD'=>'','FechaUltimoInv'=>'','fila'=>'','columna'=>'','Result'=>'0','wID'=>'0');
    }
     echo json_encode(setDataJSON($docs,1));
}
