Example #1
0
        public IHttpActionResult ThemPOTuKinhDoanh(ThongTinDonPO thongtinPO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            BH_DON_HANG_PO baogia = new BH_DON_HANG_PO();

            baogia.MA_SO_PO              = GenerateMaSoPO();
            baogia.NGAY_LEN_PO           = DateTime.Today.Date;
            baogia.MA_KHACH_HANG         = thongtinPO.MA_KHACH_HANG;
            baogia.TEN_LIEN_HE           = thongtinPO.TEN_LIEN_HE;
            baogia.HINH_THUC_THANH_TOAN  = thongtinPO.HINH_THUC_THANH_TOAN;
            baogia.TONG_TIEN_THANH_TOAN  = thongtinPO.TONG_TIEN_THANH_TOAN;
            baogia.TONG_TIEN_HANG        = thongtinPO.TONG_TIEN_HANG;
            baogia.TONG_TIEN_THUE_GTGT   = thongtinPO.TONG_TIEN_THUE_GTGT;
            baogia.SO_TIEN_VIET_BANG_CHU = thongtinPO.SO_TIEN_VIET_BANG_CHU;
            baogia.TRUC_THUOC            = thongtinPO.TRUC_THUOC;
            baogia.NHAN_VIEN_QUAN_LY     = thongtinPO.NHAN_VIEN_QUAN_LY;
            baogia.SO_BAO_GIA            = thongtinPO.SO_BAO_GIA;
            baogia.PHI_VC = thongtinPO.PHI_VC;
            if (thongtinPO.NGAY_GIAO_HANG_KD != null)
            {
                baogia.NGAY_GIAO_HANG = thongtinPO.NGAY_GIAO_HANG_KD;
            }
            baogia.DIA_DIEM_GIAO_HANG = thongtinPO.DIA_DIEM_GIAO_HANG;
            baogia.CAN_LAY_HOA_DON    = thongtinPO.CAN_LAY_HOA_DON;
            baogia.CAN_XUAT_NGAY      = thongtinPO.CAN_XUAT_NGAY;
            db.BH_DON_HANG_PO.Add(baogia);
            db.SaveChanges();

            foreach (var item in thongtinPO.ChiTietPO)
            {
                BH_CT_DON_HANG_PO lienhe = new BH_CT_DON_HANG_PO();
                lienhe.MA_SO_PO        = baogia.MA_SO_PO;
                lienhe.MA_HANG         = item.MA_HANG;
                lienhe.MA_DIEU_CHINH   = item.MA_DIEU_CHINH;
                lienhe.SO_LUONG        = item.SO_LUONG;
                lienhe.DVT             = item.DVT;
                lienhe.DON_GIA         = item.DON_GIA;
                lienhe.THANH_TIEN_HANG = item.THANH_TIEN_HANG;
                lienhe.THUE_GTGT       = thongtinPO.THUE_SUAT_GTGT;
                lienhe.TIEN_THUE_GTGT  = ((Convert.ToDouble(item.THANH_TIEN_HANG) * (thongtinPO.THUE_SUAT_GTGT / 100)));
                lienhe.TIEN_THANH_TOAN = Convert.ToDouble(lienhe.THANH_TIEN_HANG) + lienhe.TIEN_THUE_GTGT;
                db.BH_CT_DON_HANG_PO.Add(lienhe);
            }

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                throw;
            }

            return(Ok(baogia.MA_SO_PO));
        }
Example #2
0
        public IHttpActionResult PutBH_DON_HANG_PO(string id, ThongTinDonPO bH_DON_HANG_PO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != bH_DON_HANG_PO.MA_SO_PO)
            {
                return(BadRequest());
            }

            var edit = db.BH_DON_HANG_PO.Where(x => x.MA_SO_PO == id).FirstOrDefault();

            if (edit != null)
            {
                if (bH_DON_HANG_PO.NGAY_LEN_PO != null)
                {
                    edit.NGAY_LEN_PO = xlnt.Xulydatetime(bH_DON_HANG_PO.NGAY_LEN_PO);
                }
                edit.MA_KHACH_HANG         = bH_DON_HANG_PO.MA_KHACH_HANG;
                edit.TEN_LIEN_HE           = bH_DON_HANG_PO.TEN_LIEN_HE;
                edit.HINH_THUC_THANH_TOAN  = bH_DON_HANG_PO.HINH_THUC_THANH_TOAN;
                edit.TONG_TIEN_HANG        = bH_DON_HANG_PO.TONG_TIEN_HANG;
                edit.SO_TIEN_VIET_BANG_CHU = bH_DON_HANG_PO.SO_TIEN_VIET_BANG_CHU;
                if (bH_DON_HANG_PO.NGAY_GIAO_HANG != null)
                {
                    edit.NGAY_GIAO_HANG = xlnt.Xulydatetime(bH_DON_HANG_PO.NGAY_GIAO_HANG.ToString());
                }
                edit.DIA_DIEM_GIAO_HANG   = bH_DON_HANG_PO.DIA_DIEM_GIAO_HANG;
                edit.TONG_TIEN_THANH_TOAN = bH_DON_HANG_PO.TONG_TIEN_THANH_TOAN;
                edit.TONG_TIEN_THUE_GTGT  = bH_DON_HANG_PO.TONG_TIEN_THUE_GTGT;
                edit.DA_HUY          = bH_DON_HANG_PO.DA_HUY;
                edit.LY_DO_HUY       = bH_DON_HANG_PO.LY_DO_HUY;
                edit.CAN_XUAT_NGAY   = bH_DON_HANG_PO.CAN_XUAT_NGAY;
                edit.CAN_LAY_HOA_DON = bH_DON_HANG_PO.CAN_LAY_HOA_DON;
            }

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BH_DON_HANG_POExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PostThemPhieuBanHang(ThongTinDonPO thongtinPO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            BH_DON_BAN_HANG baogia = new BH_DON_BAN_HANG();

            baogia.MA_SO_BH              = GenerateSoBanHang();
            baogia.NGAY_BH               = DateTime.Today.Date;
            baogia.MA_KHACH_HANG         = thongtinPO.MA_KHACH_HANG;
            baogia.TEN_LIEN_HE           = thongtinPO.TEN_LIEN_HE;
            baogia.HINH_THUC_THANH_TOAN  = thongtinPO.HINH_THUC_THANH_TOAN;
            baogia.TONG_TIEN_THANH_TOAN  = thongtinPO.TONG_TIEN_THANH_TOAN;
            baogia.TONG_TIEN_HANG        = thongtinPO.TONG_TIEN_HANG;
            baogia.TONG_TIEN_THUE_GTGT   = thongtinPO.TONG_TIEN_THUE_GTGT;
            baogia.SO_TIEN_VIET_BANG_CHU = thongtinPO.SO_TIEN_VIET_BANG_CHU;
            baogia.TRUC_THUOC            = thongtinPO.TRUC_THUOC;
            baogia.DA_LAP_HOA_DON        = thongtinPO.DA_LAP_HOA_DON;
            baogia.NHAN_VIEN_QUAN_LY     = thongtinPO.NHAN_VIEN_QUAN_LY;
            if (thongtinPO.NGAY_GIAO_HANG != null)
            {
                baogia.NGAY_GIAO_HANG = xlnt.Xulydatetime(thongtinPO.NGAY_GIAO_HANG.ToString());
            }
            baogia.DIA_DIEM_GIAO_HANG = thongtinPO.DIA_DIEM_GIAO_HANG;
            baogia.DA_XUAT_KHO        = thongtinPO.DA_XUAT_KHO;
            baogia.MA_SO_PO           = thongtinPO.MA_SO_PO;
            db.BH_DON_BAN_HANG.Add(baogia);
            db.SaveChanges();

            foreach (var item in thongtinPO.ChiTietPO)
            {
                BH_CT_DON_BAN_HANG lienhe = new BH_CT_DON_BAN_HANG();
                lienhe.MA_SO_BH        = baogia.MA_SO_BH;
                lienhe.MA_HANG         = item.MA_HANG;
                lienhe.MA_DIEU_CHINH   = item.MA_DIEU_CHINH;
                lienhe.MA_PO           = item.MA_SO_PO;
                lienhe.TK_CO           = item.TK_CO;
                lienhe.TK_NO           = item.TK_NO;
                lienhe.TK_THUE         = item.TK_THUE;
                lienhe.SO_LUONG        = item.SO_LUONG;
                lienhe.DVT             = item.DVT;
                lienhe.DON_GIA         = item.DON_GIA;
                lienhe.THANH_TIEN_HANG = item.THANH_TIEN_HANG;
                lienhe.THUE_GTGT       = item.THUE_GTGT;
                lienhe.TIEN_THUE_GTGT  = ((Convert.ToDouble(item.THANH_TIEN_HANG) * (item.THUE_GTGT / 100)));
                lienhe.TIEN_THANH_TOAN = Convert.ToDouble(lienhe.THANH_TIEN_HANG) + lienhe.TIEN_THUE_GTGT;
                lienhe.DIEN_GIAI_THUE  = item.DIEN_GIAI_THUE;
                db.BH_CT_DON_BAN_HANG.Add(lienhe);
            }

            foreach (var item in thongtinPO.ChiTietPO)
            {
                var query = db.BH_CT_DON_HANG_PO.Where(x => x.ID == item.ID).FirstOrDefault();
                if (query != null)
                {
                    query.DA_BAN = true;
                    db.SaveChanges();
                }
            }

            var data = db.BH_CT_DON_HANG_PO.Where(x => x.MA_SO_PO == thongtinPO.MA_SO_PO && x.DA_BAN == false).ToList();

            if (data.Count() == 0)
            {
                var data1 = db.BH_DON_HANG_PO.Where(x => x.MA_SO_PO == thongtinPO.MA_SO_PO).FirstOrDefault();
                if (data1 != null)
                {
                    data1.DA_BAN_HANG = true;
                }
            }
            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                throw;
            }

            return(Ok(baogia.MA_SO_BH));
        }
Example #4
0
        public IHttpActionResult PostDon_Hang_PO(ThongTinDonPO thongtinPO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            BH_DON_HANG_PO baogia = new BH_DON_HANG_PO();

            baogia.MA_SO_PO              = GenerateMaSoPO();
            baogia.NGAY_LEN_PO           = DateTime.Today.Date;
            baogia.MA_KHACH_HANG         = thongtinPO.MA_KHACH_HANG;
            baogia.TEN_LIEN_HE           = thongtinPO.TEN_LIEN_HE;
            baogia.HINH_THUC_THANH_TOAN  = thongtinPO.HINH_THUC_THANH_TOAN;
            baogia.TONG_TIEN_THANH_TOAN  = thongtinPO.TONG_TIEN_THANH_TOAN;
            baogia.TONG_TIEN_HANG        = thongtinPO.TONG_TIEN_HANG;
            baogia.TONG_TIEN_THUE_GTGT   = thongtinPO.TONG_TIEN_THUE_GTGT;
            baogia.SO_TIEN_VIET_BANG_CHU = thongtinPO.SO_TIEN_VIET_BANG_CHU;
            baogia.PHI_VC            = thongtinPO.PHI_VC;
            baogia.TRUC_THUOC        = thongtinPO.TRUC_THUOC;
            baogia.DA_BAN_HANG       = thongtinPO.DA_BAN_HANG;
            baogia.NHAN_VIEN_QUAN_LY = thongtinPO.NHAN_VIEN_QUAN_LY;
            baogia.SO_BAO_GIA        = thongtinPO.SO_BAO_GIA;
            if (thongtinPO.NGAY_GIAO_HANG != null)
            {
                baogia.NGAY_GIAO_HANG = xlnt.Xulydatetime(thongtinPO.NGAY_GIAO_HANG.ToString());
            }
            baogia.DIA_DIEM_GIAO_HANG = thongtinPO.DIA_DIEM_GIAO_HANG;
            baogia.CAN_LAY_HOA_DON    = thongtinPO.CAN_LAY_HOA_DON;
            baogia.CAN_XUAT_NGAY      = thongtinPO.CAN_XUAT_NGAY;
            db.BH_DON_HANG_PO.Add(baogia);
            db.SaveChanges();

            foreach (var item in thongtinPO.ChiTietPO)
            {
                var query = db.TONKHO_HOPLONG.Where(x => x.MA_HANG == item.MA_HANG).ToList();
                //tongton = 0;
                //if (query != null)
                //{
                //    foreach (var tonkho in query)
                //    {
                //        tongton = tongton + tonkho.SL_HOPLONG;
                //    }
                //} else
                //{
                //    tongton = 0;
                //}

                BH_CT_DON_HANG_PO lienhe = new BH_CT_DON_HANG_PO();
                lienhe.MA_SO_PO        = baogia.MA_SO_PO;
                lienhe.MA_HANG         = item.MA_HANG;
                lienhe.MA_DIEU_CHINH   = item.MA_DIEU_CHINH;
                lienhe.SO_LUONG        = item.SO_LUONG;
                lienhe.DVT             = item.DVT;
                lienhe.DON_GIA         = item.DON_GIA;
                lienhe.THANH_TIEN_HANG = item.THANH_TIEN_HANG;
                lienhe.THUE_GTGT       = thongtinPO.THUE_SUAT_GTGT;
                lienhe.TIEN_THUE_GTGT  = ((Convert.ToDouble(item.THANH_TIEN_HANG) * (thongtinPO.THUE_SUAT_GTGT / 100)));
                lienhe.TIEN_THANH_TOAN = Convert.ToDouble(lienhe.THANH_TIEN_HANG) + lienhe.TIEN_THUE_GTGT;
                //if(item.SO_LUONG <= tongton)
                //{
                //    lienhe.CAN_GIU_HANG = true;
                //    lienhe.CAN_DAT_HANG = false;
                //} else if(item.SO_LUONG > tongton)
                //{
                //    lienhe.CAN_GIU_HANG = false;
                //    lienhe.CAN_DAT_HANG = true;
                //}
                db.BH_CT_DON_HANG_PO.Add(lienhe);
            }

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                throw;
            }

            return(Ok(baogia.MA_SO_PO));
        }