Add php files
This commit is contained in:
35
modules/Home/Dashlets/MyEcmReportDashlets/updateHistoryStates.php
Executable file
35
modules/Home/Dashlets/MyEcmReportDashlets/updateHistoryStates.php
Executable file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
session_start();
|
||||
include_once( '/var/www/html/e5crm/vserver/e5crm.more7.com/www/config.php');
|
||||
include_once( '/var/www/html/e5crm/vserver/e5crm.more7.com/www/guid.php');
|
||||
$sql=mysql_connect($sugar_config['dbconfig']['db_host_name'],$sugar_config['dbconfig']['db_user_name'],$sugar_config['dbconfig']['db_password']);
|
||||
mysql_select_db($sugar_config['dbconfig']['db_name']);
|
||||
mysql_query("set names utf8");
|
||||
//mysql_query("truncate table ecmproducts_history_states");
|
||||
$date="2010-08-02";
|
||||
$www=mysql_query("select id,name from ecmstocks where deleted='0' and no='1'");
|
||||
while($rrr=mysql_fetch_array($www)){
|
||||
$stock_id=$rrr['id'];
|
||||
$ww=mysql_query("select id,code from ecmproducts where deleted='0' and code!='' order by code");
|
||||
while($rr=mysql_fetch_array($ww)){
|
||||
$v=0;
|
||||
$product_id=$rr['id'];
|
||||
$w=mysql_query("select type,quantity,price from ecmstockoperations where stock_id='".$stock_id."' and product_id='".$product_id."' and deleted='0'");
|
||||
while($r=mysql_fetch_array($w)){
|
||||
if($r['type']==0)$v+=$r['price']*$r['quantity'];
|
||||
else $v-=$r['price']*$r['quantity'];
|
||||
}
|
||||
if($v<0)$v=0;
|
||||
$set="date='".$date."',ecmproduct_id='".$product_id."',ecmstock_id='".$stock_id."',value='".$v."'";
|
||||
if(mysql_num_rows(mysql_query("select id from ecmproducts_history_states where ecmstock_id='".$stock_id."' and ecmproduct_id='".$product_id."' and date='".$date."'"))==0){
|
||||
mysql_query("insert into ecmproducts_history_states set id='".create_guid()."',".$set);
|
||||
}
|
||||
else{
|
||||
mysql_query("update ecmproducts_history_states set value='".$v."' where ecmstock_id='".$stock_id."' and ecmproduct_id='".$product_id."' and date='".$date."'");
|
||||
}
|
||||
echo $rr['code']." ".$v."\n";
|
||||
|
||||
}
|
||||
}
|
||||
mysql_close($sql);
|
||||
?>
|
||||
Reference in New Issue
Block a user