# Quick Start Guide

## Installation & Setup

### 1. Run Migrations
```bash
php artisan migrate
```

This creates all required tables including:
- companies
- employees (with fingerprint fields)
- attendances
- attendance_bypasses

### 2. Create Test Data
```bash
php artisan tinker
```

Then run:
```php
// Create a company
$company = App\Models\Company::create([
    'no_company' => 'COMP001',
    'name' => 'Your Company Name',
    'address' => 'Company Address'
]);

// Create an employee
$employee = App\Models\Employee::create([
    'id_company' => $company->id,
    'id_department' => 1,
    'name' => 'Employee Name',
    'email' => 'employee@example.com',
    'phone_number' => '08123456789',
    'is_attendances' => true
]);

echo 'Company: ' . $company->id . ', Employee: ' . $employee->id;
```

### 3. Setup Storage
```bash
php artisan storage:link
```

This creates a symbolic link for public access to:
- Company logos: `/storage/companies/logos/`
- Attendance photos: `/storage/attendances/{employee_id}/`

### 4. Start Development Server
```bash
php artisan serve
```

Server runs at: `http://localhost:8000`

## Access Points

### Web Dashboard
- **URL**: http://localhost:8000
- **Companies**: http://localhost:8000/companies
- **Employees**: http://localhost:8000/employees
- **Attendance**: http://localhost:8000/attendance

### API Endpoints

**Public (Mobile):**
```
POST   /api/public/employee
GET    /api/public/employee?email=user@example.com
POST   /api/public/attendance/register-fingerprint
POST   /api/public/attendance/join
```

**Protected (Admin) - Requires JWT Token:**
```
GET    /api/attendance
GET    /api/attendance/{id}
POST   /api/attendance/bypass
```

## Quick Test

### 1. Get JWT Token
```bash
curl -X POST http://localhost:8000/api/login \
  -H "Content-Type: application/json" \
  -d '{"email":"admin@example.com","password":"password"}'
```

Copy the token from response.

### 2. Test Public API - Register Fingerprint
```bash
curl -X POST http://localhost:8000/api/public/attendance/register-fingerprint \
  -H "Content-Type: application/json" \
  -d '{
    "email": "employee@example.com",
    "fingerprint_data": "YWJjZGVmZ2hpamtsbW5vcA=="
  }'
```

### 3. Test Public API - Check-In
```bash
curl -X POST http://localhost:8000/api/public/attendance/join \
  -F "email=employee@example.com" \
  -F "fingerprint_data=YWJjZGVmZ2hpamtsbW5vcA==" \
  -F "location_latitude=-6.1234" \
  -F "location_longitude=106.5678" \
  -F "type=check_in"
```

### 4. Test Protected API - List Attendances
```bash
curl -X GET "http://localhost:8000/api/attendance" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"
```

### 5. Test Protected API - Bypass Attendance
```bash
curl -X POST http://localhost:8000/api/attendance/bypass \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "id_employee": 1,
    "date": "2025-11-10",
    "type": "full",
    "manual_check_in": "08:00:00",
    "manual_check_out": "17:00:00",
    "reason": "Late registration"
  }'
```

## Common Tasks

### Create Company via Web
1. Go to http://localhost:8000/companies
2. Click "+ Add Company"
3. Fill in details and upload logo
4. Click Save

### Create Employee via Web
1. Go to http://localhost:8000/employees
2. Click "+ Add Employee"
3. Select company from dropdown
4. Fill in other details
5. Click Save

### View Attendance Records
1. Go to http://localhost:8000/attendance
2. Use filters to search:
   - Employee name/email
   - Date range
   - Status
3. Click eye icon to view details
4. Click markers to open location in Google Maps

### Register Employee Fingerprint (Mobile)
1. Call: `GET /api/public/employee?email=user@example.com`
2. If `fingerprint_registered` is false:
   - Call: `POST /api/public/attendance/register-fingerprint` with fingerprint data
3. If true, fingerprint is already registered

### Daily Check-In (Mobile)
1. Call: `POST /api/public/attendance/join` with:
   - email
   - fingerprint_data
   - location_latitude, location_longitude
   - photo (optional)
   - type: 'check_in'

### Daily Check-Out (Mobile)
1. Call: `POST /api/public/attendance/join` with:
   - email
   - fingerprint_data
   - location_latitude, location_longitude
   - photo (optional)
   - type: 'check_out'

## Troubleshooting

### Photos not saving
```bash
# Verify storage link exists
ls -la public/storage

# Recreate if needed
php artisan storage:link
```

### Fingerprint verification always fails
- Check that fingerprint was registered first
- Ensure fingerprint data is base64 encoded
- Default threshold is 85% - can be adjusted in AttendanceController.php

### 401 Unauthorized on protected endpoints
- Verify JWT token is valid
- Check header format: `Authorization: Bearer {token}`
- Token may have expired - get new one via login

### Company logo not uploading
- Check file size (max 5MB)
- Verify file type (JPEG, PNG, GIF, WebP)
- Ensure `storage/` directory is writable

## File Locations

| Feature | Location |
|---------|----------|
| Company logos | `storage/app/public/companies/logos/` |
| Attendance photos | `storage/app/public/attendances/{employee_id}/` |
| API routes | `routes/api.php` |
| Controllers | `app/Http/Controllers/` |
| Models | `app/Models/` |
| Migrations | `database/migrations/` |
| Views | `resources/views/pages/` |

## Documentation

- **IMPLEMENTATION_SUMMARY.md** - Complete feature overview
- **ATTENDANCE_API_GUIDE.md** - API specifications
- **API_TESTING_GUIDE.md** - Detailed testing guide
- **MAPS_GUIDE.md** - Google Maps integration guide

## Support

For issues or questions:
1. Check the relevant documentation file
2. Review API_TESTING_GUIDE.md for endpoint examples
3. Check Laravel logs: `storage/logs/laravel.log`
4. Use `php artisan tinker` for database debugging

## What's Next?

### Ready for Production?
- [ ] Configure proper biometric library (upgrade from Levenshtein)
- [ ] Setup cloud storage for photos (AWS S3, GCP)
- [ ] Add rate limiting to public endpoints
- [ ] Enable HTTPS/SSL
- [ ] Configure email notifications
- [ ] Setup monitoring and alerting
- [ ] Perform security audit
- [ ] Load testing and optimization

### Ready for Mobile Development?
- Use API documentation in ATTENDANCE_API_GUIDE.md
- Follow flow diagram in guide
- Implement fingerprint sensor integration
- Add camera integration for photo capture
- Implement GPS tracking
- Add offline sync capability
