Compile function Lot_Services(@Service, @Params) #pragma precomp SRP_PreCompiler Declare function TEST_WAFER_PROD_SERVICES, SRP_Datetime, Datetime, Database_Services, Lot_Services, Error_Services, RTI_CREATEGUID Declare function SRP_Array, SRP_Json Declare subroutine Database_Services, Btree.Extract, Lot_Services, Error_Services, Labeling_Services, SRP_Json $insert LOGICAL $Insert LOT_EQUATES $Insert TEST_WAFER_PROD_EQUATES $Insert Lot_Operation_Equates $Insert PRODUCT_OPERATION_EQUATES $Insert LOT_EVENT_EQUATES Options EVENT_TYPES = 'MOVE_IN', 'MOVE_OUT', 'HOLD_ON', 'HOLD_OFF', 'REDUCE_WAFER_QTY', 'BONUS_WAFER_QTY', 'COMMENT', 'LOCATION' Options LOT_TYPES = 'TW', 'RDS', 'WM_OUT', 'WM_IN' GoToService Return Response or "" //----------------------------------------------------------------------------- // SERVICES //----------------------------------------------------------------------------- Service GenerateNewLotId(LotType) NewLotID = '' RightNow = Datetime() If LotType NE '' then ValidLotNum = False$ GeneratedLotID = '' Begin Case Case LotType EQ 'TW' Loop Until ValidLotNum EQ True$ LotPrefix = 'TW' LotYear = SRP_Datetime('Year', RightNow) LotMonth = SRP_Datetime('Month', RightNow) LotDay = SRP_Datetime('Day', RightNow) LotTime = SRP_Datetime('Time', RightNow) GeneratedLotId = LotPrefix : LotYear : LotMonth : LotDay : LotTime If Not(RowExists('LOT', GeneratedLotId)) then ValidLotNum = True$ end else ValidLotNum = False$ RightNow = Datetime() end Repeat Case OTHERWISE$ //null End Case If GeneratedLotID NE '' AND ValidLotNum then //Write the new lot id now so it's reserved Database_Services('WriteDataRow', 'LOT', GeneratedLotID, '') If RowExists('LOT', GeneratedLotID) then NewLotID = GeneratedLotID end end end Response = NewLotID end service Service CreateNewTestWaferLot(LotType, ProdName, LotQty, VendorPartNo, VendorLotNo, VendorCode, Username, PrinterID) CreatedLotNumber = '' ErrorMessage = '' If LotType EQ 'TW' then If ProdName NE '' then TWProdID = Test_Wafer_Prod_Services('GetTestWaferProdIDsByPartName', ProdName) If TWProdID NE '' then If DCount(TWProdID, @VM) EQ 1 then NewLotId = Lot_Services('GenerateNewLotId', 'TW') If NewLotId NE '' then If RowExists('LOT', NewLotId) then LotRec = Database_Services('ReadDataRow', 'LOT', NewLotId) //Ensure the lot record is empty If LotRec EQ '' AND LotRec EQ '' AND LotRec EQ '' AND LotRec EQ '' then LotRec = LotType LotRec = TWProdID LotRec = LotQty LotRec = LotQty LotRec = VendorPartNo LotRec = VendorLotNo LotRec = VendorCode Database_Services('WriteDataRow', 'LOT', NewLotId, LotRec) //Now Ensure that the written lot matches what was just written LotRecCheck = Database_Services('ReadDataRow', 'LOT', NewLotId) If LotRecCheck EQ LotRec then //Lot Created successfully CreatedLotNumber = NewLotId If RowExists('LOT', CreatedLotNumber) then Lot_Services('CreateInitialLotOperationRecords', CreatedLotNumber) If Error_Services('NoError') then //Check in at first operation //Get Curr Operation(Should be first one in sequence) ThisLotCurrOpId = Lot_Services('GetLotCurrOperation', CreatedLotNumber) If ThisLotCurrOpId NE '' then Lot_Services('MoveInLot', NewLotId, LotQty, Username) If PrinterID NE 'WEB' then Labeling_Services('PrintTestWaferLotLabel', CreatedLotNumber, Username, PrinterID) end Lot_Services('MoveOutLot', NewLotId, LotQty, Username) Lot_Services('MoveInLot', NewLotId, LotQty, Username) end else //Error: Error getting current operation end end else //Error: Failed to initialize lot operations end end end else //Lot attributes didn't write correctly. end end else //Error: Lot already had data end end else //Error creating new lot ID end end else //Error getting new Lot ID end end else //Ambiguous Product name, multiple results. end end else //No Matching part no found end end else ErrorMessage = 'Null value passed in for ProdID' end end else ErrorMessage = 'Lot type was not test wafer' end Response = CreatedLotNumber End Service Service GenerateInitialLotOperationRecords(LotId) If LotID NE '' then if RowExists('LOT', LotId) then LotRec = Database_Services('ReadDataRow', 'LOT', LotId) ProdID = LotRec If ProdID NE '' then //Get product operations ThisLotOperations = Lot_Services('GetPrescribedOperationsByProdId', ProdId) If ThisLotOperations NE '' then for each ProdOperationKey in ThisLotOperations using @FM OperationRec = Database_Services('ReadDataRow', 'PRODUCT_OPERATION', ProdOperationKey) //NewOperationRecID = Next operation end else //Error: No Operations returned end end else //Error: Prod ID for lot is null end //ID will be LotNum + OperationID //Get product operations end else //error: lot does not exist end end else //error: null lot id end end service Service GetPrescribedOperationsByProdId(ProdId, ProdType) ProdOperationKeys = '' If ProdId NE '' then Begin Case Case ProdType = 'TW' ProdRec = Database_Services('ReadDataRow', 'TEST_WAFER_PROD', ProdId) ProdOperationKeys = ProdRec Case Otherwise$ //error, no matching prod type. End Case end else //Error: ProdID was null end Response = ProdOperationKeys end service Service CreateInitialLotOperationRecords(LotId) If LotId NE '' then LotRec = Database_Services('ReadDataRow', 'LOT', LotId) LotType = LotRec ProdId = LotRec ThisInitialProdOperations = Lot_Services('GetPrescribedOperationsByProdId', ProdId, LotType) For each ProdOperation in ThisInitialProdOperations using @VM ProdOperationRec = Database_Services('ReadDataRow', 'PRODUCT_OPERATION', ProdOperation) OperationID = ProdOperationRec OperationSequence = ProdOperationRec LotOperationRecID = LotId : '*' : OperationID If Not(RowExists('LOT_OPERATION', LotOperationRecID)) then LotOperationRec = '' LotOperationRec = LotId LotOperationRec = OperationID LotOperationRec = OperationSequence LotOperationRec = False$ Database_Services('WriteDataRow', 'LOT_OPERATION', LotOperationRecId, LotOperationRec) TestRec = Database_Services('ReadDataRow', 'LOT', LotId) end else //Error: Lot Operation already existed, cannot overwrite end Next Operation end else //Error: Lot ID was null end TestRec = Database_Services('ReadDataRow', 'LOT', LotId) end service //Returns a @FM delimited list of operations in sequence Service GetLotOperationSequence(LotId) LotOperationsInSequence = '' If LotID NE '' then //Get Operations LotOperations = Xlate('LOT', LotId, LOT_LOT_OPERATIONS$, 'X') for each LotOperation in LotOperations using @VM ThisLotOperationSequence = Xlate('LOT_OPERATION', LotOperation, LOT_OPERATION_OPERATION_SEQUENCE$, 'X') LotOperationsInSequence = LotOperation Next LotOperation end else //error: lot id was null end Response = LotOperationsInSequence end service //Returns a @FM delimited list of events in sequence Service GetLotEventsInSequence(LotId) LotEventsUnsorted = '' LotEventsSorted = '' LotEventsToReturn = '' If LotID NE '' then //Get Operations LotEvents = Xlate('LOT', LotId, LOT_LOT_EVENTS$, 'X') for each LotEvent in LotEvents using @VM ThisEventSequence = XLATE('LOT_EVENT', LotEvent, LOT_EVENT_SEQUENCE$, 'X') LotEventsToReturn = LotEvent Next LotOperation end else //error: lot id was null end Response = LotEventsToReturn end service Service GetLotCurrOperation(LotId) CurrOperation = '' If LotID NE '' then //Get them in sequence first LotOperationsInSequence = Lot_Services('GetLotOperationSequence', LotId) for each LotOperation in LotOperationsInSequence using @FM ThisLotOperationStartDTM = Xlate('LOT_OPERATION', LotOperation, LOT_OPERATION_DATETIME_IN$, 'X') ThisLotOperationEndDTM = Xlate('LOT_OPERATION', LotOperation, LOT_OPERATION_DATETIME_OUT$, 'X') If ThisLotOperationEndDTM Eq '' then CurrOperation = LotOperation end until CurrOperation Next LotOperation end else //error: lot id was null end Response = CurrOperation end service Service AddLotOperationIntoSequence(LotId, NewOperationId, NewSequence, Rework) ErrorMessage = '' If LotId NE '' then If NewSequence NE '' AND Num(NewSequence) then //Get Current Operations in sequence //CurrSequence = Lot_Services('GetLotOperationSequence', LotId) LotCurrOperation = Lot_Services('GetLotCurrOperation', LotId) CurrOperationSequence = Xlate('LOT_OPERATION', LotCurrOperation, LOT_OPERATION_OPERATION_SEQUENCE$, 'X') If CurrOperationSequence LE NewSequence then //Get Curr Operation Sequence Done = False$ LotCurrOperationSequence = Lot_Services('GetLotOperationSequence', LotId) for each Operation in LotCurrOperationSequence using @Fm setting OpPos ThisOperationRec = Database_Services('ReadDataRow', 'LOT_OPERATION', Operation) ThisOperationSequence = ThisOperationRec If ThisOperationSequence GE NewSequence then NewOperationSequence = ThisOperationSequence + 1 ThisOperationRec = NewOperationSequence Database_Services('WriteDataRow', 'LOT_OPERATION', Operation, ThisOperationRec) If Error_Services('HasError') then Done = True$ ErrorMessage = Error_Services('GetMessage') end end Until Done Next Operation If ErrorMessage EQ '' then LotOperationRecID = LotId : '*' : NewOperationId If Not(RowExists('LOT_OPERATION', LotOperationRecID)) then LotOperationRec = '' LotOperationRec = LotId LotOperationRec = NewOperationId LotOperationRec = NewSequence LotOperationRec = Rework Database_Services('WriteDataRow', 'LOT_OPERATION', LotOperationRecId, LotOperationRec) end else //Error: Lot Operation already existed, cannot overwrite end end end else //Error: Not allowed to add new operations prior to current operation end end else //Error: null or invalid sequence passed to routine end end else //Error: Lot id was null end If ErrorMessage NE '' then Error_Services('Add', ErrorMessage) end end service Service MoveInLot(LotID, WaferQty, Operator) If LotId NE '' then If WaferQty NE '' then If RowExists('LOT', LotId) then ThisLotRec = Database_Services('ReadDataRow', 'LOT', LotId) //Possibly Add locking here If Error_Services('NoError') then ThisLotCurrOperationID = Lot_Services('GetLotCurrOperation', LotId) If ThisLotCurrOperationID NE '' then ThisLotCurrOperationRec = Database_Services('ReadDataRow', 'LOT_OPERATION', ThisLotCurrOperationID) ThisLotCurrOperationRec = Datetime() ThisLotCurrOperationRec = WaferQty ThisLotCurrOperationRec = Operator Database_Services('WriteDataRow', 'LOT_OPERATION', ThisLotCurrOperationID, ThisLotCurrOperationRec) If Error_Services('NoError') then LotType = XLATE('LOT', LotId, LOT_TYPE$, 'X') CurrOperation = XLATE('LOT_OPERATION', ThisLotCurrOperationID, LOT_OPERATION_OPERATION_ID$, 'X') Lot_Services('CreateLotEvent', LotId, LotType, Datetime(), 'MOVE_IN', '', '', 0, 0, CurrOperation, Operator) end end //Log to Lot Event Table end else //Error: Error reading record end end else //Error Invalid Lot id entered end end else //Error: Wafer Qty was null end end else //Error: Lot Id was null end end service Service MoveOutLot(LotID, WaferQty, Operator) If LotId NE '' then If WaferQty NE '' then If RowExists('LOT', LotId) then ThisLotRec = Database_Services('ReadDataRow', 'LOT', LotId) CurrLotQty = ThisLotRec BonusQty = 0 ReduceQty = 0 If WaferQty NE CurrLotQty then Begin Case Case WaferQty GT CurrLotQty //Addition of wafers BonusQty = WaferQty - CurrLotQty Case WaferQty LT CurrLotQty ReduceQty = CurrLotQty - WaferQty End Case end //Possibly Add locking here If Error_Services('NoError') then ThisLotCurrOperationID = Lot_Services('GetLotCurrOperation', LotId) If ThisLotCurrOperationID NE '' then ThisLotCurrOperationRec = Database_Services('ReadDataRow', 'LOT_OPERATION', ThisLotCurrOperationID) ThisLotCurrOperationRec = Datetime() ThisLotCurrOperationRec = WaferQty ThisLotCurrOperationRec = Operator Database_Services('WriteDataRow', 'LOT_OPERATION', ThisLotCurrOperationID, ThisLotCurrOperationRec) If Error_Services('NoError') then LotType = XLATE('LOT', LotId, LOT_TYPE$, 'X') CurrOperation = XLATE('LOT_OPERATION', ThisLotCurrOperationID, LOT_OPERATION_OPERATION_ID$, 'X') Lot_Services('CreateLotEvent', LotId, LotType, Datetime(), 'MOVE_OUT', '', '', ReduceQty, BonusQty, CurrOperation, Operator) end end //Log to lot event table. end else //Error: Error reading record end end else //Error Invalid Lot id entered end end else //Error: Wafer Qty was null end end else //Error: Lot Id was null end end service Service CreateLotEvent(LotId, LotType=LOT_TYPES, EventDatetime, EventType=EVENT_TYPES, EventNote, EventEquipmentId, ReduceWaferQty, BonusWaferQty, OperationId, OperatorId) If LotId NE '' then Begin Case Case LotType EQ 'TW' If EventType NE '' AND OperatorId NE '' then If RowExists('LOT', LotId) then ValidId = False$ NewEventId = '' Loop NewEventId = RTI_CreateGUID() If Not(RowExists('LOT_EVENT', NewEventId)) then ValidId = True$ end Until ValidId EQ True$ Repeat BeginWaferQty = Xlate('LOT', LotId, LOT_WAFER_QTY$, 'X') If OperationID EQ '' then OperationID = Lot_Services('GetLotCurrOperation', LotId) OperationID = XLATE('LOT_OPERATION', OperationID, LOT_OPERATION_OPERATION_ID$, 'X') end If ReduceWaferQty NE '' then If Num(ReduceWaferQty) then EndWaferQty = BeginWaferQty - ReduceWaferQty end end If BonusWaferQty NE '' then If Num(BonusWaferQty) then EndWaferQty = BeginWaferQty + BonusWaferQty end end NewEventRec = '' NewEventRec = LotId NewEventRec = EventType NewEventRec = EventDatetime NewEventRec = EventNote NewEventRec = EventEquipmentId NewEventRec = ReduceWaferQty NewEventRec = BonusWaferQty NewEventRec = BeginWaferQty NewEventRec = EndWaferQty NewEventRec = OperationId NewEventRec = OperatorId NewEventSequence = Lot_Services('GetLotEventNextSequence', LotId) NewEventRec = NewEventSequence Database_Services('WriteDataRow', 'LOT_EVENT', NewEventId, NewEventRec) end else //Error: Nonexistent Lot Id passed to routine end end else //Error Missing Parameter end Case LotType EQ 'RDS' null Case LotType EQ 'WM_OUT' null Case LotType EQ 'WM_IN' null Case Otherwise$ //Error: Invalid LotType Passed to routine End Case end else //Error: Lot ID was null end end service Service GetLotEventNextSequence(LotId) ErrorMessage = '' NextSequence = 1 If LotID NE '' then If RowExists('LOT', LotId) then LotEvents = XLATE('LOT', LotId, LOT_LOT_EVENTS$, 'X') for each LotEvent in LotEvents using @VM ThisEventSequence = XLATE('LOT_EVENT', LotEvent, LOT_EVENT_SEQUENCE$, 'X') If ThisEventSequence GE NextSequence then NextSequence = ThisEventSequence + 1 Next LotEvent end else ErrorMessage = 'Unable to get lot event sequence: Lot ID not found.' end end else ErrorMessage = 'Unable to get lot event sequence: Lot ID was null.' end If ErrorMessage EQ '' then Response = NextSequence end else Error_Services('Add', ErrorMessage) end end service Service ConvertLotRecordToJson(LotId, ItemURL, CurrUser, FullObject=BOOLEAN) ErrorMessage = '' JsonString = '' If FullObject EQ '' then FullObject = True$ end If RowExists('LOT', LotId) then objJSON = '' If SRP_JSON(objJSON, 'New', 'Object') then LotRec = Database_Services('ReadDataRow', 'LOT', LotId) If Error_Services('NoError') then If SRP_JSON(objLot, 'New', 'Object') then SRP_JSON(objLot, 'SetValue', 'LotId', LotId) SRP_JSON(objLot, 'SetValue', 'Type', LotRec) SRP_JSON(objLot, 'SetValue', 'ProdId', LotRec) Begin Case Case LotRec = 'TW' ProdName = XLATE('TEST_WAFER_PROD', LotRec, TEST_WAFER_PROD_PART_NAME$, 'X') Case Otherwise$ ProdName = '' End Case SRP_JSON(objLot, 'SetValue', 'ProdName', ProdName) SRP_JSON(objLot, 'SetValue', 'OrigWaferQty', LotRec) SRP_JSON(objLot, 'SetValue', 'WaferQty', LotRec) SRP_JSON(objLot, 'SetValue', 'VendorPartNo', LotRec) SRP_JSON(objLot, 'SetValue', 'VendorLotNo', LotRec) If FullObject then //Events Array EventsArrayJson = '' If SRP_Json(EventsArrayJson, 'New', 'Array') then LotEventKeys = Lot_Services('GetLotEventsInSequence', LotId) for each LotEventKey in LotEventKeys using @FM objEvent = '' EventRec = Database_Services('ReadDataRow', 'LOT_EVENT', LotEventKey) If SRP_Json(objEvent, 'New', 'Object') then SRP_JSON(objEvent, 'SetValue', 'LotEventId', LotEventKey) SRP_JSON(objEvent, 'SetValue', 'LotId', EventRec) SRP_JSON(objEvent, 'SetValue', 'LotEventType', EventRec) SRP_JSON(objEvent, 'SetValue', 'EventDatetime', OConv(EventRec, 'DT')) SRP_JSON(objEvent, 'SetValue', 'EventNote', EventRec) SRP_JSON(objEvent, 'SetValue', 'EquipmentId', EventRec) SRP_JSON(objEvent, 'SetValue', 'EventReduceWaferQty', EventRec) SRP_JSON(objEvent, 'SetValue', 'EventBonusWaferQty', EventRec) SRP_JSON(objEvent, 'SetValue', 'EventBeginWaferQty', EventRec) SRP_JSON(objEvent, 'SetValue', 'EventEndWaferQty', EventRec) SRP_JSON(objEvent, 'SetValue', 'EventOperationId', EventRec) SRP_JSON(objEvent, 'SetValue', 'EventOperatorId', EventRec) SRP_JSON(objEvent, 'SetValue', 'Sequence', EventRec) SRP_JSON(EventsArrayJson, 'Add', objEvent) SRP_JSON(objEvent, 'Release') end Next LotEventKey SRP_JSON(objLot, 'Set', 'LotEvents', EventsArrayJson) SRP_JSON(EventsArrayJson, 'Release') end else ErrorMessage = 'Error Creating Events JSON Array' end //Operations Array OperationsArrayJson = '' If SRP_Json(OperationsArrayJson, 'New', 'Array') then LotOperationKeys = Lot_Services('GetLotOperationSequence', LotId) for each LotOperationKey in LotOperationKeys using @FM objOperation = '' OperationRec = Database_Services('ReadDataRow', 'LOT_OPERATION', LotOperationKey) If SRP_Json(objOperation, 'New', 'Object') then SRP_JSON(objOperation, 'SetValue', 'LotOperationId', LotOperationKey) SRP_JSON(objOperation, 'SetValue', 'LotId', OperationRec) SRP_JSON(objOperation, 'SetValue', 'OperationId', OperationRec) SRP_JSON(objOperation, 'SetValue', 'DatetimeIn', OConv(OperationRec, 'DT')) SRP_JSON(objOperation, 'SetValue', 'DatetimeOut', Oconv(OperationRec, 'DT')) SRP_JSON(objOperation, 'SetValue', 'EquipmentId', OperationRec) SRP_JSON(objOperation, 'SetValue', 'WaferInQty', OperationRec) SRP_JSON(objOperation, 'SetValue', 'WaferOutQty', OperationRec) SRP_JSON(objOperation, 'SetValue', 'OperatorInId', OperationRec) SRP_JSON(objOperation, 'SetValue', 'OperatorOutId', OperationRec) SRP_JSON(objOperation, 'SetValue', 'OperationSequence', OperationRec) SRP_JSON(objOperation, 'SetValue', 'Rework', OperationRec) SRP_JSON(objOperation, 'SetValue', 'DatetimeStart', OConv(OperationRec, 'DT')) SRP_JSON(objOperation, 'SetValue', 'DatetimeStop', OConv(OperationRec, 'DT')) SRP_JSON(OperationsArrayJson, 'Add', objOperation) SRP_JSON(objOperation, 'Release') end Next LotOperationKey SRP_JSON(objLot, 'Set', 'LotOperations', OperationsArrayJson) SRP_JSON(OperationsArrayJson, 'Release') end else ErrorMessage = 'Error Creating Operations JSON Array' end end SRP_JSON(objJSON, 'Set', 'Lot', objLot) SRP_JSON(objLot, 'Release') end else ErrorMessage = 'Error creating new Lot Json Object' end end else ErrorMessage = 'Error reading ':LotId:' from lot table.' end JsonString = SRP_JSON(objJSON, 'Stringify', 'Styled') SRP_JSON(objJSON, 'Release') end else ErrorMessage = 'Error creating new Json Object' end end else ErrorMessage = 'Invalid or null lot number passed to routine.' end If ErrorMessage NE '' then Error_Services('Add', ErrorMessage) end Response = JsonString end service