SELECT
od.OrderDetailID,
o.OrderID,
MAX(p.PIN) AS PIN,
od.ProductCode,
p.name,
od.Quantity,
IFNULL(od.QtyShipped, 0) AS QtyShipped,
od.ProductPrice,
IFNULL(od.Vendor_Price, 0) AS Vendor_Price,
o.OrderDate,
o.OrderStatus,
IFNULL(od.ProductNote, '') AS ProductNote,
od.CustomLineItem,
IFNULL(o.TotalShippingCost, 0) AS TotalShippingCost,
IFNULL(o.Order_Entry_System, '') AS Order_Entry_System,
IFNULL(o.ShipState, '') AS ShipState,
IFNULL(o.ShipCountry, '') AS ShipCountry,
IFNULL(o.ShippingMethodID, 0) AS ShippingMethodID
FROM custopayted.orders o
	JOIN custopayted.orderdetails od ON o.OrderID = od.OrderID
	JOIN products.pins p ON p.ProductCode = od.ProductCode AND p.Hidden != 'Y'
WHERE
p.ModelID != ''
AND YEAR(o.orderdate) >= 2023
GROUP BY
od.OrderDetailID,
o.OrderID,
od.ProductCode,
od.Quantity,
od.QtyShipped,
od.ProductPrice,
od.Vendor_Price,
o.OrderDate,
o.OrderStatus,
od.CustomLineItem,
od.ProductNote,
o.TotalShippingCost,
o.Order_Entry_System,
o.ShipState,
o.ShipCountry,
o.ShippingMethodID
ORDER BY o.OrderID DESC