High-performance WebAssembly library for electrical cable inventory analysis and management. Processes stock data from Tally ERP to provide movement analytics, reorder recommendations, cut-length optimization, and wire grid calculations.
Calculates comprehensive inventory metrics including:
- Multi-period sales analysis (1/3/6/12 months)
- Time-weighted average inventory valuation
- ROI accounting for cost of capital and credit periods
- Turnover ratios and days inventory
- Gross margin and absolute margin calculations
- Sales velocity tracking
Identifies items requiring restocking based on:
- Configurable threshold levels
- Historical sales patterns
- Current stock quantities
Analyzes cable inventory to find optimal cutting opportunities from available stock batches.
Generates structured grid representations of wire inventory for visualization and reporting.
Build the WASM package:
wasm-pack build --target web --releaseThis generates the following artifacts in pkg/:
tally_wasm_core.js- JavaScript module with type bindingstally_wasm_core_bg.wasm- Compiled WebAssembly binarytally_wasm_core.d.ts- TypeScript definitions
Copy these files to your web application's static directory for use.
import init, {
get_movement_analysis,
find_reorder_items,
find_cut_lengths,
get_wire_grid
} from './tally_wasm_core.js';
await init();
// Analyze stock movement
const analysis = get_movement_analysis(
stockData.items, // Stock items with voucher history
6, // Period in months
'all', // Category filter: 'all', 'wires', 'armoured', 'flexible'
8.5 // Annual interest rate (%)
);
// Find items to reorder
const reorderList = find_reorder_items(stockData.items);
// Optimize cut lengths
const cutOpportunities = find_cut_lengths(stockData.items, targetLength);
// Generate wire grid
const wireGrid = get_wire_grid(stockData.items);The movement analysis algorithm implements a 6-step process:
- Sales Analysis: Aggregates sales amounts and quantities across multiple time periods
- Pricing: Computes weighted average purchase and sale prices from transaction data
- Margin Calculation: GM% = (Sell - Buy) / Buy × 100
- Inventory Tracking: Time-weighted average using daily closing balances
- ROI Calculation: (Gross Margin - Cost of Capital) / Avg Inventory × 100
- Accounts for 3-month credit period
- Returns infinity for zero-inventory (back-to-back) items
- Turnover Metrics: T/O Ratio = Sales Value / Avg Inventory
Opening stock is derived from the last voucher before the analysis period, or reverse-calculated from the first voucher within the period (Opening = Closing ± Transaction).
This library is used in production for managing electrical cable and wire inventory, integrated with a Tally ERP proxy server. It processes real-time stock voucher data to provide actionable insights for purchasing and inventory management decisions.
- Rust 1.70+
- wasm-pack
# Development build
wasm-pack build --target web --dev
# Production build (optimized for size)
wasm-pack build --target web --releasecargo testcargo doc --no-deps --openMIT License - see LICENSE file for details.
src/
├── lib.rs # Public API exports
├── movement.rs # Movement analysis and ROI calculations
├── reorder.rs # Reorder threshold analysis
├── cut_length.rs # Cut-length optimization
├── wire_grid.rs # Wire grid generation
├── types.rs # Data structures and type definitions
└── utils.rs # Shared utilities and helpers