-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed83ccc
commit 720a52b
Showing
15 changed files
with
834 additions
and
212 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
standard_reports/stock-detail/2_5/argument_schemas/arguments.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"definitions": { | ||
"StockFilters": { | ||
"properties": { | ||
"itemCodeOrName": { | ||
"description": "Item Code or Name", | ||
"type": "string" | ||
}, | ||
"sort": { | ||
"description": "sort by", | ||
"type": "string", | ||
"enum": [ | ||
"batch", | ||
"item.name", | ||
"item.code", | ||
"expiryDate", | ||
"location.code", | ||
"item.unitName", | ||
"packSize", | ||
"totalNumberOfPacks" | ||
] | ||
}, | ||
"dir": { | ||
"description": "sort by dir", | ||
"type": "string", | ||
"enum": ["asc", "desc"] | ||
} | ||
} | ||
} | ||
}, | ||
"type": "object", | ||
"allOf": [ | ||
{ | ||
"$ref": "#/definitions/StockFilters" | ||
} | ||
] | ||
} |
36 changes: 36 additions & 0 deletions
36
standard_reports/stock-detail/2_5/argument_schemas/arguments_ui.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"type": "VerticalLayout", | ||
"elements": [ | ||
{ | ||
"type": "Control", | ||
"scope": "#/properties/itemCodeOrName", | ||
"label": "T#report.item-code-or-name", | ||
"options": { | ||
"useDebounce": false | ||
} | ||
}, | ||
|
||
{ | ||
"type": "Control", | ||
"scope": "#/properties/sort", | ||
"label": "T#report.sort-by", | ||
"options": { | ||
"show": [ | ||
["item.name", "T#report.item-name"], | ||
["batch", "T#label.batch"], | ||
["item.code", "T#label.code"], | ||
["expiryDate", "T#report.expiry-date"], | ||
["location.code", "T#label.location"], | ||
["item.unitName", "T#label.unit"], | ||
["packSize", "T#label.pack-size"], | ||
["totalNumberOfPacks", "T#label.num-packs-total"] | ||
] | ||
} | ||
}, | ||
{ | ||
"type": "Control", | ||
"scope": "#/properties/dir", | ||
"label": "T#report.sort-direction" | ||
} | ||
] | ||
} |
16 changes: 16 additions & 0 deletions
16
standard_reports/stock-detail/2_5/convert_data_js/esbuild.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const esbuild = require("esbuild"); | ||
// include this if you need some node support: | ||
// npm i @esbuild-plugins/node-modules-polyfill --save-dev | ||
// const { NodeModulesPolyfillPlugin } = require('@esbuild-plugins/node-modules-polyfill') | ||
|
||
esbuild.build({ | ||
// supports other types like js or ts | ||
entryPoints: ["src/convert_data.js"], | ||
outdir: "dist", | ||
bundle: true, | ||
sourcemap: true, | ||
//plugins: [NodeModulesPolyfillPlugin()], // include this if you need some node support | ||
minify: false, // might want to use true for production build | ||
format: "cjs", // needs to be CJS for now | ||
target: ["es2020"], // don't go over es2020 because quickjs doesn't support it | ||
}); |
131 changes: 131 additions & 0 deletions
131
standard_reports/stock-detail/2_5/convert_data_js/input.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
{ | ||
"AMCTwelve": [ | ||
{ | ||
"quantity": 150.8, | ||
"item_id": "101" | ||
}, | ||
{ | ||
"quantity": 92.4, | ||
"item_id": "102" | ||
}, | ||
{ | ||
"quantity": 200.5, | ||
"item_id": "103" | ||
} | ||
], | ||
"AMCTwentyFour": [ | ||
{ | ||
"quantity": 250.8, | ||
"item_id": "101" | ||
}, | ||
{ | ||
"quantity": 192.4, | ||
"item_id": "102" | ||
}, | ||
{ | ||
"quantity": 300.5, | ||
"item_id": "103" | ||
} | ||
], | ||
"expiringInSixMonths": [ | ||
{ | ||
"id": 201, | ||
"item_id": "101", | ||
"quantity": 150 | ||
}, | ||
{ | ||
"id": 202, | ||
"item_id": "102", | ||
"quantity": 75 | ||
} | ||
], | ||
"expiringInTwelveMonths": [ | ||
{ | ||
"id": 201, | ||
"item_id": "101", | ||
"quantity": 170 | ||
}, | ||
{ | ||
"id": 202, | ||
"item_id": "102", | ||
"quantity": 92 | ||
}, | ||
{ | ||
"id": 203, | ||
"item_id": "103", | ||
"quantity": 400 | ||
} | ||
], | ||
"thisMonthConsumption": [ | ||
{ | ||
"quantity": 200, | ||
"item_id": "101" | ||
}, | ||
{ | ||
"quantity": 150, | ||
"item_id": "102" | ||
}, | ||
{ | ||
"quantity": 300, | ||
"item_id": "103" | ||
} | ||
], | ||
"lastMonthConsumption": [ | ||
{ | ||
"quantity": 500, | ||
"item_id": "101" | ||
}, | ||
{ | ||
"quantity": 300, | ||
"item_id": "102" | ||
}, | ||
{ | ||
"quantity": 450, | ||
"item_id": "103" | ||
} | ||
], | ||
"twoMonthsAgoConsumption": [ | ||
{ | ||
"quantity": 123, | ||
"item_id": "101" | ||
}, | ||
{ | ||
"quantity": 421, | ||
"item_id": "102" | ||
}, | ||
{ | ||
"quantity": 152, | ||
"item_id": "103" | ||
} | ||
], | ||
"items": { | ||
"nodes": [ | ||
{ | ||
"id": "101", | ||
"code": "ITEM001", | ||
"name": "Item A", | ||
"stats": { | ||
"totalConsumption": 1200, | ||
"availableMonthsOfStockOnHand": 4.5, | ||
"availableStockOnHand": 300.902, | ||
"averageMonthlyConsumption": 266.7 | ||
}, | ||
"someOtherKey": "" | ||
}, | ||
{}, | ||
{ | ||
"id": "101", | ||
"code": "ITEM001", | ||
"name": "Item A", | ||
"stats": { | ||
"totalConsumption": 100, | ||
"availableMonthsOfStockOnHand": 4.5, | ||
"availableStockOnHand": 200, | ||
"someNestedEmptyStringKey": "" | ||
}, | ||
"someOtherOtherKey": "" | ||
}, | ||
{} | ||
] | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
standard_reports/stock-detail/2_5/convert_data_js/output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"items": { | ||
"nodes": [ | ||
{ | ||
"id": "101", | ||
"code": "ITEM001", | ||
"name": "Item A", | ||
"stats": { | ||
"totalConsumption": 1200, | ||
"availableMonthsOfStockOnHand": 4.5, | ||
"availableStockOnHand": 300.902, | ||
"averageMonthlyConsumption": 266.7 | ||
}, | ||
"monthConsumption": 200, | ||
"lastMonthConsumption": 500, | ||
"twoMonthsAgoConsumption": 123, | ||
"expiringInSixMonths": 150, | ||
"expiringInTwelveMonths": 170, | ||
"stockOnOrder": 0, | ||
"AMC12": 150.8, | ||
"AMC24": 250.8, | ||
"SOH": 300.9, | ||
"MOS": 4.5 | ||
}, | ||
{ | ||
"id": "101", | ||
"code": "ITEM001", | ||
"name": "Item A", | ||
"stats": { | ||
"availableStockOnHand": 200, | ||
"totalConsumption": 100, | ||
"availableMonthsOfStockOnHand": 4.5 | ||
}, | ||
"stockOnOrder": 0, | ||
"AMC12": 150.8, | ||
"AMC24": 250.8, | ||
"SOH": 200, | ||
"MOS": 4.5, | ||
"expiringInSixMonths": 150, | ||
"expiringInTwelveMonths": 170, | ||
"lastMonthConsumption": 500, | ||
"monthConsumption": 200, | ||
"twoMonthsAgoConsumption": 123 | ||
} | ||
] | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
standard_reports/stock-detail/2_5/convert_data_js/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "convert_data_js", | ||
"version": "1.0.0", | ||
"main": "convert_data.js", | ||
"scripts": { | ||
"build": "node esbuild.js && extism-js dist/convert_data.js -i src/convert_data.d.ts -o dist/plugin.wasm" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"types": "./convert_data.d.ts", | ||
"description": "", | ||
"devDependencies": { | ||
"esbuild": "^0.24.0" | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
standard_reports/stock-detail/2_5/convert_data_js/src/convert_data.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
declare module 'main' { | ||
// Extism exports take no params and return an I32 | ||
export function convert_data(): I32; | ||
} | ||
declare module 'extism:host' { | ||
interface user { | ||
sql(ptr: I64): I64; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
standard_reports/stock-detail/2_5/convert_data_js/src/convert_data.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { processStockLines } from "./utils"; | ||
|
||
function convert_data() { | ||
const res = JSON.parse(Host.inputString()); | ||
res.data.stockLines.nodes = processStockLines( | ||
res.data.stockLines.nodes, | ||
// assign default sort values | ||
res?.arguments?.sort ?? "item.name", | ||
res?.arguments?.dir ?? "asc" | ||
); | ||
Host.outputString(JSON.stringify(res)); | ||
} | ||
|
||
module.exports = { | ||
convert_data, | ||
}; |
11 changes: 11 additions & 0 deletions
11
standard_reports/stock-detail/2_5/convert_data_js/src/utils.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { cleanUpNodes, sortNodes } from "../../../../utils"; | ||
|
||
const processStockLines = (nodes, sort, dir) => { | ||
let cleanNodes = cleanUpNodes(nodes); | ||
let sortedNodes = sortNodes(cleanNodes, sort, dir); | ||
return sortedNodes; | ||
}; | ||
|
||
module.exports = { | ||
processStockLines, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"is_custom": false, | ||
"version": "2.5.0", | ||
"code": "stock-detail", | ||
"context": "REPORT", | ||
"sub_context": "StockAndItems", | ||
"name": "Stock Detail", | ||
"queries": { | ||
"gql": "query.graphql" | ||
}, | ||
"arguments": { | ||
"schema": "argument_schemas/arguments.json", | ||
"ui": "argument_schemas/arguments_ui.json" | ||
}, | ||
"convert_data": "convert_data_js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
query StockDetail($storeId: String, $itemCodeOrName: String) { | ||
stockLines( | ||
storeId: $storeId | ||
page: { first: 5000 } | ||
filter: { | ||
itemCodeOrName: { like: $itemCodeOrName } | ||
hasPacksInStore: true | ||
isActive: true | ||
} | ||
) { | ||
... on StockLineConnector { | ||
nodes { | ||
batch | ||
expiryDate | ||
id | ||
packSize | ||
storeId | ||
totalNumberOfPacks | ||
supplierName | ||
location { | ||
code | ||
} | ||
item { | ||
code | ||
name | ||
unitName | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.