More changes to Billing and Invoice
This commit is contained in:
@@ -135,6 +135,12 @@ $pagination_entity_name = "Billingrecords";
|
||||
</tr><tr>
|
||||
<th class="text-right">Summe Gutschriften Einmalig:</th>
|
||||
<td>€ <?=number_format($sum_credit_price_setup, 2, ",", ".")?></td>
|
||||
</tr><tr>
|
||||
<th></th>
|
||||
<td></td>
|
||||
</tr><tr>
|
||||
<th class="text-right">Summe Rechnungen Bankeinzug:</th>
|
||||
<td>€ <?=number_format($sum_price_sepa, 2, ",", ".")?></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
@@ -386,7 +386,7 @@
|
||||
* billingaddress autocomplete
|
||||
*/
|
||||
<?php if($contract->billingaddress_id && is_object($contract->billingaddress)): ?>
|
||||
$('#billingaddress_id').autoComplete('set', { value: <?=$contract->billingaddress_id?>, text: '<?=($contract->billingaddress_id) ? str_replace("'", "\\'", str_replace(["\n", "\r"], " ", $contract->billingaddress->getCompanyOrName()))." (".$contract->billingaddress->zip." ".$contract->billingaddress->city.", ".$contract->billingaddress->street.")".(($contract->owner->customer_number) ? " [".$contract->owner->customer_number."]" : "") : ""?>'});
|
||||
$('#billingaddress_id').autoComplete('set', { value: <?=$contract->billingaddress_id?>, text: '<?=($contract->billingaddress_id) ? str_replace("'", "\\'", str_replace(["\n", "\r"], " ", $contract->billingaddress->getCompanyOrName()))." (".$contract->billingaddress->zip." ".$contract->billingaddress->city.", ".$contract->billingaddress->street.")".(($contract->billingaddress->customer_number) ? " [".$contract->billingaddress->customer_number."]" : "") : ""?>'});
|
||||
<?php else: ?>
|
||||
$('#billingaddress_id').autoComplete();
|
||||
<?php endif; ?>
|
||||
|
||||
@@ -52,6 +52,14 @@ $pagination_entity_name = "Rechnungen";
|
||||
<label class="form-label" for="filter_address">Adresse</label>
|
||||
<input type="text" class="form-control" name="filter[address]" id="filter_address" value="<?=(array_key_exists("address", $filter)) ? $filter['address'] : ""?>"/>
|
||||
</div>
|
||||
<div class="col-2">
|
||||
<label class="form-label" for="filter_invoice_date_from">Rechnungsdatum von</label>
|
||||
<input type="text" class="form-control" name="filter[invoice_date_from]" id="filter_invoice_date_from" value="<?=(array_key_exists("invoice_date_from", $filter)) ? $filter['invoice_date_from'] : ""?>"/>
|
||||
</div>
|
||||
<div class="col-2">
|
||||
<label class="form-label" for="filter_invoice_date_to">Rechnungsdatum bis</label>
|
||||
<input type="text" class="form-control" name="filter[invoice_date_to]" id="filter_invoice_date_to" value="<?=(array_key_exists("invoice_date_to", $filter)) ? $filter['invoice_date_to'] : ""?>"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-2">
|
||||
<div class="col">
|
||||
@@ -140,7 +148,10 @@ $pagination_entity_name = "Rechnungen";
|
||||
<td>
|
||||
<a href="<?=self::getUrl("Invoice", "downloadInvoice", ["id" => $invoice->id])?>"><i class="fas fa-download fa-fw"></i> <?=$invoice->invoice_number?></a>
|
||||
<?php if($invoice->pdf): ?>
|
||||
<i class="fas fa-fw fa-check"></i>
|
||||
<i class="fas fa-fw fa-check" title="PDF generiert"></i>
|
||||
<?php endif; ?>
|
||||
<?php if($invoice->date_delivered): ?>
|
||||
<i class="fas fa-fw fa-mail" title="per Email versendet am <?=date("d.m.Y H:i", $invoice->date_delivered)?>"></i>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td><?=date("d.m.Y", $invoice->invoice_date)?></td>
|
||||
@@ -197,6 +208,23 @@ $pagination_entity_name = "Rechnungen";
|
||||
todayBtn: 'linked',
|
||||
autoclose: true
|
||||
});
|
||||
|
||||
$('#filter_invoice_date_from').datepicker({
|
||||
orientation: "bottom",
|
||||
language: 'de',
|
||||
format: "dd.mm.yyyy",
|
||||
showWeekDays: true,
|
||||
todayBtn: 'linked',
|
||||
autoclose: true
|
||||
});
|
||||
$('#filter_invoice_date_to').datepicker({
|
||||
orientation: "bottom",
|
||||
language: 'de',
|
||||
format: "dd.mm.yyyy",
|
||||
showWeekDays: true,
|
||||
todayBtn: 'linked',
|
||||
autoclose: true
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php include(realpath(dirname(__FILE__) . "/../../$mfLayoutPackage") . "/footer.php"); ?>
|
||||
@@ -54,11 +54,15 @@ class BillingController extends mfBaseController {
|
||||
// summen berechnen
|
||||
$sum_price = BillingModel::getSumPrice($filter);
|
||||
$sum_price_setup = BillingModel::getSumPriceSetup($filter);
|
||||
$sum_price_sepa = BillingModel::getSumPrice(array_merge($filter, ["billing_type" => "sepa"])) + BillingModel::getSumPriceSetup(array_merge($filter, ["billing_type" => "sepa"]));
|
||||
|
||||
|
||||
$sum_credit_price = BillingModel::getSumCreditPrice($filter);
|
||||
$sum_credit_price_setup = BillingModel::getSumCreditPriceSetup($filter);
|
||||
|
||||
$this->layout()->set("sum_price", $sum_price);
|
||||
$this->layout()->set("sum_price_setup", $sum_price_setup);
|
||||
$this->layout()->set("sum_price_sepa", $sum_price_sepa);
|
||||
$this->layout()->set("sum_credit_price", $sum_credit_price);
|
||||
$this->layout()->set("sum_credit_price_setup", $sum_credit_price_setup);
|
||||
|
||||
@@ -155,9 +159,10 @@ class BillingController extends mfBaseController {
|
||||
$now_month = date("m");
|
||||
$now_day = date("d");
|
||||
|
||||
$now_year = 2024;
|
||||
$now_month = 7;
|
||||
$now_day = 10; // XXX for debugging only, must be removed
|
||||
// for debugging to bill a specific month
|
||||
//$now_year = 2024;
|
||||
//$now_month = 7;
|
||||
//$now_day = 10;
|
||||
|
||||
// XXX only for 1st Billing after IVT Import
|
||||
// Locking to July 2024 and keeping it for now
|
||||
@@ -488,6 +493,16 @@ class BillingController extends mfBaseController {
|
||||
$sepa_date = new DateTime("@".$billingaddress->sepa_date);
|
||||
$sepa_date->setTimezone(new DateTimeZone("Europe/Vienna"));
|
||||
$data["sepa_date"] = $sepa_date->format("Y-m-d");
|
||||
} else {
|
||||
if($contract->order_date) {
|
||||
$order_date = new DateTime("@".$contract->order_date);
|
||||
} else {
|
||||
$order_date = new DateTime("now");
|
||||
}
|
||||
|
||||
$data["sepa_date"] = $order_date->format("Y-m-d");
|
||||
$billingaddress->sepa_date = $order_date->getTimestamp();
|
||||
$billingaddress->save();
|
||||
}
|
||||
|
||||
if($billingaddress->last_invoice_date) {
|
||||
@@ -553,11 +568,11 @@ class BillingController extends mfBaseController {
|
||||
}
|
||||
|
||||
foreach ($voicenumbers as $voicenumber) {
|
||||
$vbill = BillingVoicenumberModel::getFirst(["contract_id" => $contract->id, "voicenumber" => $voicenumber->number, "start_date" => $voice_start_date->format("Y-m-d")]);
|
||||
/*$vbill = BillingVoicenumberModel::getFirst(["contract_id" => $contract->id, "voicenumber" => $voicenumber->number, "start_date" => $voice_start_date->format("Y-m-d")]);
|
||||
if ($vbill) {
|
||||
//var_dump($vbill);exit;
|
||||
continue; // number was already billed in this period
|
||||
}
|
||||
}*/
|
||||
|
||||
// check for unbilled call records in earlier months
|
||||
$call_dates = [];
|
||||
@@ -567,7 +582,7 @@ class BillingController extends mfBaseController {
|
||||
do {
|
||||
$earlier_voice_start_date->modify("-1 month");
|
||||
// not before first billing in thetool
|
||||
if($earlier_voice_start_date->format("Y-m-d") < "2024-07-01") break;
|
||||
if($earlier_voice_start_date->format("Y-m-d") < "2024-06-01") break;
|
||||
|
||||
$earlier_voice_end_date = clone $earlier_voice_start_date;
|
||||
$earlier_voice_end_date->modify("last day of this month");
|
||||
@@ -591,11 +606,15 @@ class BillingController extends mfBaseController {
|
||||
"end_date" => clone $voice_end_date,
|
||||
];
|
||||
|
||||
if(count($call_dates) > 1) {
|
||||
var_dump($call_dates);exit;
|
||||
}
|
||||
|
||||
foreach ($call_dates as $call_date) {
|
||||
$call_date_start = $call_date["start_date"]->format("Y-m-d");
|
||||
$call_date_end = $call_date["end_date"]->format("Y-m-d");
|
||||
|
||||
$test_bill = BillingVoicenumberModel::getFirst(["contract_id" => $contract->id, "voicenumber" => $voicenumber->number, "start_date" => $call_date_start]);
|
||||
if ($test_bill) {
|
||||
continue; // number was already billed in this period
|
||||
}
|
||||
|
||||
$calls = VoiceCallHistoryModel::getVoiceCallHistoryAsEntity(["contract_id" => $contract->id, "voice_account" => $voicenumber->number, "start" => ["from" => $call_date["start_date"]->getTimestamp(), "to" => $call_date["end_date"]->getTimestamp()]]);
|
||||
foreach ($calls as $call) {
|
||||
//var_dump($call);
|
||||
@@ -651,8 +670,12 @@ class BillingController extends mfBaseController {
|
||||
if (!array_key_exists($number, $voicebills)) {
|
||||
$voicebills[$number] = [];
|
||||
}
|
||||
if (!array_key_exists($zone->id, $voicebills[$number])) {
|
||||
$voicebills[$number][$zone->id] = [
|
||||
|
||||
if (!array_key_exists($call_date_start, $voicebills[$number])) {
|
||||
$voicebills[$number][$call_date_start] = [];
|
||||
}
|
||||
if (!array_key_exists($zone->id, $voicebills[$number][$call_date_start])) {
|
||||
$voicebills[$number][$call_date_start][$zone->id] = [
|
||||
"zone_name" => $zone->name,
|
||||
"voiceplan" => $voiceplan->name,
|
||||
"duration" => 0,
|
||||
@@ -666,9 +689,9 @@ class BillingController extends mfBaseController {
|
||||
];
|
||||
}
|
||||
|
||||
$voicebills[$number][$zone->id]["count"]++;
|
||||
$voicebills[$number][$zone->id]["zone_total"] += $call_price;
|
||||
$voicebills[$number][$zone->id]["duration"] += $call->duration;
|
||||
$voicebills[$number][$call_date_start][$zone->id]["count"]++;
|
||||
$voicebills[$number][$call_date_start][$zone->id]["zone_total"] += $call_price;
|
||||
$voicebills[$number][$call_date_start][$zone->id]["duration"] += $call->duration;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -676,26 +699,28 @@ class BillingController extends mfBaseController {
|
||||
// save to BillingVoicenumber
|
||||
foreach($voicebills as $vbnumber => $zones) {
|
||||
|
||||
foreach($zones as $zone_id => $vb) {
|
||||
$vbdata = [];
|
||||
$vbdata["billing_id"] = $billing->id;
|
||||
$vbdata["contract_id"] = $contract->id;
|
||||
$vbdata["voicenumber"] = $vbnumber;
|
||||
$vbdata["start_date"] = $vb["start_date"];
|
||||
$vbdata["end_date"] = $vb["end_date"];
|
||||
$vbdata["voiceplan"] = $vb["voiceplan"];
|
||||
$vbdata["zone"] = $vb["zone_name"];
|
||||
$vbdata["call_count"] = $vb["count"];
|
||||
$vbdata["duration"] = $vb["duration"];
|
||||
$vbdata["price"] = $vb["price"];
|
||||
$vbdata["price_total"] = $vb["zone_total"];
|
||||
$vbdata["increment"] = $vb["increment"];
|
||||
$vbdata["increment_first"] = $vb["increment_first"];
|
||||
foreach($zones as $zone_id => $zone) {
|
||||
foreach($zone as $zone_start_date => $vb) {
|
||||
$vbdata = [];
|
||||
$vbdata["billing_id"] = $billing->id;
|
||||
$vbdata["contract_id"] = $contract->id;
|
||||
$vbdata["voicenumber"] = $vbnumber;
|
||||
$vbdata["start_date"] = $vb["start_date"];
|
||||
$vbdata["end_date"] = $vb["end_date"];
|
||||
$vbdata["voiceplan"] = $vb["voiceplan"];
|
||||
$vbdata["zone"] = $vb["zone_name"];
|
||||
$vbdata["call_count"] = $vb["count"];
|
||||
$vbdata["duration"] = $vb["duration"];
|
||||
$vbdata["price"] = $vb["price"];
|
||||
$vbdata["price_total"] = $vb["zone_total"];
|
||||
$vbdata["increment"] = $vb["increment"];
|
||||
$vbdata["increment_first"] = $vb["increment_first"];
|
||||
|
||||
$bill_voice = BillingVoicenumberModel::create($vbdata);
|
||||
if(!$bill_voice->save()) {
|
||||
var_dump($vbdata);
|
||||
die("Error saving Billing Voicenumber!");
|
||||
$bill_voice = BillingVoicenumberModel::create($vbdata);
|
||||
if(!$bill_voice->save()) {
|
||||
var_dump($vbdata);
|
||||
die("Error saving Billing Voicenumber!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ class ContractModel {
|
||||
$data = [];
|
||||
$data["orderproduct_id"] = null;
|
||||
$data["owner_id"] = $crediting_partner_id;
|
||||
$data["billingaddress_id"] = null;
|
||||
$data["billingaddress_id"] = $crediting_partner_id;
|
||||
$data["termination_id"] = null;
|
||||
$data["product_id"] = $contract->product_id;
|
||||
$data["product_name"] = $contract->product_name;
|
||||
|
||||
@@ -78,6 +78,22 @@ class InvoiceController extends mfBaseController {
|
||||
unset($filter["invoice_number"]);
|
||||
}
|
||||
|
||||
if(array_key_exists("invoice_date_from", $filter)) {
|
||||
if($filter["invoice_date_from"]) {
|
||||
$from = Layout::dateToInt($filter["invoice_date_from"]);
|
||||
$new_filter["invoice_date>="] = $from;
|
||||
}
|
||||
unset($filter["invoice_date_from"]);
|
||||
}
|
||||
|
||||
if(array_key_exists("invoice_date_to", $filter)) {
|
||||
if($filter["invoice_date_to"]) {
|
||||
$to = Layout::dateToInt($filter["invoice_date_to"]);
|
||||
$new_filter["invoice_date<="] = $to;
|
||||
}
|
||||
unset($filter["invoice_date_to"]);
|
||||
}
|
||||
|
||||
if (is_array($filter) && count($filter)) {
|
||||
foreach ($filter as $name => $value) {
|
||||
$new_filter[$name] = $value;
|
||||
@@ -220,7 +236,7 @@ class InvoiceController extends mfBaseController {
|
||||
$price_setup_total = $bill->price_setup * $bill->amount;
|
||||
$price_setup_gross = ($vatrate) ? $price_setup_total + ($price_setup_total / 100) * $vatrate : $price_setup_total;
|
||||
$add_setup_position = ($price > 0 && $price_setup > 0);
|
||||
$is_setup_only = ($price < 0.00001 && $price_setup > 0);
|
||||
$is_setup_only = ($price < 0.00001 && ($price_setup > 0.00001 || $price_setup < -0.00001));
|
||||
|
||||
$price_total_sum += $price_gross + $price_setup_gross;
|
||||
|
||||
@@ -531,12 +547,12 @@ class InvoiceController extends mfBaseController {
|
||||
die("Error saving Invoice number and date");
|
||||
}
|
||||
|
||||
/*
|
||||
$address = new Address($invoice->billingaddress_id);
|
||||
if($address) {
|
||||
$address->last_invoice_date = date("U");
|
||||
$address->save();
|
||||
}*/
|
||||
|
||||
$baddress = new Address($invoice->billingaddress_id);
|
||||
if($baddress) {
|
||||
$baddress->last_invoice_date = date("U");
|
||||
$baddress->save();
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
if ($invoice) {
|
||||
$invoice->rollbackTransaction();
|
||||
|
||||
Reference in New Issue
Block a user