Carga inicial
This commit is contained in:
467
app/Http/Controllers/Administrador/ClientesController.php
Normal file
467
app/Http/Controllers/Administrador/ClientesController.php
Normal file
@@ -0,0 +1,467 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Administrador;
|
||||
|
||||
use App\Components\AdjustImage;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use const App\Http\Controllers\ATENCION_CLIENTES;
|
||||
use App\Http\Requests\Administrador\ClientesDomiciliosRequest;
|
||||
use App\Http\Requests\Administrador\ClientesRequest;
|
||||
use App\Models\Cliente;
|
||||
use App\Models\ClienteDatoFiscal;
|
||||
use App\Models\ClienteDomicilio;
|
||||
use App\Models\FacturaFormaPago;
|
||||
use App\Models\FacturaMetodoPago;
|
||||
use App\Models\FacturaTipoComprobante;
|
||||
use App\Models\FacturaUsoCFDI;
|
||||
use App\Models\Sucursal;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Log;
|
||||
|
||||
class ClientesController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$deleted = $request->input('deleted');
|
||||
$orderBy = $request->input('sortBy','users.nombre');
|
||||
$order = $request->input('order','asc');
|
||||
$queryBuilder = Cliente::select('clientes.*', 'users.nombre as asesor_nombre', 'users.apellido_paterno as asesor_apellido_paterno', 'users.apellido_materno as asesor_apellido_materno', 'sucursales.nombre as sucursal_nombre')
|
||||
->join('users', 'users.id', '=', 'clientes.asesor_id')
|
||||
->join('sucursales', 'sucursales.id', '=', 'clientes.sucursal_id')
|
||||
->where('clientes.sucursal_id', $user->sucursal_id)
|
||||
->orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('clientes.denominacion','like','%' .$query.'%')
|
||||
->orWhere('sucursales.nombre','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($deleted) {
|
||||
$queryBuilder->onlyTrashed();
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$clientes = $queryBuilder->paginate($perPage);
|
||||
}else{
|
||||
$clientes = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
return response()->success($clientes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(ClientesRequest $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$cliente = Cliente::create($data);
|
||||
|
||||
if($data['requiere_factura']){
|
||||
$cliente->registroDatosFiscales()->create($data['datos_fiscales']);
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->success($cliente);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::info($e->getMessage());
|
||||
return response()->unprocessable('Error', ['Error al guardar el Cliente.']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$cliente = Cliente::select('clientes.*', 'users.nombre as asesor_nombre', 'users.apellido_paterno as asesor_apellido_paterno', 'users.apellido_materno as asesor_apellido_materno', 'sucursales.nombre as sucursal_nombre')
|
||||
->join('users', 'users.id', '=', 'clientes.asesor_id')
|
||||
->join('sucursales', 'sucursales.id', '=', 'clientes.sucursal_id')
|
||||
->where('clientes.id', $id)
|
||||
->withTrashed()
|
||||
->first();
|
||||
|
||||
$cliente->datos_fiscales = ClienteDatoFiscal::where('cliente_id', $id)->first();
|
||||
|
||||
return response()->success($cliente);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(ClientesRequest $request, $id)
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$cliente = Cliente::where('id',$id)
|
||||
->withTrashed()
|
||||
->firstOrFail();
|
||||
|
||||
$cliente->update($data);
|
||||
|
||||
if($data['requiere_factura']){
|
||||
$cliente->registroDatosFiscales()->update($data['datos_fiscales']);
|
||||
}else{
|
||||
$cliente->registroDatosFiscales()->delete();
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->success($cliente);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::info($e->getMessage());
|
||||
return response()->unprocessable('Error', ['Error al actualizar el Cliente.']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id, Request $request)
|
||||
{
|
||||
$deleted = $request->input('deleted');
|
||||
|
||||
if($deleted){
|
||||
$cliente = Cliente::where('id',$id)
|
||||
->onlyTrashed()
|
||||
->first();
|
||||
|
||||
$cliente->restore();
|
||||
}else{
|
||||
$cliente = Cliente::findOrFail($id);
|
||||
$cliente->delete();
|
||||
}
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
public function indexDomiciliosXCliente(Request $request, $id)
|
||||
{
|
||||
|
||||
$orderBy = $request->input('sortBy','nombre_sucursal');
|
||||
$order = $request->input('order','asc');
|
||||
|
||||
$queryBuilder = ClienteDomicilio::where('cliente_id', $id)
|
||||
->orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('nombre_sucursal','like','%' .$query.'%')
|
||||
->orWhere('calle','like','%' .$query.'%')
|
||||
->orWhere('entre_calles','like','%' .$query.'%')
|
||||
->orWhere('num_ext','like','%' .$query.'%')
|
||||
->orWhere('colonia','like','%' .$query.'%')
|
||||
->orWhere('ciudad','like','%' .$query.'%')
|
||||
->orWhere('cp','like','%' .$query.'%')
|
||||
->orWhere('telefono','like','%' .$query.'%')
|
||||
->orWhere('celular_responsable','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
$cliente = Cliente::where('id', $id)->first();
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$data = collect($queryBuilder->paginate($perPage))->put('cliente_denominacion', $cliente->denominacion)->all();
|
||||
}else{
|
||||
$data = ['data'=>$queryBuilder->get(), 'cliente_denominacion' => $cliente->denominacion];
|
||||
}
|
||||
|
||||
return response()->success($data);
|
||||
}
|
||||
|
||||
public function showDomicilioXCliente($cliente_id, $id)
|
||||
{
|
||||
$domicilio = ClienteDomicilio::where('cliente_id', $cliente_id)
|
||||
->where('id', $id)
|
||||
->firstOrFail();
|
||||
|
||||
return response()->success($domicilio);
|
||||
}
|
||||
|
||||
public function updateDomicilioXCliente(ClientesDomiciliosRequest $request, $cliente_id, $id)
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
$nombre_croquis_pdf = null;
|
||||
$croquis_pdf = substr($request->input('nombre_croquis', false), strpos($request->input('nombre_croquis', false), ',') +1);
|
||||
|
||||
if ($croquis_pdf) {
|
||||
$nombre_croquis_pdf = 'croquis_cliente_' . $cliente_id . '_domicilio_' . $id . '.pdf';
|
||||
Storage::disk('public')->put('pdf_croquis/' . $nombre_croquis_pdf, base64_decode($croquis_pdf));
|
||||
}
|
||||
|
||||
$validator = Validator::make($data, [
|
||||
'nombre_sucursal' => [
|
||||
Rule::unique('clientes_domicilios')->where(function ($query) use($cliente_id, $id) {
|
||||
$query->where('cliente_id', $cliente_id)
|
||||
->where('id', '<>',$id);
|
||||
})
|
||||
],
|
||||
'numero_sucursal' => [
|
||||
Rule::unique('clientes_domicilios')->where(function ($query) use($cliente_id, $id) {
|
||||
$query->where('cliente_id', $cliente_id)
|
||||
->where('id', '<>',$id);
|
||||
})
|
||||
]
|
||||
]);
|
||||
|
||||
if($validator->fails()){
|
||||
return response()->unprocessable('Parametros inválidos',$validator->errors()->all());
|
||||
}
|
||||
|
||||
$domicilio = ClienteDomicilio::where('cliente_id', $cliente_id)
|
||||
->where('id', $id)
|
||||
->firstOrFail();
|
||||
|
||||
$data['nombre_croquis'] = $nombre_croquis_pdf;
|
||||
|
||||
$domicilio->update($data);
|
||||
|
||||
return response()->success($domicilio);
|
||||
}
|
||||
|
||||
public function storeDomicilioXCliente(ClientesDomiciliosRequest $request, $cliente_id)
|
||||
{
|
||||
$data = $request->all();
|
||||
$nombre_croquis_pdf = null;
|
||||
|
||||
$validator = Validator::make($data, [
|
||||
'nombre_sucursal' => [
|
||||
Rule::unique('clientes_domicilios')->where(function ($query) use($cliente_id) {
|
||||
$query->where('cliente_id', $cliente_id);
|
||||
})
|
||||
],
|
||||
'numero_sucursal' => [
|
||||
Rule::unique('clientes_domicilios')->where(function ($query) use($cliente_id) {
|
||||
$query->where('cliente_id', $cliente_id);
|
||||
})
|
||||
]
|
||||
]);
|
||||
|
||||
if($validator->fails()){
|
||||
return response()->unprocessable('Parametros inválidos',$validator->errors()->all());
|
||||
}
|
||||
|
||||
$cliente = Cliente::where('id', $cliente_id)->firstOrFail();
|
||||
|
||||
//Se agregan valores por default de lat y lng
|
||||
$lat = $request->input('lat', null);
|
||||
$lng = $request->input('lng', null);
|
||||
$data['lat'] = ($lat)? $lat : '24.772795';
|
||||
$data['lng'] = ($lng)? $lng : '-107.4432';
|
||||
|
||||
$domicilio = $cliente->registroDomicilios()->create($data);
|
||||
|
||||
$croquis_pdf = substr($request->input('nombre_croquis', false), strpos($request->input('nombre_croquis', false), ',') +1);
|
||||
|
||||
if ($croquis_pdf) {
|
||||
$nombre_croquis_pdf = 'croquis_cliente_' . $cliente_id .'_domicilio_' .$domicilio->id .'.pdf';
|
||||
Storage::disk('public')->put('pdf_croquis/' . $nombre_croquis_pdf, base64_decode($croquis_pdf));
|
||||
}
|
||||
|
||||
$domicilio->update([
|
||||
'nombre_croquis' => $nombre_croquis_pdf
|
||||
]);
|
||||
|
||||
return response()->success($domicilio);
|
||||
}
|
||||
|
||||
public function destroyDomicilioXCliente($cliente_id, $id){
|
||||
|
||||
ClienteDomicilio::where('id', $id)
|
||||
->where('cliente_id', $cliente_id)
|
||||
->delete();
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
public function asesores(Request $request){
|
||||
|
||||
$orderBy = $request->input('sortBy','nombre');
|
||||
$order = $request->input('order','asc');
|
||||
|
||||
$queryBuilder = User::select('users.*', DB::raw("coalesce (roles.name, '') as role"), 'roles.id as role_id', 'tipos_empleados.nombre as tipo_empleado', 'tipos_empleados.id as tipo_empleado_id', 'sucursales.id as sucursal_id', 'sucursales.nombre as sucursal')
|
||||
->orderBy($orderBy,$order)
|
||||
->leftJoin('role_users', 'role_users.user_id', '=', 'users.id')
|
||||
->leftJoin('roles', 'roles.id', '=', 'role_users.role_id')
|
||||
->join('sucursales', 'sucursales.id', '=', 'users.sucursal_id')
|
||||
->join('tipos_empleados', 'tipos_empleados.id', '=', 'users.tipo_empleado_id')
|
||||
->where('users.tipo_empleado_id', ATENCION_CLIENTES);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('users.email','like','%' .$query.'%')
|
||||
->orWhere('users.nombre','like','%' .$query.'%')
|
||||
->orWhere('users.apellido_paterno','like','%' .$query.'%')
|
||||
->orWhere('users.apellido_materno','like','%' .$query.'%')
|
||||
->orWhere('users.telefono','like','%' .$query.'%')
|
||||
->orWhere('roles.name','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$data = $queryBuilder->paginate($perPage);
|
||||
}else{
|
||||
$data = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
return response()->success($data);
|
||||
}
|
||||
|
||||
public function formasPago(Request $request){
|
||||
|
||||
$orderBy = $request->input('sortBy','descripcion');
|
||||
$order = $request->input('order','asc');
|
||||
|
||||
$queryBuilder = FacturaFormaPago::orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('descripcion','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$data = $queryBuilder->paginate($perPage);
|
||||
}else{
|
||||
$data = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
return response()->success($data);
|
||||
}
|
||||
|
||||
public function metodosPago(Request $request){
|
||||
|
||||
$orderBy = $request->input('sortBy','descripcion');
|
||||
$order = $request->input('order','asc');
|
||||
|
||||
$queryBuilder = FacturaMetodoPago::orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('descripcion','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$data = $queryBuilder->paginate($perPage);
|
||||
}else{
|
||||
$data = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
return response()->success($data);
|
||||
}
|
||||
|
||||
public function tipoComprobante(Request $request){
|
||||
|
||||
$orderBy = $request->input('sortBy','descripcion');
|
||||
$order = $request->input('order','asc');
|
||||
|
||||
$queryBuilder = FacturaTipoComprobante::orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('descripcion','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$data = $queryBuilder->paginate($perPage);
|
||||
}else{
|
||||
$data = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
return response()->success($data);
|
||||
}
|
||||
|
||||
public function usoCFDI(Request $request){
|
||||
|
||||
$orderBy = $request->input('sortBy','descripcion');
|
||||
$order = $request->input('order','asc');
|
||||
|
||||
$queryBuilder = FacturaUsoCFDI::orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('descripcion','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$data = $queryBuilder->paginate($perPage);
|
||||
}else{
|
||||
$data = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
return response()->success($data);
|
||||
}
|
||||
|
||||
public function sucursales(Request $request){
|
||||
|
||||
$orderBy = $request->input('sortBy','nombre');
|
||||
$order = $request->input('order','asc');
|
||||
|
||||
$queryBuilder = Sucursal::orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('nombre','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$data = $queryBuilder->paginate($perPage);
|
||||
}else{
|
||||
$data = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
return response()->success($data);
|
||||
}
|
||||
|
||||
public function mostrarPDF($domicilio_id){
|
||||
|
||||
$domicilio = ClienteDomicilio::select('nombre_croquis')->where('id', $domicilio_id)->firstOrFail();
|
||||
|
||||
if($domicilio->nombre_croquis && Storage::disk('public')->exists("pdf_croquis/". $domicilio->nombre_croquis)) {
|
||||
return response()->file(storage_path('app/public/pdf_croquis/' . $domicilio->nombre_croquis));
|
||||
}else{
|
||||
return response()->unprocessable('El domicilio del cliente no tiene asignado PDF. Favor de adjuntarlo.');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Administrador;
|
||||
|
||||
use App\Http\Requests\Administrador\EstatusServiciosRequest;
|
||||
use App\Models\CatEstatuServicio;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class EstatusServiciosController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$deleted = $request->input('deleted');
|
||||
$orderBy = $request->input('sortBy','nombre');
|
||||
$order = $request->input('order','asc');
|
||||
$queryBuilder = CatEstatuServicio::orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('nombre','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($deleted) {
|
||||
$queryBuilder->onlyTrashed();
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$estatus = $queryBuilder->paginate($perPage);
|
||||
}else{
|
||||
$estatus = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
return response()->success($estatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(EstatusServiciosRequest $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
try {
|
||||
$estatus = CatEstatuServicio::create($data);
|
||||
|
||||
return response()->success($estatus);
|
||||
} catch (\Exception $e) {
|
||||
return response()->unprocessable('Error', ['Error al guardar el Estatus de Servicio.']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$estatus = CatEstatuServicio::where('id', $id)
|
||||
->withTrashed()
|
||||
->firstOrFail();
|
||||
|
||||
return response()->success($estatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(EstatusServiciosRequest $request, $id)
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
try {
|
||||
$estatus = CatEstatuServicio::where('id',$id)
|
||||
->withTrashed()
|
||||
->firstOrFail();
|
||||
|
||||
$estatus->update($data);
|
||||
|
||||
return response()->success($estatus);
|
||||
} catch (\Exception $e) {
|
||||
return response()->unprocessable('Error', ['Error al actualizar el Estatus de Servicio.']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id, Request $request)
|
||||
{
|
||||
$deleted = $request->input('deleted');
|
||||
|
||||
if($deleted){
|
||||
$estatus = CatEstatuServicio::where('id',$id)
|
||||
->onlyTrashed()
|
||||
->first();
|
||||
|
||||
$estatus->restore();
|
||||
}else{
|
||||
$estatus = CatEstatuServicio::findOrFail($id);
|
||||
$estatus->delete();
|
||||
}
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
}
|
||||
123
app/Http/Controllers/Administrador/FormasPagosController.php
Normal file
123
app/Http/Controllers/Administrador/FormasPagosController.php
Normal file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers\Administrador;
|
||||
|
||||
use App\Http\Requests\Administrador\FormasPagosRequest;
|
||||
use App\Models\CatFormaPago;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class FormasPagosController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$deleted = $request->input('deleted');
|
||||
$orderBy = $request->input('sortBy','nombre');
|
||||
$order = $request->input('order','asc');
|
||||
$queryBuilder = CatFormaPago::orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('nombre','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($deleted) {
|
||||
$queryBuilder->onlyTrashed();
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$forma_pago = $queryBuilder->paginate($perPage);
|
||||
}else{
|
||||
$forma_pago = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
return response()->success($forma_pago);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(FormasPagosRequest $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
try {
|
||||
$forma_pago = CatFormaPago::create($data);
|
||||
|
||||
return response()->success($forma_pago);
|
||||
} catch (\Exception $e) {
|
||||
return response()->unprocessable('Error', ['Error al guardar el Estatus de Servicio.']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$forma_pago = CatFormaPago::where('id', $id)
|
||||
->withTrashed()
|
||||
->firstOrFail();
|
||||
|
||||
return response()->success($forma_pago);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(FormasPagosRequest $request, $id)
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
try {
|
||||
$forma_pago = CatFormaPago::where('id',$id)
|
||||
->withTrashed()
|
||||
->firstOrFail();
|
||||
|
||||
$forma_pago->update($data);
|
||||
|
||||
return response()->success($forma_pago);
|
||||
} catch (\Exception $e) {
|
||||
return response()->unprocessable('Error', ['Error al actualizar el Estatus de Servicio.']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id, Request $request)
|
||||
{
|
||||
$deleted = $request->input('deleted');
|
||||
|
||||
if($deleted){
|
||||
$forma_pago = CatFormaPago::where('id',$id)
|
||||
->onlyTrashed()
|
||||
->first();
|
||||
|
||||
$forma_pago->restore();
|
||||
}else{
|
||||
$forma_pago = CatFormaPago::findOrFail($id);
|
||||
$forma_pago->delete();
|
||||
}
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
}
|
||||
103
app/Http/Controllers/Administrador/OrigenesController.php
Normal file
103
app/Http/Controllers/Administrador/OrigenesController.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Administrador;
|
||||
|
||||
use App\Models\CatOrigen;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class OrigenesController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$orderBy = $request->input('sortBy','nombre');
|
||||
$order = $request->input('order','asc');
|
||||
|
||||
$queryBuilder = CatOrigen::orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('nombre','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$data = $queryBuilder->paginate($perPage);
|
||||
}else{
|
||||
$data = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
return response()->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
175
app/Http/Controllers/Administrador/RolesController.php
Normal file
175
app/Http/Controllers/Administrador/RolesController.php
Normal file
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Administrador;
|
||||
|
||||
|
||||
use App\Http\Requests\Administrador\RolesRequest;
|
||||
use App\Models\Rol;
|
||||
use Cartalyst\Sentinel\Native\Facades\Sentinel;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Log;
|
||||
|
||||
class RolesController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$orderBy = $request->input('sortBy','name');
|
||||
$order = $request->input('order','asc');
|
||||
$queryBuilder = Rol::orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('name','like','%' .$query.'%')
|
||||
->orWhere('slug','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$users = $queryBuilder->paginate($perPage);
|
||||
}else{
|
||||
$users = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
return response()->success($users);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(RolesRequest $request)
|
||||
{
|
||||
$data = $request->only([
|
||||
'slug',
|
||||
'name',
|
||||
'movil',
|
||||
'web'
|
||||
]);
|
||||
$existe = Rol::where('slug','=',$data['slug'])
|
||||
->where('name','=',$data['name'])
|
||||
->first();
|
||||
|
||||
if($existe){
|
||||
return response()->unprocessable('Error', ['El rol ya se encuentra registrado']);
|
||||
}
|
||||
|
||||
$rol = Rol::create($data);
|
||||
|
||||
$role = Sentinel::findRoleById($rol->id);
|
||||
|
||||
foreach ($request->input('permissions') as $key => $value){
|
||||
$role->addPermission($key, ($value == "true")? true : false);
|
||||
$role->save();
|
||||
}
|
||||
|
||||
return response()->success($rol);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$role = Sentinel::findRoleById($id);
|
||||
|
||||
$routeCollection = Route::getRoutes();
|
||||
foreach ($routeCollection as $value) {
|
||||
$collection[] = ['name'=>$value->getName()];
|
||||
}
|
||||
$collection = collect($collection);
|
||||
$sorted = $collection->sortBy('name');
|
||||
$sorted->values()->all();
|
||||
|
||||
$permisos = [];
|
||||
foreach ($sorted as $value) {
|
||||
if($value['name']!=''){
|
||||
$permisos[$value['name']] = false;
|
||||
}
|
||||
}
|
||||
|
||||
$role['permissions'] = collect($permisos)
|
||||
->merge($role['permissions'])
|
||||
->all();
|
||||
//Log::info("roles show");
|
||||
//Log::info($role);
|
||||
return response()->success($role);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(RolesRequest $request, $id)
|
||||
{
|
||||
$rol = Rol::findOrFail($id);
|
||||
|
||||
$data = $request->only(['slug','name','permissions','movil','web']);
|
||||
|
||||
$role = Sentinel::findRoleById($id);
|
||||
|
||||
foreach ($data['permissions'] as $key => $value){
|
||||
$role->updatePermission($key, ($value == "true")? true : false);
|
||||
$role->addPermission($key, ($value == "true")? true : false);
|
||||
$role->save();
|
||||
}
|
||||
|
||||
$rol->slug = $data['slug'];
|
||||
$rol->name = $data['name'];
|
||||
$rol->movil = $data['movil'];
|
||||
$rol->web = $data['web'];
|
||||
$rol->save();
|
||||
|
||||
return response()->success($rol);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$rol = Rol::findOrFail($id);
|
||||
$rol->delete();
|
||||
|
||||
return response()->success(['result'=>true]);
|
||||
}
|
||||
|
||||
public function rutas(){
|
||||
|
||||
$routeCollection = Route::getRoutes();
|
||||
foreach ($routeCollection as $value) {
|
||||
$collection[] = ['name'=>$value->getName()];
|
||||
}
|
||||
$collection = collect($collection);
|
||||
$sorted = $collection->values()->all();
|
||||
|
||||
$permisos = [];
|
||||
foreach ($sorted as $value) {
|
||||
if($value['name']!=''){
|
||||
$permisos[$value['name']] = false;
|
||||
}
|
||||
}
|
||||
|
||||
return response()->success($permisos);
|
||||
}
|
||||
}
|
||||
124
app/Http/Controllers/Administrador/ServiciosController.php
Normal file
124
app/Http/Controllers/Administrador/ServiciosController.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Administrador;
|
||||
|
||||
use App\Http\Requests\Administrador\ServiciosRequest;
|
||||
use App\Models\CatServicio;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class ServiciosController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$deleted = $request->input('deleted');
|
||||
$orderBy = $request->input('sortBy','nombre');
|
||||
$order = $request->input('order','asc');
|
||||
$queryBuilder = CatServicio::orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('nombre','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($deleted) {
|
||||
$queryBuilder->onlyTrashed();
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$servicios = $queryBuilder->paginate($perPage);
|
||||
}else{
|
||||
$servicios = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
return response()->success($servicios);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(ServiciosRequest $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
try {
|
||||
$servicios = CatServicio::create($data);
|
||||
|
||||
return response()->success($servicios);
|
||||
} catch (\Exception $e) {
|
||||
return response()->unprocessable('Error', ['Error al guardar el Estatus de Servicio.']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$servicios = CatServicio::where('id', $id)
|
||||
->withTrashed()
|
||||
->firstOrFail();
|
||||
|
||||
return response()->success($servicios);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(ServiciosRequest $request, $id)
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
try {
|
||||
$servicios = CatServicio::where('id',$id)
|
||||
->withTrashed()
|
||||
->firstOrFail();
|
||||
|
||||
$servicios->update($data);
|
||||
|
||||
return response()->success($servicios);
|
||||
} catch (\Exception $e) {
|
||||
return response()->unprocessable('Error', ['Error al actualizar el Estatus de Servicio.']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id, Request $request)
|
||||
{
|
||||
$deleted = $request->input('deleted');
|
||||
|
||||
if($deleted){
|
||||
$servicios = CatServicio::where('id',$id)
|
||||
->onlyTrashed()
|
||||
->first();
|
||||
|
||||
$servicios->restore();
|
||||
}else{
|
||||
$servicios = CatServicio::findOrFail($id);
|
||||
$servicios->delete();
|
||||
}
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
}
|
||||
127
app/Http/Controllers/Administrador/SucursalesController.php
Normal file
127
app/Http/Controllers/Administrador/SucursalesController.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Administrador;
|
||||
|
||||
use App\Http\Requests\Administrador\SucursalesRequest;
|
||||
use App\Models\Sucursal;
|
||||
use App\Models\VehiculoSucursal;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class SucursalesController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$deleted = $request->input('deleted');
|
||||
$orderBy = $request->input('sortBy','nombre');
|
||||
$order = $request->input('order','asc');
|
||||
$queryBuilder = Sucursal::orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('nombre','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($deleted) {
|
||||
$queryBuilder->onlyTrashed();
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$sucursal = $queryBuilder->paginate($perPage);
|
||||
}else{
|
||||
$sucursal = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
return response()->success($sucursal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(SucursalesRequest $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
try {
|
||||
$sucursal = Sucursal::create($data);
|
||||
|
||||
return response()->success($sucursal);
|
||||
} catch (\Exception $e) {
|
||||
return response()->unprocessable('Error', ['Error al guardar la sucursal.']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$sucursal = Sucursal::where('id', $id)
|
||||
->withTrashed()
|
||||
->firstOrFail();
|
||||
|
||||
return response()->success($sucursal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(SucursalesRequest $request, $id)
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
try {
|
||||
$sucursal = Sucursal::where('id',$id)
|
||||
->withTrashed()
|
||||
->firstOrFail();
|
||||
|
||||
$sucursal->update($data);
|
||||
|
||||
return response()->success($sucursal);
|
||||
} catch (\Exception $e) {
|
||||
return response()->unprocessable('Error', ['Error al actualizar la sucursal.']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id, Request $request)
|
||||
{
|
||||
$deleted = $request->input('deleted');
|
||||
|
||||
if($deleted){
|
||||
$sucursal = Sucursal::where('id',$id)
|
||||
->onlyTrashed()
|
||||
->first();
|
||||
|
||||
$sucursal->restore();
|
||||
}else{
|
||||
$sucursal = Sucursal::findOrFail($id);
|
||||
$sucursal->delete();
|
||||
|
||||
VehiculoSucursal::where('sucursal_id', $id)->delete();
|
||||
}
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
}
|
||||
124
app/Http/Controllers/Administrador/TiposServiciosController.php
Normal file
124
app/Http/Controllers/Administrador/TiposServiciosController.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Administrador;
|
||||
|
||||
use App\Http\Requests\Administrador\TiposServiciosRequest;
|
||||
use App\Models\CatTipoServicio;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class TiposServiciosController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$deleted = $request->input('deleted');
|
||||
$orderBy = $request->input('sortBy','nombre');
|
||||
$order = $request->input('order','asc');
|
||||
$queryBuilder = CatTipoServicio::orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('nombre','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($deleted) {
|
||||
$queryBuilder->onlyTrashed();
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$tipos_servicios = $queryBuilder->paginate($perPage);
|
||||
}else{
|
||||
$tipos_servicios = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
return response()->success($tipos_servicios);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(TiposServiciosRequest $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
try {
|
||||
$tipos_servicios = CatTipoServicio::create($data);
|
||||
|
||||
return response()->success($tipos_servicios);
|
||||
} catch (\Exception $e) {
|
||||
return response()->unprocessable('Error', ['Error al guardar el Estatus de Servicio.']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$tipos_servicios = CatTipoServicio::where('id', $id)
|
||||
->withTrashed()
|
||||
->firstOrFail();
|
||||
|
||||
return response()->success($tipos_servicios);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(TiposServiciosRequest $request, $id)
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
try {
|
||||
$tipos_servicios = CatTipoServicio::where('id',$id)
|
||||
->withTrashed()
|
||||
->firstOrFail();
|
||||
|
||||
$tipos_servicios->update($data);
|
||||
|
||||
return response()->success($tipos_servicios);
|
||||
} catch (\Exception $e) {
|
||||
return response()->unprocessable('Error', ['Error al actualizar el Estatus de Servicio.']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id, Request $request)
|
||||
{
|
||||
$deleted = $request->input('deleted');
|
||||
|
||||
if($deleted){
|
||||
$tipos_servicios = CatTipoServicio::where('id',$id)
|
||||
->onlyTrashed()
|
||||
->first();
|
||||
|
||||
$tipos_servicios->restore();
|
||||
}else{
|
||||
$tipos_servicios = CatTipoServicio::findOrFail($id);
|
||||
$tipos_servicios->delete();
|
||||
}
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
}
|
||||
111
app/Http/Controllers/Administrador/TiposVehiculosController.php
Normal file
111
app/Http/Controllers/Administrador/TiposVehiculosController.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers\Administrador;
|
||||
|
||||
use App\Http\Requests\Administrador\TiposVehiculosRequest;
|
||||
use App\Models\TipoVehiculo;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class TiposVehiculosController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$deleted = $request->input('deleted');
|
||||
$orderBy = $request->input('sortBy','nombre');
|
||||
$order = $request->input('order','asc');
|
||||
$queryBuilder = TipoVehiculo::orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('nombre','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($deleted) {
|
||||
$queryBuilder->onlyTrashed();
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$tipo_vehiculo = $queryBuilder->paginate($perPage);
|
||||
}else{
|
||||
$tipo_vehiculo = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
return response()->success($tipo_vehiculo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(TiposVehiculosRequest $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
try {
|
||||
$tipo_vehiculo = TipoVehiculo::create($data);
|
||||
|
||||
return response()->success($tipo_vehiculo);
|
||||
} catch (\Exception $e) {
|
||||
Log::info($e->getMessage());
|
||||
return response()->unprocessable('Error', ['Error al guardar el Tipo de Vehiculo.']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$tipo_vehiculo = TipoVehiculo::where('id', $id)
|
||||
->withTrashed()
|
||||
->firstOrFail();
|
||||
|
||||
return response()->success($tipo_vehiculo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(TiposVehiculosRequest $request, $id)
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
try {
|
||||
$tipo_vehiculo = TipoVehiculo::where('id',$id)
|
||||
->withTrashed()
|
||||
->firstOrFail();
|
||||
|
||||
$tipo_vehiculo->update($data);
|
||||
|
||||
return response()->success($tipo_vehiculo);
|
||||
} catch (\Exception $e) {
|
||||
return response()->unprocessable('Error', ['Error al guardar el Tipo de Vehiculo.']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
216
app/Http/Controllers/Administrador/UsersController.php
Normal file
216
app/Http/Controllers/Administrador/UsersController.php
Normal file
@@ -0,0 +1,216 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Administrador;
|
||||
|
||||
use App\Models\Rol;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use const App\Http\Controllers\PASSWORD;
|
||||
use App\Http\Requests\Administrador\UserRequest;
|
||||
use App\Models\RolUser;
|
||||
use App\Models\Sucursal;
|
||||
use App\Models\TipoEmpleado;
|
||||
use App\Models\User;
|
||||
use Cartalyst\Sentinel\Native\Facades\Sentinel;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Log;
|
||||
|
||||
class UsersController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
$deleted = $request->input('deleted');
|
||||
$orderBy = $request->input('sortBy','users.nombre');
|
||||
$order = $request->input('order','asc');
|
||||
$queryBuilder = User::select('users.*', DB::raw("coalesce (roles.name, '') as role"), 'roles.id as role_id', 'tipos_empleados.nombre as tipo_empleado', 'tipos_empleados.id as tipo_empleado_id', 'sucursales.id as sucursal_id', 'sucursales.nombre as sucursal')
|
||||
->orderBy($orderBy,$order)
|
||||
->leftJoin('role_users', 'role_users.user_id', '=', 'users.id')
|
||||
->leftJoin('roles', 'roles.id', '=', 'role_users.role_id')
|
||||
->join('sucursales', 'sucursales.id', '=', 'users.sucursal_id')
|
||||
->join('tipos_empleados', 'tipos_empleados.id', '=', 'users.tipo_empleado_id')
|
||||
->where('users.sucursal_id', $user->sucursal_id);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('users.email','like','%' .$query.'%')
|
||||
->orWhere('users.nombre','like','%' .$query.'%')
|
||||
->orWhere('users.apellido_paterno','like','%' .$query.'%')
|
||||
->orWhere('users.apellido_materno','like','%' .$query.'%')
|
||||
->orWhere('users.telefono','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($deleted) {
|
||||
$queryBuilder->onlyTrashed();
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$users = $queryBuilder->paginate($perPage);
|
||||
}else{
|
||||
$users = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
return response()->success($users);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(UserRequest $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
|
||||
$tipo = TipoEmpleado::where('id', $data['tipo_empleado_id'])->first();
|
||||
if($tipo->login){
|
||||
$data['password'] = bcrypt($data['password']);
|
||||
}else{
|
||||
$data['password'] = bcrypt(PASSWORD);
|
||||
}
|
||||
|
||||
$user = User::create($data);
|
||||
|
||||
$user_sentinel = Sentinel::findById($user->id);
|
||||
$role = Sentinel::findRoleById($data['role_id']);
|
||||
$role->users()->attach($user_sentinel);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->success($user);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return response()->unprocessable('Error', ['Error al guardar el usuario.']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$user = User::select('users.*', 'roles.name as role', 'roles.id as role_id', 'tipos_empleados.nombre as tipo_empleado', 'tipos_empleados.id as tipo_empleado_id', 'sucursales.id as sucursal_id', 'sucursales.nombre as sucursal')
|
||||
->leftJoin('role_users', 'role_users.user_id', '=', 'users.id')
|
||||
->leftJoin('roles', 'roles.id', '=', 'role_users.role_id')
|
||||
->join('tipos_empleados', 'tipos_empleados.id', '=', 'users.tipo_empleado_id')
|
||||
->join('sucursales', 'sucursales.id', '=', 'users.sucursal_id')
|
||||
->where('users.id', $id)
|
||||
->withTrashed()
|
||||
->firstOrFail();
|
||||
|
||||
return response()->success($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(UserRequest $request, $id)
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
|
||||
if(trim($data['password']) != ''){
|
||||
$data['password'] = bcrypt($data['password']);
|
||||
}else{
|
||||
$data = collect($data)->forget('password')->all();
|
||||
}
|
||||
|
||||
$user = User::where('id',$id)
|
||||
->withTrashed()
|
||||
->firstOrFail();
|
||||
|
||||
$user->update($data);
|
||||
|
||||
RolUser::where('user_id', $id)
|
||||
->update(['role_id' => $data['role_id']]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->success($user);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return response()->unprocessable('Error', ['Error al actualizar el usuario.']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id, Request $request)
|
||||
{
|
||||
$deleted = $request->input('deleted');
|
||||
|
||||
if($deleted){
|
||||
$user = User::where('id',$id)
|
||||
->onlyTrashed()
|
||||
->first();
|
||||
|
||||
$user->restore();
|
||||
}else{
|
||||
$user = User::findOrFail($id);
|
||||
$user->delete();
|
||||
}
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
public function tiposEmpleados(){
|
||||
|
||||
$tipos_empleados = TipoEmpleado::get();
|
||||
|
||||
return response()->success($tipos_empleados);
|
||||
}
|
||||
|
||||
public function sucursales(Request $request){
|
||||
|
||||
$orderBy = $request->input('sortBy','nombre');
|
||||
$order = $request->input('order','asc');
|
||||
|
||||
$queryBuilder = Sucursal::orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('nombre','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$data = $queryBuilder->paginate($perPage);
|
||||
}else{
|
||||
$data = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
return response()->success($data);
|
||||
}
|
||||
|
||||
public function filtrosUsuarios(){
|
||||
$sucursales = Sucursal::get();
|
||||
$tipos_empleados = TipoEmpleado::get();
|
||||
$roles = Rol::get();
|
||||
|
||||
return response()->success(compact('sucursales', 'tipos_empleados', 'roles'));
|
||||
}
|
||||
}
|
||||
214
app/Http/Controllers/Administrador/VehiculosController.php
Normal file
214
app/Http/Controllers/Administrador/VehiculosController.php
Normal file
@@ -0,0 +1,214 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers\Administrador;
|
||||
|
||||
use App\Http\Requests\Administrador\VehiculosRequest;
|
||||
use App\Models\Sucursal;
|
||||
use App\Models\TipoVehiculo;
|
||||
use App\Models\Vehiculo;
|
||||
use App\Models\VehiculoSucursal;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Pagination\Paginator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Log;
|
||||
|
||||
class VehiculosController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
|
||||
$user = Auth::user();
|
||||
$deleted = $request->input('deleted');
|
||||
$orderBy = $request->input('sortBy','id');
|
||||
$order = $request->input('order','asc');
|
||||
$queryBuilder = Vehiculo::select('cat_vehiculos.*', 'cat_tipos_vehiculos.nombre as tipo_vehiculo')
|
||||
->join('cat_tipos_vehiculos', 'cat_tipos_vehiculos.id', '=', 'cat_vehiculos.tipo_vehiculo_id')
|
||||
->join('vehiculos_sucursales', 'vehiculos_sucursales.vehiculo_id', '=', 'cat_vehiculos.id')
|
||||
->where('vehiculos_sucursales.sucursal_id', $user->sucursal_id)
|
||||
->orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('num_economico','like','%' .$query.'%')
|
||||
->orWhere('cat_tipos_vehiculos.nombre','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($deleted) {
|
||||
$queryBuilder->onlyTrashed();
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$data = $queryBuilder->paginate($perPage);
|
||||
foreach ($data->items() as $vehiculo){
|
||||
$vehiculo->sucursales = VehiculoSucursal::select('sucursales.id as sucursal_id', 'sucursales.nombre as sucursal')
|
||||
->where('vehiculo_id', $vehiculo->id)
|
||||
->join('sucursales', 'sucursales.id', '=', 'vehiculos_sucursales.sucursal_id')
|
||||
->get();
|
||||
}
|
||||
|
||||
$vehiculo = $data;
|
||||
}else{
|
||||
$data = $queryBuilder->get();
|
||||
foreach ($data as $vehiculo){
|
||||
$vehiculo->sucursales = VehiculoSucursal::select('sucursales.id as sucursal_id', 'sucursales.nombre as sucursal')
|
||||
->where('vehiculo_id', $vehiculo->id)
|
||||
->join('sucursales', 'sucursales.id', '=', 'vehiculos_sucursales.sucursal_id')
|
||||
->get();
|
||||
}
|
||||
|
||||
$vehiculo = ['data'=>$data];
|
||||
}
|
||||
|
||||
return response()->success($vehiculo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(VehiculosRequest $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
foreach ($data['sucursales'] as $s){
|
||||
if(!Sucursal::where('id', $s)->first()){
|
||||
return response()->unprocessable('Error', ['No se encuentra la sucursal ingresada.']);
|
||||
}
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$vehiculo = Vehiculo::create($data);
|
||||
|
||||
foreach ($data['sucursales'] as $s){
|
||||
VehiculoSucursal::create(['vehiculo_id' => $vehiculo->id, 'sucursal_id' => $s]);
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->success($vehiculo);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return response()->unprocessable('Error', ['Error al guardar el Estatus de Servicio.']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$vehiculo = Vehiculo::select('cat_vehiculos.*', 'cat_tipos_vehiculos.nombre as tipo_vehiculo')
|
||||
->where('cat_vehiculos.id', $id)
|
||||
->join('cat_tipos_vehiculos', 'cat_tipos_vehiculos.id', '=', 'cat_vehiculos.tipo_vehiculo_id')
|
||||
->withTrashed()
|
||||
->firstOrFail();
|
||||
|
||||
$vehiculo->sucursales = VehiculoSucursal::select('sucursales.id as sucursal_id', 'sucursales.nombre as sucursal')
|
||||
->where('vehiculo_id', $vehiculo->id)
|
||||
->join('sucursales', 'sucursales.id', '=', 'vehiculos_sucursales.sucursal_id')
|
||||
->get();
|
||||
|
||||
return response()->success($vehiculo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(VehiculosRequest $request, $id)
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$vehiculo = Vehiculo::where('id',$id)
|
||||
->withTrashed()
|
||||
->firstOrFail();
|
||||
|
||||
$vehiculo->update($data);
|
||||
|
||||
VehiculoSucursal::where('vehiculo_id', $id)->delete();
|
||||
|
||||
foreach ($data['sucursales'] as $s){
|
||||
VehiculoSucursal::create(['vehiculo_id' => $vehiculo->id, 'sucursal_id' => $s]);
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
return response()->success($vehiculo);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return response()->unprocessable('Error', ['Error al actualizar el Estatus de Servicio.']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id, Request $request)
|
||||
{
|
||||
$deleted = $request->input('deleted');
|
||||
|
||||
if($deleted){
|
||||
$vehiculo = Vehiculo::where('id',$id)
|
||||
->onlyTrashed()
|
||||
->first();
|
||||
|
||||
$vehiculo->restore();
|
||||
}else{
|
||||
$vehiculo = Vehiculo::findOrFail($id);
|
||||
$vehiculo->delete();
|
||||
|
||||
VehiculoSucursal::where('vehiculo_id', $id)->delete();
|
||||
}
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
public function sucursales(){
|
||||
|
||||
$sucursales = Sucursal::get();
|
||||
|
||||
return response()->success($sucursales);
|
||||
}
|
||||
|
||||
public function tiposVehiculos(Request $request){
|
||||
|
||||
$orderBy = $request->input('sortBy','nombre');
|
||||
$order = $request->input('order','asc');
|
||||
|
||||
$queryBuilder = TipoVehiculo::orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('nombre','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$data = $queryBuilder->paginate($perPage);
|
||||
}else{
|
||||
$data = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
return response()->success($data);
|
||||
}
|
||||
}
|
||||
110
app/Http/Controllers/AtencionClientes/EncuestasController.php
Normal file
110
app/Http/Controllers/AtencionClientes/EncuestasController.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\AtencionClientes;
|
||||
|
||||
use const App\Http\Controllers\DOMESTICO;
|
||||
use App\Models\PreguntaDomestico;
|
||||
use App\Models\PreguntaEmpresarial;
|
||||
use App\Models\RespuestaDomestico;
|
||||
use App\Models\RespuestaEmpresarial;
|
||||
use App\Models\ServicioDet;
|
||||
use App\Models\ServicioEnc;
|
||||
use App\Models\ServicioEncuestaDomestico;
|
||||
use App\Models\ServicioEncuestaEmpresarial;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use DB;
|
||||
use Log;
|
||||
|
||||
class EncuestasController extends Controller
|
||||
{
|
||||
public function resultados($servicio_id){
|
||||
|
||||
$puntuacion = 0;
|
||||
|
||||
$servicio_det = ServicioDet::select('servicios_det.*', 'cat_servicios.nombre as servicio_evaluado', 'servicios_progreso.firma')
|
||||
->join('cat_servicios', 'servicios_det.servicio_id', '=', 'cat_servicios.id')
|
||||
->leftJoin('servicios_progreso', 'servicios_det.id','=','servicios_progreso.servicio_det_id')
|
||||
->where('servicios_det.id', $servicio_id)
|
||||
->firstOrFail();
|
||||
|
||||
$servicio = ServicioEnc::select('clientes.denominacion', 'clientes_domicilios.nombre_responsable_sucursal as contacto')
|
||||
->join('clientes', 'servicios_enc.cliente_id', '=', 'clientes.id')
|
||||
->join('clientes_domicilios', 'servicios_enc.cliente_domicilio_id', '=', 'clientes_domicilios.id')
|
||||
->where('servicios_enc.id', $servicio_det->servicio_enc_id)
|
||||
->first();
|
||||
|
||||
if($servicio_det->tipo_servicio_id == DOMESTICO){
|
||||
$encuesta = ServicioEncuestaDomestico::select('servicios_encuestas_domestico.*', 'respuestas_domestico.puntuacion', 'respuestas_domestico.tipo_campo')
|
||||
->leftJoin('respuestas_domestico','servicios_encuestas_domestico.respuesta_id', '=', 'respuestas_domestico.id')
|
||||
->where('servicios_encuestas_domestico.servicio_det_id', $servicio_id)
|
||||
->get();
|
||||
|
||||
$nombre_cliente = $servicio->denominacion;
|
||||
$servicio_evaluado = $servicio_det->servicio_evaluado;
|
||||
$fecha = $servicio_det->fecha_solicitud;
|
||||
$firma = $servicio_det->firma;
|
||||
}else{
|
||||
$encuesta = ServicioEncuestaEmpresarial::select('servicios_encuestas_empresarial.*', 'respuestas_empresarial.puntuacion', 'respuestas_empresarial.tipo_campo')
|
||||
->leftJoin('respuestas_empresarial', 'servicios_encuestas_empresarial.respuesta_id', '=', 'respuestas_empresarial.id')
|
||||
->where('servicios_encuestas_empresarial.servicio_det_id', $servicio_id)
|
||||
->get();
|
||||
|
||||
$empresa = $servicio->denominacion;
|
||||
$contacto = $servicio->contacto;
|
||||
$servicio_evaluado = $servicio_det->servicio_evaluado;
|
||||
$fecha = $servicio_det->fecha_solicitud;
|
||||
$firma = $servicio_det->firma;
|
||||
}
|
||||
$preguntas = [];
|
||||
if($servicio_det->requiere_encuesta && count($encuesta) > 0) {
|
||||
|
||||
$result_collect = collect($encuesta)->where('tipo_campo', '=', 'Checkbox');
|
||||
$count = $result_collect->count();
|
||||
$sum = $result_collect->sum('puntuacion');
|
||||
$puntuacion = $sum / $count;
|
||||
|
||||
$preguntas_id = collect($encuesta)->pluck('pregunta_id');
|
||||
|
||||
$orden = 1;
|
||||
|
||||
if ($servicio_det->tipo_servicio_id == DOMESTICO) {
|
||||
$preguntas = PreguntaDomestico::withTrashed()->whereIn('id',$preguntas_id)->orderBy('orden', 'asc')->get();
|
||||
|
||||
foreach ($preguntas as $eD){
|
||||
$eD->respuestas = RespuestaDomestico::withTrashed()->where('pregunta_id', $eD->id)
|
||||
->get();
|
||||
|
||||
$eD->orden = $orden++;
|
||||
}
|
||||
}else{
|
||||
$preguntas = PreguntaEmpresarial::withTrashed()->whereIn('id',$preguntas_id)->orderBy('orden', 'asc')->get();
|
||||
|
||||
foreach ($preguntas as $eE){
|
||||
$eE->respuestas = RespuestaEmpresarial::withTrashed()->where('pregunta_id', $eE->id)
|
||||
->get();
|
||||
$eE->orden = $orden++;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($preguntas as $p){
|
||||
foreach ($p->respuestas as $r){
|
||||
foreach ($encuesta as $e){
|
||||
if($r->pregunta_id == $e->pregunta_id){
|
||||
if($r->id == $e->respuesta_id && $r->tipo_campo == 'Checkbox'){
|
||||
$r->seleccionado = 1;
|
||||
}else{
|
||||
$r->seleccionado = ($r->tipo_campo == 'Checkbox')? 0 : null;
|
||||
}
|
||||
$r->respuesta = ($e->respuesta)? $e->respuesta : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$puntuacion = round($puntuacion, 2);
|
||||
|
||||
return response()->success(compact('empresa', 'contacto', 'nombre_cliente', 'servicio_evaluado', 'fecha', 'firma', 'preguntas', 'puntuacion'));
|
||||
}
|
||||
}
|
||||
1457
app/Http/Controllers/AtencionClientes/ServiciosController.php
Normal file
1457
app/Http/Controllers/AtencionClientes/ServiciosController.php
Normal file
File diff suppressed because it is too large
Load Diff
229
app/Http/Controllers/Auth/AuthenticateController.php
Normal file
229
app/Http/Controllers/Auth/AuthenticateController.php
Normal file
@@ -0,0 +1,229 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use const App\Http\Controllers\LLAVE_VERSION_APLICACION;
|
||||
use const App\Http\Controllers\VERSION_APLICACION;
|
||||
use App\Http\Requests\LoginRequest;
|
||||
use App\Http\Requests\TokenFirebaseRequest;
|
||||
use App\Mail\ResetPassword;
|
||||
use App\Models\Parametro;
|
||||
use App\Models\RolUser;
|
||||
use App\Models\TipoEmpleado;
|
||||
use App\Models\User;
|
||||
use Cartalyst\Sentinel\Checkpoints\NotActivatedException;
|
||||
use Cartalyst\Sentinel\Checkpoints\ThrottlingException;
|
||||
use Cartalyst\Sentinel\Native\Facades\Sentinel;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Tymon\JWTAuth\Exceptions\JWTException;
|
||||
use Tymon\JWTAuth\Facades\JWTAuth;
|
||||
use Log;
|
||||
use Auth;
|
||||
|
||||
class AuthenticateController extends Controller
|
||||
{
|
||||
public function getAccessToken(LoginRequest $request)
|
||||
{
|
||||
|
||||
$credentials = $request->only('email', 'password');
|
||||
$dispositivo_id = $request->input('dispositivo_id', NULL);
|
||||
$version_apk = $request->input('version_apk', false);
|
||||
$version_parametro = Parametro::where('llave',LLAVE_VERSION_APLICACION)->first();
|
||||
|
||||
|
||||
try {
|
||||
|
||||
$usuario = User::where('email', $credentials['email'])->first();
|
||||
|
||||
|
||||
if ($usuario) {
|
||||
$tipo = TipoEmpleado::where('id', $usuario->tipo_empleado_id)->first();
|
||||
|
||||
if (!$tipo->login) {
|
||||
return response()->forbidden('No cuentas con los suficientes permisos para acceder a este módulo.');
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (!$user = Sentinel::forceAuthenticate($credentials)) {
|
||||
return response()->unauthorized('Usuario y/o contraseña incorrectas.');
|
||||
}
|
||||
} catch (ThrottlingException $e) {
|
||||
return response()->tooManyAttempts('too_many_attempts');
|
||||
}
|
||||
|
||||
$token = JWTAuth::attempt($credentials);
|
||||
|
||||
if (!$token) {
|
||||
return response()->unauthorized('Usuario y/o contraseña incorrectas.');
|
||||
}
|
||||
|
||||
$application = $request->header('Application');
|
||||
|
||||
if ($application == 'MOVIL' && (!$version_apk || $version_apk != $version_parametro->valor)){
|
||||
return response()->unauthorized('Existe una nueva versión disponible, contacta con tu supervisor.');
|
||||
}
|
||||
|
||||
$user = Auth::user();
|
||||
|
||||
$role_id = RolUser::where('user_id', $user->id)->first();
|
||||
$role = Sentinel::findRoleById($role_id->role_id);
|
||||
|
||||
$this->validarAplicacion($application, $role);
|
||||
|
||||
if ($dispositivo_id != null) {
|
||||
$user->dispositivo_id = $dispositivo_id;
|
||||
$user->update();
|
||||
}
|
||||
|
||||
return response()->success(compact('user', 'token', 'role'));
|
||||
|
||||
|
||||
} catch (JWTException $e) {
|
||||
// something went wrong whilst attempting to encode the token
|
||||
return response()->json(['error' => 'could_not_create_token'], 500);
|
||||
|
||||
} catch (NotActivatedException $e) {
|
||||
|
||||
return response()->badRequest($e->getMessage());
|
||||
} catch (\Exception $e) {
|
||||
|
||||
if ($e->getCode() == 400) {
|
||||
return response()->badRequest($e->getMessage());
|
||||
}
|
||||
|
||||
if ($e->getCode() == 401) {
|
||||
return response()->unauthorized($e->getMessage());
|
||||
}
|
||||
|
||||
if ($e->getCode() == 403) {
|
||||
return response()->forbidden($e->getMessage());
|
||||
}
|
||||
|
||||
if ($e->getCode() == 404) {
|
||||
return response()->notFound($e->getMessage());
|
||||
}
|
||||
|
||||
if ($e->getCode() == 422) {
|
||||
return response()->unprocessable('Error', [$e->getMessage()]);
|
||||
}
|
||||
|
||||
return response()->json(['error' => $e->getMessage()], $e->getCode());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function validarAplicacion($application, $role)
|
||||
{
|
||||
|
||||
if (!$application)
|
||||
throw new \Exception('El header Application es obligatorio.', 400);
|
||||
|
||||
|
||||
if (strtoupper($application) == 'MOVIL') {
|
||||
|
||||
if (!$role->movil) {
|
||||
throw new \Exception('No cuentas con los suficientes permisos para acceder a este módulo.', 403);
|
||||
}
|
||||
|
||||
} elseif (strtoupper($application) == 'WEB') {
|
||||
|
||||
if (!$role->web) {
|
||||
throw new \Exception('No cuentas con los suficientes permisos para acceder a este módulo.', 403);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Actualizar json token web
|
||||
* Retorna un nuevo token de acceso **JWT**
|
||||
*
|
||||
* @param App\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function refreshAccessToken(Request $request)
|
||||
{
|
||||
|
||||
$token = JWTAuth::parseToken()->refresh();
|
||||
|
||||
return response()->success(compact('token'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Recuperar Contraseña
|
||||
* @param App\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function recoverPassword(Request $request)
|
||||
{
|
||||
$email = $request->input('email', false);
|
||||
|
||||
$user = User::where('email', $email)->first();
|
||||
|
||||
if (!$user) {
|
||||
return response()->unprocessable('Error', ['El usuario no se encuentra disponible.']);
|
||||
}
|
||||
|
||||
$newpass = str_random(4);
|
||||
$newpass = strtolower($newpass);
|
||||
$user->password = bcrypt($newpass);
|
||||
$user->solicitar = 1;
|
||||
$user->save();
|
||||
$user['nueva'] = $newpass;
|
||||
Mail::to($email)->send(new ResetPassword($user));
|
||||
$mensaje = "Acabamos de enviar un correo electrónico con su contraseña.";
|
||||
|
||||
return response()->success(['result' => $mensaje]);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Actualizar Contraseña
|
||||
* @param App\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function updatePassword(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$data = $request->only([
|
||||
'old_password',
|
||||
'password',
|
||||
'password_confirm'
|
||||
]);
|
||||
|
||||
$current_password = Auth::attempt(['email' => $user->email, 'password' => $data['old_password']]);
|
||||
|
||||
if ($current_password) {
|
||||
if ($data['password'] == $data['password_confirm']) {
|
||||
$user->password = bcrypt($data['password']);
|
||||
$user->solicitar = 0;
|
||||
$user->update();
|
||||
return response()->success(['result' => 'Contraseña actualizada correctamente']);
|
||||
} else {
|
||||
$msg = 'Las contraseñas no coinciden.';
|
||||
return response()->unprocessable('Error', [$msg]);
|
||||
}
|
||||
} else {
|
||||
return response()->unprocessable('Error', ['Contraseña actual incorrecta.']);
|
||||
}
|
||||
}
|
||||
|
||||
public function tokenFirebase(TokenFirebaseRequest $request)
|
||||
{
|
||||
|
||||
$user = Auth::user();
|
||||
|
||||
$data = $request->only(['token_firebase']);
|
||||
|
||||
User::where('id', $user->id)->first()->update($data);
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
}
|
||||
32
app/Http/Controllers/Auth/ForgotPasswordController.php
Normal file
32
app/Http/Controllers/Auth/ForgotPasswordController.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
|
||||
|
||||
class ForgotPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset emails and
|
||||
| includes a trait which assists in sending these notifications from
|
||||
| your application to your users. Feel free to explore this trait.
|
||||
|
|
||||
*/
|
||||
|
||||
use SendsPasswordResetEmails;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest');
|
||||
}
|
||||
}
|
||||
39
app/Http/Controllers/Auth/LoginController.php
Normal file
39
app/Http/Controllers/Auth/LoginController.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Login Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles authenticating users for the application and
|
||||
| redirecting them to your home screen. The controller uses a trait
|
||||
| to conveniently provide its functionality to your applications.
|
||||
|
|
||||
*/
|
||||
|
||||
use AuthenticatesUsers;
|
||||
|
||||
/**
|
||||
* Where to redirect users after login.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = '/home';
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest')->except('logout');
|
||||
}
|
||||
}
|
||||
71
app/Http/Controllers/Auth/RegisterController.php
Normal file
71
app/Http/Controllers/Auth/RegisterController.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\User;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||
|
||||
class RegisterController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Register Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles the registration of new users as well as their
|
||||
| validation and creation. By default this controller uses a trait to
|
||||
| provide this functionality without requiring any additional code.
|
||||
|
|
||||
*/
|
||||
|
||||
use RegistersUsers;
|
||||
|
||||
/**
|
||||
* Where to redirect users after registration.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = '/home';
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a validator for an incoming registration request.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \Illuminate\Contracts\Validation\Validator
|
||||
*/
|
||||
protected function validator(array $data)
|
||||
{
|
||||
return Validator::make($data, [
|
||||
'name' => 'required|string|max:255',
|
||||
'email' => 'required|string|email|max:255|unique:users',
|
||||
'password' => 'required|string|min:6|confirmed',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user instance after a valid registration.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \App\User
|
||||
*/
|
||||
protected function create(array $data)
|
||||
{
|
||||
return User::create([
|
||||
'name' => $data['name'],
|
||||
'email' => $data['email'],
|
||||
'password' => bcrypt($data['password']),
|
||||
]);
|
||||
}
|
||||
}
|
||||
39
app/Http/Controllers/Auth/ResetPasswordController.php
Normal file
39
app/Http/Controllers/Auth/ResetPasswordController.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\ResetsPasswords;
|
||||
|
||||
class ResetPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset requests
|
||||
| and uses a simple trait to include this behavior. You're free to
|
||||
| explore this trait and override any methods you wish to tweak.
|
||||
|
|
||||
*/
|
||||
|
||||
use ResetsPasswords;
|
||||
|
||||
/**
|
||||
* Where to redirect users after resetting their password.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = '/home';
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest');
|
||||
}
|
||||
}
|
||||
211
app/Http/Controllers/Controller.php
Normal file
211
app/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,211 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Sucursal;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Log;
|
||||
|
||||
const PASSWORD = 'SECRET123123';
|
||||
|
||||
//Estatus de Servicios
|
||||
const REALIZADO = 1;
|
||||
const REPROGRAMADO = 2;
|
||||
const CANCELADO = 3;
|
||||
const PENDIENTE = 4;
|
||||
const NEGATIVO = 5;
|
||||
const PAGADO = 6;
|
||||
const VISITA = 7;
|
||||
|
||||
//Tipos De Empleados
|
||||
const GENERAL = 1;
|
||||
const ASESOR_OPERACIONES = 2;
|
||||
const AUXILIAR_TECNICO_1 = 3;
|
||||
const AUXILIAR_TECNICO_2 = 4;
|
||||
const ATENCION_CLIENTES = 5;
|
||||
|
||||
//Definio
|
||||
const DEFINIO_CLIENTE = 1;
|
||||
const DEFINIO_ATENCION_CLIENTE = 2;
|
||||
|
||||
//Tipos de servicio
|
||||
const DOMESTICO = 1;
|
||||
const EMPRESARIAL = 2;
|
||||
|
||||
//Correos
|
||||
const CORREOS_DEV = ['luis@ie-soluciones.com', 'omar@ie-soluciones.com', 'soporte@ie-soluciones.com'];
|
||||
const CORREOS_PROD = ['guillermo@drenax.com.mx', 'bladimir@drenax.com.mx', 'antonio@drenax.com.mx', 'laura@drenax.com.mx'];
|
||||
|
||||
//Nombre checklist
|
||||
const VEHICULO_ASIGNADO = "VEHÍCULO ASIGNADO";
|
||||
|
||||
//Costo de servicio negativo
|
||||
const COSTO_SERVICIO_NEGATIVO = 350;
|
||||
|
||||
//Parametros
|
||||
const LLAVE_ANCLAJE_SERVICIO_HORAS = 'ANCLAJE_SERVICIO_HORAS';
|
||||
const LLAVE_VERSION_APLICACION = 'CURRENT_VERSION_APPLICATION';
|
||||
const ANCLAJE_SERVICIO_HORAS = 3;
|
||||
|
||||
//ZIP
|
||||
const DEFAULT_PATH_ZIP_EVIDENCES = "app/public/temp/";
|
||||
|
||||
ini_set('memory_limit', '-1');
|
||||
set_time_limit(0);
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
|
||||
|
||||
public function sumarTiempos($array_tiempos){
|
||||
|
||||
if(count($array_tiempos) > 0){
|
||||
$total_segundos = 0;
|
||||
for ($i = 0; $i < count($array_tiempos); $i ++){
|
||||
|
||||
if($array_tiempos[$i]){
|
||||
list($h,$m,$s) = explode(":", $array_tiempos[$i]);
|
||||
$seg_h = ((int)$h * 3600);
|
||||
$seg_m = ((int)$m * 60);
|
||||
$seg_s = (int)$s;
|
||||
|
||||
$total_segundos += ($seg_h + $seg_m + $seg_s);
|
||||
}
|
||||
}
|
||||
|
||||
$horas = floor($total_segundos / 3600);
|
||||
$minutos = floor(($total_segundos - ($horas * 3600)) / 60);
|
||||
$segundos = $total_segundos - ($horas * 3600) - ($minutos * 60);
|
||||
|
||||
$horas = str_pad($horas, 2, 0, STR_PAD_LEFT);
|
||||
$minutos = str_pad($minutos, 2, 0, STR_PAD_LEFT);
|
||||
$segundos = str_pad($segundos, 2, 0, STR_PAD_LEFT);
|
||||
|
||||
return $horas . ':' . $minutos . ":" . $segundos;
|
||||
}else{
|
||||
return "00:00:00";
|
||||
}
|
||||
}
|
||||
|
||||
public function diferenciaFechas($t1, $t2){
|
||||
|
||||
$tiempo_atencion = Carbon::parse($t1)->diffInMinutes(Carbon::parse($t2));
|
||||
$d = intval($tiempo_atencion / 1440);
|
||||
$h = intval(($tiempo_atencion - ($d * 1440)) / 60);
|
||||
$m = intval(($tiempo_atencion - ($d * 1440) - ($h * 60)) % 60);
|
||||
|
||||
return $d.' días, '.$h.' horas y '.$m.' minutos';
|
||||
}
|
||||
|
||||
public function formatearFechaHora($fecha_hora){
|
||||
|
||||
list($fecha, $hora) = explode(" ", $fecha_hora);
|
||||
list($y, $m, $d) = explode("-", $fecha);
|
||||
list($hr, $min) = explode(":", $hora);
|
||||
|
||||
return $d.'/'.$m.'/'.$y.' '.$hr.':'.$min;
|
||||
}
|
||||
|
||||
public function base64ToImage($base64, $mime = 'image/jpeg'){
|
||||
$image_decode = base64_decode($base64);
|
||||
$resource = imagecreatefromstring($image_decode);
|
||||
|
||||
ob_start();
|
||||
|
||||
if($mime === 'image/jpeg'){
|
||||
imagejpeg($resource);
|
||||
}else{
|
||||
imagepng($resource);
|
||||
}
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
public function camposSolicitudesServiciosOperador(){
|
||||
|
||||
$user = Auth::user();
|
||||
$costo_servicio_negativo = Sucursal::select('costo_negativo')->where('sucursales.id', $user->sucursal_id)->first();
|
||||
|
||||
return [
|
||||
'servicios_enc.id as solicitud_servicio_id',
|
||||
'servicios_enc.forma_pago_id',
|
||||
'cat_formas_pagos.nombre as forma_pago_nombre',
|
||||
'fecha_agenda',
|
||||
'usuario_agenda_id',
|
||||
'users.nombre as usuario_agenda_nombre',
|
||||
'users.apellido_paterno as usuario_agenda_apellido_paterno',
|
||||
'users.apellido_materno as usuario_agenda_apellido_materno',
|
||||
'servicios_enc.cliente_id',
|
||||
'clientes.denominacion',
|
||||
'servicios_enc.cliente_domicilio_id',
|
||||
'clientes_domicilios.nombre_responsable_sucursal as clientes_nombre_responsable_sucursal',
|
||||
'clientes_domicilios.celular_responsable as clientes_celular_responsable',
|
||||
'clientes_domicilios.calle as clientes_calle',
|
||||
'clientes_domicilios.num_ext as clientes_num_ext',
|
||||
'clientes_domicilios.num_int as clientes_num_int',
|
||||
'clientes_domicilios.colonia as clientes_colonia',
|
||||
'clientes_domicilios.cp as clientes_cp',
|
||||
'clientes_domicilios.ciudad as clientes_ciudad',
|
||||
'clientes_domicilios.telefono as clientes_telefono',
|
||||
'clientes_domicilios.lat as clientes_lat',
|
||||
'clientes_domicilios.lng as clientes_lng',
|
||||
'clientes_domicilios.nombre_croquis as nombre_croquis',
|
||||
'clientes_domicilios.nombre_sucursal as nombre_sucursal',
|
||||
'servicios_enc.deleted_at',
|
||||
'servicios_det.id',
|
||||
'servicios_det.servicio_id',
|
||||
'cat_servicios.nombre as servicio_nombre',
|
||||
'servicios_det.estatus_servicio_id',
|
||||
'cat_estatus_servicios.nombre as estatus_servicio_nombre',
|
||||
'servicios_det.tipo_servicio_id',
|
||||
'cat_tipos_servicios.nombre as tipo_servicio_nombre',
|
||||
'cat_estatus_servicios.color_1 as estatus_servicio_color_1',
|
||||
'cat_estatus_servicios.color_2 as estatus_servicio_color_2',
|
||||
'fecha_solicitud',
|
||||
'servicios_det.duracion',
|
||||
'definido_cliente',
|
||||
'servicios_det.operador_id',
|
||||
'operador.nombre as operador_nombre',
|
||||
'operador.apellido_paterno as operador_apellido_paterno',
|
||||
'operador.apellido_materno as operador_apellido_materno',
|
||||
'servicios_det.vehiculo_id',
|
||||
'cat_vehiculos.num_economico as vehiculo_num_economico',
|
||||
'servicios_det.fecha_solicitud',
|
||||
'sucursales.nombre as vehiculo_sucursal',
|
||||
'sucursales.id as vehiculo_sucursal_id',
|
||||
'sucursal_operador.nombre as operador_sucursal',
|
||||
'sucursal_operador.id as operador_sucursal_id',
|
||||
'servicios_det.auxiliar_1 as auxiliar_1_id',
|
||||
'servicios_det.auxiliar_2 as auxiliar_2_id',
|
||||
'auxiliares_1.nombre as auxiliar_1',
|
||||
'auxiliares_1.apellido_paterno as auxiliar_1_apellido_paterno',
|
||||
'auxiliares_1.apellido_materno as auxiliar_1_apellido_materno',
|
||||
'auxiliares_2.nombre as auxiliar_2',
|
||||
'sucursal_auxiliares_1.nombre as sucursal_auxiliar_1',
|
||||
'sucursal_auxiliares_2.nombre as sucursal_auxiliar_2',
|
||||
'servicios_det.costo_servicio',
|
||||
'servicios_det.aceptado',
|
||||
'servicios_det.observacion_atencion_cliente',
|
||||
'servicios_det.requiere_encuesta',
|
||||
DB::raw("$costo_servicio_negativo->costo_negativo as 'costo_servicio_negativo'")
|
||||
];
|
||||
}
|
||||
|
||||
public function getMicroSeconds(){
|
||||
$micro = explode(" ", microtime());
|
||||
return $micro[1];
|
||||
}
|
||||
|
||||
public function decodeZip($base64, $path){
|
||||
$zip = base64_decode($base64);
|
||||
file_put_contents($path, $zip);
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
469
app/Http/Controllers/Operador/CheckListController.php
Normal file
469
app/Http/Controllers/Operador/CheckListController.php
Normal file
@@ -0,0 +1,469 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Operador;
|
||||
|
||||
use App\Models\CorreoSucursal;
|
||||
use App\Models\Sucursal;
|
||||
use const App\Http\Controllers\CORREOS_DEV;
|
||||
use const App\Http\Controllers\CORREOS_PROD;
|
||||
use App\Models\RespuestaOperadorDet;
|
||||
use App\Models\RespuestaOperadorEnc;
|
||||
use App\Models\Vehiculo;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Auth;
|
||||
use App\Http\Requests\Operador\RespuestasOperadorRequest;
|
||||
use DB;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Log;
|
||||
use App\Mail\RespuestasOperador;
|
||||
|
||||
|
||||
class CheckListController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
function index(Request $request)
|
||||
{
|
||||
$now = Carbon::now()->format('Y-m-d');
|
||||
$checklist = [
|
||||
[
|
||||
'id' => 1,
|
||||
'nombre' => "VEHÍCULO ASIGNADO",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'REVISION',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'nombre' => "NIVEL DE ACEITE MOTOR PRINCIPAL",
|
||||
'tipo_radio_btn' => 1,
|
||||
'tipo_text' => 1,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'REVISION',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 3,
|
||||
'nombre' => "NIVEL DE ANTICONGELANTE MOTOR PRINCIPAL",
|
||||
'tipo_radio_btn' => 1,
|
||||
'tipo_text' => 1,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'REVISION',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 4,
|
||||
'nombre' => "NIVEL ACEITE HIDRAULICO MOTOR PRINCIPAL",
|
||||
'tipo_radio_btn' => 1,
|
||||
'tipo_text' => 1,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'REVISION',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 5,
|
||||
'nombre' => "NIVEL DE ANTICONGELANTE BOMBA SUCCION",
|
||||
'tipo_radio_btn' => 1,
|
||||
'tipo_text' => 1,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'REVISION',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 6,
|
||||
'nombre' => "NIVEL DE ACEITE BOMBA DE SUCCION",
|
||||
'tipo_radio_btn' => 1,
|
||||
'tipo_text' => 1,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'REVISION',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 7,
|
||||
'nombre' => "NIVEL DE COMBUSTIBLE MOTOR PRINCIPAL",
|
||||
'tipo_radio_btn' => 1,
|
||||
'tipo_text' => 1,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'REVISION',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 8,
|
||||
'nombre' => "NIVEL DE COMBUSTIBLE MOTOR AUXILIAR",
|
||||
'tipo_radio_btn' => 1,
|
||||
'tipo_text' => 1,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'REVISION',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 9,
|
||||
'nombre' => "NIVEL DE TANQUE DE AGUA",
|
||||
'tipo_radio_btn' => 1,
|
||||
'tipo_text' => 1,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'REVISION',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 10,
|
||||
'nombre' => "REVISION DE LLANTAS",
|
||||
'tipo_radio_btn' => 1,
|
||||
'tipo_text' => 1,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'REVISION',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 11,
|
||||
'nombre' => "LIMPIEZA DE VEHÍCULO",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 1,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'REVISION',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 12,
|
||||
'nombre' => "REPORTE DE FALLAS E INCIDENCIAS",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 1,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'REVISION',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 13,
|
||||
'nombre' => "TARJETA DE CIRCULACIÓN",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'MATERIAL',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 14,
|
||||
'nombre' => "MALETIN",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'MATERIAL',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 15,
|
||||
'nombre' => "LICENCIA VIGENTE",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'MATERIAL',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 16,
|
||||
'nombre' => "PÓLIZA DE SEGURO",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'MATERIAL',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 17,
|
||||
'nombre' => "ALTA DE SEGURO",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'MATERIAL',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 18,
|
||||
'nombre' => "RECIBOS",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'MATERIAL',
|
||||
'fecha' => $now
|
||||
],
|
||||
/*[
|
||||
'id' => 19,
|
||||
'nombre' => "ENCUESTA",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'MATERIAL',
|
||||
'fecha' => $now
|
||||
],*/
|
||||
[
|
||||
'id' => 20,
|
||||
'nombre' => "PERMISO DE TIRADAS",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'MATERIAL',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 21,
|
||||
'nombre' => "RADIO",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'MATERIAL',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 22,
|
||||
'nombre' => "COMENTARIOS",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 1,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'MATERIAL',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 23,
|
||||
'nombre' => "PALA",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'HERRAMIENTA',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 24,
|
||||
'nombre' => "BARRA",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'HERRAMIENTA',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 25,
|
||||
'nombre' => "ESPATULA",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'HERRAMIENTA',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 26,
|
||||
'nombre' => "CAJA DE HERRAMIENTAS",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'HERRAMIENTA',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 27,
|
||||
'nombre' => "SANITIZANTE",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'HERRAMIENTA',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 28,
|
||||
'nombre' => "CONOS",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'HERRAMIENTA',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 29,
|
||||
'nombre' => "CHALECO",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'HERRAMIENTA',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 30,
|
||||
'nombre' => "CASCO",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'HERRAMIENTA',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 31,
|
||||
'nombre' => "K-60",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'HERRAMIENTA',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 32,
|
||||
'nombre' => "K-06",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'HERRAMIENTA',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 33,
|
||||
'nombre' => "BOQUILLA SANITARIA",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'HERRAMIENTA',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 34,
|
||||
'nombre' => "COMENTARIOS",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 1,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'HERRAMIENTA',
|
||||
'fecha' => $now
|
||||
]
|
||||
];
|
||||
|
||||
$reinicio = $request->input('cambiar_vehiculo', 0);
|
||||
|
||||
if($reinicio == 0){
|
||||
if(RespuestaOperadorEnc::where('user_id',Auth::id())->whereDate('fecha',$now)->first()){
|
||||
$checklist = [];
|
||||
}
|
||||
}
|
||||
|
||||
return response()->success($checklist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(RespuestasOperadorRequest $request)
|
||||
{
|
||||
$user_id = Auth::id();
|
||||
$user = Auth::user();
|
||||
$data = $request->all();
|
||||
$ambiente = strtolower(config('ambiente')['ambiente']);
|
||||
|
||||
$correos_sucursales_prod = CorreoSucursal::select('email')->where('correos_sucursales.sucursal_id', $user->sucursal_id)->get();
|
||||
$correos = ($ambiente == 'dev')? $correos_sucursales_prod : CORREOS_DEV;
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
|
||||
$fecha = $data[0]['fecha'];
|
||||
|
||||
$respuesta_operador_enc = RespuestaOperadorEnc::create(['user_id' => $user_id, 'fecha' => $fecha]);
|
||||
|
||||
foreach ($data as $d){
|
||||
|
||||
$info = [
|
||||
'respuestas_operador_enc_id' => $respuesta_operador_enc->id,
|
||||
'nombre' => $d['nombre'],
|
||||
'tipo' => $d['tipo'],
|
||||
'tipo_checkbox' => $d['tipo_checkbox'],
|
||||
'tipo_text' => $d['tipo_text'],
|
||||
'tipo_radio_btn' => $d['tipo_radio_btn'],
|
||||
'respuesta_checkbox' => array_key_exists('respuesta_checkbox', $d) ? $d['respuesta_checkbox'] : null,
|
||||
'respuesta_text' => array_key_exists('respuesta_text', $d) ? $d['respuesta_text'] : null,
|
||||
'respuesta_radio_btn' => array_key_exists('respuesta_radio_btn', $d) ? $d['respuesta_radio_btn'] : null
|
||||
];
|
||||
|
||||
RespuestaOperadorDet::create($info);
|
||||
}
|
||||
|
||||
|
||||
DB::commit();
|
||||
|
||||
try {
|
||||
Mail::to($correos)->send(new RespuestasOperador($respuesta_operador_enc->id));
|
||||
} catch (\Exception $e) {
|
||||
\Log::info("Error al enviar correo: " . json_encode($e->getMessage()));
|
||||
}
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::info($e->getMessage());
|
||||
return response()->unprocessable('Error', [$e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
Auth::user();
|
||||
|
||||
$campos = [
|
||||
'user_id',
|
||||
'nombre',
|
||||
'tipo',
|
||||
'tipo_checkbox',
|
||||
'tipo_text',
|
||||
'tipo_radio_btn',
|
||||
'respuesta_checkbox',
|
||||
'respuesta_text',
|
||||
'respuesta_radio_btn',
|
||||
'fecha'
|
||||
];
|
||||
|
||||
$respuestas_operador = RespuestaOperador::select($campos)
|
||||
->where('user_id', $id)
|
||||
->first();
|
||||
|
||||
return response()->success($respuestas_operador);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function vehiculos(){
|
||||
|
||||
$vehiculos = Vehiculo::select('id', 'num_economico as nombre')->get();
|
||||
|
||||
return response()->success($vehiculos);
|
||||
}
|
||||
}
|
||||
28
app/Http/Controllers/Operador/DesplazamientosController.php
Normal file
28
app/Http/Controllers/Operador/DesplazamientosController.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Operador;
|
||||
|
||||
use App\Http\Requests\Operador\DesplazamientoRequest;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Auth;
|
||||
|
||||
class DesplazamientosController extends Controller
|
||||
{
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(DesplazamientoRequest $request)
|
||||
{
|
||||
/*$data = $request->toArray();
|
||||
|
||||
Auth::user($data)
|
||||
->desplazamientos()
|
||||
->createMany($data);*/
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
}
|
||||
130
app/Http/Controllers/Operador/EncuestasController.php
Normal file
130
app/Http/Controllers/Operador/EncuestasController.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Operador;
|
||||
|
||||
use App\Models\ServicioProgreso;
|
||||
use const App\Http\Controllers\DOMESTICO;
|
||||
use App\Models\RespuestaDomestico;
|
||||
use App\Models\RespuestaEmpresarial;
|
||||
use App\Models\ServicioDet;
|
||||
use App\Models\ServicioEncuestaDomestico;
|
||||
use App\Models\ServicioEncuestaEmpresarial;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use DB;
|
||||
use Log;
|
||||
|
||||
class EncuestasController extends Controller
|
||||
{
|
||||
|
||||
public function store(Request $request, $servicio_id)
|
||||
{
|
||||
$now = Carbon::now()->format('Y-m-d');
|
||||
$servicio_det = ServicioDet::where('id', $servicio_id)->firstOrFail();
|
||||
|
||||
list($fecha) = explode(" ", $servicio_det->fecha_solicitud);
|
||||
|
||||
//Validar fecha de solicitud
|
||||
if($now != $fecha){
|
||||
//return response()->unprocessable('Parametros inválidos',['No se puede realizar la encuesta ya que corresponde a otra fecha.']);
|
||||
}
|
||||
|
||||
$data = $request->all();
|
||||
|
||||
if($servicio_det->tipo_servicio_id == DOMESTICO) {
|
||||
$validator = Validator::make($data, [
|
||||
'*.pregunta_id' => 'numeric|exists:preguntas_domestico,id',
|
||||
'*.respuesta_id' => 'numeric|exists:respuestas_domestico,id',
|
||||
'*.respuesta' => 'string|max:255'
|
||||
]);
|
||||
|
||||
if(ServicioEncuestaDomestico::where('servicio_det_id', $servicio_id)->first()){
|
||||
//return response()->unprocessable('Parametros inválidos',['La encuesta para este servicio ya se realizó.']);
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
foreach ($data as $d){
|
||||
if(isset($d['respuesta_id'])){
|
||||
$respuesta = RespuestaDomestico::where('pregunta_id', $d['pregunta_id'])
|
||||
->where('id', $d['respuesta_id'])
|
||||
->first();
|
||||
|
||||
if(!$respuesta){
|
||||
return response()->unprocessable('Parametros inválidos',['La respuesta no corresponde a la pregunta.']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$validator = Validator::make($data, [
|
||||
'*.pregunta_id' => 'numeric|exists:preguntas_empresarial,id',
|
||||
'*.respuesta_id' => 'numeric|exists:respuestas_empresarial,id',
|
||||
'*.respuesta' => 'string|max:255'
|
||||
]);
|
||||
|
||||
if(ServicioEncuestaEmpresarial::where('servicio_det_id', $servicio_id)->first()){
|
||||
//return response()->unprocessable('Parametros inválidos',['La encuesta para este servicio ya se realizó.']);
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
foreach ($data as $d){
|
||||
if(isset($d['respuesta_id'])){
|
||||
$respuesta = RespuestaEmpresarial::where('pregunta_id', $d['pregunta_id'])
|
||||
->where('id', $d['respuesta_id'])
|
||||
->first();
|
||||
|
||||
if(!$respuesta){
|
||||
return response()->unprocessable('Parametros inválidos',['La respuesta no corresponde a la pregunta.']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($validator->fails()){
|
||||
return response()->unprocessable('Parametros inválidos',$validator->errors()->all());
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
if($servicio_det->tipo_servicio_id == DOMESTICO) {
|
||||
foreach ($data as $d){
|
||||
|
||||
$data_domestico = [
|
||||
'servicio_det_id' => $servicio_id,
|
||||
'pregunta_id' => $d['pregunta_id'],
|
||||
'respuesta_id' => (isset($d['respuesta_id']))? $d['respuesta_id'] : null,
|
||||
'respuesta' => (isset($d['respuesta']))? $d['respuesta'] : null
|
||||
];
|
||||
ServicioEncuestaDomestico::create($data_domestico);
|
||||
}
|
||||
|
||||
}else{
|
||||
foreach ($data as $d){
|
||||
$data_empresarial = [
|
||||
'servicio_det_id' => $servicio_id,
|
||||
'pregunta_id' => $d['pregunta_id'],
|
||||
'respuesta_id' => (isset($d['respuesta_id']))? $d['respuesta_id'] : null,
|
||||
'respuesta' => (isset($d['respuesta']))? $d['respuesta'] : null
|
||||
];
|
||||
ServicioEncuestaEmpresarial::create($data_empresarial);
|
||||
}
|
||||
}
|
||||
|
||||
$servicio_progreso = ServicioProgreso::where('servicio_enc_id', $servicio_det->servicio_enc_id)
|
||||
->where('servicio_det_id', $servicio_det->id)
|
||||
->first();
|
||||
|
||||
if($servicio_progreso){
|
||||
$servicio_progreso->update(['encuesta_contestada' => 1]);
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return response()->unprocessable('Error', ['Error al realizar la encuesta.']);
|
||||
}
|
||||
}
|
||||
}
|
||||
193
app/Http/Controllers/Operador/JornadaController.php
Normal file
193
app/Http/Controllers/Operador/JornadaController.php
Normal file
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Operador;
|
||||
|
||||
use App\Models\CatMotivoEstatus;
|
||||
use const App\Http\Controllers\PAGADO;
|
||||
use const App\Http\Controllers\PENDIENTE;
|
||||
use const App\Http\Controllers\REPROGRAMADO;
|
||||
use const App\Http\Controllers\VEHICULO_ASIGNADO;
|
||||
use const App\Http\Controllers\VISITA;
|
||||
use App\Http\Requests\Operador\FinalizarJornadaRequest;
|
||||
use App\Http\Requests\Operador\InicioJornadaRequest;
|
||||
use App\Models\BitacoraLaboral;
|
||||
use App\Models\Parametro;
|
||||
use App\Models\PreguntaDomestico;
|
||||
use App\Models\PreguntaEmpresarial;
|
||||
use App\Models\RespuestaDomestico;
|
||||
use App\Models\RespuestaEmpresarial;
|
||||
use App\Models\RespuestaOperadorDet;
|
||||
use App\Models\RespuestaOperadorEnc;
|
||||
use App\Models\ServicioDet;
|
||||
use App\Models\ServicioEnc;
|
||||
use App\Models\User;
|
||||
use App\Models\UsuarioDesplazamiento;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Auth;
|
||||
use Log;
|
||||
use DB;
|
||||
|
||||
class JornadaController extends Controller
|
||||
{
|
||||
public function inicioJornada(InicioJornadaRequest $request)
|
||||
{
|
||||
|
||||
$data = $request->all();
|
||||
|
||||
$user = Auth::user();
|
||||
$fecha = Carbon::now()->toDateTimeString();
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
|
||||
$bitacora = BitacoraLaboral::where('usuario_id', $user->id)
|
||||
->whereNull('fecha_hora_fin')
|
||||
->first();
|
||||
|
||||
if($bitacora){
|
||||
DB::rollBack();
|
||||
return response()->unprocessable('JORNADA_YA_INICIADA', [$bitacora->id]);
|
||||
}
|
||||
|
||||
$campos = $this->camposSolicitudesServiciosOperador();
|
||||
|
||||
$servicios = ServicioDet::select($campos)
|
||||
->joinDetalleServicioDet()
|
||||
->joinDetalleServicioDetMovil()
|
||||
->leftJoin('servicios_progreso', function($join)
|
||||
{
|
||||
$join->on('servicios_enc.id', '=', 'servicios_progreso.servicio_enc_id');
|
||||
$join->on('servicios_det.id', '=', 'servicios_progreso.servicio_det_id');
|
||||
})
|
||||
->whereNull('servicios_progreso.id')
|
||||
->whereIn('servicios_det.estatus_servicio_id', [PENDIENTE, REPROGRAMADO, VISITA, PAGADO])
|
||||
->where('servicios_det.operador_id', $user->id)
|
||||
->where('servicios_enc.sucursal_id', $user->sucursal_id)
|
||||
->whereDate('servicios_det.fecha_solicitud', Carbon::now()->format('Y-m-d'))
|
||||
->orderBy('servicios_det.fecha_solicitud')
|
||||
->get();
|
||||
|
||||
/*$fecha_actual = Carbon::now()->format('Y-m-d');
|
||||
|
||||
$servicios = [];
|
||||
|
||||
foreach ($servicios_list as $s){
|
||||
|
||||
$fecha_asignacion = Carbon::createFromTimeString($s->fecha_agenda)->format('Y-m-d');
|
||||
|
||||
if($fecha_asignacion == $fecha_actual && $s->aceptado){
|
||||
$servicios[] = $s;
|
||||
}elseif ($fecha_asignacion != $fecha_actual){
|
||||
$servicios[] = $s;
|
||||
}
|
||||
}*/
|
||||
|
||||
$encuesta_operador = RespuestaOperadorEnc::select('respuestas_operador_enc.id')
|
||||
->join('respuestas_operador_det', 'respuestas_operador_det.respuestas_operador_enc_id', '=', 'respuestas_operador_enc.id')
|
||||
->where('respuestas_operador_enc.user_id', $user->id)
|
||||
->orderBy('respuestas_operador_enc.created_at','desc')
|
||||
->first();
|
||||
|
||||
$vehiculo_operador = RespuestaOperadorDet::select('cat_vehiculos.id', 'respuestas_operador_det.respuesta_text')
|
||||
->join('respuestas_operador_enc', 'respuestas_operador_enc.id', '=', 'respuestas_operador_det.respuestas_operador_enc_id')
|
||||
->join('cat_vehiculos','cat_vehiculos.num_economico', '=', 'respuestas_operador_det.respuesta_text')
|
||||
->where('respuestas_operador_enc.user_id', $user->id)
|
||||
->where('respuestas_operador_det.nombre', '=',VEHICULO_ASIGNADO)
|
||||
->where('respuestas_operador_det.respuestas_operador_enc_id', $encuesta_operador->id)
|
||||
->first();
|
||||
|
||||
//$servi = collect($servicios)->first();
|
||||
//$data['vehiculo_id'] = ($servi) ? $servi->vehiculo_id : null;
|
||||
|
||||
$data['vehiculo_id'] = ($vehiculo_operador->id) ? $vehiculo_operador->id : 2;
|
||||
|
||||
$data['usuario_id'] = $user->id;
|
||||
$data['fecha_hora_ini'] = $fecha;
|
||||
$jornada = BitacoraLaboral::create($data);
|
||||
|
||||
$data_desplazamiento = [
|
||||
'bitacora_laboral_id' => $jornada->id,
|
||||
'usuario_id' => $user->id,
|
||||
'fecha' => $fecha,
|
||||
'modelo_celular' => $data['modelo_celular'],
|
||||
'bateria' => $data['bateria'],
|
||||
'lat' => $data['lat_ini'],
|
||||
'lng' => $data['lng_ini']
|
||||
];
|
||||
|
||||
UsuarioDesplazamiento::create($data_desplazamiento);
|
||||
|
||||
User::where('id', $user->id)->first()->update(['token_firebase' => $data['token_firebase']]);
|
||||
|
||||
$parametros = Parametro::get();
|
||||
|
||||
$encuesta_domestico = PreguntaDomestico::get();
|
||||
|
||||
foreach ($encuesta_domestico as $eD){
|
||||
$eD->respuestas = RespuestaDomestico::where('pregunta_id', $eD->id)->get();
|
||||
}
|
||||
|
||||
$encuesta_empresarial = PreguntaEmpresarial::get();
|
||||
|
||||
foreach ($encuesta_empresarial as $eE){
|
||||
$eE->respuestas = RespuestaEmpresarial::where('pregunta_id', $eE->id)->get();
|
||||
}
|
||||
|
||||
$motivos_estatus = CatMotivoEstatus::select('id', 'nombre as descripcion')
|
||||
->get();
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->success(compact('servicios', 'parametros', 'jornada', 'encuesta_domestico', 'encuesta_empresarial', 'motivos_estatus'));
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::info($e->getMessage());
|
||||
return response()->unprocessable('Error', ['Error al guardar el inicio de jornada.']);
|
||||
}
|
||||
}
|
||||
|
||||
public function finalizarJornada(FinalizarJornadaRequest $request, $id){
|
||||
|
||||
$data = $request->all();
|
||||
|
||||
$user = Auth::user();
|
||||
$fecha = Carbon::now()->toDateTimeString();
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
|
||||
$jornada = BitacoraLaboral::where('id',$id)
|
||||
->first();
|
||||
|
||||
if($jornada->fecha_hora_fin){
|
||||
DB::rollBack();
|
||||
return response()->unprocessable('Error', ['La jornada ya se encuentra finalizada.']);
|
||||
}
|
||||
|
||||
$data['fecha_hora_fin'] = $fecha;
|
||||
$jornada->update($data);
|
||||
|
||||
$data_desplazamiento = [
|
||||
'bitacora_laboral_id' => $id,
|
||||
'usuario_id' => $user->id,
|
||||
'fecha' => $fecha,
|
||||
'modelo_celular' => $data['modelo_celular'],
|
||||
'bateria' => $data['bateria'],
|
||||
'lat' => $data['lat_fin'],
|
||||
'lng' => $data['lng_fin']
|
||||
];
|
||||
|
||||
UsuarioDesplazamiento::create($data_desplazamiento);
|
||||
|
||||
User::where('id', $user->id)->update(['token_firebase' => NULL]);
|
||||
DB::commit();
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return response()->unprocessable('Error', ['Error al guardar el fin de jornada.']);
|
||||
}
|
||||
}
|
||||
}
|
||||
267
app/Http/Controllers/Operador/ServiciosController.php
Normal file
267
app/Http/Controllers/Operador/ServiciosController.php
Normal file
@@ -0,0 +1,267 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Operador;
|
||||
|
||||
use App\Models\Parametro;
|
||||
use const App\Http\Controllers\ANCLAJE_SERVICIO_HORAS;
|
||||
use const App\Http\Controllers\LLAVE_ANCLAJE_SERVICIO_HORAS;
|
||||
use const App\Http\Controllers\PAGADO;
|
||||
use const App\Http\Controllers\PENDIENTE;
|
||||
use const App\Http\Controllers\REPROGRAMADO;
|
||||
use const App\Http\Controllers\VISITA;
|
||||
use App\Http\Requests\Operador\RechazarSolicitudRequest;
|
||||
use App\Models\CatServicio;
|
||||
use App\Models\ServicioDet;
|
||||
use App\Models\ServicioEnc;
|
||||
use App\Models\ServicioProgreso;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Log;
|
||||
|
||||
class ServiciosController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
if(!Carbon::parse($user->last_login)->isToday()){
|
||||
return response()->json(['error'=>'Es necesario iniciar sesión el día de hoy'],420);
|
||||
}
|
||||
|
||||
$ayer = Carbon::yesterday()->format('Y-m-d 23:00:00');
|
||||
$hoy = Carbon::now()->format('Y-m-d 23:59:59');
|
||||
|
||||
$campos = $this->camposSolicitudesServiciosOperador();
|
||||
|
||||
$s = ServicioDet::select($campos)
|
||||
->joinDetalleServicioDet()
|
||||
->joinDetalleServicioDetMovil()
|
||||
->leftJoin('servicios_progreso', function($join)
|
||||
{
|
||||
$join->on('servicios_enc.id', '=', 'servicios_progreso.servicio_enc_id');
|
||||
$join->on('servicios_det.id', '=', 'servicios_progreso.servicio_det_id');
|
||||
})
|
||||
->whereNull('servicios_progreso.id')
|
||||
->whereIn('servicios_det.estatus_servicio_id', [PENDIENTE, REPROGRAMADO, VISITA, PAGADO])
|
||||
->where('servicios_det.operador_id', $user->id)
|
||||
->where('servicios_enc.sucursal_id', $user->sucursal_id)
|
||||
->whereBetween('servicios_det.fecha_solicitud', [$ayer, $hoy])
|
||||
->get();
|
||||
|
||||
$servicios_progresos = ServicioProgreso::select('servicio_det_id')->get();
|
||||
if(count($servicios_progresos) != 0){
|
||||
$servicios = collect($s)->whereNotIn('id',$servicios_progresos->pluck('servicio_det_id'))->all();
|
||||
}else{
|
||||
$servicios = $s;
|
||||
}
|
||||
|
||||
$tiempo_anclaje = Parametro::where('llave',LLAVE_ANCLAJE_SERVICIO_HORAS)->first();
|
||||
$tiempo_anclaje = ($tiempo_anclaje)? $tiempo_anclaje->valor : ANCLAJE_SERVICIO_HORAS;
|
||||
$tiempo_anclaje = (1 + $tiempo_anclaje) * 60;
|
||||
|
||||
$data = [];
|
||||
$hoy = Carbon::now();
|
||||
$hoy_dia = $hoy->format('Y-m-d');
|
||||
|
||||
foreach ($servicios as $s){
|
||||
if(Carbon::parse($s->fecha_solicitud)->format('Y-m-d') == $hoy_dia){
|
||||
array_push($data, $s);
|
||||
}else{
|
||||
if(Carbon::parse($s->fecha_solicitud)->diffInMinutes($hoy) <= $tiempo_anclaje){
|
||||
array_push($data, $s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Comentado por rechazo del cliente
|
||||
/*$fecha_actual = Carbon::now()->format('Y-m-d');
|
||||
|
||||
$salida = [];
|
||||
|
||||
foreach ($servicios as $s){
|
||||
|
||||
$fecha_asignacion = Carbon::createFromTimeString($s->fecha_agenda)->format('Y-m-d');
|
||||
|
||||
if($fecha_asignacion == $fecha_actual && $s->aceptado){
|
||||
$salida[] = $s;
|
||||
}elseif ($fecha_asignacion != $fecha_actual){
|
||||
$salida[] = $s;
|
||||
}
|
||||
}*/
|
||||
|
||||
return response()->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$campos = $this->camposSolicitudesServiciosOperador();
|
||||
|
||||
$servicios = ServicioDet::select($campos)
|
||||
->joinDetalleServicioDet()
|
||||
->joinDetalleServicioDetMovil()
|
||||
->where('servicios_det.id', $id)
|
||||
->whereIn('servicios_det.estatus_servicio_id', [PENDIENTE, REPROGRAMADO, VISITA, PAGADO])
|
||||
->where('servicios_det.operador_id', $user->id)
|
||||
->where('servicios_enc.sucursal_id', $user->sucursal_id)
|
||||
->whereDate('servicios_det.fecha_solicitud', Carbon::now()->format('Y-m-d'))
|
||||
->first();
|
||||
|
||||
return response()->success($servicios);
|
||||
}
|
||||
|
||||
public function aceptarSolicitud($id){
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
|
||||
$ambiente = strtolower(config('ambiente')['ambiente']);
|
||||
|
||||
$url = config('ambiente')[$ambiente];
|
||||
|
||||
$servicio_det = ServicioDet::where('id',$id)->first();
|
||||
|
||||
if(!$servicio_det){
|
||||
DB::rollBack();
|
||||
return response()->unprocessable('Error', ['El servicio no se encontró en nuestros registros.']);
|
||||
}
|
||||
|
||||
$servicio_det->update(['aceptado' => 1]);
|
||||
|
||||
$servicio_enc = ServicioEnc::where('id',$servicio_det->servicio_enc_id)->first();
|
||||
$usuario = User::where('id', $servicio_enc->usuario_agenda_id)->first();
|
||||
|
||||
if($usuario->token_firebase) {
|
||||
|
||||
$authorization = config('firebase')['authorization'];
|
||||
$project_id = config('firebase')['project_id'];
|
||||
$endpoint = config('firebase')['endpoint'];
|
||||
|
||||
$headers = [
|
||||
'Authorization' => 'key=' . $authorization,
|
||||
'project_id' => $project_id,
|
||||
'content-type' => 'application/json'
|
||||
];
|
||||
|
||||
$cat_servicio = CatServicio::where('id', $servicio_det->servicio_id)->first();
|
||||
|
||||
$datos = ['registration_ids' => array($usuario->token_firebase),
|
||||
'data' => ['url' => $url, 'solicitud_id' => $servicio_det->servicio_enc_id,'servicio_id' => $id, 'title' => 'Servicio Aceptado', 'body' => $cat_servicio->nombre, 'observacion' => '']];
|
||||
|
||||
$client = new Client();
|
||||
$client->post($endpoint, [
|
||||
'headers' => $headers,
|
||||
'json' => $datos,
|
||||
]);
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return response()->unprocessable('Error', ['Error al aceptar solicitud.']);
|
||||
}
|
||||
}
|
||||
|
||||
public function rechazarSolicitud(RechazarSolicitudRequest $request, $id){
|
||||
|
||||
$data = $request->all();
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
|
||||
$ambiente = strtolower(config('ambiente')['ambiente']);
|
||||
|
||||
$url = config('ambiente')[$ambiente];
|
||||
|
||||
$servicio_det = ServicioDet::where('id',$id)->first();
|
||||
|
||||
if(!$servicio_det){
|
||||
DB::rollBack();
|
||||
return response()->unprocessable('Error', ['El servicio no se encontró en nuestros registros.']);
|
||||
}
|
||||
|
||||
$servicio_det->update(['aceptado' => 0, 'operador_id' => null, 'vehiculo_id' => null, 'auxiliar_1' => null, 'auxiliar_2' => null, 'observacion' => $data['observacion']]);
|
||||
|
||||
$servicio_enc = ServicioEnc::where('id',$servicio_det->servicio_enc_id)->first();
|
||||
$usuario = User::where('id', $servicio_enc->usuario_agenda_id)->first();
|
||||
|
||||
if($usuario->token_firebase) {
|
||||
|
||||
$authorization = config('firebase')['authorization'];
|
||||
$project_id = config('firebase')['project_id'];
|
||||
$endpoint = config('firebase')['endpoint'];
|
||||
|
||||
$headers = [
|
||||
'Authorization' => 'key=' . $authorization,
|
||||
'project_id' => $project_id,
|
||||
'content-type' => 'application/json'
|
||||
];
|
||||
|
||||
$cat_servicio = CatServicio::where('id', $servicio_det->servicio_id)->first();
|
||||
|
||||
$datos = ['registration_ids' => array($usuario->token_firebase),
|
||||
'data' => ['url' => $url, 'solicitud_id' => $servicio_det->servicio_enc_id, 'servicio_id' => $id, 'title' => 'Servicio Rechazado', 'body' => $cat_servicio->nombre, 'observacion' => $data['observacion']]];
|
||||
|
||||
$client = new Client();
|
||||
$client->post($endpoint, [
|
||||
'headers' => $headers,
|
||||
'json' => $datos,
|
||||
]);
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return response()->unprocessable('Error', ['Error al rechazar solicitud.']);
|
||||
}
|
||||
}
|
||||
|
||||
public function ServiciosDiaSiguiente()
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$campos = $this->camposSolicitudesServiciosOperador();
|
||||
|
||||
$s = ServicioDet::select($campos)
|
||||
->joinDetalleServicioDet()
|
||||
->joinDetalleServicioDetMovil()
|
||||
->whereIn('servicios_det.estatus_servicio_id', [PENDIENTE, REPROGRAMADO, VISITA, PAGADO])
|
||||
->where('servicios_det.operador_id', $user->id)
|
||||
->where('servicios_enc.sucursal_id', $user->sucursal_id)
|
||||
->whereDate('servicios_det.fecha_solicitud', Carbon::tomorrow()->format('Y-m-d'))
|
||||
->get();
|
||||
|
||||
|
||||
$servicios_progresos = ServicioProgreso::select('servicio_det_id')->get();
|
||||
if(count($servicios_progresos) != 0){
|
||||
$servicios = collect($s)->whereNotIn('id',$servicios_progresos->pluck('servicio_det_id'))->all();
|
||||
}else{
|
||||
$servicios = $s;
|
||||
}
|
||||
|
||||
return response()->success($servicios);
|
||||
}
|
||||
}
|
||||
474
app/Http/Controllers/Operador/ServiciosProgresoController.php
Normal file
474
app/Http/Controllers/Operador/ServiciosProgresoController.php
Normal file
@@ -0,0 +1,474 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Operador;
|
||||
|
||||
use const App\Http\Controllers\COSTO_SERVICIO_NEGATIVO;
|
||||
use const App\Http\Controllers\NEGATIVO;
|
||||
use const App\Http\Controllers\REALIZADO;
|
||||
use App\Http\Requests\Operador\FinalizarServicioRequest;
|
||||
use App\Http\Requests\Operador\GuardarEvidenciaRequest;
|
||||
use App\Http\Requests\Operador\GuardarFirmaRequest;
|
||||
use App\Http\Requests\Operador\IniciarServicioRequest;
|
||||
use App\Mail\SolicitudServicioTerminado;
|
||||
use App\Models\Cliente;
|
||||
use App\Models\ClienteDomicilio;
|
||||
use App\Models\ServicioDet;
|
||||
use App\Models\ServicioEnc;
|
||||
use App\Models\ServicioEvidencia;
|
||||
use App\Models\ServicioProgreso;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Log;
|
||||
use Excel;
|
||||
|
||||
class ServiciosProgresoController extends Controller
|
||||
{
|
||||
/**
|
||||
* Iniciar Servicio.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function iniciarServicio(IniciarServicioRequest $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
$now = Carbon::now()->format('Y-m-d');
|
||||
$servicio = ServicioProgreso::where('servicio_enc_id', $data['servicio_enc_id'])
|
||||
->where('servicio_det_id', $data['servicio_det_id'])
|
||||
->first();
|
||||
|
||||
$servicio_det = ServicioDet::where('servicio_enc_id', $data['servicio_enc_id'])
|
||||
->where('id', $data['servicio_det_id'])
|
||||
->first();
|
||||
|
||||
list($fecha) = explode(" ", $servicio_det->fecha_solicitud);
|
||||
|
||||
//Validar fecha de solicitud
|
||||
if($now != $fecha){
|
||||
//return response()->unprocessable('Parametros inválidos',['El servicio no se puede iniciar ya que corresponde a otra fecha.']);
|
||||
}
|
||||
|
||||
//Validar que el servicio no este iniciado
|
||||
if($servicio){
|
||||
return response()->unprocessable('Parametros inválidos',['El servicio ya está iniciado.']);
|
||||
}
|
||||
$data['fecha_ini_servidor'] = Carbon::now()->toDateTimeString();
|
||||
|
||||
//Se agrego por detalle de Geolocalizacion
|
||||
$servicio_enc = ServicioEnc::select('clientes_domicilios.lat','clientes_domicilios.lng')
|
||||
->join('clientes_domicilios','servicios_enc.cliente_domicilio_id', '=','clientes_domicilios.id')
|
||||
->where('servicios_enc.id', $servicio_det->servicio_enc_id)
|
||||
->first();
|
||||
|
||||
$data['lat_ini'] = $servicio_enc->lat;
|
||||
$data['lng_ini'] = $servicio_enc->lng;
|
||||
//
|
||||
|
||||
ServicioProgreso::create($data);
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalizar Servicio.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function finalizarServicio(FinalizarServicioRequest $request)
|
||||
{
|
||||
$data = $request->only(['fecha_fin_celular', 'duracion', 'lat_fin', 'lng_fin', 'comentarios', 'aplica_garantia','litraje']);
|
||||
$cat_motivos_estatus_id = $request->input('cat_motivos_estatus_id',0);
|
||||
$now = Carbon::now();
|
||||
|
||||
$servicio_enc_id = $request->input('servicio_enc_id');
|
||||
$servicio_det_id = $request->input('servicio_det_id');
|
||||
$litraje = $request->litraje;
|
||||
|
||||
$servicio_progreso = ServicioProgreso::where('servicio_enc_id', $servicio_enc_id)
|
||||
->where('servicio_det_id', $servicio_det_id)
|
||||
->first();
|
||||
|
||||
$servicio_det = ServicioDet::where('servicio_enc_id', $servicio_enc_id)
|
||||
->where('id', $servicio_det_id)
|
||||
->first();
|
||||
$servicio = ServicioEnc::where('id', $servicio_enc_id)->first();
|
||||
|
||||
$correos = [];
|
||||
$correo_cliente = Cliente::select('email')->where('id', $servicio->cliente_id)->first();
|
||||
$correo_cliente_domicilio = ClienteDomicilio::select('email')->where('id', $servicio->cliente_domicilio_id)->first();
|
||||
|
||||
if($correo_cliente && $correo_cliente->email){
|
||||
array_push($correos, $correo_cliente->email);
|
||||
}
|
||||
if($correo_cliente_domicilio && $correo_cliente_domicilio->email){
|
||||
array_push($correos, $correo_cliente_domicilio->email);
|
||||
}
|
||||
|
||||
//Validar fecha de solicitud
|
||||
/*
|
||||
list($fecha) = explode(" ", $servicio_det->fecha_solicitud);
|
||||
|
||||
if($now->format('Y-m-d') != $fecha){
|
||||
return response()->unprocessable('Parametros inválidos',['No se puede finalizar el servicio ya que corresponde a otra fecha.']);
|
||||
}*/
|
||||
|
||||
//Validar que el servicio no este terminado
|
||||
if($servicio_det->estatus_servicio_id == REALIZADO){
|
||||
return response()->unprocessable('Parametros inválidos',['El servicio ya está terminado']);
|
||||
}
|
||||
|
||||
//Validar que el servicio esté iniciado
|
||||
if(!$servicio_progreso){
|
||||
return response()->unprocessable('Parametros inválidos',['El servicio no está iniciado.']);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$data['fecha_fin_servidor'] = $now->toDateTimeString();
|
||||
|
||||
//Se agrego por detalle de Geolocalizacion
|
||||
$servicio_enc = ServicioEnc::select('clientes_domicilios.lat','clientes_domicilios.lng')
|
||||
->join('clientes_domicilios','servicios_enc.cliente_domicilio_id', '=','clientes_domicilios.id')
|
||||
->where('servicios_enc.id', $servicio_det->servicio_enc_id)
|
||||
->first();
|
||||
$data['lat_fin'] = $servicio_enc->lat;
|
||||
$data['lng_fin'] = $servicio_enc->lng;
|
||||
if($litraje == 0){
|
||||
$data['litraje'] = null;
|
||||
}else{
|
||||
$data['litraje'] = $litraje;
|
||||
}
|
||||
|
||||
$servicio_progreso->update($data);
|
||||
if ($cat_motivos_estatus_id != 0){
|
||||
$servicio_det->update(
|
||||
[
|
||||
'estatus_servicio_id' => NEGATIVO,
|
||||
'cat_motivos_estatus_id' => $cat_motivos_estatus_id,
|
||||
'costo_servicio' => COSTO_SERVICIO_NEGATIVO,
|
||||
]
|
||||
);
|
||||
} else{
|
||||
$servicio_det->update(['estatus_servicio_id' => REALIZADO]);
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
try {
|
||||
if(count($correos) > 0){
|
||||
Mail::to($correos)->send(new SolicitudServicioTerminado($servicio_enc_id,$servicio_det_id));
|
||||
}
|
||||
}catch (\Exception $e){
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::info($e);
|
||||
return response()->unprocessable('Error', ['Error al finalizar servicio.']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Guardar Evidencia.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function guardarEvidencia(GuardarEvidenciaRequest $request)
|
||||
{
|
||||
$data = $request->only(['etapa', 'lat', 'lng', 'servicio_enc_id', 'servicio_det_id']);
|
||||
|
||||
$servicio_progreso = ServicioProgreso::where('servicio_enc_id', $data['servicio_enc_id'])
|
||||
->where('servicio_det_id', $data['servicio_det_id'])
|
||||
->first();
|
||||
|
||||
$servicio_det = ServicioDet::where('servicio_enc_id', $data['servicio_enc_id'])
|
||||
->where('id', $data['servicio_det_id'])
|
||||
->first();
|
||||
|
||||
//Validar que el servicio no este terminado
|
||||
if($servicio_det->estatus_servicio_id == REALIZADO){
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
//Validar que el servicio esté iniciado
|
||||
if(!$servicio_progreso){
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
//Validar imagen
|
||||
if (!$request->hasFile('imagen') || !$request->file('imagen')->isValid()){
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
//Validar etapa
|
||||
if($data['etapa'] != 'Inicio' && $data['etapa'] != 'Proceso' && $data['etapa'] != 'Final'){
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
$imagen = $request->imagen;
|
||||
|
||||
$uuid = $imagen->hash('sha256');
|
||||
|
||||
//Validar que la imagen no haya sido capturada
|
||||
if(ServicioEvidencia::where('uuid', $uuid)->first()){
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
|
||||
$data['uuid'] = $uuid;
|
||||
$data['servicio_progreso_id'] = $servicio_progreso->id;
|
||||
|
||||
//Se agrego por detalle de Geolocalizacion
|
||||
$servicio_enc = ServicioEnc::select('clientes_domicilios.lat','clientes_domicilios.lng')
|
||||
->join('clientes_domicilios','servicios_enc.cliente_domicilio_id', '=','clientes_domicilios.id')
|
||||
->where('servicios_enc.id', $servicio_det->servicio_enc_id)
|
||||
->first();
|
||||
$data['lat'] = $servicio_enc->lat;
|
||||
$data['lng'] = $servicio_enc->lng;
|
||||
//
|
||||
|
||||
$evidencia = ServicioEvidencia::create($data);
|
||||
|
||||
/*
|
||||
* IMAGEN
|
||||
*/
|
||||
|
||||
$nombre_img = 'solicitud_'.$data['servicio_enc_id'].'_servicio_'.$data['servicio_det_id'].'_evidencia_'.$evidencia->id.'.'.$imagen->extension();
|
||||
$imagen->storeAs('public/servicios/evidencias', $nombre_img);
|
||||
|
||||
$evidencia->update(['imagen' => $nombre_img]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::info($e);
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Guardar Evidencia.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function guardarFirmas(GuardarFirmaRequest $request)
|
||||
{
|
||||
|
||||
$data = $request->only(['servicio_enc_id', 'servicio_det_id']);
|
||||
|
||||
$servicio_progreso = ServicioProgreso::where('servicio_enc_id', $data['servicio_enc_id'])
|
||||
->where('servicio_det_id', $data['servicio_det_id'])
|
||||
->first();
|
||||
|
||||
/*
|
||||
* Validar imagen
|
||||
* Se comenta por el cambio de guardado
|
||||
*/
|
||||
if (!$request->hasFile('imagen') || !$request->file('imagen')->isValid()){
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
$imagen = $request->imagen;
|
||||
|
||||
try {
|
||||
|
||||
/*
|
||||
* IMAGEN
|
||||
*/
|
||||
|
||||
$nombre_img = 'firma_'.'solicitud_'.$data['servicio_enc_id'].'_servicio_'.$data['servicio_det_id'].'.'.$imagen->extension();
|
||||
$imagen->storeAs('public/servicios/firmas', $nombre_img);
|
||||
|
||||
$servicio_progreso->update(['firma' => $nombre_img]);
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
} catch (\Exception $e) {
|
||||
Log::info($e);
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Guardar Evidencia.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
/*public function guardarEvidencia(GuardarEvidenciaRequest $request)
|
||||
{
|
||||
$data = $request->only(['etapa', 'lat', 'lng', 'servicio_enc_id', 'servicio_det_id']);
|
||||
$imagen = $request->input('imagen');
|
||||
$now = Carbon::now()->format('Y-m-d');
|
||||
|
||||
$servicio_progreso = ServicioProgreso::where('servicio_enc_id', $data['servicio_enc_id'])
|
||||
->where('servicio_det_id', $data['servicio_det_id'])
|
||||
->first();
|
||||
|
||||
$servicio_det = ServicioDet::where('servicio_enc_id', $data['servicio_enc_id'])
|
||||
->where('id', $data['servicio_det_id'])
|
||||
->first();
|
||||
|
||||
list($fecha) = explode(" ", $servicio_det->fecha_solicitud);
|
||||
|
||||
//Validar fecha de solicitud
|
||||
if($now != $fecha){
|
||||
//return response()->unprocessable('Parametros inválidos',['No se pueden guardar evidencias ya que el servicio corresponde a otra fecha.']);
|
||||
}
|
||||
|
||||
//Validar que el servicio no este terminado
|
||||
if($servicio_det->estatus_servicio_id == REALIZADO){
|
||||
//return response()->unprocessable('Parametros inválidos',['El servicio ya está terminado']);
|
||||
|
||||
//Se agrega para que regrese la petición pero no se guarda información
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
//Validar que el servicio esté iniciado
|
||||
if(!$servicio_progreso){
|
||||
//return response()->unprocessable('Parametros inválidos',['El servicio no está iniciado.']);
|
||||
|
||||
//Se agrega para que regrese la petición pero no se guarda información
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
//Validar imagen
|
||||
//if (!$request->hasFile('imagen') || !$request->file('imagen')->isValid()){
|
||||
// return response()->unprocessable('Parametros inválidos',['Imagen invalida']);
|
||||
//}
|
||||
|
||||
//Validar etapa
|
||||
if($data['etapa'] != 'Inicio' && $data['etapa'] != 'Proceso' && $data['etapa'] != 'Final'){
|
||||
//return response()->unprocessable('Parametros inválidos',['El valor etapa no es valido']);
|
||||
|
||||
//Se agrega para que regrese la petición pero no se guarda información
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
//$imagen = $request->imagen;
|
||||
|
||||
//$uuid = hash_file('sha256', $imagen);
|
||||
|
||||
//Validar que la imagen no haya sido capturada
|
||||
//if(ServicioEvidencia::where('uuid', $uuid)->first()){
|
||||
return response()->unprocessable('Parametros inválidos',['La imagen ya fue capturada']);
|
||||
//}
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
|
||||
$data['uuid'] = hash('sha256', $imagen);
|
||||
$data['servicio_progreso_id'] = $servicio_progreso->id;
|
||||
|
||||
//Se agrego por detalle de Geolocalizacion
|
||||
$servicio_enc = ServicioEnc::select('clientes_domicilios.lat','clientes_domicilios.lng')
|
||||
->join('clientes_domicilios','servicios_enc.cliente_domicilio_id', '=','clientes_domicilios.id')
|
||||
->where('servicios_enc.id', $servicio_det->servicio_enc_id)
|
||||
->first();
|
||||
$data['lat'] = $servicio_enc->lat;
|
||||
$data['lng'] = $servicio_enc->lng;
|
||||
//
|
||||
|
||||
$evidencia = ServicioEvidencia::create($data);
|
||||
|
||||
//$nombre_img = 'solicitud_'.$data['servicio_enc_id'].'_servicio_'.$data['servicio_det_id'].'_evidencia_'.$evidencia->id.'.'.$imagen->extension();
|
||||
//$imagen->storeAs('public/servicios/evidencias', $nombre_img);
|
||||
|
||||
$nombre_img = 'solicitud_'.$data['servicio_enc_id'].'_servicio_'.$data['servicio_det_id'].'_evidencia_'.$evidencia->id.'.jpeg';
|
||||
Storage::disk('public')->put('servicios/evidencias/' . $nombre_img, $this->base64ToImage($imagen), 'public');
|
||||
|
||||
$evidencia->update(['imagen' => $nombre_img]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::info($e);
|
||||
return response()->unprocessable('Error', ['Error al guardar la evidencia.']);
|
||||
}
|
||||
}
|
||||
|
||||
public function guardarFirmas(GuardarFirmaRequest $request)
|
||||
{
|
||||
|
||||
$data = $request->only(['servicio_enc_id', 'servicio_det_id']);
|
||||
|
||||
$servicio_progreso = ServicioProgreso::where('servicio_enc_id', $data['servicio_enc_id'])
|
||||
->where('servicio_det_id', $data['servicio_det_id'])
|
||||
->first();
|
||||
|
||||
// $now = Carbon::now()->format('Y-m-d');
|
||||
//
|
||||
// $servicio_det = ServicioDet::where('servicio_enc_id', $data['servicio_enc_id'])
|
||||
// ->where('id', $data['servicio_det_id'])
|
||||
// ->first();
|
||||
//
|
||||
// list($fecha) = explode(" ", $servicio_det->fecha_solicitud);
|
||||
//
|
||||
// //Validar fecha de solicitud
|
||||
// if($now != $fecha){
|
||||
// return response()->unprocessable('Parametros inválidos',['No se pueden guardar evidencias ya que el servicio corresponde a otra fecha.']);
|
||||
// }
|
||||
//
|
||||
// //Validar que el servicio no este terminado
|
||||
// if($servicio_det->estatus_servicio_id == REALIZADO){
|
||||
// return response()->unprocessable('Parametros inválidos',['El servicio ya está terminado']);
|
||||
// }
|
||||
//
|
||||
// //Validar que el servicio esté iniciado
|
||||
// if(!$servicio_progreso){
|
||||
// return response()->unprocessable('Parametros inválidos',['El servicio no está iniciado.']);
|
||||
// }
|
||||
|
||||
// if (!$request->hasFile('imagen') || !$request->file('imagen')->isValid()){
|
||||
// return response()->unprocessable('Parametros inválidos',['Imagen invalida']);
|
||||
// }
|
||||
|
||||
$imagen = $request->input('imagen');
|
||||
|
||||
try {
|
||||
|
||||
// $nombre_img = 'firma_'.'solicitud_'.$data['servicio_enc_id'].'_servicio_'.$data['servicio_det_id'].'.'.$imagen->extension();
|
||||
// $imagen->storeAs('public/servicios/firmas', $nombre_img);
|
||||
|
||||
$nombre_img = 'firma_'.'solicitud_'.$data['servicio_enc_id'].'_servicio_'.$data['servicio_det_id'].'.jpeg';
|
||||
Storage::disk('public')->put('servicios/firmas/' . $nombre_img, $this->base64ToImage($imagen), 'public');
|
||||
|
||||
$servicio_progreso->update(['firma' => $nombre_img]);
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
} catch (\Exception $e) {
|
||||
Log::info($e);
|
||||
return response()->unprocessable('Error', ['Error al guardar la firma.']);
|
||||
}
|
||||
}*/
|
||||
|
||||
public function verificarServicio(Request $request){
|
||||
|
||||
$servicios_id = $request->all();
|
||||
|
||||
$servicios = array();
|
||||
foreach ($servicios_id as $s){
|
||||
$servicio_det = ServicioDet::find($s);
|
||||
|
||||
if($servicio_det && $servicio_det->estatus_servicio_id == REALIZADO){
|
||||
array_push($servicios,['servicio_id' => $s]);
|
||||
}
|
||||
}
|
||||
|
||||
return response()->success($servicios);
|
||||
}
|
||||
}
|
||||
294
app/Http/Controllers/Operador/ServiciosProgresoNewController.php
Normal file
294
app/Http/Controllers/Operador/ServiciosProgresoNewController.php
Normal file
@@ -0,0 +1,294 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Operador;
|
||||
|
||||
use App\Mail\SolicitudServicioTerminadoNew;
|
||||
use App\Models\Cliente;
|
||||
use App\Models\ClienteDomicilio;
|
||||
use App\Models\RespuestaDomestico;
|
||||
use App\Models\RespuestaEmpresarial;
|
||||
use App\Models\ServicioDet;
|
||||
use App\Models\ServicioEnc;
|
||||
use App\Models\ServicioEncuestaDomestico;
|
||||
use App\Models\ServicioEncuestaEmpresarial;
|
||||
use App\Models\ServicioEvidencia;
|
||||
use App\Models\ServicioProgreso;
|
||||
use App\Models\Sucursal;
|
||||
use Carbon\Carbon;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use const App\Http\Controllers\COSTO_SERVICIO_NEGATIVO;
|
||||
use const App\Http\Controllers\DEFAULT_PATH_ZIP_EVIDENCES;
|
||||
use const App\Http\Controllers\DOMESTICO;
|
||||
use const App\Http\Controllers\NEGATIVO;
|
||||
use const App\Http\Controllers\REALIZADO;
|
||||
use Log;
|
||||
|
||||
class ServiciosProgresoNewController extends Controller
|
||||
{
|
||||
/**
|
||||
* Finalizar Servicio.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function finalizarServicio(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
$finalizar_servicio_data = $request->only(['fecha_fin_celular', 'duracion', 'lat_fin', 'lng_fin', 'comentarios', 'aplica_garantia','litraje']);
|
||||
$cat_motivos_estatus_id = $request->input('cat_motivos_estatus_id',0);
|
||||
$now = Carbon::now();
|
||||
|
||||
$servicio_enc_id = $request->input('servicio_enc_id');
|
||||
$servicio_det_id = $request->input('servicio_det_id');
|
||||
|
||||
$litraje = $request->input('litraje', null);
|
||||
|
||||
$servicio_progreso = ServicioProgreso::where('servicio_enc_id', $servicio_enc_id)
|
||||
->where('servicio_det_id', $servicio_det_id)
|
||||
->first();
|
||||
|
||||
$servicio_det = ServicioDet::where('servicio_enc_id', $servicio_enc_id)
|
||||
->where('id', $servicio_det_id)
|
||||
->first();
|
||||
$servicio = ServicioEnc::where('id', $servicio_enc_id)->first();
|
||||
|
||||
$correos = [];
|
||||
$correo_cliente = Cliente::select('email')->where('id', $servicio->cliente_id)->first();
|
||||
$correo_cliente_domicilio = ClienteDomicilio::select('email')->where('id', $servicio->cliente_domicilio_id)->first();
|
||||
|
||||
if($correo_cliente && $correo_cliente->email){
|
||||
$correos[] = $correo_cliente->email;
|
||||
}
|
||||
if($correo_cliente_domicilio && $correo_cliente_domicilio->email){
|
||||
$correos[] = $correo_cliente_domicilio->email;
|
||||
}
|
||||
|
||||
//Validar que el servicio no este terminado
|
||||
if($servicio_det->estatus_servicio_id == REALIZADO){
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
//Validar que el servicio esté iniciado
|
||||
if(!$servicio_progreso){
|
||||
return response()->unprocessable('Parametros inválidos',['El servicio no está iniciado.']);
|
||||
}
|
||||
|
||||
if (!$recibo = $request->input('recibo')){
|
||||
return response()->unprocessable('Parametros inválidos',['No se ha podido generar el recibo.']);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
|
||||
//ENCUESTA
|
||||
if($encuesta = $request->input('encuesta')){
|
||||
$this->encuesta($encuesta, $servicio_det_id);
|
||||
$finalizar_servicio_data['encuesta_contestada'] = 1;
|
||||
}
|
||||
//
|
||||
|
||||
$finalizar_servicio_data['fecha_fin_servidor'] = $now->toDateTimeString();
|
||||
|
||||
//Se agrego por detalle de Geolocalizacion
|
||||
$servicio_enc = ServicioEnc::select('clientes_domicilios.lat','clientes_domicilios.lng')
|
||||
->join('clientes_domicilios','servicios_enc.cliente_domicilio_id', '=','clientes_domicilios.id')
|
||||
->where('servicios_enc.id', $servicio_det->servicio_enc_id)
|
||||
->first();
|
||||
$finalizar_servicio_data['lat_fin'] = $servicio_enc->lat;
|
||||
$finalizar_servicio_data['lng_fin'] = $servicio_enc->lng;
|
||||
$finalizar_servicio_data['litraje'] = ($litraje == 0)? null: $litraje;
|
||||
|
||||
$costo_servicio_negativo = Sucursal::select('costo_negativo')->where('sucursales.id', $user->sucursal_id)->get();
|
||||
|
||||
$servicio_progreso->update($finalizar_servicio_data);
|
||||
if ($cat_motivos_estatus_id != 0){
|
||||
$servicio_det->update(
|
||||
[
|
||||
'estatus_servicio_id' => NEGATIVO,
|
||||
'cat_motivos_estatus_id' => $cat_motivos_estatus_id,
|
||||
'costo_servicio' => $costo_servicio_negativo,
|
||||
]
|
||||
);
|
||||
} else{
|
||||
$servicio_det->update(['estatus_servicio_id' => REALIZADO]);
|
||||
}
|
||||
|
||||
$recibo = base64_decode($recibo);
|
||||
$nombre = 'solicitud_' . $servicio_enc_id . '_servicio_' . $servicio_det_id . '.pdf';
|
||||
Storage::disk('public')->put('servicios/recibos_pdf/' . $nombre, $recibo);
|
||||
|
||||
DB::commit();
|
||||
|
||||
try {
|
||||
$ambiente = strtolower(config('ambiente')['ambiente']);
|
||||
if(count($correos) > 0 && $ambiente == 'dev'){
|
||||
try {
|
||||
Mail::to($correos)->send(new SolicitudServicioTerminadoNew($servicio_enc_id,$servicio_det_id, $nombre));
|
||||
} catch (\Exception $e) {
|
||||
\Log::info("Error al enviar correo: " . json_encode($e->getMessage()));
|
||||
}
|
||||
}
|
||||
}catch (\Exception $e){
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
return response()->success(['result' => 'ok']);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::info($e);
|
||||
return response()->unprocessable('Error', ['Error al finalizar servicio.']);
|
||||
}
|
||||
}
|
||||
|
||||
public function encuesta($data, $servicio_id)
|
||||
{
|
||||
$servicio_det = ServicioDet::where('id', $servicio_id)->firstOrFail();
|
||||
|
||||
if($servicio_det->tipo_servicio_id == DOMESTICO) {
|
||||
$validator = Validator::make($data, [
|
||||
'*.pregunta_id' => 'numeric|exists:preguntas_domestico,id',
|
||||
'*.respuesta_id' => 'numeric|exists:respuestas_domestico,id',
|
||||
'*.respuesta' => 'string|max:255'
|
||||
]);
|
||||
|
||||
if(ServicioEncuestaDomestico::where('servicio_det_id', $servicio_id)->first()){
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($data as $d){
|
||||
if(isset($d['respuesta_id'])){
|
||||
$respuesta = RespuestaDomestico::where('pregunta_id', $d['pregunta_id'])
|
||||
->where('id', $d['respuesta_id'])
|
||||
->first();
|
||||
|
||||
if(!$respuesta){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$validator = Validator::make($data, [
|
||||
'*.pregunta_id' => 'numeric|exists:preguntas_empresarial,id',
|
||||
'*.respuesta_id' => 'numeric|exists:respuestas_empresarial,id',
|
||||
'*.respuesta' => 'string|max:255'
|
||||
]);
|
||||
|
||||
if(ServicioEncuestaEmpresarial::where('servicio_det_id', $servicio_id)->first()){
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($data as $d){
|
||||
if(isset($d['respuesta_id'])){
|
||||
$respuesta = RespuestaEmpresarial::where('pregunta_id', $d['pregunta_id'])
|
||||
->where('id', $d['respuesta_id'])
|
||||
->first();
|
||||
|
||||
if(!$respuesta){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($validator->fails()){
|
||||
return false;
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
if($servicio_det->tipo_servicio_id == DOMESTICO) {
|
||||
foreach ($data as $d){
|
||||
|
||||
$data_domestico = [
|
||||
'servicio_det_id' => $servicio_id,
|
||||
'pregunta_id' => $d['pregunta_id'],
|
||||
'respuesta_id' => (isset($d['respuesta_id']))? $d['respuesta_id'] : null,
|
||||
'respuesta' => (isset($d['respuesta']))? $d['respuesta'] : null
|
||||
];
|
||||
ServicioEncuestaDomestico::create($data_domestico);
|
||||
}
|
||||
|
||||
}else{
|
||||
foreach ($data as $d){
|
||||
$data_empresarial = [
|
||||
'servicio_det_id' => $servicio_id,
|
||||
'pregunta_id' => $d['pregunta_id'],
|
||||
'respuesta_id' => (isset($d['respuesta_id']))? $d['respuesta_id'] : null,
|
||||
'respuesta' => (isset($d['respuesta']))? $d['respuesta'] : null
|
||||
];
|
||||
ServicioEncuestaEmpresarial::create($data_empresarial);
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function saveEvidence($evidencia, $servicio_enc_id, $servicio_det_id, $servicio_progreso_id){
|
||||
$image = storage_path(DEFAULT_PATH_ZIP_EVIDENCES.$evidencia['nombre']);
|
||||
|
||||
if(file_exists($image)){
|
||||
$data['uuid'] = hash_file('sha256', $image);
|
||||
|
||||
if(ServicioEvidencia::where('uuid', $data['uuid'])->first()){
|
||||
unlink($image);
|
||||
return false;
|
||||
}
|
||||
|
||||
//Se agrego por detalle de Geolocalizacion
|
||||
$servicio_enc = ServicioEnc::select('clientes_domicilios.lat','clientes_domicilios.lng')
|
||||
->join('clientes_domicilios','servicios_enc.cliente_domicilio_id', '=','clientes_domicilios.id')
|
||||
->where('servicios_enc.id', $servicio_enc_id)
|
||||
->first();
|
||||
|
||||
$data['lat'] = $servicio_enc->lat;
|
||||
$data['lng'] = $servicio_enc->lng;
|
||||
$data['servicio_progreso_id'] = $servicio_progreso_id;
|
||||
$data['etapa'] = $evidencia['etapa'];
|
||||
|
||||
$evidence = ServicioEvidencia::create($data);
|
||||
$nombre_img = 'solicitud_'.$servicio_enc_id.'_servicio_'.$servicio_det_id.'_evidencia_'.$evidence->id.'.jpg';
|
||||
rename($image, storage_path("app/public/servicios/evidencias/$nombre_img"));
|
||||
$evidence->update(['imagen' => $nombre_img]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function saveEvidenceImage($pathFile, Collection $collect_evidencias, $servicio_enc_id, $servicio_det_id, $servicio_progreso_id){
|
||||
$zip = new \ZipArchive;
|
||||
$pathInfo = pathinfo(realpath($pathFile), PATHINFO_DIRNAME);
|
||||
if($zip->open($pathFile)){
|
||||
if($zip->extractTo($pathInfo)){
|
||||
for($i=0;$i<$zip->numFiles;++$i){
|
||||
$stat = $zip->statIndex($i);
|
||||
if($evidencia = $collect_evidencias->where('nombre', '=', basename($stat['name']))->first())
|
||||
$this->saveEvidence($evidencia, $servicio_enc_id, $servicio_det_id, $servicio_progreso_id);
|
||||
}
|
||||
}
|
||||
$zip->close();
|
||||
unlink($pathFile);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function saveSignature($base64_firma, $servicio_enc_id, $servicio_det_id, $servicio_progreso){
|
||||
$nombre_img = 'firma_'.'solicitud_'.$servicio_enc_id.'_servicio_'.$servicio_det_id.'.jpg';
|
||||
Storage::disk('public')->put('servicios/firmas/' . $nombre_img, $this->base64ToImage($base64_firma), 'public');
|
||||
$servicio_progreso->update(['firma' => $nombre_img]);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Operador;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Operador\UltimaIncidenciaRequest;
|
||||
use App\Http\Requests\Operador\VehiculosIncidenciasRequest;
|
||||
use App\Models\BitacoraLaboral;
|
||||
use App\Models\VehiculoIncidencia;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class VehiculosIncidenciasController extends Controller
|
||||
{
|
||||
public function ultimaIncidencia(UltimaIncidenciaRequest $request)
|
||||
{
|
||||
$vehiculo_id = $request->input('vehiculo_id');
|
||||
|
||||
$incidencia = VehiculoIncidencia::where('vehiculo_id', $vehiculo_id)
|
||||
->latest()
|
||||
->first();
|
||||
|
||||
if ($incidencia && !$incidencia->resuelta) {
|
||||
return response()->success($incidencia);
|
||||
} else {
|
||||
return response()->success(null);
|
||||
}
|
||||
}
|
||||
|
||||
public function store(VehiculosIncidenciasRequest $request)
|
||||
{
|
||||
$data = $request->only('vehiculo_id', 'descripcion');
|
||||
$user_id = Auth::id();
|
||||
|
||||
$bitacora_laboral = BitacoraLaboral::where('usuario_id', $user_id)
|
||||
->latest()
|
||||
->first();;
|
||||
|
||||
VehiculoIncidencia::create([
|
||||
'vehiculo_id' => $bitacora_laboral->vehiculo_id,
|
||||
'user_id' => $user_id,
|
||||
'descripcion' => $data['descripcion'],
|
||||
]);
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
public function resolver($id)
|
||||
{
|
||||
$incidencia = VehiculoIncidencia::findOrfail($id);
|
||||
|
||||
$incidencia->update([
|
||||
'resuelta' => true
|
||||
]);
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
}
|
||||
409
app/Http/Controllers/Reportes/CapacidadAprovechadaController.php
Normal file
409
app/Http/Controllers/Reportes/CapacidadAprovechadaController.php
Normal file
@@ -0,0 +1,409 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Reportes;
|
||||
|
||||
use App\Http\Requests\Reportes\CapacidadAprovechadaRequest;
|
||||
use App\Http\Requests\Reportes\ConsultarVehiculosRequest;
|
||||
use App\Models\ServicioDet;
|
||||
use App\Models\Vehiculo;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use DB;
|
||||
use Excel;
|
||||
|
||||
class CapacidadAprovechadaController extends Controller
|
||||
{
|
||||
public function consultarVehiculos(ConsultarVehiculosRequest $request){
|
||||
|
||||
$sucursal = $request->input('sucursal');
|
||||
$fecha_inicio = $request->input('fecha_inicio');
|
||||
$fecha_final = $request->input('fecha_final');
|
||||
|
||||
$orderBy = $request->input('sortBy','id');
|
||||
$order = $request->input('order','asc');
|
||||
|
||||
$queryBuilder = Vehiculo::select('id', 'num_economico')
|
||||
->join('vehiculos_sucursales', 'cat_vehiculos.id', '=', 'vehiculos_sucursales.vehiculo_id')
|
||||
->where('vehiculos_sucursales.sucursal_id', $sucursal)
|
||||
->orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('num_economico','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
|
||||
$data = $queryBuilder->paginate($perPage);
|
||||
foreach ($data->items() as $v){
|
||||
$v->servicios_cantidad = ServicioDet::where('servicios_det.vehiculo_id', $v->id)
|
||||
->whereDate('servicios_det.fecha_solicitud','>=',$fecha_inicio)
|
||||
->whereDate('servicios_det.fecha_solicitud','<=',$fecha_final)
|
||||
->count();
|
||||
}
|
||||
|
||||
$vehiculos = $data;
|
||||
}else{
|
||||
|
||||
$data = $queryBuilder->get();
|
||||
foreach ($data as $v){
|
||||
$v->servicios_cantidad = ServicioDet::where('servicios_det.vehiculo_id', $v->id)
|
||||
->whereDate('servicios_det.fecha_solicitud','>=',$fecha_inicio)
|
||||
->whereDate('servicios_det.fecha_solicitud','<=',$fecha_final)
|
||||
->count();
|
||||
}
|
||||
|
||||
$vehiculos = ['data'=>$data];
|
||||
}
|
||||
|
||||
return response()->success($vehiculos);
|
||||
}
|
||||
|
||||
public function reportes(CapacidadAprovechadaRequest $request){
|
||||
|
||||
$orderBy = $request->input('sortBy','servicios_enc.id');
|
||||
$order = $request->input('order','asc');
|
||||
|
||||
$sucursal = $request->input('sucursal');
|
||||
$fecha_inicio = $request->input('fecha_inicio');
|
||||
$fecha_final = $request->input('fecha_final');
|
||||
$vehiculo_id = $request->input('vehiculo_id');
|
||||
|
||||
$campos = [
|
||||
'servicios_enc.id as numero_solicitud',
|
||||
DB::raw("DATE(servicios_det.fecha_solicitud) as 'fecha_servicio'"),
|
||||
DB::raw("TIME(servicios_det.fecha_solicitud) as 'hora_servicio'"),
|
||||
'cat_servicios.nombre as servicio',
|
||||
'servicios_det.costo_servicio as costo',
|
||||
'cat_tipos_servicios.nombre as tipo_servicio',
|
||||
'cat_estatus_servicios.nombre as estatus_servicio',
|
||||
'clientes.denominacion as nombre_cliente',
|
||||
'clientes_domicilios.calle as calle_cliente',
|
||||
'clientes_domicilios.entre_calles as entre_calles_cliente',
|
||||
'clientes_domicilios.num_ext as num_ext_cliente',
|
||||
'clientes_domicilios.num_int as num_int_cliente',
|
||||
'clientes_domicilios.colonia as colonia_cliente',
|
||||
'clientes_domicilios.ciudad as ciudad_cliente',
|
||||
'clientes_domicilios.cp as cp_cliente',
|
||||
'asesor.nombre as nombre_asesor',
|
||||
'asesor.apellido_paterno as apellido_paterno_asesor',
|
||||
'asesor.apellido_materno as apellido_materno_asesor',
|
||||
'auxiliar.nombre as nombre_auxiliar',
|
||||
'auxiliar.apellido_paterno as apellido_paterno_auxiliar',
|
||||
'auxiliar.apellido_materno as apellido_materno_auxiliar',
|
||||
'servicios_progreso.duracion as duracion_servicio'
|
||||
];
|
||||
|
||||
$queryBuilder = ServicioDet::select($campos)
|
||||
->join('servicios_enc', 'servicios_det.servicio_enc_id', '=', 'servicios_enc.id')
|
||||
->join('cat_servicios', 'servicios_det.servicio_id', '=', 'cat_servicios.id')
|
||||
->join('cat_tipos_servicios', 'servicios_det.tipo_servicio_id', '=', 'cat_tipos_servicios.id')
|
||||
->join('cat_estatus_servicios','servicios_det.estatus_servicio_id','=','cat_estatus_servicios.id')
|
||||
->join('clientes','servicios_enc.cliente_id','=','clientes.id')
|
||||
->join('clientes_domicilios','servicios_enc.cliente_domicilio_id','=','clientes_domicilios.id')
|
||||
->join('users as asesor', 'servicios_det.operador_id', '=', 'asesor.id')
|
||||
->leftJoin('users as auxiliar', 'servicios_det.auxiliar_1', '=', 'auxiliar.id')
|
||||
->leftJoin('servicios_progreso', 'servicios_det.id', '=', 'servicios_progreso.servicio_det_id')
|
||||
->where('servicios_enc.sucursal_id', $sucursal)
|
||||
->where('servicios_det.vehiculo_id', $vehiculo_id)
|
||||
->whereDate('servicios_det.fecha_solicitud','>=',$fecha_inicio)
|
||||
->whereDate('servicios_det.fecha_solicitud','<=',$fecha_final)
|
||||
->orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
//$q->where('nombre','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
$total_servicios = $queryBuilder->count();
|
||||
$total_costo = $queryBuilder->sum('servicios_det.costo_servicio');
|
||||
$total_duracion = $this->sumarTiempos($queryBuilder->pluck('duracion_servicio'));
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$data = $queryBuilder->paginate($perPage)->toArray();
|
||||
}else{
|
||||
$data = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
$data['total_servicios'] = $total_servicios;
|
||||
$data['total_costo'] = $total_costo;
|
||||
list($h,$m,$s) = explode(':',$total_duracion);
|
||||
$data['total_duracion'] = $h."hr ".$m."m ".$s."s";
|
||||
|
||||
return response()->success($data);
|
||||
}
|
||||
|
||||
public function generarExcel(CapacidadAprovechadaRequest $request){
|
||||
|
||||
$sucursal = $request->input('sucursal');
|
||||
$fecha_inicio = $request->input('fecha_inicio');
|
||||
$fecha_final = $request->input('fecha_final');
|
||||
$vehiculo_id = $request->input('vehiculo_id');
|
||||
|
||||
$campos = [
|
||||
'servicios_enc.id as numero_solicitud',
|
||||
DB::raw("DATE(servicios_det.fecha_solicitud) as 'fecha_servicio'"),
|
||||
DB::raw("TIME(servicios_det.fecha_solicitud) as 'hora_servicio'"),
|
||||
'cat_servicios.nombre as servicio',
|
||||
'servicios_det.costo_servicio as costo',
|
||||
'cat_tipos_servicios.nombre as tipo_servicio',
|
||||
'cat_estatus_servicios.nombre as estatus_servicio',
|
||||
'clientes.denominacion as nombre_cliente',
|
||||
DB::raw("CONCAT(clientes_domicilios.calle,' ',clientes_domicilios.num_ext,' ', clientes_domicilios.colonia,' ',clientes_domicilios.cp,' ',clientes_domicilios.ciudad) as domicilio"),
|
||||
DB::raw("CONCAT(asesor.nombre,' ',asesor.apellido_paterno,' ',asesor.apellido_materno) as asesor"),
|
||||
DB::raw("CONCAT(auxiliar.nombre,' ',auxiliar.apellido_paterno,' ',auxiliar.apellido_materno) as auxiliar"),
|
||||
'servicios_progreso.duracion as duracion_servicio'
|
||||
];
|
||||
|
||||
$queryBuilder = ServicioDet::select($campos)
|
||||
->join('servicios_enc', 'servicios_det.servicio_enc_id', '=', 'servicios_enc.id')
|
||||
->join('cat_servicios', 'servicios_det.servicio_id', '=', 'cat_servicios.id')
|
||||
->join('cat_tipos_servicios', 'servicios_det.tipo_servicio_id', '=', 'cat_tipos_servicios.id')
|
||||
->join('cat_estatus_servicios','servicios_det.estatus_servicio_id','=','cat_estatus_servicios.id')
|
||||
->join('clientes','servicios_enc.cliente_id','=','clientes.id')
|
||||
->join('clientes_domicilios','servicios_enc.cliente_domicilio_id','=','clientes_domicilios.id')
|
||||
->join('users as asesor', 'servicios_det.operador_id', '=', 'asesor.id')
|
||||
->leftJoin('users as auxiliar', 'servicios_det.auxiliar_1', '=', 'auxiliar.id')
|
||||
->leftJoin('servicios_progreso', 'servicios_det.id', '=', 'servicios_progreso.servicio_det_id')
|
||||
->where('servicios_enc.sucursal_id', $sucursal)
|
||||
->where('servicios_det.vehiculo_id', $vehiculo_id)
|
||||
->whereDate('servicios_det.fecha_solicitud','>=',$fecha_inicio)
|
||||
->whereDate('servicios_det.fecha_solicitud','<=',$fecha_final)
|
||||
->orderBy('servicios_enc.id','asc');
|
||||
|
||||
$servicios = $queryBuilder->get();
|
||||
$total = $queryBuilder->count();
|
||||
$total_costo = $queryBuilder->sum('servicios_det.costo_servicio');
|
||||
$duracion = $this->sumarTiempos($queryBuilder->pluck('duracion_servicio'));
|
||||
list($h,$m,$s) = explode(':',$duracion);
|
||||
$total_duracion = $h."hr ".$m."m ".$s."s";
|
||||
|
||||
$vehiculo = Vehiculo::select('num_economico', 'cat_tipos_vehiculos.nombre as tipo_vehiculo')
|
||||
->join('cat_tipos_vehiculos', 'cat_vehiculos.tipo_vehiculo_id', '=', 'cat_tipos_vehiculos.id')
|
||||
->where('cat_vehiculos.id', $vehiculo_id)
|
||||
->first();
|
||||
|
||||
$titulo = "Reporte Capacidad Aprovechada ".$vehiculo->num_economico."_".$vehiculo->tipo_vehiculo;
|
||||
|
||||
list($y_i, $m_i, $d_i) = explode("-", $fecha_inicio);
|
||||
list($y_f, $m_f, $d_f) = explode("-", $fecha_final);
|
||||
$f_i = $d_i."_".$m_i."_".$y_i;
|
||||
$f_f = $d_f."_".$m_f."_".$y_f;
|
||||
$nombre = "Reporte_Capacidad_Aprovechada_".$vehiculo->num_economico."_".$vehiculo->tipo_vehiculo."_".$f_i."-".$f_f;
|
||||
|
||||
foreach ($servicios as $s){
|
||||
$s->costo = floatval($s->costo);
|
||||
list($y, $m, $d) = explode("-", $s->fecha_servicio);
|
||||
$s->fecha_servicio = "$d/$m/$y";
|
||||
$s->numero_solicitud = (int)$s->numero_solicitud;
|
||||
}
|
||||
|
||||
Excel::create($nombre, function($excel) use($servicios, $titulo, $fecha_inicio, $fecha_final, $total, $total_costo, $total_duracion){
|
||||
|
||||
// Set the title
|
||||
$excel->setTitle('Reporte de Servicios de Cliente');
|
||||
|
||||
// Chain the setters
|
||||
$excel->setCreator('DRENAX')
|
||||
->setCompany('DRENAX');
|
||||
|
||||
// Call them separately
|
||||
$excel->setDescription('Reporte de Servicios de Cliente');
|
||||
|
||||
$excel->sheet('Reporte_Capacidad_Aprovechada', function ($sheet) use($servicios, $titulo, $fecha_inicio, $fecha_final, $total, $total_costo, $total_duracion) {
|
||||
|
||||
$sheet->setColumnFormat(array(
|
||||
'F' => '"$"#,##0.00_-',
|
||||
'C' => 'd/m/y',
|
||||
'L8' => '"$"#,##0.00_-'
|
||||
));
|
||||
|
||||
//Mostrar logo
|
||||
$sheet->mergeCells('B2:D6');
|
||||
|
||||
$objDrawing = new \PHPExcel_Worksheet_Drawing;
|
||||
$objDrawing->setPath(resource_path('assets/images/logos').'/logo_drenax.png');
|
||||
$objDrawing->setWidth(95);
|
||||
$objDrawing->setHeight(80);
|
||||
$objDrawing->setCoordinates('B2');
|
||||
$objDrawing->setOffsetX(9);
|
||||
$objDrawing->setOffsetY(9);
|
||||
$objDrawing->setWorksheet($sheet);
|
||||
|
||||
$sheet->mergeCells('G2:J6');
|
||||
|
||||
$sheet->cell('G2', function($cell) use($titulo) {
|
||||
|
||||
$cell->setFontFamily('Aharoni');
|
||||
$cell->setFontWeight('bold');
|
||||
$cell->setAlignment('center');
|
||||
$cell->setValignment('center');
|
||||
$cell->setFontSize(20);
|
||||
$cell->setValue($titulo);
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('H8', function($cell) use($fecha_inicio) {
|
||||
list($y, $m, $d) = explode("-", $fecha_inicio);
|
||||
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue('Del: '.$d.'/'.$m.'/'.$y);
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('I8', function($cell) use($fecha_final) {
|
||||
list($y, $m, $d) = explode("-", $fecha_final);
|
||||
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue('Al: '.$d.'/'.$m.'/'.$y);
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('K7', function($cell) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue('Total en Horas de servicio:');
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('K8', function($cell) use($total_duracion) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue($total_duracion);
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('L7', function($cell) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue('Total en Costos del servicio:');
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('L8', function($cell) use($total_costo) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue($total_costo);
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('M7', function($cell) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue('Total:');
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('M8', function($cell) use($total) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue($total.' Servicios');
|
||||
|
||||
});
|
||||
|
||||
//Mostar valores de consulta
|
||||
$sheet->fromArray($servicios, null, 'B9', true);
|
||||
|
||||
//Formato en columnas de titulo
|
||||
$sheet->cells('B9:M9', function ($cells) {
|
||||
$cells->setBackground('#001870');
|
||||
$cells->setFontColor('#ffffff');
|
||||
$cells->setFontSize(13);
|
||||
$cells->setFontFamily('Calibri');
|
||||
$cells->setAlignment('left');
|
||||
$cells->setFontWeight('bold');
|
||||
});
|
||||
|
||||
$sheet->getStyle('B9:M9' , $sheet->getHighestRow())->getAlignment()->setWrapText(true);
|
||||
|
||||
//Titulos personalizados
|
||||
$titulos_cell = [
|
||||
['cell' => 'B9', 'titulo' => 'Número de solicitud'],
|
||||
['cell' => 'C9', 'titulo' => 'Fecha del servicio'],
|
||||
['cell' => 'D9', 'titulo' => 'Hora del servicio'],
|
||||
['cell' => 'E9', 'titulo' => 'Servicio'],
|
||||
['cell' => 'F9', 'titulo' => 'Costo de servicio'],
|
||||
['cell' => 'G9', 'titulo' => 'Tipo de servicio'],
|
||||
['cell' => 'H9', 'titulo' => 'Estatus de servicio'],
|
||||
['cell' => 'I9', 'titulo' => 'Nombre del cliente'],
|
||||
['cell' => 'J9', 'titulo' => 'Domicilio de servicio'],
|
||||
['cell' => 'K9', 'titulo' => 'Asesor de operaciones'],
|
||||
['cell' => 'L9', 'titulo' => 'Auxiliar de operaciones'],
|
||||
['cell' => 'M9', 'titulo' => 'Duración del servicio (cronómetro)']
|
||||
];
|
||||
|
||||
foreach ($titulos_cell as $t){
|
||||
$sheet->cell($t['cell'], function($cell) use($t) {
|
||||
$cell->setValue($t['titulo']);
|
||||
});
|
||||
}
|
||||
|
||||
//Size a columnas indicadas
|
||||
$columns_set = [
|
||||
'B9', 'C9', 'D9', 'M9'
|
||||
];
|
||||
|
||||
foreach ($columns_set as $c){
|
||||
$set_column = [
|
||||
$c => [
|
||||
'width' => ($c == 'M9')? 23: 14,
|
||||
'height' => 40
|
||||
]
|
||||
];
|
||||
$sheet->setSize($set_column);
|
||||
}
|
||||
|
||||
//AutoSize en columnas indicadas
|
||||
$columns_auto= [
|
||||
'E','F','G','H','I','J','K', 'L'
|
||||
];
|
||||
|
||||
foreach ($columns_auto as $c){
|
||||
$sheet->getColumnDimension($c)->setAutoSize(true);
|
||||
}
|
||||
|
||||
$sheet->setWidth(array(
|
||||
'A' => 3,
|
||||
));
|
||||
|
||||
//Borde
|
||||
$columns_border= [
|
||||
'B','C','D','E','F','G','H','I','J','K','L','M'
|
||||
];
|
||||
|
||||
for ($i=0; $i<= $total; $i++){
|
||||
$row = 9 + $i;
|
||||
|
||||
foreach ($columns_border as $cb){
|
||||
$border = "$cb$row:$cb$row";
|
||||
$sheet->cells($border, function ($cells) {
|
||||
$cells->setBorder('thin', 'thin', 'thin', 'thin');
|
||||
});
|
||||
|
||||
if($row != 9 && ($cb == 'C' || $cb == 'D' || $cb == 'F' || $cb == 'N')){
|
||||
$sheet->cells("$cb$row", function ($cells) {
|
||||
$cells->setAlignment('right');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
})->store('xls', storage_path('app') . '/public/reportes/servicios_capacidad/');
|
||||
|
||||
return response()->success(['nombre_archivo' => $nombre.'.xls?micro='.$this->getMicroSeconds()]);
|
||||
}
|
||||
}
|
||||
709
app/Http/Controllers/Reportes/EncuestasGeneralController.php
Normal file
709
app/Http/Controllers/Reportes/EncuestasGeneralController.php
Normal file
@@ -0,0 +1,709 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Reportes;
|
||||
|
||||
use const App\Http\Controllers\DOMESTICO;
|
||||
use const App\Http\Controllers\EMPRESARIAL;
|
||||
use App\Http\Requests\Reportes\EncuestasGeneralRequest;
|
||||
use App\Models\PreguntaDomestico;
|
||||
use App\Models\PreguntaEmpresarial;
|
||||
use App\Models\RespuestaDomestico;
|
||||
use App\Models\ServicioDet;
|
||||
use App\Models\ServicioEnc;
|
||||
use App\Models\ServicioEncuestaDomestico;
|
||||
use App\Models\ServicioEncuestaEmpresarial;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use DB;
|
||||
use Illuminate\Support\Arr;
|
||||
use Log;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class EncuestasGeneralController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
|
||||
public function resultado(EncuestasGeneralRequest $request) {
|
||||
|
||||
$year = $request->input('year');
|
||||
$month = $request->input('mes',Carbon::now()->format('m'));
|
||||
$operador_id = $request->input('operador_id', 0);
|
||||
$sucursal = $request->input('sucursal');
|
||||
|
||||
$empresarial = $this->empresarial($month, $year, $operador_id, $sucursal);
|
||||
$domestico = $this->domestico($month, $year, $operador_id, $sucursal);
|
||||
|
||||
return response()->success(compact('domestico', 'empresarial'));
|
||||
|
||||
}
|
||||
|
||||
public function domestico($month, $year, $operador_id, $sucursal) {
|
||||
|
||||
$servicios_det = ServicioDet::select('servicios_det.id')
|
||||
->join('servicios_enc', 'servicios_det.servicio_enc_id', '=', 'servicios_enc.id')
|
||||
->whereMonth('servicios_det.fecha_solicitud', $month)
|
||||
->whereYear('servicios_det.fecha_solicitud', $year)
|
||||
->where('requiere_encuesta', 1)
|
||||
->where('servicios_enc.sucursal_id', $sucursal)
|
||||
->where('tipo_servicio_id', DOMESTICO);
|
||||
|
||||
if($operador_id){
|
||||
$servicios_det->where(function($q) use ($operador_id){
|
||||
$q->where('operador_id',$operador_id)
|
||||
->orWhere('auxiliar_1',$operador_id)
|
||||
->orWhere('auxiliar_2',$operador_id);
|
||||
});
|
||||
}
|
||||
|
||||
$id = $servicios_det->pluck('id');
|
||||
|
||||
$d = ServicioEncuestaDomestico::select('preguntas_domestico.nombre as pregunta', DB::raw('ROUND(AVG(coalesce(respuestas_domestico.puntuacion,0)), 2) as puntuacion'))
|
||||
->join('respuestas_domestico', 'servicios_encuestas_domestico.respuesta_id', '=', 'respuestas_domestico.id')
|
||||
->join('preguntas_domestico','servicios_encuestas_domestico.pregunta_id', '=','preguntas_domestico.id')
|
||||
->whereIn('servicio_det_id', $id)
|
||||
->whereNotNull('respuesta_id')
|
||||
->groupBy('servicios_encuestas_domestico.pregunta_id', 'preguntas_domestico.nombre')
|
||||
->get();
|
||||
|
||||
$salida = [];
|
||||
foreach ($d as $e){
|
||||
$salida[] = [$e->pregunta, (float)$e->puntuacion];
|
||||
}
|
||||
|
||||
return $salida;
|
||||
}
|
||||
|
||||
public function empresarial($month, $year, $operador_id, $sucursal){
|
||||
|
||||
$servicios_det = ServicioDet::select('servicios_det.id')
|
||||
->join('servicios_enc', 'servicios_det.servicio_enc_id', '=', 'servicios_enc.id')
|
||||
->whereMonth('servicios_det.fecha_solicitud', $month)
|
||||
->whereYear('servicios_det.fecha_solicitud', $year)
|
||||
->where('requiere_encuesta', 1)
|
||||
->where('servicios_enc.sucursal_id', $sucursal)
|
||||
->where('tipo_servicio_id', EMPRESARIAL);
|
||||
|
||||
if($operador_id){
|
||||
$servicios_det->where(function($q) use ($operador_id){
|
||||
$q->where('operador_id',$operador_id)
|
||||
->orWhere('auxiliar_1',$operador_id)
|
||||
->orWhere('auxiliar_2',$operador_id);
|
||||
});
|
||||
}
|
||||
|
||||
$id = $servicios_det->pluck('id');
|
||||
|
||||
|
||||
$e = ServicioEncuestaEmpresarial::select('preguntas_empresarial.nombre as pregunta', DB::raw('ROUND(AVG(coalesce(respuestas_empresarial.puntuacion,0)), 2) as puntuacion'))
|
||||
->join('respuestas_empresarial', 'servicios_encuestas_empresarial.respuesta_id', '=', 'respuestas_empresarial.id')
|
||||
->join('preguntas_empresarial','servicios_encuestas_empresarial.pregunta_id', '=','preguntas_empresarial.id')
|
||||
->whereIn('servicio_det_id', $id)
|
||||
->whereNotNull('respuesta_id')
|
||||
->groupBy('servicios_encuestas_empresarial.pregunta_id', 'preguntas_empresarial.nombre')
|
||||
->get();
|
||||
|
||||
$salida = [];
|
||||
foreach ($e as $l){
|
||||
$salida[] = [$l->pregunta, (float)$l->puntuacion];
|
||||
}
|
||||
|
||||
return $salida;
|
||||
}
|
||||
|
||||
|
||||
public function generarExcel(EncuestasGeneralRequest $request) {
|
||||
|
||||
$year = $request->input('year');
|
||||
$month = $request->input('mes',Carbon::now()->format('m'));
|
||||
$operador_id = $request->input('operador_id', null);
|
||||
$sucursal = $request->input('sucursal', 1);
|
||||
|
||||
|
||||
/*$domestico = PreguntaDomestico::select('nombre')
|
||||
->where('mostrar_numero', 1)
|
||||
->get();
|
||||
|
||||
$preguntas_domestico = [];
|
||||
|
||||
foreach ($domestico as $l){
|
||||
$preguntas_domestico[] = [$l->nombre];
|
||||
}
|
||||
|
||||
$empresarial = PreguntaEmpresarial::select('nombre')
|
||||
->where('mostrar_numero', 1)
|
||||
->get();
|
||||
$preguntas_empresarial = [];
|
||||
|
||||
foreach ($empresarial as $z){
|
||||
$preguntas_empresarial[] = [$z->nombre];
|
||||
}*/
|
||||
|
||||
// Se va a calcular el promedio para domestico
|
||||
|
||||
(int)$suma = 0;
|
||||
(int)$contador= 0;
|
||||
(double)$promedio_domestico = 0;
|
||||
$domestico = $this->domesticoExcel($year, $month, $operador_id, $sucursal);
|
||||
|
||||
$dom = [];
|
||||
foreach ($domestico as $domestic) {
|
||||
$preg = [];
|
||||
foreach($domestic->preguntas as $detalle) {
|
||||
if($detalle->puntuacion){
|
||||
$preg[] = $detalle->puntuacion;
|
||||
$suma += $detalle->puntuacion;
|
||||
$contador = $contador + 1;
|
||||
}
|
||||
}
|
||||
|
||||
$det = [$domestic->servicio_id, $domestic->fecha_solicitud, $domestic->cliente, $domestic->operador, $domestic->fecha_nacimiento, $domestic->correo];
|
||||
$dom[] = array_merge($det, $preg);
|
||||
}
|
||||
if($contador){
|
||||
(double)$promedio_domestico = $suma / $contador;
|
||||
}
|
||||
|
||||
|
||||
//Cálculo del promedio de empresarial
|
||||
|
||||
$empresarial = $this->empresarialExcel($year, $month, $operador_id, $sucursal);
|
||||
|
||||
|
||||
(int)$suma_e = 0;
|
||||
(int)$contador_e= 0;
|
||||
(double)$promedio_empresarial = 0;
|
||||
$empa = [];
|
||||
|
||||
foreach ($empresarial as $empresa) {
|
||||
$preg = [];
|
||||
foreach($empresa->preguntas as $detalle) {
|
||||
if($detalle->puntuacion){
|
||||
$preg[] = $detalle->puntuacion;
|
||||
$suma_e += $detalle->puntuacion;
|
||||
$contador_e = $contador_e + 1;
|
||||
}
|
||||
}
|
||||
$det = [$empresa->servicio_id, $empresa->fecha_solicitud, $empresa->cliente, $empresa->operador, $empresa->fecha_nacimiento, $empresa->correo];
|
||||
$empa[] = array_merge($det, $preg);
|
||||
|
||||
}
|
||||
|
||||
if($contador_e){
|
||||
(double)$promedio_empresarial = $suma_e / $contador_e;
|
||||
}
|
||||
|
||||
|
||||
//Información que va necesitar el excel nombre y titulos
|
||||
$total = $domestico->count();
|
||||
|
||||
|
||||
|
||||
//Transformar el número del mes por la información
|
||||
$mes = '';
|
||||
$meses = ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'];
|
||||
foreach ($meses as $key => $m){
|
||||
if($key+1 == $month) {
|
||||
$mes = $m;
|
||||
}
|
||||
}
|
||||
|
||||
if($operador_id){
|
||||
$query = User::select(DB::raw("CONCAT(users.nombre,' ', users.apellido_paterno, ' ', users.apellido_materno) as operador"))
|
||||
->where('id', $operador_id)
|
||||
->first();
|
||||
$operador_title = $query->operador;
|
||||
|
||||
}
|
||||
|
||||
$total_e = $empresarial->count();
|
||||
|
||||
$nombre = ($operador_id) ? "Reporte_encuestas_domestico_empresarial".'_'.$mes.'_'.$year.'_detalle'.'_'. str_replace(' ', '_', $operador_title) : "Reporte_encuestas_domestico_empresarial".'_'.$mes.'_'.$year.'_'.$operador_title;
|
||||
|
||||
$titulo_domestico = ($operador_id) ? "Reporte encuestas doméstico".' '.$operador_title : "Reporte encuestas doméstico general";
|
||||
$titulo_empresarial = ($operador_id) ? "Reporte encuestas empresarial".' '.$operador_title : "Reporte encuestas empresarial general";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//Generación del excel
|
||||
Excel::create($nombre, function ($excel) use($dom, $total, $titulo_domestico, $promedio_domestico, $promedio_empresarial, $titulo_empresarial, $empa, $total_e, $sucursal, $mes, $year) {
|
||||
// Set del título del documento
|
||||
$excel->setTitle('Reporte de Encuestas');
|
||||
|
||||
// Seters de la campañía
|
||||
$excel->setCreator('DRENAX')
|
||||
->setCompany('DRENAX');
|
||||
|
||||
// Creación de la descripción
|
||||
$excel->setDescription('Reporte de Encuesta en servicios');
|
||||
|
||||
$excel->sheet('Reporte_encuestas_domestico', function ($sheet) use($dom, $titulo_domestico, $total, $promedio_domestico, $sucursal, $mes, $year){
|
||||
|
||||
$sheet->mergeCells('B2:D6');
|
||||
|
||||
//Mostrar el logo
|
||||
|
||||
$objDrawing = new \PHPExcel_Worksheet_Drawing;
|
||||
$objDrawing->setPath(resource_path('assets/images/logos').'/logo_drenax.png');
|
||||
$objDrawing->setWidth(95);
|
||||
$objDrawing->setHeight(80);
|
||||
$objDrawing->setCoordinates('B2');
|
||||
$objDrawing->setOffsetX(9);
|
||||
$objDrawing->setOffsetY(9);
|
||||
$objDrawing->setWorksheet($sheet);
|
||||
|
||||
//Mostrar el título de la hoja de excel
|
||||
$sheet->mergeCells('G2:J6');
|
||||
|
||||
$sheet->cell('G2', function($cell) use($titulo_domestico) {
|
||||
|
||||
$cell->setFontFamily('Aharoni');
|
||||
$cell->setFontWeight('bold');
|
||||
$cell->setAlignment('center');
|
||||
$cell->setValignment('center');
|
||||
$cell->setFontSize(20);
|
||||
$cell->setValue($titulo_domestico);
|
||||
|
||||
});
|
||||
|
||||
//Información entre el encabezado y la información
|
||||
$sheet->cell('N7', function($cell) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue('Fecha');
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('N8', function($cell) use($mes, $year) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue($mes.' '.$year);
|
||||
});
|
||||
|
||||
$sheet->cell('O7', function($cell) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue('Promedio General:');
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('O8', function($cell) use($promedio_domestico) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue($promedio_domestico.'%');
|
||||
});
|
||||
|
||||
// Mostar valores de consulta
|
||||
$sheet->fromArray($dom, null, 'B9', true);
|
||||
|
||||
//Formato en columnas de titulo
|
||||
$sheet->cells('B9:O9', function ($cells) {
|
||||
$cells->setBackground('#001870');
|
||||
$cells->setFontColor('#ffffff');
|
||||
$cells->setFontSize(13);
|
||||
$cells->setFontFamily('Calibri');
|
||||
$cells->setAlignment('left');
|
||||
$cells->setFontWeight('bold');
|
||||
});
|
||||
// Asignar el listado
|
||||
$sheet->getStyle('B9:O9' , $sheet->getHighestRow())->getAlignment()->setWrapText(true);
|
||||
|
||||
//Titulos personalizados
|
||||
$titulos_cell = [
|
||||
['cell' => 'B9', 'titulo' => 'Número de servicio'],
|
||||
['cell' => 'C9', 'titulo' => 'Fecha de solicitud'],
|
||||
['cell' => 'D9', 'titulo' => 'Cliente'],
|
||||
['cell' => 'E9', 'titulo' => 'Asesor asignado'],
|
||||
['cell' => 'F9', 'titulo' => 'Fecha de nacimiento'],
|
||||
['cell' => 'G9', 'titulo' => 'Correo'],
|
||||
['cell' => 'H9', 'titulo' => '¿El personal se presentó y mostró la orden de trabajo previo a la realización de su servicio?'],
|
||||
['cell' => 'I9', 'titulo' => '¿Cómo califica la puntualidad de nuestro personal?'],
|
||||
['cell' => 'J9', 'titulo' => '¿Cómo califica la imagen de nuestro personal?'],
|
||||
['cell' => 'K9', 'titulo' => '¿El asesor usó los instrumentos de seguridad e higiene para la correcta ejecución del servicio?'],
|
||||
['cell' => 'L9', 'titulo' => '¿Cómo califica la atención y asesoría brindada por los asesores?'],
|
||||
['cell' => 'M9', 'titulo' => '¿El servicio fue efectivo quedando conforme con lo que contrató?'],
|
||||
['cell' => 'N9', 'titulo' => '¿Cómo califica la atención y asesoría telefonica?'],
|
||||
['cell' => 'O9', 'titulo' => 'De acuerdo al servicio recibido, ¿usted nos recomendaría?']
|
||||
];
|
||||
|
||||
// Obtener los títulos de la tabla
|
||||
foreach ($titulos_cell as $t){
|
||||
$sheet->cell($t['cell'], function($cell) use($t) {
|
||||
$cell->setValue($t['titulo']);
|
||||
});
|
||||
}
|
||||
|
||||
//Darle un tamaño a las celdas
|
||||
$columns_set = [
|
||||
'B9', 'C9', 'D9', 'K9', 'L9'
|
||||
];
|
||||
|
||||
foreach ($columns_set as $c){
|
||||
$set_column = [
|
||||
$c => [
|
||||
'width' => ($c == 'D9' || $c == 'G9')? 25: 16,
|
||||
'height' => 40
|
||||
]
|
||||
];
|
||||
$sheet->setSize($set_column);
|
||||
}
|
||||
|
||||
$question_set = [
|
||||
'H9', 'I9', 'J9', 'K9', 'L9', 'M9', 'N9', 'O9'
|
||||
];
|
||||
|
||||
foreach ($question_set as $q){
|
||||
$question = [
|
||||
$q => [
|
||||
'width' => 35,
|
||||
'height' => 50
|
||||
]
|
||||
];
|
||||
$sheet->setSize($question);
|
||||
}
|
||||
|
||||
|
||||
//Tamaño automático en columnas indicadas
|
||||
$columns_auto= [
|
||||
'E','F','G'
|
||||
];
|
||||
|
||||
foreach ($columns_auto as $c){
|
||||
$sheet->getColumnDimension($c)->setAutoSize(true);
|
||||
}
|
||||
|
||||
$sheet->setWidth(array(
|
||||
'A' => 3,
|
||||
));
|
||||
//Borde
|
||||
$columns_border= [
|
||||
'B','C','D','E','F','G','H','I','J','K','L', 'M', 'N', 'O'
|
||||
];
|
||||
|
||||
for ($i=0; $i<= $total; $i++){
|
||||
$row = 9 + $i;
|
||||
|
||||
foreach ($columns_border as $cb){
|
||||
$border = "$cb$row:$cb$row";
|
||||
$sheet->cells($border, function ($cells) {
|
||||
$cells->setBorder('thin', 'thin', 'thin', 'thin');
|
||||
});
|
||||
|
||||
if($row != 9 && ($cb == 'C' || $cb == 'F' || $cb == 'L')){
|
||||
$sheet->cells("$cb$row", function ($cells) {
|
||||
$cells->setAlignment('right');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
$excel->sheet('Reporte_encuestas_empresarial', function ($sheet) use($promedio_domestico, $sucursal, $mes, $year, $titulo_empresarial, $promedio_empresarial, $empa, $total_e){
|
||||
$sheet->mergeCells('B2:D6');
|
||||
|
||||
//Mostrar el logo
|
||||
|
||||
$objDrawing = new \PHPExcel_Worksheet_Drawing;
|
||||
$objDrawing->setPath(resource_path('assets/images/logos').'/logo_drenax.png');
|
||||
$objDrawing->setWidth(95);
|
||||
$objDrawing->setHeight(80);
|
||||
$objDrawing->setCoordinates('B2');
|
||||
$objDrawing->setOffsetX(9);
|
||||
$objDrawing->setOffsetY(9);
|
||||
$objDrawing->setWorksheet($sheet);
|
||||
|
||||
//Mostrar el título de la hoja de excel
|
||||
$sheet->mergeCells('G2:J6');
|
||||
|
||||
$sheet->cell('G2', function($cell) use($titulo_empresarial) {
|
||||
|
||||
$cell->setFontFamily('Aharoni');
|
||||
$cell->setFontWeight('bold');
|
||||
$cell->setAlignment('center');
|
||||
$cell->setValignment('center');
|
||||
$cell->setFontSize(20);
|
||||
$cell->setValue($titulo_empresarial);
|
||||
|
||||
});
|
||||
|
||||
//Información entre el encabezado y la información
|
||||
$sheet->cell('P7', function($cell) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue('Fecha');
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('P8', function($cell) use($mes, $year) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue($mes.' '.$year);
|
||||
});
|
||||
|
||||
$sheet->cell('Q7', function($cell) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue('Promedio General:');
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('Q8', function($cell) use($promedio_empresarial) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue($promedio_empresarial.'%');
|
||||
});
|
||||
|
||||
// Mostar valores de consulta
|
||||
$sheet->fromArray($empa, null, 'B9', true);
|
||||
|
||||
//Formato en columnas de titulo
|
||||
$sheet->cells('B9:Q9', function ($cells) {
|
||||
$cells->setBackground('#001870');
|
||||
$cells->setFontColor('#ffffff');
|
||||
$cells->setFontSize(13);
|
||||
$cells->setFontFamily('Calibri');
|
||||
$cells->setAlignment('left');
|
||||
$cells->setFontWeight('bold');
|
||||
});
|
||||
|
||||
$sheet->getStyle('B9:Q9' , $sheet->getHighestRow())->getAlignment()->setWrapText(true);
|
||||
|
||||
//Titulos personalizados
|
||||
$titulos_cell = [
|
||||
['cell' => 'B9', 'titulo' => 'Número de servicio'],
|
||||
['cell' => 'C9', 'titulo' => 'Fecha de solicitud'],
|
||||
['cell' => 'D9', 'titulo' => 'Cliente'],
|
||||
['cell' => 'E9', 'titulo' => 'Asesor asignado'],
|
||||
['cell' => 'F9', 'titulo' => 'Fecha de nacimiento'],
|
||||
['cell' => 'G9', 'titulo' => 'Correo'],
|
||||
['cell' => 'H9', 'titulo' => '¿Su servicio fue programado en tiempo y forma?'],
|
||||
['cell' => 'I9', 'titulo' => '¿El asesor de operaciones realiza recibo de servicio, y es llenado correctamente hora de inicio y hora final?'],
|
||||
['cell' => 'J9', 'titulo' => '¿Cómo califica la imagen del personal?'],
|
||||
['cell' => 'K9', 'titulo' => '¿El asesor usó los instrumentos de seguridad e higiene para la correcta ejecución del servicio?'],
|
||||
['cell' => 'L9', 'titulo' => '¿Cómo califica la atención y asesoría brindada por los asesores de operaciones?'],
|
||||
['cell' => 'M9', 'titulo' => '¿Cómo califica la calidad del servicio contratado?'],
|
||||
['cell' => 'N9', 'titulo' => '¿Cómo califica la atención y asesoría telefonica?'],
|
||||
['cell' => 'O9', 'titulo' => '¿Recibió su factura del mes en tiempo y forma?'],
|
||||
['cell' => 'P9', 'titulo' => '¿Cómo califica nuestra área de cobranza?'],
|
||||
['cell' => 'Q9', 'titulo' => '¿Cómo califica en general a la empresa DRENAX?']
|
||||
];
|
||||
|
||||
// Obtener los títulos de la tabla
|
||||
foreach ($titulos_cell as $t){
|
||||
$sheet->cell($t['cell'], function($cell) use($t) {
|
||||
$cell->setValue($t['titulo']);
|
||||
});
|
||||
}
|
||||
|
||||
//Darle un tamaño a las celdas
|
||||
$columns_set = [
|
||||
'B9', 'C9', 'D9', 'K9', 'L9'
|
||||
];
|
||||
|
||||
foreach ($columns_set as $c){
|
||||
$set_column = [
|
||||
$c => [
|
||||
'width' => ($c == 'D9' || $c == 'G9')? 25: 16,
|
||||
'height' => 40
|
||||
]
|
||||
];
|
||||
$sheet->setSize($set_column);
|
||||
}
|
||||
|
||||
$question_set = [
|
||||
'H9', 'I9', 'J9', 'K9', 'L9', 'M9', 'N9', 'O9', 'P9', 'Q9'
|
||||
];
|
||||
|
||||
foreach ($question_set as $q){
|
||||
$question = [
|
||||
$q => [
|
||||
'width' => 35,
|
||||
'height' => 50
|
||||
]
|
||||
];
|
||||
$sheet->setSize($question);
|
||||
}
|
||||
|
||||
|
||||
//Tamaño automático en columnas indicadas
|
||||
$columns_auto= [
|
||||
'E','F','G'
|
||||
];
|
||||
|
||||
foreach ($columns_auto as $c){
|
||||
$sheet->getColumnDimension($c)->setAutoSize(true);
|
||||
}
|
||||
|
||||
$sheet->setWidth(array(
|
||||
'A' => 3,
|
||||
));
|
||||
//Borde
|
||||
$columns_border= [
|
||||
'B','C','D','E','F','G','H','I','J','K','L', 'M', 'N', 'O', 'P', 'Q'
|
||||
];
|
||||
|
||||
for ($i=0; $i<= $total_e; $i++){
|
||||
$row = 9 + $i;
|
||||
|
||||
foreach ($columns_border as $cb){
|
||||
$border = "$cb$row:$cb$row";
|
||||
$sheet->cells($border, function ($cells) {
|
||||
$cells->setBorder('thin', 'thin', 'thin', 'thin');
|
||||
});
|
||||
|
||||
if($row != 9 && ($cb == 'C' || $cb == 'F' || $cb == 'L')){
|
||||
$sheet->cells("$cb$row", function ($cells) {
|
||||
$cells->setAlignment('right');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Hoja de excel por defecto
|
||||
$excel->setActiveSheetIndex(0);
|
||||
|
||||
})->store('xls', storage_path('app') . '/public/reportes/servicios_encuestas/');
|
||||
|
||||
return response()->success(['nombre_archivo' => $nombre.'.xls?micro='.$this->getMicroSeconds()]);
|
||||
|
||||
}
|
||||
|
||||
public function domesticoExcel($year, $month, $operador_id, $sucursal){
|
||||
// Campos que se necesitan para mostrar en el reporte de excel
|
||||
$campos = [
|
||||
'servicios_det.id as servicio_id',
|
||||
DB::raw("DATE(servicios_det.fecha_solicitud) as 'fecha_solicitud'"),
|
||||
'clientes.denominacion as cliente',
|
||||
DB::raw("CONCAT(users.nombre,' ', users.apellido_paterno, ' ', users.apellido_materno) as operador")];
|
||||
//Consulta pra trae y filtrar la información para mostrar
|
||||
$servicios_det = ServicioDet::select($campos)
|
||||
->join('users', 'servicios_det.operador_id', '=', 'users.id')
|
||||
->join('servicios_enc', 'servicio_enc_id', '=', 'servicios_enc.id')
|
||||
->join('clientes', 'servicios_enc.cliente_id', '=', 'clientes.id')
|
||||
->whereMonth('servicios_det.fecha_solicitud', $month)
|
||||
->whereYear('servicios_det.fecha_solicitud', $year)
|
||||
->where('requiere_encuesta', 1)
|
||||
->where('tipo_servicio_id', DOMESTICO)
|
||||
->where('users.sucursal_id', $sucursal)
|
||||
->orderBy('users.tipo_empleado_id', 'asc')
|
||||
->orderBy('servicios_det.id', 'asc')
|
||||
->orderBy('operador', 'asc');
|
||||
|
||||
// Validamos si está filtrado por asesor o bien auxiliar de operación
|
||||
if($operador_id){
|
||||
$servicios_det->where(function($q) use ($operador_id){
|
||||
$q->where('operador_id',$operador_id)
|
||||
->orWhere('auxiliar_1',$operador_id)
|
||||
->orWhere('auxiliar_2',$operador_id);
|
||||
});
|
||||
}
|
||||
// Obtenemos los datos antes que se va a realizar la próxima consulta
|
||||
$servicios = $servicios_det->get();
|
||||
|
||||
foreach($servicios as $servicio){
|
||||
// Esta consulta es para traer la cantidad de preguntas que vamos a mostrar en el excel
|
||||
$servicio->preguntas = ServicioEncuestaDomestico::select('respuestas_domestico.puntuacion as puntuacion')
|
||||
->join('respuestas_domestico', 'respuesta_id','=','respuestas_domestico.id')
|
||||
->where('servicio_det_id', $servicio->servicio_id)
|
||||
->get();
|
||||
// obtenemos la fecha de nacimiento del cliente en caso de haberla mandado
|
||||
$fecha = ServicioEncuestaDomestico::select('respuesta')
|
||||
->where('servicio_det_id', $servicio->servicio_id)
|
||||
->where('pregunta_id', 11)
|
||||
->first();
|
||||
$servicio->fecha_nacimiento = ($fecha)? $fecha->respuesta : null;
|
||||
//Obtenemos el correo del cliente en caso dde haberla aceptado
|
||||
$correo = ServicioEncuestaDomestico::select('respuesta')
|
||||
->where('servicio_det_id', $servicio->servicio_id)
|
||||
->where('pregunta_id', 10)
|
||||
->first();
|
||||
$servicio->correo = ($correo)? $correo->respuesta : null;
|
||||
}
|
||||
|
||||
return $servicios;
|
||||
}
|
||||
|
||||
// Esta funcion es para traer los datos que necesitamos para la hoja de servicios empresariales
|
||||
|
||||
public function empresarialExcel($year, $month, $operador_id, $sucursal){
|
||||
$campos = [
|
||||
'servicios_det.id as servicio_id',
|
||||
DB::raw("DATE(servicios_det.fecha_solicitud) as 'fecha_solicitud'"),
|
||||
'clientes.denominacion as cliente',
|
||||
DB::raw("CONCAT(users.nombre,' ', users.apellido_paterno, ' ', users.apellido_materno) as operador")];
|
||||
|
||||
$servicios_det = ServicioDet::select($campos)
|
||||
->join('users', 'servicios_det.operador_id', '=', 'users.id')
|
||||
->join('servicios_enc', 'servicio_enc_id', '=', 'servicios_enc.id')
|
||||
->join('clientes', 'servicios_enc.cliente_id', '=', 'clientes.id')
|
||||
->whereMonth('servicios_det.fecha_solicitud', $month)
|
||||
->whereYear('servicios_det.fecha_solicitud', $year)
|
||||
->where('requiere_encuesta', 1)
|
||||
->where('tipo_servicio_id', EMPRESARIAL)
|
||||
->where('users.sucursal_id', $sucursal)
|
||||
->orderBy('users.tipo_empleado_id', 'asc')
|
||||
->orderBy('servicios_det.id', 'asc')
|
||||
->orderBy('operador', 'asc');
|
||||
|
||||
if($operador_id){
|
||||
$servicios_det->where(function($q) use ($operador_id){
|
||||
$q->where('operador_id',$operador_id)
|
||||
->orWhere('auxiliar_1',$operador_id)
|
||||
->orWhere('auxiliar_2',$operador_id);
|
||||
});
|
||||
}
|
||||
|
||||
$servicios_emp = $servicios_det->get();
|
||||
|
||||
|
||||
foreach($servicios_emp as $servicio_emp){
|
||||
|
||||
$servicio_emp->preguntas = ServicioEncuestaEmpresarial::select('respuestas_empresarial.puntuacion as puntuacion')
|
||||
->join('respuestas_empresarial', 'respuesta_id','=','respuestas_empresarial.id')
|
||||
->where('servicio_det_id', $servicio_emp->servicio_id)
|
||||
->get();
|
||||
|
||||
$fecha = ServicioEncuestaEmpresarial::select('respuesta')
|
||||
->where('servicio_det_id', $servicio_emp->servicio_id)
|
||||
->where('pregunta_id', 11)
|
||||
->first();
|
||||
|
||||
$servicio_emp->fecha_nacimiento = ($fecha)? $fecha->respuesta : null;
|
||||
|
||||
$correo = ServicioEncuestaEmpresarial::select('respuesta')
|
||||
->where('servicio_det_id', $servicio_emp->servicio_id)
|
||||
->where('pregunta_id', 10)
|
||||
->first();
|
||||
|
||||
$servicio_emp->correo = ($correo)? $correo->respuesta : null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $servicios_emp;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
261
app/Http/Controllers/Reportes/FiltrosController.php
Normal file
261
app/Http/Controllers/Reportes/FiltrosController.php
Normal file
@@ -0,0 +1,261 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Reportes;
|
||||
|
||||
use const App\Http\Controllers\ASESOR_OPERACIONES;
|
||||
use const App\Http\Controllers\AUXILIAR_TECNICO_1;
|
||||
use const App\Http\Controllers\AUXILIAR_TECNICO_2;
|
||||
use App\Http\Requests\Reportes\FiltroAsesoresRequest;
|
||||
use App\Models\CatEstatuServicio;
|
||||
use App\Models\CatOrigen;
|
||||
use App\Models\CatServicio;
|
||||
use App\Models\CatTipoServicio;
|
||||
use App\Models\ServicioDet;
|
||||
use App\Models\ServicioEncuestaDomestico;
|
||||
use App\Models\ServicioEncuestaEmpresarial;
|
||||
use App\Models\Sucursal;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Auth;
|
||||
use Log;
|
||||
|
||||
class FiltrosController extends Controller
|
||||
{
|
||||
public function sucursales(Request $request){
|
||||
|
||||
$deleted = $request->input('deleted');
|
||||
$orderBy = $request->input('sortBy','nombre');
|
||||
$order = $request->input('order','asc');
|
||||
$queryBuilder = Sucursal::orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('nombre','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($deleted) {
|
||||
$queryBuilder->onlyTrashed();
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$sucursal = $queryBuilder->paginate($perPage);
|
||||
}else{
|
||||
$sucursal = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
return response()->success($sucursal);
|
||||
}
|
||||
|
||||
public function servicios(Request $request)
|
||||
{
|
||||
$deleted = $request->input('deleted');
|
||||
$orderBy = $request->input('sortBy','nombre');
|
||||
$order = $request->input('order','asc');
|
||||
$queryBuilder = CatServicio::orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('nombre','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($deleted) {
|
||||
$queryBuilder->onlyTrashed();
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$servicios = $queryBuilder->paginate($perPage);
|
||||
}else{
|
||||
$servicios = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
return response()->success($servicios);
|
||||
}
|
||||
|
||||
public function tiposServicio(Request $request)
|
||||
{
|
||||
$deleted = $request->input('deleted');
|
||||
$orderBy = $request->input('sortBy','nombre');
|
||||
$order = $request->input('order','asc');
|
||||
$queryBuilder = CatTipoServicio::orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('nombre','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($deleted) {
|
||||
$queryBuilder->onlyTrashed();
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$tipos_servicios = $queryBuilder->paginate($perPage);
|
||||
}else{
|
||||
$tipos_servicios = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
return response()->success($tipos_servicios);
|
||||
}
|
||||
|
||||
public function estatusServicio(Request $request)
|
||||
{
|
||||
$deleted = $request->input('deleted');
|
||||
$orderBy = $request->input('sortBy','nombre');
|
||||
$order = $request->input('order','asc');
|
||||
$queryBuilder = CatEstatuServicio::orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('nombre','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($deleted) {
|
||||
$queryBuilder->onlyTrashed();
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$estatus = $queryBuilder->paginate($perPage);
|
||||
}else{
|
||||
$estatus = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
return response()->success($estatus);
|
||||
}
|
||||
|
||||
public function origenes(Request $request)
|
||||
{
|
||||
$orderBy = $request->input('sortBy','nombre');
|
||||
$order = $request->input('order','asc');
|
||||
|
||||
$queryBuilder = CatOrigen::orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('nombre','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$data = $queryBuilder->paginate($perPage);
|
||||
}else{
|
||||
$data = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
return response()->success($data);
|
||||
}
|
||||
|
||||
public function asesores(FiltroAsesoresRequest $request) {
|
||||
|
||||
$sucursal = $request->input('sucursal');
|
||||
$orderBy = $request->input('sortBy','tipo_empleado_id');
|
||||
$order = $request->input('order','asc');
|
||||
$month = $request->input('mes');
|
||||
$year = $request->input('year');
|
||||
|
||||
$queryBuilder = User::select('id', 'nombre', 'apellido_paterno', 'apellido_materno', 'tipo_empleado_id')
|
||||
->where('sucursal_id', $sucursal)
|
||||
->whereIn('tipo_empleado_id', [ASESOR_OPERACIONES, AUXILIAR_TECNICO_1, AUXILIAR_TECNICO_2])
|
||||
->orderBy($orderBy, $order)
|
||||
->orderBy('nombre','asc');
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('nombre','like','%' .$query.'%')
|
||||
->orWhere('apellido_paterno','like','%' .$query.'%')
|
||||
->orWhere('apellido_materno','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
|
||||
$data = $queryBuilder->paginate($perPage);
|
||||
foreach ($data->items() as $u){
|
||||
|
||||
if($u->tipo_empleado_id == ASESOR_OPERACIONES){
|
||||
$u->tipo_empleado = 'Asesor de Operaciones';
|
||||
|
||||
$servi = ServicioDet::select('id')
|
||||
->where('servicios_det.operador_id', $u->id)
|
||||
->whereMonth('fecha_solicitud', $month)
|
||||
->whereYear('fecha_solicitud', $year)
|
||||
->where('requiere_encuesta', 1)->pluck('id');
|
||||
|
||||
$encuesta_d = ServicioEncuestaDomestico::select('servicio_det_id')->whereIn('servicio_det_id',$servi)->groupBy('servicio_det_id')->get();
|
||||
$encuesta_e = ServicioEncuestaEmpresarial::select('servicio_det_id')->whereIn('servicio_det_id',$servi)->groupBy('servicio_det_id')->get();
|
||||
$total = count($encuesta_d) + count($encuesta_e);
|
||||
|
||||
$u->servicios_cantidad = $total.' Encuestas '.' de '.count($servi).' Servicios';
|
||||
|
||||
/*$u->servicios_cantidad = ServicioDet::where('servicios_det.operador_id', $u->id)
|
||||
->whereMonth('fecha_solicitud', $month)
|
||||
->whereYear('fecha_solicitud', $year)
|
||||
->where('requiere_encuesta', 1)->count();*/
|
||||
}
|
||||
|
||||
if($u->tipo_empleado_id == AUXILIAR_TECNICO_1 || $u->tipo_empleado_id == AUXILIAR_TECNICO_2){
|
||||
$u->tipo_empleado = 'Auxiliar de Operaciones';
|
||||
|
||||
$servi = ServicioDet::select('id')
|
||||
->whereMonth('fecha_solicitud', $month)
|
||||
->whereYear('fecha_solicitud', $year)
|
||||
->where(function($q) use ($u){
|
||||
$q->where('servicios_det.auxiliar_1', $u->id)
|
||||
->orWhere('servicios_det.auxiliar_2', $u->id);
|
||||
})->pluck('id');
|
||||
|
||||
$encuesta_d = ServicioEncuestaDomestico::select('servicio_det_id')->whereIn('servicio_det_id',$servi)->groupBy('servicio_det_id')->get();
|
||||
$encuesta_e = ServicioEncuestaEmpresarial::select('servicio_det_id')->whereIn('servicio_det_id',$servi)->groupBy('servicio_det_id')->get();
|
||||
$total = count($encuesta_d) + count($encuesta_e);
|
||||
|
||||
$u->servicios_cantidad = $total.' Encuestas '. ' de '. count($servi).' Servicios';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$users = $data;
|
||||
|
||||
} else{
|
||||
|
||||
$data = $queryBuilder->get();
|
||||
|
||||
foreach ($data as $u){
|
||||
|
||||
if($u->tipo_empleado_id == ASESOR_OPERACIONES){
|
||||
$u->tipo_empleado = 'Asesor de Operaciones';
|
||||
$u->servicios_cantidad = ServicioDet::where('operador_id', $u->id)
|
||||
->where('requiere_encuesta', 1)
|
||||
->whereMonth('fecha_solicitud', $month)
|
||||
->whereYear('fecha_solicitud', $year)
|
||||
->count();
|
||||
}
|
||||
|
||||
if($u->tipo_empleado_id == AUXILIAR_TECNICO_1 || $u->tipo_empleado_id == AUXILIAR_TECNICO_2){
|
||||
$u->tipo_empleado = 'Auxiliar de Operaciones';
|
||||
|
||||
$u->servicios_cantidad = ServicioDet::whereMonth('fecha_solicitud', $month)
|
||||
->whereYear('fecha_solicitud', $year)
|
||||
->where(function($q) use ($u){
|
||||
$q->where('servicios_det.auxiliar_1', $u->id)
|
||||
->orWhere('servicios_det.auxiliar_2', $u->id);
|
||||
})
|
||||
->count();
|
||||
}
|
||||
}
|
||||
|
||||
$users = ['data'=>collect($data)->where('servicios_cantidad','<>',0)->values()];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return response()->success($users);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
285
app/Http/Controllers/Reportes/MensualController.php
Normal file
285
app/Http/Controllers/Reportes/MensualController.php
Normal file
@@ -0,0 +1,285 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Reportes;
|
||||
|
||||
use const App\Http\Controllers\ASESOR_OPERACIONES;
|
||||
use const App\Http\Controllers\ATENCION_CLIENTES;
|
||||
use App\Models\TipoVehiculo;
|
||||
use App\Models\CatEstatuServicio;
|
||||
use App\Models\ServicioDet;
|
||||
use App\Models\ServicioEnc;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use App\Http\Controllers\Controller;
|
||||
use DB;
|
||||
use Log;
|
||||
|
||||
class MensualController extends Controller{
|
||||
|
||||
function getWeek($date){
|
||||
$date = new \DateTime($date);
|
||||
$week = $date->format("W");
|
||||
return $week;
|
||||
}
|
||||
|
||||
public function reportes(){
|
||||
$mes_actual = Carbon::now()->format('m');
|
||||
|
||||
$currentWeek = $this->getWeek(date("Y-m-d"));
|
||||
$firstDateOfMonth = date("Y").'-'.date("m").'-01';
|
||||
$firstWeek = $this->getWeek($firstDateOfMonth);
|
||||
$lastDateOfMonth = date("Y-m-t", strtotime($firstDateOfMonth));
|
||||
$lastWeek = $this->getWeek($lastDateOfMonth);
|
||||
|
||||
$servicios_nombre_precios = $this->serviciosNombresPrecios($mes_actual);
|
||||
$tipos_servicios = $this->tiposServicios($mes_actual);
|
||||
$tipos_estados_servicio = $this->tipoEstadoServicio($mes_actual);
|
||||
$tipos_origen = $this->tiposOrigen($mes_actual);
|
||||
$atencion_cliente = $this->atencionCliente($mes_actual);
|
||||
$operadores = $this->operadores($mes_actual);
|
||||
$servicios_vehiculos_precios = $this->serviciosVehiculosPrecios($mes_actual);
|
||||
$capacidad_aprovechada = $this->capacidadAprovechada($mes_actual, $firstWeek, $lastWeek);
|
||||
|
||||
return response()->success(compact('servicios_nombre_precios','tipos_servicios', 'tipos_estados_servicio', 'tipos_origen', 'atencion_cliente', 'operadores', 'servicios_vehiculos_precios', 'capacidad_aprovechada'));
|
||||
}
|
||||
|
||||
public function serviciosNombresPrecios($mes_actual){
|
||||
|
||||
$servicios = ServicioDet::select('cat_servicios.nombre as name', DB::raw("SUM(servicios_det.costo_servicio) AS costo, count(servicios_det.servicio_id) as y"))
|
||||
->join('cat_servicios', 'servicios_det.servicio_id', '=', 'cat_servicios.id')
|
||||
->whereMonth('servicios_det.fecha_solicitud', $mes_actual)
|
||||
->groupBy('cat_servicios.nombre')
|
||||
->get();
|
||||
|
||||
$total_costo = (string)number_format(collect($servicios)->sum('costo'),2);
|
||||
|
||||
return compact('servicios', 'total_costo');
|
||||
}
|
||||
|
||||
public function tiposServicios($mes_actual){
|
||||
|
||||
$sevicios = ServicioDet::select('cat_tipos_servicios.nombre as name', DB::raw("count(servicios_det.tipo_servicio_id) as y"))
|
||||
->join('cat_tipos_servicios', 'servicios_det.tipo_servicio_id', '=', 'cat_tipos_servicios.id')
|
||||
->whereMonth('servicios_det.fecha_solicitud', $mes_actual)
|
||||
->groupBy('cat_tipos_servicios.nombre')
|
||||
->get();
|
||||
|
||||
return $sevicios;
|
||||
}
|
||||
|
||||
public function tipoEstadoServicio($mes_actual){
|
||||
|
||||
$sevicios = ServicioDet::select('cat_estatus_servicios.nombre as name', DB::raw("count(servicios_det.estatus_servicio_id) as y"))
|
||||
->join('cat_estatus_servicios', 'servicios_det.estatus_servicio_id', '=', 'cat_estatus_servicios.id')
|
||||
->whereMonth('servicios_det.fecha_solicitud', $mes_actual)
|
||||
->groupBy('cat_estatus_servicios.nombre')
|
||||
->get();
|
||||
|
||||
return $sevicios;
|
||||
}
|
||||
|
||||
public function tiposOrigen($mes_actual){
|
||||
|
||||
$sevicios = ServicioEnc::select('cat_origenes.nombre as name', DB::raw("count(servicios_enc.origen_id) as y"))
|
||||
->join('servicios_det', 'servicios_enc.id', '=', 'servicios_det.servicio_enc_id')
|
||||
->join('cat_origenes', 'servicios_enc.origen_id', '=', 'cat_origenes.id')
|
||||
->whereMonth('servicios_det.fecha_solicitud', $mes_actual)
|
||||
->groupBy('cat_origenes.nombre')
|
||||
->get();
|
||||
|
||||
return $sevicios;
|
||||
}
|
||||
|
||||
public function atencionCliente($mes_actual){
|
||||
|
||||
$usuarios_series = [];
|
||||
$estatus_series = [];
|
||||
|
||||
$estatus_servicio = CatEstatuServicio::get();
|
||||
|
||||
foreach ($estatus_servicio as $e){
|
||||
|
||||
$usuarios_series = [];
|
||||
$valores_estatus = [];
|
||||
|
||||
$atencion_cliente = User::select('id', DB::raw("CONCAT(nombre, ' ',apellido_paterno) as nombre_atencion"))
|
||||
->where('tipo_empleado_id', ATENCION_CLIENTES)
|
||||
->get();
|
||||
|
||||
foreach ($atencion_cliente as $aC){
|
||||
|
||||
$total = ServicioEnc::join('servicios_det', 'servicios_enc.id', '=', 'servicios_det.servicio_enc_id')
|
||||
->join('cat_estatus_servicios', 'servicios_det.estatus_servicio_id', '=', 'cat_estatus_servicios.id')
|
||||
->where('servicios_enc.usuario_agenda_id',$aC->id)
|
||||
->whereMonth('servicios_det.fecha_solicitud', $mes_actual);
|
||||
|
||||
|
||||
$total_general = ($total->count() == 1)? " (".$total->count()." servicio)" : " (".$total->count()." servicios)";
|
||||
$nombre = $aC->nombre_atencion.$total_general;
|
||||
|
||||
array_push($usuarios_series, $nombre);
|
||||
|
||||
$total_estatus = $total->where('servicios_det.estatus_servicio_id', $e->id)->count();
|
||||
array_push($valores_estatus, $total_estatus);
|
||||
}
|
||||
|
||||
$estatus_series[$e->nombre] = $valores_estatus;
|
||||
}
|
||||
|
||||
|
||||
$datos = [];
|
||||
foreach ($estatus_series as $key => $e){
|
||||
array_push($datos, ["name"=>$key, "data"=>$e]);
|
||||
}
|
||||
|
||||
$result = ["usuarios"=>$usuarios_series, "datos"=>$datos];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function operadores($mes_actual){
|
||||
|
||||
$usuarios_series = [];
|
||||
$estatus_series = [];
|
||||
|
||||
$estatus_servicio = CatEstatuServicio::get();
|
||||
|
||||
foreach ($estatus_servicio as $e){
|
||||
|
||||
$usuarios_series = [];
|
||||
$valores_estatus = [];
|
||||
|
||||
$operadores = User::select('id', DB::raw("CONCAT(nombre, ' ',apellido_paterno) as nombre_atencion"))
|
||||
->where('tipo_empleado_id', ASESOR_OPERACIONES)
|
||||
->get();
|
||||
|
||||
foreach ($operadores as $o){
|
||||
|
||||
|
||||
$total = ServicioDet::join('cat_estatus_servicios', 'servicios_det.estatus_servicio_id', '=', 'cat_estatus_servicios.id')
|
||||
->where('servicios_det.operador_id',$o->id)
|
||||
->whereMonth('servicios_det.fecha_solicitud', $mes_actual);
|
||||
|
||||
$total_general = ($total->count() == 1)? " (".$total->count()." servicio)" : " (".$total->count()." servicios)";
|
||||
$nombre = $o->nombre_atencion.$total_general;
|
||||
|
||||
array_push($usuarios_series, $nombre);
|
||||
|
||||
$total_estatus = $total->where('servicios_det.estatus_servicio_id', $e->id)->count();
|
||||
array_push($valores_estatus, $total_estatus);
|
||||
}
|
||||
|
||||
$estatus_series[$e->nombre] = $valores_estatus;
|
||||
}
|
||||
|
||||
|
||||
$datos = [];
|
||||
foreach ($estatus_series as $key => $e){
|
||||
array_push($datos, ["name"=>$key, "data"=>$e]);
|
||||
}
|
||||
$result = ["usuarios"=>$usuarios_series, "datos"=>$datos];
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function serviciosVehiculosPrecios($mes_actual){
|
||||
|
||||
$servicios = ServicioDet::select('cat_vehiculos.num_economico as name', DB::raw("SUM(servicios_det.costo_servicio) AS costo, count(servicios_det.servicio_id) as y"))
|
||||
->join('cat_vehiculos', 'servicios_det.vehiculo_id', '=', 'cat_vehiculos.id')
|
||||
->whereMonth('servicios_det.fecha_solicitud', $mes_actual)
|
||||
->groupBy('cat_vehiculos.num_economico')
|
||||
->get();
|
||||
|
||||
return $servicios;
|
||||
}
|
||||
|
||||
public function capacidadAprovechada($mes_actual, $firstWeek, $lastWeek){
|
||||
|
||||
$respuesta = [];
|
||||
$index = 0;
|
||||
|
||||
$tipos_vehiculo = TipoVehiculo::select(['id', 'nombre'])->orderBy('nombre')->get();
|
||||
foreach ($tipos_vehiculo as $t){
|
||||
$tmpId = $t->id;
|
||||
$tmpNombre = $t->nombre;
|
||||
|
||||
$campos = [
|
||||
'cat_vehiculos.tipo_vehiculo_id',
|
||||
'cat_tipos_vehiculos.nombre AS tipo_vehiculo',
|
||||
'cat_tipos_vehiculos.objetivo_mensual',
|
||||
DB::raw("SEC_TO_TIME(SUM(TIME_TO_SEC(servicios_progreso.duracion))) AS 'total_duracion'"),
|
||||
DB::raw("TRUNCATE(SUM((TIME_TO_SEC(TIME(servicios_progreso.duracion))/60)/60), 3) AS 'total_duracion_fracc'")
|
||||
];
|
||||
|
||||
$objetivoSemanal = 0;
|
||||
$objetivoMensual = 0;
|
||||
$totalWeeks = 0;
|
||||
$sumatoriaPorcentajes = 0.0;
|
||||
|
||||
$informacion = [];
|
||||
|
||||
for($i=$firstWeek;$i<=$lastWeek;$i++){
|
||||
// execute this week
|
||||
$datos = ServicioDet::select($campos)
|
||||
->join('servicios_enc', 'servicios_det.servicio_enc_id', '=', 'servicios_enc.id')
|
||||
->join('cat_servicios', 'servicios_det.servicio_id', '=', 'cat_servicios.id')
|
||||
->join('cat_tipos_servicios', 'servicios_det.tipo_servicio_id', '=', 'cat_tipos_servicios.id')
|
||||
->join('cat_estatus_servicios','servicios_det.estatus_servicio_id','=','cat_estatus_servicios.id')
|
||||
->join('cat_vehiculos', 'servicios_det.vehiculo_id', '=', 'cat_vehiculos.id')
|
||||
->join('cat_tipos_vehiculos', 'cat_tipos_vehiculos.id', '=', 'cat_vehiculos.tipo_vehiculo_id')
|
||||
->leftJoin('servicios_progreso', 'servicios_det.id', '=', 'servicios_progreso.servicio_det_id')
|
||||
->join('cat_origenes', 'servicios_enc.origen_id', '=', 'cat_origenes.id')
|
||||
->where('cat_vehiculos.tipo_vehiculo_id', $tmpId)
|
||||
//->whereMonth('servicios_det.fecha_solicitud', $mes_actual)
|
||||
->whereRaw("WEEKOFYEAR(DATE(servicios_det.fecha_solicitud))=?", $i)
|
||||
->groupBy('cat_vehiculos.tipo_vehiculo_id', 'cat_tipos_vehiculos.nombre', 'cat_tipos_vehiculos.objetivo_mensual')
|
||||
->first();
|
||||
|
||||
if($datos){
|
||||
$sumatoriaPorcentajes = floatval($sumatoriaPorcentajes) + floatval($datos->total_duracion_fracc);
|
||||
$objetivoMensual = $datos->objetivo_mensual;
|
||||
array_push($informacion, [
|
||||
'week_num'=>$i,
|
||||
'total_duracion'=>$datos->total_duracion,
|
||||
'total_duracion_fracc'=>$datos->total_duracion_fracc,
|
||||
]);
|
||||
}else{
|
||||
array_push($informacion, [
|
||||
'week_num'=>$i,
|
||||
'total_duracion'=>null,
|
||||
'total_duracion_fracc'=>null
|
||||
]);
|
||||
}
|
||||
|
||||
$totalWeeks++;
|
||||
}
|
||||
|
||||
$respuesta[$index]['tipo_vehiculo_id'] = $tmpId;
|
||||
$respuesta[$index]['tipo_vehiculo'] = $tmpNombre;
|
||||
$respuesta[$index]['objetivo_mensual'] = $objetivoMensual;
|
||||
$respuesta[$index]['objetivo_semanal'] = ($totalWeeks == 0) ? 0 : $objetivoMensual/($totalWeeks);
|
||||
$respuesta[$index]['semanas'] = $totalWeeks;
|
||||
$respuesta[$index]['total_cumplimiento'] = $sumatoriaPorcentajes;
|
||||
$respuesta[$index]['datos'] = $informacion;
|
||||
$index++;
|
||||
}
|
||||
|
||||
return $respuesta;
|
||||
}
|
||||
|
||||
function obtener_semana($date) {
|
||||
|
||||
$date2 = strtotime($date);
|
||||
$inicio0 = strtotime('sunday this week -1 week', $date2);
|
||||
$inicio=date('Y-m-d', $inicio0);
|
||||
|
||||
$dias = array();
|
||||
for($i=1;$i<=7;$i++){
|
||||
$dia = date("Y-m-d", strtotime("$inicio +$i day"));
|
||||
array_push($dias,$dia);
|
||||
}
|
||||
|
||||
return $dias;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,408 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Reportes;
|
||||
|
||||
use const App\Http\Controllers\ATENCION_CLIENTES;
|
||||
use const App\Http\Controllers\DEFINIO_ATENCION_CLIENTE;
|
||||
use const App\Http\Controllers\DEFINIO_CLIENTE;
|
||||
use App\Http\Requests\Reportes\ConsultarAtencionClientesRequest;
|
||||
use App\Http\Requests\Reportes\ProductividadAtencionClientesRequest;
|
||||
use App\Models\ServicioDet;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use DB;
|
||||
use Excel;
|
||||
|
||||
class ProductividadAtencionClientesController extends Controller
|
||||
{
|
||||
public function consultarAtencionClientes(ConsultarAtencionClientesRequest $request){
|
||||
|
||||
$sucursal = $request->input('sucursal');
|
||||
$fecha_inicio = $request->input('fecha_inicio');
|
||||
$fecha_final = $request->input('fecha_final');
|
||||
$definio = $request->input('definio');
|
||||
|
||||
$orderBy = $request->input('sortBy','nombre');
|
||||
$order = $request->input('order','asc');
|
||||
|
||||
$queryBuilder = User::select('id', 'nombre', 'apellido_paterno', 'apellido_materno')
|
||||
->where('tipo_empleado_id', ATENCION_CLIENTES)
|
||||
->where('sucursal_id', $sucursal)
|
||||
->orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('nombre','like','%' .$query.'%')
|
||||
->orWhere('apellido_paterno','like','%' .$query.'%')
|
||||
->orWhere('apellido_materno','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
|
||||
$data = $queryBuilder->paginate($perPage);
|
||||
foreach ($data->items() as $u){
|
||||
$count = ServicioDet::join('servicios_enc','servicios_det.servicio_enc_id', '=', 'servicios_enc.id')
|
||||
->where('servicios_enc.usuario_agenda_id', $u->id)
|
||||
->whereDate('servicios_det.fecha_solicitud','>=',$fecha_inicio)
|
||||
->whereDate('servicios_det.fecha_solicitud','<=',$fecha_final);
|
||||
|
||||
if($definio == DEFINIO_CLIENTE){
|
||||
$count->where('servicios_det.definido_cliente', 1);
|
||||
}
|
||||
|
||||
if($definio == DEFINIO_ATENCION_CLIENTE){
|
||||
$count->where('servicios_det.definido_cliente', 0);
|
||||
}
|
||||
|
||||
$u->servicios_cantidad = $count->count();
|
||||
}
|
||||
|
||||
$users = $data;
|
||||
}else{
|
||||
|
||||
$data = $queryBuilder->get();
|
||||
foreach ($data as $u){
|
||||
$count = ServicioDet::join('servicios_enc','servicios_det.servicio_enc_id', '=', 'servicios_enc.id')
|
||||
->where('servicios_enc.usuario_agenda_id', $u->id)
|
||||
->whereDate('servicios_det.fecha_solicitud','>=',$fecha_inicio)
|
||||
->whereDate('servicios_det.fecha_solicitud','<=',$fecha_final);
|
||||
|
||||
if($definio == DEFINIO_CLIENTE){
|
||||
$count->where('servicios_det.definido_cliente', 1);
|
||||
}
|
||||
|
||||
if($definio == DEFINIO_ATENCION_CLIENTE){
|
||||
$count->where('servicios_det.definido_cliente', 0);
|
||||
}
|
||||
|
||||
$u->servicios_cantidad = $count->count();
|
||||
}
|
||||
|
||||
$users = ['data'=>$data];
|
||||
}
|
||||
|
||||
return response()->success($users);
|
||||
}
|
||||
|
||||
public function reportes(ProductividadAtencionClientesRequest $request){
|
||||
|
||||
$orderBy = $request->input('sortBy','servicios_enc.id');
|
||||
$order = $request->input('order','asc');
|
||||
|
||||
$sucursal = $request->input('sucursal');
|
||||
$fecha_inicio = $request->input('fecha_inicio');
|
||||
$fecha_final = $request->input('fecha_final');
|
||||
$usuario_id = $request->input('usuario_id');
|
||||
$definio = $request->input('definio');
|
||||
|
||||
$campos = [
|
||||
'servicios_enc.id as numero_solicitud',
|
||||
DB::raw("DATE(servicios_det.fecha_solicitud) as 'fecha_servicio'"),
|
||||
DB::raw("TIME(servicios_det.fecha_solicitud) as 'hora_servicio'"),
|
||||
'cat_servicios.nombre as servicio',
|
||||
'servicios_det.costo_servicio as costo',
|
||||
'cat_tipos_servicios.nombre as tipo_servicio',
|
||||
'cat_estatus_servicios.nombre as estatus_servicio',
|
||||
'clientes.denominacion as nombre_cliente',
|
||||
'clientes_domicilios.calle as calle_cliente',
|
||||
'clientes_domicilios.entre_calles as entre_calles_cliente',
|
||||
'clientes_domicilios.num_ext as num_ext_cliente',
|
||||
'clientes_domicilios.num_int as num_int_cliente',
|
||||
'clientes_domicilios.colonia as colonia_cliente',
|
||||
'clientes_domicilios.ciudad as ciudad_cliente',
|
||||
'clientes_domicilios.cp as cp_cliente',
|
||||
'asesor.nombre as nombre_asesor',
|
||||
'asesor.apellido_paterno as apellido_paterno_asesor',
|
||||
'asesor.apellido_materno as apellido_materno_asesor',
|
||||
'auxiliar.nombre as nombre_auxiliar',
|
||||
'auxiliar.apellido_paterno as apellido_paterno_auxiliar',
|
||||
'auxiliar.apellido_materno as apellido_materno_auxiliar',
|
||||
'cat_vehiculos.num_economico as vehiculo',
|
||||
'servicios_progreso.duracion as duracion_servicio'
|
||||
];
|
||||
|
||||
$queryBuilder = ServicioDet::select($campos)
|
||||
->join('servicios_enc', 'servicios_det.servicio_enc_id', '=', 'servicios_enc.id')
|
||||
->join('cat_servicios', 'servicios_det.servicio_id', '=', 'cat_servicios.id')
|
||||
->join('cat_tipos_servicios', 'servicios_det.tipo_servicio_id', '=', 'cat_tipos_servicios.id')
|
||||
->join('cat_estatus_servicios','servicios_det.estatus_servicio_id','=','cat_estatus_servicios.id')
|
||||
->join('clientes','servicios_enc.cliente_id','=','clientes.id')
|
||||
->join('clientes_domicilios','servicios_enc.cliente_domicilio_id','=','clientes_domicilios.id')
|
||||
->join('users as asesor', 'servicios_det.operador_id', '=', 'asesor.id')
|
||||
->leftJoin('users as auxiliar', 'servicios_det.auxiliar_1', '=', 'auxiliar.id')
|
||||
->join('cat_vehiculos', 'servicios_det.vehiculo_id', '=', 'cat_vehiculos.id')
|
||||
->leftJoin('servicios_progreso', 'servicios_det.id', '=', 'servicios_progreso.servicio_det_id')
|
||||
->where('servicios_enc.sucursal_id', $sucursal)
|
||||
->where('servicios_enc.usuario_agenda_id', $usuario_id)
|
||||
->whereDate('servicios_det.fecha_solicitud','>=',$fecha_inicio)
|
||||
->whereDate('servicios_det.fecha_solicitud','<=',$fecha_final)
|
||||
->orderBy($orderBy,$order);
|
||||
|
||||
if($definio == DEFINIO_CLIENTE){
|
||||
$queryBuilder->where('servicios_det.definido_cliente', 1);
|
||||
}
|
||||
|
||||
if($definio == DEFINIO_ATENCION_CLIENTE){
|
||||
$queryBuilder->where('servicios_det.definido_cliente', 0);
|
||||
}
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
//$q->where('nombre','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$data = $queryBuilder->paginate($perPage);
|
||||
}else{
|
||||
$data = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
return response()->success($data);
|
||||
}
|
||||
|
||||
public function generarExcel(ProductividadAtencionClientesRequest $request){
|
||||
|
||||
$sucursal = $request->input('sucursal');
|
||||
$fecha_inicio = $request->input('fecha_inicio');
|
||||
$fecha_final = $request->input('fecha_final');
|
||||
$usuario_id = $request->input('usuario_id');
|
||||
$definio = $request->input('definio');
|
||||
|
||||
$campos = [
|
||||
'servicios_enc.id as numero_solicitud',
|
||||
DB::raw("DATE(servicios_det.fecha_solicitud) as 'fecha_servicio'"),
|
||||
DB::raw("TIME(servicios_det.fecha_solicitud) as 'hora_servicio'"),
|
||||
'cat_servicios.nombre as servicio',
|
||||
'servicios_det.costo_servicio as costo',
|
||||
'cat_tipos_servicios.nombre as tipo_servicio',
|
||||
'cat_estatus_servicios.nombre as estatus_servicio',
|
||||
'clientes.denominacion as nombre_cliente',
|
||||
DB::raw("CONCAT(clientes_domicilios.calle,' ',clientes_domicilios.num_ext,' ', clientes_domicilios.colonia,' ',clientes_domicilios.cp,' ',clientes_domicilios.ciudad) as domicilio"),
|
||||
DB::raw("CONCAT(asesor.nombre,' ',asesor.apellido_paterno,' ',asesor.apellido_materno) as asesor"),
|
||||
DB::raw("CONCAT(auxiliar.nombre,' ',auxiliar.apellido_paterno,' ',auxiliar.apellido_materno) as auxiliar"),
|
||||
'cat_vehiculos.num_economico as vehiculo',
|
||||
'servicios_progreso.duracion as duracion_servicio'
|
||||
];
|
||||
|
||||
$queryBuilder = ServicioDet::select($campos)
|
||||
->join('servicios_enc', 'servicios_det.servicio_enc_id', '=', 'servicios_enc.id')
|
||||
->join('cat_servicios', 'servicios_det.servicio_id', '=', 'cat_servicios.id')
|
||||
->join('cat_tipos_servicios', 'servicios_det.tipo_servicio_id', '=', 'cat_tipos_servicios.id')
|
||||
->join('cat_estatus_servicios','servicios_det.estatus_servicio_id','=','cat_estatus_servicios.id')
|
||||
->join('clientes','servicios_enc.cliente_id','=','clientes.id')
|
||||
->join('clientes_domicilios','servicios_enc.cliente_domicilio_id','=','clientes_domicilios.id')
|
||||
->join('users as asesor', 'servicios_det.operador_id', '=', 'asesor.id')
|
||||
->leftJoin('users as auxiliar', 'servicios_det.auxiliar_1', '=', 'auxiliar.id')
|
||||
->join('cat_vehiculos', 'servicios_det.vehiculo_id', '=', 'cat_vehiculos.id')
|
||||
->leftJoin('servicios_progreso', 'servicios_det.id', '=', 'servicios_progreso.servicio_det_id')
|
||||
->where('servicios_enc.sucursal_id', $sucursal)
|
||||
->where('servicios_enc.usuario_agenda_id', $usuario_id)
|
||||
->whereDate('servicios_det.fecha_solicitud','>=',$fecha_inicio)
|
||||
->whereDate('servicios_det.fecha_solicitud','<=',$fecha_final)
|
||||
->orderBy('servicios_enc.id','asc');
|
||||
|
||||
if($definio == DEFINIO_CLIENTE){
|
||||
$queryBuilder->where('servicios_det.definido_cliente', 1);
|
||||
}
|
||||
|
||||
if($definio == DEFINIO_ATENCION_CLIENTE){
|
||||
$queryBuilder->where('servicios_det.definido_cliente', 0);
|
||||
}
|
||||
|
||||
$servicios = $queryBuilder->get();
|
||||
$total = $queryBuilder->count();
|
||||
|
||||
$nombre_usuario = User::where('id', $usuario_id)->first();
|
||||
$titulo = "Reporte de Servicios Atención a Cliente ".$nombre_usuario->nombre." ".$nombre_usuario->apellido_paterno;
|
||||
|
||||
list($y_i, $m_i, $d_i) = explode("-", $fecha_inicio);
|
||||
list($y_f, $m_f, $d_f) = explode("-", $fecha_final);
|
||||
$f_i = $d_i."_".$m_i."_".$y_i;
|
||||
$f_f = $d_f."_".$m_f."_".$y_f;
|
||||
$nombre = "Reporte_Atención_Cliente_".$nombre_usuario->nombre."_".$nombre_usuario->apellido_paterno."_".$f_i."-".$f_f;
|
||||
|
||||
foreach ($servicios as $s){
|
||||
$s->costo = floatval($s->costo);
|
||||
list($y, $m, $d) = explode("-", $s->fecha_servicio);
|
||||
$s->fecha_servicio = "$d/$m/$y";
|
||||
$s->numero_solicitud = (int)$s->numero_solicitud;
|
||||
}
|
||||
|
||||
Excel::create($nombre, function($excel) use($servicios, $titulo, $fecha_inicio, $fecha_final, $total){
|
||||
|
||||
// Set the title
|
||||
$excel->setTitle('Reporte de Servicios Atención a Cliente');
|
||||
|
||||
// Chain the setters
|
||||
$excel->setCreator('DRENAX')
|
||||
->setCompany('DRENAX');
|
||||
|
||||
// Call them separately
|
||||
$excel->setDescription('Reporte de Servicios Atención a Cliente');
|
||||
|
||||
$excel->sheet('Reporte_Servicios_AtnCliente', function ($sheet) use($servicios, $titulo, $fecha_inicio, $fecha_final, $total) {
|
||||
|
||||
$sheet->setColumnFormat(array(
|
||||
'F' => '"$"#,##0.00_-',
|
||||
'C' => 'd/m/y'
|
||||
));
|
||||
|
||||
//Mostrar logo
|
||||
$sheet->mergeCells('B2:D6');
|
||||
|
||||
$objDrawing = new \PHPExcel_Worksheet_Drawing;
|
||||
$objDrawing->setPath(resource_path('assets/images/logos').'/logo_drenax.png');
|
||||
$objDrawing->setWidth(95);
|
||||
$objDrawing->setHeight(80);
|
||||
$objDrawing->setCoordinates('B2');
|
||||
$objDrawing->setOffsetX(9);
|
||||
$objDrawing->setOffsetY(9);
|
||||
$objDrawing->setWorksheet($sheet);
|
||||
|
||||
$sheet->mergeCells('I2:L6');
|
||||
|
||||
$sheet->cell('I2', function($cell) use($titulo, $fecha_inicio, $fecha_final, $total) {
|
||||
|
||||
$cell->setFontFamily('Aharoni');
|
||||
$cell->setFontWeight('bold');
|
||||
$cell->setAlignment('center');
|
||||
$cell->setValignment('center');
|
||||
$cell->setFontSize(20);
|
||||
$cell->setValue($titulo);
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('J8', function($cell) use($fecha_inicio) {
|
||||
list($y, $m, $d) = explode("-", $fecha_inicio);
|
||||
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue('Del: '.$d.'/'.$m.'/'.$y);
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('K8', function($cell) use($fecha_final) {
|
||||
list($y, $m, $d) = explode("-", $fecha_final);
|
||||
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue('Al: '.$d.'/'.$m.'/'.$y);
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('M8', function($cell) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue('Total:');
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('N8', function($cell) use($total) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue($total.' Servicios');
|
||||
|
||||
});
|
||||
|
||||
//Mostar valores de consulta
|
||||
$sheet->fromArray($servicios, null, 'B9', true);
|
||||
|
||||
//Formato en columnas de titulo
|
||||
$sheet->cells('B9:N9', function ($cells) {
|
||||
$cells->setBackground('#001870');
|
||||
$cells->setFontColor('#ffffff');
|
||||
$cells->setFontSize(13);
|
||||
$cells->setFontFamily('Calibri');
|
||||
$cells->setAlignment('left');
|
||||
$cells->setFontWeight('bold');
|
||||
});
|
||||
|
||||
$sheet->getStyle('B9:N9' , $sheet->getHighestRow())->getAlignment()->setWrapText(true);
|
||||
|
||||
//Titulos personalizados
|
||||
$titulos_cell = [
|
||||
['cell' => 'B9', 'titulo' => 'Número de solicitud'],
|
||||
['cell' => 'C9', 'titulo' => 'Fecha del servicio'],
|
||||
['cell' => 'D9', 'titulo' => 'Hora del servicio'],
|
||||
['cell' => 'E9', 'titulo' => 'Servicio'],
|
||||
['cell' => 'F9', 'titulo' => 'Costo de servicio'],
|
||||
['cell' => 'G9', 'titulo' => 'Tipo de servicio'],
|
||||
['cell' => 'H9', 'titulo' => 'Estatus de servicio'],
|
||||
['cell' => 'I9', 'titulo' => 'Nombre del cliente'],
|
||||
['cell' => 'J9', 'titulo' => 'Domicilio de servicio'],
|
||||
['cell' => 'K9', 'titulo' => 'Asesor de operaciones'],
|
||||
['cell' => 'L9', 'titulo' => 'Auxiliar de operaciones'],
|
||||
['cell' => 'M9', 'titulo' => 'Vehiculo asignado'],
|
||||
['cell' => 'N9', 'titulo' => 'Duración del servicio (cronómetro)']
|
||||
];
|
||||
|
||||
foreach ($titulos_cell as $t){
|
||||
$sheet->cell($t['cell'], function($cell) use($t) {
|
||||
$cell->setValue($t['titulo']);
|
||||
});
|
||||
}
|
||||
|
||||
//Size a columnas indicadas
|
||||
$columns_set = [
|
||||
'B9', 'C9', 'D9', 'M9', 'N9'
|
||||
];
|
||||
|
||||
foreach ($columns_set as $c){
|
||||
$set_column = [
|
||||
$c => [
|
||||
'width' => ($c == 'N9')? 23: 14,
|
||||
'height' => 40
|
||||
]
|
||||
];
|
||||
$sheet->setSize($set_column);
|
||||
}
|
||||
|
||||
//AutoSize en columnas indicadas
|
||||
$columns_auto= [
|
||||
'E','F','G','H','I','J','K','L'
|
||||
];
|
||||
|
||||
foreach ($columns_auto as $c){
|
||||
$sheet->getColumnDimension($c)->setAutoSize(true);
|
||||
}
|
||||
|
||||
$sheet->setWidth(array(
|
||||
'A' => 3,
|
||||
));
|
||||
|
||||
//Borde
|
||||
$columns_border= [
|
||||
'B','C','D','E','F','G','H','I','J','K','L','M','N'
|
||||
];
|
||||
|
||||
for ($i=0; $i<= $total; $i++){
|
||||
$row = 9 + $i;
|
||||
|
||||
foreach ($columns_border as $cb){
|
||||
$border = "$cb$row:$cb$row";
|
||||
$sheet->cells($border, function ($cells) {
|
||||
$cells->setBorder('thin', 'thin', 'thin', 'thin');
|
||||
});
|
||||
|
||||
if($row != 9 && ($cb == 'C' || $cb == 'D' || $cb == 'F' || $cb == 'N')){
|
||||
$sheet->cells("$cb$row", function ($cells) {
|
||||
$cells->setAlignment('right');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
})->store('xls', storage_path('app') . '/public/reportes/productividad_atencion_clientes/');
|
||||
|
||||
return response()->success(['nombre_archivo' => $nombre.'.xls?micro='.$this->getMicroSeconds()]);
|
||||
}
|
||||
}
|
||||
272
app/Http/Controllers/Reportes/SemanalController.php
Normal file
272
app/Http/Controllers/Reportes/SemanalController.php
Normal file
@@ -0,0 +1,272 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers\Reportes;
|
||||
|
||||
use const App\Http\Controllers\ASESOR_OPERACIONES;
|
||||
use const App\Http\Controllers\ATENCION_CLIENTES;
|
||||
use App\Models\TipoVehiculo;
|
||||
use App\Models\CatEstatuServicio;
|
||||
use App\Models\ServicioDet;
|
||||
use App\Models\ServicioEnc;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use App\Http\Controllers\Controller;
|
||||
use DB;
|
||||
use Log;
|
||||
|
||||
class SemanalController extends Controller
|
||||
{
|
||||
function getWeek($date){
|
||||
$date = new \DateTime($date);
|
||||
$week = $date->format("W");
|
||||
return $week;
|
||||
}
|
||||
|
||||
public function reportes(){
|
||||
|
||||
$fecha_actual = Carbon::now()->format('Y-m-d');
|
||||
$dias_semana = $this->obtener_semana($fecha_actual);
|
||||
|
||||
$currentWeek = $this->getWeek(date("Y-m-d"));
|
||||
$firstDateOfMonth = date("Y").'-'.date("m").'-01';
|
||||
$firstWeek = $this->getWeek($firstDateOfMonth);
|
||||
$lastDateOfMonth = date("Y-m-t", strtotime($firstDateOfMonth));
|
||||
$lastWeek = $this->getWeek($lastDateOfMonth);
|
||||
$weeks = 0;
|
||||
for($i=$firstWeek;$i<=$lastWeek;$i++) $weeks++;
|
||||
|
||||
$servicios_nombre_precios = $this->serviciosNombresPrecios($dias_semana);
|
||||
$tipos_servicios = $this->tiposServicios($dias_semana);
|
||||
$tipos_estados_servicio = $this->tipoEstadoServicio($dias_semana);
|
||||
$tipos_origen = $this->tiposOrigen($dias_semana);
|
||||
$atencion_cliente = $this->atencionCliente($dias_semana);
|
||||
$operadores = $this->operadores($dias_semana);
|
||||
$servicios_vehiculos_precios = $this->serviciosVehiculosPrecios($dias_semana);
|
||||
$capacidad_aprovechada = $this->capacidadAprovechada($currentWeek, $weeks);
|
||||
|
||||
return response()->success(compact('servicios_nombre_precios','tipos_servicios', 'tipos_estados_servicio', 'tipos_origen', 'atencion_cliente', 'operadores', 'servicios_vehiculos_precios', 'capacidad_aprovechada'));
|
||||
}
|
||||
|
||||
public function serviciosNombresPrecios($dias_semana){
|
||||
|
||||
$servicios = ServicioDet::select('cat_servicios.nombre as name', DB::raw("SUM(servicios_det.costo_servicio) AS costo, count(servicios_det.servicio_id) as y"))
|
||||
->join('cat_servicios', 'servicios_det.servicio_id', '=', 'cat_servicios.id')
|
||||
->whereIn(DB::raw("DATE(servicios_det.fecha_solicitud)"),$dias_semana)
|
||||
->groupBy('cat_servicios.nombre')
|
||||
->get();
|
||||
|
||||
$total_costo = (string)number_format(collect($servicios)->sum('costo'),2);
|
||||
|
||||
return compact('servicios', 'total_costo');
|
||||
}
|
||||
|
||||
public function tiposServicios($dias_semana){
|
||||
|
||||
$servicios = ServicioDet::select('cat_tipos_servicios.nombre as name', DB::raw("count(servicios_det.tipo_servicio_id) as y"))
|
||||
->join('cat_tipos_servicios', 'servicios_det.tipo_servicio_id', '=', 'cat_tipos_servicios.id')
|
||||
->whereIn(DB::raw("DATE(servicios_det.fecha_solicitud)"),$dias_semana)
|
||||
->groupBy('cat_tipos_servicios.nombre')
|
||||
->get();
|
||||
|
||||
return $servicios;
|
||||
}
|
||||
|
||||
public function tipoEstadoServicio($dias_semana){
|
||||
|
||||
$servicios = ServicioDet::select('cat_estatus_servicios.nombre as name', DB::raw("count(servicios_det.estatus_servicio_id) as y"))
|
||||
->join('cat_estatus_servicios', 'servicios_det.estatus_servicio_id', '=', 'cat_estatus_servicios.id')
|
||||
->whereIn(DB::raw("DATE(servicios_det.fecha_solicitud)"),$dias_semana)
|
||||
->groupBy('cat_estatus_servicios.nombre')
|
||||
->get();
|
||||
|
||||
return $servicios;
|
||||
}
|
||||
|
||||
public function tiposOrigen($dias_semana){
|
||||
|
||||
$servicios = ServicioEnc::select('cat_origenes.nombre as name', DB::raw("count(servicios_enc.origen_id) as y"))
|
||||
->join('servicios_det', 'servicios_enc.id', '=', 'servicios_det.servicio_enc_id')
|
||||
->join('cat_origenes', 'servicios_enc.origen_id', '=', 'cat_origenes.id')
|
||||
->whereIn(DB::raw("DATE(servicios_det.fecha_solicitud)"),$dias_semana)
|
||||
->groupBy('cat_origenes.nombre')
|
||||
->get();
|
||||
|
||||
return $servicios;
|
||||
}
|
||||
|
||||
public function atencionCliente($dias_semana){
|
||||
|
||||
$usuarios_series = [];
|
||||
$estatus_series = [];
|
||||
|
||||
$estatus_servicio = CatEstatuServicio::get();
|
||||
|
||||
foreach ($estatus_servicio as $e){
|
||||
|
||||
$usuarios_series = [];
|
||||
$valores_estatus = [];
|
||||
|
||||
$atencion_cliente = User::select('id', DB::raw("CONCAT(nombre, ' ',apellido_paterno) as nombre_atencion"))
|
||||
->where('tipo_empleado_id', ATENCION_CLIENTES)
|
||||
->get();
|
||||
|
||||
foreach ($atencion_cliente as $aC){
|
||||
|
||||
$total = ServicioEnc::join('servicios_det', 'servicios_enc.id', '=', 'servicios_det.servicio_enc_id')
|
||||
->join('cat_estatus_servicios', 'servicios_det.estatus_servicio_id', '=', 'cat_estatus_servicios.id')
|
||||
->where('servicios_enc.usuario_agenda_id',$aC->id)
|
||||
->whereIn(DB::raw("DATE(servicios_det.fecha_solicitud)"),$dias_semana);
|
||||
|
||||
|
||||
$total_general = ($total->count() == 1)? " (".$total->count()." servicio)" : " (".$total->count()." servicios)";
|
||||
$nombre = $aC->nombre_atencion.$total_general;
|
||||
|
||||
array_push($usuarios_series, $nombre);
|
||||
|
||||
$total_estatus = $total->where('servicios_det.estatus_servicio_id', $e->id)->count();
|
||||
array_push($valores_estatus, $total_estatus);
|
||||
}
|
||||
|
||||
$estatus_series[$e->nombre] = $valores_estatus;
|
||||
}
|
||||
|
||||
|
||||
$datos = [];
|
||||
foreach ($estatus_series as $key => $e){
|
||||
array_push($datos, ["name"=>$key, "data"=>$e]);
|
||||
}
|
||||
|
||||
$result = ["usuarios"=>$usuarios_series, "datos"=>$datos];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function operadores($dias_semana){
|
||||
|
||||
$usuarios_series = [];
|
||||
$estatus_series = [];
|
||||
|
||||
$estatus_servicio = CatEstatuServicio::get();
|
||||
|
||||
foreach ($estatus_servicio as $e){
|
||||
|
||||
$usuarios_series = [];
|
||||
$valores_estatus = [];
|
||||
|
||||
$operadores = User::select('id', DB::raw("CONCAT(nombre, ' ',apellido_paterno) as nombre_atencion"))
|
||||
->where('tipo_empleado_id', ASESOR_OPERACIONES)
|
||||
->get();
|
||||
|
||||
foreach ($operadores as $o){
|
||||
|
||||
|
||||
$total = ServicioDet::join('cat_estatus_servicios', 'servicios_det.estatus_servicio_id', '=', 'cat_estatus_servicios.id')
|
||||
->where('servicios_det.operador_id',$o->id)
|
||||
->whereIn(DB::raw("DATE(servicios_det.fecha_solicitud)"),$dias_semana);
|
||||
|
||||
$total_general = ($total->count() == 1)? " (".$total->count()." servicio)" : " (".$total->count()." servicios)";
|
||||
$nombre = $o->nombre_atencion.$total_general;
|
||||
|
||||
array_push($usuarios_series, $nombre);
|
||||
|
||||
$total_estatus = $total->where('servicios_det.estatus_servicio_id', $e->id)->count();
|
||||
array_push($valores_estatus, $total_estatus);
|
||||
}
|
||||
|
||||
$estatus_series[$e->nombre] = $valores_estatus;
|
||||
}
|
||||
|
||||
|
||||
$datos = [];
|
||||
foreach ($estatus_series as $key => $e){
|
||||
array_push($datos, ["name"=>$key, "data"=>$e]);
|
||||
}
|
||||
$result = ["usuarios"=>$usuarios_series, "datos"=>$datos];
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function serviciosVehiculosPrecios($dias_semana){
|
||||
|
||||
$servicios = ServicioDet::select('cat_vehiculos.num_economico as name', DB::raw("SUM(servicios_det.costo_servicio) AS costo, count(servicios_det.servicio_id) as y"))
|
||||
->join('cat_vehiculos', 'servicios_det.vehiculo_id', '=', 'cat_vehiculos.id')
|
||||
->whereIn(DB::raw("DATE(servicios_det.fecha_solicitud)"),$dias_semana)
|
||||
->groupBy('cat_vehiculos.num_economico')
|
||||
->get();
|
||||
|
||||
return $servicios;
|
||||
}
|
||||
|
||||
public function capacidadAprovechada($semana_actual, $weeks=4){
|
||||
|
||||
$respuesta = [];
|
||||
|
||||
$tipos_vehiculo = TipoVehiculo::select(['id', 'nombre'])->orderBy('nombre')->get();
|
||||
foreach ($tipos_vehiculo as $t){
|
||||
$tmpId = $t->id;
|
||||
$tmpNombre = $t->nombre;
|
||||
|
||||
$campos = [
|
||||
'cat_vehiculos.tipo_vehiculo_id',
|
||||
'cat_tipos_vehiculos.nombre AS tipo_vehiculo',
|
||||
'cat_tipos_vehiculos.objetivo_mensual',
|
||||
DB::raw("SEC_TO_TIME(SUM(TIME_TO_SEC(servicios_progreso.duracion))) AS 'total_duracion'"),
|
||||
DB::raw("TRUNCATE(SUM((TIME_TO_SEC(TIME(servicios_progreso.duracion))/60)/60), 3) AS 'total_duracion_fracc'")
|
||||
];
|
||||
|
||||
$datos = ServicioDet::select($campos)
|
||||
->join('servicios_enc', 'servicios_det.servicio_enc_id', '=', 'servicios_enc.id')
|
||||
->join('cat_servicios', 'servicios_det.servicio_id', '=', 'cat_servicios.id')
|
||||
->join('cat_tipos_servicios', 'servicios_det.tipo_servicio_id', '=', 'cat_tipos_servicios.id')
|
||||
->join('cat_estatus_servicios','servicios_det.estatus_servicio_id','=','cat_estatus_servicios.id')
|
||||
->join('cat_vehiculos', 'servicios_det.vehiculo_id', '=', 'cat_vehiculos.id')
|
||||
->join('cat_tipos_vehiculos', 'cat_tipos_vehiculos.id', '=', 'cat_vehiculos.tipo_vehiculo_id')
|
||||
->leftJoin('servicios_progreso', 'servicios_det.id', '=', 'servicios_progreso.servicio_det_id')
|
||||
->join('cat_origenes', 'servicios_enc.origen_id', '=', 'cat_origenes.id')
|
||||
->where('cat_vehiculos.tipo_vehiculo_id', $tmpId)
|
||||
->whereRaw("WEEKOFYEAR(DATE(servicios_det.fecha_solicitud))=?", $semana_actual)
|
||||
->groupBy('cat_vehiculos.tipo_vehiculo_id', 'cat_tipos_vehiculos.nombre', 'cat_tipos_vehiculos.objetivo_mensual')
|
||||
->first();
|
||||
|
||||
if($datos){
|
||||
array_push($respuesta, [
|
||||
'tipo_vehiculo_id'=>$datos->tipo_vehiculo_id,
|
||||
'tipo_vehiculo'=>$datos->tipo_vehiculo,
|
||||
'objetivo_mensual'=>$datos->objetivo_mensual,
|
||||
'objetivo_semanal'=>($weeks == 0) ? 0 : $datos->objetivo_mensual/($weeks),
|
||||
'semanas'=>$weeks,
|
||||
'total_duracion'=>$datos->total_duracion,
|
||||
'total_duracion_fracc'=>$datos->total_duracion_fracc,
|
||||
]);
|
||||
}else{
|
||||
array_push($respuesta, [
|
||||
'tipo_vehiculo_id'=>$tmpId,
|
||||
'tipo_vehiculo'=>$tmpNombre,
|
||||
'objetivo_mensual'=>0,
|
||||
'objetivo_semanal'=>0,
|
||||
'semanas'=>$weeks,
|
||||
'total_duracion'=>null,
|
||||
'total_duracion_fracc'=>null
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return $respuesta;
|
||||
}
|
||||
|
||||
function obtener_semana($date) {
|
||||
|
||||
$date2 = strtotime($date);
|
||||
$inicio0 = strtotime('sunday this week -1 week', $date2);
|
||||
$inicio=date('Y-m-d', $inicio0);
|
||||
|
||||
$dias = array();
|
||||
for($i=1;$i<=7;$i++){
|
||||
$dia = date("Y-m-d", strtotime("$inicio +$i day"));
|
||||
array_push($dias,$dia);
|
||||
}
|
||||
|
||||
return $dias;
|
||||
}
|
||||
|
||||
}
|
||||
444
app/Http/Controllers/Reportes/ServiciosAsesoresController.php
Normal file
444
app/Http/Controllers/Reportes/ServiciosAsesoresController.php
Normal file
@@ -0,0 +1,444 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Reportes;
|
||||
|
||||
use const App\Http\Controllers\ASESOR_OPERACIONES;
|
||||
use const App\Http\Controllers\AUXILIAR_TECNICO_1;
|
||||
use const App\Http\Controllers\AUXILIAR_TECNICO_2;
|
||||
use App\Http\Requests\Reportes\ConsultarAsesoresRequest;
|
||||
use App\Http\Requests\Reportes\ServiciosAsesoresRequest;
|
||||
use App\Models\ServicioDet;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use DB;
|
||||
use Excel;
|
||||
use Log;
|
||||
|
||||
class ServiciosAsesoresController extends Controller
|
||||
{
|
||||
public function consultarAsesores(ConsultarAsesoresRequest $request){
|
||||
|
||||
$sucursal = $request->input('sucursal');
|
||||
$fecha_inicio = $request->input('fecha_inicio');
|
||||
$fecha_final = $request->input('fecha_final');
|
||||
|
||||
$orderBy = $request->input('sortBy','nombre');
|
||||
$order = $request->input('order','asc');
|
||||
|
||||
$queryBuilder = User::select('id', 'nombre', 'apellido_paterno', 'apellido_materno', 'tipo_empleado_id')
|
||||
->where('sucursal_id', $sucursal)
|
||||
->whereIn('tipo_empleado_id', [ASESOR_OPERACIONES, AUXILIAR_TECNICO_1, AUXILIAR_TECNICO_2])
|
||||
->orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('nombre','like','%' .$query.'%')
|
||||
->orWhere('apellido_paterno','like','%' .$query.'%')
|
||||
->orWhere('apellido_materno','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
|
||||
$data = $queryBuilder->paginate($perPage);
|
||||
foreach ($data->items() as $u){
|
||||
|
||||
if($u->tipo_empleado_id == ASESOR_OPERACIONES){
|
||||
$u->tipo_empleado = 'Asesor de Operaciones';
|
||||
|
||||
$u->servicios_cantidad = ServicioDet::where('servicios_det.operador_id', $u->id)
|
||||
->whereDate('servicios_det.fecha_solicitud','>=',$fecha_inicio)
|
||||
->whereDate('servicios_det.fecha_solicitud','<=',$fecha_final)
|
||||
->count();
|
||||
}
|
||||
|
||||
if($u->tipo_empleado_id == AUXILIAR_TECNICO_1 || $u->tipo_empleado_id == AUXILIAR_TECNICO_2){
|
||||
$u->tipo_empleado = 'Auxiliar de Operaciones';
|
||||
|
||||
$u->servicios_cantidad = ServicioDet::where(function($q) use ($u){
|
||||
$q->where('servicios_det.auxiliar_1', $u->id)
|
||||
->orWhere('servicios_det.auxiliar_2', $u->id);
|
||||
})
|
||||
->whereDate('servicios_det.fecha_solicitud','>=',$fecha_inicio)
|
||||
->whereDate('servicios_det.fecha_solicitud','<=',$fecha_final)
|
||||
->count();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$users = $data;
|
||||
}else{
|
||||
|
||||
$data = $queryBuilder->get();
|
||||
foreach ($data as $u){
|
||||
$u->servicios_cantidad = ServicioDet::where('servicios_det.operador_id', $u->id)
|
||||
->whereDate('servicios_det.fecha_solicitud','>=',$fecha_inicio)
|
||||
->whereDate('servicios_det.fecha_solicitud','<=',$fecha_final)
|
||||
->count();
|
||||
|
||||
if($u->tipo_empleado_id == ASESOR_OPERACIONES){
|
||||
$u->tipo_empleado = 'Asesor de Operaciones';
|
||||
}
|
||||
|
||||
if($u->tipo_empleado_id == AUXILIAR_TECNICO_1 || $u->tipo_empleado_id == AUXILIAR_TECNICO_2){
|
||||
$u->tipo_empleado = 'Auxiliar de Operaciones';
|
||||
}
|
||||
}
|
||||
|
||||
$users = ['data'=>$data];
|
||||
}
|
||||
|
||||
return response()->success($users);
|
||||
}
|
||||
|
||||
public function reportes(ServiciosAsesoresRequest $request){
|
||||
|
||||
$orderBy = $request->input('sortBy','servicios_enc.id');
|
||||
$order = $request->input('order','asc');
|
||||
|
||||
$sucursal = $request->input('sucursal');
|
||||
$fecha_inicio = $request->input('fecha_inicio');
|
||||
$fecha_final = $request->input('fecha_final');
|
||||
$usuario_id = $request->input('usuario_id');
|
||||
|
||||
$campos = [
|
||||
'servicios_enc.id as numero_solicitud',
|
||||
DB::raw("DATE(servicios_det.fecha_solicitud) as 'fecha_servicio'"),
|
||||
DB::raw("TIME(servicios_det.fecha_solicitud) as 'hora_servicio'"),
|
||||
'cat_servicios.nombre as servicio',
|
||||
'servicios_det.costo_servicio as costo',
|
||||
'cat_tipos_servicios.nombre as tipo_servicio',
|
||||
'cat_estatus_servicios.nombre as estatus_servicio',
|
||||
'clientes.denominacion as nombre_cliente',
|
||||
'clientes_domicilios.calle as calle_cliente',
|
||||
'clientes_domicilios.entre_calles as entre_calles_cliente',
|
||||
'clientes_domicilios.num_ext as num_ext_cliente',
|
||||
'clientes_domicilios.num_int as num_int_cliente',
|
||||
'clientes_domicilios.colonia as colonia_cliente',
|
||||
'clientes_domicilios.ciudad as ciudad_cliente',
|
||||
'clientes_domicilios.cp as cp_cliente',
|
||||
'auxiliar.nombre as nombre_auxiliar',
|
||||
'auxiliar.apellido_paterno as apellido_paterno_auxiliar',
|
||||
'auxiliar.apellido_materno as apellido_materno_auxiliar',
|
||||
'cat_vehiculos.num_economico as vehiculo',
|
||||
'servicios_progreso.duracion as duracion_servicio',
|
||||
'servicios_progreso.litraje as litraje'
|
||||
];
|
||||
|
||||
$queryBuilder = ServicioDet::select($campos)
|
||||
->join('servicios_enc', 'servicios_det.servicio_enc_id', '=', 'servicios_enc.id')
|
||||
->join('cat_servicios', 'servicios_det.servicio_id', '=', 'cat_servicios.id')
|
||||
->join('cat_tipos_servicios', 'servicios_det.tipo_servicio_id', '=', 'cat_tipos_servicios.id')
|
||||
->join('cat_estatus_servicios','servicios_det.estatus_servicio_id','=','cat_estatus_servicios.id')
|
||||
->join('clientes','servicios_enc.cliente_id','=','clientes.id')
|
||||
->join('clientes_domicilios','servicios_enc.cliente_domicilio_id','=','clientes_domicilios.id')
|
||||
->leftJoin('users as auxiliar', 'servicios_det.auxiliar_1', '=', 'auxiliar.id')
|
||||
->join('cat_vehiculos', 'servicios_det.vehiculo_id', '=', 'cat_vehiculos.id')
|
||||
->leftJoin('servicios_progreso', 'servicios_det.id', '=', 'servicios_progreso.servicio_det_id')
|
||||
->where('servicios_enc.sucursal_id', $sucursal)
|
||||
->whereDate('servicios_det.fecha_solicitud','>=',$fecha_inicio)
|
||||
->whereDate('servicios_det.fecha_solicitud','<=',$fecha_final)
|
||||
->orderBy($orderBy,$order);
|
||||
|
||||
$user = User::where('id', $usuario_id)->first();
|
||||
|
||||
if($user->tipo_empleado_id == ASESOR_OPERACIONES){
|
||||
$queryBuilder->where('servicios_det.operador_id', $usuario_id);
|
||||
}
|
||||
|
||||
if($user->tipo_empleado_id == AUXILIAR_TECNICO_1 || $user->tipo_empleado_id == AUXILIAR_TECNICO_2){
|
||||
$queryBuilder->where(function($q) use ($usuario_id){
|
||||
$q->where('servicios_det.auxiliar_1', $usuario_id)
|
||||
->orWhere('servicios_det.auxiliar_2', $usuario_id);
|
||||
});
|
||||
}
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
//$q->where('nombre','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$data = $queryBuilder->paginate($perPage)->toArray();
|
||||
}else{
|
||||
$data = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
$total_duracion = $this->sumarTiempos($queryBuilder->pluck('duracion_servicio'));
|
||||
list($h,$m,$s) = explode(':',$total_duracion);
|
||||
$data['total_duracion'] = $h."hr ".$m."m ".$s."s";
|
||||
|
||||
return response()->success($data);
|
||||
}
|
||||
|
||||
public function generarExcel(ServiciosAsesoresRequest $request){
|
||||
|
||||
$sucursal = $request->input('sucursal');
|
||||
$fecha_inicio = $request->input('fecha_inicio');
|
||||
$fecha_final = $request->input('fecha_final');
|
||||
$usuario_id = $request->input('usuario_id');
|
||||
|
||||
$campos = [
|
||||
'servicios_enc.id as numero_solicitud',
|
||||
DB::raw("DATE(servicios_det.fecha_solicitud) as 'fecha_servicio'"),
|
||||
DB::raw("TIME(servicios_det.fecha_solicitud) as 'hora_servicio'"),
|
||||
'cat_servicios.nombre as servicio',
|
||||
'servicios_det.costo_servicio as costo',
|
||||
'cat_tipos_servicios.nombre as tipo_servicio',
|
||||
'cat_estatus_servicios.nombre as estatus_servicio',
|
||||
'clientes.denominacion as nombre_cliente',
|
||||
DB::raw("CONCAT(clientes_domicilios.calle,' ',clientes_domicilios.num_ext,' ', clientes_domicilios.colonia,' ',clientes_domicilios.cp,' ',clientes_domicilios.ciudad) as domicilio"),
|
||||
//DB::raw("CONCAT(auxiliar.nombre,' ',auxiliar.apellido_paterno,' ',auxiliar.apellido_materno) as auxiliar"),
|
||||
'cat_vehiculos.num_economico as vehiculo',
|
||||
'servicios_progreso.duracion as duracion_servicio',
|
||||
'servicios_progreso.litraje as litraje'
|
||||
|
||||
];
|
||||
|
||||
$queryBuilder = ServicioDet::select($campos)
|
||||
->join('servicios_enc', 'servicios_det.servicio_enc_id', '=', 'servicios_enc.id')
|
||||
->join('cat_servicios', 'servicios_det.servicio_id', '=', 'cat_servicios.id')
|
||||
->join('cat_tipos_servicios', 'servicios_det.tipo_servicio_id', '=', 'cat_tipos_servicios.id')
|
||||
->join('cat_estatus_servicios','servicios_det.estatus_servicio_id','=','cat_estatus_servicios.id')
|
||||
->join('clientes','servicios_enc.cliente_id','=','clientes.id')
|
||||
->join('clientes_domicilios','servicios_enc.cliente_domicilio_id','=','clientes_domicilios.id')
|
||||
->leftJoin('users as auxiliar', 'servicios_det.auxiliar_1', '=', 'auxiliar.id')
|
||||
->join('cat_vehiculos', 'servicios_det.vehiculo_id', '=', 'cat_vehiculos.id')
|
||||
->leftJoin('servicios_progreso', 'servicios_det.id', '=', 'servicios_progreso.servicio_det_id')
|
||||
->where('servicios_enc.sucursal_id', $sucursal)
|
||||
->whereDate('servicios_det.fecha_solicitud','>=',$fecha_inicio)
|
||||
->whereDate('servicios_det.fecha_solicitud','<=',$fecha_final)
|
||||
->orderBy('servicios_enc.id','asc');
|
||||
|
||||
$user = User::where('id', $usuario_id)->first();
|
||||
|
||||
if($user->tipo_empleado_id == ASESOR_OPERACIONES){
|
||||
$queryBuilder->where('servicios_det.operador_id', $usuario_id);
|
||||
}
|
||||
|
||||
if($user->tipo_empleado_id == AUXILIAR_TECNICO_1 || $user->tipo_empleado_id == AUXILIAR_TECNICO_2){
|
||||
$queryBuilder->where(function($q) use ($usuario_id){
|
||||
$q->where('servicios_det.auxiliar_1', $usuario_id)
|
||||
->orWhere('servicios_det.auxiliar_2', $usuario_id);
|
||||
});
|
||||
}
|
||||
|
||||
$servicios = $queryBuilder->get();
|
||||
|
||||
$total = $queryBuilder->count();
|
||||
|
||||
$total_duracion = $this->sumarTiempos($queryBuilder->pluck('duracion_servicio'));
|
||||
list($h,$m,$s) = explode(':',$total_duracion);
|
||||
$total_duracion = $h."hr ".$m."m ".$s."s";
|
||||
|
||||
$nombre_usuario = User::where('id', $usuario_id)->first();
|
||||
$titulo = "Reporte de Servicios Otorgados ".$nombre_usuario->nombre." ".$nombre_usuario->apellido_paterno;
|
||||
|
||||
list($y_i, $m_i, $d_i) = explode("-", $fecha_inicio);
|
||||
list($y_f, $m_f, $d_f) = explode("-", $fecha_final);
|
||||
$f_i = $d_i."_".$m_i."_".$y_i;
|
||||
$f_f = $d_f."_".$m_f."_".$y_f;
|
||||
$nombre = "Reporte_Servicios_Otorgados_".$nombre_usuario->nombre."_".$nombre_usuario->apellido_paterno."_".$f_i."-".$f_f;
|
||||
|
||||
foreach ($servicios as $s){
|
||||
$s->costo = floatval($s->costo);
|
||||
list($y, $m, $d) = explode("-", $s->fecha_servicio);
|
||||
$s->fecha_servicio = "$d/$m/$y";
|
||||
$s->numero_solicitud = (int)$s->numero_solicitud;
|
||||
}
|
||||
|
||||
Excel::create($nombre, function($excel) use($servicios, $titulo, $fecha_inicio, $fecha_final, $total, $total_duracion){
|
||||
|
||||
// Set the title
|
||||
$excel->setTitle('Reporte de Servicios Otorgados');
|
||||
|
||||
// Chain the setters
|
||||
$excel->setCreator('DRENAX')
|
||||
->setCompany('DRENAX');
|
||||
|
||||
// Call them separately
|
||||
$excel->setDescription('Reporte de Servicios Otorgados');
|
||||
|
||||
$excel->sheet('Reporte_Servicios_Asesor', function ($sheet) use($servicios, $titulo, $fecha_inicio, $fecha_final, $total, $total_duracion) {
|
||||
|
||||
$sheet->setColumnFormat(array(
|
||||
'F' => '"$"#,##0.00_-',
|
||||
'C' => 'd/m/y',
|
||||
'M' => '#,#'
|
||||
));
|
||||
|
||||
//Mostrar logo
|
||||
$sheet->mergeCells('B2:D6');
|
||||
|
||||
$objDrawing = new \PHPExcel_Worksheet_Drawing;
|
||||
$objDrawing->setPath(resource_path('assets/images/logos').'/logo_drenax.png');
|
||||
$objDrawing->setWidth(95);
|
||||
$objDrawing->setHeight(80);
|
||||
$objDrawing->setCoordinates('B2');
|
||||
$objDrawing->setOffsetX(9);
|
||||
$objDrawing->setOffsetY(9);
|
||||
$objDrawing->setWorksheet($sheet);
|
||||
|
||||
$sheet->mergeCells('G2:J6');
|
||||
|
||||
$sheet->cell('G2', function($cell) use($titulo) {
|
||||
|
||||
$cell->setFontFamily('Aharoni');
|
||||
$cell->setFontWeight('bold');
|
||||
$cell->setAlignment('center');
|
||||
$cell->setValignment('center');
|
||||
$cell->setFontSize(20);
|
||||
$cell->setValue($titulo);
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('H8', function($cell) use($fecha_inicio) {
|
||||
list($y, $m, $d) = explode("-", $fecha_inicio);
|
||||
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue('Del: '.$d.'/'.$m.'/'.$y);
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('I8', function($cell) use($fecha_final) {
|
||||
list($y, $m, $d) = explode("-", $fecha_final);
|
||||
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue('Al: '.$d.'/'.$m.'/'.$y);
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('K7', function($cell) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue('Duración:');
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('K8', function($cell) use($total_duracion) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue($total_duracion);
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('L7', function($cell) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue('Total:');
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('L8', function($cell) use($total) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue($total.' Servicios');
|
||||
|
||||
});
|
||||
|
||||
//Mostar valores de consulta
|
||||
$sheet->fromArray($servicios, null, 'B9', true);
|
||||
|
||||
//Formato en columnas de titulo
|
||||
$sheet->cells('B9:M9', function ($cells) {
|
||||
$cells->setBackground('#001870');
|
||||
$cells->setFontColor('#ffffff');
|
||||
$cells->setFontSize(13);
|
||||
$cells->setFontFamily('Calibri');
|
||||
$cells->setAlignment('left');
|
||||
$cells->setFontWeight('bold');
|
||||
});
|
||||
|
||||
$sheet->getStyle('B9:M9' , $sheet->getHighestRow())->getAlignment()->setWrapText(true);
|
||||
|
||||
|
||||
//Titulos personalizados
|
||||
$titulos_cell = [
|
||||
['cell' => 'B9', 'titulo' => 'Número de solicitud'],
|
||||
['cell' => 'C9', 'titulo' => 'Fecha del servicio'],
|
||||
['cell' => 'D9', 'titulo' => 'Hora del servicio'],
|
||||
['cell' => 'E9', 'titulo' => 'Servicio'],
|
||||
['cell' => 'F9', 'titulo' => 'Costo de servicio'],
|
||||
['cell' => 'G9', 'titulo' => 'Tipo de servicio'],
|
||||
['cell' => 'H9', 'titulo' => 'Estatus de servicio'],
|
||||
['cell' => 'I9', 'titulo' => 'Nombre del cliente'],
|
||||
['cell' => 'J9', 'titulo' => 'Domicilio de servicio'],
|
||||
['cell' => 'K9', 'titulo' => 'Vehiculo asignado'],
|
||||
['cell' => 'L9', 'titulo' => 'Duración del servicio (cronómetro)'],
|
||||
['cell' => 'M9', 'titulo' => 'Litraje']
|
||||
];
|
||||
|
||||
foreach ($titulos_cell as $t){
|
||||
$sheet->cell($t['cell'], function($cell) use($t) {
|
||||
$cell->setValue($t['titulo']);
|
||||
});
|
||||
}
|
||||
|
||||
//Size a columnas indicadas
|
||||
$columns_set = [
|
||||
'B9', 'C9', 'D9', 'K9', 'L9'
|
||||
];
|
||||
|
||||
foreach ($columns_set as $c){
|
||||
$set_column = [
|
||||
$c => [
|
||||
'width' => ($c == 'L9' || $c == 'K9')? 23: 14,
|
||||
'height' => 40
|
||||
]
|
||||
];
|
||||
$sheet->setSize($set_column);
|
||||
}
|
||||
|
||||
//AutoSize en columnas indicadas
|
||||
$columns_auto= [
|
||||
'E','F','G','H','I','J'
|
||||
];
|
||||
|
||||
foreach ($columns_auto as $c){
|
||||
$sheet->getColumnDimension($c)->setAutoSize(true);
|
||||
}
|
||||
|
||||
$sheet->setWidth(array(
|
||||
'A' => 3,
|
||||
));
|
||||
|
||||
//Borde
|
||||
$columns_border= [
|
||||
'B','C','D','E','F','G','H','I','J','K','L','M'
|
||||
];
|
||||
|
||||
for ($i=0; $i<= $total; $i++){
|
||||
$row = 9 + $i;
|
||||
|
||||
foreach ($columns_border as $cb){
|
||||
$border = "$cb$row:$cb$row";
|
||||
$sheet->cells($border, function ($cells) {
|
||||
$cells->setBorder('thin', 'thin', 'thin', 'thin');
|
||||
});
|
||||
|
||||
if($row != 9 && ($cb == 'C' || $cb == 'D' || $cb == 'F' || $cb == 'L')){
|
||||
$sheet->cells("$cb$row", function ($cells) {
|
||||
$cells->setAlignment('right');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
})->store('xls', storage_path('app') . '/public/reportes/servicios_asesores/');
|
||||
|
||||
return response()->success(['nombre_archivo' => $nombre.'.xls?micro='.$this->getMicroSeconds()]);
|
||||
}
|
||||
}
|
||||
368
app/Http/Controllers/Reportes/ServiciosClientesController.php
Normal file
368
app/Http/Controllers/Reportes/ServiciosClientesController.php
Normal file
@@ -0,0 +1,368 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Reportes;
|
||||
|
||||
use App\Http\Requests\Reportes\ConsultarClientesRequest;
|
||||
use App\Http\Requests\Reportes\ServiciosClientesRequest;
|
||||
use App\Models\Cliente;
|
||||
use App\Models\ServicioDet;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use DB;
|
||||
use Excel;
|
||||
|
||||
class ServiciosClientesController extends Controller
|
||||
{
|
||||
public function consultarClientes(ConsultarClientesRequest $request){
|
||||
|
||||
$sucursal = $request->input('sucursal');
|
||||
$fecha_inicio = $request->input('fecha_inicio');
|
||||
$fecha_final = $request->input('fecha_final');
|
||||
|
||||
$orderBy = $request->input('sortBy','denominacion');
|
||||
$order = $request->input('order','asc');
|
||||
|
||||
$queryBuilder = Cliente::select('clientes.id', 'clientes.denominacion')
|
||||
->join('servicios_enc', 'clientes.id', '=', 'servicios_enc.cliente_id')
|
||||
->join('servicios_det', 'servicios_enc.id', '=', 'servicios_det.servicio_enc_id')
|
||||
->whereDate('servicios_det.fecha_solicitud','>=',$fecha_inicio)
|
||||
->whereDate('servicios_det.fecha_solicitud','<=',$fecha_final)
|
||||
->where('clientes.sucursal_id', $sucursal)
|
||||
->orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
$q->where('denominacion','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
$queryBuilder = $queryBuilder->groupBy(['clientes.id', 'clientes.denominacion']);
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
|
||||
$data = $queryBuilder->paginate($perPage);
|
||||
foreach ($data->items() as $u){
|
||||
$u->servicios_cantidad = ServicioDet::join('servicios_enc','servicios_det.servicio_enc_id', '=', 'servicios_enc.id')
|
||||
->where('servicios_enc.cliente_id', $u->id)
|
||||
->whereDate('servicios_det.fecha_solicitud','>=',$fecha_inicio)
|
||||
->whereDate('servicios_det.fecha_solicitud','<=',$fecha_final)
|
||||
->count();
|
||||
}
|
||||
|
||||
$users = $data;
|
||||
}else{
|
||||
|
||||
$data = $queryBuilder->get();
|
||||
foreach ($data as $u){
|
||||
$u->servicios_cantidad = ServicioDet::join('servicios_enc','servicios_det.servicio_enc_id', '=', 'servicios_enc.id')
|
||||
->where('servicios_enc.cliente_id', $u->id)
|
||||
->whereDate('servicios_det.fecha_solicitud','>=',$fecha_inicio)
|
||||
->whereDate('servicios_det.fecha_solicitud','<=',$fecha_final)
|
||||
->count();
|
||||
}
|
||||
|
||||
$users = ['data'=>$data];
|
||||
}
|
||||
|
||||
return response()->success($users);
|
||||
}
|
||||
|
||||
public function reportes(ServiciosClientesRequest $request){
|
||||
|
||||
$orderBy = $request->input('sortBy','servicios_enc.id');
|
||||
$order = $request->input('order','asc');
|
||||
|
||||
$sucursal = $request->input('sucursal');
|
||||
$fecha_inicio = $request->input('fecha_inicio');
|
||||
$fecha_final = $request->input('fecha_final');
|
||||
$cliente_id = $request->input('cliente_id');
|
||||
|
||||
$campos = [
|
||||
'servicios_enc.id as numero_solicitud',
|
||||
DB::raw("DATE(servicios_det.fecha_solicitud) as 'fecha_servicio'"),
|
||||
DB::raw("TIME(servicios_det.fecha_solicitud) as 'hora_servicio'"),
|
||||
'cat_servicios.nombre as servicio',
|
||||
'servicios_det.costo_servicio as costo',
|
||||
'cat_tipos_servicios.nombre as tipo_servicio',
|
||||
'cat_estatus_servicios.nombre as estatus_servicio',
|
||||
'clientes_domicilios.calle as calle_cliente',
|
||||
'clientes_domicilios.entre_calles as entre_calles_cliente',
|
||||
'clientes_domicilios.num_ext as num_ext_cliente',
|
||||
'clientes_domicilios.num_int as num_int_cliente',
|
||||
'clientes_domicilios.colonia as colonia_cliente',
|
||||
'clientes_domicilios.ciudad as ciudad_cliente',
|
||||
'clientes_domicilios.cp as cp_cliente',
|
||||
'asesor.nombre as nombre_asesor',
|
||||
'asesor.apellido_paterno as apellido_paterno_asesor',
|
||||
'asesor.apellido_materno as apellido_materno_asesor',
|
||||
'auxiliar.nombre as nombre_auxiliar',
|
||||
'auxiliar.apellido_paterno as apellido_paterno_auxiliar',
|
||||
'auxiliar.apellido_materno as apellido_materno_auxiliar',
|
||||
'cat_vehiculos.num_economico as vehiculo',
|
||||
'servicios_progreso.duracion as duracion_servicio',
|
||||
'servicios_progreso.litraje as litraje'
|
||||
];
|
||||
|
||||
$queryBuilder = ServicioDet::select($campos)
|
||||
->join('servicios_enc', 'servicios_det.servicio_enc_id', '=', 'servicios_enc.id')
|
||||
->join('cat_servicios', 'servicios_det.servicio_id', '=', 'cat_servicios.id')
|
||||
->join('cat_tipos_servicios', 'servicios_det.tipo_servicio_id', '=', 'cat_tipos_servicios.id')
|
||||
->join('cat_estatus_servicios','servicios_det.estatus_servicio_id','=','cat_estatus_servicios.id')
|
||||
->join('clientes_domicilios','servicios_enc.cliente_domicilio_id','=','clientes_domicilios.id')
|
||||
->join('users as asesor', 'servicios_det.operador_id', '=', 'asesor.id')
|
||||
->leftJoin('users as auxiliar', 'servicios_det.auxiliar_1', '=', 'auxiliar.id')
|
||||
->join('cat_vehiculos', 'servicios_det.vehiculo_id', '=', 'cat_vehiculos.id')
|
||||
->leftJoin('servicios_progreso', 'servicios_det.id', '=', 'servicios_progreso.servicio_det_id')
|
||||
->where('servicios_enc.sucursal_id', $sucursal)
|
||||
->where('servicios_enc.cliente_id', $cliente_id)
|
||||
->whereDate('servicios_det.fecha_solicitud','>=',$fecha_inicio)
|
||||
->whereDate('servicios_det.fecha_solicitud','<=',$fecha_final)
|
||||
->orderBy($orderBy,$order);
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
//$q->where('nombre','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$data = $queryBuilder->paginate($perPage);
|
||||
}else{
|
||||
$data = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
return response()->success($data);
|
||||
}
|
||||
|
||||
public function generarExcel(ServiciosClientesRequest $request){
|
||||
|
||||
$sucursal = $request->input('sucursal');
|
||||
$fecha_inicio = $request->input('fecha_inicio');
|
||||
$fecha_final = $request->input('fecha_final');
|
||||
$cliente_id = $request->input('cliente_id');
|
||||
|
||||
$campos = [
|
||||
'servicios_enc.id as numero_solicitud',
|
||||
DB::raw("DATE(servicios_det.fecha_solicitud) as 'fecha_servicio'"),
|
||||
DB::raw("TIME(servicios_det.fecha_solicitud) as 'hora_servicio'"),
|
||||
'cat_servicios.nombre as servicio',
|
||||
'servicios_det.costo_servicio as costo',
|
||||
'cat_tipos_servicios.nombre as tipo_servicio',
|
||||
'cat_estatus_servicios.nombre as estatus_servicio',
|
||||
DB::raw("CONCAT(clientes_domicilios.calle,' ',clientes_domicilios.num_ext,' ', clientes_domicilios.colonia,' ',clientes_domicilios.cp,' ',clientes_domicilios.ciudad) as domicilio"),
|
||||
DB::raw("CONCAT(asesor.nombre,' ',asesor.apellido_paterno,' ',asesor.apellido_materno) as asesor"),
|
||||
DB::raw("CONCAT(auxiliar.nombre,' ',auxiliar.apellido_paterno,' ',auxiliar.apellido_materno) as auxiliar"),
|
||||
'cat_vehiculos.num_economico as vehiculo',
|
||||
'servicios_progreso.duracion as duracion_servicio',
|
||||
'servicios_progreso.litraje as litraje'
|
||||
];
|
||||
|
||||
$queryBuilder = ServicioDet::select($campos)
|
||||
->join('servicios_enc', 'servicios_det.servicio_enc_id', '=', 'servicios_enc.id')
|
||||
->join('cat_servicios', 'servicios_det.servicio_id', '=', 'cat_servicios.id')
|
||||
->join('cat_tipos_servicios', 'servicios_det.tipo_servicio_id', '=', 'cat_tipos_servicios.id')
|
||||
->join('cat_estatus_servicios','servicios_det.estatus_servicio_id','=','cat_estatus_servicios.id')
|
||||
->join('clientes_domicilios','servicios_enc.cliente_domicilio_id','=','clientes_domicilios.id')
|
||||
->join('users as asesor', 'servicios_det.operador_id', '=', 'asesor.id')
|
||||
->leftJoin('users as auxiliar', 'servicios_det.auxiliar_1', '=', 'auxiliar.id')
|
||||
->join('cat_vehiculos', 'servicios_det.vehiculo_id', '=', 'cat_vehiculos.id')
|
||||
->leftJoin('servicios_progreso', 'servicios_det.id', '=', 'servicios_progreso.servicio_det_id')
|
||||
->where('servicios_enc.sucursal_id', $sucursal)
|
||||
->where('servicios_enc.cliente_id', $cliente_id)
|
||||
->whereDate('servicios_det.fecha_solicitud','>=',$fecha_inicio)
|
||||
->whereDate('servicios_det.fecha_solicitud','<=',$fecha_final)
|
||||
->orderBy('servicios_enc.id','asc');
|
||||
|
||||
$servicios = $queryBuilder->get();
|
||||
$total = $queryBuilder->count();
|
||||
|
||||
$cliente = Cliente::where('id', $cliente_id)->first();
|
||||
$titulo = "Reporte de Servicios de Cliente ".$cliente->denominacion;
|
||||
|
||||
list($y_i, $m_i, $d_i) = explode("-", $fecha_inicio);
|
||||
list($y_f, $m_f, $d_f) = explode("-", $fecha_final);
|
||||
$f_i = $d_i."_".$m_i."_".$y_i;
|
||||
$f_f = $d_f."_".$m_f."_".$y_f;
|
||||
$nombre = "Reporte_Servicios_Cliente_".$cliente->denominacion."_".$f_i."-".$f_f;
|
||||
|
||||
foreach ($servicios as $s){
|
||||
$s->costo = floatval($s->costo);
|
||||
list($y, $m, $d) = explode("-", $s->fecha_servicio);
|
||||
$s->fecha_servicio = "$d/$m/$y";
|
||||
$s->numero_solicitud = (int)$s->numero_solicitud;
|
||||
}
|
||||
|
||||
Excel::create($nombre, function($excel) use($servicios, $titulo, $fecha_inicio, $fecha_final, $total){
|
||||
|
||||
// Set the title
|
||||
$excel->setTitle('Reporte de Servicios de Cliente');
|
||||
|
||||
// Chain the setters
|
||||
$excel->setCreator('DRENAX')
|
||||
->setCompany('DRENAX');
|
||||
|
||||
// Call them separately
|
||||
$excel->setDescription('Reporte de Servicios de Cliente');
|
||||
|
||||
$excel->sheet('Reporte_Servicios_Cliente', function ($sheet) use($servicios, $titulo, $fecha_inicio, $fecha_final, $total) {
|
||||
|
||||
$sheet->setColumnFormat(array(
|
||||
'F' => '"$"#,##0.00_-',
|
||||
'C' => 'd/m/y',
|
||||
'N' => '#,#'
|
||||
));
|
||||
|
||||
//Mostrar logo
|
||||
$sheet->mergeCells('B2:D6');
|
||||
|
||||
$objDrawing = new \PHPExcel_Worksheet_Drawing;
|
||||
$objDrawing->setPath(resource_path('assets/images/logos').'/logo_drenax.png');
|
||||
$objDrawing->setWidth(95);
|
||||
$objDrawing->setHeight(80);
|
||||
$objDrawing->setCoordinates('B2');
|
||||
$objDrawing->setOffsetX(9);
|
||||
$objDrawing->setOffsetY(9);
|
||||
$objDrawing->setWorksheet($sheet);
|
||||
|
||||
$sheet->mergeCells('H2:K6');
|
||||
|
||||
$sheet->cell('H2', function($cell) use($titulo, $fecha_inicio, $fecha_final, $total) {
|
||||
|
||||
$cell->setFontFamily('Aharoni');
|
||||
$cell->setFontWeight('bold');
|
||||
$cell->setAlignment('center');
|
||||
$cell->setValignment('center');
|
||||
$cell->setFontSize(20);
|
||||
$cell->setValue($titulo);
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('I8', function($cell) use($fecha_inicio) {
|
||||
list($y, $m, $d) = explode("-", $fecha_inicio);
|
||||
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue('Del: '.$d.'/'.$m.'/'.$y);
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('J8', function($cell) use($fecha_final) {
|
||||
list($y, $m, $d) = explode("-", $fecha_final);
|
||||
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue('Al: '.$d.'/'.$m.'/'.$y);
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('L8', function($cell) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue('Total:');
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('M8', function($cell) use($total) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue($total.' Servicios');
|
||||
|
||||
});
|
||||
|
||||
//Mostar valores de consulta
|
||||
$sheet->fromArray($servicios, null, 'B9', true);
|
||||
|
||||
//Formato en columnas de titulo
|
||||
$sheet->cells('B9:N9', function ($cells) {
|
||||
$cells->setBackground('#001870');
|
||||
$cells->setFontColor('#ffffff');
|
||||
$cells->setFontSize(13);
|
||||
$cells->setFontFamily('Calibri');
|
||||
$cells->setAlignment('left');
|
||||
$cells->setFontWeight('bold');
|
||||
});
|
||||
|
||||
$sheet->getStyle('B9:N9' , $sheet->getHighestRow())->getAlignment()->setWrapText(true);
|
||||
|
||||
//Titulos personalizados
|
||||
$titulos_cell = [
|
||||
['cell' => 'B9', 'titulo' => 'Número de solicitud'],
|
||||
['cell' => 'C9', 'titulo' => 'Fecha del servicio'],
|
||||
['cell' => 'D9', 'titulo' => 'Hora del servicio'],
|
||||
['cell' => 'E9', 'titulo' => 'Servicio'],
|
||||
['cell' => 'F9', 'titulo' => 'Costo de servicio'],
|
||||
['cell' => 'G9', 'titulo' => 'Tipo de servicio'],
|
||||
['cell' => 'H9', 'titulo' => 'Estatus de servicio'],
|
||||
['cell' => 'I9', 'titulo' => 'Domicilio de servicio'],
|
||||
['cell' => 'J9', 'titulo' => 'Asesor de operaciones'],
|
||||
['cell' => 'K9', 'titulo' => 'Auxiliar de operaciones'],
|
||||
['cell' => 'L9', 'titulo' => 'Vehiculo asignado'],
|
||||
['cell' => 'M9', 'titulo' => 'Duración del servicio (cronómetro)'],
|
||||
['cell' => 'N9', 'titulo' => 'Litraje']
|
||||
];
|
||||
|
||||
foreach ($titulos_cell as $t){
|
||||
$sheet->cell($t['cell'], function($cell) use($t) {
|
||||
$cell->setValue($t['titulo']);
|
||||
});
|
||||
}
|
||||
|
||||
//Size a columnas indicadas
|
||||
$columns_set = [
|
||||
'B9', 'C9', 'D9', 'L9', 'M9'
|
||||
];
|
||||
|
||||
foreach ($columns_set as $c){
|
||||
$set_column = [
|
||||
$c => [
|
||||
'width' => ($c == 'N9')? 23: 14,
|
||||
'height' => 50
|
||||
]
|
||||
];
|
||||
$sheet->setSize($set_column);
|
||||
}
|
||||
|
||||
//AutoSize en columnas indicadas
|
||||
$columns_auto= [
|
||||
'E','F','G','H','I','J','K'
|
||||
];
|
||||
|
||||
foreach ($columns_auto as $c){
|
||||
$sheet->getColumnDimension($c)->setAutoSize(true);
|
||||
}
|
||||
|
||||
$sheet->setWidth(array(
|
||||
'A' => 3,
|
||||
));
|
||||
|
||||
//Borde
|
||||
$columns_border= [
|
||||
'B','C','D','E','F','G','H','I','J','K','L','M','N'
|
||||
];
|
||||
|
||||
for ($i=0; $i<= $total; $i++){
|
||||
$row = 9 + $i;
|
||||
|
||||
foreach ($columns_border as $cb){
|
||||
$border = "$cb$row:$cb$row";
|
||||
$sheet->cells($border, function ($cells) {
|
||||
$cells->setBorder('thin', 'thin', 'thin', 'thin');
|
||||
});
|
||||
|
||||
if($row != 9 && ($cb == 'C' || $cb == 'D' || $cb == 'F' || $cb == 'N')){
|
||||
$sheet->cells("$cb$row", function ($cells) {
|
||||
$cells->setAlignment('right');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
})->store('xls', storage_path('app') . '/public/reportes/servicios_clientes/');
|
||||
|
||||
return response()->success(['nombre_archivo' => $nombre.'.xls?micro='.$this->getMicroSeconds()]);
|
||||
}
|
||||
}
|
||||
429
app/Http/Controllers/Reportes/ServiciosController.php
Normal file
429
app/Http/Controllers/Reportes/ServiciosController.php
Normal file
@@ -0,0 +1,429 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Reportes;
|
||||
|
||||
use App\Http\Requests\Reportes\ServiciosRequest;
|
||||
use App\Models\ServicioDet;
|
||||
use App\Models\Sucursal;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Excel;
|
||||
use Log;
|
||||
|
||||
|
||||
class ServiciosController extends Controller
|
||||
{
|
||||
public function reportes(ServiciosRequest $request){
|
||||
|
||||
$orderBy = $request->input('sortBy','servicios_enc.id');
|
||||
$order = $request->input('order','asc');
|
||||
|
||||
$sucursal = $request->input('sucursal');
|
||||
$fecha_inicio = $request->input('fecha_inicio');
|
||||
$fecha_final = $request->input('fecha_final');
|
||||
$tipo_servicio = $request->input('tipo_servicio');
|
||||
$estado_servicio = $request->input('estado_servicio');
|
||||
$servicio = $request->input('servicio');
|
||||
$origen = $request->input('origen');
|
||||
|
||||
$campos = [
|
||||
'servicios_enc.id as numero_solicitud',
|
||||
DB::raw("DATE(servicios_det.fecha_solicitud) as 'fecha_servicio'"),
|
||||
DB::raw("TIME(servicios_det.fecha_solicitud) as 'hora_servicio'"),
|
||||
'cat_servicios.nombre as servicio',
|
||||
'servicios_det.costo_servicio as costo',
|
||||
'cat_tipos_servicios.nombre as tipo_servicio',
|
||||
'cat_estatus_servicios.nombre as estatus_servicio',
|
||||
'clientes.denominacion as nombre_cliente',
|
||||
'clientes_domicilios.calle as calle_cliente',
|
||||
'clientes_domicilios.entre_calles as entre_calles_cliente',
|
||||
'clientes_domicilios.num_ext as num_ext_cliente',
|
||||
'clientes_domicilios.num_int as num_int_cliente',
|
||||
'clientes_domicilios.colonia as colonia_cliente',
|
||||
'clientes_domicilios.ciudad as ciudad_cliente',
|
||||
'clientes_domicilios.cp as cp_cliente',
|
||||
'asesor.nombre as nombre_asesor',
|
||||
'asesor.apellido_paterno as apellido_paterno_asesor',
|
||||
'asesor.apellido_materno as apellido_materno_asesor',
|
||||
'auxiliar.nombre as nombre_auxiliar',
|
||||
'auxiliar.apellido_paterno as apellido_paterno_auxiliar',
|
||||
'auxiliar.apellido_materno as apellido_materno_auxiliar',
|
||||
'cat_vehiculos.num_economico as vehiculo',
|
||||
'servicios_progreso.duracion as duracion_servicio',
|
||||
DB::raw("DATE(servicios_progreso.fecha_ini_servidor) as 'fecha_inicio_servicio'"),
|
||||
DB::raw("TIME(servicios_progreso.fecha_ini_servidor) as 'hora_inicio_servicio'"),
|
||||
DB::raw("TIME_FORMAT(TIMEDIFF(servicios_det.fecha_solicitud, servicios_progreso.fecha_ini_servidor),'%Hhr %im %ss') as diferencia"),
|
||||
'cat_origenes.nombre as origen',
|
||||
'servicios_progreso.litraje as litraje'
|
||||
];
|
||||
|
||||
$queryBuilder = ServicioDet::select($campos)
|
||||
->join('servicios_enc', 'servicios_det.servicio_enc_id', '=', 'servicios_enc.id')
|
||||
->join('cat_servicios', 'servicios_det.servicio_id', '=', 'cat_servicios.id')
|
||||
->join('cat_tipos_servicios', 'servicios_det.tipo_servicio_id', '=', 'cat_tipos_servicios.id')
|
||||
->join('cat_estatus_servicios','servicios_det.estatus_servicio_id','=','cat_estatus_servicios.id')
|
||||
->join('clientes','servicios_enc.cliente_id','=','clientes.id')
|
||||
->join('clientes_domicilios','servicios_enc.cliente_domicilio_id','=','clientes_domicilios.id')
|
||||
->join('users as asesor', 'servicios_det.operador_id', '=', 'asesor.id')
|
||||
->leftJoin('users as auxiliar', 'servicios_det.auxiliar_1', '=', 'auxiliar.id')
|
||||
->join('cat_vehiculos', 'servicios_det.vehiculo_id', '=', 'cat_vehiculos.id')
|
||||
->leftJoin('servicios_progreso', 'servicios_det.id', '=', 'servicios_progreso.servicio_det_id')
|
||||
->join('cat_origenes', 'servicios_enc.origen_id', '=', 'cat_origenes.id')
|
||||
->where('servicios_enc.sucursal_id', $sucursal)
|
||||
->whereDate('servicios_det.fecha_solicitud','>=',$fecha_inicio)
|
||||
->whereDate('servicios_det.fecha_solicitud','<=',$fecha_final)
|
||||
->orderBy($orderBy,$order);
|
||||
|
||||
if($tipo_servicio != 0){
|
||||
$queryBuilder->where('servicios_det.tipo_servicio_id', $tipo_servicio);
|
||||
}
|
||||
|
||||
if($estado_servicio != 0){
|
||||
$queryBuilder->where('servicios_det.estatus_servicio_id', $estado_servicio);
|
||||
}
|
||||
|
||||
if($servicio != 0){
|
||||
$queryBuilder->where('servicios_det.servicio_id', $servicio);
|
||||
}
|
||||
|
||||
if($origen != 0){
|
||||
$queryBuilder->where('servicios_enc.origen_id', $origen);
|
||||
}
|
||||
|
||||
if($query = $request->get('query',false)){
|
||||
$queryBuilder->where(function($q) use ($query){
|
||||
//$q->where('nombre','like','%' .$query.'%');
|
||||
});
|
||||
}
|
||||
$total_servicios = $queryBuilder->count();
|
||||
$total_costo = $queryBuilder->sum('servicios_det.costo_servicio');
|
||||
|
||||
if($perPage = $request->input('perPage',false)){
|
||||
$data = $queryBuilder->paginate($perPage)->toArray();
|
||||
}else{
|
||||
$data = ['data'=>$queryBuilder->get()];
|
||||
}
|
||||
|
||||
$data['total_servicios'] = $total_servicios;
|
||||
$data['total_costo'] = $total_costo;
|
||||
|
||||
return response()->success($data);
|
||||
}
|
||||
|
||||
public function generarExcel(ServiciosRequest $request){
|
||||
|
||||
$sucursal = $request->input('sucursal');
|
||||
$fecha_inicio = $request->input('fecha_inicio');
|
||||
$fecha_final = $request->input('fecha_final');
|
||||
$tipo_servicio = $request->input('tipo_servicio');
|
||||
$estado_servicio = $request->input('estado_servicio');
|
||||
$servicio = $request->input('servicio');
|
||||
$origen = $request->input('origen');
|
||||
|
||||
$campos = [
|
||||
'servicios_enc.id as numero_solicitud',
|
||||
'servicios_enc.fecha_agenda',
|
||||
'servicios_det.fecha_solicitud',
|
||||
'servicios_det.fecha_solicitud as tiempo_atencion',
|
||||
'cat_servicios.nombre as servicio',
|
||||
'servicios_det.costo_servicio as costo',
|
||||
'cat_tipos_servicios.nombre as tipo_servicio',
|
||||
'cat_estatus_servicios.nombre as estatus_servicio',
|
||||
'clientes.denominacion as nombre_cliente',
|
||||
'clientes.email as email_cliente',
|
||||
DB::raw("CONCAT(clientes_domicilios.calle,' ',clientes_domicilios.num_ext,' ', clientes_domicilios.colonia,' ',clientes_domicilios.cp,' ',clientes_domicilios.ciudad) as domicilio"),
|
||||
'clientes_domicilios.email as email_domicilio',
|
||||
DB::raw("CONCAT(asesor.nombre,' ',asesor.apellido_paterno,' ',asesor.apellido_materno) as asesor"),
|
||||
DB::raw("CONCAT(auxiliar.nombre,' ',auxiliar.apellido_paterno,' ',auxiliar.apellido_materno) as auxiliar"),
|
||||
'cat_vehiculos.num_economico as vehiculo',
|
||||
'servicios_progreso.duracion as duracion_servicio',
|
||||
DB::raw("TIME(servicios_progreso.fecha_ini_servidor) as 'hora_inicio_servicio'"),
|
||||
DB::raw("TIME_FORMAT(TIMEDIFF(servicios_det.fecha_solicitud, servicios_progreso.fecha_ini_servidor),'%Hhr %im %ss') as diferencia"),
|
||||
'cat_origenes.nombre as origen',
|
||||
'servicios_progreso.litraje as litraje',
|
||||
'servicios_det.facturado as facturado',
|
||||
'cat_formas_pagos.nombre as forma_pago',
|
||||
];
|
||||
|
||||
$queryBuilder = ServicioDet::select($campos)
|
||||
->join('servicios_enc', 'servicios_det.servicio_enc_id', '=', 'servicios_enc.id')
|
||||
->join('cat_servicios', 'servicios_det.servicio_id', '=', 'cat_servicios.id')
|
||||
->join('cat_tipos_servicios', 'servicios_det.tipo_servicio_id', '=', 'cat_tipos_servicios.id')
|
||||
->join('cat_estatus_servicios','servicios_det.estatus_servicio_id','=','cat_estatus_servicios.id')
|
||||
->join('clientes','servicios_enc.cliente_id','=','clientes.id')
|
||||
->join('clientes_domicilios','servicios_enc.cliente_domicilio_id','=','clientes_domicilios.id')
|
||||
->join('users as asesor', 'servicios_det.operador_id', '=', 'asesor.id')
|
||||
->join('cat_formas_pagos', 'cat_formas_pagos.id', '=', 'servicios_enc.forma_pago_id')
|
||||
->leftJoin('users as auxiliar', 'servicios_det.auxiliar_1', '=', 'auxiliar.id')
|
||||
->join('cat_vehiculos', 'servicios_det.vehiculo_id', '=', 'cat_vehiculos.id')
|
||||
->leftJoin('servicios_progreso', 'servicios_det.id', '=', 'servicios_progreso.servicio_det_id')
|
||||
->join('cat_origenes', 'servicios_enc.origen_id', '=', 'cat_origenes.id')
|
||||
->where('servicios_enc.sucursal_id', $sucursal)
|
||||
->whereDate('servicios_det.fecha_solicitud','>=',$fecha_inicio)
|
||||
->whereDate('servicios_det.fecha_solicitud','<=',$fecha_final)
|
||||
->orderBy('servicios_enc.id','asc');
|
||||
|
||||
if($tipo_servicio != 0){
|
||||
$queryBuilder->where('servicios_det.tipo_servicio_id', $tipo_servicio);
|
||||
}
|
||||
|
||||
if($estado_servicio != 0){
|
||||
$queryBuilder->where('servicios_det.estatus_servicio_id', $estado_servicio);
|
||||
}
|
||||
|
||||
if($servicio != 0){
|
||||
$queryBuilder->where('servicios_det.servicio_id', $servicio);
|
||||
}
|
||||
|
||||
if($origen != 0){
|
||||
$queryBuilder->where('servicios_enc.origen_id', $origen);
|
||||
}
|
||||
|
||||
$servicios = $queryBuilder->get();
|
||||
$total = $queryBuilder->count();
|
||||
$total_costo = $queryBuilder->sum('servicios_det.costo_servicio');
|
||||
$total_litraje = $queryBuilder->sum('servicios_progreso.litraje');
|
||||
|
||||
$nombre_sucursal = Sucursal::where('id', $sucursal)->first();
|
||||
$titulo = "Reporte de Servicios ".$nombre_sucursal->nombre;
|
||||
|
||||
list($y_i, $m_i, $d_i) = explode("-", $fecha_inicio);
|
||||
list($y_f, $m_f, $d_f) = explode("-", $fecha_final);
|
||||
$f_i = $d_i."_".$m_i."_".$y_i;
|
||||
$f_f = $d_f."_".$m_f."_".$y_f;
|
||||
$nombre = "Reporte_Servicios_".$nombre_sucursal->nombre."_".$f_i."-".$f_f;
|
||||
|
||||
foreach ($servicios as $s){
|
||||
$s->costo = floatval($s->costo);
|
||||
$s->numero_solicitud = (int)$s->numero_solicitud;
|
||||
if($s->facturado > 0){
|
||||
$s->facturado = "Facturado";
|
||||
}else{
|
||||
$s->facturado = "No facturado";
|
||||
}
|
||||
|
||||
$s->tiempo_atencion = $this->diferenciaFechas($s->fecha_agenda, $s->fecha_solicitud);
|
||||
$s->fecha_agenda = $this->formatearFechaHora($s->fecha_agenda);
|
||||
$s->fecha_solicitud = $this->formatearFechaHora($s->fecha_solicitud);
|
||||
}
|
||||
|
||||
Excel::create($nombre, function($excel) use($servicios, $titulo, $fecha_inicio, $fecha_final, $total, $total_costo, $total_litraje){
|
||||
|
||||
// Set the title
|
||||
$excel->setTitle('Reporte de Servicios');
|
||||
|
||||
// Chain the setters
|
||||
$excel->setCreator('DRENAX')
|
||||
->setCompany('DRENAX');
|
||||
|
||||
// Call them separately
|
||||
$excel->setDescription('Reporte de Servicios');
|
||||
|
||||
$excel->sheet('Reporte_Servicios_Sucursal', function ($sheet) use($servicios, $titulo, $fecha_inicio, $fecha_final, $total, $total_costo, $total_litraje) {
|
||||
|
||||
$sheet->setColumnFormat(array(
|
||||
'G' => '"$"#,##0.00_-',
|
||||
'C' => 'd/m/y',
|
||||
'N8' => '"$"#,##0.00_-',
|
||||
'S' => '#,#',
|
||||
'P8' => '#,#'
|
||||
));
|
||||
|
||||
//Mostrar logo
|
||||
$sheet->mergeCells('B2:D6');
|
||||
|
||||
$objDrawing = new \PHPExcel_Worksheet_Drawing;
|
||||
$objDrawing->setPath(resource_path('assets/images/logos').'/logo_drenax.png');
|
||||
$objDrawing->setWidth(95);
|
||||
$objDrawing->setHeight(80);
|
||||
$objDrawing->setCoordinates('B2');
|
||||
$objDrawing->setOffsetX(9);
|
||||
$objDrawing->setOffsetY(9);
|
||||
$objDrawing->setWorksheet($sheet);
|
||||
|
||||
$sheet->mergeCells('I2:L6');
|
||||
|
||||
$sheet->cell('I2', function($cell) use($titulo) {
|
||||
|
||||
$cell->setFontFamily('Aharoni');
|
||||
$cell->setFontWeight('bold');
|
||||
$cell->setAlignment('center');
|
||||
$cell->setValignment('center');
|
||||
$cell->setFontSize(20);
|
||||
$cell->setValue($titulo);
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('K8', function($cell) use($fecha_inicio) {
|
||||
list($y, $m, $d) = explode("-", $fecha_inicio);
|
||||
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue('Del: '.$d.'/'.$m.'/'.$y);
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('L8', function($cell) use($fecha_final) {
|
||||
list($y, $m, $d) = explode("-", $fecha_final);
|
||||
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue('Al: '.$d.'/'.$m.'/'.$y);
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('N7', function($cell) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue('Costo:');
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('N8', function($cell) use ($total_costo) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('right');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue($total_costo);
|
||||
});
|
||||
|
||||
$sheet->cell('O7', function($cell) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue('Total:');
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('O8', function($cell) use($total) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue($total.' Servicios');
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('P7', function($cell) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue('Total litros:');
|
||||
|
||||
});
|
||||
|
||||
$sheet->cell('P8', function($cell) use($total_litraje) {
|
||||
$cell->setFontFamily('Calibri');
|
||||
$cell->setAlignment('left');
|
||||
$cell->setFontSize(12);
|
||||
$cell->setValue($total_litraje);
|
||||
|
||||
});
|
||||
|
||||
//Mostar valores de consulta
|
||||
$sheet->fromArray($servicios, null, 'B9', true);
|
||||
|
||||
//Formato en columnas de titulo
|
||||
$sheet->cells('B9:W9', function ($cells) {
|
||||
$cells->setBackground('#001870');
|
||||
$cells->setFontColor('#ffffff');
|
||||
$cells->setFontSize(13);
|
||||
$cells->setFontFamily('Calibri');
|
||||
$cells->setAlignment('left');
|
||||
$cells->setFontWeight('bold');
|
||||
});
|
||||
|
||||
$sheet->getStyle('B9:R9' , $sheet->getHighestRow())->getAlignment()->setWrapText(true);
|
||||
|
||||
//Titulos personalizados
|
||||
$titulos_cell = [
|
||||
['cell' => 'B9', 'titulo' => 'Número de solicitud'],
|
||||
['cell' => 'C9', 'titulo' => 'Fecha y hora de registro'],
|
||||
['cell' => 'D9', 'titulo' => 'Fecha y hora programada'],
|
||||
['cell' => 'E9', 'titulo' => 'Tiempo de atención'],
|
||||
['cell' => 'F9', 'titulo' => 'Servicio'],
|
||||
['cell' => 'G9', 'titulo' => 'Costo de servicio'],
|
||||
['cell' => 'H9', 'titulo' => 'Tipo de servicio'],
|
||||
['cell' => 'I9', 'titulo' => 'Estatus de servicio'],
|
||||
['cell' => 'J9', 'titulo' => 'Nombre del cliente'],
|
||||
['cell' => 'K9', 'titulo' => 'Email del cliente'],
|
||||
['cell' => 'L9', 'titulo' => 'Domicilio de servicio'],
|
||||
['cell' => 'M9', 'titulo' => 'Email de domicilio'],
|
||||
['cell' => 'N9', 'titulo' => 'Asesor de operaciones'],
|
||||
['cell' => 'O9', 'titulo' => 'Auxiliar de operaciones'],
|
||||
['cell' => 'P9', 'titulo' => 'Vehículo asignado'],
|
||||
['cell' => 'Q9', 'titulo' => 'Duración del servicio (cronómetro)'],
|
||||
['cell' => 'R9', 'titulo' => 'Hora inicio'],
|
||||
['cell' => 'S9', 'titulo' => 'Puntualidad'],
|
||||
['cell' => 'T9', 'titulo' => 'Origen'],
|
||||
['cell' => 'U9', 'titulo' => 'Litraje'],
|
||||
['cell' => 'V9', 'titulo' => 'Facturado'],
|
||||
['cell' => 'W9', 'titulo' => 'Forma de pago'],
|
||||
];
|
||||
|
||||
foreach ($titulos_cell as $t){
|
||||
$sheet->cell($t['cell'], function($cell) use($t) {
|
||||
$cell->setValue($t['titulo']);
|
||||
});
|
||||
}
|
||||
|
||||
//Size a columnas indicadas
|
||||
$columns_set = [
|
||||
'B9', 'C9', 'D9', 'N9', 'O9', 'U9', 'V9', 'W9'
|
||||
];
|
||||
|
||||
foreach ($columns_set as $c){
|
||||
$set_column = [
|
||||
$c => [
|
||||
'width' => ($c == 'O9' || $c == 'Q9')? 23: ($c == 'B9') ? 14 : 20,
|
||||
'height' => 40
|
||||
]
|
||||
];
|
||||
$sheet->setSize($set_column);
|
||||
}
|
||||
|
||||
//AutoSize en columnas indicadas
|
||||
$columns_auto= [
|
||||
'E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W'
|
||||
];
|
||||
|
||||
foreach ($columns_auto as $c){
|
||||
$sheet->getColumnDimension($c)->setAutoSize(true);
|
||||
}
|
||||
|
||||
$sheet->setWidth(array(
|
||||
'A' => 3,
|
||||
));
|
||||
|
||||
//Borde
|
||||
$columns_border= [
|
||||
'B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W'
|
||||
];
|
||||
|
||||
for ($i=0; $i<= $total; $i++){
|
||||
$row = 9 + $i;
|
||||
|
||||
foreach ($columns_border as $cb){
|
||||
$border = "$cb$row:$cb$row";
|
||||
$sheet->cells($border, function ($cells) {
|
||||
$cells->setBorder('thin', 'thin', 'thin', 'thin');
|
||||
});
|
||||
|
||||
if($row != 9 && ($cb == 'C' || $cb == 'D' || $cb == 'G' || $cb == 'O' || $cb == 'P' || $cb == 'Q' || $cb == 'S' || $cb == 'T')){
|
||||
$sheet->cells("$cb$row", function ($cells) {
|
||||
$cells->setAlignment('right');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
})->store('xls', storage_path('app') . '/public/reportes/servicios/');
|
||||
|
||||
return response()->success(['nombre_archivo' => $nombre.'.xls?micro='.$this->getMicroSeconds()]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\SupervisorOperaciones;
|
||||
|
||||
use const App\Http\Controllers\ASESOR_OPERACIONES;
|
||||
use const App\Http\Controllers\PENDIENTE;
|
||||
use const App\Http\Controllers\REALIZADO;
|
||||
use App\Models\ServicioDet;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Auth;
|
||||
|
||||
class AsesoresController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$asesores = User::select('users.id', 'users.nombre', 'users.apellido_paterno', 'users.apellido_materno')
|
||||
->where('tipo_empleado_id', ASESOR_OPERACIONES)
|
||||
->where('sucursal_id', $user->sucursal_id)
|
||||
->get();
|
||||
|
||||
foreach ($asesores as $a){
|
||||
$consulta = ServicioDet::join('servicios_enc', 'servicios_enc.id', '=', 'servicios_det.servicio_enc_id')
|
||||
->where('servicios_det.operador_id', $a->id)
|
||||
->where('servicios_enc.sucursal_id', $user->sucursal_id)
|
||||
->whereDate('servicios_det.fecha_solicitud', Carbon::now()->format('Y-m-d'));
|
||||
|
||||
//$a->servicios_total = $consulta->whereIn('servicios_det.estatus_servicio_id', [PENDIENTE, REALIZADO])->count();
|
||||
$a->servicios_total = $consulta->count();
|
||||
$a->servicios_pendiente = $consulta->whereNotIn('servicios_det.estatus_servicio_id', [REALIZADO])->count();
|
||||
}
|
||||
|
||||
return response()->success($asesores);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function serviciosXAsesor($asesor_id)
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$campos = [
|
||||
'servicios_enc.id as solicitud_servicio_id',
|
||||
'servicios_enc.forma_pago_id',
|
||||
'cat_formas_pagos.nombre as forma_pago_nombre',
|
||||
'fecha_agenda',
|
||||
'usuario_agenda_id',
|
||||
'users.nombre as usuario_agenda_nombre',
|
||||
'users.apellido_paterno as usuario_agenda_apellido_paterno',
|
||||
'users.apellido_materno as usuario_agenda_apellido_materno',
|
||||
'servicios_enc.cliente_id',
|
||||
'clientes.denominacion',
|
||||
'servicios_enc.cliente_domicilio_id',
|
||||
'clientes_domicilios.nombre_responsable_sucursal as clientes_nombre_responsable_sucursal',
|
||||
'clientes_domicilios.celular_responsable as clientes_celular_responsable',
|
||||
'clientes_domicilios.calle as clientes_calle',
|
||||
'clientes_domicilios.num_ext as clientes_num_ext',
|
||||
'clientes_domicilios.num_int as clientes_num_int',
|
||||
'clientes_domicilios.colonia as clientes_colonia',
|
||||
'clientes_domicilios.cp as clientes_cp',
|
||||
'clientes_domicilios.telefono as clientes_telefono',
|
||||
'clientes_domicilios.lat as clientes_lat',
|
||||
'clientes_domicilios.lng as clientes_lng',
|
||||
'servicios_enc.deleted_at',
|
||||
'servicios_det.id',
|
||||
'servicios_det.servicio_id',
|
||||
'cat_servicios.nombre as servicio_nombre',
|
||||
'servicios_det.estatus_servicio_id',
|
||||
'cat_estatus_servicios.nombre as estatus_servicio_nombre',
|
||||
'servicios_det.tipo_servicio_id',
|
||||
'cat_tipos_servicios.nombre as tipo_servicio_nombre',
|
||||
'cat_estatus_servicios.color_1 as estatus_servicio_color_1',
|
||||
'cat_estatus_servicios.color_2 as estatus_servicio_color_2',
|
||||
'fecha_solicitud',
|
||||
'duracion',
|
||||
'definido_cliente',
|
||||
'servicios_det.operador_id',
|
||||
'operador.nombre as operador_nombre',
|
||||
'operador.apellido_paterno as operador_apellido_paterno',
|
||||
'operador.apellido_materno as operador_apellido_materno',
|
||||
'servicios_det.vehiculo_id',
|
||||
'cat_vehiculos.num_economico as vehiculo_num_economico',
|
||||
'servicios_det.fecha_solicitud',
|
||||
'sucursales.nombre as vehiculo_sucursal',
|
||||
'sucursales.id as vehiculo_sucursal_id',
|
||||
'sucursal_operador.nombre as operador_sucursal',
|
||||
'sucursal_operador.id as operador_sucursal_id',
|
||||
'servicios_det.auxiliar_1 as auxiliar_1_id',
|
||||
'servicios_det.auxiliar_2 as auxiliar_2_id',
|
||||
'auxiliares_1.nombre as auxiliar_1',
|
||||
'auxiliares_2.nombre as auxiliar_2',
|
||||
'sucursal_auxiliares_1.nombre as sucursal_auxiliar_1',
|
||||
'sucursal_auxiliares_2.nombre as sucursal_auxiliar_2',
|
||||
'servicios_det.costo_servicio',
|
||||
'servicios_det.aceptado',
|
||||
'servicios_det.observacion_atencion_cliente'
|
||||
];
|
||||
|
||||
$servicios = ServicioDet::select($campos)
|
||||
->joinDetalleServicioDet()
|
||||
->join('servicios_enc', 'servicios_enc.id', '=', 'servicios_det.servicio_enc_id')
|
||||
->join('cat_formas_pagos', 'cat_formas_pagos.id', '=', 'servicios_enc.forma_pago_id')
|
||||
->join('users', 'users.id', '=', 'servicios_enc.usuario_agenda_id')
|
||||
->join('clientes', 'clientes.id', '=', 'servicios_enc.cliente_id')
|
||||
->join('clientes_domicilios', 'clientes_domicilios.id', '=', 'servicios_enc.cliente_domicilio_id')
|
||||
//->whereIn('servicios_det.estatus_servicio_id', [PENDIENTE, REALIZADO])
|
||||
->where('servicios_det.operador_id', $asesor_id)
|
||||
->where('servicios_enc.sucursal_id', $user->sucursal_id)
|
||||
->whereDate('servicios_det.fecha_solicitud', Carbon::now()->format('Y-m-d'))
|
||||
->orderBy('servicios_det.fecha_solicitud')
|
||||
->get();
|
||||
|
||||
return response()->success($servicios);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\SupervisorOperaciones;
|
||||
|
||||
use App\Models\BitacoraLaboral;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use DB;
|
||||
use Log;
|
||||
|
||||
class JornadaController extends Controller
|
||||
{
|
||||
public function inicioJornada(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
$fecha = Carbon::now()->toDateTimeString();
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
|
||||
$bitacora = BitacoraLaboral::where('usuario_id', $user->id)
|
||||
->whereNull('fecha_hora_fin')
|
||||
->first();
|
||||
|
||||
if($bitacora){
|
||||
DB::rollBack();
|
||||
return response()->unprocessable('JORNADA_YA_INICIADA', [$bitacora->id]);
|
||||
}
|
||||
|
||||
$bitacora_laboral = BitacoraLaboral::create(['fecha_hora_ini' => $fecha, 'usuario_id' => $user->id]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->success($bitacora_laboral);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::info($e->getMessage());
|
||||
return response()->unprocessable('Error', ['Error al guardar el inicio de jornada.']);
|
||||
}
|
||||
}
|
||||
|
||||
public function finalizarJornada(Request $request, $id){
|
||||
|
||||
$fecha = Carbon::now()->toDateTimeString();
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
|
||||
$jornada = BitacoraLaboral::where('id',$id)->first();
|
||||
|
||||
if($jornada->fecha_hora_fin){
|
||||
DB::rollBack();
|
||||
return response()->unprocessable('Error', ['La jornada ya se encuentra finalizada.']);
|
||||
}
|
||||
|
||||
$jornada->update(['fecha_hora_fin' => $fecha]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return response()->unprocessable('Error', ['Error al guardar el fin de jornada.']);
|
||||
}
|
||||
}
|
||||
}
|
||||
65
app/Http/Kernel.php
Normal file
65
app/Http/Kernel.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use App\Http\Middleware\RequestLogs;
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
|
||||
class Kernel extends HttpKernel
|
||||
{
|
||||
/**
|
||||
* The application's global HTTP middleware stack.
|
||||
*
|
||||
* These middleware are run during every request to your application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [
|
||||
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware groups.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middlewareGroups = [
|
||||
'web' => [
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
// \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
'throttle:60,1',
|
||||
'bindings',
|
||||
\Barryvdh\Cors\HandleCors::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware.
|
||||
*
|
||||
* These middleware may be assigned to groups or used individually.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $routeMiddleware = [
|
||||
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'jwt' => \Tymon\JWTAuth\Middleware\GetUserFromToken::class,
|
||||
'acl.sentinel'=>\App\Http\Middleware\SentinelACL::class,
|
||||
'request.log' => RequestLogs::class,
|
||||
];
|
||||
}
|
||||
17
app/Http/Middleware/EncryptCookies.php
Normal file
17
app/Http/Middleware/EncryptCookies.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies as BaseEncrypter;
|
||||
|
||||
class EncryptCookies extends BaseEncrypter
|
||||
{
|
||||
/**
|
||||
* The names of the cookies that should not be encrypted.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
26
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
26
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
if (Auth::guard($guard)->check()) {
|
||||
return redirect('/home');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
49
app/Http/Middleware/RequestLogs.php
Normal file
49
app/Http/Middleware/RequestLogs.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\UserLoginLog;
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class RequestLogs
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
try {
|
||||
$request_uri = $request->getRequestUri();
|
||||
if(str_contains($request_uri,'?')){
|
||||
list($request_uri, $query) = explode('?', $request_uri);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'device_info' => $request->header('DEVICE-INFO'),
|
||||
'browser_info' => $request->header('BROWSER-INFO'),
|
||||
'ip' => $request->ip(),
|
||||
'request_uri' => $request_uri,
|
||||
];
|
||||
|
||||
if(Auth::check()){
|
||||
$data['user_id'] = Auth::id();
|
||||
}else{
|
||||
$data['user_id'] = User::where('email', $request->input('email'))
|
||||
->first()
|
||||
->id;
|
||||
}
|
||||
|
||||
UserLoginLog::create($data);
|
||||
}catch (\Exception $exception){
|
||||
\Log::info(json_encode($exception));
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
56
app/Http/Middleware/SentinelACL.php
Normal file
56
app/Http/Middleware/SentinelACL.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Cartalyst\Sentinel\Native\Facades\Sentinel;
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Auth\Guard;
|
||||
use Auth;
|
||||
use Log;
|
||||
|
||||
class SentinelACL
|
||||
{
|
||||
/**
|
||||
* The Guard implementation.
|
||||
*
|
||||
* @var Guard
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* Create a new filter instance.
|
||||
*
|
||||
* @param Guard $auth
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Guard $auth) {
|
||||
$this->auth = $auth;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next) {
|
||||
$currentRouteName = $request->route()->getName();
|
||||
|
||||
$usuario = Auth::user();
|
||||
|
||||
if($usuario === null){
|
||||
return response()->unauthorized('unauthorized');
|
||||
}
|
||||
|
||||
$user = Sentinel::findById($usuario->id);
|
||||
|
||||
if (!$user->hasAccess($currentRouteName) ) {
|
||||
return response()->forbidden('dont_have_permission');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
18
app/Http/Middleware/TrimStrings.php
Normal file
18
app/Http/Middleware/TrimStrings.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\TrimStrings as BaseTrimmer;
|
||||
|
||||
class TrimStrings extends BaseTrimmer
|
||||
{
|
||||
/**
|
||||
* The names of the attributes that should not be trimmed.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
}
|
||||
17
app/Http/Middleware/VerifyCsrfToken.php
Normal file
17
app/Http/Middleware/VerifyCsrfToken.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
|
||||
|
||||
class VerifyCsrfToken extends BaseVerifier
|
||||
{
|
||||
/**
|
||||
* The URIs that should be excluded from CSRF verification.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Administrador;
|
||||
|
||||
use App\Models\Cliente;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class ClientesDomiciliosRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'nombre_sucursal'=>'string|required|max:191',
|
||||
'numero_sucursal' => 'numeric|required',
|
||||
'nombre_responsable_sucursal'=>'string|required|max:191',
|
||||
'calle'=>'string|required|max:191',
|
||||
'entre_calles'=>'max:191',
|
||||
'num_ext'=>'string|required|max:10',
|
||||
'num_int'=>'nullable|max:10',
|
||||
'colonia'=>'string|required|max:191',
|
||||
'ciudad'=>'string|required|max:191',
|
||||
'cp'=>'max:191',
|
||||
'telefono' => 'alpha_num|required|max:10',
|
||||
'celular_responsable' => 'alpha_num|required|max:10',
|
||||
//'lat' => 'numeric|required',
|
||||
//'lng' => 'numeric|required'
|
||||
];
|
||||
}
|
||||
}
|
||||
84
app/Http/Requests/Administrador/ClientesRequest.php
Normal file
84
app/Http/Requests/Administrador/ClientesRequest.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Administrador;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ClientesRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
if($this->method()=='PUT'){
|
||||
|
||||
$params = $this->route()->parameters();
|
||||
$id = $params['cliente'];
|
||||
|
||||
return [
|
||||
'denominacion' => 'string|required|max:191|unique:clientes,denominacion,'.$id.',id',
|
||||
'asesor_id' => 'alpha_num|required|exists:users,id',
|
||||
'requiere_factura' => 'boolean|required',
|
||||
'datos_fiscales.razon_social'=>'string|max:191|unique:clientes_datos_fiscales,razon_social,'.$id.',cliente_id',
|
||||
'datos_fiscales.rfc'=>'string|min:12|max:13',
|
||||
'datos_fiscales.email'=>'string|email|max:191',
|
||||
'datos_fiscales.calle'=>'string|max:191',
|
||||
'datos_fiscales.num_ext'=>'string|max:10',
|
||||
'datos_fiscales.num_int'=>'nullable|max:10',
|
||||
'datos_fiscales.colonia'=>'string|max:191',
|
||||
'datos_fiscales.localidad'=>'string|max:191',
|
||||
'datos_fiscales.municipio'=>'string|max:191',
|
||||
'datos_fiscales.estado'=>'string|max:191',
|
||||
'datos_fiscales.pais'=>'string|max:191',
|
||||
'datos_fiscales.cp'=>'string|max:191',
|
||||
'datos_fiscales.factura_uso_cfdi_id' => 'alpha_num|exists:facturas_uso_cfdi,id',
|
||||
'datos_fiscales.factura_tipo_comprobante_id' => 'alpha_num|exists:facturas_tipo_comprobante,id',
|
||||
'datos_fiscales.factura_metodos_pago_id' => 'alpha_num|exists:facturas_metodos_pago,id',
|
||||
'datos_fiscales.factura_formas_pago_id' => 'alpha_num|exists:facturas_formas_pago,id',
|
||||
'datos_fiscales.condicion_pago'=>'string|max:191',
|
||||
'datos_fiscales.retencion_iva'=>'boolean',
|
||||
'datos_fiscales.observacion'=>'max:191'
|
||||
];
|
||||
|
||||
}else{
|
||||
|
||||
return [
|
||||
'denominacion' => 'string|required|max:191|unique:clientes,denominacion',
|
||||
'asesor_id' => 'alpha_num|required|exists:users,id',
|
||||
'requiere_factura' => 'boolean|required',
|
||||
'datos_fiscales.razon_social'=>'string|max:191|unique:clientes_datos_fiscales,razon_social',
|
||||
'datos_fiscales.rfc'=>'string|min:12|max:13|unique:clientes_datos_fiscales,rfc',
|
||||
'datos_fiscales.email'=>'string|email|max:191',
|
||||
'datos_fiscales.calle'=>'string|max:191',
|
||||
'datos_fiscales.num_ext'=>'string|max:10',
|
||||
'datos_fiscales.num_int'=>'nullable|max:10',
|
||||
'datos_fiscales.colonia'=>'string|max:191',
|
||||
'datos_fiscales.localidad'=>'string|max:191',
|
||||
'datos_fiscales.municipio'=>'string|max:191',
|
||||
'datos_fiscales.estado'=>'string|max:191',
|
||||
'datos_fiscales.pais'=>'string|max:191',
|
||||
'datos_fiscales.cp'=>'string|max:191',
|
||||
'datos_fiscales.factura_uso_cfdi_id' => 'alpha_num|exists:facturas_uso_cfdi,id',
|
||||
'datos_fiscales.factura_tipo_comprobante_id' => 'alpha_num|exists:facturas_tipo_comprobante,id',
|
||||
'datos_fiscales.factura_metodos_pago_id' => 'alpha_num|exists:facturas_metodos_pago,id',
|
||||
'datos_fiscales.factura_formas_pago_id' => 'alpha_num|exists:facturas_formas_pago,id',
|
||||
'datos_fiscales.condicion_pago'=>'string|max:191',
|
||||
'datos_fiscales.retencion_iva'=>'boolean',
|
||||
'datos_fiscales.observacion'=>'max:191'
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
54
app/Http/Requests/Administrador/EstatusServiciosRequest.php
Normal file
54
app/Http/Requests/Administrador/EstatusServiciosRequest.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Administrador;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class EstatusServiciosRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
if($this->method()=='PUT'){
|
||||
|
||||
$params = $this->route()->parameters();
|
||||
$id = $params['estatus_servicio'];
|
||||
|
||||
return [
|
||||
'nombre' => 'string|required|min:1|max:191|unique:cat_estatus_servicios,nombre,'.$id.',id',
|
||||
'color_1' => 'required|regex:/^(?=.*#[a-fA-F0-9]{6}).+$/',
|
||||
'color_2' => 'regex:/^(?=.*#[a-fA-F0-9]{6}).+$/',
|
||||
];
|
||||
|
||||
}else{
|
||||
|
||||
return [
|
||||
'nombre' => 'string|required|min:1|max:191|unique:cat_estatus_servicios,nombre',
|
||||
'color_1' => 'required|regex:/^(?=.*#[a-fA-F0-9]{6}).+$/',
|
||||
'color_2' => 'regex:/^(?=.*#[a-fA-F0-9]{6}).+$/',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
$messages = [
|
||||
'nombre.unique' => 'El nombre que ingresó ya se encuentra en nuestros registros.'
|
||||
];
|
||||
return $messages;
|
||||
}
|
||||
}
|
||||
48
app/Http/Requests/Administrador/FormasPagosRequest.php
Normal file
48
app/Http/Requests/Administrador/FormasPagosRequest.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
namespace App\Http\Requests\Administrador;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class FormasPagosRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
if($this->method()=='PUT'){
|
||||
$params = $this->route()->parameters();
|
||||
$id = $params['formas_pago'];
|
||||
|
||||
return [
|
||||
'nombre' => 'string|required|min:1|max:191|unique:cat_formas_pagos,nombre,'.$id.',id',
|
||||
'zeros' => 'string|min:1|max:1',
|
||||
];
|
||||
}else{
|
||||
return [
|
||||
'nombre' => 'string|required|min:1|max:191|unique:cat_formas_pagos,nombre',
|
||||
'zeros' => 'string|min:1|max:1',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
$messages = [
|
||||
'nombre.unique' => 'El nombre que ingresó ya se encuentra en nuestros registros.'
|
||||
];
|
||||
return $messages;
|
||||
}
|
||||
}
|
||||
61
app/Http/Requests/Administrador/RolesRequest.php
Normal file
61
app/Http/Requests/Administrador/RolesRequest.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Administrador;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class RolesRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
if ($this->method() == "PUT") {
|
||||
$params = $this->route()->parameters();
|
||||
$id = $params['role'];
|
||||
return [
|
||||
'name' => "string|required|min:1|max:128|unique:roles,name,$id,id",
|
||||
'slug' => "string|required|min:1|max:128|unique:roles,slug,$id,id",
|
||||
'movil' => 'boolean',
|
||||
'web' => 'boolean',
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
'name' => 'string|required|min:1|max:128|unique:roles,name',
|
||||
'slug' => 'string|required|min:1|max:128|unique:roles,slug',
|
||||
'movil' => 'boolean',
|
||||
'web' => 'boolean',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
$messages = [
|
||||
'name.string' => 'El nombre del rol debe tener caracteres.',
|
||||
'name.required' => 'El nombre del rol es requerido.',
|
||||
'name.min' => 'El tamaño mínimo del nombre del rol es 1.',
|
||||
'name.max' => 'El tamaño máximo del nombre del rol es 128.',
|
||||
'slug.string' => 'El slug del rol debe tener caracteres.',
|
||||
'slug.required' => 'El slug del rol es requerido.',
|
||||
'slug.min' => 'El tamaño mínimo del slug del rol es 1.',
|
||||
'slug.max' => 'El tamaño máximo del slug del rol es 128.',
|
||||
'slug.unique' => 'El slug ya está en uso.',
|
||||
'name.unique' => 'El nombre ya está en uso.'
|
||||
];
|
||||
return $messages;
|
||||
}
|
||||
}
|
||||
50
app/Http/Requests/Administrador/ServiciosRequest.php
Normal file
50
app/Http/Requests/Administrador/ServiciosRequest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Administrador;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ServiciosRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
if($this->method()=='PUT'){
|
||||
|
||||
$params = $this->route()->parameters();
|
||||
$id = $params['servicio'];
|
||||
|
||||
return [
|
||||
'nombre' => 'string|required|min:1|max:191|unique:cat_servicios,nombre,'.$id.',id',
|
||||
];
|
||||
|
||||
}else{
|
||||
|
||||
return [
|
||||
'nombre' => 'string|required|min:1|max:191|unique:cat_servicios,nombre',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
$messages = [
|
||||
'nombre.unique' => 'El nombre que ingresó ya se encuentra en nuestros registros.'
|
||||
];
|
||||
return $messages;
|
||||
}
|
||||
}
|
||||
66
app/Http/Requests/Administrador/SucursalesRequest.php
Normal file
66
app/Http/Requests/Administrador/SucursalesRequest.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Administrador;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class SucursalesRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
if($this->method()=='PUT'){
|
||||
|
||||
$params = $this->route()->parameters();
|
||||
$id = $params['sucursale'];
|
||||
|
||||
return [
|
||||
'nombre' => 'string|required|min:1|max:191|unique:sucursales,nombre,'.$id.',id',
|
||||
'calle' => 'string|required|min:1|max:191',
|
||||
'num_ext' => 'string|required|min:1|max:191',
|
||||
'num_int' => 'string|nullable|min:1|max:191',
|
||||
'colonia' => 'string|required|min:1|max:191',
|
||||
'cp' => 'string|required|min:1|max:191',
|
||||
'telefono' => 'alpha_num|required|max:10',
|
||||
'gerente' => 'string|required|min:1|max:191',
|
||||
'encargado' => 'string|required|min:1|max:191',
|
||||
];
|
||||
|
||||
}else{
|
||||
|
||||
return [
|
||||
'nombre' => 'string|required|min:1|max:191|unique:sucursales,nombre',
|
||||
'calle' => 'string|required|min:1|max:191',
|
||||
'num_ext' => 'string|required|min:1|max:191',
|
||||
'num_int' => 'string|nullable|min:1|max:191',
|
||||
'colonia' => 'string|required|min:1|max:191',
|
||||
'cp' => 'string|required|min:1|max:191',
|
||||
'telefono' => 'alpha_num|required|max:10',
|
||||
'gerente' => 'string|required|min:1|max:191',
|
||||
'encargado' => 'string|required|min:1|max:191',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
$messages = [
|
||||
'nombre.unique' => 'El nombre que ingresó ya se encuentra en nuestros registros.'
|
||||
];
|
||||
return $messages;
|
||||
}
|
||||
}
|
||||
50
app/Http/Requests/Administrador/TiposServiciosRequest.php
Normal file
50
app/Http/Requests/Administrador/TiposServiciosRequest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Administrador;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class TiposServiciosRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
if($this->method()=='PUT'){
|
||||
|
||||
$params = $this->route()->parameters();
|
||||
$id = $params['tipos_servicio'];
|
||||
|
||||
return [
|
||||
'nombre' => 'string|required|min:1|max:191|unique:cat_tipos_servicios,nombre,'.$id.',id',
|
||||
];
|
||||
|
||||
}else{
|
||||
|
||||
return [
|
||||
'nombre' => 'string|required|min:1|max:191|unique:cat_tipos_servicios,nombre',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
$messages = [
|
||||
'nombre.unique' => 'El nombre que ingresó ya se encuentra en nuestros registros.'
|
||||
];
|
||||
return $messages;
|
||||
}
|
||||
}
|
||||
48
app/Http/Requests/Administrador/TiposVehiculosRequest.php
Normal file
48
app/Http/Requests/Administrador/TiposVehiculosRequest.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
namespace App\Http\Requests\Administrador;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class TiposVehiculosRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
if($this->method()=='PUT'){
|
||||
$params = $this->route()->parameters();
|
||||
$id = $params['tipos_vehiculo'];
|
||||
|
||||
return [
|
||||
'nombre' => 'string|required|min:1|max:191|unique:cat_tipos_vehiculos,nombre,'.$id.',id',
|
||||
'objetivo_mensual' => 'numeric|max:1000',
|
||||
];
|
||||
}else{
|
||||
return [
|
||||
'nombre' => 'string|required|min:1|max:191|unique:cat_tipos_vehiculos,nombre',
|
||||
'objetivo_mensual' => 'numeric|max:1000',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
$messages = [
|
||||
'nombre.unique' => 'El nombre que ingresó ya se encuentra en nuestros registros.'
|
||||
];
|
||||
return $messages;
|
||||
}
|
||||
}
|
||||
64
app/Http/Requests/Administrador/UserRequest.php
Normal file
64
app/Http/Requests/Administrador/UserRequest.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Administrador;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UserRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
if($this->method()=='PUT'){
|
||||
|
||||
$params = $this->route()->parameters();
|
||||
$id = $params['usuario'];
|
||||
|
||||
return [
|
||||
'email' => 'string|required|email|max:191|unique:users,email,'.$id.',id',
|
||||
//'password' => 'string|min:5',
|
||||
'nombre' => 'string|required|min:1|max:191',
|
||||
'apellido_paterno' => 'string|required|min:1|max:191',
|
||||
'apellido_materno' =>'string|required|min:1|max:191',
|
||||
'telefono' =>'alpha_num|required|max:10',
|
||||
'role_id' => 'required|exists:roles,id',
|
||||
'sucursal_id' => 'required|exists:sucursales,id',
|
||||
];
|
||||
|
||||
}else{
|
||||
|
||||
return [
|
||||
'email' => 'string|required|email|max:255|unique:users,email',
|
||||
//'password' => 'string|min:5',
|
||||
'nombre' => 'string|required|min:1|max:255',
|
||||
'apellido_paterno' => 'string|required|min:1|max:191',
|
||||
'apellido_materno' =>'string|required|min:1|max:191',
|
||||
'telefono' =>'alpha_num|required|max:10',
|
||||
'role_id' => 'required|exists:roles,id',
|
||||
'sucursal_id' => 'required|exists:sucursales,id',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
$messages = [
|
||||
'email.unique' => 'El email que ingresó ya se encuentra en nuestros registros.'
|
||||
];
|
||||
return $messages;
|
||||
}
|
||||
}
|
||||
53
app/Http/Requests/Administrador/VehiculosRequest.php
Normal file
53
app/Http/Requests/Administrador/VehiculosRequest.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace App\Http\Requests\Administrador;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class VehiculosRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
if($this->method()=='PUT'){
|
||||
|
||||
$params = $this->route()->parameters();
|
||||
$id = $params['vehiculo'];
|
||||
|
||||
return [
|
||||
'num_economico' => 'string|required|max:191|unique:cat_vehiculos,num_economico,'.$id.',id',
|
||||
'descripcion' => 'string|max:100',
|
||||
'sucursales' => 'array|required',
|
||||
'tipo_vehiculo_id' => 'required|exists:cat_tipos_vehiculos,id',
|
||||
];
|
||||
}else{
|
||||
return [
|
||||
'num_economico' => 'string|required|max:191|unique:cat_vehiculos,num_economico',
|
||||
'descripcion' => 'string|max:100',
|
||||
'sucursales' => 'array|required',
|
||||
'tipo_vehiculo_id' => 'required|exists:cat_tipos_vehiculos,id',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
$messages = [
|
||||
'num_economico.unique' => 'El Vehículo que ingresó ya se encuentra en nuestros registros.'
|
||||
];
|
||||
return $messages;
|
||||
}
|
||||
}
|
||||
30
app/Http/Requests/AtencionCliente/LitrajeRequest.php
Normal file
30
app/Http/Requests/AtencionCliente/LitrajeRequest.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\AtencionCliente;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class LitrajeRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'litraje' => 'required|integer'
|
||||
];
|
||||
}
|
||||
}
|
||||
83
app/Http/Requests/AtencionCliente/ServiciosRequest.php
Normal file
83
app/Http/Requests/AtencionCliente/ServiciosRequest.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\AtencionCliente;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ServiciosRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
if($this->method()=='PUT'){
|
||||
return [
|
||||
'cliente_id' => 'alpha_num|required|exists:clientes,id',
|
||||
'cliente_domicilio_id' => 'alpha_num|required|exists:clientes_domicilios,id',
|
||||
'forma_pago_id' => 'alpha_num|required|exists:cat_formas_pagos,id',
|
||||
'origen_id' => 'alpha_num|required|exists:cat_origenes,id',
|
||||
'servicios' => 'array|required|max:3',
|
||||
'servicios.*.id' => 'alpha_num|required|exists:servicios_det,id',
|
||||
'servicios.*.servicio_id' => 'alpha_num|required|exists:cat_servicios,id',
|
||||
'servicios.*.estatus_servicio_id' => 'alpha_num|required|exists:cat_estatus_servicios,id',
|
||||
'servicios.*.tipo_servicio_id' => 'alpha_num|required|exists:cat_tipos_servicios,id',
|
||||
'servicios.*.fecha_solicitud' => 'required|date_format:"Y-m-d H:i:s"',
|
||||
//'usuario_agenda_id' => 'alpha_num|required|exists:users,id',
|
||||
'servicios.*.duracion' => 'required|date_format:"H:i:s"',
|
||||
'servicios.*.definido_cliente' => 'boolean|required',
|
||||
'servicios.*.operador_id' => 'alpha_num|required|exists:users,id',
|
||||
'servicios.*.vehiculo_id' => 'alpha_num|required|exists:cat_vehiculos,id',
|
||||
'servicios.*.auxiliar_1' => 'nullable|exists:users,id',
|
||||
'servicios.*.auxiliar_2' => 'nullable|exists:users,id',
|
||||
'servicios.*.costo_servicio' => 'required|numeric|max:999999',
|
||||
'servicios.*.observacion_atencion_cliente' => 'max:700',
|
||||
'servicios.*.requiere_encuesta' => 'boolean|required',
|
||||
'servicios.*.facturado' => 'boolean|required',
|
||||
];
|
||||
}else{
|
||||
return [
|
||||
'cliente_id' => 'alpha_num|required|exists:clientes,id',
|
||||
'cliente_domicilio_id' => 'alpha_num|required|exists:clientes_domicilios,id',
|
||||
'forma_pago_id' => 'alpha_num|required|exists:cat_formas_pagos,id',
|
||||
'origen_id' => 'alpha_num|required|exists:cat_origenes,id',
|
||||
'servicios' => 'array|required|max:3',
|
||||
'servicios.*.servicio_id' => 'alpha_num|required|exists:cat_servicios,id',
|
||||
'servicios.*.estatus_servicio_id' => 'alpha_num|required|exists:cat_estatus_servicios,id',
|
||||
'servicios.*.tipo_servicio_id' => 'alpha_num|required|exists:cat_tipos_servicios,id',
|
||||
'servicios.*.fecha_solicitud' => 'required|date_format:"Y-m-d H:i:s"',
|
||||
//'usuario_agenda_id' => 'alpha_num|required|exists:users,id',
|
||||
'servicios.*.duracion' => 'required|date_format:"H:i:s"',
|
||||
'servicios.*.definido_cliente' => 'boolean|required',
|
||||
'servicios.*.operador_id' => 'alpha_num|required|exists:users,id',
|
||||
'servicios.*.vehiculo_id' => 'alpha_num|required|exists:cat_vehiculos,id',
|
||||
'servicios.*.auxiliar_1' => 'nullable|exists:users,id',
|
||||
'servicios.*.auxiliar_2' => 'nullable|exists:users,id',
|
||||
'servicios.*.costo_servicio' => 'required|numeric|max:999999',
|
||||
'servicios.*.observacion_atencion_cliente' => 'max:700',
|
||||
'servicios.*.requiere_encuesta' => 'boolean|required',
|
||||
'servicios.*.facturado' => 'boolean|required',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
$messages = [
|
||||
'servicios.*.costo_servicio.max' => 'El costo máximo de servicio es de $999,999.99'
|
||||
];
|
||||
return $messages;
|
||||
}
|
||||
}
|
||||
33
app/Http/Requests/LoginRequest.php
Normal file
33
app/Http/Requests/LoginRequest.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class LoginRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'email' => 'required',
|
||||
'password' => 'required',
|
||||
'dispositivo_id' => 'string|nullable',
|
||||
'version_apk' => 'string|nullable'
|
||||
];
|
||||
}
|
||||
}
|
||||
34
app/Http/Requests/Operador/DesplazamientoRequest.php
Normal file
34
app/Http/Requests/Operador/DesplazamientoRequest.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Operador;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class DesplazamientoRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'*.lat' => 'required|numeric',
|
||||
'*.lng' => 'required|numeric',
|
||||
'*.modelo_celular' => 'string|required',
|
||||
'*.bateria' => 'numeric|required|max:100',
|
||||
'*.fecha' => 'required|date_format:"Y-m-d H:i:s"'
|
||||
];
|
||||
}
|
||||
}
|
||||
34
app/Http/Requests/Operador/FinalizarJornadaRequest.php
Normal file
34
app/Http/Requests/Operador/FinalizarJornadaRequest.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Operador;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class FinalizarJornadaRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'kilometraje_final' => 'numeric|required',
|
||||
'lat_fin' => 'required|numeric',
|
||||
'lng_fin' => 'required|numeric',
|
||||
'modelo_celular' => 'string|required',
|
||||
'bateria' => 'numeric|required|max:100'
|
||||
];
|
||||
}
|
||||
}
|
||||
36
app/Http/Requests/Operador/FinalizarServicioRequest.php
Normal file
36
app/Http/Requests/Operador/FinalizarServicioRequest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Operador;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class FinalizarServicioRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'servicio_enc_id' => 'alpha_num|required|exists:servicios_enc,id',
|
||||
'servicio_det_id' => 'alpha_num|required|exists:servicios_det,id',
|
||||
'fecha_fin_celular' => 'required|date_format:"Y-m-d H:i:s"',
|
||||
'duracion' => 'required|date_format:"H:i:s"',
|
||||
'comentarios' => 'max:505',
|
||||
'aplica_garantia' => 'required',
|
||||
'cat_motivos_estatus_id' => 'integer'
|
||||
];
|
||||
}
|
||||
}
|
||||
34
app/Http/Requests/Operador/GuardarEvidenciaRequest.php
Normal file
34
app/Http/Requests/Operador/GuardarEvidenciaRequest.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Operador;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class GuardarEvidenciaRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'servicio_enc_id' => 'alpha_num|required|exists:servicios_enc,id',
|
||||
'servicio_det_id' => 'alpha_num|required|exists:servicios_det,id',
|
||||
'etapa' => 'required|string',
|
||||
//'lat' => 'required|numeric',
|
||||
//'lng' => 'required|numeric',
|
||||
];
|
||||
}
|
||||
}
|
||||
31
app/Http/Requests/Operador/GuardarFirmaRequest.php
Normal file
31
app/Http/Requests/Operador/GuardarFirmaRequest.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Operador;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class GuardarFirmaRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'servicio_enc_id' => 'alpha_num|required|exists:servicios_enc,id',
|
||||
'servicio_det_id' => 'alpha_num|required|exists:servicios_det,id',
|
||||
];
|
||||
}
|
||||
}
|
||||
34
app/Http/Requests/Operador/IniciarServicioRequest.php
Normal file
34
app/Http/Requests/Operador/IniciarServicioRequest.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Operador;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class IniciarServicioRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'servicio_enc_id' => 'alpha_num|required|exists:servicios_enc,id',
|
||||
'servicio_det_id' => 'alpha_num|required|exists:servicios_det,id',
|
||||
'fecha_ini_celular' => 'required|date_format:"Y-m-d H:i:s"',
|
||||
//'lat_ini' => 'required|numeric',
|
||||
//'lng_ini' => 'required|numeric',
|
||||
];
|
||||
}
|
||||
}
|
||||
35
app/Http/Requests/Operador/InicioJornadaRequest.php
Normal file
35
app/Http/Requests/Operador/InicioJornadaRequest.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Operador;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class InicioJornadaRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'kilometraje_inicial' => 'numeric|required',
|
||||
'lat_ini' => 'required|numeric',
|
||||
'lng_ini' => 'required|numeric',
|
||||
'modelo_celular' => 'string|required',
|
||||
'bateria' => 'numeric|required|max:100',
|
||||
'token_firebase' => 'string|required'
|
||||
];
|
||||
}
|
||||
}
|
||||
30
app/Http/Requests/Operador/RechazarSolicitudRequest.php
Normal file
30
app/Http/Requests/Operador/RechazarSolicitudRequest.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Operador;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class RechazarSolicitudRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'observacion' => 'string|required|max:255',
|
||||
];
|
||||
}
|
||||
}
|
||||
38
app/Http/Requests/Operador/RespuestasOperadorRequest.php
Normal file
38
app/Http/Requests/Operador/RespuestasOperadorRequest.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Operador;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class RespuestasOperadorRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'*.nombre' => 'string|required',
|
||||
'*.tipo' => 'string|required',
|
||||
'*.tipo_checkbox' => 'boolean|required',
|
||||
'*.tipo_text' => 'boolean|required',
|
||||
'*.tipo_radio_btn' => 'boolean|required',
|
||||
'*.respuesta_checkbox' => 'boolean|nullable',
|
||||
'*.respuesta_text' => 'string|nullable',
|
||||
'*.respuesta_radio_btn' => 'string|nullable',
|
||||
'*.fecha' => 'date|required'
|
||||
];
|
||||
}
|
||||
}
|
||||
30
app/Http/Requests/Operador/UltimaIncidenciaRequest.php
Normal file
30
app/Http/Requests/Operador/UltimaIncidenciaRequest.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Operador;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UltimaIncidenciaRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'vehiculo_id' => 'integer|required|exists:cat_vehiculos,id',
|
||||
];
|
||||
}
|
||||
}
|
||||
30
app/Http/Requests/Operador/VehiculosIncidenciasRequest.php
Normal file
30
app/Http/Requests/Operador/VehiculosIncidenciasRequest.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Operador;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class VehiculosIncidenciasRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'descripcion' => 'string|required|',
|
||||
];
|
||||
}
|
||||
}
|
||||
33
app/Http/Requests/Reportes/CapacidadAprovechadaRequest.php
Normal file
33
app/Http/Requests/Reportes/CapacidadAprovechadaRequest.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Reportes;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CapacidadAprovechadaRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'sucursal' => 'alpha_num|required',
|
||||
'fecha_inicio' => 'required|date_format:"Y-m-d"',
|
||||
'fecha_final' => 'required|date_format:"Y-m-d"',
|
||||
'vehiculo_id' => 'alpha_num|required',
|
||||
];
|
||||
}
|
||||
}
|
||||
32
app/Http/Requests/Reportes/ConsultarAsesoresRequest.php
Normal file
32
app/Http/Requests/Reportes/ConsultarAsesoresRequest.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Reportes;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ConsultarAsesoresRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'sucursal' => 'alpha_num|required',
|
||||
'fecha_inicio' => 'required|date_format:"Y-m-d"',
|
||||
'fecha_final' => 'required|date_format:"Y-m-d"'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Reportes;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ConsultarAtencionClientesRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'sucursal' => 'alpha_num|required',
|
||||
'fecha_inicio' => 'required|date_format:"Y-m-d"',
|
||||
'fecha_final' => 'required|date_format:"Y-m-d"',
|
||||
'definio' => 'alpha_num|required',
|
||||
];
|
||||
}
|
||||
}
|
||||
32
app/Http/Requests/Reportes/ConsultarClientesRequest.php
Normal file
32
app/Http/Requests/Reportes/ConsultarClientesRequest.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Reportes;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ConsultarClientesRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'sucursal' => 'alpha_num|required',
|
||||
'fecha_inicio' => 'required|date_format:"Y-m-d"',
|
||||
'fecha_final' => 'required|date_format:"Y-m-d"'
|
||||
];
|
||||
}
|
||||
}
|
||||
32
app/Http/Requests/Reportes/ConsultarVehiculosRequest.php
Normal file
32
app/Http/Requests/Reportes/ConsultarVehiculosRequest.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Reportes;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ConsultarVehiculosRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'sucursal' => 'alpha_num|required',
|
||||
'fecha_inicio' => 'required|date_format:"Y-m-d"',
|
||||
'fecha_final' => 'required|date_format:"Y-m-d"'
|
||||
];
|
||||
}
|
||||
}
|
||||
31
app/Http/Requests/Reportes/EncuestasGeneralRequest.php
Normal file
31
app/Http/Requests/Reportes/EncuestasGeneralRequest.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Reportes;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class EncuestasGeneralRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'sucursal' => 'alpha_num|required',
|
||||
'mes' => 'required'
|
||||
];
|
||||
}
|
||||
}
|
||||
31
app/Http/Requests/Reportes/FiltroAsesoresRequest.php
Normal file
31
app/Http/Requests/Reportes/FiltroAsesoresRequest.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Reportes;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class FiltroAsesoresRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'sucursal' => 'alpha_num|required',
|
||||
'mes' => 'required'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Reportes;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ProductividadAtencionClientesRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'sucursal' => 'alpha_num|required',
|
||||
'fecha_inicio' => 'required|date_format:"Y-m-d"',
|
||||
'fecha_final' => 'required|date_format:"Y-m-d"',
|
||||
'usuario_id' => 'alpha_num|required',
|
||||
'definio' => 'alpha_num|required',
|
||||
];
|
||||
}
|
||||
}
|
||||
33
app/Http/Requests/Reportes/ServiciosAsesoresRequest.php
Normal file
33
app/Http/Requests/Reportes/ServiciosAsesoresRequest.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Reportes;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ServiciosAsesoresRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'sucursal' => 'alpha_num|required',
|
||||
'fecha_inicio' => 'required|date_format:"Y-m-d"',
|
||||
'fecha_final' => 'required|date_format:"Y-m-d"',
|
||||
'usuario_id' => 'alpha_num|required',
|
||||
];
|
||||
}
|
||||
}
|
||||
33
app/Http/Requests/Reportes/ServiciosClientesRequest.php
Normal file
33
app/Http/Requests/Reportes/ServiciosClientesRequest.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Reportes;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ServiciosClientesRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'sucursal' => 'alpha_num|required',
|
||||
'fecha_inicio' => 'required|date_format:"Y-m-d"',
|
||||
'fecha_final' => 'required|date_format:"Y-m-d"',
|
||||
'cliente_id' => 'alpha_num|required',
|
||||
];
|
||||
}
|
||||
}
|
||||
36
app/Http/Requests/Reportes/ServiciosRequest.php
Normal file
36
app/Http/Requests/Reportes/ServiciosRequest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Reportes;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ServiciosRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'sucursal' => 'alpha_num|required',
|
||||
'fecha_inicio' => 'required|date_format:"Y-m-d"',
|
||||
'fecha_final' => 'required|date_format:"Y-m-d"',
|
||||
'tipo_servicio' => 'alpha_num|required',
|
||||
'estado_servicio' => 'alpha_num|required',
|
||||
'servicio' => 'alpha_num|required',
|
||||
'origen' => 'alpha_num|required',
|
||||
];
|
||||
}
|
||||
}
|
||||
30
app/Http/Requests/TokenFirebaseRequest.php
Normal file
30
app/Http/Requests/TokenFirebaseRequest.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class TokenFirebaseRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'token_firebase' => 'string|required',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user