# Solar Savings Calculator

This is a Laravel-based solar savings and recommendation system designed to help Australian homeowners estimate the benefits of installing solar panel systems.

## Important Note About Routing

During development, it was discovered that route closures defined in `routes/web.php` are not executed when handling HTTP requests in this specific Laravel installation, despite working correctly for Artisan commands. This appears to be an environment-specific issue.

As a workaround, the core functionality has been implemented as Artisan commands that can be run from the command line. These commands implement the solar savings calculation, system comparison, and recommendation functionality.

## Installation

1. Install dependencies:
   ```bash
   composer install
   npm install
   ```

2. Copy the example environment file and configure it:
   ```bash
   cp .env.example .env
   ```
   Edit the `.env` file to configure your database connection and other settings.

3. Generate the application key:
   ```bash
   php artisan key:generate
   ```

4. Run database migrations:
   ```bash
   php artisan migrate
   ```

## Usage

The solar savings functionality is available through the following Artisan commands:

### 1. Calculate Solar Savings

Calculate savings for a specific system configuration:

```bash
php artisan solar:calculate \
    --bill=200 \
    --location="Sydney" \
    --has-battery \
    --system-type="solar-with-battery" \
    --bill-frequency=quarterly \
    --usage-pattern=balanced
```

**Options:**
- `--bill`: Average electricity bill (required)
- `--location`: Location or postcode (required)
- `--has-battery`: Whether the property has a battery (flag)
- `--system-type`: Type of system (solar-only, solar-with-battery, battery-retrofit)
- `--bill-frequency`: Frequency of bill (quarterly, monthly, annual)
- `--usage-pattern`: Usage pattern (daytime, evening, balanced, custom)

### 2. Compare Solar Systems

Compare different system types for the same property:

```bash
php artisan solar:compare \
    --bill=300 \
    --location="Melbourne"
```

**Options:**
- `--bill`: Average electricity bill (required)
- `--location`: Location or postcode (required)

### 3. Recommend Solar System

Get a recommended system based on property characteristics and constraints:

```bash
php artisan solar:recommend \
    --bill=250 \
    --location="Sydney" \
    --has-battery \
    --roof-size=40 \
    --budget=15000
```

**Options:**
- `--bill`: Average electricity bill (required)
- `--location`: Location or postcode (required)
- `--has-battery`: Whether the property already has a battery (flag)
- `--roof-size`: Available roof size in square meters (optional)
- `--budget`: Maximum budget in AUD (optional)

## Example Output

```
Solar savings calculation started.

Input Parameters:
  Bill: $200.00 (quarterly)
  Location: Sydney
  Has Battery: yes
  System Type: Solar Panels and Battery
  Usage Pattern: balanced

Results:
  Estimated annual electricity bill: $800.00
  Estimated annual savings after solar: $600.00
  Estimated system cost: $11,616.00
  Estimated payback period: 19.4 years

Calculation completed.
```

## Extending the System

The calculation logic is encapsulated in the Artisan commands located in:
- `app/Console/Commands/CalculateSolarSavings.php`
- `app/Console/Commands/CompareSolarSystems.php`
- `app/Console/Commands/RecommendSolarSystem.php`

To modify the calculation algorithms or assumptions, edit the relevant methods in these files.

## Database

The system uses a SQLite database by default (database/database.sqlite). Database migrations are available but not currently used by the core calculation logic, which is implemented entirely in the Artisan commands.

## Configuration

Various aspects of the calculation can be adjusted by modifying the methods in the Artisan commands:
- System costs per watt
- Savings percentages by system type
- Usage pattern adjustments
- Location cost adjustments
- Rebate and incentive assumptions

## Limitations

Due to the routing issue described above, a traditional web interface cannot be implemented using standard Laravel routes in this environment. The core functionality is available exclusively through the Artisan command-line interface.

For a production web interface, this issue would need to be investigated and resolved, potentially by:
1. Identifying and fixing the root cause of the route execution failure
2. Implementing the web interface using a different approach (such as Inertia.js or a separate SPA)
3. Using the Artisan commands as backend services called via AJAX or API endpoints

## Requirements

- PHP 8.5+
- Composer
- Node.js & npm (for frontend assets)
- SQLite3 (or configure alternative database in .env)

## License

This project is proprietary and confidential.