Bump version to 1.17.8
- Feat: Verbrauchsauswertung – Ablesung korrigieren (Datum, Zählerstand, Korrekturnotiz) und löschen direkt aus der Tabelle (manage_kleingarten) - Feat: Inventarverwaltung – Gegenstände erfassen, bearbeiten, löschen; Ausleihe und Rückgabe je Mitglied mit Notiz und Fälligkeitsdatum tracken; Export/Import integriert (InventoryRepository, Schema, Validator, DataTransfer) - Feat: Jahresabrechnung Sperrstatus – Festschreiben/Freigeben mit serverseitiger Prüfung aller Schreibzugriffe auf Kosten und Preise
This commit is contained in:
651
includes/Admin/Admin.php
Normal file → Executable file
651
includes/Admin/Admin.php
Normal file → Executable file
@@ -14,6 +14,7 @@ use KGV\VereinManager\Repositories\ChatRepository;
|
||||
use KGV\VereinManager\Repositories\CostRepository;
|
||||
use KGV\VereinManager\Repositories\MeterReadingRepository;
|
||||
use KGV\VereinManager\Repositories\MeterRepository;
|
||||
use KGV\VereinManager\Repositories\InventoryRepository;
|
||||
use KGV\VereinManager\Repositories\ParcelRepository;
|
||||
use KGV\VereinManager\Repositories\SectionRepository;
|
||||
use KGV\VereinManager\Repositories\TenantRepository;
|
||||
@@ -41,6 +42,7 @@ class Admin {
|
||||
private $parcels;
|
||||
private $meters;
|
||||
private $readings;
|
||||
private $inventory;
|
||||
private $tenants;
|
||||
private $assignments;
|
||||
private $chat;
|
||||
@@ -58,6 +60,7 @@ class Admin {
|
||||
$this->parcels = new ParcelRepository();
|
||||
$this->meters = new MeterRepository();
|
||||
$this->readings = new MeterReadingRepository();
|
||||
$this->inventory = new InventoryRepository();
|
||||
$this->tenants = new TenantRepository();
|
||||
$this->assignments = new AssignmentRepository();
|
||||
$this->chat = new ChatRepository();
|
||||
@@ -106,6 +109,7 @@ class Admin {
|
||||
add_submenu_page( 'kgvvm-dashboard', __( 'Sparten', KGVVM_TEXT_DOMAIN ), __( 'Sparten', KGVVM_TEXT_DOMAIN ), 'edit_sparten', 'kgvvm-sparten', array( $this, 'render_sections_page' ) );
|
||||
add_submenu_page( 'kgvvm-dashboard', __( 'Parzellen', KGVVM_TEXT_DOMAIN ), __( 'Parzellen', KGVVM_TEXT_DOMAIN ), 'edit_parzellen', 'kgvvm-parzellen', array( $this, 'render_parcels_page' ) );
|
||||
add_submenu_page( 'kgvvm-dashboard', __( 'Zähler', KGVVM_TEXT_DOMAIN ), __( 'Zähler', KGVVM_TEXT_DOMAIN ), 'edit_zaehler', 'kgvvm-zaehler', array( $this, 'render_meters_page' ) );
|
||||
add_submenu_page( 'kgvvm-dashboard', __( 'Inventar', KGVVM_TEXT_DOMAIN ), __( 'Inventar', KGVVM_TEXT_DOMAIN ), $cap, 'kgvvm-inventory', array( $this, 'render_inventory_page' ) );
|
||||
add_submenu_page( 'kgvvm-dashboard', __( 'Verbrauch', KGVVM_TEXT_DOMAIN ), __( 'Verbrauch', KGVVM_TEXT_DOMAIN ), $cap, 'kgvvm-consumption', array( $this, 'render_consumption_page' ) );
|
||||
add_submenu_page( 'kgvvm-dashboard', __( 'Kosten', KGVVM_TEXT_DOMAIN ), __( 'Kosten', KGVVM_TEXT_DOMAIN ), $cap, 'kgvvm-costs', array( $this, 'render_costs_page' ) );
|
||||
add_submenu_page( 'kgvvm-dashboard', __( 'Arbeitsstunden', KGVVM_TEXT_DOMAIN ), __( 'Arbeitsstunden', KGVVM_TEXT_DOMAIN ), $cap, 'kgvvm-arbeit', array( $this, 'render_work_page' ) );
|
||||
@@ -234,6 +238,18 @@ class Admin {
|
||||
case 'save_meter_reading':
|
||||
$this->save_meter_reading();
|
||||
break;
|
||||
case 'correct_meter_reading':
|
||||
$this->correct_meter_reading();
|
||||
break;
|
||||
case 'save_inventory_item':
|
||||
$this->save_inventory_item();
|
||||
break;
|
||||
case 'borrow_inventory_item':
|
||||
$this->borrow_inventory_item();
|
||||
break;
|
||||
case 'return_inventory_loan':
|
||||
$this->return_inventory_loan();
|
||||
break;
|
||||
case 'save_settings':
|
||||
$this->save_settings();
|
||||
break;
|
||||
@@ -252,6 +268,9 @@ class Admin {
|
||||
case 'toggle_parcel_cost_assignment':
|
||||
$this->toggle_parcel_cost_assignment();
|
||||
break;
|
||||
case 'set_statement_lock':
|
||||
$this->set_statement_lock();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,6 +315,25 @@ class Admin {
|
||||
$this->meters->delete( $id );
|
||||
$this->redirect_with_notice( 'kgvvm-zaehler', 'success', __( 'Zähler wurde gelöscht.', KGVVM_TEXT_DOMAIN ) );
|
||||
break;
|
||||
case 'delete_meter_reading':
|
||||
$this->require_cap( 'manage_kleingarten' );
|
||||
if ( ! wp_verify_nonce( $nonce, 'kgvvm_delete_meter_reading_' . $id ) ) {
|
||||
$this->redirect_with_notice( 'kgvvm-consumption', 'error', __( 'Der Löschvorgang wurde aus Sicherheitsgründen abgebrochen.', KGVVM_TEXT_DOMAIN ) );
|
||||
}
|
||||
$this->readings->delete( $id );
|
||||
$this->redirect_with_notice( 'kgvvm-consumption', 'success', __( 'Die Ablesung wurde gelöscht.', KGVVM_TEXT_DOMAIN ) );
|
||||
break;
|
||||
case 'delete_inventory_item':
|
||||
$this->require_cap( 'manage_kleingarten' );
|
||||
if ( ! wp_verify_nonce( $nonce, 'kgvvm_delete_inventory_item_' . $id ) ) {
|
||||
$this->redirect_with_notice( 'kgvvm-inventory', 'error', __( 'Der Löschvorgang für den Inventargegenstand wurde aus Sicherheitsgründen abgebrochen.', KGVVM_TEXT_DOMAIN ) );
|
||||
}
|
||||
if ( $this->inventory->has_open_loans( $id ) ) {
|
||||
$this->redirect_with_notice( 'kgvvm-inventory', 'error', __( 'Der Inventargegenstand hat noch offene Ausleihen und kann nicht gelöscht werden.', KGVVM_TEXT_DOMAIN ) );
|
||||
}
|
||||
$this->inventory->delete( $id );
|
||||
$this->redirect_with_notice( 'kgvvm-inventory', 'success', __( 'Inventargegenstand wurde gelöscht.', KGVVM_TEXT_DOMAIN ) );
|
||||
break;
|
||||
case 'delete_tenant':
|
||||
$this->require_cap( 'edit_paechter' );
|
||||
if ( ! wp_verify_nonce( $nonce, 'kgvvm_delete_tenant_' . $id ) ) {
|
||||
@@ -316,6 +354,9 @@ class Admin {
|
||||
$this->redirect_with_notice( 'kgvvm-costs', 'error', __( 'Der gewünschte Kostenposten wurde nicht gefunden.', KGVVM_TEXT_DOMAIN ), array( 'year' => $year ) );
|
||||
}
|
||||
$year = (int) $cost->entry_year;
|
||||
if ( $this->costs->is_statement_locked( $year ) ) {
|
||||
$this->redirect_with_notice( 'kgvvm-costs', 'error', __( 'Die Jahresabrechnung ist festgeschrieben. Änderungen sind erst nach erneuter Freigabe möglich.', KGVVM_TEXT_DOMAIN ), array( 'year' => $year ) );
|
||||
}
|
||||
$this->costs->delete_assignments_for_entry( $id );
|
||||
$this->costs->delete( $id );
|
||||
$this->redirect_with_notice( 'kgvvm-costs', 'success', __( 'Kostenposten wurde gelöscht.', KGVVM_TEXT_DOMAIN ), array( 'year' => $year ) );
|
||||
@@ -660,6 +701,52 @@ class Admin {
|
||||
$this->redirect_with_notice( $return_page, 'success', __( 'Die Ablesung wurde gespeichert.', KGVVM_TEXT_DOMAIN ), $return_args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Correct an existing meter reading (admin only).
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function correct_meter_reading() {
|
||||
$this->require_cap( 'manage_kleingarten' );
|
||||
check_admin_referer( 'kgvvm_correct_meter_reading' );
|
||||
|
||||
$id = absint( isset( $_POST['reading_id'] ) ? $_POST['reading_id'] : 0 );
|
||||
$value = isset( $_POST['reading_value'] ) ? (float) wp_unslash( $_POST['reading_value'] ) : null;
|
||||
$date = isset( $_POST['reading_date'] ) ? sanitize_text_field( wp_unslash( $_POST['reading_date'] ) ) : '';
|
||||
$note = isset( $_POST['note'] ) ? sanitize_textarea_field( wp_unslash( $_POST['note'] ) ) : '';
|
||||
|
||||
$return_args = array_filter(
|
||||
array(
|
||||
'section_id' => absint( isset( $_POST['section_id'] ) ? $_POST['section_id'] : 0 ),
|
||||
'date_from' => sanitize_text_field( wp_unslash( isset( $_POST['date_from'] ) ? $_POST['date_from'] : '' ) ),
|
||||
'date_to' => sanitize_text_field( wp_unslash( isset( $_POST['date_to'] ) ? $_POST['date_to'] : '' ) ),
|
||||
'order' => sanitize_key( wp_unslash( isset( $_POST['order'] ) ? $_POST['order'] : 'DESC' ) ),
|
||||
),
|
||||
static function( $v ) { return '' !== $v && 0 !== $v; }
|
||||
);
|
||||
|
||||
$reading = $id ? $this->readings->find( $id ) : null;
|
||||
|
||||
if ( ! $reading ) {
|
||||
$this->redirect_with_notice( 'kgvvm-consumption', 'error', __( 'Die Ablesung wurde nicht gefunden.', KGVVM_TEXT_DOMAIN ), $return_args );
|
||||
}
|
||||
|
||||
if ( null === $value || '' === $date ) {
|
||||
$this->redirect_with_notice( 'kgvvm-consumption', 'error', __( 'Bitte Zählerstand und Datum angeben.', KGVVM_TEXT_DOMAIN ), $return_args );
|
||||
}
|
||||
|
||||
$this->readings->update_reading(
|
||||
$id,
|
||||
array(
|
||||
'reading_value' => $value,
|
||||
'reading_date' => $date,
|
||||
'note' => $note,
|
||||
)
|
||||
);
|
||||
|
||||
$this->redirect_with_notice( 'kgvvm-consumption', 'success', __( 'Die Ablesung wurde korrigiert.', KGVVM_TEXT_DOMAIN ), $return_args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save general settings.
|
||||
*
|
||||
@@ -794,6 +881,10 @@ class Admin {
|
||||
$this->redirect_with_notice( 'kgvvm-costs', 'error', $errors->get_error_message(), array( 'year' => $data['entry_year'] ) );
|
||||
}
|
||||
|
||||
if ( $this->costs->is_statement_locked( (int) $data['entry_year'] ) ) {
|
||||
$this->redirect_with_notice( 'kgvvm-costs', 'error', __( 'Die Jahresabrechnung ist festgeschrieben. Änderungen sind erst nach erneuter Freigabe möglich.', KGVVM_TEXT_DOMAIN ), array( 'year' => $data['entry_year'] ) );
|
||||
}
|
||||
|
||||
if ( ! $this->costs->save_section_prices( $data ) ) {
|
||||
$this->redirect_with_notice( 'kgvvm-costs', 'error', __( 'Die Preise für diese Sparte konnten nicht gespeichert werden.', KGVVM_TEXT_DOMAIN ), array( 'year' => $data['entry_year'] ) );
|
||||
}
|
||||
@@ -813,11 +904,20 @@ class Admin {
|
||||
$id = absint( isset( $_POST['id'] ) ? $_POST['id'] : 0 );
|
||||
$data = $this->validator->sanitize_cost_entry( $_POST );
|
||||
$errors = $this->validator->validate_cost_entry( $data );
|
||||
$existing = $id > 0 ? $this->costs->find( $id ) : null;
|
||||
|
||||
if ( $errors->has_errors() ) {
|
||||
$this->redirect_with_notice( 'kgvvm-costs', 'error', $errors->get_error_message(), array( 'year' => $data['entry_year'], 'id' => $id ) );
|
||||
}
|
||||
|
||||
if ( $existing && $this->costs->is_statement_locked( (int) $existing->entry_year ) ) {
|
||||
$this->redirect_with_notice( 'kgvvm-costs', 'error', __( 'Die Jahresabrechnung ist festgeschrieben. Änderungen sind erst nach erneuter Freigabe möglich.', KGVVM_TEXT_DOMAIN ), array( 'year' => (int) $existing->entry_year, 'id' => $id ) );
|
||||
}
|
||||
|
||||
if ( $this->costs->is_statement_locked( (int) $data['entry_year'] ) ) {
|
||||
$this->redirect_with_notice( 'kgvvm-costs', 'error', __( 'Die Jahresabrechnung ist festgeschrieben. Änderungen sind erst nach erneuter Freigabe möglich.', KGVVM_TEXT_DOMAIN ), array( 'year' => $data['entry_year'], 'id' => $id ) );
|
||||
}
|
||||
|
||||
$active_parcels = array_values(
|
||||
array_filter(
|
||||
$this->parcels->search(),
|
||||
@@ -857,6 +957,10 @@ class Admin {
|
||||
$this->redirect_with_notice( 'kgvvm-costs', 'error', __( 'Ungültige Anfrage.', KGVVM_TEXT_DOMAIN ), array( 'view' => 'statement', 'statement_type' => 'parcel', 'subject_id' => $parcel_id, 'year' => $year ) );
|
||||
}
|
||||
|
||||
if ( $this->costs->is_statement_locked( $year ) ) {
|
||||
$this->redirect_with_notice( 'kgvvm-costs', 'error', __( 'Die Jahresabrechnung ist festgeschrieben. Änderungen sind erst nach erneuter Freigabe möglich.', KGVVM_TEXT_DOMAIN ), array( 'view' => 'statement', 'statement_type' => 'parcel', 'subject_id' => $parcel_id, 'year' => $year ) );
|
||||
}
|
||||
|
||||
if ( 'add' === $mode ) {
|
||||
$this->costs->assign_to_parcel( $parcel_id, $cost_entry_id );
|
||||
} else {
|
||||
@@ -867,6 +971,401 @@ class Admin {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock or unlock annual statement changes for one year.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function set_statement_lock() {
|
||||
$this->require_cap( 'manage_kleingarten' );
|
||||
$year = absint( isset( $_POST['year'] ) ? $_POST['year'] : current_time( 'Y' ) );
|
||||
$statement_type = isset( $_POST['statement_type'] ) ? sanitize_key( wp_unslash( $_POST['statement_type'] ) ) : 'parcel';
|
||||
$subject_id = absint( isset( $_POST['subject_id'] ) ? $_POST['subject_id'] : 0 );
|
||||
$mode = isset( $_POST['lock_mode'] ) ? sanitize_key( wp_unslash( $_POST['lock_mode'] ) ) : '';
|
||||
|
||||
check_admin_referer( 'kgvvm_set_statement_lock_' . $year );
|
||||
|
||||
if ( $year < 1 || ! in_array( $mode, array( 'lock', 'unlock' ), true ) ) {
|
||||
$this->redirect_with_notice( 'kgvvm-costs', 'error', __( 'Ungültige Anfrage.', KGVVM_TEXT_DOMAIN ), array( 'view' => 'statement', 'statement_type' => $statement_type, 'subject_id' => $subject_id, 'year' => $year ) );
|
||||
}
|
||||
|
||||
$is_locked = 'lock' === $mode;
|
||||
$saved = $this->costs->set_statement_lock( $year, $is_locked, get_current_user_id() );
|
||||
|
||||
if ( ! $saved ) {
|
||||
$this->redirect_with_notice( 'kgvvm-costs', 'error', __( 'Der Sperrstatus der Jahresabrechnung konnte nicht gespeichert werden.', KGVVM_TEXT_DOMAIN ), array( 'view' => 'statement', 'statement_type' => $statement_type, 'subject_id' => $subject_id, 'year' => $year ) );
|
||||
}
|
||||
|
||||
$this->redirect_with_notice(
|
||||
'kgvvm-costs',
|
||||
'success',
|
||||
$is_locked ? __( 'Jahresabrechnung wurde festgeschrieben.', KGVVM_TEXT_DOMAIN ) : __( 'Jahresabrechnung wurde erneut freigegeben.', KGVVM_TEXT_DOMAIN ),
|
||||
array( 'view' => 'statement', 'statement_type' => $statement_type, 'subject_id' => $subject_id, 'year' => $year )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save one inventory item.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function save_inventory_item() {
|
||||
$this->require_cap( 'manage_kleingarten' );
|
||||
check_admin_referer( 'kgvvm_save_inventory_item' );
|
||||
|
||||
$id = absint( isset( $_POST['id'] ) ? $_POST['id'] : 0 );
|
||||
$data = $this->validator->sanitize_inventory_item( $_POST );
|
||||
$errors = $this->validator->validate_inventory_item( $data );
|
||||
$existing = $id > 0 ? $this->inventory->find( $id ) : null;
|
||||
|
||||
if ( $existing ) {
|
||||
$borrowed_qty = $this->inventory->get_open_borrowed_quantity( $id );
|
||||
|
||||
if ( (int) $data['total_quantity'] < $borrowed_qty ) {
|
||||
$errors->add( 'inventory_total_too_low', __( 'Die Gesamtmenge ist kleiner als aktuell ausgeliehen. Bitte zuerst Rückgaben erfassen.', KGVVM_TEXT_DOMAIN ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $errors->has_errors() ) {
|
||||
$this->redirect_with_notice( 'kgvvm-inventory', 'error', $errors->get_error_message(), array( 'id' => $id ) );
|
||||
}
|
||||
|
||||
$saved = $this->inventory->save_item( $data, $id );
|
||||
|
||||
if ( ! $saved ) {
|
||||
$this->redirect_with_notice( 'kgvvm-inventory', 'error', __( 'Der Inventargegenstand konnte nicht gespeichert werden.', KGVVM_TEXT_DOMAIN ), array( 'id' => $id ) );
|
||||
}
|
||||
|
||||
$this->redirect_with_notice( 'kgvvm-inventory', 'success', __( 'Inventargegenstand wurde gespeichert.', KGVVM_TEXT_DOMAIN ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Borrow inventory item for one member.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function borrow_inventory_item() {
|
||||
$this->require_cap( 'manage_kleingarten' );
|
||||
check_admin_referer( 'kgvvm_borrow_inventory_item' );
|
||||
|
||||
$data = $this->validator->sanitize_inventory_loan( $_POST );
|
||||
$errors = $this->validator->validate_inventory_loan( $data );
|
||||
|
||||
$item = $this->inventory->find( $data['item_id'] );
|
||||
|
||||
if ( ! $item ) {
|
||||
$errors->add( 'inventory_item_missing', __( 'Der gewählte Inventargegenstand wurde nicht gefunden.', KGVVM_TEXT_DOMAIN ) );
|
||||
} elseif ( ! (bool) $item->is_active ) {
|
||||
$errors->add( 'inventory_item_inactive', __( 'Der gewählte Inventargegenstand ist inaktiv.', KGVVM_TEXT_DOMAIN ) );
|
||||
} elseif ( (int) $data['quantity'] > (int) $item->available_quantity ) {
|
||||
$errors->add( 'inventory_item_not_available', __( 'Die gewünschte Menge ist nicht verfügbar.', KGVVM_TEXT_DOMAIN ) );
|
||||
}
|
||||
|
||||
if ( $errors->has_errors() ) {
|
||||
$this->redirect_with_notice( 'kgvvm-inventory', 'error', $errors->get_error_message() );
|
||||
}
|
||||
|
||||
$saved = $this->inventory->borrow_item( $data['item_id'], $data['user_id'], $data['quantity'], $data['due_date'], $data['note'] );
|
||||
|
||||
if ( ! $saved ) {
|
||||
$this->redirect_with_notice( 'kgvvm-inventory', 'error', __( 'Die Ausleihe konnte nicht gespeichert werden.', KGVVM_TEXT_DOMAIN ) );
|
||||
}
|
||||
|
||||
$this->redirect_with_notice( 'kgvvm-inventory', 'success', __( 'Ausleihe wurde erfasst.', KGVVM_TEXT_DOMAIN ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return one inventory loan.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function return_inventory_loan() {
|
||||
$this->require_cap( 'manage_kleingarten' );
|
||||
check_admin_referer( 'kgvvm_return_inventory_loan' );
|
||||
|
||||
$loan_id = absint( isset( $_POST['loan_id'] ) ? $_POST['loan_id'] : 0 );
|
||||
$return_note = sanitize_textarea_field( wp_unslash( isset( $_POST['return_note'] ) ? $_POST['return_note'] : '' ) );
|
||||
|
||||
if ( $loan_id < 1 ) {
|
||||
$this->redirect_with_notice( 'kgvvm-inventory', 'error', __( 'Ungültige Anfrage.', KGVVM_TEXT_DOMAIN ) );
|
||||
}
|
||||
|
||||
$saved = $this->inventory->return_loan( $loan_id, $return_note );
|
||||
|
||||
if ( ! $saved ) {
|
||||
$this->redirect_with_notice( 'kgvvm-inventory', 'error', __( 'Die Rückgabe konnte nicht gespeichert werden.', KGVVM_TEXT_DOMAIN ) );
|
||||
}
|
||||
|
||||
$this->redirect_with_notice( 'kgvvm-inventory', 'success', __( 'Rückgabe wurde erfasst.', KGVVM_TEXT_DOMAIN ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Render inventory management page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function render_inventory_page() {
|
||||
$this->require_cap( 'manage_kleingarten' );
|
||||
|
||||
$search = isset( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : '';
|
||||
$edit_id = absint( isset( $_GET['id'] ) ? $_GET['id'] : 0 );
|
||||
$item = $edit_id > 0 ? $this->inventory->find( $edit_id ) : null;
|
||||
|
||||
$items = $this->inventory->search_items( array( 's' => $search, 'orderby' => isset( $_GET['orderby'] ) ? sanitize_key( wp_unslash( $_GET['orderby'] ) ) : 'name', 'order' => isset( $_GET['order'] ) ? sanitize_key( wp_unslash( $_GET['order'] ) ) : 'ASC' ) );
|
||||
$open_loans = $this->inventory->get_open_loans();
|
||||
$recent_loans = $this->inventory->get_recent_loans( 20 );
|
||||
|
||||
$member_query = new \WP_User_Query(
|
||||
array(
|
||||
'role' => Roles::MEMBER_ROLE,
|
||||
'fields' => array( 'ID', 'display_name', 'user_email' ),
|
||||
'orderby' => 'display_name',
|
||||
'order' => 'ASC',
|
||||
'number' => 2000,
|
||||
)
|
||||
);
|
||||
|
||||
$members = (array) $member_query->get_results();
|
||||
|
||||
if ( empty( $members ) ) {
|
||||
$members = (array) $this->assignments->get_member_users();
|
||||
}
|
||||
|
||||
$summary_total_items = count( $items );
|
||||
$summary_available_total = 0;
|
||||
$summary_open_total = count( $open_loans );
|
||||
|
||||
foreach ( $items as $row ) {
|
||||
$summary_available_total += max( 0, (int) $row->available_quantity );
|
||||
}
|
||||
?>
|
||||
<div class='wrap'>
|
||||
<h1 class='wp-heading-inline'><?php echo esc_html__( 'Inventar', KGVVM_TEXT_DOMAIN ); ?></h1>
|
||||
<?php if ( $item ) : ?>
|
||||
<a href='<?php echo esc_url( $this->admin_url( 'kgvvm-inventory' ) ); ?>' class='page-title-action'><?php echo esc_html__( 'Neuer Gegenstand', KGVVM_TEXT_DOMAIN ); ?></a>
|
||||
<?php endif; ?>
|
||||
<?php $this->render_notice(); ?>
|
||||
|
||||
<form method='get' class='kgvvm-toolbar'>
|
||||
<input type='hidden' name='page' value='kgvvm-inventory' />
|
||||
<div class='kgvvm-filters'>
|
||||
<input type='search' name='s' value='<?php echo esc_attr( $search ); ?>' placeholder='<?php echo esc_attr__( 'Inventar suchen ...', KGVVM_TEXT_DOMAIN ); ?>' />
|
||||
<button class='button'><?php echo esc_html__( 'Filtern', KGVVM_TEXT_DOMAIN ); ?></button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class='kgvvm-grid'>
|
||||
<div class='kgvvm-card'>
|
||||
<h2><?php echo esc_html( number_format_i18n( $summary_total_items, 0 ) ); ?></h2>
|
||||
<p><?php echo esc_html__( 'Inventargegenstände', KGVVM_TEXT_DOMAIN ); ?></p>
|
||||
</div>
|
||||
<div class='kgvvm-card'>
|
||||
<h2><?php echo esc_html( number_format_i18n( $summary_available_total, 0 ) ); ?></h2>
|
||||
<p><?php echo esc_html__( 'Verfügbar gesamt', KGVVM_TEXT_DOMAIN ); ?></p>
|
||||
</div>
|
||||
<div class='kgvvm-card'>
|
||||
<h2><?php echo esc_html( number_format_i18n( $summary_open_total, 0 ) ); ?></h2>
|
||||
<p><?php echo esc_html__( 'Offene Ausleihen', KGVVM_TEXT_DOMAIN ); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class='kgvvm-grid'>
|
||||
<div class='kgvvm-card'>
|
||||
<h2><?php echo esc_html( $item ? __( 'Gegenstand bearbeiten', KGVVM_TEXT_DOMAIN ) : __( 'Gegenstand anlegen', KGVVM_TEXT_DOMAIN ) ); ?></h2>
|
||||
<form method='post'>
|
||||
<?php wp_nonce_field( 'kgvvm_save_inventory_item' ); ?>
|
||||
<input type='hidden' name='kgvvm_action' value='save_inventory_item' />
|
||||
<input type='hidden' name='id' value='<?php echo esc_attr( $item ? $item->id : 0 ); ?>' />
|
||||
<table class='form-table kgvvm-form-table'>
|
||||
<tr>
|
||||
<th scope='row'><label for='kgvvm-item-name'><?php echo esc_html__( 'Name', KGVVM_TEXT_DOMAIN ); ?></label></th>
|
||||
<td><input name='name' id='kgvvm-item-name' type='text' class='regular-text' required value='<?php echo esc_attr( $item ? $item->name : '' ); ?>' /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope='row'><label for='kgvvm-item-total'><?php echo esc_html__( 'Gesamtmenge', KGVVM_TEXT_DOMAIN ); ?></label></th>
|
||||
<td><input name='total_quantity' id='kgvvm-item-total' type='number' min='0' required value='<?php echo esc_attr( $item ? (int) $item->total_quantity : 1 ); ?>' /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope='row'><label for='kgvvm-item-available'><?php echo esc_html__( 'Verfügbar', KGVVM_TEXT_DOMAIN ); ?></label></th>
|
||||
<td><input name='available_quantity' id='kgvvm-item-available' type='number' min='0' required value='<?php echo esc_attr( $item ? (int) $item->available_quantity : 1 ); ?>' /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope='row'><label for='kgvvm-item-location'><?php echo esc_html__( 'Lagerort', KGVVM_TEXT_DOMAIN ); ?></label></th>
|
||||
<td><input name='storage_location' id='kgvvm-item-location' type='text' class='regular-text' value='<?php echo esc_attr( $item ? $item->storage_location : '' ); ?>' /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope='row'><label for='kgvvm-item-description'><?php echo esc_html__( 'Beschreibung', KGVVM_TEXT_DOMAIN ); ?></label></th>
|
||||
<td><textarea name='description' id='kgvvm-item-description' rows='3' class='large-text'><?php echo esc_textarea( $item ? $item->description : '' ); ?></textarea></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope='row'><?php echo esc_html__( 'Status', KGVVM_TEXT_DOMAIN ); ?></th>
|
||||
<td>
|
||||
<label><input type='hidden' name='is_active' value='0' /><input type='checkbox' name='is_active' value='1' <?php checked( $item ? (bool) $item->is_active : true ); ?> /> <?php echo esc_html__( 'Aktiv', KGVVM_TEXT_DOMAIN ); ?></label>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php submit_button( $item ? __( 'Gegenstand aktualisieren', KGVVM_TEXT_DOMAIN ) : __( 'Gegenstand speichern', KGVVM_TEXT_DOMAIN ) ); ?>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class='kgvvm-card'>
|
||||
<h2><?php echo esc_html__( 'Ausleihe erfassen', KGVVM_TEXT_DOMAIN ); ?></h2>
|
||||
<form method='post'>
|
||||
<?php wp_nonce_field( 'kgvvm_borrow_inventory_item' ); ?>
|
||||
<input type='hidden' name='kgvvm_action' value='borrow_inventory_item' />
|
||||
<table class='form-table kgvvm-form-table'>
|
||||
<tr>
|
||||
<th scope='row'><label for='kgvvm-loan-item'><?php echo esc_html__( 'Gegenstand', KGVVM_TEXT_DOMAIN ); ?></label></th>
|
||||
<td>
|
||||
<select name='item_id' id='kgvvm-loan-item' required>
|
||||
<option value=''><?php echo esc_html__( 'Bitte wählen', KGVVM_TEXT_DOMAIN ); ?></option>
|
||||
<?php foreach ( $items as $inventory_item ) : ?>
|
||||
<?php if ( ! (bool) $inventory_item->is_active ) : ?>
|
||||
<?php continue; ?>
|
||||
<?php endif; ?>
|
||||
<option value='<?php echo esc_attr( $inventory_item->id ); ?>'><?php echo esc_html( $inventory_item->name . ' (' . (int) $inventory_item->available_quantity . ' verfügbar)' ); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope='row'><label for='kgvvm-loan-member'><?php echo esc_html__( 'Mitglied', KGVVM_TEXT_DOMAIN ); ?></label></th>
|
||||
<td>
|
||||
<select name='user_id' id='kgvvm-loan-member' required>
|
||||
<option value=''><?php echo esc_html__( 'Bitte wählen', KGVVM_TEXT_DOMAIN ); ?></option>
|
||||
<?php foreach ( $members as $member ) : ?>
|
||||
<option value='<?php echo esc_attr( $member->ID ); ?>'><?php echo esc_html( $member->display_name ); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope='row'><label for='kgvvm-loan-quantity'><?php echo esc_html__( 'Menge', KGVVM_TEXT_DOMAIN ); ?></label></th>
|
||||
<td><input name='quantity' id='kgvvm-loan-quantity' type='number' min='1' required value='1' /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope='row'><label for='kgvvm-loan-due'><?php echo esc_html__( 'Rückgabe geplant', KGVVM_TEXT_DOMAIN ); ?></label></th>
|
||||
<td><input name='due_date' id='kgvvm-loan-due' type='date' value='' /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope='row'><label for='kgvvm-loan-note'><?php echo esc_html__( 'Notiz', KGVVM_TEXT_DOMAIN ); ?></label></th>
|
||||
<td><textarea name='note' id='kgvvm-loan-note' rows='3' class='large-text'></textarea></td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php submit_button( __( 'Ausleihe speichern', KGVVM_TEXT_DOMAIN ), 'secondary' ); ?>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class='kgvvm-card'>
|
||||
<h2><?php echo esc_html__( 'Inventarliste', KGVVM_TEXT_DOMAIN ); ?></h2>
|
||||
<table class='widefat striped'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php echo esc_html__( 'Name', KGVVM_TEXT_DOMAIN ); ?></th>
|
||||
<th><?php echo esc_html__( 'Lagerort', KGVVM_TEXT_DOMAIN ); ?></th>
|
||||
<th><?php echo esc_html__( 'Gesamt', KGVVM_TEXT_DOMAIN ); ?></th>
|
||||
<th><?php echo esc_html__( 'Verfügbar', KGVVM_TEXT_DOMAIN ); ?></th>
|
||||
<th><?php echo esc_html__( 'Status', KGVVM_TEXT_DOMAIN ); ?></th>
|
||||
<th><?php echo esc_html__( 'Aktionen', KGVVM_TEXT_DOMAIN ); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if ( empty( $items ) ) : ?>
|
||||
<tr><td colspan='6'><?php echo esc_html__( 'Keine Inventargegenstände gefunden.', KGVVM_TEXT_DOMAIN ); ?></td></tr>
|
||||
<?php else : ?>
|
||||
<?php foreach ( $items as $row ) : ?>
|
||||
<tr>
|
||||
<td><strong><?php echo esc_html( $row->name ); ?></strong></td>
|
||||
<td><?php echo esc_html( ! empty( $row->storage_location ) ? $row->storage_location : '—' ); ?></td>
|
||||
<td><?php echo esc_html( number_format_i18n( (int) $row->total_quantity, 0 ) ); ?></td>
|
||||
<td><?php echo esc_html( number_format_i18n( (int) $row->available_quantity, 0 ) ); ?></td>
|
||||
<td><?php echo esc_html( (bool) $row->is_active ? __( 'Aktiv', KGVVM_TEXT_DOMAIN ) : __( 'Inaktiv', KGVVM_TEXT_DOMAIN ) ); ?></td>
|
||||
<td>
|
||||
<a href='<?php echo esc_url( $this->admin_url( 'kgvvm-inventory', array( 'id' => $row->id ) ) ); ?>'><?php echo esc_html__( 'Bearbeiten', KGVVM_TEXT_DOMAIN ); ?></a>
|
||||
|
|
||||
<a href='<?php echo esc_url( wp_nonce_url( $this->admin_url( 'kgvvm-inventory', array( 'kgvvm_action' => 'delete_inventory_item', 'id' => $row->id ) ), 'kgvvm_delete_inventory_item_' . $row->id ) ); ?>' onclick='return confirm("<?php echo esc_js( __( 'Inventargegenstand wirklich löschen?', KGVVM_TEXT_DOMAIN ) ); ?>");'><?php echo esc_html__( 'Löschen', KGVVM_TEXT_DOMAIN ); ?></a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class='kgvvm-card'>
|
||||
<h2><?php echo esc_html__( 'Offene Ausleihen', KGVVM_TEXT_DOMAIN ); ?></h2>
|
||||
<table class='widefat striped'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php echo esc_html__( 'Gegenstand', KGVVM_TEXT_DOMAIN ); ?></th>
|
||||
<th><?php echo esc_html__( 'Mitglied', KGVVM_TEXT_DOMAIN ); ?></th>
|
||||
<th><?php echo esc_html__( 'Menge', KGVVM_TEXT_DOMAIN ); ?></th>
|
||||
<th><?php echo esc_html__( 'Ausgeliehen am', KGVVM_TEXT_DOMAIN ); ?></th>
|
||||
<th><?php echo esc_html__( 'Rückgabe geplant', KGVVM_TEXT_DOMAIN ); ?></th>
|
||||
<th><?php echo esc_html__( 'Aktion', KGVVM_TEXT_DOMAIN ); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if ( empty( $open_loans ) ) : ?>
|
||||
<tr><td colspan='6'><?php echo esc_html__( 'Keine offenen Ausleihen vorhanden.', KGVVM_TEXT_DOMAIN ); ?></td></tr>
|
||||
<?php else : ?>
|
||||
<?php foreach ( $open_loans as $loan ) : ?>
|
||||
<tr>
|
||||
<td><?php echo esc_html( $loan->item_name ? $loan->item_name : '—' ); ?></td>
|
||||
<td><?php echo esc_html( $loan->borrower_name ? $loan->borrower_name : '—' ); ?></td>
|
||||
<td><?php echo esc_html( number_format_i18n( (int) $loan->borrowed_quantity, 0 ) ); ?></td>
|
||||
<td><?php echo esc_html( ! empty( $loan->borrowed_at ) ? wp_date( 'd.m.Y H:i', strtotime( $loan->borrowed_at ) ) : '—' ); ?></td>
|
||||
<td><?php echo esc_html( ! empty( $loan->due_date ) ? wp_date( 'd.m.Y', strtotime( $loan->due_date ) ) : '—' ); ?></td>
|
||||
<td>
|
||||
<form method='post' style='display:flex; gap:6px; align-items:center;'>
|
||||
<?php wp_nonce_field( 'kgvvm_return_inventory_loan' ); ?>
|
||||
<input type='hidden' name='kgvvm_action' value='return_inventory_loan' />
|
||||
<input type='hidden' name='loan_id' value='<?php echo esc_attr( $loan->id ); ?>' />
|
||||
<input type='text' name='return_note' value='' placeholder='<?php echo esc_attr__( 'Rückgabe-Notiz', KGVVM_TEXT_DOMAIN ); ?>' />
|
||||
<button type='submit' class='button button-small'><?php echo esc_html__( 'Rückgabe', KGVVM_TEXT_DOMAIN ); ?></button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class='kgvvm-card'>
|
||||
<h2><?php echo esc_html__( 'Letzte Ausleihvorgänge', KGVVM_TEXT_DOMAIN ); ?></h2>
|
||||
<table class='widefat striped'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php echo esc_html__( 'Zeitpunkt', KGVVM_TEXT_DOMAIN ); ?></th>
|
||||
<th><?php echo esc_html__( 'Gegenstand', KGVVM_TEXT_DOMAIN ); ?></th>
|
||||
<th><?php echo esc_html__( 'Mitglied', KGVVM_TEXT_DOMAIN ); ?></th>
|
||||
<th><?php echo esc_html__( 'Menge', KGVVM_TEXT_DOMAIN ); ?></th>
|
||||
<th><?php echo esc_html__( 'Status', KGVVM_TEXT_DOMAIN ); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if ( empty( $recent_loans ) ) : ?>
|
||||
<tr><td colspan='5'><?php echo esc_html__( 'Noch keine Ausleihen vorhanden.', KGVVM_TEXT_DOMAIN ); ?></td></tr>
|
||||
<?php else : ?>
|
||||
<?php foreach ( $recent_loans as $row ) : ?>
|
||||
<tr>
|
||||
<td><?php echo esc_html( ! empty( $row->borrowed_at ) ? wp_date( 'd.m.Y H:i', strtotime( $row->borrowed_at ) ) : '—' ); ?></td>
|
||||
<td><?php echo esc_html( $row->item_name ? $row->item_name : '—' ); ?></td>
|
||||
<td><?php echo esc_html( $row->borrower_name ? $row->borrower_name : '—' ); ?></td>
|
||||
<td><?php echo esc_html( number_format_i18n( (int) $row->borrowed_quantity, 0 ) ); ?></td>
|
||||
<td><?php echo esc_html( 'open' === $row->status ? __( 'Offen', KGVVM_TEXT_DOMAIN ) : __( 'Zurückgegeben', KGVVM_TEXT_DOMAIN ) ); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Render dashboard.
|
||||
*
|
||||
@@ -984,12 +1483,14 @@ class Admin {
|
||||
public function render_consumption_page() {
|
||||
$this->require_cap( 'manage_kleingarten' );
|
||||
|
||||
$section_id = isset( $_GET['section_id'] ) ? absint( $_GET['section_id'] ) : 0;
|
||||
$date_from = isset( $_GET['date_from'] ) ? sanitize_text_field( wp_unslash( $_GET['date_from'] ) ) : '';
|
||||
$date_to = isset( $_GET['date_to'] ) ? sanitize_text_field( wp_unslash( $_GET['date_to'] ) ) : '';
|
||||
$order = isset( $_GET['order'] ) ? strtoupper( sanitize_key( wp_unslash( $_GET['order'] ) ) ) : 'DESC';
|
||||
$order = 'ASC' === $order ? 'ASC' : 'DESC';
|
||||
$sections = $this->sections->all_for_options();
|
||||
$section_id = isset( $_GET['section_id'] ) ? absint( $_GET['section_id'] ) : 0;
|
||||
$date_from = isset( $_GET['date_from'] ) ? sanitize_text_field( wp_unslash( $_GET['date_from'] ) ) : '';
|
||||
$date_to = isset( $_GET['date_to'] ) ? sanitize_text_field( wp_unslash( $_GET['date_to'] ) ) : '';
|
||||
$order = isset( $_GET['order'] ) ? strtoupper( sanitize_key( wp_unslash( $_GET['order'] ) ) ) : 'DESC';
|
||||
$order = 'ASC' === $order ? 'ASC' : 'DESC';
|
||||
$edit_reading_id = isset( $_GET['edit_reading'] ) ? absint( $_GET['edit_reading'] ) : 0;
|
||||
$edit_reading = $edit_reading_id ? $this->readings->find( $edit_reading_id ) : null;
|
||||
$sections = $this->sections->all_for_options();
|
||||
|
||||
if ( $date_from && $date_to && strtotime( $date_from ) > strtotime( $date_to ) ) {
|
||||
$tmp = $date_from;
|
||||
@@ -1051,6 +1552,42 @@ class Admin {
|
||||
<h1><?php echo esc_html__( 'Verbrauchsauswertung', KGVVM_TEXT_DOMAIN ); ?></h1>
|
||||
<?php $this->render_notice(); ?>
|
||||
|
||||
<?php if ( $edit_reading ) : ?>
|
||||
<div class='kgvvm-card'>
|
||||
<h2><?php echo esc_html__( 'Ablesung korrigieren', KGVVM_TEXT_DOMAIN ); ?></h2>
|
||||
<form method='post'>
|
||||
<?php wp_nonce_field( 'kgvvm_correct_meter_reading' ); ?>
|
||||
<input type='hidden' name='kgvvm_action' value='correct_meter_reading' />
|
||||
<input type='hidden' name='reading_id' value='<?php echo esc_attr( $edit_reading->id ); ?>' />
|
||||
<input type='hidden' name='section_id' value='<?php echo esc_attr( $section_id ); ?>' />
|
||||
<input type='hidden' name='date_from' value='<?php echo esc_attr( $date_from ); ?>' />
|
||||
<input type='hidden' name='date_to' value='<?php echo esc_attr( $date_to ); ?>' />
|
||||
<input type='hidden' name='order' value='<?php echo esc_attr( $order ); ?>' />
|
||||
<table class='form-table'>
|
||||
<tr>
|
||||
<th><label for='corr_date'><?php echo esc_html__( 'Ablesedatum', KGVVM_TEXT_DOMAIN ); ?></label></th>
|
||||
<td><input type='date' id='corr_date' name='reading_date' value='<?php echo esc_attr( $edit_reading->reading_date ); ?>' required /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><label for='corr_value'><?php echo esc_html__( 'Zählerstand', KGVVM_TEXT_DOMAIN ); ?></label></th>
|
||||
<td><input type='number' id='corr_value' name='reading_value' step='0.001' value='<?php echo esc_attr( number_format( (float) $edit_reading->reading_value, 3, '.', '' ) ); ?>' required /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><label for='corr_note'><?php echo esc_html__( 'Korrekturnotiz', KGVVM_TEXT_DOMAIN ); ?></label></th>
|
||||
<td>
|
||||
<textarea id='corr_note' name='note' rows='3' cols='50'><?php echo esc_textarea( $edit_reading->note ); ?></textarea>
|
||||
<p class='description'><?php echo esc_html__( 'Bitte den Grund der Korrektur angeben.', KGVVM_TEXT_DOMAIN ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p class='submit'>
|
||||
<button type='submit' class='button button-primary'><?php echo esc_html__( 'Korrektur speichern', KGVVM_TEXT_DOMAIN ); ?></button>
|
||||
<a href='<?php echo esc_url( $this->admin_url( 'kgvvm-consumption', array_filter( array( 'section_id' => $section_id, 'date_from' => $date_from, 'date_to' => $date_to, 'order' => $order ) ) ) ); ?>' class='button'><?php echo esc_html__( 'Abbrechen', KGVVM_TEXT_DOMAIN ); ?></a>
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method='get' class='kgvvm-toolbar'>
|
||||
<input type='hidden' name='page' value='kgvvm-consumption' />
|
||||
<div class='kgvvm-filters'>
|
||||
@@ -1141,23 +1678,49 @@ class Admin {
|
||||
<th><?php echo esc_html__( 'Verbrauch seit letzter Ablesung', KGVVM_TEXT_DOMAIN ); ?></th>
|
||||
<th><?php echo esc_html__( 'Preis je Einheit', KGVVM_TEXT_DOMAIN ); ?></th>
|
||||
<th><?php echo esc_html__( 'Kosten', KGVVM_TEXT_DOMAIN ); ?></th>
|
||||
<th><?php echo esc_html__( 'Aktionen', KGVVM_TEXT_DOMAIN ); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if ( empty( $rows ) ) : ?>
|
||||
<tr><td colspan='9'><?php echo esc_html__( 'Für die aktuelle Auswahl wurden keine Ablesungen gefunden.', KGVVM_TEXT_DOMAIN ); ?></td></tr>
|
||||
<tr><td colspan='10'><?php echo esc_html__( 'Für die aktuelle Auswahl wurden keine Ablesungen gefunden.', KGVVM_TEXT_DOMAIN ); ?></td></tr>
|
||||
<?php else : ?>
|
||||
<?php foreach ( $rows as $row ) : ?>
|
||||
<tr>
|
||||
<td><?php echo esc_html( wp_date( 'd.m.Y', strtotime( $row->reading_date ) ) ); ?></td>
|
||||
<td><?php echo esc_html( $row->section_name ? $row->section_name : '—' ); ?></td>
|
||||
<td><?php echo esc_html( $row->parcel_label ? $row->parcel_label : '—' ); ?></td>
|
||||
<td><?php echo esc_html( $this->meter_type_label( $row->type ) . ' – ' . $row->meter_number ); ?></td>
|
||||
<td>
|
||||
<?php echo esc_html( $this->meter_type_label( $row->type ) . ' – ' . $row->meter_number ); ?>
|
||||
<?php if ( ! empty( $row->note ) ) : ?>
|
||||
<br /><small style='color:#666' title='<?php echo esc_attr( $row->note ); ?>'>📌 <?php echo esc_html( mb_strimwidth( $row->note, 0, 60, '…' ) ); ?></small>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td><?php echo esc_html( null !== $row->previous_value ? $this->format_meter_value_with_unit( $row->previous_value, $row->type ) : '—' ); ?></td>
|
||||
<td><?php echo esc_html( $this->format_meter_value_with_unit( $row->reading_value, $row->type ) ); ?></td>
|
||||
<td><?php echo esc_html( null !== $row->consumption ? $this->format_meter_value_with_unit( $row->consumption, $row->type ) : '—' ); ?></td>
|
||||
<td><?php echo esc_html( null !== $row->unit_price ? $this->format_price_per_unit( $row->unit_price, 'power' === $row->type ? 'kWh' : 'm³' ) : '—' ); ?></td>
|
||||
<td><?php echo esc_html( null !== $row->calculated_cost ? $this->format_currency( $row->calculated_cost ) : '—' ); ?></td>
|
||||
<td>
|
||||
<?php
|
||||
$filter_args = array_filter(
|
||||
array(
|
||||
'section_id' => $section_id,
|
||||
'date_from' => $date_from,
|
||||
'date_to' => $date_to,
|
||||
'order' => $order,
|
||||
)
|
||||
);
|
||||
$edit_url = $this->admin_url( 'kgvvm-consumption', array_merge( $filter_args, array( 'edit_reading' => $row->id ) ) );
|
||||
$delete_url = wp_nonce_url(
|
||||
$this->admin_url( 'kgvvm-consumption', array_merge( $filter_args, array( 'kgvvm_action' => 'delete_meter_reading', 'id' => $row->id ) ) ),
|
||||
'kgvvm_delete_meter_reading_' . $row->id
|
||||
);
|
||||
?>
|
||||
<a href='<?php echo esc_url( $edit_url ); ?>'><?php echo esc_html__( 'Korrektur', KGVVM_TEXT_DOMAIN ); ?></a>
|
||||
|
|
||||
<a href='<?php echo esc_url( $delete_url ); ?>' onclick='return confirm("<?php echo esc_js( __( 'Ablesung wirklich löschen?', KGVVM_TEXT_DOMAIN ) ); ?>")' style='color:#b32d2e'><?php echo esc_html__( 'Löschen', KGVVM_TEXT_DOMAIN ); ?></a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
@@ -1193,6 +1756,9 @@ class Admin {
|
||||
$selected_year = (int) $cost->entry_year;
|
||||
}
|
||||
|
||||
$year_lock_state = $this->costs->get_statement_lock_state( $selected_year );
|
||||
$year_is_locked = ! empty( $year_lock_state['is_locked'] );
|
||||
|
||||
$years = $this->costs->get_years( $selected_year );
|
||||
$sections = $this->sections->all_for_options( true );
|
||||
$section_rates = $this->costs->get_section_prices( $selected_year );
|
||||
@@ -1255,6 +1821,9 @@ class Admin {
|
||||
<a href='<?php echo esc_url( $this->admin_url( 'kgvvm-costs', array( 'year' => $selected_year ) ) ); ?>' class='page-title-action'><?php echo esc_html__( 'Neuer Eintrag', KGVVM_TEXT_DOMAIN ); ?></a>
|
||||
<?php endif; ?>
|
||||
<?php $this->render_notice(); ?>
|
||||
<?php if ( $year_is_locked ) : ?>
|
||||
<div class='notice notice-warning'><p><?php echo esc_html__( 'Diese Jahresabrechnung ist festgeschrieben. Änderungen an Kosten, Preisen und Zuordnungen sind gesperrt, bis sie erneut freigegeben wird.', KGVVM_TEXT_DOMAIN ); ?></p></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method='get' class='kgvvm-toolbar' id='kgvvm-cost-filter-form'>
|
||||
<input type='hidden' name='page' value='kgvvm-costs' />
|
||||
@@ -1327,7 +1896,7 @@ class Admin {
|
||||
<td><input type='number' min='0' step='0.0001' name='water_price_per_m3' id='kgvvm-water-price' value='<?php echo esc_attr( $edit_rate && null !== $edit_rate->water_price_per_m3 ? (float) $edit_rate->water_price_per_m3 : '' ); ?>' /> € / m³</td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php submit_button( $edit_rate ? __( 'Spartenpreise aktualisieren', KGVVM_TEXT_DOMAIN ) : __( 'Spartenpreise speichern', KGVVM_TEXT_DOMAIN ), 'secondary' ); ?>
|
||||
<?php submit_button( $edit_rate ? __( 'Spartenpreise aktualisieren', KGVVM_TEXT_DOMAIN ) : __( 'Spartenpreise speichern', KGVVM_TEXT_DOMAIN ), 'secondary', 'submit', true, $year_is_locked ? array( 'disabled' => 'disabled' ) : array() ); ?>
|
||||
<?php if ( $edit_rate ) : ?>
|
||||
<a href='<?php echo esc_url( $this->admin_url( 'kgvvm-costs', array( 'year' => $selected_year ) ) ); ?>' class='button-secondary'><?php echo esc_html__( 'Abbrechen', KGVVM_TEXT_DOMAIN ); ?></a>
|
||||
<?php endif; ?>
|
||||
@@ -1389,7 +1958,7 @@ class Admin {
|
||||
<td><textarea name='note' id='kgvvm-cost-note' rows='4' class='large-text'><?php echo esc_textarea( $cost ? $cost->note : '' ); ?></textarea></td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php submit_button( $cost ? __( 'Kostenposten aktualisieren', KGVVM_TEXT_DOMAIN ) : __( 'Kostenposten speichern', KGVVM_TEXT_DOMAIN ) ); ?>
|
||||
<?php submit_button( $cost ? __( 'Kostenposten aktualisieren', KGVVM_TEXT_DOMAIN ) : __( 'Kostenposten speichern', KGVVM_TEXT_DOMAIN ), 'primary', 'submit', true, $year_is_locked ? array( 'disabled' => 'disabled' ) : array() ); ?>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -1455,7 +2024,13 @@ class Admin {
|
||||
<td><?php echo esc_html( null !== $rate->power_price_per_kwh ? $this->format_price_per_unit( $rate->power_price_per_kwh, 'kWh' ) : '—' ); ?></td>
|
||||
<td><?php echo esc_html( null !== $rate->water_price_per_m3 ? $this->format_price_per_unit( $rate->water_price_per_m3, 'm³' ) : '—' ); ?></td>
|
||||
<td><?php echo esc_html( ! empty( $rate->updated_at ) ? wp_date( 'd.m.Y H:i', strtotime( $rate->updated_at ) ) : '—' ); ?></td>
|
||||
<td><a href='<?php echo esc_url( $this->admin_url( 'kgvvm-costs', array( 'year' => $selected_year, 'edit_rate_section_id' => $rate->section_id ) ) ); ?>'><?php echo esc_html__( 'Bearbeiten', KGVVM_TEXT_DOMAIN ); ?></a></td>
|
||||
<td>
|
||||
<?php if ( $year_is_locked ) : ?>
|
||||
<span style='opacity:.65;'><?php echo esc_html__( 'Gesperrt', KGVVM_TEXT_DOMAIN ); ?></span>
|
||||
<?php else : ?>
|
||||
<a href='<?php echo esc_url( $this->admin_url( 'kgvvm-costs', array( 'year' => $selected_year, 'edit_rate_section_id' => $rate->section_id ) ) ); ?>'><?php echo esc_html__( 'Bearbeiten', KGVVM_TEXT_DOMAIN ); ?></a>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
@@ -1496,9 +2071,13 @@ class Admin {
|
||||
<td><?php echo esc_html( $row->note ? $row->note : '—' ); ?></td>
|
||||
<td><?php echo esc_html( ! empty( $row->updated_at ) ? wp_date( 'd.m.Y H:i', strtotime( $row->updated_at ) ) : '—' ); ?></td>
|
||||
<td>
|
||||
<a href='<?php echo esc_url( $this->admin_url( 'kgvvm-costs', array( 'year' => $selected_year, 'id' => $row->id ) ) ); ?>'><?php echo esc_html__( 'Bearbeiten', KGVVM_TEXT_DOMAIN ); ?></a>
|
||||
|
|
||||
<a href='<?php echo esc_url( wp_nonce_url( $this->admin_url( 'kgvvm-costs', array( 'kgvvm_action' => 'delete_cost', 'id' => $row->id, 'year' => $selected_year ) ), 'kgvvm_delete_cost_' . $row->id ) ); ?>' onclick='return confirm("<?php echo esc_js( __( 'Kostenposten wirklich löschen?', KGVVM_TEXT_DOMAIN ) ); ?>");'><?php echo esc_html__( 'Löschen', KGVVM_TEXT_DOMAIN ); ?></a>
|
||||
<?php if ( $year_is_locked ) : ?>
|
||||
<span style='opacity:.65;'><?php echo esc_html__( 'Gesperrt', KGVVM_TEXT_DOMAIN ); ?></span>
|
||||
<?php else : ?>
|
||||
<a href='<?php echo esc_url( $this->admin_url( 'kgvvm-costs', array( 'year' => $selected_year, 'id' => $row->id ) ) ); ?>'><?php echo esc_html__( 'Bearbeiten', KGVVM_TEXT_DOMAIN ); ?></a>
|
||||
|
|
||||
<a href='<?php echo esc_url( wp_nonce_url( $this->admin_url( 'kgvvm-costs', array( 'kgvvm_action' => 'delete_cost', 'id' => $row->id, 'year' => $selected_year ) ), 'kgvvm_delete_cost_' . $row->id ) ); ?>' onclick='return confirm("<?php echo esc_js( __( 'Kostenposten wirklich löschen?', KGVVM_TEXT_DOMAIN ) ); ?>");'><?php echo esc_html__( 'Löschen', KGVVM_TEXT_DOMAIN ); ?></a>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
@@ -1605,6 +2184,8 @@ class Admin {
|
||||
$statement_type = isset( $_GET['statement_type'] ) ? sanitize_key( wp_unslash( $_GET['statement_type'] ) ) : 'parcel';
|
||||
$output = isset( $_GET['output'] ) ? sanitize_key( wp_unslash( $_GET['output'] ) ) : 'html';
|
||||
$subject_id = absint( isset( $_GET['subject_id'] ) ? $_GET['subject_id'] : 0 );
|
||||
$lock_state = $this->costs->get_statement_lock_state( $year );
|
||||
$statement_is_locked = ! empty( $lock_state['is_locked'] );
|
||||
$date_from = sprintf( '%04d-01-01', $year );
|
||||
$date_to = sprintf( '%04d-12-31', $year );
|
||||
$all_rows = $this->readings->get_consumption_report( 0, $date_from, $date_to, 'ASC' );
|
||||
@@ -1803,9 +2384,24 @@ class Admin {
|
||||
</style>
|
||||
<div class='wrap kgvvm-print-page'>
|
||||
<h1><?php echo esc_html( $subject_label ); ?></h1>
|
||||
<?php if ( $statement_is_locked ) : ?>
|
||||
<div class='notice notice-warning'><p><?php echo esc_html__( 'Diese Jahresabrechnung ist festgeschrieben. Änderungen sind erst nach erneuter Freigabe möglich.', KGVVM_TEXT_DOMAIN ); ?></p></div>
|
||||
<?php endif; ?>
|
||||
<div class='kgvvm-print-actions'>
|
||||
<a href='<?php echo esc_url( $this->admin_url( 'kgvvm-costs', array( 'view' => 'statement', 'statement_type' => $statement_type, 'subject_id' => $subject_id, 'year' => $year, 'output' => 'pdf' ) ) ); ?>' class='button button-primary' target='_blank'><?php echo esc_html__( 'PDF erzeugen', KGVVM_TEXT_DOMAIN ); ?></a>
|
||||
<a href='#' class='button button-secondary' onclick='window.print(); return false;'><?php echo esc_html__( 'Drucken / Als PDF speichern', KGVVM_TEXT_DOMAIN ); ?></a>
|
||||
<form method='post' action='<?php echo esc_url( admin_url( 'admin.php' ) ); ?>' style='display:inline-block;'>
|
||||
<?php wp_nonce_field( 'kgvvm_set_statement_lock_' . $year ); ?>
|
||||
<input type='hidden' name='kgvvm_action' value='set_statement_lock' />
|
||||
<input type='hidden' name='year' value='<?php echo esc_attr( $year ); ?>' />
|
||||
<input type='hidden' name='statement_type' value='<?php echo esc_attr( $statement_type ); ?>' />
|
||||
<input type='hidden' name='subject_id' value='<?php echo esc_attr( $subject_id ); ?>' />
|
||||
<input type='hidden' name='lock_mode' value='<?php echo esc_attr( $statement_is_locked ? 'unlock' : 'lock' ); ?>' />
|
||||
<input type='hidden' name='page' value='kgvvm-costs' />
|
||||
<button type='submit' class='button <?php echo esc_attr( $statement_is_locked ? 'button-secondary' : 'button-primary' ); ?>'>
|
||||
<?php echo esc_html( $statement_is_locked ? __( 'Erneut freigeben', KGVVM_TEXT_DOMAIN ) : __( 'Jahresabrechnung festschreiben', KGVVM_TEXT_DOMAIN ) ); ?>
|
||||
</button>
|
||||
</form>
|
||||
<a href='<?php echo esc_url( $this->admin_url( 'kgvvm-costs', array( 'year' => $year ) ) ); ?>' class='button-secondary'><?php echo esc_html__( 'Zurück', KGVVM_TEXT_DOMAIN ); ?></a>
|
||||
</div>
|
||||
|
||||
@@ -1912,6 +2508,29 @@ class Admin {
|
||||
|
||||
<?php if ( 'parcel' === $statement_type ) : ?>
|
||||
<div class='kgvvm-statement-sidebar'>
|
||||
<div class='kgvvm-card'>
|
||||
<h3 style='margin-top:0;'><?php echo esc_html__( 'Freigabe-Status', KGVVM_TEXT_DOMAIN ); ?></h3>
|
||||
<p>
|
||||
<?php if ( $statement_is_locked ) : ?>
|
||||
<strong style='color:#b32d2e;'><?php echo esc_html__( 'Festgeschrieben', KGVVM_TEXT_DOMAIN ); ?></strong>
|
||||
<?php else : ?>
|
||||
<strong style='color:#007017;'><?php echo esc_html__( 'Freigegeben', KGVVM_TEXT_DOMAIN ); ?></strong>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
<form method='post' action='<?php echo esc_url( admin_url( 'admin.php' ) ); ?>'>
|
||||
<?php wp_nonce_field( 'kgvvm_set_statement_lock_' . $year ); ?>
|
||||
<input type='hidden' name='kgvvm_action' value='set_statement_lock' />
|
||||
<input type='hidden' name='year' value='<?php echo esc_attr( $year ); ?>' />
|
||||
<input type='hidden' name='statement_type' value='<?php echo esc_attr( $statement_type ); ?>' />
|
||||
<input type='hidden' name='subject_id' value='<?php echo esc_attr( $subject_id ); ?>' />
|
||||
<input type='hidden' name='lock_mode' value='<?php echo esc_attr( $statement_is_locked ? 'unlock' : 'lock' ); ?>' />
|
||||
<input type='hidden' name='page' value='kgvvm-costs' />
|
||||
<button type='submit' class='button <?php echo esc_attr( $statement_is_locked ? 'button-secondary' : 'button-primary' ); ?>'>
|
||||
<?php echo esc_html( $statement_is_locked ? __( 'Erneut freigeben', KGVVM_TEXT_DOMAIN ) : __( 'Jahresabrechnung festschreiben', KGVVM_TEXT_DOMAIN ) ); ?>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class='kgvvm-card'>
|
||||
<h3 style='margin-top:0;'><?php echo esc_html__( 'Kostenpositionen', KGVVM_TEXT_DOMAIN ); ?></h3>
|
||||
<p class='description'><?php echo esc_html__( 'Hier legen Sie fest, welche Positionen dieser Parzelle berechnet werden. Positionen ohne Einschränkung gelten für alle Parzellen.', KGVVM_TEXT_DOMAIN ); ?></p>
|
||||
@@ -1937,7 +2556,9 @@ class Admin {
|
||||
<?php endif; ?>
|
||||
<?php echo esc_html( $entry->name ); ?>
|
||||
</span>
|
||||
<?php if ( $is_assigned ) : ?>
|
||||
<?php if ( $statement_is_locked ) : ?>
|
||||
<span class='button button-small' style='pointer-events:none; opacity:.65;'><?php echo esc_html__( 'Gesperrt', KGVVM_TEXT_DOMAIN ); ?></span>
|
||||
<?php elseif ( $is_assigned ) : ?>
|
||||
<form method='post' action='<?php echo esc_url( admin_url( 'admin.php' ) ); ?>' style='display:inline;'>
|
||||
<?php wp_nonce_field( 'kgvvm_toggle_parcel_cost' ); ?>
|
||||
<input type='hidden' name='kgvvm_action' value='toggle_parcel_cost_assignment' />
|
||||
|
||||
Reference in New Issue
Block a user