示例#1
0
        public ActionResult LuuBaoCaoTonKho(BaoCaoTonKho baoCaoTonKho)
        {
            BaoCaoTonKho bctk = new BaoCaoTonKho
            {
                Thang         = baoCaoTonKho.Thang,
                Nam           = baoCaoTonKho.Nam,
                MaNguoiDung   = baoCaoTonKho.MaNguoiDung,
                NgayLap       = baoCaoTonKho.NgayLap,
                TongSoHangHoa = baoCaoTonKho.TongSoHangHoa,
                IsDeleted     = baoCaoTonKho.IsDeleted,
            };
            bool status = false;

            try
            {
                db.BaoCaoTonKhoes.Add(bctk);
                db.SaveChanges();
                SaveAllCTBCTK(baoCaoTonKho.ChiTietBaoCaoTonKhoes, bctk.MaBaoCaoTonKho);
                status = true;
            }
            catch
            {
                status = false;
                throw;
            }
            return(new JsonResult {
                Data = new { status = status }
            });
        }
        public bool CapNhatHangHoaVaoBaoCaoTonKhoKhiTaoPhieuNhap(int maHangHoa, int soLuongNhap, int thang, int nam)
        {
            try
            {
                var result = dbContext.BaoCaoTonKhoes.SingleOrDefault(x => x.MaHangHoa == maHangHoa && x.Thang == thang && x.Nam == nam);
                if (result != null)
                {
                    result.SoLuongNhap   += soLuongNhap;
                    result.SoLuongTonCuoi = result.SoLuongTonDau + result.SoLuongNhap - result.SoLuongXuat;
                    dbContext.SaveChanges();
                }
                else
                {
                    BaoCaoTonKho baoCaoTonKho = new BaoCaoTonKho
                    {
                        Thang          = thang,
                        Nam            = nam,
                        MaHangHoa      = maHangHoa,
                        SoLuongTonDau  = LaySoLuongTonCuoiCuaThangTruoc(maHangHoa, thang, nam),
                        SoLuongNhap    = soLuongNhap,
                        SoLuongXuat    = 0,
                        SoLuongTonCuoi = LaySoLuongTonCuoiCuaThangTruoc(maHangHoa, thang, nam) + soLuongNhap - 0,
                    };

                    dbContext.BaoCaoTonKhoes.Add(baoCaoTonKho);
                    dbContext.SaveChanges();
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#3
0
        public ActionResult DeleteConfirmed(int id)
        {
            var user = (NguoiDung)Session["Account"];

            ViewBag.MaNguoiDung = new SelectList(db.NguoiDungs.Where(nd => nd.MaNguoiDung == user.MaNguoiDung), "MaNguoiDung", "TenNguoiDung");
            ViewBag.MaHangHoa   = new SelectList(db.HangHoas, "MaHangHoa", "TenHangHoa");
            DeleteAllCTBCTK(id);
            BaoCaoTonKho baoCaoTonKho = db.BaoCaoTonKhoes.Find(id);

            db.BaoCaoTonKhoes.Remove(baoCaoTonKho);
            SetAlert("Xóa báo cáo thành công!", "success");
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#4
0
        public ActionResult Create([Bind(Include = "MaBaoCaoTonKho,Thang,Nam,MaNguoiDung,NgayLap,TongSoHangHoa,IsDeleted")] BaoCaoTonKho baoCaoTonKho)
        {
            if (ModelState.IsValid)
            {
                db.BaoCaoTonKhoes.Add(baoCaoTonKho);
                db.SaveChanges();
                SetAlert("Tạo báo cáo thành công!", "success");
                return(RedirectToAction("Index"));
            }
            ViewBag.MaHangHoa = new SelectList(db.HangHoas, "MaHangHoa", "TenHangHoa");
            var user = (NguoiDung)Session["Account"];

            ViewBag.MaNguoiDung = new SelectList(db.NguoiDungs.Where(nd => nd.MaNguoiDung == user.MaNguoiDung), "MaNguoiDung", "TenNguoiDung");
            return(View(baoCaoTonKho));
        }
示例#5
0
        public bool CapNhapHangHoaVaoBaoCaoTonKhiTaoPhieuNhap(int maHangHoa, int soLuongNhap, int thang, int nam)
        {
            try
            {
                var result = _dbContext.BaoCaoTonKhos.FirstOrDefault(x => x.MaHangHoa == maHangHoa && x.Thang == thang && x.Nam == nam);

                if (result != null)
                {
                    result.SoLuongNhap   += soLuongNhap;
                    result.SoLuongTonCuoi = result.SoLuongTonDau + result.SoLuongNhap - result.SoLuongXuat;
                    _dbContext.SaveChanges();
                }
                else
                {
                    var          hanghoa      = _dbContext.HangHoas.FirstOrDefault(x => x.MaHangHoa == maHangHoa);
                    BaoCaoTonKho baocaotonkho = new BaoCaoTonKho
                    {
                        Thang          = thang,
                        Nam            = nam,
                        MaHangHoa      = maHangHoa,
                        SoLuongTonDau  = hanghoa.SoLuongTon,
                        SoLuongNhap    = soLuongNhap,
                        SoLuongXuat    = 0,
                        SoLuongTonCuoi = hanghoa.SoLuongTon + soLuongNhap - 0
                    };

                    _dbContext.BaoCaoTonKhos.Add(baocaotonkho);
                    _dbContext.SaveChanges();
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#6
0
        // GET: BaoCaoTonKho/Edit/5
        //public ActionResult Edit(int? id)
        //{
        //    if (id == null)
        //    {
        //        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        //    }
        //    BaoCaoTonKho baoCaoTonKho = db.BaoCaoTonKhoes.Find(id);
        //    if (baoCaoTonKho == null)
        //    {
        //        return HttpNotFound();
        //    }
        //    ViewBag.MaNguoiDung = new SelectList(db.NguoiDungs, "MaNguoiDung", "TenNguoiDung", baoCaoTonKho.MaNguoiDung);
        //    return View(baoCaoTonKho);
        //}

        //// POST: BaoCaoTonKho/Edit/5
        //// To protect from overposting attacks, enable the specific properties you want to bind to, for
        //// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
        //[HttpPost]
        //[ValidateAntiForgeryToken]
        //public ActionResult Edit([Bind(Include = "MaBaoCaoTonKho,Thang,Nam,MaNguoiDung,NgayLap,TongSoHangHoa,IsDeleted")] BaoCaoTonKho baoCaoTonKho)
        //{
        //    if (ModelState.IsValid)
        //    {
        //        db.Entry(baoCaoTonKho).State = EntityState.Modified;
        //        db.SaveChanges();
        //        return RedirectToAction("Index");
        //    }
        //    ViewBag.MaNguoiDung = new SelectList(db.NguoiDungs, "MaNguoiDung", "TenNguoiDung", baoCaoTonKho.MaNguoiDung);
        //    return View(baoCaoTonKho);
        //}

        // GET: BaoCaoTonKho/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BaoCaoTonKho baoCaoTonKho = db.BaoCaoTonKhoes.Find(id);
            var          user         = (NguoiDung)Session["Account"];

            ViewBag.MaNguoiDung = new SelectList(db.NguoiDungs.Where(nd => nd.MaNguoiDung == user.MaNguoiDung), "MaNguoiDung", "TenNguoiDung");
            ViewBag.MaHangHoa   = new SelectList(db.HangHoas, "MaHangHoa", "TenHangHoa");
            string thang = baoCaoTonKho.Thang.ToString();

            if (baoCaoTonKho.Thang < 10)
            {
                thang = "0" + thang;
            }
            ViewBag.ThangNam = thang + "/" + baoCaoTonKho.Nam;
            if (baoCaoTonKho == null)
            {
                return(HttpNotFound());
            }
            return(View(baoCaoTonKho));
        }
示例#7
0
 public static int Insert(BaoCaoTonKho bcTonKho)
 {
     return(Controller.Insert(bcTonKho));
 }
示例#8
0
        private void btnLapBaoCao_Click(object sender, EventArgs e)
        {
            if (cbbThang.Text == "")
            {
                MessageBox.Show("Vui lòng chọn tháng!");
                return;
            }
            thang = int.Parse(cbbThang.Text);
            if (cbbNam.Text == "")
            {
                MessageBox.Show("Vui lòng chọn năm!");
                return;
            }
            nam = int.Parse(cbbNam.Text);
            DateTime dateStart = new DateTime(nam, thang, 1);
            DateTime dateEnd   = new DateTime(nam, thang, ProjectUltil.soNgay(nam, thang));

            if (dateStart > DateTime.Now.Date)
            {
                MessageBox.Show("Thời gian phải trước ngày hiện tại!");
                return;
            }
            //if(dateEnd > DateTime.Now.Date)
            //{
            //    dateEnd = DateTime.Now.Date;
            //}
            dsPhieuNhap    = PhieuNhapService.Search(null, dateStart, dateEnd);
            dsPhieuXuat    = PhieuXuatService.Search(null, dateStart, dateEnd);
            dsBaoCaoTonKho = BaoCaoTonKhoService.GetByMonthYear(thang, nam);
            dsHangHoa      = HangHoaService.LoadDataTable();
            if (dsBaoCaoTonKho.Rows.Count > 0)
            {
                grcBaoCaoTonKho.DataSource = ChiTietBaoCaoTonKhoService.GetById(dsBaoCaoTonKho.Rows[0].Field <int>("MaBaoCaoTonKho"));
                btnIn.Enabled = true;
            }
            else
            {
                bctk            = new BaoCaoTonKho();
                bctk.MaNhanVien = (ProjectUltil.MaNhanVien != "") ? ProjectUltil.MaNhanVien : "NV0001";
                bctk.Nam        = nam;
                bctk.Thang      = thang;
                bctk.NgayLap    = DateTime.Now.Date;
                if ((bctk.MaBaoCaoTonKho = BaoCaoTonKhoService.Insert(bctk)) != -1)
                {
                    for (int i = 0; i < dsHangHoa.Rows.Count; i++)
                    {
                        ctbctk = new ChiTietBaoCaoTonKho();
                        ctbctk.MaBaoCaoTonKho = bctk.MaBaoCaoTonKho;
                        ctbctk.MaHangHoa      = dsHangHoa.Rows[i].Field <string>("MaHangHoa");
                        ctbctk.SoLuongDauKy   = 0;
                        for (int j = 0; j < dsPhieuNhap.Rows.Count; j++)
                        {
                            dsCTPhieuNhap = ChiTietPhieuNhapService.GetById(dsPhieuNhap.Rows[j].Field <string>("SoPhieuNhap"));
                            for (int k = 0; k < dsCTPhieuNhap.Rows.Count; k++)
                            {
                                if (dsCTPhieuNhap.Rows[k].Field <string>("MaHangHoa") == ctbctk.MaHangHoa)
                                {
                                    int soluong = dsCTPhieuNhap.Rows[k].Field <int>("SoLuong");
                                    ctbctk.SoLuongNhap += soluong;
                                }
                            }
                        }

                        for (int j = 0; j < dsPhieuXuat.Rows.Count; j++)
                        {
                            dsCTPhieuXuat = ChiTietPhieuXuatService.GetById(dsPhieuXuat.Rows[j].Field <string>("SoPhieuXuat"));
                            for (int k = 0; k < dsCTPhieuXuat.Rows.Count; k++)
                            {
                                if (dsCTPhieuXuat.Rows[k].Field <string>("MaHangHoa") == ctbctk.MaHangHoa)
                                {
                                    int soluong = dsCTPhieuXuat.Rows[k].Field <int>("SoLuong");
                                    ctbctk.SoLuongXuat += soluong;
                                }
                            }
                        }

                        ctbctk.SoLuongCuoiKy = ctbctk.SoLuongDauKy + ctbctk.SoLuongNhap - ctbctk.SoLuongXuat;
                        if (!ChiTietBaoCaoTonKhoService.Insert(ctbctk))
                        {
                            ChiTietBaoCaoTonKhoService.Delete(ctbctk.MaBaoCaoTonKho.ToString());
                            BaoCaoTonKhoService.Delete(ctbctk.MaBaoCaoTonKho.ToString());
                            MessageBox.Show("Không thể thêm chi tiết báo cáo!");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Không thể lập báo cáo!");
                }
                grcBaoCaoTonKho.DataSource = ChiTietBaoCaoTonKhoService.GetById(bctk.MaBaoCaoTonKho);
                btnIn.Enabled = true;
            }
        }
示例#9
0
 public int Insert(BaoCaoTonKho bcTonKho)
 {
     return(_connect.InsertGetId("SP_BAOCAOTONKHO_INS", bcTonKho, "@MaBaoCaoTonKho"));
 }