Added temporary debug entries.

This commit is contained in:
James Cole 2015-04-10 07:19:45 +02:00
parent 06f2e34bb5
commit db5d94d956

View File

@ -16,6 +16,7 @@ use Preferences;
use Response;
use Session;
use Steam;
use Log;
/**
* Class JsonController
@ -38,8 +39,6 @@ class JsonController extends Controller
case 'in':
$box = Input::get('box');
$set = $reportQuery->incomeByPeriod($start, $end, true);
foreach ($set as $entry) {
$amount += $entry->queryAmount;
}
@ -57,6 +56,7 @@ class JsonController extends Controller
$box = 'bills-unpaid';
$bills = $repository->getActiveBills();
$unpaid = new Collection; // bills
Log::debug('UnpaidBox: Unpaid box');
/** @var Bill $bill */
foreach ($bills as $bill) {
@ -85,16 +85,22 @@ class JsonController extends Controller
}
}
// loop unpaid:
/** @var Bill $entry */
foreach ($unpaid as $entry) {
$amount += ($entry[0]->amount_max + $entry[0]->amount_min) / 2;
$current = ($entry[0]->amount_max + $entry[0]->amount_min) / 2;
$amount += $current;
Log::debug('UnpaidBox: '.$entry[0]->name.': '.$current);
Log::debug('UnpaidBox: Total is now: ' . $amount);
}
Log::debug('UnpaidBox: Total is final: ' . $amount);
break;
case 'bills-paid':
$box = 'bills-paid';
// these two functions are the same as the chart TODO
$bills = Auth::user()->bills()->where('active', 1)->get();
Log::debug('PaidBox: Paid box');
/** @var Bill $bill */
foreach ($bills as $bill) {
@ -106,11 +112,15 @@ class JsonController extends Controller
if ($count != 0) {
$journal = $bill->transactionjournals()->with('transactions')->before($range['end'])->after($range['start'])->first();
$amount += $journal->amount;
Log::debug('PaidBox: Journal for bill "'.$bill->name.'": ' . $journal->amount);
Log::debug('PaidBox: Total is now: ' . $amount);
}
}
}
Log::debug('PaidBox: Doing ccs now.');
/**
* Find credit card accounts and possibly unpaid credit card bills.
*/
@ -129,6 +139,7 @@ class JsonController extends Controller
foreach ($creditCards as $creditCard) {
$balance = Steam::balance($creditCard, null, true);
if ($balance == 0) {
Log::debug('PaidBox: Balance for '.$creditCard->name.' is zero.');
// find a transfer TO the credit card which should account for
// anything paid. If not, the CC is not yet used.
$transactions = $creditCard->transactions()
@ -139,14 +150,19 @@ class JsonController extends Controller
foreach ($transactions as $transaction) {
$journal = $transaction->transactionJournal;
if ($journal->transactionType->type == 'Transfer') {
Log::debug('PaidBox: Found the transfer! Amount: ' . floatval($transaction->amount));
$amount += floatval($transaction->amount);
Log::debug('PaidBox: Total is now: ' . $amount);
}
}
}
}
}
Log::debug('PaidBox: Total is: ' . $amount);
break;
}
return Response::json(['box' => $box, 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]);
}