BMD Export Tweaks
This commit is contained in:
@@ -606,6 +606,7 @@ XINON GmbH";
|
||||
$sepa_id = "";
|
||||
$sepa_date = false;
|
||||
$last_invoice_date = false;
|
||||
$mandatskz = "";
|
||||
|
||||
if($is_sepa) {
|
||||
$iban = $invoice->bank_account_iban;
|
||||
@@ -622,6 +623,8 @@ XINON GmbH";
|
||||
}
|
||||
}
|
||||
|
||||
$mandatskz = ($last_invoice_date ? "1" : "0");
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -642,7 +645,7 @@ XINON GmbH";
|
||||
$csv_out .= $bic.";";
|
||||
$csv_out .= $sepa_id.";";
|
||||
$csv_out .= ($sepa_date ? $sepa_date->format("d.m.Y") : "").";";
|
||||
$csv_out .= ($last_invoice_date ? "1" : "0").";";
|
||||
$csv_out .= $mandatskz.";";
|
||||
$csv_out .= ($last_invoice_date ? $last_invoice_date->format("d.m.Y") : "").";";
|
||||
$csv_out .= ($is_sepa ? 0 : 10).";";
|
||||
$csv_out .= ($is_sepa ? 1 : 0);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user