Example #1
0
        public PrintReceiptA4 GetPrintReceiptA4Detail(int CustomerOrderId)
        {
            PrintReceiptA4 printReceiptA4 = new PrintReceiptA4();

            using (SqlConnection con = new SqlConnection(_ConnectionString.Value.ConnectionString))
            {
                string customerOrderDetail = string.Empty;
                string customerOrderItems  = string.Empty;
                customerOrderDetail = "SELECT b.CustomerOrderId,b.Id As BillId,CO.SalesInvoiceNumber,B.BillDateTime,O.OutletName,isnull(E.Firstname,'') + ' '+  isnull(E.lastname,'') as Username,C.CustomerName,B.GrossAmount,B.TaxAmount,B.VatableAmount,CO.NonVatableAmount, B.Discount,B.ServiceCharge,B.TotalAmount,PM.PaymentMethodName,BD.BillAmount FROM Bill B  " +
                                      " INNER JOIN CustomerOrder CO ON B.CustomerOrderId = CO.Id " +
                                      " INNER JOIN BillDetail BD ON B.Id = BD.BillId " +
                                      " INNER JOIN Outlet O ON O.Id = B.OutletId " +
                                      " INNER JOIN[User] U ON U.ID = B.UserIdInserted " +
                                      " inner join employee e on e.id = u.employeeid " +
                                      " INNER JOIN Customer C ON C.Id = b.CustomerId " +
                                      " INNER JOIN PaymentMethod PM ON PM.Id = BD.PaymentMethodId " +
                                      " WHERE b.CustomerOrderId =  " + CustomerOrderId;

                customerOrderItems = "SELECT FM.FoodMenuName,COI.FoodMenuQty,COI.FoodMenuRate,COI.Price,   " +
                                     " (select case when foodmenutaxtype = 1 then 'V' when foodmenutaxtype = 2 then 'E' when foodmenutaxtype = 3 then 'Z' ELSE '' end) AS FOODVAT " +
                                     " FROM CustomerOrderItem  COI " +
                                     " INNER JOIN FoodMenu FM ON FM.ID = COI.FoodMenuId " +
                                     " WHERE CustomerOrderId =  " + CustomerOrderId;

                printReceiptA4.PrintReceiptDetail   = con.Query <PrintReceiptModel>(customerOrderDetail).FirstOrDefault();
                printReceiptA4.PrintReceiptItemList = con.Query <PrintReceiptItemModel>(customerOrderItems).ToList();

                return(printReceiptA4);
            }
        }
        public ActionResult PrintReceiptA4(int id, string clientName, string address1, string address2, string phone)
        {
            PrintReceiptA4 printReceiptA4 = new PrintReceiptA4();

            printReceiptA4 = _iReportService.GetPrintReceiptA4Detail(id);
            string pdf_page_size = string.Empty, pdf_orientation = string.Empty;
            var    sb = new StringBuilder();

            sb.Append(@"<html>
                    <style type='text/css'>
                        table, tr, td {
                        border: 1px solid;
                    }
                    tr.noBorder td {
                    border: 0;
                    }
                    </style>
                    <body>
                        <table border=1 width='1280' Height='800'>
                        <tr align='center' Height='50'>
	                    <td colspan='6'><div align='right'>"    );

            sb.Append(clientName + "</br>" + address1 + "</br>" + address2 + "</br>" + phone);
            sb.Append(@"</div></td>
                            </tr>
                            <tr align='center' Height='50'>
                                <td colspan='6'>INVOICE </td>
                            </tr>
                            <tr Height='50'>
                            <td colspan=3 >Customer Name : " + printReceiptA4.PrintReceiptDetail.CustomerName + @" </td>
                                    <td colspan=3>Mode of payment : "     + printReceiptA4.PrintReceiptDetail.PaymentMethodName + @"</td>
                            </tr>
                            <tr Height='50'>
                                <td colspan=3>Invoice : " + printReceiptA4.PrintReceiptDetail.SalesInvoiceNumber + @"</td>
                                <td colspan=3>Date : " + printReceiptA4.PrintReceiptDetail.BillDateTime + @"</td>
                            </tr>
                            <tr Height='30' class='noBorder'>
                                <td colspan=3 >Item</td>
                                <td width=50 >Qty</td>
                                <td >Rate</td>
                                <td >Amount</td>
                            </tr>");

            foreach (var item in printReceiptA4.PrintReceiptItemList)
            {
                sb.AppendFormat(@"<tr  Height='30' class='noBorder'><td colspan=3 >{0}</td><td width=50 >{1}</td><td>{2}</td><td>{3}</td></tr>", item.FoodMenuName, item.FoodMenuQty, item.FoodMenuRate, item.Price);
            }
            sb.Append(@"<tr Height='30'><td colspan=4></td><td >Gross Total</td><td >" + printReceiptA4.PrintReceiptDetail.GrossAmount + "</td></tr>");
            sb.Append(@"<tr Height='30'><td colspan=4></td><td >Vatable</td><td >" + printReceiptA4.PrintReceiptDetail.VatableAmount + "</td></tr>");
            sb.Append(@"<tr Height='30'><td colspan=4></td><td >Non Vatable</td><td >" + printReceiptA4.PrintReceiptDetail.NonVatableAmount + "</td></tr>");
            sb.Append(@"<tr Height='30'><td colspan=4></td><td >Total Tax</td><td >" + printReceiptA4.PrintReceiptDetail.TaxAmount + "</td></tr>");
            sb.Append(@"<tr Height='30'><td colspan=4></td><td >Grand Total</td><td >" + printReceiptA4.PrintReceiptDetail.TotalAmount + "</td></tr>");
            sb.Append(@" <tr Height='30'>
                            <td colspan='6'>Remarks :  </td>
                            </tr>
                            </body>
                            </table>
                            </html>");
            pdf_page_size = "A4";
            PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), pdf_page_size, true);

            pdf_orientation = "Portrait";
            PdfPageOrientation pdfOrientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), pdf_orientation, true);
            //// instantiate a html to pdf converter object
            HtmlToPdf converter = new HtmlToPdf();

            //// set converter options
            converter.Options.PdfPageSize        = PdfPageSize.A4;
            converter.Options.PdfPageOrientation = PdfPageOrientation.Portrait;
            ////converter.Options.WebPageWidth = webPageWidth;
            ////converter.Options.WebPageHeight = webPageHeight;
            converter.Options.MarginLeft   = 10;
            converter.Options.MarginRight  = 10;
            converter.Options.MarginTop    = 20;
            converter.Options.MarginBottom = 20;
            //// create a new pdf document converting an url
            PdfDocument doc = converter.ConvertHtmlString(sb.ToString());

            //// save pdf document
            //doc.Save("Select.pdf");
            byte[] pdf = doc.Save();
            return(new FileContentResult(pdf, "application/pdf")
            {
                FileDownloadName = "Document.pdf"
            });
        }