Preorder Billing Marketshare Price + RML layout tweaks
This commit is contained in:
@@ -46,7 +46,7 @@ $pagination_entity_name = "Rechnungen";
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-1">
|
<div class="col-1">
|
||||||
<label class="form-label" for="filter_fibu_account_number">Fibu Kontonummer</label>
|
<label class="form-label" for="filter_fibu_account_number">Kundennummer</label>
|
||||||
<input type="text" class="form-control" name="filter[fibu_account_number]" id="filter_fibu_account_number" value="<?=(array_key_exists("fibu_account_number", $filter)) ? $filter['fibu_account_number'] : ""?>"/>
|
<input type="text" class="form-control" name="filter[fibu_account_number]" id="filter_fibu_account_number" value="<?=(array_key_exists("fibu_account_number", $filter)) ? $filter['fibu_account_number'] : ""?>"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -109,6 +109,7 @@ $pagination_entity_name = "Rechnungen";
|
|||||||
<th>Rechnungsdatum</th>
|
<th>Rechnungsdatum</th>
|
||||||
<th>Kundennummer</th>
|
<th>Kundennummer</th>
|
||||||
<th>Rechnungsadresse</th>
|
<th>Rechnungsadresse</th>
|
||||||
|
<th>Text</th>
|
||||||
<th>Netto</th>
|
<th>Netto</th>
|
||||||
<th>Ust.</th>
|
<th>Ust.</th>
|
||||||
<th>Brutto</th>
|
<th>Brutto</th>
|
||||||
@@ -136,6 +137,7 @@ $pagination_entity_name = "Rechnungen";
|
|||||||
<?=$invoice->zip?> <?=$invoice->city?>
|
<?=$invoice->zip?> <?=$invoice->city?>
|
||||||
<?=($invoice->country != "Österreich") ? "<br >".$invoice->country : ""?>
|
<?=($invoice->country != "Österreich") ? "<br >".$invoice->country : ""?>
|
||||||
</td>
|
</td>
|
||||||
|
<td><?=$invoice->head_text?></td>
|
||||||
<td>€ <?=number_format($invoice->total, 2, ",", ".")?></td>
|
<td>€ <?=number_format($invoice->total, 2, ",", ".")?></td>
|
||||||
<td>€ <?=number_format($invoice->total_gross - $invoice->total, 2, ",", ".")?></td>
|
<td>€ <?=number_format($invoice->total_gross - $invoice->total, 2, ",", ".")?></td>
|
||||||
<td>€ <?=number_format($invoice->total_gross, 2, ",", ".")?></td>
|
<td>€ <?=number_format($invoice->total_gross, 2, ",", ".")?></td>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 360px;
|
top: 290px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border: 0;
|
border: 0;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
@@ -102,22 +102,6 @@
|
|||||||
<td>{{ customerNumber }}</td>
|
<td>{{ customerNumber }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{ vatHtml }}
|
{{ vatHtml }}
|
||||||
<tr>
|
|
||||||
<th style="padding-top: 8px;">Sachbearbeiter:</th>
|
|
||||||
<td style="padding-top: 8px;">{{ caseWorker }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th>Telefon:</th>
|
|
||||||
<td>{{ caseWorkerPhone }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th>Email:</th>
|
|
||||||
<td>{{ caseWorkerEmail }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th>Unsere Auftragsnummer:</th>
|
|
||||||
<td>{{ orderNumber }}</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
</table>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -86,12 +86,15 @@ $this->setReturnValue(['filename' => $invoice->invoice_number . ".pdf"]);
|
|||||||
|
|
||||||
<h2><?=($is_credit) ? "Gutschrift" : "Rechnung"?> <?=$invoice->invoice_number?></h2>
|
<h2><?=($is_credit) ? "Gutschrift" : "Rechnung"?> <?=$invoice->invoice_number?></h2>
|
||||||
|
|
||||||
|
<?php if($invoice->head_text):?>
|
||||||
|
<p><?=$invoice->head_text?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
<table style="border-collapse: collapse; width: 100%;" id="invoiceTable">
|
<table style="border-collapse: collapse; width: 100%;" id="invoiceTable">
|
||||||
<tr style="font-weight: bold; border-bottom: 1px solid black;" class="uneven">
|
<tr style="font-weight: bold; border-bottom: 1px solid black;" class="uneven">
|
||||||
<th style="text-align: left">Pos</th>
|
<th style="text-align: left">Pos</th>
|
||||||
<th style="text-align: left">Artikel</th>
|
<th style="text-align: left">Artikel</th>
|
||||||
<th style="text-align: left">Leistung / Produkt</th>
|
<th style="text-align: left">Leistung / Produkt</th>
|
||||||
<th style="text-align: right">Preis</th>
|
|
||||||
<th style="text-align: right">Menge</th>
|
<th style="text-align: right">Menge</th>
|
||||||
<th style="text-align: left">Einheit</th>
|
<th style="text-align: left">Einheit</th>
|
||||||
<th style="text-align: right">Preis €</th>
|
<th style="text-align: right">Preis €</th>
|
||||||
@@ -112,7 +115,6 @@ $this->setReturnValue(['filename' => $invoice->invoice_number . ".pdf"]);
|
|||||||
<td style="text-align: left"><?=$i+1?></td>
|
<td style="text-align: left"><?=$i+1?></td>
|
||||||
<td style="text-align: left"><?=$p->article_number?></td>
|
<td style="text-align: left"><?=$p->article_number?></td>
|
||||||
<td style="text-align: left"><?=$p->article_name?></td>
|
<td style="text-align: left"><?=$p->article_name?></td>
|
||||||
<td style="text-align: right"><?=$price?> €</td>
|
|
||||||
<td style="text-align: right"><?=$amount?></td>
|
<td style="text-align: right"><?=$amount?></td>
|
||||||
<td style="text-align: left"><?=$p->unit?></td>
|
<td style="text-align: left"><?=$p->unit?></td>
|
||||||
<td style="text-align: right"><?=$price?> €</td>
|
<td style="text-align: right"><?=$price?> €</td>
|
||||||
@@ -146,13 +148,14 @@ $this->setReturnValue(['filename' => $invoice->invoice_number . ".pdf"]);
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|
||||||
<div style="margin-top: 20pt;">
|
<div style="margin-top: 20pt;">
|
||||||
<?php if($invoice->tax_text): ?>
|
<?php if($invoice->tax_text): ?>
|
||||||
<p style="font-weight: bold;"><?=$invoice->tax_text?></p>
|
<p style="font-weight: bold;"><?=$invoice->tax_text?></p>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
|
||||||
|
|
||||||
|
Zahlungsziel 14 Tage.
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -108,11 +108,13 @@ class PreorderBilling extends mfBaseModel {
|
|||||||
$items = [];
|
$items = [];
|
||||||
|
|
||||||
$where = self::getSqlFilter($filter);
|
$where = self::getSqlFilter($filter);
|
||||||
$sql = "SELECT preorderbillingcustomer_id, owner_id, billingaddress_id, billing_delivery FROM PreorderBilling
|
$sql = "SELECT preorderbillingcustomer_id, owner_id, billingaddress_id, Preorder.preordercampaign_id as campaign_id, billing_delivery FROM PreorderBilling
|
||||||
|
LEFT JOIN Preorder ON (PreorderBilling.preorder_id = Preorder.id)
|
||||||
WHERE $where
|
WHERE $where
|
||||||
GROUP BY preorderbillingcustomer_id, owner_id, billingaddress_id, billing_delivery
|
GROUP BY preorderbillingcustomer_id, owner_id, billingaddress_id, campaign_id, billing_delivery
|
||||||
ORDER BY preorderbillingcustomer_id, owner_id, billingaddress_id, billing_delivery";
|
ORDER BY preorderbillingcustomer_id, owner_id, billingaddress_id, campaign_id, billing_delivery";
|
||||||
//var_dump($sql);exit;
|
//var_dump($sql);exit;
|
||||||
|
mfLoghandler::singleton()->debug($sql);
|
||||||
$res = $db->query($sql);
|
$res = $db->query($sql);
|
||||||
if($db->num_rows($res)) {
|
if($db->num_rows($res)) {
|
||||||
while($data = $db->fetch_object($res)) {
|
while($data = $db->fetch_object($res)) {
|
||||||
@@ -120,6 +122,7 @@ class PreorderBilling extends mfBaseModel {
|
|||||||
"preorderbillingcustomer_id" => $data->preorderbillingcustomer_id,
|
"preorderbillingcustomer_id" => $data->preorderbillingcustomer_id,
|
||||||
"owner_id" => $data->owner_id,
|
"owner_id" => $data->owner_id,
|
||||||
"billingaddress_id" => $data->billingaddress_id,
|
"billingaddress_id" => $data->billingaddress_id,
|
||||||
|
"campaign_id" => $data->campaign_id,
|
||||||
"billing_delivery" => $data->billing_delivery,
|
"billing_delivery" => $data->billing_delivery,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -448,6 +451,13 @@ class PreorderBilling extends mfBaseModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(array_key_exists("campaign_id", $filter)) {
|
||||||
|
$campaign_id = $filter['campaign_id'];
|
||||||
|
if(is_numeric($campaign_id)) {
|
||||||
|
$where .= " AND Preorder.campaign_id = $campaign_id";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(array_key_exists("preordercampaign_id", $filter)) {
|
if(array_key_exists("preordercampaign_id", $filter)) {
|
||||||
$preordercampaign_id = $filter['preordercampaign_id'];
|
$preordercampaign_id = $filter['preordercampaign_id'];
|
||||||
if(is_numeric($preordercampaign_id)) {
|
if(is_numeric($preordercampaign_id)) {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class PreorderBillingController extends mfBaseController {
|
class PreorderBillingController extends mfBaseController {
|
||||||
|
|
||||||
private $billing_minimum_date = "2025-03-01";
|
private $billing_minimum_date = "2025-03-01";
|
||||||
|
private $marketshare = [];
|
||||||
|
|
||||||
protected function init() : void
|
protected function init() : void
|
||||||
{
|
{
|
||||||
@@ -133,6 +133,14 @@ class PreorderBillingController extends mfBaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function importPreorders() {
|
protected function importPreorders() {
|
||||||
|
$netowner_id = $this->me->address_id;
|
||||||
|
$netowner = new Address($netowner_id);
|
||||||
|
|
||||||
|
if(!defined("TT_PREORDER_BILLING") || !is_array(TT_PREORDER_BILLING)) {
|
||||||
|
die("Config Variable 'TT_PREORDER_BILLING' not found!");
|
||||||
|
}
|
||||||
|
$netowner_config = TT_PREORDER_BILLING[$netowner_id];
|
||||||
|
|
||||||
$earliest_bill_date = new DateTime(PreorderBilling::$earliest_bill_date);
|
$earliest_bill_date = new DateTime(PreorderBilling::$earliest_bill_date);
|
||||||
|
|
||||||
$now_year = date("Y");
|
$now_year = date("Y");
|
||||||
@@ -140,7 +148,7 @@ class PreorderBillingController extends mfBaseController {
|
|||||||
$now_day = date("d");
|
$now_day = date("d");
|
||||||
|
|
||||||
$today = new DateTime("$now_year-$now_month-$now_day");
|
$today = new DateTime("$now_year-$now_month-$now_day");
|
||||||
//$today = new DateTime("2025-02-13");
|
$today = new DateTime("2025-04-13");
|
||||||
$today->setTime(2,0,0);
|
$today->setTime(2,0,0);
|
||||||
$today->setTimezone(new DateTimeZone("Europe/Vienna"));
|
$today->setTimezone(new DateTimeZone("Europe/Vienna"));
|
||||||
|
|
||||||
@@ -151,6 +159,18 @@ class PreorderBillingController extends mfBaseController {
|
|||||||
$latest_bill_date = clone $bill_date;
|
$latest_bill_date = clone $bill_date;
|
||||||
$latest_bill_date->modify("last day of this month");
|
$latest_bill_date->modify("last day of this month");
|
||||||
|
|
||||||
|
$this_quarter_start = clone $today;
|
||||||
|
$this_quarter_start->modify("first day of this month");
|
||||||
|
$q_subtractor = ($this_quarter_start->format("m") - 1) % 3;
|
||||||
|
$this_quarter_start->modify("- $q_subtractor months");
|
||||||
|
|
||||||
|
$this_quarter_end = clone $this_quarter_start;
|
||||||
|
$this_quarter_end->modify("+ 3 months");
|
||||||
|
$this_quarter_end->modify("last day of this month");
|
||||||
|
|
||||||
|
$latest_quarter_bill_date = clone $this_quarter_start;
|
||||||
|
$latest_quarter_bill_date->modify("-1 day");
|
||||||
|
|
||||||
$del = 0;
|
$del = 0;
|
||||||
// first delete all non-invoiced billing records
|
// first delete all non-invoiced billing records
|
||||||
foreach(PreorderBilling::search(["invoice_id" => null]) as $bill) {
|
foreach(PreorderBilling::search(["invoice_id" => null]) as $bill) {
|
||||||
@@ -212,14 +232,22 @@ class PreorderBillingController extends mfBaseController {
|
|||||||
die("No netoperator found for preorder ".$preorder->id);
|
die("No netoperator found for preorder ".$preorder->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!is_array($netowner_config["netoperators"]) || !array_key_exists($netoperator->id, $netowner_config["netoperators"])) {
|
||||||
|
die("netoperator config missing for ".$netoperator->id);
|
||||||
|
}
|
||||||
|
$netoperator_config = $netowner_config["netoperators"][$netoperator->id];
|
||||||
|
|
||||||
$bill_params = [
|
$bill_params = [
|
||||||
"netowner" => new Address($this->me->address_id),
|
"netowner" => $netowner,
|
||||||
|
"netowner_config" => $netowner_config,
|
||||||
"netoperator" => $netoperator,
|
"netoperator" => $netoperator,
|
||||||
|
"netoperator_config" => $netoperator_config,
|
||||||
"order_date" => $order_date,
|
"order_date" => $order_date,
|
||||||
"today" => $today,
|
"today" => $today,
|
||||||
"bill_date" => $bill_date,
|
"bill_date" => $bill_date,
|
||||||
"earliest_bill_date" => $earliest_bill_date,
|
"earliest_bill_date" => $earliest_bill_date,
|
||||||
"latest_bill_date" => $latest_bill_date,
|
"latest_bill_date" => $latest_bill_date,
|
||||||
|
"latest_quarter_bill_date" => $latest_quarter_bill_date
|
||||||
];
|
];
|
||||||
|
|
||||||
if($preorder->status->code >= 241) {
|
if($preorder->status->code >= 241) {
|
||||||
@@ -232,6 +260,8 @@ class PreorderBillingController extends mfBaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//echo "<pre>".print_r($this->marketshare, true)."</pre>";exit;
|
||||||
|
|
||||||
$this->Layout()->setFlash("Billing records erstellt", "success");
|
$this->Layout()->setFlash("Billing records erstellt", "success");
|
||||||
$this->redirect("PreorderBilling");
|
$this->redirect("PreorderBilling");
|
||||||
|
|
||||||
@@ -239,11 +269,14 @@ class PreorderBillingController extends mfBaseController {
|
|||||||
|
|
||||||
private function billSetup($preorder, $type, $options) {
|
private function billSetup($preorder, $type, $options) {
|
||||||
$netowner = $options['netowner'];
|
$netowner = $options['netowner'];
|
||||||
|
$netowner_config = $options['netowner_config'];
|
||||||
$netoperator = $options['netoperator'];
|
$netoperator = $options['netoperator'];
|
||||||
|
$netoperator_config = $options['netoperator_config'];
|
||||||
$order_date = $options['order_date'];
|
$order_date = $options['order_date'];
|
||||||
$today = $options['today'];
|
$today = $options['today'];
|
||||||
$bill_date = $options['bill_date'];
|
$bill_date = $options['bill_date'];
|
||||||
$earliest_bill_date = $options['earliest_bill_date'];
|
$earliest_bill_date = $options['earliest_bill_date'];
|
||||||
|
$latest_quarter_bill_date = $options["latest_quarter_bill_date"];
|
||||||
|
|
||||||
$this->log->debug(__METHOD__.": bill $type Preorder ".$preorder->id);
|
$this->log->debug(__METHOD__.": bill $type Preorder ".$preorder->id);
|
||||||
|
|
||||||
@@ -296,10 +329,6 @@ class PreorderBillingController extends mfBaseController {
|
|||||||
$status_change_date = new DateTime("@".$preorder->create);
|
$status_change_date = new DateTime("@".$preorder->create);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($preorder->oaid == 'AT-8943-8392e815.001') {
|
|
||||||
//var_dump($status_change, $status_change_date);
|
|
||||||
}
|
|
||||||
|
|
||||||
$billing_data = [
|
$billing_data = [
|
||||||
"netowner_id" => $netowner->id,
|
"netowner_id" => $netowner->id,
|
||||||
"preorder_id" => $preorder->id,
|
"preorder_id" => $preorder->id,
|
||||||
@@ -373,8 +402,9 @@ class PreorderBillingController extends mfBaseController {
|
|||||||
$billing_data["end_date"] = $status_change_date->format("Y-m-d");
|
$billing_data["end_date"] = $status_change_date->format("Y-m-d");
|
||||||
}
|
}
|
||||||
|
|
||||||
if($preorder->oaid == 'AT-8943-8392e815.001') {
|
if($netoperator_config["billing-period"] == "quarterly" && $status_change_date->format("Ymd") > $latest_quarter_bill_date->format("Ymd")) {
|
||||||
//var_dump($change_to_active, $status_change_date);exit;
|
$this->log->debug(__METHOD__.": Skipping operator_setup for preorder ".$preorder->id." because Billing date ".$status_change_date->format("Y-m-d")." is after latest_quarter_bill_date ".$latest_quarter_bill_date->format("Y-m-d"));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Netzbetreiber Setup Gebühr
|
// Netzbetreiber Setup Gebühr
|
||||||
@@ -407,12 +437,30 @@ class PreorderBillingController extends mfBaseController {
|
|||||||
|
|
||||||
private function billOperatorPeriodic($preorder, $options) {
|
private function billOperatorPeriodic($preorder, $options) {
|
||||||
$netowner = $options['netowner'];
|
$netowner = $options['netowner'];
|
||||||
|
$netowner_config = $options['netowner_config'];
|
||||||
$netoperator = $options['netoperator'];
|
$netoperator = $options['netoperator'];
|
||||||
|
$netoperator_config = $options['netoperator_config'];
|
||||||
$order_date = $options['order_date'];
|
$order_date = $options['order_date'];
|
||||||
$today = $options['today'];
|
$today = $options['today'];
|
||||||
$bill_date = $options['bill_date'];
|
$bill_date = $options['bill_date'];
|
||||||
$earliest_bill_date = $options['earliest_bill_date'];
|
$earliest_bill_date = $options['earliest_bill_date'];
|
||||||
$latest_bill_date = $options['latest_bill_date'];
|
$latest_quarter_bill_date = $options["latest_quarter_bill_date"];
|
||||||
|
|
||||||
|
$campaign = new PreorderCampaign($preorder->preordercampaign_id);
|
||||||
|
if(!$campaign) {
|
||||||
|
die("Campaign ".$preorder->preordercampaign_id." not found!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!array_key_exists($campaign->id, $this->marketshare)) {
|
||||||
|
$this->marketshare[$campaign->id] = [];
|
||||||
|
$this->marketshare[$campaign->id]["max"] = $campaign->getUnitCount();
|
||||||
|
$this->marketshare[$campaign->id]["netops"] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!array_key_exists($netoperator->id, $this->marketshare[$campaign->id]["netops"])) {
|
||||||
|
$this->marketshare[$campaign->id]["netops"][$netoperator->id] = [];
|
||||||
|
$this->marketshare[$campaign->id]["netops"][$netoperator->id]["bracket_price"] = [];
|
||||||
|
}
|
||||||
|
|
||||||
if($preorder->status->code >= 899) {
|
if($preorder->status->code >= 899) {
|
||||||
$this->log->debug(__METHOD__.": Preorder ".$preorder->id." / ".$preorder->oaid." is cancelled");
|
$this->log->debug(__METHOD__.": Preorder ".$preorder->id." / ".$preorder->oaid." is cancelled");
|
||||||
@@ -490,6 +538,10 @@ class PreorderBillingController extends mfBaseController {
|
|||||||
$existing_bill = PreorderBilling::getFirst(["product_id" => $product->id, "preorder_id" => $preorder->id, "start_date" => $create_date->format("Y-m-d")]);
|
$existing_bill = PreorderBilling::getFirst(["product_id" => $product->id, "preorder_id" => $preorder->id, "start_date" => $create_date->format("Y-m-d")]);
|
||||||
//var_dump($existing_bill);
|
//var_dump($existing_bill);
|
||||||
if(!$existing_bill) {
|
if(!$existing_bill) {
|
||||||
|
if($netoperator_config["billing-period"] == "quarterly" && $create_date->format("Ymd") > $latest_quarter_bill_date->format("Ymd")) {
|
||||||
|
$this->log->debug(__METHOD__.": Skipping operator_usage ".$create_date->format("m/Y")." for preorder ".$preorder->id." because Billing date ".$create_date->format("Y-m-d")." is after latest_quarter_bill_date ".$latest_quarter_bill_date->format("Y-m-d"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
$new_create_date = clone $create_date;
|
$new_create_date = clone $create_date;
|
||||||
$to_bill_dates[] = $new_create_date;
|
$to_bill_dates[] = $new_create_date;
|
||||||
$create_date->modify("-1 months");
|
$create_date->modify("-1 months");
|
||||||
@@ -511,9 +563,44 @@ class PreorderBillingController extends mfBaseController {
|
|||||||
$sday = $start_date->format("d");
|
$sday = $start_date->format("d");
|
||||||
$eday = $end_date->format("d");
|
$eday = $end_date->format("d");
|
||||||
|
|
||||||
$bill_price = $price->price_inet;
|
$price_id = $price->id;
|
||||||
|
$base_price = $price->price_inet;
|
||||||
|
|
||||||
if ($price->price_inet && ($sday > 1)) {
|
if($netoperator_config["marketshare-discount"]) {
|
||||||
|
// get current percentage of billed homes
|
||||||
|
$ms_bill_month = $start_date->format("Ym");
|
||||||
|
if(!array_key_exists("billed-$ms_bill_month", $this->marketshare[$campaign->id]["netops"][$netoperator->id])) {
|
||||||
|
$this->marketshare[$campaign->id]["netops"][$netoperator->id]["billed-$ms_bill_month"] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$max_homes = $this->marketshare[$campaign->id]["max"];
|
||||||
|
$billed_homes = $this->marketshare[$campaign->id]["netops"][$netoperator->id]["billed-$ms_bill_month"];
|
||||||
|
|
||||||
|
if($billed_homes) {
|
||||||
|
$billed_pct = (100 * $billed_homes) / $max_homes;
|
||||||
|
|
||||||
|
foreach([15,20,25,30,35,40,45,50] as $bracket) {
|
||||||
|
if ($billed_pct >= $bracket) {
|
||||||
|
if(array_key_exists("$bracket-$price_id", $this->marketshare[$campaign->id]["netops"][$netoperator->id]["bracket_price"])) {
|
||||||
|
$base_price = $this->marketshare[$campaign->id]["netops"][$netoperator->id]["bracket_price"]["$bracket-$price_id"]->price_inet;
|
||||||
|
} else {
|
||||||
|
$bracket_price = $price->getMarketshareBracket($bracket);
|
||||||
|
if ($bracket_price) {
|
||||||
|
$this->marketshare[$campaign->id]["netops"][$netoperator->id]["bracket_price"]["$bracket-$price_id"] = $bracket_price;
|
||||||
|
$base_price = $bracket_price->price_inet;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->log->debug(__METHOD__.": ".$netoperator->getCompanyOrName()." (month: $ms_bill_month; campaign: ".$campaign->name.") Marketshare Price: $base_price (max: $max_homes | billed: $billed_homes | billed% $billed_pct ");
|
||||||
|
}
|
||||||
|
|
||||||
|
$bill_price = $base_price;
|
||||||
|
|
||||||
|
if ($base_price && ($sday > 1)) {
|
||||||
// Aliquoten Preis errechnen
|
// Aliquoten Preis errechnen
|
||||||
$first_of_period = clone $start_date;
|
$first_of_period = clone $start_date;
|
||||||
$first_of_period->modify("first day of this month");
|
$first_of_period->modify("first day of this month");
|
||||||
@@ -527,7 +614,7 @@ class PreorderBillingController extends mfBaseController {
|
|||||||
if ($period_days < 0) return true; // don't bill for negative time range
|
if ($period_days < 0) return true; // don't bill for negative time range
|
||||||
|
|
||||||
$pc = $period_days / $total_days * 100;
|
$pc = $period_days / $total_days * 100;
|
||||||
$bill_price = round($price->price_inet / 100 * $pc, 2);
|
$bill_price = round($base_price / 100 * $pc, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
$article_number = $product->article_number;
|
$article_number = $product->article_number;
|
||||||
@@ -573,8 +660,16 @@ class PreorderBillingController extends mfBaseController {
|
|||||||
if (!$billing->save()) {
|
if (!$billing->save()) {
|
||||||
die("Billing record could not be saved!");
|
die("Billing record could not be saved!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$ms_bill_month = $start_date->format("Ym");
|
||||||
|
$this->marketshare[$campaign->id]["netops"][$netoperator->id]["billed-$ms_bill_month"]++;
|
||||||
|
//$this->marketshare[$campaign->id]["netops"][$netoperator->id]["billed-$ms_bill_month"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//var_dump($this->marketshare);exit;
|
||||||
|
|
||||||
//var_dump($billing);
|
//var_dump($billing);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -84,7 +84,7 @@ class PreorderBillingInvoice extends mfBaseModel {
|
|||||||
|
|
||||||
|
|
||||||
$pdf = new PdfForm("PreorderBillingInvoice/PDF_MAIN", $pdf_vars);
|
$pdf = new PdfForm("PreorderBillingInvoice/PDF_MAIN", $pdf_vars);
|
||||||
$wkhtmltopdfArgs = "--margin-top 10mm --header-spacing 96 --header-html '$headerFile' --footer-html '$footerFile'";
|
$wkhtmltopdfArgs = "--margin-top 10mm --header-spacing 90 --header-html '$headerFile' --footer-html '$footerFile'";
|
||||||
|
|
||||||
$filename = $pdf->render($wkhtmltopdfArgs);
|
$filename = $pdf->render($wkhtmltopdfArgs);
|
||||||
|
|
||||||
@@ -182,8 +182,8 @@ class PreorderBillingInvoice extends mfBaseModel {
|
|||||||
|
|
||||||
$table_fields = [
|
$table_fields = [
|
||||||
"netowner_id","invoice_number","invoice_date","preorderbillingcustomer_id","owner_id","billingaddress_id","fibu_account_number","fibu_cost_area",
|
"netowner_id","invoice_number","invoice_date","preorderbillingcustomer_id","owner_id","billingaddress_id","fibu_account_number","fibu_cost_area",
|
||||||
"fibu_cost_account", "fibu_revenue_account","fibu_taxcode","tax_text","company","firstname","lastname","street","zip","city","country","email","uid",
|
"fibu_cost_account", "fibu_revenue_account","fibu_taxcode","tax_text","head_text","company","firstname","lastname","street","zip","city","country","email",
|
||||||
"billing_type", "billing_delivery","bank_account_bank","bank_account_owner","bank_account_iban","bank_account_bic","total","total_gross","vatgroup_id",
|
"uid", "billing_type", "billing_delivery","bank_account_bank","bank_account_owner","bank_account_iban","bank_account_bic","total","total_gross","vatgroup_id",
|
||||||
"vatrate", "bmd_export_date","date_delivered",
|
"vatrate", "bmd_export_date","date_delivered",
|
||||||
"create_by","edit_by","create","edit"
|
"create_by","edit_by","create","edit"
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -183,6 +183,14 @@ class PreorderBillingInvoiceController extends mfBaseController {
|
|||||||
$owner_id = $base["owner_id"];
|
$owner_id = $base["owner_id"];
|
||||||
$billingaddress_id = $base["billingaddress_id"];
|
$billingaddress_id = $base["billingaddress_id"];
|
||||||
$billing_delivery = $base["billing_delivery"];
|
$billing_delivery = $base["billing_delivery"];
|
||||||
|
$campaign_id = $base["campaign_id"];
|
||||||
|
|
||||||
|
$campaign = new Preordercampaign($campaign_id);
|
||||||
|
if(!$campaign->id) {
|
||||||
|
die("Kampagne $campaign_id nicht gefunden");
|
||||||
|
}
|
||||||
|
$campaign_name = $campaign->name;
|
||||||
|
$campaign_name = preg_replace('/^RML Liezen\s+-\s+/', '', $campaign_name);
|
||||||
|
|
||||||
$bill_positions = [];
|
$bill_positions = [];
|
||||||
$credit_positions = [];
|
$credit_positions = [];
|
||||||
@@ -193,12 +201,11 @@ class PreorderBillingInvoiceController extends mfBaseController {
|
|||||||
"preorderbillingcustomer_id" => $preorderbillingcustomer_id,
|
"preorderbillingcustomer_id" => $preorderbillingcustomer_id,
|
||||||
"owner_id" => $owner_id,
|
"owner_id" => $owner_id,
|
||||||
"billingaddress_id" => $billingaddress_id,
|
"billingaddress_id" => $billingaddress_id,
|
||||||
|
"preordercampaign_id" => $campaign_id,
|
||||||
"billing_delivery" => $billing_delivery,
|
"billing_delivery" => $billing_delivery,
|
||||||
"invoice_id" => null,
|
"invoice_id" => null,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$billing_rows = PreorderBilling::search($bill_filter);
|
$billing_rows = PreorderBilling::search($bill_filter);
|
||||||
if(!count($billing_rows)) {
|
if(!count($billing_rows)) {
|
||||||
var_dump($bill_filter);
|
var_dump($bill_filter);
|
||||||
@@ -210,7 +217,7 @@ class PreorderBillingInvoiceController extends mfBaseController {
|
|||||||
$sorted_positions = [];
|
$sorted_positions = [];
|
||||||
$invoice_positions = [];
|
$invoice_positions = [];
|
||||||
$invoice_vatrate = 20;
|
$invoice_vatrate = 20;
|
||||||
$price_total_sum = 0;
|
//$price_total_sum = 0;
|
||||||
|
|
||||||
foreach($billing_rows as $bill) {
|
foreach($billing_rows as $bill) {
|
||||||
$billing_row_count++;
|
$billing_row_count++;
|
||||||
@@ -241,6 +248,7 @@ class PreorderBillingInvoiceController extends mfBaseController {
|
|||||||
$detail_data = [
|
$detail_data = [
|
||||||
"owner_id" => $bill->owner_id,
|
"owner_id" => $bill->owner_id,
|
||||||
"company" => ($bill->company) ?: $bill->firstname . " " . $bill->lastname,
|
"company" => ($bill->company) ?: $bill->firstname . " " . $bill->lastname,
|
||||||
|
"network_name" => $campaign_name,
|
||||||
"oaid" => $bill->oaid,
|
"oaid" => $bill->oaid,
|
||||||
"order_date" => $bill->order_date,
|
"order_date" => $bill->order_date,
|
||||||
"start_date" => $start_date->format("Y-m-d"),
|
"start_date" => $start_date->format("Y-m-d"),
|
||||||
@@ -349,6 +357,7 @@ class PreorderBillingInvoiceController extends mfBaseController {
|
|||||||
$invoice_data["fibu_revenue_account"] = TT_PREORDER_BILLING[$netowner_id]["fibu-revenue-code"];
|
$invoice_data["fibu_revenue_account"] = TT_PREORDER_BILLING[$netowner_id]["fibu-revenue-code"];
|
||||||
$invoice_data["fibu_tax_code"] = 1;
|
$invoice_data["fibu_tax_code"] = 1;
|
||||||
$invoice_data["tax_text"] = null;
|
$invoice_data["tax_text"] = null;
|
||||||
|
$invoice_data["head_text"] = null;
|
||||||
$invoice_data["uid"] = $bill->uid;
|
$invoice_data["uid"] = $bill->uid;
|
||||||
$invoice_data["company"] = $bill->company;
|
$invoice_data["company"] = $bill->company;
|
||||||
$invoice_data["firstname"] = $bill->firstname;
|
$invoice_data["firstname"] = $bill->firstname;
|
||||||
@@ -385,6 +394,11 @@ class PreorderBillingInvoiceController extends mfBaseController {
|
|||||||
unset($position->preorder_billings);
|
unset($position->preorder_billings);
|
||||||
unset($position->count);
|
unset($position->count);
|
||||||
|
|
||||||
|
|
||||||
|
if($position->product_id != 2) {
|
||||||
|
$invoice->head_text = "Entgelte für Netzgebiet $campaign_name";
|
||||||
|
}
|
||||||
|
|
||||||
$total_net += $position->price_total;
|
$total_net += $position->price_total;
|
||||||
$total_gross += $position->price_gross;
|
$total_gross += $position->price_gross;
|
||||||
|
|
||||||
@@ -446,14 +460,15 @@ class PreorderBillingInvoiceController extends mfBaseController {
|
|||||||
if(count($invoice_detail_data)) {
|
if(count($invoice_detail_data)) {
|
||||||
// create CSV file
|
// create CSV file
|
||||||
//var_dump($invoice_detail_data);exit;
|
//var_dump($invoice_detail_data);exit;
|
||||||
$csv = "\u{FEFF}Netzbetreiber;Rechungsnummer;Rechnungsdateum;OAID;Bestelldatum;Periode von;Periode bis;Artikelnummer;Produkt;Anzahl;Preis Netto\n";
|
$csv = "\u{FEFF}Netzbetreiber;Rechungsnummer;Rechnungsdateum;Netzgebiet;OAID;Bestelldatum;Periode von;Periode bis;Artikelnummer;Produkt;Anzahl;Preis Netto\n";
|
||||||
foreach ($invoice_detail_data as $detail) {
|
foreach ($invoice_detail_data as $detail) {
|
||||||
//var_dump($detail);
|
//var_dump($detail);
|
||||||
//exit;
|
//exit;
|
||||||
|
|
||||||
$csv .= '"'.str_replace(["\r","\n"], " ", $detail["company"]).'";';
|
$csv .= '"'.str_replace(["\r","\n", '"'], [" "," ",'""'], $detail["company"]).'";';
|
||||||
$csv .= '"'.$invoice->invoice_number.'";';
|
$csv .= '"'.$invoice->invoice_number.'";';
|
||||||
$csv .= '"'.$invoice->invoice_date.'";';
|
$csv .= '"'.$invoice->invoice_date.'";';
|
||||||
|
$csv .= '"'.str_replace('"','""',$detail["network_name"]).'";';
|
||||||
$csv .= '"'.$detail["oaid"].'";';
|
$csv .= '"'.$detail["oaid"].'";';
|
||||||
$csv .= '"'.$detail["order_date"].'";';
|
$csv .= '"'.$detail["order_date"].'";';
|
||||||
$csv .= '"'.$detail["start_date"].'";';
|
$csv .= '"'.$detail["start_date"].'";';
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ class PreorderProductMarketshareDiscount extends mfBaseModel {
|
|||||||
WHERE $where
|
WHERE $where
|
||||||
ORDER BY preorderproductprice_id,bracket LIMIT 1";
|
ORDER BY preorderproductprice_id,bracket LIMIT 1";
|
||||||
//var_dump($sql);exit;
|
//var_dump($sql);exit;
|
||||||
|
mfLoghandler::singleton()->debug($sql);
|
||||||
$res = $db->query($sql);
|
$res = $db->query($sql);
|
||||||
if($db->num_rows($res)) {
|
if($db->num_rows($res)) {
|
||||||
$data = $db->fetch_object($res);
|
$data = $db->fetch_object($res);
|
||||||
|
|||||||
@@ -10,6 +10,15 @@ class PreorderProductPrice extends mfBaseModel {
|
|||||||
private $creator;
|
private $creator;
|
||||||
private $editor;
|
private $editor;
|
||||||
|
|
||||||
|
public function getMarketshareBracket($bracket) {
|
||||||
|
$bracket = PreorderProductMarketshareDiscount::getFirst(["preorderproductprice_id" => $this->id, "bracket" => $bracket]);
|
||||||
|
if(!$bracket) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $bracket;
|
||||||
|
}
|
||||||
|
|
||||||
public function getProperty($name) {
|
public function getProperty($name) {
|
||||||
if($this->$name == null) {
|
if($this->$name == null) {
|
||||||
|
|
||||||
|
|||||||
@@ -110,6 +110,17 @@ class Preordercampaign extends mfBaseModel {
|
|||||||
return ['activation' => $activation_products, 'provision' => $provision_products, 'reorder' => $reorder_products];
|
return ['activation' => $activation_products, 'provision' => $provision_products, 'reorder' => $reorder_products];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getUnitCount() {
|
||||||
|
$count = 0;
|
||||||
|
|
||||||
|
$netzgebiete = $this->getProperty("salesclusters");
|
||||||
|
foreach($netzgebiete as $netzgebiet) {
|
||||||
|
$count += $netzgebiet->unit_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $count;
|
||||||
|
}
|
||||||
|
|
||||||
public function getProperty($name) {
|
public function getProperty($name) {
|
||||||
if($this->$name == null) {
|
if($this->$name == null) {
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Phinx\Migration\AbstractMigration;
|
||||||
|
|
||||||
|
final class PreorderBillingInvoiceAddHeadText extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
if($this->getEnvironment() == "thetool") {
|
||||||
|
$table = $this->table("PreorderBillingInvoice");
|
||||||
|
$table->addColumn("head_text", "text", ["null" => true, "default" => null, "after" => "tax_text"]);
|
||||||
|
$table->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->getEnvironment() == "addressdb") {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
if($this->getEnvironment() == "thetool") {
|
||||||
|
$this->table("PreorderBillingInvoice")->removeColumn("head_text")->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->getEnvironment() == "addressdb") {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user