public List <sanphambanchaydto> doanhthubanraitnhat(DateTime ngaynhaptu, DateTime ngaynhapden)
        {
            sanphamcontroller spc = new sanphamcontroller();
            var query             =
                (from p in spc.laytatca()
                 let tongtien = (from op in cthdrp.GetAll()
                                 where op.id == p.id && op.hoadon.ngayban >= ngaynhaptu && op.hoadon.ngayban <= ngaynhapden
                                 select op.soluongmua * op.giaban).Sum()
                                let totalQuantity = (from op in cthdrp.GetAll()
                                                     where op.id == p.id && op.hoadon.ngayban >= ngaynhaptu && op.hoadon.ngayban <= ngaynhapden
                                                     select op.soluongmua).Sum()
                                                    where tongtien > 0
                                                    orderby tongtien ascending
                                                    select new sanphambanchaydto
            {
                id = p.id,
                masp = p.masp,
                tensp = p.tensp,
                giaban = p.giaban,
                soluongbanra = totalQuantity,
                doanhthu = tongtien
            }).Take(10);

            return(query.ToList());
        }
Пример #2
0
        public bool add(hoadon entity)
        {
            sanphamcontroller spcontroller = new sanphamcontroller();

            foreach (chitiethoadon cthd in entity.chitiethoadons)
            {
                if (!spcontroller.capnhatsoluong(cthd.id, cthd.soluongmua))
                {
                    return(false);
                }
            }
            return(hdrp.Add(entity));
        }
        public bool capnhattrangthai(int madon, int stt, int trangthai, int soluongmoi = 0)
        {
            chitietdondathang ctddh = ctddhrp.First(c => c.madondathang == madon && c.stt == stt);
            int?slnhancu            = ctddh.soluongnhan;
            sanphamcontroller spc   = new sanphamcontroller();

            if (trangthai == 0)
            {
                spc.capnhatsoluong(ctddh.id, slnhancu);
                ctddh.soluongnhan = 0;
                ctddh.trangthai   = "Chưa giao";
                ctddh.tinhtrang   = "Đang chờ";
            }
            else if (trangthai == 1)
            {
                int?sltangthem = ctddh.soluongdat - slnhancu;
                spc.capnhatsoluongton(ctddh.id, sltangthem);
                ctddh.trangthai   = "Đã hoàn tất";
                ctddh.tinhtrang   = "Kết thúc";
                ctddh.soluongnhan = ctddh.soluongdat;
            }
            else if (trangthai == 2)
            {
                if (ctddh.soluongnhan > 0)
                {
                    spc.capnhatsoluong(ctddh.id, ctddh.soluongnhan);
                }
                ctddh.trangthai   = "Hủy";
                ctddh.tinhtrang   = "Kết thúc";
                ctddh.soluongnhan = 0;
            }
            else if (trangthai == 3)
            {
                int?sltangthem = soluongmoi - slnhancu;
                if (soluongmoi > 0)
                {
                    spc.capnhatsoluongton(ctddh.id, soluongmoi);
                }
                ctddh.trangthai   = "Thiếu hàng";
                ctddh.soluongnhan = soluongmoi;
            }
            return(ctddhrp.Update(ctddh));
        }