ERP · E-Commerce · Pharmacy · AI

A Full ERP Built
From the Ground Up

A production-grade Enterprise Resource Planning system built entirely from scratch in CodeIgniter & MySQL — handling orders across three sales channels, real-time FIFO inventory, automated FedEx shipping, and natural language AI querying via Google Gemini.

30+
Custom DB Tables
3
Sales Channels
30h+
Saved Weekly
Live
In Production
Live System Architecture
BigCommerce API · Webhook Sync Amazon SP-API Orders · Inventory EPRX Pharmacy Rx Orders · Pets ERP Core CodeIgniter · MySQL 30+ Tables · FIFO LIVE FedEx REST OAuth · Labels Stripe Checkout · Payments Gemini + n8n AI Query Layer
4,800+
Orders Processed
12,000+
Inventory Allocations
30+
MySQL Tables
3
Sales Channels
CodeIgniter 3 MySQL FedEx REST Gemini AI n8n
System Overview

One ERP. Every Channel.
Full Visibility.

Built entirely custom — no off-the-shelf ERP could handle the combination of e-commerce, pharmacy Rx orders, FIFO inventory allocation, and AI-powered querying this business needed.

Multi-Channel Order Management

Orders flow in from BigCommerce, Amazon SP-API, and EPRX Pharmacy — all unified into a single order lifecycle with dual-status tracking and Stripe payment gates.

  • BigCommerce API webhook sync via Bcorders.php
  • Amazon SP-API private developer path
  • EPRX Rx orders with pet & medication assignment
  • Order states: Draft → Confirmed → Shipped/Completed
  • Stripe Checkout payment workflow integration

FIFO Inventory Engine

A custom allocation engine using the FIFO method tracks inventory at the lot and bin level — with five real-time metrics, auto-backorder resolution, and PO-driven receiving.

  • On Hand, Reserved, Available, On Order, Backordered
  • FIFO allocation across warehouse / bin / lot
  • Auto-allocate received stock to open backorders
  • Backorder formula: MAX(0, Reserved − On Hand)
  • Lot expiry tracking per receiving line

Pick → Pack → Ship Pipeline

Full fulfillment from picking list generation (allocation-aware, per warehouse/bin/lot) through multi-box packing to FedEx REST API label generation with OAuth.

  • Allocation-specific pick list PDF generation
  • Packing boxes with item-level assignments
  • FedEx REST OAuth + multi-box label generation
  • Barcode scanning via Picqer library
  • Shipment confirmation closes fulfillment loop
Sales Channels

Three Channels.
One Unified System.

Each sales channel has its own sync controller, but all orders converge into a single order management interface with shared inventory, fulfillment, and reporting.

Draft
Confirmed
Picking
Packing
Shipped
BigCommerce API
Batch-synced via Bcorders.php with mutex locking to prevent MySQL lock timeouts. Orders pulled per cron run, status updates pushed back to BC. Handles products, customers, and order metadata.
Amazon SP-API
Private developer path via Seller Central. Amzorders.php controller mirrors Bcorders.php architecture — pulling Amazon orders, mapping to internal schema, syncing fulfillment status back via SP-API.
EPRX Pharmacy
Rx orders with pet and medication assignment per order line. Case A/B bifurcation logic, Rx status tracking per medication, fax/email automation for vet prescriptions. Integrated into the same order lifecycle.
Stripe Payment Gate
Order status workflow is gated to Stripe Checkout. Payment confirmation triggers order progression. bc_stripe_payments tracks every transaction with full audit history.
PHP · CodeIgniter 3 BigCommerce API Amazon SP-API EPRX API Stripe Checkout MySQL · cron
BigCommerce Bcorders.php sync Amazon Amzorders.php EPRX Pharmacy Rx · Pets · Meds ERP Orders DB bc_orders · MySQL Dual-status tracking ORDER LIFECYCLE Draft Confirmed Shipped Picking Packing Backordered ⚡ Gated by Stripe Checkout
FIFO Inventory Flow
PO Receiving Warehouse · Bin · Lot · Expiry FIFO Allocation Engine bc_inventory_allocations On Hand Physical stock Reserved Allocated to orders Available On Hand − Reserved Backordered MAX(0, Res − OH) On Order Open PO qty
Inventory Engine

FIFO Allocation.
Five Live Metrics.

Every order triggers an allocation against real warehouse stock — tracked at the lot and bin level, with automated backorder resolution when stock arrives from a PO.

On Hand
Physical
Current qty in warehouse across all bins/lots
Reserved
Allocated
Qty locked against confirmed orders
Available
On Hand − Reserved
Stock free to sell right now
On Order
Open POs
Qty on open purchase orders not yet received
Backordered
MAX(0, Reserved − On Hand)
Orders waiting on stock — auto-resolved when PO is received
Key Backorder Formula
Backordered = MAX(0, Reserved − On Hand)
This formula is mathematically correct — it never goes negative, and it accurately reflects how many units are owed to customers that you don't yet have. Auto-allocation runs outside database transactions to avoid query cache isolation race conditions between allocation creation and status updates.
Fulfillment Pipeline

Pick → Pack → Ship.
All in one system.

From the moment an order is confirmed, the system guides warehouse staff through picking (allocation-aware, bin/lot specific), packing into boxes, and generating FedEx shipping labels — all without leaving the ERP.

01
Order Confirmed
Stripe payment verified, inventory allocated
02
Pick List Generated
PDF per allocation — warehouse, bin, lot, qty
03
Items Picked
Barcode scan confirmation via Picqer
04
Packed into Boxes
Multi-box support, item-level assignments
05
FedEx Label Generated
REST API + OAuth, one label per box
06
Order Shipped
Tracking number saved, status updated

Allocation-Aware Picking

Pick lists are generated per allocation record — each list specifies the exact warehouse, bin, and lot the item must be pulled from, matching the FIFO allocation that was created when the order was confirmed. Barcode scanning validates each pick.

bc_inventory_allocations pick_list_pdf Picqer Barcodes Dompdf

Multi-Box Packing

Orders can be packed across multiple boxes — each box is tracked in bc_packing_boxes with item-level assignments in bc_packing_box_items. Box dimensions and weights feed directly into the FedEx shipment request.

bc_packing_boxes bc_packing_box_items Multi-box support

FedEx REST API Integration

Full OAuth 2.0 token management with automatic refresh. Shipment requests include all box dimensions, weights, and service types — returning tracking numbers and label URLs. Shipping API credentials stored per channel for multi-carrier future expansion.

FedEx REST API OAuth 2.0 Multi-box Labels Tracking Numbers

Credential Management

Shipping API credentials are stored per channel in a dedicated table — supporting FedEx, USPS, OnTrac, and UPS. The architecture is ready for multi-carrier expansion without touching fulfillment logic.

FedEx USPS OnTrac UPS ready
AI Integration

Ask the ERP.
In Plain English.

A natural language query interface powered by Google Gemini and n8n lets anyone on the team ask the ERP questions directly — without writing SQL. The AI layer is embedded into the ERP frontend via a webhook.

Google Gemini + n8n
Natural Language → SQL → Results
Questions typed in plain English are converted to SQL queries against the ERP's 30+ table schema. The n8n AI Agent node handles the Gemini API call, runs the query, and returns formatted results to the ERP UI.
Schema-Aware System Prompt
Enforced SQL Guard Rules
The system prompt encodes critical rules — SUM() and LIMIT cannot coexist at the same query level (requires subquery pattern), collation mismatches on joins need COLLATE clauses, and soft-delete fields must be filtered. This prevents Gemini from generating invalid queries.
Frontend Integration
Embedded via n8n Webhook
The query interface lives inside the ERP dashboard. The frontend posts to an n8n webhook, which triggers the AI Agent workflow and streams results back — no separate app or login required.
// Example AI query → SQL (Gemini output)
Q: "Which orders shipped last week had backordered items?"

SELECT o.order_id, o.status, p.product_name
FROM (SELECT order_id, SUM(qty) total
      FROM bc_inventory_allocations
      WHERE flagdel = 'N') sub
JOIN bc_orders o ON o.id = sub.order_id
WHERE o.shipped_date >= DATE_SUB(NOW(), INTERVAL 7 DAY)
Complete Module List

Every Module.
Built from Scratch.

No off-the-shelf plugins or third-party modules — every piece of functionality was designed, architected, and coded to fit the exact business workflow.

Module 01

Subscriptions & Autoship

Cron-driven spawn engine generates recurring orders on schedule. Supports manual spawn, skip-date logic, per-subscription cancellation, and frequency overrides. Each subscription tracks its next billing date.

cronspawn enginebc_subscriptionsskip-date
Module 02

EPRX Pharmacy

Rx orders with per-order-line pet and medication assignment. Rx status tracked per medication line with Case A/B bifurcation logic. Fax/email automation for vet prescriptions with rate-limiting guards.

Rx ordersbc_eprx_order_rxpet medsCase A/B
Module 03

Purchasing & Receiving

PO creation and receiving with per-line warehouse, bin, lot, and expiry capture. Received stock triggers auto-allocation engine to resolve open backorders immediately. Full PO lifecycle with status tracking.

PO lifecyclebin/lot/expiryauto-allocatebackorder resolve
Module 04

Customer Management

Full customer profiles synced from BigCommerce. Tracks order history, subscription status, payment methods, and addresses. Customer-level notes and communication logs for support workflows.

BC syncorder historybc_customersaddress book
Module 05

Supplier & Vendor Catalog

Supplier catalog with per-SKU pricing and lead times. Vendor catalog supports bulk product upload via Excel (SimpleXLSX). Ties purchasing, pricing, and receiving into a unified supplier view.

bc_suppliers_catalogExcel uploadSimpleXLSXSKU pricing
Module 06

Audit, Access & Dashboard

Role-based access control via MY_Controller.php. Full audit/change tracking on critical records. Operations dashboard with period selectors, trend badges, and Chart.js visualizations for orders, revenue, and inventory health.

RBACaudit logChart.jstrend badges
Technology Stack

Chosen for Production Reality

Every tool in the stack was chosen for a reason — reliability, fit, and the ability to build fast without sacrificing correctness. Nothing was added for hype.

Backend & Database
PHP 8 CodeIgniter 3 MySQL 8 Ord_model.php cron jobs Mutex locking
Frontend
Bootstrap 3.3.7 jQuery Chart.js Select2 Toastr ti-* icons
Sales Channel APIs
BigCommerce API Amazon SP-API EPRX API LWA OAuth AWS IAM
Fulfillment & Payments
FedEx REST API OAuth 2.0 Stripe Checkout USPS OnTrac UPS (ready)
AI & Automation
Google Gemini n8n (self-hosted) AI Agent node Webhook
Libraries & Utilities
Dompdf Picqer Barcodes SimpleXLSX TCPDF Soft deletes
Let's Work Together

Need a System Like This
Built for Your Business?

This ERP was built entirely custom to handle a complex, multi-channel, multi-module operation. If your business has outgrown generic tools — let's talk about what a purpose-built system could do for you.