WIP Ivt Crediting import

This commit is contained in:
Frank Schubert
2024-01-09 16:30:38 +01:00
parent 9390f12c45
commit 3d353cdabe
10 changed files with 519 additions and 8 deletions

View File

@@ -37,7 +37,7 @@
<div class="row col-12">
<div><a href="<?=self::getUrl("Admin", "ivtImportMatchProducts")?>">IVT Produkte zu thetool Produkte matchen</a></div>
</div>
<div class="row col-12">
<div class="row col-12 mt-2">
<div><a href="<?=self::getUrl("Admin", "ivtDownloadActiveProducts")?>">Produkte in Verwendung herunterladen</a></div>
</div>
</div>
@@ -51,11 +51,15 @@
<div class="card">
<div class="card-body">
<div class="row col-12">
<div><a href="<?=self::getUrl("Admin", "ivtAdminImport")?>" class="text-danger">IVT Contracts importieren</a></div>
<div><a href="<?=self::getUrl("Admin", "ivtContractImport")?>" class="text-danger">IVT Contracts importieren</a></div>
</div>
<div class="row col-12 mt-2">
<div><a href="<?=self::getUrl("Admin", "ivtCreditImport")?>" class="text-danger">IVT Gutschriften importieren</a></div>
</div>
</div>
</div>
</div>
</div>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>

View File

@@ -0,0 +1,79 @@
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/header.php"); ?>
<link href="<?= self::getResourcePath() ?>assets/css/datatables-std.css?<?= date('U') ?>" rel="stylesheet"
type="text/css"/>
<!-- start page title -->
<div class="row">
<div class="col-12">
<div class="page-title-box">
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="breadcrumb-item"><a href="<?=self::getUrl("Dashboard")?>"><?=MFAPPNAME_SLUG?></a></li>
<li class="breadcrumb-item"><a href="<?=self::getUrl("Admin")?>">Admin</a></li>
<li class="breadcrumb-item active">IVT Contract Import</li>
</ol>
</div>
<h4 class="page-title">IVT Import</h4>
</div>
</div>
</div>
<!-- end page title -->
<div class="row">
<div class="col-lg-12">
<div class="row">
<div class="col-8">
<div class="card border-top-primary">
<div class="card-body">
<table id="datatable" class="table table-sm table-striped table-sm">
<thead>
<tr>
<th>Kunde</th>
<th>IVT Produkt</th>
<th>Produkt</th>
<th>Preis Setup</th>
<th>Preis</th>
<th>Rech. Interval</th>
<th>Aktion</th>
</tr>
</thead>
<tbody>
<?php foreach($data['contracts'] as $d): ?>
<tr>
<td><?=$d["customer"]->getCompanyOrName()?></td>
<td><?=$d["ivtproduct"]->name?></td>
<td><?=$d["product"]->name?></td>
<td><?=$d["contract"]->price_setup?></td>
<td><?=$d["contract"]->price?></td>
<td>
<?=$d["contract"]->billing_period?> (<?=($d["contract"]->billing_period == 1) ? "Monatlich" : ""?><?=($d["contract"]->billing_period == 12) ? "Jährlich" : ""?><?=($d["contract"]->billing_period == 24) ? "Zweijährlich" : ""?><?=($d["contract"]->billing_period == 36) ? "Dreijährlich" : ""?>)
</td>
<td><?=$d["action"]?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div>
<a href="<?=self::getUrl("Admin", "ivtAdminImport", ["doit" => 1])?>"><button class="btn btn-primary" id="doitbutton"><i class="far fa-fw fa-exclamation-circle"></i> Jetzt importieren</button></a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="<?= self::getResourcePath() ?>assets/js/datatables-std.js?<?= date('U') ?>"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#doitbutton").click(function() {
$("#doitbutton").text("Bitte warten...");
$("#doitbutton").prop("disabled", true);
});
});
</script>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>

View File

@@ -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");
}
}
}
}

View File

@@ -1,6 +1,6 @@
<?php
class Admin_IvtAdminImport {
class Admin_IvtContractImport {
private $request;
public function __construct($request) {

View File

@@ -0,0 +1,26 @@
<?php
class Admin_IvtCreditImport {
private $request;
public function __construct($request) {
$this->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;
}
}
}

View File

@@ -0,0 +1,74 @@
<?php
class IvtCreditingProduct extends mfBaseModel {
protected $forcestr = [];
/**
* Takes ID or DB row as arguments
* @param id or table row $_
*/
public function __construct($_=NULL) {
$this->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;
}
}

View File

@@ -0,0 +1,105 @@
<?php
class IvtCreditingProductModel {
public static function getAll() {
$items = [];
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
$res = $db->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;
}
}

View File

@@ -0,0 +1,94 @@
<?php
class IvtCustomerCrediting extends mfBaseModel {
private $netowner;
private $customer;
private $crediting_product;
public function __construct($_=NULL) {
$this->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;
}
}

View File

@@ -0,0 +1,107 @@
<?php
class IvtCustomerCreditingModel {
public static function getAll() {
$items = [];
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
$res = $db->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;
}
}