public static GetPayableItemResponse ToGetPayableItemResponse(PayableItem entity) { var response = new GetPayableItemResponse(); switch (entity.BillFromType.ToUpper()) { case EntityType.ACCOUNT_ENTITY: response.BillFromType = EntityType.ACCOUNT_ENTITY; response.BillFromId = entity.BillFromAccountEntityId; response.BillFromName = entity.BillFromAccountEntity?.Name; response.BillFromLabel = string.Concat(EntityType.ACCOUNT_ENTITY, "-", entity.BillFromAccountEntityId); break; case EntityType.VENDOR: response.BillFromType = EntityType.VENDOR; response.BillFromId = entity.BillFromVendorId; response.BillFromName = entity.BillFromVendor?.Name; response.BillFromLabel = string.Concat(EntityType.VENDOR, "-", entity.BillFromVendorId); break; case EntityType.TRANSFEREE: response.BillFromType = EntityType.TRANSFEREE; response.BillFromId = entity.BillFromTransfereeId; response.BillFromName = string.Concat(entity.BillFromTransferee?.FirstName, " ", entity.BillFromTransferee?.LastName); response.BillFromLabel = string.Concat(EntityType.TRANSFEREE, "-", entity.BillFromTransfereeId); break; } return(response); }
/* Spostare in una classe dedicata all'admin */ public bool AddOtherRequest(int person_id, double amount, string description, out string message) { // TODO verifica admin message = string.Empty; int base_length = 2; PayableItem model = new PayableItem() { Name = "Altro", Code = "OTHER_" + StringUtils.RandomString(base_length), Year = DateTime.Now.Year, RequestCost = amount, Description = description, IsPrintable = false, IsRequestable = false, IsUnique = true, IsOther = true, RequestPrintCost = 0 }; int count = 0; while (count <= 3) { if (db.Save(model)) { break; } else { model.Code = "OTHER_" + StringUtils.RandomString(base_length + count); count++; } } if (model.Id <= 0) // non è stato possibile salvare nel database { return(false); } ItemRequest request = new ItemRequest() { PersonId = person_id, Item = model, ItemId = model.Id, Note = description, IsPrint = false, IsRequest = true, PrintCopies = 0, RequestQuantity = 1, }; return(RequestModel(request, out message, true)); }
public async Task Handle(SettlementPriceMessageEvent @event) { if (@event == null) { throw new ArgumentNullException(nameof(SettlementPriceMessageEvent)); } //根据event内容分析出各种费项与计价单位 //获取计价单位 var priceUnit = GetPriceUnit(@event.Calculates.FirstOrDefault()); //分析各种费项结果,并生成各种费项类 var prices = AnalyzeFeesAndSetTransportFees(@event.Fees); //开始计算费用 var priceHandler = new PriceHandler(prices, priceUnit, @event.Goods); priceHandler.Handle(); if (priceHandler != null && priceHandler.PriceValue > 0) { //根据operationid取相关任务 var task = await _taskRepository.FindByOperationAsync(@event.OperationID); if (task == null) { throw new SettlementDomainException(@event.OperationID + "下的运输任务不存在"); } if (task.Payable == null) { throw new SettlementDomainException(@event.OperationID + "运输下的应付没有被初始化"); } task.Payable.ExChangeStatus(PayableStatusEnum.Todo); task.Payable.SetPrice(priceHandler.PriceValue); //应付子集 foreach (var item in prices) { PayableItem pi = new PayableItem { Amount = item.Value, CostCode = item.Code, CostName = item.Name, CostType = item.Id, PayableBasis = PayableBasisEnum.Contract }; task.Payable.AddItem(pi); } await _taskRepository.UpdateAsync(task); //这里可以继续发送FinishPriceEvent事件 } await _taskRepository.UnitOfWork.SaveChangesAsync(); }
public static PayableItem ToPayableItem(GetPayableItemResponse dto) { var response = new PayableItem(); switch (dto.BillFromType.ToUpper()) { case EntityType.ACCOUNT_ENTITY: response.BillFromType = EntityType.ACCOUNT_ENTITY; response.BillFromAccountEntityId = dto?.BillFromId; break; case EntityType.VENDOR: response.BillFromType = EntityType.VENDOR; response.BillFromVendorId = dto?.BillFromId; break; case EntityType.TRANSFEREE: response.BillFromType = EntityType.TRANSFEREE; response.BillFromTransfereeId = dto?.BillFromId; break; } return(response); }
/* Spostare in una classe dedicata all'admin */ public bool CreateModel(PayableItem model) { // TODO verifica amministratore return(db.Save(model)); }
public async Task CalculatePrice(SettlementPriceMessageEvent evt) { if (evt == null) { throw new ArgumentNullException(nameof(SettlementPriceMessageEvent)); } if (evt.Calculates.Count == 0) { throw new ArgumentException("指派操作为:" + evt.OperationID + "的报价不存在"); } if (evt.Fees.Count == 0) { throw new ArgumentException("指派操作为:" + evt.OperationID + "的费项不存在"); } //根据event内容分析出各种费项与计价单位 //获取计价单位 var priceUnit = GetPriceUnit(evt.Calculates.FirstOrDefault()); //分析各种费项结果,并生成各种费项类 var prices = AnalyzeFeesAndSetTransportFees(evt.Fees); //开始计算费用 var priceHandler = new PriceHandler(prices, priceUnit, evt.Goods); priceHandler.Handle(); if (priceHandler != null && priceHandler.PriceValue > 0) { //根据operationid取相关任务 var task = await _taskRepository.FindByOperationAsync(evt.OperationID); if (task == null) { throw new SettlementDomainException(evt.OperationID + "下的运输任务不存在"); } if (task.Payable == null) { throw new SettlementDomainException(evt.OperationID + "运输下的应付没有被初始化"); } task.Payable.ExChangeStatus(PayableStatusEnum.Todo); task.Payable.SetPrice(priceHandler.PriceValue); //取送货类 var sendPrice = prices.Where(p => p.GetType() == typeof(SendGoodsPrice)).Where(p => p.Value > 0).Cast <SendGoodsPrice>().FirstOrDefault(); if (sendPrice != null) { task.Payable.AddItem(new PayableItem { Amount = sendPrice.SumPrice, UnitPrice = sendPrice.Value, CostCode = sendPrice.Code, CostName = sendPrice.Name, CostType = sendPrice.Id, LowestPrice = sendPrice.LowestPrice, Unit = sendPrice.Unit, Number = sendPrice.Number, PayableBasis = PayableBasisEnum.Contract, Note = sendPrice.Remark }); } prices.Where(p => p.GetType() != typeof(LowestPrice)) .Where(p => p.GetType() != typeof(SendGoodsPrice)) .Where(p => p.GetType() != typeof(FreePickWeightOrVolumePrice)) .Where(p => p.GetType() != typeof(FreeSendWeightOrVolumePrice)) .Where(p => p.Value > 0) .ForEach(item => { PayableItem pi = new PayableItem { Amount = item.SumPrice, UnitPrice = item.Value, CostCode = item.Code, CostName = item.Name, CostType = item.Id, LowestPrice = item.LowestPrice, Unit = item.Unit, Number = item.Number, PayableBasis = PayableBasisEnum.Contract }; if (item.GetType() == typeof(PickGoodsPrice)) { pi.Note = (item as PickGoodsPrice).Remark; } task.Payable.AddItem(pi); }); await _taskRepository.UpdateAsync(task); //这里可以继续发送FinishPriceEvent领域事件 var finishSettlementEvent = new FinishSettlementEvent(); var settlementPayable = new SettlementPayable { Amount = task.Payable.Amount, OperationId = evt.OperationID, SettlementUnit = task.Payable.SettlementUnit, SettlementUnitCode = task.Payable.SettlementUnitCode, PayableItems = _mapper.Map <List <SettlementPayableItem> >(task.Payable.Details) }; finishSettlementEvent.SetPayable(settlementPayable); task.AddDomainEvent(finishSettlementEvent); await _taskRepository.UnitOfWork.SaveEntitiesAsync(); } }