Fix parcel statement cost assignment behavior
This commit is contained in:
@@ -1715,22 +1715,28 @@ class Admin {
|
||||
$fixed_items = array();
|
||||
$fixed_total = 0.0;
|
||||
|
||||
// Load parcel-specific cost assignments so that entries with explicit
|
||||
// assignments are only charged to the assigned parcels.
|
||||
$entries_with_assignments = ( 'parcel' === $statement_type )
|
||||
? $this->costs->get_entry_ids_with_assignments( $year )
|
||||
: array();
|
||||
$parcel_assigned_ids = ( 'parcel' === $statement_type )
|
||||
? $this->costs->get_assigned_entry_ids( $subject_id )
|
||||
: array();
|
||||
// Load parcel-specific cost assignments so entries can either apply to
|
||||
// all parcels (mandatory) or only to explicitly assigned parcels (manual).
|
||||
$entries_with_assignments = $this->costs->get_entry_ids_with_assignments( $year );
|
||||
$subject_assigned_ids = array();
|
||||
|
||||
foreach ( array_map( 'intval', $parcel_ids ) as $parcel_id ) {
|
||||
$subject_assigned_ids = array_merge( $subject_assigned_ids, $this->costs->get_assigned_entry_ids( $parcel_id ) );
|
||||
}
|
||||
|
||||
$subject_assigned_ids = array_values( array_unique( array_map( 'intval', $subject_assigned_ids ) ) );
|
||||
|
||||
foreach ( $cost_entries as $entry ) {
|
||||
$entry_id = (int) $entry->id;
|
||||
$has_assignments = in_array( $entry_id, $entries_with_assignments, true );
|
||||
$is_assigned = in_array( $entry_id, $subject_assigned_ids, true );
|
||||
$is_mandatory = ! isset( $entry->is_mandatory ) || (bool) $entry->is_mandatory;
|
||||
|
||||
// For parcel statements: if this entry has any parcel restrictions,
|
||||
// skip it unless this specific parcel is assigned.
|
||||
if ( 'parcel' === $statement_type && $has_assignments && ! in_array( $entry_id, $parcel_assigned_ids, true ) ) {
|
||||
if ( ! $is_mandatory && ! $is_assigned ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $is_mandatory && $has_assignments && ! $is_assigned ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1909,14 +1915,15 @@ class Admin {
|
||||
<ul class='kgvvm-cost-assignment-list'>
|
||||
<?php foreach ( $cost_entries as $entry ) :
|
||||
$entry_id = (int) $entry->id;
|
||||
$is_assigned = in_array( $entry_id, $parcel_assigned_ids, true );
|
||||
$is_assigned = in_array( $entry_id, $subject_assigned_ids, true );
|
||||
$has_any = in_array( $entry_id, $entries_with_assignments, true );
|
||||
$is_mandatory = ! isset( $entry->is_mandatory ) || (bool) $entry->is_mandatory;
|
||||
?>
|
||||
<li>
|
||||
<span class='kgvvm-entry-name'>
|
||||
<?php if ( $is_assigned ) : ?>
|
||||
<span style='color:#007017;' title='<?php esc_attr_e( 'Diese Parzelle ist zugeordnet', KGVVM_TEXT_DOMAIN ); ?>'>✓</span>
|
||||
<?php elseif ( $has_any ) : ?>
|
||||
<?php elseif ( ! $is_mandatory || $has_any ) : ?>
|
||||
<span style='color:#b32d2e;' title='<?php esc_attr_e( 'Diese Parzelle ist nicht zugeordnet', KGVVM_TEXT_DOMAIN ); ?>'>✗</span>
|
||||
<?php else : ?>
|
||||
<span style='color:#999;' title='<?php esc_attr_e( 'Gilt für alle Parzellen', KGVVM_TEXT_DOMAIN ); ?>'>—</span>
|
||||
@@ -1934,6 +1941,8 @@ class Admin {
|
||||
<input type='hidden' name='page' value='kgvvm-costs' />
|
||||
<button type='submit' class='button button-small'><?php echo esc_html__( 'Entfernen', KGVVM_TEXT_DOMAIN ); ?></button>
|
||||
</form>
|
||||
<?php elseif ( $is_mandatory && ! $has_any ) : ?>
|
||||
<span class='button button-small' style='pointer-events:none; opacity:.65;'><?php echo esc_html__( 'Automatisch', KGVVM_TEXT_DOMAIN ); ?></span>
|
||||
<?php else : ?>
|
||||
<form method='post' action='<?php echo esc_url( admin_url( 'admin.php' ) ); ?>' style='display:inline;'>
|
||||
<?php wp_nonce_field( 'kgvvm_toggle_parcel_cost' ); ?>
|
||||
@@ -1951,8 +1960,8 @@ class Admin {
|
||||
</ul>
|
||||
<p class='description' style='margin-top:12px; font-size:11px;'>
|
||||
<span style='color:#007017;'>✓</span> <?php echo esc_html__( 'zugeordnet', KGVVM_TEXT_DOMAIN ); ?>
|
||||
<span style='color:#b32d2e;'>✗</span> <?php echo esc_html__( 'nicht zugeordnet', KGVVM_TEXT_DOMAIN ); ?>
|
||||
<span style='color:#999;'>—</span> <?php echo esc_html__( 'alle Parzellen', KGVVM_TEXT_DOMAIN ); ?>
|
||||
<span style='color:#b32d2e;'>✗</span> <?php echo esc_html__( 'manuell oder ausgeschlossen', KGVVM_TEXT_DOMAIN ); ?>
|
||||
<span style='color:#999;'>—</span> <?php echo esc_html__( 'Pflichtposition für alle Parzellen', KGVVM_TEXT_DOMAIN ); ?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user