diff --git a/Layout/default/Building/Index.php b/Layout/default/Building/Index.php
index bd669702e..7a34278b9 100644
--- a/Layout/default/Building/Index.php
+++ b/Layout/default/Building/Index.php
@@ -147,6 +147,7 @@
Adresse |
Einheiten |
Status |
+
|
@@ -162,6 +163,7 @@
=$building->units?> |
=__($building->status->name."-b")?> |
+
$building->id])?>">
$building->id])?>" class="text-danger" onclick="if(!confirm('Objekt wirklich löschen?')) return false;" title="Objekt Löschen">
diff --git a/application/Admin/functions/IvtContractImport.php b/application/Admin/functions/IvtContractImport.php
index ddc3469ba..d3d987c8b 100644
--- a/application/Admin/functions/IvtContractImport.php
+++ b/application/Admin/functions/IvtContractImport.php
@@ -166,12 +166,12 @@ class Admin_IvtContractImport {
- $finish_date = new DateTime($ivt_contract->created);
- $finish_date->modify("+2 hours");
+ $order_date = new DateTime($ivt_contract->created);
+ $order_date->modify("+2 hours");
- $last_date = new DateTime($ivt_contract->lastdate);
- $last_date->modify("+1 day");
- $last_date->modify("+1 hours");
+ $finish_date = new DateTime($ivt_contract->lastdate);
+ $finish_date->setDate($finish_date->format("Y"), $finish_date->format("m"), 1);
+ //$finish_date->modify("+1 hours");
$contract_data = [];
$contract_data['owner_id'] = $customer->id;
@@ -184,8 +184,8 @@ class Admin_IvtContractImport {
$contract_data['price_nne'] = 0;
$contract_data['price_nbe'] = 0;
$contract_data['sla_id'] = $this->getNewSlaId($ivt_contract->sid);
- $contract_data['order_date'] = $finish_date->getTimestamp();
- $contract_data['finish_date'] = $last_date->getTimestamp();
+ $contract_data['order_date'] = $order_date->getTimestamp();
+ $contract_data['finish_date'] = $finish_date->getTimestamp();
$contract_data['finish_date_by'] = 1;
$contract_data['imported_from'] = "ivt";
$contract_data['imported_data'] = $ivt_contract->id;
diff --git a/application/Admin/functions/IvtCreditImport.php b/application/Admin/functions/IvtCreditImport.php
index a155bc2b2..66149db77 100644
--- a/application/Admin/functions/IvtCreditImport.php
+++ b/application/Admin/functions/IvtCreditImport.php
@@ -6,12 +6,18 @@ class Admin_IvtCreditImport {
private $netownerid = [
3805 => 2840,
4941 => 2840,
- 4909 => 3199,
+ 4909 => 3199
];
private $cust_cred_ignore = [
2267,
2934
];
+ private $netowner_ignore = [
+ 3716
+ ];
+ private $netowner_rules = [
+ 3715 => ["action" => "double_price"],
+ ];
private $cust_cred_id_to_customer_id = [
2891 => 104004,
@@ -49,6 +55,8 @@ class Admin_IvtCreditImport {
$ivt_customer = $cust_cred->customer;
}
+ if(in_array($ivt_netowner->id, $this->netowner_ignore)) continue;
+
if(!$ivt_customer) {
echo __METHOD__.": No customer in cust_cred ".$cust_cred->id."\n";
continue;
@@ -62,7 +70,7 @@ class Admin_IvtCreditImport {
}
if(!$customer) {
- echo __METHOD__ . ": No Customer ".$ivt_customer->id." cust_cred ".$cust_cred->id."\n";
+ // XXX echo __METHOD__ . ": No Customer ".$ivt_customer->id." cust_cred ".$cust_cred->id."\n";
//$this->log->debug("No Customer ".$ivt_customer->id." cust_cred ".$cust_cred->id);
exit;
}
@@ -74,60 +82,105 @@ class Admin_IvtCreditImport {
}
$contracts = ContractModel::search(["owner_id" => $customer->id]);
-
- // DEBUG: not all contracts imported yet
- if(!count($contracts)) {
- $ivt_contract_count = IvtCustomerProductModel::count(["cid" => $customer->id]);
- echo __METHOD__ . ": Contract not found for credit ".$cust_cred->id." Kunde ".$customer->getCompanyOrName()." (".$customer->customer_number."; $ivt_contract_count IVT Contracts), GS an ".$netowner->getCompanyOrName()." (".$netowner->customer_number.")\n";
- continue;
- }
- // use first contract as primary contract
- $primary_contract = reset($contracts);
- // find more suitable primary contract
- foreach($contracts as $contract) {
- // only monthly products
- if($contract->biling_period > 1) continue;
- // no one-off products
- if(!$contract->price && $contract->price_setup) continue;
- if($contract->termination_id) {
- $primary_contract = $contract;
- break;
- }
- if(preg_match('/(dsl|funkinternet|standortgeber|glasfaser|brettljausn)/i', $contract->product->name)) {
- $primary_contract = $contract;
- break;
- }
-
- }
-
- if(!$primary_contract) {
- //echo __METHOD__ . ": Contract not found for credit ".$cust_cred->id."\n";
- $this->log->debug("No primary contract cust ".$ivt_customer->id);
- }
-
- // create Credit Contract
-
- if(!$primary_contract->product_id) {
- var_dump($primary_contract);exit;
- }
-
$data = [];
- $data["orderproduct_id"] = $primary_contract->orderproduct_id;
- $data["product_id"] = $primary_contract->product_id;
- $data["product_name"] = $primary_contract->product_name;
- $data["product_info"] = $primary_contract->product_info;
- $data["amount"] = $primary_contract->amount;
- $data["sla_id"] = $primary_contract->sla_id;
- $data["product_external"] = $primary_contract->product_external;
- $data["product_external_id"] = $primary_contract->product_external_id;
- $data["billing_delay"] = $primary_contract->billing_delay;
- $data["billing_period"] = $primary_contract->billing_period;
- $data["contract_term"] = $primary_contract->contract_term;
- $data["order_date"] = $primary_contract->order_date;
- $data["finish_date"] = $primary_contract->finish_date;
- $data["finish_date_by"] = $primary_contract->finish_date_by;
- $data["note"] = $primary_contract->note;
+ /*
+ * 1962 - internal xinon account for credits missing contract
+ *
+ */
+ if($ivt_customer->id != 1962) {
+ // if not xinon internal, look up primary contract for linking
+ if(!count($contracts)) {
+ $ivt_contracts = IvtCustomerProductModel::search(["cid" => $ivt_customer->id]);
+ //echo __METHOD__ . ": Contract not found for credit ".$cust_cred->id." Kunde ".$customer->getCompanyOrName()." (".$customer->customer_number."; ".count($ivt_contracts)." IVT Contracts), GS an ".$netowner->getCompanyOrName()." (".$netowner->customer_number.")\n";
+ echo "Netzinhaber: " . $netowner->getCompanyOrName() . " (" . $netowner->customer_number . ")\n";
+ echo "Kunde: " . $customer->getCompanyOrName() . " (" . $customer->customer_number . ")\n";
+ echo "Gutschft: " . $cust_cred->crediting_product->name . " | " . $cust_cred->crediting_product->price_excl . "\n";
+ echo "GS Comment: " . $cust_cred->comment . "\n";
+ if($ivt_contracts) {
+ echo "Kunde Produkte:\n";
+ foreach($ivt_contracts as $ivtc) {
+ echo "\t" . $ivtc->pid . ": " . $ivtc->product->name . " | " . $ivtc->product->price . "\n";
+ }
+ } else {
+ echo "Keine aktiven Produkte\n";
+ }
+
+ echo "=========================\n\n";
+ continue;
+ }
+
+ // use first contract as primary contract
+ $primary_contract = reset($contracts);
+ // find more suitable primary contract
+ foreach($contracts as $contract) {
+ // only monthly products
+ if($contract->biling_period > 1) continue;
+ // no one-off products
+ if(!$contract->price && $contract->price_setup) continue;
+ if($contract->termination_id) {
+ $primary_contract = $contract;
+ break;
+ }
+ if(preg_match('/(dsl|funkinternet|standortgeber|glasfaser|brettljausn)/i', $contract->product->name)) {
+ $primary_contract = $contract;
+ break;
+ }
+
+ }
+
+ if(!$primary_contract) {
+ //echo __METHOD__ . ": Contract not found for credit ".$cust_cred->id."\n";
+ $this->log->debug("No primary contract cust " . $ivt_customer->id);
+ }
+
+ // create Credit Contract
+
+ if(!$primary_contract->product_id) {
+ var_dump($primary_contract);
+ exit;
+ }
+
+
+ $data["orderproduct_id"] = $primary_contract->orderproduct_id;
+ $data["product_id"] = $primary_contract->product_id;
+ $data["product_name"] = $primary_contract->product_name;
+ $data["product_info"] = $primary_contract->product_info;
+ $data["amount"] = $primary_contract->amount;
+ $data["sla_id"] = $primary_contract->sla_id;
+ $data["product_external"] = $primary_contract->product_external;
+ $data["product_external_id"] = $primary_contract->product_external_id;
+ $data["billing_delay"] = $primary_contract->billing_delay;
+ $data["billing_period"] = $primary_contract->billing_period;
+ $data["contract_term"] = $primary_contract->contract_term;
+ $data["order_date"] = $primary_contract->order_date;
+
+ $data["finish_date"] = $primary_contract->finish_date;
+ $data["finish_date_by"] = $primary_contract->finish_date_by;
+ $data["note"] = $primary_contract->note;
+ } else {
+ $create_date = new DateTime($cust_cred->created);
+ $create_date->setTime(2,0);
+
+ $finish_date = new DateTime($cust_cred->lastdate);
+ $finish_date->setDate($finish_date->format("Y"), $finish_date->format("m"), 1);
+
+ $data["orderproduct_id"] = null;
+ $data["product_id"] = 336; // Mainproduct dummy for crediting import [IVT]
+ $data["product_name"] = $cust_cred->crediting_product->name;
+ $data["product_info"] = null;
+ $data["amount"] = 1;
+ $data["sla_id"] = 4;
+ $data["product_external"] = 0;
+ $data["product_external_id"] = null;
+ $data["billing_delay"] = 0;
+ $data["billing_period"] = 1;
+ $data["contract_term"] = 12;
+ $data["order_date"] = $create_date->getTimestamp();
+ $data["finish_date"] = $finish_date->getTimestamp();
+ $data["finish_date_by"] = 1;
+ $data["note"] = null;
+ }
$data["matchcode"] = $cust_cred->comment;
$data["owner_id"] = $netowner->id;
@@ -138,6 +191,16 @@ class Admin_IvtCreditImport {
$data["price_nne"] = 0;
$data["price_nbe"] = 0;
+ $data['imported_from'] = "ivt-credit";
+ $data['imported_data'] = $cust_cred->id;
+
+
+ if(array_key_exists($ivt_netowner->id, $this->netowner_rules)) {
+ if($this->netowner_rules[$ivt_netowner->id]["action"] == "double_price") {
+ $data['price'] *= 2;
+ }
+ }
+
$cred_contract = ContractModel::create($data);
if(!$cred_contract->save()) {
$this->log->debug("error saving credit contract");
@@ -146,22 +209,50 @@ class Admin_IvtCreditImport {
}
$c++;
+ // create Journals
+ // creation journal
+ $journal = ContractjournalModel::create([
+ 'contract_id' => $cred_contract->id,
+ 'type' => "created_from",
+ 'value' => "import",
+ 'text' => "IVT customer_credit ".$cust_cred->id."; cid: ".$cust_cred->cust_id."; pid: ".$ivt_cred_product->id." (".$ivt_cred_product->name.")"
+ ]);
+ $journal_id = $journal->save();
+ if(!$journal_id) {
+ echo "Fehler beim Journal erstellen. \n";
+ exit;
+ }
- // Link to all Contracts of Customer
- foreach($contracts as $contract) {
- if (ContractLinkModel::getFirst(["contract_id" => $cred_contract->id, "origin_contract_id" => $contract->id])) {
- continue;
+ // credit linking journal
+ $journal = ContractjournalModel::create([
+ 'contract_id' => $primary_contract->id,
+ 'type' => "credit_created",
+ 'value' => $primary_contract->id,
+ //'text' => "IVT customer_credit ".$cust_cred->id."; cid: ".$cust_cred->cust_id."; pid: ".$ivt_cred_product->id." (".$ivt_cred_product->name.")"
+ ]);
+ $journal_id = $journal->save();
+ if(!$journal_id) {
+ echo "Fehler beim Journal erstellen. \n";
+ exit;
+ }
+
+ if(count($contracts)) {
+ // Link to all Contracts of Customer
+ foreach($contracts as $contract) {
+ if(ContractLinkModel::getFirst(["contract_id" => $cred_contract->id, "origin_contract_id" => $contract->id])) {
+ continue;
+ }
+ $link = ContractLinkModel::create([
+ 'contract_id' => $cred_contract->id,
+ 'origin_contract_id' => $contract->id,
+ 'type' => 'link'
+ ]);
+ $link->save();
}
- $link = ContractLinkModel::create([
- 'contract_id' => $cred_contract->id,
- 'origin_contract_id' => $contract->id,
- 'type' => 'link'
- ]);
- $link->save();
}
}
- echo "Imported $i credits; $c Contracts erstellt\n";
+ echo "Imported $i credits; $c Credit Contracts erstellt\n";
}
}
\ No newline at end of file
diff --git a/application/Api/v1/AddressdbApicontroller.php b/application/Api/v1/AddressdbApicontroller.php
index ae55d5710..deaf5fc20 100644
--- a/application/Api/v1/AddressdbApicontroller.php
+++ b/application/Api/v1/AddressdbApicontroller.php
@@ -854,10 +854,7 @@ class AddressdbApicontroller extends mfBaseApicontroller {
foreach($my_networks as $network) {
if($network->adb_netzgebiet_id && !in_array($network->adb_netzgebiet_id, $netzgebiet_ids)) {
$netzgebiet_ids[] = $network->id;
- if($network->adb_netzgebiet_id) {
- $adb_network_ids[] = $network->adb_netzgebiet_id;
- }
-
+ $adb_network_ids[] = $network->adb_netzgebiet_id;
}
}
diff --git a/application/Contract/ContractModel.php b/application/Contract/ContractModel.php
index 30c916861..c35e4daf7 100644
--- a/application/Contract/ContractModel.php
+++ b/application/Contract/ContractModel.php
@@ -482,7 +482,12 @@ class ContractModel {
}
}
-
+ if(array_key_exists("finish_date<", $filter)) {
+ $finish_date = $filter['finish_date<'];
+ if(is_numeric($finish_date)) {
+ $where .= " AND Contract.finish_date <= $finish_date";
+ }
+ }
if(array_key_exists("add-where", $filter)) {
$where .= " ".$filter['add-where'];
diff --git a/application/IvtCrediting/IvtCrediting.php b/application/IvtCrediting/IvtCrediting.php
new file mode 100644
index 000000000..c22829826
--- /dev/null
+++ b/application/IvtCrediting/IvtCrediting.php
@@ -0,0 +1,34 @@
+log = mfLoghandler::singleton();
+ $this->data = new stdClass();
+ $this->table = "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() {
+ throw new Exception("Cannot save Ivt Bills");
+ }
+
+ 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/IvtCrediting/IvtCreditingModel.php b/application/IvtCrediting/IvtCreditingModel.php
new file mode 100644
index 000000000..2d7daa311
--- /dev/null
+++ b/application/IvtCrediting/IvtCreditingModel.php
@@ -0,0 +1,117 @@
+select("crediting", "*", "1=1 ORDER BY id");
+ if($db->num_rows($res)) {
+ while($data = $db->fetch_object($res)) {
+ $items[] = new IvtCrediting($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", "*", "$where ORDER BY id LIMIT 1");
+ if($db->num_rows($res)) {
+ $data = $db->fetch_object($res);
+ $item = new IvtCrediting($data);
+ if($item->id) {
+ return $item;
+ } else {
+ return null;
+ }
+ }
+ return null;
+ }
+
+ public static function getLast($filter = []) {
+ $db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
+
+ $where = self::getSqlFilter($filter);
+ $res = $db->select("crediting", "*", "$where ORDER BY id DESC LIMIT 1");
+ if($db->num_rows($res)) {
+ $data = $db->fetch_object($res);
+ $item = new IvtCrediting($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 crediting WHERE $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($limit['count'])) {
+ $sql .= " LIMIT " . $limit['count'];
+ }
+ }
+
+ $res = $db->query($sql);
+ if($db->num_rows($res)) {
+ while($data = $db->fetch_object($res)) {
+ $items[] = new IvtCrediting($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("date_outgoing", $filter)) {
+ $date_outgoing = $filter['date_outgoing'];
+ if($date_outgoing) {
+ $where .= " AND date_outgoing='$date_outgoing'";
+ }
+ }
+
+ if(array_key_exists("date_outgoing>", $filter)) {
+ $date_outgoing = $filter['date_outgoing>'];
+ if($date_outgoing) {
+ $where .= " AND date_outgoing >= '$date_outgoing'";
+ }
+ }
+
+ if(array_key_exists("date_outgoing<", $filter)) {
+ $date_outgoing = $filter['date_outgoing<'];
+ if($date_outgoing) {
+ $where .= " AND date_outgoing <= '$date_outgoing'";
+ }
+ }
+
+ return $where;
+ }
+
+}
diff --git a/application/IvtCreditingPosition/IvtCreditingPosition.php b/application/IvtCreditingPosition/IvtCreditingPosition.php
new file mode 100644
index 000000000..804d2a899
--- /dev/null
+++ b/application/IvtCreditingPosition/IvtCreditingPosition.php
@@ -0,0 +1,34 @@
+log = mfLoghandler::singleton();
+ $this->data = new stdClass();
+ $this->table = "crediting_positions";
+
+ $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() {
+ throw new Exception("Cannot save Ivt Bills");
+ }
+
+ 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/IvtCreditingPosition/IvtCreditingPositionModel.php b/application/IvtCreditingPosition/IvtCreditingPositionModel.php
new file mode 100644
index 000000000..83faa6c8e
--- /dev/null
+++ b/application/IvtCreditingPosition/IvtCreditingPositionModel.php
@@ -0,0 +1,96 @@
+select("crediting_positions", "*", "1=1 ORDER BY id");
+ if($db->num_rows($res)) {
+ while($data = $db->fetch_object($res)) {
+ $items[] = new IvtCreditingPosition($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_positions", "*", "$where ORDER BY id LIMIT 1");
+ if($db->num_rows($res)) {
+ $data = $db->fetch_object($res);
+ $item = new IvtCreditingPosition($data);
+ if($item->id) {
+ return $item;
+ } else {
+ return null;
+ }
+ }
+ return null;
+ }
+
+ public static function getLast($filter = []) {
+ $db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
+
+ $where = self::getSqlFilter($filter);
+ $res = $db->select("crediting_positions", "*", "$where ORDER BY id DESC LIMIT 1");
+ if($db->num_rows($res)) {
+ $data = $db->fetch_object($res);
+ $item = new IvtCreditingPosition($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 crediting_positions WHERE $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($limit['count'])) {
+ $sql .= " LIMIT " . $limit['count'];
+ }
+ }
+
+ $res = $db->query($sql);
+ if($db->num_rows($res)) {
+ while($data = $db->fetch_object($res)) {
+ $items[] = new IvtCreditingPosition($data);
+ }
+ }
+ return $items;
+ }
+
+ private static function getSqlFilter($filter) {
+ $where = "1=1 ";
+
+ if(array_key_exists("head_id", $filter)) {
+ $head_id = $filter['head_id'];
+ if($head_id) {
+ $where .= " AND head_id = '$head_id'";
+ }
+ }
+
+ return $where;
+ }
+
+}
diff --git a/application/IvtCustomerCrediting/IvtCustomerCreditingModel.php b/application/IvtCustomerCrediting/IvtCustomerCreditingModel.php
index 3189194c5..116a037ff 100644
--- a/application/IvtCustomerCrediting/IvtCustomerCreditingModel.php
+++ b/application/IvtCustomerCrediting/IvtCustomerCreditingModel.php
@@ -53,7 +53,7 @@ class IvtCustomerCreditingModel {
$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";
+ $sql = "SELECT * FROM customer_crediting WHERE $where ORDER by id";
mfLoghandler::singleton()->debug($sql);
if(is_array($limit) && count($limit)) {
@@ -99,6 +99,13 @@ class IvtCustomerCreditingModel {
$where .= " AND cust_id=$cust_id";
}
}
+
+ if(array_key_exists("lastdate", $filter)) {
+ $lastdate = $filter['lastdate'];
+ if($lastdate) {
+ $where .= " AND lastdate = '$lastdate'";
+ }
+ }
//var_dump($filter, $where);exit;
return $where;
diff --git a/application/IvtCustomerProduct/IvtCustomerProductModel.php b/application/IvtCustomerProduct/IvtCustomerProductModel.php
index 0fef4decf..539877df0 100644
--- a/application/IvtCustomerProduct/IvtCustomerProductModel.php
+++ b/application/IvtCustomerProduct/IvtCustomerProductModel.php
@@ -57,7 +57,7 @@ class IvtCustomerProductModel {
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
$where = self::getSqlFilter($filter);
- $sql = "SELECT * FROM customer_product WHERE $where ORDER by cid,pid,sid,id";
+ $sql = "SELECT * FROM customer_product WHERE $where ORDER by id";
mfLoghandler::singleton()->debug($sql);
if(is_array($limit) && count($limit)) {
@@ -102,13 +102,37 @@ class IvtCustomerProductModel {
}
//var_dump($filter);exit;
+ if(array_key_exists("lastdate", $filter)) {
+ $lastdate = $filter['lastdate'];
+ if($lastdate) {
+ $where .= " AND lastdate = '$lastdate'";
+ }
+ }
if(array_key_exists("lastdate>", $filter)) {
$lastdate = $filter['lastdate>'];
if($lastdate) {
- $where .= " AND lastdate >= $lastdate";
+ $where .= " AND lastdate >= '$lastdate'";
+ }
+ }
+ if(array_key_exists("lastdate<", $filter)) {
+ $lastdate = $filter['lastdate<'];
+ if($lastdate) {
+ $where .= " AND lastdate <= '$lastdate'";
+ }
+ }
+
+ if(array_key_exists("createdate>", $filter)) {
+ $createdate = $filter['createdate>'];
+ if($createdate) {
+ $where .= " AND createdate >= '$createdate'";
+ }
+ }
+ if(array_key_exists("createdate<", $filter)) {
+ $createdate = $filter['createdat<'];
+ if($createdate) {
+ $where .= " AND createdate <= '$createdate'";
}
}
-
//var_dump($filter, $where);exit;
return $where;
}
diff --git a/scripts/contract/test.php b/scripts/contract/test.php
index 6353f66b3..76d494589 100644
--- a/scripts/contract/test.php
+++ b/scripts/contract/test.php
@@ -13,10 +13,13 @@ require_once(LIBDIR."/mvcfronk/mfBase/mfBaseController.php");
$me = new User(1);
define("INTERNAL_USER_ID", $me->id);
+$finish_date_from = new DateTime("2024-05-31 22:00:00");
+$finish_date_to = new DateTime("2024-06-01 23:59:59");
+
$cms = 0;
$cmss = 0;
$cys = 0;
-foreach(ContractModel::getAll() as $contract) {
+foreach(ContractModel::search(["finish_date>" => $finish_date_from->getTimestamp(), "finish_date<" => $finish_date_to->getTimestamp()]) as $contract) {
if($contract->billing_period == 1 && $contract->price > 0.00000) {
$cms += $contract->price;
}
@@ -27,9 +30,9 @@ foreach(ContractModel::getAll() as $contract) {
}
-$First = new DateTime("2024-05-13 00:00:00");
+$First = new DateTime("2024-05-31 22:00:00");
//$First = new DateTime("2024-06-09 00:00:00");
-$Last = new DateTime("2024-06-12 23:59:59");
+$Last = new DateTime("2024-06-01 06:00:00");
foreach(ContractModel::search(["billing_period" => 12]) as $contract) {
$fdate = new DateTime("@".$contract->finish_date);
@@ -38,7 +41,7 @@ foreach(ContractModel::search(["billing_period" => 12]) as $contract) {
$d = $fdate->format("d");
//if(($m == 5 && $d >= 11) || ($m == 6 && $d <= 10)) {
- if($contract->finish_date >= $First->getTimestamp() && $contract->finish_date <= $Last->getTimestamp()) {
+ if($contract->finish_date >= $First->getTimestamp() && $contract->finish_date <= $Last->getTimestamp()) {
$cys += $contract->price;
}
}
@@ -53,11 +56,10 @@ echo "Contract Total Sum: $cts\n";
echo "======================================\n";
-
$ims = 0;
$iys = 0;
-foreach(IvtCustomerProductModel::getAll() as $ivt_contract) {
+foreach(IvtCustomerProductModel::search(["lastdate" => '2024-06-10']) as $ivt_contract) {
$product = $ivt_contract->product;
if($product->interval == 0) {
$ims += $product->price;
@@ -77,7 +79,7 @@ echo "======================================\n";
$ibs = 0;
-foreach(IvtBillModel::search(['date_outgoing>' => "2024-06-01"]) as $ivt_bill) {
+foreach(IvtBillModel::search(['date_outgoing' => "2024-06-10"]) as $ivt_bill) {
$positions = IvtBillPositionProductModel::search(["bid" => $ivt_bill->id]);
foreach($positions as $position) {
$ibs += $position->price;
@@ -89,4 +91,55 @@ echo "Ivt Bills Total Sum: $ibs\n";
echo "======================================\n";
$cid = $ibs - $cts;
-echo "Diff thetool <-> ivt Bills: $cid\n";
+echo "Diff thetool <-> ivt Bills: ".round($cid, 4)."\n";
+
+
+
+$gsm = 0;
+$gsy = 0;
+foreach(ContractModel::search(["price<" => 0, "finish_date>" => $finish_date_from->getTimestamp(), "finish_date<" => $finish_date_to->getTimestamp()]) as $contract) {
+ if($contract->billing_period == 1) {
+ $gsm += $contract->price;
+ } elseif($contract->billing_period == 12) {
+ $gsy += $contract->price;
+ }
+}
+
+$gst = $gsm + $gsy;
+
+echo "\n\n";
+echo "Contract Credit monthly: $gsm\n";
+echo "Contract Credit yearly: $gsy\n";
+echo "--------------------------------------\n";
+echo "Contract Credit Total: $gst\n";
+echo "======================================\n";
+
+$icm = 0;
+foreach(IvtCustomerCreditingModel::search(['lastdate' => '2024-06-10']) as $ivt_credit) {
+ $product = $ivt_credit->crediting_product;
+ $icm += $product->price_excl;
+}
+
+$icm *= -1;
+
+echo "IVT Credit Total: $icm\n";
+echo "======================================\n";
+
+$icbs = 0;
+
+foreach(IvtCreditingModel::search(["date_outgoing" => "2024-06-10"]) as $ivt_credit) {
+ foreach(IvtCreditingPositionModel::search(["head_id" => $ivt_credit->id]) as $position) {
+ $icbs += $position->price_excl;
+ }
+}
+
+$icbs *= -1;
+
+$cred_diff = $icbs - ($gsm + $gsy);
+
+echo "IVT Credit Bill Total: $icbs\n";
+echo "======================================\n";
+
+echo "\n";
+echo "Credit Diff thetool <-> ivt: ".round($cred_diff, 4)."\n";
+echo "======================================\n";
\ No newline at end of file
|