Example #1
0
 public function cancelarPago(Egreso $egreso)
 {
     if (count($egreso->solicitudes) > 0) {
         $estatus = 'Autorizada';
         //Verifica si existen más de un egreso de  la solicitud, para en su caso el estatus sea "Pago Parcial"
         foreach ($egreso->solicitudes as $solicitud) {
             $sol_verifica = Solicitud::find($solicitud->id)->load('egresos');
             if (count($sol_verifica->egresos) > 1) {
                 $estatus = 'Pago Parcial';
             } else {
                 $estatus = 'Autorizada';
             }
         }
         $egreso->solicitudes()->update(['estatus' => $estatus]);
     } elseif (count($egreso->ocs) > 0) {
         $estatus = '';
         //Verifica si existe más de un egreso de la Oc, para en su caso el estatus sea "Pago Parcial;
         foreach ($egreso->ocs as $oc) {
             $oc_verifica = Oc::find($oc->id)->load('egresos');
             if (coun($oc_verifica->egresos) > 1) {
                 $estatus = 'Pago Parcial';
             } else {
                 $estatus = '';
             }
         }
         $egreso->ocs()->update(['estatus' => $estatus]);
         $this->actualizarEstatusReq($egreso->ocs[0]->req_id);
     }
 }
 private function registrarPagoSolicitud($pago_sol_legacy)
 {
     //Encontrar solicitud_id
     $solicitud_id = Solicitud::where('obs', 'LIKE', '% #SIGI: ' . $pago_sol_legacy->solicitud_id)->pluck('id');
     if (!empty($solicitud_id)) {
         //Enconrar egreso_id
         $cuenta_bancaria_id = $this->getCuentaBancariaId($pago_sol_legacy->cta_b);
         if (!empty($cuenta_bancaria_id)) {
             $egreso = Egreso::where('cuenta_bancaria_id', '=', $cuenta_bancaria_id);
             if ($pago_sol_legacy->tipo == 'ch') {
                 $egreso->where('cheque', '=', $pago_sol_legacy->poliza);
             } else {
                 $egreso->where('poliza', '=', $pago_sol_legacy->poliza);
             }
             $egreso = $egreso->first();
             if (empty($egreso->id)) {
                 dd('Egreso no encontrado ' . $pago_sol_legacy->poliza);
             }
             //Crear Relación
             $egreso->solicitudes()->attach($solicitud_id);
         }
     } else {
         dd('No se encontró la Solicitud ' . $pago_sol_legacy->solicitud_id);
     }
 }
 private function registrarComprobacion($comp_legacy)
 {
     $user_id = $this->getUserId($comp_legacy->responsable);
     $elabora = $this->getUserId($comp_legacy->usr_elabora);
     $comp = Comp::create(['oficio_c' => $comp_legacy->oficio_c, 'estatus' => $comp_legacy->estatus, 'comp_siiau' => $comp_legacy->comp_siiau, 'user_id' => $user_id, 'elabora' => $elabora, 'created_at' => '', 'updated_at' => '']);
     $comp_chegs = \DB::connection($this->db_origen)->table('tbl_comprobacion')->where('comp_id', '=', $comp_legacy->comp_id)->get();
     foreach ($comp_chegs as $comp_cheg) {
         $cuenta_bancaria_id = $this->getCuentaBancariaId($comp_cheg->cta_b);
         if (!empty($cuenta_bancaria_id)) {
             $egreso = Egreso::where('cuenta_bancaria_id', '=', $cuenta_bancaria_id);
             if ($comp_cheg->tipo == 'ch') {
                 $egreso->where('cheque', '=', $comp_cheg->ch_eg);
             } else {
                 $egreso->where('poliza', '=', $comp_cheg->ch_eg);
             }
             $egreso = $egreso->first();
             if (empty($egreso->id)) {
                 dd('Egreso no encontrado ' . $comp_cheg->ch_eg);
             }
             //Crear Relación
             $egreso->comps()->save($comp);
         }
         $gxc_id = $this->getGxCId($comp_cheg);
         if (!empty($gxc_id) && $gxc_id > 0) {
             $this->importarCompRms($comp, $gxc_id);
             $this->importarFacturas($comp, $gxc_id);
         }
     }
 }
Example #4
0
 public function nextPolizaEgreso($cuenta_bancaria_id)
 {
     $egreso = Egreso::withTrashed()->where('cuenta_bancaria_id', $cuenta_bancaria_id)->orderBy('poliza', 'DESC')->first(array('poliza'));
     if (isset($egreso)) {
         $egreso->poliza++;
         return $egreso->poliza;
     } else {
         return env('POLIZA_EGRESO_INICIAL', 1);
     }
 }
 private function getEgresosComprobados(Proyecto $proyecto)
 {
     $egresos = Egreso::whereHas('proyectos', function ($query) use($proyecto) {
         $query->where('proyectos.id', $proyecto->id);
     })->whereHas('solicitudes', function ($query) {
         $query->where('tipo_solicitud', 'Vale');
     })->whereHas('comps', function ($query) {
         $query->has('Rms');
     })->get(['id']);
     $egresos_id_comprobados = $egresos->toArray();
     return $egresos_id_comprobados;
 }
Example #6
0
 private function crearEgreso($e_legacy)
 {
     $benef_id = $this->getBenefId($e_legacy->benef_id);
     $cuenta_id = $this->getCuentaId($e_legacy->concepto);
     $user_id = $this->getUserId($e_legacy->responsable);
     $egreso = Egreso::create(['cuenta_bancaria_id' => $this->cuenta_bancaria->id, 'poliza' => $e_legacy->egreso_id, 'cheque' => 0, 'fecha' => $e_legacy->fecha, 'benef_id' => $benef_id, 'cuenta_id' => $cuenta_id, 'concepto' => '(' . $e_legacy->concepto . ') ' . $e_legacy->cmt, 'monto' => round($e_legacy->monto, 2), 'estatus' => $e_legacy->estatus, 'user_id' => $user_id]);
     //Presupuesto: Importar RMs
     if ($cuenta_id == 1 && $this->db_origen == 'legacy') {
         $egreso_rms_legacy = $this->getEgresoRmLegacy($e_legacy->egreso_id);
         foreach ($egreso_rms_legacy as $eg_rm) {
             $rm_id = Rm::whereRm($eg_rm->rm)->pluck('id');
             $egreso->rms()->attach($rm_id, ['monto' => $eg_rm->monto]);
         }
     }
 }
Example #7
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $tipo = $request->input('tipo');
     $egreso_id = $request->input('egreso_id');
     if ($tipo == 'Ingreso' && !empty($egreso_id)) {
         $no_identificado_id = $request->input('no_identificado_id');
         $no_identificado = NoIdentificado::findOrFail($no_identificado_id);
         $egreso = Egreso::findOrFail($egreso_id);
         $egreso->load('rms');
         //Determina el monto total
         $sum_monto = 0;
         $arr_monto_rms = [];
         foreach ($egreso->rms as $rm) {
             $monto_rm_id = $request->input('monto_rm_id_' . $rm->id);
             if (!empty($monto_rm_id)) {
                 $arr_monto_rms[$rm->id] = $monto_rm_id;
             }
         }
         //Determina el monto total
         foreach ($arr_monto_rms as $monto_rm) {
             $sum_monto += $monto_rm;
         }
         //Generar Póliza
         $poliza = Poliza::create(['cuenta_bancaria_id' => $no_identificado->cuenta_bancaria_id, 'fecha' => Carbon::now()->toDateString(), 'tipo' => $tipo, 'user_id' => \Auth::user()->id]);
         //Generar Cargo (cuenta_id => 10 //No Identificado)
         $poliza->polizaCargos()->create(['cuenta_id' => 10, 'monto' => $sum_monto, 'origen_id' => $no_identificado_id, 'origen_type' => 'Guia\\Models\\NoIdentificado']);
         //Generar Abono
         $poliza_abono = $poliza->polizaAbonos()->create(['cuenta_id' => $egreso->cuenta_id, 'monto' => $sum_monto, 'origen_id' => $egreso_id, 'origen_type' => 'Guia\\Models\\Egreso']);
         //Insertar RMs
         foreach ($arr_monto_rms as $rm => $monto) {
             $poliza_abono->rms()->attach($rm, ['monto' => $monto]);
         }
         //Actualizar NoIdentificado
         if (round($no_identificado->monto, 2) == round($sum_monto, 2)) {
             $no_identificado->identificado = 1;
             $no_identificado->fecha_identificado = Carbon::now()->toDateString();
             $no_identificado->save();
         }
         return redirect()->action('EgresosController@show', $egreso_id)->with(['message' => 'Póliza de Ingreso creada con éxito']);
     } else {
         return redirect()->back()->with(['message' => 'No se puede realizar esta acción']);
     }
 }
 private function registrarProyectoEgreso($gxc)
 {
     //Determinar proyecto_id
     $proyecto_id = Proyecto::where('proyecto', 'LIKE', $gxc->proy)->pluck('id');
     //Enconrar egreso_id
     $cuenta_bancaria_id = $this->getCuentaBancariaId($gxc->cta_b);
     if (!empty($cuenta_bancaria_id)) {
         $query_egreso = Egreso::where('cuenta_bancaria_id', '=', $cuenta_bancaria_id);
         if ($gxc->tipo == 'ch') {
             $query_egreso->where('cheque', '=', $gxc->poliza);
             $legacy_fecha = \DB::connection($this->db_origen)->table('tbl_cheques')->where('cta_b', $gxc->cta_b)->where('cheque', $gxc->poliza)->pluck('fecha');
         } else {
             $query_egreso->where('poliza', '=', $gxc->poliza);
             $legacy_fecha = \DB::connection($this->db_origen)->table('tbl_egresos')->where('cta_b', $gxc->cta_b)->where('egreso_id', $gxc->poliza)->pluck('fecha');
         }
         $query_egreso->where('fecha', $legacy_fecha);
         $egreso = $query_egreso->first();
         if (empty($egreso->id)) {
             dd('Egreso no encontrado ' . $gxc->poliza);
         }
         //Crear Relación
         $egreso->proyectos()->attach($proyecto_id, ['monto' => round($gxc->monto, 2)]);
     }
 }
 public function chequeRtf($id)
 {
     $egreso = Egreso::findOrFail($id);
     $egreso->load('proyectos.fondos', 'proyectos.urg');
     $arr_rms = [];
     if (count($egreso->rms) > 0) {
         foreach ($egreso->rms as $rm) {
             $arr_rms[$rm->rm] = ['cog' => $rm->cog->cog, 'monto' => 0];
         }
         foreach ($egreso->rms as $rm) {
             $arr_rms[$rm->rm]['monto'] += $rm->pivot->monto;
         }
     }
     $fecha_texto = \Utility::fecha_texto($egreso->fecha);
     $nat = new Nat(round($egreso->monto, 2), '');
     $monto_letra = $nat->convertir();
     $presu = \InfoDirectivos::getResponsable('PRESU')->iniciales;
     $cfin = \InfoDirectivos::getResponsable('FIN')->iniciales;
     $elabora = \Auth::user()->iniciales;
     return view('egresos.formCheque', compact('egreso', 'monto_letra', 'fecha_texto', 'presu', 'cfin', 'elabora', 'arr_rms'));
 }
Example #10
0
 public function reporteEjercidoRms($proyecto_id)
 {
     $rms = Rm::whereProyectoId($proyecto_id)->get(['id']);
     $egresos_id = [];
     foreach ($rms as $rm) {
         $rm_obj = RM::find($rm->id);
         //Exlusión de egresos de vales comprobados
         $egresos_id_comprobados = $this->getEgresosComprobados($rm_obj);
         $egresos_query = $rm->egresos()->where('cuenta_id', 1);
         if (count($egresos_id_comprobados) > 0) {
             $egresos_query->whereNotIn('egresos.id', $egresos_id_comprobados);
         }
         $nvo = $egresos_query->get(['egresos.id'])->lists('id')->all();
         $egresos_id = array_merge($egresos_id, $nvo);
     }
     $ejercido_rm = Egreso::whereIn('id', $egresos_id)->with('benef', 'cuenta', 'user')->get();
     return $ejercido_rm;
 }
 public function importarReembolsosFaltantes()
 {
     $legacy_reembolsos = \DB::connection($this->db_origen)->table('tbl_reembolsos')->where('cta_b', $this->cuenta_bancaria->cuenta_bancaria)->whereNotIn('ingreso_id', $this->reembolsos_importados)->get();
     foreach ($legacy_reembolsos as $legacy_reembolso) {
         $cuenta_bancaria_id_egreso = $this->getCuentaBancariaId($legacy_reembolso->cta_b_cheg);
         $legacy_ingreso = \DB::connection($this->db_origen)->table('tbl_ingresos')->where('cta_b', $legacy_reembolso->cta_b)->where('ingreso_id', $legacy_reembolso->ingreso_id)->first();
         if (!empty($legacy_ingreso->ingreso_id)) {
             //Crear No Identificado
             $no_identificado = NoIdentificado::create(['cuenta_bancaria_id' => $this->cuenta_bancaria->id, 'fecha' => $legacy_ingreso->fecha, 'monto' => $legacy_ingreso->monto, 'no_deposito' => '', 'identificado' => 0]);
             $poliza = Poliza::create(['fecha' => $legacy_ingreso->fecha, 'tipo' => 'Ingreso', 'concepto' => $legacy_ingreso->cmt, 'user_id' => \Auth::user()->id]);
             $poliza->polizaCargos()->create(['cuenta_id' => 10, 'monto' => $legacy_ingreso->monto, 'origen_id' => $no_identificado->id, 'origen_type' => 'Guia\\Models\\NoIdentificado']);
             $egreso_query = Egreso::where('cuenta_bancaria_id', $cuenta_bancaria_id_egreso);
             if ($legacy_reembolso->tipo == 'ch') {
                 $egreso_query->where('cheque', $legacy_reembolso->ch_eg);
             } else {
                 $egreso_query->where('poliza', $legacy_reembolso->ch_eg);
             }
             $egreso_id = $egreso_query->pluck('id');
             $origen_id = $egreso_id;
             $origen_type = 'Guia\\Models\\Egreso';
             $cuenta_id = $this->getCuentaId($legacy_ingreso->concepto);
             $poliza_abono = $poliza->polizaAbonos()->create(['cuenta_id' => $cuenta_id, 'monto' => $legacy_ingreso->monto, 'origen_id' => $origen_id, 'origen_type' => $origen_type]);
             //Registrar RMs del Ingreso
             $legacy_ingreso_rms = \DB::connection($this->db_origen)->table('tbl_ingresos_rm')->where('cta_b', $legacy_ingreso->cta_b)->where('ingreso_id', $legacy_ingreso->ingreso_id)->get();
             if (count($legacy_ingreso_rms) > 0) {
                 foreach ($legacy_ingreso_rms as $legacy_ingreso_rm) {
                     $rm_id = Rm::whereRm($legacy_ingreso_rm->rm)->pluck('id');
                     $poliza_abono->rms()->attach($rm_id, ['monto' => $legacy_ingreso_rm->monto]);
                 }
             }
         }
     }
 }
Example #12
0
 private function getChequesImportados()
 {
     $cheques_importados = Egreso::where('cuenta_bancaria_id', $this->cuenta_bancaria->id)->lists('cheque')->all();
     return $cheques_importados;
 }
 /**
  * Genera egreso para pago total de una solicitud u orden de compra.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     if ($request->input('doc_type') == 'Solicitud') {
         $doc = Solicitud::findOrFail($request->input('doc_id'));
         $benef_id = $doc->benef_id;
         $concepto = $doc->concepto;
         $monto = $doc->monto;
         $ocultar_id = 'sol-' . $request->input('doc_id');
         $message = "Solicitud " . $request->input('doc_id') . " agregada";
     }
     if ($request->input('doc_type') == 'Oc') {
         $doc = Oc::findOrFail($request->input('doc_id'));
         $doc->load('articulos.rms');
         $benef_id = $doc->benef_id;
         $concepto = '';
         /**
          * @todo Determinar Monto de OC
          */
         $monto = 0;
         $ocultar_id = 'oc-' . $request->input('doc_id');
         $message = "Orden de Compra " . $doc->oc . " agregada";
     }
     $tipo_egreso = $request->input('tipo_egreso');
     if ($tipo_egreso == 'cheque') {
         $cheque = $request->input('cheque');
         if (empty($cheque)) {
             $cheque = \Consecutivo::nextCheque($request->input('cuenta_bancaria_id'));
         }
         $poliza = 0;
     } else {
         $poliza = \Consecutivo::nextPolizaEgreso($request->input('cuenta_bancaria_id'));
         $cheque = 0;
     }
     $egreso = new Egreso();
     $egreso->cuenta_bancaria_id = $request->input('cuenta_bancaria_id');
     $egreso->poliza = $poliza;
     $egreso->cheque = $cheque;
     $egreso->fecha = $request->input('fecha');
     $egreso->benef_id = $benef_id;
     $egreso->cuenta_id = 1;
     //Presupuesto
     $egreso->concepto = $concepto;
     $egreso->monto = $monto;
     $egreso->user_id = \Auth::user()->id;
     $egreso->save();
     if ($request->input('doc_type') == 'Solicitud') {
         $rms = $doc->rms;
         foreach ($rms as $rm) {
             $monto_rm = $rm->pivot->monto;
             $egreso->rms()->attach($rm->id, ['monto' => $monto_rm]);
         }
     } else {
         $sum_monto = 0;
         //Creación de Arreglo
         foreach ($doc->articulos as $articulo) {
             foreach ($articulo->rms as $rm) {
                 $arr_rms[$rm->id] = 0;
             }
         }
         //Suma por Rm
         foreach ($doc->articulos as $articulo) {
             foreach ($articulo->rms as $rm) {
                 $arr_rms[$rm->id] += round($rm->pivot->monto, 2);
             }
         }
         //Crea Registro
         foreach ($arr_rms as $rm_id => $monto_rm) {
             $sum_monto += $monto_rm;
             $egreso->rms()->attach($rm_id, ['monto' => $monto_rm]);
         }
         $egreso->monto = $sum_monto;
         $egreso->save();
     }
     $pago = new PagoDocumento($doc, $request->input('doc_type'));
     $pago->pagarDocumento($egreso, 'Total');
     //Inserta suma por proyecto en tabla egreso_proyecto
     $egreso_rms = $egreso->rms()->get();
     $egreso_rms = $egreso_rms->groupBy('proyecto_id');
     $egreso_rms->each(function ($item, $key) use($egreso) {
         $egreso->proyectos()->attach($key, ['monto' => $egreso->rms()->where('proyecto_id', '=', $key)->sum('egreso_rm.monto')]);
     });
     return redirect(action('GenerarEgresoController@index'))->with(['message' => 'Cheque ' . $cheque . ' Generado']);
     //        if($request->ajax()) {
     //            return response()->json([
     //                'message' => $message,
     //                'ocultar' => $ocultar_id
     //            ]);
     //        }
 }
 private function getCancelados()
 {
     $cancelados = Egreso::onlyTrashed()->where('cuenta_bancaria_id', $this->cuenta_bancaria_id)->whereBetween('deleted_at', [$this->fecha_inicio, $this->fecha_fin])->with('cuenta')->get();
     return $cancelados;
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id, Request $request)
 {
     $rel_interna = RelInterna::findOrFail($id);
     $rel_interna->fecha_revision = Carbon::today()->toDateString();
     $rel_interna->recibe = \Auth::user()->id;
     $rel_interna->estatus = 'Recibida';
     $rel_interna->save();
     foreach ($request->input('docs') as $doc_id) {
         if ($rel_interna->tipo_documentos == 'Egresos') {
             $documento = Egreso::find($doc_id);
         }
         if ($rel_interna->tipo_documentos == 'Solicitudes') {
             $documento = Solicitud::find($doc_id);
         }
         $documento->user_id = \Auth::user()->id;
         $documento->save();
         $documento_rel_interna = $documento->relacionInternaDocs()->where('rel_interna_id', $id)->first();
         $documento_rel_interna->validacion = 'Aceptada';
         $documento_rel_interna->save();
     }
     $rel_interna->load('relInternaDocs');
     foreach ($rel_interna->relInternaDocs as $doc) {
         if (empty($doc->validacion)) {
             RelInternaDoc::find($doc->id)->update(['validacion' => 'Rechazada']);
         }
     }
     $message = 'Relación ' . $rel_interna->id . ' recibida con éxito';
     return redirect()->action('RelacionInternaController@index')->with(['message' => $message]);
 }