INVOICE SYSTEM - PHP + MySQL (cPanel / phpMyAdmin version)
==========================================================
Works on normal cPanel hosting: PHP 7.4 or newer + MySQL/MariaDB. No Node.js needed.

FILES
  web/            <- upload everything inside this folder to your website
  database.sql    <- optional: import in phpMyAdmin (do NOT upload it to the website)

STEP 1 - Create the database (cPanel)
  cPanel > "MySQL Database Wizard":
    a) create a database      (cPanel adds a prefix, e.g.  myuser_invoices)
    b) create a database user (e.g.  myuser_invuser) with a strong password
    c) give the user ALL PRIVILEGES
  Write down the 3 FULL names/passwords exactly as cPanel shows them.

STEP 2 - Create the tables in phpMyAdmin (optional but recommended)
  cPanel > phpMyAdmin > click your database on the left > "Import" tab >
  choose database.sql > "Go".  (install.php in Step 5 can also create the tables for you.)

STEP 3 - Upload the system
  cPanel > File Manager > public_html (or a sub-folder such as public_html/invoices)
  > Upload the contents of the "web" folder (index.html, app.js, api.php, config.php, install.php).

STEP 4 - Edit config.php (File Manager > right-click > Edit)
  DB_NAME = your full database name
  DB_USER = your full database user name
  DB_PASS = that user's password
  COOKIE_SECURE = true   (only if your site opens with https://)

STEP 5 - Run the installer once
  Open  https://yourdomain.com/invoices/install.php  in your browser.
  It shows a checklist (PHP version, database connection, tables). Fix any red line it shows.
  Then type the admin username/password and the first company name > Install.

STEP 6 - DELETE install.php from the server (File Manager). Important for security.

STEP 7 - Open https://yourdomain.com/invoices/ and log in.

SELF-REGISTRATION (controlled in config.php)
  ALLOW_REGISTER     true  = a "New here? Create an account" link appears on the login page
                     false = no link, and the server refuses registrations
  REGISTER_APPROVAL  true  = a new account stays "Pending" until an admin approves it
                     false = the account is active at once
  REGISTER_CODE      optional secret code people must type to register ('' = none)
  A self-registered user is always a normal "user" and sees NO company until an admin assigns one:
  Control Panel > Users > click the username > tick the company > "Add / update user"
  (leave the password blank to keep it). Pending users are approved with the "Approve" button.
  Registration is limited to 3 attempts per computer per 10 minutes.

  ALREADY INSTALLED? Upload the new files, add the 3 new lines to YOUR config.php (copy them from the
  new config.php), upload install.php, open it once (it adds the two new user columns), then delete it.

LOGIN PAGE
  - Company picker, show/hide password, Caps-Lock warning, "remember my username and company"
  - Locks sign-in for 10 minutes after 10 wrong passwords from the same computer
  - Logs out automatically after 30 minutes without activity, and when the session expires

WHERE IS THE DATA? (phpMyAdmin > your database)
  companies, users (passwords are stored scrambled), user_companies, invoices, login_fails
  Backup: Control Panel > "Download database backup" (an .sql file), or phpMyAdmin > Export.
  Restore: phpMyAdmin > Import that .sql file.

TROUBLESHOOTING
  - "Create an account" link is not on the login page: (1) your config.php on the server must contain the
    3 lines ALLOW_REGISTER / REGISTER_APPROVAL / REGISTER_CODE (an old config.php without them keeps
    registration OFF); (2) open  api.php?p=/config/public  - it must show  {"register":true,...};
    (3) press Ctrl+F5 to clear the cached page; (4) make sure api.php, index.html and app.js are all the new files.
  - Page loads but login says "Cannot connect to the database": check the 3 lines in config.php.
  - Quick test: open  api.php?p=/companies/public  - you should see  [{"id":1,"name":"Company 1"}].
  - "Server error": cPanel > Select PHP Version > make sure PHP is 7.4+ and the extension pdo_mysql is ticked.
  - Lost the admin password: phpMyAdmin > table "users" > delete the admin row, upload install.php again,
    run it and create a new admin, then delete install.php.
  - Excel / PDF export needs the PC to have internet (libraries load from cdnjs).
