Added Sepa Mandats stuff
This commit is contained in:
@@ -30,6 +30,7 @@ class AddressModel {
|
||||
public $bank_account_iban;
|
||||
public $bank_account_bic;
|
||||
public $sepa_date;
|
||||
public $last_invoice_date;
|
||||
public $allow_contact;
|
||||
public $allow_spin;
|
||||
|
||||
@@ -270,6 +271,8 @@ class AddressModel {
|
||||
if ($fan) {
|
||||
if (is_numeric($fan)) {
|
||||
$where .= " AND fibu_account_number=$fan";
|
||||
} elseif($fan === true) {
|
||||
$where .= " AND (fibu_account_number IS NOT NULL AND fibu_account_number > 0)";
|
||||
} else {
|
||||
$fan = FronkDB::singleton()->escape($fan);
|
||||
$where .= " AND fibu_account_number LIKE '$fan'";
|
||||
|
||||
@@ -95,7 +95,7 @@ class BillingController extends mfBaseController {
|
||||
$r = $this->request;
|
||||
|
||||
$last_run_ts = new mfConfig("voicecallhistory.contact-job.ts");
|
||||
if($last_run_ts->value() < date("U") - 43200) {
|
||||
if($last_run_ts->value() < date("U") - 86400) {
|
||||
$this->layout()->setFlash("Voicecall History Contract Job ist heute noch nicht gelaufen", "error");
|
||||
$this->redirect("Billing");
|
||||
}
|
||||
@@ -370,6 +370,11 @@ class BillingController extends mfBaseController {
|
||||
$billing_delivery = $billingaddress->billing_delivery;
|
||||
}
|
||||
|
||||
$fibu_account_num = $contract->billingaddress->fibu_account_number;
|
||||
if(!$fibu_account_num) {
|
||||
die("Keine Fibu Account Nummer in Rechnungskontakt in Contract ID ".$contract->id);
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data["contract_id"] = $contract->id;
|
||||
$data["start_date"] = $start_date->format("Y-m-d");
|
||||
@@ -377,7 +382,7 @@ class BillingController extends mfBaseController {
|
||||
$data["owner_id"] = $contract->owner_id;
|
||||
$data["billingaddress_id"] = ($contract->billingaddress_id) ? $contract->billingaddress_id : $contract->owner_id;
|
||||
$data["customer_number"] = $contract->owner->customer_number;
|
||||
$data["fibu_account_number"] = $contract->owner->fibu_account_number; // TODO: fibu_account_number von billingaddress
|
||||
$data["fibu_account_number"] = $fibu_account_num;
|
||||
$data["company"] = $billingaddress->company;
|
||||
$data["firstname"] = $billingaddress->firstname;
|
||||
$data["lastname"] = $billingaddress->lastname;
|
||||
@@ -400,12 +405,7 @@ class BillingController extends mfBaseController {
|
||||
$data["price_setup"] = $price_setup;
|
||||
$data["billing_period"] = $contract->billing_period;
|
||||
|
||||
$matchcode = $contract->matchcode;
|
||||
// if voice product and matchcode consists of phonenumbers only, remove matchcode
|
||||
if(array_key_exists("needs_number", $contract->product->attributes) && $contract->product->attributes["needs_number"] == 1 && preg_match('/^[0-9, ]+$]/', $matchcode)) {
|
||||
$matchcode = "";
|
||||
}
|
||||
$data["matchcode"] = $matchcode;
|
||||
$data["matchcode"] = $contract->matchcode;
|
||||
|
||||
if(!$contract->billingaddress->country_id) {
|
||||
$billcountry = CountryModel::getFirst(["isocode" => TT_HOMECOUNTRY_ISOCODE]);
|
||||
@@ -426,6 +426,24 @@ class BillingController extends mfBaseController {
|
||||
$data["vatgroup_id"] = $contract->vatgroup_id;
|
||||
$data["vatarea"] = $vatarea;
|
||||
|
||||
if($billing_type == "sepa") {
|
||||
if($contract->billingaddress->sepa_date) {
|
||||
$sepa_date = new DateTime("@".$contract->billingaddress->sepa_date);
|
||||
$sepa_date->setTimezone(new DateTimeZone("Europe/Vienna"));
|
||||
$data["sepa_date"] = $sepa_date->format("Y-m-d");
|
||||
}
|
||||
|
||||
if($contract->billingaddress->last_invoice_date) {
|
||||
$sepa_last_date = new DateTime("@".$contract->billingaddress->last_invoice_date);
|
||||
$sepa_last_date->setTimezone(new DateTimeZone("Europe/Vienna"));
|
||||
$data["sepa_last_date"] = $sepa_last_date->format("Y-m-d");
|
||||
}
|
||||
|
||||
$data["sepa_id"] = "R".$fibu_account_num;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$billing = BillingModel::create($data);
|
||||
if (!$billing->save()) {
|
||||
|
||||
@@ -9,6 +9,9 @@ class BillingModel {
|
||||
public $billingaddress_id;
|
||||
public $customer_number;
|
||||
public $fibu_account_number;
|
||||
public $sepa_date;
|
||||
public $sepa_id;
|
||||
public $sepa_last_date;
|
||||
public $company;
|
||||
public $firstname;
|
||||
public $lastname;
|
||||
|
||||
@@ -382,6 +382,9 @@ XINON GmbH";
|
||||
$invoice_data["billingaddress_id"] = $billingaddress_id;
|
||||
$invoice_data["customer_number"] = $bill->customer_number;
|
||||
$invoice_data["fibu_account_number"] = $bill->fibu_account_number;
|
||||
$invoice_data["sepa_date"] = $bill->sepa_date;
|
||||
$invoice_data["sepa_id"] = $bill->sepa_id;
|
||||
$invoice_data["sepa_last_date"] = $bill->sepa_last_date;
|
||||
|
||||
$invoice_data["company"] = $bill->company;
|
||||
$invoice_data["firstname"] = $bill->firstname;
|
||||
|
||||
@@ -7,6 +7,9 @@ class InvoiceModel {
|
||||
public $billingaddress_id;
|
||||
public $customer_number;
|
||||
public $fibu_account_number;
|
||||
public $sepa_date;
|
||||
public $sepa_id;
|
||||
public $sepa_last_date;
|
||||
public $fibu_cost_area;
|
||||
public $fibu_cost_account;
|
||||
public $fibu_cost_account_legacy;
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class AddressAddLastInvoiceDate extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
$table = $this->table('Address');
|
||||
$table->addColumn("last_invoice_date", "integer", ["null" => true, "default" => null, "after" => "sepa_date"]);
|
||||
$table->save();
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
$this->table('Address')->removeColumn("last_invoice_date")->save();
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
43
db/migrations/20240708175301_billing_add_sepa.php
Normal file
43
db/migrations/20240708175301_billing_add_sepa.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class BillingAddSepa extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
$table = $this->table("Billing");
|
||||
$table->addColumn("sepa_date", "date", ["null" => true, "default" => null, "after" => "fibu_account_number"]);
|
||||
$table->addColumn("sepa_id", "string", ["null" => true, "default" => null, "after" => "sepa_date"]);
|
||||
$table->addColumn("sepa_last_date", "date", ["null" => true, "default" => null, "after" => "sepa_id"]);
|
||||
$table->update();
|
||||
|
||||
$invoice = $this->table("Invoice");
|
||||
$invoice->addColumn("sepa_date", "date", ["null" => true, "default" => null, "after" => "fibu_account_number"]);
|
||||
$invoice->addColumn("sepa_id", "string", ["null" => true, "default" => null, "after" => "sepa_date"]);
|
||||
$invoice->addColumn("sepa_last_date", "date", ["null" => true, "default" => null, "after" => "sepa_id"]);
|
||||
$invoice->update();
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
$table = $this->table("Billing");
|
||||
$table->removeColumn("sepa_date");
|
||||
$table->removeColumn("sepa_id");
|
||||
$table->removeColumn("sepa_last_date");
|
||||
$table->update();
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
45
scripts/contract/generate-sepa-data.php
Normal file
45
scripts/contract/generate-sepa-data.php
Normal 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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user