Esempio n. 1
0
        public ActionResult View(long?id)
        {
            SalesDeliveryModel purchaseModel = new SalesDeliveryModel();

            if (UserRolePermissionForPage.View == true)
            {
                if (id > 0)
                {
                    long purchaseGRNId = Convert.ToInt64(id);
                    purchaseModel = _iSalesDeliveryService.GetViewSalesDeliveryFoodMenuById(purchaseGRNId);
                }
                else
                {
                    purchaseModel.SalesDeliveryDate = DateTime.UtcNow.AddMinutes(LoginInfo.Timeoffset);
                    purchaseModel.ReferenceNo       = _iSalesDeliveryService.ReferenceNumberFoodMenu().ToString();
                }

                purchaseModel.CustomerList = _iDropDownService.GetCustomerList();
                purchaseModel.StoreList    = _iDropDownService.GetStoreList();
                purchaseModel.EmployeeList = _iDropDownService.GetEmployeeList();
                return(View(purchaseModel));
            }
            else
            {
                return(RedirectToAction("NotFound", "Error"));
            }
        }
Esempio n. 2
0
        public ActionResult GetDeliveryPrint(int id, string reportName)
        {
            SalesDeliveryModel salesInvoiceModel = new SalesDeliveryModel();

            salesInvoiceModel = _iSalesDeliveryService.GetSalesDeliveryReportById(id);
            string html = _iSalesDeliveryService.GetDeliveryHtmlString(salesInvoiceModel, reportName);

            var pdf = Pdf
                      .From(html)
                      .OfSize(PaperSize.Letter)
                      .WithTitle("Title")
                      .WithoutOutline()
                      .WithMargins(.25.Centimeters())
                      .Portrait()
                      .Comressed()
                      .Content();

            string webRootPath = _hostingEnvironment.WebRootPath;
            string InvoicePath = Path.Combine(webRootPath, "Sales");
            string FileNmae    = InvoicePath + "\\SalesDelivery_" + DateTime.UtcNow.AddMinutes(LoginInfo.Timeoffset).ToString("MM/dd/yyyy HH:mm").Replace("/", "").Replace(" ", "").Replace(":", "").ToString() + ".pdf";

            Stream myStream = new MemoryStream(pdf);

            using (var fileStream = System.IO.File.Create(FileNmae))
            {
                myStream.Seek(0, SeekOrigin.Begin);
                myStream.CopyTo(fileStream);
            }

            byte[] FileBytes = System.IO.File.ReadAllBytes(FileNmae);
            return(File(FileBytes, "application/pdf"));
        }
Esempio n. 3
0
        public ActionResult SalesDeliveryFoodMenu(SalesDeliveryModel purchaseModel, string Submit)
        {
            purchaseModel.CustomerList = _iDropDownService.GetCustomerList();
            purchaseModel.StoreList    = _iDropDownService.GetStoreList();
            purchaseModel.EmployeeList = _iDropDownService.GetEmployeeList();
            purchaseModel.ReferenceNo  = _iSalesDeliveryService.ReferenceNumberFoodMenu().ToString();

            string purchaseMessage = string.Empty;

            if (!ModelState.IsValid)
            {
                string errorString = this.ValidationPurchaseGRN(purchaseModel);
                if (!string.IsNullOrEmpty(errorString))
                {
                    return(Json(new { error = true, message = errorString, status = 201 }));
                }
            }

            if (purchaseModel.salesDeliveryDetails != null)
            {
                if (purchaseModel.salesDeliveryDetails.Count > 0)
                {
                    purchaseModel.InventoryType = 1;
                    if (purchaseModel.Id > 0)
                    {
                        int result = _iSalesDeliveryService.UpdatePurchaseGRNFoodMenu(purchaseModel);
                        if (result > 0)
                        {
                            purchaseMessage = _locService.GetLocalizedHtmlString("EditSuccss");
                        }
                    }
                    else
                    {
                        purchaseModel.ReferenceNo = _iSalesDeliveryService.ReferenceNumberFoodMenu().ToString();

                        int result = _iSalesDeliveryService.InsertPurchaseGRNFoodMenu(purchaseModel);
                        if (result > 0)
                        {
                            purchaseMessage = _locService.GetLocalizedHtmlString("SaveSuccess") + " Reference No is: " + result.ToString();
                        }
                    }
                }
                else
                {
                    purchaseMessage = _locService.GetLocalizedHtmlString("ValidPurchaseGRNDetails");
                    return(Json(new { error = true, message = purchaseMessage, status = 201 }));
                }
            }
            else
            {
                purchaseMessage = _locService.GetLocalizedHtmlString("ValidPurchaseGRNDetails");
                return(RedirectToAction("PurchaseGRNFoodMenu", "PurchaseGRNFoodMenu"));
                // return Json(new { error = true, message = purchaseMessage, status = 201 });
            }
            // return View(purchaseModel);
            return(Json(new { error = false, message = purchaseMessage, status = 200 }));
            //return View();
        }
        public SalesDeliveryModel GetViewSalesDeliveryFoodMenuById(long purchaseGRNId)
        {
            SalesDeliveryModel purchaseModel = new SalesDeliveryModel();

            var model = (from purchase in _iSalesDeliveryRepository.GetViewSalesDeliveryFoodMenuById(purchaseGRNId).ToList()
                         select new SalesDeliveryModel()
            {
                Id = purchase.Id,
                ReferenceNo = purchase.ReferenceNo,
                CustomerId = purchase.CustomerId,
                EmployeeId = purchase.EmployeeId,
                StoreId = purchase.StoreId,
                SalesDeliveryDate = purchase.SalesDeliveryDate,
                GrossAmount = purchase.GrossAmount,
                TaxAmount = purchase.TaxAmount,
                TotalAmount = purchase.TotalAmount,
                PaidAmount = purchase.PaidAmount,
                DueAmount = purchase.DueAmount,
                DeliveryNoteNumber = purchase.DeliveryNoteNumber,
                DeliveryDate = purchase.DeliveryDate,
                DriverName = purchase.DriverName,
                VehicleNumber = purchase.VehicleNumber,
                Notes = purchase.Notes,
                CustomerName = purchase.CustomerName,
                StoreName = purchase.StoreName,
                SOReferenceNo = purchase.SOReferenceNo,
                SODate = purchase.SODate,
                VatableAmount = purchase.VatableAmount,
                NonVatableAmount = purchase.NonVatableAmount
            }).SingleOrDefault();

            if (model != null)
            {
                model.salesDeliveryDetails = (from purchasedetails in _iSalesDeliveryRepository.GetViewSalesDeliveryFoodMenuDetails(purchaseGRNId)
                                              select new SalesDeliveryDetailModel()
                {
                    SalesDeliveryId = purchasedetails.SalesDeliveryId,
                    FoodMenuId = purchasedetails.FoodMenuId,
                    SOQTY = purchasedetails.SOQTY,
                    DeliveryQTY = purchasedetails.DeliveryQTY,
                    UnitPrice = purchasedetails.UnitPrice,
                    GrossAmount = purchasedetails.GrossAmount,
                    DiscountPercentage = purchasedetails.DiscountPercentage,
                    DiscountAmount = purchasedetails.DiscountAmount,
                    TaxAmount = purchasedetails.TaxAmount,
                    TotalAmount = purchasedetails.TotalAmount,
                    IngredientName = purchasedetails.IngredientName,
                    FoodMenuName = purchasedetails.FoodMenuName,
                    ItemType = purchasedetails.ItemType,
                    UnitName = purchasedetails.UnitName,
                    VatableAmount = purchasedetails.VatableAmount,
                    NonVatableAmount = purchasedetails.NonVatableAmount
                }).ToList();
            }
            return(model);
        }
Esempio n. 5
0
        private string ValidationPurchaseGRN(SalesDeliveryModel purchaseModel)
        {
            string ErrorString = string.Empty;

            if (string.IsNullOrEmpty(purchaseModel.CustomerId.ToString()) || purchaseModel.CustomerId == 0)
            {
                ErrorString = _locService.GetLocalizedHtmlString("ValidCustomer");
                return(ErrorString);
            }
            if (purchaseModel.salesDeliveryDetails == null || purchaseModel.salesDeliveryDetails.Count < 1)
            {
                ErrorString = _locService.GetLocalizedHtmlString("ValidSalesDeliveryDetails");
                return(ErrorString);
            }

            return(ErrorString);
        }
        public int UpdatePurchaseGRNFoodMenu(SalesDeliveryModel purchaseModel)//
        {
            int result = 0;

            using (SqlConnection con = new SqlConnection(_ConnectionString.Value.ConnectionString))
            {
                con.Open();
                SqlTransaction sqltrans = con.BeginTransaction();
                var            query    = "Update [dbo].[SalesDelivery] set " +
                                          "   [CustomerId]  = @CustomerId" +
                                          "  ,[StoreId]  = @StoreId" +
                                          "  ,[EmployeeId]  = @EmployeeId" +
                                          "  ,[SalesDeliveryDate] = @SalesDeliveryDate  " +
                                          "  ,[GrossAmount]  =  @GrossAmount  " +
                                          "  ,[TaxAmount]  = @TaxAmount   " +
                                          "  ,[TotalAmount]  = @TotalAmount   " +
                                          "  ,[VatableAmount] = @VatableAmount     " +
                                          "  ,[NonVatableAmount] = @NonVatableAmount      " +
                                          " ,[DeliveryNoteNumber] =@DeliveryNoteNumber " +
                                          "  ,[DeliveryDate]=@DeliveryDate  " +
                                          "  ,[DriverName] =@DriverName  " +
                                          "  ,[VehicleNumber] =@VehicleNumber  " +
                                          "  ,[PaidAmount] = @PaidAmount    " +
                                          "  ,[DueAmount] =  @DueAmount    " +
                                          "  ,[Notes] =  @Notes    " +
                                          "  ,[UserIdUpdated] = " + LoginInfo.Userid + " " +
                                          "  ,[DateUpdated]  = GetUtcDate()  where id= " + purchaseModel.Id + ";";
                result = con.Execute(query, purchaseModel, sqltrans, 0, System.Data.CommandType.Text);

                if (result > 0)
                {
                    int detailResult = 0;
                    if (purchaseModel.DeletedId != null)
                    {
                        foreach (var item in purchaseModel.DeletedId)
                        {
                            var deleteQuery = $"update SalesDeliveryDetail set IsDeleted = 1, UserIdDeleted = " + LoginInfo.Userid + ", DateDeleted = GetutcDate() where id = " + item + ";";
                            result = con.Execute(deleteQuery, null, sqltrans, 0, System.Data.CommandType.Text);
                        }
                    }
                    foreach (var item in purchaseModel.salesDeliveryDetails)
                    {
                        var queryDetails = string.Empty;
                        if (item.SalesDeliveryId > 0)
                        {
                            queryDetails = "Update [dbo].[SalesDeliveryDetail] set " +
                                           "[SalesDeliveryId] = " + purchaseModel.Id;
                            if (item.ItemType == 0)
                            {
                                queryDetails = queryDetails + " ,[FoodMenuId]  = " + item.FoodMenuId + ",[IngredientId] = null,[AssetItemId] = null, ";
                            }
                            else if (item.ItemType == 1)
                            {
                                queryDetails = queryDetails + " [IngredientId]  = " + item.FoodMenuId + ",[FoodMenuId] = null,[AssetItemId] = null, ";
                            }
                            else if (item.ItemType == 2)
                            {
                                queryDetails = queryDetails + " [AssetItemId]  = " + item.FoodMenuId + ",[FoodMenuId] = null,[IngredientId] = null, ";
                            }
                            queryDetails = queryDetails + " [UnitPrice]   = " + item.UnitPrice +
                                           ",[SOQTY]  = " + item.SOQTY +
                                           ",[DeliveryQTY]   = " + item.DeliveryQTY +
                                           ",[GrossAmount]   = " + item.GrossAmount +
                                           ",[DiscountPercentage] = " + item.DiscountPercentage +
                                           ",[DiscountAmount]  = " + item.DiscountAmount +
                                           ",[TaxAmount]   = " + item.TaxAmount +
                                           ",[TotalAmount]  = " + item.TotalAmount +
                                           " ,[VatableAmount] = " + item.VatableAmount +
                                           " ,[NonVatableAmount] = " + item.NonVatableAmount +
                                           " ,[UserIdUpdated] = " + LoginInfo.Userid + "," +
                                           " [DateUpdated] = GetUTCDate() " +
                                           " where id = " + item.SalesDeliveryId + ";";
                        }
                        else
                        {
                            queryDetails = "INSERT INTO [dbo].[SalesDeliveryDetail]" +
                                           "  ([SalesDeliveryId] " +
                                           " ,[FoodMenuId] " +
                                           " ,[IngredientId] " +
                                           " ,[AssetItemId] " +
                                           " ,[SOQty] " +
                                           " ,[DeliveryQTY] " +
                                           " ,[UnitPrice] " +
                                           " ,[GrossAmount] " +
                                           " ,[DiscountPercentage]  " +
                                           " ,[DiscountAmount] " +
                                           " ,[TaxAmount] " +
                                           " ,[TotalAmount]  " +
                                           "  ,[VatableAmount]      " +
                                           "  ,[NonVatableAmount]      " +
                                           " ,[UserIdInserted]" +
                                           " ,[DateInserted]" +
                                           " ,[IsDeleted])   " +
                                           "VALUES           " +
                                           "(" + purchaseModel.Id + ",";
                            if (item.ItemType == 0)
                            {
                                queryDetails = queryDetails + "" + item.FoodMenuId + ",NUll,NUll,";
                            }
                            else if (item.ItemType == 1)
                            {
                                queryDetails = queryDetails + "NULL," + item.FoodMenuId + ",NUll,";
                            }
                            else if (item.ItemType == 2)
                            {
                                queryDetails = queryDetails + "NUll,NULL," + item.FoodMenuId + ",";
                            }
                            queryDetails = queryDetails + item.SOQTY + "," +
                                           item.DeliveryQTY + "," +
                                           item.UnitPrice + "," +
                                           item.GrossAmount + "," +
                                           item.DiscountPercentage + "," +
                                           item.DiscountAmount + "," +
                                           item.TaxAmount + "," +
                                           item.TotalAmount + "," +
                                           item.VatableAmount + "," +
                                           item.NonVatableAmount + "," +
                                           LoginInfo.Userid + ",GetUTCDate(),0); SELECT SCOPE_IDENTITY() ";
                        }
                        detailResult = con.Execute(queryDetails, null, sqltrans, 0, System.Data.CommandType.Text);
                    }

                    if (detailResult > 0)
                    {
                        sqltrans.Commit();
                    }
                    else
                    {
                        sqltrans.Rollback();
                    }
                }
                else
                {
                    sqltrans.Rollback();
                }
            }

            return(result);
        }
        public int InsertPurchaseGRNFoodMenu(SalesDeliveryModel purchaseModel)//
        {
            bool taxInclusive = GetCustomerTaxExampt((int)purchaseModel.CustomerId);

            int result       = 0;
            int detailResult = 0;

            using (SqlConnection con = new SqlConnection(_ConnectionString.Value.ConnectionString))
            {
                con.Open();
                SqlTransaction sqltrans = con.BeginTransaction();
                var            query    = "INSERT INTO [dbo].[SalesDelivery] " +
                                          "  ([SalesId] " +
                                          "  ,[ReferenceNumber] " +
                                          "  ,[InventoryType]  " +
                                          "  ,[CustomerId]     " +
                                          "  ,[StoreId]        " +
                                          "  ,[EmployeeId]        " +
                                          "  ,[SalesDeliveryDate]   " +
                                          "  ,[GrossAmount]    " +
                                          "  ,[TaxAmount]      " +
                                          "  ,[TotalAmount]     " +
                                          "  ,[VatableAmount]      " +
                                          "  ,[NonVatableAmount]      " +
                                          " ,[DeliveryNoteNumber] " +
                                          "  ,[DeliveryDate] " +
                                          "  ,[DriverName]   " +
                                          "  ,[VehicleNumber]  " +
                                          "  ,[PaidAmount]     " +
                                          "  ,[DueAmount]      " +
                                          "  ,[Notes]          " +
                                          "  ,[UserIdInserted]  " +
                                          "  ,[DateInserted]   " +
                                          "  ,[IsDeleted] )     " +
                                          "   VALUES           " +
                                          "  (@SalesId,  " +
                                          "  @ReferenceNo,  " +
                                          "   @InventoryType,      " +
                                          "   @CustomerId,      " +
                                          "   @StoreId,         " +
                                          "   @EmployeeId,         " +
                                          "   @SalesDeliveryDate,    ";

                if (taxInclusive == true)
                {
                    query = query + "   @GrossAmount,     " +
                            "   @TaxAmount,     " +
                            "   @TotalAmount,     " +
                            "   @VatableAmount,      " +
                            "   @NonVatableAmount,      ";
                }
                else
                {
                    query = query + "  @TotalAmount,     " +
                            "   0,     " +
                            "   @TotalAmount,     " +
                            "   0,      " +
                            "   0,      ";
                }

                query = query + "  @DeliveryNoteNumber," +
                        "  @DeliveryDate," +
                        "  @DriverName," +
                        " @VehicleNumber," +
                        "   @PaidAmount,      " +
                        "   @DueAmount,       " +
                        "   @Notes," +
                        "" + LoginInfo.Userid + "," +
                        "   GetUtcDate(),    " +
                        "   0); SELECT CAST(SCOPE_IDENTITY() as int); ";
                result = con.ExecuteScalar <int>(query, purchaseModel, sqltrans, 0, System.Data.CommandType.Text);

                if (result > 0)
                {
                    foreach (var item in purchaseModel.salesDeliveryDetails)
                    {
                        var queryDetails = "INSERT INTO [dbo].[SalesDeliveryDetail]" +
                                           "  ([SalesDeliveryId] " +
                                           " ,[FoodMenuId] " +
                                           " ,[IngredientId] " +
                                           " ,[AssetItemId] " +
                                           " ,[SOQty] " +
                                           " ,[DeliveryQty] " +
                                           " ,[UnitPrice] " +
                                           " ,[GrossAmount] " +
                                           " ,[DiscountPercentage]  " +
                                           " ,[DiscountAmount] " +
                                           " ,[TaxAmount] " +
                                           " ,[TotalAmount]  " +
                                           "  ,[VatableAmount]      " +
                                           "  ,[NonVatableAmount]      " +
                                           " ,[UserIdInserted]" +
                                           " ,[DateInserted]" +
                                           " ,[IsDeleted])   " +
                                           "VALUES (          " + result + ",";
                        if (item.ItemType == 0)
                        {
                            queryDetails = queryDetails + "" + item.FoodMenuId + ",NUll,NUll,";
                        }
                        else if (item.ItemType == 1)
                        {
                            queryDetails = queryDetails + "NULL," + item.FoodMenuId + ",NUll,";
                        }
                        else if (item.ItemType == 2)
                        {
                            queryDetails = queryDetails + "NUll,NULL," + item.FoodMenuId + ",";
                        }
                        queryDetails = queryDetails + "" + item.SOQTY + "," +
                                       item.DeliveryQTY + "," +
                                       item.UnitPrice + ",";

                        if (taxInclusive == true)
                        {
                            queryDetails = queryDetails +
                                           item.GrossAmount + "," +
                                           item.DiscountPercentage + "," +
                                           item.DiscountAmount + "," +
                                           item.TaxAmount + "," +
                                           item.TotalAmount + "," +
                                           item.VatableAmount + "," +
                                           item.NonVatableAmount + ",";
                        }
                        else
                        {
                            queryDetails = queryDetails +
                                           item.TotalAmount + "," +
                                           item.DiscountPercentage + "," +
                                           item.DiscountAmount + "," +
                                           "0," +
                                           item.TotalAmount + "," +
                                           "0," +
                                           "0,";
                        }

                        queryDetails = queryDetails + LoginInfo.Userid + ",GetUTCDate(),0); SELECT CAST(ReferenceNumber as INT) from SalesDelivery where id = " + result + "; ";

                        detailResult = con.ExecuteScalar <int>(queryDetails, null, sqltrans, 0, System.Data.CommandType.Text);
                    }

                    if (detailResult > 0)
                    {
                        sqltrans.Commit();

                        int outResult = 0;
                        if (purchaseModel.SalesId > 0)
                        {
                            outResult = UpdatePurchaseOrderId(purchaseModel.SalesId);
                        }

                        CommonRepository commonRepository = new CommonRepository(_ConnectionString);
                        string           sResult          = commonRepository.InventoryPush("SalesDelivery", result);
                    }
                    else
                    {
                        sqltrans.Rollback();
                    }
                }
                else
                {
                    sqltrans.Rollback();
                }
            }

            return(detailResult);
        }
 public int UpdatePurchaseGRNFoodMenu(SalesDeliveryModel purchaseModel)//
 {
     return(_iSalesDeliveryRepository.UpdatePurchaseGRNFoodMenu(purchaseModel));
 }
 public int InsertPurchaseGRNFoodMenu(SalesDeliveryModel purchaseModel)//
 {
     return(_iSalesDeliveryRepository.InsertPurchaseGRNFoodMenu(purchaseModel));
 }
        public string GetDeliveryHtmlString(SalesDeliveryModel salesInvoiceModel, string reportName)
        {
            var     sb       = new StringBuilder();
            decimal total    = (decimal)salesInvoiceModel.salesDeliveryDetails.Count;
            int     totalRow = (int)total;
            decimal rowCount = total / 15;

            int noOfPages = (int)Math.Ceiling(rowCount);
            int limit = 15, start = 0;
            int logoTop = 35;

            //HTML
            sb.Append(@"<html><body style='font-family:Helvetica; font-size:16px;'>");

            for (int j = 1; j <= noOfPages; j++)
            {
                //Header Start
                string HtmlHeader = @"<table style='border:0px solid black;' width='1280' Height='200'>
                            <tr style='border:0px solid black;' align='center' Height='50'>
	                        <td style='font-size:20px; border:0px solid black; vertical-align:top;padding-top:15px;'>
                            <div style='text-align:center; padding-top:20px; position: rela1tive;'>
                            <img src='http://shayona.rocketpos.uk/img/clientlogo.jpg' width='350' height='140' style='position: absolute; left: 15px; top: " + logoTop + @"px' >" +
                                    @"<div style='font-size:28px; font-weigth:bold'><b>" + salesInvoiceModel.InvoiceHeader + @"</b></div>
                            <div style='font-size:22px;'>" + salesInvoiceModel.OutletAddress1 +
                                    "</br>" + salesInvoiceModel.OutletAddress2 +
                                    "</br>" + salesInvoiceModel.OutletEmail +
                                    "</br>" + salesInvoiceModel.OutletPhone +
                                    "</div></div></div>" +
                                    "</td></tr></table>";

                sb.Append(HtmlHeader);

                //Report Title
                if (reportName == "Note")
                {
                    sb.Append(@"<table style='border-right:1px solid;border-left:1px solid;border-top:1px solid' width='1280' Height='35'>
                            <tr  align='center'>
                            <td style='font-size:22px;'><b>DELIVERY NOTE <b></td>
                            </tr>
                            </table>");
                }
                else
                {
                    sb.Append(@"<table style='border-right:1px solid;border-left:1px solid;border-top:1px solid' width='1280' Height='35'>
                            <tr  align='center'>
                            <td style='font-size:22px;'><b>PACKING LIST <b></td>
                            </tr>
                            </table>");
                }

                //Buyer name & two empty column
                sb.Append(@"<table style='font-size:21px;border-right:1px solid;border-left:1px solid;border-top:1px solid' width='1280' Height='170'>
                            <tr>
                            <td style='padding-left:5px; border-right:1px solid;' width='398'> <b> Buyer</b></br>  " + salesInvoiceModel.CustomerName + "</br> " + salesInvoiceModel.CustomerAddress1 + "</br> " + salesInvoiceModel.CustomerAddress2 + "</br> " + salesInvoiceModel.CustomerEmail + @"</br></br></td>
                            <td style='padding-left:5px;border-right:1px solid;' width='397'></td>
                            <td width='400'></td>
                            </tr>
                            </table>");

                //Invoice no, Order No., Invoice Date, Page No
                sb.Append(@"<table style='font-size:20px;border-right:1px solid;border-left:1px solid;border-top:1px solid' width='1280' Height='50'>
                            <tr>
                                <td style='padding-left:5px; border-right:1px solid;' width='400'><b>No.</b></br> " + salesInvoiceModel.ReferenceNo + @"</td>");

                if (salesInvoiceModel.DeliveryNoteNumber != null)
                {
                    if (salesInvoiceModel.DeliveryNoteNumber != "")
                    {
                        sb.Append(@"<td style='padding-left:5px; border-right:1px solid;' width='400'><b>Order No. </b></br> " + salesInvoiceModel.DeliveryNoteNumber + @"</td>");
                    }
                    else
                    {
                        sb.Append(@"<td style='padding-left:5px; border-right:1px solid;' width='400'></td>");
                    }
                }
                else
                {
                    sb.Append(@"<td style='padding-left:5px; border-right:1px solid;' width='400'></td>");
                }

                sb.Append(@"<td width='400' style='padding-left:5px;'><b> Date </b></br><div style='float:left'>" + salesInvoiceModel.SalesDeliveryDate.ToShortDateString() + @"</div><div style='float:right'>" +
                          @"Page " + j.ToString() + @" of " + noOfPages.ToString() + @"</div>
                        </tr> 
                        </table>");

                //Item List
                sb.Append(@"<table style='font-size:20px;border-right:1px solid;border-left:1px solid;border-top:1px solid' width='1280'>
                            <tr Height='42' >
                                    <td style='padding-left:5px;;width:1.5%;text-align: right; padding-right:15px'><b>No</b></td>
                                    <td style='width:66.5%;text-align: left; padding-right:15px'><b>Description of Goods</b></td>
                                    <td style='width:7%;text-align: right; padding-right:40px'><b>Quantity</b></td>
                                    <td style='width:7%;text-align: left; padding-right:20px'><b>UoM</b></td>
                            </tr>");
                //        <td style='width:8%;text-align: right; padding-right:30px'><b>Rate</b></td>
                //        <td style='width:10%;text-align: right; padding-right:15px'><b>Amount</b></td>

                if (noOfPages == 1)
                {
                    limit = 15;
                    if (totalRow < limit)
                    {
                        limit = totalRow;
                    }
                }
                else
                {
                    limit = (j * 15);
                    if (totalRow < limit)
                    {
                        limit = totalRow - ((j - 1) * 15);
                    }

                    if (limit > 15)
                    {
                        limit = 15;
                    }
                }

                int i = 1;
                for (; i <= limit; i++)
                {
                    var item = salesInvoiceModel.salesDeliveryDetails[start];
                    start++;
                    sb.AppendFormat(@"<tr Height='42'>
                                    <td style='padding-left:5px; width:1.5%;text-align: right; padding-right:15px'>{0}</td>
                                    <td style='width:66.5%;text-align: left; padding-right:15px'>{1}</td>
                                    <td style='width:7%;text-align: right; padding-right:40px'>{2}</td>
                                    <td style='width:7%;text-align: left; padding-right:20px'>{3}</td>
                                 </tr>",
                                    item.SrNumber, item.FoodMenuName, item.DeliveryQTY.ToString("0.00"), item.UnitName);
                }

                // <td style='width:8%;text-align: right; padding-right:30px'>{4}</td>
                // <td style='width:10%;text-align: right; padding-right:15px'>{5}</td>

                for (; i <= 15; i++)
                {
                    sb.AppendFormat(@"<tr Height='42'>
                                    <td style='padding-left:5px; width:1.5%;text-align: right; padding-right:5px'></td>
                                    <td style='width:58.5%;text-align: left; padding-right:5px'></td>
                                    <td style='width:10%;text-align: right; padding-right:20px'></td>
                                    <td style='width:12%;text-align: left; padding-right:20px'></td>
                                 </tr>");
                }
                //<td style='width:8%;text-align: right; padding-right:20px'></td>
                //<td style='width:10%;text-align: right; padding-right:15px'></td>

                //emplty row
                sb.AppendFormat(@"<table style='border-right:1px solid;border-left:1px solid;border-top:0px' Height='210' width = '1280'><tr></tr></table>");

                /*              string strAmountWord = "", VatableAmount = "", NonVatableAmount = "", TaxAmount = "", TotalAmount = "";
                 *
                 *            if (j == noOfPages)
                 *            {
                 *                strAmountWord = NumberToWords.ConvertAmount((double)salesInvoiceModel.TotalAmount) + " KENYAN SHILLINGS";
                 *
                 *                if (salesInvoiceModel.CustomerTaxInclusive)
                 *                {
                 *                    VatableAmount = salesInvoiceModel.VatableAmount.ToString("0.00");
                 *                    NonVatableAmount = salesInvoiceModel.NonVatableAmount.ToString("0.00");
                 *                    TaxAmount = salesInvoiceModel.TaxAmount.ToString("0.00");
                 *                }
                 *                TotalAmount = salesInvoiceModel.TotalAmount.ToString("0.00");
                 *            }
                 *
                 *            //Reamrks & Totals
                 *            sb.Append(@"<table  style='font-size:22px;border-right:1px solid;border-left:1px solid;border-top:1px solid' width = '1280' Height = '119' >
                 *                    <tr  Height='40'>
                 *                        <td rowspan=2 style='padding-left:5px; width:76%; vertical-align:top; text-align : left;font-size:12px'>
                 *                                <b>Remarks : </b></br>" + salesInvoiceModel.Notes + @"</td>
                 *                        <td style='width:12%;  text-align:right; border-left:1px solid; border-right:1px solid; border-bottom:1px solid; padding-right:15px;font-size:20px'><b>Vatable:</b></td >
                 *                        <td style='width:12%;  text-align:right;; border-bottom:1px solid; padding-right:15px;font-size:20px'><b>" + VatableAmount + @"</b></td>
                 *                    </tr>
                 *                    <tr Height='40'>
                 *                        <td style='width:12%;  text-align:right; border-right:1px solid; border-left:1px solid; border-bottom:1px solid; padding-right:15px;font-size:20px'><b>NON-VAT:</b></td>
                 *                        <td style='width:12%;  text-align:right;; border-bottom:1px solid; padding-right:15px;font-size:20px'><b>" + NonVatableAmount + @"</b></td>
                 *                    </tr>
                 *                    <tr Height='40'>
                 *                        <td rowspan=2><div style='vertical-align:bottom;text-align:left;padding-left:5px; '>" + strAmountWord.ToString().ToUpper() + @"</div></td>
                 *                        <td style='width:12%;  text-align:right; border-right:1px solid; border-left:1px solid; border-bottom:1px solid; padding-right:15px;font-size:20px'><b>VAT Total:</b></td>
                 *                        <td style='width:12%;  text-align:right; border-bottom:1px solid; padding-right:15px;font-size:20px'><b>" + TaxAmount + @"</b></td>
                 *                    </tr>
                 *                    <tr Height='40' style='border:0px'>
                 *                        <td style='width:12%;  text-align:right; border-left:1px solid; border-right:1px solid;; padding-right:15px;font-size:20px'><b>Total</b></td>
                 *                        <td style='width:12%;  text-align:right; padding-right:15px;font-size:20px'><b>" + TotalAmount + @"</b></td>
                 *                    </tr>
                 *                </table>");
                 */
                //Terms and condition
                sb.Append(@"<table style='font-size:20px;border:1px solid; ' width = '1280' Height = '220'>
                            <tr Height='50'>
                                <td colspan='7' style='padding-left:5px; vertical-align:top;'><b>Terms and Conditions: </b>");

                string   strInvoiceTerms = LoginInfo.InvoiceTerms;
                string[] strSplit        = strInvoiceTerms.Split('\n');

                for (i = 0; i < strSplit.Length; i++)
                {
                    sb.Append(@"</br>" + strSplit[i]);
                }

                sb.Append(@"</td>
                        </tr>
                        </table>");

                //emplty row
                sb.AppendFormat(@"<table style='border:0px solid;' Height='40'></table>");

                //logo at header settings
                logoTop = logoTop + 1654 + (j * 14);
            }

            //end of body and html
            sb.Append(@"</body></html>");

            return(sb.ToString());
        }
        public SalesDeliveryModel GetSalesDeliveryReportById(long id)
        {
            SalesDeliveryModel purchaseModel = new SalesDeliveryModel();

            var model = (from purchase in _iSalesDeliveryRepository.GetSalesDeliveryReportById(id).ToList()
                         select new SalesDeliveryModel()
            {
                Id = purchase.Id,
                SalesId = purchase.SalesId,
                ReferenceNo = purchase.ReferenceNo,
                CustomerId = purchase.CustomerId,
                EmployeeId = purchase.EmployeeId,
                StoreId = purchase.StoreId,
                SalesDeliveryDate = purchase.SalesDeliveryDate,
                GrossAmount = purchase.GrossAmount,
                TaxAmount = purchase.TaxAmount,
                TotalAmount = purchase.TotalAmount,
                PaidAmount = purchase.PaidAmount,
                DueAmount = purchase.DueAmount,
                VatableAmount = purchase.VatableAmount,
                NonVatableAmount = purchase.NonVatableAmount,
                DeliveryNoteNumber = purchase.DeliveryNoteNumber,
                DeliveryDate = purchase.DeliveryDate,
                DriverName = purchase.DriverName,
                VehicleNumber = purchase.VehicleNumber,
                Notes = purchase.Notes,
                SOReferenceNo = purchase.SOReferenceNo,
                SODate = purchase.SODate,
                CustomerAddress1 = purchase.CustomerAddress1,
                CustomerAddress2 = purchase.CustomerAddress2,
                CustomerEmail = purchase.CustomerEmail,
                CustomerName = purchase.CustomerName,
                StoreName = purchase.StoreName,
                OutletAddress1 = purchase.OutletAddress1,
                OutletAddress2 = purchase.OutletAddress2,
                OutletPhone = purchase.OutletPhone,
                OutletEmail = purchase.OutletEmail,
                InvoiceHeader = purchase.InvoiceHeader,
                InvoiceFooter = purchase.InvoiceFooter,
                CustomerTaxInclusive = purchase.CustomerTaxInclusive
            }).SingleOrDefault();

            if (model != null)
            {
                model.salesDeliveryDetails = (from purchasedetails in _iSalesDeliveryRepository.GetSalesDeliveryReportFoodMenuDetails(id)
                                              select new SalesDeliveryDetailModel()
                {
                    SrNumber = purchasedetails.SrNumber,
                    SalesDeliveryId = purchasedetails.SalesDeliveryId,
                    IngredientId = purchasedetails.IngredientId,
                    FoodMenuId = purchasedetails.FoodMenuId,
                    SOQTY = purchasedetails.SOQTY,
                    DeliveryQTY = purchasedetails.DeliveryQTY,
                    UnitPrice = purchasedetails.UnitPrice,
                    GrossAmount = purchasedetails.GrossAmount,
                    DiscountPercentage = purchasedetails.DiscountPercentage,
                    DiscountAmount = purchasedetails.DiscountAmount,
                    TaxAmount = purchasedetails.TaxAmount,
                    TotalAmount = purchasedetails.TotalAmount,
                    IngredientName = purchasedetails.IngredientName,
                    FoodMenuName = purchasedetails.FoodMenuName,
                    UnitName = purchasedetails.UnitName
                }).ToList();
            }
            return(model);
        }