Invoice BMD export
This commit is contained in:
@@ -203,6 +203,7 @@ XINON GmbH";
|
||||
|
||||
$invoice_data = [];
|
||||
$invoice_vatrate = 20;
|
||||
$price_total_sum = 0;
|
||||
|
||||
foreach($billing_rows as $bill) {
|
||||
$vatarea = $bill->vatarea;
|
||||
@@ -218,6 +219,8 @@ XINON GmbH";
|
||||
$add_setup_position = ($price > 0 && $price_setup > 0);
|
||||
$is_setup_only = ($price < 0.00001 && $price_setup > 0);
|
||||
|
||||
$price_total_sum += $price_gross + $price_setup_gross;
|
||||
|
||||
$position_data = [];
|
||||
$position_data["billing_id"] = $bill->id;
|
||||
$position_data["contract_id"] = $bill->contract_id;
|
||||
@@ -347,12 +350,16 @@ XINON GmbH";
|
||||
$voicenumber_zone = InvoiceVoicenumberZoneModel::create($zone_data);
|
||||
//var_dump($voicenumber_zone);
|
||||
$invoice_voicenumber->data->voicenumberzones[] = $voicenumber_zone;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
//var_dump($invoice_voicenumber);exit;
|
||||
$invoice_voicenumbers[] = $invoice_voicenumber;
|
||||
}
|
||||
//var_dump($invoice_voicenumbers);exit;
|
||||
|
||||
$price_total_sum += $total_voice_price;
|
||||
//var_dump($invoice_voicenumbers);exit;
|
||||
|
||||
|
||||
$this->log->debug("Adding Voice Invoiceposition for Contract ID " . $bill->contract_id);
|
||||
@@ -363,7 +370,6 @@ XINON GmbH";
|
||||
$voice_data["price"] = $total_voice_price;
|
||||
$voice_data["price_total"] = $total_voice_price;
|
||||
$voice_data["price_gross"] = $total_voice_price + (($total_voice_price / 100) * 20);
|
||||
$voice_data["vatrate"] = $invoice_vatrate;
|
||||
$voice_data["start_date"] = $voice_start_date;
|
||||
$voice_data["end_date"] = $voice_end_date;
|
||||
$voice_position = InvoicepositionModel::create($voice_data);
|
||||
@@ -416,6 +422,13 @@ XINON GmbH";
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
// to not generate zero total invoices
|
||||
if($price_total_sum == 0.0000) {
|
||||
continue;
|
||||
}*/
|
||||
|
||||
|
||||
/*
|
||||
* *******************************
|
||||
* Save invoice and add positions
|
||||
@@ -512,6 +525,13 @@ XINON GmbH";
|
||||
$invoice->rollbackTransaction();
|
||||
die("Error saving Invoice number and date");
|
||||
}
|
||||
|
||||
/*
|
||||
$address = new Address($invoice->billingaddress_id);
|
||||
if($address) {
|
||||
$address->last_invoice_date = date("U");
|
||||
$address->save();
|
||||
}*/
|
||||
} catch (Exception $e) {
|
||||
if ($invoice) {
|
||||
$invoice->rollbackTransaction();
|
||||
@@ -539,4 +559,103 @@ XINON GmbH";
|
||||
$this->redirect("Invoice");
|
||||
|
||||
}
|
||||
|
||||
protected function exportBmdAction() {
|
||||
/*
|
||||
* satzart;konto;gkonto;belegnr;belegdatum;buchsymbol;buchcode;prozent;steuercode;betrag;steuer;text;kost;bank-iban-nr;bank-swiftcode;bank-mandatsid;bank-mandatsdatum;bank-mandatskz;bank-letztereinzug;zvsperre;bankeinzug
|
||||
* 0;234941;40010;TEST-1;23.01.2024;AR;1;20;1;1,2;-0,2;RNTEST-01;;AT293828200003027919;RZSTAT2G282;KJ2813;13.01.2023;0;;0;1
|
||||
* 0;234325;40010;TEST-2;23.01.2024;GU;1;20;1;-1,2;0,2;GSTEST-01;;;;;;;;10;0
|
||||
*/
|
||||
|
||||
$csv_header = "satzart;konto;gkonto;belegnr;belegdatum;buchsymbol;buchcode;prozent;steuercode;betrag;steuer;text;kost;bank-iban-nr;bank-swiftcode;bank-mandatsid;bank-mandatsdatum;bank-mandatskz;bank-letztereinzug;zvsperre;bankeinzug";
|
||||
$csv_out = "";
|
||||
|
||||
if(!InvoiceModel::search(["bmd_export_date" => null])) {
|
||||
$this->layout()->setFlash("Keine neuen Rechnungen seit letztem BMD-Export vorhanden.");
|
||||
$this->redirect("Invoice");
|
||||
}
|
||||
foreach(InvoiceModel::search(["bmd_export_date" => null]) as $invoice) {
|
||||
if($invoice->bmd_export_date) {
|
||||
die("wtf");
|
||||
}
|
||||
|
||||
$vatrate = (($invoice->total == $invoice->total_gross) ? "0" : "20");
|
||||
$vat = $invoice->total_gross - $invoice->total;
|
||||
$vat *= -1;
|
||||
|
||||
if($invoice->total < 0) {
|
||||
$buchsymbol = "GU";
|
||||
} else {
|
||||
$buchsymbol = "AR";
|
||||
|
||||
}
|
||||
|
||||
$buchungstext = "[".$invoice->customer_number."]";
|
||||
if($invoice->company) {
|
||||
$buchungstext .= " ".$invoice->company;
|
||||
} elseif($invoice->firstname || $invoice->lastname) {
|
||||
$buchungstext .= " ".$invoice->firstname." ".$invoice->lastname;
|
||||
}
|
||||
|
||||
$buchungstext = str_replace(["\n","\r", ";"], "", $buchungstext);
|
||||
|
||||
$is_sepa = ($invoice->billing_type == "sepa");
|
||||
|
||||
$iban = "";
|
||||
$bic = "";
|
||||
$sepa_id = "";
|
||||
$sepa_date = false;
|
||||
$last_invoice_date = false;
|
||||
|
||||
if($is_sepa) {
|
||||
$iban = $invoice->bank_account_iban;
|
||||
$bic = $invoice->bank_account_bic;
|
||||
$sepa_id = $invoice->sepa_id;
|
||||
if($invoice->sepa_date) {
|
||||
$sepa_date = new DateTime($invoice->sepa_date);
|
||||
if($invoice->sepa_last_date) {
|
||||
$last_invoice_date = new DateTime($invoice->sepa_last_date);
|
||||
|
||||
if($last_invoice_date->format("Y-m-d") < $sepa_date->format("Y-m-d")) {
|
||||
$last_invoice_date = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
$csv_out .= "0;";
|
||||
$csv_out .= $invoice->fibu_account_number.";";
|
||||
$csv_out .= $invoice->fibu_cost_account.";";
|
||||
$csv_out .= $invoice->invoice_number.";";
|
||||
$csv_out .= date("d.m.Y", $invoice->invoice_date).";";
|
||||
$csv_out .= $buchsymbol.";";
|
||||
$csv_out .= "1;";
|
||||
$csv_out .= $vatrate.";";
|
||||
$csv_out .= $invoice->fibu_taxcode.";";
|
||||
$csv_out .= number_format($invoice->total_gross, 2, ",", "").";";
|
||||
$csv_out .= number_format($vat, 2, ",", "").";";
|
||||
$csv_out .= $buchungstext.";";
|
||||
$csv_out .= ";"; // kostenstelle
|
||||
$csv_out .= $iban.";";
|
||||
$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 .= ($last_invoice_date ? $last_invoice_date->format("d.m.Y") : "").";";
|
||||
$csv_out .= ($is_sepa ? 0 : 10).";";
|
||||
$csv_out .= ($is_sepa ? 1 : 0);
|
||||
$csv_out .= "\n";
|
||||
}
|
||||
|
||||
/*$this->layout()->setFlash("Export erfolgreich abgeschlossen", "success");
|
||||
$this->redirect("Invoice");*/
|
||||
|
||||
header("Content-type: text/csv");
|
||||
header('Content-disposition: attachment; filename="tt-rech-export-bmd-'.date('Y-m-d_H-i-s').'.csv"');
|
||||
|
||||
echo $csv_header."\n".$csv_out;
|
||||
exit;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user