=== Cenariu Orders & Inventory Offline ===
Contributors: cenariu
Tags: inventory, orders, offline
Requires at least: 6.5
Tested up to: 7.1
Requires PHP: 8.1
Requires Plugins: cenariu-orders-inventory
Stable tag: 0.1.3
License: GPL-3.0-or-later
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Offline order drafts on a prepared device, with an authenticated, company-scoped upload inbox for review.

== Description ==

Initial development candidate. Requires Cenariu Orders & Inventory Free 0.36.5 or later. PRO is optional. HTTPS, WordPress pretty permalinks, service workers, IndexedDB and crypto.randomUUID are required for offline preparation. A pre-existing wider-scope service worker can prevent preparation; this addon does not replace it.

Open /cenariu-offline/ under the WordPress home URL (for example /work/cenariu-offline/). Sign in using WordPress, return to the app and explicitly prepare the device while online. Only a public, credential-free application shell and its local assets are cached. Authenticated catalog data and saved drafts use IndexedDB, separated by site, user, company and membership revision. AJAX, wp-admin and unrelated site pages are not cached by this worker. The app is served separately from the theme; no existing intake form is replaced.

Select products, edit quantities, enter the order intake date (current device date by default) and customer name, then save a draft locally. Phone and notes are optional. Estimated totals use exact fixed-point arithmetic. Downloaded prices are estimates, not guaranteed current server prices. This candidate does not download or reserve live stock.

With the separately installed Cenariu Orders & Inventory Barcode 0.2.2 or later, preparation also downloads active company barcode mappings. USB/Bluetooth keyboard readers with an Enter suffix and camera scanning can then use these mappings without server lookups. Pair readers through the operating system. The camera uses the Barcode module's local ZXing bundle, requests video only, suppresses repeated frames and stops on Stop, hidden page, page departure or draft save. Products sold by measured quantity require explicit quantity entry. No GS1 registration, scale-barcode interpretation or external product catalog is provided.

Synchronization is attempted while the app is open on reconnect, reopening online and returning to the foreground. A manual button is also available. It requires the same authorized user/company context and a fresh contextual nonce. Drafts remain queued if the connection or acknowledgment is lost. The server's unique scope/draft identifier and payload hash return the same receipt for identical retries and reject altered retries. There is no background synchronization promise when the app is closed.

IMPORTANT: upload receives an unconfirmed draft in Orders > Offline drafts. It does NOT create a Free ledger order, consume/reserve stock, record payment, issue an invoice or print a fiscal receipt. Manager confirmation/conversion, stock and price reconciliation are not implemented in this first stage. The inbox shows the latest 100 drafts for the current company. No automatic conversion is scheduled.

Fiscal readiness consists only of a versioned data envelope with no configured connector and state not_requested. There is no cash-register driver, local bridge, fiscal document numbering, payment collection or certified integration. Future connectors will be separate modules for explicitly supported and tested device families.

== Installation ==

1. Back up the site database and install compatible Free. Activate this addon per site on 64-bit PHP with InnoDB.
2. For barcode preparation, install Barcode 0.2.2 or later separately. Without it, manual product selection works.
3. Open the offline app, sign in, and prepare this device online before disconnecting.
4. Test with fictitious data: disconnect, save, reopen, reconnect, and verify a single received draft in the inbox.

No site menu, page content, existing plugin file or WordPress rewrite rules are modified automatically. The dedicated route relies on the existing WordPress front-controller routing.

== Privacy and retention ==

Use a trusted device. Offline access intentionally remains possible without contacting WordPress or reauthenticating. Customer names, optional phones/notes and catalog data are retained in that browser profile, unencrypted by the addon. Server logout or revocation cannot remotely erase an offline browser's data. Browser-profile users and site scripts on the same origin may be able to access local data. A changed user/company/revision is blocked from uploading old drafts; export them before clearing or changing context. Do not use a shared public device.

Browser storage can be cleared or evicted. A persistent-storage request is optional and not a guarantee. Export local backup before clearing browser data. Export includes all saved local contexts and drafts and contains personal data; keep it private. This candidate provides export, but not backup restore/import. The currently edited, unsaved cart is not part of the backup. A departure prompt is attempted for unsaved edits. Clear this device deletes all local catalogs and saved drafts after explicit confirmation; it does not erase received server drafts.

Received drafts use one separate cenoio_inbox InnoDB table: account id, operator id, scope hash, draft id, payload hash, captured details and server received time. Payload content remains an untrusted captured estimate until future review/conversion. The Free JSON ledger backup does NOT include this table; use a full database backup. Deactivation/uninstall retains received drafts and does not remotely remove prepared devices or their shell cache. This initial candidate has no automatic retention, WordPress privacy eraser integration or received-draft deletion screen; those controls and restore support are required before a production release.

No third-party service receives catalog, customer details or camera frames. No telemetry, external CDN, payment or fiscal API calls. Optional camera decoder is supplied by the separate Barcode plugin; see its bundled source and license notices.

== Changelog ==

= 0.1.3 =
* Add a visible Offline order intake link above the existing intake form for authorized operators. No Free plugin or page content changes.

= 0.1.2 =
* Version the optional decoder URL consistently for WordPress and the offline cache. Prefix template variables. No draft schema or ledger changes.

= 0.1.1 =
* Enqueue and print only the offline shell's own assets through WordPress. Wait for an installing service-worker update before marking preparation complete. Document narrowly scoped raw validation and own-table operations.

= 0.1.0 =
* First local candidate: scoped public shell, explicit catalog preparation, local draft queue and backup export, retry-safe received-draft inbox and optional local Barcode adapter.
