mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Code for #207
This commit is contained in:
@@ -110,11 +110,29 @@ class BillController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function index(BillRepositoryInterface $repository)
|
public function index(BillRepositoryInterface $repository)
|
||||||
{
|
{
|
||||||
|
$start = session('start');
|
||||||
|
$end = session('end');
|
||||||
|
|
||||||
$bills = $repository->getBills();
|
$bills = $repository->getBills();
|
||||||
$bills->each(
|
$bills->each(
|
||||||
function (Bill $bill) use ($repository) {
|
function (Bill $bill) use ($repository, $start, $end) {
|
||||||
$bill->nextExpectedMatch = $repository->nextExpectedMatch($bill);
|
$bill->nextExpectedMatch = $repository->nextExpectedMatch($bill);
|
||||||
$bill->lastFoundMatch = $repository->lastFoundMatch($bill);
|
$bill->lastFoundMatch = $repository->lastFoundMatch($bill);
|
||||||
|
$journals = $repository->getJournalsInRange($bill, $start, $end);
|
||||||
|
// loop journals, find average:
|
||||||
|
$average = '0';
|
||||||
|
$count = $journals->count();
|
||||||
|
if ($count > 0) {
|
||||||
|
$sum = '0';
|
||||||
|
foreach ($journals as $journal) {
|
||||||
|
$sum = bcadd($sum, TransactionJournal::amountPositive($journal));
|
||||||
|
}
|
||||||
|
$average = bcdiv($sum, strval($count));
|
||||||
|
}
|
||||||
|
|
||||||
|
$bill->lastPaidAmount = $average;
|
||||||
|
$bill->paidInPeriod = ($start <= $bill->lastFoundMatch) && ($end >= $bill->lastFoundMatch);
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@@ -27,6 +27,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|||||||
* @property-read \FireflyIII\User $user
|
* @property-read \FireflyIII\User $user
|
||||||
* @property \Carbon\Carbon $nextExpectedMatch
|
* @property \Carbon\Carbon $nextExpectedMatch
|
||||||
* @property \Carbon\Carbon $lastFoundMatch
|
* @property \Carbon\Carbon $lastFoundMatch
|
||||||
|
* @property bool $paidInPeriod
|
||||||
|
* @property string $lastPaidAmount
|
||||||
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereId($value)
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereId($value)
|
||||||
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereCreatedAt($value)
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereCreatedAt($value)
|
||||||
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereUpdatedAt($value)
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereUpdatedAt($value)
|
||||||
@@ -47,11 +49,25 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|||||||
class Bill extends Model
|
class Bill extends Model
|
||||||
{
|
{
|
||||||
|
|
||||||
|
protected $dates = ['created_at', 'updated_at', 'date'];
|
||||||
protected $fillable
|
protected $fillable
|
||||||
= ['name', 'match', 'amount_min', 'match_encrypted', 'name_encrypted', 'user_id', 'amount_max', 'date', 'repeat_freq', 'skip', 'automatch', 'active',];
|
= ['name', 'match', 'amount_min', 'match_encrypted', 'name_encrypted', 'user_id', 'amount_max', 'date', 'repeat_freq', 'skip', 'automatch', 'active',];
|
||||||
|
|
||||||
protected $hidden = ['amount_min_encrypted', 'amount_max_encrypted', 'name_encrypted', 'match_encrypted'];
|
protected $hidden = ['amount_min_encrypted', 'amount_max_encrypted', 'name_encrypted', 'match_encrypted'];
|
||||||
protected $dates = ['created_at', 'updated_at', 'date'];
|
|
||||||
|
/**
|
||||||
|
* @param Bill $value
|
||||||
|
*
|
||||||
|
* @return Bill
|
||||||
|
*/
|
||||||
|
public static function routeBinder(Bill $value)
|
||||||
|
{
|
||||||
|
if (Auth::check()) {
|
||||||
|
if ($value->user_id == Auth::user()->id) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new NotFoundHttpException;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $value
|
* @param $value
|
||||||
@@ -134,20 +150,4 @@ class Bill extends Model
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Bill $value
|
|
||||||
*
|
|
||||||
* @return Bill
|
|
||||||
*/
|
|
||||||
public static function routeBinder(Bill $value)
|
|
||||||
{
|
|
||||||
if (Auth::check()) {
|
|
||||||
if ($value->user_id == Auth::user()->id) {
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new NotFoundHttpException;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -8,34 +8,35 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'name' => 'Name',
|
'name' => 'Name',
|
||||||
'role' => 'Role',
|
'role' => 'Role',
|
||||||
'currentBalance' => 'Current balance',
|
'currentBalance' => 'Current balance',
|
||||||
'active' => 'Is active?',
|
'active' => 'Is active?',
|
||||||
'lastActivity' => 'Last activity',
|
'lastActivity' => 'Last activity',
|
||||||
'balanceDiff' => 'Balance difference between :start and :end',
|
'balanceDiff' => 'Balance difference between :start and :end',
|
||||||
'matchedOn' => 'Matched on',
|
'matchedOn' => 'Matched on',
|
||||||
'matchesOn' => 'Matched on',
|
'matchesOn' => 'Matched on',
|
||||||
'matchingAmount' => 'Amount',
|
'matchingAmount' => 'Amount',
|
||||||
'lastMatch' => 'Last match',
|
'lastMatch' => 'Last match',
|
||||||
'expectedMatch' => 'Expected match',
|
'expectedMatch' => 'Expected match',
|
||||||
'automatch' => 'Auto match?',
|
'automatch' => 'Auto match?',
|
||||||
'repeat_freq' => 'Repeats',
|
'repeat_freq' => 'Repeats',
|
||||||
'description' => 'Description',
|
'description' => 'Description',
|
||||||
'amount' => 'Amount',
|
'amount' => 'Amount',
|
||||||
'date' => 'Date',
|
'date' => 'Date',
|
||||||
'interest_date' => 'Interest date',
|
'interest_date' => 'Interest date',
|
||||||
'book_date' => 'Book date',
|
'book_date' => 'Book date',
|
||||||
'process_date' => 'Processing date',
|
'process_date' => 'Processing date',
|
||||||
'from' => 'From',
|
'from' => 'From',
|
||||||
'to' => 'To',
|
'to' => 'To',
|
||||||
'budget' => 'Budget',
|
'budget' => 'Budget',
|
||||||
'category' => 'Category',
|
'category' => 'Category',
|
||||||
'bill' => 'Bill',
|
'bill' => 'Bill',
|
||||||
'withdrawal' => 'Withdrawal',
|
'withdrawal' => 'Withdrawal',
|
||||||
'deposit' => 'Deposit',
|
'deposit' => 'Deposit',
|
||||||
'transfer' => 'Transfer',
|
'transfer' => 'Transfer',
|
||||||
'type' => 'Type',
|
'type' => 'Type',
|
||||||
'completed' => 'Completed',
|
'completed' => 'Completed',
|
||||||
'iban' => 'IBAN',
|
'iban' => 'IBAN',
|
||||||
|
'paid_current_period' => 'Paid this period',
|
||||||
];
|
];
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
<th>{{ trans('list.name') }}</th>
|
<th>{{ trans('list.name') }}</th>
|
||||||
<th class="hidden-sm hidden-xs">{{ trans('list.matchesOn') }}</th>
|
<th class="hidden-sm hidden-xs">{{ trans('list.matchesOn') }}</th>
|
||||||
<th colspan="2">{{ trans('list.matchingAmount') }}</th>
|
<th colspan="2">{{ trans('list.matchingAmount') }}</th>
|
||||||
<th class="hidden-sm hidden-xs">{{ trans('list.lastMatch') }}</th>
|
<th class="hidden-sm hidden-xs">{{ trans('list.paid_current_period') }}</th>
|
||||||
<th class="hidden-sm hidden-xs">{{ trans('list.expectedMatch') }}</th>
|
<th class="hidden-sm hidden-xs">{{ trans('list.expectedMatch') }}</th>
|
||||||
<th class="hidden-sm hidden-xs">{{ trans('list.active') }}</th>
|
<th class="hidden-sm hidden-xs">{{ trans('list.active') }}</th>
|
||||||
<th class="hidden-sm hidden-xs">{{ trans('list.automatch') }}</th>
|
<th class="hidden-sm hidden-xs">{{ trans('list.automatch') }}</th>
|
||||||
@@ -36,8 +36,19 @@
|
|||||||
{{ entry.amount_max|formatAmount }}
|
{{ entry.amount_max|formatAmount }}
|
||||||
</td>
|
</td>
|
||||||
{% if not entry.lastFoundMatch.isFuture %}
|
{% if not entry.lastFoundMatch.isFuture %}
|
||||||
<td class="hidden-sm hidden-xs" data-value="{{ entry.lastFoundMatch.format('U') }}">
|
<td class="hidden-sm hidden-xs
|
||||||
|
{% if entry.active %}
|
||||||
|
{% if entry.paidInPeriod %}
|
||||||
|
bg-success
|
||||||
|
{% else %}
|
||||||
|
bg-danger
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
" data-value="{{ entry.lastFoundMatch.format('U') }}">
|
||||||
{{ entry.lastFoundMatch.formatLocalized(monthAndDayFormat) }}
|
{{ entry.lastFoundMatch.formatLocalized(monthAndDayFormat) }}
|
||||||
|
{% if entry.active and entry.paidInPeriod %}
|
||||||
|
({{ entry.lastPaidAmount|formatAmountPlain }})
|
||||||
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td class="hidden-sm hidden-xs" data-value="0">
|
<td class="hidden-sm hidden-xs" data-value="0">
|
||||||
@@ -51,7 +62,7 @@
|
|||||||
</td>
|
</td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td class="hidden-sm hidden-xs" data-value="{{ entry.nextExpectedMatch.format('U') }}">
|
<td class="hidden-sm hidden-xs" data-value="{{ entry.nextExpectedMatch.format('U') }}">
|
||||||
{{ entry.nextExpectedMatch.formatLocalized(monthAndDayFormat) }}
|
~ {{ entry.nextExpectedMatch.formatLocalized(monthAndDayFormat) }}
|
||||||
</td>
|
</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user