#Include "TOTVS.ch"
#Include "TBICONN.ch"

User Function TCSAA100()
	Local nOpr    := 3
	Local aHeader := {}
	Local aArea   := {}

	Private lMsErroAuto := .F.
	Private lMsHelpAuto := .T.

	RPCSetEnv("99", "01", NIL, NIL, "TMK", NIL, {"SQB"})
		GetEnvInfo("CSAA100.PRW")

		aArea := GetArea()

		// BEGIN: INCLUDE //
		If (nOpr == 3)
			AAdd(aHeader, {"QB_DEPTO",      "DEPT00003"})
			AAdd(aHeader, {"QB_DESCRIC",    "QUALITY ASSURANCE"})
			AAdd(aHeader, {"QB_CC",         ""})
			AAdd(aHeader, {"QB_FILRESP",    ""})
			AAdd(aHeader, {"QB_MATRESP",    ""})
			AAdd(aHeader, {"QB_DEPSUP",     ""})
			AAdd(aHeader, {"QB_ARELIN",     ""})
		EndIf
		// END: INCLUDE //

		MsExecAuto({|w, x, y, z| CSAA100(w, x, y, z)}, NIL, NIL, aHeader, nOpr)

		If (lMsErroAuto == .T.)
			MostraErro()

			ConOut(Repl("-", 80))
			ConOut(PadC("CSAA100 automatic routine ended with error", 80))
			ConOut(PadC("Ends at: " + Time(), 80))
			ConOut(Repl("-", 80))
		Else
			ConOut(Repl("-", 80))
			ConOut(PadC("CSAA100 automatic routine successfully ended", 80))
			ConOut(PadC("Ends at: " + Time(), 80))
			ConOut(Repl("-", 80))
		EndIf

		RestArea(aArea)
	RPCClearEnv()
Return (NIL)

/*----------------------------------------------------------*\
| DESCRIPTION: This function returns environment and routine |
| information without GUI use.                               |
|------------------------------------------------------------|
| AUTHOR: Guilherme Bigois       |      MODIFIED: 2018/05/23 |
\*----------------------------------------------------------*/

Static Function GetEnvInfo(cRoutine)
	Local aRPO := {}
    Default cRoutine := ""

    aRPO := GetApoInfo(cRoutine)

    If (Empty(aRPO) == .F.)
        ConOut(Repl("-", 80))
        ConOut(PadC("Routine: " + aRPO[1], 80))
        ConOut(PadC("Date: " + DToC(aRPO[4]) + " " + aRPO[5], 80))
        ConOut(Repl("-", 80))
        ConOut(PadC("SmartClient: " + GetBuild(.T.), 80))
        ConOut(PadC("AppServer: " + GetBuild(.F.), 80))
        ConOut(PadC("DbAccess: " + TCAPIBuild() + "/MSSQL" , 80))
		ConOut(Repl("-", 80))
        ConOut(PadC("Started at: " + Time(), 80))
        ConOut(Repl("-", 80))
    Else
        ConOut(Repl("-", 80))
        ConOut(PadC("An error occurred while searching routine data with GetEnvInfo()", 80))
        ConOut(Repl("-", 80))
    EndIf
Return (NIL)
