From 92bce34fb1f500c1be859b7b3769a9ea86abab66 Mon Sep 17 00:00:00 2001 From: naomi Date: Thu, 21 Apr 2022 12:15:00 +0100 Subject: [PATCH] total fee updates when a case fee is deleted --- modules/opencase_cases/opencase_cases.module | 3 ++- modules/opencase_cases/src/Entity/OCCase.php | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/opencase_cases/opencase_cases.module b/modules/opencase_cases/opencase_cases.module index 1f8e098..baa574e 100644 --- a/modules/opencase_cases/opencase_cases.module +++ b/modules/opencase_cases/opencase_cases.module @@ -126,7 +126,8 @@ function opencase_cases_oc_case_fee_insert(Drupal\opencase_cases\entity\OCCaseFe } function opencase_cases_oc_case_fee_delete(Drupal\opencase_cases\entity\OCCaseFee $case_fee): void { - opencase_cases_update_total_fee_for_case_belonging_to_case_fee($case_fee); + $case = $case_fee->getCase(); + $case->subtractFromTotalFee($case_fee->amount->value); } function opencase_cases_entity_base_field_info($entity_type) { diff --git a/modules/opencase_cases/src/Entity/OCCase.php b/modules/opencase_cases/src/Entity/OCCase.php index 12e679a..8e8bc8d 100644 --- a/modules/opencase_cases/src/Entity/OCCase.php +++ b/modules/opencase_cases/src/Entity/OCCase.php @@ -227,6 +227,11 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface $this->save(); } + public function subtractFromTotalFee(string $amountToSubtract): void { + $this->set('total_fee', $this->total_fee->value - $amountToSubtract); + $this->save(); + } + /** * {@inheritdoc} */