Ejemplo n.º 1
0
        public NvVatTuChungTu InsertPhieu(NvXuatKhacVm.Dto instance)
        {
            var _ParentUnitCode = GetParentUnitCode();
            var item            = Mapper.Map <NvXuatKhacVm.Dto, NvVatTuChungTu>(instance);

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

            result.MaChungTu = BuildCode_PTNX(TypeVoucher.XKHAC.ToString(), _unitCode, true);
            item.GenerateMaChungTuPk();
            result = Insert(result);
            var detailData            = AutoMapper.Mapper.Map <List <NvXuatKhacVm.DtoDetail>, List <NvVatTuChungTuChiTiet> >(instance.DataDetails);
            var importWareHouse       = 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.SoLuongCT    = x.SoLuong;
                x.SoLuongBaoCT = x.SoLuongBao;
                x.GiaVon       = x.DonGia;
            });
            InsertGeneralLedger(instance.DataClauseDetails, result);
            UnitOfWork.Repository <NvVatTuChungTuChiTiet>().InsertRange(detailData);
            return(result);
        }
Ejemplo n.º 2
0
        public NvVatTuChungTu UpdatePhieu(NvXuatKhacVm.Dto instance)
        {
            var _ParentUnitCode = GetParentUnitCode();

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

            if (exsitItem.TrangThai == (int)ApprovalState.IsComplete)
            {
                return(null);
            }

            var masterData = Mapper.Map <NvXuatKhacVm.Dto, NvVatTuChungTu>(instance);
            var detailData = Mapper.Map <List <NvXuatKhacVm.DtoDetail>, List <NvVatTuChungTuChiTiet> >(instance.DataDetails);

            var merchandiseCollection = UnitOfWork.Repository <MdMerchandise>().DbSet;

            {
                var detailCollection = UnitOfWork.Repository <NvVatTuChungTuChiTiet>().DbSet.Where(x => x.MaChungTuPk == exsitItem.MaChungTuPk);
                detailCollection.ToList().ForEach(x => x.ObjectState = ObjectState.Deleted);
            }
            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.MaChungTuPk  = exsitItem.MaChungTuPk;
                x.MaChungTu    = exsitItem.MaChungTu;
                x.SoLuongCT    = x.SoLuong;
                x.SoLuongBaoCT = x.SoLuongBao;
            });
            UnitOfWork.Repository <NvVatTuChungTuChiTiet>().InsertRange(detailData);
            UpdateGeneralLedger(instance.DataClauseDetails, exsitItem);
            var result = Update(masterData);

            return(result);
        }