Correction of query Gross Annual Savings.
This commit is contained in:
parent
c07de31547
commit
471c4fb3ed
@ -27,7 +27,7 @@ class Helpers
|
|||||||
->transform(fn($value) => Arr::set(
|
->transform(fn($value) => Arr::set(
|
||||||
$value,
|
$value,
|
||||||
$field,
|
$field,
|
||||||
Carbon::createFromFormat('ym', $value['mes'])
|
Carbon::createFromFormat('ym', $value['mes'])->locale('pt-BR')
|
||||||
->translatedFormat('M/Y')))
|
->translatedFormat('M/Y')))
|
||||||
->all();
|
->all();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,6 +32,9 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function register(): void
|
public function register(): void
|
||||||
{
|
{
|
||||||
|
|
||||||
|
setlocale(LC_TIME, config('app.locale'), 'pt_BR.utf-8', 'pt_BR.utf-8', 'portuguese');
|
||||||
|
|
||||||
$this->app->bind(
|
$this->app->bind(
|
||||||
UserContractInterface::class,
|
UserContractInterface::class,
|
||||||
UserRepository::class
|
UserRepository::class
|
||||||
@ -78,6 +81,5 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
setlocale(LC_TIME, config('app.locale'), 'pt_BR.utf-8', 'pt_BR.utf-8', 'portuguese');
|
setlocale(LC_TIME, config('app.locale'), 'pt_BR.utf-8', 'pt_BR.utf-8', 'portuguese');
|
||||||
date_default_timezone_set('America/Sao_Paulo');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,7 @@ use DatePeriod;
|
|||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
@ -39,19 +40,43 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt
|
|||||||
public function getGrossAnnualEconomy($params): Collection|array
|
public function getGrossAnnualEconomy($params): Collection|array
|
||||||
{
|
{
|
||||||
$field = [
|
$field = [
|
||||||
|
"economia.mes",
|
||||||
DB::raw("TO_CHAR(TO_DATE(economia.mes, 'YYMM'), 'YYYY') as ano"),
|
DB::raw("TO_CHAR(TO_DATE(economia.mes, 'YYMM'), 'YYYY') as ano"),
|
||||||
DB::raw("SUM(economia.economia_acumulada)/1000 as economia_acumulada"),
|
DB::raw("SUM(economia.economia_mensal) as economia_acumulada_a"),
|
||||||
DB::raw("(SUM(economia.economia_mensal)/SUM(economia.custo_livre)) as econ_percentual"),
|
DB::raw("SUM(economia.economia_acumulada) as economia_acumulada"),
|
||||||
|
DB::raw("(SUM(economia.economia_mensal)/SUM(economia.custo_cativo)) as econ_percentual"),
|
||||||
"economia.dad_estimado"
|
"economia.dad_estimado"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
return $this->execute($params, $field)
|
return $this->execute($params, $field)
|
||||||
->where(DB::raw("TO_DATE(economia.mes, 'YYMM')"),
|
->where(DB::raw(
|
||||||
|
"TO_DATE(economia.mes, 'YYMM')"),
|
||||||
">=",
|
">=",
|
||||||
DB::raw("TO_DATE(TO_CHAR(current_date , 'YYYY-12-01'), 'YYYY-MM-DD') - interval '1' year"))
|
DB::raw("TO_DATE(TO_CHAR(current_date , 'YYYY-12-01'), 'YYYY-MM-DD') - interval '1' year"))
|
||||||
->groupBy(['ano', 'dad_estimado'])
|
->where(function ($query) {
|
||||||
->orderBy(DB::raw("ano, dad_estimado"))
|
$query->where(DB::raw("extract(month from TO_DATE(economia.mes, 'YYMM'))"), '=', 12)
|
||||||
|
->orWhere(function ($query) {
|
||||||
|
$query->where(DB::raw("extract(year from TO_DATE(economia.mes, 'YYMM'))"), '=', DB::raw('extract(year from NOW())'))
|
||||||
|
->whereIn(DB::raw("extract(month from TO_DATE(economia.mes, 'YYMM'))"),
|
||||||
|
DB::table('economia')
|
||||||
|
->selectRaw(
|
||||||
|
"max(extract(month from TO_DATE(mes, 'YYMM')))"
|
||||||
|
)
|
||||||
|
->where('dad_estimado', '=', false)
|
||||||
|
->where(DB::raw("extract(year from TO_DATE(mes, 'YYMM'))"), '=', DB::raw('extract(year from NOW())'))
|
||||||
|
->whereIn(
|
||||||
|
'economia.cod_smart_unidade',
|
||||||
|
DB::table('dados_cadastrais')
|
||||||
|
->select('cod_smart_unidade')
|
||||||
|
->where('dados_cadastrais.codigo_scde', '!=', '0P')
|
||||||
|
->where('dados_cadastrais.cod_smart_cliente', '=', Auth::user()->client_id)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
->groupBy(['mes', 'ano', 'dad_estimado'])
|
||||||
|
->havingRaw("sum(custo_livre) > 0")
|
||||||
|
->orderBy(DB::raw("mes, ano, dad_estimado"))
|
||||||
->get();
|
->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +84,7 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt
|
|||||||
public function getGrossMonthlyEconomy($params)
|
public function getGrossMonthlyEconomy($params)
|
||||||
{
|
{
|
||||||
$field = [
|
$field = [
|
||||||
DB::raw("TO_DATE(economia.mes, 'YYMM') as mes"),
|
"economia.mes",
|
||||||
DB::raw("SUM(economia.economia_acumulada)/1000 as economia_acumulada"),
|
DB::raw("SUM(economia.economia_acumulada)/1000 as economia_acumulada"),
|
||||||
DB::raw("(SUM(economia.economia_mensal)/SUM(economia.custo_cativo)) as econ_percentual"),
|
DB::raw("(SUM(economia.economia_mensal)/SUM(economia.custo_cativo)) as econ_percentual"),
|
||||||
"economia.dad_estimado"
|
"economia.dad_estimado"
|
||||||
@ -75,9 +100,7 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt
|
|||||||
->havingRaw("sum(custo_livre) > 0")
|
->havingRaw("sum(custo_livre) > 0")
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
return collect($result)
|
return Helpers::orderByDate($result);
|
||||||
->transform(fn($value) => Arr::set($value, 'mes', date_format(date_create($value['mes']), "M/Y")))
|
|
||||||
->all();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +113,7 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt
|
|||||||
DB::raw("SUM(economia.custo_cativo)/1000 as custo_cativo"),
|
DB::raw("SUM(economia.custo_cativo)/1000 as custo_cativo"),
|
||||||
DB::raw("SUM(economia.custo_livre)/1000 as custo_livre"),
|
DB::raw("SUM(economia.custo_livre)/1000 as custo_livre"),
|
||||||
DB::raw("SUM(economia.economia_mensal)/1000 as economia_mensal"),
|
DB::raw("SUM(economia.economia_mensal)/1000 as economia_mensal"),
|
||||||
DB::raw("(SUM(economia_mensal)/SUM(custo_cativo)) as econ_percentual"),
|
DB::raw("(SUM(economia_mensal)/SUM(custo_livre)) as econ_percentual"),
|
||||||
"economia.dad_estimado"
|
"economia.dad_estimado"
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -115,7 +138,7 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt
|
|||||||
public function getCostMWhEconomy($params)
|
public function getCostMWhEconomy($params)
|
||||||
{
|
{
|
||||||
$field = [
|
$field = [
|
||||||
DB::raw("TO_DATE(economia.mes, 'YYMM') as mes"),
|
"economia.mes",
|
||||||
DB::raw("SUM(economia.custo_unit) as custo_unit"),
|
DB::raw("SUM(economia.custo_unit) as custo_unit"),
|
||||||
"economia.dad_estimado"
|
"economia.dad_estimado"
|
||||||
];
|
];
|
||||||
@ -131,9 +154,7 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt
|
|||||||
->orderBy(DB::raw("mes, dad_estimado"))
|
->orderBy(DB::raw("mes, dad_estimado"))
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
return collect(static::checkDate($result))
|
return Helpers::orderByDate($result);
|
||||||
->transform(fn($value) => Arr::set($value, 'mes', date_format(date_create($value['mes']), "M/Y")))
|
|
||||||
->all();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user