Files
thetool/scripts/contract/test.php
2024-06-25 12:19:35 +02:00

203 lines
5.5 KiB
PHP

#!/usr/bin/php
<?php
require("../../config/config.php");
define('FRONKDB_SQLDEBUG',false);
error_reporting(E_ALL & ~(E_NOTICE | E_STRICT | E_DEPRECATED));
require_once(LIBDIR."/mvcfronk/mfRouter/mfRouter.php");
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseModel.php");
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseController.php");
$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 03:00:00");
$finish_date = new DateTime("2024-06-01 02:00:00");
$cms = 0;
$cmss = 0;
$cys = 0;
foreach(ContractModel::search(["finish_date" => $finish_date->getTimestamp()]) 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("2023-05-31 22:00:00");
//$First = new DateTime("2024-06-09 00:00:00");
$Last = new DateTime("2024-06-01 03:00:00");
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");
$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 == $Last->getTimestamp()) {
$cys += $contract->price;
//}
}
$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";
$ims = 0;
$iys = 0;
foreach(IvtCustomerProductModel::search(["lastdate" => '2024-06-10']) as $ivt_contract) {
$product = $ivt_contract->product;
if($product->interval == 0) {
$ims += $product->price;
} elseif($product->interval == 1 && $ivt_contract->lastdate == "2024-06-10") {
$iys += $product->price;
}
}
$its = $ims + $iys;
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-10"]) 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: ".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;
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) {
$gsy += $contract->price;
}
}
$gst = $gsm + $gsy;
echo "\n\n";
echo "Contract Credit monthly: $gsm\n";
echo "Contract Credit yearly: $gsy\n";
echo "--------------------------------------\n";
echo "Contract Credit Total: $gst\n";
echo "======================================\n";
$icm = 0;
foreach(IvtCustomerCreditingModel::search(['lastdate' => '2024-06-10']) as $ivt_credit) {
$product = $ivt_credit->crediting_product;
$icm += $product->price_excl;
}
$icm *= -1;
echo "IVT Credit Total: $icm\n";
echo "======================================\n";
$icbs = 0;
foreach(IvtCreditingModel::search(["date_outgoing" => "2024-06-10"]) as $ivt_credit) {
foreach(IvtCreditingPositionModel::search(["head_id" => $ivt_credit->id]) as $position) {
$icbs += $position->price_excl;
}
}
$icbs *= -1;
$cred_diff = $icbs - ($gsm + $gsy);
echo "IVT Credit Bill Total: $icbs\n";
echo "======================================\n";
echo "\n";
echo "Credit Diff thetool <-> ivt: ".round($cred_diff, 4)."\n";
echo "======================================\n";