Show the queries powering this tab
1. Roster + attendance (anchored on jedi_master) - hrms.jedi_master LEFT JOIN hrms.attendance
-- Anchoring on jedi_master ensures the full active roster shows up - absentees too.
-- Same pattern dash.more.in uses. employee_status='A' + date_of_exit IS NULL filters to active staff.
SELECT l.loc AS store_code, jm.full_name, jm.designation, jm.employee_type,
jm.attendance_shift AS shift, jm.attendance_weeklyoff AS weekly_off,
LEFT(a.clock_in::varchar, 5) AS clock_in,
LEFT(a.clock_out::varchar, 5) AS clock_out,
CASE WHEN a.employee_id IS NULL THEN 1 ELSE 0 END AS absent,
CASE WHEN jm.attendance_weeklyoff = TO_CHAR(CURRENT_DATE, 'FMDay') THEN 1 ELSE 0 END AS is_weekly_off
FROM hrms.jedi_master jm
INNER JOIN master.loc l ON l.location_fin = jm.work_area_code_x
LEFT JOIN hrms.attendance a ON a.employee_id = jm.employee_id AND a.date = CURRENT_DATE
WHERE jm.employee_status = 'A' AND jm.date_of_exit IS NULL
AND (l.open_date >= CURRENT_DATE - INTERVAL '365 days' OR l.loc IN (1600, 4132))
ORDER BY l.loc, absent ASC, is_weekly_off DESC, a.clock_in NULLS LAST, jm.full_name;
2. GRN timing - tran.shipment
SELECT to_loc AS location_code,
(received_date AT TIME ZONE 'UTC' AT TIME ZONE 'Asia/Kolkata')::date AS dt,
CASE WHEN distro_type = 'A' THEN 'Alloc'
WHEN distro_type = 'T' THEN 'TO' ELSE 'Oth' END AS type,
COUNT(DISTINCT distro_no) AS shipments,
COUNT(DISTINCT item) AS items,
ROUND(SUM(received_qty)) AS qty,
TO_CHAR(MIN(received_date AT TIME ZONE 'UTC' AT TIME ZONE 'Asia/Kolkata'), 'HH24:MI') AS first_grn,
TO_CHAR(MAX(received_date AT TIME ZONE 'UTC' AT TIME ZONE 'Asia/Kolkata'), 'HH24:MI') AS last_grn
FROM tran.shipment
WHERE received_date >= CURRENT_DATE - 3
AND received_qty > 0
AND to_loc IN (SELECT loc FROM master.loc
WHERE open_date >= CURRENT_DATE - INTERVAL '365 days' OR loc IN (1600, 4132))
GROUP BY 1, 2, 3
ORDER BY 1, 2 DESC, 3;
3a. New Hope summary by module + section - sim.newhope_dashboard
-- Latest snapshot per store (matches dash.more.in behaviour).
SELECT nh.loc AS store_code, nh.module, nh.section,
COUNT(*) AS total_tasks,
SUM(CASE WHEN nh.is_completed = 1 THEN 1 ELSE 0 END) AS completed,
ROUND(SUM(CASE WHEN nh.is_completed = 1 THEN 1 ELSE 0 END) * 100.0
/ NULLIF(COUNT(*), 0), 1) AS pct
FROM sim.newhope_dashboard nh
INNER JOIN master.loc l ON l.loc = nh.loc
WHERE nh.create_date::date = (
SELECT MAX(create_date::date) FROM sim.newhope_dashboard WHERE loc = nh.loc
)
AND (l.open_date >= CURRENT_DATE - INTERVAL '365 days' OR l.loc IN (1600, 4132))
GROUP BY nh.loc, nh.module, nh.section;
3b. New Hope open items - tasks where is_completed = 0
-- Same task can repeat within a snapshot (e.g. OCP per shift). Group + count avoids duplicate rows.
SELECT nh.loc AS store_code, nh.module, nh.section, nh.task,
COUNT(*) AS task_count,
TO_CHAR(MAX(nh.modify_date), 'DD-Mon HH24:MI') AS last_updated
FROM sim.newhope_dashboard nh
INNER JOIN master.loc l ON l.loc = nh.loc
WHERE nh.create_date::date = (
SELECT MAX(create_date::date) FROM sim.newhope_dashboard WHERE loc = nh.loc
)
AND nh.is_completed = 0
AND (l.open_date >= CURRENT_DATE - INTERVAL '365 days' OR l.loc IN (1600, 4132))
GROUP BY nh.loc, nh.module, nh.section, nh.task
ORDER BY nh.loc, nh.module, nh.section, nh.task;
Roster is anchored on hrms.jedi_master so absent and weekly-off
employees both show up - matching how dash.more.in displays them.
Attendance join key: master.loc.location_fin (DarwinBox financial code)
maps to hrms.jedi_master.work_area_code_x.
New Hope rows older than the latest snapshot are excluded so the open-items table
shows only what's pending against today's checklist (not historical leftovers).