WIP Contract 2024-06-13
This commit is contained in:
@@ -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,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.<br />\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.<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])) {
|
||||
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";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)) {
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user