fixed year filter in reports
This commit is contained in:
@@ -2,10 +2,13 @@
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use App\Traits\SearchString;
|
||||
use Date;
|
||||
|
||||
trait DateTime
|
||||
{
|
||||
use SearchString;
|
||||
|
||||
/*
|
||||
* Get the date format based on company settings.
|
||||
* getDateFormat method is used by Eloquent
|
||||
@@ -37,19 +40,15 @@ trait DateTime
|
||||
public function scopeMonthsOfYear($query, $field)
|
||||
{
|
||||
$now = Date::now();
|
||||
$year = request('year', $now->year);
|
||||
$year = $this->getSearchStringValue('year', $now->year);
|
||||
|
||||
$financial_start = $this->getFinancialStart();
|
||||
$financial_start = $this->getFinancialStart($year);
|
||||
|
||||
// Check if FS has been customized
|
||||
if ($now->startOfYear()->format('Y-m-d') === $financial_start->format('Y-m-d')) {
|
||||
$start = Date::parse($year . '-01-01')->startOfDay()->format('Y-m-d H:i:s');
|
||||
$end = Date::parse($year . '-12-31')->endOfDay()->format('Y-m-d H:i:s');
|
||||
} else {
|
||||
if (!is_null(request('year'))) {
|
||||
$financial_start->year = $year;
|
||||
}
|
||||
|
||||
$start = $financial_start->format('Y-m-d H:i:s');
|
||||
$end = $financial_start->addYear(1)->subDays(1)->format('Y-m-d H:i:s');
|
||||
}
|
||||
@@ -97,7 +96,7 @@ trait DateTime
|
||||
return $groups;
|
||||
}
|
||||
|
||||
public function getFinancialStart()
|
||||
public function getFinancialStart($year = null)
|
||||
{
|
||||
$now = Date::now();
|
||||
$start = Date::now()->startOfYear();
|
||||
@@ -106,7 +105,7 @@ trait DateTime
|
||||
|
||||
$day = !empty($setting[0]) ? $setting[0] : $start->day;
|
||||
$month = !empty($setting[1]) ? $setting[1] : $start->month;
|
||||
$year = request('year', $now->year);
|
||||
$year = $year ?? $this->getSearchStringValue('year', $now->year);
|
||||
|
||||
$financial_start = Date::create($year, $month, $day);
|
||||
|
||||
@@ -118,22 +117,22 @@ trait DateTime
|
||||
return $financial_start;
|
||||
}
|
||||
|
||||
public function getMonthlyDateFormat()
|
||||
public function getMonthlyDateFormat($year = null)
|
||||
{
|
||||
$format = 'M';
|
||||
|
||||
if ($this->getFinancialStart()->month != 1) {
|
||||
if ($this->getFinancialStart($year)->month != 1) {
|
||||
$format = 'M Y';
|
||||
}
|
||||
|
||||
return $format;
|
||||
}
|
||||
|
||||
public function getQuarterlyDateFormat()
|
||||
public function getQuarterlyDateFormat($year = null)
|
||||
{
|
||||
$format = 'M';
|
||||
|
||||
if ($this->getFinancialStart()->month != 1) {
|
||||
if ($this->getFinancialStart($year)->month != 1) {
|
||||
$format = 'M Y';
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Traits;
|
||||
|
||||
use App\Models\Auth\Permission;
|
||||
use App\Models\Auth\Role;
|
||||
use App\Traits\SearchString;
|
||||
use App\Utilities\Reports;
|
||||
use App\Utilities\Widgets;
|
||||
use Illuminate\Routing\Route;
|
||||
@@ -11,6 +12,8 @@ use Illuminate\Support\Str;
|
||||
|
||||
trait Permissions
|
||||
{
|
||||
use SearchString;
|
||||
|
||||
public function getActionsMap()
|
||||
{
|
||||
return [
|
||||
@@ -405,21 +408,10 @@ trait Permissions
|
||||
|
||||
// Find the proper controller for common API endpoints
|
||||
if (in_array($table, ['contacts', 'documents', 'transactions'])) {
|
||||
$controller = $type = '';
|
||||
$controller = '';
|
||||
|
||||
// Look for type in search variable like api/contacts?search=type:customer
|
||||
$queries = explode(' ', request()->get('search'));
|
||||
foreach ($queries as $query) {
|
||||
$tmp = explode(':', $query);
|
||||
|
||||
if (empty($tmp[0]) || ($tmp[0] != 'type') || empty($tmp[1])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$type = $tmp[1];
|
||||
|
||||
break;
|
||||
}
|
||||
$type = $this->getSearchStringValue('type');
|
||||
|
||||
if (!empty($type)) {
|
||||
$alias = config('type.' . $type . '.alias');
|
||||
|
||||
40
app/Traits/SearchString.php
Normal file
40
app/Traits/SearchString.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
trait SearchString
|
||||
{
|
||||
/**
|
||||
* Get the value of a name in search string
|
||||
* Example: search=type:customer year:2020 account_id:20
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSearchStringValue($name, $default = '', $input = null)
|
||||
{
|
||||
$value = $default;
|
||||
|
||||
if (is_null($input)) {
|
||||
$input = request('search');
|
||||
}
|
||||
|
||||
//$manager = $this->getSearchStringManager();
|
||||
//$parsed = $manager->parse($input);
|
||||
|
||||
$columns = explode(' ', $input);
|
||||
|
||||
foreach ($columns as $column) {
|
||||
$variable = explode(':', $column);
|
||||
|
||||
if (empty($variable[0]) || ($variable[0] != $name) || empty($variable[1])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$value = $variable[1];
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user