mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-01-23 23:13:18 -06:00
Improve bill things for issue #341
This commit is contained in:
parent
d92768ecbf
commit
f83aaf77f1
@ -137,7 +137,7 @@ class BillController extends Controller
|
||||
$bills = $repository->getBills();
|
||||
$bills->each(
|
||||
function (Bill $bill) use ($repository, $start, $end) {
|
||||
$bill->nextExpectedMatch = $repository->nextExpectedMatch($bill);
|
||||
$bill->nextExpectedMatch = $repository->nextExpectedMatch($bill, new Carbon);
|
||||
$bill->lastFoundMatch = $repository->lastFoundMatch($bill);
|
||||
$journals = $repository->getJournalsInRange($bill, $start, $end);
|
||||
// loop journals, find average:
|
||||
@ -204,7 +204,7 @@ class BillController extends Controller
|
||||
$yearAverage = $repository->getYearAverage($bill, $date);
|
||||
$overallAverage = $repository->getOverallAverage($bill);
|
||||
$journals->setPath('/bills/show/' . $bill->id);
|
||||
$bill->nextExpectedMatch = $repository->nextExpectedMatch($bill);
|
||||
$bill->nextExpectedMatch = $repository->nextExpectedMatch($bill, new Carbon);
|
||||
$hideBill = true;
|
||||
$subTitle = e($bill->name);
|
||||
|
||||
|
@ -18,10 +18,12 @@ use DB;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Database\Query\JoinClause;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Navigation;
|
||||
|
||||
/**
|
||||
@ -461,52 +463,44 @@ class BillRepository implements BillRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param Bill $bill
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return \Carbon\Carbon
|
||||
* @return Carbon
|
||||
*/
|
||||
public function nextExpectedMatch(Bill $bill): Carbon
|
||||
public function nextExpectedMatch(Bill $bill, Carbon $date): Carbon
|
||||
{
|
||||
|
||||
$finalDate = Carbon::now();
|
||||
$finalDate->year = 1900;
|
||||
if ($bill->active == 0) {
|
||||
return $finalDate;
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($bill->id);
|
||||
$cache->addProperty('nextExpectedMatch');
|
||||
if ($cache->has()) {
|
||||
return $cache->get();
|
||||
}
|
||||
// find the most recent date for this bill NOT in the future. Cache this date:
|
||||
$start = clone $bill->date;
|
||||
$now = new Carbon;
|
||||
Log::debug('Start is ' . $start->format('Y-m-d'));
|
||||
|
||||
/*
|
||||
* $today is the start of the next period, to make sure FF3 won't miss anything
|
||||
* when the current period has a transaction journal.
|
||||
*/
|
||||
/** @var \Carbon\Carbon $obj */
|
||||
$obj = new Carbon;
|
||||
$today = Navigation::addPeriod($obj, $bill->repeat_freq, 0);
|
||||
do {
|
||||
$start = Navigation::addPeriod($start, $bill->repeat_freq, $bill->skip);
|
||||
Log::debug('Start is now ' . $start->format('Y-m-d'));
|
||||
} while ($start <= $now);
|
||||
|
||||
$skip = $bill->skip + 1;
|
||||
$start = Navigation::startOfPeriod($obj, $bill->repeat_freq);
|
||||
/*
|
||||
* go back exactly one month/week/etc because FF3 does not care about 'next'
|
||||
* bills if they're too far into the past.
|
||||
*/
|
||||
$end = Navigation::addPeriod($start, $bill->repeat_freq, $bill->skip);
|
||||
Log::debug('Final start is ' . $start->format('Y-m-d'));
|
||||
Log::debug('Matching end is ' . $end->format('Y-m-d'));
|
||||
|
||||
$counter = 0;
|
||||
while ($start <= $today) {
|
||||
if (($counter % $skip) == 0) {
|
||||
// do something.
|
||||
$end = Navigation::endOfPeriod(clone $start, $bill->repeat_freq);
|
||||
$journalCount = $bill->transactionJournals()->before($end)->after($start)->count();
|
||||
if ($journalCount == 0) {
|
||||
$finalDate = new Carbon($start->format('Y-m-d'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
// see if the bill was paid in this period.
|
||||
$journalCount = $bill->transactionJournals()->before($end)->after($start)->count();
|
||||
|
||||
// add period for next round!
|
||||
$start = Navigation::addPeriod($start, $bill->repeat_freq, 0);
|
||||
$counter++;
|
||||
if ($journalCount > 0) {
|
||||
// this period had in fact a bill. The new start is the current end, and we create a new end.
|
||||
$start = clone $end;
|
||||
$end = Navigation::addPeriod($start, $bill->repeat_freq, $bill->skip);
|
||||
}
|
||||
$cache->store($start);
|
||||
|
||||
return $finalDate;
|
||||
return $start;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -168,11 +168,12 @@ interface BillRepositoryInterface
|
||||
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param Bill $bill
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return \Carbon\Carbon
|
||||
*/
|
||||
public function nextExpectedMatch(Bill $bill): Carbon;
|
||||
public function nextExpectedMatch(Bill $bill, Carbon $date): Carbon;
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
|
@ -6,7 +6,7 @@
|
||||
<th class="hidden-sm hidden-xs">{{ trans('list.matchesOn') }}</th>
|
||||
<th colspan="2">{{ trans('list.matchingAmount') }}</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.next_expected_match') }}</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.repeat_freq') }}</th>
|
||||
|
84
storage/database/seed.bill-test.json
Normal file
84
storage/database/seed.bill-test.json
Normal file
@ -0,0 +1,84 @@
|
||||
{
|
||||
"users": [
|
||||
{
|
||||
"email": "thegrumpydictator@gmail.com",
|
||||
"password": "james"
|
||||
},
|
||||
{
|
||||
"email": "thegrumpydictator+empty@gmail.com",
|
||||
"password": "james"
|
||||
},
|
||||
{
|
||||
"email": "thegrumpydictator+deleteme@gmail.com",
|
||||
"password": "james"
|
||||
}
|
||||
],
|
||||
"roles": [
|
||||
{
|
||||
"user_id": 1,
|
||||
"role": 1
|
||||
}
|
||||
],
|
||||
"accounts": [
|
||||
{
|
||||
"user_id": 1,
|
||||
"account_type_id": 3,
|
||||
"name": "Checking Account",
|
||||
"iban": "NL11XOLA6707795988"
|
||||
}
|
||||
],
|
||||
"account-meta": [
|
||||
],
|
||||
"bills": [
|
||||
{
|
||||
"name": "Some weird weekly bill",
|
||||
"match": "weird,weekly,bill",
|
||||
"amount_min": 30,
|
||||
"amount_max": 35,
|
||||
"user_id": 1,
|
||||
"date": "2016-06-12",
|
||||
"active": 1,
|
||||
"automatch": 1,
|
||||
"repeat_freq": "weekly",
|
||||
"skip": 0
|
||||
}
|
||||
],
|
||||
"budgets": [
|
||||
],
|
||||
"budget-limits": [
|
||||
],
|
||||
"monthly-limits": [
|
||||
],
|
||||
"categories": [
|
||||
],
|
||||
"piggy-banks": [
|
||||
],
|
||||
"piggy-events": [
|
||||
],
|
||||
"rule-groups": [
|
||||
],
|
||||
"rules": [
|
||||
],
|
||||
"rule-triggers": [
|
||||
],
|
||||
"rule-actions": [
|
||||
],
|
||||
"tags": [
|
||||
],
|
||||
"monthly-deposits": [
|
||||
],
|
||||
"monthly-transfers": [
|
||||
],
|
||||
"monthly-withdrawals": [
|
||||
],
|
||||
"attachments": [
|
||||
],
|
||||
"multi-withdrawals": [
|
||||
],
|
||||
"multi-deposits": [
|
||||
],
|
||||
"multi-transfers": [
|
||||
],
|
||||
"import-jobs": [],
|
||||
"currencies": []
|
||||
}
|
@ -245,27 +245,15 @@
|
||||
],
|
||||
"bills": [
|
||||
{
|
||||
"name": "Rent",
|
||||
"match": "rent,land,lord",
|
||||
"amount_min": 795,
|
||||
"amount_max": 805,
|
||||
"name": "Some weird weekly bill",
|
||||
"match": "weird,weekly,bill",
|
||||
"amount_min": 30,
|
||||
"amount_max": 35,
|
||||
"user_id": 1,
|
||||
"date": "2015-01-01",
|
||||
"date": "2016-06-12",
|
||||
"active": 1,
|
||||
"automatch": 1,
|
||||
"repeat_freq": "monthly",
|
||||
"skip": 0
|
||||
},
|
||||
{
|
||||
"name": "Health insurance",
|
||||
"match": "insurer,insurance,health",
|
||||
"amount_min": 120,
|
||||
"amount_max": 140,
|
||||
"user_id": 1,
|
||||
"date": "2015-01-01",
|
||||
"active": 1,
|
||||
"automatch": 1,
|
||||
"repeat_freq": "monthly",
|
||||
"repeat_freq": "weekly",
|
||||
"skip": 0
|
||||
}
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user