Exemple #1
0
        public HttpResponseMessage CreateInvoicePDF(string orderkey)
        {
            var viewmodel = new InvoiceViewModel();
            //   string orderKey = "33215b82-91a6-11e9-b6c9-3f0945f4a3b5";
            DeliveryOrderDL orderDl = new DeliveryOrderDL();
            InvoiceDL       dl      = new InvoiceDL();
            var             orderBO = orderDl.GetDeliveryOrder(orderkey);

            viewmodel.Order = orderBO;
            var orderdetailBO = orderDl.GetOrderDetailsByKey(orderkey);

            if (orderdetailBO != null && orderdetailBO.Count > 0)
            {
                var orderdtlList = new List <ThinOrderDetailViewModel>();
                orderdetailBO.ForEach(d =>
                {
                    orderdtlList.Add(new ThinOrderDetailViewModel()
                    {
                        Chassis        = d.Chassis,
                        ContainerNo    = d.ContainerNo,
                        OrderDetailKey = d.OrderDetailKey,
                        InvoiceHeader  = d.OrderDetailKey != null ? dl.GetInvoicebyOrderDetailKey(Convert.ToString(d.OrderDetailKey)) : null,
                        InvoiceDetail  = d.OrderDetailKey != null ? dl.GetInvoiceDetail(Convert.ToString(d.OrderDetailKey)) : null,
                    });
                });
                viewmodel.OrderDtl = orderdtlList;
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Order not found", Configuration.Formatters.JsonFormatter));
            }
            var stringified = new InvoiceViewController().RenderRazorViewToString("~/Views/InvoiceView/Index.cshtml", viewmodel);
            var pdf         = IronPdf.HtmlToPdf.StaticRenderHtmlAsPdf(stringified);
            var basepath    = HttpContext.Current.Server.MapPath("~/App_Data/Files/");
            var doccreated  = pdf.SaveAs(Path.Combine(basepath, $"{viewmodel.Order.OrderNo}.pdf"));

            if (doccreated.PageCount > 0)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, "Invoice generated", Configuration.Formatters.JsonFormatter));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Error occurred while creating Invoice", Configuration.Formatters.JsonFormatter));
            }
        }
Exemple #2
0
        public HttpResponseMessage GetbyOrderDetailKey([FromBody] string orderdetailkey)
        {
            var invoiceHeader = dl.GetInvoicebyOrderDetailKey(orderdetailkey);

            return(Request.CreateResponse(HttpStatusCode.OK, invoiceHeader, Configuration.Formatters.JsonFormatter));
        }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="custname"></param>
        /// <returns></returns>
        //[HttpPost]
        //[Route("DownloadInvoice_1")]
        //[SwaggerOperation("DownloadInvoice_1")]
        private HttpResponseMessage DownloadInvoice_1(string orderkey)
        {
            // var invoicetotals = dl.AutoPullInvoiceCosts(orderkey);
            var             fileuploadPath = HttpContext.Current.Server.MapPath("~/App_Data/Files/");
            PdfDocument     pdfDoc         = new PdfDocument(new PdfWriter(Path.Combine(fileuploadPath, $"invoice_{orderkey}.pdf")));
            DeliveryOrderDL doObj          = new DeliveryOrderDL();
            var             orderHeader    = doObj.GetDeliveryOrder(orderkey);
            var             customer       = new CustomerDL().GetCustomerbykey(orderHeader.CustKey);

            var      orderdetaillist = doObj.GetOrderDetailsByKey(orderkey);
            Document doc             = new Document(pdfDoc);

            /*
             * 1483 Via Plata StreetLong Beach, CA
             */
            var paragraph = new Paragraph("INVOICE").SetTextAlignment(TextAlignment.CENTER).SetFontSize(15);

            doc.Add(paragraph);

            var cell = new Cell().SetTextAlignment(TextAlignment.LEFT);

            cell.Add(new Paragraph(new Text("PLEASE REMIT TO").SetFontSize(14).SetBold()));
            cell.Add(new Paragraph("Junction Collaborative Transports").SetFontSize(12));
            cell.Add(new Paragraph("1483 Via Plata Street").SetFontSize(12));
            cell.Add(new Paragraph("Long Beach, CA").SetFontSize(12));
            cell.Add(new Paragraph("90810").SetFontSize(12));
            cell.Add(new Paragraph("Phone: (310) 537-7730").SetFontSize(12));
            cell.Add(new Paragraph("Fax: (310) 537-7723").SetFontSize(12));

            //p.Add(new Paragraph().Add("PLEASE REMIT TO").Add(customer.CustName).Add(customer.Address.Address1)
            //    .Add(customer.Address.Address2).Add(customer.Address.City).Add(customer.Address.State)
            //    .Add(customer.Address.Zip));
            doc.Add(cell);

            List      header       = new List();
            double    runningtotal = 0.0;
            InvoiceDL dl           = new InvoiceDL();

            foreach (var orderdetail in orderdetaillist)
            {
                var   invoice  = dl.GetInvoicebyOrderDetailKey(orderdetail.OrderDetailKey.ToString());
                Table dtlTable = new Table(UnitValue.CreatePercentArray(7)).UseAllAvailableWidth();
                dtlTable.AddHeaderCell(new Cell().Add(new Paragraph("Container no")));
                dtlTable.AddHeaderCell(new Cell().Add(new Paragraph("Container size")));
                dtlTable.AddHeaderCell(new Cell().Add(new Paragraph("Chassis")));
                dtlTable.AddHeaderCell(new Cell().Add(new Paragraph("Invoice No")));
                dtlTable.AddHeaderCell(new Cell().Add(new Paragraph("Due date")));
                dtlTable.AddHeaderCell(new Cell().Add(new Paragraph("Invoice Date")));
                dtlTable.AddHeaderCell(new Cell().Add(new Paragraph("Amount")));
                dtlTable.AddCell(new Cell().Add(new Paragraph(orderdetail.ContainerNo)));
                dtlTable.AddCell(new Cell().Add(new Paragraph(orderdetail.ContainerSize.ToString())));
                dtlTable.AddCell(new Cell().Add(new Paragraph(orderdetail.Chassis)));
                dtlTable.AddCell(new Cell().Add(new Paragraph(invoice.InvoiceNo.ToString())));
                dtlTable.AddCell(new Cell().Add(new Paragraph(invoice.DueDate.ToString())));
                dtlTable.AddCell(new Cell().Add(new Paragraph(invoice.InvoiceDate.ToString())));
                dtlTable.AddCell(new Cell().Add(new Paragraph(invoice.InvoiceAmt.ToString())));
                runningtotal += (double)invoice.InvoiceAmt;
                ListItem dtl = new ListItem();
                dtl.Add(new Paragraph().Add(dtlTable));

                // doc.Add(dtlTable);

                var      invoicedtl  = dl.GetInvoiceDetail(orderdetail.OrderDetailKey.ToString());
                ListItem invoiceItem = new ListItem();
                Table    table       = new Table(UnitValue.CreatePercentArray(5));
                table.AddHeaderCell(new Cell().Add(new Paragraph("Item")));
                table.AddHeaderCell(new Cell().Add(new Paragraph("Price")));
                table.AddHeaderCell(new Cell().Add(new Paragraph("Quantity")));
                table.AddHeaderCell(new Cell().Add(new Paragraph("UnitPrice")));
                table.AddHeaderCell(new Cell().Add(new Paragraph("Excess Amount")));

                foreach (var invoiceline in invoicedtl)
                {
                    table.AddCell(new Cell().Add(new Paragraph(invoiceline.Description)));
                    table.AddCell(new Cell().Add(new Paragraph(invoiceline.Price.ToString())));
                    table.AddCell(new Cell().Add(new Paragraph(invoiceline.Quantity.ToString())));
                    table.AddCell(new Cell().Add(new Paragraph(invoiceline.UnitPrice.ToString())));
                    table.AddCell(new Cell().Add(new Paragraph(invoiceline.ExcessAmount.ToString())));
                    runningtotal += (double)invoiceline.Price * (double)invoiceline.Quantity;
                }

                invoiceItem.Add(new Paragraph("Detailed Breakup:").SetFirstLineIndent(25).Add(table));
                dtl.Add(invoiceItem);
                header.Add(dtl);
            }
            header.SetSymbolIndent(80).Add($"Total:{runningtotal.ToString()}");
            doc.Add(header);
            //Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);


            // By default column width is calculated automatically for the best fit.
            // useAllAvailableWidth() method set table to use the whole page's width while placing the content.

            //foreach (var record in invoicetotals)
            //{
            //    table.AddCell(new Cell().Add(new Paragraph(record.ContainerNo)));
            //    table.AddCell(new Cell().Add(new Paragraph(record.ItemId)));
            //    table.AddCell(new Cell().Add(new Paragraph(record.UnitPrice.ToString())));
            //}
            //table.AddCell(new Cell().Add(new Paragraph()));
            //table.AddCell(new Cell().Add(new Paragraph("Totals:")));
            //table.AddCell(new Cell().Add(new Paragraph(invoicetotals.Select(x => x.UnitPrice).Sum().ToString())));
            //doc.Add(table);
            //}
            doc.Close();
            if (doc != null)
            {
                byte[] bytes = File.ReadAllBytes(Path.Combine(fileuploadPath, $"invoice_{orderkey}.pdf"));
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK);
                //Set the Response Content.
                response.Content = new ByteArrayContent(bytes);

                //Set the Response Content Length.
                response.Content.Headers.ContentLength = bytes.LongLength;

                //Set the Content Disposition Header Value and FileName.
                response.Content.Headers.ContentDisposition          = new ContentDispositionHeaderValue("attachment");
                response.Content.Headers.ContentDisposition.FileName = $"invoice_{orderkey}.pdf";

                //Set the File Content Type.
                response.Content.Headers.ContentType = new MediaTypeHeaderValue(MimeMapping.GetMimeMapping($"invoice_{orderkey}.pdf"));
                return(response);
            }
            return(Request.CreateResponse(HttpStatusCode.InternalServerError, string.Empty, Configuration.Formatters.JsonFormatter));
        }