{"database": "fishbowl_archive", "table": "biscript", "rows": [[30, "_binary \u0001", "let partNum = '$PART{Part|%|General}';\r\npartNum == -1 ? (partNum = '%') : true;\r\nlet locationGroupId = '$LG{Location_Group|%|General}';\r\nlocationGroupId == -1 ? (locationGroupId = '%') : true;\r\nlet user = JSON.parse(getUser());\r\nlet currentUser = user.id;\r\n\r\nlet dataset;\r\n\r\nfunction monitor() {\r\n  function getData() {\r\n    let query = `SELECT\r\n      COALESCE((SELECT (sysvalue) * 1000 FROM sysproperties WHERE syskey = 'Refresh Rate'),300000) as refresh,\r\n      watch.id as watchid,\r\n      part.num as partnum,\r\n      part.description as partdescription,\r\n      COALESCE(locationgroup.name,'Company Wide') as locationgroup,\r\n      coalesce(uom.code,'') as uom,\r\n      @avail:= coalesce(IF(coalesce(qtyonhand.qty,0) - coalesce(qtyallocated.qty,0) - coalesce(qtynotavailable.qty,0) + coalesce(qtydropship.qty,0) < 0,0,coalesce(qtyonhand.qty,0) - coalesce(qtyallocated.qty,0) - coalesce(qtynotavailable.qty,0) + coalesce(qtydropship.qty,0))) as avail,\r\n\r\n      @onhand:=(CASE WHEN watch.locationgroupid IS NOT NULL THEN coalesce(qtyonhand.qty,0) ELSE coalesce(totals.qtyonhand, 0) END) as onhand,\r\n      @available:=(CASE WHEN watch.locationgroupid IS NOT NULL THEN coalesce(@avail,0) ELSE coalesce(totals.qtyavailable, 0) END) as available,\r\n      @committed:=(CASE WHEN watch.locationgroupid IS NOT NULL THEN coalesce(qtycommitted.qty,0) ELSE coalesce((SELECT sum(qty) FROM qtycommitted qtyc WHERE qtyc.partid = part.id GROUP BY partid),0) END) as committed,\r\n      @allocated:=(CASE WHEN watch.locationgroupid IS NOT NULL THEN coalesce(qtyallocated.qty,0) ELSE coalesce(totals.qtyallocated, 0) END) as allocated,\r\n      @notavailable:=(CASE WHEN watch.locationgroupid IS NOT NULL THEN coalesce(qtynotavailable.qty,0) ELSE coalesce(totals.qtynotavailable, 0) END) as 'not available',\r\n      @onorder:=(CASE WHEN watch.locationgroupid IS NOT NULL THEN coalesce(qtyonorder.qty,0) ELSE coalesce(totals.qtyonorder, 0) END) as 'on order',\r\n\r\n     (CASE \r\n          WHEN @onhand > watch.alertlevel THEN 'fb10'\r\n          WHEN @onhand <= watch.alertlevel && @onhand > watch.criticallevel THEN 'fb20'\r\n          WHEN @onhand < watch.alertlevel && @onhand <= watch.criticallevel THEN 'fb30'\r\n      END) as state,\r\n      (CASE \r\n        WHEN @onhand > watch.alertlevel THEN '1-Good'\r\n        WHEN @onhand <= watch.alertlevel && @onhand > watch.criticallevel THEN '2-Alert'\r\n        WHEN @onhand < watch.alertlevel && @onhand <= watch.criticallevel THEN '3-Critical'\r\n    END) as statetext\r\n\r\n    FROM watch\r\n\r\n      INNER JOIN part ON watch.itemid = part.id\r\n      INNER JOIN uom ON part.uomid = uom.id\r\n      LEFT OUTER JOIN locationgroup ON watch.locationgroupid = locationgroup.id\r\n      left outer join qtyonhand on (part.id = qtyonhand.partid and locationgroup.id = qtyonhand.locationgroupid)\r\n      left outer join qtycommitted on (part.id = qtycommitted.partid and locationgroup.id = qtycommitted.locationgroupid)\r\n      left outer join qtyallocated on (part.id = qtyallocated.partid and locationgroup.id = qtyallocated.locationgroupid)\r\n      left outer join qtyonorder on (part.id = qtyonorder.partid and locationgroup.id = qtyonorder.locationgroupid)\r\n      left outer join qtynotavailable on (part.id = qtynotavailable.partid and locationgroup.id = qtynotavailable.locationgroupid)\r\n      left outer join qtydropship on (part.id = qtydropship.partid and locationgroup.id = qtydropship.locationgroupid)\r\n      left outer join (select coalesce(sum(qti.qtyonhand),0) as qtyonhand,\r\n                  coalesce(sum(qti.qtyallocated),0) as qtyallocated,\r\n                  coalesce(sum(qti.qtyonorder),0) as qtyonorder,\r\n                  if(coalesce((sum(qti.qtyonhand) - sum(qti.qtyallocated) - sum(qti.qtynotavailable) + sum(qti.qtydropship)),0) < 0,0,coalesce((sum(qti.qtyonhand) - sum(qti.qtyallocated) - sum(qti.qtynotavailable) + sum(qti.qtydropship)),0)) as qtyavailable,                  coalesce(sum(qti.qtynotavailable),0) as qtynotavailable,\r\n                  coalesce(sum(qti.qtydropship),0) as qtydropship, qti.partid\r\n              from qtyinventorytotals qti\r\n              group by qti.partid) as totals on part.id = totals.partid\r\n              \r\n    WHERE part.id LIKE '${partNum}'\r\n            AND COALESCE(locationgroup.id,'') LIKE '${locationGroupId}'\r\n            AND watch.sysuserid LIKE '${currentUser}'`;\r\n\r\n    console.log(query);\r\n    let dataset = JSON.parse(runQuery(query));\r\n    console.log(dataset);\r\n    return dataset;\r\n  }\r\n\r\n  function drawTable() {\r\n    dataset = getData();\r\n\r\n    let table = $('#report-table');\r\n    table.empty();\r\n\r\n    table.DataTable({\r\n      dom: 'B<\"clear\">lfrtip',\r\n      data: dataset,\r\n      columns: [\r\n        {\r\n          title: 'State',\r\n          data: 'statetext',\r\n          defaultContent: '',\r\n          className: 'stateText',\r\n          createdCell: function(td, cellData, rowData, row, col) {\r\n            let statecircle = document.createElement('div');\r\n            console.log(statecircle);\r\n            statecircle.setAttribute('watchid', rowData.watchid);\r\n            td.append(statecircle);\r\n            statecircle.classList.add(rowData.state);\r\n            statecircle.classList.add('dot');\r\n          }\r\n        },\r\n        { title: 'Part Number', data: 'partnum' },\r\n        { title: 'Part Description', data: 'partdescription' },\r\n        { title: 'Location Group', data: 'locationgroup' },\r\n        { title: 'UOM', data: 'uom' },\r\n        { title: 'On Hand', data: 'onhand' },\r\n        { title: 'Available', data: 'available' },\r\n        { title: 'Committed', data: 'committed', defaultContent: '0' },\r\n        { title: 'Allocated', data: 'allocated' },\r\n        { title: 'Not Available', data: 'not available' },\r\n        { title: 'On Order', data: 'on order' }\r\n      ],\r\n      fixedHeader: true,\r\n      colReorder: false,\r\n      pagingType: 'simple',\r\n      responsive: true,\r\n      deferRender: true,\r\n      buttons: ['csv'],\r\n      language: {\r\n        paginate: {\r\n          previous: 'PREV',\r\n          next: 'NEXT'\r\n        }\r\n      }\r\n    });\r\n  }\r\n\r\n  function refreshTable() {\r\n    console.time('refreshRate');\r\n    let table = $('#report-table').DataTable();\r\n    dataset = getData();\r\n    table.clear();\r\n    table.rows.add(dataset);\r\n    table.draw(false);\r\n    console.timeEnd('refreshRate');\r\n    setTimeout(refreshTable, dataset[0].refresh);\r\n  }\r\n\r\n  drawTable();\r\n  $(\".dt-buttons\").addClass( \"csv-button-margin\" );\r\n  console.log(dataset[0].refresh);\r\n  setTimeout(refreshTable, dataset[0].refresh);\r\n}\r\n\r\n$(document).ready(function() {\r\n  monitor();\r\n});\r\n", "2023-01-05 17:28:07.068000", "Replicates the functionality of the Monitor Module, but adds the option to display it on your dashboard. Watches must be created in the Monitor Module.", "Inventory Watch List", "", 20, 2, "inventory-watch-list", 0]], "columns": ["id", "active", "data", "dateLastModified", "description", "name", "note", "typeId", "fbVersion", "fbName", "published"], "primary_keys": ["id"], "primary_key_values": ["30"], "units": {}, "query_ms": 1.4220059965737164}