Beispiel #1
0
        public async Task <IHttpActionResult> Put(string id, MdCustomer instance)
        {
            var result = new TransferObj <MdCustomer>();

            if (id != instance.Id)
            {
                result.Status  = false;
                result.Message = "Id không hợp lệ";
                return(Ok(result));
            }
            try
            {
                var item = _serviceCustomer.TakeCareOfCustomer(instance);
                _serviceCustomer.UnitOfWork.Save();
                result.Status = true;
                result.Data   = item;
                return(Ok(result));
            }
            catch (Exception e)
            {
                result.Status  = false;
                result.Message = e.Message;
                return(Ok(result));
            }
        }
Beispiel #2
0
            public List <IQueryFilter> GetFilters()
            {
                var result = new List <IQueryFilter>();
                var refObj = new MdCustomer();

                if (!string.IsNullOrEmpty(this.MaKH))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.MaKH),
                        Value    = this.MaKH,
                        Method   = FilterMethod.Like
                    });
                }
                if (!string.IsNullOrEmpty(this.TenKH))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.TenKH),
                        Value    = this.TenKH,
                        Method   = FilterMethod.Like
                    });
                }
                if (!string.IsNullOrEmpty(this.DiaChi))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.DiaChi),
                        Value    = this.DiaChi,
                        Method   = FilterMethod.Like
                    });
                }
                if (!string.IsNullOrEmpty(this.TinhThanhPho))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.TinhThanhPho),
                        Value    = this.TinhThanhPho,
                        Method   = FilterMethod.Like
                    });
                }
                if (!string.IsNullOrEmpty(this.MaSoThue))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.MaSoThue),
                        Value    = this.MaSoThue,
                        Method   = FilterMethod.Like
                    });
                }
                if (!string.IsNullOrEmpty(this.DienThoai))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.DienThoai),
                        Value    = this.DienThoai,
                        Method   = FilterMethod.Like
                    });
                }
                if (!string.IsNullOrEmpty(this.Email))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.Email),
                        Value    = this.Email,
                        Method   = FilterMethod.Like
                    });
                }
                if (!string.IsNullOrEmpty(this.QuanHuyen))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.QuanHuyen),
                        Value    = this.QuanHuyen,
                        Method   = FilterMethod.Like
                    });
                }
                return(result);
            }
Beispiel #3
0
        public List <MdCustomer> ReportLoyalCustomer(ParameterCustomerCare para)
        {
            List <MdCustomer> result = new List <MdCustomer>();

            try
            {
                using (var ctx = new ERPContext())
                {
                    using (var dbContextTransaction = ctx.Database.BeginTransaction())
                    {
                        try
                        {
                            var pUnitCode       = new OracleParameter("pUnitCode", OracleDbType.NVarchar2, para.UnitCode, ParameterDirection.Input);
                            var pWareHouseCode  = new OracleParameter("pWareHouseCode", OracleDbType.NVarchar2, para.WareHouseCodes, ParameterDirection.Input);
                            var pFromDate       = new OracleParameter("pFromDate", OracleDbType.Date, para.FromDate.Date, ParameterDirection.Input);
                            var pToDate         = new OracleParameter("pToDate", OracleDbType.Date, para.ToDate.Date, ParameterDirection.Input);
                            var pStateTypeMoney = new OracleParameter("pStateTypeMoney", OracleDbType.Int32, para.StateTypeMoney, ParameterDirection.Input);
                            var pFromMoney      = new OracleParameter("pFromMoney", OracleDbType.Decimal, para.FromMoney, ParameterDirection.Input);
                            var pToMoney        = new OracleParameter("pToMoney", OracleDbType.Decimal, para.ToMoney, ParameterDirection.Input);
                            var pMaThe          = new OracleParameter("pMaThe", OracleDbType.NVarchar2, para.MaThe, ParameterDirection.Input);
                            var pDiaChi         = new OracleParameter("pDiaChi", OracleDbType.NVarchar2, para.DiaChi, ParameterDirection.Input);
                            //var pNgayHetHan = new OracleParameter("pNgayHetHan", OracleDbType.Date, para.NgayHetHan.Date, ParameterDirection.Input);
                            var outRef = new OracleParameter("outRef", OracleDbType.RefCursor, ParameterDirection.Output);
                            var str    = "BEGIN TBNETERP.CUSTOMERCARE.REPORT_LOYAL_CUSTOMER(:pUnitCode, :pWareHouseCode, :pFromDate,:pToDate,:pStateTypeMoney, :pFromMoney,:pToMoney, :pMaThe,:pDiaChi, :outRef); END;";
                            ctx.Database.ExecuteSqlCommand(str, pUnitCode, pWareHouseCode, pFromDate, pToDate, pStateTypeMoney, pFromMoney, pToMoney, pMaThe, pDiaChi, outRef);
                            OracleDataReader reader = ((OracleRefCursor)outRef.Value).GetDataReader();
                            while (reader.Read())
                            {
                                decimal  tienNguyenGia, tongTien;
                                DateTime ngayDacBiet, ngaySinh, ngayCapThe, ngayHetHan;
                                var      istienNguyenGia = decimal.TryParse(reader["tienNguyenGia"].ToString(), out tienNguyenGia);
                                var      istongTien      = decimal.TryParse(reader["tongTien"].ToString(), out tongTien);
                                var      isNgayDb        = DateTime.TryParse(reader["NGAYDACBIET"].ToString(), out ngayDacBiet);
                                var      isNgaySn        = DateTime.TryParse(reader["NGAYSINH"].ToString(), out ngaySinh);
                                var      isNgayCT        = DateTime.TryParse(reader["NGAYCAPTHE"].ToString(), out ngayCapThe);
                                var      isNgayHH        = DateTime.TryParse(reader["NGAYHETHAN"].ToString(), out ngayHetHan);
                                var      item            = new MdCustomer()
                                {
                                    MaKH          = reader["MaKH"].ToString(),
                                    TenKH         = reader["TenKH"].ToString(),
                                    DiaChi        = reader["DiaChi"].ToString(),
                                    DienThoai     = reader["DienThoai"].ToString(),
                                    Email         = reader["Email"].ToString(),
                                    MaThe         = reader["MATHE"].ToString(),
                                    NgayDacBiet   = isNgayDb?ngayDacBiet:new DateTime(0001, 1, 1),
                                    NgaySinh      = isNgaySn ? ngaySinh : new DateTime(0001, 1, 1),
                                    NgayCapThe    = isNgayCT ? ngayCapThe : new DateTime(0001, 1, 1),
                                    NgayHetHan    = isNgayHH ? ngayHetHan : new DateTime(0001, 1, 1),
                                    TienNguyenGia = istienNguyenGia?tienNguyenGia:0,
                                    TongTien      = istongTien?tongTien:0,
                                };
                                result.Add(item);
                            }
                            if (para.StateExpiredCard != null && para.StateExpiredCard == 1 && para.NgayHetHan != null)
                            {
                                var lstItem = result.Where(x => x.NgayHetHan <= para.NgayHetHan).ToList();
                                if (lstItem.Count > 0)
                                {
                                    lstItem.ForEach(x => result.Remove(x));
                                }
                            }
                            if (para.StateGiveCard != null)
                            {
                                switch (para.StateGiveCard)
                                {
                                case 1:     // Chưa cấp thẻ => Delete (Ngay cap the != null || != 0001)
                                    var lst = result.Where(x => x.NgayCapThe != null).ToList();
                                    if (lst.Count > 0)
                                    {
                                        lst.ForEach(x => {
                                            if (x.NgayCapThe.Value.Year != 0001)
                                            {
                                                result.Remove(x);
                                            }
                                        });
                                    }
                                    break;

                                case 2:     // Đã cấp thẻ => Delete (Ngay cap the = null || = 0001)
                                    lst = result.Where(x => x.NgayCapThe == null || x.NgayCapThe.Value.Year == 0001).ToList();
                                    if (lst.Count > 0)
                                    {
                                        lst.ForEach(x => result.Remove(x));
                                    }
                                    break;
                                }
                            }

                            dbContextTransaction.Commit();
                            return(result);
                        }
                        catch
                        {
                            dbContextTransaction.Rollback();
                            throw new Exception("Xảy ra lỗi trong khi chạy Store_Procude. Tự động rollback!");
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #4
0
        public List <MdCustomer> CustomerLevelUpCollection(ParameterCustomerCare para)
        {
            List <MdCustomer> result = new List <MdCustomer>();

            try
            {
                using (var ctx = new ERPContext())
                {
                    using (var dbContextTransaction = ctx.Database.BeginTransaction())
                    {
                        try
                        {
                            var pUnitCode          = new OracleParameter("pUnitCode", OracleDbType.NVarchar2, para.UnitCode, ParameterDirection.Input);
                            var pWareHouseCode     = new OracleParameter("pWareHouseCode", OracleDbType.NVarchar2, para.WareHouseCodes, ParameterDirection.Input);
                            var pFromDate          = new OracleParameter("pFromDate", OracleDbType.Date, para.FromDate.Date, ParameterDirection.Input);
                            var pToDate            = new OracleParameter("pToDate", OracleDbType.Date, para.ToDate.Date, ParameterDirection.Input);
                            var pStateTypeMoney    = new OracleParameter("pStateTypeMoney", OracleDbType.Int32, para.StateTypeMoney, ParameterDirection.Input);
                            var pFromMoney         = new OracleParameter("pFromMoney", OracleDbType.Decimal, para.FromMoney, ParameterDirection.Input);
                            var pToMoney           = new OracleParameter("pToMoney", OracleDbType.Decimal, para.ToMoney, ParameterDirection.Input);
                            var pStateCustomerCare = new OracleParameter("pStateCustomerCare", OracleDbType.Int32, para.StateCustomerCare, ParameterDirection.Input);

                            //var pNgayHetHan = new OracleParameter("pNgayHetHan", OracleDbType.Date, para.NgayHetHan.Date, ParameterDirection.Input);
                            var outRef = new OracleParameter("outRef", OracleDbType.RefCursor, ParameterDirection.Output);
                            var str    = "BEGIN TBNETERP.CUSTOMERCARE.CUSTOMER_LEVELUP(:pUnitCode, :pWareHouseCode, :pFromDate,:pToDate,:pStateTypeMoney, :pFromMoney,:pToMoney, :pStateCustomerCare, :outRef); END;";
                            ctx.Database.ExecuteSqlCommand(str, pUnitCode, pWareHouseCode, pFromDate, pToDate, pStateTypeMoney, pFromMoney, pToMoney, pStateCustomerCare, outRef);
                            OracleDataReader reader = ((OracleRefCursor)outRef.Value).GetDataReader();
                            while (reader.Read())
                            {
                                bool     care;
                                decimal  tienNguyenGia, tongTien, tienNguyenGiaCS, tongTienCS;
                                DateTime ngayDacBiet, ngaySinh, ngayCapThe, ngayHetHan, ngayChamSoc;
                                var      isTongTienCS      = decimal.TryParse(reader["tongTien_CHAMSOC"].ToString(), out tongTienCS);
                                var      istienNguyenGiaCS = decimal.TryParse(reader["tienNguyenGia_CHAMSOC"].ToString(), out tienNguyenGiaCS);
                                var      istienNguyenGia   = decimal.TryParse(reader["tienNguyenGia"].ToString(), out tienNguyenGia);
                                var      istongTien        = decimal.TryParse(reader["tongTien"].ToString(), out tongTien);
                                var      isNgayDb          = DateTime.TryParse(reader["NGAYDACBIET"].ToString(), out ngayDacBiet);
                                var      isNgaySn          = DateTime.TryParse(reader["NGAYSINH"].ToString(), out ngaySinh);
                                var      isNgayCT          = DateTime.TryParse(reader["NGAYCAPTHE"].ToString(), out ngayCapThe);
                                var      isNgayHH          = DateTime.TryParse(reader["NGAYHETHAN"].ToString(), out ngayHetHan);
                                var      isNgayChamSoc     = DateTime.TryParse(reader["NGAYCHAMSOC"].ToString(), out ngayChamSoc);
                                var      isCare            = bool.TryParse(reader["ISCARE"].ToString(), out care);
                                var      item = new MdCustomer()
                                {
                                    Id                    = reader["ID"].ToString(),
                                    MaKH                  = reader["MaKH"].ToString(),
                                    TenKH                 = reader["TenKH"].ToString(),
                                    DiaChi                = reader["DiaChi"].ToString(),
                                    DienThoai             = reader["DienThoai"].ToString(),
                                    Email                 = reader["Email"].ToString(),
                                    MaThe                 = reader["MATHE"].ToString(),
                                    GhiChu                = reader["GHICHU"].ToString(),
                                    GhiChuCu              = reader["GHICHUCU"].ToString(),
                                    IsCare                = isCare ? care : false,
                                    NgayDacBiet           = isNgayDb ? ngayDacBiet : new DateTime(0001, 1, 1),
                                    NgaySinh              = isNgaySn ? ngaySinh : new DateTime(0001, 1, 1),
                                    NgayCapThe            = isNgayCT ? ngayCapThe : new DateTime(0001, 1, 1),
                                    NgayHetHan            = isNgayHH ? ngayHetHan : new DateTime(0001, 1, 1),
                                    NgayChamSoc           = isNgayChamSoc ? ngayChamSoc : new DateTime(0001, 1, 1),
                                    TienNguyenGia         = istienNguyenGia ? tienNguyenGia : 0,
                                    TongTien              = istongTien ? tongTien : 0,
                                    TienNguyenGia_ChamSoc = istienNguyenGiaCS ? tienNguyenGiaCS : 0,
                                    TongTien_ChamSoc      = isTongTienCS ? tongTienCS : 0,
                                };
                                result.Add(item);
                            }


                            dbContextTransaction.Commit();
                            return(result);
                        }
                        catch
                        {
                            dbContextTransaction.Rollback();
                            throw new Exception("Xảy ra lỗi trong khi chạy Store_Procude. Tự động rollback!");
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #5
0
        public void SaveCustomer(string maKhachHang, NvGiaoDichQuayVm.DataDto instance)
        {
            bool    flag = false;
            decimal tienNguyenGia = 0, sumTienNguyenGia = 0, tienSale = 0, sumTienSale = 0, tongTien = 0, soDiem = 0;
            int     quenThe         = 0;
            var     _parentUnitCode = _serviceCustomer.GetParentUnitCode();
            var     khachHang       = _serviceCustomer.Repository.DbSet.FirstOrDefault(x => x.MaKH == maKhachHang && x.UnitCode.StartsWith(_parentUnitCode));

            if (khachHang != null)
            {
                foreach (var record in instance.DataDetails)
                {
                    if (instance.IsTichDiem)
                    {
                        flag = true;
                    }
                    if (record != null && record.TienKhuyenMai > 0)
                    {
                        decimal.TryParse(record.ThanhTien.ToString(), out tienSale);
                        sumTienSale = sumTienSale + tienSale;
                    }
                    else
                    {
                        decimal.TryParse(record.ThanhTien.ToString(), out tienNguyenGia);
                        sumTienNguyenGia = sumTienNguyenGia + tienNguyenGia;
                    }
                }
                decimal.TryParse(instance.SumTienHang.ToString(), out soDiem);
                if (flag)
                {
                    soDiem = soDiem * 2;
                }
                tongTien = sumTienNguyenGia + sumTienSale;
                //có rồi -- update
                int.TryParse(instance.QuenThe.ToString(), out quenThe);
                _serviceCustomer.UpdateCustomerAfterPurchase(sumTienNguyenGia, sumTienSale, tongTien, soDiem, quenThe, khachHang.Id);
            }
            else //chưa có khách hàng này
            {
                var kh = new MdCustomer();
                kh.MaKH        = instance.Makh;
                kh.TenKH       = instance.TenKH;
                kh.TenKhac     = instance.TenKH;
                kh.DiaChi      = instance.DiaChi;
                kh.DienThoai   = instance.DienThoai;
                kh.NgaySinh    = instance.NgaySinh;
                kh.NgayDacBiet = instance.NgayDacBiet;
                kh.Email       = instance.Email;
                kh.MaThe       = instance.MaThe;
                kh.SoDiem      = instance.TTienCoVat;
                kh.QuenThe     = 0;
                foreach (var record in instance.DataDetails)
                {
                    if (record != null && record.TienKhuyenMai > 0)
                    {
                        decimal.TryParse(record.ThanhTien.ToString(), out tienSale);
                        sumTienSale = sumTienSale + tienSale;
                    }
                    else
                    {
                        decimal.TryParse(record.ThanhTien.ToString(), out tienNguyenGia);
                        sumTienNguyenGia = sumTienNguyenGia + tienNguyenGia;
                    }
                }
                decimal.TryParse(instance.TTienCoVat.ToString(), out soDiem);
                tongTien = sumTienNguyenGia + sumTienSale;
                int quenTheNew = 0;
                _serviceCustomer.Insert(kh);
                _serviceCustomer.UpdateCustomerAfterPurchase(sumTienNguyenGia, sumTienSale, tongTien, soDiem, quenTheNew, kh.Id);
            }
        }