diff --git a/Layout/default/Contract/Index.php b/Layout/default/Contract/Index.php index 6db6634a5..2c7a54fea 100644 --- a/Layout/default/Contract/Index.php +++ b/Layout/default/Contract/Index.php @@ -137,7 +137,7 @@ biennal billing_period == 36): ?> triennal - + billing_period): ?> billing_period)?>x Jährlich diff --git a/application/Admin/functions/IvtContractImport.php b/application/Admin/functions/IvtContractImport.php index 93fc58768..ddc3469ba 100644 --- a/application/Admin/functions/IvtContractImport.php +++ b/application/Admin/functions/IvtContractImport.php @@ -91,6 +91,9 @@ class Admin_IvtContractImport { $last_cid = 0; $i = 0; + $maxIvtContracts = IvtCustomerProductModel::count([]); + echo "Importing from $maxIvtContracts Ivt customer_products\n"; + foreach(IvtCustomerProductModel::getAll() as $ivt_contract) { //if($ivt_contract->cid < 104200) continue; //if($i > 1000 && $ivt_contract->cid != $last_cid) break; // only break after the last ivtcontract of this customer @@ -166,6 +169,9 @@ class Admin_IvtContractImport { $finish_date = new DateTime($ivt_contract->created); $finish_date->modify("+2 hours"); + $last_date = new DateTime($ivt_contract->lastdate); + $last_date->modify("+1 day"); + $last_date->modify("+1 hours"); $contract_data = []; $contract_data['owner_id'] = $customer->id; @@ -179,7 +185,7 @@ class Admin_IvtContractImport { $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'] = $finish_date->getTimestamp(); + $contract_data['finish_date'] = $last_date->getTimestamp(); $contract_data['finish_date_by'] = 1; $contract_data['imported_from'] = "ivt"; $contract_data['imported_data'] = $ivt_contract->id; @@ -208,8 +214,9 @@ class Admin_IvtContractImport { $contract_data['price'] = 0; $contract_data['price_setup'] = $ip->price; $contract_data['billing_period'] = 0; - $neu['action'] = "ignore"; - $ignore = true; + //$neu['action'] = "ignore"; + + //$ignore = true; } // filter cancelled products @@ -247,7 +254,7 @@ class Admin_IvtContractImport { } /* - * Create Contract (dont save yet) + * Create Contract (don't save yet) */ $contract = ContractModel::create($contract_data); if(trim($ivt_contract->comment)) { diff --git a/application/Contract/ContractModel.php b/application/Contract/ContractModel.php index cf3159c73..30c916861 100644 --- a/application/Contract/ContractModel.php +++ b/application/Contract/ContractModel.php @@ -315,7 +315,7 @@ class ContractModel { return 0; } - public static function search($filter, $limit = false) { + public static function search($filter = [], $limit = false) { //var_dump($filter);exit; $items = []; $db = FronkDB::singleton(); diff --git a/application/IvtBill/IvtBillModel.php b/application/IvtBill/IvtBillModel.php index 3a031606b..d6365313f 100644 --- a/application/IvtBill/IvtBillModel.php +++ b/application/IvtBill/IvtBillModel.php @@ -59,13 +59,13 @@ class IvtBillModel { $db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME); $where = self::getSqlFilter($filter); - $sql = "SELECT * FROM bills $where ORDER by id"; + $sql = "SELECT * FROM bills 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($count)) { + } elseif(is_numeric($limit['count'])) { $sql .= " LIMIT ".$limit['count']; } } @@ -88,7 +88,27 @@ class IvtBillModel { $where .= " AND bills.cid=$cid"; } } - + + if(array_key_exists("date_outgoing", $filter)) { + $date_outgoing = $filter['date_outgoing']; + if($date_outgoing) { + $where .= " AND bills.date_outgoing='$date_outgoing'"; + } + } + + if(array_key_exists("date_outgoing>", $filter)) { + $date_outgoing = $filter['date_outgoing>']; + if($date_outgoing) { + $where .= " AND bills.date_outgoing >= '$date_outgoing'"; + } + } + + if(array_key_exists("date_outgoing<", $filter)) { + $date_outgoing = $filter['date_outgoing<']; + if($date_outgoing) { + $where .= " AND bills.date_outgoing <= '$date_outgoing'"; + } + } /* if(array_key_exists("status_id", $filter)) { $status_id = $filter['status_id']; diff --git a/application/IvtBillPositionProduct/IvtBillPositionProduct.php b/application/IvtBillPositionProduct/IvtBillPositionProduct.php new file mode 100644 index 000000000..b1ca18b37 --- /dev/null +++ b/application/IvtBillPositionProduct/IvtBillPositionProduct.php @@ -0,0 +1,5 @@ +select("bills_positions_products", "*", "1=1 ORDER BY id"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new IvtBillPositionProduct($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("bills_positions_products", "*", "$where ORDER BY id LIMIT 1"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new IvtBillPositionProduct($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("bills_positions_products", "*", "$where ORDER BY id DESC LIMIT 1"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new IvtBillPositionProduct($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 bills_positions_products 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 IvtBillPositionProduct($data); + } + } + return $items; + } + + private static function getSqlFilter($filter) { + $where = "1=1 "; + + if(array_key_exists("bid", $filter)) { + $bid = $filter['bid']; + if($bid) { + $where .= " AND bid='$bid'"; + } + } + + + /* + if(array_key_exists("status_id", $filter)) { + $status_id = $filter['status_id']; + if(is_numeric($status_id)) { + $where .= " AND IvtBillPositionProduct.status_id=$status_id"; + } + } + + + if(array_key_exists("street", $filter)) { + $street = FronkDB::singleton()->escape($filter["street"]); + if($street) { + $where .= " AND street like '%$street%'"; + } + } + */ + + //var_dump($filter, $where);exit; + return $where; + } + +} diff --git a/scripts/contract/test.php b/scripts/contract/test.php index 6a8c60875..6353f66b3 100644 --- a/scripts/contract/test.php +++ b/scripts/contract/test.php @@ -14,26 +14,43 @@ $me = new User(1); define("INTERNAL_USER_ID", $me->id); $cms = 0; +$cmss = 0; $cys = 0; -foreach(ContractModel::search(["billing_period" => 1]) as $contract) { - $cms += $contract->price; +foreach(ContractModel::getAll() as $contract) { + if($contract->billing_period == 1 && $contract->price > 0.00000) { + $cms += $contract->price; + } + if($contract->price_setup && $contract->price_setup > 0.00000) { + $cmss += $contract->price_setup; + } + } -$First = new DateTime("2024-04-10 00:00:00"); -$Last = new DateTime("2024-05-10 23:59:59"); + +$First = new DateTime("2024-05-13 00:00:00"); +//$First = new DateTime("2024-06-09 00:00:00"); +$Last = new DateTime("2024-06-12 23:59:59"); foreach(ContractModel::search(["billing_period" => 12]) as $contract) { - if($contract->finish_date >= $First->getTimestamp() && $contract->finish_date <= $Last->getTimestamp()) { + $fdate = new DateTime("@".$contract->finish_date); + $y = $fdate->format("Y"); + $m = $fdate->format("m"); + $d = $fdate->format("d"); + + //if(($m == 5 && $d >= 11) || ($m == 6 && $d <= 10)) { + if($contract->finish_date >= $First->getTimestamp() && $contract->finish_date <= $Last->getTimestamp()) { $cys += $contract->price; } } -$cts = $cms + $cys; +$cts = $cms + $cys + $cmss; echo "Contract Monthly Sum: $cms\n"; +echo "Contract Setup Sum: $cmss\n"; echo "Contract Yearly Sum: $cys\n"; +echo "--------------------------------------\n"; echo "Contract Total Sum: $cts\n"; - +echo "======================================\n"; @@ -42,15 +59,34 @@ $iys = 0; foreach(IvtCustomerProductModel::getAll() as $ivt_contract) { $product = $ivt_contract->product; - if($product->interval < 1) { + if($product->interval == 0) { $ims += $product->price; - } elseif($product->interval == 1 && $ivt_contract->lastdate == "2023-06-06") { + } elseif($product->interval == 1 && $ivt_contract->lastdate == "2024-06-10") { $iys += $product->price; } } $its = $ims + $iys; -echo "IvtContract Monthly Sum: $ims\n"; -echo "IvtContract Yearly Sum: $iys\n"; -echo "IvtContract Total Sum: $its\n"; \ No newline at end of file +echo "\n"; +echo "Ivt product_customer Monthly Sum: $ims\n"; +echo "Ivt product_customer Yearly Sum: $iys\n"; +echo "--------------------------------------\n"; +echo "Ivt product_customer Total Sum: $its\n"; +echo "======================================\n"; + +$ibs = 0; + +foreach(IvtBillModel::search(['date_outgoing>' => "2024-06-01"]) as $ivt_bill) { + $positions = IvtBillPositionProductModel::search(["bid" => $ivt_bill->id]); + foreach($positions as $position) { + $ibs += $position->price; + } +} + +//echo "\n"; +echo "Ivt Bills Total Sum: $ibs\n"; +echo "======================================\n"; + +$cid = $ibs - $cts; +echo "Diff thetool <-> ivt Bills: $cid\n";