public ConsignToAcctLogInfo CreateConsignToAccountLog(ConsignToAcctLogInfo logInfo) { DataCommand command = DataCommandManager.GetDataCommand("CreateConsignToAccountLog"); command.SetParameterValue("@SysNo", logInfo.LogSysNo); command.SetParameterValue("@ProductSysNo", logInfo.ProductSysNo); command.SetParameterValue("@VendorSysNo", logInfo.VendorSysNo); command.SetParameterValue("@StockSysNo", logInfo.StockSysNo); command.SetParameterValue("@Quantity", logInfo.ProductQuantity); command.SetParameterValue("@CreateCost", logInfo.CreateCost); command.SetParameterValue("@SettleCost", logInfo.SettleCost); command.SetParameterValue("@ConsignToAccType", (int)logInfo.ConsignToAccType); command.SetParameterValue("@Note", logInfo.Note); object getCode = ""; EnumCodeMapper.TryGetCode(logInfo.ConsignToAccStatus, out getCode); if (null != getCode) { command.SetParameterValue("@Status", getCode.ToString()); } command.SetParameterValue("@SettleType", logInfo.SettleType.ToString()); command.SetParameterValue("@SettlePercentage", logInfo.SettlePercentage); command.SetParameterValue("@SalePrice", logInfo.SalePrice); command.SetParameterValue("@Point", logInfo.Point); command.SetParameterValue("@OrderSysNo", logInfo.OrderSysNo); command.SetParameterValue("@CompanyCode", logInfo.CompanyCode); logInfo.LogSysNo = System.Convert.ToInt32(command.ExecuteScalar()); return(logInfo); }
/// <summary> /// 创建代销转财务记录(Inventory) /// </summary> /// <param name="logInfo"></param> /// <returns></returns> public static ConsignToAcctLogInfo CreatePOConsignToAccLogForInventory(ConsignToAcctLogInfo logInfo) { var command = DataCommandManager.GetDataCommand("CreatePOConsignToAccLogForInventory"); command.SetParameterValue("@ProductSysNo", logInfo.ProductSysNo); command.SetParameterValue("@StockSysNo", logInfo.StockSysNo); command.SetParameterValue("@Quantity", logInfo.ProductQuantity); command.SetParameterValue("@CreateTime", logInfo.OutStockTime); command.SetParameterValue("@CreateCost", logInfo.CreateCost); command.SetParameterValue("@CompanyCode", logInfo.CompanyCode); command.SetParameterValue("@StoreCompanyCode", logInfo.StoreCompanyCode); command.SetParameterValue("@OrderSysNo", logInfo.OrderSysNo); command.SetParameterValue("@VendorSysNoOut", logInfo.VendorSysNo.HasValue ? logInfo.VendorSysNo : 0); command.SetParameterValue("@IsConsign", logInfo.IsConsign.HasValue ? logInfo.IsConsign : 1); logInfo.LogSysNo = System.Convert.ToInt32(command.ExecuteScalar()); return(logInfo); }
/// <summary> /// 损益单出库 (确认成功): /// </summary> /// <param name="adjustRequestSysNo">原始损益单编号</param> /// <param name="productSysNo">损益商品编号</param> /// <param name="realAdjustQty">该商品的实际损益数量</param> /// <returns></returns> public static AdjustRequestInfo AdjustOutStock(int adjustRequestSysNo, int?productSysNo, int?realAdjustQty, int sellerSysNo) { var adjustRequestInfo = GetAdjustRequestInfoBySysNo(adjustRequestSysNo); #region Check操作 : if (null == adjustRequestInfo || adjustRequestInfo.SysNo <= 0) { throw new BusinessException(string.Format("找不到编号为{0}的损益单据信息!", adjustRequestSysNo)); } if (productSysNo.HasValue && realAdjustQty.HasValue) { var productItemInfo = adjustRequestInfo.AdjustItemInfoList.FirstOrDefault(x => x.ProductSysNo == productSysNo); if (productItemInfo == null) { throw new BusinessException(string.Format("编号为{0}的商品不存在于该损益单中!损益单编号 :{1}", productSysNo, adjustRequestSysNo)); } if (realAdjustQty >= 0) { if (realAdjustQty > productItemInfo.AdjustQuantity) { throw new BusinessException(string.Format("编号为{0}的商品实际损益的数量大于预损益的数量!损益单编号 :{1}", productSysNo, adjustRequestSysNo)); } } else { if (realAdjustQty < productItemInfo.AdjustQuantity) { throw new BusinessException(string.Format("编号为{0}的商品实际损益的数量大于预损益的数量!损益单编号 :{1}", productSysNo, adjustRequestSysNo)); } } } var stockInfo = StockService.LoadStock(adjustRequestInfo.Stock.SysNo); if (null == stockInfo) { throw new BusinessException("损益单据关联的仓库编号无效!"); } if (stockInfo.MerchantSysNo != sellerSysNo) { throw new BusinessException("此商家无权操作此单据!"); } //增加损益单状态Check (已申报状态): if (adjustRequestInfo.RequestStatus != AdjustRequestStatus.Reported) { throw new BusinessException(string.Format("损益单编号 :{1},当前单据的状态不是'已申报'状态,不能进行损益单确认操作", productSysNo, adjustRequestSysNo)); } #endregion bool isConsign = false; adjustRequestInfo.OutStockDate = DateTime.Now; adjustRequestInfo.RequestStatus = Enums.AdjustRequestStatus.OutStock; isConsign = (adjustRequestInfo.ConsignFlag == RequestConsignFlag.Consign || adjustRequestInfo.ConsignFlag == RequestConsignFlag.GatherPay); var inventoryAdjustContract = new InventoryAdjustContractInfo { SourceBizFunctionName = InventoryAdjustSourceBizFunction.Inventory_AdjustRequest, SourceActionName = InventoryAdjustSourceAction.OutStock, ReferenceSysNo = adjustRequestInfo.SysNo.ToString(), AdjustItemList = new List <InventoryAdjustItemInfo>() }; using (TransactionScope scope = new TransactionScope()) { if (adjustRequestInfo.AdjustItemInfoList != null && adjustRequestInfo.AdjustItemInfoList.Count > 0) { adjustRequestInfo.AdjustItemInfoList.ForEach(adjustItem => { //if (adjustItem.AdjustProduct.ProductPriceInfo == null) //{ // BizExceptionHelper.Throw("Common_CannotFindPriceInformation"); // throw new BusinessException("损益数量只能为非0的整数!"); //} if (adjustItem.AdjustQuantity == 0) { throw new BusinessException("损益数量只能为非0的整数!"); } var cost = InventoryDA.GetItemCost(adjustItem.ProductSysNo.Value); inventoryAdjustContract.AdjustItemList.Add(new InventoryAdjustItemInfo { AdjustQuantity = adjustItem.AdjustQuantity.Value, ProductSysNo = adjustItem.ProductSysNo.Value, StockSysNo = (int)adjustRequestInfo.Stock.SysNo, AdjustUnitCost = cost, }); //update flash item unit cost if (adjustItem.AdjustCost != cost) { adjustItem.AdjustCost = cost; InventoryDA.UpdateAdjustItemCost(adjustItem); } }); } InventoryDA.UpdateAdjustRequestStatus(adjustRequestInfo); if (inventoryAdjustContract.AdjustItemList.Count > 0) { //string adjustResult = ObjectFactory<InventoryAdjustContractProcessor>.Instance.ProcessAdjustContract(inventoryAdjustContract); //if (!string.IsNullOrEmpty(adjustResult)) //{ // throw new BizException("库存调整失败: " + adjustResult); //} #region 调整库存: foreach (InventoryAdjustItemInfo adjustItem in inventoryAdjustContract.AdjustItemList) { ProductQueryInfo productInfo = ProductService.GetProductBySysNo(adjustItem.ProductSysNo); if (productInfo == null || productInfo.SysNo <= 0) { throw new BusinessException(string.Format("欲调库存的商品不存在,商品编号:{0}", adjustItem.ProductSysNo)); } InventoryDA.InitProductInventoryInfo(adjustItem.ProductSysNo, adjustItem.StockSysNo); var inventoryType = InventoryDA.GetProductInventroyType(adjustItem.ProductSysNo); ECommerce.Entity.Inventory.ProductInventoryInfo stockInventoryCurrentInfo = InventoryDA.GetProductInventoryInfoByStock(adjustItem.ProductSysNo, adjustItem.StockSysNo); ECommerce.Entity.Inventory.ProductInventoryInfo totalInventoryCurrentInfo = InventoryDA.GetProductTotalInventoryInfo(adjustItem.ProductSysNo); ECommerce.Entity.Inventory.ProductInventoryInfo stockInventoryAdjustInfo = new Entity.Inventory.ProductInventoryInfo() { ProductSysNo = adjustItem.ProductSysNo, StockSysNo = adjustItem.StockSysNo }; ECommerce.Entity.Inventory.ProductInventoryInfo totalInventoryAdjustInfo = new ECommerce.Entity.Inventory.ProductInventoryInfo() { ProductSysNo = adjustItem.ProductSysNo }; if (adjustItem.AdjustQuantity < 0) { //损单出库 if (adjustRequestInfo.ConsignFlag == RequestConsignFlag.Consign || adjustRequestInfo.ConsignFlag == RequestConsignFlag.GatherPay) { //代销商品, 恢复可用库存, 减少已分配库存/代销库存 stockInventoryAdjustInfo.AvailableQty = -adjustItem.AdjustQuantity; totalInventoryAdjustInfo.AvailableQty = -adjustItem.AdjustQuantity; if (adjustItem.AdjustQuantity < 0) { //AllocatedQty(-,->0),小于0则自动调为0。 if (stockInventoryCurrentInfo.AllocatedQty + adjustItem.AdjustQuantity < 0) { stockInventoryAdjustInfo.AllocatedQty = -stockInventoryCurrentInfo.AllocatedQty; } else { stockInventoryAdjustInfo.AllocatedQty = adjustItem.AdjustQuantity; } if (totalInventoryCurrentInfo.AllocatedQty + adjustItem.AdjustQuantity < 0) { totalInventoryAdjustInfo.AllocatedQty = -totalInventoryCurrentInfo.AllocatedQty; } else { totalInventoryAdjustInfo.AllocatedQty = adjustItem.AdjustQuantity; } } else { stockInventoryAdjustInfo.AllocatedQty = adjustItem.AdjustQuantity; totalInventoryAdjustInfo.AllocatedQty = adjustItem.AdjustQuantity; } stockInventoryAdjustInfo.ConsignQty = adjustItem.AdjustQuantity; totalInventoryAdjustInfo.ConsignQty = adjustItem.AdjustQuantity; } else { //非代销商品, 减少财务库存/已分配库存 stockInventoryAdjustInfo.AccountQty = adjustItem.AdjustQuantity; totalInventoryAdjustInfo.AccountQty = adjustItem.AdjustQuantity; if (adjustItem.AdjustQuantity < 0) { //AllocatedQty(-,->0),小于0则自动调为0。 if (stockInventoryCurrentInfo.AllocatedQty + adjustItem.AdjustQuantity < 0) { stockInventoryAdjustInfo.AllocatedQty = -stockInventoryCurrentInfo.AllocatedQty; } else { stockInventoryAdjustInfo.AllocatedQty = adjustItem.AdjustQuantity; } if (totalInventoryCurrentInfo.AllocatedQty + adjustItem.AdjustQuantity < 0) { totalInventoryAdjustInfo.AllocatedQty = -totalInventoryCurrentInfo.AllocatedQty; } else { totalInventoryAdjustInfo.AllocatedQty = adjustItem.AdjustQuantity; } } else { stockInventoryAdjustInfo.AllocatedQty = adjustItem.AdjustQuantity; totalInventoryAdjustInfo.AllocatedQty = adjustItem.AdjustQuantity; } } } else { //溢单出库 if (adjustRequestInfo.ConsignFlag == RequestConsignFlag.Consign || adjustRequestInfo.ConsignFlag == RequestConsignFlag.GatherPay) { //代销商品, 增加代销库存 (损/溢单都增加代销库存?) stockInventoryAdjustInfo.ConsignQty = adjustItem.AdjustQuantity; totalInventoryAdjustInfo.ConsignQty = adjustItem.AdjustQuantity; } else { //非代销商品, 增加财务库存/可用库存 stockInventoryAdjustInfo.AccountQty = adjustItem.AdjustQuantity; totalInventoryAdjustInfo.AccountQty = adjustItem.AdjustQuantity; stockInventoryAdjustInfo.AvailableQty = adjustItem.AdjustQuantity; totalInventoryAdjustInfo.AvailableQty = adjustItem.AdjustQuantity; } } //预检调整后的商品库存是否合法 Entity.Inventory.ProductInventoryInfo stockInventoryAdjustAfterAdjust = InventoryService.PreCalculateInventoryAfterAdjust(stockInventoryCurrentInfo, stockInventoryAdjustInfo); Entity.Inventory.ProductInventoryInfo totalInventoryAdjustAfterAdjust = InventoryService.PreCalculateInventoryAfterAdjust(totalInventoryCurrentInfo, totalInventoryAdjustInfo); bool isNeedCompareAvailableQtyAndAccountQty = true; InventoryService.PreCheckGeneralRules(stockInventoryAdjustAfterAdjust, ref isNeedCompareAvailableQtyAndAccountQty); InventoryService.PreCheckGeneralRules(totalInventoryAdjustAfterAdjust, ref isNeedCompareAvailableQtyAndAccountQty); //调整商品库存: InventoryDA.AdjustProductStockInventoryInfo(stockInventoryAdjustInfo); InventoryDA.AdjustProductTotalInventoryInfo(totalInventoryAdjustInfo); } #endregion #region 损益单为代销类型,出库时需要写入代销转财务日志 if (isConsign) { List <ConsignToAcctLogInfo> acctLogInfoList = new List <ConsignToAcctLogInfo>(); adjustRequestInfo.AdjustItemInfoList.ForEach(x => { ConsignToAcctLogInfo acctLog = new ConsignToAcctLogInfo(); acctLog.ProductSysNo = x.ProductSysNo; acctLog.StockSysNo = adjustRequestInfo.Stock.SysNo; acctLog.VendorSysNo = InventoryDA.GetProductBelongVendorSysNo(x.ProductSysNo.Value); acctLog.ProductQuantity = -x.AdjustQuantity; acctLog.OutStockTime = adjustRequestInfo.OutStockDate; acctLog.CreateCost = x.AdjustCost; acctLog.OrderSysNo = adjustRequestInfo.SysNo; acctLog.CompanyCode = adjustRequestInfo.CompanyCode; acctLog.StoreCompanyCode = adjustRequestInfo.CompanyCode; acctLog.IsConsign = (int)adjustRequestInfo.ConsignFlag; acctLogInfoList.Add(acctLog); }); if (acctLogInfoList.Count > 0) { foreach (var item in acctLogInfoList) { InventoryDA.CreatePOConsignToAccLogForInventory(item); } } } #endregion #region string InUser = "******"; List <InventoryBatchDetailsInfo> batchDetailsInfoEntitylist = InventoryDA.GetBatchDetailsInfoEntityListByNumber(adjustRequestInfo.SysNo.Value); if (batchDetailsInfoEntitylist != null && batchDetailsInfoEntitylist.Count > 0) { #region 构建损益单 出库调整批次库存表的SSB消息 调整库存 List <ItemBatchInfo> itemBatchInfoList = new List <ItemBatchInfo>(); foreach (var item in batchDetailsInfoEntitylist) { ItemBatchInfo itemBatchInfo = new ItemBatchInfo(); itemBatchInfo.BatchNumber = item.BatchNumber; itemBatchInfo.ProductNumber = item.ProductSysNo.ToString(); Stock stock = new Stock(); AdjustRequestItemInfo aEntity = new AdjustRequestItemInfo(); aEntity = adjustRequestInfo.AdjustItemInfoList.Find(x => { return(x.ProductSysNo == item.ProductSysNo); }); if (aEntity != null && aEntity.AdjustQuantity > 0) { stock.Quantity = item.Quantity.ToString(); //单据出库两个数量都要调整 stock.AllocatedQty = string.Empty; //益单不调 占用库存 作废 取消作废 单据 只调整 占用库存 } else { stock.Quantity = item.Quantity.ToString(); //单据出库两个数量都要调整 stock.AllocatedQty = item.Quantity.ToString(); //损单 需要调整 占用库存 作废 取消作废 单据 只调整 占用库存 } stock.WarehouseNumber = item.StockSysNo.ToString(); List <Stock> StockList = new List <Stock>(); StockList.Add(stock); Stocks stocks = new Stocks(); stocks.Stock = StockList; itemBatchInfo.Stocks = stocks; itemBatchInfoList.Add(itemBatchInfo); } BatchXMLMessage batchXMLMessage = new BatchXMLMessage() { Header = new InventoryHeader { NameSpace = "http://soa.ECommerce.com/InventoryProfile", Action = "OutStock", Version = "V10", Type = "Adjust", CompanyCode = "8601", Tag = "AdjustOutStock", Language = "zh-CN", From = "IPP", GlobalBusinessType = "Listing", StoreCompanyCode = "8601", TransactionCode = adjustRequestInfo.SysNo.ToString() }, Body = new InventoryBody { InUser = InUser, Number = adjustRequestInfo.SysNo.ToString(), ItemBatchInfo = itemBatchInfoList } }; string paramXml = SerializationUtility.XmlSerialize(batchXMLMessage); XmlDocument xmlD = new XmlDocument(); xmlD.LoadXml(paramXml); paramXml = "<" + xmlD.DocumentElement.Name + ">" + xmlD.DocumentElement.InnerXml + "</" + xmlD.DocumentElement.Name + ">"; InventoryDA.AdjustBatchNumberInventory(paramXml);//调整批次库存表 占用数量 #endregion } List <InventoryAdjustItemInfo> adjustCaseEntityList = new List <InventoryAdjustItemInfo>(); foreach (var item in inventoryAdjustContract.AdjustItemList) { if (!InventoryDA.CheckISBatchNumberProduct(item.ProductSysNo)) { item.AdjustQuantity = item.AdjustQuantity; adjustCaseEntityList.Add(item); } } AdjustSendSSBToWMS(adjustRequestInfo.SysNo.Value, adjustRequestInfo.Stock.SysNo.ToString(), batchDetailsInfoEntitylist, adjustCaseEntityList);//损益单出库向仓库发送SSB消息 #endregion } scope.Complete(); } return(adjustRequestInfo); }
/// <summary> /// 新建/更新结算单时对结算商品的Check逻辑 /// </summary> /// <param name="info"></param> /// <param name="verifyType"></param> public virtual void VerifySettleItems(CollectionPaymentInfo info, SettlementVerifyType verifyType) { decimal totalCount = 0; foreach (CollectionPaymentItem item in info.SettleItems) { //检查当前item是否是要删除的项目 if (item.SettleSysNo.HasValue && item.SettleSysNo.Value == -1) { continue; } ConsignToAcctLogInfo getConsignToAccLog = ConsignSettlementDA.LoadConsignToAccountLogInfo(item.ConsignToAccLogInfo.LogSysNo); //1 检查当前item是否有对应的account记录 if (getConsignToAccLog == null) { //未找到当前商品(商品系统编号:{0})对应的代销转财务记录! throw new BizException(string.Format(GetMessageString("Consign_ProductsAccLog_NotFound"), item.ConsignToAccLogInfo.ProductSysNo)); } switch (verifyType) { case SettlementVerifyType.CREATE: //1 检查当前财务记录的状态 if (getConsignToAccLog.ConsignToAccStatus != ConsignToAccountLogStatus.Origin) { //当前商品(商品系统编号:{0})对应的到财务记录不为待结算状态! throw new BizException(string.Format(GetMessageString("Consign_ProductsAccLog_WaitingSettle"), item.ConsignToAccLogInfo.ProductSysNo)); } break; case SettlementVerifyType.SETTLE: //2 检查当前财务记录的状态 if (getConsignToAccLog.ConsignToAccStatus != ConsignToAccountLogStatus.SystemCreated && getConsignToAccLog.ConsignToAccStatus != ConsignToAccountLogStatus.ManualCreated) { //当前商品(商品系统编号:{0})对应的到财务记录不为待结算状态! throw new BizException(string.Format(GetMessageString("Consign_ProductsAccLog_WaitingSettle"), item.ConsignToAccLogInfo.ProductSysNo)); } break; case SettlementVerifyType.UPDATE: //3 检查当前财务记录的状态 if (getConsignToAccLog.ConsignToAccStatus == ConsignToAccountLogStatus.Finance || getConsignToAccLog.ConsignToAccStatus == ConsignToAccountLogStatus.Settled) { //当前商品(商品系统编号:{0})对应的到财务记录不为待结算状态! throw new BizException(string.Format(GetMessageString("Consign_ProductsAccLog_WaitingSettle"), item.ConsignToAccLogInfo.ProductSysNo)); } break; default: //verifyType没有传入有效的值 throw new BizException(GetMessageString("Consign_VerifytType_Invalid")); } //3 检查当前记录的结算价格 if (item.Cost < 0) { //当前商品(商品系统编号:{0})的结算价格不能小于零! throw new BizException(string.Format(GetMessageString("Consign_Products_SettleAmt_Check2"), item.ConsignToAccLogInfo.ProductSysNo)); } //4 检查当前记录是否是同一个vendor if (getConsignToAccLog.VendorSysNo.Value != info.VendorInfo.SysNo) { //当前商品(商品系统编号:{0})的供应商与结算单的供应商不一致! throw new BizException(string.Format(GetMessageString("Consign_VendorNotTheSame"), item.ConsignToAccLogInfo.ProductSysNo)); } //5 检查当前记录是否是同一个stock if (getConsignToAccLog.StockSysNo != info.SourceStockInfo.SysNo) { //因为存在按仓库拆分逻辑,创建时不判断仓库 if (verifyType != SettlementVerifyType.CREATE) { //当前商品(商品系统编号:{0})的仓库与结算单的仓库不一致! throw new BizException(string.Format(GetMessageString("Consign_StockNotTheSame"), item.ConsignToAccLogInfo.ProductSysNo)); } } //6 计算总价 totalCount += item.Cost * getConsignToAccLog.ProductQuantity.Value; } //7 检查计算的总价 if (info.TotalAmt != totalCount) { //结算单的总金额与当前实际结算金额不一致 throw new BizException(GetMessageString("Consign_SettleAmtTheSame")); } }