added filter for sended emails

This commit is contained in:
Luca Haid
2025-07-03 12:00:36 +02:00
parent 4bec93b14e
commit 72858d3eb3
5 changed files with 133 additions and 6 deletions

View File

@@ -418,11 +418,6 @@ $pagination_entity_name = "Vorbestellungen";
<button type="submit" formaction="<?=self::getUrl("Preorder", "export")?>" id="export-button" class="btn btn-outline-success"><i class="fas fa-download"></i> CSV-Export</button>
<?php endif; ?>
<!-- i need a dropdown with 2 options beautifull dropdown no select
Gelöschte Bestellungen mit Workorder (button with href)
Wohnung - Verkabelung erledigt (button with href)
-->
<div class="dropdown">
<button class="btn btn-outline-primary dropdown-toggle" type="button" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-expanded="false">
Filter-Vorlagen <i class="fas fa-caret-down"></i>
@@ -430,6 +425,9 @@ $pagination_entity_name = "Vorbestellungen";
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<li><a class="dropdown-item" href="<?=self::getUrl("Preorder", "Index", ["filter" => ["status" => [21,22,23,24,25], "rimo_workorder" => 1, "borderpoint" => "all"]])?>">Gelöschte Bestellungen mit Workorder</a></li>
<li><a class="dropdown-item" href="<?=self::getUrl("Preorder", "Index", ["filter" => ["preorder_status_flags" => [4], "connection_type" => ["apartment", "apartment-building"], "borderpoint" => "all"]])?>">Wohnung - Verkabelung erledigt</a></li>
<?php if ($me->isAdmin() || $me->address->id == 209): ?>
<li><a class="dropdown-item" href="<?=self::getUrl("Preorder", "Index", ["filter" => ["onlyShowCustomMailSent" => 1]])?>">Bestellungen mit gesendeter Custom-300 Benachrichtigung</a></li>
<?php endif; ?>
</ul>
</div>

View File

@@ -102,7 +102,66 @@
</div>
<?php endif; ?>
</td>
</tr><tr>
</tr>
<!-- add new checkbox field here called "Verrechnet" and if $preorder->billed is not null or 0 show the unix date, also only show this when
preordercampaign -> network_id -> network -> owner_id === 209
then show billed = timestamp (no input as the checkbox is the only thing that can be changed)
also show billed_by
-->
<?php if($preorder->campaign->network->owner_id === "209"): ?>
<tr>
<th>Verrechnet:</th>
<td>
<div class="flex items-center space-x-2">
<input
type="checkbox"
id="preorder-detail-billed-<?=$preorder->id?>"
class="form-checkbox h-5 w-5 text-blue-600 rounded focus:ring-blue-500"
<?=($preorder->billed) ? 'checked' : ''?>
onchange="updatePreorderBilled(<?=$preorder->id?>, this.checked)"
/>
<label for="preorder-detail-billed-<?=$preorder->id?>" class="text-gray-700 mb-0">Verrechnet</label>
</div>
<?php if($preorder->billed_by): ?>
<div class="mt-2 text-sm text-gray-600" id="billed_text">Verrechnet durch: <?=(new User($preorder->billed_by))->name?> am <?=date("d.m.Y H:i", $preorder->billed)?> Uhr</div>
<?php endif; ?>
</td>
<script>
// console log if changed
function updatePreorderBilled(preorderId, isChecked) {
console.log("Updating billed status for preorder " + preorderId + ": " + (isChecked ? "checked" : "unchecked"));
$.ajax({
url: '<?=self::getUrl("Preorder", "Api")?>?do=updateBilled',
type: 'POST',
data: {
do: 'updateBilled',
id: preorderId,
billed: isChecked ? 1 : 0
},
success: function(response) {
console.log("Update successful:", response);
if (isChecked) {
$("#billed_text").html(`Verrechnet durch: ${response.result.billed_by_name} am ${response.result.billed_date} Uhr`);
window.notify("success", "Preorder wurde als verrechnet markiert.");
} else {
$("#billed_text").html("");
window.notify("success", "Preorder wurde als nicht verrechnet markiert.");
}
},
error: function(xhr, status, error) {
console.error("Update failed:", error);
window.notify("error", "Fehler beim Aktualisieren des Verrechnungsstatus: " + error);
}
});
}
</script>
</tr>
<?php endif; ?>
<tr>
<th>Erstellt:</th>
<td class="text-monospace"><?=date("d.m.Y H:i",$preorder->create)?> (<?=$preorder->creator->name?>)</td>
</tr><tr>

View File

@@ -1080,6 +1080,9 @@ class PreorderController extends mfBaseController {
case "setBilled":
$return = $this->setBilledApi();
break;
case "updateBilled":
$return = $this->updateBilledApi();
break;
default:
$return = false;
}
@@ -1610,4 +1613,29 @@ class PreorderController extends mfBaseController {
return ["message" => "Workorder deleted successfully", "id" => $preorder->id, "wid" => $wo_id];
}
private function updateBilledApi() {
$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;
$billed = $this->request->billed ? (string)time() : "0";
$preorder->billed = $billed;
$preorder->billed_by = $this->me->id;
if (!$preorder->save()) return false;
return [
"message" => "Billed status updated successfully",
"id" => $preorder_id,
"billed" => $billed,
"billed_by_name" => $this->me->name,
"billed_by_id" => $this->me->id,
"billed_date" => date("d.m.Y H:i", $preorder->billed ? $preorder->billed : time())
];
}
}

View File

@@ -1076,6 +1076,13 @@ class PreorderModel
}
}
if (array_key_exists("onlyShowCustomMailSent", $filter)) {
// Only apply the filter if the value is truthy (e.g., true, 1)
if ($filter['onlyShowCustomMailSent']) {
$where .= " AND tt_preorder.id IN (SELECT preorder_id FROM PreorderStatusnotificationLog WHERE email_type = '300-custom')";
}
}
// custom where clause
if (array_key_exists("add-where", $filter)) {
$where .= " " . $filter['add-where'];

View File

@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class PreorderAddBillingFields extends AbstractMigration
{
public function up(): void
{
if($this->getEnvironment() == "thetool") {
$table = $this->table("Preorder");
$table->addColumn("billed", "integer", ["default" => 0, "after" => "billing_period", "comment" => "UNIX timestamp of when the preorder was billed or 0 if not billed"]);
$table->addColumn("billed_by", "integer", ["default" => 0, "after" => "billing_period", "comment" => "User ID of the user who billed the preorder, 0 if not billed"]);
$table->update();
}
if($this->getEnvironment() == "addressdb") {
}
}
public function down(): void
{
if($this->getEnvironment() == "thetool") {
$table = $this->table("Preorder");
$table->removeColumn("billed");
$table->removeColumn("billed_by");
$table->update();
}
if($this->getEnvironment() == "addressdb") {
}
}
}