Added Sepa Mandats stuff

This commit is contained in:
Frank Schubert
2024-07-08 20:09:47 +02:00
parent 1888dd71e5
commit 40b1ea8605
9 changed files with 176 additions and 17 deletions

View File

@@ -0,0 +1,45 @@
#!/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);
foreach(ContractModel::searchActive([]) as $contract) {
$owner = $contract->owner;
$billingaddress = $contract->billingaddress;
if($billingaddress->last_invcice_date) continue;
if($billingaddress->billing_type != "sepa") continue;
if(!$billingaddress->fibu_account_number) continue;
if(!$billingaddress->sepa_date) {
$sepa_date = $contract->owner->sepa_date;
if($sepa_date) {
echo $billingaddress->id." sepa date $sepa_date\n";
$billingaddress->sepa_date = $sepa_date;
$billingaddress->save();
}
}
if(!$billingaddress->last_invoice_date) {
$last_bill = IvtBillModel::getLast(["cid" => $owner->customer_number]);
if(!$last_bill) continue;
$last_date = new DateTime($last_bill->date_outgoing);
$last_invoice_date = $last_date->getTimestamp();
echo $billingaddress->id." last_invoice: $last_invoice_date\n";
$billingaddress->last_invoice_date = $last_invoice_date;
$billingaddress->save();
}
}

View File

@@ -16,28 +16,38 @@ 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) {
if($address->sepa_date) continue;
//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 - ".$bill->date_outgoing."\n";
echo "sepa date: $sepa_date - ".$bill->date_outgoing."\n";
if(!$sepa_date){
echo "Konnte Datum nicht umwandeln\n";
}
$address->sepa_date = $sepa_date;
$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++;
}