diff --git a/Layout/default/Billing/Index.php b/Layout/default/Billing/Index.php index c1591b1cc..f2dffa09d 100644 --- a/Layout/default/Billing/Index.php +++ b/Layout/default/Billing/Index.php @@ -135,6 +135,12 @@ $pagination_entity_name = "Billingrecords"; Summe Gutschriften Einmalig: € + + + + + Summe Rechnungen Bankeinzug: + € diff --git a/Layout/default/Contract/Form.php b/Layout/default/Contract/Form.php index f881cada9..84122d8fb 100644 --- a/Layout/default/Contract/Form.php +++ b/Layout/default/Contract/Form.php @@ -386,7 +386,7 @@ * billingaddress autocomplete */ billingaddress_id && is_object($contract->billingaddress)): ?> - $('#billingaddress_id').autoComplete('set', { value: billingaddress_id?>, text: '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: billingaddress_id?>, text: '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."]" : "") : ""?>'}); $('#billingaddress_id').autoComplete(); diff --git a/Layout/default/Invoice/Index.php b/Layout/default/Invoice/Index.php index 03876d014..334b80469 100644 --- a/Layout/default/Invoice/Index.php +++ b/Layout/default/Invoice/Index.php @@ -52,6 +52,14 @@ $pagination_entity_name = "Rechnungen"; "/> +
+ + "/> +
+
+ + "/> +
@@ -140,7 +148,10 @@ $pagination_entity_name = "Rechnungen"; $invoice->id])?>"> invoice_number?> pdf): ?> - + + + date_delivered): ?> + date_delivered)?>"> invoice_date)?> @@ -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 + }); \ No newline at end of file diff --git a/application/Billing/BillingController.php b/application/Billing/BillingController.php index 06b1615b4..4381c92fb 100644 --- a/application/Billing/BillingController.php +++ b/application/Billing/BillingController.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!"); + } } } } diff --git a/application/Contract/ContractModel.php b/application/Contract/ContractModel.php index a59b6d8ba..a35908560 100644 --- a/application/Contract/ContractModel.php +++ b/application/Contract/ContractModel.php @@ -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; diff --git a/application/Invoice/InvoiceController.php b/application/Invoice/InvoiceController.php index 8712c53a7..c0836d3af 100644 --- a/application/Invoice/InvoiceController.php +++ b/application/Invoice/InvoiceController.php @@ -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();