$qty)$diff_minus+=$qty-$rsale['quantity']*$rsale['price']; if($rsale['quantity']*$rsale['price']<$qty)$diff_plus+=$qty-$rsale['quantity']*$rsale['price']; $sum[$rsale['ecmproduct_id']]['wz']+=$qty; $sum[$rsale['ecmproduct_id']]['sale']+=$rsale['quantity']*$rsale['price']; } } } $percent=number_format((100*$sum_wz_qty/$sum_sale_qty),2,",",".")."%"; $rst=0; $rwt=0; $diff_plus=$diff_minus=0; $ww=mysql_query("select id,product_category_id from ecmproducts where deleted='0' order by code asc"); while($rr=mysql_fetch_array($ww)){ $k=$rr['id']; if(!$sum[$k])continue; $rst+=$sum[$k]['sale']; $rwt+=$sum[$k]['wz']; $cst[$rr['product_category_id']]+=$sum[$k]['sale']; $cwt[$rr['product_category_id']]+=$sum[$k]['wz']; if($sum[$k]['sale']>$sum[$k]['wz'])$diff_minus+=$sum[$k]['wz']-$sum[$k]['sale']; if($sum[$k]['sale']<$sum[$k]['wz'])$diff_plus+=$sum[$k]['wz']-$sum[$k]['sale']; } $ww=mysql_query("select id,name from ecmproductcategories where deleted='0' order by name asc"); while($rr=mysql_fetch_array($ww)){ $k=$rr['id']; if($cwt[$k]<$cst[$k])$color="red"; elseif($cwt[$k]>$cst[$k])$color="green"; else $color="black"; $set="date='".$mdate."',product_category_id='".$rr['id']."',value_sale='".$cst[$k]."',value_wz='".$cwt[$k]."'"; if(mysql_num_rows(mysql_query("select id from ecmproductcategories_realisation where product_category_id='".$rr['id']."' and date like '".$mdate."%'"))==0){ mysql_query("insert into ecmproductcategories_realisation set id='".create_guid()."',".$set); } else mysql_query("update ecmproductcategories_realisation set ".$set." where product_category_id='".$rr['id']."' and date like '".$mdate."%'"); echo $rr['name']."\n"; } $set="date='".$mdate."',product_category_id='diff_minus',value_sale='".$diff_minus."'"; if(mysql_num_rows(mysql_query("select id from ecmproductcategories_realisation where product_category_id='diff_minus' and date like '".$mdate."%'"))==0){ mysql_query("insert into ecmproductcategories_realisation set id='".create_guid()."',".$set); } else mysql_query("update ecmproductcategories_realisation set ".$set." where product_category_id='diff_minus' and date like '".$mdate."%'"); $set="date='".$mdate."',product_category_id='diff_plus',value_sale='".$diff_plus."'"; if(mysql_num_rows(mysql_query("select id from ecmproductcategories_realisation where product_category_id='diff_plus' and date like '".$mdate."%'"))==0){ mysql_query("insert into ecmproductcategories_realisation set id='".create_guid()."',".$set); } else mysql_query("update ecmproductcategories_realisation set ".$set." where product_category_id='diff_plus' and date like '".$mdate."%'"); mysql_close($sql); ?>