Example #1
0
 public function importarReqs()
 {
     $reqs_legacy = $this->consultarReqsLegacy();
     foreach ($reqs_legacy as $req_legacy) {
         if (!empty($req_legacy->proy)) {
             $proyecto = Proyecto::whereProyecto($req_legacy->proy)->get(['id', 'urg_id']);
         } else {
             $proyecto = Proyecto::where('proyecto', 'like', $req_legacy->proy_esp . '%')->get(['id', 'urg_id']);
         }
         //Determinar el ID del usuario solicitante
         $solicita_id = User::whereLegacyUsername($req_legacy->solicita)->pluck('id');
         if (empty($solicita_id)) {
             $solicita_id = 2;
         }
         //Determinar el ID del usuario autoriza
         if (!empty($req_legacy->autoriza)) {
             $autoriza_id = User::whereLegacyUsername($req_legacy->autoriza)->pluck('id');
         } else {
             $autoriza_id = 0;
         }
         if (empty($autoriza_id)) {
             $autoriza_id = 2;
         }
         //Determinar el usuario responsable
         if (!empty($req_legacy->responsable)) {
             $user_id = User::whereLegacyUsername($req_legacy->responsable)->pluck('id');
         } else {
             $user_id = 0;
         }
         if (empty($user_id)) {
             $user_id = 2;
         }
         $test_req = Req::whereReq($req_legacy->req)->first(['req']);
         if (empty($test_req)) {
             $req_nueva = new Req();
             $req_nueva->req = $req_legacy->req;
             $req_nueva->fecha_req = $req_legacy->fecha_req;
             if (count($proyecto) > 0) {
                 $req_nueva->urg_id = $proyecto[0]->urg_id;
                 $req_nueva->proyecto_id = $proyecto[0]->id;
                 $req_nueva->etiqueta = $req_legacy->etiqueta;
             } else {
                 $req_nueva->urg_id = 1;
                 $req_nueva->proyecto_id = 1;
                 $req_nueva->etiqueta = $req_legacy->etiqueta . ' #RevisarProy-URG';
             }
             $req_nueva->lugar_entrega = $req_legacy->lugar_entrega;
             $req_nueva->obs = $req_legacy->obs;
             $req_nueva->solicita = $solicita_id;
             $req_nueva->autoriza = $autoriza_id;
             $req_nueva->estatus = $req_legacy->estatus;
             $req_nueva->user_id = $user_id;
             $req_nueva->tipo_cambio = $req_legacy->tc;
             $req_nueva->moneda = $req_legacy->moneda;
             $req_nueva->tipo_orden = $req_legacy->tipo_orden;
             $req_nueva->save();
         }
     }
 }
 public function importarArticulos()
 {
     $reqs = Req::whereBetween('req', $this->arr_rango)->get(['id', 'req', 'estatus']);
     foreach ($reqs as $req) {
         $articulos_legacy = $this->consultarArticulosLegacy($req->req);
         foreach ($articulos_legacy as $art_legacy) {
             if (!empty($art_legacy->oc)) {
                 $oc_id = Oc::whereOc($art_legacy->oc)->pluck('id');
                 if (empty($oc_id)) {
                     $oc_id = 0;
                 }
             } else {
                 $oc_id = 0;
             }
             $articulo = new Articulo();
             $articulo->req_id = $req->id;
             $articulo->articulo = $art_legacy->art . ' ' . $art_legacy->esp;
             $articulo->cantidad = $art_legacy->cantidad;
             $articulo->impuesto = $art_legacy->impuesto;
             $articulo->monto = $art_legacy->monto;
             $articulo->oc_id = $oc_id;
             $articulo->unidad = $art_legacy->unidad;
             $articulo->inventariable = $art_legacy->alta;
             $articulo->save();
             if (!empty($art_legacy->rm)) {
                 $rm_id = Rm::whereRm($art_legacy->rm)->value('id');
                 $articulo->rms()->attach($rm_id, ['monto' => $art_legacy->monto]);
             }
         }
     }
 }
Example #3
0
 public function getEjercicioRm($rm)
 {
     $ejercicio_rm = collect(['rm' => $rm->rm]);
     $ejercicio_rm->put('objetivo', $rm->objetivo->objetivo);
     $ejercicio_rm->put('cog', $rm->cog->cog);
     $ejercicio_rm->put('d_cog', $rm->cog->d_cog);
     $ejercicio_rm->put('presupuestado', $rm->monto);
     $compensado_origen = CompensaOrigen::where('rm_id', $rm->id)->sum('monto');
     $compensado_destino = CompensaDestino::where('rm_id', $rm->id)->sum('monto');
     $compensado = round($compensado_destino, 2) - round($compensado_origen, 2);
     $ejercicio_rm->put('compensado', $compensado);
     $rm_objeto = Rm::find($rm->id);
     $ejercido = $this->getMontoEjercido($rm_objeto);
     $ejercicio_rm->put('ejercido', $ejercido);
     $reintegros_df = $this->getMontoReintegrosDF($rm_objeto);
     $ejercicio_rm->put('reintegros_df', $reintegros_df);
     //-- Reservado --//
     $reqs_id = Req::where('proyecto_id', $rm->proyecto_id)->where('estatus', 'Autorizada')->lists('id')->all();
     $reservado_reqs = round($rm_objeto->articulos()->whereIn('req_id', $reqs_id)->sum('articulo_rm.monto'), 2);
     $solicitudes_id = Solicitud::where('proyecto_id', $rm->proyecto_id)->where('estatus', 'Autorizada')->lists('id')->all();
     $reservado_solicitudes = round($rm_objeto->solicitudes()->whereIn('solicitud_id', $solicitudes_id)->sum('rm_solicitud.monto'), 2);
     $reservado = $reservado_reqs + $reservado_solicitudes;
     $ejercicio_rm->put('reservado', $reservado);
     $saldo = $ejercicio_rm->get('presupuestado') + $ejercicio_rm->get('compensado') - $ejercicio_rm->get('ejercido') - $ejercicio_rm->get('reservado');
     $ejercicio_rm->put('saldo', round($saldo, 2));
     return $ejercicio_rm;
 }
Example #4
0
 public function nextReq()
 {
     $req = Req::orderBy('req', 'DESC')->first(array('req'));
     if (isset($req)) {
         $req->req++;
         return $req->req;
     } else {
         return 1;
     }
 }
Example #5
0
 public function estatusReq($estatus)
 {
     $req = Req::find($this->req->id);
     $req->estatus = $estatus;
     $req->save();
     //Creación de registro
     $fecha_hora = Carbon::now();
     $registro = new Registro(['user_id' => \Auth::user()->id, 'estatus' => $estatus, 'fecha_hora' => $fecha_hora]);
     $req->registros()->save($registro);
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $cuentas_bancarias = CuentaBancaria::all();
     $fecha = Carbon::today()->toDateString();
     $solicitudes = array();
     $solicitudes = Solicitud::whereIn('estatus', ['Autorizada', 'Pago Parcial'])->with('proyecto', 'benef')->get();
     $reqs = array();
     $reqs = Req::whereEstatus('Autorizada')->with('ocs.benef', 'proyecto')->get();
     return view('egresos.generarEgresos', compact('solicitudes', 'reqs', 'cuentas_bancarias', 'fecha'));
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $req_id = $request->route()->getParameter('req_id');
     $req = \Guia\Models\Req::whereId($req_id)->get(['solicita', 'estatus']);
     //Valida que el usuario sea el dueño de la req y que la req no esté enviada
     if (\Auth::user()->id != $req[0]->solicita || $req[0]->estatus != '') {
         return redirect()->action('RequisicionController@show', array($req_id))->with(['alert-class' => 'alert-warning', 'message' => 'No puede editar esta requisición']);
     }
     return $next($request);
 }
 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function create($req_id)
 {
     $req = Req::find($req_id);
     $unidades = Unidad::all();
     $data['req'] = $req;
     $solicita = User::find($req->solicita);
     $data['solicita'] = $solicita;
     foreach ($unidades as $unidad) {
         $arr_unidades[$unidad->tipo][$unidad->unidad] = $unidad->unidad;
     }
     $data['unidades'] = $arr_unidades;
     return view('reqs.formArticulo')->with($data);
 }
 public function recibirReq(RecibirRequest $request)
 {
     foreach ($request->input('arr_req_id') as $req_id) {
         $requisicion = Req::find($req_id);
         $requisicion->estatus = $request->input('estatus');
         $requisicion->user_id = \Auth::user()->id;
         $requisicion->save();
         //Creación de registro
         $fecha_hora = Carbon::now();
         $registro = new Registro(['user_id' => \Auth::user()->id, 'estatus' => $request->input('estatus'), 'fecha_hora' => $fecha_hora]);
         $requisicion->registros()->save($registro);
     }
     return redirect()->action('RecibirController@seleccionarReq')->with(['message' => 'Requisiciones recibidas', 'alert-class' => 'alert-success']);
 }
Example #10
0
 public function importarOcs()
 {
     $legacy_ocs = $this->consultarOcsLegacy();
     foreach ($legacy_ocs as $oc_legacy) {
         $benef_id = $this->getBenefId($oc_legacy->benef_id);
         $req_id = Req::whereReq($oc_legacy->req)->pluck('id');
         $oc_nueva = new Oc();
         $oc_nueva->req_id = $req_id;
         $oc_nueva->oc = $oc_legacy->oc;
         $oc_nueva->fecha_oc = $oc_legacy->fecha_oc;
         $oc_nueva->benef_id = $benef_id;
         $oc_nueva->estatus = $oc_legacy->estatus;
         $oc_nueva->save();
     }
 }
 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function create($soldep_id)
 {
     $soldep = SolDeposito::findOrFail($soldep_id);
     $fondo_filto = $soldep->fondo_id;
     $solicitudes = array();
     $solicitudes = Solicitud::whereEstatus('Autorizada')->with('proyecto', 'benef')->whereHas('proyecto', function ($query) use($fondo_filto) {
         $query->whereHas('fondos', function ($fondos_query) use($fondo_filto) {
             $fondos_query->where('fondo_id', '=', $fondo_filto);
         });
     })->get();
     $reqs = array();
     $reqs = Req::whereEstatus('Autorizada')->with('ocs.benef', 'proyecto')->whereHas('proyecto', function ($query) use($fondo_filto) {
         $query->whereHas('fondos', function ($fondos_query) use($fondo_filto) {
             $fondos_query->where('fondo_id', '=', $fondo_filto);
         });
     })->get();
     return view('soldep.formSolDepDocs', compact('soldep', 'solicitudes', 'reqs'));
 }
 public function actualizarImpuesto()
 {
     $reqs_legacy = $this->consultarReqsLegacy();
     foreach ($reqs_legacy as $req) {
         $req_id = Req::whereReq($req)->pluck('id');
         $articulos = Articulo::whereReqId($req_id)->get();
         $cuadro_legacy = $this->consultarCuadroLegacy($req);
         if (count($articulos) != count($cuadro_legacy)) {
             dd($req->id . ' #Articulos: ' . count($articulos) . ' #Cuadro: ' . count($cuadro_legacy));
         }
         $i = 0;
         foreach ($articulos as $articulo) {
             $articulo->impuesto = $cuadro_legacy[$i]->impuesto;
             $articulo->save();
             $i++;
         }
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(InvitacionRequest $request)
 {
     //Si existe un cuadro para la requisición, agrega la referencia del ID del cuadro
     $verifica_cuadro = Cuadro::whereReqId($request->input('req_id'))->first();
     if (!empty($verifica_cuadro)) {
         $request->merge(array('cuadro_id' => $verifica_cuadro->id));
     }
     //Verifica si es la primer invitación
     $cotizaciones_existentes = Cotizacion::whereReqId($request->input('req_id'))->count();
     //Si es la primera, se crea registro en requisición y se actualiza su estatus
     if ($cotizaciones_existentes == 0) {
         $req = Req::find($request->input('req_id'));
         $estatus_req = 'Cotizando';
         $req->save();
         $fecha_hora = Carbon::now();
         $registro = new Registro(['user_id' => \Auth::user()->id, 'estatus' => $estatus_req, 'fecha_hora' => $fecha_hora]);
         $req->registros()->save($registro);
     }
     $request->merge(array('fecha_invitacion' => Carbon::now()->toDateString()));
     $invitacion = Cotizacion::create($request->all());
     return redirect()->action('InvitacionController@index', array($invitacion->req_id));
 }
 /**
  * Muestra formulario para autorizar requisición.
  *
  * @return Response
  */
 public function formAutorizar($id)
 {
     $req = Req::find($id);
     $articulos = Articulo::whereReqId($id)->with('cotizaciones')->with('rms.cog')->get();
     $articulos_helper = new ArticulosHelper($articulos, $id);
     $articulos_helper->setArticulosSinRms();
     $articulos_helper->setRmsArticulos();
     $arr_rms = Rm::whereProyectoId($req->proyecto_id)->get()->lists('cog_rm_saldo', 'id')->all();
     $data['req'] = $req;
     $data['articulos'] = $articulos;
     $data['articulos_sin_rms'] = $articulos_helper->articulos_sin_rms;
     $data['rms_articulos'] = $articulos_helper->rms_articulos;
     $data['arr_rms'] = $arr_rms;
     $rms_asignados = true;
     foreach ($articulos as $articulo) {
         if ($articulo->rms->count() == 0) {
             $rms_asignados = false;
         }
     }
     $data['rms_asignados'] = $rms_asignados;
     $solicita = User::find($req->solicita);
     $data['solicita'] = $solicita;
     return view('reqs.formAutorizarReq')->with($data);
 }
 public function formatoPdf($id)
 {
     $req = Req::find($id);
     $articulos = Articulo::whereReqId($id)->get();
     $req_pdf = new Requisicion($req, $articulos);
     return response($req_pdf->crearPdf()->header('Content-Type', 'application/pdf'));
 }
Example #16
0
 private function getMontoReservado(Proyecto $proyecto)
 {
     $reqs_id = Req::where('proyecto_id', $proyecto->id)->where('estatus', 'Autorizada')->lists('id')->all();
     $articulos = Articulo::whereIn('req_id', $reqs_id)->with('rms')->get();
     $reservado_reqs = $articulos->sum('articulo_rm.monto');
     //$reservado_reqs = round($rm_objeto->articulos()->whereIn('req_id', $reqs_id)->sum('articulo_rm.monto'),2);
     $reservado_solicitudes = round(Solicitud::where('proyecto_id', $proyecto->id)->where('estatus', 'Autorizada')->sum('monto'), 2);
     $montoReservado = $reservado_reqs + $reservado_solicitudes;
     return round($montoReservado, 2);
 }
Example #17
0
 private function actualizarEstatusReq($req_id)
 {
     $ocs = Oc::where('req_id', $req_id)->get();
     $estatus_req = 'Pagada';
     foreach ($ocs as $oc) {
         if ($oc->estatus != 'Pagada') {
             $estatus_req = 'Autorizada';
         }
     }
     $req = Req::find($req_id);
     if ($req->estatus != $estatus_req) {
         $req->estatus = $estatus_req;
         $req->save();
     }
 }
 /**
  * Actualiza cuadro comparativo
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id, MatrizCuadroRequest $request)
 {
     /**
      * @todo Validar que no se seleccione una cotización de un artículo con costo == 0
      */
     $cuadro = Cuadro::find($id);
     $arr_articulos_id = Articulo::whereReqId($cuadro->req_id)->lists('id')->all();
     $arr_cotizaciones_id = Cotizacion::whereReqId($cuadro->req_id)->lists('id')->all();
     foreach ($arr_articulos_id as $articulo_id) {
         $articulo = Articulo::find($articulo_id);
         $sel_value = $request->input('sel_' . $articulo_id);
         $no_cotizado = $request->input('no_cotizado_' . $articulo_id);
         if (empty($no_cotizado)) {
             $no_cotizado = 0;
         }
         foreach ($arr_cotizaciones_id as $cotizacion_id) {
             $costo_nuevo = $request->input('costo_' . $articulo_id . '_' . $cotizacion_id);
             if (isset($costo_nuevo)) {
                 $sel_value == $cotizacion_id && $costo_nuevo > 0 && empty($no_cotizado) ? $sel = 1 : ($sel = 0);
                 //Verifica existencia de pivote
                 if ($articulo->cotizaciones()->get()->contains($cotizacion_id)) {
                     $costo_actual = $articulo->cotizaciones()->whereCotizacionId($cotizacion_id)->first()->pivot->costo;
                     $sel_actual = $articulo->cotizaciones()->whereCotizacionId($cotizacion_id)->first()->pivot->sel;
                     if ($costo_actual != $costo_nuevo || $sel_actual != $sel) {
                         $articulo->cotizaciones()->updateExistingPivot($cotizacion_id, ['costo' => round($costo_nuevo, 2), 'sel' => $sel]);
                     }
                 } else {
                     //Crea un nuevo registro en pivote articulo_cotizacion
                     $articulo->cotizaciones()->attach([$cotizacion_id => ['costo' => round($costo_nuevo, 2), 'sel' => $sel]]);
                 }
             }
         }
         //Actualizar impuesto en articulos
         $articulo->impuesto = $request->input('impuesto_' . $articulo_id);
         $articulo->no_cotizado = $no_cotizado;
         $articulo->save();
     }
     //Actualiza información de vigencia y garantía @cotizaciones
     foreach ($arr_cotizaciones_id as $cotizacion_id) {
         $cotizacion = Cotizacion::find($cotizacion_id);
         $cotizacion->vigencia = $request->input('vigencia_' . $cotizacion_id);
         $cotizacion->garantia = $request->input('garantia_' . $cotizacion_id);
         $cotizacion->imprimir = true;
         $cotizacion->save();
     }
     //Actualizar Tipo de Cambio en @reqs
     $tipo_cambio = $request->input('tipo_cambio');
     $moneda = $request->input('moneda');
     $req = Req::find($cuadro->req_id);
     if ($req->tipo_cambio != $tipo_cambio || $req->moneda != $moneda) {
         $req->tipo_cambio = $tipo_cambio;
         $req->moneda = $moneda;
         $req->save();
     }
     return redirect()->action('MatrizCuadroController@show', array($cuadro->req_id));
 }
 public function validarOperacion()
 {
     $operacion = true;
     $hoy = \Carbon\Carbon::today()->toDateString();
     if (!$this->proyecto_id) {
         if ($this->modelo == 'Req') {
             $this->proyecto_id = Req::where('id', $this->documento_id)->pluck('proyecto_id');
         } elseif ($this->modelo == 'Solicitud') {
             $this->proyecto_id = Solicitud::where('id', $this->documento_id)->pluck('proyecto_id');
         }
     }
     $proyecto = Proyecto::find($this->proyecto_id);
     if (empty($proyecto)) {
         return false;
     }
     $op_restrigindas = OpRestringida::where('aaaa', $proyecto->aaaa)->where('modelo', $this->modelo)->whereNested(function ($query) use($hoy) {
         $query->where('inicio', '<=', $hoy);
         //                $query->where('fin', '>=', $hoy);
     })->whereNested(function ($query) use($proyecto) {
         $query->orWhere(function ($q) use($proyecto) {
             $q->where('aplica_type', 'Guia\\Models\\TipoProyecto');
             $q->where('aplica_id', $proyecto->tipo_proyecto_id);
         });
         $query->orWhere(function ($q) use($proyecto) {
             $q->where('aplica_type', 'Guia\\Models\\Urg');
             $q->where('aplica_id', $proyecto->urg_id);
         });
         $query->orWhere(function ($q) use($proyecto) {
             $q->where('aplica_type', 'Guia\\Models\\Proyecto');
             $q->where('aplica_id', $proyecto->id);
         });
     })->get();
     if (count($op_restrigindas) > 0) {
         $operacion = false;
         $this->op_restringida = $op_restrigindas[0];
         foreach ($op_restrigindas as $restriccion) {
             $excepcion = OpExcepcion::where('op_restringida_id', $restriccion->id)->whereNested(function ($query) use($hoy) {
                 $query->where('inicio', '<=', $hoy);
                 $query->where('fin', '>=', $hoy);
             })->whereNested(function ($query) use($proyecto) {
                 $query->orWhere(function ($q) use($proyecto) {
                     $q->where('aplica_type', 'Guia\\Models\\TipoProyecto');
                     $q->where('aplica_id', $proyecto->tipo_proyecto_id);
                 });
                 $query->orWhere(function ($q) use($proyecto) {
                     $q->where('aplica_type', 'Guia\\Models\\Urg');
                     $q->where('aplica_id', $proyecto->urg_id);
                 });
                 $query->orWhere(function ($q) use($proyecto) {
                     $q->where('aplica_type', 'Guia\\Models\\Proyecto');
                     $q->where('aplica_id', $proyecto->id);
                 });
                 $query->orWhere(function ($q) {
                     $q->where('aplica_type', 'Guia\\User');
                     $q->where('aplica_id', \Auth::user()->id);
                 });
             })->get();
             if (count($excepcion) > 0) {
                 $operacion = true;
             }
         }
     }
     return $operacion;
 }
 public function actualizarFechaCuadro()
 {
     $legacy_reqs = \DB::connection($this->db_origen)->table('tbl_req')->get(['req', 'fecha_cuadro']);
     foreach ($legacy_reqs as $legacy_req) {
         $req_id = Req::whereReq($legacy_req->req)->pluck('id');
         Cuadro::whereReqId($req_id)->update(['fecha_cuadro' => $legacy_req->fecha_cuadro]);
     }
 }