117 lines
4.0 KiB
PHP
Executable File
117 lines
4.0 KiB
PHP
Executable File
<?php
|
|
|
|
function countDigits($str) {
|
|
$noDigits=0;
|
|
for ($i=0;$i<strlen($str);$i++) {
|
|
if (is_numeric($str{$i})) $noDigits++;
|
|
}
|
|
return $noDigits;
|
|
}
|
|
|
|
include_once("class.dbf.php");
|
|
include_once("../../config.php");
|
|
include_once("helper.php");
|
|
global $sugar_config;
|
|
$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 character set utf8;");
|
|
|
|
$path = dirname(__FILE__).'/E-m-s/_ODBIOR.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'], $sugar_config['dbconfig']['db_name']);
|
|
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->prepare("INSERT INTO accounts (id,name,index_dbf,index_dbf2,register_address_street,register_address_postalcode,to_vatid,phone_office,
|
|
phone_fax,description,email,ownership,currency_id,invoice_type,account_type,account_type2) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
|
|
$stmt->bind_param("ssssssssssssssss", $id,$nazwa,$indeks,$indeks2,$poczta,$ulica,$nip,$tel,$fax,$opis,$email,$dyr,$wal,$pdf,$typ,$typ2);
|
|
|
|
$a=1;
|
|
|
|
for($i=$num_recp;$i>0;$i--){
|
|
$rowp=$dbfp->getRowAssoc($i);
|
|
if($rowp["BRAK_VAT"]=='T'){
|
|
echo 'UPDATE accounts SET vat_payer="1" WHERE index_dbf2 = "' . $rowp["NR_EWIDENC"] . '"';
|
|
mysql_query('UPDATE accounts SET vat_payer="1" WHERE index_dbf2 = "' . $rowp["NR_EWIDENC"] . '"');
|
|
echo '<br><br>';
|
|
}
|
|
continue;
|
|
if($rowp['NAZWA`z`O']!=''){
|
|
$nazwa= $rowp['NAZWA`z`O'];
|
|
if($rowp['NAZWA1`z`O']!=''){
|
|
$nazwa.= ' '.$rowp['NAZWA1`z`O'];
|
|
}
|
|
} else {
|
|
continue;
|
|
}
|
|
if ($check = $mysqli->prepare("SELECT id FROM accounts WHERE index_dbf2=?")) {
|
|
$check->bind_param("s", ch($rowp['NR_EWIDENC']));
|
|
|
|
// execute query
|
|
$check->execute();
|
|
|
|
$check->store_result();
|
|
$numrows = $check->num_rows;
|
|
if($numrows==1)continue;
|
|
}
|
|
echo "dodaje!<br>";
|
|
$indeks=ch($rowp['INDEKS`z`O']);
|
|
$nazwa=ch($nazwa);
|
|
$indeks2=ch($rowp['NR_EWIDENC']);
|
|
$id=create_guid();
|
|
$poczta=ch($rowp['ADRES1`z`O']);
|
|
$ulica=ch($rowp['ADRES2`z`O']);
|
|
$nip=ch($rowp['NIPBK1NY']);
|
|
$tel=ch($rowp['TELA2PC']);
|
|
$fax=ch($rowp['FAXA2PC']);
|
|
$opis=ch($rowp['OPIS1`z`O']).' '.ch($rowp['OPIS2`z`O']).' '.ch($rowp['OPIS3`z`O']).' '.ch($rowp['OPIS4`z`O']).' '.ch($rowp['OPIS5`z`O']).' '.ch($rowp['ADRES1`z`O']).' '.ch($rowp['ADRES2`z`O']).' '.ch($rowp['UWAGI`z`O']);
|
|
$emal=ch($rowp['EMAILCZT']);
|
|
$dyr=ch($rowp['DYR_WLRK']);
|
|
$wal=ch('PLN');
|
|
$pdf=ch('K');
|
|
$typ=ch('rec');
|
|
|
|
if (!$stmt->execute()) {
|
|
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
|
|
}
|
|
$a++;
|
|
|
|
}
|
|
echo $a;
|
|
|
|
die();
|
|
//CREATE QUERY
|
|
//echo sizeof($insert).'';
|
|
|
|
for ($i=0; $i<count($insert); $i++) {
|
|
//echo implode("','",$insert[$i]);
|
|
//PRODUCT INSERT
|
|
$query = 'INSERT INTO crm.accounts ('.implode(",",$sugar_fields).',date_entered,date_modified,created_by,modified_user_id,assigned_user_id) VALUES (\''.implode("','",$insert[$i]).'\',\''.date("Y-m-d H:i:s").'\',\''.date("Y-m-d H:i:s").'\',\'cf3a00c2-807d-8e12-592e-4fe88f59cbf6\',\'cf3a00c2-807d-8e12-592e-4fe88f59cbf6\',\'cf3a00c2-807d-8e12-592e-4fe88f59cbf6\');';
|
|
//echo $query;
|
|
mysql_query(ch($query));
|
|
if (mysql_error()) echo 'Database error: '.mysql_error().'
|
|
';
|
|
}
|
|
mysql_close($sql);
|
|
|
|
?>
|