# Miliki Portal

Miliki Portal is a Laravel-based web application for property/project management, plot sales workflows, and post-purchase tracking.

## Tech Stack

- PHP / Laravel 9
- MySQL-compatible database
- Blade templates
- Laravel Mix (Webpack)
- jQuery/DataTables in admin screens

## Prerequisites

- PHP 8.x
- Composer
- Node.js and npm
- MySQL or MariaDB

## Project Setup

1. Install PHP dependencies.

```bash
composer install
```

2. Install frontend dependencies.

```bash
npm install
```

3. Create environment file and generate app key.

```bash
cp .env.example .env
php artisan key:generate
```

4. Configure database credentials in `.env`.

5. Run migrations.

```bash
php artisan migrate
```

6. Build frontend assets.

```bash
npm run dev
```

7. Start the application.

```bash
php artisan serve
```

Optional project bootstrap command used in this codebase:

```bash
php artisan project:reset
```

## Useful Commands

### Backend

```bash
php artisan serve
php artisan migrate
php artisan route:list
php artisan cache:clear
php artisan config:clear
php artisan optimize:clear
```

### Frontend

```bash
npm run dev
npm run watch
npm run prod
```

### Testing

```bash
php artisan test
```

or

```bash
./vendor/bin/phpunit
```

## Plot Purchase Status Management

This project includes two related flows:

1. Plot-level post-purchase updates
2. Master status-step configuration for post-purchase flow

### A) Plot-level updates (existing flow)

- Route (form): `GET /property/updatepostpurchase/{plotid}`
- Route (submit): `POST /property/updatepostpurchase/{plotid}`
- Controller: `PropertyController@updatepostpurchase` and `PropertyController@storepostpurchase_status`

### B) Master status-step configuration (new Superadmin UI)

Superadmin can now manage status steps from the dashboard sidebar:

- Menu: `Plot Purchase`
- Add: `GET/POST /plot-purchase/add`
- View: `GET /plot-purchase/view`
- Edit: `GET/POST /plot-purchase/edit/{id}`

The feature is handled by `CompletedOrderStatusController` and views under `resources/views/superadmin/plotpurchase`.

## Status Population Command (Idempotent)

Default status steps are now populated via command instead of relying only on seeding.

Run:

```bash
php artisan plotpurchase:sync-statuses
```

What it does:

- Inserts default status steps only when missing
- Leaves existing matching steps untouched
- Fills missing slug values for existing rows

Default steps:

- Started
- District Office
- Revenue Authority (TRA) Review
- Ministry Of Lands
- Ready For Signing
- Closed

## Roles and Access

- Plot Purchase status-step management UI is restricted to `superadmin` role.
- Access checks are enforced in controller methods.

## Troubleshooting

1. If classes are not detected after pulling changes:

```bash
composer dump-autoload
```

2. If routes appear stale:

```bash
php artisan route:clear
php artisan optimize:clear
```

3. If frontend changes are not reflected:

```bash
npm run dev
```

4. If permissions or role changes are needed, ensure your user has `superadmin` role before testing admin configuration pages.

## Notes for Deployment

- Run migrations before first boot of new release.
- Run `php artisan plotpurchase:sync-statuses` once after deployment to guarantee baseline status data exists.
- Rebuild assets with production mode:

```bash
npm run prod
```
