WIP Contract 2024-06-13
This commit is contained in:
@@ -147,6 +147,7 @@
|
||||
<th>Adresse</th>
|
||||
<th>Einheiten</th>
|
||||
<th>Status</th>
|
||||
<!--th class="text-center"><img src="<?=self::getResourcePath()?>assets/images/snopp-sm.png" style="width: 24px; height: 24px;" /> Export</th-->
|
||||
<th></th>
|
||||
</tr>
|
||||
<?php foreach($buildings as $building): ?>
|
||||
@@ -162,6 +163,7 @@
|
||||
</td>
|
||||
<td onclick="toggleBuilding(<?=$building->id?>)"><?=$building->units?></td>
|
||||
<td onclick="toggleBuilding(<?=$building->id?>)" class="text-monospace"><?=__($building->status->name."-b")?></td>
|
||||
<!--td><input type="checkbox" class="form-control" id="snopp-export-<?=$building->id?>" data-building-id="<?=$building->id?>" /></td-->
|
||||
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
|
||||
<a href="<?=self::getUrl("Building", "edit", ["id" => $building->id])?>"><i class="far fa-edit" title="Objekt Bearbeiten"></i></a>
|
||||
<a href="<?=self::getUrl("Building", "delete", ["id" => $building->id])?>" class="text-danger" onclick="if(!confirm('Objekt wirklich löschen?')) return false;" title="Objekt Löschen"><i class="fas fa-trash"></i></a>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,13 +82,34 @@ class Admin_IvtCreditImport {
|
||||
}
|
||||
|
||||
$contracts = ContractModel::search(["owner_id" => $customer->id]);
|
||||
$data = [];
|
||||
|
||||
// DEBUG: not all contracts imported yet
|
||||
/*
|
||||
* 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_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";
|
||||
$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
|
||||
@@ -108,10 +137,11 @@ class Admin_IvtCreditImport {
|
||||
// create Credit Contract
|
||||
|
||||
if(!$primary_contract->product_id) {
|
||||
var_dump($primary_contract);exit;
|
||||
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;
|
||||
@@ -128,6 +158,29 @@ class Admin_IvtCreditImport {
|
||||
$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,7 +209,34 @@ 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.<br />\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
// 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.<br />\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])) {
|
||||
@@ -160,8 +250,9 @@ class Admin_IvtCreditImport {
|
||||
$link->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo "Imported $i credits; $c Contracts erstellt\n";
|
||||
echo "Imported $i credits; $c Credit Contracts erstellt\n";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -854,11 +854,8 @@ 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($adb_network_ids);exit;
|
||||
|
||||
@@ -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'];
|
||||
|
||||
34
application/IvtCrediting/IvtCrediting.php
Normal file
34
application/IvtCrediting/IvtCrediting.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
class IvtCrediting extends mfBaseModel {
|
||||
|
||||
/**
|
||||
* 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";
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
}
|
||||
117
application/IvtCrediting/IvtCreditingModel.php
Normal file
117
application/IvtCrediting/IvtCreditingModel.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
|
||||
class IvtCreditingModel {
|
||||
|
||||
public static function create(array $data) {
|
||||
throw new Exception("Please use IvtCreditingController to create IvtCreditings");
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
||||
|
||||
$res = $db->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;
|
||||
}
|
||||
|
||||
}
|
||||
34
application/IvtCreditingPosition/IvtCreditingPosition.php
Normal file
34
application/IvtCreditingPosition/IvtCreditingPosition.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
class IvtCreditingPosition extends mfBaseModel {
|
||||
|
||||
/**
|
||||
* 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_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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
|
||||
class IvtCreditingPositionModel {
|
||||
|
||||
public static function create(array $data) {
|
||||
throw new Exception("Please use IvtCreditingPositionController to create IvtCreditingPositions");
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
||||
|
||||
$res = $db->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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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)) {
|
||||
@@ -100,6 +100,13 @@ class IvtCustomerCreditingModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("lastdate", $filter)) {
|
||||
$lastdate = $filter['lastdate'];
|
||||
if($lastdate) {
|
||||
$where .= " AND lastdate = '$lastdate'";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
@@ -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";
|
||||
Reference in New Issue
Block a user