Files
thetool/scripts/import_customers_from_ivt.php
2022-01-25 22:39:57 +01:00

103 lines
2.9 KiB
PHP

#!/usr/bin/php
<?php
// ivtcustomer id blacklist
$blacklist = [3805];
//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);
//$db = FronkDB::singleton();
//$ivt = new FronkDB(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
foreach(IvtCustomerModel::getAll() as $cust) {
//var_dump($cust);exit;
if(!$cust->id) {
continue;
}
foreach(['deleted', 'deletet', 'deleded', 'delete', 'deledet'] as $word) {
if(strtolower(trim($cust->company)) == $word || strtolower(trim($cust->surname)) == $word || strtolower(trim($cust->firstname)) == $word) {
continue 2;
}
}
if(in_array($cust->id, $blacklist)) {
// dont import blacklisted customer ids
echo $cust->id. " in blacklist\n";
continue;
}
$address = AddressModel::getFirst(['customer_number' => $cust->id]);
if(is_object($address) && $address->id) {
continue;
}
// new customer
$address_data['customer_number'] = $cust->id;
$address_data['spin'] = $cust->MandatID;
$address_data['company'] = $cust->company;
$address_data['firstname'] = $cust->firstname;
$address_data['lastname'] = $cust->surname;
$address_data['street'] = $cust->street;
if(strlen($cust->housenumber)) {
$address_data['street'] .= " ".$cust->housenumber;
}
$address_data['zip'] = $cust->zip;
$address_data['city'] = $cust->location;
$address_data['country'] = "";
$address_data['phone'] = $cust->phone;
$address_data['fax'] = "";
$address_data['mobile'] = "";
$address_data['email'] = $cust->email;
$address_data['note'] = $cust->extrainfo;
$address_data['uid'] = ($cust->UID) ? $cust->UID : null;
$address_data["bank_account_bank"] = "";
$address_data["bank_account_owner"] = ($cust->company) ? $cust->company : $cust->firstname . " " . $cust->surname;
$address_data["bank_account_iban"] = $cust->IBAN;
$address_data["bank_account_bic"] = $cust->BIC;
if($cust->payment == 0 ) { // 0 = sepa / 1 = rechnung
$address_data['billing_type'] = "sepa";
} else {
$address_data['billing_type'] = "invoice";
}
if($cust->paper_invoice == 1) {
$address_data["billing_delivery"] = "paper";
} else {
$address_data["billing_delivery"] = "email";
}
if($cust->accept_adver == 2) {
$address_data["allow_contact"] = 1;
} else {
$address_data["allow_contact"] = 0;
}
if($cust->accept_info == 2) {
$address_data["allow_spin"] = 1;
} else {
$address_data["allow_spin"] = 0;
}
$address_data['create_by'] = $me->id;
$address_data['edit_by'] = $me->id;
$address = AddressModel::create($address_data);
if(!$address->save()) {
echo "Error creating address";
}
//exit;
}