Files
thetool/scripts/rml-billing/import-magenta-activation-dates.php
2025-03-29 20:51:44 +01:00

109 lines
2.6 KiB
PHP

#!/usr/bin/php
<?php
//require 'vendor/autoload.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);
define("INTERNAL_USER_USERNAME", $me->username);
define("MFBASE_BYPASS_LOGIN", true);
$folder = __DIR__."/import/";
$filename = "25_MagentaKunden.csv";
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$log = mfLoghandler::singleton();
$start = date("U");
$last_ts = $start;
$input = fopen($folder.$filename, "r");
$bom = "\xef\xbb\xbf";
if(fgets($input, 4) !== $bom) {
// BOM not found - rewind pointer to start of file.
rewind($input);
}
$headers = [];
$import_date = false;
$status_500 = PreorderstatusModel::getFirst(["code" => 500]);
if(!$status_500) {
die("No status 500");
}
//$c = 0;
$i = 0;
while($csv = fgetcsv($input, 0)) {
$i++;
if ($i == 1) {
foreach ($csv as $key => $name) {
$headers[$name] = $key;
}
continue;
}
if (!trim($csv[0])) {
continue;
}
$oaid = trim($csv[$headers["OAID HOME"]]);
$input_date = trim($csv[$headers["ISP Service aktiv"]]);
if(!$oaid || !$input_date) {
break;
}
$activation_date = new DateTime($input_date);
$activation_date->setTime(4, 0, 0);
if(PreorderModel::countActive(["oaid" => $oaid]) > 1) {
die("OAID $oaid more than 1 active Preorder!");
}
$preorder = PreorderModel::getFirstActive(["oaid" => $oaid]);
if(!$preorder) {
die("Preorder $oaid not Found!");
}
if($preorder->status->code < 500) {
echo "$oaid -> status ".$preorder->status->code."\n";
}
$active_change = PreorderHistoryModel::getLastStatusChangeTo($preorder->id, 500);
/*echo "$oaid: $input_date\n";
echo "$oaid: ".$activation_date->format("Y-m-d")."\n";
if($input_date != $activation_date->format("Y-m-d")) {
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
}
continue;*/
if(!$active_change) {
$active_change = PreorderHistoryModel::create([
"preorder_id" => $preorder->id,
"key" => "status_id",
"old_value" => 1,
"new_value" => $status_500->id,
]);
$active_change->save();
}
$active_change->changed = $activation_date->getTimestamp();
$active_change->save();
}
echo "$i\n";