From 3d353cdabea75fe68e12c5227181f121464f801d Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Tue, 9 Jan 2024 16:30:38 +0100 Subject: [PATCH] WIP Ivt Crediting import --- Layout/default/Admin/Index.php | 8 +- ...tAdminImport.php => IvtContractImport.php} | 0 Layout/default/Admin/IvtCreditImport.php | 79 +++++++++++++ application/Admin/AdminController.php | 32 +++++- ...tAdminImport.php => IvtContractImport.php} | 2 +- .../Admin/functions/IvtCreditImport.php | 26 +++++ .../IvtCreditingProduct.php | 74 ++++++++++++ .../IvtCreditingProductModel.php | 105 +++++++++++++++++ .../IvtCustomerCrediting.php | 94 +++++++++++++++ .../IvtCustomerCreditingModel.php | 107 ++++++++++++++++++ 10 files changed, 519 insertions(+), 8 deletions(-) rename Layout/default/Admin/{IvtAdminImport.php => IvtContractImport.php} (100%) create mode 100644 Layout/default/Admin/IvtCreditImport.php rename application/Admin/functions/{IvtAdminImport.php => IvtContractImport.php} (99%) create mode 100644 application/Admin/functions/IvtCreditImport.php create mode 100644 application/IvtCreditingProduct/IvtCreditingProduct.php create mode 100644 application/IvtCreditingProduct/IvtCreditingProductModel.php create mode 100644 application/IvtCustomerCrediting/IvtCustomerCrediting.php create mode 100644 application/IvtCustomerCrediting/IvtCustomerCreditingModel.php diff --git a/Layout/default/Admin/Index.php b/Layout/default/Admin/Index.php index e5a6cca0b..ec2ada089 100644 --- a/Layout/default/Admin/Index.php +++ b/Layout/default/Admin/Index.php @@ -37,7 +37,7 @@
">IVT Produkte zu thetool Produkte matchen
-
+
@@ -51,11 +51,15 @@
+ \ No newline at end of file diff --git a/Layout/default/Admin/IvtAdminImport.php b/Layout/default/Admin/IvtContractImport.php similarity index 100% rename from Layout/default/Admin/IvtAdminImport.php rename to Layout/default/Admin/IvtContractImport.php diff --git a/Layout/default/Admin/IvtCreditImport.php b/Layout/default/Admin/IvtCreditImport.php new file mode 100644 index 000000000..1e69bbcc2 --- /dev/null +++ b/Layout/default/Admin/IvtCreditImport.php @@ -0,0 +1,79 @@ + + + +
+
+
+
+ +
+

IVT Import

+
+
+
+ + +
+
+ + +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
KundeIVT ProduktProduktPreis SetupPreisRech. IntervalAktion
getCompanyOrName()?>name?>name?>price_setup?>price?> + billing_period?> (billing_period == 1) ? "Monatlich" : ""?>billing_period == 12) ? "Jährlich" : ""?>billing_period == 24) ? "Zweijährlich" : ""?>billing_period == 36) ? "Dreijährlich" : ""?>) +
+ + + +
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/application/Admin/AdminController.php b/application/Admin/AdminController.php index 310515260..7d9acd6bb 100644 --- a/application/Admin/AdminController.php +++ b/application/Admin/AdminController.php @@ -150,20 +150,20 @@ class AdminController extends mfBaseController { $this->layout()->set("products", $products); } - protected function ivtAdminImportAction() { + protected function ivtContractImportAction() { exit; $doit = false; if($this->request->doit == 1) { $doit = true; } - require_once(realpath(dirname(__FILE__)."/functions")."/IvtAdminImport.php"); + require_once(realpath(dirname(__FILE__)."/functions")."/IvtContractImport.php"); - if(class_exists("Admin_IvtAdminImport")) { - $import = new Admin_IvtAdminImport($this->request); + if(class_exists("Admin_IvtContractImport")) { + $import = new Admin_IvtContractImport($this->request); $data = $import->run($doit); - $this->layout()->setTemplate("Admin/IvtAdminImport"); + $this->layout()->setTemplate("Admin/IvtContractImport"); $this->layout()->set("data", $data); if($doit) { @@ -173,4 +173,26 @@ class AdminController extends mfBaseController { } } + protected function ivtCreditImportAction() { + $doit = false; + if($this->request->doit == 1) { + $doit = true; + } + + require_once(realpath(dirname(__FILE__)."/functions")."/IvtCreditImport.php"); + + if(class_exists("Admin_IvtCreditImport")) { + $import = new Admin_IvtCreditImport($this->request); + $data = $import->run($doit); + + $this->layout()->setTemplate("Admin/IvtCreditImport"); + $this->layout()->set("data", $data); + + if($doit) { + $this->layout()->setFlash((count($data['contracts']) - $data['ignore'])." Gutschriften aus IVT importiert!", "success"); + } + + } + } + } \ No newline at end of file diff --git a/application/Admin/functions/IvtAdminImport.php b/application/Admin/functions/IvtContractImport.php similarity index 99% rename from application/Admin/functions/IvtAdminImport.php rename to application/Admin/functions/IvtContractImport.php index 83cc34e81..5cf184fec 100644 --- a/application/Admin/functions/IvtAdminImport.php +++ b/application/Admin/functions/IvtContractImport.php @@ -1,6 +1,6 @@ request = $request; + } + + public function run($doit = false) { + $i = 0; + foreach(IvtCustomerCreditingModel::getAll() as $cust_cred) { + if($i<200) {$i++; continue;} + var_dump($cust_cred); + var_dump($cust_cred->netowner); + var_dump($cust_cred->customer); + var_dump($cust_cred->crediting_product); + exit; + + if(!$cust_cred->customer) continue; + + + } + } + +} \ No newline at end of file diff --git a/application/IvtCreditingProduct/IvtCreditingProduct.php b/application/IvtCreditingProduct/IvtCreditingProduct.php new file mode 100644 index 000000000..12f36d556 --- /dev/null +++ b/application/IvtCreditingProduct/IvtCreditingProduct.php @@ -0,0 +1,74 @@ +log = mfLoghandler::singleton(); + $this->data = new stdClass(); + $this->table = "crediting_products"; + + $this->db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME); + + if(is_numeric($_)) { + $this->fetch($_); + } elseif(is_object($_)) { + $this->load($_); + } + } + + public function save() { + return true; + } + + public function getProperty($name) { + if($this->$name == null) { + + if($name == "product") { + $ivtproduct = new IvtProduct($this->pid); + if($ivtproduct->id) { + $this->ivtproduct = $ivtproduct; + } + return $this->ivtproduct; + } + + if($name == "customer") { + $ivtcustomer = new IvtCustomer($this->cid); + if($ivtcustomer->id) { + $this->ivtcustomer = $ivtcustomer; + } + return $this->ivtcustomer; + } + + $classname = ucfirst($name); + $idfield = $name."_id"; + $this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield); + if(!$this->$name) { + $this->$name = new $classname($this->$idfield); + } + + if($this->$name->id) { + mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name); + return $this->$name; + } else { + return null; + } + + } + + return $this->$name; + } + + + public function __debugInfo() { + $vars = get_object_vars($this); + if(is_object($vars['db'])) $vars['db'] = "object(FronkDB)"; + if(is_object($vars['log'])) $vars['log'] = 'object(mfLoghandler)'; + return $vars; + } + +} \ No newline at end of file diff --git a/application/IvtCreditingProduct/IvtCreditingProductModel.php b/application/IvtCreditingProduct/IvtCreditingProductModel.php new file mode 100644 index 000000000..f95e09dc1 --- /dev/null +++ b/application/IvtCreditingProduct/IvtCreditingProductModel.php @@ -0,0 +1,105 @@ +select("crediting_products", "*"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new IvtCreditingProduct($data); + } + } + return $items; + } + + public static function getFirst($filter = []) { + $db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME); + + $where = self::getSqlFilter($filter); + $res = $db->select("crediting_products", "*", "$where LIMIT 1"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new IvtCreditingProduct($data); + if($item->id) { + return $item; + } else { + return null; + } + } + return null; + } + + public static function count($filter) { + $db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME); + + $where = self::getSqlFilter($filter); + $sql = "SELECT COUNT(*) cnt FROM crediting_products WHERE $where"; + + $res = $db->query($sql); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + return $data->cnt; + } + return 0; + } + + 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 crediting_products WHERE $where"; + + 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 IvtCreditingProduct($data); + } + } + return $items; + } + + private static function getSqlFilter($filter) { + $where = "1=1 "; + + /* + if(array_key_exists("cid", $filter)) { + $cid = $filter['cid']; + if(is_numeric($cid)) { + $where .= " AND cid=$cid"; + } + } + + if(array_key_exists("pid", $filter)) { + $pid = $filter['pid']; + if(is_numeric($pid)) { + $where .= " AND pid=$pid"; + } + } + + if(array_key_exists("sid", $filter)) { + $sid = $filter['sid']; + if(is_numeric($sid)) { + $where .= " AND sid=$sid"; + } + } + */ + //var_dump($filter, $where);exit; + return $where; + } + +} diff --git a/application/IvtCustomerCrediting/IvtCustomerCrediting.php b/application/IvtCustomerCrediting/IvtCustomerCrediting.php new file mode 100644 index 000000000..b7e3560a2 --- /dev/null +++ b/application/IvtCustomerCrediting/IvtCustomerCrediting.php @@ -0,0 +1,94 @@ +log = mfLoghandler::singleton(); + $this->data = new stdClass(); + $this->table = "customer_crediting"; + + $this->db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME); + + if(is_numeric($_)) { + $this->fetch($_); + } elseif(is_object($_)) { + $this->load($_); + } + } + + public function save() { + return true; + } + + private function getCustomerId() { + $customer_id = false; + + $m = []; + if(preg_match('/(\d+)\s*$/', $this->comment, $m)) { + $customer_id = $m[1]; + } + if(!$customer_id) { + $this->log->warn(__METHOD__.": Cannot extract customer id from comment"); + } + return $customer_id; + } + + public function getProperty($name) { + if($this->$name == null) { + + if($name == "crediting_product") { + $cred_prod = new IvtCreditingProduct($this->cred_id); + if($cred_prod->id) { + $this->crediting_product = $cred_prod; + } + return $this->crediting_product; + } + + if($name == "netowner") { + $netowner = new IvtCustomer($this->cust_id); + if($netowner->id) { + $this->netowner = $netowner; + } + return $this->netowner; + } + + if($name == "customer") { + $customer_id = $this->getCustomerId(); + $customer = new IvtCustomer($customer_id); + if($customer->id) { + $this->customer = $customer; + } + return $this->customer; + } + + $classname = ucfirst($name); + $idfield = $name."_id"; + $this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield); + if(!$this->$name) { + $this->$name = new $classname($this->$idfield); + } + + if($this->$name->id) { + mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name); + return $this->$name; + } else { + return null; + } + + } + + return $this->$name; + } + + + public function __debugInfo() { + $vars = get_object_vars($this); + if(is_object($vars['db'])) $vars['db'] = "object(FronkDB)"; + if(is_object($vars['log'])) $vars['log'] = 'object(mfLoghandler)'; + return $vars; + } +} \ No newline at end of file diff --git a/application/IvtCustomerCrediting/IvtCustomerCreditingModel.php b/application/IvtCustomerCrediting/IvtCustomerCreditingModel.php new file mode 100644 index 000000000..3189194c5 --- /dev/null +++ b/application/IvtCustomerCrediting/IvtCustomerCreditingModel.php @@ -0,0 +1,107 @@ +select("customer_crediting", "*", "1=1 ORDER BY id"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new IvtCustomerCrediting($data); + } + } + return $items; + } + + public static function getFirst($filter = []) { + $db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME); + + $where = self::getSqlFilter($filter); + $res = $db->select("customer_crediting", "*", "$where ORDER BY id LIMIT 1"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new IvtCustomerCrediting($data); + if($item->id) { + return $item; + } else { + return null; + } + } + return null; + } + + public static function count($filter) { + $db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME); + + $where = self::getSqlFilter($filter); + $sql = "SELECT COUNT(*) cnt FROM customer_crediting WHERE $where ORDER by id"; + + $res = $db->query($sql); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + return $data->cnt; + } + return 0; + } + + 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 customer_crediting WHERE $where ORDER by cid,pid,sid,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 IvtCustomerCrediting($data); + } + } + return $items; + } + + private static 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 IvtCustomerCrediting.status_id=$status_id"; + } + } + + + if(array_key_exists("street", $filter)) { + $street = FronkDB::singleton()->escape($filter["street"]); + if($street) { + $where .= " AND street like '%$street%'"; + } + } + */ + + if(array_key_exists("cust_id", $filter)) { + $cust_id = $filter['cust_id']; + if(is_numeric($cust_id)) { + $where .= " AND cust_id=$cust_id"; + } + } + + //var_dump($filter, $where);exit; + return $where; + } + +}