query("select id from ecmproducts where product_active='1' and deleted='0' order by product_category_name asc,code asc");
while($r=$db->fetchByAssoc($w)){
$ww=$db->query("select id from accounts where deleted='0' and core_client='1' order by name asc");
while($rr=$db->fetchByAssoc($ww)){
$rrr=$db->fetchByAssoc($db->query("select count(*) as cnt from ecmforecasts where ecmproduct_id='".$r['id']."' and account_id='".$rr['id']."'"));
if($_REQUEST['pred'][$r['id']][$rr['id']]!=0){
$value=$_REQUEST['pred'][$r['id']][$rr['id']];
if($rrr['cnt']>0){
$db->query("update ecmforecasts set value='".$value."' where ecmproduct_id='".$r['id']."' and account_id='".$rr['id']."'");
}
else{
$db->query("insert into ecmforecasts set id='".create_guid()."',ecmproduct_id='".$r['id']."',account_id='".$rr['id']."',value='".$value."'");
}
}
}
$rrr=$db->fetchByAssoc($db->query("select count(*) as cnt from ecmforecasts where ecmproduct_id='".$r['id']."' and account_id='new'"));
if($_REQUEST['pred'][$r['id']]["new"]!=0){
$value=$_REQUEST['pred'][$r['id']]["new"];
if($rrr['cnt']>0){
$db->query("update ecmforecasts set value='".$value."' where ecmproduct_id='".$r['id']."' and account_id='new'");
}
else{
$db->query("insert into ecmforecasts set id='".create_guid()."',ecmproduct_id='".$r['id']."',account_id='new',value='".$value."'");
}
}
}
header("Location: index.php?module=EcmReports&action=Forecast&category=".$_REQUEST['category']);
}
?>