Implementation correction Cost indicator R$/MWh.
This commit is contained in:
parent
4e1eda8e91
commit
7b99cfbf7f
@ -34,7 +34,6 @@ class Helpers
|
|||||||
|
|
||||||
public static function checkDate($value): array
|
public static function checkDate($value): array
|
||||||
{
|
{
|
||||||
|
|
||||||
$year = collect($value)->transform(fn($item, $value) => collect(Str::of($item['mes'])
|
$year = collect($value)->transform(fn($item, $value) => collect(Str::of($item['mes'])
|
||||||
->explode('-')->offsetGet(0)))->unique()->toArray();
|
->explode('-')->offsetGet(0)))->unique()->toArray();
|
||||||
$month = collect($value)->transform(fn($item, $value) => collect(Str::of($item['mes'])
|
$month = collect($value)->transform(fn($item, $value) => collect(Str::of($item['mes'])
|
||||||
|
|||||||
@ -7,12 +7,10 @@ namespace App\Repositories\Economy;
|
|||||||
use App\Helpers\Helpers;
|
use App\Helpers\Helpers;
|
||||||
use App\Models\Economy;
|
use App\Models\Economy;
|
||||||
use App\Repositories\AbstractRepository;
|
use App\Repositories\AbstractRepository;
|
||||||
use Carbon\Carbon;
|
|
||||||
use DateInterval;
|
use DateInterval;
|
||||||
use DatePeriod;
|
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\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
@ -138,12 +136,12 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt
|
|||||||
public function getCostMWhEconomy($params)
|
public function getCostMWhEconomy($params)
|
||||||
{
|
{
|
||||||
$field = [
|
$field = [
|
||||||
"economia.mes",
|
DB::raw("TO_DATE(economia.mes, 'YYMM') as 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"
|
||||||
];
|
];
|
||||||
|
|
||||||
$result = $this->execute($params, $field)
|
$value = $this->execute($params, $field)
|
||||||
->whereBetween(
|
->whereBetween(
|
||||||
DB::raw("TO_DATE(economia.mes, 'YYMM')"),
|
DB::raw("TO_DATE(economia.mes, 'YYMM')"),
|
||||||
[
|
[
|
||||||
@ -154,48 +152,9 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt
|
|||||||
->orderBy(DB::raw("mes, dad_estimado"))
|
->orderBy(DB::raw("mes, dad_estimado"))
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
$result = Helpers::checkDate($value);
|
||||||
|
|
||||||
return Helpers::orderByDate($result);
|
return Helpers::orderByDate($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function checkDate($value): array
|
|
||||||
{
|
|
||||||
|
|
||||||
$year = collect($value)->transform(fn($item, $value) => collect(Str::of($item['mes'])
|
|
||||||
->explode('-')->offsetGet(0)))->unique()->toArray();
|
|
||||||
$month = collect($value)->transform(fn($item, $value) => collect(Str::of($item['mes'])
|
|
||||||
->explode('-')->offsetGet(1)))->unique()->toArray();
|
|
||||||
|
|
||||||
$month_stat = end($month);
|
|
||||||
$date_stat = current($year);
|
|
||||||
$date_end = end($year);
|
|
||||||
|
|
||||||
$start_date = date_create("{$date_stat[0]}-01-01");
|
|
||||||
$end_date = date_create("{$date_end[0]}-{$month_stat[0]}-30");
|
|
||||||
|
|
||||||
$interval = DateInterval::createFromDateString('1 months');
|
|
||||||
$daterange = new DatePeriod($start_date, $interval, $end_date);
|
|
||||||
|
|
||||||
$date = [];
|
|
||||||
foreach ($daterange as $date1) {
|
|
||||||
$date[] = $date1->format('Y-m' . '-01');
|
|
||||||
}
|
|
||||||
|
|
||||||
$arr = collect($value)->toArray();
|
|
||||||
|
|
||||||
foreach ($date as $dt) {
|
|
||||||
if (!in_array($dt, array_column($arr, 'mes'))) {
|
|
||||||
$arr[] = ['mes' => $dt];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
usort($arr, function ($a, $b, $i = 'mes') {
|
|
||||||
$t1 = strtotime($a[$i]);
|
|
||||||
$t2 = strtotime($b[$i]);
|
|
||||||
return $t1 - $t2;
|
|
||||||
});
|
|
||||||
|
|
||||||
return $arr;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user