mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-09 20:11:22 +00:00
Fixed more of the index.
This commit is contained in:
57
app/Support/Amount.php
Normal file
57
app/Support/Amount.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Support;
|
||||
|
||||
use FireflyIII\Models\Transaction;
|
||||
/**
|
||||
* Class Amount
|
||||
*
|
||||
* @package FireflyIII\Support
|
||||
*/
|
||||
class Amount
|
||||
{
|
||||
/**
|
||||
* @param \Transaction $transaction
|
||||
* @param bool $coloured
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function formatTransaction(Transaction $transaction, $coloured = true)
|
||||
{
|
||||
$symbol = $transaction->transactionJournal->transactionCurrency->symbol;
|
||||
$amount = floatval($transaction->amount);
|
||||
|
||||
return $this->formatWithSymbol($symbol, $amount, $coloured);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $symbol
|
||||
* @param float $amount
|
||||
* @param bool $coloured
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function formatWithSymbol($symbol, $amount, $coloured = true)
|
||||
{
|
||||
$amount = floatval($amount);
|
||||
$amount = round($amount, 2);
|
||||
$string = number_format($amount, 2, ',', '.');
|
||||
|
||||
if ($coloured === true) {
|
||||
if ($amount === 0.0) {
|
||||
return '<span style="color:#999">' . $symbol . ' ' . $string . '</span>';
|
||||
}
|
||||
if ($amount > 0) {
|
||||
return '<span class="text-success">' . $symbol . ' ' . $string . '</span>';
|
||||
}
|
||||
|
||||
return '<span class="text-danger">' . $symbol . ' ' . $string . '</span>';
|
||||
}
|
||||
|
||||
// €
|
||||
return $symbol . ' ' . $string;
|
||||
}
|
||||
}
|
||||
23
app/Support/Facades/Amount.php
Normal file
23
app/Support/Facades/Amount.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Support\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
/**
|
||||
* Class Amount
|
||||
*
|
||||
* @package FireflyIII\Support\Facades
|
||||
*/
|
||||
class Amount extends Facade
|
||||
{
|
||||
/**
|
||||
* Get the registered name of the component.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return 'amount';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,7 +4,7 @@ namespace FireflyIII\Support\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
/**
|
||||
* Class Preferences
|
||||
* Class Navigation
|
||||
*
|
||||
* @package FireflyIII\Support\Facades
|
||||
*/
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace FireflyIII\Support;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exception\FireflyException;
|
||||
use Session;
|
||||
|
||||
/**
|
||||
* Class Navigation
|
||||
@@ -15,48 +14,6 @@ class Navigation
|
||||
{
|
||||
|
||||
|
||||
public function jumpToPrevious($range, Carbon $date)
|
||||
{
|
||||
$functionMap = [
|
||||
'1D' => 'Day',
|
||||
'1W' => 'Week',
|
||||
'1M' => 'Month',
|
||||
'1Y' => 'Year'
|
||||
];
|
||||
|
||||
if (isset($functionMap[$range])) {
|
||||
$startFunction = 'startOf' . $functionMap[$range];
|
||||
$subFunction = 'sub' . $functionMap[$range];
|
||||
$date->$startFunction()->$subFunction();
|
||||
|
||||
return $date;
|
||||
}
|
||||
if ($range == '3M') {
|
||||
$date->firstOfQuarter()->subMonths(3)->firstOfQuarter();
|
||||
|
||||
return $date;
|
||||
}
|
||||
if ($range == '6M') {
|
||||
$month = intval($date->format('m'));
|
||||
$date->startOfYear();
|
||||
if ($month <= 6) {
|
||||
$date->subMonths(6);
|
||||
}
|
||||
|
||||
return $date;
|
||||
}
|
||||
throw new FireflyException('Cannot do _previous() on ' . $range);
|
||||
}
|
||||
|
||||
public function next()
|
||||
{
|
||||
|
||||
$range = Session::get('range');
|
||||
$start = Session::get('start');
|
||||
|
||||
Session::put('start', Navigation::jumpToNext($range, clone $start));
|
||||
}
|
||||
|
||||
public function jumpToNext($range, Carbon $date)
|
||||
{
|
||||
switch ($range) {
|
||||
@@ -90,6 +47,39 @@ class Navigation
|
||||
return $date;
|
||||
}
|
||||
|
||||
public function jumpToPrevious($range, Carbon $date)
|
||||
{
|
||||
$functionMap = [
|
||||
'1D' => 'Day',
|
||||
'1W' => 'Week',
|
||||
'1M' => 'Month',
|
||||
'1Y' => 'Year'
|
||||
];
|
||||
|
||||
if (isset($functionMap[$range])) {
|
||||
$startFunction = 'startOf' . $functionMap[$range];
|
||||
$subFunction = 'sub' . $functionMap[$range];
|
||||
$date->$startFunction()->$subFunction();
|
||||
|
||||
return $date;
|
||||
}
|
||||
if ($range == '3M') {
|
||||
$date->firstOfQuarter()->subMonths(3)->firstOfQuarter();
|
||||
|
||||
return $date;
|
||||
}
|
||||
if ($range == '6M') {
|
||||
$month = intval($date->format('m'));
|
||||
$date->startOfYear();
|
||||
if ($month <= 6) {
|
||||
$date->subMonths(6);
|
||||
}
|
||||
|
||||
return $date;
|
||||
}
|
||||
throw new FireflyException('Cannot do _previous() on ' . $range);
|
||||
}
|
||||
|
||||
public function periodName($range, Carbon $date)
|
||||
{
|
||||
$formatMap = [
|
||||
@@ -116,15 +106,6 @@ class Navigation
|
||||
throw new FireflyException('No _periodName() for range "' . $range . '"');
|
||||
}
|
||||
|
||||
public function prev()
|
||||
{
|
||||
$range = Session::get('range');
|
||||
$start = Session::get('start');
|
||||
|
||||
Session::put('start', Navigation::jumpToPrevious($range, clone $start));
|
||||
|
||||
}
|
||||
|
||||
public function updateEndDate($range, Carbon $start)
|
||||
{
|
||||
$functionMap = [
|
||||
|
||||
Reference in New Issue
Block a user