Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
control_sql_-_check_inventory_received_levels_on_pos [2019/01/27 11:28] 127.0.0.1 external edit |
control_sql_-_check_inventory_received_levels_on_pos [2022/07/07 11:20] (current) shendrix [SQL Query to Reduce Received without changing Billed Qty] |
||
---|---|---|---|
Line 28: | Line 28: | ||
**High**. Inventory data is modified in this query. Do not run this except under the direction of a Cyrious Technical Support staff member. Doing otherwise may result in lost or contaminated data. All data modifications done through direct SQL **are permanent and non-reversable**. | **High**. Inventory data is modified in this query. Do not run this except under the direction of a Cyrious Technical Support staff member. Doing otherwise may result in lost or contaminated data. All data modifications done through direct SQL **are permanent and non-reversable**. | ||
- | |||
====== SQL Queries ====== | ====== SQL Queries ====== | ||
+ | There are two SQL queries listed below, it is very important that you understand the difference between these two queries and only apply the one that fits the scenario that you are encountering. | ||
- | |||
- | There are two SQL queries listed below, it is very important that you understand the difference between these two queries and only apply the one that fits the scenario that you are encountering. | ||
- The first query will post any adjustment necessary to Received while also posting an opposite adjustment to the Billed Qty on the part. | - The first query will post any adjustment necessary to Received while also posting an opposite adjustment to the Billed Qty on the part. | ||
- The second query will post any adjustment necessary to Received while not posting any adjustment to the Billed Qty on the part. | - The second query will post any adjustment necessary to Received while not posting any adjustment to the Billed Qty on the part. | ||
- | |||
- | |||
If you do not understand when you should use one of the queries above vs. the other please consult assistance prior to running these the database. | If you do not understand when you should use one of the queries above vs. the other please consult assistance prior to running these the database. | ||
- | |||
- | |||
All users should be out of the system when running this query | All users should be out of the system when running this query | ||
- | **Restart Chapi and the SSLIP** otherwise duplicate Journal records will be created. | + | **Restart Chapi and the SSLIP** |
- | + | ||
- | + | ||
- | + | ||
- | ===== SQL Query to Reduce Received, Increase Billed Qty ===== | + | |
- | + | ||
<code sql> | <code sql> | ||
Line 72: | Line 60: | ||
DECLARE @T TABLE(InventoryID INT, | DECLARE @T TABLE(InventoryID INT, | ||
PartID INT, | PartID INT, | ||
+ | ItemName VARCHAR(100), | ||
DivisionID INT, | DivisionID INT, | ||
WarehouseID INT, | WarehouseID INT, | ||
Line 80: | Line 69: | ||
-- Insert all of the inventory items into the temp table | -- Insert all of the inventory items into the temp table | ||
INSERT INTO @T | INSERT INTO @T | ||
- | (InventoryID, | + | (InventoryID, |
- | SELECT I.ID, I.PartID, I.DivisionID, | + | SELECT I.ID, I.PartID,I.ItemName, I.DivisionID, |
FROM Inventory I | FROM Inventory I | ||
LEFT JOIN Part P ON P.ID = I.PartID | LEFT JOIN Part P ON P.ID = I.PartID | ||
Line 113: | Line 102: | ||
WarehouseID | WarehouseID | ||
FROM VendorTransDetail | FROM VendorTransDetail | ||
- | WHERE ID > 0 | + | WHERE ID> 0 |
AND ItemID IS NOT NULL | AND ItemID IS NOT NULL | ||
AND StationID IN (108, 109) -- Received, Partially Received | AND StationID IN (108, 109) -- Received, Partially Received | ||
Line 125: | Line 114: | ||
CASE | CASE | ||
WHEN PartInventoryConversion.ConversionFormula IS NULL THEN 1.00 | WHEN PartInventoryConversion.ConversionFormula IS NULL THEN 1.00 | ||
- | WHEN PATINDEX( ' | + | WHEN PATINDEX( ' |
ELSE CAST(CAST(PartInventoryConversion.ConversionFormula AS VARCHAR(100)) AS FLOAT) | ELSE CAST(CAST(PartInventoryConversion.ConversionFormula AS VARCHAR(100)) AS FLOAT) | ||
END FxUpper, | END FxUpper, | ||
CASE | CASE | ||
WHEN PartInventoryConversion.ConversionFormula IS NULL THEN 1.00 | WHEN PartInventoryConversion.ConversionFormula IS NULL THEN 1.00 | ||
- | WHEN PATINDEX( ' | + | WHEN PATINDEX( ' |
ELSE 1.00 | ELSE 1.00 | ||
END FxLower | END FxLower | ||
Line 188: | Line 177: | ||
END | END | ||
ELSE | ELSE | ||
- | SELECT InventoryID, | + | SELECT InventoryID, |
</ | </ | ||
- | |||
===== SQL Query to Reduce Received without changing Billed Qty ===== | ===== SQL Query to Reduce Received without changing Billed Qty ===== | ||
+ | <code sql> | ||
- | |||
- | <code sql> | ||
DECLARE @CommitChanges BIT; | DECLARE @CommitChanges BIT; | ||
SET @CommitChanges = 0; | SET @CommitChanges = 0; | ||
Line 213: | Line 200: | ||
SET @ModifiedByComputer = ' | SET @ModifiedByComputer = ' | ||
DECLARE @T TABLE(InventoryID INT, | DECLARE @T TABLE(InventoryID INT, | ||
- | PartID INT, | + | PartID INT, |
- | | + | |
- | | + | DivisionID INT, |
- | | + | |
- | | + | |
- | | + | |
+ | | ||
; | ; | ||
-- Insert all of the inventory items into the temp table | -- Insert all of the inventory items into the temp table | ||
INSERT INTO @T | INSERT INTO @T | ||
- | (InventoryID, | + | (InventoryID, |
- | SELECT I.ID, I.PartID, I.DivisionID, | + | SELECT I.ID, I.PartID, I.ItemName, I.DivisionID, |
FROM | FROM | ||
- | LEFT JOIN Part P ON P.ID = I.PartID | + | LEFT JOIN Part P ON P.ID = I.PartID |
WHERE P.PartType = 0 AND I.IsGroup = 0 AND P.TrackInventory = 1 | WHERE P.PartType = 0 AND I.IsGroup = 0 AND P.TrackInventory = 1 | ||
; | ; | ||
Line 232: | Line 220: | ||
SET CurrentReceivedOnly = ISNULL( IL.QuantityReceivedOnly, | SET CurrentReceivedOnly = ISNULL( IL.QuantityReceivedOnly, | ||
FROM @T T | FROM @T T | ||
- | LEFT JOIN ( SELECT | + | LEFT JOIN ( SELECT |
- | , ROUND( SUM( ISNULL( QuantityReceivedOnly, | + | , ROUND( SUM( ISNULL( QuantityReceivedOnly, |
- | | + | |
- | | + | |
- | | + | |
; | ; | ||
-- Compute the actual on order quantity and set the value | -- Compute the actual on order quantity and set the value | ||
Line 242: | Line 230: | ||
INSERT INTO @ActualReceivedOnly | INSERT INTO @ActualReceivedOnly | ||
SELECT I.ID InventoryID, | SELECT I.ID InventoryID, | ||
- | SUM( CASE WHEN TD.UnitID = P.UnitID THEN TD.POQuantityReceivedOnly | + | SUM( CASE WHEN TD.UnitID = P.UnitID THEN TD.POQuantityReceivedOnly |
- | | + | |
- | END ) POQuantityReceivedOnly | + | END ) POQuantityReceivedOnly |
FROM ( SELECT TransHeaderID, | FROM ( SELECT TransHeaderID, | ||
- | | + | |
- | | + | |
- | END ) PartID, | + | END ) PartID, |
- | UnitID, | + | UnitID, |
- | Quantity, | + | Quantity, |
- | BillQuantity, | + | BillQuantity, |
- | ( ISNULL( Quantity, 0 ) - ISNULL( BillQuantity, | + | ( ISNULL( Quantity, 0 ) - ISNULL( BillQuantity, |
- | WarehouseID | + | WarehouseID |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | UnitID, | + | UnitID, |
- | PartInventoryConversion.ConversionFormula, | + | PartInventoryConversion.ConversionFormula, |
- | CASE | + | CASE |
- | WHEN PartInventoryConversion.ConversionFormula IS NULL THEN 1.00 | + | WHEN PartInventoryConversion.ConversionFormula IS NULL THEN 1.00 |
- | WHEN PATINDEX( ' | + | WHEN PATINDEX( ' |
- | ELSE CAST(CAST(PartInventoryConversion.ConversionFormula AS VARCHAR(100)) AS FLOAT) | + | ELSE CAST(CAST(PartInventoryConversion.ConversionFormula AS VARCHAR(100)) AS FLOAT) |
- | END FxUpper, | + | END FxUpper, |
- | CASE | + | CASE |
- | WHEN PartInventoryConversion.ConversionFormula IS NULL THEN 1.00 | + | WHEN PartInventoryConversion.ConversionFormula IS NULL THEN 1.00 |
- | WHEN PATINDEX( ' | + | WHEN PATINDEX( ' |
- | ELSE 1.00 | + | ELSE 1.00 |
- | END FxLower | + | END FxLower |
- | | + | |
WHERE TH.TransactionType = 7 AND I.ID IS NOT NULL -- PO, we don't filter on status since we're filtering on line item statuses. | WHERE TH.TransactionType = 7 AND I.ID IS NOT NULL -- PO, we don't filter on status since we're filtering on line item statuses. | ||
GROUP BY I.ID | GROUP BY I.ID | ||
Line 282: | Line 270: | ||
SET ActualReceivedOnly = ISNULL( CR.Amount, 0 ) | SET ActualReceivedOnly = ISNULL( CR.Amount, 0 ) | ||
FROM @T T | FROM @T T | ||
- | LEFT JOIN @ActualReceivedOnly CR ON CR.InventoryID = T.InventoryID | + | LEFT JOIN @ActualReceivedOnly CR ON CR.InventoryID = T.InventoryID |
; | ; | ||
-- Delete all inventory records that do not require a change from the temp table | -- Delete all inventory records that do not require a change from the temp table | ||
Line 290: | Line 278: | ||
IF @CommitChanges = 1 | IF @CommitChanges = 1 | ||
BEGIN | BEGIN | ||
- | | + | |
- | DECLARE @LastJournalID INT; | + | DECLARE @LastJournalID INT; |
- | SET @LastJournalID = (SELECT MAX(ID) FROM Journal); | + | SET @LastJournalID = (SELECT MAX(ID) FROM Journal); |
- | UPDATE T | + | UPDATE T |
- | SET New_JournalID = RowNum + @LastJournalID | + | SET New_JournalID = RowNum + @LastJournalID |
- | FROM | + | FROM |
- | ( | + | ( |
- | SELECT | + | SELECT |
- | ROW_NUMBER() OVER(ORDER BY x.InventoryID) AS RowNum | + | ROW_NUMBER() OVER(ORDER BY x.InventoryID) AS RowNum |
- | FROM @T x | + | FROM @T x |
- | ) AS T | + | ) AS T |
- | ; | + | ; |
- | -- Insert Journal entry | + | -- Insert Journal entry |
- | INSERT INTO Journal | + | INSERT INTO Journal |
- | (ID, StoreID, ClassTypeID, | + | (ID, StoreID, ClassTypeID, |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | SELECT New_JournalID, | + | SELECT New_JournalID, |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | FROM @T | + | FROM @T |
- | ; | + | ; |
- | -- Insert InventoryLog entry | + | -- Insert InventoryLog entry |
- | INSERT INTO InventoryLog | + | INSERT INTO InventoryLog |
- | (ID, StoreID, ClassTypeID, | + | (ID, StoreID, ClassTypeID, |
- | | + | |
- | | + | |
- | | + | |
- | SELECT New_JournalID, | + | SELECT New_JournalID, |
- | | + | |
- | | + | |
- | | + | |
- | FROM @T T | + | FROM @T T |
- | ; | + | ; |
END | END | ||
ELSE | ELSE | ||
- | | + | |
</ | </ | ||
- | |||
- | |||
- | |||
====== Version Information ====== | ====== Version Information ====== | ||
* Revised : 07/2018 | * Revised : 07/2018 |