mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-17 17:57:09 +00:00
Make boxes respond to unpaid / paid credit card bills.
This commit is contained in:
@@ -2,14 +2,18 @@
|
|||||||
|
|
||||||
use Amount;
|
use Amount;
|
||||||
use Auth;
|
use Auth;
|
||||||
|
use Carbon\Carbon;
|
||||||
use DB;
|
use DB;
|
||||||
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\Bill;
|
use FireflyIII\Models\Bill;
|
||||||
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||||
use Input;
|
use Input;
|
||||||
use Preferences;
|
use Preferences;
|
||||||
use Response;
|
use Response;
|
||||||
use Session;
|
use Session;
|
||||||
|
use Steam;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class JsonController
|
* Class JsonController
|
||||||
@@ -70,11 +74,34 @@ class JsonController extends Controller
|
|||||||
$count = $bill->transactionjournals()->before($range['end'])->after($range['start'])->count();
|
$count = $bill->transactionjournals()->before($range['end'])->after($range['start'])->count();
|
||||||
if ($count == 0) {
|
if ($count == 0) {
|
||||||
$amount += floatval($bill->amount_max + $bill->amount_min / 2);
|
$amount += floatval($bill->amount_max + $bill->amount_min / 2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
||||||
|
$balance = Steam::balance($creditCard, null, true);
|
||||||
|
if ($balance < 0) {
|
||||||
|
// unpaid!
|
||||||
|
$amount += $balance * -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'bills-paid':
|
case 'bills-paid':
|
||||||
$box = 'bills-paid';
|
$box = 'bills-paid';
|
||||||
@@ -101,6 +128,41 @@ class JsonController extends Controller
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
||||||
|
$balance = Steam::balance($creditCard, null, true);
|
||||||
|
if ($balance == 0) {
|
||||||
|
// find a transfer TO the credit card which should account for
|
||||||
|
// anything paid. If not, the CC is not yet used.
|
||||||
|
$transactions = $creditCard->transactions()
|
||||||
|
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||||
|
->before($end)->after($start)->get();
|
||||||
|
if ($transactions->count() > 0) {
|
||||||
|
/** @var Transaction $transaction */
|
||||||
|
foreach ($transactions as $transaction) {
|
||||||
|
$journal = $transaction->transactionJournal;
|
||||||
|
if ($journal->transactionType->type == 'Transfer') {
|
||||||
|
$amount += floatval($transaction->amount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Response::json(['box' => $box, 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]);
|
return Response::json(['box' => $box, 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]);
|
||||||
|
Reference in New Issue
Block a user