Added termination select to Product/Form

This commit is contained in:
Frank Schubert
2021-07-30 20:03:24 +02:00
parent ec0abff225
commit 0a5e447587
11 changed files with 249 additions and 28 deletions

View File

@@ -345,7 +345,7 @@
<!-- product lines -->
<div class="row">
<!-- line 1 -->
<div class="col-5">
<div class="col-4">
<label class="form-label" for="product_id-<?=$product->id?>">Produkt</label>
<select name="products[<?=$product->id?>][product_id]" id="product_id-<?=$product->id?>" class="form-control" onchange="updateProduct(<?=$product->id?>)">
<option></option>
@@ -355,7 +355,7 @@
</select>
</div>
<div class="col-3">
<div class="col-2">
<label class="form-label" for="amount-<?=$product->id?>">Anzahl/Menge</label>
<input type="text" class="form-control" name="products[<?=$product->id?>][amount]" id="amount-<?=$product->id?>" value="<?=$product->formatAmount()?>" placeholder="Anzahl/Menge" />
</div>
@@ -370,9 +370,29 @@
<label class="form-label" for="price-<?=$product->id?>">Preis p. Periode</label>
<input type="text" class="form-control" name="products[<?=$product->id?>][price]" id="price-<?=$product->id?>" value="<?=$this::dotToComma($product->price)?>" placeholder="Preis p. Periode" />
</div>
<div class="col-2">
<label class="form-label" for="price_setup-<?=$product->id?>">Preis Setup</label>
<input type="text" class="form-control" name="products[<?=$product->id?>][price_setup]" id="price_setup-<?=$product->id?>" value="<?=$this::dotToComma($product->price_setup)?>" placeholder="Preis Setup" />
</div>
</div>
<?php if(array_key_exists(TT_ATTRIB_TERMINATION_REQUIRED_NAME, $product->product->attributes) && $product->product->attributes[TT_ATTRIB_TERMINATION_REQUIRED_NAME] == 1): ?>
<div class="row mt-1 mb-2">
<!-- line to choose termination -->
<div class="col-12">
<label class="form-label" for="termination_id-<?=$product->id?>">Anschluss</label>
<select name="products[<?=$product->id?>][termination_id]" id="termination_id-<?=$product->id?>" class="form-control select2">
<option></option>
<?php foreach($terminations as $t): ?>
<option value="<?=$t->id?>" <?=($t->id == $product->termination_id) ? "selected='selected'" : ""?>><?=$t->code?> - <?=$t->getAddress()?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<?php endif; ?>
<div class="row mt-1 mb-2">
<!-- line 2 -->
<div class="col-10">
@@ -380,9 +400,10 @@
<textarea class="form-control" name="products[<?=$product->id?>][description]" id="description-<?=$product->id?>" placeholder="Zusatztext"><?=$product->description?></textarea>
</div>
<div class="col-2">
<label class="form-label" for="price_setup-<?=$product->id?>" >Preis Setup</label>
<input type="text" class="form-control" name="products[<?=$product->id?>][price_setup]" id="price_setup-<?=$product->id?>" value="<?=$this::dotToComma($product->price_setup)?>" placeholder="Preis Setup" />
<label class="form-label" for="billing_delay-<?=$product->id?>" >Verzögerter Verrechnungsstart</label>
<input type="text" class="form-control" name="products[<?=$product->id?>][billing_delay]" id="billing_delay-<?=$product->id?>" value="" placeholder="(Monate)" />
</div>
</div>
</div>
</div>
@@ -402,7 +423,7 @@
<!-- product lines -->
<div class="row">
<!-- line 1 -->
<div class="col-5">
<div class="col-4">
<label class="form-label" for="product_id-new">Produkt</label>
<select name="products[new][product_id]" id="product_id-new" class="form-control" onchange="updateProduct('new')">
<option></option>
@@ -411,7 +432,7 @@
<?php endforeach; ?>
</select>
</div>
<div class="col-3">
<div class="col-2">
<label class="form-label" for="amount-new">Anzahl/Menge</label>
<input type="text" class="form-control" name="products[new][amount]" id="amount-new" value="" placeholder="Anzahl/Menge (Standard: 1)" />
</div>
@@ -427,6 +448,24 @@
<input type="text" class="form-control" name="products[new][price]" id="price-new" value="" placeholder="Preis p. Periode" />
</div>
<div class="col-2">
<label class="form-label" for="price_setup-new" >Preis Setup</label>
<input type="text" class="form-control" name="products[new][price_setup]" id="price_setup-new" value="" placeholder="Preis Setup" />
</div>
</div>
<div class="row mt-1 mb-2 hidden" id="termination_id-new-line">
<!-- line to choose termination -->
<div class="col-12">
<label class="form-label" for="termination_id-new">Anschluss</label>
<select name="products[new][termination_id]" id="termination_id-new" class="form-control">
<option></option>
<?php foreach($terminations as $t): ?>
<option value="<?=$t->id?>"><?=$t->code?> - <?=$t->getAddress()?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="row mt-1 mb-2">
@@ -437,8 +476,8 @@
</div>
<div class="col-2">
<label class="form-label" for="price_setup-new" >Preis Setup</label>
<input type="text" class="form-control" name="products[new][price_setup]" id="price_setup-new" value="" placeholder="Preis Setup" />
<label class="form-label" for="billing_delay-new" >Verzögerter Verrechnungsstart</label>
<input type="text" class="form-control" name="products[new][billing_delay]" id="billing_delay-new" value="" placeholder="(in Monaten)" />
</div>
</div>
@@ -456,7 +495,7 @@
<div class="card">
<div class="card-body">
<?php if(!$order->id): ?>
<i>Verfügbar nach speichern.</i>
<i class="text-pink">Verfügbar nach speichern.</i>
<?php else: ?>
<?php if(is_array($order->files) && count($order->files)): ?>
@@ -564,6 +603,13 @@
placeholder: ""
});
$('.select2').each(function(){
$(this).select2({
allowClear: true,
placeholder: ""
});
});
$('#owner_id').change(function() {
var val = $('#owner_id').val();
@@ -620,6 +666,20 @@
$('#billing_period-' + id).val(p.billing_period);
$('#price-' + id).val(p.price);
$('#price_setup-' + id).val(p.price_setup);
console.log(p.attributes);
if(typeof p.attributes === 'object' && "termination_required" in p.attributes && p.attributes.termination_required == 1) {
console.log("termination_required");
$('#termination_id-new-line').show();
console.log($('#termination_id-new').val());
$('#termination_id-new').select2({
allowClear: true,
placeholder: ""
});
} else {
$('#termination_id-new-line').hide();
}
},
'json');

View File

@@ -21,7 +21,7 @@
</footer>
<!-- end Footer -->
<script type="text/javascript" src="<?=self::getResourcePath()?>assets/js/vendor.min.js"></script>
<script type="text/javascript" src="<?=self::getResourcePath()?>assests/js/vendor.min.js"></script>
</body>
</html>

View File

@@ -1,8 +0,0 @@
<script type="text/javascript" src="<?=self::getResourcePath()?>js/jquery.min.js"></script>
<script type="text/javascript" src="<?=self::getResourcePath()?>js/popper.min.js"></script>
<script type="text/javascript" src="<?=self::getResourcePath()?>js/bootstrap.min.js"></script>
<script type="text/javascript" src="<?=self::getResourcePath()?>js/bootstrap-autocomplete.min.js"></script>
<script type="text/javascript" src="<?=self::getResourcePath()?>fontawesome/js/all.min.js"></script>
<script type="text/javascript" src="<?=self::getResourcePath()?>js/jquery.datetimepicker.full.min.js"></script>
<script type="text/javascript" src="<?=self::getResourcePath()?>js/select2.min.js"></script>

View File

@@ -151,7 +151,7 @@
<ul class="list-unstyled topnav-menu-left m-0">
<li class="logo-box float-left">
<a href="index.html" class="logo">
<a href="<?=self::getUrl("Dashboard")?>" class="logo">
<span class="logo-lg">
<img src="<?=self::getResourcePath()?>assets/images/the-tool-logo-kopf.png" alt="" style="height:80px; padding-top:12px; padding-left:32px;">
</span>

View File

@@ -10,6 +10,20 @@ class Building extends mfBaseModel {
private $pipeworker;
private $terminations;
public function getAddress($singelLine = false) {
if(!$this->id) {
return false;
}
$address = $this->street."\n".$this->zip." ".$this->city;
if($singelLine) {
$address = str_replace("\n", " ", $address);
}
return $address;
}
public function getNewObjectCode() {
if(!$this->zip) {
return false;

View File

@@ -1,7 +1,8 @@
<?php
class File extends mfBaseModel {
private $creator;
private $editor;
public function delete() {
if($this->id) {
@@ -28,4 +29,36 @@ class File extends mfBaseModel {
}
return false;
}
public function getProperty($name) {
if($this->$name == null) {
if(!$this->id) {
return null;
}
if($name == "creator") {
$this->creator = new User($this->create_by);
return $this->creator;
}
if($name == "editor") {
$this->editor = new User($this->edit_by);
return $this->editor;
}
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = new $classname($this->$idfield);
if($this->$name->id) {
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}
}

View File

@@ -21,9 +21,11 @@ class OrderController extends mfBaseController {
}
protected function addAction() {
// TODO: filter by network permissions
$this->layout()->setTemplate("Order/Form");
$this->layout()->set("addresses", AddressModel::search(['parents_only' => 1]));
$this->layout()->set("products", ProductModel::getAll());
$this->layout()->set("terminations", TerminationModel::getAll());
}
@@ -264,6 +266,16 @@ class OrderController extends mfBaseController {
if(!$product_id || !$p["product_id"]) {
continue;
}
$prod = new Product($p['product_id']);
if(!$prod->id) {
$this->log->warn(__CLASS__."::save() Invalid product: ".$p['product_id']);
}
$product_data = [];
$product_data["order_id"] = $new_id;
$product_data["product_id"] = $p["product_id"];
@@ -275,6 +287,17 @@ class OrderController extends mfBaseController {
$product_data["billing_delay"] = 0;
$product_data["billing_period"] = $p["billing_period"];
$require_term = false;
if(array_key_exists(TT_ATTRIB_TERMINATION_REQUIRED_NAME, $prod->attributes) && $prod->attributes[TT_ATTRIB_TERMINATION_REQUIRED_NAME] == 1) {
$require_term = true;
if(!$p['termination_id']) {
$this->layout()->setFlash("Produkt nicht gespeichert. Produkt erfordert Anschluss.", "warn");
continue;
}
$product_data['termination_id'] = $p['termination_id'];
}
if($product_id == "new") {
$product = OrderProductModel::create($product_data);
} else {

View File

@@ -2,6 +2,8 @@
class OrderFile extends mfBaseModel {
private $file;
private $creator;
private $editor;
public function getProperty($name) {
if($this->$name == null) {

View File

@@ -63,10 +63,10 @@ class ProductController extends mfBaseController {
$data['description'] = $r->description;
$data['sla_id'] = $r->sla_id;
$data['external'] = ($r->external == 1) ? "1" : "0";
$data['price_nne'] = Layout::commaToDot($r->price_nne);
$data['price_nbe'] = Layout::commaToDot($r->price_nbe);
$data['price'] = Layout::commaToDot($r->price);
$data['price_setup'] = Layout::commaToDot($r->price_setup);
$data['price_nne'] = ($data['price_nne']) ? Layout::commaToDot($r->price_nne) : 0;
$data['price_nbe'] = ($data['price_nbe']) ? Layout::commaToDot($r->price_nbe) : 0;
$data['price'] = ($data['price']) ? Layout::commaToDot($r->price) : 0;
$data['price_setup'] = ($data['price_setup']) ? Layout::commaToDot($r->price_setup) : 0;
$data['billing_period'] = $r->billing_period;
$data['billing_delay'] = $r->billing_delay;
$data['ivt_id'] = ($r->ivt_id) ? $r->ivt_id : null;
@@ -216,6 +216,15 @@ class ProductController extends mfBaseController {
return false;
}
if(is_array($product->attributes) && count($product->attributes)) {
$attributes = $product->attributes;
$product->data->attributes = [];
foreach($attributes as $attrib) {
$product->data->attributes[$attrib->name] = $attrib->value;
}
}
return ["product" => $product->data, "form_id" => $form_id];
}
}

View File

@@ -10,6 +10,25 @@ class Termination extends mfBaseModel {
private $editor;
public function getAddress($singelLine = false) {
if(!$this->id) {
return false;
}
$b = $this->getProperty("building");
$address = $b->street;
if($this->name) {
$address .= " ".$this->name;
}
$address .= "\n".$b->zip." ".$b->city;
if($singelLine) {
$address = str_replace("\n", " ", $address);
}
return $address;
}
public function getNewObjectCode() {
if(!$this->building_id) {
return false;
@@ -51,6 +70,8 @@ class Termination extends mfBaseModel {
return $code;
}
public function getProperty($name) {
if($this->$name == null) {

View File

@@ -0,0 +1,67 @@
CREATE TABLE `File` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(1024) NOT NULL,
`description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
`filename` varchar(1024) NOT NULL,
`store_filename` varchar(1024) NOT NULL,
`orig_filename` varchar(1024) NOT NULL,
`subfolder` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
`create_by` int NOT NULL,
`edit_by` int NOT NULL,
`create` int NOT NULL,
`edit` int NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
CREATE TABLE `Order` (
`id` int NOT NULL AUTO_INCREMENT,
`owner_id` int DEFAULT NULL,
`billingaddress_id` int DEFAULT NULL,
`order_date` int NOT NULL,
`finish_date` int DEFAULT NULL COMMENT 'timestamp',
`billing_type` enum('invoice','sepa') CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`bank_account_bank` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`bank_account_owner` varchar(1024) NOT NULL,
`bank_account_iban` varchar(255) NOT NULL,
`bank_account_bic` varchar(64) NOT NULL,
`allow_contact` tinyint NOT NULL DEFAULT '0',
`allow_spin` tinyint NOT NULL DEFAULT '0',
`note` text NOT NULL,
`create_by` int NOT NULL,
`edit_by` int NOT NULL,
`create` int NOT NULL,
`edit` int NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
CREATE TABLE `OrderFile` (
`id` int NOT NULL AUTO_INCREMENT,
`order_id` int NOT NULL,
`file_id` int NOT NULL,
`name` varchar(1024) NOT NULL,
`description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
`create_by` int NOT NULL,
`edit_by` int NOT NULL,
`create` int NOT NULL,
`edit` int NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
CREATE TABLE `OrderProduct` (
`id` int NOT NULL AUTO_INCREMENT,
`order_id` int NOT NULL,
`product_id` int NOT NULL,
`amount` decimal(9,6) NOT NULL DEFAULT '1.000000',
`pos` int NOT NULL,
`description` text NOT NULL,
`price` int NOT NULL DEFAULT '0',
`price_setup` int NOT NULL DEFAULT '0',
`billing_delay` int NOT NULL DEFAULT '0' COMMENT 'in months',
`billing_period` int NOT NULL COMMENT 'in months',
`note` text NOT NULL,
`create_by` int NOT NULL,
`edit_by` int NOT NULL,
`create` int NOT NULL,
`edit` int NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;