diff --git a/Layout/default/Billing/Index.php b/Layout/default/Billing/Index.php
new file mode 100644
index 000000000..f943a071d
--- /dev/null
+++ b/Layout/default/Billing/Index.php
@@ -0,0 +1,97 @@
+getUrl($Mod, "Index");
+$pagination_baseurl_params = ["filter" => $filter];
+$pagination_entity_name = "Billingrecords";
+?>
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/application/Address/AddressModel.php b/application/Address/AddressModel.php
index dc61e811a..73189b104 100644
--- a/application/Address/AddressModel.php
+++ b/application/Address/AddressModel.php
@@ -219,7 +219,7 @@ class AddressModel {
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'];
}
}
diff --git a/application/Addresstype/AddresstypeModel.php b/application/Addresstype/AddresstypeModel.php
index 0f30428ff..901eb0ff1 100644
--- a/application/Addresstype/AddresstypeModel.php
+++ b/application/Addresstype/AddresstypeModel.php
@@ -34,28 +34,14 @@ class AddresstypeModel {
return $model;
}
-
- public static function getOne($id) {
- if(!is_numeric($id) || !$id) {
- throw new Exception("Invalid number", 400);
- }
- $item = [];
- $db = FronkDB::singleton();
-
- $res = $db->select($this->table, "*", "id=$id LIMIT 1");
- if($db->num_rows($res)) {
- $data = $db->fetch_object($res);
- $item = new Addresstype($data);
- }
- return $item;
- }
+
public static function getAll() {
$items = [];
$db = FronkDB::singleton();
- $res = $db->select($this->table, "*");
+ $res = $db->select("Addresstype", "*");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new Addresstype($data);
diff --git a/application/Admin/functions/IvtContractImport.php b/application/Admin/functions/IvtContractImport.php
index d3d987c8b..d3f5076f3 100644
--- a/application/Admin/functions/IvtContractImport.php
+++ b/application/Admin/functions/IvtContractImport.php
@@ -167,10 +167,12 @@ class Admin_IvtContractImport {
$order_date = new DateTime($ivt_contract->created);
- $order_date->modify("+2 hours");
+ $order_date->setTime(0,0,0);
$finish_date = new DateTime($ivt_contract->lastdate);
- $finish_date->setDate($finish_date->format("Y"), $finish_date->format("m"), 1);
+ $finish_date->modify("first day of this month");
+ $finish_date->setTime(0,0,0);
+ //$finish_date->setDate($finish_date->format("Y"), $finish_date->format("m"), 1);
//$finish_date->modify("+1 hours");
$contract_data = [];
diff --git a/application/Billing/Billing.php b/application/Billing/Billing.php
new file mode 100644
index 000000000..82aecf33f
--- /dev/null
+++ b/application/Billing/Billing.php
@@ -0,0 +1,31 @@
+$name == null) {
+
+
+
+ $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;
+ }
+}
\ No newline at end of file
diff --git a/application/Billing/BillingController.php b/application/Billing/BillingController.php
new file mode 100644
index 000000000..55f85a210
--- /dev/null
+++ b/application/Billing/BillingController.php
@@ -0,0 +1,191 @@
+needlogin = true;
+ $me = new User();
+ $me->loadMe();
+ $this->me = $me;
+ $this->layout()->set("me", $me);
+
+ if (!$me->is(["Admin"])) {
+ $this->redirect("Dashboard");
+ }
+ }
+
+ protected function indexAction() {
+ $this->layout()->setTemplate("Billing/Index");
+
+ if ($this->request->resetFilter) {
+ unset($_SESSION[MFAPPNAME . '-Billing-filter']);
+ }
+
+ $filter = [];
+ if (is_array($this->request->filter)) {
+ $filter = $this->request->filter;
+ $_SESSION[MFAPPNAME . '-Billing-filter'] = $filter;
+ } else {
+ if (array_key_exists(MFAPPNAME . '-Billing-filter', $_SESSION) && count($_SESSION[MFAPPNAME . '-Billing-filter'])) {
+ $filter = $_SESSION[MFAPPNAME . '-Billing-filter'];
+ }
+ }
+
+ $this->layout->set("filter", $filter);
+ $filter = $this->getPreparedFilter($filter);
+
+ // pagination defaults
+ $pagination = [];
+ $pagination['start'] = 0;
+ $pagination['count'] = 50;
+ $pagination['maxItems'] = 0;
+
+ if (is_numeric($this->request->s)) {
+ $pagination['start'] = intval($this->request->s);
+ }
+ //var_dump($filter);exit;
+ $pagination['maxItems'] = BillingModel::count($filter);
+ $billings = BillingModel::search($filter, $pagination);
+
+ $this->layout()->set("billings", $billings);
+ $this->layout()->set("pagination", $pagination);
+
+ }
+
+ private function getPreparedFilter($filter)
+ {
+ $new_filter = [];
+
+ if (is_array($filter) && count($filter)) {
+ foreach ($filter as $name => $value) {
+ $new_filter[$name] = $value;
+ }
+ }
+
+ return $new_filter;
+ }
+
+ protected function importContractsAction() {
+ $r = $this->request;
+
+ $today = new DateTime("now");
+ $today->setTime(0,0,0);
+
+ //$tomorrow = new DateTime("tomorrow");
+ //$tomorrow->setTime(0,0,0);
+
+ $i = 0;
+
+ foreach(ContractModel::searchActive(["finish_date<" => $today->getTimestamp()]) as $contract) {
+ //var_dump($contract);exit;
+
+ $now_year = date("Y");
+ $now_month = date("m");
+ $now_day = date("d");
+
+ $finish_year = date("Y", $contract->finish_date);
+ $finish_month = date("m", $contract->finish_date);
+ $finish_day = date("d", $contract->finish_date);
+
+ $cancel_date = false;
+ if($contract->cancel_date) {
+ $cancel_date = new DateTime("@".$contract->cancel_date);
+ $cancel_date->setTime(0,0,0);
+ if($cancel_date->format("Y") != $now_year || $cancel_date->format("m") != $now_month) {
+ $cancel_date = false;
+ }
+ }
+
+ // find last Billing row
+ $last_billing = BillingModel::getLast(["contract_id" => $contract->id]);
+ if(!$last_billing) {
+ // First billing
+ // check finish_date
+ // create Billing with start_date=finish_date and end_date = end of billing_period (month or year)
+
+ $start_date = new DateTime("@".$contract->finish_date);
+ $start_date->setTime(2,0,0);
+
+ $price_setup = $contract->price_setup;
+ } else {
+ // Concurrent Billing
+ // start_date next date after previous end_date
+
+ $start_date = new DateTime($last_billing->end_date);
+ $start_date->modify("+1 month");
+
+ // set Setup price to 0, because it was billed already
+ $price_setup = 0;
+ }
+
+
+
+ // if contract has cancel date this month
+ // use cancel date as end_date
+ if($cancel_date) {
+ $end_date = clone($cancel_date);
+ } else {
+ // else calculate last of month
+ $end_date = clone($start_date);
+ $end_date->modify("+".$contract->billing_period." months");
+ $end_date->modify("first day of this month");
+ $end_date->modify("-1 day");
+ }
+
+ $sday = $start_date->format("d");
+ $eday = $end_date->format("d");
+
+ if($sday > 1 || $cancel_date) {
+ // aliquoter preis
+ $days = ($eday - $sday) + 1;
+ $pc = $days / $eday * 100;
+ $price = round($contract->price / 100 * $pc, 4);
+ } else {
+ $price = $contract->price;
+ }
+
+ $owner = $contract->owner;
+ $billingaddress = $contract->billingaddress;
+
+ $data = [];
+ $data["contract_id"] = $contract->id;
+ $data["start_date"] = $start_date->format("Y-m-d");
+ $data["end_date"] = $end_date->format("Y-m-d");
+ $data["billingaddress_id"] = ($contract->billingaddress_id) ? $contract->billingaddress_id : $contract->owner_id;
+ $data["customer_number"] = $contract->owner->customer_number;
+ $data["company"] = $billingaddress->company;
+ $data["firstname"] = $billingaddress->firstname;
+ $data["lastname"] = $billingaddress->lastname;
+ $data["street"] = $billingaddress->street;
+ $data["zip"] = $billingaddress->zip;
+ $data["city"] = $billingaddress->city;
+ $data["country"] = $billingaddress->country->name;
+ $data["email"] = $billingaddress->email;
+ $data["uid"] = $billingaddress->uid;
+ $data["billing_type"] = $billingaddress->billing_type;
+ $data["billing_delivery"] = $billingaddress->billing_delivery;
+ $data["bank_account_bank"] = $billingaddress->bank_account_bank;
+ $data["bank_account_owner"] = $billingaddress->bank_account_owner;
+ $data["bank_account_iban"] = $billingaddress->bank_account_iban;
+ $data["bank_account_bic"] = $billingaddress->bank_account_bic;
+ $data["matchcode"] = $contract->mathcode;
+ $data["product_id"] = $contract->product_id;
+ $data["product_name"] = $contract->product_name;
+ $data["product_info"] = $contract->product_info;
+ $data["amount"] = $contract->amount;
+ $data["price"] = $price;
+ $data["price_setup"] = $price_setup;
+ $data["billing_period"] = $contract->billing_period;
+
+ $billing = BillingModel::create($data);
+ if(!$billing->save()) {
+ var_dump($billing);exit;
+ }
+
+ $i++;
+
+ }
+ $this->layout()->setFlash("$i Billing records generiert");
+ }
+}
\ No newline at end of file
diff --git a/application/Billing/BillingModel.php b/application/Billing/BillingModel.php
new file mode 100644
index 000000000..07b2b1793
--- /dev/null
+++ b/application/Billing/BillingModel.php
@@ -0,0 +1,325 @@
+ $value) {
+ if(property_exists(get_called_class(), $field)) {
+ $model ->$field = $value;
+ }
+ }
+
+ $me = new User();
+ $me->loadMe();
+
+ if($model->create_by === null) {
+ $model->create_by = $me->id;
+ }
+ if($model->edit_by === null) {
+ $model->edit_by = $me->id;
+ }
+
+ return $model;
+ }
+
+ public static function getAll() {
+ $items = [];
+
+ $db = FronkDB::singleton();
+
+ $res = $db->select("Billing", "*", "1 = 1 ORDER BY billingaddress_id");
+ if($db->num_rows($res)) {
+ while($data = $db->fetch_object($res)) {
+ $items[] = new Billing($data);
+ }
+ }
+ return $items;
+
+ }
+
+ public static function getFirst($filter) {
+ $db = FronkDB::singleton();
+
+ $where = self::getSqlFilter($filter);
+ $sql = "SELECT * FROM Billing
+ WHERE $where
+ ORDER BY billingaddress_id LIMIT 1";
+ //var_dump($sql);exit;
+ $res = $db->query($sql);
+ if($db->num_rows($res)) {
+ $data = $db->fetch_object($res);
+ $item = new Billing($data);
+ if($item->id) {
+ return $item;
+ } else {
+ return null;
+ }
+ }
+ return null;
+ }
+
+ public static function getLast($filter) {
+ $db = FronkDB::singleton();
+
+ $where = self::getSqlFilter($filter);
+ $sql = "SELECT * FROM Billing
+ WHERE $where
+ ORDER BY `create` DESC LIMIT 1";
+ //var_dump($sql);exit;
+ $res = $db->query($sql);
+ if($db->num_rows($res)) {
+ $data = $db->fetch_object($res);
+ $item = new Billing($data);
+ if($item->id) {
+ return $item;
+ } else {
+ return null;
+ }
+ }
+ return null;
+ }
+
+ public static function count($filter) {
+ $db = FronkDB::singleton();
+
+ $where = self::getSqlFilter($filter);
+ $sql = "SELECT COUNT(*) as cnt FROM Billing
+ WHERE $where";
+
+ mfLoghandler::singleton()->debug($sql);
+
+ $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) {
+ //var_dump($filter);exit;
+ $items = [];
+ $db = FronkDB::singleton();
+
+ $where = self::getSqlFilter($filter);
+ $sql = "SELECT * FROM Billing
+ WHERE $where
+ ORDER BY billingaddress_id";
+
+ 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'];
+ }
+ }
+
+ mfLoghandler::singleton()->debug($sql);
+
+ $res = $db->query($sql);
+ if($db->num_rows($res)) {
+ while($data = $db->fetch_object($res)) {
+ $items[$data->id] = new Billing($data);
+ }
+ }
+
+ return $items;
+ }
+
+ private static function getSqlFilter($filter) {
+ $where = "1=1 ";
+
+ $db = FronkDB::singleton();
+
+ //var_dump($filter);exit;
+
+ if(array_key_exists("id", $filter)) {
+ $id = $filter['id'];
+ if(is_numeric($id)) {
+ $where .= " AND Billing.id like '%$id%'";
+ }
+ }
+
+ if(array_key_exists("approved", $filter)) {
+ $approved = $filter['approved'];
+ if($approved) {
+ $where .= " AND Billing.approved = 1";
+ } else {
+ $where .= " AND Billing.approved = 0";
+ }
+ }
+
+ if(array_key_exists("invoice_id", $filter)) {
+ $invoice_id = $filter['invoice_id'];
+ if(is_numeric($invoice_id)) {
+ $where .= " AND Billing.invoice_id=$invoice_id";
+ }
+ }
+
+ if(array_key_exists("invoice_date", $filter)) {
+ $invoice_date = $filter['invoice_date'];
+ if($invoice_date) {
+ $where .= " AND Billing.invoice_date='$invoice_date'";
+ }
+ }
+
+ if(array_key_exists("contract_id", $filter)) {
+ $contract_id = $filter['contract_id'];
+ if(is_numeric($contract_id)) {
+ $where .= " AND Billing.contract_id=$contract_id";
+ }
+ }
+
+ if(array_key_exists("billingaddress_id", $filter)) {
+ $billingaddress_id = $filter['billingaddress_id'];
+ if(is_numeric($billingaddress_id)) {
+ $where .= " AND Billing.billingaddress_id=$billingaddress_id";
+ }
+ }
+
+ if(array_key_exists("customer_number", $filter)) {
+ $customer_number = $filter['customer_number'];
+ if(is_numeric($customer_number)) {
+ $where .= " AND Billing.customer_number LIKE $customer_number";
+ }
+ }
+
+ if (array_key_exists("company", $filter)) {
+ $company = FronkDB::singleton()->escape($filter["company"]);
+ if ($company) {
+ $where .= " AND company like '%$company%'";
+ }
+ }
+
+ if (array_key_exists("firstname", $filter)) {
+ $firstname = FronkDB::singleton()->escape($filter["firstname"]);
+ if ($firstname) {
+ $where .= " AND firstname like '%$firstname%'";
+ }
+ }
+
+ if (array_key_exists("lastname", $filter)) {
+ $lastname = FronkDB::singleton()->escape($filter["lastname"]);
+ if ($lastname) {
+ $where .= " AND lastname like '%$lastname%'";
+ }
+ }
+
+ if (array_key_exists("mergedName", $filter)) {
+ $name = FronkDB::singleton()->escape($filter["mergedName"]);
+ if ($name) {
+ $where .= " AND (CONCAT(firstname, ' ', lastname) like '%$name%' OR CONCAT(lastname, ' ', firstname) like '%$name%' )";
+ }
+ }
+
+ if (array_key_exists("street", $filter)) {
+ $street = FronkDB::singleton()->escape($filter["street"]);
+ if ($street) {
+ $where .= " AND street like '%$street%'";
+ }
+ }
+
+ if (array_key_exists("zip", $filter)) {
+ $zip = FronkDB::singleton()->escape($filter["zip"]);
+ if ($zip) {
+ $where .= " AND zip like '%$zip%'";
+ }
+ }
+
+ if (array_key_exists("city", $filter)) {
+ $city = FronkDB::singleton()->escape($filter["city"]);
+ if ($city) {
+ $where .= " AND city like '%$city%'";
+ }
+ }
+
+ if (array_key_exists("country", $filter)) {
+ $country = FronkDB::singleton()->escape($filter["country"]);
+ if ($country) {
+ $where .= " AND country like '%$country%'";
+ }
+ }
+
+ if (array_key_exists("email", $filter)) {
+ $email = FronkDB::singleton()->escape($filter["email"]);
+ if ($email) {
+ $where .= " AND email like '%$email%'";
+ }
+ }
+
+ if(array_key_exists("matchcode", $filter)) {
+ $matchcode = FronkDB::singleton()->escape($filter["matchcode"]);
+ if($matchcode) {
+ $where .= " AND matchcode like '%$matchcode%'";
+ }
+ }
+
+ if(array_key_exists("product_id", $filter)) {
+ $product_id = $filter['product_id'];
+ if(is_numeric($product_id)) {
+ $where .= " AND Billing.product_id=$product_id";
+ }
+ }
+
+ if(array_key_exists("product_name", $filter)) {
+ $product_name = $db->escape($filter['product_name']);
+ if($product_name) {
+ $where .= " AND product_name like '%$product_name%')";
+ }
+ }
+
+ if(array_key_exists("matchcode", $filter)) {
+ $matchcode = $db->escape($filter['matchcode']);
+ if($matchcode) {
+ $where .= " AND Billing.`matchcode` like '%$matchcode%'";
+ }
+ }
+
+ if(array_key_exists("add-where", $filter)) {
+ $where .= " ".$filter['add-where'];
+ }
+
+
+ //var_dump($filter, $where);exit;
+ return $where;
+ }
+
+}
diff --git a/application/Contract/ContractModel.php b/application/Contract/ContractModel.php
index c35e4daf7..94d78d311 100644
--- a/application/Contract/ContractModel.php
+++ b/application/Contract/ContractModel.php
@@ -184,10 +184,6 @@ class ContractModel {
return $contract;
}
- public function savePrecontract($contract) {
-
- }
-
public static function getAll() {
$items = [];
@@ -475,6 +471,13 @@ 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("finish_date>", $filter)) {
$finish_date = $filter['finish_date>'];
if(is_numeric($finish_date)) {
@@ -488,6 +491,20 @@ class ContractModel {
$where .= " AND Contract.finish_date <= $finish_date";
}
}
+
+ if(array_key_exists("cancel_date>", $filter)) {
+ $cancel_date = $filter['cancel_date>'];
+ if(is_numeric($cancel_date)) {
+ $where .= " AND Contract.cancel_date >= $cancel_date";
+ }
+ }
+
+ if(array_key_exists("cancel_date<", $filter)) {
+ $cancel_date = $filter['cancel_date<'];
+ if(is_numeric($cancel_date)) {
+ $where .= " AND Contract.cancel_date <= $cancel_date";
+ }
+ }
if(array_key_exists("add-where", $filter)) {
$where .= " ".$filter['add-where'];
diff --git a/db/migrations/20240620160026_create_billing.php b/db/migrations/20240620160026_create_billing.php
new file mode 100644
index 000000000..5eb323ad2
--- /dev/null
+++ b/db/migrations/20240620160026_create_billing.php
@@ -0,0 +1,72 @@
+getEnvironment() == "thetool") {
+ $table = $this->table("Billing");
+ $table->addColumn("invoice_id", "integer", ["null" => true, "default" => null]);
+ $table->addColumn("invoice_date", "date", ["null" => true, "default" => null]);
+ $table->addColumn("contract_id", "integer", ["null" => false]);
+ $table->addColumn("start_date", "date", ["null" => false]);
+ /*$table->addColumn("start_year", "integer", ["null" => false]);
+ $table->addColumn("start_month", "integer", ["null" => false]);
+ $table->addColumn("start_day", "integer", ["null" => false]);*/
+ $table->addColumn("end_date", "date", ["null" => false]);
+ /*$table->addColumn("end_year", "integer", ["null" => false]);
+ $table->addColumn("end_month", "integer", ["null" => false]);
+ $table->addColumn("end_day", "integer", ["null" => false]);*/
+ $table->addColumn("billingaddress_id", "integer", ["null" => false]);
+ $table->addColumn("customer_number", "integer", ["null" => false]);
+ $table->addColumn("company", "string", ["null" => true, "default" => null, "length" => 1024]);
+ $table->addColumn("firstname", "string", ["null" => true, "default" => null, "length" => 1024]);
+ $table->addColumn("lastname", "string", ["null" => true, "default" => null, "length" => 1024]);
+ $table->addColumn("street", "string", ["null" => false, "length" => 1024]);
+ $table->addColumn("zip", "string", ["null" => false, "length" => 1024]);
+ $table->addColumn("city", "string", ["null" => false, "length" => 1024]);
+ $table->addColumn("country", "string", ["null" => true, "default" => null, "length" => 1024]);
+ $table->addColumn("email", "string", ["null" => true, "default" => null, "length" => 1024]);
+ $table->addColumn("uid", "string", ["null" => true, "default" => null, "length" => 1024]);
+ $table->addColumn("billing_type", "enum", ["null" => false, "values" => "invoice,sepa"]);
+ $table->addColumn("billing_delivery", "enum", ["null" => false, "values" => "email,paper"]);
+ $table->addColumn("bank_account_bank", "string", ["null" => true, "default" => null, "length" => 255]);
+ $table->addColumn("bank_account_owner", "string", ["null" => true, "default" => null, "length" => 255]);
+ $table->addColumn("bank_account_iban", "string", ["null" => true, "default" => null, "length" => 255]);
+ $table->addColumn("bank_account_bic", "string", ["null" => true, "default" => null, "length" => 255]);
+ $table->addColumn("matchcode", "string", ["null" => true, "default" => null, "length" => 255]);
+ $table->addColumn("product_id", "integer", ["null" => false]);
+ $table->addColumn("product_name", "string", ["null" => false, "length" => 255]);
+ $table->addColumn("product_info", "text", ["null" => true, "default" => null]);
+ $table->addColumn("amount", "decimal", ["null" => false, "precision" => 9, "scale" => 6]);
+ $table->addColumn("price", "decimal", ["null" => false, "precision" => 14, "scale" => 4]);
+ $table->addColumn("price_setup", "decimal", ["null" => false, "default" => 0, "precision" => 14, "scale" => 4]);
+ $table->addColumn("billing_period", "integer", ["null" => false, "default" => 0]);
+
+ $table->addColumn("create_by", "integer", ["null" => false]);
+ $table->addColumn("edit_by", "integer", ["null" => false]);
+ $table->addColumn("create", "integer", ["null" => false]);
+ $table->addColumn("edit", "integer", ["null" => false]);
+ $table->create();
+
+ }
+
+ if($this->getEnvironment() == "addressdb") {
+
+ }
+ }
+
+ public function down(): void
+ {
+ if($this->getEnvironment() == "thetool") {
+ $this->table("Billing")->drop()->save();
+ }
+
+ if($this->getEnvironment() == "addressdb") {
+
+ }
+ }
+}
diff --git a/public/assets/images/snopp-sm.png b/public/assets/images/snopp-sm.png
new file mode 100644
index 000000000..7eb02f36e
Binary files /dev/null and b/public/assets/images/snopp-sm.png differ
diff --git a/scripts/contract/test.php b/scripts/contract/test.php
index 76d494589..c0f01e28c 100644
--- a/scripts/contract/test.php
+++ b/scripts/contract/test.php
@@ -14,12 +14,13 @@ $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");
+$finish_date_to = new DateTime("2024-06-01 02:00:00");
+$finish_date = new DateTime("2024-06-01 00:00:00");
$cms = 0;
$cmss = 0;
$cys = 0;
-foreach(ContractModel::search(["finish_date>" => $finish_date_from->getTimestamp(), "finish_date<" => $finish_date_to->getTimestamp()]) as $contract) {
+foreach(ContractModel::search(["finish_date" => $finish_date->getTimestamp()]) as $contract) {
if($contract->billing_period == 1 && $contract->price > 0.00000) {
$cms += $contract->price;
}
@@ -30,9 +31,9 @@ foreach(ContractModel::search(["finish_date>" => $finish_date_from->getTimestamp
}
-$First = new DateTime("2024-05-31 22:00:00");
+$First = new DateTime("2023-05-31 22:00:00");
//$First = new DateTime("2024-06-09 00:00:00");
-$Last = new DateTime("2024-06-01 06:00:00");
+$Last = new DateTime("2024-06-01 00:00:00");
foreach(ContractModel::search(["billing_period" => 12]) as $contract) {
$fdate = new DateTime("@".$contract->finish_date);
@@ -41,7 +42,8 @@ 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()) {
+ if($contract->finish_date == $Last->getTimestamp()) {
$cys += $contract->price;
}
}
@@ -97,7 +99,7 @@ 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) {
+foreach(ContractModel::search(["price<" => 0, "finish_date" => $finish_date->getTimestamp()]) as $contract) {
if($contract->billing_period == 1) {
$gsm += $contract->price;
} elseif($contract->billing_period == 12) {