public ActionResult Edit(PhieuXuat model, FormCollection collection)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (PhieuXuatManager.edit(model))
             {
                 _currentPhieu = null;
                 putSuccessMessage("Cập nhật thành công");
                 return(RedirectToAction("Details", new { id = model.MaSoPhieuXuat }));
             }
             else
             {
                 putErrorMessage("Cập nhật không thành công");
             }
         }
         else
         {
             putModelStateFailErrors(ModelState);
             return(RedirectToAction("Edit", new { id = model.MaSoPhieuXuat }));
         }
         //// TODO: Add update logic here
         //_phieu = model;
         //ViewBag.DMSach = new SelectList(SachManager.getAllAlive()
         //                                .Where(s => s.Soluong > 0).ToList(),
         //                    nameof(SachManager.Properties.MaSoSach),
         //                    nameof(SachManager.Properties.TenSach), "");
         //ViewBag.DMDaiLy = new SelectList(DaiLyManager.getAllAlive(),
         //                        nameof(DaiLyManager.Properties.MaSoDaiLy),
         //                        nameof(DaiLyManager.Properties.TenDaiLy), "");
         //return View(_phieu);
         return(RedirectToAction("Edit", new { id = model.MaSoPhieuXuat }));
     }
     catch (Exception ex)
     {
         putErrorMessage(ex.Message);
         return(RedirectToAction("Edit", new { id = model.MaSoPhieuXuat }));
     }
 }
예제 #2
0
        /// <summary>
        /// Duyệt phiếu nhập
        /// </summary>
        /// <returns></returns>
        public AcceptStatus accept()
        {
            if (Daily.TongTienNo > 10000000)
            {
                return(AcceptStatus.Limited);
            }
            //Kiểm tra số lượng có thể duyệt không
            foreach (ChiTietPhieuXuat ct in this.ChiTiet)
            {
                if (ct.Sach.Soluong < ct.SoLuong)
                {
                    return(AcceptStatus.ProductNotEnought);
                }
            }

            //Duyệt từng chi tiết
            foreach (ChiTietPhieuXuat ct in this.ChiTiet)
            {
                //Cập nhật thông tin sách
                ct.Sach.Soluong -= ct.SoLuong;
                if (!SachManager.edit(ct.Sach))
                {
                    return(AcceptStatus.UpdateProductFail);
                }

                //Ghi thẻ kho
                var tk = new TheKho
                {
                    MaSoSach = ct.MaSoSach,
                    SoLuong  = ct.Sach.Soluong,
                    NgayGhi  = DateTime.Now
                };
                if (TheKhoManager.add(tk) == 0)
                {
                    return(AcceptStatus.UpdateStoreFail);
                }
                //Cập nhật công nợ
                var congno = new CongNoDaiLy
                {
                    MaSoDaiLy = this.MaSoDaiLy,
                    MaSoSach  = ct.MaSoSach,
                    SoLuong   = ct.SoLuong,
                    DonGia    = ct.DonGia,
                    Thang     = DateTime.Now
                };
                if (CongNoDaiLyManager.add(congno) == 0)
                {
                    return(AcceptStatus.UpdateLiabilitiesFail);
                }
                ct.TrangThai = 1;
            }
            //Thay đổi trang thái phiếu nhập
            this.TrangThai = 1;
            if (PhieuXuatManager.edit(this))
            {
                return(AcceptStatus.Success);
            }
            else
            {
                return(AcceptStatus.Error);
            }
        }