Billing changes
This commit is contained in:
@@ -163,28 +163,39 @@ class InvoiceController extends mfBaseController {
|
||||
$i = 0;
|
||||
$p = 0;
|
||||
|
||||
$base_rows_bill = BillingModel::getInvoiceBaseData(['invoice_id' => null, "!vatgroup_id" => TT_VATGROUP_CREDIT]);
|
||||
$base_rows_credit = BillingModel::getInvoiceBaseData(['invoice_id' => null, "vatgroup_id" => TT_VATGROUP_CREDIT]);
|
||||
|
||||
$base_rows = array_merge($base_rows_bill, $base_rows_credit);
|
||||
|
||||
// get pairs of owner_id and billingaddress_id, so each will be its own invoice
|
||||
foreach (BillingModel::getInvoiceBaseData(['invoice_id' => null]) as $base) {
|
||||
//var_dump($base); continue;
|
||||
foreach ($base_rows as $base) {
|
||||
//var_dump($base);exit;
|
||||
$owner_id = $base["owner_id"];
|
||||
$billingaddress_id = $base["billingaddress_id"];
|
||||
$billing_type = $base["billing_type"];
|
||||
$billing_delivery = $base["billing_delivery"];
|
||||
$base_vatgroup_id = $base["vatgroup_id"];
|
||||
|
||||
$bill_positions = [];
|
||||
$credit_positions = [];
|
||||
$invoice_voicenumbers = [];
|
||||
|
||||
$billing_rows = BillingModel::search(["owner_id" => $owner_id,
|
||||
"billingaddress_id" => $billingaddress_id,
|
||||
"billing_type" => $billing_type,
|
||||
"billing_delivery" => $billing_delivery,
|
||||
"invoice_id" => null]);
|
||||
$bill_filter = ["owner_id" => $owner_id,
|
||||
"billingaddress_id" => $billingaddress_id,
|
||||
"billing_type" => $billing_type,
|
||||
"billing_delivery" => $billing_delivery,
|
||||
"invoice_id" => null];
|
||||
|
||||
if (!count($billing_rows)) {
|
||||
die("Keine nicht verrechneten Billing records für billingaddress_id");
|
||||
if($base_vatgroup_id == TT_VATGROUP_CREDIT) {
|
||||
$bill_filter["vatgroup_id"] = TT_VATGROUP_CREDIT;
|
||||
} else {
|
||||
$bill_filter["!vatgroup_id"] = TT_VATGROUP_CREDIT;
|
||||
}
|
||||
|
||||
$billing_rows = BillingModel::search($bill_filter);
|
||||
if(!count($billing_rows)) continue;
|
||||
//var_dump($billing_rows);exit;
|
||||
//var_dump($owner_id, $billingaddress_id, $bills);exit;
|
||||
|
||||
$invoice_data = [];
|
||||
@@ -192,6 +203,7 @@ class InvoiceController extends mfBaseController {
|
||||
$price_total_sum = 0;
|
||||
|
||||
foreach($billing_rows as $bill) {
|
||||
$vatgroup_id = $bill->vatgroup_id;
|
||||
$vatarea = $bill->vatarea;
|
||||
$invoice_vatrate = $bill->vatgroup->rates[$vatarea]->rate;
|
||||
|
||||
@@ -263,7 +275,7 @@ class InvoiceController extends mfBaseController {
|
||||
|
||||
$voicebills = BillingVoicenumberModel::search(["billing_id" => $bill->id]);
|
||||
//var_dump($voicebills);exit;
|
||||
if(count($voicebills)) {
|
||||
if (count($voicebills)) {
|
||||
$voice_start_date = reset($voicebills)->start_date;
|
||||
$voice_end_date = reset($voicebills)->end_date;
|
||||
$voiceplan = reset($voicebills)->voiceplan;
|
||||
@@ -271,7 +283,7 @@ class InvoiceController extends mfBaseController {
|
||||
$inc_first = reset($voicebills)->increment_first;
|
||||
|
||||
$voice_rows = [];
|
||||
foreach($voicebills as $voicebill) {
|
||||
foreach ($voicebills as $voicebill) {
|
||||
$number = $voicebill->voicenumber;
|
||||
$zone = $voicebill->zone;
|
||||
$call_count = $voicebill->call_count;
|
||||
@@ -280,15 +292,15 @@ class InvoiceController extends mfBaseController {
|
||||
$price_total = $voicebill->price_total;
|
||||
|
||||
|
||||
if(!array_key_exists($number, $voice_rows)) {
|
||||
if (!array_key_exists($number, $voice_rows)) {
|
||||
$voice_rows[$number] = [];
|
||||
}
|
||||
|
||||
if(!array_key_exists($zone, $voice_rows[$number])) {
|
||||
if (!array_key_exists($zone, $voice_rows[$number])) {
|
||||
$voice_rows[$number][$zone] = [];
|
||||
}
|
||||
|
||||
if(!array_key_exists($price, $voice_rows[$number][$zone])) {
|
||||
if (!array_key_exists($price, $voice_rows[$number][$zone])) {
|
||||
$voice_rows[$number][$zone][$price] = [];
|
||||
$voice_rows[$number][$zone][$price]["call_count"] = 0;
|
||||
$voice_rows[$number][$zone][$price]["duration"] = 0;
|
||||
@@ -304,7 +316,7 @@ class InvoiceController extends mfBaseController {
|
||||
|
||||
$total_voice_price = 0;
|
||||
|
||||
foreach($voice_rows as $number => $zones) {
|
||||
foreach ($voice_rows as $number => $zones) {
|
||||
$voicenumber_data = [];
|
||||
$voicenumber_data["voicenumber"] = $number;
|
||||
$voicenumber_data["start_date"] = $voice_start_date;
|
||||
@@ -317,9 +329,8 @@ class InvoiceController extends mfBaseController {
|
||||
$invoice_voicenumber->voicenumberzones = [];
|
||||
|
||||
|
||||
|
||||
foreach($zones as $zone => $prices) {
|
||||
foreach($prices as $price => $row_values) {
|
||||
foreach ($zones as $zone => $prices) {
|
||||
foreach ($prices as $price => $row_values) {
|
||||
$zone_data = [];
|
||||
$zone_data["zone"] = $zone;
|
||||
$zone_data["call_count"] = $row_values["call_count"];
|
||||
@@ -327,7 +338,7 @@ class InvoiceController extends mfBaseController {
|
||||
$zone_data["price"] = $price;
|
||||
$zone_data["price_total"] = $row_values["price_total"];
|
||||
$zone_data["price_total_gross"] = $row_values["price_total"];
|
||||
if($invoice_vatrate) {
|
||||
if ($invoice_vatrate) {
|
||||
$zone_data["price_total_gross"] = $row_values["price_total"] + (($row_values["price_total"] / 100) * $invoice_vatrate);
|
||||
}
|
||||
$zone_data["vatrate"] = $invoice_vatrate;
|
||||
@@ -345,7 +356,7 @@ class InvoiceController extends mfBaseController {
|
||||
}
|
||||
|
||||
$price_total_sum += $total_voice_price;
|
||||
//var_dump($invoice_voicenumbers);exit;
|
||||
//var_dump($invoice_voicenumbers);exit;
|
||||
|
||||
|
||||
$this->log->debug("Adding Voice Invoiceposition for Contract ID " . $bill->contract_id);
|
||||
@@ -374,6 +385,8 @@ class InvoiceController extends mfBaseController {
|
||||
$invoice_data["billingaddress_id"] = $billingaddress_id;
|
||||
$invoice_data["customer_number"] = $bill->customer_number;
|
||||
$invoice_data["fibu_account_number"] = $bill->fibu_account_number;
|
||||
|
||||
|
||||
$invoice_data["sepa_date"] = $bill->sepa_date;
|
||||
$invoice_data["sepa_id"] = $bill->sepa_id;
|
||||
$invoice_data["sepa_last_date"] = $bill->sepa_last_date;
|
||||
@@ -395,6 +408,7 @@ class InvoiceController extends mfBaseController {
|
||||
$invoice_data["bank_account_bic"] = $bill->bank_account_bic;
|
||||
$invoice_data["total"] = 0;
|
||||
$invoice_data["total_gross"] = 0;
|
||||
$invoice_data["vatgroup_id"] = $vatgroup_id;
|
||||
//$invoice_data["total_vat"] = 0;
|
||||
|
||||
|
||||
@@ -404,7 +418,6 @@ class InvoiceController extends mfBaseController {
|
||||
$invoice_data["fibu_taxcode"] = $bill->vatgroup->rates[$vatarea]->taxcode;
|
||||
$invoice_data["tax_text"] = $bill->vatgroup->rates[$vatarea]->invoice_text;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -414,7 +427,7 @@ class InvoiceController extends mfBaseController {
|
||||
continue;
|
||||
}*/
|
||||
|
||||
|
||||
//var_dump($invoice_data);exit;
|
||||
/*
|
||||
* *******************************
|
||||
* Save invoice and add positions
|
||||
@@ -426,6 +439,7 @@ class InvoiceController extends mfBaseController {
|
||||
|
||||
try {
|
||||
if (!$invoice->save()) {
|
||||
var_dump($invoice);
|
||||
$invoice->rollbackTransaction();
|
||||
die("Error saving Invoice");
|
||||
}
|
||||
@@ -556,14 +570,37 @@ class InvoiceController extends mfBaseController {
|
||||
* 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";
|
||||
//var_dump($this->request->type);exit;
|
||||
$type = "normal";
|
||||
if($this->request->type == "credit") {
|
||||
$type = "credit";
|
||||
}
|
||||
|
||||
$csv_header = "satzart;konto;gkonto;belegnr;belegdatum;buchsymbol;buchcode;prozent;steuercode;betrag;steuer;text;kost;";
|
||||
|
||||
if($type == "credit") {
|
||||
$csv_header .= "extbelegnr";
|
||||
} else {
|
||||
$csv_header .= "bank-iban-nr;bank-swiftcode;bank-mandatsid;bank-mandatsdatum;bank-mandatskz;bank-letztereinzug;zvsperre;bankeinzug";
|
||||
}
|
||||
$csv_out = "";
|
||||
|
||||
if(!InvoiceModel::search(["bmd_export_date" => null])) {
|
||||
$filter = [
|
||||
"bmd_export_date" => null,
|
||||
];
|
||||
|
||||
if($type == "credit") {
|
||||
$filter["vatgroup_id"] = TT_VATGROUP_CREDIT;
|
||||
} else {
|
||||
$filter["!vatgroup_id"] = TT_VATGROUP_CREDIT;
|
||||
}
|
||||
|
||||
|
||||
if(!InvoiceModel::search($filter)) {
|
||||
$this->layout()->setFlash("Keine neuen Rechnungen seit letztem BMD-Export vorhanden.");
|
||||
$this->redirect("Invoice");
|
||||
}
|
||||
foreach(InvoiceModel::search(["bmd_export_date" => null]) as $invoice) {
|
||||
foreach(InvoiceModel::search($filter) as $invoice) {
|
||||
if($invoice->bmd_export_date) {
|
||||
die("wtf");
|
||||
}
|
||||
@@ -579,9 +616,10 @@ class InvoiceController extends mfBaseController {
|
||||
$buchsymbol = "GU";
|
||||
} else {
|
||||
$buchsymbol = "AR";
|
||||
|
||||
}
|
||||
|
||||
$fibu_account = $invoice->fibu_account_number;
|
||||
|
||||
$buchungstext = "[".$invoice->customer_number."]";
|
||||
if($invoice->company) {
|
||||
$buchungstext .= " ".$invoice->company;
|
||||
@@ -590,7 +628,7 @@ class InvoiceController extends mfBaseController {
|
||||
}
|
||||
|
||||
$buchungstext = str_replace(["\n","\r", ";"], "", $buchungstext);
|
||||
|
||||
$buchcode = "1";
|
||||
$is_sepa = ($invoice->billing_type == "sepa");
|
||||
|
||||
$iban = "";
|
||||
@@ -620,27 +658,41 @@ class InvoiceController extends mfBaseController {
|
||||
|
||||
}
|
||||
|
||||
if($type == "credit") {
|
||||
$buchsymbol = "ER";
|
||||
$buchcode = "2";
|
||||
|
||||
if($invoice->fibu_supplier_number) {
|
||||
$this->layout()->setFlash("Lieferant ".$invoice->customer_number." - ".$invoice->company." ".$invoice->firstname." ".$invoice->lastname. " hat keine Lieferantennummer! Bitte nachtragen.");
|
||||
$this->redirect("Invoice");
|
||||
}
|
||||
$fibu_account = $invoice->fibu_account_number;
|
||||
}
|
||||
|
||||
$csv_out .= "0;";
|
||||
$csv_out .= $invoice->fibu_account_number.";";
|
||||
$csv_out .= $fibu_account.";";
|
||||
$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 .= $buchcode.";";
|
||||
$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 .= $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);
|
||||
|
||||
if($type != "credit") {
|
||||
$csv_out .= $iban.";";
|
||||
$csv_out .= $bic.";";
|
||||
$csv_out .= $sepa_id.";";
|
||||
$csv_out .= ($sepa_date ? $sepa_date->format("d.m.Y") : "").";";
|
||||
$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);
|
||||
}
|
||||
$csv_out .= "\n";
|
||||
}
|
||||
|
||||
@@ -648,7 +700,12 @@ class InvoiceController extends mfBaseController {
|
||||
$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"');
|
||||
if($type == "credit") {
|
||||
header('Content-disposition: attachment; filename="tt-prov-export-bmd-'.date('Y-m-d_H-i-s').'.csv"');
|
||||
} else {
|
||||
header('Content-disposition: attachment; filename="tt-rech-export-bmd-'.date('Y-m-d_H-i-s').'.csv"');
|
||||
}
|
||||
|
||||
|
||||
echo $csv_header."\n".$csv_out;
|
||||
exit;
|
||||
|
||||
@@ -32,6 +32,7 @@ class InvoiceModel {
|
||||
public $bank_account_bic;
|
||||
public $total;
|
||||
public $total_gross;
|
||||
public $vatgroup_id;
|
||||
public $bmd_export_date;
|
||||
public $date_delivered;
|
||||
public $total_vat;
|
||||
@@ -407,6 +408,19 @@ class InvoiceModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("vatgroup_id", $filter)) {
|
||||
$vatgroup_id = $filter['vatgroup_id'];
|
||||
if(is_numeric($vatgroup_id)) {
|
||||
$where .= " AND Invoice.vatgroup_id = '$vatgroup_id'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("!vatgroup_id", $filter)) {
|
||||
$vatgroup_id = $filter['!vatgroup_id'];
|
||||
if(is_numeric($vatgroup_id)) {
|
||||
$where .= " AND Invoice.vatgroup_id <> '$vatgroup_id'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("add-where", $filter)) {
|
||||
$where .= " ".$filter['add-where'];
|
||||
|
||||
Reference in New Issue
Block a user