WIP Contract/Billing 2024-06-20

This commit is contained in:
Frank Schubert
2024-06-21 12:10:04 +02:00
parent 92724ca6b5
commit da52a802ef
11 changed files with 752 additions and 29 deletions

View File

@@ -0,0 +1,97 @@
<?php
$pagination_baseurl = $this->getUrl($Mod, "Index");
$pagination_baseurl_params = ["filter" => $filter];
$pagination_entity_name = "Billingrecords";
?>
<?php include(realpath(dirname(__FILE__) . "/../../$mfLayoutPackage") . "/header.php"); ?>
<!-- start page title -->
<div class="row">
<div class="col-12">
<div class="page-title-box">
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="breadcrumb-item"><a href="<?=self::getUrl("Dashboard")?>"><?=MFAPPNAME_SLUG?></a>
</li>
<li class="breadcrumb-item active">Fertiggestellte Bestellungen</li>
</ol>
</div>
<h4 class="page-title">Contractfreigabe</h4>
</div>
</div>
</div>
<!-- end page title -->
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body mb-3">
<h4 class="header-title mb-3">Filter</h4>
<form method="get" action="<?=self::getUrl("Billing")?>">
<div class="row">
<div class="col-1">
<label class="form-label" for="filter_owner">Kundennummer</label>
<input type="text" class="form-control" name="filter[customer_number]" id="filter_street" value="<?=(array_key_exists("customer_number", $filter)) ? $filter['customer_number'] : ""?>"/>
</div>
</div>
<div class="row mt-2">
<div class="col">
<button type="submit" class="btn btn-primary">Filter anwenden</button>
<a class="btn btn-secondary" href="<?=self::getUrl("Billing")?>?resetFilter=1">Filter zurücksetzen</a>
</div>
</div>
</form>
</div>
</div>
<div class="card">
<div class="card-body mb-3">
<div class="row">
<div class="col-12">
<div class="float-left">
<h4 class="header-title">Fertiggestellte Bestellungen</h4>
<!--button type="submit" class="btn btn-primary"><i class="fas fa-fw fa-check"></i> Markierte Elemente als Contract übernehmen</button-->
</div>
<div class="float-right">
<a class="btn btn-outline-primary mb-2" href="<?=self::getUrl("Billing", "importContracts")?>">
<i class="fas fa-fw fa-file-import"></i> Verrechenbare Contracts importieren
</a>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination.php"); ?>
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination-summary.php"); ?>
<table class="table table-sm table-striped table-hover">
<tr>
<th></th>
</tr>
</table>
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination-summary.php"); ?>
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination.php"); ?>
</div>
</div>
</div>
</div>
</div>
</div>
<?php include(realpath(dirname(__FILE__) . "/../../$mfLayoutPackage") . "/footer.php"); ?>

View File

@@ -219,7 +219,7 @@ class AddressModel {
if (is_array($limit) && count($limit)) { if (is_array($limit) && count($limit)) {
if (is_numeric($limit['start']) && is_numeric($limit['count'])) { if (is_numeric($limit['start']) && is_numeric($limit['count'])) {
$sql .= " LIMIT " . $limit['start'] . ", " . $limit['count']; $sql .= " LIMIT " . $limit['start'] . ", " . $limit['count'];
} elseif (is_numeric($count)) { } elseif (is_numeric($limit['count'])) {
$sql .= " LIMIT " . $limit['count']; $sql .= " LIMIT " . $limit['count'];
} }
} }

View File

@@ -35,27 +35,13 @@ class AddresstypeModel {
return $model; 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() { public static function getAll() {
$items = []; $items = [];
$db = FronkDB::singleton(); $db = FronkDB::singleton();
$res = $db->select($this->table, "*"); $res = $db->select("Addresstype", "*");
if($db->num_rows($res)) { if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) { while($data = $db->fetch_object($res)) {
$items[] = new Addresstype($data); $items[] = new Addresstype($data);

View File

@@ -167,10 +167,12 @@ class Admin_IvtContractImport {
$order_date = new DateTime($ivt_contract->created); $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 = 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"); //$finish_date->modify("+1 hours");
$contract_data = []; $contract_data = [];

View File

@@ -0,0 +1,31 @@
<?php
class Billing extends mfBaseModel {
protected $forcestr = ["product_name","product_info","matchcode"];
public function getProperty($name) {
if($this->$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;
}
}

View File

@@ -0,0 +1,191 @@
<?php
class BillingController extends mfBaseController {
protected function init()
{
$this->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");
}
}

View File

@@ -0,0 +1,325 @@
<?php
class BillingModel {
public $invoice_id;
public $invoice_date;
public $contract_id;
public $start_date;
public $end_date;
public $billingaddress_id;
public $customer_number;
public $company;
public $firstname;
public $lastname;
public $street;
public $zip;
public $city;
public $country;
public $email;
public $uid;
public $billing_type;
public $billing_delivery;
public $bank_account_bank;
public $bank_account_owner;
public $bank_account_iban;
public $bank_account_bic;
public $matchcode;
public $product_id;
public $product_name;
public $product_info;
public $amount;
public $price;
public $price_setup;
public $billing_period;
public $create_by;
public $edit_by;
public $create;
public $edit;
public static function create(Array $data) {
$model = new Billing();
foreach($data as $field => $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;
}
}

View File

@@ -184,10 +184,6 @@ class ContractModel {
return $contract; return $contract;
} }
public function savePrecontract($contract) {
}
public static function getAll() { public static function getAll() {
$items = []; $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)) { if(array_key_exists("finish_date>", $filter)) {
$finish_date = $filter['finish_date>']; $finish_date = $filter['finish_date>'];
if(is_numeric($finish_date)) { if(is_numeric($finish_date)) {
@@ -489,6 +492,20 @@ class ContractModel {
} }
} }
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)) { if(array_key_exists("add-where", $filter)) {
$where .= " ".$filter['add-where']; $where .= " ".$filter['add-where'];
} }

View File

@@ -0,0 +1,72 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class CreateBilling extends AbstractMigration
{
public function up(): void
{
if($this->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") {
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

@@ -14,12 +14,13 @@ $me = new User(1);
define("INTERNAL_USER_ID", $me->id); define("INTERNAL_USER_ID", $me->id);
$finish_date_from = new DateTime("2024-05-31 22:00:00"); $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; $cms = 0;
$cmss = 0; $cmss = 0;
$cys = 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) { if($contract->billing_period == 1 && $contract->price > 0.00000) {
$cms += $contract->price; $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"); //$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) { foreach(ContractModel::search(["billing_period" => 12]) as $contract) {
$fdate = new DateTime("@".$contract->finish_date); $fdate = new DateTime("@".$contract->finish_date);
@@ -41,7 +42,8 @@ foreach(ContractModel::search(["billing_period" => 12]) as $contract) {
$d = $fdate->format("d"); $d = $fdate->format("d");
//if(($m == 5 && $d >= 11) || ($m == 6 && $d <= 10)) { //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; $cys += $contract->price;
} }
} }
@@ -97,7 +99,7 @@ echo "Diff thetool <-> ivt Bills: ".round($cid, 4)."\n";
$gsm = 0; $gsm = 0;
$gsy = 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) { if($contract->billing_period == 1) {
$gsm += $contract->price; $gsm += $contract->price;
} elseif($contract->billing_period == 12) { } elseif($contract->billing_period == 12) {