public void AnularFacturas(List<int> LISTA_ID_FACTURA) { Init(); //ListaDetalleFactura = new List<DTO_REPORTE_DETALLEFACTURA_PRESTACION>(); try { using (LQCEEntities context = new LQCEEntities()) { RepositorioFACTURA _RepositorioFACTURA = new RepositorioFACTURA(context); foreach (int ID_FACTURA in LISTA_ID_FACTURA) { FACTURA _FACTURA = _RepositorioFACTURA.GetByIdWithReferences(ID_FACTURA); if (_FACTURA == null) throw new Exception("No se encuentra informacion de la factura"); if (_FACTURA.NUMERO_FACTURA.HasValue) throw new Exception("La factura ya ha sido numerada"); if (_FACTURA.NOTA_CREDITO.Any(nc => nc.ACTIVO)) throw new Exception("La factura tiene notas de créditos asociadas"); _FACTURA.ACTIVO = false; foreach (FACTURA_DETALLE _FACTURA_DETALLE in _FACTURA.FACTURA_DETALLE.Where(fd => fd.ACTIVO)) { _FACTURA_DETALLE.ACTIVO = false; context.ApplyPropertyChanges("FACTURA_DETALLE", _FACTURA_DETALLE); } context.ApplyPropertyChanges("FACTURA", _FACTURA); context.SaveChanges(); } } } catch (Exception ex) { ISException.RegisterExcepcion(ex); Error = ex.Message; throw ex; } }
public FACTURA GetByIdWithReferences(int ID) { Init(); try { using (LQCEEntities context = new LQCEEntities()) { RepositorioFACTURA repositorio = new RepositorioFACTURA(context); return repositorio.GetByIdWithReferences(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; } }
protected List<DTO_REPORTE_FACTURA> GetReporteFacturaByID_FACTURA(int IdFactura) { 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 información de la factura"); DTO_REPORTE_FACTURA _DTO_REPORTE_FACTURA = new DTO_REPORTE_FACTURA(); _DTO_REPORTE_FACTURA.NOMBRE_REPORTE_FACTURA = _FACTURA.TIPO_FACTURA.NOMBRE_REPORTE_FACTURA; _DTO_REPORTE_FACTURA.NOMBRE_REPORTE_FACTURA_INDIVIDUAL = _FACTURA.TIPO_FACTURA.NOMBRE_REPORTE_FACTURA_INDIVIDUAL; _DTO_REPORTE_FACTURA.DIA = _FACTURA.FACTURACION.FECHA_FACTURACION.Day; _DTO_REPORTE_FACTURA.MES = _FACTURA.FACTURACION.FECHA_FACTURACION.ToString("MMMM"); _DTO_REPORTE_FACTURA.AÑO = _FACTURA.FACTURACION.FECHA_FACTURACION.Year; _DTO_REPORTE_FACTURA.NOMBRE_CLIENTE = _FACTURA.NOMBRE_CLIENTE; _DTO_REPORTE_FACTURA.RUT_CLIENTE = _FACTURA.RUT_CLIENTE; _DTO_REPORTE_FACTURA.DIRECCION = _FACTURA.DIRECCION; _DTO_REPORTE_FACTURA.COMUNA = _FACTURA.NOMBRE_COMUNA; _DTO_REPORTE_FACTURA.FONO = _FACTURA.FONO; _DTO_REPORTE_FACTURA.GIRO = _FACTURA.GIRO; _DTO_REPORTE_FACTURA.DETALLE = _FACTURA.DETALLE; _DTO_REPORTE_FACTURA.NETO = _FACTURA.NETO; _DTO_REPORTE_FACTURA.IVA = _FACTURA.IVA; _DTO_REPORTE_FACTURA.TOTAL = _FACTURA.TOTAL; _DTO_REPORTE_FACTURA.NUMERO_FACTURA = _FACTURA.NUMERO_FACTURA; _DTO_REPORTE_FACTURA.NOMBRE_TIPO_FACTURA = _FACTURA.TIPO_FACTURA.NOMBRE_FACTURA; List<DTO_REPORTE_FACTURA> lista = new List<DTO_REPORTE_FACTURA>(); lista.Add(_DTO_REPORTE_FACTURA); return lista; } } catch (Exception ex) { ISException.RegisterExcepcion(ex); Error = ex.Message; throw ex; } }