Ejemplo n.º 1
0
        public JsonResult CreateCashInFinal(CashIn cashflow, string log)
        {
            try
            {
                CashIn cashInActive = cashflow;
                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 (cashflow.Id != 0)
                {
                    cashInActive = db.CashCards.OfType<CashIn>().First(p => p.Id == cashflow.Id);

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

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

                cashInActive.SetTotal();
                db.SaveChanges();

                return Json(new {Success = 1, CashOutId = cashflow.Id, ex = ""});
            }
            catch (Exception ex)
            {
                return Json(new {Success = 0, ex = ex.Message});
            }
        }
Ejemplo n.º 2
0
        public JsonResult CreateCashInDraft(CashIn cashIn)
        {
            try
            {
                CashIn cashInActive = cashIn;

                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 (cashIn.Id != 0)
                {
                    cashInActive = db.CashCards.OfType<CashIn>().First(p => p.Id == cashIn.Id);

                    Subtitution(cashInActive, cashIn);
                }
                else
                {
                    db.CashCards.Add(cashInActive);
                    //CashOut.Date = DateTime.Now;
                    cashInActive.CutOffId = cutOff.Id;
                    cashInActive.UserId = usr;
                }
                //set subtotal and total

                cashInActive.SetToDraft();

                cashInActive.SetTotal();
                db.SaveChanges();

                return Json(new {Success = 1, CashOutId = cashIn.Id, ex = ""});
            }
            catch (Exception ex)
            {
                return Json(new {Success = 0, ex = ex.Message});
            }
        }
Ejemplo n.º 3
0
        private void Subtitution(CashIn cashInDb, CashIn cashInView)
        {
            cashInDb.Date = cashInView.Date;
            cashInDb.Note = cashInView.Note;

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

                CashInDetail reg = cashInView.CashInDetails.FirstOrDefault(p => p.Id == idReg);
                if (reg == null)
                {
                    db.Entry(cashInDb.CashInDetails[i]).State = EntityState.Deleted;
                    //cashoutDb.RegularDetails.RemoveAt(i);
                }
            }
            //add or update detail
            for (int i = 0; i < cashInView.CashInDetails.Count; i++)
            {
                if (cashInView.CashInDetails[i].Id == 0)
                {
                    cashInDb.CashInDetails.Add(cashInView.CashInDetails[i]);
                }
                else
                {
                    CashInDetail regDetail = cashInView.CashInDetails[i];
                    CashInDetail detail = cashInDb.CashInDetails.First(p => p.Id == regDetail.Id);
                    detail.Note = regDetail.Note;
                    detail.Amount = regDetail.Amount;
                }
            }

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

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

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

            }
        }
Ejemplo n.º 4
0
        public ActionResult CashIn()
        {
            var cash = new CashIn();

            return View(cash);
        }