Example #1
1
 /**
  * Dodatkowe filtry Twig zwiazane z formatowaniem danych uzytkownika
  *
  * @return array
  */
 public function getFilters()
 {
     return [new Twig_SimpleFilter('format_date', function ($dateTime, $diffForHumans = true) {
         $format = Auth::check() ? auth()->user()->date_format : '%Y-%m-%d %H:%M';
         if (!$dateTime instanceof Carbon) {
             $dateTime = new Carbon($dateTime);
         }
         $now = Carbon::now();
         if (!$diffForHumans) {
             return $dateTime->formatLocalized($format);
         } elseif ($dateTime->diffInHours($now) < 1) {
             return $dateTime->diffForHumans(null, true) . ' temu';
         } elseif ($dateTime->isToday()) {
             return 'dziƛ, ' . $dateTime->format('H:i');
         } elseif ($dateTime->isYesterday()) {
             return 'wczoraj, ' . $dateTime->format('H:i');
         } else {
             return $dateTime->formatLocalized($format);
         }
     }), new Twig_SimpleFilter('timestamp', function ($dateTime) {
         if ($dateTime instanceof Carbon) {
             return $dateTime->getTimestamp();
         } else {
             return strtotime($dateTime);
         }
     })];
 }
Example #2
0
 /**
  * @param string $year
  * @param string $month
  *
  * @param bool   $shared
  *
  * @return \Illuminate\View\View
  */
 public function month($year = '2014', $month = '1', $shared = false)
 {
     $start = new Carbon($year . '-' . $month . '-01');
     $subTitle = trans('firefly.reportForMonth', ['month' => $start->formatLocalized($this->monthFormat)]);
     $subTitleIcon = 'fa-calendar';
     $end = clone $start;
     $incomeTopLength = 8;
     $expenseTopLength = 8;
     if ($shared == 'shared') {
         $shared = true;
         $subTitle = trans('firefly.reportForMonthShared', ['month' => $start->formatLocalized($this->monthFormat)]);
     }
     $end->endOfMonth();
     $accounts = $this->helper->getAccountReport($start, $end, $shared);
     $incomes = $this->helper->getIncomeReport($start, $end, $shared);
     $expenses = $this->helper->getExpenseReport($start, $end, $shared);
     $budgets = $this->helper->getBudgetReport($start, $end, $shared);
     $categories = $this->helper->getCategoryReport($start, $end, $shared);
     $balance = $this->helper->getBalanceReport($start, $end, $shared);
     $bills = $this->helper->getBillReport($start, $end);
     Session::flash('gaEventCategory', 'report');
     Session::flash('gaEventAction', 'month');
     Session::flash('gaEventLabel', $start->format('F Y'));
     return view('reports.month', compact('start', 'shared', 'subTitle', 'subTitleIcon', 'accounts', 'incomes', 'incomeTopLength', 'expenses', 'expenseTopLength', 'budgets', 'balance', 'categories', 'bills'));
 }
 public function formatLocalized($format = self::COOKIE)
 {
     if (strpos($format, '%f') !== false) {
         $langKey = strtolower(parent::format("F"));
         $replace = \Lang::get("localized-carbon::months." . $langKey);
         $result = str_replace('%f', $replace, $format);
     } else {
         $result = $format;
     }
     $result = parent::formatLocalized($result);
     return $result;
 }
 /**
  * @param Collection $set
  *
  * @return array
  */
 public function history(Collection $set) : array
 {
     // language:
     $format = (string) trans('config.month_and_day');
     $data = ['count' => 1, 'labels' => [], 'datasets' => [['label' => 'Diff', 'data' => []]]];
     $sum = '0';
     foreach ($set as $key => $value) {
         $date = new Carbon($key);
         $sum = bcadd($sum, $value);
         $data['labels'][] = $date->formatLocalized($format);
         $data['datasets'][0]['data'][] = round($sum, 2);
     }
     return $data;
 }
 /**
  * @param Collection $set
  *
  * @return array
  */
 public function history(Collection $set)
 {
     // language:
     $format = trans('config.month_and_day');
     $data = ['count' => 1, 'labels' => [], 'datasets' => [['label' => 'Diff', 'data' => []]]];
     $sum = '0';
     bcscale(2);
     foreach ($set as $entry) {
         $date = new Carbon($entry->date);
         $sum = bcadd($sum, $entry->sum);
         $data['labels'][] = $date->formatLocalized($format);
         $data['datasets'][0]['data'][] = round($sum, 2);
     }
     return $data;
 }
 /**
  * @param Collection $set
  *
  * @return array
  */
 public function history(Collection $set)
 {
     // language:
     $language = Preferences::get('language', 'en')->data;
     $format = Config::get('firefly.month.' . $language);
     $data = ['count' => 1, 'labels' => [], 'datasets' => [['label' => 'Diff', 'data' => []]]];
     $sum = '0';
     bcscale(2);
     foreach ($set as $entry) {
         $date = new Carbon($entry->date);
         $sum = bcadd($sum, $entry->sum);
         $data['labels'][] = $date->formatLocalized($format);
         $data['datasets'][0]['data'][] = round($sum, 2);
     }
     return $data;
 }
 /**
  * @param string     $reportType
  * @param Carbon     $start
  * @param Carbon     $end
  * @param Collection $accounts
  *
  * @return View
  * @throws FireflyException
  */
 public function report(string $reportType, Carbon $start, Carbon $end, Collection $accounts)
 {
     $this->createRepositories();
     // throw an error if necessary.
     if ($end < $start) {
         throw new FireflyException('End date cannot be before start date, silly!');
     }
     // lower threshold
     if ($start < session('first')) {
         $start = session('first');
     }
     View::share('subTitle', trans('firefly.report_' . $reportType, ['start' => $start->formatLocalized($this->monthFormat), 'end' => $end->formatLocalized($this->monthFormat)]));
     View::share('subTitleIcon', 'fa-calendar');
     switch ($reportType) {
         default:
             throw new FireflyException('Unfortunately, reports of the type "' . e($reportType) . '" are not yet available. ');
         case 'default':
             // more than one year date difference means year report.
             if ($start->diffInMonths($end) > 12) {
                 return $this->defaultMultiYear($reportType, $start, $end, $accounts);
             }
             // more than two months date difference means year report.
             if ($start->diffInMonths($end) > 1) {
                 return $this->defaultYear($reportType, $start, $end, $accounts);
             }
             // otherwise default
             return $this->defaultMonth($reportType, $start, $end, $accounts);
         case 'audit':
             // always default
             return $this->auditReport($start, $end, $accounts);
     }
 }
Example #8
0
 public function timestamp(Carbon $date, $format = '%x %X')
 {
     return $date->formatLocalized($format);
 }
 /**
  * @param            $reportType
  * @param Carbon     $start
  * @param Carbon     $end
  * @param Collection $accounts
  *
  * @return View
  */
 public function report($reportType, Carbon $start, Carbon $end, Collection $accounts)
 {
     // throw an error if necessary.
     if ($end < $start) {
         return view('error')->with('message', 'End date cannot be before start date, silly!');
     }
     // lower threshold
     if ($start < Session::get('first')) {
         $start = Session::get('first');
     }
     switch ($reportType) {
         default:
         case 'default':
             View::share('subTitle', trans('firefly.report_default', ['start' => $start->formatLocalized($this->monthFormat), 'end' => $end->formatLocalized($this->monthFormat)]));
             View::share('subTitleIcon', 'fa-calendar');
             // more than one year date difference means year report.
             if ($start->diffInMonths($end) > 12) {
                 return $this->defaultMultiYear($reportType, $start, $end, $accounts);
             }
             // more than two months date difference means year report.
             if ($start->diffInMonths($end) > 1) {
                 return $this->defaultYear($reportType, $start, $end, $accounts);
             }
             return $this->defaultMonth($reportType, $start, $end, $accounts);
     }
 }
 /**
  * @param Carbon $current
  * @param Carbon $end
  *
  * @return array
  */
 private function createYearHeaders(Carbon $current, Carbon $end) : array
 {
     $headers = [];
     while ($current < $end) {
         $short = $current->format('m-Y');
         $headers[$short] = $current->formatLocalized((string) trans('config.month'));
         $current->addMonth();
     }
     return $headers;
 }
Example #11
0
 /**
  * @param \Carbon\Carbon $date
  * @param                $repeatFrequency
  *
  * @return string
  * @throws FireflyException
  */
 public function periodShow(Carbon $date, $repeatFrequency)
 {
     $formatMap = ['daily' => '%e %B %Y', 'week' => 'Week %W, %Y', 'weekly' => 'Week %W, %Y', 'quarter' => '%B %Y', 'month' => '%B %Y', 'monthly' => '%B %Y', 'year' => '%Y', 'yearly' => '%Y'];
     if (isset($formatMap[$repeatFrequency])) {
         return $date->formatLocalized($formatMap[$repeatFrequency]);
     }
     throw new FireflyException('No date formats for frequency "' . $repeatFrequency . '"!');
 }
Example #12
0
 /**
  * @param \Carbon\Carbon $date
  * @param                $repeatFrequency
  *
  * @return string
  * @throws FireflyException
  */
 public function periodShow(Carbon $date, string $repeatFrequency) : string
 {
     $formatMap = ['1D' => trans('config.specific_day'), 'daily' => trans('config.specific_day'), 'custom' => trans('config.specific_day'), '1W' => trans('config.week_in_year'), 'week' => trans('config.week_in_year'), 'weekly' => trans('config.week_in_year'), '3M' => trans('config.quarter_of_year'), 'quarter' => trans('config.quarter_of_year'), '1M' => trans('config.month'), 'month' => trans('config.month'), 'monthly' => trans('config.month'), '1Y' => trans('config.year'), 'year' => trans('config.year'), 'yearly' => trans('config.year'), '6M' => trans('config.half_year')];
     if (isset($formatMap[$repeatFrequency])) {
         return $date->formatLocalized(strval($formatMap[$repeatFrequency]));
     }
     throw new FireflyException('No date formats for frequency "' . $repeatFrequency . '"!');
 }
Example #13
0
 /**
  *
  * Returns localized month name
  *
  * @param string $date
  * @return string
  */
 protected function getMonthName($date = '')
 {
     $d = new Carbon($date);
     return $d->formatLocalized('%B');
 }
Example #14
0
 public function getPostedOnAttribute($date)
 {
     $new_date = new Carbon($date);
     return $new_date->formatLocalized('%A %d, %B %Y at %H:%M:%S');
 }