public int Add(int FACTURAId, System.DateTime FECHA_EMISION, int NUMERO_NOTA_CREDITO, bool CORRECCION_TOTAL_PARCIAL)
        {
            Init();
            try
            {
                 using (LQCEEntities context = new LQCEEntities())
                {
                    RepositorioFACTURA _repositorioFACTURA = new RepositorioFACTURA(context);
                    FACTURA _objFACTURA = _repositorioFACTURA.GetById(FACTURAId);
                    if(Equals(_objFACTURA,null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado FACTURA con Id =",FACTURAId.ToString()));
                    }

                    NOTA_CREDITO _NOTA_CREDITO = new NOTA_CREDITO();

                    //properties

                    _NOTA_CREDITO.FECHA_EMISION = FECHA_EMISION;
                    _NOTA_CREDITO.NUMERO_NOTA_CREDITO = NUMERO_NOTA_CREDITO;
                    _NOTA_CREDITO.CORRECCION_TOTAL_PARCIAL = CORRECCION_TOTAL_PARCIAL;
                    _NOTA_CREDITO.ACTIVO = true;

                    //parents

                    _NOTA_CREDITO.FACTURA = _objFACTURA;

                    context.AddObject("NOTA_CREDITO",_NOTA_CREDITO);
                    context.SaveChanges();

                    return _NOTA_CREDITO.ID;
                }
            }
            catch(Exception ex)
            {
                 ISException.RegisterExcepcion(ex);
                Error = ex.Message;
                throw ex;
            }
        }
        public void EmitirNotaCredito(int IdFactura, int NumeroNotaCredito, bool CorreccionTotal)
        {
            Init();
            try
            {
                using (LQCEEntities context = new LQCEEntities())
                {
                    RepositorioFACTURA _RepositorioFACTURA = new RepositorioFACTURA(context);

                    FACTURA _FACTURA = _RepositorioFACTURA.GetByIdWithReferences(IdFactura);
                    if (_FACTURA == null)
                        throw new Exception("No se encuentra informacion de la factura");

                    if (!_FACTURA.NUMERO_FACTURA.HasValue)
                        throw new Exception("La factura no ha sido numerada");

                    if (_FACTURA.PAGADA.HasValue && _FACTURA.PAGADA.Value == true)
                        throw new Exception("La factura ya ha sido pagada");

                    NOTA_CREDITO _NOTA_CREDITO = new NOTA_CREDITO();
                    _NOTA_CREDITO.FACTURA = _FACTURA;
                    _NOTA_CREDITO.FECHA_EMISION = DateTime.Now;
                    _NOTA_CREDITO.NUMERO_NOTA_CREDITO = NumeroNotaCredito;
                    _NOTA_CREDITO.CORRECCION_TOTAL_PARCIAL = CorreccionTotal;
                    _NOTA_CREDITO.ACTIVO = true;
                    context.AddToNOTA_CREDITO(_NOTA_CREDITO);

                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                ISException.RegisterExcepcion(ex);
                Error = ex.Message;
                throw ex;
            }
        }