Billing / generation of Invoices finished
This commit is contained in:
@@ -354,7 +354,7 @@
|
|||||||
<td class="text-monospace"><?=$preorder->adb_wohneinheit->rimo_ex_state?>
|
<td class="text-monospace"><?=$preorder->adb_wohneinheit->rimo_ex_state?>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
<th>Home Operational State:</th>
|
<th>Home Operational State:</th>
|
||||||
<td class="text-monospace"><?=($preorder->adb_wohneinheit->rimo_op_state != "Undefined") ? $preorder->adb_wohneinheit->rimo_op_state : ""?>
|
<td class="text-monospace"><?=($preorder->adb_wohneinheit->rimo_op_state != "Undefined") ? $preorder->adb_wohneinheit->rimo_op_state : ""?>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1006,7 +1006,8 @@ class Admin_IvtContractImport {
|
|||||||
// import Voiceplan
|
// import Voiceplan
|
||||||
$this->getVoiceplan($voice_contract);
|
$this->getVoiceplan($voice_contract);
|
||||||
|
|
||||||
$voice_contract->matchcode = implode(", ", $contract_matchcode_numbers);
|
//$voice_contract->matchcode = implode(", ", $contract_matchcode_numbers);
|
||||||
|
$voice_contract->matchcode = "";
|
||||||
$voice_contract->save();
|
$voice_contract->save();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -166,10 +166,11 @@ class Admin_IvtCreditImport {
|
|||||||
if($building->networksection_id) {
|
if($building->networksection_id) {
|
||||||
$matchcode .= $building->networksection->name;
|
$matchcode .= $building->networksection->name;
|
||||||
}
|
}
|
||||||
$matchcode .= $customer->getCompanyOrName();
|
$matchcode .= "; ".$customer->getCompanyOrName();
|
||||||
$matchcode .= "; ".$building->street.", ".$building->zip." ".$building->city;
|
$matchcode .= ", ".$building->street.", ".$building->zip." ".$building->city;
|
||||||
} else {
|
} else {
|
||||||
$matchcode .= "; ".$customer->street.", ".$customer->zip." ".$customer->city;
|
$matchcode .= $customer->getCompanyOrName();
|
||||||
|
$matchcode .= ", ".$customer->street.", ".$customer->zip." ".$customer->city;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -448,7 +448,6 @@ class BillingController extends mfBaseController {
|
|||||||
}
|
}
|
||||||
$voiceplan = new Voiceplan($voiceplan_id);
|
$voiceplan = new Voiceplan($voiceplan_id);
|
||||||
|
|
||||||
|
|
||||||
// always look for whole month
|
// always look for whole month
|
||||||
// numbers usually don't change owner without at least a few months being stale
|
// numbers usually don't change owner without at least a few months being stale
|
||||||
if($voice_start_date->format("d") > 1) {
|
if($voice_start_date->format("d") > 1) {
|
||||||
@@ -467,11 +466,21 @@ class BillingController extends mfBaseController {
|
|||||||
//var_dump($call);
|
//var_dump($call);
|
||||||
$number = $call->voice_account;
|
$number = $call->voice_account;
|
||||||
$dest_nummer = $call->destination;
|
$dest_nummer = $call->destination;
|
||||||
|
if(substr($dest_nummer, 0, 2) == "00") {
|
||||||
|
$dest_nummer = substr($dest_nummer, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(substr($dest_nummer, 0, 1) == "+") {
|
||||||
|
$dest_nummer = substr($dest_nummer, 1);
|
||||||
|
}
|
||||||
|
|
||||||
if (array_key_exists($dest_nummer, $destinations_cache)) {
|
if (array_key_exists($dest_nummer, $destinations_cache)) {
|
||||||
$destination = $destinations_cache[$dest_nummer];
|
$destination = $destinations_cache[$dest_nummer];
|
||||||
} else {
|
} else {
|
||||||
$destination = $voiceplan->getDestinationByNumber($dest_nummer);
|
$destination = $voiceplan->getDestinationByNumber($dest_nummer);
|
||||||
|
if(!$destination) {
|
||||||
|
die("Destination für Zielrufnummer ".$call->destination." nicht gefunden");
|
||||||
|
}
|
||||||
$destinations_cache[$dest_nummer] = $destination;
|
$destinations_cache[$dest_nummer] = $destination;
|
||||||
}
|
}
|
||||||
//var_dump($destination);
|
//var_dump($destination);
|
||||||
@@ -520,43 +529,35 @@ class BillingController extends mfBaseController {
|
|||||||
$voicebills[$number][$zone->id]["zone_total"] += $call_price;
|
$voicebills[$number][$zone->id]["zone_total"] += $call_price;
|
||||||
$voicebills[$number][$zone->id]["duration"] += $call->duration;
|
$voicebills[$number][$zone->id]["duration"] += $call->duration;
|
||||||
}
|
}
|
||||||
if(!count($voicebills)) {
|
}
|
||||||
continue;
|
|
||||||
}
|
|
||||||
//var_dump($voicebills);exit;
|
|
||||||
|
|
||||||
foreach($voicebills as $vbnumber => $zones) {
|
// save to BillingVoicenumber
|
||||||
foreach($zones as $zone_id => $vb) {
|
foreach($voicebills as $vbnumber => $zones) {
|
||||||
$vbdata = [];
|
foreach($zones as $zone_id => $vb) {
|
||||||
$vbdata["billing_id"] = $billing->id;
|
$vbdata = [];
|
||||||
$vbdata["contract_id"] = $contract->id;
|
$vbdata["billing_id"] = $billing->id;
|
||||||
$vbdata["voicenumber"] = $vbnumber;
|
$vbdata["contract_id"] = $contract->id;
|
||||||
$vbdata["start_date"] = $voice_start_date->format("Y-m-d");
|
$vbdata["voicenumber"] = $vbnumber;
|
||||||
$vbdata["end_date"] = $voice_end_date->format("Y-m-d");
|
$vbdata["start_date"] = $voice_start_date->format("Y-m-d");
|
||||||
$vbdata["voiceplan"] = $vb["voiceplan"];
|
$vbdata["end_date"] = $voice_end_date->format("Y-m-d");
|
||||||
$vbdata["zone"] = $vb["zone_name"];
|
$vbdata["voiceplan"] = $vb["voiceplan"];
|
||||||
$vbdata["call_count"] = $vb["count"];
|
$vbdata["zone"] = $vb["zone_name"];
|
||||||
$vbdata["duration"] = $vb["duration"];
|
$vbdata["call_count"] = $vb["count"];
|
||||||
$vbdata["price"] = $vb["price"];
|
$vbdata["duration"] = $vb["duration"];
|
||||||
$vbdata["price_total"] = $vb["zone_total"];
|
$vbdata["price"] = $vb["price"];
|
||||||
$vbdata["increment"] = $vb["increment"];
|
$vbdata["price_total"] = $vb["zone_total"];
|
||||||
$vbdata["increment_first"] = $vb["increment_first"];
|
$vbdata["increment"] = $vb["increment"];
|
||||||
|
$vbdata["increment_first"] = $vb["increment_first"];
|
||||||
|
|
||||||
$bill_voice = BillingVoicenumberModel::create($vbdata);
|
$bill_voice = BillingVoicenumberModel::create($vbdata);
|
||||||
if(!$bill_voice->save()) {
|
if(!$bill_voice->save()) {
|
||||||
var_dump($vbdata);
|
var_dump($vbdata);
|
||||||
die("Error saving Billing Voicenumber!");
|
die("Error saving Billing Voicenumber!");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$v++;
|
|
||||||
|
|
||||||
// save to BillingVoicenumber
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
$v++;
|
||||||
|
//var_dump($voicebills);exit;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -168,15 +168,6 @@ class BillingVoicenumberModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(array_key_exists("approved", $filter)) {
|
|
||||||
$approved = $filter['approved'];
|
|
||||||
if($approved) {
|
|
||||||
$where .= " AND BillingVoicenumber.approved = 1";
|
|
||||||
} else {
|
|
||||||
$where .= " AND BillingVoicenumber.approved = 0";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(array_key_exists("billing_id", $filter)) {
|
if(array_key_exists("billing_id", $filter)) {
|
||||||
$billing_id = $filter['billing_id'];
|
$billing_id = $filter['billing_id'];
|
||||||
if(is_numeric($billing_id)) {
|
if(is_numeric($billing_id)) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
class Invoice extends mfBaseModel {
|
class Invoice extends mfBaseModel {
|
||||||
private $positions;
|
private $positions;
|
||||||
|
private $voicenumbers;
|
||||||
|
|
||||||
public function getProperty($name) {
|
public function getProperty($name) {
|
||||||
if($this->$name == null) {
|
if($this->$name == null) {
|
||||||
@@ -17,6 +18,12 @@ class Invoice extends mfBaseModel {
|
|||||||
return $this->positions;
|
return $this->positions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($name == "voicenumbers") {
|
||||||
|
$voicenumbers = InvoiceVoicenumberModel::search(["invoice_id" => $this->id]);
|
||||||
|
$this->voicenumbers = $voicenumbers;
|
||||||
|
return $this->voicenumbers;
|
||||||
|
}
|
||||||
|
|
||||||
if($name == "creator") {
|
if($name == "creator") {
|
||||||
$this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
$this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
||||||
if($this->creator === null) {
|
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_4 }}", $invoice->zip . " " . $invoice->city, $headerHtml);
|
||||||
$headerHtml = str_replace("{{ addressLine_5 }}", $invoice->country != "Österreich" ? $invoice->country : "", $headerHtml);
|
$headerHtml = str_replace("{{ addressLine_5 }}", $invoice->country != "Österreich" ? $invoice->country : "", $headerHtml);
|
||||||
$headerHtml = str_replace("{{ customerNumber }}", $invoice->customer_number, $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("{{ invoiceNumber }}", $invoice->invoice_number, $headerHtml);
|
||||||
$headerHtml = str_replace("{{ invoiceDate }}", date("d.m.Y", $invoice->invoice_date), $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);
|
$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 = [];
|
$bill_positions = [];
|
||||||
$credit_positions = [];
|
$credit_positions = [];
|
||||||
|
$invoice_voicenumbers = [];
|
||||||
|
|
||||||
$billing_rows = BillingModel::search(["owner_id" => $owner_id,
|
$billing_rows = BillingModel::search(["owner_id" => $owner_id,
|
||||||
"billingaddress_id" => $billingaddress_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) {
|
/*if($bill->price >= 0 || $bill->price_setup >= 0) {
|
||||||
$bill_positions[] = InvoicepositionModel::create($position_data);
|
$bill_positions[] = InvoicepositionModel::create($position_data);
|
||||||
} else {
|
} else {
|
||||||
@@ -285,9 +392,11 @@ XINON GmbH";
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//var_dump($bill_positions, $credit_positions);exit;
|
/*
|
||||||
|
* *******************************
|
||||||
|
* Save invoice and add positions
|
||||||
|
* *******************************
|
||||||
|
*/
|
||||||
// create Invoice
|
// create Invoice
|
||||||
$invoice = InvoiceModel::create($invoice_data);
|
$invoice = InvoiceModel::create($invoice_data);
|
||||||
$invoice->startTransaction();
|
$invoice->startTransaction();
|
||||||
@@ -346,29 +455,51 @@ XINON GmbH";
|
|||||||
$invoice->rollbackTransaction();
|
$invoice->rollbackTransaction();
|
||||||
die("Error saving totals in Invoice");
|
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();
|
$new_num = InvoiceModel::getNextInvoiceNUmber();
|
||||||
$invoice->invoice_number = $new_num;
|
$invoice->invoice_number = $new_num;
|
||||||
$invoice->invoice_date = date("U");
|
$invoice->invoice_date = date("U");
|
||||||
|
|
||||||
|
// voicenumbers
|
||||||
|
//var_dump($invoice_voicenumbers);exit;
|
||||||
|
|
||||||
if (!$invoice->save()) {
|
if (!$invoice->save()) {
|
||||||
$invoice->rollbackTransaction();
|
$invoice->rollbackTransaction();
|
||||||
die("Error saving Invoice number and date");
|
die("Error saving Invoice number and date");
|
||||||
}
|
}
|
||||||
|
|
||||||
// commit transaction
|
|
||||||
$invoice->commitTransaction();
|
|
||||||
$i++;
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
if ($invoice) {
|
if ($invoice) {
|
||||||
$invoice->rollbackTransaction();
|
$invoice->rollbackTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
die("Error saving Invoice!\n");
|
die("Error saving Invoice!\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// commit transaction
|
||||||
|
$invoice->commitTransaction();
|
||||||
|
$i++;
|
||||||
|
|
||||||
// Create Invoice PDF
|
// Create Invoice PDF
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
60
application/InvoiceVoicenumber/InvoiceVoicenumber.php
Normal file
60
application/InvoiceVoicenumber/InvoiceVoicenumber.php
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class InvoiceVoicenumber extends mfBaseModel {
|
||||||
|
private $zones;
|
||||||
|
|
||||||
|
public function getProperty($name) {
|
||||||
|
if($this->$name == null) {
|
||||||
|
|
||||||
|
if(!$this->id) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if($name == "zones") {
|
||||||
|
$zones = InvoiceVoicenumberZoneModel::search(["invoicevoicenumber_id" => $this->id]);
|
||||||
|
$this->zones = $zones;
|
||||||
|
return $this->zones;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($name == "creator") {
|
||||||
|
$this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
||||||
|
if($this->creator === null) {
|
||||||
|
$this->creator = new User($this->create_by);
|
||||||
|
if($this->creator->id) {
|
||||||
|
mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->creator;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($name == "editor") {
|
||||||
|
$this->editor = mfValuecache::singleton()->get("Worker-id-".$this->edit_by);
|
||||||
|
if($this->editor === null) {
|
||||||
|
$this->editor = new User($this->edit_by);
|
||||||
|
if($this->editor->id) {
|
||||||
|
mfValuecache::singleton()->set("Worker-id-".$this->edit_by, $this->editor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->editor;
|
||||||
|
}
|
||||||
|
|
||||||
|
$classname = ucfirst($name);
|
||||||
|
$idfield = $name."_id";
|
||||||
|
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
|
||||||
|
if(!$this->$name) {
|
||||||
|
$this->$name = new $classname($this->$idfield);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->$name->id) {
|
||||||
|
mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
|
||||||
|
return $this->$name;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->$name;
|
||||||
|
}
|
||||||
|
}
|
||||||
137
application/InvoiceVoicenumber/InvoiceVoicenumberModel.php
Normal file
137
application/InvoiceVoicenumber/InvoiceVoicenumberModel.php
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class InvoiceVoicenumberModel {
|
||||||
|
public $invoice_id;
|
||||||
|
public $voicenumber;
|
||||||
|
public $start_date;
|
||||||
|
public $end_date;
|
||||||
|
public $voiceplan;
|
||||||
|
public $increment;
|
||||||
|
public $increment_first;
|
||||||
|
|
||||||
|
public $create_by;
|
||||||
|
public $edit_by;
|
||||||
|
public $create;
|
||||||
|
public $edit;
|
||||||
|
|
||||||
|
|
||||||
|
public static function create(Array $data) {
|
||||||
|
$model = new InvoiceVoicenumber();
|
||||||
|
|
||||||
|
foreach($data as $field => $value) {
|
||||||
|
if(property_exists(get_called_class(), $field)) {
|
||||||
|
$model ->$field = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$me = new User();
|
||||||
|
$me->loadMe();
|
||||||
|
|
||||||
|
if($model->create_by === null) {
|
||||||
|
$model->create_by = $me->id;
|
||||||
|
}
|
||||||
|
if($model->edit_by === null) {
|
||||||
|
$model->edit_by = $me->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getFirst($filter) {
|
||||||
|
$db = FronkDB::singleton();
|
||||||
|
|
||||||
|
$where = self::getSqlFilter($filter);
|
||||||
|
$sql = "SELECT * FROM InvoiceVoicenumber
|
||||||
|
WHERE $where
|
||||||
|
ORDER BY invoice_id,voicenumber,start_date LIMIT 1";
|
||||||
|
//var_dump($sql);exit;
|
||||||
|
$res = $db->query($sql);
|
||||||
|
if($db->num_rows($res)) {
|
||||||
|
$data = $db->fetch_object($res);
|
||||||
|
$item = new InvoiceVoicenumber($data);
|
||||||
|
if($item->id) {
|
||||||
|
return $item;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function count($filter) {
|
||||||
|
$db = FronkDB::singleton();
|
||||||
|
|
||||||
|
$where = self::getSqlFilter($filter);
|
||||||
|
$sql = "SELECT COUNT(*) as cnt FROM InvoiceVoicenumber
|
||||||
|
WHERE $where";
|
||||||
|
|
||||||
|
//mfLoghandler::singleton()->debug($sql);
|
||||||
|
|
||||||
|
$res = $db->query($sql);
|
||||||
|
if($db->num_rows($res)) {
|
||||||
|
$data = $db->fetch_object($res);
|
||||||
|
return $data->cnt;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function search($filter, $limit = false, $order = false) {
|
||||||
|
//var_dump($filter);exit;
|
||||||
|
$items = [];
|
||||||
|
|
||||||
|
if(!$order) {
|
||||||
|
$order = "invoice_id,voicenumber,start_date";
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = FronkDB::singleton();
|
||||||
|
|
||||||
|
$where = self::getSqlFilter($filter);
|
||||||
|
$sql = "SELECT * FROM InvoiceVoicenumber
|
||||||
|
WHERE $where
|
||||||
|
ORDER BY $order";
|
||||||
|
|
||||||
|
if(is_array($limit) && count($limit)) {
|
||||||
|
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
||||||
|
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
||||||
|
} elseif(is_numeric($limit['count'])) {
|
||||||
|
$sql .= " LIMIT ".$limit['count'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mfLoghandler::singleton()->debug($sql);
|
||||||
|
|
||||||
|
$res = $db->query($sql);
|
||||||
|
if($db->num_rows($res)) {
|
||||||
|
while($data = $db->fetch_object($res)) {
|
||||||
|
$items[$data->id] = new InvoiceVoicenumber($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $items;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function getSqlFilter($filter) {
|
||||||
|
$where = "1=1 ";
|
||||||
|
|
||||||
|
$db = FronkDB::singleton();
|
||||||
|
|
||||||
|
//var_dump($filter);exit;
|
||||||
|
|
||||||
|
if(array_key_exists("invoice_id", $filter)) {
|
||||||
|
$invoice_id = $filter['invoice_id'];
|
||||||
|
if(is_numeric($invoice_id)) {
|
||||||
|
$where .= " AND InvoiceVoicenumber.invoice_id=$invoice_id";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(array_key_exists("add-where", $filter)) {
|
||||||
|
$where .= " ".$filter['add-where'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//var_dump($filter, $where);exit;
|
||||||
|
return $where;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class InvoiceVoicenumberZone extends mfBaseModel {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class InvoiceVoicenumberZoneModel {
|
||||||
|
public $invoicevoicenumber_id;
|
||||||
|
public $zone;
|
||||||
|
public $call_count;
|
||||||
|
public $duration;
|
||||||
|
public $price;
|
||||||
|
public $price_total;
|
||||||
|
public $price_total_gross;
|
||||||
|
public $vatrate;
|
||||||
|
|
||||||
|
public $create_by;
|
||||||
|
public $edit_by;
|
||||||
|
public $create;
|
||||||
|
public $edit;
|
||||||
|
|
||||||
|
|
||||||
|
public static function create(Array $data) {
|
||||||
|
$model = new InvoiceVoicenumberZone();
|
||||||
|
|
||||||
|
foreach($data as $field => $value) {
|
||||||
|
if(property_exists(get_called_class(), $field)) {
|
||||||
|
$model ->$field = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$me = new User();
|
||||||
|
$me->loadMe();
|
||||||
|
|
||||||
|
if($model->create_by === null) {
|
||||||
|
$model->create_by = $me->id;
|
||||||
|
}
|
||||||
|
if($model->edit_by === null) {
|
||||||
|
$model->edit_by = $me->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getFirst($filter) {
|
||||||
|
$db = FronkDB::singleton();
|
||||||
|
|
||||||
|
$where = self::getSqlFilter($filter);
|
||||||
|
$sql = "SELECT * FROM InvoiceVoicenumberZone
|
||||||
|
WHERE $where
|
||||||
|
ORDER BY invoicevoicenumber_id,zone,price LIMIT 1";
|
||||||
|
//var_dump($sql);exit;
|
||||||
|
$res = $db->query($sql);
|
||||||
|
if($db->num_rows($res)) {
|
||||||
|
$data = $db->fetch_object($res);
|
||||||
|
$item = new InvoiceVoicenumberZone($data);
|
||||||
|
if($item->id) {
|
||||||
|
return $item;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function count($filter) {
|
||||||
|
$db = FronkDB::singleton();
|
||||||
|
|
||||||
|
$where = self::getSqlFilter($filter);
|
||||||
|
$sql = "SELECT COUNT(*) as cnt FROM InvoiceVoicenumberZone
|
||||||
|
WHERE $where";
|
||||||
|
|
||||||
|
//mfLoghandler::singleton()->debug($sql);
|
||||||
|
|
||||||
|
$res = $db->query($sql);
|
||||||
|
if($db->num_rows($res)) {
|
||||||
|
$data = $db->fetch_object($res);
|
||||||
|
return $data->cnt;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function search($filter, $limit = false, $order = false) {
|
||||||
|
//var_dump($filter);exit;
|
||||||
|
$items = [];
|
||||||
|
|
||||||
|
if(!$order) {
|
||||||
|
$order = "invoicevoicenumber_id,zone,price";
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = FronkDB::singleton();
|
||||||
|
|
||||||
|
$where = self::getSqlFilter($filter);
|
||||||
|
$sql = "SELECT * FROM InvoiceVoicenumberZone
|
||||||
|
WHERE $where
|
||||||
|
ORDER BY $order";
|
||||||
|
|
||||||
|
if(is_array($limit) && count($limit)) {
|
||||||
|
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
||||||
|
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
||||||
|
} elseif(is_numeric($limit['count'])) {
|
||||||
|
$sql .= " LIMIT ".$limit['count'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mfLoghandler::singleton()->debug($sql);
|
||||||
|
|
||||||
|
$res = $db->query($sql);
|
||||||
|
if($db->num_rows($res)) {
|
||||||
|
while($data = $db->fetch_object($res)) {
|
||||||
|
$items[$data->id] = new InvoiceVoicenumberZone($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $items;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function getSqlFilter($filter) {
|
||||||
|
$where = "1=1 ";
|
||||||
|
|
||||||
|
$db = FronkDB::singleton();
|
||||||
|
|
||||||
|
//var_dump($filter);exit;
|
||||||
|
|
||||||
|
if(array_key_exists("invoicevoicenumber_id", $filter)) {
|
||||||
|
$invoicevoicenumber_id = $filter['invoicevoicenumber_id'];
|
||||||
|
if(is_numeric($invoicevoicenumber_id)) {
|
||||||
|
$where .= " AND InvoiceVoicenumberZone.invoicevoicenumber_id=$invoicevoicenumber_id";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(array_key_exists("add-where", $filter)) {
|
||||||
|
$where .= " ".$filter['add-where'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//var_dump($filter, $where);exit;
|
||||||
|
return $where;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,7 +2,41 @@
|
|||||||
|
|
||||||
class Invoiceposition extends mfBaseModel {
|
class Invoiceposition extends mfBaseModel {
|
||||||
|
|
||||||
|
public function setOption($name, $value) {
|
||||||
|
$options = $this->getOptions;
|
||||||
|
|
||||||
|
if($options) {
|
||||||
|
$options = json_decode($this->options);
|
||||||
|
if(json_last_error() !== JSON_ERROR_NONE) {
|
||||||
|
$options = new stdClass();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$options = new stdClass();
|
||||||
|
}
|
||||||
|
|
||||||
|
$options->$name = $value;
|
||||||
|
|
||||||
|
$this->options = json_encode($options);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getOption($name) {
|
||||||
|
if(!$this->options) return null;
|
||||||
|
|
||||||
|
$this->log->debug("getOptions ($name): ".print_r($this->options, true));
|
||||||
|
|
||||||
|
$options = json_decode($this->options);
|
||||||
|
if(json_last_error() !== JSON_ERROR_NONE) {
|
||||||
|
$this->log->debug("getOptions ($name) decoding failed");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(property_exists($options, $name)) {
|
||||||
|
|
||||||
|
return $options->$name;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
public function __clone() {
|
public function __clone() {
|
||||||
$me = new User;
|
$me = new User;
|
||||||
$me->loadMe();
|
$me->loadMe();
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ class InvoicepositionModel {
|
|||||||
public $fibu_cost_account_legacy;
|
public $fibu_cost_account_legacy;
|
||||||
public $fibu_taxcode;
|
public $fibu_taxcode;
|
||||||
public $billing_period;
|
public $billing_period;
|
||||||
|
public $options;
|
||||||
|
|
||||||
public $create_by;
|
public $create_by;
|
||||||
public $edit_by;
|
public $edit_by;
|
||||||
@@ -106,7 +107,7 @@ class InvoicepositionModel {
|
|||||||
$items = [];
|
$items = [];
|
||||||
|
|
||||||
if(!$order) {
|
if(!$order) {
|
||||||
$order = "invoice_id,contract_id,start_date,matchcode ASC";
|
$order = "invoice_id,contract_id,id ASC";
|
||||||
}
|
}
|
||||||
|
|
||||||
$db = FronkDB::singleton();
|
$db = FronkDB::singleton();
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ class VoiceplandestinationModel {
|
|||||||
WHERE $where
|
WHERE $where
|
||||||
ORDER BY destination,prefix LIMIT 1
|
ORDER BY destination,prefix LIMIT 1
|
||||||
";
|
";
|
||||||
mfLoghandler::singleton()->debug($sql);
|
//mfLoghandler::singleton()->debug($sql);
|
||||||
$res = $db->query($sql);
|
$res = $db->query($sql);
|
||||||
//$res = $db->select("Voiceplandestination", "*", "$where ORDER BY destination,prefix");
|
//$res = $db->select("Voiceplandestination", "*", "$where ORDER BY destination,prefix");
|
||||||
if($db->num_rows($res)) {
|
if($db->num_rows($res)) {
|
||||||
@@ -114,7 +114,7 @@ class VoiceplandestinationModel {
|
|||||||
|
|
||||||
$res = $db->query($sql);
|
$res = $db->query($sql);
|
||||||
|
|
||||||
mfLoghandler::singleton()->debug($sql);
|
//mfLoghandler::singleton()->debug($sql);
|
||||||
|
|
||||||
if($db->num_rows($res)) {
|
if($db->num_rows($res)) {
|
||||||
while($data = $db->fetch_object($res)) {
|
while($data = $db->fetch_object($res)) {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ final class CreateInvoiceTables extends AbstractMigration
|
|||||||
|
|
||||||
$invoice->addColumn("invoice_number", "string", ["null" => true, "default" => null]); // RN2024-X000001
|
$invoice->addColumn("invoice_number", "string", ["null" => true, "default" => null]); // RN2024-X000001
|
||||||
$invoice->addColumn("invoice_date", "integer", ["default" => 0]);
|
$invoice->addColumn("invoice_date", "integer", ["default" => 0]);
|
||||||
|
$invoice->addColumn("owner_id", "integer", ["null" => false]);
|
||||||
$invoice->addColumn("billingaddress_id", "integer", ["null" => false]);
|
$invoice->addColumn("billingaddress_id", "integer", ["null" => false]);
|
||||||
$invoice->addColumn("customer_number", "integer", ["null" => false]);
|
$invoice->addColumn("customer_number", "integer", ["null" => false]);
|
||||||
$invoice->addColumn("company", "string", ["null" => true, "default" => null, "length" => 1024]);
|
$invoice->addColumn("company", "string", ["null" => true, "default" => null, "length" => 1024]);
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Phinx\Migration\AbstractMigration;
|
||||||
|
|
||||||
|
final class CreateInvoiceVoicenumberTables extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
if($this->getEnvironment() == "thetool") {
|
||||||
|
$iv = $this->table("InvoiceVoicenumber");
|
||||||
|
$iv->addColumn("invoice_id", "integer", ["null" => false]);
|
||||||
|
$iv->addColumn("voicenumber", "string", ["null" => false, "length" => 64]);
|
||||||
|
$iv->addColumn("start_date", "date", ["null" => false]);
|
||||||
|
$iv->addColumn("end_date", "date", ["null" => false]);
|
||||||
|
$iv->addColumn("voiceplan", "string", ["null" => false, "length" => 64]);
|
||||||
|
$iv->addColumn("increment", "integer", ["null" => false]);
|
||||||
|
$iv->addColumn("increment_first", "integer", ["null" => false]);
|
||||||
|
|
||||||
|
$iv->addColumn("create_by", "integer", ["null" => false]);
|
||||||
|
$iv->addColumn("edit_by", "integer", ["null" => false]);
|
||||||
|
$iv->addColumn("create", "integer", ["null" => false]);
|
||||||
|
$iv->addColumn("edit", "integer", ["null" => false]);
|
||||||
|
|
||||||
|
$iv->create();
|
||||||
|
|
||||||
|
$ivz = $this->table("InvoiceVoicenumberZone");
|
||||||
|
$ivz->addColumn("invoicevoicenumber_id", "integer", ["null" => false]);
|
||||||
|
$ivz->addColumn("zone", "string", ["null" => false, "length" => 64]);
|
||||||
|
$ivz->addColumn("call_count", "integer", ["null" => false]);
|
||||||
|
$ivz->addColumn("duration", "integer", ["null" => false]);
|
||||||
|
$ivz->addColumn("price", "decimal", ["null" => false, "precision" => 14, "scale" => 8]);
|
||||||
|
$ivz->addColumn("price_total", "decimal", ["null" => false, "precision" => 14, "scale" => 4]);
|
||||||
|
$ivz->addColumn("price_total_gross", "decimal", ["null" => false, "precision" => 14, "scale" => 4]);
|
||||||
|
$ivz->addColumn("vatrate", "decimal", ["null" => false, "default" => 0, "precision" => 6, "scale" => 2]);
|
||||||
|
|
||||||
|
|
||||||
|
$ivz->addColumn("create_by", "integer", ["null" => false]);
|
||||||
|
$ivz->addColumn("edit_by", "integer", ["null" => false]);
|
||||||
|
$ivz->addColumn("create", "integer", ["null" => false]);
|
||||||
|
$ivz->addColumn("edit", "integer", ["null" => false]);
|
||||||
|
|
||||||
|
$ivz->create();
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->getEnvironment() == "addressdb") {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
if($this->getEnvironment() == "thetool") {
|
||||||
|
$this->table("InvoiceVoicenumberZone")->drop()->save();
|
||||||
|
$this->table("InvoiceVoicenumber")->drop()->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->getEnvironment() == "addressdb") {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
31
db/migrations/20240706192917_invoiceposition_add_options.php
Normal file
31
db/migrations/20240706192917_invoiceposition_add_options.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Phinx\Migration\AbstractMigration;
|
||||||
|
|
||||||
|
final class InvoicepositionAddOptions extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
if($this->getEnvironment() == "thetool") {
|
||||||
|
$table = $this->table("Invoiceposition");
|
||||||
|
$table->addColumn("options", "json", ["null" => true, "default" => null, "after" => "billing_period"]);
|
||||||
|
$table->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->getEnvironment() == "addressdb") {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
if($this->getEnvironment() == "thetool") {
|
||||||
|
$this->table("Invoiceposition")->removeColumn("options")->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->getEnvironment() == "addressdb") {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -198,6 +198,10 @@ class mfLayout {
|
|||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getHumanReadableInterval($seconds) {
|
||||||
|
return sprintf("%02d:%02d:%02d", floor($seconds / 3600), ($seconds / 60) % 60, $seconds % 60);
|
||||||
|
}
|
||||||
|
|
||||||
public static function getResourcePath() {
|
public static function getResourcePath() {
|
||||||
if (MFUSEFANCYURLS) {
|
if (MFUSEFANCYURLS) {
|
||||||
$path = MFFANCYBASEURL;
|
$path = MFFANCYBASEURL;
|
||||||
|
|||||||
Reference in New Issue
Block a user