mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 02:36:28 +00:00 
			
		
		
		
	Code for #1040
This commit is contained in:
		| @@ -31,6 +31,7 @@ use FireflyIII\Models\Note; | ||||
| use FireflyIII\Models\TransactionJournal; | ||||
| use FireflyIII\Repositories\Bill\BillRepositoryInterface; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Pagination\LengthAwarePaginator; | ||||
| use Illuminate\Support\Collection; | ||||
| use Preferences; | ||||
| use URL; | ||||
| @@ -167,15 +168,19 @@ class BillController extends Controller | ||||
|      * | ||||
|      * @return View | ||||
|      */ | ||||
|     public function index(BillRepositoryInterface $repository) | ||||
|     public function index(Request $request, BillRepositoryInterface $repository) | ||||
|     { | ||||
|         /** @var Carbon $start */ | ||||
|         $start = session('start'); | ||||
|         /** @var Carbon $end */ | ||||
|         $end = session('end'); | ||||
|         $end        = session('end'); | ||||
|         $page       = 0 === intval($request->get('page')) ? 1 : intval($request->get('page')); | ||||
|         $pageSize   = intval(Preferences::get('listPageSize', 50)->data); | ||||
|         $collection = $repository->getBills(); | ||||
|         $total      = $collection->count(); | ||||
|         $collection = $collection->slice(($page - 1) * $pageSize, $pageSize); | ||||
|  | ||||
|         $bills = $repository->getBills(); | ||||
|         $bills->each( | ||||
|         $collection->each( | ||||
|             function (Bill $bill) use ($repository, $start, $end) { | ||||
|                 // paid in this period? | ||||
|                 $bill->paidDates = $repository->getPaidDatesInRange($bill, $start, $end); | ||||
| @@ -188,6 +193,9 @@ class BillController extends Controller | ||||
|                 $bill->nextExpectedMatch = $repository->nextExpectedMatch($bill, $lastPaidDate); | ||||
|             } | ||||
|         ); | ||||
|         // paginate bills | ||||
|         $bills= new LengthAwarePaginator($collection, $total, $pageSize, $page); | ||||
|         $bills->setPath(route('bills.index')); | ||||
|  | ||||
|         return view('bills.index', compact('bills')); | ||||
|     } | ||||
|   | ||||
| @@ -35,6 +35,7 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; | ||||
| use FireflyIII\Repositories\Journal\JournalRepositoryInterface; | ||||
| use FireflyIII\Support\CacheProperties; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Pagination\LengthAwarePaginator; | ||||
| use Illuminate\Support\Collection; | ||||
| use Log; | ||||
| use Preferences; | ||||
| @@ -175,11 +176,13 @@ class BudgetController extends Controller | ||||
|      * @SuppressWarnings(PHPMD.CyclomaticComplexity) complex because of while loop | ||||
|      * @SuppressWarnings(PHPMD.ExcessiveMethodLength) | ||||
|      */ | ||||
|     public function index(string $moment = null) | ||||
|     public function index(Request $request, string $moment = null) | ||||
|     { | ||||
|         $range = Preferences::get('viewRange', '1M')->data; | ||||
|         $start = session('start', new Carbon); | ||||
|         $end   = session('end', new Carbon); | ||||
|         $range    = Preferences::get('viewRange', '1M')->data; | ||||
|         $start    = session('start', new Carbon); | ||||
|         $end      = session('end', new Carbon); | ||||
|         $page     = 0 === intval($request->get('page')) ? 1 : intval($request->get('page')); | ||||
|         $pageSize = intval(Preferences::get('listPageSize', 50)->data); | ||||
|  | ||||
|         // make date if present: | ||||
|         if (null !== $moment || 0 !== strlen(strval($moment))) { | ||||
| @@ -197,6 +200,8 @@ class BudgetController extends Controller | ||||
|         $prev = app('navigation')->startOfPeriod($prev, $range); | ||||
|         $this->repository->cleanupBudgets(); | ||||
|         $budgets           = $this->repository->getActiveBudgets(); | ||||
|         $total             = $budgets->count(); | ||||
|         $budgets           = $budgets->slice(($page - 1) * $pageSize, $pageSize); | ||||
|         $inactive          = $this->repository->getInactiveBudgets(); | ||||
|         $periodStart       = $start->formatLocalized($this->monthAndDayFormat); | ||||
|         $periodEnd         = $end->formatLocalized($this->monthAndDayFormat); | ||||
| @@ -206,6 +211,10 @@ class BudgetController extends Controller | ||||
|         $spent             = array_sum(array_column($budgetInformation, 'spent')); | ||||
|         $budgeted          = array_sum(array_column($budgetInformation, 'budgeted')); | ||||
|  | ||||
|         // paginate budgets | ||||
|         $budgets = new LengthAwarePaginator($budgets, $total, $pageSize, $page); | ||||
|         $budgets->setPath(route('budgets.index')); | ||||
|  | ||||
|         // select thing for last 12 periods: | ||||
|         $previousLoop = []; | ||||
|         $previousDate = clone $start; | ||||
| @@ -248,6 +257,7 @@ class BudgetController extends Controller | ||||
|                 'prevText', | ||||
|                 'periodStart', | ||||
|                 'periodEnd', | ||||
|                 'page', | ||||
|                 'budgetInformation', | ||||
|                 'inactive', | ||||
|                 'budgets', | ||||
|   | ||||
| @@ -34,6 +34,7 @@ use FireflyIII\Repositories\Category\CategoryRepositoryInterface; | ||||
| use FireflyIII\Repositories\Journal\JournalRepositoryInterface; | ||||
| use FireflyIII\Support\CacheProperties; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Pagination\LengthAwarePaginator; | ||||
| use Illuminate\Support\Collection; | ||||
| use Log; | ||||
| use Preferences; | ||||
| @@ -136,16 +137,24 @@ class CategoryController extends Controller | ||||
|      * | ||||
|      * @return View | ||||
|      */ | ||||
|     public function index(CategoryRepositoryInterface $repository) | ||||
|     public function index(Request $request, CategoryRepositoryInterface $repository) | ||||
|     { | ||||
|         $categories = $repository->getCategories(); | ||||
|         $page       = 0 === intval($request->get('page')) ? 1 : intval($request->get('page')); | ||||
|         $pageSize   = intval(Preferences::get('listPageSize', 50)->data); | ||||
|         $collection = $repository->getCategories(); | ||||
|         $total      = $collection->count(); | ||||
|         $collection = $collection->slice(($page - 1) * $pageSize, $pageSize); | ||||
|  | ||||
|         $categories->each( | ||||
|         $collection->each( | ||||
|             function (Category $category) use ($repository) { | ||||
|                 $category->lastActivity = $repository->lastUseDate($category, new Collection); | ||||
|             } | ||||
|         ); | ||||
|  | ||||
|         // paginate categories | ||||
|         $categories = new LengthAwarePaginator($collection, $total, $pageSize, $page); | ||||
|         $categories->setPath(route('categories.index')); | ||||
|  | ||||
|         return view('categories.index', compact('categories')); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -28,6 +28,7 @@ use FireflyIII\Models\TransactionCurrency; | ||||
| use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; | ||||
| use FireflyIII\Repositories\User\UserRepositoryInterface; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Pagination\LengthAwarePaginator; | ||||
| use Log; | ||||
| use Preferences; | ||||
| use View; | ||||
| @@ -198,12 +199,19 @@ class CurrencyController extends Controller | ||||
|      */ | ||||
|     public function index(Request $request) | ||||
|     { | ||||
|         $currencies      = $this->repository->get(); | ||||
|         $currencies      = $currencies->sortBy( | ||||
|         $page       = 0 === intval($request->get('page')) ? 1 : intval($request->get('page')); | ||||
|         $pageSize   = intval(Preferences::get('listPageSize', 50)->data); | ||||
|         $collection = $this->repository->get(); | ||||
|         $total      = $collection->count(); | ||||
|         $collection = $collection->sortBy( | ||||
|             function (TransactionCurrency $currency) { | ||||
|                 return $currency->name; | ||||
|             } | ||||
|         ); | ||||
|         $collection = $collection->slice(($page - 1) * $pageSize, $pageSize); | ||||
|         $currencies = new LengthAwarePaginator($collection, $total, $pageSize, $page); | ||||
|         $currencies->setPath(route('currencies.index')); | ||||
|  | ||||
|         $defaultCurrency = $this->repository->getCurrencyByPreference(Preferences::get('currencyPreference', config('firefly.default_currency', 'EUR'))); | ||||
|         $isOwner         = true; | ||||
|         if (!$this->userRepository->hasRole(auth()->user(), 'owner')) { | ||||
|   | ||||
| @@ -30,7 +30,7 @@ use FireflyIII\Models\PiggyBank; | ||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||
| use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Support\Collection; | ||||
| use Illuminate\Pagination\LengthAwarePaginator; | ||||
| use Log; | ||||
| use Preferences; | ||||
| use Response; | ||||
| @@ -199,17 +199,19 @@ class PiggyBankController extends Controller | ||||
|      * | ||||
|      * @return View | ||||
|      */ | ||||
|     public function index(PiggyBankRepositoryInterface $piggyRepository) | ||||
|     public function index(Request $request, PiggyBankRepositoryInterface $piggyRepository) | ||||
|     { | ||||
|         /** @var Collection $piggyBanks */ | ||||
|         $piggyBanks = $piggyRepository->getPiggyBanks(); | ||||
|         $collection = $piggyRepository->getPiggyBanks(); | ||||
|         $total      = $collection->count(); | ||||
|         $page       = 0 === intval($request->get('page')) ? 1 : intval($request->get('page')); | ||||
|         $pageSize   = intval(Preferences::get('listPageSize', 50)->data); | ||||
|         /** @var Carbon $end */ | ||||
|         $end = session('end', Carbon::now()->endOfMonth()); | ||||
|  | ||||
|         $accounts = []; | ||||
|         Log::debug('Looping piggues'); | ||||
|         /** @var PiggyBank $piggyBank */ | ||||
|         foreach ($piggyBanks as $piggyBank) { | ||||
|         foreach ($collection as $piggyBank) { | ||||
|             $piggyBank->savedSoFar = $piggyBank->currentRelevantRep()->currentamount ?? '0'; | ||||
|             $piggyBank->percentage = 0 !== bccomp('0', $piggyBank->savedSoFar) ? intval($piggyBank->savedSoFar / $piggyBank->targetamount * 100) : 0; | ||||
|             $piggyBank->leftToSave = bcsub($piggyBank->targetamount, strval($piggyBank->savedSoFar)); | ||||
| @@ -236,6 +238,11 @@ class PiggyBankController extends Controller | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         // paginate piggy banks | ||||
|         $collection = $collection->slice(($page - 1) * $pageSize, $pageSize); | ||||
|         $piggyBanks = new LengthAwarePaginator($collection, $total, $pageSize, $page); | ||||
|         $piggyBanks->setPath(route('piggy-banks.index')); | ||||
|  | ||||
|         return view('piggy-banks.index', compact('piggyBanks', 'accounts')); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -83,7 +83,7 @@ | ||||
|             {% endif %} | ||||
|         </div> | ||||
|     </div> | ||||
|     {% if budgets.count == 0 and inactive.count == 0 %} | ||||
|     {% if budgets.count == 0 and inactive.count == 0 and page == 1 %} | ||||
|         {% include 'partials.empty' with {what: 'default', type: 'budgets',route: route('budgets.create')} %} | ||||
|         {# make FF ignore demo for now. #} | ||||
|         {% set shownDemo = true %} | ||||
| @@ -134,6 +134,9 @@ | ||||
|                     <h3 class="box-title">{{ 'budgets'|_ }}</h3> | ||||
|                 </div> | ||||
|                 <div class="box-body no-padding"> | ||||
|                     <div style="padding-left:8px;"> | ||||
|                         {{ budgets.render|raw }} | ||||
|                     </div> | ||||
|                     <table class="table table-bordered table-striped sortable" id="budgetList"> | ||||
|                         <thead> | ||||
|                         <tr> | ||||
| @@ -190,6 +193,9 @@ | ||||
|                         {% endfor %} | ||||
|                         </tbody> | ||||
|                     </table> | ||||
|                     <div style="padding-left:8px;"> | ||||
|                         {{ budgets.render|raw }} | ||||
|                     </div> | ||||
|                 </div> | ||||
|             </div> | ||||
|         </div> | ||||
|   | ||||
| @@ -16,11 +16,14 @@ | ||||
|                         {{ 'currencies_intro'|_ }} | ||||
|                     </p> | ||||
|                     {% if currencies|length > 0 %} | ||||
|                         <div style="padding-left:8px;"> | ||||
|                             {{ currencies.render|raw }} | ||||
|                         </div> | ||||
|                         <table class="table table-hover"> | ||||
|                             <thead> | ||||
|                             <tr> | ||||
|                                 {% if isOwner %} | ||||
|                                 <th> </th> | ||||
|                                     <th> </th> | ||||
|                                 {% endif %} | ||||
|                                 <th>{{ 'currency'|_ }}</th> | ||||
|                                 <th>{{ 'number_of_decimals'|_ }}</th> | ||||
| @@ -31,12 +34,12 @@ | ||||
|                             {% for currency in currencies %} | ||||
|                                 <tr> | ||||
|                                     {% if isOwner %} | ||||
|                                     <td> | ||||
|                                         <div class="btn-group btn-group-xs"> | ||||
|                                             <a class="btn btn-default" href="{{ route('currencies.edit',currency.id) }}"><i class="fa fa-fw fa-pencil"></i></a> | ||||
|                                             <a class="btn btn-danger" href="{{ route('currencies.delete',currency.id) }}"><i class="fa fa-fw fa-trash"></i></a> | ||||
|                                         </div> | ||||
|                                     </td> | ||||
|                                         <td> | ||||
|                                             <div class="btn-group btn-group-xs"> | ||||
|                                                 <a class="btn btn-default" href="{{ route('currencies.edit',currency.id) }}"><i class="fa fa-fw fa-pencil"></i></a> | ||||
|                                                 <a class="btn btn-danger" href="{{ route('currencies.delete',currency.id) }}"><i class="fa fa-fw fa-trash"></i></a> | ||||
|                                             </div> | ||||
|                                         </td> | ||||
|                                     {% endif %} | ||||
|                                     <td>{{ currency.name }} ({{ currency.code }}) ({{ currency.symbol|raw }})</td> | ||||
|                                     <td>{{ currency.decimal_places }}</td> | ||||
| @@ -52,6 +55,9 @@ | ||||
|                             {% endfor %} | ||||
|                             </tbody> | ||||
|                         </table> | ||||
|                         <div style="padding-left:8px;"> | ||||
|                             {{ currencies.render|raw }} | ||||
|                         </div> | ||||
|                     {% endif %} | ||||
|                 </div> | ||||
|                 <div class="box-footer"> | ||||
|   | ||||
| @@ -1,3 +1,6 @@ | ||||
| <div style="padding-left:8px;"> | ||||
|     {{ bills.render|raw }} | ||||
| </div> | ||||
| <table class="table table-hover sortable"> | ||||
|     <thead> | ||||
|     <tr> | ||||
| @@ -126,3 +129,6 @@ | ||||
|     {% endfor %} | ||||
|     </tbody> | ||||
| </table> | ||||
| <div style="padding-left:8px;"> | ||||
|     {{ bills.render|raw }} | ||||
| </div> | ||||
| @@ -1,3 +1,6 @@ | ||||
| <div style="padding-left:8px;"> | ||||
|     {{ categories.render|raw }} | ||||
| </div> | ||||
| <table class="table table-hover sortable"> | ||||
|     <thead> | ||||
|     <tr> | ||||
| @@ -36,3 +39,6 @@ | ||||
|     {% endfor %} | ||||
|     </tbody> | ||||
| </table> | ||||
| <div style="padding-left:8px;"> | ||||
|     {{ categories.render|raw }} | ||||
| </div> | ||||
| @@ -1,3 +1,6 @@ | ||||
| <div style="padding-left:8px;"> | ||||
|     {{ piggyBanks.render|raw }} | ||||
| </div> | ||||
| <table class="table table-hover table-condensed" id="sortable-piggy"> | ||||
|     <thead> | ||||
|     <tr> | ||||
| @@ -80,3 +83,6 @@ | ||||
|     {% endfor %} | ||||
|     </tbody> | ||||
| </table> | ||||
| <div style="padding-left:8px;"> | ||||
|     {{ piggyBanks.render|raw }} | ||||
| </div> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user