Exemplo n.º 1
0
        public NvVatTuChungTu InsertPhieu(NvNhapHangBanTraLaiVm.Dto instance)
        {
            var _parentUnitCode = GetParentUnitCode();

            instance.Calc();
            var item = Mapper.Map <NvNhapHangBanTraLaiVm.Dto, NvVatTuChungTu>(instance);

            item.Id = Guid.NewGuid().ToString();
            var    result    = AddUnit(item);
            string _unitCode = GetCurrentUnitCode();

            result.MaChungTu = BuildCode_PTNX(TypeVoucher.NHBANTL.ToString(), _unitCode, true);
            result.LoaiPhieu = TypeVoucher.NHBANTL.ToString();
            result.NgayCT    = DateTime.Now;
            result.TrangThai = 0;
            item.GenerateMaChungTuPk();
            result = Insert(result);
            var detailData            = Mapper.Map <List <NvNhapHangBanTraLaiVm.DtoDetail>, List <NvVatTuChungTuChiTiet> >(instance.DataDetails);
            var wareHouse             = UnitOfWork.Repository <MdWareHouse>().DbSet.FirstOrDefault(x => x.MaKho == result.MaKhoNhap);
            var merchandiseCollection = UnitOfWork.Repository <MdMerchandise>().DbSet;

            detailData.ForEach(x =>
            {
                var hang      = merchandiseCollection.FirstOrDefault(u => u.MaVatTu == x.MaHang && u.UnitCode.StartsWith(_parentUnitCode));
                x.TenHang     = hang != null ? hang.TenHang : "";
                x.Id          = Guid.NewGuid().ToString();
                x.MaChungTu   = result.MaChungTu;
                x.MaChungTuPk = result.MaChungTuPk;
                x.Index       = x.Index;
                x.VAT         = hang.MaVatVao;
            });
            InsertGeneralLedger(instance.DataClauseDetails, result);
            UnitOfWork.Repository <NvVatTuChungTuChiTiet>().InsertRange(detailData);
            return(result);
        }
Exemplo n.º 2
0
        public NvVatTuChungTu UpdatePhieu(NvNhapHangBanTraLaiVm.Dto instance)
        {
            var _parentUnitCode = GetParentUnitCode();

            instance.Calc();
            var exsitItem = FindById(instance.Id);

            if (exsitItem.TrangThai == (int)ApprovalState.IsComplete)
            {
                return(null);
            }
            var masterData = Mapper.Map <NvNhapHangBanTraLaiVm.Dto, NvVatTuChungTu>(instance);
            var detailData = Mapper.Map <List <NvNhapHangBanTraLaiVm.DtoDetail>, List <NvVatTuChungTuChiTiet> >(instance.DataDetails);

            {
                var detailCollection = UnitOfWork.Repository <NvVatTuChungTuChiTiet>().DbSet.Where(x => x.MaChungTuPk == exsitItem.MaChungTuPk);
                detailCollection.ToList().ForEach(x => x.ObjectState = ObjectState.Deleted);
            }
            var merchandiseCollection = UnitOfWork.Repository <MdMerchandise>().DbSet;

            detailData.ForEach(x =>
            {
                var merchandise = merchandiseCollection.FirstOrDefault(u => u.MaVatTu == x.MaHang && u.UnitCode.StartsWith(_parentUnitCode));
                x.TenHang       = merchandise != null ? merchandise.TenHang : "";
                x.Id            = Guid.NewGuid().ToString();
                x.MaChungTuPk   = exsitItem.MaChungTuPk;
                x.MaChungTu     = exsitItem.MaChungTu;
                x.SoLuongCT     = x.SoLuong;
                x.Index         = x.Index;
            });
            UnitOfWork.Repository <NvVatTuChungTuChiTiet>().InsertRange(detailData);
            UpdateGeneralLedger(instance.DataClauseDetails, exsitItem);
            var result = Update(masterData);

            return(result);
        }