<?php
require_once 'ApiGlobalFunctions.php';

$usuario=$_POST['uid'];
$password=$_POST['key'];
$url=$_POST['url'];
$inventario=$_POST['InvID'];
$include=includec($url);
include $include;
$validate=loginkey($usuario,$password,$url);
if($validate==1){

    mysqli_set_charset($link, "utf8");
    $tipo=diccionario($url,'LoteB');
    $bodega_field=diccionario($url,'BodAsset');
    
    $query=mysqli_query($link, "SELECT bodegas_tks_nombre
    FROM vtiger_inventario
    INNER JOIN vtiger_bodegas ON vtiger_bodegas.bodegasid=vtiger_inventario.inventario_tks_bodega
    WHERE inventarioid ='$inventario'");
    $data=mysqli_fetch_array($query);  
    $bodega=$data['bodegas_tks_nombre'];
  
    $query=mysqli_query($link, "SELECT serialnumber
    FROM vtiger_assets
    INNER JOIN vtiger_assetscf ON vtiger_assets.assetsid=vtiger_assetscf.assetsid
    INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_assets.assetsid
    WHERE $tipo<>'Individual' AND $bodega_field='$bodega' ");
    while ($row = mysqli_fetch_array($query)) {  
        $docs[]=$row['serialnumber'];
    }
    echo json_encode(setDataJSON($docs,1));
}    