# BBB Dashboard (Laravel)

Internal BBB courier dashboard built on Laravel. Migrations were rebuilt from controller logic and seeded data so the app can boot without the legacy database snapshot. Login still mirrors the existing behavior (API-first with a local bypass).

## Setup
- `composer install`
- Copy `.env.example` → `.env`, fill database + API keys.
- `php artisan migrate`
- `php artisan db:seed` (or rerun the `2024_01_02_000011_run_initial_seeder` migration if you already migrated)
- Optional dummy rows: set `SEED_DUMMY_DATA=true` before seeding to load sample customer + consumer key.

## Front-end assets

- The new npm stack uses Laravel Mix (`webpack.mix.js`) to compile `resources/assets/sass/app.scss` via Dart Sass. No Gson/Node-gyp/python 2 dependency remains.
- Run `npm install` once (requires Node >= 16) and `npm run prod` / `npm run dev` to rebuild the CSS bundle.

## Database notes
- New migrations cover: `users`, `warehouses`, `customers`, `consumer_keys`, `consolidates`, `containers`, `waybills` (with soft deletes), `baby_parcels` (with soft deletes), `shippings` (with soft deletes), `manifest_waybills`, `in_bundle_message_q_waybills`.
- `InitialCoreSeeder` seeds HQ/HUB warehouses and two admin users; password comes from `SEED_DEFAULT_PASSWORD` (defaults to `password`).
- Seeding is also wired into `2024_01_02_000011_run_initial_seeder` so fresh migrations can auto-load base data.

## Auth & login
- Primary flow hits external APIs: `API_PATH` (`/auth/login`, `/api/v2/courier/users`) and `COURIER_API_MATRIX` (`/api/auth/login`).
- Offline/dev shortcut: set `LOCAL_AUTH=true` to authenticate against the local `users` table with the seeded credentials.
- `DEPLOPYMENT_PLATFORM` toggles login UX and customer-only flow (`STATION` vs `CUSTOMER`).

## Status checklist
- [x] Rebuilt core migrations with indexes/soft deletes where present in controllers.
- [x] Base seed data for warehouses + admin users; optional dummy customer/consumer key behind `SEED_DUMMY_DATA`.
- [x] Local-auth fallback (`LOCAL_AUTH`) for environments without API access.
- [ ] Remote login requires live `API_PATH` and `COURIER_API_MATRIX` endpoints/tokens — not testable or fixable without the third-party services.
- [ ] Shipment/waybill flows rely on external APIs (`API_PATH`, `COURIER_API_MATRIX`, `RPC_API_PATH`, `MESSAGE_API_PATH`, `BILLING_API_PATH`, `DASHBOARD_API_PATH`); functionality will stay blocked until those services respond.
- [ ] SMS and billing hooks depend on provided tokens (`MESSAGE_API_PATH`, `BILLING_API_TOKEN`); no local replacement available.

## Docker

The root `Dockerfile` builds a PHP/FPM image with the Laravel app, production dependencies, and the compiled Laravel Mix assets.

### Build
- Copy `.env.example` to `.env` and update the credentials you need.
- Run `docker build -t bbb-dashboard .` to produce an image tagged `bbb-dashboard`.

### Run
- Mount the storage dirs so `php-fpm` can write logs/cache:  
  `docker run --rm -e APP_ENV=production -v "$(pwd)/storage:/var/www/html/storage" -v "$(pwd)/bootstrap/cache:/var/www/html/bootstrap/cache" -p 9000:9000 bbb-dashboard`
- This container exposes port `9000`, so pair it with a web server (Nginx/Traefik) that proxies PHP requests to the socket/port.

## CI/CD (Drone)

The included `.drone.yml` runs composer + npm asset builds, then spins up PHP 7.2 containers (with the `gd`, `zip`, and `pdo_sqlite` extensions enabled) to run migrations against a temporary SQLite database before pushing the Docker image. Because Debian Buster is archived, both PHP steps rewrite `/etc/apt/sources.list` to `archive.debian.org` and disable the release-date check so the packages for `php:7.2-cli` stay installable.

Set the following secrets so the Docker step can publish:

- `DOCKER_REGISTRY` (e.g., `index.docker.io`)
- `DOCKER_IMAGE` (the repository name, e.g., `your-org/bbb-dashboard`)
- `DOCKER_USERNAME` / `DOCKER_PASSWORD`

The pipeline tags the image with both `${DRONE_BUILD_NUMBER}` and `latest`.
