| 37679 |
amit |
1 |
-- Backdated PO auto-approval: backfill of the POs still stuck awaiting an HOD click.
|
|
|
2 |
--
|
|
|
3 |
-- Backdated POs used to be parked in status 0 (INIT) until someone clicked a mailed approval link. INIT keeps a
|
|
|
4 |
-- PO out of the PO list, out of GRN/invoice matching and out of the auto-close sweep, so an unclicked PO is
|
|
|
5 |
-- simply frozen. 440 POs are sitting that way, going back to 2024.
|
|
|
6 |
--
|
|
|
7 |
-- Code now auto-approves at creation, so only POs that are still operationally live are worth moving. POScheduler
|
|
|
8 |
-- auto-closes READY POs older than 6 days (4 days for internal suppliers), so anything older than that window
|
|
|
9 |
-- would go READY -> CLOSED on the next cron tick and never be receivable. That leaves three:
|
|
|
10 |
--
|
|
|
11 |
-- 53974 2026-09-15 BSB Marketing (external) -- stays open
|
|
|
12 |
-- 53901 2026-09-14 BSB Marketing (external) -- stays open
|
|
|
13 |
-- 53855 2026-09-12 NSSPL UP-DLHR (internal) -- past its 4-day window, will auto-close
|
|
|
14 |
--
|
|
|
15 |
-- The creator of a historical PO was never recorded anywhere, so these are stamped SYSTEM (backfill) rather than
|
|
|
16 |
-- guessed at. New POs carry their real creator.
|
|
|
17 |
--
|
|
|
18 |
-- approvedOn is a varchar(128) holding 'YYYY-MM-DD HH:MM:SS.SSS' - that is what Hibernate writes and reads back.
|
|
|
19 |
|
|
|
20 |
-- Backup before touching anything.
|
|
|
21 |
CREATE TABLE IF NOT EXISTS warehouse.poapproval_backup_20260917 AS
|
|
|
22 |
SELECT * FROM warehouse.poapproval WHERE poId IN (53974, 53901, 53855);
|
|
|
23 |
|
|
|
24 |
CREATE TABLE IF NOT EXISTS warehouse.purchaseorder_backup_20260917 AS
|
|
|
25 |
SELECT id, status, updatedAt FROM warehouse.purchaseorder WHERE id IN (53974, 53901, 53855);
|
|
|
26 |
|
|
|
27 |
-- Stamp the approval rows, only where still genuinely unapproved.
|
|
|
28 |
UPDATE warehouse.poapproval
|
|
|
29 |
SET approvedOn = LEFT(DATE_FORMAT(NOW(3), '%Y-%m-%d %H:%i:%s.%f'), 23),
|
|
|
30 |
approvedBy = 'SYSTEM (backfill)'
|
|
|
31 |
WHERE poId IN (53974, 53901, 53855)
|
|
|
32 |
AND approvedOn IS NULL;
|
|
|
33 |
|
|
|
34 |
-- Release the POs, only where still INIT.
|
|
|
35 |
UPDATE warehouse.purchaseorder
|
|
|
36 |
SET status = 1,
|
|
|
37 |
updatedAt = NOW()
|
|
|
38 |
WHERE id IN (53974, 53901, 53855)
|
|
|
39 |
AND status = 0;
|
|
|
40 |
|
|
|
41 |
-- Verify: all three should read status 1 with an approvedBy set.
|
|
|
42 |
SELECT p.id, p.poNumber, p.status, DATE(p.createdAt) poDate, a.approvedOn, a.approvedBy
|
|
|
43 |
FROM warehouse.purchaseorder p
|
|
|
44 |
JOIN warehouse.poapproval a ON a.poId = p.id
|
|
|
45 |
WHERE p.id IN (53974, 53901, 53855);
|