mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-21 02:31:19 +00:00
Fixed a small bug in the bill-chart and simplified yet another Json box.
This commit is contained in:
@@ -302,7 +302,7 @@ class GoogleChartController extends Controller
|
|||||||
/** @var Bill $entry */
|
/** @var Bill $entry */
|
||||||
foreach ($unpaid as $entry) {
|
foreach ($unpaid as $entry) {
|
||||||
$unpaidDescriptions[] = $entry[0]->name . ' (' . $entry[1]->format('jS M Y') . ')';
|
$unpaidDescriptions[] = $entry[0]->name . ' (' . $entry[1]->format('jS M Y') . ')';
|
||||||
$unpaidAmount += ($bill->amount_max + $bill->amount_min / 2);
|
$unpaidAmount += ($entry[0]->amount_max + $entry[0]->amount_min / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
$chart->addRow('Unpaid: ' . join(', ', $unpaidDescriptions), $unpaidAmount);
|
$chart->addRow('Unpaid: ' . join(', ', $unpaidDescriptions), $unpaidAmount);
|
||||||
|
|||||||
@@ -2,12 +2,15 @@
|
|||||||
|
|
||||||
use Amount;
|
use Amount;
|
||||||
use Auth;
|
use Auth;
|
||||||
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Helpers\Report\ReportQueryInterface;
|
use FireflyIII\Helpers\Report\ReportQueryInterface;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\Bill;
|
use FireflyIII\Models\Bill;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
use Input;
|
use Input;
|
||||||
use Preferences;
|
use Preferences;
|
||||||
use Response;
|
use Response;
|
||||||
@@ -25,7 +28,7 @@ class JsonController extends Controller
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function box(BillRepositoryInterface $repository, ReportQueryInterface $reportQuery)
|
public function box(BillRepositoryInterface $repository, ReportQueryInterface $reportQuery, AccountRepositoryInterface $accountRepository)
|
||||||
{
|
{
|
||||||
$amount = 0;
|
$amount = 0;
|
||||||
$start = Session::get('start');
|
$start = Session::get('start');
|
||||||
@@ -51,8 +54,9 @@ class JsonController extends Controller
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case 'bills-unpaid':
|
case 'bills-unpaid':
|
||||||
$box = 'bills-unpaid';
|
$box = 'bills-unpaid';
|
||||||
$bills = Auth::user()->bills()->where('active', 1)->get();
|
$bills = $repository->getActiveBills();
|
||||||
|
$unpaid = new Collection; // bills
|
||||||
|
|
||||||
/** @var Bill $bill */
|
/** @var Bill $bill */
|
||||||
foreach ($bills as $bill) {
|
foreach ($bills as $bill) {
|
||||||
@@ -60,36 +64,31 @@ class JsonController extends Controller
|
|||||||
|
|
||||||
foreach ($ranges as $range) {
|
foreach ($ranges as $range) {
|
||||||
// paid a bill in this range?
|
// paid a bill in this range?
|
||||||
$count = $bill->transactionjournals()->before($range['end'])->after($range['start'])->count();
|
$journals = $repository->getJournalsInRange($bill, $range['start'], $range['end']);
|
||||||
if ($count == 0) {
|
if ($journals->count() == 0) {
|
||||||
$amount += floatval($bill->amount_max + $bill->amount_min / 2);
|
$unpaid->push([$bill, $range['start']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
$creditCards = $accountRepository->getCreditCards();
|
||||||
* Find credit card accounts and possibly unpaid credit card bills.
|
|
||||||
*/
|
|
||||||
$creditCards = Auth::user()->accounts()
|
|
||||||
->hasMetaValue('accountRole', 'ccAsset')
|
|
||||||
->hasMetaValue('ccType', 'monthlyFull')
|
|
||||||
->get(
|
|
||||||
[
|
|
||||||
'accounts.*',
|
|
||||||
'ccType.data as ccType',
|
|
||||||
'accountRole.data as accountRole'
|
|
||||||
]
|
|
||||||
);
|
|
||||||
// if the balance is not zero, the monthly payment is still underway.
|
|
||||||
/** @var Account $creditCard */
|
|
||||||
foreach ($creditCards as $creditCard) {
|
foreach ($creditCards as $creditCard) {
|
||||||
$balance = Steam::balance($creditCard, null, true);
|
$balance = Steam::balance($creditCard, null, true);
|
||||||
|
$date = new Carbon($creditCard->getMeta('ccMonthlyPaymentDate'));
|
||||||
if ($balance < 0) {
|
if ($balance < 0) {
|
||||||
// unpaid!
|
// unpaid! create a fake bill that matches the amount.
|
||||||
$amount += $balance * -1;
|
$description = $creditCard->name;
|
||||||
|
$amount = $balance * -1;
|
||||||
|
$fakeBill = $repository->createFakeBill($description, $date, $amount);
|
||||||
|
$unpaid->push([$fakeBill, $date]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// loop unpaid:
|
||||||
|
/** @var Bill $entry */
|
||||||
|
foreach ($unpaid as $entry) {
|
||||||
|
$unpaidDescriptions[] = $entry[0]->name . ' (' . $entry[1]->format('jS M Y') . ')';
|
||||||
|
$amount += ($entry[0]->amount_max + $entry[0]->amount_min / 2);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'bills-paid':
|
case 'bills-paid':
|
||||||
|
|||||||
Reference in New Issue
Block a user