Skip to content

Commit

Permalink
fix: repeated customers
Browse files Browse the repository at this point in the history
  • Loading branch information
jabir-tridz committed Aug 24, 2024
1 parent 80c4585 commit 18a16ec
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"add_total_row": 0,
"columns": [],
"creation": "2023-09-29 14:52:16.514901",
"disable_prepared_report": 0,
"disabled": 0,
"docstatus": 0,
"doctype": "Report",
Expand Down Expand Up @@ -32,13 +31,14 @@
],
"idx": 0,
"is_standard": "Yes",
"modified": "2023-12-06 10:46:00.224850",
"letterhead": null,
"modified": "2024-08-24 12:08:25.676663",
"modified_by": "Administrator",
"module": "URY Pulse",
"name": "Repeated Customers",
"owner": "Administrator",
"prepared_report": 0,
"query": "SELECT\n `Date`,\n `Total Customers`,\n `New Customers`,\n `Total Customers`-`New Customers` AS `Repeated Customers`,\n ROUND(((`Total Customers`-`New Customers`) / `Total Customers`)*100,2) AS Percentage\nFROM\n (SELECT\n date_list.`date` AS `Date`,\n COUNT(d.customer) AS `Total Customers`,\n COUNT(DISTINCT CASE WHEN b.customer IS NOT NULL THEN b.customer END) AS `New Customers`\n FROM \n (\n SELECT %(start_date)s AS `date`\n UNION\n SELECT DATE_ADD(%(start_date)s, INTERVAL n DAY) AS `date`\n FROM (\n SELECT a.N + b.N * 10 + c.N * 100 + 1 AS n\n FROM (\n SELECT 0 AS N UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9\n ) AS a\n CROSS JOIN (\n SELECT 0 AS N UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9\n ) AS b\n CROSS JOIN (\n SELECT 0 AS N UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9\n ) AS c\n ORDER BY n\n ) AS nums\n WHERE DATE_ADD(%(start_date)s, INTERVAL n DAY) < %(end_date)s\n UNION\n SELECT %(end_date)s AS `date`\n ) AS date_list\n LEFT JOIN `tabPOS Invoice` d ON (\n d.`branch` = %(branch)s\n AND d.`status` IN (\"Consolidated\",\"Paid\") \n AND d.`docstatus` = 1\n )\n LEFT JOIN `tabPOS Invoice` b ON (\n b.`name` = d.`name`\n AND b.`branch` = %(branch)s\n AND b.`status` IN (\"Consolidated\", \"Paid\")\n AND b.`docstatus` = 1\n AND NOT EXISTS (\n SELECT 1\n FROM `tabPOS Invoice` c\n LEFT JOIN `tabURY Report Settings` rs ON (\n rs.`branch` = %(branch)s\n )\n WHERE\n (\n ((rs.`hours` IS NULL OR rs.`hours` = 0) IS NULL AND c.`posting_date` < date_list.`date`)\n OR (rs.`hours` > 0 AND TIMESTAMP(c.`posting_date`, c.`posting_time`) < TIMESTAMP(date_list.`date`, CONCAT(LPAD(rs.`hours`, 2, '0'), ':00:00')))\n OR (rs.`branch` IS NULL AND c.`posting_date` < da(rs.`hours` IS NULL OR rs.`hours` = 0)te_list.`date`)\n )\n AND c.`customer` = b.`customer`\n AND c.`branch` = %(branch)s\n AND c.`status` IN (\"Consolidated\", \"Paid\")\n AND c.`docstatus` = 1\n )\n )\n LEFT JOIN `tabURY Report Settings` rs ON (\n rs.`branch` = %(branch)s\n )\n WHERE\n (\n ((rs.`hours` IS NULL OR rs.`hours` = 0) IS NULL AND d.`posting_date` = date_list.`date`)\n OR (rs.`hours` > 0 AND TIMESTAMP(d.`posting_date`, d.`posting_time`) <= TIMESTAMP(DATE_ADD(date_list.`date`, INTERVAL 1 DAY), CONCAT(LPAD(rs.`hours`, 2, '0'), ':00:00')) AND TIMESTAMP(d.`posting_date`, d.`posting_time`) >= TIMESTAMP(date_list.`date`, CONCAT(LPAD(rs.`hours`, 2, '0'), ':00:00')))\n OR (rs.`branch` IS NULL AND d.`posting_date` = date_list.`date`)\n )\n GROUP BY \n date_list.`date`\n ORDER BY \n date_list.`date` DESC) AS subquery;",
"query": "SELECT\n `Date`,\n `Total Customers`,\n `New Customers`,\n `Total Customers`-`New Customers` AS `Repeated Customers`,\n ROUND(((`Total Customers`-`New Customers`) / `Total Customers`)*100,2) AS Percentage\nFROM\n (SELECT\n date_list.`date` AS `Date`,\n COUNT(d.customer) AS `Total Customers`,\n COUNT(DISTINCT CASE WHEN b.customer IS NOT NULL THEN b.customer END) AS `New Customers`\n FROM \n (\n SELECT %(start_date)s AS `date`\n UNION\n SELECT DATE_ADD(%(start_date)s, INTERVAL n DAY) AS `date`\n FROM (\n SELECT a.N + b.N * 10 + c.N * 100 + 1 AS n\n FROM (\n SELECT 0 AS N UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9\n ) AS a\n CROSS JOIN (\n SELECT 0 AS N UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9\n ) AS b\n CROSS JOIN (\n SELECT 0 AS N UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9\n ) AS c\n ORDER BY n\n ) AS nums\n WHERE DATE_ADD(%(start_date)s, INTERVAL n DAY) < %(end_date)s\n UNION\n SELECT %(end_date)s AS `date`\n ) AS date_list\n LEFT JOIN `tabPOS Invoice` d ON (\n d.`branch` = %(branch)s\n AND d.`status` IN (\"Consolidated\",\"Paid\") \n AND d.`docstatus` = 1\n )\n LEFT JOIN `tabPOS Invoice` b ON (\n b.`name` = d.`name`\n AND b.`branch` = %(branch)s\n AND b.`status` IN (\"Consolidated\", \"Paid\")\n AND b.`docstatus` = 1\n AND NOT EXISTS (\n SELECT 1\n FROM `tabPOS Invoice` c\n LEFT JOIN `tabURY Report Settings` rs ON (\n rs.`branch` = %(branch)s\n )\n WHERE\n (\n ((rs.`hours` IS NULL OR rs.`hours` = 0) IS NULL AND c.`posting_date` < date_list.`date`)\n OR (rs.`hours` > 0 AND TIMESTAMP(c.`posting_date`, c.`posting_time`) < TIMESTAMP(date_list.`date`, CONCAT(LPAD(rs.`hours`, 2, '0'), ':00:00')))\n OR (rs.`branch` IS NULL AND c.`posting_date` < date_list.`date`)\n )\n AND c.`customer` = b.`customer`\n AND c.`branch` = %(branch)s\n AND c.`status` IN (\"Consolidated\", \"Paid\")\n AND c.`docstatus` = 1\n )\n )\n LEFT JOIN `tabURY Report Settings` rs ON (\n rs.`branch` = %(branch)s\n )\n WHERE\n (\n ((rs.`hours` IS NULL OR rs.`hours` = 0) IS NULL AND d.`posting_date` = date_list.`date`)\n OR (rs.`hours` > 0 AND TIMESTAMP(d.`posting_date`, d.`posting_time`) <= TIMESTAMP(DATE_ADD(date_list.`date`, INTERVAL 1 DAY), CONCAT(LPAD(rs.`hours`, 2, '0'), ':00:00')) AND TIMESTAMP(d.`posting_date`, d.`posting_time`) >= TIMESTAMP(date_list.`date`, CONCAT(LPAD(rs.`hours`, 2, '0'), ':00:00')))\n OR (rs.`branch` IS NULL AND d.`posting_date` = date_list.`date`)\n )\n GROUP BY \n date_list.`date`\n ORDER BY \n date_list.`date` DESC) AS subquery;",
"ref_doctype": "POS Invoice",
"report_name": "Repeated Customers",
"report_type": "Query Report",
Expand Down

0 comments on commit 18a16ec

Please sign in to comment.