PLD api resume correction.
This commit is contained in:
parent
f112ab68cf
commit
3ff091ca12
@ -7,6 +7,8 @@ namespace App\Http\Controllers;
|
||||
use App\Http\Resources\EconomyResource;
|
||||
use App\Repositories\Economy\EconomyContractInterface;
|
||||
use App\Traits\ApiResponse;
|
||||
use DateInterval;
|
||||
use DatePeriod;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
@ -75,6 +77,11 @@ class EconomyController extends Controller
|
||||
{
|
||||
try {
|
||||
$response = $this->economyContract->getCostMWhEconomy($request->all());
|
||||
|
||||
$res = static::checkDate();
|
||||
|
||||
dd($res);
|
||||
|
||||
return (new EconomyResource($response))
|
||||
->response()
|
||||
->setStatusCode(Response::HTTP_OK);
|
||||
@ -83,5 +90,22 @@ class EconomyController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
public static function checkDate(){
|
||||
$start_date = date_create("2021-04-01");
|
||||
$end_date = date_create("2022-03-01"); // If you want to include this date, add 1 day
|
||||
|
||||
$interval = DateInterval::createFromDateString('1 months');
|
||||
$daterange = new DatePeriod($start_date, $interval ,$end_date);
|
||||
|
||||
$res = [];
|
||||
foreach($daterange as $date1){
|
||||
|
||||
if (!'02/2022' )
|
||||
|
||||
$res[] = $date1->format('m/Y');
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
||||
|
||||
// Carbon::now()->format('m/Y')
|
||||
return $this->execute($fields)
|
||||
->where( DB::raw("TO_CHAR(TO_DATE(pld.mes_ref, 'YYMM'), 'MM/YYYY')"), '=', '04/2022')
|
||||
->where(DB::raw("TO_CHAR(TO_DATE(pld.mes_ref, 'YYMM'), 'MM/YYYY')"), '=', '04/2022')
|
||||
->groupBy(['submarket', 'year_month', 'year_month_formatted'])
|
||||
->get();
|
||||
}
|
||||
@ -115,7 +115,14 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
||||
*/
|
||||
public function getConsumptionByDaily($params, $field = "mes_ref"): Collection|array
|
||||
{
|
||||
$fields = static::getRowField();
|
||||
$fields = [
|
||||
DB::raw("TO_CHAR((date('1899-12-30') + interval '1' day * pld.dia_num), 'DD') as day_formatted"),
|
||||
DB::raw("(date('1899-12-30') + interval '1' day * pld.dia_num) as day_calc"),
|
||||
'pld.submercado as submarket',
|
||||
DB::raw("SUM(pld.valor) as value"),
|
||||
DB::raw("TO_CHAR(TO_DATE(pld.mes_ref, 'YYMM'), 'MM/YYYY') as year_month"),
|
||||
DB::raw("TO_CHAR(TO_DATE(pld.mes_ref, 'YYMM'), 'MM/YYYY') as year_month_formatted"),
|
||||
];
|
||||
|
||||
$i = 0;
|
||||
foreach ($params['filters'] as $param) {
|
||||
@ -125,13 +132,23 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $this->execute($fields, $params)->get();
|
||||
return $this->execute($fields, $params)
|
||||
->groupBy('day_formatted', 'day_calc', 'submarket', 'year_month', 'year_month_formatted')
|
||||
->get();
|
||||
|
||||
}
|
||||
|
||||
public function getConsumptionBySchedule($params, $field = "dia_num"): Collection|array
|
||||
{
|
||||
$fields = static::getRowField();
|
||||
$fields = [
|
||||
DB::raw("TO_CHAR((date('1899-12-30') + interval '1' day * pld.dia_num), 'DD') as day_formatted"),
|
||||
'hora as hour',
|
||||
DB::raw("(date('1899-12-30') + interval '1' day * pld.dia_num) as day_calc"),
|
||||
'pld.submercado as submarket',
|
||||
DB::raw("SUM(pld.valor) as value"),
|
||||
DB::raw("TO_CHAR(TO_DATE(pld.mes_ref, 'YYMM'), 'MM/YYYY') as year_month"),
|
||||
DB::raw("TO_CHAR(TO_DATE(pld.mes_ref, 'YYMM'), 'MM/YYYY') as year_month_formatted"),
|
||||
];
|
||||
|
||||
$i = 0;
|
||||
foreach ($params['filters'] as $param) {
|
||||
@ -141,7 +158,9 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $this->execute($fields, $params)->get();
|
||||
return $this->execute($fields, $params)
|
||||
->groupBy('day_formatted', 'hour', 'day_calc', 'submarket', 'year_month', 'year_month_formatted')
|
||||
->get();
|
||||
}
|
||||
|
||||
protected static function getRowField(): array
|
||||
@ -151,6 +170,7 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
||||
'hora as hour',
|
||||
DB::raw("(date('1899-12-30') + interval '1' day * pld.dia_num) as day_calc"),
|
||||
'pld.submercado as submarket',
|
||||
DB::raw("SUM(pld.valor) as value"),
|
||||
DB::raw("TO_CHAR(TO_DATE(pld.mes_ref, 'YYMM'), 'MM/YYYY') as year_month"),
|
||||
DB::raw("TO_CHAR(TO_DATE(pld.mes_ref, 'YYMM'), 'MM/YYYY') as year_month_formatted"),
|
||||
];
|
||||
|
||||
@ -10,7 +10,7 @@ use Illuminate\Database\Eloquent\Builder;
|
||||
class FilterQueryBuilder extends EntityJson implements IFilterBuilder
|
||||
{
|
||||
|
||||
protected int $limit = 10;
|
||||
protected int $limit = 20;
|
||||
|
||||
protected int $offset = 0;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user