/// <summary> /// 收货取消 /// </summary> /// <param name="warehouseId"></param> /// <param name="productId"></param> /// <param name="merchantId"></param> /// <param name="qtyReceipt"></param> /// <param name="isOpenTrans"></param> /// <returns></returns> public bool UpdateInventoryByUnReceive(string sourceNo, InventoryTransactionType type, string warehouseId, string productId, string merchantId, int qtyReceipt, DbTransaction isOpenTrans) { StringBuilder strSql = new StringBuilder(); strSql.Append( @"UPDATE [Inventory] SET QtyOnHand = QtyOnHand - @QtyReceipt, QtyAllocated = QtyAllocated - @QtyReceipt"); strSql.Append(" WHERE ProductId = @ProductId"); strSql.Append(" AND WarehouseId = @WarehouseId"); strSql.Append(" AND MerchantId = @MerchantId "); strSql.Append(" AND QtyOnHand - @QtyReceipt >= 0"); var updateParameters = new List <DbParameter> { DbFactory.CreateDbParameter("@WarehouseId", warehouseId), DbFactory.CreateDbParameter("@ProductId", productId), DbFactory.CreateDbParameter("@MerchantId", merchantId), DbFactory.CreateDbParameter("@QtyReceipt", qtyReceipt) }; InventoryTransactionEntity transaction = new InventoryTransactionEntity(); transaction.Create(); transaction.Type = (int)type; transaction.WarehouseId = warehouseId; transaction.ProductId = productId; transaction.MerchantFrom = merchantId; transaction.MerchantTo = merchantId; transaction.Qty = -1 * qtyReceipt; transaction.SourceNo = sourceNo; var isOK = new InventoryTransactionBLL().InsertTransaction(transaction, isOpenTrans); if (isOK) { return(Repository().ExecuteBySql(strSql, updateParameters.ToArray(), isOpenTrans) > 0); } else { return(false); } }
/// <summary> /// 更新商户在库库存(收货、拣货移入) /// </summary> /// <param name="sourceNo"></param> /// <param name="warehouseId"></param> /// <param name="productId"></param> /// <param name="merchantId"></param> /// <param name="moveInQty"></param> /// <param name="isOpenTrans"></param> public bool UpdateInventoryByReceive(string sourceNo, InventoryTransactionType type, string warehouseId, string productId, string merchantId, int moveInQty, DbTransaction isOpenTrans) { StringBuilder strSql = new StringBuilder(); strSql.Append(@"SELECT * FROM dbo.Inventory WHERE WarehouseId = @WarehouseId"); strSql.Append(" AND ProductId = @ProductId"); strSql.Append(" AND MerchantId = @MerchantId"); var parameter = new List <DbParameter> { DbFactory.CreateDbParameter("@WarehouseId", warehouseId), DbFactory.CreateDbParameter("@ProductId", productId), DbFactory.CreateDbParameter("@MerchantId", merchantId) }; InventoryTransactionEntity transaction = new InventoryTransactionEntity(); transaction.Create(); transaction.Type = (int)type; transaction.WarehouseId = warehouseId; transaction.ProductId = productId; transaction.MerchantFrom = merchantId; transaction.MerchantTo = merchantId; transaction.Qty = moveInQty; transaction.SourceNo = sourceNo; var isOK = new InventoryTransactionBLL().InsertTransaction(transaction, isOpenTrans); if (isOK) { var inventory = Repository().FindEntityBySql(strSql.ToString(), parameter.ToArray()); if (string.IsNullOrEmpty(inventory?.InventoryId)) { inventory = new InventoryEntity(); inventory.Create(); inventory.WarehouseId = warehouseId; inventory.ProductId = productId; inventory.QtyOnHand = moveInQty; inventory.MerchantId = merchantId; return(Repository().Insert(inventory, isOpenTrans) > 0); } else { StringBuilder strUpdateSql = new StringBuilder(); strUpdateSql.Append( @"UPDATE [Inventory] SET QtyOnHand = QtyOnHand + @QtyOnHand WHERE InventoryId = @InventoryId "); List <DbParameter> updateParameters = new List <DbParameter> { DbFactory.CreateDbParameter("@QtyOnHand", moveInQty), DbFactory.CreateDbParameter("@InventoryId", inventory.InventoryId) }; return(Repository().ExecuteBySql(strUpdateSql, updateParameters.ToArray(), isOpenTrans) > 0); } } else { return(false); } }