Contract WIP

This commit is contained in:
Frank Schubert
2022-06-13 17:27:08 +02:00
parent 121312cdc3
commit e5233568a3
5 changed files with 386 additions and 32 deletions
+242 -11
View File
@@ -57,19 +57,132 @@
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="product_name">Individueller Produktname</label>
<label class="col-lg-2 col-form-label" for="matchcode">Matchcode</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="product_name" id="product_name" value="<?=$contract->product_name?>">
<input type="text" class="form-control" name="matchcode" id="matchcode" value="<?=$contract->matchcode?>">
<small class="font-italic">Eindeutige Identifizierung das Produkts. Z.B. Anschlussadresse, Domainname usw.</small>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="matchcode">Matchcode</label>
<label class="col-lg-2 col-form-label" for="product_name">Individueller Produktname</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="matchcode" id="matchcode" value="<?=$contract->matchcode?>">
<input type="text" class="form-control" name="product_name" id="product_name" value="<?=$contract->product_name?>">
<small class="font-italic">Scheint statt dem echten Produktnamen auf der Rechnung auf</small>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="product_info">Produkt Zusatztext</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="product_info" id="product_info" value="<?=$contract->product_info?>">
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="amount">Anzahl</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="amount" id="product_info" placeholder="1" value="<?=$contract->amount?>">
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="price">Preis</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="price" id="price" value="<?=$contract->price?>">
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="price_setup">Preis Setup</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="price" id="price_setup" value="<?=$contract->price_setup?>">
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="price_nne">Preis NNE</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="price_nne" id="price_nne" value="<?=$contract->price_nne?>">
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="price_nbe">Preis NBE</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="price_nbe" id="price_nbe" value="<?=$contract->price_nbe?>">
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="billing_period">Verrechnungsperiode</label>
<div class="col-lg-10">
<select class="form-control" name="products[<?=$i?>][billing_period]" id="billing_period-<?=$i?>" placeholder="Verrechnungsperiode">
<option value="1" <?=($product->billing_period == 1) ? "selected='selected'" : ""?>>Monatlich</option>
<option value="12" <?=($product->billing_period == 12) ? "selected='selected'" : ""?>>Jährlich</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="billing_delay">Verzögerter Verrechnungsstart</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="billing_delay" id="billing_delay" placeholder="Freimonate" value="<?=$contract->billing_delay?>">
</div>
</div>
<hr />
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="finish_date">Fertigstellungsdatum</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="finish_date" id="finish_date" value="<?=$contract->finish_date?>">
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="cancel_date">Kündigungsdatum</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="cancel_date" id="cancel_date" value="<?=$contract->cancel_date?>">
</div>
</div>
<!--
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="price_reason">Rabatt</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="price" id="price" value="<?=$contract->price?>">
</div>
</div>
-->
</div>
</div>
<div class="card">
<div class="card-body" id="link-container">
<h4>Verknüpfungen</h4>
<?php $linknum = 1337; ?>
<div class="form-group row" id="link-<?=$linknum?>">
<label class="col-lg-2 col-form-label" for="links_<?=$linknum?>_contract_id"></label>
<div class="col-lg-6">
<div class="input-group mb-3">
<div class="input-group-prepend">
<select class="form-control" name="links[<?=$linknum?>][type]">
<option value="link">Verknüpfung</option>
<option value="upgrade">Upgrade</option>
<option value="downgrade">Downgrade</option>
<option value="relocation">Umzug</option>
<option value="productchange">Produktwechsel</option>
</select>
</div>
<!--input type="text" class="form-control" name="links[<?=$linknum?>][contract_id]" id="links_<?=$linknum?>_contract_id" placeholder="Contact ID oder Suche nach Produkt, Matchcode, Kunde" value="<?=$contract->cancel_date?>"-->
<select class="form-control basicAutoComplete link-autocomplete" autocomplete="off" name="links[<?=$linknum?>][contract_id]" id="links_<?=$linknum?>_contract_id" data-linknum="<?=$linknum?>" data-url="<?=self::getUrl('Contract','api')?>?do=findContract&autocomplete=1" placeholder="Contact ID oder Suche nach Produkt, Matchcode, Kunde" data-noresults-text="Keine Suchergebnisse">
<option></option>
</select>
<div class="input-group-append">
<button type="button" class="btn btn-danger" onclick="clearNewLink(<?=$linknum?>)"><i class="fas fa-xmark-large mr-1"></i> Entfernen</button>
</div>
</div>
</div>
</div>
</div>
</div>
@@ -101,11 +214,31 @@
</div>
<script type="text/javascript">
$('#finish_date').datepicker({
language: 'de',
format: "dd.mm.yyyy",
showWeekDays: true,
todayBtn: 'linked',
autoclose: true
});
$('#cancel_date').datepicker({
language: 'de',
format: "dd.mm.yyyy",
showWeekDays: true,
todayBtn: 'linked',
autoclose: true
});
$(".select2").select2({
allowClear: true,
placeholder: ""
});
/*
* customer autocomplete
*/
// kunde
<?php if($contract->owner_id && is_object(($contract->owner))): ?>
$('#owner_id').autoComplete('set', { value: <?=$contract->owner_id?>, text: '<?=($contract->owner_id) ? str_replace("'", "\\'", str_replace(["\n", "\r"], " ", $contract->owner->getCompanyOrName()))." (".$contract->owner->zip." ".$contract->owner->city.", ".$contract->owner->street.")".(($contract->owner->customer_number) ? " [".$contract->owner->customer_number."]" : "") : ""?>'});
@@ -150,8 +283,12 @@
);
});
// customer autocomplete
// rechnungsadresse
/*
* 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.")" : ""?>'});
<?php else: ?>
@@ -170,11 +307,11 @@
$('#billingaddress_id').autoComplete('set', null);
}
});
// billingaddress autocomplete
// Produkt
// kunde
/*
* product autocomplete
*/
<?php if($contract->product_id && is_object(($contract->product))): ?>
$('#product_id').autoComplete('set', { value: <?=$contract->product_id?>, text: '<?=($contract->product_id) ? str_replace("'", "\\'", str_replace(["\n", "\r"], " ", $contract->product->name))." [".$contract->product_id."]" : ""?>'});
<?php else: ?>
@@ -193,15 +330,109 @@
$('#product_id').autoComplete('set', null);
}
});
// product autocomplete
<?php if($contract->owner_id && is_object(($contract->owner))): ?>
//$('.link-autocomplete').autoComplete('set', { value: <?=$contract->owner_id?>, text: '<?=($contract->owner_id) ? str_replace("'", "\\'", str_replace(["\n", "\r"], " ", $contract->owner->getCompanyOrName()))." (".$contract->owner->zip." ".$contract->owner->city.", ".$contract->owner->street.")".(($contract->owner->customer_number) ? " [".$contract->owner->customer_number."]" : "") : ""?>'});
<?php else: ?>
//$('.link-autocomplete').autoComplete();
<?php endif; ?>
$('.link-autocomplete').autoComplete();
$('.link-autocomplete').keydown(function() {
if(event.keyCode == 13) {
event.preventDefault();
return false;
}
});
/*
* Links autocomplete
*/
$('.link-autocomplete').on("autocomplete.select", function(evt, item) {
autocompleteSelect(evt,item);
});
function autocompleteSelect(evt, item) {
if(item && item.value === 0) {
$('.link-autocomplete').autoComplete('set', null);
return;
}
var match = evt.currentTarget.id.match(/links_(\d+)_contract_id/);
var link_num = match[1];
if(!link_num) {
console.log("Couldn't find selected Link");
}
addLink(Number(link_num) + 1);
}
function deleteLink(linknum) {
}
function addLink(linknum) {
if(!linknum) {
console.log("no linknum");
return false;
}
if($("#links_" + linknum + "_contract_id").length) {
console.log("gibs scho");
return false;
}
var new_link = '<div class="form-group row" id="link-' + linknum + '"> \
<label class="col-lg-2 col-form-label" for="links_' + linknum + '_contract_id"></label> \
<div class="col-lg-6"> \
<div class="input-group mb-3"> \
<div class="input-group-prepend"> \
<select class="form-control" name="links[' + linknum + '][type]"> \
<option value="link">Verknüpfung</option> \
<option value="upgrade">Upgrade</option> \
<option value="downgrade">Downgrade</option> \
<option value="relocation">Umzug</option> \
<option value="productchange">Produktwechsel</option> \
</select> \
</div> \
<select class="form-control basicAutoComplete link-autocomplete" autocomplete="off" name="links[' + linknum + '][contract_id]" id="links_' + linknum + '_contract_id" data-linknum="' + linknum + '" data-url="<?=self::getUrl('Contract','api')?>?do=findContract&autocomplete=1" placeholder="Contact ID oder Suche nach Produkt, Matchcode, Kunde" data-noresults-text="Keine Suchergebnisse"> \
<option></option> \
</select> \
<div class="input-group-append"> \
<button type="button" class="btn btn-danger" onclick="clearNewLink(' + linknum + ')"><i class="fas fa-xmark-large mr-1"></i> Entfernen</button> \
</div> \
</div> \
</div> \
</div>';
$('#link-container').append(new_link);
//$('#links_' + linknum + '_contract_id').autocomplete();
$('#links_' + linknum + '_contract_id').autoComplete();
$('#links_' + linknum + '_contract_id').keydown(function() {
if(event.keyCode == 13) {
event.preventDefault();
return false;
}
});
$('#links_' + linknum + '_contract_id').on("autocomplete.select", function(evt, item) {
autocompleteSelect(evt,item);
});
}
function clearNewLink(linknum) {
if(!$("#link-" + linknum).length) {
return;
}
// only remove is not the only one
if($('#link-container').find('div.row').length > 1) {
$("#link-" + linknum).remove();
}
}
// disable mousewheel on input number field when in focus
$('form').on('focus', 'input[type=number]', function (e) {
-16
View File
@@ -54,9 +54,6 @@ class Address extends mfBaseModel {
$this->phoneparts = [$cc,$num];
return $this->phoneparts;
}
public function getCompanyOrName($returnParent = false) {
@@ -121,19 +118,6 @@ class Address extends mfBaseModel {
return $spin;
}
public function toArray() {
if(!$this->id) {
return [];
}
$a = [];
$a['id'] = $this->id;
foreach($this->data as $key => $value) {
$a[$key] = $value;
}
return $a;
}
public function getProperty($name) {
if($this->$name == null) {
+101
View File
@@ -65,4 +65,105 @@ class ContractController extends mfBaseController {
return $this->addAction();
}
protected function apiAction() {
if(!$this->me->is(["Admin"])) {
$this->redirect("Dashboard");
}
$do = $this->request->do;
$data = [];
switch($do) {
case "getContract":
$return = $this->getContractApi();
break;
case "findContract":
$return = $this->findContractApi();
default:
$return = false;
}
if(!is_array($return) || !count($return)) {
$data = ["status" => "error"];
$this->returnJson($data);
}
$data['status'] = "OK";
$data['result'] = $return;
$this->returnJson($data);
}
private function getContractApi() {
$contract_id = $this->request->contract_id;
if(!is_numeric($contract_id) || $contract_id < 1) {
return false;
}
$form_id = false;
if($this->request->form_id) {
$form_id = $this->request->form_id;
}
$contract = new Contract($contract_id);
if(!$contract->id) {
return false;
}
$data = $contract->toArray();
return ["contract" => $data, "form_id" => $form_id];
}
private function findContractApi() {
$search = trim($this->request->q);
$autocomplete = $this->request->autocomplete;
$contracts = [];
if(is_numeric($search)) {
$c = new Contract($search);
if($c->id) {
if(!array_key_exists($c->id, $contracts)) {
$contracts[$c->id] = $c;
}
}
foreach(["id", "owner_id", "product_id"] as $search_key) {
foreach(ContractModel::search([$search_key => $search]) as $c) {
if(!array_key_exists($c->id, $contracts)) {
$contracts[$c->id] = $c;
}
}
}
}
foreach(["product_name", "matchcode", "owner"] as $search_key) {
foreach(ContractModel::search([$search_key => $search]) as $c) {
if(!array_key_exists($c->id, $contracts)) {
$contracts[$c->id] = $c;
}
}
}
if(!is_array($contracts) && !count($contracts)) {
return false;
}
$results = [];
// return bootstrap-autocomplete format
foreach($contracts as $contract) {
//$result = ['value' => $contract->id, 'text' => str_replace("'", "\\'", str_replace(["\n", "\r"], " ",$contract->name))];
$result = ['value' => $contract->id, 'text' => $contract->id.": ".$contract->product_name." [".$contract->matchcode."] (".$contract->owner->getCompanyOrName().", ".$contract->owner->street.", ".$contract->owner->zip." ".$contract->owner->city.")"];
$results[] = $result;
if(count($results) > 15) {
$results[] = ['value' => 0, 'text' => "&nbsp;&nbsp;--> &nbsp;&nbsp;Mehr Suchergebnisse vorhanden. Bitte Suchbegriff genauer definieren &nbsp;&nbsp;<--"];
break;
}
}
$this->returnJson($results);
}
}
+28 -4
View File
@@ -135,7 +135,7 @@ class ContractModel {
$res = $db->query($sql);
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new Contract($data);
$items[$data->id] = new Contract($data);
}
}
@@ -148,17 +148,25 @@ class ContractModel {
$db = FronkDB::singleton();
//var_dump($filter);exit;
if(array_key_exists("id", $filter)) {
$id = $filter['id'];
if(is_numeric($id)) {
$where .= " AND Contract.id like '%$id%'";
}
}
if(array_key_exists("owner_id", $filter)) {
$owner_id = $filter['owner_id'];
if(is_numeric($owner_id)) {
$where .= " AND owner_id=$owner_id";
$where .= " AND Contract.owner_id=$owner_id";
}
}
if(array_key_exists("product_id", $filter)) {
$product_id = $filter['product_id'];
if(is_numeric($product_id)) {
$where .= " AND product_id=$product_id";
$where .= " AND Contract.product_id=$product_id";
}
}
@@ -172,10 +180,26 @@ class ContractModel {
if(array_key_exists("product_name", $filter)) {
$product_name = $db->escape($filter['product_name']);
if($product_name) {
$where .= " AND `product_name` like '$product_name'";
$where .= " AND (Contract.`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 Contract.`matchcode` like '%$matchcode%'";
}
}
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%' ))";
}
}
//var_dump($filter, $where);exit;
return $where;
}
+15 -1
View File
@@ -218,8 +218,22 @@ class mfBaseModel {
}
}
// generic functions for entity-classes
public function toArray() {
if(!$this->id) {
return [];
}
$item = [];
$item['id'] = $this->id;
foreach($this->data as $key => $value) {
$item[$key] = $value;
}
return $item;
}
// generic functions for entity-classes
public function __toString() {
return (string) $this->data->Name;
}