Various code for bills and rules.

This commit is contained in:
James Cole
2018-04-14 09:59:04 +02:00
parent 5862b832d9
commit d8a00f4314
22 changed files with 498 additions and 309 deletions

View File

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

View File

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