示例#1
0
        public async Task Update(UpdateCWGLTravelReimbursementInput input)
        {
            if (input.Id != Guid.Empty)
            {
                var dbmodel = await _repository.FirstOrDefaultAsync(x => x.Id == input.Id);

                if (dbmodel == null)
                {
                    throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "该数据不存在。");
                }
                var logModel = new CWGLTravelReimbursement();
                if (input.IsUpdateForChange)
                {
                    logModel = dbmodel.DeepClone();
                }

                dbmodel.Money            = input.Money;
                dbmodel.Note             = input.Note;
                dbmodel.Nummber          = input.Nummber;
                dbmodel.BorrowMoneyId    = input.BorrowMoneyId;
                dbmodel.WorkoutId        = input.WorkoutId;
                input.FACData.BusinessId = input.Id.ToString();
                var totalFee = 0m;
                foreach (var item in input.DetailList)
                {
                    totalFee = totalFee + item.Fare ?? 0 + item.Accommodation ?? 0 + item.Other ?? 0;
                }
                if (input.BorrowMoneyId.HasValue)
                {
                    var entityBorro = await _cWGLBorrowMonetrepository.GetAsync(input.BorrowMoneyId.Value);

                    if (entityBorro.Money == totalFee)
                    {
                        dbmodel.ResultType = (int)RefundResultType.无退无报;
                    }
                    else if (entityBorro.Money > totalFee)
                    {
                        dbmodel.ResultType = (int)RefundResultType.财务应收款;
                    }
                    else
                    {
                        dbmodel.ResultType = (int)RefundResultType.财务应付款;
                    }
                    dbmodel.Money = Math.Abs(entityBorro.Money - totalFee);
                }
                else
                {
                    dbmodel.Money      = totalFee;
                    dbmodel.ResultType = (int)RefundResultType.财务应付款;
                }


                await _repository.UpdateAsync(dbmodel);

                var details = await _detailRepository.GetAll().Where(r => r.TravelReimbursementId == dbmodel.Id).ToListAsync();

                var old_Details = new List <CWGLTravelReimbursementDetailLogDto>();
                var old_Model   = new CWGLTravelReimbursementLogDto()
                {
                    Id = logModel.Id, Money = logModel.Money, Note = logModel.Note, Nummber = logModel.Nummber
                };
                foreach (var item in details)
                {
                    old_Details.Add(item.MapTo <CWGLTravelReimbursementDetailLogDto>());
                }
                old_Model.Detail = old_Details;
                var new_Detail = new List <CWGLTravelReimbursementDetailLogDto>();
                foreach (var item in input.DetailList)
                {
                    var entity = new CWGLTravelReimbursementDetailLogDto()
                    {
                        Accommodation = item.Accommodation,
                        Address       = item.Address,
                        BeginTime     = item.BeginTime,
                        Day           = item.Day,
                        EndTime       = item.EndTime,
                        Fare          = item.Fare,
                        Id            = item.Id ?? Guid.Empty,
                        Other         = item.Other,
                        Vehicle       = item.Vehicle
                    };
                    new_Detail.Add(entity);
                }
                var new_Model = new CWGLTravelReimbursementLogDto()
                {
                    Id = dbmodel.Id, Money = dbmodel.Money, Note = dbmodel.Note, Nummber = dbmodel.Nummber, Detail = new_Detail
                };
                var add_details = input.DetailList.Where(r => !r.Id.HasValue);
                foreach (var item in add_details)
                {
                    var entity = item.MapTo <CWGLTravelReimbursementDetail>();
                    entity.Id = Guid.NewGuid();
                    entity.TravelReimbursementId = dbmodel.Id;
                    await _detailRepository.InsertAsync(entity);
                }
                var update_details = input.DetailList.Where(r => r.Id.HasValue);
                foreach (var item in update_details)
                {
                    var db_detail = await _detailRepository.GetAsync(item.Id.Value);

                    item.MapTo(db_detail);
                }
                var less_detailIds = details.Select(r => r.Id).Except(input.DetailList.Where(r => r.Id.HasValue).Select(r => r.Id.Value)).ToList();
                var less_details   = details.Where(r => less_detailIds.Contains(r.Id));
                foreach (var item in less_details)
                {
                    await _detailRepository.DeleteAsync(item);
                }

                var fileList = new List <AbpFileListInput>();
                if (input.FileList != null)
                {
                    foreach (var item in input.FileList)
                    {
                        fileList.Add(new AbpFileListInput()
                        {
                            Id = item.Id, Sort = item.Sort
                        });
                    }
                }
                await _abpFileRelationAppService.UpdateAsync(new CreateFileRelationsInput()
                {
                    BusinessId   = input.Id.ToString(),
                    BusinessType = (int)AbpFileBusinessType.差旅费报销,
                    Files        = fileList
                });

                var groupId = Guid.NewGuid();
                input.FACData.GroupId = groupId;
                if (input.IsUpdateForChange)
                {
                    var flowModel = _workFlowCacheManager.GetWorkFlowModelFromCache(input.FlowId);
                    if (flowModel == null)
                    {
                        throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "流程不存在");
                    }
                    var files = _abpFileRelationAppService.GetList(new GetAbpFilesInput()
                    {
                        BusinessId = old_Model.Id.ToString(), BusinessType = (int)AbpFileBusinessType.差旅费报销
                    });
                    if (files.Count > 0)
                    {
                        old_Model.Files = files.Select(r => new AbpFileChangeDto {
                            Id = r.Id, FileName = r.FileName
                        }).ToList();
                    }

                    if (input.FileList.Count > 0)
                    {
                        new_Model.Files = input.FileList.Select(r => new AbpFileChangeDto {
                            FileName = r.FileName, Id = r.Id
                        }).ToList();
                    }

                    var logs = old_Model.GetColumnAllLogs(new_Model);
                    await _projectAuditManager.InsertAsync(logs, input.Id.ToString(), flowModel.TitleField.Table, groupId);
                }
            }
            else
            {
                throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "该数据不存在。");
            }
        }
示例#2
0
        public async Task <InitWorkFlowOutput> Create(CreateCWGLTravelReimbursementInput input)
        {
            var service      = AbpBootstrapper.Create <Abp.Modules.AbpModule>().IocManager.IocContainer.Resolve <IWorkFlowOrganizationUnitsAppService>();
            var userOrgModel = await service.GetUserPostInfo(new NullableIdDto <long>() { Id = AbpSession.UserId.Value, }, new NullableIdDto <long>() { Id = null });

            var newmodel = new CWGLTravelReimbursement()
            {
                Id            = Guid.NewGuid(),
                UserId        = AbpSession.UserId.Value,
                OrgId         = userOrgModel.OrgId,
                Money         = input.Money,
                Note          = input.Note,
                Nummber       = input.Nummber,
                BorrowMoneyId = input.BorrowMoneyId,
                WorkoutId     = input.WorkoutId,
            };

            newmodel.Status = 0;
            var totalFee = 0m;

            foreach (var item in input.DetailList)
            {
                var entity = item.MapTo <CWGLTravelReimbursementDetail>();
                entity.TravelReimbursementId = newmodel.Id;
                totalFee = totalFee + entity.Fare ?? 0 + entity.Accommodation ?? 0 + entity.Other ?? 0;
                await _detailRepository.InsertAsync(entity);
            }
            if (input.BorrowMoneyId.HasValue)
            {
                var entityBorro = await _cWGLBorrowMonetrepository.GetAsync(input.BorrowMoneyId.Value);

                if (entityBorro.Money == totalFee)
                {
                    newmodel.ResultType = (int)RefundResultType.无退无报;
                }
                else if (entityBorro.Money > totalFee)
                {
                    newmodel.ResultType = (int)RefundResultType.财务应收款;
                }
                else
                {
                    newmodel.ResultType = (int)RefundResultType.财务应付款;
                }
                newmodel.Money = Math.Abs(entityBorro.Money - totalFee);
            }
            else
            {
                newmodel.Money      = totalFee;
                newmodel.ResultType = (int)RefundResultType.财务应付款;
            }

            await _repository.InsertAsync(newmodel);

            if (input.FileList != null)
            {
                var fileList = new List <AbpFileListInput>();
                foreach (var item in input.FileList)
                {
                    fileList.Add(new AbpFileListInput()
                    {
                        Id = item.Id, Sort = item.Sort
                    });
                }
                await _abpFileRelationAppService.CreateAsync(new CreateFileRelationsInput()
                {
                    BusinessId   = newmodel.Id.ToString(),
                    BusinessType = (int)AbpFileBusinessType.差旅费报销,
                    Files        = fileList
                });
            }
            return(new InitWorkFlowOutput()
            {
                InStanceId = newmodel.Id.ToString()
            });
        }