Example #1
0
 public bool anularDB(cxc_cobro_Info info)
 {
     try
     {
         return(odata.anularDB(info));
     }
     catch (Exception)
     {
         throw;
     }
 }
        public bool anularDB(fa_notaCreDeb_Info info)
        {
            try
            {
                #region Variables
                ct_cbtecble_Data odata_ct   = new ct_cbtecble_Data();
                cxc_cobro_Data   odata_cobr = new cxc_cobro_Data();
                #endregion

                using (Entities_facturacion db_f = new Entities_facturacion())
                {
                    #region Nota de debito credito

                    #region Cabecera
                    var entity = db_f.fa_notaCreDeb.Where(q => q.IdEmpresa == info.IdEmpresa && q.IdSucursal == info.IdSucursal && q.IdBodega == info.IdBodega && q.IdNota == info.IdNota).FirstOrDefault();
                    if (entity == null)
                    {
                        return(false);
                    }

                    entity.Estado          = "I";
                    entity.IdUsuarioUltAnu = info.IdUsuarioUltAnu;
                    entity.Fecha_UltAnu    = DateTime.Now;
                    entity.MotiAnula       = info.MotiAnula;
                    #endregion

                    var lst_cruce = db_f.fa_notaCreDeb_x_fa_factura_NotaDeb.Where(q => q.IdEmpresa_nt == info.IdEmpresa && q.IdSucursal_nt == info.IdSucursal && q.IdBodega_nt == info.IdBodega && q.IdNota_nt == info.IdNota).ToList();
                    db_f.fa_notaCreDeb_x_fa_factura_NotaDeb.RemoveRange(lst_cruce);
                    #endregion

                    #region Contabilidad
                    var rel_conta = db_f.fa_notaCreDeb_x_ct_cbtecble.Where(q => q.no_IdEmpresa == info.IdEmpresa && q.no_IdSucursal == info.IdSucursal && q.no_IdBodega == info.IdBodega && q.no_IdNota == info.IdNota).FirstOrDefault();
                    if (rel_conta != null)
                    {
                        if (!odata_ct.anularDB(new ct_cbtecble_Info {
                            IdEmpresa = rel_conta.ct_IdEmpresa, IdTipoCbte = rel_conta.ct_IdTipoCbte, IdCbteCble = rel_conta.ct_IdCbteCble, IdUsuarioAnu = info.IdUsuarioUltAnu
                        }))
                        {
                            entity.Estado          = "A";
                            entity.IdUsuarioUltAnu = null;
                            entity.Fecha_UltAnu    = null;
                            entity.MotiAnula       = null;
                        }
                    }


                    #endregion

                    #region Cobranza

                    var rel_cobr = db_f.fa_notaCreDeb_x_cxc_cobro.Where(q => q.IdEmpresa_nt == info.IdEmpresa && q.IdSucursal_nt == info.IdSucursal && q.IdBodega_nt == info.IdBodega && q.IdNota_nt == info.IdNota).FirstOrDefault();
                    if (rel_cobr != null)
                    {
                        if (!odata_cobr.anularDB(new cxc_cobro_Info {
                            IdEmpresa = rel_cobr.IdEmpresa_cbr, IdSucursal = rel_cobr.IdSucursal_cbr, IdCobro = rel_cobr.IdCobro_cbr, IdUsuarioUltAnu = info.IdUsuarioUltAnu
                        }))
                        {
                            entity.Estado          = "A";
                            entity.IdUsuarioUltAnu = null;
                            entity.Fecha_UltAnu    = null;
                            entity.MotiAnula       = null;
                        }
                    }
                    #endregion

                    db_f.SaveChanges();
                }

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }