# ABC YARN HOUSE ERP — Laravel 12 + Tailwind CSS v4 + MySQL

A production-ready, enterprise-grade Enterprise Resource Planning system built with Laravel 12, Eloquent ORM, Blade Components, Tailwind CSS v4, Alpine.js, and ApexCharts.

## 🎯 Features

### Core Modules
- **Dashboard** — Live KPI cards, ApexCharts (monthly purchase/sales, profit, stock movement), AI insights panel
- **Purchase Management** — Create, list, view, edit, delete purchases with dynamic item rows, stock auto-posting
- **Sales Management** — Full sales cycle with item management, live bill calculation
- **Stock Ledger** — Real-time FIFO stock tracking with automatic balance updates
- **Supplier Ledger** — Running balance Dr/Cr ledger per supplier
- **Customer Ledger** — Running balance Dr/Cr ledger per customer
- **Cash & Bank** — Receipt/payment vouchers, cash book, bank book with running balance
- **Daily Transaction Register** — Split-screen daily purchase/sales view
- **Challan Management** — Delivery challan with status tracking
- **Reports** — Purchase, Sales, Profit & Loss, Stock, Cash Book, Bank Book
- **AI Insights** — Low stock alerts, demand prediction, top/slow movers, supplier recommendations
- **Recycle Bin** — Soft-delete with restore and permanent delete
- **Settings & Profile** — System configuration and user management

### Architecture
- **MVC Pattern** — Resource Controllers + Service Layer + Eloquent Models
- **Service Layer** — DashboardService, PurchaseService, SaleService, StockService, LedgerService, AccountService
- **Form Request Validation** — StorePurchaseRequest, StoreSaleRequest, StorePartyRequest, StoreVoucherRequest
- **Eloquent Relationships** — BelongsTo, HasMany, morphTo, Scopes, Accessors
- **Soft Deletes** — Purchase, Sale, Party models support soft delete
- **Auto Numbering** — Voucher numbers auto-generated with year prefix (PUR-2026-0001)
- **Stock Auto-Posting** — StockLedger entries created automatically on purchase/sale

## 🛠️ Tech Stack

| Layer | Technology |
|-------|-----------|
| Framework | Laravel 12 |
| Frontend | Blade Components + Tailwind CSS v4 |
| JavaScript | Alpine.js 3 + Lucide Icons |
| Charts | ApexCharts |
| Database | MySQL |
| ORM | Eloquent |

## 📁 Project Structure

```
abc/
├── app/
│   ├── Http/
│   │   ├── Controllers/
│   │   │   ├── DashboardController.php
│   │   │   ├── PurchaseController.php
│   │   │   ├── SaleController.php
│   │   │   ├── StockController.php
│   │   │   ├── PartyController.php
│   │   │   ├── AccountController.php
│   │   │   ├── ReportController.php
│   │   │   ├── RecycleController.php
│   │   │   ├── ChallanController.php
│   │   │   └── AiController.php
│   │   └── Requests/
│   │       ├── StorePurchaseRequest.php
│   │       ├── StoreSaleRequest.php
│   │       ├── StorePartyRequest.php
│   │       └── StoreVoucherRequest.php
│   ├── Models/
│   │   ├── User.php
│   │   ├── Party.php
│   │   ├── Yarn.php
│   │   ├── Purchase.php
│   │   ├── PurchaseItem.php
│   │   ├── Sale.php
│   │   ├── SaleItem.php
│   │   ├── StockLedger.php
│   │   ├── Account.php
│   │   ├── Voucher.php
│   │   ├── Challan.php
│   │   └── CompanySetting.php
│   ├── Services/
│   │   ├── DashboardService.php
│   │   ├── PurchaseService.php
│   │   ├── SaleService.php
│   │   ├── StockService.php
│   │   ├── LedgerService.php
│   │   └── AccountService.php
│   └── Providers/
│       └── AppServiceProvider.php
├── config/
│   └── erp.php
├── database/
│   ├── migrations/
│   │   ├── 2026_01_01_000001_create_parties_table.php
│   │   ├── 2026_01_01_000002_create_yarns_table.php
│   │   ├── 2026_01_01_000003_create_purchases_table.php
│   │   ├── 2026_01_01_000004_create_purchase_items_table.php
│   │   ├── 2026_01_01_000005_create_sales_table.php
│   │   ├── 2026_01_01_000006_create_sale_items_table.php
│   │   ├── 2026_01_01_000007_create_stock_ledgers_table.php
│   │   ├── 2026_01_01_000008_create_accounts_table.php
│   │   ├── 2026_01_01_000009_create_vouchers_table.php
│   │   ├── 2026_01_01_000010_create_challans_table.php
│   │   └── 2026_01_01_000011_create_company_settings_table.php
│   └── seeders/
│       └── DatabaseSeeder.php
├── resources/views/
│   ├── layouts/app.blade.php
│   ├── components/
│   │   ├── sidebar.blade.php
│   │   ├── navbar.blade.php
│   │   ├── footer.blade.php
│   │   ├── breadcrumb.blade.php
│   │   ├── card.blade.php
│   │   ├── stat-card.blade.php
│   │   ├── table.blade.php
│   │   ├── form-input.blade.php
│   │   ├── button.blade.php
│   │   ├── modal.blade.php
│   │   └── badge.blade.php
│   ├── dashboard/index.blade.php
│   ├── purchase/{create,index,show,edit}.blade.php
│   ├── sales/{create,index,show,edit}.blade.php
│   ├── stock/{index,ledger}.blade.php
│   ├── reports/{purchase,sales,supplier,customer,pl}.blade.php
│   ├── parties/{supplier,customer}.blade.php
│   ├── accounts/index.blade.php
│   ├── daily/register.blade.php
│   ├── challan/{index,create}.blade.php
│   ├── ai/dashboard.blade.php
│   ├── recycle/index.blade.php
│   ├── settings/index.blade.php
│   ├── profile/index.blade.php
│   └── auth/login.blade.php
└── routes/web.php
```

## 🚀 Quick Start

```bash
# 1. Install Laravel dependencies
composer install

# 2. Create .env file
cp .env.example .env
php artisan key:generate

# 3. Configure MySQL in .env
DB_DATABASE=abcyarn
DB_USERNAME=root
DB_PASSWORD=

# 4. Run migrations
php artisan migrate

# 5. Seed initial data (creates users, parties, yarns, accounts + sample transactions)
php artisan db:seed

# 6. Start server
php artisan serve
```

**Default login:** `admin@abcyarnhouse.com` / `password`

## 📊 Database Schema

### Core Entities
- **parties** — Suppliers, customers, or both with credit limits
- **yarns** — Product catalog with reorder levels
- **purchases / purchase_items** — Purchase orders with line items
- **sales / sale_items** — Sales invoices with line items
- **stock_ledgers** — Automatic stock movement tracking
- **accounts** — Cash and bank accounts
- **vouchers** — Receipt/payment/journal entries
- **challans** — Delivery challans

## 🎨 Design System

| Token | Value |
|-------|-------|
| Primary | `#2563eb` (Blue) |
| Font | Inter |
| Border Radius | `rounded-xl` |
| Shadows | Soft, `shadow-soft` |
| Theme | Corporate Blue + Slate + White |
| Dark Mode | Full support via Tailwind `dark:` |

## 🔗 Routes

| URL | Controller |
|-----|-----------|
| `/dashboard` | DashboardController |
| `/purchase/*` | PurchaseController (resource) |
| `/sales/*` | SaleController (resource) |
| `/stock`, `/stock/ledger` | StockController |
| `/suppliers`, `/customers` | PartyController |
| `/cash/*`, `/bank/*` | AccountController |
| `/reports/*` | ReportController |
| `/recycle-bin/*` | RecycleController |
| `/ai/dashboard` | AiController |
| `/challan/*` | ChallanController |

## ✅ Quality Standards

- No mock/hardcoded data — all stats from real Eloquent queries
- Service layer separates business logic from controllers
- Form Request validation for all data entry
- Soft deletes preserve audit trail
- Stock ledger auto-updates on every transaction
- Running balance calculated in real-time for ledgers
- Proper Eloquent relationships with eager loading
- Pagination with query string preservation
- CSRF protection on all POST forms
- Confirmation dialogs on delete actions
