Asset Movement Including Last Stock Take
Last Modified on 03/06/2022 2:37 pm EDT
You can execute this query using Excel Query Builder in RentalPoint...
|
|
SELECT A.asset_code [Barcode],
A.product_code [Product],
A.description,
A.Location,
A.stock_number [Stock Number],
A.serial_no [Serial],
CASE
WHEN idisposaltype = 0 THEN 'CURRENT'
WHEN idisposaltype = 1 THEN 'SOLD'
WHEN idisposaltype = 2 THEN 'LOST'
WHEN idisposaltype = 3 THEN 'STOLEN'
WHEN idisposaltype = 4 THEN 'WRITTENOFF'
END,
A.cost,
A.est_resale,
A.insured_val,
(SELECT TOP 1 CASE
WHEN AT.actindate = CAST('Jan 1 1980' AS datetime) THEN 'Out'
WHEN AT.actindate > CAST('Jan 1 1980' AS datetime) THEN 'In'
END
FROM tblassetran AT
WHERE AT.product_code = A.product_code
AND AT.stock_number = A.stock_number
ORDER BY actoutdate DESC) [Last Asset Movement Type],
(SELECT TOP 1 AT.booking_no
FROM tblassetran AT
WHERE AT.product_code = A.product_code
AND AT.stock_number = A.stock_number
ORDER BY actoutdate DESC) [Last Asset Movement Booking],
(SELECT TOP 1 CASE
WHEN AT.actindate = CAST('Jan 1 1980' AS datetime) THEN 'Still Out On Booking'
ELSE CONVERT(varchar, AT.actindate, 103)
END
FROM tblassetran AT
WHERE AT.product_code = A.product_code
AND AT.stock_number = A.stock_number
ORDER BY actoutdate DESC) [Last Asset Movement Date],
(SELECT MAX(EntryDateTime)
FROM tblstocktakhistory S
WHERE A.product_code = S.product_code
AND A.stock_number = S.stock_number) [Last StockTake],
CASE
WHEN LEN(b.rdate) > 0 THEN CONVERT(varchar, B.rdate, 103)
ELSE ''
END [Warehouse IN Date]
FROM tblasset01 A
LEFT OUTER JOIN tblinvmas IM ON IM.product_code = A.product_code
LEFT OUTER JOIN tblbookings B ON B.booking_no = A.booking_no /*WHERE A.Asset_Code = 'XXXXXX' */
ORDER BY IM.groupfld,
IM.category,
A.product_code,
A.asset_code