# Tailor Shop Management System – Phase 1 Setup

Project path: `C:\Users\manus\Voters Rights Foundation\tailor`

## Requirements

- PHP 8.2+ (8.3+ recommended)
- Composer
- Node.js 18+ and npm
- MySQL 8+

## 1. Install PHP dependencies

```bash
cd "C:\Users\manus\Voters Rights Foundation\tailor"
composer install
```

If your PHP is below 8.2, use:

```bash
composer install --ignore-platform-reqs
```

(Application code targets PHP 8.3+; run on 8.2+ when possible.)

## 2. Install Laravel Breeze (Blade + Tailwind + Alpine)

```bash
php artisan breeze:install blade
```

When prompted, choose **Blade** and the default options. This adds login, register, password reset, and profile routes and views.

## 3. Publish Spatie Laravel Permission

```bash
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider"
```

This publishes the config file and migrations for roles and permissions.

## 4. Environment and database

Copy the example env and set your DB credentials:

```bash
copy .env.example .env
php artisan key:generate
```

Edit `.env` and set:

- `DB_CONNECTION=mysql`
- `DB_DATABASE=tailor_shop` (or your database name)
- `DB_USERNAME=...`
- `DB_PASSWORD=...`

Create the database (e.g. in MySQL: `CREATE DATABASE tailor_shop;`), then run migrations:

```bash
php artisan migrate
```

## 5. Seed roles, permissions, and Super Admin

```bash
php artisan db:seed
```

This creates:

- All roles: Super Admin, Shop Owner, Branch Manager, Receptionist, Tailor, Delivery Staff, Accountant, Customer
- Permissions for: user management, branch management, customer/measurement/order/trial/delivery management, billing, payments, expense management, inventory, reports, settings
- A **Super Admin** user: `admin@tailorshop.com` / `password`

## 6. Merge admin routes into `routes/web.php`

After Breeze install, Breeze overwrites `routes/web.php`. Restore the dashboard and admin routes by replacing the contents of `routes/web.php` with:

```php
<?php

use App\Http\Controllers\BranchController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\UserController;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    if (Auth::check()) {
        return redirect()->route('dashboard');
    }
    return view('welcome');
});

require __DIR__.'/auth.php';

Route::middleware(['auth'])->group(function () {
    Route::get('/dashboard', DashboardController::class)->name('dashboard');
    Route::resource('branches', BranchController::class);
    Route::resource('users', UserController::class);
});
```

(Breeze’s `auth.php` already defines the `logout` route.)

## 7. Storage link (profile images)

```bash
php artisan storage:link
```

## 8. Frontend assets

```bash
npm install
npm run dev
```

For production:

```bash
npm run build
```

## 9. Run the app

```bash
php artisan serve
```

Visit `http://localhost:8000`, register or log in as `admin@tailorshop.com` / `password`, then open the Dashboard. From there you can manage Branches and Users (with roles and branch assignment).

## Roles and branch isolation

- **Super Admin** and **Shop Owner** can see and manage all branches and users.
- **Branch Manager** and other branch-level roles only see their own branch (and users in that branch). This is enforced by policies and the `EnsureUserHasBranchAccess` middleware.

## File summary (Phase 1)

- **Migrations:** `database/migrations/2025_03_14_000001_create_branches_table.php`, `2025_03_14_000002_add_branch_and_profile_to_users_table.php` (+ Spatie’s)
- **Models:** `app/Models/Branch.php`, `app/Models/User.php` (HasRoles, branch, scopes)
- **Policies:** `app/Policies/BranchPolicy.php`, `app/Policies/UserPolicy.php`
- **Middleware:** `app/Http/Middleware/EnsureUserHasBranchAccess.php`
- **Controllers:** `DashboardController`, `BranchController`, `UserController`
- **Form requests:** `StoreBranchRequest`, `UpdateBranchRequest`, `StoreUserRequest`, `UpdateUserRequest`
- **Seeders:** `database/seeders/RolePermissionSeeder.php`, `DatabaseSeeder.php`
- **Views:** `resources/views/layouts/admin.blade.php`, `layouts/partials/sidebar.blade.php`, `layouts/partials/navbar.blade.php`, `dashboard.blade.php`, `branches/*`, `users/*`
- **Routes:** `routes/web.php` (and Breeze’s `routes/auth.php` after install)
