# Notch ERP

A modular ERP system for a marketing &amp; software agency, built with **Laravel 11**,
**Livewire 3**, **Tailwind CSS** and **Alpine.js**. Architecture is modular (Odoo-style):
every feature area is a self-contained module under `/modules` that can be enabled or
disabled from the admin panel.

## Features

### Core
- **Setup wizard** (`/install`) — requirements check → database config → admin account →
  module selection → done. Locks itself after install via `storage/install.lock`.
- **Modular system** — `App\Modules\ModuleManager` discovers modules from `/modules`,
  stores state in the `modules` table, and auto-loads each enabled module's routes,
  views, migrations and permissions through `App\Providers\ModuleServiceProvider`.
- **Multi-role auth** — Super Admin, Admin, Manager, Employee, with a granular
  permission system (`roles`, `permissions`, pivots). Each module registers its own
  permissions. Super Admin bypasses all gates.
- **Dynamic sidebar** — shows only enabled modules; modules self-register nav entries.
- **Global search** across employees, contacts and deals.
- **Notifications** — DB-backed, with a Livewire bell component.
- **Settings** — company info, logo, timezone, currency (EGP), primary color, locale.
- **Audit log** — who did what, when (via the `Auditable` trait + `Audit` helper).
- **Dark mode** toggle and **full RTL (Arabic)** support.

### HR module (`/modules/HR`)
Employees (full profile, photo, documents, emergency contacts, employment status),
Departments (manager, hierarchy, headcount), Positions, Attendance (manual check-in/out,
monthly report, late flagging), Leaves (request → manager approval workflow, balances,
types), Payroll (basic + allowances − deductions, monthly runs, PDF payslips, history).

### CRM module (`/modules/CRM`)
Contacts (companies &amp; individuals, lead/prospect/client/inactive, social links, assigned
rep), Pipeline (drag-and-drop Kanban: New → Qualified → Proposal → Negotiation → Won/Lost,
deal value/probability/close date), Proposals (line items, discount, PDF export, status
workflow), Activities (log calls/meetings/emails, scheduled follow-ups with reminders).

## Tech stack
Laravel 11 · Livewire 3 · Tailwind CSS (CDN) · Alpine.js · DomPDF · MySQL or SQLite.

## Installation

### Easiest — one command

```bash
bash setup.sh
php artisan serve
```

`setup.sh` installs dependencies, creates `.env`, generates the app key, sets up a
zero-config SQLite database, runs all migrations, seeds roles/permissions, installs the
HR &amp; CRM modules and creates the admin account. Then open `http://localhost:8000`.

**Login:** `admin@notch.test` / `password`

### Manual

```bash
composer install
cp .env.example .env          # uses SQLite by default
php artisan key:generate
touch database/database.sqlite
php artisan erp:install --fresh   # migrate + seed + modules + admin user
php artisan serve
```

### Guided web wizard

Prefer to configure MySQL and pick modules through a UI? Skip `erp:install`, set up your
`.env`/key, then visit `http://localhost:8000` — you'll be redirected to the **setup
wizard** (`/install`): requirements check → database → admin account → module selection →
done. It self-locks afterwards via `storage/install.lock`.

> To re-run the wizard or reinstall, delete `storage/install.lock` (and the database).


## Building a new module
See [`docs/MODULE_CONVENTIONS.md`](docs/MODULE_CONVENTIONS.md). In short, create
`/modules/{Name}/` with `module.json`, a provider extending
`App\Modules\BaseModuleServiceProvider`, and the usual `Controllers/`, `Models/`,
`Views/`, `routes/`, `database/migrations/` folders. It is auto-discovered.
