Files
crm.twinpol.com/import/import/import_kontrahentow_dostaw.php
2025-05-12 15:44:39 +00:00

106 lines
3.1 KiB
PHP

<?php
ini_set('display_errors',1);
include_once("class.dbf.php");
include_once("helper.php");
$sugar_config = array(
'dbconfig' =>
array(
'db_host_name' => 'localhost',
'db_user_name' => 'root',
'db_password' => '%g7!@fG',
'db_name' => 'sugarcrm',
'db_type' => 'mysql',
),
);
$path = dirname(__FILE__).'/bsl/_dostaw.dbf';
$dbfp = new dbf_class($path);
$num_recp=$dbfp->dbf_num_rec;
$mysqli = new mysqli($sugar_config['dbconfig']['db_host_name'], $sugar_config['dbconfig']['db_user_name'], $sugar_config['dbconfig']['db_password'], 'preDb_45ab7160e7af49269e17044eaed9e0ba');
if (!$mysqli->set_charset("utf8")) {
printf("Error loading character set utf8: %s\n", $mysqli->error);
} else {
printf("Current character set: %s\n", $mysqli->character_set_name());
}
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$sugar_fields = array ('id','index_dbf2','name','register_address_postalcode','register_address_street','to_vatid','phone_office','phone_fax','description','email','index_dbf','ownership','currency_id','invoice_type','account_type');
$insert = array();
$count =0;
//for($i=0;$i<$num_recp;$i++){
$j=0;
$stmt=$mysqli->query("INSERT INTO dom_lists (id,lang,dom_name,`key`,`value`) VALUES ('eeaeae','pl_pl','account_type_dom','321dea2','DOSTAWCA')");
$stmt=$mysqli->prepare("INSERT INTO accounts (id,name,register_address_street,register_address_city,register_address_state,register_address_postalcode,register_address_country,to_vatid
,index_dbf,account_type,index_dbf2,ks_account,description,phone_office,phone_fax,currency_id,invoice_type) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
$stmt->bind_param("sssssssssssssssss", $id,$nazwa,$ulica,$miasto,$woj,$poczta,$panstwo,$nip,$indeks,$typ,$indeks2,$ks_account,$description,$tel,$fax,$wal,$pdf);
$a=1;
// uzupełnianie listy profili
for($i=$num_recp;$i>=0;$i--){
$rowp=$dbfp->getRowAssoc($i);
if($rowp['NAZWA']!=''){
$nazwa= $rowp['NAZWA'];
if($rowp['NAZWA1']!=''){
$nazwa.= ' '.$rowp['NAZWA1'];
}
} else {
continue;
}
$indeks=ch($rowp['INDEKS']);
$nazwa=ch($nazwa);
$indeks2=ch($rowp['NR_EWIDENC']);
$id=create_guid();
$adres=explode(" ",ch($rowp['ADRES1']));
$poczta=$adres[0];
$ks_account=ch($rowp['KONTO']);
$ulica=ch($rowp['ADRES2']);
$miasto=$adres[1];
$nip=ch($rowp['NR_IDENT']);
$tel=ch($rowp['TEL']);
$fax=ch($rowp['FAX']);
$opis=ch($rowp['OPIS1']).' '.ch($rowp['OPIS2']).' '.ch($rowp['OPIS3']).' '.ch($rowp['OPIS4']).' '.ch($rowp['OPIS5']).' '.ch($rowp['ADRES1']).' '.ch($rowp['ADRES2']).' '.ch($rowp['UWAGI']);
$emal=ch($rowp['EMAIL']);
$dyr=ch($rowp['DYR_WLRK']);
$wal=ch('PLN');
$pdf=ch('K');
$typ=md5(ch($rowp['PROFIL']));
if(ch($rowp['PROFIL'])==''){
$typ='321dea2';
} else {
$typ='321dea2';
}
if(ch($rowp['BRAK_VAT'])!='F'){
$vat_payer='1';
} else {
$vat_payer='0';
}
$typ2='ab54eee0-5782-a292-bcaf-54d11a78b153';
if (!$stmt->execute()) {
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
$a++;
}
?>