Пример #1
0
        void ucGe_Menu_event_btnAnular_Click(object sender, EventArgs e)
        {
            try
            {
                ct_Cbtecble_tipo_Bus tipo_bus = new ct_Cbtecble_tipo_Bus();
                if (!tipo_bus.Get_Es_Interno(param.IdEmpresa, InfoCbteCble.IdTipoCbte, ref MensajeError))
                {
                    MessageBox.Show("Este comprobante no se puede eliminar, debido que es generado de otro modulo");
                    return;
                }
                if (InfoCbteCble.Estado != "A")
                {
                    MessageBox.Show("No se pudo anular el Comprobante Contable: " + InfoCbteCble.IdCbteCble.ToString() + " debido a que ya se encuentra anulado", "Anulación de Cbte", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (MessageBox.Show("¿Está seguro que desea anular dicho comprobante contable?", "Anulación de Cbte", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    if (BusPeriodo.Get_Periodo_Esta_Cerrado(InfoCbteCble.IdEmpresa, InfoCbteCble.cb_Fecha, ref MensajeError) == true)
                    {
                        MessageBox.Show("No se puede anular el Comprobante Contable porque el período se encuentra cerrado", "Anulación de Cbte", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }


                    FrmGe_MotivoAnulacion frmAnul = new FrmGe_MotivoAnulacion();
                    frmAnul.ShowDialog();
                    InfoCbteCble.IdUsuarioAnu = param.IdUsuario;
                    InfoCbteCble.cb_FechaAnu  = param.Fecha_Transac;
                    InfoCbteCble.cb_MotivoAnu = frmAnul.motivoAnulacion;


                    ct_Cbtecble_tipo_Info tipoComp = List_Tipo_Comprobante.First(q => q.IdTipoCbte == (Convert.ToInt32(cmb_tipocomprobante.EditValue)));
                    decimal IdCbteCntablerev       = 0;
                    string  msj = "";

                    if (BusCbteCble.ReversoCbteCble(param.IdEmpresa, Convert.ToDecimal(lbl_no_comprobante.Text), (int)cmb_tipocomprobante.EditValue,
                                                    Convert.ToInt16(tipoComp.IdTipoCbte_Anul), ref IdCbteCntablerev, ref msj, param.IdUsuario, Cl_Motivo.motivo_anulacion))
                    {
                        // se procede actualizar los campos
                        string smensaje = string.Format(Core.Erp.Recursos.Properties.Resources.msgDespues_Anular, "Comprobante Contable: ", InfoCbteCble.IdCbteCble.ToString());
                        MessageBox.Show(smensaje, param.Nombre_sistema, MessageBoxButtons.OK, MessageBoxIcon.Information);

                        set_Info_en_Controles();
                    }
                    else
                    {
                        MessageBox.Show("No se pudo anular el Comprobante Contable: " + InfoCbteCble.IdCbteCble.ToString(), "Anulación de Cbte", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            catch (Exception ex)
            {
                Log_Error_bus.Log_Error(ex.ToString());
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public Boolean AnularDevolucion(int idEmpresa, int idSucursal, int idBodega, decimal idDevolucion, DateTime Fecha_Anulacion, string motivo, ref string mensageError)
        {
            try
            {
                in_movi_inve_Bus    MoviInve_Bus = new in_movi_inve_Bus();
                in_movi_inve_Info   InfoMoviAnu  = new in_movi_inve_Info();
                fa_devol_venta_Bus  DevVtaBus    = new fa_devol_venta_Bus();
                fa_devol_venta_Info DevVta_info  = new fa_devol_venta_Info();
                fa_notaCredDeb_Bus  BusBNotaDB   = new fa_notaCredDeb_Bus();
                fa_notaCreDeb_Info  InfoNotaCre  = new fa_notaCreDeb_Info();
                Boolean             resAnuMoviInv;
                Boolean             resAnuDevVta;
                string MensajeError = "";



                Fecha_Anulacion = Convert.ToDateTime(Fecha_Anulacion.ToShortDateString());

                #region "validaciones"
                ct_Periodo_Bus Perbus = new ct_Periodo_Bus();


                if (Perbus.Get_Periodo_Esta_Cerrado(idEmpresa, Fecha_Anulacion, ref MensajeError))
                {
                    mensageError = "no se puede anular por q el periodo esta cerrardo para esta fecha de anulacion";
                    return(false);
                }

                #endregion


                DevVta_info = DevVtaBus.Get_Info_devol_vent(idEmpresa, idSucursal, idBodega, idDevolucion, ref mensageError);

                ///////// optengo el movimiento de inventario q se genero por la devolcuion en vta
                InfoMoviAnu = MoviInve_Bus.Get_Info_Movi_inven
                                  (DevVta_info.mvInv_IdEmpresa, DevVta_info.mvInv_IdSucursal, DevVta_info.mvInv_IdBodega, DevVta_info.mvInv_IdMovi_inven_tipo, DevVta_info.mvInv_IdNumMovi);
                ///////////////

                InfoMoviAnu.MotivoAnulacion = motivo;
                InfoMoviAnu.IdusuarioUltAnu = param.IdUsuario;

                //////////// anula el movimiento de inventario /////////////////////////
                resAnuMoviInv = MoviInve_Bus.AnularDB(InfoMoviAnu, Fecha_Anulacion, ref mensageError);
                //////////// anula el movimiento de inventario /////////////////////////

                //////////// anula el la cabecera de dev vat
                resAnuDevVta = data.AnularDB(idEmpresa, idSucursal, idBodega, idDevolucion, motivo);
                //////////// anula el la cabecera de dev vat

                //////////// anula la nota de credito
                InfoNotaCre                 = BusBNotaDB.Get_Info_notaCreDeb_x_ND(idEmpresa, idSucursal, idBodega, DevVta_info.IdNota);
                InfoNotaCre.MotiAnula       = motivo;
                InfoNotaCre.IdUsuarioUltAnu = param.IdUsuario;
                InfoNotaCre.Fecha_UltAnu    = Fecha_Anulacion;
                BusBNotaDB.AnularDB(InfoNotaCre, ref mensageError);
                //////////// anula la nota de credito

                ///modifica la devolucion

                ///

                return(resAnuMoviInv && resAnuDevVta);
            }
            catch (Exception ex)
            {
                Core.Erp.Info.Log_Exception.LoggingManager.Logger.Log(Core.Erp.Info.Log_Exception.LoggingCategory.Error, ex.Message);
                throw new Core.Erp.Info.Log_Exception.DalException(string.Format("", "AnularDevolucion", ex.Message), ex)
                      {
                          EntityType = typeof(fa_devol_venta_Bus)
                      };
            }
        }