Versão atual:

Duvida de como alinhar um valor sql a esquerda da coluna

Não estou conseguindo alinhar uma coluna com valor do banco de dados (float) a esquerda, campo B1_XRKPROD

include 'protheus.ch'

include 'parmtype.ch'

INCLUDE "TOPCONN.CH"

INCLUDE "FWPrintSetup.ch"

INCLUDE "TBICONN.CH"

INCLUDE "COLORS.CH"

INCLUDE "RPTDEF.CH"

//CRIADA POR PEDRO SOUZA //TELA PARA SUGERIR PRODUTOS E QUANTIDADE A SER COMPRADA DAS MARCAS SELECIONADAS //A PARTIR DO ESTOQUE EM DIAS

User Function SUGESDOM() //inicializa a tela

Local cAias := "ZZ3"

PRIVATE aRotina := MenuZZ3()

DbSelectArea("ZZ3") DbSetOrder(1)

mBrowse(06, 01, 22, 75, cAias,,,,,,,,,,,,,,)

Return()

Static Function MenuZZ3() //função para criação do a Rotina (menu)

Private aRotina := {{OemToAnsi("Incluir"), "U_INCZZ3", 0, 3},; {OemToAnsi("Visualizar") , "U_VisualZZ3" , 0, 2},; {OemToAnsi("Alterar") , "U_AlterZZ3" , 0, 4},; {OemToAnsi("Excluir") , "U_DelZZ3" , 0, 5},; {OemToAnsi("Efetivar") , "U_Efetsug(M->ZZ3_COD)" , 0, 4}}

Return(aRotina)

User Function VisualZZ3(cAlias, nReg, nOpc) //função para alteração do registro posicionado

Local cSql := "" Local nOpcG := GD_INSERT + GD_UPDATE + GD_DELETE Local nOpcA := 0 Local aSize := {}, aObjects := {}, aInfo := {}, aPObjs := {} Local aArea := GetArea() //CAMPOS QUE PODERAM SER EDITADOS Local aCpoMostra := {} Local cMarca := "" Local cEst := "" Local nDias := 0 Local nQtdSug := 0 Local nVlTotal := 0 local nUltcom := 0 local nCount := 0 local nFor local aACampos := {'ZZ4_VLUNIT','ZZ4_QTDINF', 'ZZ3TINF'} Local aButtons := {} Private oZZ3, oZZ4 Private aHeader := {}, aCols := {}, nUSD2 := 0 //Private cPerg := Padr("SUGDOMA",Len(SX1->X1_GRUPO)) Private aTela := {}, aGets := {}

RegToMemory("ZZ3", .T.)

//CRIA CABEÇALHO GerHead()

cSql := " select " cSql += " ZZ4PROD, " cSql += " ZZ4_DESCP, " cSql += " B1_XRKPROD " cSql += " ZZ4_ESTDIS, " cSql += " ZZ4_MEDDIA," cSql += " ZZ4_ESTDIA, " cSql += " ZZ4_EMBA," cSql += " ZZ4_QTDSUG," cSql += " ZZ4_VLTOTA, " cSql += " ZZ4_QTDINF," cSql += " ZZ4_VLINFO," cSql += " ZZ4_VLUNIT," cSql += " ZZ4_QTDCOM," cSql += " ZZ4_CURVAD," cSql += " ZZ4_CURVAM," cSql += " ZZ4_ESTDF," cSql += " ZZ4_UNICOM" cSql += " FROM ZZ4010" cSql += " INNER JOIN SB1010" cSql += " ON B1_COD = ZZ4_PROD" cSql += " where ZZ4_COD = '" + ZZ3->ZZ3_COD + "'" cSql += " AND ZZ4010.D_E_L_E_T = ''"

cSQL := ChangeQuery(cSQL) TCQUERY cSQL NEW ALIAS "QZZ4" DbSelectArea("QZZ4") DbGoTop()

M->ZZ3_COD := ZZ3->ZZ3_COD M->ZZ3_DESCM := ZZ3->ZZ3_DESCM M->ZZ3_FORNEC := ZZ3->ZZ3_FORNEC M->ZZ3_LOJA := ZZ3->ZZ3_LOJA M->ZZ3_NFORNE := ZZ3->ZZ3_NFORNE M->ZZ3_DIASSU := ZZ3->ZZ3_DIASSU M->ZZ3_EMISSA := ZZ3->ZZ3_EMISSA M->ZZ3_DIAQTD := ZZ3->ZZ3_DIAQTD M->ZZ3_COND := ZZ3->ZZ3_COND M->ZZ3_PRAZO := ZZ3->ZZ3_PRAZO

//MONTA O ACOLS COM OS DADOS DO SELECT While !Eof() AADD(aCols ,{QZZ4->ZZ4_PROD,QZZ4->ZZ4_DESCP,QZZ4->RK_PROD,QZZ4->ZZ4_CURVAD,QZZ4->ZZ4_CURVAM,QZZ4->ZZ4_ESTDIS,QZZ4->ZZ4_MEDDIA,QZZ4->ZZ4_ESTDIA,QZZ4->ZZ4_EMBA,; QZZ4->ZZ4_QTDSUG,QZZ4->ZZ4_UNICOM,QZZ4->ZZ4_VLTOTA,QZZ4->ZZ4_QTDCOM,QZZ4->ZZ4_QTDINF,QZZ4->ZZ4_VLUNIT,QZZ4->ZZ4_VLINFO,QZZ4->ZZ4_ESTDF,.F.})

DbSelectArea("QZZ4") DBSKIP() End

DbSelectArea("QZZ4") DbCloseArea()

aSize := MsAdvSize(.T.) aObjects := {}

AAdd(aObjects, {100, 060, .T., .T.}) AAdd(aObjects, {100, 040, .T., .T.})

aInfo := {aSize[1], aSize[2], aSize[3], aSize[4], 0, 0} aPObjs := MsObjSize(aInfo, aObjects, .T.)

nOpcA := 0

DEFINE MSDIALOG oDlg TITLE "SUGESTÃO DE COMPRAS DOMA" From aSize[7], 000 To aSize[6], aSize[5] Of oMainWnd Pixel

Aadd( aButtons, {"Exportar", {|| GDToExcel(aHeader,aCols)}, "Exportar", "Exportar" , {|| .T.}} )

oZZ3 := MsMGet():New("ZZ3",, 3,,,,aCpoMostra, aPObjs[1],aCpoMostra, 3,,,,oDlg) oZZ3:oBox:Align := CONTROL_ALIGN_NONE

oZZ4 := MsNewGetDados():New(aPObjs[1, 1], aPObjs[1, 2], aPObjs[1, 3], aPObjs[1, 4], nOpcG,,,,aACampos,, 99999,,,,oDlg, aHeader, aCols ) oZZ4:oBrowse:Align := CONTROL_ALIGN_BOTTOM oZZ4:oBrowse:bHeaderClick := {|oZZ4,nCol| Ordena(nCol)} SetKey(VK_F4, {|| Funf4()})

//oZZ4:oBrowse:bSeekChange := {|| VlTotal(@oZZ4,nUltcom)}

ACTIVATE MSDIALOG oDlg ON INIT EnchoiceBar(oDlg, {|| nOpcA := 1, oDlg:End()} , {|| nOpcA := 0, oDlg:End()},,@aButtons) //ACTIVATE MSDIALOG oDlg ON INIT (EnchoiceBar(oDlg,{||lOk:=.T.,oDlg:End()},{||oDlg:End()},,@aButtons)) Return

User Function AlterZZ3(cAlias, nReg, nOpc) //função para alteração do registro posicionado

Local cSql := "" Local nOpcG := GD_INSERT + GD_UPDATE + GD_DELETE Local nOpcA := 0 Local aSize := {}, aObjects := {}, aInfo := {}, aPObjs := {} Local aArea := GetArea() //CAMPOS QUE PODERAM SER EDITADOS Local aCpoMostra := {"ZZ3_FORNEC","ZZ3_LOJA","ZZ3_NFORNE","ZZ3_COND","ZZ3_PRAZO"} Local cMarca := "" Local cEst := "" Local nDias := 0 Local nQtdSug := 0 Local nVlTotal := 0 local nUltcom := 0 local aACampos := {'ZZ4_VLUNIT','ZZ4_QTDINF', 'ZZ3TINF'} Local aButtons := {} Private oZZ3, oZZ4 Private aHeader := {}, aCols := {}, nUSD2 := 0 //Private cPerg := Padr("SUGDOMA",Len(SX1->X1_GRUPO)) Private aTela := {}, aGets := {}

RegToMemory("ZZ3", .T.)

//CRIA CABEÇALHO GerHead()

cSql := " select " cSql += " ZZ4PROD, " cSql += " ZZ4_DESCP, " cSql += " ZZ4_ESTDIS, " cSql += " ZZ4_MEDDIA," cSql += " ZZ4_ESTDIA, " cSql += " ZZ4_EMBA," cSql += " ZZ4_QTDSUG," cSql += " ZZ4_VLTOTA, " cSql += " ZZ4_QTDINF," cSql += " ZZ4_VLINFO," cSql += " ZZ4_VLUNIT," cSql += " ZZ4_QTDCOM," cSql += " ZZ4_CURVAD," cSql += " ZZ4_CURVAM," cSql += " ZZ4_ESTDF," cSql += " ZZ4_UNICOM" cSql += " ,B1_XRKPROD" cSql += " FROM ZZ4010" cSql += " INNER JOIN SB1010" cSql += " ON B1_COD = ZZ4_PROD" cSql += " where ZZ4_COD = '" + ZZ3->ZZ3_COD + "'" cSql += " AND ZZ4010.D_E_L_E_T = ''"

cSQL := ChangeQuery(cSQL) TCQUERY cSQL NEW ALIAS "QZZ4" DbSelectArea("QZZ4") DbGoTop()

M->ZZ3_COD := ZZ3->ZZ3_COD M->ZZ3_DESCM := ZZ3->ZZ3_DESCM M->ZZ3_FORNEC := ZZ3->ZZ3_FORNEC M->ZZ3_LOJA := ZZ3->ZZ3_LOJA M->ZZ3_NFORNE := ZZ3->ZZ3_NFORNE M->ZZ3_DIASSU := ZZ3->ZZ3_DIASSU M->ZZ3_EMISSA := ZZ3->ZZ3_EMISSA M->ZZ3_DIAQTD := ZZ3->ZZ3_DIAQTD M->ZZ3_COND := ZZ3->ZZ3_COND M->ZZ3_PRAZO := ZZ3->ZZ3_PRAZO

//MONTA O ACOLS COM OS DADOS DO SELECT While !Eof()

AADD(aCols ,{QZZ4->ZZ4_PROD,QZZ4->ZZ4_DESCP,QZZ4->B1_XRKPROD,QZZ4->ZZ4_CURVAD,QZZ4->ZZ4_CURVAM,QZZ4->ZZ4_ESTDIS,QZZ4->ZZ4_MEDDIA,QZZ4->ZZ4_ESTDIA,QZZ4->ZZ4_EMBA,; QZZ4->ZZ4_QTDSUG,QZZ4->ZZ4_UNICOM,QZZ4->ZZ4_VLTOTA,QZZ4->ZZ4_QTDCOM,QZZ4->ZZ4_QTDINF,ZZ4_VLUNIT,QZZ4->ZZ4_VLINFO,QZZ4->ZZ4_ESTDF,.F.})

DbSelectArea("QZZ4") DBSKIP() End

DbSelectArea("QZZ4") DbCloseArea()

aSize := MsAdvSize(.T.) aObjects := {}

AAdd( aObjects, { 100, 060, .T., .T. } ) AAdd( aObjects, { 100, 040, .T., .T. } )

aInfo := { aSize[ 1 ], aSize[ 2 ], aSize[ 3 ], aSize[ 4 ], 0, 0 } aPObjs := MsObjSize( aInfo, aObjects, .T. )

nOpcA := 0

DEFINE MSDIALOG oDlg TITLE "SUGESTÃO DE COMPRAS DOMA" From aSize[7], 000 To aSize[6], aSize[5] Of oMainWnd Pixel

Aadd( aButtons, {"Exportar", {|| GDToExcel(aHeader,aCols)}, "Exportar", "Exportar" , {|| .T.}} )

oZZ3 := MsMGet():New("ZZ3",, 3,,,,aCpoMostra, aPObjs[1],aCpoMostra, 3,,,,oDlg) oZZ3:oBox:Align := CONTROL_ALIGN_NONE

oZZ4 := MsNewGetDados():New(aPObjs[1, 1], aPObjs[1, 2], aPObjs[1, 3], aPObjs[1, 4], nOpcG,,,,aACampos,, 99999,,,,oDlg, aHeader, aCols ) oZZ4:oBrowse:Align := CONTROL_ALIGN_BOTTOM oZZ4:oBrowse:bHeaderClick := {|oZZ4,nCol| Ordena(nCol)} SetKey(VK_F4, {|| Funf4()}) //oZZ4:oBrowse:bSeekChange := {|| VlTotal(@oZZ4,nUltcom)}

ACTIVATE MSDIALOG oDlg ON INIT EnchoiceBar(oDlg,{|| AltSug()}, {|| nOpcA := 0, oDlg:End()},,@aButtons)//EnchoiceBar(oDlg, {|| nOpcA := 1, oDlg:End()} , {|| nOpcA := 0, oDlg:End()})

Return

User Function INCZZ3() //FUNÇÃO PARA ABRIR TELA DE INCLUSÃO DA SUGESTÃO

Local cCont := 1 Local cSql := "" Local nOpcG := GD_INSERT + GD_UPDATE + GD_DELETE Local nOpcA := 0 Local aSize := {}, aObjects := {}, aInfo := {}, aPObjs := {} Local aArea := GetArea() //CAMPOS QUE PODERAM SER EDITADOS Local aCpoMostra := {"ZZ3_COD","ZZ3_DESCM","ZZ3_EMISSA","ZZ3_DIASSU","ZZ3_FORNEC","ZZ3_LOJA","ZZ3_NFORNE","ZZ3_COND",; "ZZ3_PRAZO"} Local cMarca := "" Local cEst := "" Local nDias := 0 Local nQtdSug := 0 Local nVlTotal := 0 local nUltcom := 0 local aACampos := {'ZZ4_VLUNIT','ZZ4_QTDINF', 'ZZ3TINF'} Private oZZ3, oZZ4 Private aHeader := {}, aCols := {}, nUSD2 := 0 Private cPerg := "SUGDOMA" //Padr("SUGDOMA",Len(SX1->X1_GRUPO)) Private aTela := {}, aGets := {}

If !Pergunte(cPerg,.T.) Return(Nil) EndIf

cMarca := mv_par01 cEst := mv_par02 nDias := mv_par03

U_notificaMarca(cMarca)

RegToMemory("ZZ3", .T.)

//CRIA CABEÇALHO GerHead() // linha 295 modificada cSql := " select " cSql += " SB1.B1COD," cSql += " SB1.B1_DESC," cSql += " B1_XRKPROD," cSql += " (SELECT SUM(B2_QATU - B2_RESERVA) AS EST" cSql += " FROM SB2010" cSql += " WHERE SB2010.B2_COD = SB1.B1_COD" cSql += " AND B2_LOCAL != '03'" cSql += " AND B2_LOCAL != '04'" cSql += " AND B2_LOCAL != '53'" cSql += " AND B2_LOCAL != '07'" cSql += " AND B2_LOCAL != '57'" cSql += " AND B2_LOCAL != '54') AS EST," cSql += " SB1.B1_XMDIA," cSql += " SB1.B1_ESTDIA," cSql += " B1_CONV," cSql += " B1_XDESCM," cSql += " (CASE WHEN ((SELECT TOP 1 D1_VUNIT FROM SD1010" cSql += " WHERE D1_COD = SB1.B1_COD" cSql += " AND SD1010.D_E_L_E_T = '' AND D1TIPO = 'N'" cSql += " ORDER BY D1_DTDIGIT DESC) IS NOT NULL) " cSql += " THEN (SELECT TOP 1 round((D1_TOTAL-D1_VALDESC)/D1_QUANT,4) FROM SD1010" cSql += " WHERE D1_COD = SB1.B1_COD" cSql += " AND SD1010.D_E_L_E_T = '' AND D1TIPO = 'N'" cSql += " ORDER BY D1_DTDIGIT DESC) " cSql += " ELSE ((SELECT TOP 1 Z9_PRCVEN FROM SZ9010" cSql += " WHERE Z9_CODBARR = SB1.B1_COD" cSql += " AND SZ9010.D_E_L_E_T = '' AND Z9ESTOQUE = 'E'" cSql += " ORDER BY Z9_EMISSAO DESC))" cSql += " END) AS ULTCOM," cSql += " 0 AS ZZ4_QTDINF," cSql += " 0 AS ZZ4_VLINFO," cSql += " (SELECT" cSql += " SUM(C7_QUANT - C7_QUJE) AS QUANT" cSql += " FROM SC7010 SC7" cSql += " INNER JOIN SB1010 ON SC7.C7_PRODUTO = SB1.B1_COD" cSql += " AND SB1.D_E_L_E_T = ''" cSql += " WHERE SC7.DE_L_E_T = ''" cSql += " AND SC7.C7ENCER = ''" cSql += " AND B1_COD = SB1.B1_COD) AS COMPRA," cSql += " B1_CURVAD," cSql += " B1_CURVAM" cSql += " from SB1010 SB1" cSql += " WHERE SB1.D_E_L_E_T = '' AND SB1.B1_MSBLQL = '2'" cSql += " AND SB1.B1_XMARCA in (" + STRTRAN(ALLTRIM(cMarca),"\",",") + ")" If ALLTRIM(cEst) != "" cSql += " AND SB1.B1_ESTDIA < '" + cEst + "'" EndIf cSql += " AND SB1.B1_TIPO = 'PA'"

cSQL := ChangeQuery(cSQL) TCQUERY cSQL NEW ALIAS "QZZ4" DbSelectArea("QZZ4") DbGoTop()

M->ZZ3_DIASSU := ALLTRIM(cEst) M->ZZ3_EMISSA := Date() M->ZZ3_DIAQTD := ALLTRIM(nDias)

//MONTA O ACOLS COM OS DADOS DO SELECT While !Eof()

nQtdSug := 0 nUltcom := 0

IF ALLTRIM(QZZ4->B1_XDESCM) $ ALLTRIM(M->ZZ3_DESCM) else if cCont = 1 M->ZZ3_DESCM := ALLTRIM(QZZ4->B1_XDESCM) else M->ZZ3_DESCM += "," + ALLTRIM(QZZ4->B1_XDESCM) endif ENDIF

//PREENCHE A QUANTIDADE SUGERIADA COM O NUMERO DE DIAS INFOMADO MEDIA DIA - ESTOQUE DISPONIVEL nQtdSug := ((VAL(nDias) QZZ4->B1_XMDIA) - QZZ4->EST) - QZZ4->COMPRA

if nQtdSug < 0 nQtdSug := 0 EndIf

nQtdSug := ROUND(nQtdSug,0) //FAZ A QUANTIDADE DISPONIVEL O VALOR TOTAL nVlTotal := nQtdSug ULTCOM nUltcom := ULTCOM

AADD(aCols ,{QZZ4->B1_COD,QZZ4->B1_DESC, QZZ4->B1_XRKPROD,10, QZZ4->B1_CURVAD,QZZ4->B1_CURVAM,QZZ4->EST,QZZ4->B1_XMDIA,QZZ4->B1_ESTDIA,QZZ4->B1_CONV,; nQtdSug,nUltcom,nVlTotal,QZZ4->COMPRA,QZZ4->ZZ4_QTDINF,nUltcom,QZZ4->ZZ4_VLINFO,QZZ4->B1_ESTDIA,.F.})

DbSelectArea("QZZ4") DBSKIP() cCont++ End

DbSelectArea("QZZ4") DbCloseArea()

aSize := MsAdvSize(.T.) aObjects := {}

AAdd( aObjects, { 100, 060, .T., .T. } ) AAdd( aObjects, { 100, 040, .T., .T. } )

aInfo := { aSize[ 1 ], aSize[ 2 ], aSize[ 3 ], aSize[ 4 ], 0, 0 } aPObjs := MsObjSize( aInfo, aObjects, .T. )

nOpcA := 0

DEFINE MSDIALOG oDlg TITLE "SUGESTÃO DE COMPRAS DOMA" From aSize[7], 000 To aSize[6], aSize[5] Of oMainWnd Pixel

oZZ3 := MsMGet():New("ZZ3",, 3,,,,aCpoMostra, aPObjs[1],aCpoMostra, 3,,,,oDlg) oZZ3:oBox:Align := CONTROL_ALIGN_NONE

oZZ4 := MsNewGetDados():New(aPObjs[1, 1], aPObjs[1, 2], aPObjs[1, 3], aPObjs[1, 4], nOpcG,,,,aACampos,, 99999,,,,oDlg, aHeader, aCols ) oZZ4:oBrowse:Align := CONTROL_ALIGN_BOTTOM oZZ4:oBrowse:bHeaderClick := {|oZZ4,nCol| Ordena(nCol)} SetKey(VK_F4, {|| Funf4()}) //oZZ4:oBrowse:bSeekChange := {|| VlTotal(@oZZ4,nUltcom)}

ACTIVATE MSDIALOG oDlg ON INIT EnchoiceBar(oDlg,{|| GravaSug()}, {|| nOpcA := 0, oDlg:End()})//EnchoiceBar(oDlg, {|| nOpcA := 1, oDlg:End()} , {|| nOpcA := 0, oDlg:End()})

Return()

User Function DelZZ3(cAlias, nReg, nOpc) //função para alteração do registro posicionado

Local cSql := "" Local nOpcG := GD_INSERT + GD_UPDATE + GD_DELETE Local nOpcA := 0 Local aSize := {}, aObjects := {}, aInfo := {}, aPObjs := {} Local aArea := GetArea() //CAMPOS QUE PODERAM SER EDITADOS Local aCpoMostra := {} Local cMarca := "" Local cEst := "" Local nDias := 0 Local nQtdSug := 0 Local nVlTotal := 0 local nUltcom := 0 local aACampos := {'ZZ4_VLUNIT','ZZ4_QTDINF', 'ZZ3TINF'} Private oZZ3, oZZ4 Private aHeader := {}, aCols := {}, nUSD2 := 0

Private aTela := {}, aGets := {}

RegToMemory("ZZ3", .T.)

//CRIA CABEÇALHO GerHead()

cSql := " select " cSql += " ZZ4PROD, " cSql += " ZZ4_DESCP, " cSql += " ZZ4_ESTDIS, " cSql += " ZZ4_MEDDIA," cSql += " ZZ4_ESTDIA, " cSql += " ZZ4_EMBA," cSql += " ZZ4_QTDSUG," cSql += " ZZ4_VLTOTA, " cSql += " ZZ4_QTDINF," cSql += " ZZ4_VLINFO," cSql += " ZZ4_VLUNIT," cSql += " ZZ4_QTDCOM," cSql += " ZZ4_CURVAD," cSql += " ZZ4_CURVAM," cSql += " ZZ4_ESTDF," cSql += " ZZ4_UNICOM" cSql += " ,B1_XRKPROD" cSql += " FROM ZZ4010" cSql += " INNER JOIN SB1010" cSql += " ON B1_COD = ZZ4_PROD" cSql += " where ZZ4_COD = '" + ZZ3->ZZ3_COD + "'" cSql += " AND ZZ4010.D_E_L_E_T = ''"

cSQL := ChangeQuery(cSQL) TCQUERY cSQL NEW ALIAS "QZZ4" DbSelectArea("QZZ4") DbGoTop()

M->ZZ3_COD := ZZ3->ZZ3_COD M->ZZ3_DESCM := ZZ3->ZZ3_DESCM M->ZZ3_FORNEC := ZZ3->ZZ3_FORNEC M->ZZ3_LOJA := ZZ3->ZZ3_LOJA M->ZZ3_NFORNE := ZZ3->ZZ3_NFORNE M->ZZ3_DIASSU := ZZ3->ZZ3_DIASSU M->ZZ3_EMISSA := ZZ3->ZZ3_EMISSA M->ZZ3_DIAQTD := ZZ3->ZZ3_DIAQTD M->ZZ3_COND := ZZ3->ZZ3_COND M->ZZ3_PRAZO := ZZ3->ZZ3_PRAZO

//MONTA O ACOLS COM OS DADOS DO SELECT While !Eof()

AADD(aCols ,{QZZ4->ZZ4_PROD,QZZ4->ZZ4_DESCP,QZZ4->B1_XRKPROD ,QZZ4->ZZ4_CURVAD,QZZ4->ZZ4_CURVAM,QZZ4->ZZ4_ESTDIS,QZZ4->ZZ4_MEDDIA,QZZ4->ZZ4_ESTDIA,QZZ4->ZZ4_EMBA,; QZZ4->ZZ4_QTDSUG,QZZ4->ZZ4_UNICOM,QZZ4->ZZ4_VLTOTA,QZZ4->ZZ4_QTDCOM,QZZ4->ZZ4_QTDINF,ZZ4_VLUNIT,QZZ4->ZZ4_VLINFO,QZZ4->ZZ4_ESTDF,.F.})

DbSelectArea("QZZ4") DBSKIP() End

DbSelectArea("QZZ4") DbCloseArea()

aSize := MsAdvSize(.T.) aObjects := {}

AAdd( aObjects, { 100, 060, .T., .T. } ) AAdd( aObjects, { 100, 040, .T., .T. } )

aInfo := { aSize[ 1 ], aSize[ 2 ], aSize[ 3 ], aSize[ 4 ], 0, 0 } aPObjs := MsObjSize( aInfo, aObjects, .T. )

nOpcA := 0

DEFINE MSDIALOG oDlg TITLE "SUGESTÃO DE COMPRAS DOMA" From aSize[7], 000 To aSize[6], aSize[5] Of oMainWnd Pixel

oZZ3 := MsMGet():New("ZZ3",, 3,,,,aCpoMostra, aPObjs[1],aCpoMostra, 3,,,,oDlg) oZZ3:oBox:Align := CONTROL_ALIGN_NONE

oZZ4 := MsNewGetDados():New(aPObjs[1, 1], aPObjs[1, 2], aPObjs[1, 3], aPObjs[1, 4], nOpcG,,,,aACampos,, 99999,,,,oDlg, aHeader, aCols ) oZZ4:oBrowse:Align := CONTROL_ALIGN_BOTTOM //oZZ4:oBrowse:bSeekChange := {|| VlTotal(@oZZ4,nUltcom)}

ACTIVATE MSDIALOG oDlg ON INIT EnchoiceBar(oDlg, {|| nOpcA := 1, DeletaSug()} , {|| nOpcA := 0, oDlg:End()})

Return

Static Function GerHead()

Local aAux := {'ZZ4_PROD', 'ZZ4_DESCP', 'B1_XRKPROD','ZZ4_CURVAD', 'ZZ4_CURVAM', 'ZZ4_ESTDIS', 'ZZ4_MEDDIA',; 'ZZ4_ESTDIA', 'ZZ4_EMBA', 'ZZ4_QTDSUG', 'ZZ4_UNICOM', 'ZZ4_VLTOTA', 'ZZ4_QTDCOM',; 'ZZ4_QTDINF', 'ZZ4_VLUNIT', 'ZZ4_VLINFO','ZZ4_ESTDF'}

Local nFor := 1 Local cCampo := ""

For nFor := 1 To Len(aAux)

AADD(aHeader,{ TRIM(GetSx3Cache(aAux[nFor],"X3_TITULO")),; AllTrim(GetSx3Cache(aAux[nFor],"X3_CAMPO")),; GetSx3Cache(aAux[nFor],"X3_PICTURE"),; GetSx3Cache(aAux[nFor],"X3_TAMANHO"),; GetSx3Cache(aAux[nFor],"X3_DECIMAL"),; "",; GetSx3Cache(aAux[nFor],"X3_USADO"),; GetSx3Cache(aAux[nFor],"X3_TIPO"),; GetSx3Cache(aAux[nFor],"X3_ARQUIVO"),; GetSx3Cache(aAux[nFor],"X3_CONTEXT") } )

Next nFor

Return()

Static Function GravaSug()

if ValidInc()

//INCLUI ZZ3 (CABEÇALHO)

RecLock("ZZ3", .T.) DbSelectArea("ZZ3") DbSetOrder(1) ZZ3->ZZ3_COD := M->ZZ3_COD ZZ3->ZZ3_DESCM := M->ZZ3_DESCM ZZ3->ZZ3_EMISSA := M->ZZ3_EMISSA ZZ3->ZZ3_DIASSU := val(M->ZZ3_DIASSU) ZZ3->ZZ3_DIAQTD := val(M->ZZ3_DIAQTD) ZZ3->ZZ3_FORNEC := M->ZZ3_FORNEC ZZ3->ZZ3_LOJA := M->ZZ3_LOJA ZZ3->ZZ3_NFORNE := M->ZZ3_NFORNE ZZ3->ZZ3_COND := M->ZZ3_COND ZZ3->ZZ3_PRAZO := M->ZZ3_PRAZO ZZ3->ZZ3_EFET := M->ZZ3_EFET MsUnLock()

//INCLUI ZZ4 (ITENS)

For nCont := 1 to Len(oZZ4:aCols)

IF !GDDeleted(nCont,oZZ4:aHeader,oZZ4:aCols)

RecLock("ZZ4", .T.) DbSelectArea("ZZ4") DbSetOrder(1)

ZZ4->ZZ4_COD := M->ZZ3_COD ZZ4->ZZ4_PROD := oZZ4:ACOLS[nCont][AScan(aHeader,{|x| AllTrim(x[2]) == 'ZZ4_PROD'})] ZZ4->ZZ4_DESCP := oZZ4:ACOLS[nCont][AScan(aHeader,{|x| AllTrim(x[2]) == 'ZZ4_DESCP'})] ZZ4->ZZ4_ESTDIS := oZZ4:ACOLS[nCont][AScan(aHeader,{|x| AllTrim(x[2]) == 'ZZ4_ESTDIS'})] ZZ4->ZZ4_MEDDIA := oZZ4:ACOLS[nCont][AScan(aHeader,{|x| AllTrim(x[2]) == 'ZZ4_MEDDIA'})] ZZ4->ZZ4_ESTDIA := oZZ4:ACOLS[nCont][AScan(aHeader,{|x| AllTrim(x[2]) == 'ZZ4_ESTDIA'})] ZZ4->ZZ4_EMBA := oZZ4:ACOLS[nCont][AScan(aHeader,{|x| AllTrim(x[2]) == 'ZZ4_EMBA'})] ZZ4->ZZ4_QTDSUG := oZZ4:ACOLS[nCont][AScan(aHeader,{|x| AllTrim(x[2]) == 'ZZ4_QTDSUG'})] ZZ4->ZZ4_QTDCOM := oZZ4:ACOLS[nCont][AScan(aHeader,{|x| AllTrim(x[2]) == 'ZZ4_QTDCOM'})] ZZ4->ZZ4_VLUNIT := oZZ4:ACOLS[nCont][AScan(aHeader,{|x| AllTrim(x[2]) == 'ZZ4_VLUNIT'})] ZZ4->ZZ4_VLTOTA := oZZ4:ACOLS[nCont][AScan(aHeader,{|x| AllTrim(x[2]) == 'ZZ4_VLTOTA'})] ZZ4->ZZ4_QTDINF := oZZ4:ACOLS[nCont][AScan(aHeader,{|x| AllTrim(x[2]) == 'ZZ4_QTDINF'})] ZZ4->ZZ4_VLINFO := oZZ4:ACOLS[nCont][AScan(aHeader,{|x| AllTrim(x[2]) == 'ZZ4_VLINFO'})] ZZ4->ZZ4_CURVAD := oZZ4:ACOLS[nCont][AScan(aHeader,{|x| AllTrim(x[2]) == 'ZZ4_CURVAD'})] ZZ4->ZZ4_CURVAM := oZZ4:ACOLS[nCont][AScan(aHeader,{|x| AllTrim(x[2]) == 'ZZ4_CURVAM'})] ZZ4->ZZ4_ESTDF := oZZ4:ACOLS[nCont][AScan(aHeader,{|x| AllTrim(x[2]) == 'ZZ4_ESTDF'})] ZZ4->ZZ4_UNICOM := oZZ4:ACOLS[nCont][AScan(aHeader,{|x| AllTrim(x[2]) == 'ZZ4_UNICOM'})]

MsUnLock()

Endif Next oDlg:End() else MsgAlert("Deve preencher todos os itens obrigatorios","Prencher itens obrigatorios") EndIf

Return()

//VALIDAÇÕES DE INCLUSÃO DA SUGESTÃO Static Function ValidInc()

Local lRet := .f. Local nCont := 0

if alltrim(M->ZZ3_FORNEC) != "" .AND. alltrim(M->ZZ3_COND) != "" lRet := .t. End

For nCont := 1 to Len(oZZ4:ACOLS) IF !GDDeleted(nCont,oZZ4:aHeader,oZZ4:aCols) if oZZ4:ACOLS[nCont][AScan(aHeader,{|x| AllTrim(x[2]) == 'ZZ4_QTDINF'})] = 0 lRet := .f. endif ENDIF

Next

Return(lRet)

//ALTERA A SUGESTÃO NO BANCO NAS TABELAS //ZZ3 E ZZ4 Static Function AltSug()

Local cCod := M->ZZ3_COD

if ValidInc()

//ALTERA ZZ3 (CABEÇALHO)

DbSelectArea("ZZ3") DbSetOrder(1) If DbSeek(xFilial()+ZZ3->(cCod)) RecLock("ZZ3", .F.) ZZ3->ZZ3_FORNEC := M->ZZ3_FORNEC ZZ3->ZZ3_LOJA := M->ZZ3_LOJA ZZ3->ZZ3_NFORNE := M->ZZ3_NFORNE ZZ3->ZZ3_COND := M->ZZ3_COND ZZ3->ZZ3_PRAZO := M->ZZ3_PRAZO MsUnLock() endif

//ALTERA ZZ4 (ITENS) For nCont := 1 to Len(oZZ4:ACOLS)

IF !GDDeleted(nCont,oZZ4:aHeader,oZZ4:aCols) DbSelectArea("ZZ4") DbSetOrder(1) If DbSeek(xFilial()+ZZ4->(cCod)+oZZ4:ACOLS[nCont][AScan(aHeader,{|x| AllTrim(x[2]) == 'ZZ4_PROD'})]) RecLock("ZZ4", .F.) ZZ4->ZZ4_QTDINF := oZZ4:ACOLS[nCont][AScan(aHeader,{|x| AllTrim(x[2]) == 'ZZ4_QTDINF'})] ZZ4->ZZ4_VLINFO := oZZ4:ACOLS[nCont][AScan(aHeader,{|x| AllTrim(x[2]) == 'ZZ4_VLINFO'})] ZZ4->ZZ4_VLUNIT := oZZ4:ACOLS[nCont][AScan(aHeader,{|x| AllTrim(x[2]) == 'ZZ4_VLUNIT'})] MsUnLock() ENDIF ELSE DbSelectArea("ZZ4") DbSetOrder(1) If DbSeek(xFilial()+ZZ4->(cCod)+oZZ4:ACOLS[nCont][AScan(aHeader,{|x| AllTrim(x[2]) == 'ZZ4_PROD'})]) RecLock("ZZ4", .F.) ZZ4->( dbDelete() ) MsUnLock() ENDIF Endif Next oDlg:End() else MsgAlert("Deve preencher todos os itens obrigatorios","Prencher itens obrigatorios") EndIf

Return()

//GRAVA A SUGESTÃO NO BANCO NAS TABELAS //ZZ3 E ZZ4 Static Function DeletaSug()

Local cCod := M->ZZ3_COD

DbSelectArea("ZZ3") DbSetOrder(1) If DbSeek(xFilial()+ZZ3->(cCod)) RecLock("ZZ3",.F.) ZZ3->(DbDelete()) ZZ3->(MsUnlock()) endif

For nCont := 1 to Len(oZZ4:ACOLS)

DbSelectArea("ZZ4") DbSetOrder(1) If DbSeek(xFilial()+ZZ4->(cCod)+oZZ4:ACOLS[nCont][AScan(aHeader,{|x| AllTrim(x[2]) == 'ZZ4_PROD'})]) RecLock("ZZ4", .F.) ZZ4->( dbDelete() ) MsUnLock() ENDIF

Next

oDlg:End() Return()

Static Function Funf4()

Local nLinha := oZZ4:oBrowse:nAt

Local cCod := oZZ4:ACOLS[nLinha][AScan(aHeader,{|x| AllTrim(x[2]) == 'ZZ4_PROD'})] Local cDesc := oZZ4:ACOLS[nLinha][AScan(aHeader,{|x| AllTrim(x[2]) == 'ZZ4_DESCP'})]

U_XMEDPROD(cCod,cDesc)

Return()

STATIC FUNCTION Ordena(nCol)

aCols := oZZ4:ACOLS aSort( aCols,,,{|x,y|x[nCol] < y[nCol]}) oZZ4:setArray(aCols) oZZ4:oBrowse:Refresh()

RETURN

Static Function GDToExcel(aHeader,aCols,cWorkSheet,cTable,lTotalize,lPicture)

Local oFWMSExcel := FWMSExcel():New() Local oMsExcel Local aCells Local cType Local cColumn Local cFile Local cFileTMP Local cPicture Local lTotal Local nRow Local nRows Local nField Local nFields Local nAlign Local nFormat Local cabecalho := "" Local uCell

DEFAULT cWorkSheet := "MARCA: " + alltrim(ZZ3->ZZ3_DESCM) + " - " + "FORNECEDOR: " + alltrim(ZZ3->ZZ3_NFORNE) + " - " + "COND.: " + alltrim(ZZ3_PRAZO) DEFAULT cTable := cWorkSheet DEFAULT lTotalize := .T. DEFAULT lPicture := .F.

BEGIN SEQUENCE

oFWMSExcel:AddworkSheet(cWorkSheet) oFWMSExcel:AddTable(cWorkSheet,cTable)

nFields := Len( aHeader ) For nField := 1 To nFields cType := aHeader[nField][8] nAlign := IF(cType=="C",1,IF(cType=="N",3,2)) nFormat := IF(cType=="D",4,IF(cType=="N",2,1)) cColumn := aHeader[nField][1] lTotal := ( lTotalize .and. cType == "N" ) oFWMSExcel:AddColumn(@cWorkSheet,@cTable,@cColumn,@nAlign,@nFormat,@lTotal) Next nField

aCells := Array(nFields)

nRows := Len( aCols ) For nRow := 1 To nRows For nField := 1 To nFields uCell := aCols[nRow][nField] IF ( lPicture ) cPicture := aHeader[nField][3] IF .NOT.( Empty(cPicture) ) uCell := Transform(uCell,cPicture) EndIF EndIF aCells[nField] := uCell Next nField oFWMSExcel:AddRow(@cWorkSheet,@cTable,aClone(aCells)) Next nRow

oFWMSExcel:Activate()

cFile := ( CriaTrab( NIL, .F. ) + ".xml" )

While File( cFile ) cFile := ( CriaTrab( NIL, .F. ) + ".xml" ) End While

oFWMSExcel:GetXMLFile( cFile ) oFWMSExcel:DeActivate()

IF .NOT.( File( cFile ) ) cFile := "" BREAK EndIF

cFileTMP := ( GetTempPath() + cFile ) IF .NOT.( __CopyFile( cFile , cFileTMP ) ) fErase( cFile ) cFile := "" BREAK EndIF

fErase( cFile )

cFile := cFileTMP

IF .NOT.( File( cFile ) ) cFile := "" BREAK EndIF

IF .NOT.( ApOleClient("MsExcel") ) BREAK EndIF

oMsExcel := MsExcel():New() oMsExcel:WorkBooks:Open( cFile ) oMsExcel:SetVisible( .T. ) oMsExcel := oMsExcel:Destroy()

END SEQUENCE

oFWMSExcel := FreeObj( oFWMSExcel )

Return( cFile )

user Function notificaMarca(cMarca)

local cSql := "" Local lAvencer := .F. Local lAReceber := .F. Local lRecebidos := .F. Local cVencerDescMarca := "" Local cReceberDescMarca := "" Local cRecebidosDescMarca := ""

IF FUNNAME() == "MATA121"

cSql := " SELECT STRINGAGG(ZN_MARCA,'\') MARCA," cSql += " STRING_AGG(trim(ZN_DESCM),',') DMARCAS" cSql += " FROM SZN010" cSql += " WHERE ZN_FORNEC = '" + CA120FORN + "' AND ZN_LOJAF = '" + CA120LOJ + "' AND SZN010.D_E_L_E_T = ''"

cSQL := ChangeQuery(cSQL) TCQUERY cSQL NEW ALIAS "QMARC" DbSelectArea("QMARC") DbGoTop() While !Eof() cMarca := ALLTRIM(QMARC->MARCA) DbSelectArea("QMARC") DBSKIP() End

DbSelectArea("QMARC") DbCloseArea()

ENDIF

IF Empty(cMarca) RETURN ENDIF

cSql := " SELECT STRINGAGG(TRIM(B1_XDESCM), ',') MARCA" cSql += " FROM (" cSql += " SELECT " cSql += " B1_XDESCM cSql += " FROM SB8010 " cSql += " JOIN SB1010 ON SB1010.D_E_L_E_T='' AND B1COD = B8_PRODUTO" cSql += " WHERE SB8010.D_E_L_E_T='' AND B8_SALDO<>'0' AND (B8_SALDO) <>'0' and B8_DTVALID <= DATEADD(DAY, 180 , GETDATE())" cSql += " AND B8_LOCAL NOT IN ('03','04','53','54','07','57') AND B1_XMARCA in (" + STRTRAN(ALLTRIM(cMarca),"\",",") + ")" cSql += " GROUP BY B1_XDESCM) RESULTADO"

cSQL := ChangeQuery(cSQL) TCQUERY cSQL NEW ALIAS "QVENC" DbSelectArea("QVENC") DbGoTop() While !Eof() if !empty(QVENC->MARCA) lAvencer := .t. cVencerDescMarca := alltrim(QVENC->MARCA) endif DbSelectArea("QVENC") DBSKIP() End

DbSelectArea("QVENC") DbCloseArea()

cSql := " SELECT STRINGAGG(TRIM(B1_XDESCM), ',') MARCA" cSql += " FROM (" cSql += " SELECT " cSql += " B1_XDESCM" cSql += " FROM SB8010 " cSql += " JOIN SB1010 ON SB1010.D_E_L_E_T='' AND B1COD = B8_PRODUTO " cSql += " LEFT JOIN SB2010 ON B1_COD = B2_COD " cSql += " JOIN NNR010 ON NNR010.D_E_L_E_T='' AND NNRCODIGO = B8_LOCAL AND NNR_FILIAL = B8_FILIAL " cSql += " WHERE SB8010.D_E_L_E_T='' AND B8_SALDO <> '0' AND B8_LOCAL IN ('03','53')" cSql += " AND B1_XMARCA in (" + STRTRAN(ALLTRIM(cMarca),"\",",") + ")" cSql += " group by B1_XDESCM) RESULTADO"

cSQL := ChangeQuery(cSQL) TCQUERY cSQL NEW ALIAS "QVENC" DbSelectArea("QVENC") DbGoTop() While !Eof() if !empty(QVENC->MARCA) lAReceber := .t. cReceberDescMarca := alltrim(QVENC->MARCA) endif DbSelectArea("QVENC") DBSKIP() End

DbSelectArea("QVENC") DbCloseArea()

if lAvencer MsgAlert('Existem produtos a vencer para a marca: ' + cVencerDescMarca) endif

if lAReceber MsgAlert('Existem produtos vencidos a receber para a marca: ' + cReceberDescMarca) endif

Return

user Function NotFornec(cFornecedor,cLoja,cMarca)

local cSql := "" Local lPendencia := .F. Local cCliente := "" Local cLojaCli := "" Local lAutomato := IsBlind()

IF !lAutomato

if empty(cLoja) IF FUNNAME() == "MATA121" cLoja := CA120LOJ endif endif

//VERIFICA SE EXISTE RELACIONAMENTO COM ALGUM CLIENTE NA TABELA (MARCA X FORNECEDOR X CLIENTE) cSql := " SELECT TOP 1 ZNCLIENTE,ZN_LOJAC FROM SZN010" cSql += " WHERE ZN_FORNEC = '" + cFornecedor + "' cSql += " AND ZN_LOJAF = '" + cLoja + "' AND SZN010.D_E_L_E_T = ''"

cSQL := ChangeQuery(cSQL) TCQUERY cSQL NEW ALIAS "QCLI" DbSelectArea("QCLI") DbGoTop() While !Eof() cCliente := QCLI->ZN_CLIENTE cLojaCli := QCLI->ZN_LOJAC DbSelectArea("QCLI") DBSKIP() End DbSelectArea("QCLI") DbCloseArea()

if !empty(cCliente)

cSql := " SELECT TOP 1 * " cSql += " FROM SE1010" cSql += " WHERE E1CLIENTE = '" + cCliente + "' AND E1_LOJA = '" + cLojaCli + "'" cSql += " AND E1_STATUS = 'A' AND E1_TIPO NOT IN ('RA','NCC') and SE1010.D_E_L_E_T = ''"

cSQL := ChangeQuery(cSQL) TCQUERY cSQL NEW ALIAS "QVENC" DbSelectArea("QVENC") DbGoTop() While !Eof() lPendencia := .t. DbSelectArea("QVENC") DBSKIP() End DbSelectArea("QVENC") DbCloseArea()

if lPendencia MsgAlert('Este fornecedor possui DEBITO') endif

lPendencia := .f. cSql := " SELECT TOP 1 * " cSql += " FROM SE1010" cSql += " WHERE E1CLIENTE = '" + cCliente + "' AND E1_LOJA = '" + cLojaCli + "'" cSql += " AND E1_STATUS = 'A' AND E1_TIPO IN ('RA','NCC') and SE1010.D_E_L_E_T = ''"

cSQL := ChangeQuery(cSQL) TCQUERY cSQL NEW ALIAS "QVENC" DbSelectArea("QVENC") DbGoTop() While !Eof() lPendencia := .t. DbSelectArea("QVENC") DBSKIP() End DbSelectArea("QVENC") DbCloseArea()

if lPendencia MsgAlert('Este fornecedor possui CREDITO') endif

endif

IF FUNNAME() == "MATA121" U_notificaMarca("") ENDIF ENDIF

Return .T.

Versão (1):

Ver a versão formatada

Duvida de como alinhar um valor sql a esquerda da coluna

  • criado 16 de May de 2023

Comentário

new question