Created script to import customers from IVT
This commit is contained in:
@@ -15,6 +15,18 @@ class AddressModel {
|
||||
public $fax = null;
|
||||
public $mobile = null;
|
||||
public $email = null;
|
||||
public $uid;
|
||||
public $billing_type;
|
||||
public $billing_delivery;
|
||||
public $bank_account_bank;
|
||||
public $bank_account_owner;
|
||||
public $bank_account_iban;
|
||||
public $bank_account_bic;
|
||||
public $allow_contact;
|
||||
public $allow_spin;
|
||||
|
||||
|
||||
|
||||
public $note = null;
|
||||
|
||||
public $create_by = null;
|
||||
@@ -34,10 +46,10 @@ class AddressModel {
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
if($model->create_by === null) {
|
||||
if(!is_numeric($model->create_by) && !$model->create_by) {
|
||||
$model->create_by = $me->id;
|
||||
}
|
||||
if($model->edit_by === null) {
|
||||
if(!is_numeric($model->edit_by) && !$model->edit_by) {
|
||||
$model->edit_by = $me->id;
|
||||
}
|
||||
|
||||
@@ -47,20 +59,23 @@ class AddressModel {
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function getOne($id) {
|
||||
if(!is_numeric($id) || !$id) {
|
||||
throw new Exception("Invalid number", 400);
|
||||
}
|
||||
$item = [];
|
||||
|
||||
public static function getFirst($filter = null) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Address", "*", "id=$id LIMIT 1");
|
||||
$where = self::getSqlFilter($filter);
|
||||
//mfLoghandler::singleton()->debug($where);
|
||||
$res = $db->select("Address", "*", "$where ORDER BY company, lastname, firstname, zip, city LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Address($data);
|
||||
$item = new Voicenumber($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return $item;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
@@ -130,7 +145,7 @@ class AddressModel {
|
||||
WHERE $where
|
||||
GROUP BY Address.id
|
||||
) as tbl";
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
//mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
@@ -166,7 +181,7 @@ class AddressModel {
|
||||
}
|
||||
}
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
//mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
|
||||
@@ -50,19 +50,21 @@ class BuildingModel {
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function getOne($id) {
|
||||
if(!is_numeric($id) || !$id) {
|
||||
throw new Exception("Invalid number", 400);
|
||||
}
|
||||
$item = [];
|
||||
public static function getFirst() {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Building", "*", "id=$id LIMIT 1");
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Building", "*", "$where ORDER BY network_id,pop_id,street,zip,city LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Building($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return $item;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
|
||||
@@ -70,7 +70,7 @@ class FileModel {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("File", "*", "$where ORDER BY name, filename");
|
||||
$res = $db->select("File", "*", "$where ORDER BY name, filename LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new File($data);
|
||||
|
||||
@@ -13,7 +13,7 @@ class IvtCustomer extends mfBaseModel {
|
||||
$this->data = new stdClass();
|
||||
$this->table = "customers";
|
||||
|
||||
$this->db = new FronkDB(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
||||
$this->db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
||||
|
||||
if(is_numeric($_)) {
|
||||
$this->fetch($_);
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
class IvtCustomerModel {
|
||||
|
||||
public static function create(Array $data) {
|
||||
throw new Exception("Please use IvtCustomerController to create IvtCustomers");
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
||||
|
||||
$res = $db->select("customers", "*", "1=1 ORDER BY id");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new IvtCustomer($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("customers", "*", "$where ORDER BY id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new IvtCustomer($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function search($filter, $limit = false) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT * FROM customers $where ORDER by id";
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
if(is_array($limit) && count($limit)) {
|
||||
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
||||
} elseif(is_numeric($count)) {
|
||||
$sql .= " LIMIT ".$limit['count'];
|
||||
}
|
||||
}
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new IvtCustomer($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
/*
|
||||
if(array_key_exists("status_id", $filter)) {
|
||||
$status_id = $filter['status_id'];
|
||||
if(is_numeric($status_id)) {
|
||||
$where .= " AND IvtCustomer.status_id=$status_id";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(array_key_exists("street", $filter)) {
|
||||
$street = FronkDB::singleton()->escape($filter["street"]);
|
||||
if($street) {
|
||||
$where .= " AND street like '%$street%'";
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user