Exemplo n.º 1
0
 /// <summary>
 /// thêm thông tin phiếu thu tiền phạtvào database
 /// </summary>
 public static void AddPhieuThuTienPhat(PhieuThuTienPhat PhieuThuTienPhat)
 {
     using (var db = new LiteDatabase(DatabaseConnectionString))
     {
         db.GetCollection <PhieuThuTienPhat>("PhieuThuTienPhat").Insert(PhieuThuTienPhat);
     }
 }
        public async Task <IActionResult> Edit(int id, [Bind("PhieuThuTienPhatID,TienCoc,TienPhat,TienConLai,DocGiaID,PhieuTraID")] PhieuThuTienPhat phieuThuTienPhat)
        {
            if (id != phieuThuTienPhat.PhieuThuTienPhatID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(phieuThuTienPhat);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PhieuThuTienPhatExists(phieuThuTienPhat.PhieuThuTienPhatID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DocGiaID"]   = new SelectList(_context.DocGia, "DocGiaID", "DiaChi", phieuThuTienPhat.DocGiaID);
            ViewData["PhieuTraID"] = new SelectList(_context.PhieuTra, "PhieuTraID", "PhieuTraID", phieuThuTienPhat.PhieuTraID);
            return(View(phieuThuTienPhat));
        }
Exemplo n.º 3
0
        /// <summary>
        /// cập nhật thông tin phiếu thu tiền phạtvào database
        /// </summary>
        public static bool SetPhieuThuTienPhat(PhieuThuTienPhat PhieuThuTienPhat)
        {
            bool result;

            using (var db = new LiteDatabase(DatabaseConnectionString))
            {
                result = db.GetCollection <PhieuThuTienPhat>("PhieuThuTienPhat").Update(PhieuThuTienPhat);
            }
            return(result);
        }
        public async Task <IActionResult> Create([Bind("PhieuThuTienPhatID,TienCoc,TienPhat,TienConLai,DocGiaID,PhieuTraID")] PhieuThuTienPhat phieuThuTienPhat)
        {
            if (ModelState.IsValid)
            {
                _context.Add(phieuThuTienPhat);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DocGiaID"]   = new SelectList(_context.DocGia, "DocGiaID", "DiaChi", phieuThuTienPhat.DocGiaID);
            ViewData["PhieuTraID"] = new SelectList(_context.PhieuTra, "PhieuTraID", "PhieuTraID", phieuThuTienPhat.PhieuTraID);
            return(View(phieuThuTienPhat));
        }
Exemplo n.º 5
0
        public ActionResult DaTraSach(string stt, string iddg, string idsach)
        {
            CTMuonTra ct = db.CTMuonTras.Where(n => n.STT == stt && n.IDSach == idsach && n.IDDocGia == iddg).SingleOrDefault();

            ct.NgayTraThucTe = DateTime.Now.Date;
            if (DateTime.Now.Date <= ct.NgayTraQuyDinh)
            {
                ct.NgayQuaHan = 0;
                ct.TienPhat   = 0;
            }
            else
            {
                TimeSpan Time = DateTime.Now.Date - ct.NgayTraQuyDinh.Value;
                ct.NgayQuaHan = Time.Days;
                ct.TienPhat   = Time.Days * 1000;
                ct.TongTien  += Time.Days * 1000;

                DocGia dg = db.DocGias.Find(iddg);
                dg.TongTienPhat   += Time.Days * 1000;
                db.Entry(dg).State = EntityState.Modified;
                db.SaveChanges();

                PhieuThuTienPhat phieu = new PhieuThuTienPhat();
                phieu.IDPhieuThuTienPhat = "";
                phieu.NgayThang          = DateTime.Now.Date;
                phieu.IDDocGia           = iddg;
                phieu.TienThu            = Time.Days * 1000;
                db.PhieuThuTienPhats.Add(phieu);
                db.SaveChanges();
            }
            ct.TinhTrangMuon = 3;

            db.Entry(ct).State = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("SachDaTra"));
        }
Exemplo n.º 6
0
        public IActionResult SubmitKiemTraPhieuTra(List <CT_PhieuMuon> model, int id)
        {
            var phieumuon = _context.PhieuMuon.Find(id);
            var ctpm      = _context.CT_PhieuMuon.Where(s => s.PhieuMuonID == id).ToList();

            //tinh so ngay muon
            TimeSpan songaymuon = DateTime.Now.Subtract(phieumuon.NgayMuon);

            if (phieumuon.TinhTrangPhieuMuonID == 2) //2 là phiếu mượn đã trả
            {
                return(RedirectToAction("index", "phieumuon"));
            }
            else
            {
                //so ngay muon ko qua han
                if (songaymuon.Days <= 4)
                {
                    PhieuTra phieutra = new PhieuTra();
                    phieutra.DocGiaID = phieumuon.DocGiaID;
                    phieutra.NgayTra  = DateTime.Now;
                    _context.PhieuTra.Add(phieutra);
                    _context.SaveChanges();

                    foreach (var a in ctpm)
                    {
                        CT_PhieuTra ctpt = new CT_PhieuTra();
                        ctpt.SoNgayMuon = songaymuon.Days;
                        ctpt.PhieuTraID = phieutra.PhieuTraID;
                        ctpt.SachID     = a.SachID;
                        _context.CT_PhieuTra.Add(ctpt);
                        _context.SaveChanges();
                    }

                    var docgia = _context.DocGia.FirstOrDefault(l => l.DocGiaID == phieutra.DocGiaID);
                    docgia.SLSachDaMuon = 0;
                    _context.SaveChanges();

                    //cập nhật lại tình trạng phiếu mượn
                    phieumuon.TinhTrangPhieuMuonID = 2;//2 là phiếu mượn hoan thanh
                    _context.SaveChanges();

                    double sum = 0;

#pragma warning disable CS0162 // Unreachable code detected
                    for (int i = 0; i < model.Count; i++)
#pragma warning restore CS0162 // Unreachable code detected
                    {
                        if (model[i].IsSelected)
                        {
                            var sach = _context.Sach.FirstOrDefault(x => x.SachID == model[i].SachID);
                            sach.TinhTrangSachID = 1; //1 chua thue
                            _context.SaveChanges();
                        }

                        else
                        {
                            var sach = _context.Sach.FirstOrDefault(x => x.SachID == model[i].SachID);
                            sach.TinhTrangSachID = 3; //3 mat
                            sum += sach.Gia;
                        }
                    }
                    PhieuThuTienPhat pttp = new PhieuThuTienPhat();
                    pttp.DocGiaID   = docgia.DocGiaID;
                    pttp.TienCoc    = phieumuon.TienCoc;
                    pttp.PhieuTraID = phieutra.PhieuTraID;
                    pttp.TienPhat   = sum;
                    pttp.TienConLai = phieumuon.TienCoc - pttp.TienPhat;
                    _context.PhieuThuTienPhat.Add(pttp);
                    docgia.ConLai = pttp.TienConLai;
                    _context.SaveChanges();
                    return(RedirectToAction("details", new RouteValueDictionary(new { Controller = "phieuthutienphat", Action = "details", id = pttp.PhieuThuTienPhatID })));
                }
                //so ngay muon qua han
                else
                {
                    PhieuTra phieutra = new PhieuTra();
                    phieutra.DocGiaID = phieumuon.DocGiaID;
                    phieutra.NgayTra  = DateTime.Now;
                    _context.PhieuTra.Add(phieutra);
                    _context.SaveChanges();

                    // tien tra tre han
                    double sum = 0;
                    sum = (songaymuon.Days - 4) * 1000;


                    foreach (var a in ctpm)
                    {
                        CT_PhieuTra ctpt = new CT_PhieuTra();
                        ctpt.SoNgayMuon = songaymuon.Days;
                        ctpt.PhieuTraID = phieutra.PhieuTraID;
                        ctpt.SachID     = a.SachID;
                        _context.CT_PhieuTra.Add(ctpt);
                        _context.SaveChanges();
                    }

                    var docgia = _context.DocGia.FirstOrDefault(l => l.DocGiaID == phieutra.DocGiaID);
                    docgia.SLSachDaMuon = 0;
                    _context.SaveChanges();

                    //cập nhật lại tình trạng phiếu mượn
                    phieumuon.TinhTrangPhieuMuonID = 2;//2 là phiếu mượn hoan thanh
                    _context.SaveChanges();

                    for (int i = 0; i < model.Count; i++)
                    {
                        // trễ hạn nhưng đủ sách
                        if (model[i].IsSelected == true)
                        {
                            var sach = _context.Sach.FirstOrDefault(x => x.SachID == model[i].SachID);
                            sach.TinhTrangSachID = 1; //1 chua thue
                            _context.SaveChanges();
                        }
                        // trễ hạn nhưng thiếu sách
                        else
                        {
                            var sach = _context.Sach.FirstOrDefault(x => x.SachID == model[i].SachID);
                            sach.TinhTrangSachID = 3; //3 mat
                            sum += sach.Gia;
                        }
                    }
                    PhieuThuTienPhat pttp = new PhieuThuTienPhat();
                    pttp.DocGiaID   = docgia.DocGiaID;
                    pttp.PhieuTraID = phieutra.PhieuTraID;
                    pttp.TienCoc    = phieumuon.TienCoc;
                    pttp.TienPhat   = sum;
                    pttp.TienConLai = phieumuon.TienCoc - pttp.TienPhat;
                    _context.PhieuThuTienPhat.Add(pttp);
                    _context.SaveChanges();

                    return(RedirectToAction("details", new RouteValueDictionary(new { Controller = "phieuthutienphat", Action = "details", id = pttp.PhieuThuTienPhatID })));
                }
            }
        }