mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 08:35:00 +00:00
Various code for bills and rules.
This commit is contained in:
@@ -367,6 +367,22 @@ class BillRepository implements BillRepositoryInterface
|
||||
return $journals;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all rules for one bill
|
||||
*
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getRulesForBill(Bill $bill): Collection
|
||||
{
|
||||
return $this->user->rules()
|
||||
->leftJoin('rule_actions', 'rule_actions.rule_id', '=', 'rules.id')
|
||||
->where('rule_actions.action_type', 'link_to_bill')
|
||||
->where('rule_actions.action_value', $bill->name)
|
||||
->get(['rules.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all rules related to the bills in the collection, in an associative array:
|
||||
* 5= billid
|
||||
@@ -426,6 +442,21 @@ class BillRepository implements BillRepositoryInterface
|
||||
return $avg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Link a set of journals to a bill.
|
||||
*
|
||||
* @param Bill $bill
|
||||
* @param Collection $journals
|
||||
*/
|
||||
public function linkCollectionToBill(Bill $bill, Collection $journals): void
|
||||
{
|
||||
$ids = $journals->pluck('id')->toArray();
|
||||
DB::table('transaction_journals')
|
||||
->where('user_id', $this->user->id)
|
||||
->whereIn('id', $ids)
|
||||
->update(['bill_id' => $bill->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a bill and a date, this method will tell you at which moment this bill expects its next
|
||||
* transaction. Whether or not it is there already, is not relevant.
|
||||
|
@@ -140,6 +140,15 @@ interface BillRepositoryInterface
|
||||
*/
|
||||
public function getPossiblyRelatedJournals(Bill $bill): Collection;
|
||||
|
||||
/**
|
||||
* Return all rules for one bill
|
||||
*
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getRulesForBill(Bill $bill): Collection;
|
||||
|
||||
/**
|
||||
* Return all rules related to the bills in the collection, in an associative array:
|
||||
* 5= billid
|
||||
@@ -160,6 +169,14 @@ interface BillRepositoryInterface
|
||||
*/
|
||||
public function getYearAverage(Bill $bill, Carbon $date): string;
|
||||
|
||||
/**
|
||||
* Link a set of journals to a bill.
|
||||
*
|
||||
* @param Bill $bill
|
||||
* @param Collection $journals
|
||||
*/
|
||||
public function linkCollectionToBill(Bill $bill, Collection $journals): void;
|
||||
|
||||
/**
|
||||
* Given a bill and a date, this method will tell you at which moment this bill expects its next
|
||||
* transaction. Whether or not it is there already, is not relevant.
|
||||
|
Reference in New Issue
Block a user