Esempio n. 1
0
        /// <summary>
        /// Xoa don hang - bao gom ca don hang  chi tiet vaf cap nhat so luong cung nhu cong no
        /// </summary>
        /// <param name="strDonHangID">Don hang ID</param>
        static public void Del(string strDonHangID)
        {
            dbControl = new QlShop();
            DonHang DelItem = dbControl.DonHangs.SingleOrDefault(p => p.DonHangID == strDonHangID);

            if (DelItem != null)
            {
                //lay danh sach san pham cua don hang
                List <DonHangChiTiet> ListSanPham = new List <DonHangChiTiet>();
                ListSanPham = (from p in dbControl.DonHangChiTiets
                               where p.DonHangID == strDonHangID
                               select p).ToList <DonHangChiTiet>();
                using (TransactionScope scope = new TransactionScope())
                {
                    foreach (DonHangChiTiet item in ListSanPham)
                    {
                        //cap nhat lai ton kho khi xoa
                        SanPhamController.CapNhatTonKho(item.SanPhamID, 0 - item.SoLuong);
                    }
                    //cap nhat lai con no khach hang va tien hang
                    if (DelItem.KhachHangID != null)
                    {
                        KhachHangController.CapNhatCongNo_MuaHang(DelItem.KhachHangID, 0 - DelItem.ConNo, 0 - DelItem.TongCong);
                    }
                    dbControl.DonHangs.Remove(DelItem);
                    dbControl.DonHangChiTiets.RemoveRange(ListSanPham);
                    dbControl.SaveChanges();
                    scope.Complete();
                }
            }
        }
Esempio n. 2
0
        static public void Add(DonHang item, List <DonHangChiTiet> items)
        {
            dbControl = new QlShop();
            using (TransactionScope scope = new TransactionScope())
            {
                //cap nhat so luong ton kho thuc te luc xuat
                foreach (DonHangChiTiet DonHangItem in items)
                {
                    //DonHangItem.TonKho = SanPhamController.GetTonKho(DonHangItem.SanPhamID);
                    DonHangItem.GiaVon = SanPhamController.GetGiaVon(DonHangItem.SanPhamID);
                    //SanPhamController.CapNhatTonKho(DonHangItem.SanPhamID, DonHangItem.SoLuong);
                }

                dbControl.DonHangs.Add(item);
                dbControl.DonHangChiTiets.AddRange(items);

                //cap nhat so luong ton kho

                foreach (DonHangChiTiet DonHangItem in items)
                {
                    SanPhamController.CapNhatTonKho(DonHangItem.SanPhamID, DonHangItem.SoLuong);
                }
                //cap nha cong no va tong tien hang
                if (item.KhachHangID != null)
                {
                    KhachHangController.CapNhatCongNo_MuaHang(item.KhachHangID, item.ConNo, item.TongCong);
                }
                //21/11/2015: fanit82
                //cap nha vo quy tien mat
                //---------------------------------

                decimal decTienMatThu = 0;
                decTienMatThu = item.KhachDua == null ? 0 : (decimal)item.KhachDua;

                /*
                 * Nếu khách đưa tiền mặt lớn hơn số tiền cần thanh toán
                 * thì phai thoi tien cho khach, và số tiền thực sự vô quỹ tiền mặt
                 * chỉ là số tiền khách thanh toán
                 *
                 *
                 */
                if (decTienMatThu > item.ThanhToan)
                {
                    decTienMatThu = item.ThanhToan;
                }
                //decTienMatThu = item.KhachDua > item.ThanhToan ? item.ThanhToan : (decimal)item.KhachDua;

                QuyTienMatController.NhapQuyTienMat(item.DonHangID, item.NgayBan, decTienMatThu, "BH", "Tiền mặt bán hàng");
                //------------------end-------------
                dbControl.SaveChanges();
                scope.Complete();
            }
        }
Esempio n. 3
0
        static public void Add(TraHang item, List <TraHangChiTiet> items)
        {
            dbControl = new QlShop();
            using (TransactionScope scope = new TransactionScope())
            {
                item.TraHangID = TaoMaTraHang("RT", 8);
                //cap nhat so luong ton kho thuc te luc xuat
                foreach (TraHangChiTiet TraHangItem in items)
                {
                    TraHangItem.TraHangID = item.TraHangID;
                    TraHangItem.TonKho    = SanPhamController.GetTonKho(TraHangItem.SanPhamID);
                    TraHangItem.GiaVon    = SanPhamController.GetGiaVon(TraHangItem.SanPhamID);
                    //SanPhamController.CapNhatTonKho(DonHangItem.SanPhamID, DonHangItem.SoLuong);
                }

                dbControl.TraHangs.Add(item);
                dbControl.TraHangChiTiets.AddRange(items);
                //cap nhat so luong ton kho

                foreach (TraHangChiTiet TraHangItem in items)
                {
                    SanPhamController.CapNhatTonKho(TraHangItem.SanPhamID, 0 - TraHangItem.SoLuongTra);
                }
                //cap nha cong no va tong tien hang
                //if (item.KhachHangID != null)
                //{
                //    KhachHangController.CapNhatCongNo_MuaHang(item.KhachHangID, item.ConNo, item.TongCong);
                //}
                //21/11/2015: fanit82
                //cap nha vo quy tien mat
                //---------------------------------
                //QuyTienMatController.NhapQuyTienMat(item.DonHangID, item.NgayBan, item.ThanhToan, "BH", "Tiền mặt bán hàng");
                //------------------end-------------
                dbControl.SaveChanges();
                scope.Complete();
            }
        }