conditional oaid assignment on unit creation
This commit is contained in:
@@ -127,7 +127,11 @@
|
||||
<tr>
|
||||
<td><a href="<?=self::getUrl("ADBWohneinheit", "edit", ["id" => $unit->id])?>"><i class="fas fa-edit"></i></a></td>
|
||||
<td><?=$unit->id?></td>
|
||||
<td class="text-pink"><?=$unit->oaid?></td>
|
||||
<td class="text-pink">
|
||||
<?php if($unit->oaid && OpenAccessIdModel::getFirst(["oaid" => $unit->oaid])): ?>
|
||||
<a href="<?=self::getUrl("OpenAccessId", "", ["filter" => ["oaid" => $unit->oaid]])?>" class="text-pink" target="_blank"><?=$unit->oaid?></a>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td class="text-monospace"><?=$unit->status->code?> - <?=$unit->status->name?></td>
|
||||
<td><?=((string)$unit) ? "<strong>".(string)$unit."</strong>" : ""?></td>
|
||||
<td><?=($unit->extref) ? "[".$unit->extref."]" : ""?></td>
|
||||
|
||||
101
Layout/default/OpenAccessId/ChangeUnit.php
Normal file
101
Layout/default/OpenAccessId/ChangeUnit.php
Normal file
@@ -0,0 +1,101 @@
|
||||
|
||||
<?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("AddressDB")?>">Open Access ID</a></li>
|
||||
<li class="breadcrumb-item active"><?=($oaid->id) ? "bearbeiten" : "Neu" ?></li>
|
||||
</ol>
|
||||
</div>
|
||||
<h4 class="page-title">Wohneinheit</h4>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- end page title -->
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
|
||||
<div class="card bg-light">
|
||||
<div class="card-body">
|
||||
<h4 class="header-title mb-2"><?=($oaid->id) ? "Wohneinheit bearbeiten" : "Neue Adresse"?></h4>
|
||||
|
||||
<form class="form-horizontal" method="post" action="<?=self::getUrl("OpenAccessId", "changeUnit")?>">
|
||||
<input type="hidden" name="id" value="<?=$oaid->id?>" />
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label">OAID</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="text" class="form-control" value="<?=$oaid->oaid?>" disabled="disabled" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label">Bisheriger Anschnluss</label>
|
||||
<div class="col-lg-10">
|
||||
<?php if($oaid->adb_wohneinheit_id && is_object($oaid->adb_wohneinheit)): ?>
|
||||
<input type="text" class="form-control" disabled="disabled"
|
||||
value="[<?=$oaid->adb_wohneinheit->hausnummer->strasse->gemeinde->name?>] <?=$oaid->adb_wohneinheit->hausnummer->plz->plz?><?=$oaid->adb_wohneinheit->hausnummer->ortschaft->name?>, <?=$oaid->adb_wohneinheit->hausnummer->strasse->name?><?=$oaid->adb_wohneinheit->hausnummer->hausnummer?><?=((string)$oaid->adb_wohneinheit) ? " - ".(string)$oaid->adb_wohneinheit : ""?>"
|
||||
/>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="new_unit_id">Neuer Anschluss</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="text" class="form-control" id="new_unit_id" value="<?=$new_unit_id?>" />
|
||||
<small>Wohneinheit ID</small>
|
||||
<p id="new_unit_text" class="text-pink"></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2"></label>
|
||||
<div class="col-lg-10">
|
||||
<button type="submit" class="btn btn-primary">Speichern</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$("#new_unit_id").change(function() {
|
||||
var id = $("#new_unit_id").val();
|
||||
if(!id) return;
|
||||
|
||||
$.post("<?=self::getUrl("AddressDB", "api")?>", {
|
||||
do: "getUnit",
|
||||
id: id
|
||||
},
|
||||
function(success) {
|
||||
if(success.status == "OK") {
|
||||
console.log(success.result.string);
|
||||
$("#new_unit_text").text(success.result.string);
|
||||
}
|
||||
},
|
||||
"json"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>
|
||||
@@ -135,12 +135,15 @@
|
||||
<td><?=$oaid->origin_id?></td>
|
||||
<td><?=$oaid->origin?></td>
|
||||
<td><?=$oaid->owner->getCompanyOrName()?></td>
|
||||
<td class="text-right <?=($oaid->adb_wohneinheit_count > 1 || $oaid->adb_wohneinheit_id && $oaid->adb_wohneinheit_count < 1) ? "text-danger" : ""?>"><?=($oaid->adb_wohneinheit_id) ? $oaid->adb_wohneinheit_count."x" : ""?></td>
|
||||
<td class="text-right <?=($oaid->adb_wohneinheit_count > 1 || $oaid->adb_wohneinheit_id && $oaid->adb_wohneinheit_count < 1) ? "text-danger" : ""?>">
|
||||
<?=($oaid->adb_wohneinheit_id) ? $oaid->adb_wohneinheit_count."x" : ""?>
|
||||
</td>
|
||||
<td>
|
||||
<?php if($oaid->termination_id): ?>
|
||||
<?=(is_object($oaid->termination) && $oaid->termination->building_id) ? $oaid->termination->building->getAddress() : ""?>
|
||||
<?=($oaid->termination->name) ? " - ".$oaid->termination->name : ""?>
|
||||
<?php elseif($oaid->adb_wohneinheit_id && is_object($oaid->adb_wohneinheit)): ?>
|
||||
<!--a href="<?=self::getUrl("OpenAccessId", "changeADBWohneinheit", ["id" => $oaid->id])?>" class="mr-1"><i class="fas fa-edit"></i></a-->
|
||||
[<?=$oaid->adb_wohneinheit->hausnummer->strasse->gemeinde->name?>]
|
||||
<?=$oaid->adb_wohneinheit->hausnummer->plz->plz?>
|
||||
<?=$oaid->adb_wohneinheit->hausnummer->ortschaft->name?>,
|
||||
|
||||
@@ -370,7 +370,9 @@ class AddressDBController extends mfBaseController {
|
||||
$this->layout()->setFlash("Fehler beim Erstellen einer Wohneinheit!", "warning");
|
||||
return $this->addAction();
|
||||
}
|
||||
if($hausnummer->netzgebiet->unit_create_oaid) {
|
||||
$wohneinheit->oaid = $wohneinheit->getNewOAID();
|
||||
}
|
||||
$wohneinheit->save();
|
||||
$w++;
|
||||
}
|
||||
@@ -472,6 +474,9 @@ class AddressDBController extends mfBaseController {
|
||||
case 'findBuildings':
|
||||
$return = $this->findBuildingsApi();
|
||||
break;
|
||||
case 'getUnit':
|
||||
$return = $this->getUnitApi();
|
||||
break;
|
||||
case "findUnit":
|
||||
break;
|
||||
default:
|
||||
@@ -487,6 +492,18 @@ class AddressDBController extends mfBaseController {
|
||||
$this->returnJson($data);
|
||||
}
|
||||
|
||||
private function getUnitApi() {
|
||||
$id = $this->request->id;
|
||||
if(!$id) return false;
|
||||
|
||||
$unit = new ADBWohneinheit($id);
|
||||
if(!$unit->id) return false;
|
||||
|
||||
$return = $unit->hausnummer->getAddress();
|
||||
if((string)$unit) $return .= " ".(string)$unit;
|
||||
return["string" => $return];
|
||||
}
|
||||
|
||||
private function findAddressApi() {
|
||||
$addresses = [];
|
||||
$search = trim($this->request->q);
|
||||
|
||||
@@ -258,7 +258,7 @@ class OpenAccessId extends mfBaseModel {
|
||||
$exp_data_update->rimo->ftu_name = $ftu_data['name'];
|
||||
$exp_data_update->rimo->ftu_assigned_date = date("U");
|
||||
$this->export_data = json_encode($ext_data_update);
|
||||
$this-save();
|
||||
$this->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,6 +85,79 @@ class OpenAccessIdController extends mfBaseController {
|
||||
return $new_filter;
|
||||
}
|
||||
|
||||
protected function changeADBWohneinheitAction() {
|
||||
$this->layout()->setTemplate("OpenAccessId/ChangeUnit");
|
||||
$id = $this->request->id;
|
||||
if(!$id || $id <1) {
|
||||
$this->layout()->setFlash("Ungültige OAID", "error");
|
||||
$this->redirect("OpenAccessId");
|
||||
}
|
||||
|
||||
$oaid = new OpenAccessId($id);
|
||||
if(!$oaid->id) {
|
||||
$this->layout()->setFlash("Ungültige OAID", "error");
|
||||
$this->redirect("OpenAccessId");
|
||||
}
|
||||
|
||||
$this->layout()->set("oaid", $oaid);
|
||||
|
||||
if(!$this->request->new_unit_id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// get old and new unit_id
|
||||
$old_unit = ADBWohneinheitModel::getFirst(["oaid" => $oaid->oaid]);
|
||||
$new_unit = new ADBWohneinheit($this->request->new_unit_id);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if($old_unit) {
|
||||
$old_preorder = PreorderModel::getFirst(["adb_wohneinheit_id" => $old_unit->id]);
|
||||
if($old_preorder) {
|
||||
// remove oaid from preorder
|
||||
$old_preorder->oaid = null;
|
||||
$old_preorder->save();
|
||||
}
|
||||
// unassign oaid from rimo ftu
|
||||
// get oaid from rimo
|
||||
// unassign ftu from aoid
|
||||
// remove oaid from old unit
|
||||
|
||||
// remove meta data from oaid
|
||||
$oaid->assigned = 0;
|
||||
$oaid->adb_wohneinheit_id = null;
|
||||
$oaid->termination_id = null;
|
||||
$oaid->exported = 0;
|
||||
$oaid->exported_to = null;
|
||||
$oaid->exported_data = null;
|
||||
$oaid->address = null;
|
||||
$oaid->unit_string = null;
|
||||
$oaid->save();
|
||||
}
|
||||
|
||||
if($new_unit) {
|
||||
$new_preorder = PreorderModel::getFirst(["adb_wohneinheit_id" => $new_unit->id]);
|
||||
// add oaid to new unit
|
||||
// assign oaid to new ftu in rimo
|
||||
if($new_preorder) {
|
||||
// add oaid to preorder
|
||||
$new_preorder->oaid = $oaid->oaid;
|
||||
}
|
||||
// save metadata to oaid
|
||||
$oaid->assigned = date("U");
|
||||
$oaid->adb_wohneinheit_id = $new_unit->id;
|
||||
$oaid->termination_id = null;
|
||||
$oaid->exported = date("U");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function importerAction() {
|
||||
$this->layout()->setTemplate("OpenAccessId/Importer");
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class NetzgebietAddUnitCreateOaid extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
$table = $this->table("Netzgebiet");
|
||||
$table->addColumn("unit_create_oaid", "integer", ["null" => false, "default" => 0, "after" => "unit_count"]);
|
||||
$table->update();
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
$this->table("Netzgebiet")->removeColumn("unit_create_oaid")->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user