mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 10:47:00 +00:00 
			
		
		
		
	Some query optimisations.
This commit is contained in:
		| @@ -15,7 +15,6 @@ use Illuminate\Support\Collection; | ||||
| use Preferences; | ||||
| use Response; | ||||
| use Session; | ||||
| use Steam; | ||||
|  | ||||
| /** | ||||
|  * Class JsonController | ||||
| @@ -72,8 +71,8 @@ class JsonController extends Controller | ||||
|      */ | ||||
|     public function boxBillsPaid(BillRepositoryInterface $repository, AccountRepositoryInterface $accountRepository) | ||||
|     { | ||||
|         $start  = Session::get('start', Carbon::now()->startOfMonth()); | ||||
|         $end    = Session::get('end', Carbon::now()->endOfMonth()); | ||||
|         $start = Session::get('start', Carbon::now()->startOfMonth()); | ||||
|         $end   = Session::get('end', Carbon::now()->endOfMonth()); | ||||
|         bcscale(2); | ||||
|  | ||||
|         // works for json too! | ||||
| @@ -88,11 +87,10 @@ class JsonController extends Controller | ||||
|         $amount = $repository->billsPaidInRange($start, $end)->sum('paid'); | ||||
|  | ||||
|         // add credit card bill. | ||||
|         $creditCards = $accountRepository->getCreditCards(); // Find credit card accounts and possibly unpaid credit card bills. | ||||
|         $creditCards = $accountRepository->getCreditCards($end); // Find credit card accounts and possibly unpaid credit card bills. | ||||
|         /** @var Account $creditCard */ | ||||
|         foreach ($creditCards as $creditCard) { | ||||
|             $balance = Steam::balance($creditCard, $end, true); // if the balance is not zero, the monthly payment is still underway. | ||||
|             if ($balance == 0) { | ||||
|             if ($creditCard->balance == 0) { | ||||
|                 // find a transfer TO the credit card which should account for | ||||
|                 // anything paid. If not, the CC is not yet used. | ||||
|                 $amount = bcadd($amount, $accountRepository->getTransfersInRange($creditCard, $start, $end)->sum('amount')); | ||||
| @@ -142,14 +140,15 @@ class JsonController extends Controller | ||||
|         } | ||||
|         unset($bill, $bills, $range, $ranges); | ||||
|  | ||||
|         $creditCards = $accountRepository->getCreditCards(); | ||||
|         $creditCards = $accountRepository->getCreditCards($end); | ||||
|  | ||||
|         /** @var Account $creditCard */ | ||||
|         foreach ($creditCards as $creditCard) { | ||||
|             $balance = Steam::balance($creditCard, $end, true); | ||||
|             $date    = new Carbon($creditCard->getMeta('ccMonthlyPaymentDate')); | ||||
|             if ($balance < 0) { | ||||
|             $date = new Carbon($creditCard->getMeta('ccMonthlyPaymentDate')); | ||||
|             if ($creditCard->balance < 0) { | ||||
|                 // unpaid! create a fake bill that matches the amount. | ||||
|                 $description = $creditCard->name; | ||||
|                 $fakeAmount  = $balance * -1; | ||||
|                 $fakeAmount  = $creditCard->balance * -1; | ||||
|                 $fakeBill    = $repository->createFakeBill($description, $date, $fakeAmount); | ||||
|                 $unpaid->push([$fakeBill, $date]); | ||||
|             } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user