Files
thetool/scripts/update_address_bank_data_from_order.php
2022-02-17 23:22:36 +01:00

55 lines
1.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);
$orders = OrderModel::getAll();
$i = 0;
foreach($orders as $order) {
if($order->billing_type != "sepa") {
continue;
}
if($order->billingaddress_id) {
$address = new Address($order->billingaddress_id);
} elseif($order->owner_id) {
$address = new Address($order->owner_id);
} else {
echo "No owner or billing contact found for Order ".$order->id."\n";
continue;
}
if(!$address->id) {
echo "Address ".$order->billingaddress_id." not found\n";
continue;
}
if($address->bank_account_bank || $address->bank_account_owner || $address->bank_account_iban || $address->bank_account_bic) {
echo "Billingaddress ".$address->company." ".$address->firstname." ".$address->lastname." (".$address->id.") has bank data set already. Not updating...\n";
continue;
}
$address->billing_type = $order->billing_type;
$address->bank_account_bank = $order->bank_account_bank;
$address->bank_account_owner = $order->bank_account_owner;
$address->bank_account_iban = $order->bank_account_iban;
$address->bank_account_bic = $order->bank_account_bic;
//var_dump($address);
$address->save();
$i++;
}
echo "Updated $i addresses with bank account data.\n";