public Resultado Banco_Concepto_Actualizar(DTO.Bancos.Conceptos.Actualizar ficha) { var result = new Resultado(); try { using (var ctx = new dBEntities(_cn.ConnectionString)) { using (var ts = new TransactionScope()) { var entBanConcepto = ctx.bancos_movimientos_conceptos.Find(ficha.AutoConcepto); if (entBanConcepto == null) { result.Mensaje = "[ ID ] CONCEPTO NO ENCONTRADO"; result.Result = EnumResult.isError; return(result); } if (ficha.IdCtaGasto != -1) { var entCtaGasto = ctx.contabilidad_plancta.Find(ficha.IdCtaGasto); if (entCtaGasto == null) { result.Mensaje = "[ ID CTA GASTO ] NO ENCONTRADO"; result.Result = EnumResult.isError; return(result); } } if (ficha.IdCtaPasivo != -1) { var entCtaPasivo = ctx.contabilidad_plancta.Find(ficha.IdCtaPasivo); if (entCtaPasivo == null) { result.Mensaje = "[ ID CTA PASIVO ] NO ENCONTRADO"; result.Result = EnumResult.isError; return(result); } } if (ficha.IdCtaBanco != -1) { var entCtaBanco = ctx.contabilidad_plancta.Find(ficha.IdCtaBanco); if (entCtaBanco == null) { result.Mensaje = "[ ID CTA BANCO ] NO ENCONTRADO"; result.Result = EnumResult.isError; return(result); } } var entContBanConcepto = ctx.contabilidad_banco_conceptos.FirstOrDefault(ct => ct.autoMovimientoConcepto == ficha.AutoConcepto); if (entContBanConcepto == null) { entContBanConcepto = new contabilidad_banco_conceptos() { autoMovimientoConcepto = ficha.AutoConcepto, idCtaGasto = ficha.IdCtaGasto, idCtaPasivo = ficha.IdCtaPasivo, idCtaBanco = ficha.IdCtaBanco, idSucursal = "", }; ctx.contabilidad_banco_conceptos.Add(entContBanConcepto); } else { entContBanConcepto.idCtaGasto = ficha.IdCtaGasto; entContBanConcepto.idCtaPasivo = ficha.IdCtaPasivo; entContBanConcepto.idCtaBanco = ficha.IdCtaBanco; } ctx.SaveChanges(); if (ficha.IdCtaBanco != -1) { var modoRef = entContBanConcepto.bancos_movimientos_conceptos.clase.Trim().ToUpper() == "EGRESO" ? "NDB" : "DEP"; var entRegla = ctx.contabilidad_reglas_integracion_detalle.FirstOrDefault(dt => dt.idPlanCta == ficha.IdCtaBanco && dt.referencia == modoRef && dt.idReglaIntegracion == 6); if (entRegla == null) { entRegla = new contabilidad_reglas_integracion_detalle() { idReglaIntegracion = 6, idPlanCta = ficha.IdCtaBanco, signo = -1, referencia = modoRef, idSucursal = 0, }; ctx.contabilidad_reglas_integracion_detalle.Add(entRegla); } else { entRegla.idPlanCta = ficha.IdCtaBanco; } ctx.SaveChanges(); } if (ficha.IdCtaPasivo != -1) { var entRegla = ctx.contabilidad_reglas_integracion_detalle.FirstOrDefault(dt => dt.idPlanCta == ficha.IdCtaPasivo && dt.referencia == "MONTO POR PAGAR" && dt.idReglaIntegracion == 2); if (entRegla == null) { entRegla = new contabilidad_reglas_integracion_detalle() { idReglaIntegracion = 2, idPlanCta = ficha.IdCtaPasivo, signo = -1, referencia = "MONTO POR PAGAR", idSucursal = 0, }; ctx.contabilidad_reglas_integracion_detalle.Add(entRegla); } else { entRegla.idPlanCta = ficha.IdCtaPasivo; } ctx.SaveChanges(); entRegla = ctx.contabilidad_reglas_integracion_detalle.FirstOrDefault(dt => dt.idPlanCta == ficha.IdCtaPasivo && dt.referencia == "MONTO PAGADO" && dt.idReglaIntegracion == 3); if (entRegla == null) { entRegla = new contabilidad_reglas_integracion_detalle() { idReglaIntegracion = 3, idPlanCta = ficha.IdCtaPasivo, signo = 1, referencia = "MONTO PAGADO", idSucursal = 0, }; ctx.contabilidad_reglas_integracion_detalle.Add(entRegla); } else { entRegla.idPlanCta = ficha.IdCtaPasivo; } ctx.SaveChanges(); } if (ficha.IdCtaGasto != -1) { var entRegla = ctx.contabilidad_reglas_integracion_detalle.FirstOrDefault(dt => dt.idPlanCta == ficha.IdCtaGasto && dt.referencia == "GASTO" && dt.idReglaIntegracion == 2); if (entRegla == null) { entRegla = new contabilidad_reglas_integracion_detalle() { idReglaIntegracion = 2, idPlanCta = ficha.IdCtaGasto, signo = 1, referencia = "GASTO", idSucursal = 0, }; ctx.contabilidad_reglas_integracion_detalle.Add(entRegla); } else { entRegla.idPlanCta = ficha.IdCtaGasto; } ctx.SaveChanges(); } ctx.SaveChanges(); ts.Complete(); } } } catch (Exception e) { result.Mensaje = e.Message; result.Result = DTO.EnumResult.isError; } return(result); }
public Resultado Bancos_Banco_Actualizar(DTO.Bancos.Banco.Actualizar ficha) { var result = new Resultado(); try { using (var ctx = new dBEntities(_cn.ConnectionString)) { using (var ts = new TransactionScope()) { //if (ficha.IdCtaContable.HasValue) //{ //} //else //{ // var entContBanco = ctx.contabilidad_banco.FirstOrDefault(b => b.auto_banco == ficha.AutoBanco); // ctx.contabilidad_banco.Remove(entContBanco); //} var entContBanco = ctx.contabilidad_banco.FirstOrDefault(b => b.auto_banco == ficha.AutoBanco); if (entContBanco == null) { entContBanco = new contabilidad_banco() { idPlanCta = ficha.IdCtaContable.Value, idPlanCta_IGTF = ficha.IdCtaIGTF.Value, auto_banco = ficha.AutoBanco, }; ctx.contabilidad_banco.Add(entContBanco); ctx.SaveChanges(); } else { var entReglaIntPago = ctx.contabilidad_reglas_integracion_detalle.FirstOrDefault(w => w.idReglaIntegracion == 3 && w.referencia.Trim().ToUpper() == "BANCO" && w.idPlanCta == entContBanco.idPlanCta); if (entReglaIntPago != null) { ctx.contabilidad_reglas_integracion_detalle.Remove(entReglaIntPago); ctx.SaveChanges(); } var entReglaIntBanco = ctx.contabilidad_reglas_integracion_detalle.FirstOrDefault(w => w.idReglaIntegracion == 6 && w.referencia.Trim().ToUpper() == "BANCO MOV" && w.idPlanCta == entContBanco.idPlanCta); if (entReglaIntBanco != null) { ctx.contabilidad_reglas_integracion_detalle.Remove(entReglaIntBanco); ctx.SaveChanges(); } entContBanco.idPlanCta = null; if (ficha.IdCtaContable.HasValue) { entContBanco.idPlanCta = ficha.IdCtaContable.Value; } entContBanco.idPlanCta_IGTF = null; if (ficha.IdCtaIGTF.HasValue) { entContBanco.idPlanCta_IGTF = ficha.IdCtaIGTF.Value; } ctx.SaveChanges(); if (ficha.IdCtaContable.HasValue) { entContBanco.idPlanCta = ficha.IdCtaContable.Value; } if (ficha.IdCtaIGTF.HasValue) { entContBanco.idPlanCta_IGTF = ficha.IdCtaIGTF.Value; } ctx.SaveChanges(); } if (ficha.IdCtaContable.HasValue) { var reglaPago = new contabilidad_reglas_integracion_detalle() { idReglaIntegracion = 3, idPlanCta = ficha.IdCtaContable.Value, signo = -1, referencia = "BANCO", idSucursal = 0, }; ctx.contabilidad_reglas_integracion_detalle.Add(reglaPago); ctx.SaveChanges(); var reglaBanco = new contabilidad_reglas_integracion_detalle() { idReglaIntegracion = 6, idPlanCta = ficha.IdCtaContable.Value, signo = 1, referencia = "BANCO MOV", idSucursal = 0, }; ctx.contabilidad_reglas_integracion_detalle.Add(reglaBanco); ctx.SaveChanges(); } ctx.SaveChanges(); ts.Complete(); } } } catch (Exception e) { result.Mensaje = e.Message; result.Result = DTO.EnumResult.isError; } return(result); }