<?php
require_once 'ApiGlobalFunctions.php';

$usuario=$_POST['uid'];
$password=$_POST['key'];
$url=$_POST['url'];
$cajaid=$_POST['cajaID'];
$product=$_POST['productCode'];

$include=includec($url);
include $include;

$validate=loginkey($usuario,$password,$url);
$codprod=diccionario($url,'codproduct'); 
$MovAsset=diccionario($url,'MovAsset'); 

error_log("BoxListAsset.php Usuario: ".$usuario."Password: ".$password." URL: ".$url." Caja: ".$cajaid." Producto: ".$product."\n", 3, "php.log");

if($validate==1){
    $query=mysqli_query($link,"SELECT crmid, serialnumber
    FROM vtiger_movimientos
    INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_movimientos.movimientosid
    INNER JOIN vtiger_assets ON vtiger_assets.assetsid=vtiger_movimientos.$MovAsset
    INNER JOIN vtiger_products ON vtiger_products.productid=vtiger_assets.product
    INNER JOIN vtiger_productcf ON vtiger_productcf.productid=vtiger_products.productid
    WHERE deleted='0' AND movimientos_tks_caja='$cajaid' AND $codprod='$product'");
    $num=mysqli_num_rows($query);
    if($num>0){
        $z=0;
         while ($row = mysqli_fetch_array($query)) {
            $assetid=$row['crmid'];
            $serial=$row['serialnumber'];
            $ListBox[$z]=array("assetid"=>$assetid,"serialnumber"=>$serial);

            $z++;
        }
	}else{
	    $ListBox[0]=array("assetid"=>"","serialnumber"=>"");
	}

     echo json_encode(setDataJSON($ListBox,1));
}









