# Invoice Printing + Company Settings — Install Guide

This package adds printable **Invoice**, **Order** and **Sales Return** documents,
applies the same company letterhead to all PDF reports, and adds a
**Settings → Company Profile** screen where the company name, logo, address,
email and mobile numbers can be changed at any time.

All code, comments and UI labels are in English.

---

## 1. Copy the files

Merge the folders in this package into the project root. Files marked
**(replaces)** overwrite an existing file — back them up first if needed.

### New files

```
app/Models/Setting.php
app/Support/NumberToWords.php
app/Http/Controllers/Admin/PrintController.php
app/Http/Controllers/Admin/SettingController.php
database/migrations/2026_07_27_100001_create_settings_table.php
resources/views/print/layout.blade.php
resources/views/print/invoice.blade.php
resources/views/print/order.blade.php
resources/views/print/sales-return.blade.php
resources/views/admin/settings/company.blade.php
```

### Modified files (replaces)

```
routes/web.php
app/Providers/AppServiceProvider.php
resources/views/layouts/app.blade.php
resources/views/reports/pdf/layout.blade.php
resources/views/admin/orders/show.blade.php
resources/views/admin/invoices/index.blade.php
resources/views/admin/sales-returns/index.blade.php
```

## 2. Run the commands

```bash
php artisan migrate
php artisan storage:link      # required, otherwise the logo will not display
php artisan optimize:clear
```

`storage:link` only needs to be run once per installation.

## 3. Set the company profile

Log in as an admin and open **Setup → Company Profile** in the sidebar
(requires the `settings.manage` permission).

| Field | Where it appears |
|---|---|
| Company Name | Invoice/report heading, sidebar brand, browser tab title |
| Tagline | Line under the company name |
| Address | Letterhead |
| Mobile / Phone | Letterhead, prefixed with `Cell:` |
| Email | Letterhead, prefixed with `Email:` |
| Website | Stored for future use |
| Currency Label | The "Amount in Words" line, e.g. `Taka` |
| Logo | Top-left of every document, and the sidebar |
| Notes / Terms | Printed under the `Note:` heading in the footer |
| Closing Line | The bold line at the very bottom |

Defaults ship with the ACTIVE HEALTH LTD. details, so documents look correct
before anything is saved.

---

## Routes added

| Route name | URL | Purpose |
|---|---|---|
| `print.order` | `/print/orders/{order}` | Order document |
| `print.invoice` | `/print/invoices/{invoice}` | Invoice document |
| `print.sales-return` | `/print/sales-returns/{salesReturn}` | Sales return document |
| `settings.company` | `/settings/company` | Company profile form |
| `settings.company.update` | `PUT /settings/company` | Save company profile |

### Query strings

- `?pdf=1` — stream the document as a PDF instead of an HTML page
  (e.g. `/print/invoices/12?pdf=1`)
- `?auto=1` — open the browser print dialog automatically on load,
  useful for a one-click print button

The print pages carry **Back**, **Download PDF** and **Print** buttons, all of
which are hidden when the page is actually printed.

### Permissions

Print routes sit inside the existing `permission:order.view` group and the
settings routes inside `permission:settings.manage`. Move them to a different
group if a different access rule is required.

---

## Notes

- **Logo in PDFs.** DomPDF cannot reliably fetch a logo over HTTP, so
  `Setting::logoDataUri()` embeds it as base64 instead. HTML print pages use the
  normal storage URL. Both are handled automatically.
- **Report headers.** `resources/views/reports/pdf/layout.blade.php` was
  restyled to use the company letterhead. The eight individual report views
  (sales, stock, expiry, due, collection, dcr, attendance) needed no changes,
  because the new stylesheet targets plain `<table>` markup.
- **Caching.** Settings are cached forever and the cache is flushed
  automatically whenever a value is saved, so there is no stale-data risk.
- **Amount in words** uses the international scale
  (thousand / million / billion). If the lakh–crore scale is preferred,
  `App\Support\NumberToWords::convert()` is the only method that needs editing.
