assign
This commit is contained in:
@@ -61,8 +61,12 @@ const (
|
||||
SUM(CASE WHEN c.orderstatus = 'cancelled' THEN 1 ELSE 0 END) AS deliveriescancelled,
|
||||
SUM(CASE WHEN c.paymenttype = 64 THEN c.deliveryamt ELSE 0 END) AS paylater,
|
||||
SUM(CASE WHEN c.paymenttype = 43 THEN c.deliveryamt ELSE 0 END) AS payondelivery,
|
||||
ROUND(SUM(c.kms), 2) AS kms,
|
||||
ROUND(SUM(c.actualkms), 2) AS actualkms,
|
||||
-- Cast before summing: both are TEXT columns.
|
||||
-- Raw, this is "function sum(text) does not exist" and the endpoint 500s on
|
||||
-- every call — verified on production 2026-09-04. Same defect as the rider
|
||||
-- summary above, which is the other place these two columns are added up.
|
||||
ROUND(SUM(COALESCE(NULLIF(c.kms, '')::numeric, 0)), 2) AS kms,
|
||||
ROUND(SUM(COALESCE(NULLIF(c.actualkms, '')::numeric, 0)), 2) AS actualkms,
|
||||
SUM(c.deliveryamt) AS charges
|
||||
FROM
|
||||
tenants b
|
||||
@@ -77,8 +81,19 @@ const (
|
||||
SUM(CASE WHEN b.orderstatus = 'arrived' THEN 1 ELSE 0 END) AS arrived,
|
||||
SUM(CASE WHEN b.orderstatus = 'picked' THEN 1 ELSE 0 END) AS picked,
|
||||
SUM(CASE WHEN b.orderstatus = 'delivered' THEN 1 ELSE 0 END) AS delivered,
|
||||
SUM(CASE WHEN b.orderstatus = 'delivered' THEN b.actualkms ELSE 0 END) AS actualkms,
|
||||
SUM(CASE WHEN b.orderstatus = 'delivered' THEN b.kms ELSE 0 END) AS kms,
|
||||
-- kms and actualkms are TEXT columns, not numbers.
|
||||
--
|
||||
-- Summed raw they produce
|
||||
-- "CASE types integer and text cannot be matched", because the ELSE arm is
|
||||
-- the integer 0 — so this endpoint answered 500 on every call. Verified on
|
||||
-- production 2026-09-04. Every other SUM here is over a real numeric
|
||||
-- (deliveryamt) or a literal 1, which is why only these two broke it.
|
||||
--
|
||||
-- NULLIF handles the empty string, which is what an unridden job carries
|
||||
-- and what ::numeric would choke on; a value that is not a number at all
|
||||
-- would still raise, but nothing writes one.
|
||||
SUM(CASE WHEN b.orderstatus = 'delivered' THEN COALESCE(NULLIF(b.actualkms, '')::numeric, 0) ELSE 0 END) AS actualkms,
|
||||
SUM(CASE WHEN b.orderstatus = 'delivered' THEN COALESCE(NULLIF(b.kms, '')::numeric, 0) ELSE 0 END) AS kms,
|
||||
SUM(CASE WHEN b.paymenttype = 64 THEN b.deliveryamt ELSE 0 END) AS paylater,
|
||||
SUM(CASE WHEN b.paymenttype = 43 THEN b.deliveryamt ELSE 0 END) AS payondelivery,
|
||||
SUM(CASE WHEN b.orderstatus = 'delivered' THEN b.deliveryamt ELSE 0 END) AS deliveryamt
|
||||
@@ -460,40 +475,40 @@ func (r *deliveriesRepository) GetReportSummary(tid, pid, uid, aid int, fdate, t
|
||||
case tid != 0:
|
||||
if fdate != "" && tdate != "" {
|
||||
q1 = reports + ` WHERE a.tenantid=` + strconv.Itoa(tid) +
|
||||
` AND a.orderdate::date BETWEEN '` + fdate + `' AND '` + tdate + `' GROUP BY a.tenantid, b.tenantname`
|
||||
` AND a.orderdate::date BETWEEN '` + fdate + `' AND '` + tdate + `' GROUP BY b.tenantid, b.tenantname`
|
||||
} else {
|
||||
q1 = reports + ` WHERE a.tenantid=` + strconv.Itoa(tid) + ` GROUP BY a.tenantid, b.tenantname`
|
||||
q1 = reports + ` WHERE a.tenantid=` + strconv.Itoa(tid) + ` GROUP BY b.tenantid, b.tenantname`
|
||||
}
|
||||
|
||||
case pid != 0:
|
||||
if fdate != "" && tdate != "" {
|
||||
q1 = reports + ` WHERE a.partnerid=` + strconv.Itoa(pid) +
|
||||
` AND a.orderdate::date BETWEEN '` + fdate + `' AND '` + tdate + `' GROUP BY a.tenantid, b.tenantname`
|
||||
` AND a.orderdate::date BETWEEN '` + fdate + `' AND '` + tdate + `' GROUP BY b.tenantid, b.tenantname`
|
||||
} else {
|
||||
q1 = reports + ` WHERE a.partnerid=` + strconv.Itoa(pid) + ` GROUP BY a.tenantid, b.tenantname`
|
||||
q1 = reports + ` WHERE a.partnerid=` + strconv.Itoa(pid) + ` GROUP BY b.tenantid, b.tenantname`
|
||||
}
|
||||
|
||||
case uid != 0:
|
||||
if fdate != "" && tdate != "" {
|
||||
q1 = reports + ` WHERE c.userid=` + strconv.Itoa(uid) +
|
||||
` AND a.orderdate::date BETWEEN '` + fdate + `' AND '` + tdate + `' GROUP BY a.tenantid, b.tenantname`
|
||||
` AND a.orderdate::date BETWEEN '` + fdate + `' AND '` + tdate + `' GROUP BY b.tenantid, b.tenantname`
|
||||
} else {
|
||||
q1 = reports + ` WHERE c.userid=` + strconv.Itoa(uid) + ` GROUP BY a.tenantid, b.tenantname`
|
||||
q1 = reports + ` WHERE c.userid=` + strconv.Itoa(uid) + ` GROUP BY b.tenantid, b.tenantname`
|
||||
}
|
||||
|
||||
case aid != 0:
|
||||
if fdate != "" && tdate != "" {
|
||||
q1 = reports + ` WHERE c.applocationid=` + strconv.Itoa(aid) +
|
||||
` AND a.orderdate::date BETWEEN '` + fdate + `' AND '` + tdate + `' GROUP BY a.tenantid, b.tenantname`
|
||||
` AND a.orderdate::date BETWEEN '` + fdate + `' AND '` + tdate + `' GROUP BY b.tenantid, b.tenantname`
|
||||
} else {
|
||||
q1 = reports + ` WHERE c.applocationid=` + strconv.Itoa(aid) + ` GROUP BY a.tenantid, b.tenantname`
|
||||
q1 = reports + ` WHERE c.applocationid=` + strconv.Itoa(aid) + ` GROUP BY b.tenantid, b.tenantname`
|
||||
}
|
||||
|
||||
default:
|
||||
if fdate != "" && tdate != "" {
|
||||
q1 = reports + ` WHERE a.orderdate::date BETWEEN '` + fdate + `' AND '` + tdate + `' GROUP BY a.tenantid, b.tenantname`
|
||||
q1 = reports + ` WHERE a.orderdate::date BETWEEN '` + fdate + `' AND '` + tdate + `' GROUP BY b.tenantid, b.tenantname`
|
||||
} else {
|
||||
q1 = reports + ` GROUP BY a.tenantid, b.tenantname`
|
||||
q1 = reports + ` GROUP BY b.tenantid, b.tenantname`
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user