=== Connect with Emblem.gr ===
Contributors: tsirosgeorge
Tags: woocommerce, orders, invoice, pdf, accounting
Requires at least: 5.9
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.4.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Issue Emblem.gr invoices and credit notes from WooCommerce Orders — one click, in bulk, or automatically — and open the resulting PDF.

== Description ==
Connect with Emblem.gr links your WooCommerce store to your Emblem.gr accounting account. Issue a document for an order with one click from the Orders list or the order screen, issue many at once, or let the plugin do it on its own as soon as an order is paid. The document ID, series, number, MARK and PDF link are stored on the order, so everything stays traceable from WooCommerce.

Works with both the classic Orders list and WooCommerce High-Performance Order Storage (HPOS).

= Key features =
- One-click issuing from the Orders list and from the single order screen
- Bulk issuing for many orders at once, with live progress and a per-order result
- Optional automatic issuing when an order reaches Processing
- Support for your own custom document series, both for invoices and credit notes
- Payment method mapping (WooCommerce gateway to Emblem payment method) directly from WordPress
- Credit notes, with the correct credit series chosen from the original document
- Always refreshes the PDF URL server-side before opening it
- Order notes for every send, failure and retry, so problems are easy to trace
- HPOS compatible

= What is new in 1.4.0 =
This release adds four things you can control from WooCommerce that previously had to be done inside Emblem, or one order at a time.

**Bulk issuing.** Select orders in the Orders list, choose "Έκδοση παραστατικών (Emblem)" from the bulk actions menu, and pick the document once for the whole batch. Orders are processed one after another, never in parallel, so your Emblem account is not flooded. A progress window shows how many succeeded, which ones failed and why, and you can stop the run at any point without losing what already went through.

**Automatic issuing.** Turn on "Αυτόματη Έκδοση" in the settings and the document is issued on its own once an order reaches Processing. The work is queued and runs a minute later rather than during checkout, so your customer is never left waiting on the payment page. This needs a default document to be set, because there is nobody to answer a popup. An order that is already issued, or that has moved on to another status in the meantime, is skipped silently.

**Custom document series.** If your Emblem account has its own named series (for example a series dedicated to your eshop), they now appear alongside the standard document types, marked "(custom σειρά)". Pick one as your default, or choose per order in the popup. Standard series behave exactly as before.

**Payment method mapping.** A "Τρόποι Πληρωμής" tab lists the payment gateways actually installed in your store next to a dropdown of Emblem payment methods. The mapping is saved in Emblem, so it is the same mapping you see in your company settings there — edit it in either place.

= Settings explained =
All settings live under WooCommerce → Connect with Emblem.gr.

**Account Email / Account Password** — your Emblem.gr credentials. "Έλεγχος Σύνδεσης" next to them verifies that the store can reach Emblem and log in.

**Τύπος Συναλλαγής (Transaction type)** — whether documents default to retail (Λιανική) or wholesale (Χονδρική).

**Προεπιλεγμένο Παραστατικό (Default document)** — which document is issued. Leave it on "Popup επιλογής κάθε φορά" to be asked each time, or pick one so issuing takes a single click. The list contains the standard document types plus any custom series on your account.

**Προεπιλεγμένο Πιστωτικό (Default credit note)** — the same idea for credit notes. It is only used when it matches the credit series that corresponds to the original document; otherwise you are asked, or the only available series is used.

**Αυτόματη Έκδοση (Automatic issuing)** — issue automatically when an order reaches Processing. Requires a default document.

**Ολοκλήρωση Παραγγελίας (Complete the order)** — whether the order is set to Completed after a document is issued successfully. On by default, which is how the plugin has always behaved. Turn it off if your workflow keeps orders in Processing after invoicing.

**Τρόποι Πληρωμής (Payment methods)** — map each WooCommerce payment gateway to an Emblem payment method. Gateways that are switched off in your store are listed separately, and mappings for gateways you have since removed are kept rather than silently dropped.

= How credit notes work =
Issuing a credit note copies the original document, so the credit series follows the document it credits. If your account has more than one series for that credit type, you are asked which one to use; if there is only one, the flow is the single confirmation it has always been.

= How it works =
- Send: posts order data to your endpoint (createOrderFromPlugin) with orderId, iddochead, email and password in the payload.
- PDF: the server requests ajaxSrv.php?op=47 with email, password, orderId and iddochead, stores the URL and returns it to the browser.

== External Services ==
This plugin connects to the Emblem.gr service in order to create invoices and synchronize invoicing settings.

It sends order, customer and invoicing configuration data to the remote Emblem.gr API when:
- creating invoices and credit notes
- synchronizing settings
- fetching remote configuration, document series and payment method mappings
- printing invoices

This service is provided by Emblem.gr:

Terms of Service:
https://emblem.gr/wp/policy.html

Privacy Policy:
https://emblem.gr/wp/policy.html

== Installation ==
1. Upload the plugin ZIP via Plugins → Add New → Upload, or copy the `connect-with-emblemgr` folder into `wp-content/plugins/`.
2. Activate the plugin.
3. Go to WooCommerce → Connect with Emblem.gr and enter your Emblem.gr email and password, then press "Έλεγχος Σύνδεσης" to confirm the connection.
4. Optionally set a default document, map your payment methods, and turn on automatic issuing.
5. Open WooCommerce → Orders and use the Emblem column to issue documents and open PDFs.

== Frequently Asked Questions ==
= Where do I configure the credentials? =
WooCommerce → Connect with Emblem.gr.

= Does it work with HPOS? =
Yes, it is compatible with the WooCommerce High-Performance Order Storage screen, and bulk issuing works on both the classic and the HPOS Orders list.

= Why does bulk issuing ask me for the document only once? =
Because the whole batch is issued on the same document. If you need different documents for different orders, issue them in separate batches.

= Why is nothing issued automatically? =
Automatic issuing needs a default document. With "Popup επιλογής κάθε φορά" there is nobody to answer the popup, so the plugin skips the order and writes a note on it explaining why. It also only triggers when an order becomes Processing.

= Will automatic issuing slow down my checkout? =
No. The document is queued and issued shortly after the order is placed, not while the customer is waiting.

= My custom series do not appear in the list. =
The list is read from your Emblem account for the current year. Open the settings page to refresh it. If Emblem cannot be reached, the plugin falls back to the standard document types so issuing keeps working.

= Can I stop a bulk run? =
Yes. The progress window has a stop button; orders already processed keep their documents.

== Changelog ==
= 1.4.0 =
- New: bulk issuing from the Orders list, with progress, per-order results and a stop button. Works on the classic and HPOS lists.
- New: optional automatic issuing when an order reaches Processing, queued so it never delays checkout.
- New: support for custom document series defined in your Emblem account, for both invoices and credit notes.
- New: credit series are now resolved from the original document, and you are asked only when there is a real choice.
- New: "Τρόποι Πληρωμής" tab to map WooCommerce payment gateways to Emblem payment methods, stored in Emblem so both sides stay in sync.
- New: "Ολοκλήρωση Παραγγελίας" setting, for stores that do not want the order set to Completed on issuing.
- Change: renamed the WooCommerce menu entry to "Connect with Emblem.gr".
- Change: the extras tabs are now off unless enabled for your account.
- Change: transaction type is a single dropdown, and the password field uses an eye icon with "Έλεγχος Σύνδεσης" on the same line.
- Fix: saving settings no longer re-enables the extras tabs on its own.

= 1.0.1 =
- Security: removed unauthenticated admin_init/GET-triggered remote sync and fetch; the logic now runs only inside the protected Settings API sanitize callback, with an added capability check.

= 1.0.0 =
- First stable release.

= 0.1.17 =
- Release hardening: production defaults, metadata alignment, uninstall cleanup routine.

= 0.1.14 =
- Initial submission.

== Upgrade Notice ==
= 1.4.0 =
Adds bulk and automatic issuing, custom document series, credit series selection and payment method mapping. Existing settings and behaviour are preserved.
