=== HostKhata – Hosting Billing & Client Management ===
Contributors: hmbashar
Tags: billing, invoices, hosting, clients, orders
Requires at least: 6.0
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 0.1.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Billing and client management for hosting companies: orders, invoices, payments, renewal reminders and a customer portal. No server automation.

== Description ==

HostKhata helps hosting companies and resellers run the business side of hosting from WordPress:

* Customers and client management
* Hosting packages and domain products
* Orders with a manual fulfilment queue
* Invoices, payments and recurring billing
* Renewal reminders for invoices, domains and hosting
* Email notifications and customer notices
* A modern customer portal

HostKhata never connects to a server, control panel or domain registrar. You create accounts yourself and record them in HostKhata.

== Installation ==

1. Upload the `hostkhata` folder to `/wp-content/plugins/`, or install the plugin from the Plugins screen.
2. Activate the plugin through the Plugins screen.
3. Open **HostKhata** in the admin menu.

== Frequently Asked Questions ==

= How can customers register themselves? =

Add the shortcode `[hostkhata_register]` to a page. Registration can be switched off, or set to need your approval, under HostKhata → Settings → Portal. You can change the form by copying `templates/portal/register-form.php` to `yourtheme/hostkhata/portal/register-form.php`.

= How do I show my packages on a page? =

Add the shortcode `[hostkhata_products]` to a page. Use `view="table"` for a comparison table, `group="slug"` to show one group, `type="domain"` for domain prices and `columns="2"` for the number of columns. Choose the order page under HostKhata → Settings → Portal so the Order now button works.

= How do customers place an order? =

Add the shortcode `[hostkhata_order product="your-package-slug"]` to a page, or link to that page with `?product=your-package-slug`. Customers must be logged in. The order is saved as pending and appears under HostKhata → Orders. You can change the form by copying the files in `templates/portal/order-*.php` to `yourtheme/hostkhata/portal/`.

= How do I record a payment? =

Open HostKhata → Invoices, choose the invoice and click "Record payment". HostKhata does not collect money or connect to a payment gateway; you write down what the customer paid (cash, bank transfer, bKash, Nagad and so on). When an invoice is paid in full its order moves to the setup queue.

= Can customers see or print their invoice? =

Admins can print any invoice from the invoice screen. To let customers open an invoice by a secret link, switch on "Invoice public links" under HostKhata → Settings.

= Which emails does HostKhata send? =

Order received, account ready, invoice issued, payment received, refunds, invoice reminders and overdue notices, domain and hosting renewal reminders, and notices you choose to email. Edit or switch off any of them under HostKhata → Emails & notices. Emails are queued and sent by WP-Cron every few minutes; any SMTP plugin that handles `wp_mail()` works. Passwords are never sent by email.

= How do reminders work? =

Under HostKhata → Reminders each rule says, for example, "3 days before an invoice is due, send the invoice reminder". Each rule sends one email per invoice, domain or hosting record. You can mute a customer from their profile and set quiet hours in Settings.

= Can I edit or delete an invoice? =

Yes, while it is safe to. A draft can be changed and deleted freely. An issued invoice with no payment can have its lines, due date and notes changed, and can be deleted. Once a payment or credit is on it, only the due date and notes can change, and it can be cancelled after refunds. Paid invoices are kept for your records.

= What does the printable invoice look like? =

A clean A4 page with your logo, company details, tax ID, a PAID / UNPAID stamp and watermark, the customer's details, the items, totals, transactions and your payment instructions. Use the Print / PDF button and choose "Save as PDF". Add your logo, address and tax ID under HostKhata → Settings.

= Can I export my data or import customers? =

Yes. Under HostKhata → Reports (and on the Customers screen) you can download customers, invoices and payments as CSV files that open in Excel or Google Sheets. On the Customers screen, Import CSV adds many customers at once; it checks every row first and shows what is wrong before anything is saved. Imported customers get no email and can use "lost password" to choose a password.

= How do customers log in and see their account? =

Add the shortcode `[hostkhata_portal]` to a page and choose that page as the customer portal page under HostKhata → Settings → Portal. Customers see their orders, hosting, domains and invoices, can print invoices, tell you about a payment, send requests and change their details. A customer only ever sees their own records.

= How do I confirm a payment a customer reported? =

Open the invoice under HostKhata → Invoices. A payment the customer reported shows "Confirm payment" and "Reject". The invoice only changes when you confirm.

= Are renewals invoiced automatically? =

Yes. Every day HostKhata invoices hosting and domains that fall due within the number of days you set under Settings → Invoices, once per renewal period. When the invoice is paid, the due date or expiry moves forward. See HostKhata → Renewals for what is coming up and whether WP-Cron is running.

= Does HostKhata suspend accounts? =

No. "Suspended" and "expired" are only labels in HostKhata, applied after the grace period if you switch that on. You suspend the real account in your own control panel.

= Can I charge a late fee? =

Yes: a fixed amount or a percentage, added once to an invoice that is unpaid after the grace period.

= Can I upgrade or downgrade a hosting plan? =

Yes. Open the hosting record and choose "Change plan". The rest of the period is prorated into an invoice (upgrade) or customer credit (downgrade).

= Can an existing WordPress user, such as my own admin account, be a customer? =

Yes. Under HostKhata → Customers choose "Add customer" and then "Existing WordPress user". The user keeps their login, email and roles; HostKhata only adds the customer role. To move a customer to a different WordPress user, open the customer, choose Edit and then "Link to a different WordPress user". Orders and invoices stay with the customer, and the old user is kept.

= Can I delete a customer? =

Yes, if the customer has no orders, invoices, hosting, domains or payments. Otherwise use "Erase personal data": the name, contact details, notes and login are removed, and the billing records stay for your accounts.

= Does HostKhata create hosting accounts automatically? =

No. HostKhata has no server, cPanel or registrar integration. Orders land in a setup queue and you create the account manually.

== Screenshots ==

1. Dashboard: money received, unpaid invoices, what needs your attention and income for the last 12 months.
2. Customers: search, filter, tag and import your clients in one place.
3. Invoices: unpaid, part paid, overdue and paid invoices at a glance.
4. Hosting records: every account you set up, its price and when it renews.
5. Packages: hosting plans and domain prices with billing cycles.
6. Reports: income, invoices, tax and payment methods, with CSV export.

== Source code ==

The admin screens are a React app. The compiled files in `assets/build/` are generated from the readable source that ships inside this plugin: the `assets/src/` folder, together with `package.json` and `webpack.config.js`. To build it yourself, run `npm install` and then `npm run build` in the plugin folder.

== Privacy ==

HostKhata stores your customers' names, email addresses, phone numbers, addresses, orders, invoices and payment records in your own WordPress database. It supports the WordPress personal data export and erase tools. Nothing is sent to HostKhata or any third party.

== External services ==

HostKhata does not connect to any external service. It makes no requests to third-party servers; customer data, orders, invoices and payment records stay in your own WordPress database.

== Trademarks ==

"HostKhata" is an original name ("khata" means ledger in Bengali). The plugin does not use any other company's name or logo.

== Changelog ==

= 0.1.1 =
* New: make an existing WordPress user a customer. Customers → Add customer → "Existing WordPress user". The user keeps their login, email and roles.
* New: link a customer to a different WordPress user from the customer's edit screen. Orders, invoices and other records stay with the customer.
* Improved: the "email already exists" message on a customer now points to the new link option.

= 0.1.0 =
* First public release.
* Core: database tables, roles and capabilities, settings, REST base and setup wizard.
* Catalogue: groups, hosting packages, domain extensions, add-ons, prices per billing cycle, order-form questions, tax rates, coupons and the `[hostkhata_products]` listing.
* Dashboard, reports (income, tax, receivables aging, top customers), a Ctrl+K quick search, and CSV export and import.
* Customer portal: orders, hosting, domains, invoices, payment reports you confirm, requests, profile and notices.
* Recurring billing: automatic renewal invoices, late fees, optional suspended and expired labels, plan changes with proration, and a cron health panel.
* Emails: editable templates with preview, a retrying email queue, reminder rules for invoices, domains and hosting, and notices.
* Billing: invoices from orders or by hand, manual payments and refunds, customer credit, overdue tracking and a printable invoice.
* Orders: order statuses, price quotes, stock limits, coupon counting, a setup queue and fulfilment that creates hosting and domain records; hosting and domain lists with CSV import; the `[hostkhata_order]` form.
* Customers: list with search, filters, bulk actions and saved views; customer profile page; notes, contacts and tags; registration form; personal data export and erase.

== Upgrade Notice ==

= 0.1.1 =
Adds the option to use an existing WordPress user as a customer.

= 0.1.0 =
First release.
