Added Unused Items stat
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"gitSyncId": "11976947d24e48cf90c738f1_c8a3dcce-d31d-42fe-9aa7-7773bd28f1d9",
|
||||
"id": "Operations - Unused Items_unused_items",
|
||||
"pluginId": "postgres-plugin",
|
||||
"pluginType": "DB",
|
||||
"unpublishedAction": {
|
||||
"actionConfiguration": {
|
||||
"body": "SELECT\n i.item_number AS \"Item Number\",\n i.item_descrip1 AS \"Description\",\n CASE i.item_type\n WHEN 'P' THEN 'Purchased'\n WHEN 'M' THEN 'Manufactured'\n WHEN 'R' THEN 'Reference'\n WHEN 'T' THEN 'Tooling'\n WHEN 'O' THEN 'Outside Process'\n WHEN 'B' THEN 'Breeder'\n WHEN 'C' THEN 'Co-Product'\n WHEN 'F' THEN 'Phantom'\n ELSE i.item_type\n END AS \"Item Type\",\n CASE WHEN i.item_active THEN 'Active' ELSE 'Inactive' END AS \"Status\",\n cc.comment_user AS \"Created By\",\n COALESCE(i.item_created, cc.comment_date)::date AS \"Date Created\",\n last_txn.last_transaction_date::date AS \"Last Transaction\",\n (CURRENT_DATE - COALESCE(last_txn.last_transaction_date, i.item_created, cc.comment_date)::date) AS \"Days Unused\"\nFROM item i\nLEFT JOIN comment cc\n ON cc.comment_source_id = i.item_id\n AND cc.comment_source = 'I'\n AND cc.comment_text = 'Created'\nLEFT JOIN (\n SELECT\n isite.itemsite_item_id,\n MAX(ih.invhist_transdate) AS last_transaction_date\n FROM itemsite isite\n JOIN invhist ih ON ih.invhist_itemsite_id = isite.itemsite_id\n GROUP BY isite.itemsite_item_id\n) last_txn ON last_txn.itemsite_item_id = i.item_id\nWHERE (CURRENT_DATE - COALESCE(last_txn.last_transaction_date, i.item_created, cc.comment_date)::date)\n >= COALESCE(NULLIF('{{UnusedDays.text}}','')::int, 365)\nORDER BY \"Days Unused\" DESC",
|
||||
"encodeParamsToggle": true,
|
||||
"paginationType": "NONE",
|
||||
"pluginSpecifiedTemplates": [
|
||||
{
|
||||
"value": true
|
||||
}
|
||||
],
|
||||
"timeoutInMillisecond": 30000
|
||||
},
|
||||
"confirmBeforeExecute": false,
|
||||
"datasource": {
|
||||
"id": "xTuple_GoLive",
|
||||
"isAutoGenerated": false,
|
||||
"name": "xTuple_GoLive",
|
||||
"pluginId": "postgres-plugin"
|
||||
},
|
||||
"dynamicBindingPathList": [
|
||||
{
|
||||
"key": "body"
|
||||
}
|
||||
],
|
||||
"name": "unused_items",
|
||||
"pageId": "Operations - Unused Items",
|
||||
"runBehaviour": "AUTOMATIC",
|
||||
"userSetOnLoad": false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
SELECT
|
||||
i.item_number AS "Item Number",
|
||||
i.item_descrip1 AS "Description",
|
||||
CASE i.item_type
|
||||
WHEN 'P' THEN 'Purchased'
|
||||
WHEN 'M' THEN 'Manufactured'
|
||||
WHEN 'R' THEN 'Reference'
|
||||
WHEN 'T' THEN 'Tooling'
|
||||
WHEN 'O' THEN 'Outside Process'
|
||||
WHEN 'B' THEN 'Breeder'
|
||||
WHEN 'C' THEN 'Co-Product'
|
||||
WHEN 'F' THEN 'Phantom'
|
||||
ELSE i.item_type
|
||||
END AS "Item Type",
|
||||
CASE WHEN i.item_active THEN 'Active' ELSE 'Inactive' END AS "Status",
|
||||
cc.comment_user AS "Created By",
|
||||
COALESCE(i.item_created, cc.comment_date)::date AS "Date Created",
|
||||
last_txn.last_transaction_date::date AS "Last Transaction",
|
||||
(CURRENT_DATE - COALESCE(last_txn.last_transaction_date, i.item_created, cc.comment_date)::date) AS "Days Unused"
|
||||
FROM item i
|
||||
LEFT JOIN comment cc
|
||||
ON cc.comment_source_id = i.item_id
|
||||
AND cc.comment_source = 'I'
|
||||
AND cc.comment_text = 'Created'
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
isite.itemsite_item_id,
|
||||
MAX(ih.invhist_transdate) AS last_transaction_date
|
||||
FROM itemsite isite
|
||||
JOIN invhist ih ON ih.invhist_itemsite_id = isite.itemsite_id
|
||||
GROUP BY isite.itemsite_item_id
|
||||
) last_txn ON last_txn.itemsite_item_id = i.item_id
|
||||
WHERE (CURRENT_DATE - COALESCE(last_txn.last_transaction_date, i.item_created, cc.comment_date)::date)
|
||||
>= COALESCE(NULLIF('{{UnusedDays.text}}','')::int, 365)
|
||||
ORDER BY "Days Unused" DESC
|
||||
Reference in New Issue
Block a user