Preorder: Status can now be changed manually

This commit is contained in:
Frank Schubert
2023-11-07 13:00:29 +01:00
parent bd3489f6e4
commit 79fe0aa00e
18 changed files with 367 additions and 69 deletions
+1 -1
View File
@@ -151,7 +151,7 @@ class AdminController extends mfBaseController {
}
protected function ivtAdminImportAction() {
exit;
//exit;
$doit = false;
if($this->request->doit == 1) {
$doit = true;
+23
View File
@@ -211,6 +211,8 @@ class Preorder extends mfBaseModel {
return $this->ucode;
}
private function generateNewUcode() {
$chars = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ';
$charsLength = strlen($chars);
@@ -221,6 +223,25 @@ class Preorder extends mfBaseModel {
return $ucode;
}
public function createCifCode() {
$cifcode = $this->generateNewCifcode();
while(PreorderModel::search(['cifcode' => $cifcode])) {
$cifcode = $this->generateNewCifcode();
}
$this->cifcode = $cifcode;
return $this->cifcode;
}
private function generateNewCifcode() {
$chars = '23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxzy';
$charsLength = strlen($chars);
$cifcode = '';
for ($i = 0; $i < 16; $i++) {
$cifcode .= $chars[rand(0, $charsLength - 1)];
}
return $cifcode;
}
public function getApiArray() {
if(!$this->id) {
return false;
@@ -233,6 +254,8 @@ class Preorder extends mfBaseModel {
$a = [];
$a['code'] = strtoupper($this->ucode);
$a['cifcode'] = $this->cifcode;
$a['cifurl'] = $this->cifurl;
$a['oaid'] = $this->oaid;
$a['extref'] = $this->extref;
$a['status'] = $this->getProperty("status")->getApiArray();
@@ -249,6 +249,15 @@ class PreorderController extends mfBaseController {
unset($filter['oaid']);
}
if(array_key_exists("status", $filter) && is_array($filter['status']) && count($filter['status'])) {
$new_filter['status_id'] = [];
foreach($filter["status"] as $s) {
if(is_numeric($s) && $s > 0) {
$new_filter['status_id'][] = $s;
}
}
}
/*if(array_key_exists("attributes", $filter) && count($filter['attributes'])) {
}*/
@@ -785,6 +794,9 @@ class PreorderController extends mfBaseController {
case "getFilteredPreorders":
$return = $this->getFilteredPreordersApi();
break;
case "updateStatus":
$return = $this->updateStatusApi();
break;
default:
$return = false;
}
@@ -926,4 +938,32 @@ class PreorderController extends mfBaseController {
}
private function updateStatusApi() {
$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;
}
$status_id = $this->request->status_id;
if(!is_numeric($status_id) || $status_id < 1) {
return false;
}
$status = new Preorderstatus($status_id);
if(!$status->id) {
return false;
}
$preorder->status_id = $status_id;
$preorder->save();
return ["message" => "Status saved successfully", "id" => $preorder_id, "status_id" => $status->id, "status_code" => $status->code, "status_text" => $status->name];
}
}
+12 -3
View File
@@ -321,21 +321,23 @@ class PreorderModel {
if(array_key_exists("status_id", $filter)) {
$status_id = $filter['status_id'];
if(is_numeric($status_id)) {
$where .= " AND status_id=$status_id";
$where .= " AND tt_preorder.status_id=$status_id";
} elseif(is_array($status_id)) {
$where .= " AND tt_preorder.status_id IN (". implode(",", $status_id).")";
}
}
if(array_key_exists("<status_id", $filter)) {
$status_id = $filter['<status_id'];
if(is_numeric($status_id)) {
$where .= " AND status_id < $status_id";
$where .= " AND tt_preorder.status_id < $status_id";
}
}
if(array_key_exists(">status_id", $filter)) {
$status_id = $filter['>status_id'];
if(is_numeric($status_id)) {
$where .= " AND status_id > $status_id";
$where .= " AND tt_preorder.status_id > $status_id";
}
}
@@ -455,6 +457,13 @@ class PreorderModel {
}
}
if(array_key_exists("cifcode", $filter)) {
$cifcode = FronkDB::singleton()->escape($filter['cifcode']);
if($cifcode) {
$where .= " AND cifcode LIKE '$cifcode'";
}
}
if(array_key_exists("oaid", $filter)) {
$oaid = $filter['oaid'];
if($oaid) {
@@ -44,7 +44,7 @@ class PreorderstatusModel {
public static function getAll() {
$items = [];
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$db = FronkDB::singleton();
$res = $db->select("Preorderstatus", "*");
if($db->num_rows($res)) {
@@ -57,7 +57,7 @@ class PreorderstatusModel {
}
public static function getFirst($filter = false) {
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("Preorderstatus", "*", "$where ORDER BY code, name");
@@ -74,7 +74,7 @@ class PreorderstatusModel {
}
public static function count($filter) {
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT COUNT(*) as cnt FROM Preorderstatus
@@ -93,7 +93,7 @@ class PreorderstatusModel {
public static function search($filter, $limit = false) {
$items = [];
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
+38
View File
@@ -65,6 +65,44 @@ class Voiceplan extends mfBaseModel {
}
}
public function importZonesFromCsv(File $file) {
if(!$this->id) {
return false;
}
try {
$i = 0;
$filename = $file->getFullPath();
$input = fopen($filename, "r");
while($csv = fgetcsv($input, 0, ",")) {
$i++;
if($i == 1) continue;
if(!trim($csv[0])) {
continue;
}
$name = trim($csv[0]);
$prefix = trim($csv[1]);
$price_ek = str_replace(",",".", trim($csv[2]));
$price_vk = str_replace(",",".", trim($csv[3]));
if(!$name || !$prefix || !$price_ek || !$price_vk) {
$this->log->warning("not Importing Voiceplandestination with empty value: destination: $name | prefix: $prefix | ek: $price_ek | vk: $price_vk");
continue;
}
}
return true;
} catch(Exception $e) {
echo $e->getCode().": ".$e->getMessage();exit;
return false;
}
}
public function getProperty($name) {
if($this->$name == null) {
+45 -15
View File
@@ -125,7 +125,7 @@ class VoiceplanController extends mfBaseController {
$data['name'] = $r->name;
$data['description'] = $r->description;
if($r->increment) {
/*if($r->increment) {
$increments = explode("/",$r->increment);
if(count($increments) != 2) {
$this->layout()->setFlash("Ungültige Taktung", "error");
@@ -134,7 +134,7 @@ class VoiceplanController extends mfBaseController {
$data["increment_first"] = $increments[0];
$data["increment"] = $increments[1];
}
}*/
if(!$data['name']) {
$this->layout()->setFlash("Bitte Name eingeben", "error");
@@ -153,39 +153,69 @@ class VoiceplanController extends mfBaseController {
return $this->editAction();
}
if(is_array($_FILES) && array_key_exists("voiceplanfile", $_FILES) && !$_FILES['voiceplanfile']['error']) {
// import zones
if(is_array($_FILES) && array_key_exists("voiceplanzonefile", $_FILES) && !$_FILES['voiceplanzonefile']['error']) {
// look for uploaded import file
try {
// returns File object or throws Exception on error
$file = mfUpload::handleFormUpload("voiceplanfile");
$file = mfUpload::handleFormUpload("voiceplanzonefile");
} catch (Exception $ex) {
$this->layout()->setFlash("Fehler beim Dateiupload: ".$ex->getMessage(), "error");
$this->layout()->setFlash("Fehler beim Upload des Zonenfiles: ".$ex->getMessage(), "error");
return $this->editAction();
}
$vpf = VoiceplanFileModel::create([
'voiceplan_id' => $id,
'file_id' => $file->id,
'name' => "voiceplan-import-".date("Y-m-d_H-i-s").".csv",
'name' => "voiceplan-zone-import-".date("Y-m-d_H-i-s").".csv",
]);
$voiceplanfile_id = $vpf->save();
if(!$voiceplanfile_id) {
$voiceplanzonefile_id = $vpf->save();
if(!$voiceplanzonefile_id) {
$this->layout()->setFlash("Fehler beim Speichern der hochgeladenen Datei", "error");
return $this->editAction();
}
// if file was uploaded successfully, delete old destinations
// if file was uploaded successfully, delete old destinations and zones
foreach(VoiceplandestinationModel::search(['voiceplan_id' => $id]) as $destination) {
$destination->delete();
}
foreach(VoiceplanzoneModel::search(['voiceplan_id' => $id]) as $zone) {
$zone->delete();
}
if(!$voiceplan->importDestinationsFromCsv($file)) {
$this->layout()->setFlash("Fehler beim Importieren!", "error");
if(!$voiceplan->importZonesFromCsv($file)) {
$this->layout()->setFlash("Fehler beim Importieren der Zonen!", "error");
return $this->editAction();
}
// import destinations
if(is_array($_FILES) && array_key_exists("voiceplandestinationfile", $_FILES) && !$_FILES['voiceplandestinationfile']['error']) {
// look for uploaded import file
try {
// returns File object or throws Exception on error
$file = mfUpload::handleFormUpload("voiceplandestinationfile");
} catch (Exception $ex) {
$this->layout()->setFlash("Fehler beim Upload des Destinationfiles: ".$ex->getMessage(), "error");
return $this->editAction();
}
$vpf = VoiceplanFileModel::create([
'voiceplan_id' => $id,
'file_id' => $file->id,
'name' => "voiceplan-dest-import-".date("Y-m-d_H-i-s").".csv",
]);
$voiceplandestinationfile_id = $vpf->save();
if(!$voiceplandestinationfile_id) {
$this->layout()->setFlash("Fehler beim Speichern der hochgeladenen Datei", "error");
return $this->editAction();
}
if(!$voiceplan->importDestinationsFromCsv($file)) {
$this->layout()->setFlash("Fehler beim Importieren!", "error");
return $this->editAction();
}
}
}
$this->layout()->setFlash("Sprachtarifpaket erfolgreich gespeichert!", "success");
@@ -70,8 +70,12 @@ class VoiceplandestinationModel {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT COUNT(*) as cnt FROM Voiceplandestination
WHERE $where
$sql = "SELECT COUNT(*) as cnt FROM (
SELECT Voiceplandestination.id FROM Voiceplandestination
LEFT JOIN Voiceplanzone ON (Voiceplanzone.id = Voiceplandestination.voiceplanzone_id)
WHERE $where
GROUP BY Voiceplandestination.id
) as v
";
$res = $db->query($sql);
@@ -87,7 +91,8 @@ class VoiceplandestinationModel {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM Voiceplandestination
$sql = "SELECT Voiceplandestination.* FROM Voiceplandestination
LEFT JOIN Voiceplanzone ON (Voiceplanzone.id = Voiceplandestination.voiceplanzone_id)
WHERE $where
ORDER BY destination,prefix";
@@ -126,6 +131,13 @@ class VoiceplandestinationModel {
}
}
if(array_key_exists("voiceplan_id", $filter)) {
$voiceplan_id = $filter['voiceplan_id'];
if(is_numeric($voiceplan_id)) {
$where .= " AND Voiceplanzone.voiceplan_id = $voiceplan_id";
}
}
if(array_key_exists("name", $filter)) {
$name = $db->escape($filter['name']);
if($name) {