public new static IAgenteHipatiaList GetAgentes(EntidadInfo entidad) { IAgenteHipatiaList lista = new IAgenteHipatiaList(new List <IAgenteHipatia>()); if (entidad.Tipo == typeof(Cliente).Name) { ClienteList list = ClienteList.GetList(false); foreach (ClienteInfo obj in list) { if (entidad.Agentes.GetItemByProperty("Oid", obj.Oid) == null) { lista.Add(obj); } } } else if (entidad.Tipo == typeof(Charge).Name) { ChargeList list = ChargeList.GetList(false); foreach (ChargeInfo obj in list) { if (entidad.Agentes.GetItemByProperty("Oid", obj.Oid) == null) { lista.Add(obj); } } } else if (entidad.Tipo == typeof(OutputInvoice).Name) { OutputInvoiceList list = OutputInvoiceList.GetList(false); foreach (OutputInvoiceInfo obj in list) { if (entidad.Agentes.GetItemByProperty("Oid", obj.Oid) == null) { lista.Add(obj); } } } else { throw new iQException("No se ha encontrado el tipo de entidad " + entidad.Tipo); } return(lista); }
public virtual void ExportCharges() { Charges charges2 = null; try { _invoice_conditions.Orders.Clear(); _invoice_conditions.Orders.NewOrder("Vencimiento", System.ComponentModel.ListSortDirection.Ascending, typeof(Charge)); ChargeList cobros = ChargeList.GetList(_invoice_conditions, true); //Hacen falta todas porque un cobro puede estar asociado a una factura que no este en las condiciones del filtro _invoices = OutputInvoiceList.GetList(false); _clients = (_clients == null) ? ClienteList.GetList(false) : _clients; _expedients = ExpedienteList.GetList(false); foreach (ChargeInfo item in cobros) { if (item.EEstado == EEstado.Anulado) { continue; } LineaRegistro lr = _registry.LineaRegistros.NewItem(_registry, item); switch (item.ETipoCobro) { case ETipoCobro.Cliente: { BuildChargeAccountingEntry(item, lr); BuildFinalcialCashBookChargeAccountingEntry(item); } break; case ETipoCobro.REA: { BuildREAChargeAccountingEntry(item, lr); } break; } _accounting_entry++; } //Cambiamos el estado de las cobros contabilizados charges2 = Charges.GetList(_invoice_conditions, false); FinancialCashList efectos = FinancialCashList.GetList(false); foreach (Charge item in charges2) { if (item.EEstado == EEstado.Anulado) { continue; } if (item.EEstado != EEstado.Exportado) { if (item.EEstadoCobro == EEstado.Charged) { if (item.EMedioPago != EMedioPago.Cheque && item.EMedioPago != EMedioPago.Pagare) { item.EEstado = EEstado.Exportado; } else { FinancialCashInfo efecto = efectos.GetItemByCobro(item.Oid); if (efecto != null && efecto.EEstadoCobro == EEstado.Charged) { item.EEstado = EEstado.Exportado; } } } } } charges2.Save(); } catch (iQException ex) { _registry = null; throw ex; } catch (Exception ex) { _registry = null; throw ex; } finally { if (charges2 != null) { charges2.CloseSession(); } } }
public static void SendMailsFacturasPendientes() { try { OutputInvoiceList facturas = OutputInvoiceList.GetNoCobradasList(true); ClienteList clientes = ClienteList.GetList(false); SerieList series = SerieList.GetList(false); CompanyInfo empresa = CompanyInfo.Get(AppContext.ActiveSchema.Oid); SerieInfo serie; ClienteInfo cliente; Registro registro = Registro.New(ETipoRegistro.Email); registro.Nombre = "Envio automático de Facturas"; registro.Observaciones = "Envio automático de Facturas pendientes de pago"; foreach (OutputInvoiceInfo item in facturas) { if (item.Prevision.AddDays(ModulePrincipal.GetPeriodicidadEnvioFacturasPendientes()) > DateTime.Today) { continue; } cliente = clientes.GetItem(item.OidCliente); if (!cliente.EnviarFacturaPendiente) { continue; } serie = series.GetItem(item.OidSerie); FormatConfFacturaAlbaranReport conf = new FormatConfFacturaAlbaranReport(); conf.nota = (cliente.OidImpuesto == 1) ? Resources.Messages.NOTA_EXENTO_IGIC : string.Empty; conf.nota += Environment.NewLine + (item.Nota ? serie.Cabecera : ""); OutputInvoiceReportMng reportMng = new OutputInvoiceReportMng(AppContext.ActiveSchema, string.Empty, string.Empty); ReportClass report = reportMng.GetDetailReport(item, serie, cliente, null, conf); if (report != null) { LineaRegistro linea = registro.LineaRegistros.NewItem(registro, cliente); ExportOptions options = new ExportOptions(); DiskFileDestinationOptions diskFileDestinationOptions = new DiskFileDestinationOptions(); string fileName = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); fileName += "\\" + item.FileName; diskFileDestinationOptions.DiskFileName = fileName; options.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat; options.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile; options.ExportDestinationOptions = diskFileDestinationOptions; report.Export(options); System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); mail.To.Add(new MailAddress(cliente.Email, cliente.Nombre)); mail.From = new MailAddress(SettingsMng.Instance.GetSMTPMail(), empresa.Name); mail.Body = String.Format(Resources.Messages.FACTURA_EMAIL_ATTACHMENT_BODY, empresa.Name); mail.Subject = Resources.Messages.FACTURA_EMAIL_SUBJECT; mail.Attachments.Add(new Attachment(fileName)); try { Thread mailThread = new Thread(SendMailDelegate); mailThread.Start(mail); while (mailThread.IsAlive) { ; } linea.Observaciones = linea.Descripcion; linea.Descripcion = String.Format(Resources.Messages.FACTURA_EMAIL_OK, item.NFactura); } catch (Exception ex) { linea.Observaciones = linea.Descripcion; linea.Descripcion = String.Format(Resources.Messages.FACTURA_EMAIL_ERROR, item.NFactura); registro.Save(); throw new iQException(ex.Message + Environment.NewLine + Environment.NewLine + moleQule.Library.Resources.Errors.SMTP_SETTINGS); } finally { mail.Dispose(); try { File.Delete(fileName); } catch (Exception ex) { string a = ex.Message; } } } } registro.Save(); ModulePrincipal.SetFechaUltimoEnvioFacturasPendientes(DateTime.Now); AppContext.Principal.SaveSettings(); } catch { } }
public virtual void ExportOutputInvoices() { OutputInvoices invoices = null; try { _invoice_conditions.Orders.Clear(); _invoice_conditions.Orders.NewOrder("Fecha", System.ComponentModel.ListSortDirection.Ascending, typeof(OutputInvoice)); _invoices = OutputInvoiceList.GetList(_invoice_conditions, true); _clients = (_clients == null) ? ClienteList.GetList(false) : _clients; foreach (OutputInvoiceInfo item in _invoices) { if (item.EEstado == EEstado.Anulado) { continue; } LineaRegistro lr = _registry.LineaRegistros.NewItem(_registry, item); BuildOutputInvoiceAccountingEntry(item, lr); BuildTaxBookRepercutidoAccountingEntry(item); _accounting_entry++; } //Cambiamos el estado de las facturas contabilizadas invoices = OutputInvoices.GetList(_invoice_conditions, false); foreach (OutputInvoice item in invoices) { if (item.EEstado == EEstado.Anulado) { continue; } if (item.EEstado != EEstado.Exportado) { item.EEstado = EEstado.Exportado; } } invoices.Save(); } catch (iQException ex) { _registry = null; throw ex; } catch (Exception ex) { _registry = null; throw ex; } finally { if (invoices != null) { invoices.CloseSession(); } } }