public ActionResult Details(int?id, int page = 1, int pageSize = 10, string search = null)
        {
            if (id == null)
            {
                putErrorMessage("Đường dẫn không chính xác");
                return(RedirectToAction("TheoDoi"));
            }
            ViewBag.cultureInfo = CultureInfo;
            var dl = DaiLyManager.find((int)id);

            if (dl == null)
            {
                putErrorMessage("Không tìm thấy đại lý");
                return(RedirectToAction("TheoDoi"));
            }
            ViewBag.currentDaiLy = dl;
            var DMCongNo = dl.CongNo;

            if (!String.IsNullOrEmpty(search))
            {
                DMCongNo          = CongNoDaiLyManager.filter(search, DMCongNo);
                ViewBag.SearchKey = search;
            }
            ViewBag.tongSoLuongNo = DMCongNo.Sum(cn => cn.SoLuong);
            ViewBag.tongTienNo    = DMCongNo.Sum(cn => cn.ThanhTien);
            var models = DMCongNo.ToPagedList(page, pageSize);

            setAlertMessage();
            return(View(models));
        }
Exemple #2
0
 public bool accept()
 {
     //Kiểm tra số lượng có thể duyệt không
     foreach (ChiTietHoaDonDaiLy ct in this.ChiTiet)
     {
         //Nếu tổng số lượng sách mà đại lý nợ ít hơn só sách sẽ thanh toán thì hủy duyệt
         if (ct.Sach.TongSoLuongDaiLyNo < ct.SoLuong)
         {
             return(false);
         }
     }
     //Duyệt từng chi tiết
     foreach (ChiTietHoaDonDaiLy ct in this.ChiTiet)
     {
         //
         //Cập nhật công nợ
         var sl    = ct.SoLuong;                // Số lượng sách thanh toán
         var count = ct.Sach.CongNoDaiLy.Count; // Số lượng các công nợ
         var index = 0;
         while (sl > 0)
         {
             if (index == count)
             {
                 //Đã duyệt hết các công nợ
                 break;
             }
             if (ct.Sach.CongNoDaiLy[index].SoLuong >= sl) // Nếu công nợ nhiều hơn hoặc bằng số lượng thanh toán
             {
                 //Giảm số lượng công nợ
                 ct.Sach.CongNoDaiLy[index].SoLuong -= sl;
                 sl -= sl;
                 //Cập nhật
                 if (!CongNoDaiLyManager.edit(ct.Sach.CongNoDaiLy[index]))
                 {
                     return(false);
                 }
             }
             else // Nếu công nợ ít hơn số lượng thanh toán
             {
                 sl -= ct.Sach.CongNoDaiLy[index].SoLuong;
                 ct.Sach.CongNoDaiLy[index].SoLuong = 0;
                 //Cập nhật
                 if (!CongNoDaiLyManager.edit(ct.Sach.CongNoDaiLy[index]))
                 {
                     return(false);
                 }
             }
             index++;
         }
         ct.TrangThai = 1;
     }
     //Thay đổi trang thái phiếu nhập
     this.TrangThai = 1;
     if (HoaDonDaiLyManager.edit(this))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #3
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);
            }
        }