mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00: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
|
||||
|
Reference in New Issue
Block a user