Beispiel #1
0
        //public ActionResult ViewPdfReportForSearchResult(int? storeId, int shiftId, DateTime fromDate)
        public ActionResult ViewPdfReportForSearchResult(int storeId, int shiftId, DateTime fromDate)
        {
            try
            {
                var date      = DateTime.Parse(fromDate.ToString());
                var printInfo = string.Format("{0:yyyy-MM-dd}", date);

                //IEnumerable<VM_Product> sellsPointProductList = (from a in unitOfWork.ProductRepository.Get().Where(a => a.ProductTypeId == (int)ProductType.SellTypeProduct || a.ProductTypeId == (int)ProductType.PurchaseAndSellTypeProduct)
                //                                                 select new VM_Product()
                //                                                 {
                //                                                     ProductId = a.ProductId,
                //                                                     ProductName = a.ProductName,
                //                                                     Unit = a.Unit,
                //                                                     UnitPrice = (decimal)a.UnitPrice
                //                                                 }).ToList();



                List <DAL.ViewModel.VM_Product> products;

                string  groupName;
                decimal totalAmount       = 0;
                decimal totalOtherExpense = 0;
                double  netCash           = 0;


                //List<VM_Product> products = new List<VM_Product>();
                if (shiftId == 1)
                {
                    groupName =
                        unitOfWork.GroupAndShiftMappingRepository.Get()
                        .Where(x => x.TransferDate.Value.Date == Convert.ToDateTime(printInfo))
                        .Select(a => a.Day)
                        .FirstOrDefault();
                    //foreach (VM_Product aProduct in sellsPointProductList)
                    //{
                    //    var product =
                    //    unitOfWork.ProductTransferRepository.Get()
                    //        .Where(x => x.ProductId == aProduct.ProductId && x.StoreId == storeId)
                    //        .ToList();



                    //    decimal ProductIn = (decimal)product.Where(x => x.isIn == true && x.TransferDate < fromDate).Select(x => x.Quantity).Sum();
                    //    decimal ProductOut = (decimal)product.Where(x => x.isOut == true && x.TransferDate < fromDate).Select(x => x.Quantity).Sum();

                    //    decimal getProductAvilableQty = ProductIn - ProductOut;
                    //    aProduct.OpeningProduct = getProductAvilableQty;



                    //    decimal issue = (decimal)product.Where(x => x.isIn == true && x.ShiftId == shiftId && x.TransferDate.Value.Date == Convert.ToDateTime(printInfo)).Select(x => x.Quantity).Sum();

                    //    aProduct.InProduct = issue;
                    //    aProduct.TotalProduct = aProduct.OpeningProduct + aProduct.InProduct;


                    //    decimal SellproductSelectDate = (decimal)product.Where(x => x.isOut == true && x.ShiftId == shiftId && x.TransferDate.Value.Date == Convert.ToDateTime(printInfo)).Select(x => x.Quantity).Sum();
                    //    aProduct.SellProduct = SellproductSelectDate;

                    //    aProduct.ClosingProduct = aProduct.TotalProduct - aProduct.SellProduct;

                    //    aProduct.TotalPrice = aProduct.UnitPrice * aProduct.SellProduct;

                    //    totalAmount += aProduct.TotalPrice;

                    //    if (getProductAvilableQty > 0 || issue > 0 || SellproductSelectDate > 0)
                    //    {
                    //        products.Add(aProduct);
                    //    }

                    //}


                    products =
                        unitOfWork.CustomRepository.sp_ProductSellHistoryWithOpeningProductForDayShift(storeId, shiftId, fromDate).ToList();


                    if (products.Any())
                    {
                        totalAmount = products.Select(x => x.TotalPrice).Sum();
                    }
                }

                else
                {
                    groupName =
                        unitOfWork.GroupAndShiftMappingRepository.Get()
                        .Where(x => x.TransferDate.Value.Date == Convert.ToDateTime(printInfo))
                        .Select(a => a.Night)
                        .FirstOrDefault();
                    //foreach (VM_Product aProduct in sellsPointProductList)
                    //{
                    //    var product =
                    //    unitOfWork.ProductTransferRepository.Get()
                    //        .Where(x => x.ProductId == aProduct.ProductId && x.StoreId == storeId)
                    //        .ToList();



                    //    decimal ProductIn = (decimal)product.Where(x => x.isIn == true && x.TransferDate < fromDate).Select(x => x.Quantity).Sum();
                    //    decimal ProductOut = (decimal)product.Where(x => x.isOut == true && x.TransferDate < fromDate).Select(x => x.Quantity).Sum();

                    //    decimal getProductAvilableQty = ProductIn - ProductOut;


                    //    decimal issueForDay = (decimal)product.Where(x => x.isIn == true && x.ShiftId == 1 && x.TransferDate.Value.Date == Convert.ToDateTime(printInfo)).Select(x => x.Quantity).Sum();


                    //    decimal totalProductForDay = getProductAvilableQty + issueForDay;


                    //    decimal SellproductSelectDateForDay = (decimal)product.Where(x => x.isOut == true && x.ShiftId == 1 && x.TransferDate.Value.Date == Convert.ToDateTime(printInfo)).Select(x => x.Quantity).Sum();


                    //    decimal closingProductForDay = totalProductForDay - SellproductSelectDateForDay;


                    //    aProduct.OpeningProduct = closingProductForDay;

                    //    decimal issue = (decimal)product.Where(x => x.isIn == true && x.ShiftId == shiftId && x.TransferDate.Value.Date == Convert.ToDateTime(printInfo)).Select(x => x.Quantity).Sum();

                    //    aProduct.InProduct = issue;
                    //    aProduct.TotalProduct = aProduct.OpeningProduct + aProduct.InProduct;


                    //    decimal SellproductSelectDate = (decimal)product.Where(x => x.isOut == true && x.ShiftId == shiftId && x.TransferDate.Value.Date == Convert.ToDateTime(printInfo)).Select(x => x.Quantity).Sum();
                    //    aProduct.SellProduct = SellproductSelectDate;

                    //    aProduct.ClosingProduct = aProduct.TotalProduct - aProduct.SellProduct;

                    //    aProduct.TotalPrice = aProduct.UnitPrice * aProduct.SellProduct;

                    //    totalAmount += aProduct.TotalPrice;

                    //    if (closingProductForDay > 0 || issue > 0 || SellproductSelectDate > 0)
                    //    {
                    //        products.Add(aProduct);
                    //    }

                    //}

                    products =
                        unitOfWork.CustomRepository.sp_ProductSellHistoryWithOpeningProductForNightShift(storeId, shiftId, fromDate).ToList();


                    if (products.Any())
                    {
                        totalAmount = products.Select(x => x.TotalPrice).Sum();
                    }
                }

                //decimal less = (decimal)
                //   unitOfWork.OtherExpenseRepository.Get()
                //       .Where(
                //           x =>
                //               x.StoreId == storeId  && x.ShiftId == shiftId &&
                //               x.TransferDate.Value.Date == Convert.ToDateTime(printInfo))
                //       .Select(x => x.Less)
                //       .Sum();
                //decimal due = (decimal)
                //   unitOfWork.OtherExpenseRepository.Get()
                //       .Where(
                //           x =>
                //               x.StoreId == storeId  && x.ShiftId == shiftId &&
                //               x.TransferDate.Value.Date == Convert.ToDateTime(printInfo))
                //       .Select(x => x.Due)
                //       .Sum();
                //decimal complimen = (decimal)
                //   unitOfWork.OtherExpenseRepository.Get()
                //       .Where(
                //           x =>
                //               x.StoreId == storeId  && x.ShiftId == shiftId &&
                //               x.TransferDate.Value.Date == Convert.ToDateTime(printInfo))
                //       .Select(x => x.Compliment)
                //       .Sum();
                //decimal damage = (decimal)
                //   unitOfWork.OtherExpenseRepository.Get()
                //       .Where(
                //           x =>
                //               x.StoreId == storeId  && x.ShiftId == shiftId &&
                //               x.TransferDate.Value.Date == Convert.ToDateTime(printInfo))
                //       .Select(x => x.Damage)
                //       .Sum();



                decimal less =
                    unitOfWork.CustomRepository.sp_OtherExpenseAmountForSellReportWithOpeningProduct(storeId, shiftId,
                                                                                                     fromDate).Select(a => a.Less).FirstOrDefault();
                decimal due =
                    unitOfWork.CustomRepository.sp_OtherExpenseAmountForSellReportWithOpeningProduct(storeId, shiftId,
                                                                                                     fromDate).Select(a => a.Due).FirstOrDefault();
                decimal complimen =
                    unitOfWork.CustomRepository.sp_OtherExpenseAmountForSellReportWithOpeningProduct(storeId, shiftId,
                                                                                                     fromDate).Select(a => a.Compliment).FirstOrDefault();
                decimal damage =
                    unitOfWork.CustomRepository.sp_OtherExpenseAmountForSellReportWithOpeningProduct(storeId, shiftId,
                                                                                                     fromDate).Select(a => a.Damage).FirstOrDefault();



                totalOtherExpense = less + due + complimen + damage;

                netCash = (double)(totalAmount - totalOtherExpense);


                int    restaurantId      = Int32.Parse(SessionManger.RestaurantOfLoggedInUser(Session).ToString());
                string restaurantName    = unitOfWork.RestaurantRepository.GetByID(restaurantId).Name;
                string restaurantAddress = unitOfWork.RestaurantRepository.GetByID(restaurantId).Address;
                string storeName         = unitOfWork.StoreRepository.GetByID(storeId).store_name;
                //string groupName = unitOfWork.GroupForShiftRepository.GetByID(groupId).GroupName;
                string shiftName = unitOfWork.ShiftRepository.GetByID(shiftId).ShiftName;

                LocalReport localReport = new LocalReport();
                localReport.ReportPath = Server.MapPath("~/Reports/ProductSellHistoryWithOpeningProductReport.rdlc");
                //localReport.SetParameters(new ReportParameter("Date", fromDate.ToString()));
                localReport.SetParameters(new ReportParameter("Date", printInfo));
                localReport.SetParameters(new ReportParameter("StoreName", storeName.ToString()));
                localReport.SetParameters(new ReportParameter("RestaurantName", restaurantName));
                localReport.SetParameters(new ReportParameter("RestaurantAddress", restaurantAddress));
                localReport.SetParameters(new ReportParameter("GroupName", groupName));
                localReport.SetParameters(new ReportParameter("ShiftName", shiftName));
                localReport.SetParameters(new ReportParameter("Less", less.ToString()));
                localReport.SetParameters(new ReportParameter("Due", due.ToString()));
                localReport.SetParameters(new ReportParameter("Complimen", complimen.ToString()));
                localReport.SetParameters(new ReportParameter("Damage", damage.ToString()));
                localReport.SetParameters(new ReportParameter("TotalOtherExpense", totalOtherExpense.ToString()));
                localReport.SetParameters(new ReportParameter("NetCash", netCash.ToString()));
                ReportDataSource reportDataSource = new ReportDataSource("ProductSellHistoryWithOpeningProductDataSet", products);

                localReport.DataSources.Add(reportDataSource);
                string reportType = "pdf";
                string mimeType;
                string encoding;
                string fileNameExtension;
                //The DeviceInfo settings should be changed based on the reportType
                //http://msdn.microsoft.com/en-us/library/ms155397.aspx
                string deviceInfo =
                    "<DeviceInfo>" +
                    "  <OutputFormat>PDF</OutputFormat>" +
                    "  <PageWidth>8.5in</PageWidth>" +
                    "  <PageHeight>11in</PageHeight>" +
                    "  <MarginTop>0.5in</MarginTop>" +
                    "  <MarginLeft>0in</MarginLeft>" +
                    "  <MarginRight>0in</MarginRight>" +
                    "  <MarginBottom>0.5in</MarginBottom>" +
                    "</DeviceInfo>";

                Warning[] warnings;
                string[]  streams;
                byte[]    renderedBytes;

                //Render the report
                renderedBytes = localReport.Render(
                    reportType,
                    deviceInfo,
                    out mimeType,
                    out encoding,
                    out fileNameExtension,
                    out streams,
                    out warnings);
                return(File(renderedBytes, mimeType));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, errorMessage = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult ViewPdfReportForSearchResult(int sellsPointStoreId, string fromDate, string toDate, int shiftId)
        {
            try
            {
                List <DAL.ViewModel.VM_Product> productList = unitOfWork.CustomRepository.spSearchProductEntryHistoryInSellsPoint(Convert.ToDateTime(fromDate), Convert.ToDateTime(toDate),
                                                                                                                                  sellsPointStoreId, shiftId);
                var newProductList = new List <VM_Product>();
                int serial         = 0;
                foreach (var product in productList)
                {
                    VM_Product newProduct = new VM_Product();
                    newProduct.Serial          = ++serial;
                    newProduct.ProductName     = product.ProductName;
                    newProduct.ProductTypeName = product.ProductTypeName;
                    newProduct.UnitPrice       = product.UnitPrice;
                    newProduct.Quantity        = product.Quantity;
                    newProduct.Unit            = product.Unit;
                    newProduct.TotalPrice      = product.TotalPrice;
                    newProductList.Add(newProduct);
                }

                int         restaurantId      = Int32.Parse(SessionManger.RestaurantOfLoggedInUser(Session).ToString());;
                string      restaurantName    = unitOfWork.RestaurantRepository.GetByID(restaurantId).Name;
                string      restaurantAddress = unitOfWork.RestaurantRepository.GetByID(restaurantId).Address;
                string      sellsPointName    = unitOfWork.StoreRepository.GetByID(sellsPointStoreId).store_name;
                string      shiftName         = unitOfWork.ShiftRepository.GetByID(shiftId).ShiftName;
                LocalReport localReport       = new LocalReport();
                localReport.ReportPath = Server.MapPath("~/Reports/ProductEntryHistoryInSellPointReport.rdlc");
                localReport.SetParameters(new ReportParameter("FromDate", fromDate.ToString()));
                localReport.SetParameters(new ReportParameter("ToDate", toDate.ToString()));
                localReport.SetParameters(new ReportParameter("ShiftName", shiftName));
                localReport.SetParameters(new ReportParameter("SellsPointName", sellsPointName));
                localReport.SetParameters(new ReportParameter("RestaurantName", restaurantName));
                localReport.SetParameters(new ReportParameter("RestaurantAddress", restaurantAddress));
                ReportDataSource reportDataSource = new ReportDataSource("ProductEntryHistoryInSellPointDataSet", newProductList);

                localReport.DataSources.Add(reportDataSource);
                string reportType = "pdf";
                string mimeType;
                string encoding;
                string fileNameExtension;
                //The DeviceInfo settings should be changed based on the reportType
                //http://msdn.microsoft.com/en-us/library/ms155397.aspx
                string deviceInfo =
                    "<DeviceInfo>" +
                    "  <OutputFormat>PDF</OutputFormat>" +
                    "  <PageWidth>8.5in</PageWidth>" +
                    "  <PageHeight>11in</PageHeight>" +
                    "  <MarginTop>0.5in</MarginTop>" +
                    "  <MarginLeft>0in</MarginLeft>" +
                    "  <MarginRight>0in</MarginRight>" +
                    "  <MarginBottom>0.5in</MarginBottom>" +
                    "</DeviceInfo>";

                Warning[] warnings;
                string[]  streams;
                byte[]    renderedBytes;

                //Render the report
                renderedBytes = localReport.Render(
                    reportType,
                    deviceInfo,
                    out mimeType,
                    out encoding,
                    out fileNameExtension,
                    out streams,
                    out warnings);
                return(File(renderedBytes, mimeType));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, errorMessage = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
        //public JsonResult SaveProductToSellPoint(int SellsPointId, int ProductionHouseStoreId,int shiftId,DateTime fromDate, List<VM_PHtoSPProductTransfer> productList)
        public JsonResult SaveProductToSellPoint(int SellsPointId, int ProductionHouseStoreId, int shiftId, List <VM_PHtoSPProductTransfer> productList)
        {
            try
            {
                var productionHouse = unitOfWork.ProductionHouseInformationRepository.Get().Where(x => x.OwnStore == ProductionHouseStoreId).FirstOrDefault();
                //var mainStore = unitOfWork.StoreRepository.Get().Where(x => x.is_mainStore == true && x.store_id == ProductionHouseStoreId && x.store_id!=2).First();
                var SellsPoint = unitOfWork.SellsPointRepository.Get().Where(x => x.SellsPointStoreId == SellsPointId).FirstOrDefault();


                if (productionHouse != null)
                {
                    foreach (VM_PHtoSPProductTransfer vmProduct in productList)
                    {
                        using (TransactionScope scope = new TransactionScope())
                        {
                            tblPHtoSPProductTransfer aProduct = new tblPHtoSPProductTransfer();
                            aProduct.SellsPointId      = SellsPoint.SellsPointId;
                            aProduct.ProductionHouseId = productionHouse.ProductionHouseId;
                            //aProduct.GroupId = groupId;
                            aProduct.ShiftId = shiftId;
                            //aProduct.TransferDate = fromDate;
                            aProduct.TransferDate    = DateTime.Now;
                            aProduct.ProductId       = vmProduct.ProductId;
                            aProduct.Quantity        = (decimal)vmProduct.Quantity;
                            aProduct.Unit            = vmProduct.Unit;
                            aProduct.isIn            = true;
                            aProduct.RestaurantId    = int.Parse(SessionManger.RestaurantOfLoggedInUser(Session).ToString());
                            aProduct.CreatedBy       = SessionManger.LoggedInUser(Session);
                            aProduct.CreatedDateTime = DateTime.Now;
                            aProduct.EditedBy        = null;
                            aProduct.EditedDateTime  = null;
                            unitOfWork.PHToSPProductTransferRepository.Insert(aProduct);
                            unitOfWork.Save();


                            tblProductTransfer product = new tblProductTransfer();
                            product.StoreId = ProductionHouseStoreId;
                            //product.GroupId = groupId;
                            product.ShiftId = shiftId;
                            //product.TransferDate = fromDate;
                            product.TransferDate    = DateTime.Now;
                            product.ProductId       = vmProduct.ProductId;
                            product.Quantity        = (decimal)vmProduct.Quantity;
                            product.Unit            = vmProduct.Unit;
                            product.isOut           = true;
                            product.CreatedBy       = SessionManger.LoggedInUser(Session);
                            product.CreatedDateTime = DateTime.Now;
                            product.EditedBy        = null;
                            product.EditedDateTime  = null;
                            unitOfWork.ProductTransferRepository.Insert(product);
                            unitOfWork.Save();

                            tblProductTransfer product2 = new tblProductTransfer();
                            product2.StoreId = SellsPointId;
                            //product2.GroupId = groupId;
                            product2.ShiftId = shiftId;
                            //product2.TransferDate = fromDate;
                            product2.TransferDate    = DateTime.Now;
                            product2.ProductId       = vmProduct.ProductId;
                            product2.Quantity        = (decimal)vmProduct.Quantity;
                            product2.Unit            = vmProduct.Unit;
                            product2.isIn            = true;
                            product2.CreatedBy       = SessionManger.LoggedInUser(Session);
                            product2.CreatedDateTime = DateTime.Now;
                            product2.EditedBy        = null;
                            product2.EditedDateTime  = null;
                            unitOfWork.ProductTransferRepository.Insert(product2);
                            unitOfWork.Save();
                            scope.Complete();
                        }
                    }
                }

                else
                {
                    foreach (VM_PHtoSPProductTransfer vmProduct in productList)
                    {
                        using (TransactionScope scope = new TransactionScope())
                        {
                            tblPHtoSPProductTransfer aProduct = new tblPHtoSPProductTransfer();
                            aProduct.SellsPointId      = SellsPoint.SellsPointId;
                            aProduct.ProductionHouseId = null;
                            //aProduct.GroupId = groupId;
                            aProduct.ShiftId = shiftId;
                            //aProduct.TransferDate = fromDate;
                            aProduct.TransferDate    = DateTime.Now;
                            aProduct.ProductId       = vmProduct.ProductId;
                            aProduct.Quantity        = (decimal)vmProduct.Quantity;
                            aProduct.Unit            = vmProduct.Unit;
                            aProduct.isIn            = true;
                            aProduct.RestaurantId    = int.Parse(SessionManger.RestaurantOfLoggedInUser(Session).ToString());
                            aProduct.CreatedBy       = SessionManger.LoggedInUser(Session);
                            aProduct.CreatedDateTime = DateTime.Now;
                            aProduct.EditedBy        = null;
                            aProduct.EditedDateTime  = null;
                            unitOfWork.PHToSPProductTransferRepository.Insert(aProduct);
                            unitOfWork.Save();


                            tblProductTransfer product = new tblProductTransfer();
                            product.StoreId = ProductionHouseStoreId;
                            //product.GroupId = groupId;
                            product.ShiftId = shiftId;
                            //product.TransferDate = fromDate;
                            product.TransferDate    = DateTime.Now;
                            product.ProductId       = vmProduct.ProductId;
                            product.Quantity        = (decimal)vmProduct.Quantity;
                            product.Unit            = vmProduct.Unit;
                            product.isOut           = true;
                            product.CreatedBy       = SessionManger.LoggedInUser(Session);
                            product.CreatedDateTime = DateTime.Now;
                            product.EditedBy        = null;
                            product.EditedDateTime  = null;
                            unitOfWork.ProductTransferRepository.Insert(product);
                            unitOfWork.Save();

                            tblProductTransfer product2 = new tblProductTransfer();
                            product2.StoreId = SellsPointId;
                            //product2.GroupId = groupId;
                            product2.ShiftId = shiftId;
                            //product2.TransferDate = fromDate;
                            product2.TransferDate    = DateTime.Now;
                            product2.ProductId       = vmProduct.ProductId;
                            product2.Quantity        = (decimal)vmProduct.Quantity;
                            product2.Unit            = vmProduct.Unit;
                            product2.isIn            = true;
                            product2.CreatedBy       = SessionManger.LoggedInUser(Session);
                            product2.CreatedDateTime = DateTime.Now;
                            product2.EditedBy        = null;
                            product2.EditedDateTime  = null;
                            unitOfWork.ProductTransferRepository.Insert(product2);
                            unitOfWork.Save();
                            scope.Complete();
                        }
                    }
                }

                this.ProductionHouseToSellsPointReport(Convert.ToInt32(SellsPointId), Convert.ToInt32(ProductionHouseStoreId), productList);
                //unitOfWork.Save();
                return(Json(new { success = true, successMessage = " Successfully Added" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception exception)
            {
                return(Json(new { success = false, errorMessage = exception.Message }, JsonRequestBehavior.AllowGet));
            }
        }
        private void ProductionHouseToSellsPointReport(int SellsPointId, int ProductionHouseStoreId, List <VM_PHtoSPProductTransfer> productList)
        {
            var newProductList = new List <VM_PHtoSPProductTransfer>();
            int serial         = 0;

            foreach (var product in productList)
            {
                VM_PHtoSPProductTransfer newProduct = new VM_PHtoSPProductTransfer();
                newProduct.SL          = ++serial;
                newProduct.ProductName = unitOfWork.ProductRepository.GetByID(product.ProductId).ProductName;;
                newProduct.Quantity    = product.Quantity;
                newProduct.Unit        = product.Unit;
                newProduct.ProductionHouseStoreName =
                    unitOfWork.StoreRepository.GetByID(ProductionHouseStoreId).store_name;

                newProduct.SellsPointName = unitOfWork.StoreRepository.GetByID(SellsPointId).store_name;
                newProductList.Add(newProduct);
            }

            int    restaurantId      = Int32.Parse(SessionManger.RestaurantOfLoggedInUser(Session).ToString());;
            string restaurantName    = unitOfWork.RestaurantRepository.GetByID(restaurantId).Name;
            string restaurantAddress = unitOfWork.RestaurantRepository.GetByID(restaurantId).Address;

            LocalReport localReport = new LocalReport();

            localReport.ReportPath = Server.MapPath("~/Reports/ProductionHouseToSellPointReport.rdlc");
            localReport.SetParameters(new ReportParameter("RestaurantName", restaurantName));
            localReport.SetParameters(new ReportParameter("RestaurantAddress", restaurantAddress));
            ReportDataSource reportDataSource = new ReportDataSource("ProductionHouseToSellPointReport", newProductList);

            localReport.DataSources.Add(reportDataSource);
            string reportType = "pdf";
            string mimeType;
            string encoding;
            string fileNameExtension;
            //The DeviceInfo settings should be changed based on the reportType
            //http://msdn.microsoft.com/en-us/library/ms155397.aspx
            string deviceInfo =
                "<DeviceInfo>" +
                "  <OutputFormat>PDF</OutputFormat>" +
                "  <PageWidth>8.5in</PageWidth>" +
                "  <PageHeight>11in</PageHeight>" +
                "  <MarginTop>0.5in</MarginTop>" +
                "  <MarginLeft>0in</MarginLeft>" +
                "  <MarginRight>0in</MarginRight>" +
                "  <MarginBottom>0.5in</MarginBottom>" +
                "</DeviceInfo>";

            Warning[] warnings;
            string[]  streams;
            byte[]    renderedBytes;



            //Render the report
            renderedBytes = localReport.Render(
                reportType,
                deviceInfo,
                out mimeType,
                out encoding,
                out fileNameExtension,
                out streams,
                out warnings);
            //rename file
            var fileName = RenameReportFile(ProductionHouseStoreId, SellsPointId, DateTime.Now, "Pro", "Sell");

            var path = System.IO.Path.Combine(Server.MapPath("~/pdfReport"));


            var saveAs = path + "\\" + fileName + ".pdf";

            var idx = 0;

            while (System.IO.File.Exists(saveAs))
            {
                idx++;
                saveAs = string.Format("{0}.{1}.pdf", Path.Combine(path, fileName), idx);
            }

            using (var stream = new FileStream(saveAs, FileMode.Create, FileAccess.Write))
            {
                stream.Write(renderedBytes, 0, renderedBytes.Length);
                stream.Close();
            }
            var report = new tblChalanReport();

            report.FromStore  = Convert.ToString(ProductionHouseStoreId);
            report.ToStore    = Convert.ToString(SellsPointId);
            report.Date       = DateTime.Now.Date;
            report.ReportName = fileName;

            SaveToDatabase(report);

            localReport.Dispose();
        }
Beispiel #5
0
        //public ActionResult ViewPdfReportForSearchResult(int? storeId)
        public ActionResult ViewPdfReportForSearchResult(int storeId)
        {
            //IEnumerable<VM_Product> sellsPointProductList = (from a in unitOfWork.ProductRepository.Get().Where(a => a.ProductTypeId == (int)ProductType.SellTypeProduct || a.ProductTypeId == (int)ProductType.PurchaseAndSellTypeProduct)
            //                                                 select new VM_Product()
            //                                                 {
            //                                                     ProductId = a.ProductId,
            //                                                     ProductName = a.ProductName,
            //                                                     Unit = a.Unit,
            //                                                     UnitPrice = (decimal)a.UnitPrice
            //                                                 }).ToList();
            try
            {
                decimal totalAmount = 0;
                //List<VM_Product> products = new List<VM_Product>();
                //foreach (VM_Product aProduct in sellsPointProductList)
                //{
                //    var product =
                //    unitOfWork.ProductTransferRepository.Get()
                //        .Where(x => x.ProductId == aProduct.ProductId && x.StoreId == storeId)
                //        .ToList();

                //    decimal ProductIn = (decimal)product.Where(x => x.isIn == true).Select(x => x.Quantity).Sum();
                //    decimal ProductOut = (decimal)product.Where(x => x.isOut == true).Select(x => x.Quantity).Sum();


                //    decimal getProductAvilableQty = ProductIn - ProductOut;
                //    if (getProductAvilableQty > 0)
                //    {
                //        aProduct.Quantity = getProductAvilableQty;
                //        aProduct.TotalPrice = aProduct.UnitPrice*getProductAvilableQty;
                //        totalAmount += aProduct.TotalPrice;
                //        products.Add(aProduct);
                //    }
                //}

                //DateTime today = DateTime.Now;

                //var dateToday = DateTime.Parse(today.ToString());
                //var date = string.Format("{0:yyyy-MM-dd}", dateToday);

                //List<DAL.ViewModel.VM_Product> products = unitOfWork.CustomRepository.sp_SellPointProductStatus(storeId, Convert.ToDateTime(date)).ToList();
                List <DAL.ViewModel.VM_Product> products = unitOfWork.CustomRepository.sp_SellPointProductStatus(storeId).ToList();



                string storeName         = unitOfWork.StoreRepository.GetByID(storeId).store_name;
                int    restaurantId      = Int32.Parse(SessionManger.RestaurantOfLoggedInUser(Session).ToString());;
                string restaurantName    = unitOfWork.RestaurantRepository.GetByID(restaurantId).Name;
                string restaurantAddress = unitOfWork.RestaurantRepository.GetByID(restaurantId).Address;

                LocalReport localReport = new LocalReport();
                localReport.ReportPath = Server.MapPath("~/Reports/SellsPointStatusReport.rdlc");
                localReport.SetParameters(new ReportParameter("StoreName", storeName));
                localReport.SetParameters(new ReportParameter("RestaurantName", restaurantName));
                localReport.SetParameters(new ReportParameter("RestaurantAddress", restaurantAddress));
                ReportDataSource reportDataSource = new ReportDataSource("SellsPointStatusDataSet", products);

                localReport.DataSources.Add(reportDataSource);
                string reportType = "pdf";
                string mimeType;
                string encoding;
                string fileNameExtension;
                //The DeviceInfo settings should be changed based on the reportType
                //http://msdn.microsoft.com/en-us/library/ms155397.aspx
                string deviceInfo =
                    "<DeviceInfo>" +
                    "  <OutputFormat>PDF</OutputFormat>" +
                    "  <PageWidth>8.5in</PageWidth>" +
                    "  <PageHeight>11in</PageHeight>" +
                    "  <MarginTop>0.5in</MarginTop>" +
                    "  <MarginLeft>0in</MarginLeft>" +
                    "  <MarginRight>0in</MarginRight>" +
                    "  <MarginBottom>0.5in</MarginBottom>" +
                    "</DeviceInfo>";

                Warning[] warnings;
                string[]  streams;
                byte[]    renderedBytes;

                //Render the report
                renderedBytes = localReport.Render(
                    reportType,
                    deviceInfo,
                    out mimeType,
                    out encoding,
                    out fileNameExtension,
                    out streams,
                    out warnings);
                return(File(renderedBytes, mimeType));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, errorMessage = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
        //public JsonResult AddSoldProductInfoToProductTransfer(int storeId, int shiftId, DateTime fromDate, List<VM_ProductSold> productsoldList)
        public JsonResult AddSoldProductInfoToProductTransfer(int storeId, int shiftId, List <VM_ProductSold> productsoldList)
        {
            try
            {
                foreach (var productsold in productsoldList)
                {
                    using (TransactionScope scope = new TransactionScope())
                    {
                        tblProductTransfer productTransfer = new tblProductTransfer();
                        productTransfer.StoreId = storeId;
                        //productTransfer.GroupId = groupId;
                        productTransfer.ShiftId = shiftId;
                        //productTransfer.TransferDate = fromDate;
                        productTransfer.TransferDate    = DateTime.Now;
                        productTransfer.ProductId       = productsold.ProductId;
                        productTransfer.Quantity        = productsold.Quantity;
                        productTransfer.Unit            = unitOfWork.ProductRepository.GetByID(productsold.ProductId).Unit;
                        productTransfer.UnitPrice       = unitOfWork.ProductRepository.GetByID(productsold.ProductId).UnitPrice;
                        productTransfer.isOut           = true;
                        productTransfer.DateTime        = DateTime.Now;
                        productTransfer.CreatedBy       = SessionManger.LoggedInUser(Session);
                        productTransfer.EditedBy        = null;
                        productTransfer.RestaurantId    = Int32.Parse(SessionManger.RestaurantOfLoggedInUser(Session).ToString());
                        productTransfer.CreatedDateTime = DateTime.Now;
                        unitOfWork.ProductTransferRepository.Insert(productTransfer);
                        unitOfWork.Save();



                        //add product to productSold table

                        tblProductSold productSold = new tblProductSold();

                        productSold.StoreId = storeId;
                        //productSold.GroupId = groupId;
                        productSold.ShiftId = shiftId;
                        //productSold.TransferDate = fromDate;
                        productSold.TransferDate    = DateTime.Now;
                        productSold.ProductId       = productsold.ProductId;
                        productSold.Quantity        = productsold.Quantity;
                        productSold.Unit            = unitOfWork.ProductRepository.GetByID(productsold.ProductId).Unit;
                        productSold.UnitPrice       = unitOfWork.ProductRepository.GetByID(productsold.ProductId).UnitPrice;
                        productSold.DateTime        = DateTime.Now;
                        productSold.CreatedBy       = SessionManger.LoggedInUser(Session);
                        productSold.EditedBy        = null;
                        productSold.RestaurantId    = Int32.Parse(SessionManger.RestaurantOfLoggedInUser(Session).ToString());
                        productSold.CreatedDateTime = DateTime.Now;
                        unitOfWork.ProductSoldRepository.Insert(productSold);
                        unitOfWork.Save();


                        if (shiftId == 1)
                        {
                            unitOfWork.CustomRepository.sp_InsertTotalAmountDailyByShiftWise();
                        }
                        else
                        {
                            unitOfWork.CustomRepository.sp_InsertTotalAmountDailyForNightShift();
                        }

                        scope.Complete();
                    }
                }
                return(Json(new { success = true, successMessage = "Product Sold" }));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, errorMessage = ex.Message }, JsonRequestBehavior.AllowGet));
            }
            //return Json(new { success = true, successMessage = "Product Sold" });
        }
Beispiel #7
0
        public JsonResult GenerateReportForSearchResult(int supplierId, DateTime fromDate, DateTime toDate)
        {
            try
            {
                List <DAL.ViewModel.VM_Product> productList = unitOfWork.CustomRepository.sp_ProductEntryHistoryFromSupplierToMainStore(fromDate, toDate,
                                                                                                                                        supplierId);
                decimal totalAmount    = 0;
                var     newProductList = new List <VM_Product>();
                foreach (var product in productList)
                {
                    VM_Product newProduct = new VM_Product();
                    newProduct.ProductName = product.ProductName;
                    newProduct.UnitPrice   = product.UnitPrice;
                    newProduct.Quantity    = product.Quantity;
                    newProduct.TotalPrice  = product.TotalPrice;
                    newProductList.Add(newProduct);
                }
                totalAmount = productList.Select(s => s.TotalPrice).Sum();
                string supplierName      = unitOfWork.SuppliersInformationRepository.GetByID(supplierId).SupplierName;
                int    restaurantId      = Int32.Parse(SessionManger.RestaurantOfLoggedInUser(Session).ToString());;
                string restaurantName    = unitOfWork.RestaurantRepository.GetByID(restaurantId).Name;
                string restaurantAddress = unitOfWork.RestaurantRepository.GetByID(restaurantId).Address;

                LocalReport localReport = new LocalReport();
                localReport.ReportPath = Server.MapPath("~/Reports/ProductEntryHistoryFromSupplierToMainStoreReport.rdlc");
                localReport.SetParameters(new ReportParameter("FromDate", fromDate.ToString()));
                localReport.SetParameters(new ReportParameter("ToDate", toDate.ToString()));
                localReport.SetParameters(new ReportParameter("SupplierName", supplierName));
                localReport.SetParameters(new ReportParameter("RestaurantName", restaurantName));
                localReport.SetParameters(new ReportParameter("RestaurantAddress", restaurantAddress));
                ReportDataSource reportDataSource = new ReportDataSource("ProductEntryHistoryFromSupplierToMainStoreDataSet", newProductList);

                localReport.DataSources.Add(reportDataSource);
                string reportType = "pdf";
                string mimeType;
                string encoding;
                string fileNameExtension;
                //The DeviceInfo settings should be changed based on the reportType
                //http://msdn.microsoft.com/en-us/library/ms155397.aspx
                string deviceInfo =
                    "<DeviceInfo>" +
                    "  <OutputFormat>PDF</OutputFormat>" +
                    "  <PageWidth>8.5in</PageWidth>" +
                    "  <PageHeight>11in</PageHeight>" +
                    "  <MarginTop>0.5in</MarginTop>" +
                    "  <MarginLeft>0in</MarginLeft>" +
                    "  <MarginRight>0in</MarginRight>" +
                    "  <MarginBottom>0.5in</MarginBottom>" +
                    "</DeviceInfo>";
                Warning[] warnings;
                string[]  streams;
                byte[]    renderedBytes;
                //Render the report
                renderedBytes = localReport.Render(
                    reportType,
                    deviceInfo,
                    out mimeType,
                    out encoding,
                    out fileNameExtension,
                    out streams,
                    out warnings);
                var path   = System.IO.Path.Combine(Server.MapPath("~/pdfReport"));
                var saveAs = string.Format("{0}.pdf", Path.Combine(path, "myfilename"));

                var idx = 0;
                while (System.IO.File.Exists(saveAs))
                {
                    idx++;
                    saveAs = string.Format("{0}.{1}.pdf", Path.Combine(path, "myfilename"), idx);
                }
                Session["report"] = saveAs;
                using (var stream = new FileStream(saveAs, FileMode.Create, FileAccess.Write))
                {
                    stream.Write(renderedBytes, 0, renderedBytes.Length);
                    stream.Close();
                }
                localReport.Dispose();
                return(Json(new { success = true, successMessage = "Product Report generated.", result = productList, TotalAmount = totalAmount }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, errorMessage = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #8
0
        //[ValidateAntiForgeryToken]
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var results = await UserManager.FindByNameAsync(model.UserName);

                if (results != null)
                {
                    return(Json(new { success = false, errorMessage = "This User Name already exists" }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    // Create User
                    var user = new ApplicationUser()
                    {
                        UserName = model.UserName, Email = model.Email, PhoneNumber = model.PhoneNumber
                    };
                    var result = await UserManager.CreateAsync(user, model.Password);

                    RestaurantEntities RestaurantCal = new RestaurantEntities();
                    AspNetUser         anu           = new AspNetUser();

                    //AspNetUser userId = RestaurantCal.AspNetRoles.Select(a => a.Name == model.UserName).FirstOrDefault();
                    AspNetUser searchUser   = RestaurantCal.AspNetUsers.Where(a => a.UserName == model.UserName).FirstOrDefault();
                    decimal    restaurentId = SessionManger.RestaurantOfLoggedInUser(Session);
                    if (result.Succeeded)
                    {
                        using (RestaurantEntities rc = new RestaurantEntities())
                        {
                            try
                            {
                                tblRestaurantUser RestaurantUser = new tblRestaurantUser();


                                RestaurantUser.UserId          = searchUser.Id;
                                RestaurantUser.restaurant_id   = restaurentId;
                                RestaurantUser.RestaurantId    = Int32.Parse(SessionManger.RestaurantOfLoggedInUser(Session).ToString());
                                RestaurantUser.CreatedBy       = SessionManger.LoggedInUser(Session);
                                RestaurantUser.CreatedDateTime = DateTime.Now;
                                RestaurantUser.EditedBy        = null;
                                RestaurantUser.EditedDateTime  = null;
                                // RestaurantUser.is_admin = 0;
                                //RestaurantUser.is_loggedIn = null;
                                //RestaurantUser.last_logged_time = null;
                                //RestaurantUser.approve_by = null;
                                //RestaurantUser.approve_date = null;
                                rc.tblRestaurantUsers.Add(RestaurantUser);
                                rc.SaveChanges();

                                return(Json(new { success = true, successMessage = "User has created Successfully." }));
                            }
                            catch (Exception)
                            {
                                throw;
                            }
                        }
                    }
                    else
                    {
                        return(Json(new { success = false, errorMessage = "This Email has already taken." }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            else
            {
                return(Json(new { success = false, errorMessage = "Model is not Valid." }, JsonRequestBehavior.AllowGet));
            }


            return(View(model));
        }
        public ActionResult ViewPdfReportForVoucher(int?VoucherID)
        {
            try
            {
                var VoucherDetailsList = unitOfWork.AccVoucherDetailsRepository.Get().Where(a => a.VoucherID == VoucherID).Select(s => new VM_AccVoucher()
                {
                    VoucherDetailID = s.VoucherDetailID.ToString(),
                    VoucherID       = s.VoucherID,
                    LedgerID        = s.LedgerID.ToString(),
                    LedgerName      = s.acc_Ledger.LedgerName,
                    Debit           = (double)s.Debit,
                    Credit          = (double)s.Credit,
                    ChequeNumber    = s.ChequeNumber,
                    TransactionDate = s.TransactionDate.ToString(),
                    VTypeID         = (int)s.VTypeID,
                    OCode           = (int)s.OCode,
                    RestaurantId    = (int)s.RestaurantId,
                    CreatedBy       = s.CreatedBy,
                    CreatedDateTime = s.CreatedDateTime.ToString(),
                    EditedBy        = s.EditedBy,
                    EditedDateTime  = s.EditedDateTime.ToString()
                }).ToList();
                string VNumber         = unitOfWork.AccVoucherEntryRepository.GetByID(VoucherID).VNumber;
                string VoucherName     = unitOfWork.AccVoucherEntryRepository.GetByID(VoucherID).VoucherName;
                string transactionDate =
                    unitOfWork.AccVoucherEntryRepository.GetByID(VoucherID).TransactionDate.ToString();
                int    restaurantId      = Int32.Parse(SessionManger.RestaurantOfLoggedInUser(Session).ToString());;
                string restaurantName    = unitOfWork.RestaurantRepository.GetByID(restaurantId).Name;
                string restaurantAddress = unitOfWork.RestaurantRepository.GetByID(restaurantId).Address;

                LocalReport localReport = new LocalReport();
                localReport.ReportPath = Server.MapPath("~/Reports/VoucherReport.rdlc");
                localReport.SetParameters(new ReportParameter("VNumber", VNumber));
                localReport.SetParameters(new ReportParameter("VoucherName", VoucherName));
                localReport.SetParameters(new ReportParameter("TransactionDate", transactionDate));
                localReport.SetParameters(new ReportParameter("RestaurantName", restaurantName));
                localReport.SetParameters(new ReportParameter("RestaurantAddress", restaurantAddress));
                ReportDataSource reportDataSource = new ReportDataSource("VoucherDataSet", VoucherDetailsList);

                localReport.DataSources.Add(reportDataSource);
                string reportType = "pdf";
                string mimeType;
                string encoding;
                string fileNameExtension;
                //The DeviceInfo settings should be changed based on the reportType
                //http://msdn.microsoft.com/en-us/library/ms155397.aspx
                string deviceInfo =
                    "<DeviceInfo>" +
                    "  <OutputFormat>PDF</OutputFormat>" +
                    "  <PageWidth>8.5in</PageWidth>" +
                    "  <PageHeight>11in</PageHeight>" +
                    "  <MarginTop>0.5in</MarginTop>" +
                    "  <MarginLeft>1in</MarginLeft>" +
                    "  <MarginRight>1in</MarginRight>" +
                    "  <MarginBottom>0.5in</MarginBottom>" +
                    "</DeviceInfo>";

                Warning[] warnings;
                string[]  streams;
                byte[]    renderedBytes;

                //Render the report
                renderedBytes = localReport.Render(
                    reportType,
                    deviceInfo,
                    out mimeType,
                    out encoding,
                    out fileNameExtension,
                    out streams,
                    out warnings);
                return(File(renderedBytes, mimeType));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, errorMessage = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }