#include "rwmake.ch"
#include 'tbiconn.ch'
User Function Auto450()
Local aAutoCab := {}
Local aArea := GetArea()
Local cTabSe1 := "TMPSE1A"
Local cTabSe2 := "TMPSE2A"
Local aSE1450 := {}
Local aSE2450 := {}
Local aFilCmp := {}
Private lMsHelpAuto := .F.
Private lMsErroAuto := .F.
BeginSql Alias cTabSe1
SELECT R_E_C_N_O_ as RECNO
FROM %Table:SE1% SE1
WHERE SE1.E1_FILIAL = 'D MG 01 '
AND SE1.E1_PREFIXO = 'CPT'
AND SE1.E1_NUM = 'VT001'
AND SE1.E1_TIPO = 'NF'
AND SE1.E1_CLIENTE = 'FIN001'
AND SE1.E1_LOJA = '01'
AND SE1.%NotDel%
EndSql
While (cTabSe1)->(!EOF())
SE1->(DbGoto((cTabSe1)->RECNO))
AAdd(aSE1450, {SE1->E1_FILIAL+SE1->E1_PREFIXO+SE1->E1_NUM+SE1->E1_PARCELA+SE1->E1_TIPO})
If ascan(aFilCmp,SE1->E1_FILIAL) == 0
Aadd(aFilCmp, SE1->E1_FILIAL)
EndIf
(cTabSe1)->(DbSkip())
Enddo
(cTabSe1)->(DbCloseArea())
BeginSql Alias cTabSe2
SELECT R_E_C_N_O_ as RECNO
FROM %Table:SE2% SE2
WHERE SE2.E2_FILIAL = 'D MG 02 '
AND SE2.E2_PREFIXO = 'CPT'
AND SE2.E2_NUM = 'VT001'
AND SE2.E2_TIPO = 'NF'
AND SE2.E2_FORNECE = 'FIN001'
AND SE2.E2_LOJA = '01'
AND SE2.%NotDel%
EndSql
While (cTabSe2)->(!EOF())
SE2->(DbGoto((cTabSe2)->RECNO))
AAdd(aSE2450, {SE2->E2_FILIAL+SE2->E2_PREFIXO+SE2->E2_NUM+SE2->E2_PARCELA+SE2->E2_TIPO+SE2->E2_FORNECE+SE2->E2_LOJA})
If ascan(aFilCmp,SE2->E2_FILIAL) == 0
Aadd(aFilCmp, SE2->E2_FILIAL)
EndIf
(cTabSe2)->(DbSkip())
Enddo
(cTabSe2)->(DbCloseArea())
aAutoCab :={ {"AUTDVENINI450", cTod('27/08/19') , nil},;
{"AUTDVENFIM450", cTod('27/08/19') , nil},;
{"AUTNLIM450" ,8000, nil},;
{"AUTCCLI450" , "FIN001" , nil},;
{"AUTCLJCLI" , "01" , nil},;
{"AUTCFOR450" , "FIN001" , nil},;
{"AUTCLJFOR" , "01" , nil},;
{"AUTCMOEDA450" , "01" , nil},;
{"AUTNDEBCRED" , 1 , nil},;
{"AUTLTITFUTURO", .F. , nil},;
{"AUTARECCHAVE" ,aSE1450, nil},;
{"AUTAPAGCHAVE" , aSE2450 , nil},;
{"AUTAFILCOMP" , aFilCmp , nil}}
MSExecAuto({|x,y,z| Fina450(x,y,z)}, nil , aAutoCab , 3 )
If !lMsErroAuto
ConOut("Added successfully! ")
confirmsx8()
Else
ConOut("Error when adding!")
rollbacksx8()
MostraErro()
EndIf
RestArea(aArea)
Return