WIP Contractqueue
This commit is contained in:
451
Layout/default/Contractqueue/Index.php
Normal file
451
Layout/default/Contractqueue/Index.php
Normal file
@@ -0,0 +1,451 @@
|
||||
<?php
|
||||
$pagination_baseurl = $this->getUrl($Mod,"Index");
|
||||
$pagination_baseurl_params = ["filter" => $filter];
|
||||
$pagination_entity_name = "Produkte";
|
||||
?>
|
||||
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/header.php"); ?>
|
||||
|
||||
<!-- start page title -->
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="page-title-box">
|
||||
<div class="page-title-right">
|
||||
<ol class="breadcrumb m-0">
|
||||
<li class="breadcrumb-item"><a href="<?=self::getUrl("Dashboard")?>"><?=MFAPPNAME_SLUG?></a></li>
|
||||
<li class="breadcrumb-item active">Fertiggestellte Bestellungen</li>
|
||||
</ol>
|
||||
</div>
|
||||
<h4 class="page-title">Contractfreigabe</h4>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- end page title -->
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body mb-3">
|
||||
<h4 class="header-title mb-3">Filter</h4>
|
||||
|
||||
<form method="get" action="<?=self::getUrl("Contractqueue")?>">
|
||||
<div class="row">
|
||||
|
||||
<div class="col-1">
|
||||
<label class="form-label" for="filter_owner">Kundennummer</label>
|
||||
<input type="text" class="form-control" name="filter[customer_number]" id="filter_street" value="<?=(array_key_exists("customer_number", $filter)) ? $filter['customer_number'] : ""?>" />
|
||||
</div>
|
||||
|
||||
<div class="col-1">
|
||||
<label class="form-label" for="filter_owner">Inhaber Name</label>
|
||||
<input type="text" class="form-control" name="filter[owner]" id="filter_street" value="<?=(array_key_exists("owner", $filter)) ? $filter['owner'] : ""?>" />
|
||||
</div>
|
||||
|
||||
<div class="col-1">
|
||||
<label class="form-label" for="filter_billingaddress">Rech.Empfänger</label>
|
||||
<input type="text" class="form-control" name="filter[billingaddress]" id="filter_billingaddress" value="<?=(array_key_exists("billing_address", $filter)) ? $filter['billingaddress'] : ""?>" />
|
||||
</div>
|
||||
|
||||
<div class="col-1">
|
||||
<label class="form-label" for="filter_product_group">Produktgruppe</label>
|
||||
<input type="text" class="form-control" name="filter[product_group]" id="filter_product_group" value="<?=(array_key_exists("product_group", $filter)) ? $filter['product_group'] : ""?>" />
|
||||
</div>
|
||||
|
||||
<div class="col-1">
|
||||
<label class="form-label" for="filter_product_name">Produkt</label>
|
||||
<input type="text" class="form-control" name="filter[product_name]" id="filter_product_name" value="<?=(array_key_exists("product_name", $filter)) ? $filter['product_name'] : ""?>" />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="row mt-2">
|
||||
<div class="col">
|
||||
<button type="submit" class="btn btn-primary">Filter anwenden</button>
|
||||
<a class="btn btn-secondary" href="<?=self::getUrl("Contractqueue")?>?resetFilter=1">Filter zurücksetzen</a>
|
||||
</div>
|
||||
<!--<div class="col">
|
||||
<button class="btn btn-info" type="button" onclick="refreshMap()"><i class="far fa-map"></i> Auf Karte anzeigen</button>
|
||||
</div>-->
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body mb-3">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="float-left">
|
||||
<h4 class="header-title">Fertiggestellte Bestellungen</h4>
|
||||
</div>
|
||||
<div class="float-right">
|
||||
<a class="btn btn-primary mb-2" href="<?=self::getUrl("Contractqueue", "importFinishedOrders")?>"><i class="fas fa-fw fa-file-import"></i> Fertiggestellte Bestellungen importieren</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination.php"); ?>
|
||||
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination-summary.php"); ?>
|
||||
|
||||
<?php $i = 0; foreach($orders as $order_id => $contracts): ?>
|
||||
<?php $order = $contracts[0]->orderproduct->order; ?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="card border-top-success">
|
||||
<div class="card-header">
|
||||
<span class="float-right order-date-pill active mr-2 mt-1">Fertigstellung: <span class="text-monospace font-weight-bold"><?=date("d.m.Y", $order->finish_date)?></span></span>
|
||||
<span class="float-right order-date-pill active mr-2 mt-1">Zuletzt bearbeitet: <span class="text-monospace font-weight-bold"><?=date("d.m.Y H:i", $order->edit)?> (<?=$order->editor?>)</span></span>
|
||||
<span class="float-right order-date-pill active mr-2 mt-1">Erstellt: <span class="text-monospace font-weight-bold"><?=date("d.m.Y H:i", $order->create)?> (<?=$order->creator?>)</span></span>
|
||||
|
||||
<h4><a href="<?=self::getUrl("Order", "", ["id" => $order_id])?>" target="_blank">Bestellung <?=$order_id?></a></h4>
|
||||
</div>
|
||||
<div class="card-body bg-light">
|
||||
|
||||
<div class="row">
|
||||
|
||||
<div class="col-6">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div>
|
||||
<span class="float-right"><i class="fas fa-fw fa-pencil pointer text-primary" onclick="toggleEdit('owner', <?=$order_id?>, false)"></i></span>
|
||||
<h5 class="m-0">Inhaber</h5>
|
||||
|
||||
</div>
|
||||
<hr class="mt-1" />
|
||||
<span class="text-monospace"><?=$order->owner->customer_number?></span><br />
|
||||
<strong><?=$order->owner->getCompanyOrName()?></strong><br />
|
||||
<?=$order->owner->street?><br />
|
||||
<?=$order->owner->zip?> <?=$order->owner->city?><br />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div>
|
||||
<span class="float-right"><i class="fas fa-fw fa-pencil pointer text-primary" onclick="toggleEdit('billingaddress', <?=$order_id?>, false)"></i></span>
|
||||
<h5 class="m-0">Rechnungsempfänger</h5>
|
||||
<hr class="mt-1" />
|
||||
</div>
|
||||
<?php if($order->billingaddress_id): ?>
|
||||
<?=($order->billingaddress->customer_number) ? $order->billingaddress->customer_number."<br />" : ""?>
|
||||
<?=$order->billingaddress->getCompanyOrName()?><br />
|
||||
<?=$order->billingaddress->street?><br />
|
||||
<?=$order->billingaddress->zip?> <?=$order->billingaddress->city?><br />
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-6">
|
||||
<div class="card mb-1">
|
||||
<div class="card-body">
|
||||
<h5 class="m-0">Bestelljournal</h5>
|
||||
|
||||
<table class="table table-sm table-striped mt-1 mb-0">
|
||||
<tr>
|
||||
<th>Erstellt</th>
|
||||
<th>Text</th>
|
||||
</tr>
|
||||
<?php foreach($order->journals as $journal): ?>
|
||||
<tr>
|
||||
<td class="text-monospace"><?=date("d.m.Y H:i", $journal->create)?> (<?=$journal->creator?>)</td>
|
||||
<td><?=nl2br($journal->text)?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<?php if(trim($order->note)): ?>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="m-0">Interne Notiz</h5>
|
||||
<hr class="mt-1">
|
||||
<?=nl2br(htmlentities($order->note))?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="row">
|
||||
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
|
||||
<h5>Produkte</h5>
|
||||
<table class="table table-striped table-hover" id="order-products-<?=$order_id?>">
|
||||
<tr>
|
||||
<th style="width:56px;"><input type="checkbox" class="form-control pointer checkbox-toggle" onclick="toggleOrderApproval(this, <?=$order_id?>, 'order')" /></th>
|
||||
<th>Produkt</th>
|
||||
<th>Matchcode</th>
|
||||
<th>Preis</th>
|
||||
<th>Preis Setup</th>
|
||||
<th>Rechnungsperiode</th>
|
||||
<th>Verz. Verrechnungsstart</th>
|
||||
<th>Erstellt</th>
|
||||
<th>Zuletzt bearbeitet</th>
|
||||
</tr>
|
||||
|
||||
<?php foreach($contracts as $contract): ?>
|
||||
<tr id="contract-<?=$contract->id?>">
|
||||
<td><input type="checkbox" class="form-control pointer" id="approve-order-<?=$order_id?>-contract-<?=$contract->id?>" onclick="toggleApproval(<?=$order_id?>, 'order')" <?=($contract->approved) ? "checked='checked'" : ""?> /></td>
|
||||
<td class="text-wrap product">
|
||||
<div class="text">
|
||||
<i class="fas fa-fw fa-pencil pointer text-primary" onclick="toggleEdit('contract', <?=$contract->id?>, 'product')"></i> <?=$contract->product_name?>
|
||||
<?php if($contract->termination_id && $contract->termination): ?>
|
||||
<br /><small class="text-pink"><?=$contract->termination->code?> - <?= str_replace("\n", " - ", $contract->termination->getAddress())?></small>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<div class="edit hidden">
|
||||
<div class="input-group mb-3">
|
||||
<select class="edit-control form-control" data-val="<?=$contract->product_id?>" data-ov="<?=$contract->product_id?>"></select>
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-primary"><i class="fas fa-check"></i></button>
|
||||
<button class="btn btn-secondary" onclick="toggleEdit('contract', <?=$contract->id?>, 'product')"><i class="fas fa-times"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="matchcode">
|
||||
<div class="text">
|
||||
<i class="fas fa-fw fa-pencil pointer text-primary" onclick="toggleEdit('contract', <?=$contract->id?>, 'matchcode')"></i> <?= htmlentities($contract->matchcode)?>
|
||||
</div>
|
||||
<div class="edit hidden">
|
||||
<div class="input-group mb-3">
|
||||
<input type="text" class="form-control edit-control" value="<?=$contract->matchcode?>" data-val="<?=htmlentities($contract->matchcode)?>" data-ov="<?=htmlentities($contract->matchcode)?>" />
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-primary"><i class="fas fa-check"></i></button>
|
||||
<button class="btn btn-secondary" onclick="toggleEdit('contract', <?=$contract->id?>, 'matchcode')"><i class="fas fa-times"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="price">
|
||||
<div class="text"><i class="fas fa-fw fa-pencil pointer text-primary" onclick="toggleEdit('contract', <?=$contract->id?>, 'price')"></i> € <?=$contract->price?></div>
|
||||
<div class="edit hidden">
|
||||
<div class="input-group mb-3">
|
||||
<input type="text" class="form-control edit-control" value="<?=$contract->price?>" data-val="<?=$contract->price?>" data-ov="<?=$contract->price?>" />
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-primary"><i class="fas fa-check"></i></button>
|
||||
<button class="btn btn-secondary" onclick="toggleEdit('contract', <?=$contract->id?>, 'price')"><i class="fas fa-times"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="price_setup">
|
||||
<div class="text"><i class="fas fa-fw fa-pencil pointer text-primary" onclick="toggleEdit('contract', <?=$contract->id?>, 'price_setup')"></i> € <?=$contract->price_setup?></div>
|
||||
<div class="edit hidden">
|
||||
<div class="input-group mb-3">
|
||||
<input type="text" class="form-control edit-control" value="<?=$contract->price_setup?>" data-val="<?=$contract->price_setup?>" data-ov="<?=$contract->price_setup?>" />
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-primary"><i class="fas fa-check"></i></button>
|
||||
<button class="btn btn-secondary" onclick="toggleEdit('contract', <?=$contract->id?>, 'price_setup')"><i class="fas fa-times"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="billing_period">
|
||||
<div class="text">
|
||||
<i class="fas fa-fw fa-pencil pointer text-primary" onclick="toggleEdit('contract', <?=$contract->id?>, 'billing_period')"></i>
|
||||
<?php if($contract->billing_period == 1): ?>
|
||||
monatlich
|
||||
<?php elseif($contract->billing_period == 24): ?>
|
||||
biennal
|
||||
<?php elseif($contract->billing_period == 36): ?>
|
||||
triennal
|
||||
<?php else: ?>
|
||||
<?=(12 / $contract->billing_period)?>x Jährlich
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="edit hidden">
|
||||
<div class="input-group mb-3">
|
||||
<select class="edit-control form-control" data-val="<?=$contract->product_id?>" data-ov="<?=$contract->product_id?>">
|
||||
<option value="1" <?=($contract->billing_period == 1) ? "selected='selected'" : ""?>>Monatlich</option>
|
||||
<option value="12" <?=($contract->billing_period == 12) ? "selected='selected'" : ""?>>Jährlich</option>
|
||||
<option value="24" <?=($contract->billing_period == 24) ? "selected='selected'" : ""?>>2-Jährlich</option>
|
||||
<option value="36" <?=($contract->billing_period == 36) ? "selected='selected'" : ""?>>3-Jährlich</option>
|
||||
</select>
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-primary"><i class="fas fa-check"></i></button>
|
||||
<button class="btn btn-secondary" onclick="toggleEdit('contract', <?=$contract->id?>, 'billing_period')"><i class="fas fa-times"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="billing_delay">
|
||||
<div class="text"><i class="fas fa-fw fa-pencil pointer text-primary" onclick="toggleEdit('contract', <?=$contract->id?>, 'billing_delay')"></i> <?=($contract->billing_delay) ? $contract->billing_delay." Monate" : ""?></div>
|
||||
<div class="edit hidden">
|
||||
<div class="input-group mb-3">
|
||||
<input type="text" class="form-control edit-control" value="<?=$contract->billing_delay?>" data-val="<?=$contract->billing_delay?>" data-ov="<?=$contract->billing_delay?>" />
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-primary"><i class="fas fa-check"></i></button>
|
||||
<button class="btn btn-secondary" onclick="toggleEdit('contract', <?=$contract->id?>, 'billing_delay')"><i class="fas fa-times"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="text-monospace"><?=date('d.m.Y H:i', $contract->orderproduct->create)?><br /><?=$contract->orderproduct->creator->name?></td>
|
||||
<td class="text-monospace"><?=date('d.m.Y H:i', $contract->orderproduct->edit)?><br /><?=$contract->orderproduct->editor->name?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
|
||||
<h5>Gutschriften / Provisionen</h5>
|
||||
<table class="table table-striped table-hover" id="credit-products-<?=$order_id?>">
|
||||
<tr>
|
||||
<th style="width:56px;"><input type="checkbox" class="form-control pointer checkbox-toggle" onclick="toggleOrderApproval(this, <?=$order_id?>, 'credit')" /></th>
|
||||
<th>Bezieher</th>
|
||||
<th>Produkt</th>
|
||||
<th>Matchcode</th>
|
||||
<th>Provision</th>
|
||||
<th>Rechnungsperiode</th>
|
||||
<th>Verz. Verrechnungsstart</th>
|
||||
</tr>
|
||||
|
||||
<?php foreach($contracts as $contract): ?>
|
||||
<?php $credit = $contract->getCredit(); if(!$credit) continue; ?>
|
||||
<tr id="credit-<?=$contract->id?>">
|
||||
<td><input type="checkbox" class="form-control pointer" id="approve-credit-<?=$order_id?>-contract-<?=$contract->id?>" onclick="toggleApproval(<?=$order_id?>, 'credit')" <?=($contract->approved) ? "checked='checked'" : ""?> /></td>
|
||||
<td><?=($credit["partner"]) ? $credit["partner"]->getCompanyOrName() : ""?></td>
|
||||
<td class="text-wrap">
|
||||
<?=$contract->product_name?>
|
||||
<?php if($contract->termination_id && $contract->termination): ?>
|
||||
<br /><small class="text-pink"><?=$contract->termination->code?> - <?= str_replace("\n", " - ", $contract->termination->getAddress())?></small>
|
||||
<?php endif ?>
|
||||
</td>
|
||||
<td class="matchcode">
|
||||
<div class="text">
|
||||
<i class="fas fa-fw fa-pencil pointer text-primary" onclick="toggleEdit('credit', <?=$contract->id?>, 'matchcode')"></i> <?=$contract->matchcode?>
|
||||
</div>
|
||||
<div class="edit hidden">
|
||||
<div class="input-group mb-3">
|
||||
<input type="text" class="form-control edit-control" value="<?=$contract->matchcode?>" data-val="<?=$contract->matchcode?>" data-ov="<?=$contract->matchcode?>" />
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-primary"><i class="fas fa-check"></i></button>
|
||||
<button class="btn btn-secondary" onclick="toggleEdit('credit', <?=$contract->id?>, 'matchcode')"><i class="fas fa-times"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td><?=($credit["rate_source"] == "rate") ? "€ ".$credit["rate"] : "€ ".$contract->price_nne?> <?=($credit["rate_source"] == "rate") ? "(Prozentrate)" : "(NNE)"?></td>
|
||||
<td>
|
||||
<?php if($contract->billing_period == 1): ?>
|
||||
monatlich
|
||||
<?php elseif($contract->billing_period == 24): ?>
|
||||
biennal
|
||||
<?php elseif($contract->billing_period == 36): ?>
|
||||
triennal
|
||||
<?php else: ?>
|
||||
<?=(12 / $contract->billing_period)?>x Jährlich
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td class=""><?=($contract->billing_delay) ? $contract->billing_delay." Monate" : ""?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php $i++; endforeach; ?>
|
||||
|
||||
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination-summary.php"); ?>
|
||||
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination.php"); ?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
<?php
|
||||
$prods = [];
|
||||
foreach(ProductModel::getActive() as $product):
|
||||
$prods[] = ["id" => $product->id, "name" => $product->name];
|
||||
endforeach;
|
||||
?>
|
||||
|
||||
var products = <?=json_encode($prods)?>;
|
||||
|
||||
function toggleOrderApproval(cbox, order_id, type) {
|
||||
if(!parseInt(order_id) || !order_id) return;
|
||||
|
||||
//var checked_count = $("#order-products-" + order_id + " input[id^='approve-contract-']:checked").length;
|
||||
|
||||
if($(cbox).is(":checked")) {
|
||||
$("#" + type + "-products-" + order_id + " input[id^='approve-" + type + "-" + order_id + "-contract-']").prop('checked', true);
|
||||
} else {
|
||||
$("#" + type + "-products-" + order_id + " input[id^='approve-" + type + "-" + order_id + "-contract-']").prop('checked', false);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleApproval(order_id, type) {
|
||||
if(!parseInt(order_id) || !order_id) return;
|
||||
|
||||
console.log("#" + type + "-products-" + order_id + " input[id^='approve-" + order_id + "-contract-']");
|
||||
|
||||
var box_count = $("#" + type + "-products-" + order_id + " input[id^='approve-" + type + "-" + order_id + "-contract-']").length;
|
||||
var checked_count = $("#" + type + "-products-" + order_id + " input[id^='approve-" + type + "-" + order_id + "-contract-']:checked").length;
|
||||
|
||||
console.log("box_count: " + box_count + " checked_count: " + checked_count);
|
||||
|
||||
if(checked_count == box_count) {
|
||||
$("#" + type + "-products-" + order_id + " .checkbox-toggle").prop("checked", true);
|
||||
}
|
||||
if(checked_count < box_count) {
|
||||
$("#" + type + "-products-" + order_id + " .checkbox-toggle").prop("checked", false);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleEdit(type, id, control_name) {
|
||||
var textBlock = $("#" + type + "-" + id + " ." + control_name + " .text");
|
||||
var editBlock = $("#" + type + "-" + id + " ." + control_name + " .edit");
|
||||
|
||||
var control = $("#" + type + "-" + id + " ." + control_name + " .edit .edit-control");
|
||||
|
||||
var current_val = control.data("val");
|
||||
var original_val = control.data("ov");
|
||||
|
||||
textBlock.toggle();
|
||||
editBlock.toggle();
|
||||
|
||||
if(type == "owner" || type == "billingaddress") {
|
||||
return;
|
||||
}
|
||||
|
||||
if(control_name == "product") {
|
||||
if(!control.children().length) {
|
||||
products.forEach((product) => {
|
||||
var opt = document.createElement("option");
|
||||
opt.text = product.name;
|
||||
opt.value = product.id;
|
||||
control.append(opt);
|
||||
});
|
||||
console.log(current_val);
|
||||
control.val(current_val);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>
|
||||
@@ -1,8 +1,164 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
class Contractqueue extends mfBaseModel {
|
||||
protected $forcestr = ["product_name","product_info","matchcode"];
|
||||
|
||||
private $crediting_partner;
|
||||
private $reseller;
|
||||
private $owner;
|
||||
private $billingaddress;
|
||||
private $product;
|
||||
private $orderproduct;
|
||||
private $termination;
|
||||
private $sla;
|
||||
private $creator;
|
||||
private $editor;
|
||||
|
||||
public function generateMatchcode() {
|
||||
$owner_address = $this->getProperty("owner")->street.", ".$this->getProperty("owner")->zip." ".$this->getProperty("owner")->city;
|
||||
|
||||
// phone
|
||||
if($this->getProperty("product")->productgroup->mathcodeorigin == "voicenumber") {
|
||||
|
||||
}
|
||||
// domain
|
||||
if($this->getProperty("product")->productgroup->mathcodeorigin == "domain") {
|
||||
|
||||
}
|
||||
|
||||
if($this->termination_id) {
|
||||
$termination = new Termination($this->termination_id);
|
||||
$termination_address = $termination->building->street.", ".$termination->building->zip." ".$termination->building->city;
|
||||
return $termination_address;
|
||||
} else {
|
||||
|
||||
|
||||
|
||||
// everything else
|
||||
|
||||
return $owner_address;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getCredit() {
|
||||
$crediting = [];
|
||||
|
||||
if(!$this->crediting_partner_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$crediting["partner"] = $this->getProperty("crediting_partner");
|
||||
|
||||
if($this->crediting_partner_rate) {
|
||||
// use rate
|
||||
$crediting["rate_source"] = "rate";
|
||||
$crediting["rate"] = round($this->price / 100 * $this->crediting_partner_rate, 4);
|
||||
} else {
|
||||
$crediting["rate_source"] = "nne";
|
||||
}
|
||||
|
||||
return $crediting;
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if($name == "billingaddress" && $this->billingaddress_id) {
|
||||
$this->billingaddress = mfValuecache::singleton()->get("mfObjectmodel-Address-".$this->billingaddress_id);
|
||||
if($this->billingaddress === null) {
|
||||
$this->billingaddress = new Address($this->billingaddress_id);
|
||||
if($this->billingaddress->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-Address-".$this->billingaddress_id, $this->billingaddress);
|
||||
}
|
||||
}
|
||||
return $this->billingaddress;
|
||||
}
|
||||
|
||||
if($name == "owner" && $this->owner_id) {
|
||||
$this->owner = mfValuecache::singleton()->get("mfObjectmodel-Address-".$this->owner_id);
|
||||
if($this->owner === null) {
|
||||
$this->owner = new Address($this->owner_id);
|
||||
if($this->owner->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-Address-".$this->owner_id, $this->owner);
|
||||
}
|
||||
}
|
||||
return $this->owner;
|
||||
}
|
||||
|
||||
if($name == "crediting_partner" && $this->crediting_partner_id) {
|
||||
$this->crediting_partner = mfValuecache::singleton()->get("mfObjectmodel-Address-".$this->crediting_partner_id);
|
||||
if($this->crediting_partner === null) {
|
||||
$this->crediting_partner = new Address($this->crediting_partner_id);
|
||||
if($this->crediting_partner->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-Address-".$this->crediting_partner_id, $this->crediting_partner);
|
||||
}
|
||||
}
|
||||
return $this->crediting_partner;
|
||||
}
|
||||
|
||||
if($name == "product") {
|
||||
$this->product = mfValuecache::singleton()->get("mfObjectmodel-Product-".$this->product_id);
|
||||
if($this->product === null) {
|
||||
$this->product = new Product($this->product_id);
|
||||
if($this->product->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-Product-".$this->product_id, $this->product);
|
||||
}
|
||||
}
|
||||
return $this->product;
|
||||
}
|
||||
|
||||
if($name == "orderproduct") {
|
||||
$this->orderproduct = mfValuecache::singleton()->get("mfObjectmodel-OrderProduct-".$this->orderproduct_id);
|
||||
if($this->orderproduct === null) {
|
||||
$this->orderproduct = new OrderProduct($this->orderproduct_id);
|
||||
if($this->orderproduct->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-OrderProduct-".$this->orderproduct_id, $this->orderproduct);
|
||||
}
|
||||
}
|
||||
return $this->orderproduct;
|
||||
}
|
||||
|
||||
|
||||
if($name == "creator" && $this->id) {
|
||||
$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->id) {
|
||||
$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;
|
||||
}
|
||||
}
|
||||
171
application/Contractqueue/ContractqueueController.php
Normal file
171
application/Contractqueue/ContractqueueController.php
Normal file
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
|
||||
class ContractqueueController extends mfBaseController {
|
||||
|
||||
protected function init() {
|
||||
$this->needlogin=true;
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
|
||||
if(!$me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
}
|
||||
|
||||
protected function indexAction() {
|
||||
if($this->request->resetFilter) {
|
||||
unset($_SESSION[MFAPPNAME.'-Contractqueue-filter']);
|
||||
}
|
||||
|
||||
$filter = [];
|
||||
if(is_array($this->request->filter)) {
|
||||
$filter = $this->request->filter;
|
||||
$_SESSION[MFAPPNAME.'-Contractqueue-filter'] = $filter;
|
||||
} else {
|
||||
if(array_key_exists(MFAPPNAME.'-Contractqueue-filter', $_SESSION) && count($_SESSION[MFAPPNAME.'-Contractqueue-filter'])) {
|
||||
$filter = $_SESSION[MFAPPNAME.'-Contractqueue-filter'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->layout->set("filter", $filter);
|
||||
$filter = $this->getPreparedFilter($filter);
|
||||
|
||||
// pagination defaults
|
||||
$pagination = [];
|
||||
$pagination['start'] = 0;
|
||||
$pagination['count'] = 50;
|
||||
$pagination['maxItems'] = 0;
|
||||
|
||||
if(is_numeric($this->request->s)) {
|
||||
$pagination['start'] = intval($this->request->s);
|
||||
}
|
||||
|
||||
$filter["contract_id"] = null;
|
||||
$pagination['maxItems'] = ContractqueueModel::count($filter);
|
||||
|
||||
$last_order_id = false;
|
||||
$orders = [];
|
||||
foreach(ContractqueueModel::search($filter, $pagination) as $contractq) {
|
||||
$last_order_id = $contractq->order_id;
|
||||
$orders[$contractq->order_id][] = $contractq;
|
||||
}
|
||||
|
||||
if($last_order_id) {
|
||||
$filter["order_id"] = $last_order_id;
|
||||
$orders[$contractq->order_id] = [];
|
||||
foreach(ContractqueueModel::search($filter, $pagination) as $contractq) {
|
||||
$orders[$contractq->order_id][] = $contractq;
|
||||
}
|
||||
}
|
||||
|
||||
$this->layout()->set("orders", $orders);
|
||||
$this->layout()->set("pagination", $pagination);
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function getPreparedFilter($filter) {
|
||||
|
||||
return $filter;
|
||||
}
|
||||
|
||||
protected function importFinishedOrdersAction() {
|
||||
$o = 0;
|
||||
$max_orders = 1500;
|
||||
foreach(OrderModel::search(["finish_date<" => date("U")]) as $order) {
|
||||
if(!is_array($order->products) || !count($order->products)) {
|
||||
//echo "keine Produkte in Order ".$order->id."\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
if(ContractqueueModel::getFirst(["order_id" => $order->id])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$contracts = [];
|
||||
$primary_matchcode = false;
|
||||
|
||||
|
||||
foreach($order->products as $op) {
|
||||
$contract = ContractModel::getFirst(["orderproduct_id" => $op->id]);
|
||||
if(!$contract) {
|
||||
$contract = ContractqueueModel::getFirst(["orderproduct_id" => $op->id]);
|
||||
}
|
||||
if($contract && $contract->matchcode) {
|
||||
$primary_matchcode = $contract->matchcode;
|
||||
continue;
|
||||
}
|
||||
|
||||
// if contract does not exist yet, create Contractqueue
|
||||
$contract = ContractqueueModel::createFromOrderproduct($op);
|
||||
|
||||
// find reseller / receiver of credit
|
||||
// from product
|
||||
$product_attribs = $contract->product->attributes;
|
||||
/*if($op->id == "8666") {
|
||||
var_dump($product_attribs);exit;
|
||||
}*/
|
||||
if(is_array($product_attribs) && array_key_exists("crediting_partner", $product_attribs) && $product_attribs["crediting_partner"] && is_object($product_attribs["crediting_partner"])) {
|
||||
|
||||
if($product_attribs["crediting_partner"]->value) {
|
||||
$contract->crediting_partner_id = $product_attribs["crediting_partner"]->value;
|
||||
}
|
||||
if($product_attribs["crediting_rate"]->value) {
|
||||
$contract->crediting_partner_rate = str_replace(",", ".",$product_attribs["crediting_rate"]->value);
|
||||
}
|
||||
}
|
||||
// or from netowner if anschluss product
|
||||
if(!$contract->crediting_partner_id && $contract->termination_id) {
|
||||
$contract->crediting_partner_id = $contract->termination->building->network->owner_id;
|
||||
}
|
||||
|
||||
if($contract->matchcode) {
|
||||
$primary_matchcode = $contract->matchcode;
|
||||
}
|
||||
$contracts[] = $contract;
|
||||
}
|
||||
|
||||
|
||||
if(!$primary_matchcode) {
|
||||
$primary_matchcode = $order->owner->street.", ".$order->owner->zip." ".$order->owner->city;
|
||||
}
|
||||
|
||||
$links = [];
|
||||
// set matchcode and save
|
||||
foreach($contracts as $contract) {
|
||||
if(!$contract->matchcode) {
|
||||
$contract->matchcode = $primary_matchcode;
|
||||
|
||||
}
|
||||
//var_dump($contract);exit;
|
||||
$contract->save();
|
||||
|
||||
/*if(!count($links)) {
|
||||
$links[$contract->id] = $contract;
|
||||
} elseif(!array_key_exists($contract->id, $links)) {
|
||||
$first_link = reset($links);
|
||||
|
||||
$new_link = ContractLinkModel::create([
|
||||
"contract_id" => $first_link->id,
|
||||
"origin_contract_id" => $contract->id,
|
||||
"type" => "link"
|
||||
]);
|
||||
$new_link->save();
|
||||
$links[$contract->id] = $contract;
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
$o++;
|
||||
|
||||
if($o >= $max_orders) {
|
||||
$this->layout()->setFlash("$o Bestellungen importiert, es gibt noch mehr Bestellungen zum importieren.", "info");
|
||||
$this->redirect("Contractqueue");
|
||||
}
|
||||
}
|
||||
$this->layout()->setFlash("Alle Bestellungen importiert", "success");
|
||||
$this->redirect("Contractqueue");
|
||||
}
|
||||
}
|
||||
374
application/Contractqueue/ContractqueueModel.php
Normal file
374
application/Contractqueue/ContractqueueModel.php
Normal file
@@ -0,0 +1,374 @@
|
||||
<?php
|
||||
|
||||
class ContractqueueModel {
|
||||
public $approved;
|
||||
public $contract_id;
|
||||
public $order_id;
|
||||
public $orderproduct_id;
|
||||
public $owner_id;
|
||||
public $crediting_partner_id;
|
||||
public $crediting_partner_rate;
|
||||
public $billingaddress_id;
|
||||
public $termination_id;
|
||||
public $product_id;
|
||||
public $product_name;
|
||||
public $product_info;
|
||||
public $matchcode;
|
||||
public $amount;
|
||||
public $sla_id = null;
|
||||
public $product_external;
|
||||
public $product_external_id;
|
||||
public $price = null;
|
||||
public $price_setup = null;
|
||||
public $price_nne = null;
|
||||
public $price_nbe = null;
|
||||
public $billing_delay = null;
|
||||
public $billing_period = null;
|
||||
public $order_date;
|
||||
public $finish_date;
|
||||
public $finish_date_by;
|
||||
public $cancel_date;
|
||||
public $cancel_date_by;
|
||||
public $imported_from;
|
||||
public $imported_data;
|
||||
|
||||
public $note = null;
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new Contractqueue();
|
||||
|
||||
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 createFromOrderproduct($op) {
|
||||
$log = mfLoghandler::singleton();
|
||||
|
||||
if(!$op->id) {
|
||||
$log->warning(__METHOD__."(): Invalid OrderProduct object");
|
||||
return false;
|
||||
}
|
||||
|
||||
$order = $op->order;
|
||||
$product = $op->product;
|
||||
|
||||
if(!$order->id || !$product->id) {
|
||||
$log->warning(__METHOD__."(): Invalid Order or Product");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!$order->finish_date || $order->finish_date > date("U")) {
|
||||
$log->warning(__METHOD__."(): Order not finished yet");
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data["order_id"] = $order->id;
|
||||
$data["orderproduct_id"] = $op->id;
|
||||
$data["owner_id"] = $order->owner_id;
|
||||
$data["billingaddress_id"] = $order->billingaddress_id;
|
||||
$data["termination_id"] = ($op->termination_id) ? $op->termination_id : null;
|
||||
$data["product_id"] = $op->product_id;
|
||||
$data["product_name"] = $product->name;
|
||||
$data["product_info"] = $product->description;
|
||||
$data["amount"] = $op->amount;
|
||||
$data["sla_id"] = $product->sla_id;
|
||||
$data["product_external"] = ($product->external) ? $product->external : 0;
|
||||
$data["product_external_id"] = ($product->external) ? $product->external_id : null;
|
||||
$data["price"] = $op->price;
|
||||
$data["price_setup"] = $op->price_setup;
|
||||
$data["price_nne"] = $op->price_nne;
|
||||
$data["price_nbe"] = $op->price_nbe;
|
||||
$data["billing_delay"] = $op->billing_delay;
|
||||
$data["billing_period"] = $op->billing_period;
|
||||
$data["order_date"] = $order->order_date;
|
||||
|
||||
$data["finish_date"] = $order->finish_date;
|
||||
$data["finish_date_by"] = 1;
|
||||
$data["note"] = $order->note;
|
||||
|
||||
$contractq = ContractqueueModel::create($data);
|
||||
$contractq->matchcode = $contractq->generateMatchcode();
|
||||
//var_dump($contract);exit;
|
||||
|
||||
return $contractq;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Contractqueue", "*", "1 = 1 ORDER BY owner_id,`create`");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Contractqueue($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT Contractqueue.* FROM Contractqueue
|
||||
LEFT JOIN Address ON (Contractqueue.owner_id = Address.id)
|
||||
LEFT JOIN OrderProduct ON (Contractqueue.orderproduct_id = OrderProduct.id)
|
||||
LEFT JOIN `Order` ON (OrderProduct.order_id = `Order`.id)
|
||||
LEFT JOIN Product ON (Contractqueue.product_id = Product.id)
|
||||
WHERE $where
|
||||
GROUP BY Contractqueue.id
|
||||
ORDER BY Contractqueue.owner_id,Contractqueue.product_id,Contractqueue.`create`
|
||||
LIMIT 1";
|
||||
//var_dump($sql);exit;
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Contractqueue($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 (
|
||||
SELECT Contractqueue.* FROM Contractqueue
|
||||
LEFT JOIN Address ON (Contractqueue.owner_id = Address.id)
|
||||
LEFT JOIN OrderProduct ON (Contractqueue.orderproduct_id = OrderProduct.id)
|
||||
LEFT JOIN `Order` ON (OrderProduct.order_id = `Order`.id)
|
||||
LEFT JOIN Product ON (Contractqueue.product_id = Product.id)
|
||||
WHERE $where
|
||||
AND (cancel_date IS NULL OR cancel_date > UNIX_TIMESTAMP())
|
||||
GROUP BY Contractqueue.id
|
||||
) contract";
|
||||
|
||||
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 searchActive($filter, $limit = false) {
|
||||
//var_dump($filter);exit;
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT Contractqueue.* FROM Contractqueue
|
||||
LEFT JOIN Address ON (Contractqueue.owner_id = Address.id)
|
||||
LEFT JOIN OrderProduct ON (Contractqueue.orderproduct_id = OrderProduct.id)
|
||||
LEFT JOIN `Order` ON (OrderProduct.order_id = `Order`.id)
|
||||
LEFT JOIN Product ON (Contractqueue.product_id = Product.id)
|
||||
WHERE $where
|
||||
AND (cancel_date IS NULL OR cancel_date > UNIX_TIMESTAMP())
|
||||
GROUP BY Contractqueue.id
|
||||
ORDER BY Contractqueue.owner_id,Contractqueue.`create`";
|
||||
|
||||
if(is_array($limit) && count($limit)) {
|
||||
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
||||
} elseif(is_numeric($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 Contractqueue($data);
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
public static function search($filter, $limit = false) {
|
||||
//var_dump($filter);exit;
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT Contractqueue.* FROM Contractqueue
|
||||
LEFT JOIN Address ON (Contractqueue.owner_id = Address.id)
|
||||
LEFT JOIN OrderProduct ON (Contractqueue.orderproduct_id = OrderProduct.id)
|
||||
LEFT JOIN `Order` ON (OrderProduct.order_id = `Order`.id)
|
||||
LEFT JOIN Product ON (Contractqueue.product_id = Product.id)
|
||||
WHERE $where
|
||||
GROUP BY Contractqueue.id
|
||||
ORDER BY Contractqueue.owner_id,Contractqueue.`create`";
|
||||
|
||||
if(is_array($limit) && count($limit)) {
|
||||
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
||||
} elseif(is_numeric($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 Contractqueue($data);
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
//var_dump($filter);exit;
|
||||
|
||||
if(array_key_exists("id", $filter)) {
|
||||
$id = $filter['id'];
|
||||
if(is_numeric($id)) {
|
||||
$where .= " AND Contractqueue.id like '%$id%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("contract_id", $filter)) {
|
||||
$contract_id = $filter['contract_id'];
|
||||
if(is_numeric($contract_id)) {
|
||||
$where .= " AND Contractqueue.contract_id=$contract_id";
|
||||
} elseif($contract_id === null || $contract_id === false) {
|
||||
$where .= " AND (Contractqueue.contract_id IS NULL OR Contractqueue.contract_id = 0)";
|
||||
} elseif($contract_id === true) {
|
||||
$where .= " AND (Contractqueue.contract_id IS NOT NULL AND Contractqueue.contract_id > 0)";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("owner_id", $filter)) {
|
||||
$owner_id = $filter['owner_id'];
|
||||
if(is_numeric($owner_id)) {
|
||||
$where .= " AND Contractqueue.owner_id=$owner_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("billingaddress_id", $filter)) {
|
||||
$billingaddress_id = $filter['billingaddress_id'];
|
||||
if(is_numeric($billingaddress_id)) {
|
||||
$where .= " AND Contractqueue.billingaddress_id=$billingaddress_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("product_id", $filter)) {
|
||||
$product_id = $filter['product_id'];
|
||||
if(is_numeric($product_id)) {
|
||||
$where .= " AND Contractqueue.product_id=$product_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("order_id", $filter)) {
|
||||
$order_id = $filter['order_id'];
|
||||
if(is_numeric($order_id)) {
|
||||
$where .= " AND `Order`.id=$order_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("orderproduct_id", $filter)) {
|
||||
$orderproduct_id = $filter['orderproduct_id'];
|
||||
if(is_numeric($orderproduct_id)) {
|
||||
$where .= " AND Contractqueue.orderproduct_id=$orderproduct_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("product_name", $filter)) {
|
||||
$product_name = $db->escape($filter['product_name']);
|
||||
if($product_name) {
|
||||
$where .= " AND (Contractqueue.`product_name` like '%$product_name%' OR Product.name like '%$product_name%')";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(array_key_exists("matchcode", $filter)) {
|
||||
$matchcode = $db->escape($filter['matchcode']);
|
||||
if($matchcode) {
|
||||
$where .= " AND Contractqueue.`matchcode` like '%$matchcode%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("rtr_code", $filter)) {
|
||||
$rtr_code = $filter['rtr_code'];
|
||||
if(is_numeric($rtr_code)) {
|
||||
$where .= " AND Contractqueue.rtr_code=$rtr_code";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("customer_number", $filter)) {
|
||||
$customer_number = $filter['customer_number'];
|
||||
if(is_numeric($customer_number)) {
|
||||
$where .= " AND Address.customer_number=$customer_number";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("owner", $filter)) {
|
||||
$owner = FronkDB::singleton()->escape($filter["owner"]);
|
||||
if($owner) {
|
||||
$where .= " AND (Address.company like '%$owner%' OR (CONCAT(Address.firstname, ' ', Address.lastname) like '%$owner%' OR CONCAT(Address.lastname, ' ', Address.firstname) like '%$owner%' ))";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("imported_from", $filter)) {
|
||||
$imported_from = FronkDB::singleton()->escape($filter["imported_from"]);
|
||||
if($imported_from) {
|
||||
$where .= " AND Contractqueue.imported_from like '$imported_from'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("imported_data", $filter)) {
|
||||
$imported_data = FronkDB::singleton()->escape($filter["imported_data"]);
|
||||
if($imported_data) {
|
||||
$where .= " AND Contractqueue.imported_data like '$imported_data'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("add-where", $filter)) {
|
||||
$where .= " ".$filter['add-where'];
|
||||
}
|
||||
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user