WIP Mass Productchange

This commit is contained in:
Frank Schubert
2025-05-08 20:08:09 +02:00
parent 678544ced7
commit 52b8462afc
2 changed files with 182 additions and 0 deletions

View File

@@ -0,0 +1,107 @@
<?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"><a href="<?=self::getUrl("Admin")?>">Admin</a></li>
<li class="breadcrumb-item active">RTR Reporting</li>
</ol>
</div>
<h4 class="page-title">Massenproduktwechsel</h4>
</div>
</div>
</div>
<!-- end page title -->
<div class="row">
<div class="col-12 col-xl-10">
<h3>Produktwechsel erstellen</h3>
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-6">
<div class="alert alert-purple">
Sucht alle aktiven Contracts mit <strong>bisherigem Produkt</strong> und erstellt jeweils einen <strong>Produktwechsel</strong>.
</div>
<form method="post" action="<?=self::getUrl("Admin", "massProductchange", ["do" => "create"])?>">
<div class="form-group">
<label for="old_product_id">Bisheriges Produkt</label>
<select name="old_product_id" class="form-control select2">
<?php foreach(ProductModel::getAll() as $product): ?>
<option value="<?=$product->id?>"><?=$product->name?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<label for="new_product_id">Neues Produkt</label>
<select name="new_product_id" class="form-control select2">
<?php foreach(ProductModel::getAll() as $product): ?>
<option value="<?=$product->id?>"><?=$product->name?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<label for="price_type">Neuer Preis</label>
<select name="price_type" id="price_type" class="form-control">
<option value="keep">Bisherigen Preis beibehalten</option>
<option value="from_new_product">Preis vom neuen Produkt übernehmen</option>
<option value="fixed">Fixen Preis definieren</option>
</select>
</div>
<div class="form-group hidden" id="fix_price_container">
<label for="fix_price">Fixpreis</label>
<input type="text" name="fix_price" class="form-control" placeholder="Neuer Preis" value="">
</div>
<div class="form-group">
<label for="linked_contracts_action">Verknüpfte Contracts</label>
<select name="linked_contracts_action" id="linked_contracts_action" class="form-control">
<option value="keep">übernehmen</option>
<option value="cancel">Kündigen</option>
</select>
</div>
<div class="form-group">
<label for="change_date">Produktwechsel durchführen am</label>
<input type="text" name="change_date" class="form-control" value="">
</div>
<button type="submit" name="preview" value="1" class="btn btn-primary">Vorschau</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
$(".select2").select2({
placeholder: "Bisheriges Produkt auswählen"
});
$("#price_type").change(function() {
if($(this).val() == "fixed") {
$("#fix_price_container").show();
} else {
$("#fix_price_container").hide();
}
});
});
</script>
<?php include(realpath(dirname(__FILE__)."/../../../$mfLayoutPackage")."/footer.php"); ?>

View File

@@ -0,0 +1,75 @@
<?php
class Admin_MassProductchange {
private $request;
private $db;
private $log;
private $flash = [];
public function __construct($request = false) {
$this->request = $request;
$this->db = FronkDB::singleton();
$this->log = mfLoghandler::singleton();
}
public function runRequest() {
$action = $this->request->do;
if(!$action) {
return $this->indexAction();
} else {
$method = $action."Action";
if(method_exists($this, $method)) {
return $this->$method();
} else {
throw new Exception("Method not found", "404");
}
}
}
public function indexAction() {
return [
"template" => "Admin/MassProductchange/Index",
"redirect" => "",
"templateVars" => []
];
}
public function createAction() {
$this->log->debug("Create action called");
$this->log->debug($this->request->getPost());
$old_product_id = $this->request->getPost("old_product_id");
$new_product_id = $this->request->getPost("new_product_id");
if(!$old_product_id || !$new_product_id) {
$this->flash[] = "Beide Produkte werden benötigt.";
return [
"template" => "Admin/MassProductchange/Index",
"redirect" => "",
"templateVars" => []
];
}
$contracts = ContractModel::searchActive(["product_id" => $old_product_id]);
if($this->request->preview) {
return [
"template" => "Admin/MassProductchange/Index",
"redirect" => "",
"templateVars" => ["contracts" => $contracts]
];
}
return [
"template" => "Admin/MassProductchange/Index",
"redirect" => "",
"templateVars" => []
];
}
}