delivery slot updated in orders and deliveries

This commit is contained in:
2026-10-06 19:37:08 +05:30
parent 03ae7d310b
commit a30763d323
5 changed files with 274 additions and 6 deletions

View File

@@ -120,13 +120,26 @@ const (
a.riderslat,a.riderslon,a.deliveryamt,a.kms,a.actualkms,a.riderkms,a.deliverycharges,a.deliverytype,a.paymenttype,a.smsdelivery,
a.expecteddeliverytime,a.profit,a.transitminutes,a.calculationdistancekm,
a.notes,a.ordernotes,b.tenantname,b.primarycontact as tenantcontactno,b.tenanttoken,b.suburb as tenantsuburb,b.city as tenantcity,
c.firstname AS ridername,c.userfcmtoken,e.locationname,e.suburb AS locationsuburb,e.contactno AS locationcontactno
c.firstname AS ridername,c.userfcmtoken,e.locationname,e.suburb AS locationsuburb,e.contactno AS locationcontactno,
-- The delivery window, read from the ORDER.
--
-- The deliveries table has no window column and deliberately gets none:
-- the window is a fact about what the customer asked for, and copying it
-- here would be a second truth that can drift from the first. The
-- dispatch board is exactly where drift would be noticed and exactly where
-- it would cost the most, so it is joined.
o.deliveryslotid, o.deliveryslotdate, s.slotkey, s.name AS deliveryslotname,
s.starttime AS deliveryslotstart, s.endtime AS deliveryslotend
FROM deliveries a
INNER JOIN tenants b ON a.tenantid=b.tenantid
INNER JOIN app_users c ON a.userid=c.userid
INNER JOIN tenantlocations e ON a.locationid=e.locationid
INNER JOIN app_location f ON a.applocationid = f.applocationid
INNER JOIN app_locationconfig g ON f.applocationid = g.applocationid`
INNER JOIN app_locationconfig g ON f.applocationid = g.applocationid
-- Both LEFT. Most deliveries have no window, and every one of them must
-- still appear on the board — an INNER JOIN here would empty dispatch.
LEFT JOIN orders o ON a.orderheaderid = o.orderheaderid
LEFT JOIN deliveryslots s ON o.deliveryslotid = s.slotid`
)
func (r *deliveriesRepository) CreateDeliveries(data []models.Deliveries) error {

View File

@@ -102,14 +102,30 @@ const (
a.deliveryid AS deliverycustomerid, a.deliveryid, a.deliveryaddress, a.deliverylat, a.deliverylong, a.deliverytype,
a.deliverycustomer,a.deliverycontactno,a.deliverylocation as deliverysuburb, a.deliverycity, a.paymenttype, a.smsdelivery, b.customertoken,
c.tenantname, c.tenanttoken, c.primarycontact AS tenantcontactno, c.postcode AS tenantpostcode, c.suburb AS tenantsuburb, c.city AS tenantcity,
d.locationname, d.contactno AS locationcontactno, d.postcode AS locationpostcode, d.suburb AS locationsuburb, d.city AS locationcity
d.locationname, d.contactno AS locationcontactno, d.postcode AS locationpostcode, d.suburb AS locationsuburb, d.city AS locationcity,
-- The delivery window the customer asked for.
--
-- Selected EXPLICITLY, like everything else here: this select names its
-- columns, so a field added to the Go struct and not added to this line
-- is simply absent from every row, with nothing anywhere saying so. That
-- exact gap shipped once on products.showhealthscore and made every
-- reading taken from the list meaningless.
--
-- The NAME is joined rather than stored on the order, so a shop that
-- renames "Evening" to "After work" sees the new name on old orders --
-- the window they chose has not changed, only what it is called.
a.deliveryslotid, a.deliveryslotdate, s.slotkey, s.name AS deliveryslotname,
s.starttime AS deliveryslotstart, s.endtime AS deliveryslotend
FROM orders a
LEFT JOIN customers b ON a.customerid = b.customerid
LEFT JOIN tenants c ON a.tenantid = c.tenantid
LEFT JOIN tenantlocations d ON a.locationid = d.locationid
LEFT JOIN app_location h ON a.applocationid = h.applocationid
LEFT JOIN app_locationconfig i ON a.applocationid = i.applocationid`
LEFT JOIN app_locationconfig i ON a.applocationid = i.applocationid
-- LEFT, because the overwhelming majority of orders have no window and
-- must still appear. An INNER JOIN here would silently empty the list.
LEFT JOIN deliveryslots s ON a.deliveryslotid = s.slotid`
orderdetails = `SELECT DISTINCT a.orderheaderid, a.applocationid,
a.tenantid, a.locationid, a.partnerid, a.configid, a.categoryid, a.subcategoryid, a.moduleid,