Developer notes
| Table | Content |
|---|---|
?:kv_ia_items |
Current state per tracked product (latest snapshot): stock, on hand, unit cost + source, price, value, warehouse split flag, units and revenue in the ABC period, units in the velocity window, average daily sales, days of cover, ABC classes (store-wide and within the company), last sale, creation time, lead time, on order, reorder point and quantity. |
?:kv_ia_item_wh |
Stock per warehouse of products split by the core Warehouses add-on. |
?:kv_ia_sales |
Units and line revenue per product and shop day (orders in the counted statuses, Multi-Vendor parent orders skipped). |
?:kv_ia_snapshots |
Daily totals per company (company_id 0 = everything): products, in stock, out of stock, units, value, estimated value, dead stock value. |
?:kv_ia_snapshot_groups |
Daily value per category (kind c) and warehouse (kind w). |
?:kv_ia_stockouts |
Stockout periods (end_day 0 = still out). |
?:kv_ia_filters |
Saved filters (user, company, JSON parameters). |
?:kv_ia_meta |
Snapshot state (phase, cursor, days), last cron run, first snapshot day. |
Days are shop days YYYYMMDD in the store time zone (Settings → Appearance).
Snapshot
Section titled “Snapshot”Tygh\Addons\KvInventoryAnalytics\Snapshot::run($budget) works for $budget seconds and is resumable:
- sales: rebuilds
?:kv_ia_salesday by day (15 days per step) from?:orders(index ontimestamp) +?:order_details. The first run readshistory_days, later runs the lastlookback_days. - items: 500 products per step (
product_id > cursor), tracked products only (tracking != D, global inventory tracking on, Multi-Vendor common products withcompany_id = 0skipped). Costs (Costs::resolve()), warehouse split, sales metrics, reorder (Calc), stockout open/close. - finish: removes rows of products deleted or untracked since, ABC classes (
Calc::abc()), daily totals and groups, retention.
A MySQL named lock (GET_LOCK) prevents parallel runs. Re-running the same day replaces the day’s rows. Report pages only read ?:kv_ia_* (plus product, category and company names of the rows on screen).
Entry points: cron kv_inventory_analytics.cron (console or HTTP with the core cron password), admin AJAX kv_inventory_analytics.snapshot (POST, restart=Y starts over).
Calculations (Calc)
Section titled “Calculations (Calc)”value(amount, unit_cost)= max(0, amount) × max(0, cost), rounded to cents.abc(values, a, b): rank by value (ties by id); an item is A while the cumulative share before it is belowa, B belowb, else C; zero values are C.avgDaily(qty, window, age): qty / min(window, age) when the product is younger than the window.daysOfCover(on_hand, avg): on hand / avg; 0 when out of stock; null (infinite) when nothing sells.reorder(avg, on_hand, on_order, lead, safety, review): see Configuration.
Unit tests: php tests/unit_pure.php (no store needed).
Permissions
Section titled “Permissions”schemas/permissions/admin.post.php: View reports for the reports, export and filters; Manage catalog for the snapshot.schemas/permissions/vendor_multivendor.post.php: each vendor mode listed;snapshotandcrondenied. The controller forces the vendor’s company on every query (runtime.company_id).schemas/permissions/trusted_controllers.post.php: only thecronmode, which checks the console or the cron password itself.
Hooks and templates
Section titled “Hooks and templates”- Controller
index.post.phpassigns the dashboard card data; templateshooks/index/simple_dashboard_content.pre.tpl(default dashboard) andhooks/index/products_statistic.post.tpl(classic dashboard). - No storefront templates, no storefront hooks.
Licence
Section titled “Licence”License\Client::isActive() gates reports, export, the dashboard card and snapshots (Config::isOn()). Without a licence the pages show a switched-off panel; data is kept.