Files
thetool/scripts/import-sepa-date-from-ivt.php
2024-07-08 20:09:47 +02:00

55 lines
1.7 KiB
PHP
Executable File

#!/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);
$i = 0;
//foreach(AddressModel::search(["customer_number" => true, "billing_type" => "sepa"]) as $address) {
foreach(AddressModel::search(["fibu_account_number" => true, "billing_type" => "sepa"]) as $address) {
//if($address->sepa_date) continue;
$bill = IvtBillModel::getFirst(["cid" => $address->customer_number]);
if(!$bill) continue;
if(!trim($bill->IBAN) || !trim($bill->BIC)) continue;
if(!$bill->date_outgoing) {
echo "date outgoing fehlt im ivt: ".$address->customer_number."\n";
continue;
}
$out_date = new DateTime($bill->date_outgoing);
$sepa_date = $out_date->getTimestamp();
echo "sepa date: $sepa_date - ".$bill->date_outgoing."\n";
if(!$sepa_date){
echo "Konnte Datum nicht umwandeln\n";
}
$last_bill = IvtBillModel::getLast(["cid" => $address->customer_number]);
if(!$last_bill) continue;
$last_date = new DateTime($last_bill->date_outgoing);
$last_invoice_date = $last_date->getTimestamp();
echo "last invoice date: $last_invoice_date ".$last_bill->date_outgoing."\n";
if(!$address->sepa_date) {
$address->sepa_date = $sepa_date;
}
$address->last_invoice_date = $last_invoice_date;
$address->save();
$i++;
}
echo "Updated $i addresses\n\n";