Exemplo n.º 1
0
 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]);
                 }
             }
         }
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Requests\NoIdentificadoRequest $request)
 {
     $no_identificado = NoIdentificado::create($request->all());
     return redirect()->action('NoIdentificadoController@show', $no_identificado->id)->with(['message' => 'Depósito No Identificado creado con éxito', 'alert-class' => 'alert-success']);
 }