Added activation_billing (Nachverrechnen) in PreorderBilling
This commit is contained in:
@@ -1353,6 +1353,7 @@ $pagination_entity_name = "Vorbestellungen";
|
||||
// toggle controls
|
||||
$("#preorder-detail-activationdate-" + pid + "-text").toggle();
|
||||
$("#preorder-detail-activationdate-" + pid + "-input").toggle();
|
||||
$("#preorder-detail-activation-billing-" + pid).toggle();
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -1363,6 +1364,9 @@ $pagination_entity_name = "Vorbestellungen";
|
||||
}
|
||||
|
||||
var value = $("#preorder-detail-activationdate-" + pid + "-input input").val();
|
||||
var activation_billing = $("#preorder-detail-activation-billing-" + pid + " input[type='checkbox'").is(":checked") ? 1 : 0;
|
||||
console.log($("#preorder-detail-activation-billing-" + pid + " input[type='checkbox'"));
|
||||
console.log(activation_billing);
|
||||
|
||||
//console.log("add opacity-5 to ")
|
||||
$("#preorder-" + pid + "-body").addClass("opacity-5");
|
||||
@@ -1378,17 +1382,25 @@ $pagination_entity_name = "Vorbestellungen";
|
||||
{
|
||||
'do': "saveActivationdate",
|
||||
id: pid,
|
||||
activation_date: value
|
||||
activation_date: value,
|
||||
activation_billing: activation_billing
|
||||
},
|
||||
function(success) {
|
||||
if(success.status == "OK") {
|
||||
console.log(success);
|
||||
var new_activationdate = success.result.activation_date;
|
||||
var new_activation_billing = success.result.activation_billing;
|
||||
var pid = success.result.preorder_id;
|
||||
//console.log(updates);
|
||||
$("#preorder-detail-activationdate-" + pid + "-textpart").text(new_activationdate);
|
||||
$("#preorder-detail-activationdate-" + pid + "-input").val(new_activationdate);
|
||||
|
||||
console.log($("#preorder-detail-activationdate-" + pid + "-activation-billing-part"));
|
||||
$("#preorder-detail-activationdate-" + pid + "-activation-billing-part").text("");
|
||||
if(new_activation_billing) {
|
||||
$("#preorder-detail-activationdate-" + pid + "-activation-billing-part").text("(Billing ab Aktivierung)");
|
||||
}
|
||||
|
||||
$("#preorder-detail-activationdate-" + pid + "-text").addClass("text-success");
|
||||
setTimeout(() => { $("#preorder-detail-activationdate-" + pid + "-text").removeClass("text-success") }, 1500);
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
<th>Aktivierungsdatum (Status 500):</th>
|
||||
<td>
|
||||
<?php if($preorder->getStatuschangeTo(500)): ?>
|
||||
<span id="preorder-detail-activationdate-<?=$preorder->id?>-text" data-activationdate="<?=($preorder->getStatuschangeTo(500)) ? (new DateTime("@".$preorder->getStatuschangeTo(500)))->format("d.m.Y") : ""?>"><span id="preorder-detail-activationdate-<?=$preorder->id?>-textpart"><?=($preorder->getStatuschangeTo(500)) ? (new DateTime("@".$preorder->getStatuschangeTo(500)))->format("d.m.Y") : ""?></span> <a href="#" onclick="return toggleActivationdateControl(<?=$preorder->id?>)"><i class="fas fa-fw fa-edit"></i></a></span>
|
||||
<span id="preorder-detail-activationdate-<?=$preorder->id?>-text" data-activationdate="<?=($preorder->getStatuschangeTo(500)) ? (new DateTime("@".$preorder->getStatuschangeTo(500)))->format("d.m.Y") : ""?>"><span id="preorder-detail-activationdate-<?=$preorder->id?>-textpart"><?=($preorder->getStatuschangeTo(500)) ? (new DateTime("@".$preorder->getStatuschangeTo(500)))->format("d.m.Y") : ""?></span> <span id="preorder-detail-activationdate-<?=$preorder->id?>-activation-billing-part"><?=($preorder->activation_billing) ? "(Billing ab Aktivierung)" : ""?></span> <a href="#" onclick="return toggleActivationdateControl(<?=$preorder->id?>)"><i class="fas fa-fw fa-edit"></i></a></span>
|
||||
<div class="input-group" id="preorder-detail-activationdate-<?=$preorder->id?>-input" style="display:none">
|
||||
<input type="text" class="form-control datepicker" value="<?=($preorder->getStatuschangeTo(500)) ? (new DateTime("@".$preorder->getStatuschangeTo(500)))->format("d.m.Y") : ""?>" />
|
||||
<div class="input-group-append">
|
||||
@@ -97,6 +97,9 @@
|
||||
<button type="button" class="btn btn-secondary" title="Abbrechen" onclick="toggleActivationdateControl(<?=$preorder->id?>)"><i class="fas fa-times"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="preorder-detail-activation-billing-<?=$preorder->id?>" class="mt-1 hidden">
|
||||
<label><input type="checkbox" name="activation_billing" value="1" <?=($preorder->activation_billing) ? "checked='checked'" : "" ?> /> Verrechnung ab Aktivierungsdatum (Wenn vor globalem Verrechnungsstart)</label><br />
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr><tr>
|
||||
|
||||
@@ -1177,6 +1177,9 @@ class PreorderController extends mfBaseController {
|
||||
private function saveActivationdateApi() {
|
||||
$preorder_id = $this->request->id;
|
||||
$activation_date = $this->request->activation_date;
|
||||
$activation_billing = $this->request->activation_billing ? 1 : 0;
|
||||
|
||||
$this->log->debug(print_r($this->request->get(), true));
|
||||
|
||||
$preorder = new Preorder($preorder_id);
|
||||
if(!$preorder->id) {
|
||||
@@ -1199,7 +1202,15 @@ class PreorderController extends mfBaseController {
|
||||
$history->changed = $activationdate->getTimestamp();
|
||||
$history->save();
|
||||
|
||||
return ["message" => "Activationdate saved successfully", "preorder_id" => $preorder_id, "activation_date" => $activation_date];
|
||||
//$this->log->debug(print_r($preorder, true));
|
||||
$this->log->debug(print_r($activation_billing, true));
|
||||
if($preorder->activation_billing != $activation_billing) {
|
||||
$preorder->activation_billing = $activation_billing;
|
||||
$this->log->debug(print_r($preorder, true));
|
||||
$preorder->save();
|
||||
}
|
||||
|
||||
return ["message" => "Activationdate saved successfully", "preorder_id" => $preorder_id, "activation_date" => $activation_date, "activation_billing" => $activation_billing];
|
||||
}
|
||||
|
||||
private function addWorkorderRemarkApi() {
|
||||
|
||||
@@ -64,6 +64,7 @@ class PreorderModel
|
||||
public $workorder_export_date;
|
||||
public $workorder_export_data;
|
||||
public $order_date;
|
||||
public $activation_billing;
|
||||
|
||||
public $cancel_request;
|
||||
public $cancel_request_by;
|
||||
|
||||
@@ -8,7 +8,7 @@ class PreorderBilling extends mfBaseModel {
|
||||
private $creator;
|
||||
private $editor;
|
||||
|
||||
public static $earliest_bill_date = "2025-01-01";
|
||||
public static $earliest_bill_date = "2025-01-01"; // TODO: auslagern in config file
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
@@ -134,7 +134,7 @@ class PreorderBillingController extends mfBaseController {
|
||||
}
|
||||
$netowner_config = TT_PREORDER_BILLING[$netowner_id];
|
||||
|
||||
$earliest_bill_date = new DateTime(PreorderBilling::$earliest_bill_date);
|
||||
$earliest_bill_date = new DateTime(PreorderBilling::$earliest_bill_date); // TODO: auslagern in config file
|
||||
|
||||
$now_year = date("Y");
|
||||
$now_month = date("m");
|
||||
@@ -180,7 +180,7 @@ class PreorderBillingController extends mfBaseController {
|
||||
$preorder_search = [
|
||||
"preordercampaign_id" => $campaign_ids,
|
||||
">=status_code" => 244,
|
||||
//"oaid" => "AT-8943-a1116acf.001",
|
||||
//"oaid" => "AT-8943-f2c2ae10.001",
|
||||
];
|
||||
|
||||
$billing_records = [];
|
||||
@@ -263,7 +263,6 @@ class PreorderBillingController extends mfBaseController {
|
||||
if($preorder->status->code >= 500) {
|
||||
if($bill_operator_setup) $this->billSetup($preorder, "operator_setup", $bill_params);
|
||||
if($bill_usage) $this->billOperatorPeriodic($preorder, $bill_params);
|
||||
//exit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -589,7 +588,7 @@ class PreorderBillingController extends mfBaseController {
|
||||
$cancel_date = new DateTime("@".$cancel_change->changed);
|
||||
}
|
||||
|
||||
$first_bill_date = clone $status_change_date;
|
||||
|
||||
|
||||
|
||||
// get earlier missing billing records and bill them too
|
||||
@@ -642,10 +641,56 @@ class PreorderBillingController extends mfBaseController {
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if($preorder->activation_billing) {
|
||||
// bill from activation_date, even if it's before earliest_bill_date
|
||||
$first_bill_date = clone $status_change_date;
|
||||
$create_date = clone $earliest_bill_date;
|
||||
$create_date->modify("first day of this month");
|
||||
$create_date->modify("-1 month");
|
||||
$create_date->setTime(0,0,0);
|
||||
|
||||
//var_dump($first_bill_date);
|
||||
/*var_dump($create_date);
|
||||
var_dump($earliest_bill_date);*/
|
||||
|
||||
// get months from activation date
|
||||
$last_create_date = false;
|
||||
while($create_date->format("Ym") < $earliest_bill_date->format("Ym")) {
|
||||
//var_dump($create_date);
|
||||
if($last_create_date) {
|
||||
//var_dump($create_dates);
|
||||
// just for safety / shouldn't happen
|
||||
break;
|
||||
//die("need-date ran out of dates");
|
||||
}
|
||||
|
||||
//echo " - \$create_date ".$create_date->format("Y-m-d H:i:s")."<br />\n";
|
||||
//echo " - \$earliest_bill_date ".$earliest_bill_date->format("Y-m-d H:i:s")."<br /><br />\n";
|
||||
if($create_date->format("Y") == $first_bill_date->format("Y") && $create_date->format("m") == $first_bill_date->format("m")) {
|
||||
// this is the finish month, so set day back to day of finish_date
|
||||
$create_date->setDate($first_bill_date->format("Y"), $first_bill_date->format("m"), $first_bill_date->format("d"));
|
||||
$last_create_date = true;
|
||||
}
|
||||
|
||||
$existing_bill = PreorderBilling::getFirst(["product_id" => $product->id, "preorder_id" => $preorder->id, "start_date" => $create_date->format("Y-m-d")]);
|
||||
//var_dump($existing_bill);
|
||||
if(!$existing_bill) {
|
||||
if($netoperator_config["billing-period"] == "quarterly" && $create_date->format("Ymd") > $latest_quarter_bill_date->format("Ymd")) {
|
||||
$this->log->debug(__METHOD__.": Skipping operator_usage ".$create_date->format("m/Y")." for preorder ".$preorder->id." because Billing date ".$create_date->format("Y-m-d")." is after latest_quarter_bill_date ".$latest_quarter_bill_date->format("Y-m-d"));
|
||||
return true;
|
||||
}
|
||||
$new_create_date = clone $create_date;
|
||||
$to_bill_dates[] = $new_create_date;
|
||||
$create_date->modify("-1 months");
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
//var_dump($to_bill_dates);
|
||||
//exit;
|
||||
|
||||
|
||||
foreach($to_bill_dates as $start_date) {
|
||||
$end_date = clone $start_date;
|
||||
$end_date->modify("first day of this month");
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class PreorderAddActivationBilling extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
$table = $this->table("Preorder");
|
||||
$table->addColumn("activation_billing", "integer", ["default" => 0, "length" => \Phinx\Db\Adapter\MysqlAdapter::INT_TINY, "after" => "order_date"]);
|
||||
$table->update();
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
$table = $this->table("Preorder");
|
||||
$table->removeColumn("activation_billing");
|
||||
$table->update();
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user