=== Billvane – Bill to Stock for WooCommerce ===
Contributors: srikrishnaduduku
Tags: woocommerce, inventory, stock, supplier invoice, ocr
Requires at least: 6.6
Tested up to: 7.1
Requires PHP: 8.0
Stable tag: 1.3.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Photograph a supplier bill. AI reads every line, matches your products – even without SKUs – and updates stock and cost after you approve.

== Description ==

Every delivery comes with a bill. Typing each line into WooCommerce is slow and easy to get wrong.

Billvane reads the bill for you:

1. **Upload a PDF or take a photo** of a supplier bill, invoice or packing slip from Products → Billvane (phone camera works in the browser – no app).
2. **AI reads it** – supplier, bill number, date, and every product line with quantity and unit cost. No API key needed: start with 5 free bills a month on Billvane Cloud, or add your own Gemini key for unlimited reading.
3. **Lines are matched to your products and variations** – by SKU, barcode, your earlier choices for that supplier, or by name when you have no SKUs.
4. **You review** – the bill on the left, the lines on the right. Green means sure, amber means please check, red means pick the product. Change anything, untick what you don't want.
5. **Add to stock** – quantities are added and unit cost is saved. Every change is logged and can be undone for 30 days.

= Built to be safe =

* Nothing changes in your store until you click "Add to stock".
* The AI only reads the bill. All matching and stock changes happen in your own site.
* Line totals are checked against quantity × unit cost, and line totals against the bill subtotal, so misread numbers stand out.
* Variable products must be matched to the exact variation.
* Full history: stock before and after, cost before and after, who applied it, and one-click undo.
* Bill files are stored in a protected folder and deleted after 90 days (you can change this).

= Who it is for =

Shops that buy stock from suppliers and sell on WooCommerce: clothing and saree stores, gift shops, bookshops, hardware, grocery and speciality food – especially catalogs without SKUs.

= Billvane Pro =

Busy shops can upgrade to Billvane Pro: 200 Billvane Cloud bills a month per site, bulk upload of many bills at once, and multi-page bills from several photos. Billvane works fully without Pro – with your own Gemini key, reading is unlimited.

Works well alongside Countervane – Inventory Sync for Square, which sends the new stock on to your Square shop.

== External services ==

To read a bill, this plugin sends the bill file to an AI service. You choose which one in Products → Billvane → Settings.

= Billvane Cloud (default, no API key needed) =

A service run by the plugin author so you can read bills without your own AI key. It is free for 5 bills a month per site.

* **What is sent:** when your site first uses the service, its home address (to create a site token). After that, the bill file you uploaded (PDF or image; large photos are made smaller first). No customer or order data is sent.
* **When:** only when a bill is read – automatically right after you upload it, or when you click "Read bill with AI" / "Read again with AI" – and when the bills page shows your monthly usage.
* **Where it goes:** Billvane Cloud (billvane-cloud.srikrishna-duduku.workers.dev, hosted on Cloudflare) passes the file to the Google Gemini API (paid tier) to read it, and returns the result. The file is not stored.
* Billvane Cloud terms: https://billvane-cloud.srikrishna-duduku.workers.dev/terms
* Billvane Cloud privacy policy: https://billvane-cloud.srikrishna-duduku.workers.dev/privacy
* Gemini API terms: https://ai.google.dev/gemini-api/terms
* Cloudflare privacy policy: https://www.cloudflare.com/privacypolicy/

= Google Gemini API (with your own key) =

* **What is sent:** the bill file you uploaded (PDF or image) and reading instructions. No customer or order data is sent.
* **When:** only when a bill is read, as above.
* **Service:** Google Gemini API (generativelanguage.googleapis.com), provided by Google LLC.
* Gemini API terms: https://ai.google.dev/gemini-api/terms
* Google privacy policy: https://policies.google.com/privacy

== Installation ==

1. Install and activate WooCommerce.
2. Install and activate Billvane.
3. Go to Products → Billvane and upload your first bill. It is read with Billvane Cloud – no setup needed.
4. Optional: for unlimited reading, create a Gemini API key at https://aistudio.google.com/apikey and choose "My own Gemini API key" in Products → Billvane → Settings.

== Frequently Asked Questions ==

= Do my products need SKUs? =

No. Lines are matched by name when there is no SKU or barcode. When you correct a match, Billvane remembers your choice for that supplier.

= What happens to products that don't track stock? =

Stock tracking is switched on for that product and its stock is set to the quantity on the bill. Undo switches tracking off again.

= Where is the cost price saved? =

In the product meta field `_billvane_cost`. If WooCommerce's Cost of Goods feature is enabled, the product's cost is updated too.

= Which bills work best? =

Printed bills and PDFs. Clear, flat, well-lit photos work well. Handwritten bills may need more corrections.

= Do I need an API key? =

No. Billvane Cloud reads 5 bills a month per site for free without any key. For more, add your own Gemini API key – reading with your own key is unlimited.

= What does the AI cost? =

Billvane Cloud is free for 5 bills a month. With your own key, you pay Google directly for your own API usage. Reading a typical one-page bill with a "flash" model costs a fraction of a cent; Google also offers a free tier with limits.

== Screenshots ==

1. Upload a supplier bill (PDF or image) or take a photo of it with your phone.
2. Review screen: the bill beside every line it read, matched to your products. Green is sure, amber needs a check, red is not in your catalog – create it as a new draft product or skip it.
3. Bill history after adding to stock: stock before and after, cost saved, Square status, and one-click undo.

== Changelog ==

= 1.3.0 =
* New: works with Billvane Pro (200 cloud bills a month, bulk upload, multi-page bills).
* Developers: new filters `billvane_cloud_headers` and `billvane_show_pro_offer`, action `billvane_after_upload_card`, and `Billvane_Admin::queue_read()`.

= 1.2.0 =
* New: Billvane Cloud – read bills without an API key. 5 free bills a month per site; your own Gemini key stays unlimited.
* New: choose how bills are read in Settings; the bills page shows how many cloud bills are left this month.
* Improved: large photos are made smaller before they are sent to Billvane Cloud, so they upload faster.

= 1.1.0 =
* New: lines that match nothing can be created as new draft products (stock and cost filled in; you set the price and publish). Undo moves them to the trash.
* New: works with Countervane – Inventory Sync for Square. Stock added from a bill is sent to Square for linked products, and the bill history shows the Square status.
* Improved: clothing sizes on bills ("M", "L", "XL", "Extra Large") now match product sizes written in full ("Medium", "Large").
* Improved: more reliable AI reads. Waits and retries when the AI model is busy, never uses an answer that was cut off, and avoids a model glitch that could repeat digits endlessly.
* Fixed: the bill image no longer fills the whole page on the bill history screen.

= 1.0.0 =
* First release: upload or photograph supplier bills, AI reading (Gemini, your own key), matching by SKU, barcode, remembered choices or name, review screen, add to stock and cost, history and 30-day undo.
* Bills are read in the background so slow AI answers never hit server time limits.
* Bill files are stored under random, unguessable names.
