Merge branch 'Preorderlogistics/make-working' into 'master'

made preorderlogistics working again

See merge request fronk/thetool!1145
This commit is contained in:
Luca Haid
2025-03-25 16:13:27 +00:00
5 changed files with 1864 additions and 70 deletions
+5 -1
View File
@@ -184,7 +184,11 @@
function(success) { function(success) {
console.log(success); console.log(success);
if(success.status == "OK") { if(success.status == "OK") {
$("#sent-label-" + success.result.preorder_id).show(); if(checked) {
$("#sent-label-" + success.result.preorder_id).show();
} else {
$("#sent-label-" + success.result.preorder_id).hide();
}
} }
}, },
"json" "json"
+14 -2
View File
@@ -623,6 +623,18 @@ class PreorderModel
} }
} }
if (array_key_exists("preorder_status_flags_disabled", $filter)) {
$preorder_status_flags_disabled = $filter['preorder_status_flags_disabled'];
if (is_array($preorder_status_flags_disabled) && count($preorder_status_flags_disabled)) {
$where .= " AND tt_preorder.id NOT IN (
SELECT psv.preorder_id
FROM `" . FRONKDB_DBNAME . "`.PreorderStatusflagValue psv
WHERE psv.flag_id IN (" . implode(',', $preorder_status_flags_disabled) . ")
AND psv.value = 1
)";
}
}
if (array_key_exists("created_from", $filter)) { if (array_key_exists("created_from", $filter)) {
$created_from = $filter['created_from']; $created_from = $filter['created_from'];
if (is_numeric($created_from)) { if (is_numeric($created_from)) {
@@ -958,9 +970,9 @@ class PreorderModel
if (array_key_exists("sent", $filter)) { if (array_key_exists("sent", $filter)) {
$sent = $filter['sent']; $sent = $filter['sent'];
if ($sent) { if ($sent) {
$where .= " AND sent > 0"; $where .= " AND Preorderlogistics.sent > 0";
} else { } else {
$where .= " AND (sent = 0 OR sent IS NULL)"; $where .= " AND (Preorderlogistics.sent = 0 OR Preorderlogistics.sent IS NULL)";
} }
} }
@@ -1,53 +1,9 @@
<?php <?php
//use \chillerlan\QRCode;
use chillerlan\QRCode\QRCode;
use chillerlan\QRCode\QROptions;
use chillerlan\QRCode\Output\QROutputInterface;
class Preorderlogistics extends mfBaseModel { class Preorderlogistics extends mfBaseModel {
private $qrfilename; private $qrfilename;
private $preorder; private $preorder;
public function getCifQrPng($content) {
/*$filename = $this->getProperty("qrfilename");
if(!$filename) {
return false;
}
$qrpath = MFUPLOAD_FILE_SAVE_PATH."/".TT_PREORDER_CIF_QR_SUBFOLDER."/$filename";
var_dump($qrpath);*/
$img = $this->generateCifQrFile($content);
return $img;
}
public function generateCifQrFile($content) {
$qr_opts = new QROptions();
$qr_opts->outputType = QROutputInterface::GDIMAGE_PNG;
$qr = new QRCode($qr_opts);
try {
$png_data = $qr->render($content);
} catch (Exception $ex) {
throw $ex;
}
if(!$png_data) {
echo "Kein png data!";exit;
}
/*
$filename = $this->getProperty("qrfilename");
$qrpath = MFUPLOAD_FILE_SAVE_PATH."/".TT_PREORDER_CIF_QR_SUBFOLDER."/$filename";
$data_parts = explode(",", $png_data);
file_put_contents($qrpath, base64_decode($data_parts[1]));
*/
return $png_data;
}
public function getProperty($name) { public function getProperty($name) {
if($this->$name == null) { if($this->$name == null) {
@@ -1,4 +1,6 @@
<?php <?php
include_once(BASEDIR."/lib/QRCode/QRCode.php");
use Apirone\Lib\PhpQrCode\QrCode;
class PreorderlogisticsController extends mfBaseController { class PreorderlogisticsController extends mfBaseController {
@@ -76,10 +78,16 @@ class PreorderlogisticsController extends mfBaseController {
$filter['network_id'] = $my_network_ids; $filter['network_id'] = $my_network_ids;
$filter["status_code"] = 140; // $filter["status_code"] = 140;
//$filter["<status_code"] = 800; //$filter["<status_code"] = 800;
$filter["deleted"] = 0; $filter["deleted"] = 0;
$filter["connection_type"] = ["single-dwelling", "business"]; $filter["connection_type"] = ["single-dwelling", "business"];
$installation_kit_status_flag = PreorderStatusflagModel::getFirst(["code" => "145"]);
if ($filter['sent'] !== true) {
$filter["preorder_status_flags_disabled"] = [$installation_kit_status_flag->id];
} else {
$filter["preorder_status_flags"] = [$installation_kit_status_flag->id];
}
$pagination['maxItems'] = PreorderModel::countWithLogistics($filter); $pagination['maxItems'] = PreorderModel::countWithLogistics($filter);
$preorders = PreorderModel::searchWithLogistics($filter, $pagination); $preorders = PreorderModel::searchWithLogistics($filter, $pagination);
@@ -219,10 +227,14 @@ class PreorderlogisticsController extends mfBaseController {
$this->layout()->setFlash("Eintrag konnte nicht gespeichert werden"); $this->layout()->setFlash("Eintrag konnte nicht gespeichert werden");
} }
} }
$qrimg = $plog->getCifQrPng($preorder->cifurl); $qrimg = $plog->getCifQrPng($preorder->cifurl);
$this->layout()->set("qr_url", $qrimg); $qr = QRCode::init($preorder->cifurl); // $data & $options are optional
$image_encoded = $qr->base64();
$this->layout()->set("qr_url", $image_encoded);
$this->layout()->set("preorder", $preorder); $this->layout()->set("preorder", $preorder);
} }
@@ -253,9 +265,7 @@ class PreorderlogisticsController extends mfBaseController {
private function saveSentApi() { private function saveSentApi() {
if(!$this->me->is(["Preorderlogistics"])) { if(!$this->me->is(["Preorderlogistics"])) return false;
return false;
}
$preorder_id = $this->request->id; $preorder_id = $this->request->id;
if(!is_numeric($preorder_id) || $preorder_id < 1) { if(!is_numeric($preorder_id) || $preorder_id < 1) {
@@ -276,28 +286,38 @@ class PreorderlogisticsController extends mfBaseController {
$sent = intval($this->request->sent); $sent = intval($this->request->sent);
if($sent < 0 || $sent > 1) return false; if($sent < 0 || $sent > 1) return false;
$installation_kit_status_flag = PreorderStatusflagModel::getFirst(["code" => "145"]);
$flagvalue = PreorderStatusflagValueModel::getFirst(["preorder_id" => $preorder_id, "flag_id" => $installation_kit_status_flag->id]);
// var_dump($flagvalue);
// exit;
if(!$flagvalue) {
$flagvalue = PreorderStatusflagValueModel::create([
"preorder_id" => $preorder_id,
"flag_id" => $installation_kit_status_flag->id
]);
}
$value = ($sent) ? 1 : 0;
$flagvalue->value = $value;
try {
if(!$flagvalue->save()) {
return false;
}
} catch(Exception $e) {
$this->log->debug($e->getTraceAsString());
die("hi");
}
if($sent) { if($sent) {
$plog->sent_by = $this->me->id; $plog->sent_by = $this->me->id;
$plog->sent = date('U'); $plog->sent = date('U');
$new_status = PreorderstatusModel::getFirst(["code" => 145]);
if($preorder->status->code < $new_status->code) {
$plog->prev_status_code = $preorder->status->code;
$preorder->status_id = $new_status->id;
$preorder->save();
}
} else { } else {
$plog->sent_by = null; $plog->sent_by = null;
$plog->sent = 0; $plog->sent = 0;
} }
if(!$plog->save()) {
return false; if(!$plog->save()) return false;
}
return ["preorder_id" => $preorder->id]; return ["preorder_id" => $preorder->id];
} }
} }
File diff suppressed because it is too large Load Diff