Billing / generation of Invoices finished
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
class Invoice extends mfBaseModel {
|
||||
private $positions;
|
||||
private $voicenumbers;
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
@@ -17,6 +18,12 @@ class Invoice extends mfBaseModel {
|
||||
return $this->positions;
|
||||
}
|
||||
|
||||
if($name == "voicenumbers") {
|
||||
$voicenumbers = InvoiceVoicenumberModel::search(["invoice_id" => $this->id]);
|
||||
$this->voicenumbers = $voicenumbers;
|
||||
return $this->voicenumbers;
|
||||
}
|
||||
|
||||
if($name == "creator") {
|
||||
$this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
||||
if($this->creator === null) {
|
||||
|
||||
@@ -117,7 +117,7 @@ class InvoiceController extends mfBaseController {
|
||||
$headerHtml = str_replace("{{ addressLine_4 }}", $invoice->zip . " " . $invoice->city, $headerHtml);
|
||||
$headerHtml = str_replace("{{ addressLine_5 }}", $invoice->country != "Österreich" ? $invoice->country : "", $headerHtml);
|
||||
$headerHtml = str_replace("{{ customerNumber }}", $invoice->customer_number, $headerHtml);
|
||||
$headerHtml = str_replace("{{ billingAccount }}", "testtest", $headerHtml);
|
||||
$headerHtml = str_replace("{{ billingAccount }}", $invoice->fibu_account_number, $headerHtml);
|
||||
$headerHtml = str_replace("{{ invoiceNumber }}", $invoice->invoice_number, $headerHtml);
|
||||
$headerHtml = str_replace("{{ invoiceDate }}", date("d.m.Y", $invoice->invoice_date), $headerHtml);
|
||||
$headerHtml = str_replace("{{ vatHtml }}", $invoice->uid ? "<tr><td>Ihre UID:</td><td>" . $invoice->uid . "</td></tr>" : "", $headerHtml);
|
||||
@@ -166,6 +166,7 @@ XINON GmbH";
|
||||
|
||||
$bill_positions = [];
|
||||
$credit_positions = [];
|
||||
$invoice_voicenumbers = [];
|
||||
|
||||
$billing_rows = BillingModel::search(["owner_id" => $owner_id,
|
||||
"billingaddress_id" => $billingaddress_id,
|
||||
@@ -244,6 +245,112 @@ XINON GmbH";
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ***************************************
|
||||
* Get Voicenumber Billing to Billing row
|
||||
* ***************************************
|
||||
*/
|
||||
|
||||
$voicebills = BillingVoicenumberModel::search(["billing_id" => $bill->id]);
|
||||
//var_dump($voicebills);exit;
|
||||
if(count($voicebills)) {
|
||||
$voice_start_date = reset($voicebills)->start_date;
|
||||
$voice_end_date = reset($voicebills)->end_date;
|
||||
$voiceplan = reset($voicebills)->voiceplan;
|
||||
$inc = reset($voicebills)->increment;
|
||||
$inc_first = reset($voicebills)->increment_first;
|
||||
|
||||
$voice_rows = [];
|
||||
foreach($voicebills as $voicebill) {
|
||||
$number = $voicebill->voicenumber;
|
||||
$zone = $voicebill->zone;
|
||||
$call_count = $voicebill->call_count;
|
||||
$duration = $voicebill->duration;
|
||||
$price = $voicebill->price;
|
||||
$price_total = $voicebill->price_total;
|
||||
|
||||
|
||||
if(!array_key_exists($number, $voice_rows)) {
|
||||
$voice_rows[$number] = [];
|
||||
}
|
||||
|
||||
if(!array_key_exists($zone, $voice_rows[$number])) {
|
||||
$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;
|
||||
$voice_rows[$number][$zone][$price]["price_total"] = 0;
|
||||
}
|
||||
|
||||
$voice_rows[$number][$zone][$price]["call_count"] += $call_count;
|
||||
$voice_rows[$number][$zone][$price]["duration"] = $duration;
|
||||
$voice_rows[$number][$zone][$price]["price_total"] = $price_total;
|
||||
}
|
||||
|
||||
//var_dump($voice_rows);exit;
|
||||
|
||||
$total_voice_price = 0;
|
||||
|
||||
foreach($voice_rows as $number => $zones) {
|
||||
$voicenumber_data = [];
|
||||
$voicenumber_data["voicenumber"] = $number;
|
||||
$voicenumber_data["start_date"] = $voice_start_date;
|
||||
$voicenumber_data["end_date"] = $voice_end_date;
|
||||
$voicenumber_data["voiceplan"] = $voiceplan;
|
||||
$voicenumber_data["increment"] = $inc;
|
||||
$voicenumber_data["increment_first"] = $inc_first;
|
||||
|
||||
$invoice_voicenumber = InvoiceVoicenumberModel::create($voicenumber_data);
|
||||
$invoice_voicenumber->voicenumberzones = [];
|
||||
|
||||
|
||||
|
||||
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"];
|
||||
$zone_data["duration"] = $row_values["duration"];
|
||||
$zone_data["price"] = $price;
|
||||
$zone_data["price_total"] = $row_values["price_total"];
|
||||
$zone_data["price_total_gross"] = $row_values["price_total"];
|
||||
if($invoice_vatrate) {
|
||||
$zone_data["price_total_gross"] = $row_values["price_total"] + (($row_values["price_total"] / 100) * $invoice_vatrate);
|
||||
}
|
||||
$zone_data["vatrate"] = $invoice_vatrate;
|
||||
$total_voice_price += $row_values["price_total"];
|
||||
|
||||
$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;
|
||||
|
||||
|
||||
$this->log->debug("Adding Voice Invoiceposition for Contract ID " . $bill->contract_id);
|
||||
$voice_data = $position_data;
|
||||
$voice_data["product_name"] = "Gesprächsgebühren zu " . $bill->product_name;
|
||||
$voice_data["product_info"] = null;
|
||||
$voice_data["matchcode"] = null;
|
||||
$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);
|
||||
$voice_position->setOption("timerange_month_only", true);
|
||||
$bill_positions[] = $voice_position;
|
||||
}
|
||||
|
||||
|
||||
/*if($bill->price >= 0 || $bill->price_setup >= 0) {
|
||||
$bill_positions[] = InvoicepositionModel::create($position_data);
|
||||
} else {
|
||||
@@ -285,9 +392,11 @@ XINON GmbH";
|
||||
}
|
||||
|
||||
|
||||
//var_dump($bill_positions, $credit_positions);exit;
|
||||
|
||||
|
||||
/*
|
||||
* *******************************
|
||||
* Save invoice and add positions
|
||||
* *******************************
|
||||
*/
|
||||
// create Invoice
|
||||
$invoice = InvoiceModel::create($invoice_data);
|
||||
$invoice->startTransaction();
|
||||
@@ -346,29 +455,51 @@ XINON GmbH";
|
||||
$invoice->rollbackTransaction();
|
||||
die("Error saving totals in Invoice");
|
||||
}
|
||||
// generate Invoice number
|
||||
|
||||
if(count($invoice_voicenumbers)) {
|
||||
foreach($invoice_voicenumbers as $inv_vn) {
|
||||
$invnz_s = $inv_vn->voicenumberzones;
|
||||
unset($inv_vn->voicenumberzones);
|
||||
|
||||
$inv_vn->invoice_id = $invoice->id;
|
||||
if(!$inv_vn->save()) {
|
||||
$invoice->rollbackTransaction();
|
||||
die("Error saving InvoiceVoicenumber");
|
||||
}
|
||||
foreach($invnz_s as $invnz) {
|
||||
$invnz->invoicevoicenumber_id = $inv_vn->id;
|
||||
if(!$invnz->save()) {
|
||||
$invoice->rollbackTransaction();
|
||||
die("Error saving InvoiceVoicenumberZone");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// generate Invoice number
|
||||
$new_num = InvoiceModel::getNextInvoiceNUmber();
|
||||
$invoice->invoice_number = $new_num;
|
||||
$invoice->invoice_date = date("U");
|
||||
|
||||
// voicenumbers
|
||||
//var_dump($invoice_voicenumbers);exit;
|
||||
|
||||
if (!$invoice->save()) {
|
||||
$invoice->rollbackTransaction();
|
||||
die("Error saving Invoice number and date");
|
||||
}
|
||||
|
||||
// commit transaction
|
||||
$invoice->commitTransaction();
|
||||
$i++;
|
||||
} catch (Exception $e) {
|
||||
if ($invoice) {
|
||||
$invoice->rollbackTransaction();
|
||||
}
|
||||
|
||||
die("Error saving Invoice!\n");
|
||||
|
||||
}
|
||||
|
||||
// commit transaction
|
||||
$invoice->commitTransaction();
|
||||
$i++;
|
||||
|
||||
// Create Invoice PDF
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user