{"database": "fishbowl_archive", "table": "biscript", "rows": [[12, "_binary \u0001", "const dateRange = $RANGE{Date_Range|this month};\r\n\r\nconst includeReturns = $CHECK{IncludeReturns|false};\r\nconst includeDiscounts = $CHECK{IncludeDiscounts|false};\r\n\r\nconst query = `SELECT so.salesman, SUM(postSoItem.totalPrice) AS totalPrice\r\nFROM postSoItem\r\n    JOIN soItem ON postSoItem.soItemId = soitem.id AND soItem.typeId <> 40 AND soItem.qtyfulfilled > 0\r\n    JOIN so ON soItem.soId = so.id\r\n    JOIN postSo ON postSo.Id = postsoitem.postsoid\r\nWHERE postSo.postDate between '${dateRange.fromDate}' AND '${dateRange.toDate}'\r\n    AND IF(${includeReturns} = 1,1=1,soitem.typeid NOT IN (20,21))\r\n    AND IF(${includeDiscounts} = 1,1=1,soitem.typeid NOT IN (30,31))\r\nGROUP BY so.salesmanId\r\nORDER BY totalPrice DESC`;\r\n\r\nconst data = JSON.parse(runQuery(query));\r\n\r\nconsole.log(query);\r\nconsole.log(data);\r\n\r\nlet dateStr = UTIL.convertDate(dateRange.fromDate, true) + \" - \" + UTIL.convertDate(dateRange.toDate, false);\r\nif (moment(dateRange.fromDate).isSame('1000-01-01', 'year') && moment(dateRange.toDate).isSame('3000-01-01', 'year')) {\r\n  dateStr = 'All';\r\n}\r\n   \r\nfunction createBar(totalPrice, tableColors){\r\n    return {\r\n        backgroundColor: tableColors.halfAlpha,\r\n        borderColor: tableColors.fullAlpha,\r\n        borderWidth: 3,\r\n        data: totalPrice,\r\n    };\r\n}\r\n\r\nconst barLabels = [];\r\nconst barTotalPrices = [];\r\nlet barTotalPriceOverall = 0;\r\nconst chartData = [];\r\n\r\nfor (let salesman = 0; salesman < data.length; salesman++) {\r\n    barLabels.push(data[salesman].salesman);\r\n    barTotalPrices.push(data[salesman].totalprice);\r\n    barTotalPriceOverall += barTotalPrices[salesman];\r\n}\r\n\r\nlet tableColors = COLORS.get(data.length);\r\nchartData.push(createBar(barTotalPrices, tableColors));\r\n\r\nconst barChartData = {\r\n    labels: barLabels,\r\n    datasets: chartData\r\n}\r\n\r\nconst barOptions = {\r\n    title: {\r\n        display: true,\r\n        padding: 3\r\n    },\r\n    mode: 'index',\r\n    position: 'cursor',\r\n    intersect: false,\r\n    legend: {\r\n        display: false,\r\n    },\r\n    scales: {\r\n        xAxes: [{\r\n            ticks: {\r\n                autoSkip: false\r\n            }\r\n        }],\r\n        yAxes: [{\r\n            ticks: {\r\n                beginAtZero: true,\r\n                callback: function(value, index, values) {\r\n                    return UTIL.dollarify(value, 0);\r\n                }\r\n            }\r\n        }]\r\n    },\r\n    tooltips: {\r\n        callbacks: {\r\n            label: (tooltipItem, data) => {\r\n                return UTIL.dollarify(tooltipItem.yLabel);\r\n            },\r\n            title: (tooltipItem, data) => {\r\n                return tooltipItem[0].xLabel;\r\n            }\r\n        },\r\n    },\r\n    responsive: true,\r\n    maintainAspectRatio: false,\r\n    plugins: {\r\n        datalabels: {\r\n            align: 'end',\r\n            anchor: 'end',\r\n            color: '#828891',\r\n            font: {\r\n                weight: 'bold',\r\n                family: 'Helvetica'\r\n            },\r\n            formatter: function(value, context) {\r\n                return UTIL.dollarify(value);\r\n            }\r\n        }\r\n    }\r\n};\r\n\r\nconst ctxBar = document.getElementById('topSalesman');\r\nnew Chart(ctxBar, {\r\n    type: 'bar',\r\n    data: barChartData,\r\n    options: barOptions\r\n});\r\n\r\ndocument.getElementById(\"title\").innerHTML = 'Sales By Rep';\r\ndocument.getElementById(\"subTitle\").innerHTML = dateStr;\r\ndocument.getElementById(\"description\").innerHTML = '<Description>';", "2023-01-05 17:28:06.974000", "Query and logic for the Sales By Rep page", "Sales By Rep", "", 20, 5, "sales-by-rep", 0]], "columns": ["id", "active", "data", "dateLastModified", "description", "name", "note", "typeId", "fbVersion", "fbName", "published"], "primary_keys": ["id"], "primary_key_values": ["12"], "units": {}, "query_ms": 1.7890330054797232}