Compile function RDS_LAYER_Services(@Service, @Params)
#pragma precomp SRP_PreCompiler

$Insert SERVICE_SETUP
$insert APP_INSERTS
$insert RDS_LAYER_EQUATES
$INSERT RECIPE_PARMS_EQU
$Insert RDS_Equates

Declare function   Database_Services, Error_Services, SRP_JSONX, SRP_JSONX_END, SRP_JSON, Obj_Tables, Obj_Recipe
Declare subroutine Error_Services, SRP_JSONX, SRP_JSONX_BEGIN, SRP_JSON, Obj_Tables, Set_Status, Database_Services


GoToService

Return Response or ""

//-----------------------------------------------------------------------------
// SERVICES
//-----------------------------------------------------------------------------

Service ConvertRecordToJSON(KeyID, Record, itemURL)
    
    jsonRecord    = ''

    If KeyID NE '' then
        If Record EQ '' then Record = Database_Services('ReadDataRow', 'RDS_LAYER', KeyID)
        If Error_Services('NoError') then
            @DICT       = Database_Services('GetTableHandle', 'DICT.RDS_LAYER')
            @ID         = KeyID
            @RECORD     = Record
            If SRP_JSON(objRDSLayer, 'New', 'Object') then
                SRP_JSON(objRDSLayer, 'SetValue', 'keyID', @ID)
                SRP_JSON(objRDSLayer, 'SetValue', 'EpiTime', OCONV(Record<RDS_LAYER_EPI_TIME$>, 'MD1'))
                SRP_JSON(objRDSLayer, 'SetValue', 'DiluentAdjParam', OCONV(Record<RDS_LAYER_DILUENT_ADJ_PARAM$>,'MD2'))
                SRP_JSON(objRDSLayer, 'SetValue', 'DopantFlow', OCONV(Record<RDS_LAYER_DOPANT_FLOW$>,'MD2'))
                SRP_JSON(objRDSLayer, 'SetValue', 'HCLFlow', OCONV(Record<RDS_LAYER_HCL_FLOW$>,'MD2'))
                SRP_JSON(objRDSLayer, 'SetValue', 'BakeTime', OCONV(Record<RDS_LAYER_BAKE_TIME$>,'[SECONDS_CONV]'))
                SRP_JSON(objRDSLayer, 'SetValue', 'EpiH2Flow', OCONV(Record<RDS_LAYER_EPI_H2_FLOW$>,'MD0'))
                SRP_JSON(objRDSLayer, 'SetValue', 'TCSFlow', OCONV(Record<RDS_LAYER_TCS_FLOW$>, 'MD1'))
                SRP_JSON(objRDSLayer, 'SetValue', 'DCSFlow', OCONV(Record<RDS_LAYER_DCS_FLOW$>,'MD0'))
                SRP_JSON(objRDSLayer, 'SetValue', 'FOffset', OCONV(Record<RDS_LAYER_F_OFFSET$>,'MD0'))
                SRP_JSON(objRDSLayer, 'SetValue', 'SOffset', OCONV(Record<RDS_LAYER_S_OFFSET$>,'MD0'))
                SRP_JSON(objRDSLayer, 'SetValue', 'ROffset', OCONV(Record<RDS_LAYER_R_OFFSET$>,'MD0'))
                SRP_JSON(objRDSLayer, 'SetValue', 'Etch1', OCONV(Record<RDS_LAYER_ETCH1$>,'[SECONDS_CONV]'))
                SRP_JSON(objRDSLayer, 'SetValue', 'Etch2', OCONV(Record<RDS_LAYER_ETCH2$>,'[SECONDS_CONV]'))
                SRP_JSON(objRDSLayer, 'SetValue', 'Etch3', OCONV(Record<RDS_LAYER_ETCH3$>,'[SECONDS_CONV]'))
                SRP_JSON(objRDSLayer, 'SetValue', 'AUX1', OCONV(Record<RDS_LAYER_AUX1$>,'[SECONDS_CONV]'))
                SRP_JSON(objRDSLayer, 'SetValue', 'AUX2', OCONV(Record<RDS_LAYER_AUX2$>,'[SECONDS_CONV]'))
                SRP_JSON(objRDSLayer, 'SetValue', 'ULTemp', OCONV(Record<RDS_LAYER_UL_TEMP$>,'MD0'))
                SRP_JSON(objRDSLayer, 'SetValue', 'SuscEtch', OCONV(Record<RDS_LAYER_SUSC_ETCH$>,'MD1'))
                jsonRecord = SRP_JSON(objRDSLayer, 'Stringify', 'Styled')
                SRP_JSON(objRDSLayer, 'Release')
                
            end

        end
    end else
        Error_Services('Add', 'KeyID argument was missing in the ' : Service : ' service.')
    end
    Response    = jsonRecord
end service


Service UpdateRDSLayerSpecs(RDSNo)
   
   ErrMsg = ''
    IF RDSNo = ''		THEN
        Error_Services('RDSNo parameter missing from service')
        return
    end
    
    RDSLayerKeys = Xlate('RDS', RDSNo, 'RDS_LAYER_KEYS', 'X')

    LayerCount = DCount(RDSLayerKeys, @VM)
    For I = 1 to LayerCount
        
        RLKey = RDSLayerKeys<1,I>
        LayerSet = Field(RLKey, '*', 2)

        RDSLayerRec = Database_Services('ReadDataRow', 'RDS_LAYER', RLKey, '', '', '')

        IF Error_Services('NoError') then

            RecipeNo	= RDSLayerRec<RDS_LAYER_RECIPE_NO$>
            WOStepKey	= XLATE('RDS',RDSNo,RDS_WO_STEP_KEY$,'X')
            PSNId		= XLATE('WO_STEP',WOStepKey,1,'X')

            IF INDEX(LayerSet,'L',1) THEN
                LayerLimits = obj_Recipe('GetLimits',RecipeNo:@RM:PSNId:@RM:LayerSet)

                RDSLayerRec<RDS_LAYER_RECIPE_NO$>			= RecipeNo
                RDSLayerRec<RDS_LAYER_DOPANT$>				= LayerLimits<RP_DOPANT$>

                RDSLayerRec<RDS_LAYER_EPI_DILUENT$>			= LayerLimits<RP_EPI_DILUENT$>
                
                RDSLayerRec<RDS_LAYER_EPI_TIME_MIN$>		= LayerLimits<RP_DEPOSIT_TIME_MIN$>
                RDSLayerRec<RDS_LAYER_EPI_TIME_MAX$>		= LayerLimits<RP_DEPOSIT_TIME_MAX$>
                
                RDSLayerRec<RDS_LAYER_DILUENT_MIN$>			= LayerLimits<RP_DILUENT_FLOW_MIN$>
                RDSLayerRec<RDS_LAYER_DILUENT_MAX$>			= LayerLimits<RP_DILUENT_FLOW_MAX$>
                
                RDSLayerRec<RDS_LAYER_DOPANT_FLOW_MIN$>		= LayerLimits<RP_DOPANT_FLOW_MIN$>
                RDSLayerRec<RDS_LAYER_DOPANT_FLOW_MAX$>		= LayerLimits<RP_DOPANT_FLOW_MAX$>
                
                RDSLayerRec<RDS_LAYER_HCL_FLOW_MIN$>		= LayerLimits<RP_HCL_FLOW_MIN$>
                RDSLayerRec<RDS_LAYER_HCL_FLOW_MAX$>		= LayerLimits<RP_HCL_FLOW_MAX$>
                
                RDSLayerRec<RDS_LAYER_BAKE_TIME_MIN$>		= LayerLimits<RP_BAKE_TIME_MIN$>
                RDSLayerRec<RDS_LAYER_BAKE_TIME_MAX$>		= LayerLimits<RP_BAKE_TIME_MAX$>
                
                RDSLayerRec<RDS_LAYER_EPI_H2_FLOW_MIN$>		= LayerLimits<RP_H2_FLOW_MIN$>
                RDSLayerRec<RDS_LAYER_EPI_H2_FLOW_MAX$>		= LayerLimits<RP_H2_FLOW_MAX$>
                
                RDSLayerRec<RDS_LAYER_TCS_FLOW_MIN$>		= LayerLimits<RP_TCS_FLOW_MIN$>
                RDSLayerRec<RDS_LAYER_TCS_FLOW_MAX$>		= LayerLimits<RP_TCS_FLOW_MAX$>
                
                RDSLayerRec<RDS_LAYER_DCS_FLOW_MIN$>		= LayerLimits<RP_DCS_FLOW_MIN$>
                RDSLayerRec<RDS_LAYER_DCS_FLOW_MAX$>		= LayerLimits<RP_DCS_FLOW_MAX$>
                
                RDSLayerRec<RDS_LAYER_AUX1_MIN$>			= LayerLimits<RP_AUX1_FLOW_MIN$>
                RDSLayerRec<RDS_LAYER_AUX1_MAX$>			= LayerLimits<RP_AUX1_FLOW_MAX$>
                
                RDSLayerRec<RDS_LAYER_AUX2_MIN$>			= LayerLimits<RP_AUX2_FLOW_MIN$>
                RDSLayerRec<RDS_LAYER_AUX2_MAX$>			= LayerLimits<RP_AUX2_FLOW_MAX$>
                
                RDSLayerRec<RDS_LAYER_F_OFFSET_MIN$>		= LayerLimits<RP_FOFFSET_MIN$>
                RDSLayerRec<RDS_LAYER_F_OFFSET_MAX$>		= LayerLimits<RP_FOFFSET_MAX$>
                
                RDSLayerRec<RDS_LAYER_S_OFFSET_MIN$>		= LayerLimits<RP_SOFFSET_MIN$>
                RDSLayerRec<RDS_LAYER_S_OFFSET_MAX$>		= LayerLimits<RP_SOFFSET_MAX$>
                
                RDSLayerRec<RDS_LAYER_R_OFFSET_MIN$>		= LayerLimits<RP_ROFFSET_MIN$>
                RDSLayerRec<RDS_LAYER_R_OFFSET_MAX$>		= LayerLimits<RP_ROFFSET_MAX$>
                
                RDSLayerRec<RDS_LAYER_SUSC_ETCH_MIN$>		= LayerLimits<RP_SUSC_ETCH_MIN$>
                RDSLayerRec<RDS_LAYER_SUSC_ETCH_MAX$>		= LayerLimits<RP_SUSC_ETCH_MAX$>
                
                RDSLayerRec<RDS_LAYER_ETCH1_MIN$>			= LayerLimits<RP_ETCH1_MIN$>
                RDSLayerRec<RDS_LAYER_ETCH1_MAX$>			= LayerLimits<RP_ETCH1_MAX$>
                
                RDSLayerRec<RDS_LAYER_ETCH2_MIN$>			= LayerLimits<RP_ETCH2_MIN$>
                RDSLayerRec<RDS_LAYER_ETCH2_MAX$>			= LayerLimits<RP_ETCH2_MAX$>
                
                RDSLayerRec<RDS_LAYER_ETCH3_MIN$> = LayerLimits<RP_ETCH3_MIN$>
                RDSLayerRec<RDS_LAYER_ETCH3_MAX$> = LayerLimits<RP_ETCH3_MAX$>
                
                RDSLayerRec<RDS_LAYER_UL_TEMP_MIN$> = LayerLimits<RP_UL_TEMP_MIN$>
                RDSLayerRec<RDS_LAYER_UL_TEMP_MAX$> = LayerLimits<RP_UL_TEMP_MAX$>
                
            END

            Database_Services('WriteDataRow', 'RDS_LAYER', RLKey, RDSLayerRec, True$, False$, False$)
            
        end else
            Errmsg = Error_Services('GetMessage')
        end
        
    Until Errmsg NE ''
        
    Next I
    
    If ErrMsg NE '' then Error_Services('Add',ErrMsg)
    
end service

