Olá pessoal, tudo bem? Alguém que tenha experiência com MVC em advpl poderia me dar uma luz de como adequar esse ponto de entrada do GCT, segue código tradicional:
User Function CN120ENCMD()
Local cQuery := ""
Private aSaldo := {} Private nSaldoP := 0 Private nSaldoT := 0 Private nSaldoX := 0 Private nParc := 0 Private cTipo := "" Private oButton1 Private oButton2 Private oRadMenu1 Private nRadMenu1 := 1 Private oSay1 Private oDlgx
//VERIFICA SE É UM PEDIDO DE COMPRA OU VENDA PARA TRATAR SE1 OU SE2 cQuery := " SELECT CN1ESPCTR FROM "+RetSqlName("CN9")+" CN9 " cQuery += " INNER JOIN "+RetSqlName("CN1")+" CN1 ON CN1.D_E_L_E_T = '' AND CN1CODIGO = CN9_TPCTO " cQuery += " WHERE CN9.D_E_L_E_T = '' " cQuery += " AND CN9_NUMERO = '"+CND->CND_CONTRA+"' " cQuery := ChangeQuery(cQuery) dbUseArea(.T., "TOPCONN", TCGenQry(,,cQuery), 'TMPA', .T., .F.)
DbSelectArea("TMPA") DbGoTop()
cTipo := AllTrim(TMPA->CN1_ESPCTR)
DbSelectArea("TMPA") DbCloseArea()
If AllTrim(cTipo) == '2' //VENDA //TRATAMENTO PARA PREENCHER OS CAMPOS DE HISTORICO E MENSAGEM NOTA NA SE1 cQuery := " SELECT RE_C_N_O AS RECCNE FROM "+RetSqlName("CNE") cQuery += " WHERE DE_L_E_T = '' " cQuery += " AND CNE_CONTRA = '"+CND->CND_CONTRA+"' " cQuery += " AND CNE_NUMMED = '"+CND->CND_NUMMED+"' " cQuery := ChangeQuery(cQuery) dbUseArea(.T., "TOPCONN", TCGenQry(,,cQuery), 'TMP', .T., .F.)
DbSelectArea("TMP") DbGoTop()
DbSelectArea("CNE") DbGoTo(TMP->RECCNE)
DbSelectArea("CN9") DbSetOrder(1) DbSeek(xFilial("CN9") + CND->CND_CONTRA + CND->CND_REVISA)
DbSelectArea("TMP") DbCloseArea()
If CNE->CNEPEDTIT == "2" cQuery := " SELECT R_E_C_N_O AS RECSE1 FROM "+RetSqlName("SE1") cQuery += " WHERE DE_L_E_T = '' " cQuery += " AND E1_MDCONTR = '"+CND->CND_CONTRA+"' " cQuery += " AND E1_MEDNUME = '"+CND->CND_NUMMED+"' " cQuery := ChangeQuery(cQuery) dbUseArea(.T., "TOPCONN", TCGenQry(,,cQuery), 'TMP', .T., .F.)
DbSelectArea("TMP") DbGoTop()
While !Eof() DbSelectArea("SE1") DbGoTo(TMP->RECSE1) RecLock("SE1",.F.) SE1->E1_XHIST := CND->CND_XHIST SE1->E1_HIST := CND->CND_XHIST SE1->E1_XMNOTA := CNE->CNE_XMNOTA SE1->E1_XOPFAT := CN9->CN9_XOPFAT SE1->E1_CCUSTO := CNE->CNE_CC // customização 21-10 MsUnLock()
DbSelectArea("TMP") DbSkip() End
DbSelectArea("TMP") DbCloseArea() EndIf Else //TRATAMENTO PARA PREENCHER OS CAMPOS DE HISTORICO E MENSAGEM NOTA NA SE2 cQuery := " SELECT RE_C_N_O AS RECCNE FROM "+RetSqlName("CNE") cQuery += " WHERE DE_L_E_T = '' " cQuery += " AND CNE_CONTRA = '"+CND->CND_CONTRA+"' " cQuery += " AND CNE_NUMMED = '"+CND->CND_NUMMED+"' " cQuery := ChangeQuery(cQuery) dbUseArea(.T., "TOPCONN", TCGenQry(,,cQuery), 'TMP', .T., .F.)
DbSelectArea("TMP") DbGoTop()
DbSelectArea("CNE") DbGoTo(TMP->RECCNE)
DbSelectArea("CN9") DbSetOrder(1) DbSeek(xFilial("CN9") + CND->CND_CONTRA + CND->CND_REVISA)
DbSelectArea("TMP") DbCloseArea()
If CNE->CNE_PEDTIT == "2"
cQuery := " SELECT RE_C_N_O AS RECSE2 FROM "+RetSqlName("SE2") cQuery += " WHERE DE_L_E_T = '' " cQuery += " AND E2_MDCONTR = '"+CND->CND_CONTRA+"' " cQuery += " AND E2_MDPLANI = '"+CND->CND_NUMERO+"' " cQuery += " AND E2_MDPARCE = '"+CND->CND_PARCEL+"' " // customização 24-07 cQuery += " AND E2_CODBAR = '' " cQuery := ChangeQuery(cQuery) dbUseArea(.T., "TOPCONN", TCGenQry(,,cQuery), 'TMP', .T., .F.)
DbSelectArea("TMP") DbGoTop()
While !Eof() DbSelectArea("SE2") DbGoTo(TMP->RECSE2) RecLock("SE2",.F.) SE2->E2_XHIST := CND->CND_XHIST SE2->E2_HIST := CND->CND_XHIST SE2->E2_CCUSTO := CNE->CNE_CC // customização If !Empty(CND->CND_XCODBA) SE2->E2_CODBAR := CND->CND_XCODBA EndIf MsUnLock()
DbSelectArea("TMP") DbSkip() End
DbSelectArea("TMP") DbCloseArea() EndIf EndIf
//TRATAMENTO PARA DISTRIBUIÇÃO DE SALDOS cQuery := " SELECT CN1MEDEVE FROM "+RetSqlName("CN9")+" CN9 " cQuery += " INNER JOIN "+RetSqlName("CN1")+" CN1 ON CN1.D_E_L_E_T = '' AND CN1CODIGO = CN9_TPCTO " cQuery += " WHERE CN9.D_E_L_E_T = '' " cQuery += " AND CN9_NUMERO = '"+CND->CND_CONTRA+"' " cQuery := ChangeQuery(cQuery) dbUseArea(.T., "TOPCONN", TCGenQry(,,cQuery), 'TMPA', .T., .F.)
DbSelectArea("TMPA") DbGoTop()
If AllTrim(TMPA->CN1MEDEVE) == "2" //SE ENTROU, VERIFICAR SE O CNF TEM SALDO A SER DISTRIBUIDO cQuery := " SELECT SUM(CNF_SALDO) AS CNF_SALDO FROM "+RetSqlName("CNF") cQuery += " WHERE D_E_L_E_T = '' " cQuery += " AND CNF_CONTRA = '"+CND->CND_CONTRA+"' " cQuery += " AND CNF_SALDO <> 0 " cQuery += " AND CNF_VLREAL <> 0 " cQuery := ChangeQuery(cQuery) dbUseArea(.T., "TOPCONN", TCGenQry(,,cQuery), 'TMPB', .T., .F.)
DbSelectArea("TMPB") DbGoTop()
nSaldoT := TMPB->CNF_SALDO nSaldoX := TMPB->CNF_SALDO
DbSelectArea("TMPB") DbCloseArea()
//SE O SALDO FOR DIFERENTE DE ZERO, PERGUNTA O QUE FAZER, DISTRIBUIR, ARRASTAR PRÓXIMA PARCELA OU NADA If nSaldoT <> 0
DEFINE MSDIALOG oDlgx TITLE "Saldos" FROM 000, 000 TO 170, 200 COLORS 0, 16777215 PIXEL
@ 004, 003 SAY oSay1 PROMPT "Selecione uma das opções abaixo:" SIZE 088, 012 OF oDlgx COLORS 0, 16777215 PIXEL @ 024, 004 RADIO oRadMenu1 VAR nRadMenu1 ITEMS "Redistribuir","Arrastar","Nenhuma" SIZE 085, 031 OF oDlgx COLOR 0, 16777215 PIXEL @ 063, 024 BUTTON oButton1 PROMPT "Ok" SIZE 032, 014 OF oDlgx ACTION U_DistSaldo(nRadMenu1,cTipo,oDlgx) PIXEL @ 062, 060 BUTTON oButton2 PROMPT "Cancelar" SIZE 032, 014 OF oDlgx ACTION oDlgx:End() PIXEL
ACTIVATE MSDIALOG oDlgx CENTERED
EndIf EndIf
DbSelectArea("TMPA") DbCloseArea()
Return