コード例 #1
0
        public JsonResult CreateCashoutRegularFinal(CashOut cashout, string log)
        {
            try
            {
                CashOut cashout1 = cashout;
                string usr = User.Identity.GetUserId();
                ApplicationUser xx = db.Users.Find(usr);

                CutOff cutOff =
                    db.CutOffs.FirstOrDefault(p => p.BranchId == xx.BranchId && p.State == StateCutOff.Open) ??
                    SetCutOff(xx.BranchId.Value);

                if (cashout.Id != 0)
                {
                    cashout = db.CashCards.OfType<CashOut>().First(p => p.Id == cashout.Id);

                    Subtitution(cashout, cashout1);
                }
                else
                {
                    db.CashCards.Add(cashout);
                    //CashOut.Date = DateTime.Now;
                    cashout.CutOffId = cutOff.Id;
                    cashout.UserId = usr;
                }

                cashout.SetToFinal();
                cashout.LogNote = DateTime.Now.ToString("yyyy-MM-dd HH:mm") + " | " + User.Identity.Name + " | Final | " +
                                  log + "<br>" + cashout.LogNote;

                cashout.RegularDetails.ForEach(p => p.SetSubTotal());
                cashout.SetTotal();
                db.SaveChanges();

                return Json(new {Success = 1, CashOutId = cashout.Id, ex = ""});
            }
            catch (Exception ex)
            {
                return Json(new {Success = 0, ex = ex.Message});
            }
        }
コード例 #2
0
        private void Subtitution(CashOut cashoutDb, CashOut cashoutView)
        {
            cashoutDb.Date = cashoutView.Date;
            cashoutDb.Note = cashoutView.Note;

            //delete detail
            for (int i = cashoutDb.RegularDetails.Count - 1; i >= 0; i--)
            {
                int idReg = cashoutDb.RegularDetails[i].Id;

                CashOutDetail reg = cashoutView.RegularDetails.FirstOrDefault(p => p.Id == idReg);
                if (reg == null)
                {
                    db.Entry(cashoutDb.RegularDetails[i]).State = EntityState.Deleted;
                    //cashoutDb.RegularDetails.RemoveAt(i);
                }
            }
            //add or update detail
            for (int i = 0; i < cashoutView.RegularDetails.Count; i++)
            {
                if (cashoutView.RegularDetails[i].Id == 0)
                {
                    cashoutDb.RegularDetails.Add(cashoutView.RegularDetails[i]);
                }
                else
                {
                    CashOutDetail regDetail = cashoutView.RegularDetails[i];
                    CashOutDetail detail = cashoutDb.RegularDetails.First(p => p.Id == regDetail.Id);
                    detail.QuizId = regDetail.QuizId;
                    detail.Quiz = null;
                    detail.Note1 = regDetail.Note1;
                    detail.Note2 = regDetail.Note2;
                    detail.Note3 = regDetail.Note3;
                    detail.DateInfo = regDetail.DateInfo;

                    detail.Qty = regDetail.Qty;
                    detail.Amount = regDetail.Amount;
                    detail.DateInfo = regDetail.DateInfo;
                }
            }

            //image list
            //delete detail
            for (int i = cashoutDb.ImageDatas.Count - 1; i >= 0; i--)
            {
                int idImg = cashoutDb.ImageDatas[i].Id;

                var img = cashoutView.ImageDatas.FirstOrDefault(p => p.Id == idImg);
                if (img == null)
                {
                    db.Entry(cashoutDb.ImageDatas[i]).State = EntityState.Deleted;

                }
            }
            //add or update detail
            for (int i = 0; i < cashoutView.ImageDatas.Count; i++)
            {
                if (cashoutView.ImageDatas[i].Id == 0)
                {
                    cashoutDb.ImageDatas.Add(cashoutView.ImageDatas[i]);
                }

            }
        }
コード例 #3
0
        public ActionResult CreateCashOut(TypeOut? typeOut, CostCenter? userType)
        {
            var cash = new CashOut();
            cash.TypeOut = typeOut == null ? TypeOut.Regular : typeOut.Value;
            cash.CostCenter = userType == null ? CostCenter.Other : userType.Value;

               // ViewBag.Kendaraan = db.Kendaraan.Select(p => p.NoKendaraan).ToList();
            ViewBag.Kendaraan = new SelectList(db.Kendaraan, "NoKendaraan", "NoKendaraan");

            if (cash.TypeOut == TypeOut.Irregular)
            {
                var data = db.Quizs.Where(p => p.QuizGroup.GroupType == GroupType.Irregularaties).ToList();
                //data.Insert(0, new Quiz());
                ViewBag.Quiz =new SelectList(data, "Id", "Info");

                ViewBag.QuizInfo = from dt in data select new { dt.Id, label1 = dt.Note1Label, label2 = dt.Note2Label, label3 = dt.Note3Label, requiredAll = dt.RequiredAll };

            }
            else
            {
                var data = db.Quizs.Where(
                    p => p.CostCenter == cash.CostCenter && p.QuizGroup.GroupType != GroupType.Irregularaties).ToList();
               // data.Insert(0, new Quiz());

                ViewBag.Quiz = new SelectList(data, "Id", "Info");

                ViewBag.QuizInfo = from dt in data select new { dt.Id, label1 = dt.Note1Label, label2 = dt.Note2Label, label3 = dt.Note3Label, requiredAll = dt.RequiredAll };

            }

            return View("CashOut", cash);
        }