/// <summary> /// 验证导入的采购篮数据是否合法并创建采购篮 /// </summary> /// <param name="itemList"></param> /// <returns></returns> public virtual List <BasketItemsInfo> BatchImportAndCreateBasketItem(List <BasketItemsInfo> itemList, bool isThrowException) { if (null == itemList || 0 == itemList.Count) { //没有需要导入的数据 throw new BizException(GetMessageString("Basket_NoDataImport")); } foreach (var entity in itemList) { #region [Check实体逻辑] if (!entity.LastVendorSysNo.HasValue) { //供应商编号无效 entity.ErrorMessage += GetMessageString("Basket_VendorSysNoInvalid"); if (isThrowException) { throw new BizException(GetMessageString("Basket_VendorSysNoInvalid")); } } var vendor = VendorDA.LoadVendorInfo(entity.LastVendorSysNo.Value); if (vendor == null) { //供应商无效 entity.ErrorMessage += GetMessageString("Basket_VendorInvalid"); if (isThrowException) { throw new BizException(GetMessageString("Basket_VendorInvalid")); } } else { entity.CompanyCode = vendor.CompanyCode; entity.VendorSysNo = vendor.SysNo.Value; } if (!entity.Quantity.HasValue || entity.Quantity == 0) { //{0}:该商品数量不能为空! entity.ErrorMessage += string.Format(GetMessageString("Basket_ProductQtyEmpty"), entity.ProductID); if (isThrowException) { throw new BizException(string.Format(GetMessageString("Basket_ProductQtyEmpty"), entity.ProductID)); } } if (!entity.OrderPrice.HasValue) { //采购价格为空 entity.ErrorMessage += GetMessageString("Basket_PurchasePriceEmpty"); if (isThrowException) { throw new BizException(GetMessageString("Basket_PurchasePriceEmpty")); } } entity.ProductSysNo = BasketDA.GetItemSysNoByItemID(entity.ProductID, entity.CompanyCode); if (!entity.ProductSysNo.HasValue || entity.ProductSysNo == 0) { entity.ErrorMessage += GetMessageString("Basket_ProductSysNoInvalid"); if (isThrowException) { throw new BizException(GetMessageString("Basket_ProductSysNoInvalid")); } } entity.StockSysNo = BasketDA.GetStockSysNoByName(entity.StockName, entity.CompanyCode); if (!entity.StockSysNo.HasValue || entity.StockSysNo == 0) { entity.ErrorMessage += GetMessageString("Basket_StocknameInvalid"); if (isThrowException) { throw new BizException(GetMessageString("Basket_StocknameInvalid")); } } if (BasketDA.CheckProductHasExistInBasket(entity) && !entity.ItemSysNo.HasValue) { //添加采购篮中item记录是否重复判断条件:采购员,供应商,item,目标仓库 //{0}:该商品已存在于采购篮中! entity.ErrorMessage += string.Format(GetMessageString("Basket_ItemExists"), entity.ProductID); if (isThrowException) { throw new BizException(string.Format(GetMessageString("Basket_ItemExists"), entity.ProductID)); } } #endregion if (string.IsNullOrEmpty(entity.ErrorMessage)) { entity.ReadyQuantity = 0; var resultEntity = BasketDA.CreateBasketItemForPrepare(entity); //写LOG: //CommonService.WriteLog<BasketItemEntity>(entity, " Batch Created BaksetItem ", entity.SysNo.Value.ToString(), (int)LogType.PO_Basket_Insert); ExternalDomainBroker.CreateLog(" Batch Created BaksetItem " , BizEntity.Common.BizLogType.Purchase_Basket_Insert , entity.ItemSysNo.Value , entity.CompanyCode); } } return(itemList); }
/// <summary> /// 加载代销结算单详细 /// </summary> /// <param name="settlementSysNo"></param> /// <returns></returns> public virtual CollectionPaymentInfo Create(CollectionPaymentInfo entity) { //去除已经删除的Item(SysNo=-1) 次方法已经在Portal加过了,此处只为以防万一了 entity.SettleItems = (from tItem in entity.SettleItems where tItem.SettleSysNo != -1 select tItem).ToList(); string OperationIP = string.Empty; string OperationUserUniqueName = string.Empty; VerifyCreate(entity); VerifySettleItems(entity, SettlementVerifyType.CREATE); VerifyProductPMSysNo(entity); //VerityOverConsignRuleQuantity(entity); //entity.CreateUserSysNo = SystemUserHelper.GetUserSystemNumber(BusinessContext.Current.OperationUserFullName, // BusinessContext.Current.OperationUserSourceDirectoryKey, BusinessContext.Current.OperationUserLoginName, // BusinessContext.Current.CompanyCode); entity.CreateUserSysNo = entity.CurrentUserSysNo;; entity.CreateTime = DateTime.Now; entity.Status = POCollectionPaymentSettleStatus.Origin; //修改代销转财务记录的状态 foreach (var item in entity.SettleItems) { item.ConsignToAccLogInfo.ConsignToAccStatus = ConsignToAccountLogStatus.ManualCreated; //item. } //用于收集操作过的结算单 List <CollectionPaymentInfo> settleEntityList = new List <CollectionPaymentInfo>(); //计算返点,返点总额将会平均分配到以下结算单,当返点总额大于单个结算单的返点额,那单个结算单返点将和计算单总额相等 //剩余返点额将在下个结算单中使用 decimal totalUsingReturnPoint = entity.UsingReturnPoint ?? 0; using (TransactionScope scope = new TransactionScope()) { //按照仓库的不同自动分结算单 var stockSysNoList = entity.SettleItems.Select(p => p.ConsignToAccLogInfo.StockSysNo).Distinct(); foreach (int?stockSysNo in stockSysNoList) { //需要深度赋值新的类 var newEntity = SerializationUtility.DeepClone <CollectionPaymentInfo>(entity); newEntity.SourceStockInfo.SysNo = stockSysNo; var tempSettleList = new List <CollectionPaymentItem>(); tempSettleList.AddRange(newEntity.SettleItems.Where(p => p.ConsignToAccLogInfo.StockSysNo == stockSysNo)); //计算总结算数 newEntity.TotalAmt = tempSettleList.Sum(p => p.Cost * p.ConsignToAccLogInfo.ProductQuantity.Value); newEntity.SettleItems = tempSettleList; //判断规则数量是否还有剩余 newEntity = CollectionPaymentDA.Create(newEntity); entity.SysNo = newEntity.SysNo; //将操作完成的收集在临时列表中 settleEntityList.Add(newEntity); } //更新代销转财务记录状态 settleEntityList.ForEach(x => { UpdateConsignToAccLogStatus(x); }); //发送ESB消息 EventPublisher.Publish <CollectionPaymentCreateMessage>(new CollectionPaymentCreateMessage() { CurrentUserSysNo = ServiceContext.Current.UserSysNo, SysNo = entity.SysNo.Value }); scope.Complete(); } foreach (var newEntity in settleEntityList) { //执行其它操作 newEntity.OperationIP = OperationIP; newEntity.OperationUserSysNumber = entity.CreateUserSysNo; newEntity.OperationUserUniqueName = OperationUserUniqueName; //CommonService.WriteLog<CollectionPaymentEntity>(newEntity, " Create VendorSettle ", newEntity.SysNo.Value.ToString(), (int)LogType.CollectionPayment_Create); VendorInfo vendor = VendorDA.LoadVendorInfo(newEntity.VendorInfo.SysNo.Value); if (vendor.VendorFinanceInfo.IsAutoAudit != null && vendor.VendorFinanceInfo.IsAutoAudit == true) { try { Audit(newEntity); } catch (Exception ex) { //MailService.SendMail(ConfigurationManager.AppSettings["VendorSettleFrom"], ConfigurationManager.AppSettings["VendorSettleTo"], "代销结算单自动审核", newEntity.SysNo.ToString() + ":" + ex.ErrorDescription); } //自动结算 entity = Settle(newEntity); } } return(entity); }