Query Reports in iVendNext let advanced users pull data using SQL for detailed, custom reporting. Unlike the no-code Report Builder, they offer full control over data queries—ideal for complex needs. However, cloud users can't write SQL directly due to security limits. This article covers how Query Reports work, when to use them, and tips for safe, effective setup.
Query Reports are SQL-based reports that:
✔ Pull raw data from database tables.
✔ Support dynamic filters (unlike Report Builder).
✔ Are used for advanced analytics and cross-module data fetching.
Example: The "Purchase Order Items to Be Received" report in the Stock module is a Query Report.
Note: Only on-premise users or administrators can create/modify SQL queries in iVendNext. Cloud users must rely on pre-built Query Reports.
A basic Query Report includes:
SELECT (columns to fetch).
FROM (database tables).
WHERE (filters).
JOIN (linking related tables).
Example:
SELECT item_code, qty, rate
FROM `tabPurchase Order Item`
WHERE received_qty < qty
Users can apply filters at runtime (e.g., date ranges, statuses). Filters are added as %(...)s placeholders in SQL:
WHERE posting_date BETWEEN %(from_date)s AND %(to_date)s
For cloud users (or those without SQL access):
Navigate to the module containing the report (e.g., Stock).
Open the Reports section.
Select a Query Report (e.g., "Purchase Order Items to Be Received").
Apply filters (e.g., date range, supplier) and click Run.
Pro Tip: Use the Export feature to download data in Excel/PDF for further analysis.
Go to Customize > Report > New Report.
Select Report Type: Query Report.
Reference table names with `tabTableName` (e.g., `tabPurchase Order`).
Use %(...)s for dynamic filters.
Example:
SELECT
po.name AS purchase_order,
poi.item_code,
poi.qty - poi.received_qty AS pending_qty
FROM `tabPurchase Order` po
JOIN `tabPurchase Order Item` poi ON po.name = poi.parent
WHERE po.status = "Submitted"
AND poi.qty > poi.received_qty
AND po.transaction_date >= %(from_date)s
Add filter parameters in the "Filter" section:
filters = [
{
"fieldname": "from_date",
"label": "From Date",
"fieldtype": "Date"
}
]
Click Save.
Run the report to verify data accuracy.
Cause: The user lacks database access rights.
Fix: Grant read permissions for the referenced tables.
Causes:
Typos in table/field names (e.g., `tabPurchaseOrder` vs. `tabPurchase Order`).
Missing JOIN conditions.
Fix: Validate SQL syntax and test with simple queries first.
Cause: Unoptimized queries (e.g., fetching all columns).
Fix:
Use SELECT only for necessary columns.
Add INDEXES to frequently filtered fields.
Restrict SQL Access: Only admins should modify Query Reports.
Sanitize Inputs: Use %(...)s placeholders to prevent SQL injection.
Avoid SELECT *: Fetch only required columns to reduce load.