Skip to content

udayj/tally-wasm-core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tally WASM Core

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.

Features

Movement Analysis

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

Reorder Analysis

Identifies items requiring restocking based on:

  • Configurable threshold levels
  • Historical sales patterns
  • Current stock quantities

Cut-Length Optimization

Analyzes cable inventory to find optimal cutting opportunities from available stock batches.

Wire Grid Display

Generates structured grid representations of wire inventory for visualization and reporting.

Usage

Build

Build the WASM package:

wasm-pack build --target web --release

This generates the following artifacts in pkg/:

  • tally_wasm_core.js - JavaScript module with type bindings
  • tally_wasm_core_bg.wasm - Compiled WebAssembly binary
  • tally_wasm_core.d.ts - TypeScript definitions

Copy these files to your web application's static directory for use.

Integration

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);

Algorithm Overview

The movement analysis algorithm implements a 6-step process:

  1. Sales Analysis: Aggregates sales amounts and quantities across multiple time periods
  2. Pricing: Computes weighted average purchase and sale prices from transaction data
  3. Margin Calculation: GM% = (Sell - Buy) / Buy × 100
  4. Inventory Tracking: Time-weighted average using daily closing balances
  5. 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
  6. 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).

Production Usage

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.

Development

Prerequisites

  • Rust 1.70+
  • wasm-pack

Build

# Development build
wasm-pack build --target web --dev

# Production build (optimized for size)
wasm-pack build --target web --release

Test

cargo test

Documentation

cargo doc --no-deps --open

License

MIT License - see LICENSE file for details.

Project Structure

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

About

Rust based WebAssembly library for electrical cable inventory analysis

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages