How a glazing order (frame + lens) is routed to one of four portals: DC, HUB-A, HUB-B or TOG.
The logic in brief
Checks run in this order. The first match wins.
Interim mode (only when switched on): a client with a HUB is never glazed at DC. The HUB takes the order (frame from the HUB, DC or the client; lens from the HUB or DC, or a lens DC substitutes). If the HUB is over max cap, TOG takes it when it can glaze it directly, otherwise it queues at the HUB. Clients without a HUB follow the checks below.
DC: enough frame stock for the order and open jobs within max cap. The lens never blocks DC.
Client's HUB: each client has one HUB or none. That HUB needs frame stock to spare (more than the order needs), enough lens stock, and capacity.
TOG: TOG lenses only. TOG needs enough frame stock and capacity. It makes its lenses on demand. TOG uses only its own frame stock; nothing is sent to it.
Client's HUB, whatever its frame stock: a HUB within max cap that can get the lens glazes the order, because the frame never blocks it. The frame comes from the HUB's own stock (only if at least 1 frame stays after glazing), else from DC, else the client sends their own. If the HUB cannot take it and no frame is in stock at DC or the HUB, the client sends their own frame to DC.
Nothing else can take it: overflow to DC. A frame is never moved from a HUB to DC, and nothing is sent to or taken from TOG.
On every assignment, the order's frame and lens quantities are deducted from real stock and the portal's open jobs go up by one.