Page 1 of 1
Filters for FPDF
Posted: 2025-02-10 13:33
by meickert
Hi everyone,
in the current AG, I am trying to generate a PDF using FPDF by replacing the default print button in the table view. So far, this is working well. Now, I tried setting a filter so that not all records are displayed. AG also correctly shows the filtered data, but no matter what I do, all data is still passed to the PDF.
I have a date field called "Wiedervorlage" in my table, and I only want to pass the records to the PDF that I have previously filtered by a specific date. However, I don’t understand how AG applies the filter.
Can someone help me? Thanks in advance.
Marcus
Re: Filters for FPDF
Posted: 2025-02-10 13:43
by meickert
P.S.: I should probably add that I don’t always use the same filter. Instead, I apply different filters for the "Wiedervorlage" field using the filter function, which is why I can't "hardcode" the cell value.
Re: Filters for FPDF
Posted: 2025-02-10 14:10
by meickert
In FPDF I tried:
Code: Select all
// **Filterwerte aus der URL oder Anfrage**
$filterField = isset($_REQUEST['FilterField'][1]) ? $_REQUEST['FilterField'][1] : null;
$filterOperator = isset($_REQUEST['FilterOperator'][1]) ? $_REQUEST['FilterOperator'][1] : null;
$filterValue = isset($_REQUEST['FilterValue'][1]) ? $_REQUEST['FilterValue'][1] : null;
// **SQL-Abfrage mit dynamischem Filter**
$conditions = [];
if (!empty($filterField) && !empty($filterOperator) && !empty($filterValue)) {
// In meinem Fall: FilterField[1] = 12, FilterOperator[1] = equal-to, FilterValue[1] = '2025-02-10'
// Hier Bedingung abhängig von den übergebenen Parametern
if ($filterField == 12) { // Feld-ID 12 entspricht Wiedervorlage
switch ($filterOperator) {
case 'equal-to':
$conditions[] = "v.Wiedervorlage = '" . $mysqli->real_escape_string($filterValue) . "'";
break;
case 'greater-than-or-equal-to':
$conditions[] = "v.Wiedervorlage >= '" . $mysqli->real_escape_string($filterValue) . "'";
break;
case 'less-than-or-equal-to':
$conditions[] = "v.Wiedervorlage <= '" . $mysqli->real_escape_string($filterValue) . "'";
break;
}
}
}
// Grund-Query
$query = "SELECT
v.ContractID,
f.Firma AS Firmenname,
v.Bezeichnung,
v.Jahr,
v.Laufzeit,
v.Betrag,
v.Betriebszweig,
v.Bemerkungen,
v.Stichworte,
v.Produkt,
v.Konto,
v.Wiedervorlage,
v.Kuendigung,
v.Dokumente
FROM vertraege_sh AS v
LEFT JOIN firmen AS f ON v.Firma = f.CustomerID";
// Bedingungen hinzufügen, falls vorhanden
if (count($conditions) > 0) {
$query .= " WHERE " . implode(" AND ", $conditions);
}
// Sortierung
$query .= " ORDER BY v.ContractID ASC";
echo $query; // Debug-Ausgabe, um die Query zu prüfen
$result = $mysqli->query($query);
if (!$result) {
die("SQL-Fehler: " . $mysqli->error);
}
// **Prüfen, ob Daten vorhanden sind**
if ($result->num_rows === 0) {
die("Fehler: Keine gefilterten Verträge gefunden.");
}
This is the code part that has not been successful so far. I have already tried other approaches that didn’t work either, but maybe this still explains a bit what I am trying to do.
