BMD Export Tweaks

This commit is contained in:
Frank Schubert
2024-07-09 19:48:04 +02:00
parent 29776b61dc
commit 47baeeecbb
2 changed files with 39 additions and 4 deletions

View File

@@ -22,9 +22,12 @@ foreach(AddressModel::search(["billing_type" => "sepa"]) as $address) {
$sepa_date = false;
$last_invoice_date = false;
$bill = false;
if($address->customer_number) {
$bill = IvtBillModel::getFirst(["cid" => $address->customer_number, "iban" => true, "bic" => true]);
}
if(!$address->customer_number) continue;
$bill = IvtBillModel::getFirst(["cid" => $address->customer_number, "iban" => true, "bic" => true]);
if($bill) {
$out_date = new DateTime($bill->date_outgoing);
$sepa_date = $out_date;
@@ -32,7 +35,34 @@ foreach(AddressModel::search(["billing_type" => "sepa"]) as $address) {
} else {
// find order
$order = OrderModel::getFirst(["owner_id" => $address->id]);
if($order) {
if(!$order) {
// try finding order via contract
$contract = ContractModel::getFirst(["billingaddress_id" => $address->id]);
if(!$contract) {
echo "Kunde address_id " . $address->id . " nirgendwo gefunden (kein Kundennummer, keine Order, kein Contract\n";
continue;
}
$order = OrderModel::getFirst(["owner_id" => $contract->owner_id]);
if(!$order) {
$order = OrderModel::getFirst(["owner_id" => $contract->billingaddress_id]);
}
if(!$order) {
$bill = IvtBillModel::getFirst(["cid" => $contract->owner->customer_number, "iban" => true, "bic" => true]);
if($bill) {
$out_date = new DateTime($bill->date_outgoing);
$sepa_date = $out_date;
}
}
}
if(!$sepa_date) {
if(!$order) {
echo "Kunde address_id " . $address->id . " nirgendwo gefunden (kein Kundennummer, keine Order, kein Contract\n";
continue;
}
if($order->order_date) {
$sepa_date = new DateTime("@" . $order->order_date);
if($sepa_date->format("Y") < 2020) $sepa_date = false;
@@ -42,6 +72,8 @@ foreach(AddressModel::search(["billing_type" => "sepa"]) as $address) {
$sepa_date = new DateTime("@" . $order->create);
}
}
}
if(!$sepa_date) {