Example #1
0
        /// <summary>
        /// Genera el PDF para la descarga de la factura
        /// </summary>
        public string DownloadInvoice(int id)
        {
            AddressManager    addressManager    = new AddressManager();
            UserManager       userManager       = new UserManager();
            CreditNoteManager creditNoteManager = new CreditNoteManager();
            CreditCardManager creditCardmanager = new CreditCardManager();
            InvoiceItemMapper invoiceItemMapper = new InvoiceItemMapper();
            InvoiceMapper     invoiceMapper     = new InvoiceMapper();

            Invoice invoice = invoiceMapper.Get(id);

            invoice.BillingAddress = addressManager.Get(invoice.BillingAddress.Id);
            invoice.User           = userManager.Get(invoice.User.Id);
            invoice.InvoiceItems   = invoiceItemMapper.Get(invoice);

            foreach (InvoiceItem invoiceItem in invoice.InvoiceItems)
            {
                invoiceItem.Resource = new MapManager().Get(invoiceItem.Resource.Id);
            }

            invoice.CreditNotes = creditNoteManager.GetUsedByInvoice(invoice);
            invoice.CreditCard  = creditCardmanager.Get(invoice);

            if (invoice.CreditCard != null)
            {
                invoice.CreditCard.Field1 = SecurityHelper.RDesencrypt(invoice.CreditCard.Field1);
                invoice.CreditCard.Field4 = SecurityHelper.RDesencrypt(invoice.CreditCard.Field4);
            }

            string fullPath = PDFHelper.CreateInvoice(invoice);

            if (String.IsNullOrEmpty(fullPath))
            {
                string errorDescription = "Se ha producido un error al generar el archivo de la factura.";
                log.AddLogCritical("DownloadInvoice", errorDescription, this);
                AddError(new ResultBE(ResultBE.Type.FAIL, errorDescription));
            }

            return(fullPath);
        }