Implement endpoint to view a customer's unit listing.
This commit is contained in:
parent
3fa0440b31
commit
d1e3574501
@ -20,6 +20,18 @@ class OperationSummaryController extends Controller
|
||||
{
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
$response = $this->dadosTeContract->search($request->all(), true);
|
||||
return (new OperationSummaryResource($response))
|
||||
->response()
|
||||
->setStatusCode(Response::HTTP_OK);
|
||||
} catch (\Exception $ex) {
|
||||
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
public function operationSummary(Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
@ -10,5 +10,5 @@ interface ContractInterface
|
||||
public function update(array $params, $id);
|
||||
public function destroy($id);
|
||||
public function withRelationsByAll($relations);
|
||||
public function search($params);
|
||||
public function search($params, $distinct = false);
|
||||
}
|
||||
|
||||
@ -20,19 +20,9 @@ class DadosTeRepository extends AbstractRepository implements DadosTeContractInt
|
||||
parent::__construct($dadosTe);
|
||||
}
|
||||
|
||||
private function execute($params): Builder
|
||||
private function execute($fields, $params): Builder
|
||||
{
|
||||
$query = $this->model
|
||||
->select(
|
||||
DB::raw("TO_CHAR(TO_DATE(dados_te.mes, 'YYMM'), 'MM/YYYY') as mes"),
|
||||
'dados_te.cod_smart_unidade',
|
||||
'dados_te.operacao',
|
||||
'dados_te.tipo',
|
||||
'dados_te.perfil_contr as contraparte',
|
||||
'dados_te.montante_nf',
|
||||
'dados_te.preco_nf',
|
||||
'dados_te.nf_c_icms'
|
||||
);
|
||||
$query = $this->model->select($fields);
|
||||
|
||||
if (!empty($params)) {
|
||||
$query = static::getFilterBuilder($params)->applyFilter($query);
|
||||
@ -43,8 +33,19 @@ class DadosTeRepository extends AbstractRepository implements DadosTeContractInt
|
||||
|
||||
public function getOperationSummary($params): Collection|array
|
||||
{
|
||||
$fields = [
|
||||
DB::raw("TO_CHAR(TO_DATE(dados_te.mes, 'YYMM'), 'MM/YYYY') as mes"),
|
||||
'dados_te.cod_smart_unidade',
|
||||
'dados_te.operacao',
|
||||
'dados_te.tipo',
|
||||
'dados_te.perfil_contr as contraparte',
|
||||
'dados_te.montante_nf',
|
||||
'dados_te.preco_nf',
|
||||
'dados_te.nf_c_icms'
|
||||
];
|
||||
|
||||
$params = static::filterRow($params);
|
||||
return $this->execute($params)->get();
|
||||
return $this->execute($fields, $params)->get();
|
||||
}
|
||||
|
||||
public static function filterRow($params, $field = 'mes'): array
|
||||
|
||||
@ -38,12 +38,20 @@ trait MethodsTrait
|
||||
return $this->model->with($relations)->get();
|
||||
}
|
||||
|
||||
public function search($params)
|
||||
public function search($params, $distinct = false)
|
||||
{
|
||||
$filter = static::getFilterBuilder($params);
|
||||
|
||||
$filter->setFields(collect($filter->getFields())->transform(fn($value) => $this->model->qualifyColumn($value))->all());
|
||||
|
||||
$query = $this->model->select($filter->getFields());
|
||||
|
||||
return $filter->applyFilter($query)->get();
|
||||
$response = $filter->applyFilter($query);
|
||||
|
||||
if (isset($distinct)){
|
||||
$response = $response->distinct();
|
||||
}
|
||||
|
||||
return $response->get();
|
||||
}
|
||||
}
|
||||
@ -52,7 +52,8 @@ Route::middleware(['auth:sanctum', 'ability:Client'])->group(function () {
|
||||
Route::post('economy/estimates', [\App\Http\Controllers\EconomyController::class, 'captiveMonthlyEconomy']);
|
||||
Route::post('economy/MWh', [\App\Http\Controllers\EconomyController::class, 'costMWhEconomy']);
|
||||
|
||||
Route::post('operation', [\App\Http\Controllers\OperationSummaryController::class, 'operationSummary']);
|
||||
Route::post('operation/summary', [\App\Http\Controllers\OperationSummaryController::class, 'operationSummary']);
|
||||
Route::post('operation', [\App\Http\Controllers\OperationSummaryController::class, 'index']);
|
||||
});
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user