Ejemplo n.º 1
0
        public ActionResult Download(int?id)
        {
            if (id.HasValue)
            {
                var quote               = _unitOfWork.Quotes.SingleOrDefault(s => s.Id == id);
                var customer            = _unitOfWork.Customers.SingleOrDefault(s => s.Id == quote.CustomerId);
                var stockItemQuantities = _unitOfWork.StockItemQuantities.GetStockItemsForQuote(quote.Id);

                InvoiceService.Business business = new InvoiceService.Business()
                {
                    LogoRootPath        = HttpContext.Server.MapPath("~//Content//Assets//Images//abstergo.gif"),
                    CompanyName         = "Abstergo (Pty) Ltd",
                    EmailAddress        = "*****@*****.**",
                    WebsiteAddress      = "www.abstergo.co.za",
                    PhoneNumber         = "031 100 8096",
                    PhysicalAddress     = "16 Rosedale Place, Kloof",
                    BankAccountNumber   = "62746768235",
                    BankBranchCode      = "250 655",
                    SwiftCode           = "FIRNZAJJXXX",
                    BankReferenceNumber = "#1561607274945",
                };

                InvoiceService.Client client = new Client(
                    customer.Name,
                    customer.Surname,
                    customer.CellNumber,
                    customer.Email,
                    customer.Address);

                List <InvoiceService.InvoiceItem> invoiceItems = new List <InvoiceItem>();

                foreach (var item in stockItemQuantities)
                {
                    var inv = new InvoiceItem()
                    {
                        Id       = item.StockItemId,
                        Name     = item.StockItem.Name,
                        Price    = item.StockItem.SellingPrice,
                        Quantity = item.Quantity
                    };
                    invoiceItems.Add(inv);
                }

                string docname;

                if (quote.Approve == true)
                {
                    docname = "Invoice";
                }
                else
                {
                    docname = "Quotation";
                }

                InvoiceService.Invoice invoice = new InvoiceService.Invoice()
                {
                    Client       = client,
                    Business     = business,
                    InvoiceItems = invoiceItems,
                    //
                    Currency = "R",


                    Title         = docname,
                    InvoiceNumber = "1561607274945",
                    Discount      = 0,
                    Status        = "Due",
                    Notes         = "Thank you for your business.",
                    Terms         = "Sales Invoice generated by Abstergo (Pty) Ltd. Visit our website at www.abstergo.net for more information.",
                    Date          = DateTime.Now,
                };

                InvoiceService.Generate invoiceGeneration = new Generate();

                byte[] pdfBytes = invoiceGeneration.GetInvoice(invoice);
                return(File(pdfBytes, "application/pdf",
                            fileDownloadName: DateTime.Now.ToShortDateString()
                            + "_Invoice_"
                            + invoice.Business.BankReferenceNumber + ".pdf"));
            }
            else
            {
                return(RedirectToAction("Index", "Dashboard"));
            }
        }
Ejemplo n.º 2
0
        public void Download()
        {
            InvoiceService.Business business = new InvoiceService.Business()
            {
                LogoRootPath        = "~//Content//Assets//Images//merge.png",
                CompanyName         = "Merge Group (Pty) Ltd",
                EmailAddress        = "*****@*****.**",
                WebsiteAddress      = "www.mergemedia.co.za",
                PhoneNumber         = "031 100 8096",
                PhysicalAddress     = "16 Rosedale Place, Kloof",
                BankAccountNumber   = "62746768235",
                BankBranchCode      = "250 655",
                SwiftCode           = "FIRNZAJJXXX",
                BankReferenceNumber = "#1561607274945",
            };
            //
            InvoiceService.Client client = new Client(
                "Roag (Mauritius)",
                "Bob",
                "0861007624",
                "*****@*****.**",
                "12 Cope Road");

            List <InvoiceService.InvoiceItem> invoiceItems = new List <InvoiceItem>()
            {
                new InvoiceItem()
                {
                    Id       = 1,
                    Name     = "IT and development support",
                    Price    = 5000,
                    Quantity = 1
                }
            };

            InvoiceService.Invoice invoice = new InvoiceService.Invoice()
            {
                Client       = client,
                Business     = business,
                InvoiceItems = invoiceItems,
                //
                Currency      = "R",
                Title         = "Invoice",
                InvoiceNumber = "1561607274945",
                Discount      = 0,
                Status        = "Due",
                Notes         = "Thank you for your business.",
                Terms         = "Sales Invoice generated by Merge Group (Pty) Ltd. Visit our website at www.Mergegroup.net for more information.",
                Date          = DateTime.Now,
            };

            Generate generate = new Generate();

            byte[] pdfBytes = generate.GetInvoice(invoice);


            bool doesContainValues = true;
            bool testContainValues = false;

            if (pdfBytes == null)
            {
                testContainValues = true;
            }


            Assert.AreEqual(doesContainValues, testContainValues);
        }