Invoice BMD export
This commit is contained in:
@@ -17,41 +17,64 @@ define("INTERNAL_USER_USERNAME", $me->username);
|
||||
|
||||
$i = 0;
|
||||
//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 && $address->last_invoice_date) continue;
|
||||
foreach(AddressModel::search(["billing_type" => "sepa"]) as $address) {
|
||||
//if($address->sepa_date && $address->last_invoice_date) continue;
|
||||
|
||||
$sepa_date = false;
|
||||
$last_invoice_date = false;
|
||||
|
||||
if(!$address->customer_number) continue;
|
||||
$bill = IvtBillModel::getFirst(["cid" => $address->customer_number, "iban" => true, "bic" => true]);
|
||||
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;
|
||||
if($bill) {
|
||||
$out_date = new DateTime($bill->date_outgoing);
|
||||
$sepa_date = $out_date;
|
||||
//echo "sepa date: $sepa_date - ".$bill->date_outgoing."\n";
|
||||
} else {
|
||||
// find order
|
||||
$order = OrderModel::getFirst(["owner_id" => $address->id]);
|
||||
if($order) {
|
||||
if($order->order_date) {
|
||||
$sepa_date = new DateTime("@" . $order->order_date);
|
||||
if($sepa_date->format("Y") < 2020) $sepa_date = false;
|
||||
}
|
||||
if(!$sepa_date) {
|
||||
// order create
|
||||
$sepa_date = new DateTime("@" . $order->create);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$out_date = new DateTime($bill->date_outgoing);
|
||||
$sepa_date = $out_date->getTimestamp();
|
||||
echo "sepa date: $sepa_date - ".$bill->date_outgoing."\n";
|
||||
|
||||
if(!$sepa_date){
|
||||
echo "Konnte Datum nicht umwandeln\n";
|
||||
if(!$sepa_date) {
|
||||
echo "Kein sepa date für customer_number ".$address->customer_number."\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
$last_bill = IvtBillModel::getLast(["cid" => $address->customer_number, "iban" => true, "bic" => true]);
|
||||
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($last_bill) {
|
||||
$last_date = new DateTime($last_bill->date_outgoing);
|
||||
if($last_date->format("Y-m") == "2024-07") {
|
||||
var_dump($last_date, $last_bill);exit;
|
||||
}
|
||||
$last_invoice_date = $last_date->getTimestamp();
|
||||
//echo "last invoice date: $last_invoice_date ".$last_bill->date_outgoing."\n";
|
||||
} else {
|
||||
$last_invoice_date = null;
|
||||
}
|
||||
|
||||
if(!$address->sepa_date) {
|
||||
$address->sepa_date = $sepa_date;
|
||||
if(!$address->sepa_date && $sepa_date) {
|
||||
//echo "updating sepa_date ".$address->customer_number."\n";
|
||||
$address->sepa_date = $sepa_date->getTimestamp();
|
||||
$address->save();
|
||||
}
|
||||
|
||||
if(!$address->last_invoice_date) {
|
||||
if($last_invoice_date) {
|
||||
$address->last_invoice_date = $last_invoice_date;
|
||||
$address->save();
|
||||
}
|
||||
if($last_invoice_date === null) {
|
||||
$address->last_invoice_date = null;
|
||||
$address->save();
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user