mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Expand rules and bills.
This commit is contained in:
@@ -25,6 +25,8 @@ namespace FireflyIII\Services\Internal\Support;
|
||||
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Models\RuleAction;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Trait BillServiceTrait
|
||||
@@ -34,6 +36,29 @@ use FireflyIII\Models\Note;
|
||||
trait BillServiceTrait
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param string $oldName
|
||||
* @param string $newName
|
||||
*/
|
||||
public function updateBillActions(Bill $bill, string $oldName, string $newName): void
|
||||
{
|
||||
if ($oldName === $newName) {
|
||||
return;
|
||||
}
|
||||
$ruleIds = $bill->user->rules()->get(['id'])->pluck('id')->toArray();
|
||||
/** @var Collection $set */
|
||||
$set = RuleAction::whereIn('rule_id', $ruleIds)
|
||||
->where('action_type', 'link_to_bill')
|
||||
->where('action_value', $oldName)->get();
|
||||
|
||||
/** @var RuleAction $ruleAction */
|
||||
foreach ($set as $ruleAction) {
|
||||
$ruleAction->action_value = $newName;
|
||||
$ruleAction->save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
|
||||
@@ -42,6 +42,7 @@ class BillUpdateService
|
||||
*/
|
||||
public function update(Bill $bill, array $data): Bill
|
||||
{
|
||||
$oldName = $bill->name;
|
||||
$bill->name = $data['name'];
|
||||
$bill->amount_min = $data['amount_min'];
|
||||
$bill->amount_max = $data['amount_max'];
|
||||
@@ -58,6 +59,9 @@ class BillUpdateService
|
||||
$this->updateNote($bill, (string)$data['notes']);
|
||||
}
|
||||
|
||||
// update rule actions.
|
||||
$this->updateBillActions($bill, $oldName, $data['name']);
|
||||
|
||||
return $bill;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user