Merge branch 'ConstructionConsent/add-signature' into 'master'
added new signature action See merge request fronk/thetool!1340
This commit is contained in:
@@ -679,4 +679,85 @@ FROM ConstructionConsent
|
||||
return $where;
|
||||
}
|
||||
|
||||
public static function searchConstructionConsentBasedOnName($name, $filter = []) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$searchName = trim($name);
|
||||
if (empty($searchName)) {
|
||||
// return $items;
|
||||
}
|
||||
|
||||
$searchTerms = explode(' ', $searchName);
|
||||
$searchConditions = [];
|
||||
|
||||
foreach ($searchTerms as $term) {
|
||||
$escapedTerm = $db->escape($term);
|
||||
$searchConditions[] = "(cco.firstname LIKE '%$escapedTerm%' OR
|
||||
cco.lastname LIKE '%$escapedTerm%' OR
|
||||
cc.name LIKE '%$escapedTerm%' OR
|
||||
ccp.name LIKE '%$escapedTerm%')";
|
||||
}
|
||||
|
||||
if (!empty($searchConditions)) {
|
||||
$intelligentSearchWhere = "(" . implode(' AND ', $searchConditions) . ")";
|
||||
if (isset($filter['add-where'])) {
|
||||
$filter['add-where'] .= " AND $intelligentSearchWhere";
|
||||
} else {
|
||||
$filter['add-where'] = "AND $intelligentSearchWhere";
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($filter['add-where'])) {
|
||||
$filter['add-where'] .= " AND cco.firstname IS NOT NULL";
|
||||
} else {
|
||||
$filter['add-where'] = "AND cco.firstname IS NOT NULL";
|
||||
}
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
|
||||
$sql = "SELECT cc.id AS consent_id, cc.name AS consent_name, cc.status AS consent_status,
|
||||
cc.result AS consent_result, cc.ez, cc.kg, cc.gst, cc.gstnr,
|
||||
ccp.id AS project_id, ccp.name AS project_name,
|
||||
cco.id AS owner_id, cco.firstname, cco.lastname, cco.street, cco.zip, cco.city,
|
||||
cco.email, cco.phone, cco.status AS owner_status, cco.result AS owner_result,
|
||||
vh.strasse AS address_street, vh.hausnummer AS address_number,
|
||||
vh.plz AS address_zip, vh.ortschaft AS address_city
|
||||
FROM ConstructionConsent cc
|
||||
LEFT JOIN ConstructionConsentProject ccp ON cc.constructionconsentproject_id = ccp.id
|
||||
LEFT JOIN ConstructionConsentOwner cco ON cc.id = cco.constructionconsent_id
|
||||
LEFT JOIN `".ADDRESSDB_DBNAME."`.view_hausnummer vh ON cc.adb_hausnummer_id = vh.hausnummer_id
|
||||
WHERE $where
|
||||
ORDER BY cc.edit DESC, cco.lastname ASC, cco.firstname ASC";
|
||||
|
||||
$res = $db->query($sql);
|
||||
while ($data = $res->fetch_assoc()) {
|
||||
$items[] = [
|
||||
'consent_id' => $data['consent_id'],
|
||||
'consent_name' => $data['consent_name'],
|
||||
'consent_status' => $data['consent_status'],
|
||||
'consent_result' => $data['consent_result'],
|
||||
'project_id' => $data['project_id'],
|
||||
'project_name' => $data['project_name'],
|
||||
'owner_id' => $data['owner_id'],
|
||||
'owner_name' => trim($data['firstname'] . ' ' . $data['lastname']),
|
||||
'owner_address' => $data['street'] . ', ' . $data['zip'] . ' ' . $data['city'],
|
||||
'owner_contact' => $data['email'] . ($data['phone'] ? ' / ' . $data['phone'] : ''),
|
||||
'owner_status' => $data['owner_status'],
|
||||
'owner_result' => $data['owner_result'],
|
||||
'property_info' => 'EZ:' . $data['ez'] . ' KG:' . $data['kg'] . ' GST:' . $data['gst'] . ($data['gstnr'] ? '-' . $data['gstnr'] : ''),
|
||||
'address' => $data['address_street'] . ' ' . $data['address_number'] . ', ' . $data['address_zip'] . ' ' . $data['address_city'],
|
||||
];
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -168,6 +168,7 @@ class ConstructionConsentController extends mfBaseController {
|
||||
protected function downloadAction()
|
||||
{
|
||||
$owner_id = $this->request->owner_id;
|
||||
$open = $this->request->open;
|
||||
|
||||
if (!is_numeric($owner_id) || $owner_id < 1 || !($owner = new ConstructionConsentOwner($owner_id))->id) {
|
||||
$this->layout()->setFlash("Besitzer nicht gefunden", "error");
|
||||
@@ -184,7 +185,7 @@ class ConstructionConsentController extends mfBaseController {
|
||||
$this->redirect("ConstructionConsent", "View", ["id" => $cc->id]);
|
||||
}
|
||||
|
||||
$this->sendPdfResponse($filename, "Zustimmungserklärung-{$cc->id}-{$owner_id}.pdf");
|
||||
$this->sendPdfResponse($filename, "Zustimmungserklärung-{$cc->id}-{$owner_id}.pdf", $open === 'true');
|
||||
}
|
||||
|
||||
protected function downloadMultipleAction()
|
||||
@@ -224,10 +225,12 @@ class ConstructionConsentController extends mfBaseController {
|
||||
$this->sendPdfResponse($filename, "Zustimmungserklärungen-".date('Y-m-d').".pdf");
|
||||
}
|
||||
|
||||
private function sendPdfResponse(string $filename, string $downloadName): void
|
||||
private function sendPdfResponse(string $filename, string $downloadName, bool $open = false): void
|
||||
{
|
||||
header('Content-Type: ' . mime_content_type($filename));
|
||||
header('Content-disposition: attachment; filename="' . rawurlencode($downloadName) . '"');
|
||||
if ($open === true) header('Content-disposition: inline; filename="' . rawurlencode($downloadName) . '"');
|
||||
else header('Content-disposition: attachment; filename="' . rawurlencode($downloadName) . '"');
|
||||
|
||||
header('Content-Length: ' . filesize($filename));
|
||||
readfile($filename);
|
||||
exit;
|
||||
@@ -1278,4 +1281,84 @@ class ConstructionConsentController extends mfBaseController {
|
||||
fclose($output);
|
||||
exit();
|
||||
}
|
||||
|
||||
protected function searchTabletAction() {
|
||||
$name = '';
|
||||
$filter = [];
|
||||
|
||||
// Handle POST data - support both form data and JSON input
|
||||
if($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$postData = [];
|
||||
|
||||
// Check for JSON input (Axios sends JSON)
|
||||
$inputJSON = file_get_contents('php://input');
|
||||
$jsonData = json_decode($inputJSON, true);
|
||||
|
||||
if($jsonData !== null) {
|
||||
$postData = $jsonData;
|
||||
} else {
|
||||
$postData = $_POST;
|
||||
}
|
||||
|
||||
if(isset($postData['name'])) {
|
||||
$name = $postData['name'];
|
||||
}
|
||||
|
||||
if(isset($postData['filter']) && is_array($postData['filter'])) {
|
||||
$filter = $postData['filter'];
|
||||
}
|
||||
}
|
||||
|
||||
$results = ConstructionConsent::searchConstructionConsentBasedOnName($name, $filter);
|
||||
|
||||
self::returnJson([
|
||||
'success' => true,
|
||||
'count' => count($results),
|
||||
'results' => $results
|
||||
]);
|
||||
}
|
||||
|
||||
protected function signTabletAction() {
|
||||
$JSGlobals = ["BASE_PATH" => self::getUrl(""),
|
||||
"DASHBOARD_URL" => self::getUrl("Dashboard"),
|
||||
"MFAPPNAME" => MFAPPNAME_SLUG,
|
||||
"PAGE_TITLE" => "Zustimmungserklärungen unterzeichnen",
|
||||
"PATH" => [
|
||||
["text" => MFAPPNAME_SLUG, "href" => self::getUrl("Dashboard")],
|
||||
["text" => "Zustimmungserklärungen unterzeichnen", "href" => self::getUrl("ConstructionConsent", "SignTablet")],
|
||||
],
|
||||
"IS_ADMIN" => $this->me->is("Admin"),
|
||||
];
|
||||
|
||||
$this->layout()->set("vueViewName", "ConstructionConsentSignTablet");
|
||||
$this->layout()->set("JSGlobals", $JSGlobals);
|
||||
$this->layout()->setTemplate("VueViews/Vue");
|
||||
}
|
||||
|
||||
protected function signAction() {
|
||||
$POST = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
$owner_id = $POST['owner_id'] ?? null;
|
||||
$signature = $POST['signature'] ?? null;
|
||||
$signature_name = $POST['signature_name'] ?? null;
|
||||
$signature_date = $POST['signature_date'] ?? null;
|
||||
|
||||
if(!$owner_id || !$signature) {
|
||||
self::sendError("Invalid request");
|
||||
}
|
||||
|
||||
$owner = new ConstructionConsentOwner($owner_id);
|
||||
if(!$owner->id) self::sendError("Owner not found");
|
||||
|
||||
if($signature_name) $owner->signature_name = $signature_name;
|
||||
if($signature_date) $owner->signature_date = date("U", strtotime($signature_date));
|
||||
if($signature) $owner->signature = $signature;
|
||||
|
||||
$owner->status = 'returned';
|
||||
$owner->result = 'accepted';
|
||||
|
||||
if(!$owner->save()) self::sendError("Error saving signature");
|
||||
self::returnJson(["success" => true]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user