=== Ni WooCommerce Sales Report By User Role ===
Contributors: anzia
Tags: sales agent, sales report, woocommerce report, user role, salesperson
Requires at least: 6.1
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 2.2.0
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.html
WC requires at least: 3.0.0
WC tested up to: 11.1

Assign WooCommerce orders to sales agents and track sales by user role with agent reports, dashboard KPIs and HPOS support.

== Description ==

**Ni WooCommerce Sales Report By User Role** links every WooCommerce order to a sales agent (salesperson) and shows how much each agent sells. Choose any WordPress user role as your sales team, assign an agent on the order screen, and get a sales dashboard, a product-wise sales report and a sales agent report — all filtered by date period and agent.

It is built for stores that sell through sales representatives, field agents, resellers, phone or in-store staff, and for anyone who needs a simple WooCommerce sales report by user, by salesperson or by user role.

= Accurate sales figures =

* **Net of refunds** – partial and full refunds are subtracted from sales totals, quantities sold, line totals and tax.
* **Paid orders only** – reports count orders with the status Processing, On hold or Completed. Pending, Failed, Cancelled and Refunded orders are excluded.
* **Your time zone** – "Today", "Yesterday", "This year" and other periods follow the time zone set in WordPress Settings.

= Key features =

* **Sales dashboard** – total, this year, this month, this week and today sales, plus order counts.
* **Today's sales analysis** – orders, sales, products sold, discount and tax for the current day.
* **Recent orders** – the 10 latest orders with customer, country, status and net order total.
* **Sales product report** – product-wise sales with quantity, line tax and line total, filtered by sales agent.
* **Sales agent report** – order count and net sales total per agent.
* **Date filters** – Today, Yesterday, Last 7 days, Last 10 days, Last 15 days, Last 30 days, This year and Last year.
* **Assign sales agents to orders** – a "Select Sales Agent" box on the order edit screen.
* **Sales Agent column** in the WooCommerce orders list.
* **Choose the agent role** – use any existing role or the included **Ni Sales Agent** role.

= WooCommerce HPOS compatible =

The plugin is fully compatible with WooCommerce **High-Performance Order Storage (HPOS)** and with the legacy WordPress posts storage, including compatibility (sync) mode. Reports read the active order tables directly with optimised SQL, so they stay fast on large stores, and the sales agent is stored as standard WooCommerce order meta.

= Secure =

Reports and settings are available only to administrators, requests are protected with nonces, user input in database queries is validated and prepared, and report output is escaped.

= For developers =

* `ni_sales_agent_report_order_statuses` – filter the order statuses included in reports (default: `wc-processing`, `wc-on-hold`, `wc-completed`).
* `ni_sales_agent_report_columns`, `nisabur_sales_product_report_columns` and `nisabur_sales_product_report_data` – customise report columns and rows.

= Need more reports? =

Get **Ni WooCommerce Sales Agent and Sales Commission** for agent commission reports, CSV export of all reports and a separate login for sales agents.

* [View demo](http://demo.naziinfotech.com/?demo_login=woo_agent_commission)
* [Buy Ni WooCommerce Sales Agent and Sales Commission](http://naziinfotech.com/product/ni-woocommerce-sales-agent-and-sales-commission/)

== Installation ==

1. In WordPress go to **Plugins > Add New**, search for "Ni WooCommerce Sales Report By User Role", then install and activate it. You can also upload the plugin folder to `/wp-content/plugins/`.
2. Make sure WooCommerce is installed and active.
3. Open the **User Role Report** menu.
4. Go to **User Role Report > Setting** and select the user role of your sales agents, for example **Ni Sales Agent**.
5. Go to **Users > Add New** and create your sales agents with that role. Fill in the first and last name — they are shown in the reports.
6. Edit an order, choose the agent in the **Select Sales Agent** box and update the order.
7. Open the **Dashboard**, **Sales Product Report** or **Agent Report**.

== Frequently Asked Questions ==

= Is the plugin compatible with WooCommerce HPOS? =

Yes. It declares HPOS compatibility and works with High-Performance Order Storage, legacy post storage and compatibility (sync) mode. When you update from an older version on an HPOS store, existing sales agent assignments are copied to the HPOS order meta table automatically the first time an administrator opens the WordPress admin.

= Which orders are included in the reports? =

Orders with the status Processing, On hold or Completed. Developers can change the list with the `ni_sales_agent_report_order_statuses` filter.

= Are refunds subtracted? =

Yes. Refunds reduce the sales total, the agent total, quantities sold, line totals and tax. A refund is counted against the date of the original order.

= How do I assign a sales agent to an order? =

Open the order in WooCommerce, select the agent in the **Select Sales Agent** box and update the order. The agent then appears in the orders list and in all reports.

= Can I use my own user role for sales agents? =

Yes. Select any role under **User Role Report > Setting**. Only users with that role are listed as agents.

= Why is an agent missing from the dropdown? =

The user must have the role selected in the settings. First and last names are shown, so add them to the user profile.

= Which dates and time zone are used? =

Order dates are shown and filtered in the time zone set under **Settings > General**.

= Where can I get help? =

Use the support tab on WordPress.org or email support@naziinfotech.com.

= Do you customize this plugin? =

Yes, we can customize the plugin and build custom reports for your requirements.

== Screenshots ==

1. Create a sales agent user with the Ni Sales Agent role.
2. Select the sales agent user role in the User Role Report settings.
3. Assign a sales agent on the WooCommerce order edit screen.
4. Sales dashboard with total, yearly, monthly, weekly and today sales.
5. Recent orders list on the dashboard.
6. Sales product report filtered by period and sales agent.
7. Sales agent report with order count and net sales per agent.

== Changelog ==

= version 2.2.0 - 04-October-2026 =
* Tested: Compatible With WordPress 7.1.2
* Tested: Compatible With WooCommerce 11.1.2
* Tested: PHP 7.4 and PHP 8.2
* Fixed: HPOS - the sales agent is now saved as WooCommerce order meta (wc_orders_meta on HPOS stores, postmeta on legacy stores), so it is no longer lost when HPOS compatibility (sync) mode is enabled.
* Fixed: HPOS - existing sales agent assignments are copied to the HPOS order meta table once after updating.
* Fixed: HPOS - agent filter and agent report read the correct order meta table for the active storage.
* Fixed: HPOS - Sales Agent column added to the HPOS orders list.
* Fixed: HPOS - recent orders showed the phone number instead of the email address.
* Fixed: HPOS - orders without a billing address were missing from the recent orders list and product report.
* Fixed: Order dates and date filters now use the WordPress time zone in both HPOS and legacy storage.
* Fixed: The saved sales agent was not preselected on the legacy order edit screen and was reset when the order was updated.
* Changed: Reports include only Processing, On hold and Completed orders.
* Changed: Refunds are subtracted from sales totals, agent totals, quantities sold, line totals and tax.
* Changed: Fully refunded order lines are removed from the sales product report.
* Added: `ni_sales_agent_report_order_statuses` filter for the order statuses used in reports.
* Security: Report AJAX requests require administrator access and a nonce.
* Security: Settings are saved only by administrators with a valid nonce, and only valid roles are accepted.
* Security: Sales agent IDs are validated and all user input in SQL is prepared.
* Security: Report output is escaped.
* Improved: Multisite-safe user table names.
* Improved: PHP 8 warnings fixed.
* Improved: New responsive admin design for the dashboard and reports; the plugin CSS no longer affects other admin tables.
* Improved: Order links open the correct order screen in HPOS and legacy storage.

= version 2.1.2 -15-October-2024 =
* Tested: Compatible With WooCommerce 9.3.3
* Tested: Compatible With WordPress 6.6.2

= version 2.1.1 -20-August-2024 =
* Tested: Compatible With WooCommerce 9.1.4
* Tested: Compatible With WordPress 6.6.1
* Tested: High-Performance Order Storage (HPOS)


= version 2.1.0 -23-November-2023 =
* Tested: Compatible With WooCommerce 8.3.1
* Tested: Compatible With WordPress 6.4.1

= version  2.0.9 -13-February-2023 =
* Tested: Compatible With WooCommerce 7.6.1 
* Tested: Compatible With WordPress 6.2

= version  2.0.8 -13-February-2023 =
* Tested: Compatible With WooCommerce 7.4.0 
* Tested: Compatible With WordPress 6.1.1

= version  2.0.7 -11-November-2022 =
* Tested: Compatible With WooCommerce 7.0.1
* Tested: Compatible With WordPress 6.1

= version  2.0.6 -08-September-2022 =
* Tested: Compatible With WooCommerce 6.8.2
* Tested: Compatible With WordPress 6.0.2

= version  2.0.5 -07-August-2022 =
* Tested: Compatible With WooCommerce 6.7.0
* Tested: Compatible With WordPress 6.0.1

= version  2.0.4 -01-June-2022 =
* Tested: Compatible With WooCommerce 6.5.1
* Tested: Compatible With WordPress 6.0

= version 2.0.3 -26-March-2022 =
* Tested: Compatible With WooCommerce  6.3.1
* Tested: Compatible With WordPress 5.9.2

= version 2.0.2 -14-January-2022 =
* Tested: Compatible With WooCommerce 6.1.0
* Tested: Compatible With WordPress 5.8.3
* Added:  Added new hook 

= version 2.0.1 -21-December-2021 =
* Tested: Compatible With WooCommerce 6.0.0
* Tested: Compatible With WordPress 5.8.2

= version 2.0.0 -03-October-2021 =
* Tested: Compatible With WooCommerce 5.7.1
* Tested: Compatible With WordPress 5.8.1

= version  1.9.9 -13-Aug-2021 =
* Tested: Compatible With WooCommerce 5.5.2
* Tested: Compatible With WordPress 5.8

= version  1.9.8 -07-July-2021 =
* Update: Update UI issue

= version  1.9.7 -01-July-2021 =
* Tested: Compatible With WooCommerce 5.4.1
* Tested: Compatible With WordPress  5.7.2

= version  1.9.6 -08-April-2021 =
* Added:  Added Last 15 days 

= version  1.9.5 -16-March-2021 =
* Tested: Compatible With WooCommerce 5.1.0
* Tested: Compatible With WordPress 5.7

= version  1.9.4 -11-February-2021 =
* Tested: Compatible With WooCommerce 5.0.0

= version 1.9.3 -23-December-2020 =
* Tested: Compatible With WooCommerce  4.8.0 
* Tested: Compatible With WordPress 5.6

= version 1.9.2 -28-October-2020 =
* Tested: Compatible With WooCommerce  4.6.1
* Tested: Compatible With WordPress 5.5.1


= version 1.9.1 -16-August-2020 =
* Tested: Compatible With WooCommerce 4.3.3
* Tested: Compatible With WordPress 5.5

= version 1.9.0 -26-June-2020 =
* Tested: Compatible With WooCommerce 4.2.2 
* Tested: Compatible With WordPress 5.4.2
* Added: Display Sales agent name in order list

= version 1.8.0 -30-April-2020 =
* Tested: Compatible With WooCommerce 4.0.1
* Tested: Compatible With WordPress  5.4.1

= version 1.7.9 -30-April-2020 =
* Tested: Compatible With WooCommerce 4.0.1
* Tested: Compatible With WordPress  5.4.1

= version 1.7.8 -24-February-2020 =
* Tested: Compatible With WooCommerce 3.8.1
* Tested: Compatible With WordPress 5.3.2
* Added: Last Year Filter

= version 1.7.7 -20-January-2019 =
* Tested: Compatible With WooCommerce 3.8.1
* Tested: Compatible With WordPress  5.3.2

= version 1.7.6 -15-November-2019 =
* Tested: Compatible With WordPress 5.3

= version 1.7.5 -10-November-2019 =
* Tested: Compatible With WooCommerce 3.8.0
* Tested: Compatible With WordPress  5.2.4


= version 1.7.4 -24-September-2019 =
* Tested: Compatible With WordPress  5.2.3
* Added: Added New Hook 

= version 1.7.3 -04-September-2019 =
* Tested: Compatible With WooCommerce 3.7.0 
* Added: Added New Hook 

= version 1.7.2 -27-July-2019 =
* Tested: Compatible With WooCommerce 3.6.5
* Tested: Compatible With WordPress  5.2.2


= version 1.7.1 -09-May-2019 =
* Tested: Compatible With WooCommerce 3.6.2
* Tested: Compatible With WordPress  5.2
* Added: Added New Hook

= version 1.7.0 -16-April-2019 =
* Tested: Compatible With WooCommerce 3.5.8
* Tested: Compatible With WordPress  5.1.1

= version 1.6.0 -03-March-2019 =
* Tested: Compatible With WooCommerce 3.5.5
* Tested: Compatible With WordPress  5.1

= version 1.5.9 -11-February-2019 =
* Tested: Compatible With WooCommerce 3.5.4
* Tested: Compatible With WordPress 5.0.3

= version 1.5.8 -01-December-2019 =
* Tested: Compatible With WooCommerce 3.5.3
* Tested: Compatible With WordPress 5.0.2


= version  1.5.7 -14-November-2018 =
* Tested: Compatible With WooCommerce 3.5.1


= version  1.5.6 -21-October-2018 =
* Tested: Compatible With WooCommerce 3.4.7
* Tested: Compatible With WordPress  4.9.8


= version  1.5.5 -30-June-2018 =
* Tested: Compatible With WooCommerce 3.4.4

= version  1.5.3 -28-May-2018 =
* Tested: Compatible With WooCommerce 3.4.0
* Added: Product name columns


= version  1.5.2 -19-May-2018 =
* Tested: Compatible With WooCommerce 3.3.5
* Tested: Compatible With WordPress 4.9.6

= version  1.5.1 -02-April-2018 =
* Tested: Compatible With WooCommerce 3.3.4

= version 1.5 -08-March-2018 =
* Tested: Compatible With WordPress 4.9.4
* Tested: Compatible With WooCommerce 3.2.5
* Added: Sales Agent Report 

= version 1.4 -28-November-2017 =
* Tested: Compatible With WordPress 4.9
* Tested: Compatible With WooCommerce 3.2.5


= version 1.3 -04-November-2017 =
* Tested: Compatible With WordPress 4.8.3
* Tested: Compatible With Woocommerce 3.2.3

= version 1.2 -09-September -2017 =
* Tested: Compatible With WordPress 4.8.1
* Tested: Compatible With Woocommerce  3.1.2 

= version 1.1 - 07-April -2017 =
* Tested: Compatible With WordPress 4.7.3
* Tested: Compatible With Woocommerce  3.0.0

= version 1.0 09-January-2017 =
* Initial release

== Upgrade Notice ==

= 2.2.0 =
Important security and HPOS fixes. Reports now show net sales (refunds subtracted) for Processing, On hold and Completed orders. Back up your site before updating.

== Disclaimer ==

It is not responsible for any harm or wrong doing this Plugin may cause. Users are fully responsible for their own use. This Plugin is to be used WITHOUT warranty.
