154 lines
3.8 KiB
PHP
154 lines
3.8 KiB
PHP
#!/usr/bin/php
|
|
<?php
|
|
|
|
//require 'vendor/autoload.php';
|
|
require("../../config/config.php");
|
|
|
|
define('FRONKDB_SQLDEBUG',false);
|
|
error_reporting(E_ALL & ~(E_NOTICE | E_STRICT | E_DEPRECATED));
|
|
|
|
require_once(LIBDIR."/mvcfronk/mfRouter/mfRouter.php");
|
|
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseModel.php");
|
|
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseController.php");
|
|
|
|
$me = new User(1);
|
|
|
|
die("country auf country_id umbauen!");
|
|
|
|
$folder = __DIR__."/files/";
|
|
$csvname = "Kontaktliste.csv";
|
|
$filename = $folder.$csvname;
|
|
|
|
$db = FronkDB::singleton();
|
|
$log = mfLoghandler::singleton();
|
|
|
|
$input = fopen($filename, "r");
|
|
|
|
$l = 0;
|
|
while($csv = fgetcsv($input)) {
|
|
$l++;
|
|
if($l == 1) continue;
|
|
|
|
if(!trim($csv[0])) {
|
|
continue;
|
|
}
|
|
|
|
//var_dump($csv);exit;
|
|
|
|
$fibu_account_number = trim($csv[1]);
|
|
$fibu_supplier_number = trim($csv[3]);
|
|
|
|
$lastname = trim($csv[4]);
|
|
$firstname = trim($csv[5]);
|
|
$company = trim($csv[6]);
|
|
|
|
$street = trim($csv[7]);
|
|
$zip = trim($csv[8]);
|
|
$city = trim($csv[9]);
|
|
$country = trim($csv[10]);
|
|
|
|
$uid = strtoupper(trim($csv[11]));
|
|
$email = trim($csv[12]);
|
|
|
|
$iban = strtoupper(trim($csv[13]));
|
|
$bic = strtoupper(trim($csv[14]));
|
|
|
|
|
|
if(!$fibu_account_number && !$fibu_supplier_number) {
|
|
echo "invalid line: ".implode(", ", $csv)."\n";
|
|
continue;
|
|
}
|
|
|
|
$address = false;
|
|
$supplier = false;
|
|
|
|
if($fibu_account_number) {
|
|
$address = AddressModel::getFirst(["fibu_account_number" => $fibu_account_number]);
|
|
if(!$address) {
|
|
echo "Kunde $fibu_account_number ($company $firstname $lastname) missing in thetool\n";
|
|
}
|
|
if(!$address->fibu_primary_account) {
|
|
$primary = AddressModel::getFirst(["fibu_account_number" => $fibu_account_number, "fibu_primary_account" => 1]);
|
|
if($primary) $address = $primary;
|
|
}
|
|
}
|
|
|
|
if($fibu_supplier_number) {
|
|
$supplier = AddressModel::getFirst(["fibu_supplier_number" => $fibu_supplier_number]);
|
|
if(!$supplier) {
|
|
echo "Lieferant $fibu_supplier_number ($company $firstname $lastname) missing in thetool\n";
|
|
|
|
$supplier = AddressModel::create([
|
|
"fibu_supplier_number" => $fibu_supplier_number,
|
|
"company" => $company,
|
|
"lastname" => $lastname,
|
|
"firstname" => $firstname,
|
|
"street" => $street,
|
|
"zip" => $zip,
|
|
"city" => $city,
|
|
"country" => $country,
|
|
"uid" => $uid,
|
|
"email" => $email,
|
|
"phone" => "",
|
|
"fax" => "",
|
|
"mobile" => "",
|
|
"create_by" => 1,
|
|
"edit_by" => 1
|
|
]);
|
|
if(!$supplier->save()) {
|
|
die("Error saving supplier $fibu_supplier_number\n");
|
|
}
|
|
//var_dump($supplier);exit;
|
|
|
|
}
|
|
}
|
|
|
|
if($supplier) $address = $supplier;
|
|
if(!$address) continue;
|
|
|
|
// check UID
|
|
if($uid && $address->uid != $uid) {
|
|
echo "UID weicht ab: ".$address->uid." vs. $uid ($fibu_account_number $fibu_supplier_number)\n";
|
|
$address->uid = $uid;
|
|
if($fibu_supplier_number != 330189) {
|
|
$address->save();
|
|
}
|
|
}
|
|
|
|
continue;
|
|
// check bankdata
|
|
|
|
$a_iban = strtoupper(trim($address->bank_account_iban));
|
|
$a_bic = strtoupper(trim($address->bank_account_bic));
|
|
|
|
if($supplier) {
|
|
if(!$iban || !$bic) {
|
|
continue;
|
|
}
|
|
|
|
if(!$a_iban && !$a_bic) {
|
|
echo "Bankdaten im tool fehlen\n";
|
|
continue;
|
|
}
|
|
|
|
$ibans = explode("\n", $iban);
|
|
$bics = explode("\n", $bic);
|
|
|
|
if($ibans) {
|
|
foreach($ibans as $c => $ib) {
|
|
if(!array_key_exists($c, $bics)) continue;
|
|
if($ib == $a_iban && $bics[$c] == $a_bic) {
|
|
echo "Bankdaten in array gefunden\n";
|
|
continue 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
if(($iban && $bic) && ($iban != $a_iban || $bic != $a_bic)) {
|
|
echo "Bankdaten weichen ab (account: $fibu_account_number, supplier: $fibu_supplier_number) thetool iban/bic: $a_iban/$a_bic vs. $iban/$bic\n";
|
|
}
|
|
}
|
|
|
|
|
|
}
|