46a1911c1c
Uniform stock management for healthcare linen rooms: the coordinator app, the phone counter and the staff app, for your own server. Built from 5470a36 on 2026-09-13. Licensed under the Functional Source License (FSL-1.1-ALv2).
14 lines
812 B
SQL
14 lines
812 B
SQL
-- Cost at time of issue (backfilled from the current catalogue price for existing rows)
|
|
ALTER TABLE "Issue" ADD COLUMN "cost" DOUBLE PRECISION NOT NULL DEFAULT 0;
|
|
UPDATE "Issue" i SET "cost" = c."cost" FROM "CatalogItem" c WHERE c."id" = i."itemId";
|
|
|
|
-- Back orders link to their parent order
|
|
ALTER TABLE "Order" ADD COLUMN "parentId" TEXT;
|
|
ALTER TABLE "Order" ADD CONSTRAINT "Order_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "Order"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
UPDATE "Order" b SET "parentId" = p."id"
|
|
FROM "Order" p
|
|
WHERE b."parentId" IS NULL AND b."status" IN ('Back Order','Received','Cancelled','Shipped','Ordered')
|
|
AND b."notes" LIKE 'Back order — short on ORD-%'
|
|
AND p."facilityId" = b."facilityId"
|
|
AND p."code" = substring(b."notes" from 'short on (ORD-[0-9]+-[0-9]+)');
|