mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Code for #1324
This commit is contained in:
parent
8f0e36a8e4
commit
3fbd2f93c8
@ -119,9 +119,11 @@ class UpgradeDatabase extends Command
|
||||
}
|
||||
|
||||
// loop bills.
|
||||
$order = 1;
|
||||
$order = 1;
|
||||
/** @var Collection $collection */
|
||||
$collection = $user->bills()->where('active', 1)->get();
|
||||
/** @var Bill $bill */
|
||||
foreach ($user->bills()->get() as $bill) {
|
||||
foreach ($collection as $bill) {
|
||||
if ($bill->match !== 'MIGRATED_TO_RULES') {
|
||||
$rule = Rule::create(
|
||||
[
|
||||
|
@ -199,6 +199,16 @@ class BillController extends Controller
|
||||
}
|
||||
);
|
||||
|
||||
// add info about rules:
|
||||
$rules = $repository->getRulesForBills($paginator->getCollection());
|
||||
$bills = $bills->map(
|
||||
function (array $bill) use ($rules) {
|
||||
$bill['rules'] = $rules[$bill['id']] ?? [];
|
||||
|
||||
return $bill;
|
||||
}
|
||||
);
|
||||
|
||||
$paginator->setPath(route('bills.index'));
|
||||
|
||||
return view('bills.index', compact('bills', 'paginator'));
|
||||
|
@ -369,7 +369,7 @@ class RuleController extends Controller
|
||||
|
||||
// redirect to new bill creation.
|
||||
if ((int)$request->get('bill_id') > 0) {
|
||||
return redirect(route('bills.create'));
|
||||
return redirect($this->getPreviousUri('bills.create.uri'));
|
||||
}
|
||||
|
||||
|
||||
|
@ -367,6 +367,35 @@ class BillRepository implements BillRepositoryInterface
|
||||
return $journals;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all rules related to the bills in the collection, in an associative array:
|
||||
* 5= billid
|
||||
*
|
||||
* 5 => [['id' => 1, 'title' => 'Some rule'],['id' => 2, 'title' => 'Some other rule']]
|
||||
*
|
||||
* @param Collection $collection
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRulesForBills(Collection $collection): array
|
||||
{
|
||||
$rules = $this->user->rules()
|
||||
->leftJoin('rule_actions', 'rule_actions.rule_id', '=', 'rules.id')
|
||||
->where('rule_actions.action_type', 'link_to_bill')
|
||||
->get(['rules.id', 'rules.title', 'rule_actions.action_value']);
|
||||
$array = [];
|
||||
foreach ($rules as $rule) {
|
||||
$array[$rule->action_value] = $array[$rule->action_value] ?? [];
|
||||
$array[$rule->action_value][] = ['id' => $rule->id, 'title' => $rule->title];
|
||||
}
|
||||
$return = [];
|
||||
foreach ($collection as $bill) {
|
||||
$return[$bill->id] = $array[$bill->name] ?? [];
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param Carbon $date
|
||||
|
@ -140,6 +140,18 @@ interface BillRepositoryInterface
|
||||
*/
|
||||
public function getPossiblyRelatedJournals(Bill $bill): Collection;
|
||||
|
||||
/**
|
||||
* Return all rules related to the bills in the collection, in an associative array:
|
||||
* 5= billid
|
||||
*
|
||||
* 5 => [['id' => 1, 'title' => 'Some rule'],['id' => 2, 'title' => 'Some other rule']]
|
||||
*
|
||||
* @param Collection $collection
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRulesForBills(Collection $collection): array;
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param Carbon $date
|
||||
|
@ -21,8 +21,8 @@
|
||||
{% for entry in bills %}
|
||||
{% if entry.active %}
|
||||
{% set count = count + 1 %}
|
||||
{% set sum_min = sum_min + entry.amount_min %}
|
||||
{% set sum_max = sum_min + entry.amount_max %}
|
||||
{% set sum_min = sum_min + entry.amount_min %}
|
||||
{% set sum_max = sum_min + entry.amount_max %}
|
||||
{% set expected_total = expected_total + ((entry.amount_min + entry.amount_max) / 2) %}
|
||||
{% endif %}
|
||||
<tr>
|
||||
@ -43,7 +43,13 @@
|
||||
|
||||
</td>
|
||||
<td class="hidden-sm hidden-md hidden-xs">
|
||||
(rules)
|
||||
{% if entry.rules|length > 0 %}
|
||||
<ul class="list-unstyled">
|
||||
{% for rule in entry.rules %}
|
||||
<li><a href="{{ route('rules.edit', [rule.id]) }}">{{ rule.title }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td data-value="{{ entry.amount_min }}" style="text-align: right;">
|
||||
<span style="margin-right:5px;" title="{{ entry.amount_min|formatAmountPlain }} - {{ entry.amount_max|formatAmountPlain }}">
|
||||
@ -127,7 +133,7 @@
|
||||
<td colspan="5"> </td>
|
||||
</tr>
|
||||
|
||||
{# calculate total#}
|
||||
{# calculate total#}
|
||||
{% if count > 0 %}
|
||||
{% set avg_min = (sum_min / count) %}
|
||||
{% set avg_max = (sum_max / count) %}
|
||||
|
Loading…
Reference in New Issue
Block a user