init
This commit is contained in:
133
modules/EcmStockStates/pz.php
Executable file
133
modules/EcmStockStates/pz.php
Executable file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
set_time_limit(9999999999);
|
||||
$sql=mysql_connect("localhost","root","");
|
||||
mysql_select_db("saascrm");
|
||||
mysql_query("set names utf8");
|
||||
mysql_query("truncate table ecmstockdocins");
|
||||
mysql_query("truncate table ecmstockdocinitems");
|
||||
|
||||
function addPz($row,$i,$stock_id){
|
||||
$r=mysql_fetch_array(mysql_query("select id from accounts where name like '%".$row['PLATNIK']."%' and deleted='0'"));
|
||||
$parent_id=$r['id'];
|
||||
$rd=$row['DATA'];
|
||||
$a1=explode(" ",$row['ADRES1']);
|
||||
$r=mysql_fetch_array(mysql_query("select id from ecmstockdocins where name like 'PZ ".$row['KOR_DO_WZ']."' and deleted='0'"));
|
||||
$correct_id=$r['id'];
|
||||
if($correct_id)$pre="PZKOR";
|
||||
else $pre="PZ";
|
||||
$id=create_guid();
|
||||
$arr=array(
|
||||
"id"=>$id,
|
||||
"name"=>$pre." ".$row['NR_PZ'],
|
||||
"date_entered"=>date("Y-m-d H:i:s"),
|
||||
"date_modified"=>date("Y-m-d H:i:s"),
|
||||
"document_no"=>"PZ ".$row['NR_PZ'],
|
||||
"number"=>($i+1),
|
||||
"modified_user_id"=>1,
|
||||
"assigned_user_id"=>1,
|
||||
"created_by"=>1,
|
||||
"parent_name"=>$row['DOSTAWCA'],
|
||||
"parent_id"=>$parent_id,
|
||||
"status"=>"accepted",
|
||||
"register_date"=>$rd[0].$rd[1].$rd[2].$rd[3]."-".$rd[4].$rd[5]."-".$rd[6].$rd[7],
|
||||
"parent_address_street"=>$row['ADRES2'],
|
||||
"parent_address_city"=>$a1[1],
|
||||
"parent_address_postalcode"=>$a1[0],
|
||||
"subtotal"=>($row['WARTOSC_ZAK']),
|
||||
"total"=>$row['WARTOSC_ZAK'],
|
||||
"discount"=>0,
|
||||
"ecmlanguage"=>"pl_pl",
|
||||
"template_id"=>"1d178dc6-0904-3fa3-f51b-4a4b4698a173",
|
||||
"template_name"=>"E5 Polska Sp. z o. o.",
|
||||
"stock_id"=>$stock_id,
|
||||
"currency_id"=>"PLN",
|
||||
"correct_id"=>$correct_id,
|
||||
);
|
||||
foreach($arr as $k=>$v){
|
||||
$in[]=$k."='".$v."'";
|
||||
}
|
||||
mysql_query("insert into ecmstockdocins set ".implode(",",$in));
|
||||
return $id;
|
||||
}
|
||||
|
||||
function addProductLine($id,$i,$r){
|
||||
$vats=array(
|
||||
0=>"9b783d21-5548-6653-e1d6-49610eb3f9dd",
|
||||
22=>"9c592a4a-2de0-1fa3-e082-494aeceb122c",
|
||||
7=>"bf3a5fec-435f-af22-024a-4958b51863c8",
|
||||
);
|
||||
$rr=mysql_fetch_array(mysql_query("select id from ecmproducts where code like '".$r['INDEKS']."' and deleted='0'"));
|
||||
$pid=$rr['id'];
|
||||
if($pid==""){
|
||||
$pid=addProduct($r['INDEKS'],$r['NAZWA']);
|
||||
}
|
||||
$iid=create_guid();
|
||||
if(!$r['RABAT'])$rabat=0;
|
||||
else $rabat=$r['RABAT'];
|
||||
$arr=array(
|
||||
"id"=>$iid,
|
||||
"date_entered"=>date("Y-m-d H:i:s"),
|
||||
"date_modified"=>date("Y-m-d H:i:s"),
|
||||
"deleted"=>0,
|
||||
"modified_user_id"=>1,
|
||||
"assigned_user_id"=>1,
|
||||
"created_by"=>1,
|
||||
"ecmstockdocin_id"=>$id,
|
||||
"ecmproduct_id"=>$pid,
|
||||
"position"=>$i,
|
||||
"code"=>$r['INDEKS'],
|
||||
"name"=>str_replace("'","",$r['NAZWA']),
|
||||
"quantity"=>$r['ILOSC'],
|
||||
"price"=>$r['CENA_ZAK'],
|
||||
"discount"=>$rabat,
|
||||
"total"=>$r['WART_ZAK'],
|
||||
"dd_unit_name"=>$r['NAZWA_J_M'],
|
||||
"dd_unit_id"=>1,
|
||||
"ecmvat_id"=>$vats[$r['VAT']],
|
||||
"ecmvat_value"=>$r['VAT'],
|
||||
"ecmvat_name"=>$r['VAT']."%",
|
||||
"currency_id"=>"PLN",
|
||||
"currency_name"=>"PLN",
|
||||
);
|
||||
foreach($arr as $k=>$v){
|
||||
$in[]=$k."='".$v."'";
|
||||
}
|
||||
mysql_query("insert into ecmstockdocinitems set ".implode(",",$in));
|
||||
if(mysql_error()){
|
||||
echo mysql_error()."\n".implode(",",$in);
|
||||
}
|
||||
return $iid;
|
||||
}
|
||||
|
||||
|
||||
include_once("class.dbf.php");
|
||||
include_once("helper.php");
|
||||
|
||||
$w=mysql_query("select id,name,dir from ecmstocks where deleted='0'");
|
||||
while($r=mysql_fetch_array($w)){
|
||||
|
||||
$dbf = new dbf_class('klk/'.$r['dir'].'/_pz.dbf');
|
||||
$num_rec=$dbf->dbf_num_rec;
|
||||
|
||||
$dbfp = new dbf_class('klk/'.$r['dir'].'/_pz_list.dbf');
|
||||
$num_recp=$dbfp->dbf_num_rec;
|
||||
|
||||
$n=0;
|
||||
for($i=0; $i<$num_rec; $i++){
|
||||
$row = $dbf->getRowAssoc($i);
|
||||
$id=addPz($row,$i,$r['id']);
|
||||
|
||||
echo $i."/".$num_rec." ".$r['dir']." [".$row['NR_PZ']."]\n";
|
||||
|
||||
for($j=$n; $j<$num_recp; $j++){
|
||||
$rowp = $dbfp->getRowAssoc($j);
|
||||
if($row['NR_SYSTEM']==$rowp['NR_SYSTEM']){
|
||||
$lid=addProductLine($id,$j,$rowp);
|
||||
$n++;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
}
|
||||
}
|
||||
mysql_close($sql);
|
||||
?>
|
||||
Reference in New Issue
Block a user