# Degabriele Kitchens CRM — Installation Guide

## Requirements

| Requirement | Version |
|-------------|---------|
| PHP         | 8.2+    |
| Laravel     | 12.x    |
| MySQL       | 8.0+    |
| Node.js     | 18+     |
| Composer    | 2.x     |

---

## Step 1 — Create MySQL Database

Log in to MySQL and create the database:

```sql
CREATE DATABASE degabriele_crm CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
```

---

## Step 2 — Configure Environment

Copy the example env file and edit it:

```bash
cp .env.example .env
```

Update the following in `.env`:

```env
APP_NAME="Degabriele Kitchens CRM"
APP_URL=http://localhost:8000

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=degabriele_crm
DB_USERNAME=root
DB_PASSWORD=your_password
```

---

## Step 3 — Install PHP Dependencies

```bash
composer install
```

---

## Step 4 — Generate App Key

```bash
php artisan key:generate
```

---

## Step 5 — Run Migrations & Seed

```bash
php artisan migrate --seed
```

This creates all tables including:
- `users`, `roles`, `role_permissions`
- `contacts`, `leads`, `crm_jobs`
- `quotes`, `contracts`, `check_measures`, `cm_checklist_items`
- `processing_orders`, `deliveries`, `installations`, `completions`
- `purchase_orders`, `purchase_order_items`, `po_receipts`, `po_receipt_items`
- `stocks`, `stock_movements`, `job_po_allocations`
- `documents`, `activity_logs`, `app_settings`
- Sessions, cache, and queue tables

---

## Step 6 — Install Node & Build Assets

```bash
npm install
npm run build
```

---

## Step 7 — Set Up Storage

```bash
php artisan storage:link
```

---

## Step 8 — Clear Caches

```bash
php artisan config:clear
php artisan route:clear
php artisan view:clear
php artisan cache:clear
```

---

## Step 9 — Run the App

```bash
php artisan serve
```

Visit **http://localhost:8000** and log in with the seeded admin credentials.

---

## Default Admin Login

| Field    | Value              |
|----------|--------------------|
| Email    | admin@example.com  |
| Password | password           |

> Change the password immediately after first login via **Settings → Users**.

---

## Running on Apache / Nginx

- Point the web root to the `public/` directory.
- Ensure `mod_rewrite` (Apache) or `try_files` (Nginx) is configured.
- Set folder permissions: `storage/` and `bootstrap/cache/` must be writable by the web server.

```bash
chmod -R 775 storage bootstrap/cache
chown -R www-data:www-data storage bootstrap/cache
```

---

## Troubleshooting

| Issue | Fix |
|-------|-----|
| `SQLSTATE[HY000]` connection refused | Verify DB_HOST, DB_PORT, DB_USERNAME, DB_PASSWORD in `.env` |
| `Class "Pdo\Mysql" not found` | Ensure PHP 8.2 is active (`php -v`). This project does not require PHP 8.4+. |
| White screen / 500 error | Run `php artisan config:clear` and check `storage/logs/laravel.log` |
| Assets not loading | Run `npm run build` and `php artisan storage:link` |
| Sessions not working | Ensure `SESSION_DRIVER=database` and migrations have run |

---

## Key Settings After Install

Go to **Settings → General** to configure:
- Company name, ABN, phone, address
- Payment terms, deposit percentages
- Check Measure Lead Days (days before delivery = manufacture date)

Go to **Settings → Permissions** to assign module access per role.

Go to **Settings → Users** to create staff accounts and assign roles.
