<?php

require_once 'ApiGlobalFunctions.php';

$usuario="47";
$password="6CDrYRrL34P05XL";
$url="http://smxdevel.globalb.co";
$include=includec($url);
include ($include);

mysqli_set_charset($link, "utf8");

$query=mysqli_query($link,"SELECT cf_1799,SUM(cf_1801) as suma
	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 
	WHERE deleted='0' AND cf_1799>'1' AND cf_1801>'1' group BY 1");
 while ($row = mysqli_fetch_array($query)) {
        $producto=$row['cf_1799'];
        $cantidad=$row['suma'];
        mysqli_query($link,"UPDATE vtiger_products SET qtyinstock='$cantidad' WHERE productid='$producto'");
        mysqli_query($link,"UPDATE vtiger_productcf SET cf_1842='$cantidad' WHERE productid='$producto'");
    }