Versões comparadas

Chave

  • Esta linha foi adicionada.
  • Esta linha foi removida.
  • A formatação mudou.

...

RDMAKE


Bloco de código
languagejs
themeMidnight
firstline001
linenumberstrue
#include "protheus.ch" 
#include "totvs.ch"

User Function FIXSEQBX()
 
    MsApp():New( "SIGAFIN" )
    oApp:cInternet  := Nil
    __cInterNet := NIL
    oApp:bMainInit  := { || ( oApp:lFlat := .F. , WizardSeq() , FnQuit(oApp) ) } 
    oApp:CreateEnv()
    OpenSM0()
 
    PtSetTheme( "TEMAP10" )
    SetFunName( "FIXSEQBX" )
    oApp:lMessageBar := .T.
 
    oApp:Activate()
 
Return Nil

Static Function WizardSeq()

    Local oWizard   As Object
    Local aBrowse   As Array

    Static __TmpTbl As Object
    
    __TmpTbl := NIL
    aBrowse := {}
    oWizard := FwWizardControl():New()
    oWizard:ActiveUISteps()

	//----------------------------
	// Pagina 1 - Presentación
	//----------------------------
	o1stPage := oWizard:AddStep("1STSTEP",{|Panel| cria_pn1(Panel)}) 
	o1stPage:SetStepDescription("Presentación") 							 
	o1stPage:SetNextTitle("Avanzar") 		 							  
	o1stPage:SetNextAction({||.T.}) 	 							 
	o1stPage:SetCancelAction({||.T.})       

	//---------------------------------------
	// Pagina 2 - Selección del grupo de empresas
	//---------------------------------------
	o2ndPage := oWizard:AddStep("2RDSTEP", {|Panel|cria_pn2(Panel,@aBrowse)})   
	o2ndPage:SetStepDescription("Grupo de empresa")                              
	o2ndPage:SetNextTitle("Avanzar") 									  
	o2ndPage:SetPrevTitle("Regresar") 									  
	o2ndPage:SetNextAction({|| .T.}) 
	o2ndPage:SetPrevWhen({|| .F. })
	o2ndPage:SetCancelAction({|| .T.})

	//----------------------------
	// Pagina 3 - Aviso de la copia de seguridad
    //----------------------------
	o3rdPage := oWizard:AddStep("3NDSTEP", {|Panel|cria_pn3(Panel,aBrowse)})
	o3rdPage:SetStepDescription("Avisos") 							  
	o3rdPage:SetNextTitle("Finalizar") 									 
	o3rdPage:SetPrevTitle("Regresar") 									  
	o3rdPage:SetNextAction({|| ExecFix(aBrowse) }) 
	o3rdPage:SetPrevAction({|| .T.}) 							  
	o3rdPage:SetCancelAction({|| .T.}) 						   

	oWizard:Activate()
	oWizard:Destroy()

Return

Static Function cria_pn1(oPanel As Object)

	Local oSay0 AS Object
	Local oSay1 AS Object
	Local oSay2 AS Object
	Local oFont	AS Object
    Local oFont2 AS Object
	
	oFont := TFont():New( ,, -25, .T., .T.,,,,, )
    oFont2 := TFont():New("Arial",,-15,,.F.,,,,,,.F.,.F.)	
	oSay0 := TSay():New(010,015, {|| "Ajuste sequencia de baja" }, oPanel,,oFont ,,,,.T.,CLR_BLUE, ) 
	oSay1 := TSay():New(045,015, {|| "Este FIX tiene como objetivo ajustar la secuencia de baja de los campos que estuvieran"}, oPanel,,oFont2,,,,.T.,CLR_BLACK,)
    oSay1 := TSay():New(060,015, {|| "contenidos en el grupo de campos 134 - Secuencia de baja"}, oPanel,,oFont2,,,,.T.,CLR_BLACK,)
	oSay2 := TSay():New(075,015, {|| "Haga clic en la opción avanzar para continuar" }, oPanel,,oFont2,,,,.T.,CLR_BLACK,) 

Return

Static Function cria_pn2(oPanel,aBrowse)
    Local oMrkBrowse
    Local nX := 0
    Local oOk      		:= LoadBitMap(GetResources(), "LBOK")
    Local oNo      		:= LoadBitMap(GetResources(), "LBNO")   

    aGrupo := FWAllGrpCompany()

    For nX := 1 to len(aGrupo)
        Aadd(aBrowse,{.F.,aGrupo[nX],FWGrpName(aGrupo[nX])})
    Next nX

    oMrkBrowse := TWBrowse():New( 010 , 010 , (oPanel:nClientWidth/2 - 020) , oPanel:nClientHeight/2 - 020  ,,,,oPanel,,,,,{|| IIF(!Empty(aBrowse[oMrkBrowse:nAt][2]), aBrowse[oMrkBrowse:nAt][1] := !aBrowse[oMrkBrowse:nAt][1] , '') , oMrkBrowse:Refresh() },,,,,,,.F.,,.T.,,.F.,,, )
    oMrkBrowse:SetArray(aBrowse)

    oMrkBrowse:AddColumn(TCColumn():New(""						, {|| Iif(aBrowse[oMrkBrowse:nAt][1],oOK,oNO)}	,,,,'CENTER'	,20,.T.,.F.,,,,.F.,))
    oMrkBrowse:AddColumn(TCColumn():New("EMPRESA", {|| aBrowse[oMrkBrowse:nAt][2] }	,,,,'LEFT'	    ,40,.F.,.F.,,,,.F.,))
    oMrkBrowse:AddColumn(TCColumn():New("DESCRIPCIÓN", {|| aBrowse[oMrkBrowse:nAt][3] }	,,,,'LEFT'	    ,70,.F.,.F.,,,,.F.,))

Return 

Static Function cria_pn3(oPanel As Object, aBrowse As Array)

	Local oSay0 AS Object
	Local oSay1 AS Object
	Local oFont	AS Object
    Local oFont2 AS Object
	
	oFont := TFont():New( ,, -25, .T., .T.,,,,, )
    oFont2 := TFont():New("Arial",,-15,,.F.,,,,,,.F.,.F.)	
	oSay0 := TSay():New(010,015, {|| "Verificación del entorno" }, oPanel,,oFont ,,,,.T.,CLR_BLUE, ) 
	oSay1 := TSay():New(045,015, {|| "Ejecute el proceso en modo exclusivo"}, oPanel,,oFont2,,,,.T.,CLR_BLACK,)
    oSay1 := TSay():New(060,015, {|| "Ejecute el FIX en una base de homologación para validar los ajustes"}, oPanel,,oFont2,,,,.T.,CLR_BLACK,)
    oSay1 := TSay():New(075,015, {|| "Haga la copia de seguridad de la base de datos antes de iniciar la ejecución"}, oPanel,,oFont2,,,,.T.,CLR_BLACK,)

Return

Static Function ExecFix(aBrowse As Array)
    Local nX As Numeric 
    Local aTables := {"SE2","SE5","FK2","FK1","FK5","SE1"}

    For nX := 1 to Len(aBrowse)
        If aBrowse[nX][1]
            FWMsgRun(, {|| StartRPC(aBrowse[nX][2],aTables) }, "Procesando", "Actualizando datos empresa "+aBrowse[nX][2])   
        Endif    
    Next nX

Return .T.

Static Function StartRPC(cGrpEmp,aTables)

    RpcSetType(3)
    RpcSetEnv( cGrpEmp,,,,,,aTables,,,.T. )
      
    FnSeqBx()
    RpcClearEnv()  
Return

Static Function FnSeqBx()
    Local aTables := {}
    Local nX := 0
    Local cAlias := ""
    Local nY := 0
    Local nTamNew := 0
    Local cLogMsg := ""
    
    aFields := FWSX3Util():GetAllGroupFields( "134" )
    
    //Utilizo el tamaño de cualquier campo, pues todos tendrán el mismo tamaño
    nTamNew := FWSX3Util():GetFieldStruct( aFields[1] )[3]

    For nY := 1 to Len(aFields)
        cAlias := SUBSTR(aFields[nY], 1, AT("_", aFields[nY]) - 1) 
        If Len(cAlias) == 2
            cAlias := "S"+cAlias
        Endif    
        Aadd(aTables,{cAlias,aFields[nY]})
    Next nY    

    For nX := 1 to Len(aTables)
        UPDATETBL(aTables[nX][1],aTables[nX][2],nTamNew,@cLogMsg)
    Next nX

    If TCSPExist("UPDTMP_"+cEmpAnt)
	    If TcSqlExec("DROP PROCEDURE UPDTMP_"+cEmpAnt) <> 0
            Conou("Error al borrar Stored procedure "+ TcSqlError())
        Endif    
	EndIf

    FnLog(cLogMsg)

Return

Static Function UPDATETBL(cTable,cField,nTamNew,cLogMsg)
    Local cQuery := ""
    Local cErro  := ""
    Local cOut   := ""
    Local cRet  := ""
    Local nError := 0
    Local lRet  := .T.
    Local cAliasQry := ""
    Local cCampo := cTable + "->" + cField
    
    If TCSPExist("UPDTMP_"+cEmpAnt)
	    If TcSqlExec("DROP PROCEDURE UPDTMP_"+cEmpAnt) <> 0
            lRet := .F.
        Endif    
	EndIf

    If lRet
        If Alltrim(TcGetDB()) == "ORACLE"
            cQuery := "SELECT R_E_C_N_O_ RECNO" 
            cQuery += "FROM "+RetSqlName(cTable) + " " 
            cQuery += "WHERE "+cField+" <> '' AND D_E_L_E_T_ = '' "
            
            cQuery := ChangeQuery(cQuery)
            cAliasQry := MpSysOpenQuery(cQuery)
            
            (cAliasQry)->(DbGotop())
            DbSelectArea(cTable)
            If (cAliasQry)->(!EOF())
                WHILE (cAliasQry)->(!EOF())
                    &(cTable)->(DbGoto((cAliasQry)->RECNO))
                    
                    If Len(ALLTRIM(&cCampo)) < nTamNew
                        cZero := Replicate("0", nTamNew - Len(ALLTRIM(&cCampo))) 
                        Reclock(cTable,.F.)
                            Do Case
                                CASE cTable == "FIP"
                                    FIP->FIP_SEQBX := cZero + ALLTRIM(FIP->FIP_SEQBX)
                                CASE cTable == "FIS"
                                    FIS->FIS_SEQBX := cZero + ALLTRIM(FIS->FIS_SEQBX)
                                CASE cTable == "FK1"
                                    FK1->FK1_SEQ := cZero + ALLTRIM(FK1->FK1_SEQ)
                                CASE cTable == "FK2"
                                    FK2->FK2_SEQ := cZero + ALLTRIM(FK2->FK2_SEQ)
                                CASE cTable == "FK5"
                                    FK5->FK5_SEQ := cZero + ALLTRIM(FK5->FK5_SEQ)
                                CASE cTable == "FR2"
                                    FR2->FR2_SEQBX  := cZero + ALLTRIM(FR2->FR2_SEQBX)   
                                CASE cTable == "GZK"
                                    GZK->GZK_SEQ  := cZero + ALLTRIM(GZK->GZK_SEQ)
                                CASE cTable == "MDM"
                                    MDM->MDM_SEQ  := cZero + ALLTRIM(MDM->MDM_SEQ)
                                CASE cTable == "N9G"
                                    N9G->N9G_SEQBXA  := cZero + ALLTRIM(N9G->N9G_SEQBXA)
                                CASE cTable == "SE1"
                                    SE1->E1_SEQBX  := cZero + ALLTRIM(SE1->E1_SEQBX)
                                CASE cTable == "SE2"
                                    SE2->E2_SEQBX  := cZero + ALLTRIM(SE2->E2_SEQBX)
                                CASE cTable == "SE5"    
                                    SE5->E5_SEQ  := cZero + ALLTRIM(SE5->E5_SEQ)
                                CASE cTable == "SEI"
                                    SEI->EI_SEQ  := cZero + ALLTRIM(SEI->EI_SEQ)
                                CASE cTable == "SEV"
                                    SEV->EV_SEQ  := cZero + ALLTRIM(SEV->EV_SEQ)
                                CASE cTable == "SEZ"
                                    SEZ->EZ_SEQ  := cZero + ALLTRIM(SEZ->EZ_SEQ)
                                CASE cTable == "SFQ"
                                    SFQ->FQ_SEQORI := cZero + ALLTRIM(SFQ->FQ_SEQORI)
                                CASE cTable == "SFQ"   
                                    SFQ->FQ_SEQDES := cZero + ALLTRIM(SFQ->FQ_SEQDES)   
                            END CASE          
                        MsUnLock()
                    Endif        
                    (cAliasQry)->(DbSkip())    
                ENDDO
                cLogMsg += 'Actualización ejecutada con éxito, Tabla '+cTable+ ' Actualizada ' + chr(10)
            Endif    
        Else    
            cQuery := "CREATE PROCEDURE UPDTMP_" + cEmpAnt + " AS " + CRLF
            cQuery += 	"DECLARE CUR_SEQUEN CURSOR FOR SELECT  "+cField+", R_E_C_N_O_ " + CRLF 
            cQuery +=    "FROM "+RetSqlName(cTable) + CRLF + " "
            cQuery +=    "WHERE "+cField+" <> '' AND LEN("+cField+") < "+cValTochar(nTamNew+1)+" AND D_E_L_E_T_ = '' " + CRLF 
            cQuery += 	"DECLARE @NEWSEQ CHAR(4) " + CRLF
            cQuery += 	"DECLARE @FIELD CHAR(10) " + CRLF
            cQuery += 	"DECLARE @RECNO INT " + CRLF

            cQuery += 	"OPEN CUR_SEQUEN " + CRLF

            cQuery += 	"FETCH NEXT FROM CUR_SEQUEN " + CRLF
            cQuery += 	"INTO @FIELD, @RECNO " + CRLF

            cQuery += 	"WHILE @@FETCH_STATUS = 0 " + CRLF
            cQuery += 		"BEGIN " + CRLF
            cQuery += 			"SELECT @NEWSEQ = REPLICATE( '0' ,"+cValTochar(nTamNew)+" - LEN(@FIELD)) || @FIELD " + CRLF
            cQuery += 			"UPDATE "+RetSqlName(cTable)+" SET "+cField+" = @NEWSEQ WHERE R_E_C_N_O_ = @RECNO " + CRLF 

            cQuery += 			"FETCH NEXT FROM CUR_SEQUEN " + CRLF
            cQuery += 			"INTO @FIELD, @RECNO " + CRLF
            cQuery += 		"END " + CRLF

            cQuery += 	"CLOSE CUR_SEQUEN " + CRLF
            cQuery += 	"DEALLOCATE CUR_SEQUEN " + CRLF

            cRet := msparsefull(cQuery,Alltrim(TcGetDB()), @cErro, @cOut)
        
            If cRet == '1'
                cLogMsg += "Resultado: ¡Parse de la query ejecutado con éxito!" + chr(10)
                nError := TcSqlExec(cOut)

                If nError < 0
                    cLogMsg += 'Error en la creación de la Stored Procedure : ' + TcSqlError() + chr(10)
                Else    
                    TCSPEXEC( xProcedures("UPDTMP") )
                    If !Empty(TcSqlError())
                        cLogMsg += 'Error en la creación de la Stored Procedure : ' + TcSqlError() + chr(10) 
                    Else
                        cLogMsg += 'Procedure ejecutada con éxito, Tabla '+cTable+ ' Actualizada ' + chr(10)
                    Endif
                Endif
            Else
                cLogMsg += "Resultado: ¡Falla!" + chr(10) + "Error: " + cErro + chr(10) + "Parcial: " + cOut
            Endif
        Endif
    Endif  

Return

Static Function FnLog(cLogText)  
    Local cLogFile  As Character 
    Local cLogHead  As Character 
    Local lContinua As Logical 
    Local nHandle   As Numeric 

    lContinua := .T. 
    cLogFile := "\SYSTEM\FIXSEQBX.log"

    If !File(cLogFile)
        nHandle := FCreate( cLogFile ) 
        If nHandle == -1 
            lContinua := .F. 
        Else 
            cLogHead:= DToC(date()) + CRLF
            FSeek ( nHandle, 0, 2 )	// Marca al final del archivo.
            FWrite( nHandle, cLogHead, Len(cLogHead) )
            FClose(nHandle)

        EndIf 
    EndIf 

    If lContinua
        // Graba el texto en el Archivo de LOG
        cLogText := "Ejecución de la THREAD" + "[" + AllTrim(Str(ThreadID())) + "]" + CRLF + cLogText;

        nHandle := FOpen(cLogFile, 2 )
        FSeek ( nHandle, 0, 2 )	// Marca al final del archivo.
        FWrite( nHandle, cLogText, Len(cLogText) )
        FClose( nHandle )
    EndIf   

Return

Static  Static Function FnQuit(oApp)

    oApp:CreateEnv()
        
    MsgInfo("Se generó un archivo de log en la system con el nombre FIXSEQBX.log con lalas informacióninformaciones de la ejecución","LOG de procesamiento")
    Final__Quit()
 "Finalización normal" , "" )
Return    
Return

   



03. TABLAS UTILIZADAS

Este RDMAKE realiza realiza la corrección en las tablas donde los campos pertenecen al grupo 134 (SXG - Grupo de campos)

...