
/*
	1. Create an order
	2. Pick some items from the order and update their MinOrderQty and MaxOrderQty in tbVendorEntityItem 
	3. Delete that order
	4. Recreate an order for that vendor and entity, now with min max values set
*/

DECLARE @EntityId bigint = 4232
DECLARE @VendorId bigint = 10	
DECLARE @VendorCode varchar(50) = '030348'
DECLARE @MinQuantity float = 7
DECLARE @MaxQuantity float = null


update tbVendorEntityItem set MinOrderQty = @MinQuantity, @MaxQuantity = @MaxQuantity 
where VendorCode like @VendorCode and entityid = @EntityId and vendorid = @VendorId

select VendorCode, VendorDescription, MinOrderQty, MaxOrderQty from tbVendorEntityItem 
where VendorId = @VendorId and EntityID = @EntityId 
and (minOrderQty is not null or MaxOrderQty is not null)

--------------------------------------------
DECLARE @SalesOrderId bigint = 3968925

select * from tbTransactionSalesOrderDetail D
inner join tbTransactionSalesOrderDetailItemQuantity q on D.TransactionSalesOrderDetailID = q.TransactionSalesOrderDetailID
where @EntityId = EntityID
and iTransaction_num = @SalesOrderId
and (MinOrderQty is not null or MaxOrderQty is not null)
