Added fields to Preordercampaign

This commit is contained in:
Frank Schubert
2022-05-11 17:35:21 +02:00
parent 11ede6a5b7
commit ebf2f808f3
13 changed files with 531 additions and 15 deletions

View File

@@ -0,0 +1,71 @@
<?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">Verträge</li>
</ol>
</div>
<h4 class="page-title">Verträge</h4>
</div>
</div>
</div>
<!-- end page title -->
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body mb-3">
<div class="float-left">
<h4 class="header-title">Liste aller Verträge</h4>
</div>
<div class="float-right">
<a class="btn btn-primary mb-2" href="<?=self::getUrl("Contract", "add")?>"><i class="fas fa-plus"></i> Neuen Vertrag anlegen</a>
</div>
<table class="table table-striped table-hover">
<tr>
<th>Inhaber</th>
<th>Produkt</th>
<th>Anschluss</th>
<th>Preis</th>
<th>Preis Setup</th>
<th>Rechnungsperiode</th>
<th>Erstellt</th>
<th>Zuletzt bearbeitet</th>
<th></th>
</tr>
<?php foreach($contracts as $contract): ?>
<tr>
<td><?=$contract->owner->getCompanyOrName()?></td>
<td><?=$contract->product->name?></td>
<td>
<?php if($contract->termination_id): ?>
<?=$contract->termination->building->street?><br />
<?=$contract->termination->building->zip?> <?=$contract->termination->building->city?>
<?php endif; ?>
</td>
<td><?=$contract->price?></td>
<td><?=$contract->price_setup?></td>
<td><?=(12 / $contract->billing_period)?>x Jährlich</td>
<td><?=date('d.m.Y H:i', $contract->create)?> (<?=$contract->creator->name?>)</td>
<td><?=date('d.m.Y H:i', $contract->edit)?> (<?=$contract->editor->name?>)</td>
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
<a href="<?=self::getUrl("Contract", "edit", ["id" => $contract->id])?>"><i class="far fa-edit" title="Vertrag bearbeiten"></i></a>
<a href="<?=self::getUrl("Contract", "cancel", ["id" => $contract->id])?>" class="text-danger" title="Vertrag kündigen"><i class="fas fa-trash"></i></a>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
</div>
</div>
</div>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>

View File

@@ -119,9 +119,9 @@
<label class="col-lg-2 col-form-label" for="type">Vorbestelltyp *</label>
<div class="col-lg-10">
<select class="form-control" name="type" id="type">
<option value="interest" <?=($preorder->type == "interest") ? "selected='selected'" : ""?>>Interessensbekundung</option>
<option value="provision" <?=($preorder->type == "provision") ? "selected='selected'" : ""?>>Vorsorgeanschluss</option>
<option value="order" <?=($preorder->type == "order") ? "selected='selected'" : ""?>>Vollanschluss</option>
<?php if(array_key_exists("interest", $campaign->types)): ?><option value="interest" <?=($preorder->type == "interest") ? "selected='selected'" : ""?>>Interessensbekundung</option><?php endif; ?>
<?php if(array_key_exists("provision", $campaign->types)): ?><option value="provision" <?=($preorder->type == "provision") ? "selected='selected'" : ""?>>Vorsorgeanschluss</option><?php endif; ?>
<?php if(array_key_exists("order", $campaign->types)): ?><option value="order" <?=($preorder->type == "order") ? "selected='selected'" : ""?>>Vollanschluss</option><?php endif; ?>
</select>
</div>
</div>

View File

@@ -70,7 +70,6 @@
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="to">Bis</label>
<div class="col-lg-10">
@@ -78,6 +77,39 @@
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="product_type">Verfügbare Produkte *</label>
<div class="col-lg-10">
<select class="form-control" name="product_type" id="product_type" data-placeholder="Bitte auswählen ...">
<option value="all" <?=($campaign->product_type == "all") ? "selected='selected'" : ""?>>Alle Produkte im Netzgebiet</option>
<option value="setup_only" <?=($campaign->product_type == "setup_only") ? "selected='selected'" : ""?>>Nur Anschlussbestellung, keine Produkte</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="types">Erlaubte Anschlusstypen *</label>
<div class="col-lg-10">
<select class="select2 form-control select2-multiple" name="types[]" id="types" multiple="multiple" data-placeholder="Bitte auswählen ...">
<option value="interest" <?=(is_array($campaign->types) && array_key_exists("interest", $campaign->types)) ? "selected='selected'" : ""?>><?=__("interest", "preorder")?></option>
<option value="provision" <?=(is_array($campaign->types) && array_key_exists("provision", $campaign->types)) ? "selected='selected'" : ""?>><?=__("provision", "preorder")?></option>
<option value="order" <?=(is_array($campaign->types) && array_key_exists("order", $campaign->types)) ? "selected='selected'" : "netowner"?>><?=__("order", "preorder")?></option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="fulfillment">Auftragsabwicklung bei Projektstart *</label>
<div class="col-lg-10">
<select class="form-control" name="fulfillment" id="fulfillment" data-placeholder="Bitte auswählen ...">
<option value="thetool" <?=($campaign->fulfillment == "thetool") ? "selected='selected'" : ""?>>thetool</option>
<option value="thirdparty" <?=($campaign->fulfillment == "thirdparty") ? "selected='selected'" : ""?>>Drittsystem</option>
</select>
</div>
</div>
</div>
</div>
@@ -117,5 +149,12 @@
todayBtn: 'linked',
autoclose: true
});
$("#types").select2({
allowClear: true,
placeholder: "",
closeOnSelect: false
});
</script>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>

View File

@@ -0,0 +1,5 @@
<?php
class Contract extends mfBaseModel {
}

View File

@@ -0,0 +1,57 @@
<?php
class ContractController 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() {
$this->layout()->setTemplate("Contract/Index");
$rfilter = $this->request->filter;
iF(!is_array($rfilter)) {
$rfilter = [];
}
$this->layout->set("filter", $rfilter);
$filter = $this->getPreparedFilter($rfilter);
// pagination defaults
$pagination = [];
$pagination['start'] = 0;
$pagination['count'] = 50;
$pagination['maxItems'] = 0;
if(is_numeric($this->request->s)) {
$pagination['start'] = intval($this->request->s);
}
//var_dump($filter);exit;
$pagination['maxItems'] = ContractModel::count($filter);
$contracts = ContractModel::search($filter, $pagination);
$this->layout()->set("contracts", $contracts);
}
private function getPreparedFilter($filter) {
$new_filter = [];
if(is_array($filter) && count($filter)) {
foreach($filter as $name => $value) {
$new_filter[$name] = $value;
}
}
return $new_filter;
}
}

View File

@@ -0,0 +1,161 @@
<?php
class ContractModel {
public $name = null;
public $description = null;
public $sla_id = null;
public $external = null;
public $external_id;
public $productgroup_id = null;
public $producttech_id = null;
public $price = null;
public $price_setup = null;
public $price_nne = null;
public $price_nbe = null;
public $billing_delay = null;
public $billing_period = null;
public $ivt_id = null;
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 Contract();
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 getAll() {
$items = [];
$db = FronkDB::singleton();
$res = $db->select("Contract", "*", "1 = 1 ORDER BY owner_id,product_id,`create`");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new Contract($data);
}
}
return $items;
}
public static function getFirst() {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("Contract", "*", "$where ORDER BY owner_id,product_id,`create` LIMIT 1");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new Contract($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(*) FROM Contract
LEFT JOIN Address ON (Contract.address_id = Address.id)
WHERE $where
GROUP BY Contract.id
ORDER BY owner_id,product_id,`create`";
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
return $data->cnt;
}
return 0;
}
public static function search($filter, $limit = false) {
//var_dump($filter);exit;
$items = [];
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT Contract.* FROM Contract
LEFT JOIN Address ON (Contract.address_id = Address.id)
WHERE $where
GROUP BY Contract.id
ORDER BY owner_id,product_id,`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[] = new Contract($data);
}
}
return $items;
}
private function getSqlFilter($filter) {
$where = "1=1 ";
$db = FronkDB::singleton();
//var_dump($filter);exit;
if(array_key_exists("owner_id", $filter)) {
$owner_id = $filter['owner_id'];
if(is_numeric($owner_id)) {
$where .= " AND 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";
}
}
if(array_key_exists("product_name", $filter)) {
$product_name = $db->escape($filter['product_name']);
if($product_name) {
$where .= " AND `product_name` like '$product_name'";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}

View File

@@ -199,6 +199,13 @@ class PreorderController extends mfBaseController {
$this->redirect("Preordercampaign");
}
if(!array_key_exists($data['type'], $campaign->types)) {
$this->layout()->setFlash("Bitte Vorbestelltyp auswählen!", "error");
$this->layout()->set("preorder", $preorder);
$this->layout()->set("campaign", $campaign);
return $this->addAction();
}
$product = new Product($data['product_id']);
if(!$product->id) {
$this->layout()->setFlash("Bitte Produkt auswählen!", "error");

View File

@@ -6,6 +6,7 @@ class PreorderModel {
public $termination_id;
public $product_id;
public $type;
public $order_id;
public $price;
public $price_setup;
public $price_nne;

View File

@@ -3,8 +3,45 @@
class Preordercampaign extends mfBaseModel {
private $network;
private $preorders;
private $types;
public function addTypes(Array $types) {
$allowd_types = ["interest","provision","order"];
$new_types = [];
foreach($types as $type) {
if(!in_array($type, $allowd_types)) {
$this->log->debug("$type not in allowed_types");
continue;
}
$new_types[] = $type;
}
//var_dump($new_types);
foreach($allowd_types as $atype) {
$existing = PreordercampaignTypeModel::getFirst(['preordercampaign_id' => $this->id, "type" => $atype]);
//var_dump($existing);exit;
if($existing) {
if(!in_array($atype,$new_types)) {
$existing->delete();
}
} else {
if(in_array($atype, $new_types)) {
$data = [];
$data['preordercampaign_id'] = $this->id;
$data['type'] = $atype;
$nt = PreordercampaignTypeModel::create($data);
$nt->save();
}
}
}
return true;
}
public function getProperty($name) {
if($this->$name == null) {
@@ -13,6 +50,14 @@ class Preordercampaign extends mfBaseModel {
return $this->preorders;
}
if($name == "types") {
$types = PreordercampaignTypeModel::search(['preordercampaign_id' => $this->id]);
foreach($types as $type) {
$this->types[$type->type] = $type;
}
return $this->types;
}
if($name == "creator") {
$user = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
if($user) {

View File

@@ -142,6 +142,19 @@ class PreordercampaignController extends mfBaseController {
$data['to'] = self::dateToTimestamp($r->to);
}
if($r->fulfillment == "thirdparty") {
$data['fulfillment'] = "thirdparty";
} else {
$data['fulfillment'] = "thetool";
}
if($r->product_type == "setup_only") {
$data['product_type'] = "setup_only";
} else {
$data['product_type'] = "all";
}
$data['edit_by'] = $this->me->id;
if($mode == "add") {
@@ -158,6 +171,11 @@ class PreordercampaignController extends mfBaseController {
return $this->add();
}
if(is_array($r->types) && count($r->types)) {
$campaign->addTypes($r->types);
}
$this->layout()->setFlash("Vorbestellkampagne erfolgreich gespeichert.", "success");
//$this->redirect("Preordercampaign", "Edit", ['id' => $new_id]);
$this->redirect("Preordercampaign");

View File

@@ -1,19 +1,20 @@
<?php
class PreordercampaignModel {
public $name = null;
public $network_id = null;
public $description = null;
public $area = null;
public $from = null;
public $to = null;
public $name;
public $network_id;
public $fulfillment;
public $description;
public $area;
public $from;
public $to;
public $note = null;
public $note;
public $create_by = null;
public $edit_by = null;
public $create = null;
public $edit = null;
public $create_by;
public $edit_by;
public $create;
public $edit;
public static function create(Array $data) {
$model = new Preordercampaign();

View File

@@ -0,0 +1,5 @@
<?php
class PreordercampaignType extends mfBaseModel {
}

View File

@@ -0,0 +1,106 @@
<?php
class PreordercampaignTypeModel {
public $preordercampaign_id;
public $type;
public $create_by;
public $edit_by;
public $create;
public $edit;
public static function create(Array $data) {
$model = new PreordercampaignType();
foreach($data as $field => $value) {
if(property_exists(get_called_class(), $field)) {
$model->$field = $value;
}
}
$me = mfValuecache::singleton()->get("me");
if(!$me) {
$me = new User();
$me->loadMe();
mfValuecache::singleton()->set("me", $me);
}
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 getAll() {
$items = [];
$db = FronkDB::singleton();
$res = $db->select("PreordercampaignType", "*", "ORDER BY preordercampaign_id, type");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new PreordercampaignType($data);
}
}
return $items;
}
public static function getFirst($filter) {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("PreordercampaignType", "*", "$where ORDER BY preordercampaign_id, type");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new PreordercampaignType($data);
if($item->id) {
return $item;
} else {
return null;
}
}
return null;
}
public static function search($filter) {
$items = [];
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("PreordercampaignType", "*", "$where ORDER BY preordercampaign_id, type");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new PreordercampaignType($data);
}
}
return $items;
}
private function getSqlFilter($filter) {
$where = "1=1 ";
//var_dump($filter);exit;
if(array_key_exists("preordercampaign_id", $filter)) {
$preordercampaign_id = $filter['preordercampaign_id'];
if(is_numeric($preordercampaign_id)) {
$where .= " AND preordercampaign_id=$preordercampaign_id";
}
}
if(array_key_exists("type", $filter)) {
$type = FronkDB::singleton()->escape($filter['type']);
if($type) {
$where .= " AND type='$type'";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}