From 1e739cfd3f0af38194f70f3393437f00bd4bc101 Mon Sep 17 00:00:00 2001 From: Ronny Grobel Date: Fri, 17 Apr 2026 17:02:13 +0200 Subject: [PATCH] =?UTF-8?q?Feature:=20is=5Fmandatory=20Flag=20f=C3=BCr=20K?= =?UTF-8?q?ostenpositionstypen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Neue Spalte wp_kgvvm_cost_entries.is_mandatory (TINYINT, default 1) - Kostenposten können jetzt als 'verpflichtend' oder 'manuell/optional' gekennzeichnet werden - Validator: sanitize_cost_entry() und validate_cost_entry() aktualisiert - CostRepository.save(): is_mandatory wird gespeichert - Admin: Checkbox 'Verpflichtende Position' in der Kostenposten-Form hinzugefügt - Datenbank: ALTER TABLE durchgeführt für existierende Instanzen --- includes/Admin/Admin.php | 10 ++++++++++ includes/Repositories/CostRepository.php | 5 +++-- includes/Schema.php | 1 + includes/Validator.php | 2 ++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/includes/Admin/Admin.php b/includes/Admin/Admin.php index 2718eb1..4cdc486 100644 --- a/includes/Admin/Admin.php +++ b/includes/Admin/Admin.php @@ -1373,6 +1373,16 @@ class Admin {

+ + + + +

+ + diff --git a/includes/Repositories/CostRepository.php b/includes/Repositories/CostRepository.php index 3c65246..a6fde31 100644 --- a/includes/Repositories/CostRepository.php +++ b/includes/Repositories/CostRepository.php @@ -93,11 +93,12 @@ class CostRepository extends AbstractRepository { 'distribution_type' => isset( $data['distribution_type'] ) ? $data['distribution_type'] : 'parcel', 'unit_amount' => isset( $data['unit_amount'] ) ? (float) $data['unit_amount'] : 0, 'total_cost' => (float) $data['total_cost'], + 'is_mandatory' => isset( $data['is_mandatory'] ) ? (int) (bool) $data['is_mandatory'] : 1, 'note' => $data['note'], 'updated_at' => $this->now(), ); - $formats = array( '%d', '%s', '%s', '%f', '%f', '%s', '%s' ); + $formats = array( '%d', '%s', '%s', '%f', '%f', '%d', '%s', '%s' ); $this->ensure_year( $payload['entry_year'] ); @@ -107,7 +108,7 @@ class CostRepository extends AbstractRepository { } $payload['created_at'] = $this->now(); - $this->wpdb->insert( $this->table, $payload, array( '%d', '%s', '%s', '%f', '%f', '%s', '%s', '%s' ) ); + $this->wpdb->insert( $this->table, $payload, array( '%d', '%s', '%s', '%f', '%f', '%d', '%s', '%s', '%s' ) ); return $this->wpdb->insert_id; } diff --git a/includes/Schema.php b/includes/Schema.php index 3925d2b..1d46e67 100644 --- a/includes/Schema.php +++ b/includes/Schema.php @@ -201,6 +201,7 @@ class Schema { distribution_type VARCHAR(20) NOT NULL DEFAULT 'parcel', unit_amount DECIMAL(12,2) NULL, total_cost DECIMAL(12,2) NOT NULL DEFAULT 0.00, + is_mandatory TINYINT(1) NOT NULL DEFAULT 1, note TEXT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, diff --git a/includes/Validator.php b/includes/Validator.php index d4c9688..f0c1d02 100644 --- a/includes/Validator.php +++ b/includes/Validator.php @@ -259,6 +259,7 @@ class Validator { $unit_amount = isset( $data['unit_amount'] ) ? str_replace( ',', '.', wp_unslash( $data['unit_amount'] ) ) : ''; $entry_year = $this->sanitize_cost_year( $data ); $distribution_type = sanitize_key( wp_unslash( isset( $data['distribution_type'] ) ? $data['distribution_type'] : 'parcel' ) ); + $is_mandatory = isset( $data['is_mandatory'] ) ? (bool) $data['is_mandatory'] : true; return array( 'entry_year' => $entry_year, @@ -266,6 +267,7 @@ class Validator { 'distribution_type' => $distribution_type, 'unit_amount' => '' === trim( (string) $unit_amount ) ? '' : (float) $unit_amount, 'total_cost' => 0.0, + 'is_mandatory' => $is_mandatory, 'note' => sanitize_textarea_field( wp_unslash( isset( $data['note'] ) ? $data['note'] : '' ) ), ); }