private void OnSave(object parameter)
        {
            decimal amount = 0.0M;

            if (IsBillBasedReturn)
            {
                foreach (var item in _returnSalesDetailsList)
                {
                    if (item.Selected)
                    {
                        amount += item.ReturnAmount;
                        SaveReturnItems(item, _billSales.BillId);
                    }
                }
                var customer = _rmsEntities.Customers.FirstOrDefault(c => c.Id == _billSales.CustomerId);
                if (customer != null)
                {
                    customer.BalanceDue -= amount;
                }

                _rmsEntities.SaveChanges();
                Clear();
                return;
            }

            foreach (var item in _returnSalesDetailsList)
            {
                SaveReturnItems(item, null);
            }
            _rmsEntities.SaveChanges();
            Clear();
        }
 private static void CreateLevel(RMSEntities dbContext)
 {
     try
     {
         var levels = new List <string>()
         {
             "100", "200", "300", "400", "500"
         };
         foreach (var level in levels)
         {
             if (!dbContext.Levels.Any(c => c.Name == level))
             {
                 dbContext.Levels.Add(new Level()
                 {
                     Name = level, CreatedAt = DateTime.UtcNow
                 });
                 dbContext.SaveChanges();
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
Exemple #3
0
        public ActionResult UserSignup(SignupModel obj)
        {
            if (ModelState.IsValid)
            {
                RMSEntities rtx  = new RMSEntities();
                var         data = rtx.Customers.FirstOrDefault(i => i.Userid == obj.Userid);
                if (data != null)
                {
                    ModelState.AddModelError("", "Username already exists");
                    return(View("Signup"));
                }
                Customer c = new Customer();
                c.Username  = obj.Username;
                c.Userid    = obj.Userid;
                c.password  = obj.Password;
                c.Usercity  = obj.Usercity;
                c.Uphonenum = long.Parse(obj.Userphno);
                rtx.Customers.Add(c);
                rtx.SaveChanges();

                return(RedirectToAction("UserLogin"));
            }
            else
            {
                return(View("Signup"));
            }
        }
Exemple #4
0
        public JsonResult AddToCart2(Cart c1)
        {
            RMSEntities ctx = new RMSEntities();

            var data = from a in ctx.Menus.ToList()
                       where a.Rname == Session["Rname"].ToString() &&
                       a.Itemsname == c1.Fooditems
                       select new
            {
                a.Itemsname,
                a.price,
                a.Rname,
            };

            foreach (var item in data)
            {
                Cart c = new Cart();
                c.Fooditems = item.Itemsname;
                c.Price     = item.price;
                c.Rname     = item.Rname;
                c.Quantity  = c1.Quantity;
                ctx.Carts.Add(c);
                ctx.SaveChanges();
                break;
            }
            return(Json(c1, JsonRequestBehavior.AllowGet));
        }
Exemple #5
0
 public JsonResult PlaceOrder2()
 {
     {
         RMSEntities ctx = new RMSEntities();
         foreach (var item in ctx.Carts)
         {
             OrderedFood h1 = new OrderedFood()
             {
                 Userid   = Session["Userid"].ToString(),
                 Rname    = item.Rname,
                 Itemname = item.Fooditems,
                 Price    = item.Price,
                 Quantity = item.Quantity.ToString(),
                 Date     = DateTime.Now
             };
             ctx.OrderedFoods.Add(h1);
         }
         var rows = from a in ctx.Carts
                    select a;
         foreach (var row in rows)
         {
             ctx.Carts.Remove(row);
         }
         ctx.SaveChanges();
         int d = 1;
         return(Json(d, JsonRequestBehavior.AllowGet));
     }
 }
Exemple #6
0
        public ActionResult FinalUpdateMenu(Menu r1, HttpPostedFileBase pfile1)
        {
            RMSEntities ctx = new RMSEntities();

            if (pfile1 != null)
            {
                BinaryReader brd = new BinaryReader(pfile1.InputStream);
                byte[]       bt  = brd.ReadBytes((int)pfile1.InputStream.Length);
                foreach (var item in ctx.Menus)
                {
                    if (r1.Rname == item.Rname && r1.Itemsname == item.Itemsname)
                    {
                        item.Itemimage = bt;
                        item.price     = (int)r1.price;
                        break;
                    }
                }
            }
            else
            {
                foreach (var item in ctx.Menus)
                {
                    if (r1.Rname == item.Rname && r1.Itemsname == item.Itemsname)
                    {
                        item.price = (int)r1.price;
                        break;
                    }
                }
            }
            ctx.SaveChanges();
            return(RedirectToAction("EditMenu"));
        }
 private static void CreateSemester(RMSEntities dbContext)
 {
     try
     {
         var roles = new List <string>()
         {
             "Harmattan", "Rain"
         };
         foreach (var role in roles)
         {
             if (!dbContext.Semeters.Any(c => c.Name == role))
             {
                 dbContext.Semeters.Add(new Semeter()
                 {
                     Name = role, CreatedAt = DateTime.UtcNow
                 });
                 dbContext.SaveChanges();
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
Exemple #8
0
        public ActionResult AddBranch2(Branch r1, HttpPostedFileBase pfile1)
        {
            try
            {
                RMSEntities ctx  = new RMSEntities();
                Branch      obj  = new Branch();
                var         data = ctx.Branches.FirstOrDefault(i => (i.Location == r1.Location && i.bcity == r1.bcity && i.Rname == r1.Rname));

                if (data == null)
                {
                    BinaryReader brd = new BinaryReader(pfile1.InputStream);
                    byte[]       bt  = brd.ReadBytes((int)pfile1.InputStream.Length);
                    r1.bimage = bt;
                    ctx.Branches.Add(r1);

                    ctx.SaveChanges();
                    //ViewBag.Message = "Restaurant Added";
                    TempData["success"] = "Branch Added";
                    return(RedirectToAction("AddBranch"));
                }


                TempData["Error"] = "Duplicate Entry!";
                return(RedirectToAction("AddBranch"));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Error", "Home"));
            }
        }
Exemple #9
0
        public JsonResult DelBranch2(Branch r1)
        {
            RMSEntities ctx = new RMSEntities();

            foreach (var item in ctx.Menus)
            {
                if (r1.Rname == item.Rname)
                {
                    ctx.Menus.Remove(item);
                }
            }
            ctx.SaveChanges();
            foreach (var item2 in ctx.Branches)
            {
                if (r1.Rname == item2.Rname && r1.bcity == item2.bcity && r1.Location == item2.Location)
                {
                    ctx.Branches.Remove(item2);
                    break;
                }
            }
            ctx.SaveChanges();
            return(Json(r1));
        }
Exemple #10
0
        private void OnSave(object parameter)
        {
            if (!string.IsNullOrWhiteSpace(SelectedCustomer.Name))
            {
                if (_isEditMode)
                {
                    var cust = _rmsEntities.Customers.FirstOrDefault(c => c.Id == _customer.Id);
                    cust = _customer;
                }
                else
                {
                    _rmsEntities.Customers.Add(_customer);
                }

                _rmsEntities.SaveChanges();
                ClearCommand.Execute(null);
                RaisePropertyChanged("CustomersList");
            }
            else
            {
                Utilities.Utility.ShowErrorBox("Customer Name can't be empty");
            }
        }
Exemple #11
0
        public JsonResult ChangeQuantity2(Cart F)
        {
            RMSEntities ctx = new RMSEntities();

            foreach (var item in ctx.Carts.ToList())
            {
                if (item.Fooditems == F.Fooditems)
                {
                    item.Quantity = F.Quantity;
                    break;
                }
            }
            ctx.SaveChanges();
            return(Json(F, JsonRequestBehavior.AllowGet));
        }
Exemple #12
0
        public JsonResult DelItem2(Menu f1)
        {
            RMSEntities ctx = new RMSEntities();

            foreach (var item in ctx.Menus)
            {
                if (f1.Rname == item.Rname && f1.Itemsname == item.Itemsname)
                {
                    ctx.Menus.Remove(item);
                    break;
                }
            }
            ctx.SaveChanges();
            return(Json(f1));
        }
Exemple #13
0
        public ActionResult AddMenu2(Menu b1, HttpPostedFileBase pfile1)
        {
            RMSEntities ctx = new RMSEntities();
            string      cat = Request.Form["type2"].ToString();

            try
            {
                foreach (var item in ctx.Restaurants)
                {
                    Menu obj = new Menu();
                    if (cat == "BOTH")
                    {
                        BinaryReader brd = new BinaryReader(pfile1.InputStream);
                        byte[]       bt  = brd.ReadBytes((int)pfile1.InputStream.Length);
                        b1.Itemimage = bt;
                        ctx.Menus.Add(b1);
                        TempData["menu_succ"] = "Menu Added";
                        break;
                    }
                    else
                    {
                        if (item.Rname == b1.Rname && item.Category == b1.Foodtype)
                        {
                            BinaryReader brd = new BinaryReader(pfile1.InputStream);
                            byte[]       bt  = brd.ReadBytes((int)pfile1.InputStream.Length);
                            b1.Itemimage = bt;
                            ctx.Menus.Add(b1);
                            TempData["menu_succ"] = "Menu Added";
                            break;
                        }
                        else
                        {
                            //TempData["dup_msg"] = "Kindly Check Data...";
                            // return RedirectToAction("AddMenu");
                        }
                    }
                }
                ctx.SaveChanges();

                return(RedirectToAction("AddMenu"));
            }
            catch (Exception ex)
            {
                return(View("Error",
                            new HandleErrorInfo(ex, "Admin", "AddBranch")));
                //return View("Error");
            }
        }
Exemple #14
0
        public JsonResult DeleteItem2(Cart F)
        {
            RMSEntities ctx = new RMSEntities();

            foreach (var item in ctx.Carts.ToList())
            {
                if (item.Fooditems == F.Fooditems)
                {
                    ctx.Carts.Remove(item);
                    break;
                }
            }

            ctx.SaveChanges();
            return(Json(F, JsonRequestBehavior.AllowGet));
        }
Exemple #15
0
 public ActionResult AddRestaurant2(Restaurant r1, HttpPostedFileBase pfile1)
 {
     try
     {
         RMSEntities  ctx = new RMSEntities();
         BinaryReader brd = new BinaryReader(pfile1.InputStream);
         byte[]       bt  = brd.ReadBytes((int)pfile1.InputStream.Length);
         r1.Rimages = bt;
         ctx.Restaurants.Add(r1);
         ctx.SaveChanges();
         TempData["rest_msg"] = "Restaurant Added";
         return(RedirectToAction("AddRest"));
     }
     catch (Exception ex)
     {
         return(RedirectToAction("Error", "Home"));
     }
 }
Exemple #16
0
        public JsonResult GetHistory2()
        {
            RMSEntities ctx  = new RMSEntities();
            var         data = (from a in ctx.OrderedFoods.ToList()
                                where (a.Userid == Session["Userid"].ToString())
                                select new
            {
                a.Userid,
                a.Rname,
                a.Itemname,
                a.Price,
                a.Quantity,
                Date = a.Date.ToString()
                       //a.DaTi
                       //DaTi = a.DaTi.ToString().Substring(
                       //        0, a.ReleaseDate.ToString().IndexOf(' ')),
                       //DaTi = a.DaTi.ToString()
            }).ToList();

            ctx.SaveChanges();
            return(Json(data, JsonRequestBehavior.AllowGet));
        }
Exemple #17
0
        public ActionResult FinalUpdateBranch(Branch r1, HttpPostedFileBase pfile3)
        {
            RMSEntities ctx = new RMSEntities();
            string      dum = Request.Form["Location1"].ToString();

            if (pfile3 != null)
            {
                BinaryReader brd = new BinaryReader(pfile3.InputStream);
                byte[]       bt  = brd.ReadBytes((int)pfile3.InputStream.Length);
                foreach (var item in ctx.Branches)
                {
                    if (r1.Rname == item.Rname && r1.bcity == item.bcity && r1.Location == item.Location)
                    {
                        item.bimage    = bt;
                        item.bphonenum = (Int64)r1.bphonenum;
                        item.Location  = dum;
                        break;
                    }
                }
            }
            else
            {
                foreach (var item in ctx.Branches)
                {
                    if (r1.Rname == item.Rname && r1.bcity == item.bcity && r1.Location == item.Location)
                    {
                        item.bphonenum = (Int64)r1.bphonenum;
                        item.Location  = dum;
                        break;
                    }
                }
            }
            TempData["succ_msg"] = "Branch Updated Successfully !!!";
            ctx.SaveChanges();
            return(RedirectToAction("EditRest"));
        }
Exemple #18
0
        private void OnSave(object parameter)
        {
            if (_isEditMode)
            {
                SaveOnEdit(parameter);
                return;
            }

            PanelLoading = true;
            var purchaseSaveTask = System.Threading.Tasks.Task.Run(() =>
            {
                //Add free items to free items table
                //Sum up the free item to main stock
                var purchase = new Purchase()
                {
                    RunningBillNo      = RunningBillNo,
                    CompanyId          = SelectedCompany.Id,
                    Discount           = GetDiscountValue(),
                    SpecialDiscount    = SpecialDiscountAmount,
                    InvoiceNo          = InvoiceNo,
                    TotalBillAmount    = TotalAmount,
                    TransportCharges   = TransportCharges,
                    CoolieCharges      = CoolieCharges,
                    KCoolieCharges     = KCoolieCharges,
                    LocalCoolieCharges = LocalCoolieCharges,
                    Tax         = TotalTax,
                    PaymentMode = SelectedPaymentId.ToString()
                };

                foreach (var item in _purchaseDetailsList)
                {
                    if (item.Qty == null || item.Qty <= 0)
                    {
                        Utility.ShowErrorBox("Purchase quantity can't be empty or zero");
                        return;

                        //App.Current.Dispatcher.BeginInvoke(
                        //    (Action)(() =>
                        //    {
                        //        Utility.ShowErrorBox("Purchase quantity can't be empty or zero");
                        //    }
                        //    ));
                    }
                    var purchaseDetail         = new PurchaseDetail();
                    purchaseDetail.ProductId   = item.ProductId;
                    purchaseDetail.Discount    = item.Discount;
                    purchaseDetail.ActualPrice = item.PurchasePrice.Value;
                    purchaseDetail.Tax         = item.Tax;

                    var priceDetails = _rmsEntities.PriceDetails.Where(pr => pr.ProductId == item.ProductId &&
                                                                       pr.Price == item.CostPrice &&
                                                                       pr.SellingPrice == item.SellingPrice);
                    var priceId = 0;
                    PriceDetail priceDetailItem = null;
                    if (priceDetails.Any())
                    {
                        //Same item exists. Just update the with new billId
                        priceDetailItem        = priceDetails.FirstOrDefault();
                        priceDetailItem.BillId = item.BillId;
                        priceId = priceDetailItem.PriceId;
                        priceDetailItem.SellingPrice = item.SellingPrice.Value;
                    }
                    else
                    {
                        //New Price, add it to price details list
                        priceDetailItem = new PriceDetail()
                        {
                            BillId       = RunningBillNo,
                            ProductId    = item.ProductId,
                            Price        = item.CostPrice,
                            SellingPrice = item.SellingPrice.Value
                        };
                        _rmsEntities.PriceDetails.Add(priceDetailItem);
                    }

                    var stock = _rmsEntities.Stocks.Where(s => s.ProductId == item.ProductId &&
                                                          s.PriceId == priceId &&
                                                          s.ExpiryDate.CompareTo(item.ExpiryDate.Value) == 0);
                    var qty = item.Qty;
                    if (item.FreeIssue.HasValue)
                    {
                        qty = item.FreeIssue.Value + item.Qty.Value;
                        _rmsEntities.PurchaseFreeDetails.Add(
                            new PurchaseFreeDetail()
                        {
                            ProductId  = item.ProductId,
                            FreeQty    = item.FreeIssue.Value,
                            FreeAmount = item.PurchasePrice * item.FreeIssue.Value
                                         //BillId = RunningBillNo
                        });
                    }
                    if (stock.Any())
                    {
                        stock.FirstOrDefault().Quantity += qty.Value;
                    }
                    else
                    {
                        //Add stock for new price
                        var newStock = new Stock()
                        {
                            //PriceId = priceDetailItem.PriceId,
                            ExpiryDate = item.ExpiryDate.Value,
                            Quantity   = qty.Value,
                            ProductId  = item.ProductId
                        };

                        _rmsEntities.Stocks.Add(newStock);

                        newStock.PriceDetail = priceDetailItem;
                    }

                    purchaseDetail.PurchasedQty = qty;
                    purchaseDetail.PriceId      = priceDetailItem.PriceId;
                    purchaseDetail.PriceDetail  = priceDetailItem;
                    purchase.PurchaseDetails.Add(purchaseDetail);
                }

                //check if complete amount is paid, else mark it in PaymentDetails table against the customer
                var outstandingBalance = _totalAmount.Value - AmountPaid;
                if (outstandingBalance > 0)
                {
                    //var msg = "Outstanding balance Rs " + outstandingBalance + ". Do you want to keep as pending balance amount?";
                    //var result = Utility.ShowMessageBoxWithOptions(msg);
                    //if (result == System.Windows.MessageBoxResult.Yes)
                    //{
                    _rmsEntities.PurchasePaymentDetails.Add
                    (
                        new PurchasePaymentDetail
                    {
                        PurchaseBillId = purchase.BillId,
                        AmountPaid     = AmountPaid,
                        CompanyId      = _selectedCompany.Id
                    }
                    );
                    //}
                    var company       = _rmsEntities.Companies.FirstOrDefault(c => c.Id == SelectedCompany.Id);
                    company.DueAmount = company.DueAmount.HasValue ? company.DueAmount.Value + outstandingBalance : outstandingBalance;
                }

                var _category       = _rmsEntities.Categories.FirstOrDefault(c => c.Id == _categoryId);
                _category.RollingNo = _runningBillNo;

                _rmsEntities.Purchases.Add(purchase);
                _rmsEntities.SaveChanges();

                var currentRunningBillNo = _runningBillNo;

                if (parameter.ToString() == "PrintSave")
                {
                    App.Current.Dispatcher.BeginInvoke((Action)(() =>
                    {
                        //Call the print on print & save
                        PurchaseSummaryViewModel psummVM = new PurchaseSummaryViewModel(_showRestrictedCompanies);
                        psummVM.RunningBillNo = currentRunningBillNo;
                        psummVM.PrintCommand.Execute(null);
                    }));
                }

                RMSEntitiesHelper.Instance.SelectRunningBillNo(_categoryId);
                RunningBillNo = _runningBillNo;

                Clear();
            }).ContinueWith(
                (t) =>
            {
                PanelLoading = false;
            });
        }