@@ -73,8 +87,62 @@ $pagination_entity_name = "Billingrecords";
+ | Contract ID |
+ Periode |
+ Vertragsinhaber |
+ Rechnungsadresse |
+ Kundennummer |
+ Einzug |
+ Zustellung |
+ Bankdaten |
+ Produkt |
+ Anzahl |
+ Preis |
+ Preis Setup |
|
+
+
+ | $billing->contract_id])?>" target="_blank">=$billing->contract_id?> |
+ =$billing->start_date?> - =$billing->end_date?> |
+
+ =$billing->contract->owner->getCompanyOrName()?>
+ =$billing->contract->owner->street?>
+ =$billing->contract->owner->zip?> =$billing->contract->owner->city?>
+ =$billing->contract->owner->country->name?>
+ |
+
+ =($billing->company) ? $billing->company." " : ""?>
+ =($billing->firstname || $billing->lastname) ? $billing->firstname." ".$billing->lastname." " : ""?>
+ =$billing->street?>
+ =$billing->zip?> =$billing->city?>
+ =$billing->country?>
+ |
+ =$billing->customer_number?> |
+ =($billing->billing_type == "sepa") ? "SEPA" : ""?> |
+ =($billing->billing_delivery == "email") ? "Email" : "Papier"?> |
+
+ billing_type == "sepa"): ?>
+ Kontoinhaber: =$billing->bank_account_owner?>
+ Bank: =$billing->bank_account_bank?>
+ IBAN: =$billing->bank_account_iban?>
+ BIC: =$billing->bank_account_bic?>
+
+ |
+
+ =$billing->product_name?>=($billing->matchcode) ? " (".$billing->matchcode.")" : ""?>
+ product_info): ?>
+
+ =$billing->product_info?>
+
+
+ |
+ =number_format($billing->amount,3,",",".")?> |
+ € =number_format($billing->price,4,",",".")?> |
+ € =number_format($billing->price_setup,4,",",".")?> |
+ |
+
+
diff --git a/Layout/default/Contract/Index.php b/Layout/default/Contract/Index.php
index 2c7a54fea..8926ffc5f 100644
--- a/Layout/default/Contract/Index.php
+++ b/Layout/default/Contract/Index.php
@@ -128,8 +128,8 @@
-->
-
=(!$contract->isFinished()) ? "not-finished" : "" ?> =($contract->price < 0) ? "text-danger" : ""?>">=$contract->price?> |
-
=(!$contract->isFinished()) ? "not-finished" : "" ?> =($contract->price_setup < 0) ? "text-danger" : ""?>">=$contract->price_setup?> |
+
=(!$contract->isFinished()) ? "not-finished" : "" ?> =($contract->price < 0) ? "text-danger" : ""?>">€ =number_format($contract->price,4,",",".")?> |
+
=(!$contract->isFinished()) ? "not-finished" : "" ?> =($contract->price_setup < 0) ? "text-danger" : ""?>">€ =number_format($contract->price_setup,4,",",".")?> |
=(!$contract->isFinished()) ? "not-finished" : "" ?>">
billing_period == 1): ?>
monatlich
diff --git a/application/Admin/functions/IvtContractImport.php b/application/Admin/functions/IvtContractImport.php
index d3f5076f3..c9351c0bf 100644
--- a/application/Admin/functions/IvtContractImport.php
+++ b/application/Admin/functions/IvtContractImport.php
@@ -4,6 +4,7 @@ class Admin_IvtContractImport {
private $request;
private $log;
private $static_ivt_order_match = [];
+ private $no_matchcode = [];
public function __construct($request = false) {
$this->request = $request;
@@ -77,6 +78,13 @@ class Admin_IvtContractImport {
16267 => 3079, // schmuck marianne
16786 => 3079
];
+ $this->no_matchcode = [
+ 9,
+ 2847,
+ 3049,
+ 5719
+
+ ];
}
/* TODO: Credit */
@@ -166,14 +174,9 @@ class Admin_IvtContractImport {
- $order_date = new DateTime($ivt_contract->created);
- $order_date->setTime(0,0,0);
- $finish_date = new DateTime($ivt_contract->lastdate);
- $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 = [];
$contract_data['owner_id'] = $customer->id;
@@ -186,23 +189,35 @@ 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'] = $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;
$contract_data['create_by'] = 1;
$contract_data['edit_by'] = 1;
+ $finish_date = new DateTime($ivt_contract->lastdate);
+
switch($ip->interval) {
case 0:
$contract_data['billing_period'] = 1;
+ $finish_date->modify("+1 month");
break;
case 1:
$contract_data['billing_period'] = 12;
+ $finish_date->modify("+1 year");
break;
}
+ $order_date = new DateTime($ivt_contract->created);
+ $order_date->setTime(2,0,0);
+
+ $finish_date->modify("first day of this month");
+ $finish_date->setTime(2,0,0);
+ //$finish_date->setDate($finish_date->format("Y"), $finish_date->format("m"), 1);
+ //$finish_date->modify("+1 hours");
+
+ $contract_data['order_date'] = $order_date->getTimestamp();
+ $contract_data['finish_date'] = $finish_date->getTimestamp();
+ $contract_data['finish_date_by'] = 1;
$neu["customer"] = $customer;
$neu["ivtcustomer"] = $ivt_customer;
@@ -321,6 +336,8 @@ class Admin_IvtContractImport {
foreach($new_contracts as $ivt_customer_id => $contracts) {
$this->addVoipData($ivt_customer_id, $contracts);
+ if(in_array($ivt_contract->id, $this->no_matchcode)) break;
+
if(count($contracts) < 2) continue;
$prev_contracts = [];
$primary_matchcode = false;
diff --git a/application/Admin/functions/IvtCreditImport.php b/application/Admin/functions/IvtCreditImport.php
index 66149db77..cc90709cc 100644
--- a/application/Admin/functions/IvtCreditImport.php
+++ b/application/Admin/functions/IvtCreditImport.php
@@ -163,7 +163,9 @@ class Admin_IvtCreditImport {
$create_date->setTime(2,0);
$finish_date = new DateTime($cust_cred->lastdate);
- $finish_date->setDate($finish_date->format("Y"), $finish_date->format("m"), 1);
+ $finish_date->modify("first day of this month");
+ $finish_date->setTime(2,0,0);
+ //$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]
@@ -227,8 +229,7 @@ class Admin_IvtCreditImport {
$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.")"
+ 'value' => $cred_contract->id,
]);
$journal_id = $journal->save();
if(!$journal_id) {
diff --git a/application/Billing/Billing.php b/application/Billing/Billing.php
index 82aecf33f..69ccd8318 100644
--- a/application/Billing/Billing.php
+++ b/application/Billing/Billing.php
@@ -2,6 +2,7 @@
class Billing extends mfBaseModel {
protected $forcestr = ["product_name","product_info","matchcode"];
+ private $contract;
diff --git a/application/Billing/BillingController.php b/application/Billing/BillingController.php
index 55f85a210..160e0d254 100644
--- a/application/Billing/BillingController.php
+++ b/application/Billing/BillingController.php
@@ -57,6 +57,15 @@ class BillingController extends mfBaseController {
{
$new_filter = [];
+ if (array_key_exists("show_credit", $filter)) {
+ if ($filter["show_credit"] == 0) {
+ $new_filter["price>="] = 0;
+ }
+ unset($filter["show_credit"]);
+ } else {
+ $new_filter["price>="] = 0;
+ }
+
if (is_array($filter) && count($filter)) {
foreach ($filter as $name => $value) {
$new_filter[$name] = $value;
@@ -77,17 +86,49 @@ class BillingController extends mfBaseController {
$i = 0;
- foreach(ContractModel::searchActive(["finish_date<" => $today->getTimestamp()]) as $contract) {
+ $now_year = date("Y");
+ $now_month = date("m");
+ $now_day = date("d");
+ $now_year = 2024;
+ $now_month = 7;
+
+ foreach(ContractModel::search(["finish_date<" => mktime(0,0,0,$now_month, $now_day, $now_year), "cancel_date" => null]) as $contract) {
//var_dump($contract);exit;
+ //$contract = new Contract(1);
- $now_year = date("Y");
- $now_month = date("m");
- $now_day = date("d");
+
+
+ $bill_month = $now_month;
+ $bill_year = $now_year;
+ //$bill_day = $now_day;
+ $bill_date = new DateTime("$bill_year-$bill_month-01");
+ //echo $bill_date->format("Y-m-d H:i:s")." ";
+ $monthly_bill_period_to = clone($bill_date);
+ $monthly_bill_period_to->modify("last day of this month");
+
+ $contract_finish_date = new DateTime("@".$contract->finish_date);
$finish_year = date("Y", $contract->finish_date);
$finish_month = date("m", $contract->finish_date);
$finish_day = date("d", $contract->finish_date);
+ //echo "$bill_month $bill_year\n";exit;
+
+ //echo $monthly_bill_period_to->format("Y-m-d H:i:s");exit;
+ if($contract_finish_date > $monthly_bill_period_to) {
+ $this->log->debug(__METHOD__.": Ignoring Contract ".$contract->id." because finish_date is in $finish_month $finish_year");
+ continue;
+ }
+
+ if($contract->billing_period < 1) {
+ $this->log->debug(__METHOD__.": Ignoring Contract ".$contract->id." because billing_period == 0");
+ continue;
+ }
+ if($contract->price == 0 && $contract->price_setup == 0) {
+ $this->log->debug(__METHOD__.": Ignoring Contract ".$contract->id." because price and price_setup == 0");
+ continue;
+ }
+
$cancel_date = false;
if($contract->cancel_date) {
$cancel_date = new DateTime("@".$contract->cancel_date);
@@ -97,95 +138,240 @@ class BillingController extends mfBaseController {
}
}
- // find last Billing row
- $last_billing = BillingModel::getLast(["contract_id" => $contract->id]);
- if(!$last_billing) {
+ $start_date = new DateTime("@".$contract->finish_date);
+ $start_date->setTimezone(new DateTimeZone("Europe/Vienna"));
+
+ // ignore yearly contracts which are not billable this month
+ if($contract->billing_period == 12) {
+ if($start_date->format("m") != $bill_month) {
+ continue;
+ }
+ }
+
+ $create_bills = [];
+
+ // Concurrent Billing
+ // find not yet billed periods
+
+ $create_dates = [];
+
+ $create_date = clone $start_date;
+ //$create_date->modify("+".$contract->billing_period." month");
+ $create_date->modify("first day of this month");
+ $last_create_date = false;
+ //echo "first create_date: ".$create_date->format("Y-m-d H:i:s")." \n";
+ //echo "while ".$create_date->getTimestamp()." (".$create_date->format("Y-m-d H:i:s").") >= ".$contract->finish_date." (".date("Y-m-d H:i:s", $contract->finish_date).") \n";
+
+ while($create_date->getTimestamp() >= $contract->finish_date) {
+ //echo "in need date while (".$create_date->format("Y-m-d H:i:s").") ";
+ if($last_create_date) {
+ // must for safety / shouldn't happen
+ die("need-date ran out of dates");
+ }
+
+ //echo " ";
+ //echo $create_date->format("Y")." == ".$finish_year." && ".$create_date->format("m")." == ".$finish_month." ";
+ if($create_date->format("Y") == $finish_year && $create_date->format("m") == $finish_month) {
+ $create_date->setDate($finish_year, $finish_month, $finish_day);
+ //echo "set last_create_date true ";
+ $last_create_date = true;
+ }
+
+ $existing_bill = BillingModel::getFirst(["contract_id" => $contract->id, "start_date" => $create_date->format("Y-m-d")]);
+ //var_dump($need_bill);exit;
+ if(!$existing_bill) {
+ //echo "adding date to create_dates[] ";
+ $new_create_date = clone $create_date;
+ $create_dates[] = $new_create_date;
+ $create_date->modify("-".$contract->billing_period." months");
+ continue;
+ }
+ break;
+ }
+
+ //var_dump($create_dates);
+ // find missing billings
+ foreach($create_dates as $start_date) {
+ $price_setup = 0;
+ if($start_date->format("Y") == $finish_year && $start_date->format("m") == $finish_month) {
+ $price_setup = $contract->price_setup;
+ }
+ $create_bills[] = [
+ "start_date" => $start_date,
+ "price_setup" => $price_setup // set Setup price to 0, because it was billed already
+ ];
+ }
+
+ /*$last_billings = BillingModel::count(["contract_id" => $contract->id]);
+ if(!$last_billings) {
// 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;
+ $start_date->setTime(0,0,0);
+ //echo "start_date: ".$start_date->format("Y-m-d H:i:s")." ";
+ $create_bills[] = [
+ "start_date" => $start_date,
+ "price_setup" => $contract->price_setup
+ ];
} else {
// Concurrent Billing
- // start_date next date after previous end_date
+ // find not yet billed periods
- $start_date = new DateTime($last_billing->end_date);
- $start_date->modify("+1 month");
+ $create_dates = [];
- // set Setup price to 0, because it was billed already
- $price_setup = 0;
+ $create_date = clone $start_date;
+ $create_date->modify("+1 month");
+ $create_date->modify("first day of this month");
+ $last_create_date = false;
+ //echo "first create_date: ".$create_date->format("Y-m-d H:i:s")." \n";
+ //echo "while ".$create_date->getTimestamp()." (".$create_date->format("Y-m-d H:i:s").") >= ".$contract->finish_date." (".date("Y-m-d H:i:s", $contract->finish_date).") \n";
+
+ while($create_date->getTimestamp() >= $contract->finish_date) {
+ //echo "in need date while (".$create_date->format("Y-m-d H:i:s").") ";
+ if($last_create_date) {
+ // must for safety / shouldn't happen
+ die("need-date ran out of dates");
+ }
+
+ //echo " ";
+ //echo $create_date->format("Y")." == ".$finish_year." && ".$create_date->format("m")." == ".$finish_month." ";
+ if($create_date->format("Y") == $finish_year && $create_date->format("m") == $finish_month) {
+ $create_date->setDate($finish_year, $finish_month, $finish_day);
+ //echo "set last_create_date true ";
+ $last_create_date = true;
+ }
+
+ $existing_bill = BillingModel::getFirst(["contract_id" => $contract->id, "start_date" => $create_date->format("Y-m-d")]);
+ //var_dump($need_bill);exit;
+ if(!$existing_bill) {
+ //echo "adding date to create_dates[] ";
+ $new_create_date = clone $create_date;
+ $create_dates[] = $new_create_date;
+ $create_date->modify("-".$contract->billing_period." months");
+ continue;
+ }
+ break;
+ }
+
+ //var_dump($create_dates);
+ // find missing billings
+ foreach($create_dates as $start_date) {
+ // ignore if last billing row is from this month
+ /*if($start_date->getTimestamp() < $earliest_next_billing_date->getTimestamp()) {
+ $this->log->debug(__METHOD__.": last billing row is current billing row. Skip creating new billing row");
+ continue;
+ }*//*
+ $create_bills[] = [
+ "start_date" => $start_date,
+ "price_setup" => 0 // set Setup price to 0, because it was billed already
+ ];
+ }
+ }*/
+
+
+ $create_bills = array_reverse($create_bills);
+ //var_dump($create_bills);exit;
+ foreach($create_bills as $bill_data) {
+ $start_date = $bill_data["start_date"];
+ $price_setup = $bill_data["price_setup"];
+
+ // 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("first day of this month");
+ $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;
+ //echo "days: $days ";
+ $pc = $days / $eday * 100;
+ //echo "pc: $pc ";
+ $price = round($contract->price / 100 * $pc, 4);
+ } else {
+ $price = $contract->price;
+ }
+
+ /*
+ echo "contact ID: ".$contract->id." ";
+ echo "contract price: ". $contract->price." ";
+ echo "price: ". $price." ";
+ echo "start_date: ".$start_date->format("Y-m-d H:i:s")." ";
+ echo "sday: $sday ";
+ exit;
+ */
+
+
+ $owner = $contract->owner;
+ $billingaddress = $contract->billingaddress;
+
+ $billing_type = "invoice";
+ $billing_delivery = "paper";
+
+ if ($owner->billing_type) {
+ $billing_type = $owner->billing_type;
+ }
+ if ($owner->billing_delivery) {
+ $billing_delivery = $owner->billing_delivery;
+ }
+
+ if ($billingaddress->billing_type) {
+ $billing_type = $billingaddress->billing_type;
+ }
+ if ($billingaddress->billing_delivery) {
+ $billing_delivery = $billingaddress->billing_delivery;
+ }
+
+ $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"] = $billing_type;
+ $data["billing_delivery"] = $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++;
}
-
-
- // 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");
+ $this->redirect("Billing");
+
}
}
\ No newline at end of file
diff --git a/application/Billing/BillingModel.php b/application/Billing/BillingModel.php
index 07b2b1793..53f16efec 100644
--- a/application/Billing/BillingModel.php
+++ b/application/Billing/BillingModel.php
@@ -124,7 +124,7 @@ class BillingModel {
$sql = "SELECT COUNT(*) as cnt FROM Billing
WHERE $where";
- mfLoghandler::singleton()->debug($sql);
+ //mfLoghandler::singleton()->debug($sql);
$res = $db->query($sql);
if($db->num_rows($res)) {
@@ -134,15 +134,20 @@ class BillingModel {
return 0;
}
- public static function search($filter, $limit = false) {
+ public static function search($filter, $limit = false, $order = false) {
//var_dump($filter);exit;
$items = [];
+
+ if(!$order) {
+ $order = "id ASC";
+ }
+
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM Billing
WHERE $where
- ORDER BY billingaddress_id";
+ ORDER BY $order";
if(is_array($limit) && count($limit)) {
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
@@ -208,6 +213,41 @@ class BillingModel {
}
}
+ if(array_key_exists("start_date", $filter)) {
+ $start_date = FronkDB::singleton()->escape($filter['start_date']);
+ if($start_date) {
+ $where .= " AND Billing.start_date='$start_date'";
+ }
+ }
+
+ if(array_key_exists("start_date>", $filter)) {
+ $start_date = FronkDB::singleton()->escape($filter['start_date>']);
+ if($start_date) {
+ $where .= " AND Billing.start_date > '$start_date'";
+ }
+ }
+
+ if(array_key_exists("start_date<", $filter)) {
+ $start_date = FronkDB::singleton()->escape($filter['start_date<']);
+ if($start_date) {
+ $where .= " AND Billing.start_date < '$start_date'";
+ }
+ }
+
+ if(array_key_exists("start_date>=", $filter)) {
+ $start_date = FronkDB::singleton()->escape($filter['start_date>=']);
+ if($start_date) {
+ $where .= " AND Billing.start_date >='$start_date'";
+ }
+ }
+
+ if(array_key_exists("start_date<=", $filter)) {
+ $start_date = FronkDB::singleton()->escape($filter['start_date<=']);
+ if($start_date) {
+ $where .= " AND Billing.start_date <= '$start_date'";
+ }
+ }
+
if(array_key_exists("billingaddress_id", $filter)) {
$billingaddress_id = $filter['billingaddress_id'];
if(is_numeric($billingaddress_id)) {
@@ -313,11 +353,44 @@ class BillingModel {
}
}
+ if(array_key_exists("price<", $filter)) {
+ $price = $filter['price<'];
+ if(is_numeric($price)) {
+ $where .= " AND Billing.price < $price";
+ }
+ }
+ if(array_key_exists("price<=", $filter)) {
+ $price = $filter['price<='];
+ if(is_numeric($price)) {
+ $where .= " AND Billing.price <= $price";
+ }
+ }
+
+ if(array_key_exists("price>", $filter)) {
+ $price = $filter['price>'];
+ if(is_numeric($price)) {
+ $where .= " AND Billing.price > $price";
+ }
+ }
+ if(array_key_exists("price>=", $filter)) {
+ $price = $filter['price>='];
+ if(is_numeric($price)) {
+ $where .= " AND Billing.price >= $price";
+ }
+ }
+
if(array_key_exists("add-where", $filter)) {
$where .= " ".$filter['add-where'];
}
+ if(array_key_exists("billing_period", $filter)) {
+ $billing_period = $filter['billing_period'];
+ if(is_numeric($billing_period)) {
+ $where .= " AND Billing.billing_period = $billing_period";
+ }
+ }
+
//var_dump($filter, $where);exit;
return $where;
}
diff --git a/application/PreorderDiscount/PreorderDiscountController.php b/application/PreorderDiscount/PreorderDiscountController.php
index 70c69c32f..ad9e39089 100644
--- a/application/PreorderDiscount/PreorderDiscountController.php
+++ b/application/PreorderDiscount/PreorderDiscountController.php
@@ -61,7 +61,7 @@ class PreorderDiscountController extends mfBaseController {
continue;
}
- $discount_code = PreorderDiscountModel::getFirst(["code" => $code, "preorer_id" => $preorder->id]);
+ $discount_code = PreorderDiscountModel::getFirst(["code" => $code, "preorder_id" => $preorder->id]);
if($discount_code) {
$exists++;
continue;
diff --git a/scripts/contract/test.php b/scripts/contract/test.php
index c0f01e28c..2d802ce8b 100644
--- a/scripts/contract/test.php
+++ b/scripts/contract/test.php
@@ -14,8 +14,8 @@ $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 02:00:00");
-$finish_date = new DateTime("2024-06-01 00:00:00");
+$finish_date_to = new DateTime("2024-06-01 03:00:00");
+$finish_date = new DateTime("2024-06-01 02:00:00");
$cms = 0;
$cmss = 0;
@@ -33,9 +33,9 @@ foreach(ContractModel::search(["finish_date" => $finish_date->getTimestamp()]) a
$First = new DateTime("2023-05-31 22:00:00");
//$First = new DateTime("2024-06-09 00:00:00");
-$Last = new DateTime("2024-06-01 00:00:00");
+$Last = new DateTime("2024-06-01 03:00:00");
-foreach(ContractModel::search(["billing_period" => 12]) as $contract) {
+foreach(ContractModel::search(["billing_period" => 12, "finish_date" => $finish_date->getTimestamp()]) as $contract) {
$fdate = new DateTime("@".$contract->finish_date);
$y = $fdate->format("Y");
$m = $fdate->format("m");
@@ -43,9 +43,9 @@ foreach(ContractModel::search(["billing_period" => 12]) as $contract) {
//if(($m == 5 && $d >= 11) || ($m == 6 && $d <= 10)) {
//if($contract->finish_date >= $First->getTimestamp() && $contract->finish_date <= $Last->getTimestamp()) {
- if($contract->finish_date == $Last->getTimestamp()) {
+ //if($contract->finish_date == $Last->getTimestamp()) {
$cys += $contract->price;
- }
+ //}
}
$cts = $cms + $cys + $cmss;
@@ -94,8 +94,64 @@ echo "======================================\n";
$cid = $ibs - $cts;
echo "Diff thetool <-> ivt Bills: ".round($cid, 4)."\n";
+echo "======================================\n";
+$tbms = 0;
+$tbys = 0;
+$tbs = 0;
+
+foreach(BillingModel::search(["price>=" => 0]) as $bill) {
+ if($bill->billing_period == 1) {
+ $tbms += $bill->price;
+ }
+ if($bill->billing_period == 12) {
+ $tbys += $bill->price;
+ }
+ if($bill->price_setup) {
+ $tbs += $bill->price_setup;
+ }
+}
+
+
+$tbts = $tbms + $tbys + $tbs;
+
+echo "\n";
+echo "Tool Billing Monthly Sum: $tbms\n";
+echo "Tool Billing Setup Sum: $tbs\n";
+echo "Tool Billing Yearly Sum: $tbys\n";
+echo "--------------------------------------\n";
+echo "Tool Billing Total Sum: $tbts\n";
+echo "======================================\n";
+
+
+$tbcms = 0;
+$tbcys = 0;
+$tbcs = 0;
+
+foreach(BillingModel::search(["price<" => 0]) as $bill) {
+ if($bill->billing_period == 1) {
+ $tbcms += $bill->price;
+ }
+ if($bill->billing_period == 12) {
+ $tbcys += $bill->price;
+ }
+ if($bill->price_setup) {
+ $tbcs += $bill->price_setup;
+ }
+}
+
+
+$tbcts = $tbcms + $tbcys + $tbcs;
+
+echo "\n";
+echo "Tool Billing Crediting Monthly Sum: $tbcms\n";
+echo "Tool Billing Crediting Setup Sum: $tbcs\n";
+echo "Tool Billing Crediting Yearly Sum: $tbcys\n";
+echo "--------------------------------------\n";
+echo "Tool Billing Crediting Total Sum: $tbcts\n";
+echo "======================================\n";
+
$gsm = 0;
$gsy = 0;
|