Expand rules and bills.

This commit is contained in:
James Cole
2018-04-14 20:31:31 +02:00
parent 926c03986c
commit 15a22f0bfc
13 changed files with 90 additions and 36 deletions

View File

@@ -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