mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Updates to bill code for #1029
This commit is contained in:
parent
8eded63055
commit
efaa69cba1
@ -42,9 +42,39 @@ class BillLine
|
||||
protected $min;
|
||||
/** @var Carbon */
|
||||
private $lastHitDate;
|
||||
/** @var Carbon */
|
||||
private $payDate;
|
||||
/** @var Carbon */
|
||||
private $endOfPayDate;
|
||||
/** @var int */
|
||||
private $transactionJournalId;
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getPayDate(): Carbon
|
||||
{
|
||||
return $this->payDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getEndOfPayDate(): Carbon
|
||||
{
|
||||
return $this->endOfPayDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $endOfPayDate
|
||||
*/
|
||||
public function setEndOfPayDate(Carbon $endOfPayDate): void
|
||||
{
|
||||
$this->endOfPayDate = $endOfPayDate;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* BillLine constructor.
|
||||
*/
|
||||
@ -172,4 +202,12 @@ class BillLine
|
||||
{
|
||||
$this->hit = $hit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $payDate
|
||||
*/
|
||||
public function setPayDate(Carbon $payDate): void
|
||||
{
|
||||
$this->payDate = $payDate;
|
||||
}
|
||||
}
|
||||
|
@ -71,17 +71,25 @@ class ReportHelper implements ReportHelperInterface
|
||||
/** @var BillRepositoryInterface $repository */
|
||||
$repository = app(BillRepositoryInterface::class);
|
||||
$bills = $repository->getBillsForAccounts($accounts);
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setAccounts($accounts)->setRange($start, $end)->setBills($bills);
|
||||
$journals = $collector->getJournals();
|
||||
|
||||
$collection = new BillCollection;
|
||||
$collection->setStartDate($start);
|
||||
$collection->setEndDate($end);
|
||||
|
||||
/** @var Bill $bill */
|
||||
foreach ($bills as $bill) {
|
||||
$expectedDates = $repository->getPayDatesInRange($bill, $start, $end);
|
||||
foreach($expectedDates as $payDate) {
|
||||
$endOfPayPeriod = app('navigation')->endOfX($payDate, $bill->repeat_freq, null);
|
||||
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setAccounts($accounts)->setRange($payDate, $endOfPayPeriod)->setBills($bills);
|
||||
$journals = $collector->getJournals();
|
||||
|
||||
$billLine = new BillLine;
|
||||
$billLine->setBill($bill);
|
||||
$billLine->setPayDate($payDate);
|
||||
$billLine->setEndOfPayDate($endOfPayPeriod);
|
||||
$billLine->setMin(strval($bill->amount_min));
|
||||
$billLine->setMax(strval($bill->amount_max));
|
||||
$billLine->setHit(false);
|
||||
@ -101,6 +109,7 @@ class ReportHelper implements ReportHelperInterface
|
||||
$collection->addBill($billLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
$collection->filterBills();
|
||||
|
||||
return $collection;
|
||||
|
@ -186,11 +186,12 @@ class BillController extends Controller
|
||||
// paid in this period?
|
||||
$bill->paidDates = $repository->getPaidDatesInRange($bill, $start, $end);
|
||||
$bill->payDates = $repository->getPayDatesInRange($bill, $start, $end);
|
||||
$lastDate = clone $start;
|
||||
$lastPaidDate = $this->lastPaidDate($repository->getPaidDatesInRange($bill, $start, $end), $start);
|
||||
if ($bill->paidDates->count() >= $bill->payDates->count()) {
|
||||
$lastDate = $end;
|
||||
// if all bills have been been paid, jump to next period.
|
||||
$lastPaidDate = $end;
|
||||
}
|
||||
$bill->nextExpectedMatch = $repository->nextExpectedMatch($bill, $lastDate);
|
||||
$bill->nextExpectedMatch = $repository->nextExpectedMatch($bill, $lastPaidDate);
|
||||
}
|
||||
);
|
||||
|
||||
@ -235,6 +236,8 @@ class BillController extends Controller
|
||||
{
|
||||
/** @var Carbon $date */
|
||||
$date = session('start');
|
||||
/** @var Carbon $end */
|
||||
$end = session('end');
|
||||
$year = $date->year;
|
||||
$page = intval($request->get('page'));
|
||||
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||
@ -249,7 +252,15 @@ class BillController extends Controller
|
||||
$transactions = $collector->getPaginatedJournals();
|
||||
$transactions->setPath(route('bills.show', [$bill->id]));
|
||||
|
||||
$bill->nextExpectedMatch = $repository->nextExpectedMatch($bill, new Carbon);
|
||||
|
||||
$bill->paidDates = $repository->getPaidDatesInRange($bill, $date, $end);
|
||||
$bill->payDates = $repository->getPayDatesInRange($bill, $date, $end);
|
||||
$lastPaidDate = $this->lastPaidDate($repository->getPaidDatesInRange($bill, $date, $end), $date);
|
||||
if ($bill->paidDates->count() >= $bill->payDates->count()) {
|
||||
// if all bills have been been paid, jump to next period.
|
||||
$lastPaidDate = $end;
|
||||
}
|
||||
$bill->nextExpectedMatch = $repository->nextExpectedMatch($bill, $lastPaidDate);
|
||||
$hideBill = true;
|
||||
$subTitle = e($bill->name);
|
||||
|
||||
@ -325,4 +336,29 @@ class BillController extends Controller
|
||||
|
||||
return redirect($this->getPreviousUri('bills.edit.uri'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the latest date in the set, or start when set is empty.
|
||||
*
|
||||
* @param Collection $dates
|
||||
* @param Carbon $default
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
private function lastPaidDate(Collection $dates, Carbon $default): Carbon
|
||||
{
|
||||
if ($dates->count() === 0) {
|
||||
return $default;
|
||||
}
|
||||
$latest = $dates->first();
|
||||
/** @var Carbon $date */
|
||||
foreach ($dates as $date) {
|
||||
if ($date->gte($latest)) {
|
||||
$latest = $date;
|
||||
}
|
||||
}
|
||||
|
||||
return $latest;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -589,6 +589,7 @@ return [
|
||||
'not_or_not_yet' => 'Not (yet)',
|
||||
'not_expected_period' => 'Not expected this period',
|
||||
'bill_is_active' => 'Bill is active',
|
||||
'bill_expected_between' => 'Expeced between :start and :end',
|
||||
'bill_will_automatch' => 'Bill will automatically linked to matching transactions',
|
||||
'skips_over' => 'skips over',
|
||||
|
||||
|
@ -18,6 +18,9 @@
|
||||
<tr>
|
||||
<td data-value="{{ line.getBill.name }}">
|
||||
<a href="{{ route('bills.show',line.getBill.id) }}">{{ line.getBill.name }}</a>
|
||||
<small class="text-muted"><br />
|
||||
{{ trans('firefly.bill_expected_between', {start: line.getPayDate.formatLocalized(monthAndDayFormat), end: line.getEndOfPayDate.formatLocalized(monthAndDayFormat) }) }}
|
||||
</small>
|
||||
</td>
|
||||
<td class="hidden-xs" data-value="{{ line.getMin }}" style="text-align: right;">{{ line.getMin|formatAmount }}</td>
|
||||
<td class="hidden-xs" data-value="{{ line.getMax }}" style="text-align: right;">{{ line.getMax|formatAmount }}</td>
|
||||
|
Loading…
Reference in New Issue
Block a user