85 lines
2.7 KiB
PHP
85 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Imunizacao;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Services\Imunizacao\CadastroCampanhaService;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
|
|
class CadastroCampanhaController extends Controller
|
|
{
|
|
protected $modulo = 'imunizacao';
|
|
protected $funcionalidade = 'cadastro-campanha';
|
|
|
|
public function index()
|
|
{
|
|
return response()->json(CadastroCampanhaService::index(), Response::HTTP_OK);
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
$this->auth(__FUNCTION__);
|
|
|
|
return response()->json(CadastroCampanhaService::create(), Response::HTTP_OK);
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$this->auth(__FUNCTION__);
|
|
|
|
return response()->json(CadastroCampanhaService::store($request), Response::HTTP_CREATED);
|
|
}
|
|
|
|
public function edit($id)
|
|
{
|
|
$this->auth(__FUNCTION__);
|
|
|
|
return response()->json(CadastroCampanhaService::edit($id), Response::HTTP_OK);
|
|
}
|
|
|
|
public function update(Request $request, $id)
|
|
{
|
|
$this->auth(__FUNCTION__);
|
|
|
|
return response()->json(CadastroCampanhaService::update($request, $id), Response::HTTP_OK);
|
|
}
|
|
|
|
public function destroy($id)
|
|
{
|
|
$this->auth(__FUNCTION__);
|
|
|
|
return response()->json(CadastroCampanhaService::destroy($id), Response::HTTP_NO_CONTENT);
|
|
}
|
|
|
|
public function datatable()
|
|
{
|
|
return datatables()
|
|
->of(CadastroCampanhaService::datatable())
|
|
->filterColumn('imunizacao_campanha.periodo_de', function ($query, $keyword) {
|
|
$query->whereRaw("DATE_FORMAT(imunizacao_campanha.periodo_de, '%d/%m/%Y') LIKE ?", ["%{$keyword}%"])
|
|
->orWhereRaw(
|
|
"CONCAT(
|
|
SUBSTR(imunizacao_campanha.periodo_de,9,2),
|
|
SUBSTR(imunizacao_campanha.periodo_de,6,2),
|
|
SUBSTR(imunizacao_campanha.periodo_de,1,4)
|
|
) like ?",
|
|
["%{$keyword}%"]
|
|
);
|
|
})
|
|
->filterColumn('imunizacao_campanha.periodo_ate', function ($query, $keyword) {
|
|
$query->whereRaw("DATE_FORMAT(imunizacao_campanha.periodo_ate, '%d/%m/%Y') LIKE ?", ["%{$keyword}%"])
|
|
->orWhereRaw(
|
|
"CONCAT(
|
|
SUBSTR(imunizacao_campanha.periodo_ate,9,2),
|
|
SUBSTR(imunizacao_campanha.periodo_ate,6,2),
|
|
SUBSTR(imunizacao_campanha.periodo_ate,1,4)
|
|
) like ?",
|
|
["%{$keyword}%"]
|
|
);
|
|
})
|
|
->skipTotalRecords()
|
|
->make(true);
|
|
}
|
|
}
|