COMPILE ROUTINE FIX_PART(Dummy)
ROWDEF(CHARSTR)

DECLARE SUBROUTINE obj_Schedule,Send_Dyn,Send_Infom, obj_Order, obj_WO_Log, RList, RList, ErrMsg
DECLARE SUBROUTIne  Set_Status, Send_Info, Btree.Extract
DECLARE FUNCTION Get_Status, Set_Printer, Collect.IXVals

$INSERT ORDER_DET_EQU
$INSERT PART_EQUATES
$INSERT COMPANY_EQU
$INSERT QUOTE_SPEC_EQU
$INSERT PROD_SPEC_EQU


OPEN 'PART' TO PartTable  ELSE
	DEBUG
	GOTO Bail
END

OPEN 'CUST_PART' TO CustPartTable ELSE
	DEBUG
	GOTO BAil
END

OPEN 'PART_WORK' TO PartWorkTable ELSE
	DEBUG
	GOTO Bail
END

OPEN 'DICT.PART_WORK' TO DictVar ELSE
	DEBUG
	GOTO Bail
END

OPEN 'PROD_SPEC' TO ProdSpecTable ELSE
	DEBUG
	GOTO Bail
END


SELECT PartTable

DEBUG

RecCnt = 0
Done = 0
LOOP
	READNEXT PartNo ELSE Done = 1
UNTIL Done
	
	READ PartRec FROM PartTable,PartNo THEN
		RecCnt += 1
		Send_Info(RecCnt)
		
		PSNs = PartRec<PART_PROC_STEP_PSN$>
		
		PSCnt = COUNT(PSNs,@VM) + (PSNs NE '')
		
		FOR I = 1 TO PSCnt
			PSNo = PSNs<1,I>
			
			
			READ PSRec FROM ProdSpecTable,PSNo THEN
				LOCATE PartNo IN PSRec<134> BY 'AR' USING @VM SETTING Pos ELSE
					PSRec = INSERT(PSRec,134,Pos,0,PartNo)
				END
	
				WRITE PSRec ON ProdSpecTable,PSNo THEN
					Send_Dyn('PSN ':PSNo:' Updated ':PSRec<134>)
				END
			END	;* End of PSRec Read
		NEXT I
		
	END

REPEAT


GOTO Bail

* * * * * * * * * * * * * * * * * * * * * *

SELECT PartTable

RecCnt = 0
Done = 0
LOOP
	READNEXT PartNo ELSE Done = 1
UNTIL Done
	
	READ PartRec FROM PartTable,PartNo THEN
		RecCnt += 1
		
		Send_Info(RecCnt)
		
		PSNs = PartRec<PART_PROC_STEP_PSN$>
		
		ShipPSN = PSNs[-1,'B':@VM]
		
		ProdSpecRec = XLATE('PROD_SPEC',ShipPSN,'','X')
		
		WriteFlag = 0
		
		ShipReactType = ProdSpecRec<PROD_SPEC_REACTOR_TYPE$>
		
		IF ShipReactType NE '' THEN
		
			BEGIN CASE
				CASE ShipReactType = 'A'	; ReactType = 'ASM+'
				CASE ShipReactType = 'P'	; ReactType = 'EPP'
				CASE ShipReactType = 'E'	; ReactType = 'EPS'
				CASE ShipReactType = 'H'	; ReactType = 'HTR'
				CASE ShipReactType = 'C'	; ReactType = 'SIG'
				CASE 1						; ReactType = ''
			END CASE
			
			PartRec<PART_REACT_TYPE$> = ReactType
			
			WriteFlag = 1
		END
			
		IF PartRec<PART_CUST_NO$> = '' THEN
			PartRec<PART_CUST_NO$> = ProdSpecRec<PROD_SPEC_CUST_ID$>
			WriteFlag = 1
		END
		
		
		L1 = ProdSpecRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubBl1Dopant$>
		L2 = ProdSpecRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubBl2Dopant$>
		L3 = ProdSpecRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubBl3Dopant$>
		
		
		PartRec<PART_SUB_BL_DOPANT$> = ''
		
		IF L1 NE '' THEN
			PartRec<PART_SUB_BL_DOPANT$,-1> = L1
		END
			
		IF L2 NE '' THEN
			PartRec<PART_SUB_BL_DOPANT$,-1> = L2
		END	
		
		IF L3 NE '' THEN
			PartRec<PART_SUB_BL_DOPANT$,-1> = L3
		END
		
		IF PartRec<PART_SUB_BL_DOPANT$> NE '' THEN WriteFlag = 1
		
		IF WriteFlag = 1 THEN
			WRITE PartRec ON PartTable,PartNo THEN
				Send_Dyn('Part ':PartNo:' - ':PartRec<PART_SUB_BL_DOPANT$>)
			END
		END			
	END
REPEAT




GOTO Bail

OPEN 'DICT.PART' TO PartDict ELSE
	DEBUG
	GOTO Bail
END

SELECT PartTable

DEBUG

RecCnt = 0
Done = 0
LOOP
	READNEXT PartNo ELSE Done = 1
UNTIL Done
	
	READ PartRec FROM PartTable,PartNo THEN
		RecCnt += 1
		
		Send_Info(RecCnt)
		
		PSNStatus = XLATE('PART',PartNo,'PSN_STATUS','X')
		
		PartRec<PART_STATUS$> = PSNStatus
		
	*	WRITE PartRec ON PartTable,PartNo THEN
			*Send_Dyn('Part ':PartNo:' - ':PSNStatus)
	*	END			
	END
REPEAT

*/
* * * * * * *
Bail:
* * * * * * *

END
