Updated preorder api

This commit is contained in:
Frank Schubert
2023-11-09 14:55:10 +01:00
parent 36c6036ed9
commit 19cd396175
9 changed files with 137 additions and 21 deletions

View File

@@ -313,21 +313,25 @@
<div class="col-6">
<h3>Workorder</h3>
<table class="table table-sm table-striped">
<tr>
<th>Name</th>
<td class="text-monospace"><?=$preorder->adb_wohneinheit->rimo_workorder->rimo_name?></td>
</tr><tr>
<th>External ID</th>
<td class="text-monospace"><?=$preorder->adb_wohneinheit->rimo_workorder->rimo_id?></td>
</tr><tr>
<th>Status</th>
<td><?=$preorder->adb_wohneinheit->rimo_workorder->rimo_status?></td>
</tr><tr>
<th>Erstellt</th>
<td class="text-monospace"><?=($preorder->adb_wohneinheit->rimo_workorder->id) ? date("d.m.Y H:i:s", $preorder->adb_wohneinheit->rimo_workorder->create) : ""?></td>
</tr>
</table>
<?php if(is_object($preorder->adb_wohneinheit->rimo_workorder) && $preorder->adb_wohneinheit->rimo_workorder->id): ?>
<small id="preorder-detail-<?=$preorder->id?>-workorder-del"><a href="#" onclick="if(confirm('Achtung: Löscht die Workorder in thetool, aber NICHT in RIMO!')) return deleteWorkorder(<?=$preorder->id?>)" class="text-danger"><i class="far fa-times-circle"></i> Workorder löschen</a></small>
<table class="table table-sm table-striped" id="preorder-detail-<?=$preorder->id?>-workorder">
<tr>
<th>Name</th>
<td class="text-monospace"><?=$preorder->adb_wohneinheit->rimo_workorder->rimo_name?></td>
</tr><tr>
<th>External ID</th>
<td class="text-monospace"><?=$preorder->adb_wohneinheit->rimo_workorder->rimo_id?></td>
</tr><tr>
<th>Status</th>
<td><?=$preorder->adb_wohneinheit->rimo_workorder->rimo_status?></td>
</tr><tr>
<th>Erstellt</th>
<td class="text-monospace"><?=(is_object($preorder->adb_wohneinheit->rimo_workorder)) ? date("d.m.Y H:i:s", $preorder->adb_wohneinheit->rimo_workorder->create) : ""?></td>
</tr>
</table>
<?php endif; ?>
</div>
@@ -402,4 +406,29 @@
},
'json');
}
function deleteWorkorder(pid) {
console.log("in delete workorder");
if(!Number.isInteger(pid) || pid < 1) {
return false;
}
$.post("<?=self::getUrl("Preorder","Api")?>",
{
'do': "deleteWorkorder",
id: pid,
},
function(success) {
if(success.status == "OK") {
$("#preorder-detail-" + success.result.id + "-workorder td").each(function() {
$(this).html("<em class='text-monospace'>--gelöscht--</em>");
});
$("#preorder-detail-" + success.result.id + "-workorder-del").remove();
}
},
'json');
return false;
}
</script>

View File

@@ -168,7 +168,10 @@ class ADBWohneinheit extends mfBaseModel {
}
if($name == "rimo_workorder") {
$this->rimo_workorder = RimoWorkorderModel::getFirst(['adb_wohneinheit_id' => $this->id]);
$this->rimo_workorder = new RimoWorkorder();
if($this->id) {
$this->rimo_workorder = RimoWorkorderModel::getFirst(['adb_wohneinheit_id' => $this->id]);
}
return $this->rimo_workorder;
}

View File

@@ -54,7 +54,7 @@ class ADBWohneinheitModel {
ORDER BY hausnummer_id,block,stiege,LENGTH(stock),stock,LENGTH(tuer),tuer,num
LIMIT 1";
mfLoghandler::singleton()->debug($sql);
//mfLoghandler::singleton()->debug($sql);
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
@@ -96,7 +96,7 @@ class ADBWohneinheitModel {
) as tbl
";
mfLoghandler::singleton()->debug($sql);
//mfLoghandler::singleton()->debug($sql);
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);

View File

@@ -82,7 +82,7 @@ class OpenAccessIdModel {
if(!$oaid) return null;
$where = self::getSqlFilter(["oaid" => $oaid]);
mfLoghandler::singleton()->debug($where);
//mfLoghandler::singleton()->debug($where);
$res = $db->select("OpenAccessId", "*", "$where ORDER BY id");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);

View File

@@ -359,7 +359,11 @@ class Preorder extends mfBaseModel {
$a['cifurl'] = $this->cifurl;
$a['oaid'] = $this->oaid;
$a['extref'] = $this->extref;
$a['orderDate'] = ($this->order_date) ? date("Y-m-d",$this->order_date) : null;
$a['status'] = $this->getProperty("status")->getApiArray();
$a['ciftoken'] = ($this->ciftoken) ? $this->ciftoken : null;
$a['cifurl'] = ($this->cifurl) ? $this->cifurl : null;
$a['installationDate'] = ($this->installation_date) ? date("c", $this->installation_date) : null;
$a['connectionType'] = $this->connection_type;
$a['connectionCount'] = ($this->connection_count) ? (int)$this->connection_count : 1;
$a['isAdditionalOrder'] = ($this->is_additional_order) ? true : false;

View File

@@ -797,6 +797,9 @@ class PreorderController extends mfBaseController {
case "updateStatus":
$return = $this->updateStatusApi();
break;
case "deleteWorkorder":
$return = $this->deleteWorkorderApi();
break;
default:
$return = false;
}
@@ -997,4 +1000,33 @@ class PreorderController extends mfBaseController {
return ["message" => "Status saved successfully", "id" => $preorder_id, "update" => $update];
}
private function deleteWorkorderApi() {
if(!$this->me->is("Admin")) {
return false;
}
$preorder_id = $this->request->id;
if(!is_numeric($preorder_id) || $preorder_id < 1) {
return false;
}
$preorder = new Preorder($preorder_id);
if(!$preorder->id) {
return false;
}
if(!$preorder->adb_wohneinheit_id) {
return false;
}
$workorder = RimoWorkorderModel::getFirst(["adb_wohneinheit_id" => $preorder->adb_wohneinheit_id]);
if(!$workorder) {
return false;
}
$workorder->delete();
return ["Message" => "Workorder deleted successfully", "id" => $preorder->id];
}
}

View File

@@ -54,7 +54,7 @@ class RimoWorkorderModel {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
mfLoghandler::singleton()->debug($where);
//mfLoghandler::singleton()->debug($where);
$res = $db->select("RimoWorkorder", "*", "$where ORDER BY `create`");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);

View File

@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class PreorderAddInstallationAndOrderDates extends AbstractMigration
{
public function up(): void
{
if($this->getEnvironment() == "thetool") {
$table = $this->table("Preorder");
$table->addColumn("installation_date", "integer", ["null" => true, "default" => null, "after" => "submit_request"]);
$table->addColumn("order_date", "integer", ["null" => true, "default" => null, "after" => "note"]);
$table->update();
}
if($this->getEnvironment() == "addressdb") {
}
}
public function down(): void
{
if($this->getEnvironment() == "thetool") {
$this->table("Preorder")->removeColumn("installation_date")->save();
$this->table("Preorder")->removeColumn("order_date")->save();
}
if($this->getEnvironment() == "addressdb") {
}
}
}

View File

@@ -760,7 +760,7 @@ paths:
description: Unauthorized
'404':
description: Vorbestellung nicht gefunden
/preorder/{id}/inhouseInstallationFinished:
/preorder/{id}/serviceActivated:
post:
tags:
- preorder
@@ -1137,6 +1137,11 @@ components:
extref:
type: string
description: Providereigener Identifikationsstring. Wird unverändert gespeichert und kann statt `code` in `GET /preorder` und `DELETE /preorder` angegeben werden. **Darf nicht mit Dateiendung wie z.B. `.json`, `.csv` enden, da diese als Ausgabeformat interpretiert werden können**
orderDate:
type: string
format: date
description: Bestell- oder Vertragsdatum ISO 8601 Format
example: "2023-02-01"
preorderType:
type: string
enum: [interest, provision, order]
@@ -1402,6 +1407,11 @@ components:
extref:
type: string
description: Providereigener Identifikationsstring. Wird unverändert gespeichert und kann statt `code` in `GET /preorder` und `DELETE /preorder` angegeben werden. **Darf nicht mit Dateiendung wie z.B. `.json`, `.csv` enden, da diese als Ausgabeformat interpretiert werden können**
orderDate:
type: string
format: date
description: Bestell- oder Vertragsdatum ISO 8601 Format
example: "2023-02-01"
status:
type: object
properties:
@@ -1421,6 +1431,11 @@ components:
type: string
description: Customer Installation Feedback Url
example: "https://pro.ichwillglasfaser.at/ClientSubmit/finishedInstallationWork?c=XArjnWQXGq4a8JWF"
installationDate:
type: string
format: date-time
description: Installationstermin in ISO 8601 Format
example: "2023-02-01T00:00:00+01:00"
connectionType:
type: string
enum: [single-dwelling, multi-dwelling, apartment-building, apartment, business]