init
This commit is contained in:
68
modules/EcmStockStates/us.php
Executable file
68
modules/EcmStockStates/us.php
Executable file
@@ -0,0 +1,68 @@
|
||||
<?
|
||||
set_time_limit(9999999999);
|
||||
|
||||
$re="RE01439";
|
||||
|
||||
$sql=mysql_connect("localhost","root","");
|
||||
mysql_select_db("saascrm");
|
||||
include_once("helper.php");
|
||||
mysql_query("truncate table ecmstockstates");
|
||||
mysql_query("set names utf8");
|
||||
|
||||
$w=mysql_query("select id,name,dir from ecmstocks where deleted='0'");
|
||||
while($r=mysql_fetch_array($w)){
|
||||
$stock_id=$r['id'];
|
||||
$ww=mysql_query("select id,code,name from ecmproducts where deleted='0'");
|
||||
while($rr=mysql_fetch_array($ww)){
|
||||
$product_id=$rr['id'];
|
||||
$product_name=$rr['name'];
|
||||
$product_code=$rr['code'];
|
||||
//if($product_code!=$re)continue;
|
||||
$w=mysql_query("select quantity,price,type from ecmstockoperations where stock_id='".$stock_id."' and product_id='".$product_id."' and deleted='0'");
|
||||
$q=0;
|
||||
$p=0;
|
||||
$i=0;
|
||||
$pp=0;
|
||||
$qq=0;
|
||||
while($r=mysql_fetch_array($w)){
|
||||
if($r['type']==0){
|
||||
$q+=$r['quantity'];
|
||||
$pp+=$r['quantity']*$r['price'];
|
||||
$i++;
|
||||
}
|
||||
elseif($r['type']==1){
|
||||
$q-=$r['quantity'];
|
||||
$pp-=$r['quantity']*$r['price'];
|
||||
}
|
||||
}
|
||||
mysql_query("delete from ecmstockstates where stock_id='".$stock_id."' and product_id='".$product_id."' and deleted='0'");
|
||||
|
||||
$rrr=mysql_fetch_array(mysql_query("select name from ecmstocks where id='".$stock_id."'"));
|
||||
$stock_name=$rrr['name'];
|
||||
if($q>0)$avg_price=($pp/$q);
|
||||
else $avg_price=0;
|
||||
$arr=array(
|
||||
'id'=>create_guid(),
|
||||
'name'=>'',
|
||||
'date_entered'=>date("Y-m-d H:i:s"),
|
||||
'date_modified'=>date("Y-m-d H:i:s"),
|
||||
'created_by'=>1,
|
||||
'assigned_user_id'=>1,
|
||||
'product_id'=>$product_id,
|
||||
'product_name'=>$product_name,
|
||||
'product_code'=>$product_code,
|
||||
'stock_id'=>$stock_id,
|
||||
'stock_name'=>$stock_name,
|
||||
'quantity'=>$q,
|
||||
'price'=>$avg_price,
|
||||
);
|
||||
$se=array();
|
||||
foreach($arr as $k=>$v){
|
||||
$se[]=$k."='".$v."'";
|
||||
}
|
||||
echo $product_code." ".$q." ".$avg_price."\n";
|
||||
mysql_query("insert into ecmstockstates set ".implode(",",$se));
|
||||
}
|
||||
}
|
||||
mysql_close($sql);
|
||||
?>
|
||||
Reference in New Issue
Block a user