case fee total updates when a fee is updated
This commit is contained in:
parent
92bce34fb1
commit
86c0fb1f65
@ -96,28 +96,9 @@ function opencase_cases_get_activities(Drupal\opencase_cases\entity\OCCase $case
|
|||||||
return $activities;
|
return $activities;
|
||||||
}
|
}
|
||||||
|
|
||||||
function opencase_cases_get_amount(Drupal\opencase_cases\entity\OCCaseFee $case_fee): string {
|
|
||||||
if (!isEmpty($case_fee->amount)) return $case_fee->amount->first()->value;
|
|
||||||
else return '0';
|
|
||||||
}
|
|
||||||
|
|
||||||
function opencase_cases_get_case(Drupal\opencase_cases\entity\OCCaseFee $case_fee): Drupal\opencase_cases\entity\OCCase {
|
|
||||||
return $case_fee->oc_case->referencedEntities()[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
function opencase_cases_update_total_fee_for_case_belonging_to_case_fee(Drupal\opencase_cases\entity\OCCaseFee $case_fee): void {
|
|
||||||
$total = 0;
|
|
||||||
$case = opencase_cases_get_case($case_fee);
|
|
||||||
$case_fees = opencase_cases_get_case_fees($case);
|
|
||||||
foreach($case_fees as $case_fee) {
|
|
||||||
$total += opencase_cases_get_amount($case_fee);
|
|
||||||
}
|
|
||||||
$case->set('total_fee', $total);
|
|
||||||
$case->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
function opencase_cases_oc_case_fee_update(Drupal\opencase_cases\entity\OCCaseFee $case_fee): void {
|
function opencase_cases_oc_case_fee_update(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->addToTotalFee($case_fee->amount->value - $case_fee->original->amount->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function opencase_cases_oc_case_fee_insert(Drupal\opencase_cases\entity\OCCaseFee $case_fee): void {
|
function opencase_cases_oc_case_fee_insert(Drupal\opencase_cases\entity\OCCaseFee $case_fee): void {
|
||||||
@ -127,7 +108,7 @@ 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 {
|
function opencase_cases_oc_case_fee_delete(Drupal\opencase_cases\entity\OCCaseFee $case_fee): void {
|
||||||
$case = $case_fee->getCase();
|
$case = $case_fee->getCase();
|
||||||
$case->subtractFromTotalFee($case_fee->amount->value);
|
$case->addToTotalFee(0 - $case_fee->amount->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function opencase_cases_entity_base_field_info($entity_type) {
|
function opencase_cases_entity_base_field_info($entity_type) {
|
||||||
|
@ -227,11 +227,6 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface
|
|||||||
$this->save();
|
$this->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function subtractFromTotalFee(string $amountToSubtract): void {
|
|
||||||
$this->set('total_fee', $this->total_fee->value - $amountToSubtract);
|
|
||||||
$this->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user