=== Kascado Accounts Receivable for WooCommerce ===
Contributors: kascado
Tags: accounts receivable, invoices, payments, wholesale, b2b
Requires at least: 7.0
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.1.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Requires Plugins: woocommerce

Accounts receivable for WooCommerce B2B stores. See who owes you, how much, and how overdue, and record the payments that come in.

== Description ==

**Database requirement:** this plugin stores money in its own tables and relies
on transactions to keep a payment and the invoices it settles consistent with
each other. Those tables must use InnoDB, which is the default on every MySQL
since 5.5 and every MariaDB. On a server configured to default to MyISAM the
tables are created without transaction support and a failure part-way through
recording a payment could leave the entry saved and its allocation missing.


If your store ships before it gets paid, WooCommerce alone cannot tell you what you are owed. An order marked Processing means the goods went out, not that the money came in, and the gap between the two is where a spreadsheet usually appears.

This plugin closes that gap. It watches orders placed through the payment methods you nominate — bank transfer, cheque, cash on delivery, purchase order, anything that defers payment — and records each one as a charge against that customer. When money arrives, you record it, and the balance moves.

**What it does**

* An accounts receivable dashboard: total outstanding, how many customers carry a balance, and how much is overdue including the age of the oldest overdue amount
* A receivables trend chart covering the last six months
* A customer list showing each account's balance, company, email and oldest unpaid date, sortable by balance, name or oldest unpaid date
* Charges created automatically from orders placed with the payment methods you choose
* Payments recorded against a customer with the amount, the date the money actually arrived, the method, a reference such as a cheque number, and a note
* Payments applied automatically to the oldest open charges first, which is how B2B receivables are normally settled
* Credits and write-offs, each requiring a note, and corrections for an entry recorded in error
* Payment terms for the store — Due on Receipt through NET 120 — giving every new charge a due date
* A screen for each customer: their balance, the invoices still open against them, and their full history with a running balance
* Historical import, so orders already in your store can be brought in as charges without duplicating anything — an order that was already refunded arrives as its gross invoice plus each refund as its own dated credit
* Customer balances exported to CSV

**What happens when an order changes**

An order is not a fixed document, and the ledger follows what actually happened to it rather than what it looked like on the day it was placed.

* A refund is recorded as a credit dated the day the refund was issued, not the day the order was placed. Deleting that refund in WooCommerce reverses the credit.
* Cancelling an order withdraws its charge. Any payment already sitting on that charge is released and applied to whatever else the customer owes, rather than disappearing with it.
* Editing an order's total records the difference as its own dated entry — an increase as a charge, a decrease as a credit. The original invoice is left as it was, so the history shows what was billed and when it changed.
* Orders placed in a currency other than your store's base currency are left out rather than converted, and the plugin tells you how many, so an absence is never silent.
* Two payments recorded against the same customer at the same moment cannot interleave: each customer's entries are written under a lock, so a payment and the invoices it settles are always consistent with each other.

**Built for real money**

Amounts are stored and calculated as exact whole units of your currency rather than as decimal fractions, so a balance never drifts by a fraction of a penny and a fully paid charge closes at exactly zero. Your currency's decimal places are respected throughout, including currencies with none such as the Japanese yen and currencies with three such as the Kuwaiti dinar. An amount typed with more precision than your currency allows is reported back to you rather than quietly rounded.

**Works with what you already run**

Requires WooCommerce 11.1 or later. Compatible with High-Performance Order Storage, and every order lookup goes through the WooCommerce API rather than direct database access. Compatible with the Cart and Checkout blocks: an order placed through either checkout is recorded the same way. Any customer role can be treated as a B2B account, including roles created by other B2B plugins, and an optional filter restricts tracking to the roles you nominate.

Your data stays in your database. The plugin makes no external requests of any kind.

A paid add-on, Kascado Accounts Receivable Pro, adds aging reports, automated payment reminders, credit limits and a customer-facing balance page.

== Installation ==

1. Upload the plugin folder to `/wp-content/plugins/` or install it through **Plugins → Add New**.
2. Activate it through the **Plugins** screen.
3. Make sure WooCommerce is installed and active.
4. Go to **Kascado → Accounts Receivable** to see the dashboard.
5. Open the settings and choose which payment methods create a receivable. Instant-payment methods such as card or PayPal should be left unticked — those orders are paid at checkout.

== Frequently Asked Questions ==

= Which orders become receivables? =

Only orders placed with the payment methods you tick in the settings. On activation the plugin pre-selects the common deferred-payment gateways it finds, such as bank transfer, cheque and cash on delivery, and you can change that selection at any time.

= Does an order marked Processing or Completed count as paid? =

No, and deliberately so. Those statuses tell you the order has been handled or shipped, not that the money arrived. A charge is only settled when you record a payment against it.

= How are payments matched to charges? =

Oldest open charge first. A single payment covering several invoices is spread across them in that order, and a charge that is only partly covered keeps its remaining balance. You do not have to nominate an invoice when recording a payment.

= Can I record a payment that is not tied to any order? =

Yes. A payment belongs to the customer, not to an order, so a cheque covering five invoices or a payment received in advance are both recorded the same way.

= Can I correct a mistake? =

The ledger is append-only, so nothing is edited or deleted. Credits, write-offs and corrections are recorded as new dated entries alongside the entry they relate to, each with a note explaining it, which keeps the history intact for audit.

= Does it work with my currency? =

Yes, including currencies with no decimal places and currencies with three. Amounts are stored as exact whole units of your currency, and the entry form only accepts the precision your currency actually uses.

= Will it slow my store down? =

No. The dashboard runs on indexed queries against its own tables, and its scripts and styles load only on its own admin screens. The plugin adds no scripts, styles or markup to your storefront. The one thing that runs on a storefront request is the hook that records a charge when a qualifying order is placed, which is a single insert against the plugin's own table.

= What happens to my data if I remove the plugin? =

Deactivating changes nothing. Uninstalling removes the plugin's tables, options and settings completely.

== Screenshots ==

1. The accounts receivable dashboard: outstanding total, customers carrying a balance, overdue amount and the receivables trend.
2. The customer list, sortable by balance, name or oldest unpaid date.
3. A customer's account: balance, overdue amount, oldest unpaid date and payment terms, above the open invoices and the full history with a running balance.
4. Settings: choosing which payment methods create a receivable, which customer roles count as B2B accounts, and the store's payment terms.
5. Recording a payment. Choosing the customer shows their balance and their open invoices, oldest first, before you enter the amount.
6. Importing past orders as charges: scanning a date range reports how many orders it found, how many are already tracked, and what the rest are worth.

== Changelog ==

= 1.1.1 =
* Fix: dates showed a day early on stores in time zones west of UTC.

= 1.1.0 =
* Tabs added to the Accounts Receivable screen: Overview, Customers, Import and Settings.
* Requires WordPress 7.0, WooCommerce 11.1 and PHP 7.4.
* Charges are created only for standard orders. Subscription objects and other order types are ignored.
* Declares compatibility with the WooCommerce Cart and Checkout blocks.
* Dependency notice now shows only on the Plugins screen.

= 1.0.1 =
* Fix: uninstalling no longer deletes the shared B2B role list while another installed Kascado plugin that reads it is present, active or not. Version 1.0.0 looked for Customer Statements under the wrong folder name, so the list was always deleted.
* Fix: the customer search on the Record Payment screen finds every customer an order could charge, not only customers who already have a balance, so a payment received in advance can be recorded.
* Fix: the Record Payment screen shows the form even before anything has been recorded. When no payment method is selected to create receivables, a notice above the form says so and links to the setting.
* Fix: the import scan no longer counts orders it cannot import. Orders in another currency, orders without a customer account and orders with a zero total are listed separately with the reason. The scan and the import use the same checks.
* Fix: "Record credit or write-off" on a customer's account opens the Credit tab.
* Plugin URI now points to https://kascado.com/woocommerce/accounts-receivable/.

= 1.0.0 =
* First public release.

== Upgrade Notice ==

= 1.1.1 =
Fixes dates shown a day early on stores west of UTC.

= 1.1.0 =
Requires WordPress 7.0 or later. Update WordPress before updating this plugin.

= 1.0.1 =
Fixes uninstall deleting the B2B role list that Customer Statements also uses, the import scan counting orders it cannot import, and recording a payment for a customer with no balance.

= 1.0.0 =
First public release.
