# Ecofina GST Billing

<p align="center">
  <img src="Reference/logo.png" alt="Ecofina Logo" width="200" />
</p>

Node.js + MySQL/SQLite GST billing web application for Ecofina tissue paper business.

## Features

- Secure admin login with bcrypt password hashing
- Dashboard with bill, amount, GST, and monthly summaries
- Application settings for business details, GST rates, invoice number series, logo, signature, and seal
- GST bill creation for Soft, Semi Soft, and Hard tissue paper types
- Automatic CGST/SGST/IGST calculation based on seller and buyer state codes
- Dynamic GST invoice print/PDF template based on the provided references
- Billing history with filters
- Invoice cancellation without deletion
- Invoice, GST, and HSN CSV reports for a selected period
- Dual Database Support: Run effortlessly with **SQLite** (local/easy setup) or **MySQL** (production).

## Screenshots

<details>
<summary><strong>View Bill Sample</strong></summary>

![Bill Sample](Reference/Bill%20sample.png)

</details>

## Suggested Invoice Number Format

Default format:

```text
EF/2026-27/0001
```

You can change prefix, financial year, padding, and next invoice number from Settings.

## Local Setup

1. Install dependencies:

```bash
npm install
```

2. Copy environment file:

```bash
copy .env.example .env
```

3. Configure Database (`.env`):

- **For SQLite (Easiest)**: Set `DB_CLIENT=sqlite` in `.env`.
- **For MySQL**: Provide `DB_HOST`, `DB_USER`, `DB_PASSWORD`, and `DB_NAME`.

4. Import database schema and seed (MySQL only - SQLite does this automatically):

```bash
mysql -u root -p < database/schema.sql
mysql -u root -p ecofina_billing < database/seed.sql
```

5. Create or update admin login:

```bash
node scripts/create-admin.js admin@ecofina.local Admin@12345 Administrator
```

6. Start the app:

```bash
npm start
```

7. Open:

```text
http://localhost:3000
```

Default login after running the admin script:

```text
Email: admin@ecofina.local
Password: Admin@12345
```

Change this password immediately after first login.

## Spaceship Shared Hosting Deployment

1. Confirm your Spaceship plan supports Node.js apps and MySQL (or use SQLite).
2. Create a MySQL database and user from hosting control panel (if using MySQL).
3. Import `database/schema.sql` and `database/seed.sql` (for MySQL).
4. Upload the project files.
5. Install dependencies from the hosting terminal or Node.js app panel.
6. Configure environment variables using `.env` values (`DB_CLIENT=mysql` or `sqlite`).
7. Set startup file to `server.js`.
8. Run the admin creation script once if terminal access is available.
9. Ensure `public/uploads` and `database` directories are writable for uploads and SQLite files.

## GST Logic

- Same state code as seller: CGST + SGST
- Different state code: IGST
- Kerala seller state code defaults to `32`
- GST percentages are configured in Settings

## Important Notes

- Browser print is used for PDF download for better shared-hosting compatibility.
- Bills are cancelled instead of deleted to preserve accounting history.
- Always take database backups before hosting migration or version updates.
