public static void NhapKho(KaraokeEntities kara, BOChiTietNhapKho chitiet,BONhapKho nhapKho)
 {
     LICHSUTONKHO lichSuDauKy = (from a in kara.LICHSUTONKHOes
                                 where a.MonID == chitiet.MenuKichThuocMon.MenuKichThuocMon.MonID && a.KhoID==nhapKho.NhapKho.KhoID
                                 orderby a.ID descending
                                 select a).FirstOrDefault();
     LICHSUTONKHO lichSu = new LICHSUTONKHO();
     if (lichSuDauKy == null)
     {
         lichSu.DauKySoLuong = 0;
         lichSu.DauKyDonGia = 0;
     }
     else
     {
         lichSu.DauKySoLuong = lichSuDauKy.CuoiKySoLuong;
         lichSu.DauKyDonGia = lichSuDauKy.CuoiKyDonGia;
     }
     int soluong = chitiet.ChiTietNhapKho.SoLuongNhap * chitiet.MenuKichThuocMon.MenuKichThuocMon.KichThuocLoaiBan;
     lichSu.NhapSoLuong = soluong;
     lichSu.NhapDonGia = chitiet.ChiTietNhapKho.GiaNhap / chitiet.MenuKichThuocMon.MenuKichThuocMon.KichThuocLoaiBan;
     lichSu.CuoiKySoLuong = lichSu.DauKySoLuong + lichSu.NhapSoLuong;
     lichSu.CuoiKyDonGia = lichSu.CuoiKyDonGia;
     lichSu.NgayGhiNhan = DateTime.Now;
     lichSu.MonID = chitiet.MenuKichThuocMon.MenuKichThuocMon.MonID;
     lichSu.KhoID = nhapKho.NhapKho.KhoID;
     lichSu.LoaiPhatSinhID = 1;
     kara.LICHSUTONKHOes.AddObject(lichSu);
 }
 /// <summary>
 /// Create a new LICHSUTONKHO object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="ngayGhiNhan">Initial value of the NgayGhiNhan property.</param>
 /// <param name="dauKySoLuong">Initial value of the DauKySoLuong property.</param>
 /// <param name="dauKyDonGia">Initial value of the DauKyDonGia property.</param>
 /// <param name="nhapSoLuong">Initial value of the NhapSoLuong property.</param>
 /// <param name="nhapDonGia">Initial value of the NhapDonGia property.</param>
 /// <param name="xuatSoLuong">Initial value of the XuatSoLuong property.</param>
 /// <param name="xuatDonGia">Initial value of the XuatDonGia property.</param>
 /// <param name="cuoiKySoLuong">Initial value of the CuoiKySoLuong property.</param>
 /// <param name="cuoiKyDonGia">Initial value of the CuoiKyDonGia property.</param>
 public static LICHSUTONKHO CreateLICHSUTONKHO(global::System.Int32 id, global::System.DateTime ngayGhiNhan, global::System.Int32 dauKySoLuong, global::System.Decimal dauKyDonGia, global::System.Int32 nhapSoLuong, global::System.Decimal nhapDonGia, global::System.Int32 xuatSoLuong, global::System.Decimal xuatDonGia, global::System.Int32 cuoiKySoLuong, global::System.Decimal cuoiKyDonGia)
 {
     LICHSUTONKHO lICHSUTONKHO = new LICHSUTONKHO();
     lICHSUTONKHO.ID = id;
     lICHSUTONKHO.NgayGhiNhan = ngayGhiNhan;
     lICHSUTONKHO.DauKySoLuong = dauKySoLuong;
     lICHSUTONKHO.DauKyDonGia = dauKyDonGia;
     lICHSUTONKHO.NhapSoLuong = nhapSoLuong;
     lICHSUTONKHO.NhapDonGia = nhapDonGia;
     lICHSUTONKHO.XuatSoLuong = xuatSoLuong;
     lICHSUTONKHO.XuatDonGia = xuatDonGia;
     lICHSUTONKHO.CuoiKySoLuong = cuoiKySoLuong;
     lICHSUTONKHO.CuoiKyDonGia = cuoiKyDonGia;
     return lICHSUTONKHO;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the LICHSUTONKHOes EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToLICHSUTONKHOes(LICHSUTONKHO lICHSUTONKHO)
 {
     base.AddObject("LICHSUTONKHOes", lICHSUTONKHO);
 }
        public static void ChuyenKho(KaraokeEntities kara, BOChuyenKho chuyenKho)
        {
            var ktm = (from a in kara.MENUKICHTHUOCMONs
                       where a.MonID == chuyenKho.TonKho.MonID
                       orderby a.KichThuocLoaiBan ascending
                       select a).FirstOrDefault();
            if (ktm!=null)
            {
                int soluong = chuyenKho.SoLuong;
                //if (ktm.KichThuocLoaiBan>0)
                //{
                //    soluong = soluong / ktm.KichThuocLoaiBan;
                //}
                //kho di
                LICHSUTONKHO lichSuDauKyDi = (from a in kara.LICHSUTONKHOes
                                        where a.MonID == ktm.MonID && a.KhoID == chuyenKho.TonKho.KhoID
                                        orderby a.ID descending
                                        select a).FirstOrDefault();
                LICHSUTONKHO lichSuDi = new LICHSUTONKHO();
                if (lichSuDauKyDi == null)
                {
                    lichSuDi.DauKySoLuong = 0;
                    lichSuDi.DauKyDonGia = 0;
                }
                else
                {
                    lichSuDi.DauKySoLuong = lichSuDauKyDi.CuoiKySoLuong;
                    lichSuDi.DauKyDonGia = lichSuDauKyDi.CuoiKyDonGia;
                }
                lichSuDi.XuatSoLuong = soluong;
                lichSuDi.XuatDonGia = chuyenKho.TonKho.GiaNhap;
                lichSuDi.CuoiKySoLuong = lichSuDi.DauKySoLuong - lichSuDi.XuatSoLuong;
                lichSuDi.CuoiKyDonGia = lichSuDi.CuoiKyDonGia;
                lichSuDi.NgayGhiNhan = DateTime.Now;
                lichSuDi.MonID = ktm.MonID;
                lichSuDi.KhoID = chuyenKho.TonKho.KhoID;
                lichSuDi.LoaiPhatSinhID = 2;
                kara.LICHSUTONKHOes.AddObject(lichSuDi);

                //kho den
                LICHSUTONKHO lichSuDauKyDen = (from a in kara.LICHSUTONKHOes
                                            where a.MonID == ktm.MonID && a.KhoID == chuyenKho.KhoDenID
                                            orderby a.ID descending
                                            select a).FirstOrDefault();
                LICHSUTONKHO lichSuDen = new LICHSUTONKHO();
                if (lichSuDauKyDen == null)
                {
                    lichSuDen.DauKySoLuong = 0;
                    lichSuDen.DauKyDonGia = 0;
                }
                else
                {
                    lichSuDen.DauKySoLuong = lichSuDauKyDen.CuoiKySoLuong;
                    lichSuDen.DauKyDonGia = lichSuDauKyDen.CuoiKyDonGia;
                }
                lichSuDen.NhapSoLuong = soluong;
                lichSuDen.XuatDonGia = chuyenKho.TonKho.GiaNhap;
                lichSuDen.CuoiKySoLuong = lichSuDen.DauKySoLuong + lichSuDen.NhapSoLuong;
                lichSuDen.CuoiKyDonGia = lichSuDen.CuoiKyDonGia;
                lichSuDen.NgayGhiNhan = DateTime.Now;
                lichSuDen.MonID = ktm.MonID;
                lichSuDen.KhoID = chuyenKho.KhoDenID;
                lichSuDen.LoaiPhatSinhID = 2;
                kara.LICHSUTONKHOes.AddObject(lichSuDen);
            }
        }
 public static void BanHang(KaraokeEntities kara, BOBanHang banhang)
 {
     foreach (var chitiet in banhang._ListChiTietBanHang)
     {                
         int soluong = chitiet.ChiTietBanHang.SoLuongBan * chitiet.ChiTietBanHang.KichThuocLoaiBan;
         LICHSUTONKHO lichSuDauKy = (from a in kara.LICHSUTONKHOes
                                     where a.MonID == chitiet.MenuKichThuocMon.MonID
                                     orderby a.ID descending
                                     select a).FirstOrDefault();
         LICHSUTONKHO lichSu = new LICHSUTONKHO();
         if (lichSuDauKy == null)
         {
             lichSu.DauKySoLuong = 0;
             lichSu.DauKyDonGia = 0;
         }
         else
         {
             lichSu.DauKySoLuong = lichSuDauKy.CuoiKySoLuong;
             lichSu.DauKyDonGia = lichSuDauKy.CuoiKyDonGia;
         }
         lichSu.XuatSoLuong = soluong;
         lichSu.XuatDonGia = chitiet.ChiTietBanHang.GiaBan;
         lichSu.CuoiKySoLuong = lichSu.DauKySoLuong - lichSu.XuatSoLuong;
         lichSu.CuoiKyDonGia = lichSu.CuoiKyDonGia;
         lichSu.NgayGhiNhan = DateTime.Now;
         lichSu.MonID = chitiet.MenuKichThuocMon.MonID;
         lichSu.KhoID = banhang.KhoID;
         lichSu.LoaiPhatSinhID = 5;
         kara.LICHSUTONKHOes.AddObject(lichSu);
     }
 }