Beispiel #1
0
        public async Task <IHttpActionResult> Delete(string id)
        {
            NvVatTuChungTu instance = await _service.Repository.FindAsync(id);

            List <NvVatTuChungTuChiTiet> chitietinstance = _service.UnitOfWork.Repository <NvVatTuChungTuChiTiet>().DbSet.Where(o => o.MaChungTuPk == instance.MaChungTuPk).ToList();

            if (instance == null)
            {
                return(NotFound());
            }
            try
            {
                if (_service.DeletePhieu(id))
                {
                    _service.Delete(instance.Id);
                    _service.UnitOfWork.Save();
                    return(Ok(instance));
                }
                return(InternalServerError());
            }
            catch (Exception e)
            {
                WriteLogs.LogError(e);
                return(InternalServerError());
            }
        }
Beispiel #2
0
        public async Task <IHttpActionResult> Post(NvNhapHangBanTraLaiVm.Dto instance)
        {
            TransferObj <NvVatTuChungTu> result = new TransferObj <NvVatTuChungTu>();

            try
            {
                for (int i = 0; i < instance.DataDetails.Count; i++)
                {
                    if (string.IsNullOrEmpty(instance.DataDetails[i].MaHang))
                    {
                        instance.DataDetails.RemoveAt(i);
                    }
                }
                NvVatTuChungTu item = _service.InsertPhieu(instance);
                await _service.UnitOfWork.SaveAsync();

                result.Data   = item;
                result.Status = true;
                return(CreatedAtRoute("DefaultApi", new { controller = this, id = instance.Id }, result));
            }
            catch (Exception e)
            {
                return(InternalServerError());
            }
        }
Beispiel #3
0
        public async Task <IHttpActionResult> PostApproval(NvVatTuChungTu instance)
        {
            string         unitCode = _service.GetCurrentUnitCode();
            NvVatTuChungTu chungTu  = _service.FindById(instance.Id);

            if (chungTu == null || chungTu.TrangThai == (int)ApprovalState.IsComplete)
            {
                return(NotFound());
            }
            #region For Only ILOVEVN - B&T
            //chungTu.NgayDuyetPhieu = CurrentSetting.GetNgayKhoaSo(unitCode);
            //_InsertPhieuCongNo(chungTu);
            #endregion
            //chungTu = _service.FindById(instance.Id);
            chungTu.TrangThai          = (int)ApprovalState.IsComplete;
            chungTu.NgayDuyetPhieu     = CurrentSetting.GetNgayKhoaSo(unitCode);
            chungTu.ThoiGianDuyetPhieu = int.Parse(DateTime.Now.ToString("HHmmssfff"));
            chungTu.ObjectState        = ObjectState.Modified;
            _service.UnitOfWork.Save();
            switch (_service.Approval(chungTu))
            {
            case StateProcessApproval.NoPeriod:
                try
                {
                    await _service.UnitOfWork.SaveAsync();

                    return(Ok(true));
                }
                catch (Exception e)
                {
                    return(InternalServerError());
                }

            case StateProcessApproval.Success:
                try
                {
                    await _service.UnitOfWork.SaveAsync();

                    return(Ok(true));
                }
                catch (Exception e)
                {
                    return(InternalServerError());
                }

            case StateProcessApproval.Failed:
                break;

            default:
                break;
            }

            return(BadRequest("Không thể duyệt phiếu này"));
        }
Beispiel #4
0
            public List <IQueryFilter> GetFilters()
            {
                var result = new List <IQueryFilter>();
                var refObj = new NvVatTuChungTu();

                if (!string.IsNullOrEmpty(this.MaChungTu))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.MaChungTu),
                        Value    = this.MaChungTu,
                        Method   = FilterMethod.Like
                    });
                }

                if (!string.IsNullOrEmpty(this.NoiDung))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.NoiDung),
                        Value    = this.NoiDung,
                        Method   = FilterMethod.Like
                    });
                }
                if (!string.IsNullOrEmpty(this.MaKhoNhap))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.MaKhoNhap),
                        Value    = this.MaKhoNhap,
                        Method   = FilterMethod.Like
                    });
                }
                if (this.TuNgay.HasValue)
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.NgayCT),
                        Value    = this.TuNgay.Value,
                        Method   = FilterMethod.GreaterThanOrEqualTo
                    });
                }
                if (this.DenNgay.HasValue)
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.NgayCT),
                        Value    = this.DenNgay.Value.AddDays(1),
                        Method   = FilterMethod.LessThan
                    });
                }
                return(result);
            }
Beispiel #5
0
        public async Task <IHttpActionResult> PostApproval(NvVatTuChungTu instance)
        {
            var unitCode = _service.GetCurrentUnitCode();
            var chungTu  = _service.FindById(instance.Id);

            if (chungTu == null || chungTu.TrangThai == (int)ApprovalState.IsComplete)
            {
                return(NotFound());
            }
            chungTu.TrangThai      = (int)ApprovalState.IsComplete;
            chungTu.NgayDuyetPhieu = CurrentSetting.GetNgayKhoaSo(unitCode);
            chungTu.ObjectState    = ObjectState.Modified;
            await _service.UnitOfWork.SaveAsync();

            switch (_service.Approval(chungTu.Id))
            {
            case StateProcessApproval.NoPeriod:

                try
                {
                    await _service.UnitOfWork.SaveAsync();

                    return(Ok(true));
                }
                catch (Exception e)
                {
                    return(InternalServerError());
                }

            case StateProcessApproval.Success:

                try
                {
                    await _service.UnitOfWork.SaveAsync();

                    return(Ok(true));
                }
                catch (Exception e)
                {
                    return(InternalServerError());
                }

            case StateProcessApproval.Failed:
                break;

            default:
                break;
            }

            return(BadRequest("Không thể duyệt phiếu này"));
        }
Beispiel #6
0
        private void _InsertPhieuCongNo(NvVatTuChungTu chungTu)
        {
            //Cos nhieu phieu trong ngay phat sinh no.
            var unitCode = _service.GetCurrentUnitCode();

            var _thanhTienCanTra = _serviceCongNo.GetAmmountCustomerBorrowed(chungTu.MaKhachHang, chungTu.NgayDuyetPhieu.Value).ThanhTienCanTra;

            _serviceCongNo.InsertPhieu(new NvCongNoVm.Dto()
            {
                Id              = Guid.NewGuid().ToString(),
                LoaiChungTu     = LoaiCongNo.CNKH.ToString(),
                NgayCT          = CurrentSetting.GetNgayKhoaSo(unitCode),
                MaKhachHang     = chungTu.MaKhachHang,
                GhiChu          = "[" + chungTu.MaChungTu + "]",
                ThanhTien       = chungTu.ThanhTienSauVat,
                ThanhTienCanTra = _thanhTienCanTra,
            });
            _serviceCongNo.UnitOfWork.Save();
        }
Beispiel #7
0
        public async Task <IHttpActionResult> Delete(string id)
        {
            NvVatTuChungTu instance = await _service.Repository.FindAsync(id);

            if (instance == null)
            {
                return(NotFound());
            }
            try
            {
                _service.Delete(instance.Id);
                await _service.UnitOfWork.SaveAsync();

                return(Ok(instance));
            }
            catch (Exception)
            {
                return(null);
            }
        }
Beispiel #8
0
        public async Task <IHttpActionResult> GetDetails(string id)
        {
            TransferObj <NvNhapHangBanTraLaiVm.Dto> result = new TransferObj <NvNhapHangBanTraLaiVm.Dto>();

            NvNhapHangBanTraLaiVm.Dto temp = new NvNhapHangBanTraLaiVm.Dto();

            NvVatTuChungTu phieu = _service.FindById(id);

            if (phieu != null)
            {
                temp = Mapper.Map <NvVatTuChungTu, NvNhapHangBanTraLaiVm.Dto>(phieu);
                List <NvVatTuChungTuChiTiet> chiTietPhieu = _service.UnitOfWork.Repository <NvVatTuChungTuChiTiet>().DbSet.Where(x => x.MaChungTuPk == phieu.MaChungTuPk).ToList();
                List <DclGeneralLedger>      chiTietSoCai = _service.UnitOfWork.Repository <DclGeneralLedger>().DbSet.Where(x => x.MaChungTuPk == phieu.MaChungTuPk).ToList();
                temp.DataDetails = Mapper.Map <List <NvVatTuChungTuChiTiet>, List <NvNhapHangBanTraLaiVm.DtoDetail> >(chiTietPhieu);
                //temp.DataDetails.ForEach(x => x.CalcResult());
                temp.DataClauseDetails = Mapper.Map <List <DclGeneralLedger>, List <NvNhapHangBanTraLaiVm.DtoClauseDetail> >(chiTietSoCai);
                result.Data            = temp;
                result.Status          = true;
                return(Ok(result));
            }
            return(NotFound());
        }
Beispiel #9
0
        public async Task <IHttpActionResult> Delete(string id)
        {
            NvVatTuChungTu instance = await _service.Repository.FindAsync(id);

            if (instance == null)
            {
                return(NotFound());
            }
            try
            {
                if (_service.DeletePhieu(id))
                {
                    _service.Delete(instance.Id);
                    _service.UnitOfWork.Save();
                    return(Ok(instance));
                }
                return(InternalServerError());
            }
            catch (Exception e)
            {
                WriteLogs.LogError(e);
                return(InternalServerError());
            }
        }
Beispiel #10
0
        public async Task <IHttpActionResult> Put(string id, NvNhapHangBanTraLaiVm.Dto instance)
        {
            TransferObj <NvVatTuChungTu> result = new TransferObj <NvVatTuChungTu>();

            for (int i = 0; i < instance.DataDetails.Count; i++)
            {
                if (instance.DataDetails[i].MaHang == null)
                {
                    instance.DataDetails.RemoveAt(i);
                }
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            NvVatTuChungTu check = _service.FindById(instance.Id);

            if (id != instance.Id || check.TrangThai == (int)ApprovalState.IsComplete)
            {
                return(BadRequest());
            }
            try
            {
                NvVatTuChungTu item = _service.UpdatePhieu(instance);
                await _service.UnitOfWork.SaveAsync();

                result.Status = true;
                result.Data   = item;
                return(Ok(result));
            }
            catch (Exception e)
            {
                return(InternalServerError());
            }
        }
Beispiel #11
0
            public List <IQueryFilter> GetFilters()
            {
                var result = new List <IQueryFilter>();
                var refObj = new NvVatTuChungTu();

                if (!string.IsNullOrEmpty(this.MaChungTu))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.MaChungTu),
                        Value    = this.MaChungTu,
                        Method   = FilterMethod.Like
                    });
                }
                if (this.TrangThai != -1)// không tồn tại trạng thái
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.TrangThai),
                        Value    = this.TrangThai,
                        Method   = FilterMethod.EqualTo
                    });
                }
                if (!string.IsNullOrEmpty(this.MaKhachHang))
                {
                    var codes = this.MaKhachHang.Split(',').ToList();
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.MaKhachHang),
                        Value    = codes,
                        Method   = FilterMethod.In
                    });
                }
                if (!string.IsNullOrEmpty(this.NoiDung))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.NoiDung),
                        Value    = this.NoiDung,
                        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.MaKhoNhap))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.MaKhoNhap),
                        Value    = this.MaKhoNhap,
                        Method   = FilterMethod.Like
                    });
                }
                if (!string.IsNullOrEmpty(this.MaHoaDon))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.MaHoaDon),
                        Value    = this.MaHoaDon,
                        Method   = FilterMethod.Like
                    });
                }
                if (this.TuNgay.HasValue)
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.NgayCT),
                        Value    = this.TuNgay.Value,
                        Method   = FilterMethod.GreaterThanOrEqualTo
                    });
                }
                if (this.DenNgay.HasValue)
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.NgayCT),
                        Value    = this.DenNgay.Value.AddDays(1),
                        Method   = FilterMethod.LessThan
                    });
                }
                if (!string.IsNullOrEmpty(this.ICreateBy))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.ICreateBy),
                        Value    = this.ICreateBy,
                        Method   = FilterMethod.Like
                    });
                }
                return(result);
            }
Beispiel #12
0
            public List <IQueryFilter> GetFilters()
            {
                var result = new List <IQueryFilter>();
                var refObj = new NvVatTuChungTu();

                if (!string.IsNullOrEmpty(this.MaChungTu))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.MaChungTu),
                        Value    = this.MaChungTu,
                        Method   = FilterMethod.Like
                    });
                }
                if (!string.IsNullOrEmpty(this.NoiDung))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.NoiDung),
                        Value    = this.NoiDung,
                        Method   = FilterMethod.Like
                    });
                }
                if (!string.IsNullOrEmpty(this.MaHoaDon))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.MaHoaDon),
                        Value    = this.MaHoaDon,
                        Method   = FilterMethod.Like
                    });
                }
                if (!string.IsNullOrEmpty(this.MaKhachHang))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.MaKhachHang),
                        Value    = this.MaKhachHang,
                        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.MaKhoXuat))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.MaKhoXuat),
                        Value    = this.MaKhoXuat,
                        Method   = FilterMethod.Like
                    });
                }
                if (this.NgayCT.HasValue)
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.NgayCT),
                        Value    = this.NgayCT.Value,
                        Method   = FilterMethod.EqualTo
                    });
                }
                return(result);
            }
Beispiel #13
0
            public List <IQueryFilter> GetFilters()
            {
                var result = new List <IQueryFilter>();
                var refObj = new NvVatTuChungTu();

                if (!string.IsNullOrEmpty(this.MaChungTu))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.MaChungTu),
                        Value    = this.MaChungTu,
                        Method   = FilterMethod.Like
                    });
                }
                if (!string.IsNullOrEmpty(this.NoiDung))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.NoiDung),
                        Value    = this.NoiDung,
                        Method   = FilterMethod.Like
                    });
                }
                if (!string.IsNullOrEmpty(this.NguoiVanChuyen))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.NguoiVanChuyen),
                        Value    = this.NguoiVanChuyen,
                        Method   = FilterMethod.Like
                    });
                }
                if (!string.IsNullOrEmpty(this.LenhDieuDong))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.LenhDieuDong),
                        Value    = this.LenhDieuDong,
                        Method   = FilterMethod.Like
                    });
                }
                if (!string.IsNullOrEmpty(this.PhuongTienVanChuyen))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.PhuongTienVanChuyen),
                        Value    = this.PhuongTienVanChuyen,
                        Method   = FilterMethod.Like
                    });
                }
                if (!string.IsNullOrEmpty(this.MaDonViNhan))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.MaDonViNhan),
                        Value    = this.MaDonViNhan,
                        Method   = FilterMethod.Like
                    });
                }
                if (this.TuNgay.HasValue)
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.NgayCT),
                        Value    = this.TuNgay.Value,
                        Method   = FilterMethod.GreaterThanOrEqualTo
                    });
                }
                if (this.DenNgay.HasValue)
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.NgayCT),
                        Value    = this.DenNgay.Value.AddDays(1),
                        Method   = FilterMethod.LessThan
                    });
                }
                if (!string.IsNullOrEmpty(this.MaKhoXuat))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.MaKhoXuat),
                        Value    = this.MaKhoXuat,
                        Method   = FilterMethod.Like
                    });
                }
                if (!string.IsNullOrEmpty(this.MaKhoNhap))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.MaKhoNhap),
                        Value    = this.MaKhoNhap,
                        Method   = FilterMethod.Like
                    });
                }
                if (TrangThai != 1)
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.TrangThai),
                        Value    = this.TrangThai,
                        Method   = FilterMethod.EqualTo
                    });
                }
                return(result);
            }