#INCLUDE 'Protheus.ch'
User Function MyPCPA135(nOpc)
Local aCab :={}
Local aItem := {}
Local aGets := {}
Local lOK := .T.
Local cString
Private lMsErroAuto := .F.
Default nOpc := 4
//Abertura do ambiente |
RpcSetEnv( "99" , "01" , Nil, Nil, "PCP", Nil )
ConOut(Repl("-",80))
ConOut(PadC("Teste de rotina automatica para estrutura de produtos",80))
//Verificacao do ambiente para teste |
dbSelectArea("SB1")
dbSetOrder(1)
If !SB1->(MsSeek(xFilial("SB1")+"PA001"))
lOk := .F.
ConOut("Cadastrar produto acabado: PA001")
EndIf
If !SB1->(MsSeek(xFilial("SB1")+"PI001"))
lOk := .F.
ConOut("Cadastrar produto intermediario: PI001")
EndIf
If !SB1->(MsSeek(xFilial("SB1")+"PI002"))
lOk := .F.
ConOut("Cadastrar produto intermediario: PI002")
EndIf
If !SB1->(MsSeek(xFilial("SB1")+"PI003"))
lOk := .F.
ConOut("Cadastrar produto intermediario: PA003")
EndIf
If !SB1->(MsSeek(xFilial("SB1")+"MP001"))
lOk := .F.
ConOut("Cadastrar produto materia prima: MP001")
EndIf
If !SB1->(MsSeek(xFilial("SB1")+"MP002"))
lOk := .F.
ConOut("Cadastrar produto materia prima: MP002")
EndIf
If !SB1->(MsSeek(xFilial("SB1")+"MP003"))
lOk := .F.
ConOut("Cadastrar produto materia prima: MP003")
EndIf
If !SB1->(MsSeek(xFilial("SB1")+"MP004"))
lOk := .F.
ConOut("Cadastrar produto materia prima: MP004")
EndIf
If nOpc==3 .And. lOk
aCab := { {"GG_COD" ,"PA001" ,NIL},;
{"GG_QUANT" ,2 ,NIL}}
aGets := {}
aadd(aGets, {"GG_COD" ,"PA001" ,NIL})
aadd(aGets, {"GG_COMP" ,"PI001" ,NIL})
aadd(aGets, {"GG_TRT" ," " ,NIL})
aadd(aGets, {"GG_QUANT" ,1 ,NIL})
aadd(aGets, {"GG_PERDA" ,0 ,NIL})
aadd(aGets, {"GG_INI" ,CTOD("01/01/01") ,NIL})
aadd(aGets, {"GG_FIM" ,CTOD("31/12/49") ,NIL})
aadd(aItem,aGets)
aGets := {}
aadd(aGets, {"GG_COD" ,"PA001" ,NIL})
aadd(aGets, {"GG_COMP" ,"MP001" ,NIL})
aadd(aGets, {"GG_TRT" ,Space(3) ,NIL})
aadd(aGets, {"GG_QUANT" ,1 ,NIL})
aadd(aGets, {"GG_PERDA" ,0 ,NIL})
aadd(aGets, {"GG_INI" ,CTOD("01/01/01") ,NIL})
aadd(aGets, {"GG_FIM" ,CTOD("31/12/49") ,NIL})
aadd(aItem,aGets)
aGets := {}
aadd(aGets, {"GG_COD" ,"PA001" ,NIL})
aadd(aGets, {"GG_COMP" ,"MP002" ,NIL})
aadd(aGets, {"GG_TRT" ,Space(3) ,NIL})
aadd(aGets, {"GG_QUANT" ,2 ,NIL})
aadd(aGets, {"GG_PERDA" ,0 ,NIL})
aadd(aGets, {"GG_INI" ,CTOD("01/01/01") ,NIL})
aadd(aGets, {"GG_FIM" ,CTOD("31/12/49") ,NIL})
aadd(aItem,aGets)
aGets := {}
aadd(aGets, {"GG_COD" ,"PI002" ,NIL})
aadd(aGets, {"GG_COMP" ,"MP003" ,NIL})
aadd(aGets, {"GG_TRT" ,Space(3) ,NIL})
aadd(aGets, {"GG_QUANT" ,3 ,NIL})
aadd(aGets, {"GG_PERDA" ,0 ,NIL})
aadd(aGets, {"GG_INI" ,CTOD("01/01/01") ,NIL})
aadd(aGets, {"GG_FIM" ,CTOD("31/12/49") ,NIL})
aadd(aItem,aGets)
aGets := {}
aadd(aGets, {"GG_COD" ,"PI002" ,NIL})
aadd(aGets, {"GG_COMP" ,"MP001" ,NIL})
aadd(aGets, {"GG_TRT" ,Space(3) ,NIL})
aadd(aGets, {"GG_QUANT" ,1 ,NIL})
aadd(aGets, {"GG_PERDA" ,0 ,NIL})
aadd(aGets, {"GG_INI" ,CTOD("01/01/01") ,NIL})
aadd(aGets, {"GG_FIM" ,CTOD("31/12/49") ,NIL})
aadd(aItem,aGets)
aGets := {}
aadd(aGets, {"GG_COD" ,"PI001" ,NIL})
aadd(aGets, {"GG_COMP" ,"MP002" ,NIL})
aadd(aGets, {"GG_TRT" ,Space(3) ,NIL})
aadd(aGets, {"GG_QUANT" ,1 ,NIL})
aadd(aGets, {"GG_PERDA" ,0 ,NIL})
aadd(aGets, {"GG_INI" ,CTOD("01/01/01") ,NIL})
aadd(aGets, {"GG_FIM" ,CTOD("31/12/49") ,NIL})
aadd(aItem,aGets)
aGets := {}
aadd(aGets, {"GG_COD" ,"PA001" ,NIL})
aadd(aGets, {"GG_COMP" ,"PI003" ,NIL})
aadd(aGets, {"GG_TRT" ,Space(3) ,NIL})
aadd(aGets, {"GG_QUANT" ,1 ,NIL})
aadd(aGets, {"GG_PERDA" ,0 ,NIL})
aadd(aGets, {"GG_INI" ,CTOD("01/01/01") ,NIL})
aadd(aGets, {"GG_FIM" ,CTOD("31/12/49") ,NIL})
aadd(aItem,aGets)
aGets := {}
aadd(aGets, {"GG_COD" ,"PA001" ,NIL})
aadd(aGets, {"GG_COMP" ,"MP004" ,NIL})
aadd(aGets, {"GG_TRT" ,Space(3) ,NIL})
aadd(aGets, {"GG_QUANT" ,1 ,NIL})
aadd(aGets, {"GG_PERDA" ,0 ,NIL})
aadd(aGets, {"GG_INI" ,CTOD("01/01/01") ,NIL})
aadd(aGets, {"GG_FIM" ,CTOD("31/12/49") ,NIL})
aadd(aItem,aGets)
aGets := {}
aadd(aGets, {"GG_COD" ,"PI003" ,NIL})
aadd(aGets, {"GG_COMP" ,"MP003" ,NIL})
aadd(aGets, {"GG_TRT" ,Space(3) ,NIL})
aadd(aGets, {"GG_QUANT" ,1 ,NIL})
aadd(aGets, {"GG_PERDA" ,0 ,NIL})
aadd(aGets, {"GG_INI" ,CTOD("01/01/01") ,NIL})
aadd(aGets, {"GG_FIM" ,CTOD("31/12/49") ,NIL})
aadd(aItem,aGets)
ConOut("Teste de Inclusao")
ConOut("Inicio: "+Time())
MSExecAuto({|x,y,z| PCPA135(x,y,z)},aCab,aItem,3) //Inclusao
ConOut("Fim: "+Time())
ElseIf nOpc == 4 .And. lOk
//--------------- Exemplo de Alteração ------------------------------------
aCab := { {"GG_COD", "PA001", NIL}}
aGets := {}
aadd(aGets, {"GG_COD" ,"PA001" ,NIL})
aadd(aGets, {"GG_COMP" ,"MP001" ,NIL})
aadd(aGets, {"GG_TRT" ,Space(3) ,NIL})
aadd(aGets, {"GG_QUANT" ,5 ,NIL})
aadd(aGets, {"GG_PERDA" ,1 ,NIL})
aadd(aGets, {"GG_INI" ,CTOD("01/01/01") ,NIL})
aadd(aGets, {"GG_FIM" ,CTOD("31/12/49") ,NIL})
aAdd(aGets, {"AUTDELETA" ,"S" ,NIL})
aAdd(aGets, {"LINPOS" ,"GG_COD+GG_COMP+GG_TRT","PA001","MP001",Space(3)})
aadd(aItem,aGets)
aGets := {}
aadd(aGets, {"GG_COD" ,"PA001" ,NIL})
aadd(aGets, {"GG_COMP" ,"PI003" ,NIL})
aadd(aGets, {"GG_TRT" ,"001" ,NIL})
aadd(aGets, {"GG_QUANT" ,5 ,NIL})
aadd(aGets, {"GG_PERDA" ,1 ,NIL})
aadd(aGets, {"GG_INI" ,CTOD("01/01/20") ,NIL})
aadd(aGets, {"GG_FIM" ,CTOD("31/12/49") ,NIL})
aAdd(aGets, {"LINPOS" ,"GG_COD+GG_COMP+GG_TRT","PA001","PI003",Space(3)})
aadd(aItem,aGets)
ConOut("Teste de Alteracao")
ConOut("Inicio: "+Time())
MSExecAuto({|x,y,z| PCPA135(x,y,z)},aCab,aItem,4) //Alteração
ConOut("Fim: "+Time())
ElseIf lOk
//--------------- Exemplo de Exclusao ------------------------------------
aCab := { {"GG_COD" ,"PA001" ,NIL}}
ConOut("Teste de Exclusao do codigo PA001")
ConOut("Inicio: "+Time())
MSExecAuto({|x,y,z| PCPA135(x,y,z)},aCab,NIL,5) //Exclusao
lOk := !lMsErroAuto
ConOut("Fim: "+Time())
aCab := { {"GG_COD" ,"PI001" ,NIL}}
ConOut("Teste de Exclusao do codigo PI001")
ConOut("Inicio: "+Time())
MSExecAuto({|x,y,z| PCPA135(x,y,z)},aCab,NIL,5) //Exclusao
lOk := !lMsErroAuto
ConOut("Fim: "+Time())
aCab := { {"GG_COD" ,"PI002" ,NIL}}
ConOut("Teste de Exclusao do codigo PI002")
ConOut("Inicio: "+Time())
MSExecAuto({|x,y,z| PCPA135(x,y,z)},aCab,NIL,5) //Exclusao
lOk := !lMsErroAuto
ConOut("Fim: "+Time())
aCab := { {"GG_COD" ,"PI003" ,NIL}}
ConOut("Teste de Exclusao do codigo PI003")
ConOut("Inicio: "+Time())
MSExecAuto({|x,y,z| PCPA135(x,y,z)},aCab,NIL,5) //Exclusao
ConOut("Fim: "+Time())
EndIf
If lMsErroAuto
//MostraErro()
If IsBlind()
If IsTelnet()
VTDispFile(NomeAutoLog(),.t.)
Else
cString := MemoRead(NomeAutoLog())
Conout("Aviso de Erro:",cString)
EndIf
Else
MostraErro()
EndIf
Else
If lOk
Aviso("Aviso","Incluido com sucesso",{"Ok"})
Else
Aviso("Aviso","Fazer os devidos cadastros",{"Ok"})
EndIf
Endif
Return