firefly-iii/app/Http/Controllers/Controller.php

82 lines
2.2 KiB
PHP
Raw Normal View History

<?php
/**
* Controller.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
2016-02-05 05:08:25 -06:00
declare(strict_types = 1);
2015-02-05 21:39:52 -06:00
namespace FireflyIII\Http\Controllers;
2016-01-09 00:48:45 -06:00
use Carbon\Carbon;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
2015-06-13 03:02:36 -05:00
use Illuminate\Foundation\Bus\DispatchesJobs;
2015-02-05 21:39:52 -06:00
use Illuminate\Foundation\Validation\ValidatesRequests;
2015-02-11 00:35:10 -06:00
use Illuminate\Routing\Controller as BaseController;
2016-01-09 00:48:45 -06:00
use View;
2015-02-05 21:39:52 -06:00
2015-02-11 00:35:10 -06:00
/**
* Class Controller
*
* @package FireflyIII\Http\Controllers
*/
class Controller extends BaseController
2015-02-11 00:35:10 -06:00
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
2015-05-14 06:41:21 -05:00
2016-03-01 14:31:25 -06:00
/** @var string */
protected $dateTimeFormat;
/** @var string */
2016-01-09 00:48:45 -06:00
protected $monthAndDayFormat;
/** @var string */
2016-01-24 08:58:16 -06:00
protected $monthFormat;
2016-01-09 00:48:45 -06:00
2015-04-28 08:26:30 -05:00
/**
* Controller constructor.
2015-04-28 08:26:30 -05:00
*/
public function __construct()
{
View::share('hideBudgets', false);
View::share('hideCategories', false);
View::share('hideBills', false);
View::share('hideTags', false);
2015-05-14 06:41:21 -05:00
2016-09-16 03:50:19 -05:00
// save some formats:
$this->monthFormat = (string)trans('config.month');
$this->monthAndDayFormat = (string)trans('config.month_and_day');
$this->dateTimeFormat = (string)trans('config.date_time');
2015-05-14 06:41:21 -05:00
2015-04-28 08:26:30 -05:00
}
2015-12-31 10:20:54 -06:00
/**
* Take the array as returned by CategoryRepositoryInterface::spentPerDay and CategoryRepositoryInterface::earnedByDay
2015-12-31 10:20:54 -06:00
* and sum up everything in the array in the given range.
*
* @param Carbon $start
* @param Carbon $end
* @param array $array
*
* @return string
*/
protected function getSumOfRange(Carbon $start, Carbon $end, array $array)
{
$sum = '0';
$currentStart = clone $start; // to not mess with the original one
$currentEnd = clone $end; // to not mess with the original one
while ($currentStart <= $currentEnd) {
$date = $currentStart->format('Y-m-d');
if (isset($array[$date])) {
$sum = bcadd($sum, $array[$date]);
}
$currentStart->addDay();
}
return $sum;
}
2015-02-05 21:39:52 -06:00
}