public ReportClass GetDetailReport(OutputDeliveryInfo item, FormatConfFacturaAlbaranReport conf)
        {
            if (item == null)
            {
                return(null);
            }

            List <OutputDeliveryLinePrint> conceptos = new List <OutputDeliveryLinePrint>();
            List <OutputDeliveryPrint>     pList     = new List <OutputDeliveryPrint>();

            foreach (OutputDeliveryLineInfo cfi in item.Conceptos)
            {
                conceptos.Add(OutputDeliveryLinePrint.New(cfi));
            }

            //Si no existen conceptos, no tiene sentido un informe detallado. Además, falla en Crystal Reports
            if (conceptos.Count <= 0)
            {
                return(null);
            }

            pList.Add(item.GetPrintObject());

            ReportClass doc = null;

            try
            {
                doc = GetReportFromName("Delivery", "OutputDeliveryRpt");
            }
            catch
            {
                doc = new OutputDeliveryRpt();
            }

            doc.SetDataSource(pList);
            doc.Subreports["LinesClientCopy"].SetDataSource(conceptos);
            //doc.Subreports["LinesCompanyCopy"].SetDataSource(conceptos);

            CompanyInfo empresa = CompanyInfo.Get(Schema.Oid);

            doc.SetParameterValue("nombreEmpresa", empresa.Name);
            doc.SetParameterValue("dirEmpresa", empresa.Direccion);
            doc.SetParameterValue("CIFEmpresa", empresa.VatNumber);
            doc.SetParameterValue("nota", conf.nota);
            doc.SetParameterValue("CPEmpresa", empresa.CodPostal);
            doc.SetParameterValue("municipioEmpresa", empresa.Municipio);
            doc.SetParameterValue("TlfEmpresa", empresa.Telefonos);
            doc.SetParameterValue("WebEmpresa", empresa.Url);

            return(doc);
        }
        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 { }
        }
Exemplo n.º 3
0
        public ReportClass GetDetailReport(OutputInvoiceInfo item,
                                           SerieInfo serie,
                                           ClienteInfo cliente,
                                           TransporterInfo transporter,
                                           FormatConfFacturaAlbaranReport conf)
        {
            if (item == null)
            {
                return(null);
            }

            List <OutputInvoiceLinePrint> conceptos = new List <OutputInvoiceLinePrint>();
            List <OutputInvoicePrint>     pList     = new List <OutputInvoicePrint>();

            foreach (OutputInvoiceLineInfo cfi in item.ConceptoFacturas)
            {
                conceptos.Add(cfi.GetPrintObject());
            }

            //Si no existen conceptos, no tiene sentido un informe detallado. Además, falla en Crystal Reports
            if (conceptos.Count <= 0)
            {
                return(null);
            }

            pList.Add(OutputInvoicePrint.New(item, cliente, transporter, serie));

            ProductList productos = ProductList.GetList(false);

            foreach (OutputInvoiceLinePrint cfp in conceptos)
            {
                if (cfp.OidProducto == 0)
                {
                    continue;
                }

                ProductInfo prod = productos.GetItem(cfp.OidProducto);
                if (prod != null)
                {
                    continue;
                }

                if (prod.AyudaKilo > 0)
                {
                    cfp.Concepto += " *";
                }
            }

            List <ImpuestoResumen> impuestos = new List <ImpuestoResumen>();

            foreach (DictionaryEntry impuesto in item.GetImpuestos())
            {
                impuestos.Add((ImpuestoResumen)impuesto.Value);
            }

            ReportClass doc = null;

            try
            {
                doc = GetReportFromName("Invoice", "OutputInvoiceRpt");
            }
            catch
            {
                doc = new OutputInvoiceRpt();
            }

            doc.SetDataSource(pList);
            doc.Subreports["ConceptosRpt"].SetDataSource(conceptos);

            if (doc.Subreports["ImpuestoResumenRpt"] != null)
            {
                doc.Subreports["ImpuestoResumenRpt"].SetDataSource(impuestos);
            }

            Library.Common.CompanyInfo empresa = Library.Common.CompanyInfo.Get(Schema.Oid, false);
            doc.SetParameterValue("nombreEmpresa", empresa.Name);
            doc.SetParameterValue("dirEmpresa", empresa.Direccion);
            doc.SetParameterValue("dir2Empresa", empresa.CodPostal + ". " + empresa.Municipio + ". " + empresa.Provincia);
            doc.SetParameterValue("CIFEmpresa", empresa.VatNumber);
            doc.SetParameterValue("TlfEmpresa", empresa.Telefonos);
            doc.SetParameterValue("FaxEmpresa", empresa.Fax);
            doc.SetParameterValue("WebEmpresa", empresa.Url);
            doc.SetParameterValue("nota", conf.nota);
            doc.SetParameterValue("ACuenta", (item.CobroFacturas != null) ? item.CobroFacturas.GetTotal() : 0);
            doc.SetParameterValue("CPEmpresa", empresa.CodPostal);
            doc.SetParameterValue("municipioEmpresa", empresa.Municipio);

            return(doc);
        }
        public ReportClass GetAlbaran(OutputDeliveryInfo item, FormatConfFacturaAlbaranReport conf)
        {
            if (item == null)
            {
                return(null);
            }

            List <OutputDeliveryLinePrint> conceptos = new List <OutputDeliveryLinePrint>();
            List <OutputDeliveryPrint>     pList     = new List <OutputDeliveryPrint>();

            foreach (OutputDeliveryLineInfo cfi in item.Conceptos)
            {
                conceptos.Add(OutputDeliveryLinePrint.New(cfi));
            }

            //Si no existen conceptos, no tiene sentido un informe detallado. Además, falla en Crystal Reports
            if (conceptos.Count <= 0)
            {
                return(null);
            }

            pList.Add(item.GetPrintObject());

            ProductList productos = ProductList.GetList(false);

            foreach (OutputDeliveryLinePrint cfp in conceptos)
            {
                if (cfp.OidProducto == 0)
                {
                    continue;
                }
                ProductInfo prod = productos.GetItem(cfp.OidProducto);
                if (prod != null)
                {
                    if (prod.AyudaKilo > 0)
                    {
                        cfp.Concepto += " *";
                    }
                }
            }

            ReportClass doc = null;

            try
            {
                doc = GetReportFromName("Delivery", "OutputDeliveryRpt");
            }
            catch
            {
                doc = new OutputDeliveryRpt();
            }

            doc.Subreports["ConceptosRpt"].SetDataSource(conceptos);

            doc.SetDataSource(pList);
            CompanyInfo empresa = CompanyInfo.Get(Schema.Oid);

            doc.SetParameterValue("nombreEmpresa", empresa.Name);
            doc.SetParameterValue("dirEmpresa", empresa.Direccion);
            doc.SetParameterValue("CIFEmpresa", empresa.VatNumber);
            doc.SetParameterValue("TlfEmpresa", empresa.Telefonos);
            doc.SetParameterValue("nota", (conf.nota != null) ? conf.nota : string.Empty);

            return(doc);
        }
Exemplo n.º 5
0
        /*private static void FormatReport(ProformaRpt rpt, string logo)
         * {
         * /*string path = Images.GetRootPath() + "\\" + Resources.Paths.LOGO_EMPRESAS + logo;
         *
         * if (File.Exists(path))
         * {
         * Image image = Image.FromFile(path);
         * int width = rpt.Section1.ReportObjects["Logo"].Width;
         * int height = rpt.Section1.ReportObjects["Logo"].Height;
         *
         * rpt.Section1.ReportObjects["Logo"].Width = 15 * image.Width;
         * rpt.Section1.ReportObjects["Logo"].Height = 15 * image.Height;
         * rpt.Section1.ReportObjects["Logo"].Left += (width - 15 * image.Width) / 2;
         * rpt.Section1.ReportObjects["Logo"].Top += (height - 15 * image.Height) / 2;
         * }
         * }*/

        #endregion

        #region Business Methods

        public ReportClass GetDetailReport(BudgetInfo item, FormatConfFacturaAlbaranReport conf)
        {
            if (item == null)
            {
                return(null);
            }

            List <BudgetPrint> pList = new List <BudgetPrint>();

            pList.Add(item.GetPrintObject());

            List <BudgetLinePrint> pConceptos = new List <BudgetLinePrint>();

            //Si no existen conceptos, no tiene sentido un informe detallado. Además, falla en Crystal Reports
            if (item.Conceptos.Count <= 0)
            {
                return(null);
            }

            foreach (BudgetLineInfo concepto in item.Conceptos)
            {
                pConceptos.Add(BudgetLinePrint.New(concepto));
            }

            ProductList productos = ProductList.GetList(false);

            foreach (BudgetLinePrint cfp in pConceptos)
            {
                if (cfp.OidProducto == 0)
                {
                    continue;
                }
                ProductInfo prod = productos.GetItem(cfp.OidProducto);
                if (prod != null)
                {
                    if (prod.AyudaKilo > 0)
                    {
                        cfp.Concepto += " *";
                    }
                }
            }

            ReportClass doc = null;

            try
            {
                doc = GetReportFromName("Budget", "BudgetRpt");
            }
            catch
            {
                doc = new BudgetRpt();
            }

            doc.SetDataSource(pList);
            doc.Subreports["ConceptosRpt"].SetDataSource(pConceptos);

            CompanyInfo empresa = CompanyInfo.Get(Schema.Oid, false);

            doc.SetParameterValue("nombreEmpresa", empresa.Name);
            doc.SetParameterValue("dirEmpresa", empresa.Direccion);
            doc.SetParameterValue("CIFEmpresa", empresa.VatNumber);
            doc.SetParameterValue("TlfEmpresa", empresa.Telefonos);
            doc.SetParameterValue("CPEmpresa", empresa.CodPostal);
            doc.SetParameterValue("municipioEmpresa", empresa.Municipio);
            doc.SetParameterValue("nota", conf.nota);
            doc.SetParameterValue("WebEmpresa", empresa.Url);

            return(doc);
        }