Bibliotecas #INCLUDE PROTHEUS.CH #INCLUDE FWMVCDEF.CH #INCLUDE FWBROWSE.CH #INCLUDE Tbiconn.CH #INCLUDE topconn.ch Aglutinar pedidos de compra do mesmo fornecedor User Function AGLPEDIDOS(_Fornece) Private aCpoInfo = {} Private aCampos = {} Private aCpoData = {} Private oTable = Nil Private oMarkBrow = Nil Private cCadastro = 'Aglutinar' Private aRot = aRotina aRotina = {} FwMsgRun(,{ fLoadData(_Fornece) }, cCadastro, 'Carregando dados...') oMarkBrow = FwMarkBrowse()New() oMarkBrowSetAlias('TRB') oMarkBrowSetTemporary() oMarkBrowSetColumns(aCampos) oMarkBrowSetFieldMark('TMP_OK') oMarkBrowSetMenuDef('AGLPEDIDOS') oMarkBrowSetDescription('Aglutinar pedidos de compra') SetFunName(AGLPEDIDOS) oMarkBrowSetAllMark( { fInvert() } ) oMarkBrowActivate() SetFunName(cFunBkp) If(Type('oTable') 'U') oTableDelete() oTable = Nil Endif aRotina = aRot Return Static Function MenuDef Private aRot = {} Add Option aRot Title 'Aglutinar itens' Action 'U_COMP25PROC()' Operation 3 Access 0 Return(aRot) Static Function fLoadData(_Fornece) Local nI = 0 If(Type('oTable') 'U') oTableDelete() oTable = Nil Endif oTable = FwTemporaryTable()New('TRB') aCampos = {} aCpoInfo = {} aCpoData = {} aAdd(aCpoInfo, {'Marcar' , '@!' , 1}) aAdd(aCpoInfo, {'Fornecedor' , '@!' , 1}) aAdd(aCpoInfo, {'Loja' , '@!' , 1}) aAdd(aCpoInfo, {'Pedido' , '@!' , 1}) aAdd(aCpoInfo, {'Item' , '@!' , 1}) aAdd(aCpoInfo, {'Produto' , '@!' , 1}) aAdd(aCpoInfo, {'Descrição' , '@!' , 1}) aAdd(aCpoInfo, {'UM' , '@!' , 1}) aAdd(aCpoInfo, {'Quantidade' , '999999.99' , 1}) aAdd(aCpoInfo, {'Preço' , '999999.99' , 1}) aAdd(aCpoInfo, {'Total' , '999999.99' , 1}) aAdd(aCpoInfo, {'Qtd. Conc.' , '999999.99' , 1}) aAdd(aCpoInfo, {'Qtd Disp.' , '999999.99' , 1}) aAdd(aCpoInfo, {'Centro Custo' , '@!' , 1}) aAdd(aCpoInfo, {'Prev. Entreg.' , '@!' , 1}) aAdd(aCpoInfo, {'Cond. Pag.' , '@!' , 1}) aAdd(aCpoInfo, {'Lead Time' , '99' , 1}) aAdd(aCpoInfo, {'Observação' , '@!' , 1}) aAdd(aCpoData, {'TMP_OK' , 'C' , 2 , 0}) aAdd(aCpoData, {'TMP_FORNEC', TamSx3('C7_FORNECE')[3] , TamSx3('C7_FORNECE')[1] , 0}) aAdd(aCpoData, {'TMP_LOJA' , TamSx3('C7_LOJA')[3] , TamSx3('C7_LOJA')[1] , 0}) aAdd(aCpoData, {'TMP_PEDIDO' , TamSx3('C7_NUM')[3] , TamSx3('C7_NUM')[1] , 0}) aAdd(aCpoData, {'TMP_ITEM' , TamSx3('C7_ITEM')[3] , TamSx3('C7_ITEM')[1] , 0}) aAdd(aCpoData, {'TMP_PRODUT' , TamSx3('C7_PRODUTO')[3] , TamSx3('C7_PRODUTO')[1] , 0}) aAdd(aCpoData, {'TMP_DESCRI' , TamSx3('C7_DESCRI')[3] , TamSx3('C7_DESCRI')[1] , 0}) aAdd(aCpoData, {'TMP_UM' , TamSx3('C7_UM')[3] , TamSx3('C7_UM')[1] , 0}) aAdd(aCpoData, {'TMP_QUANT' , TamSx3('C7_QUANT')[3] , TamSx3('C7_QUANT')[1] , 0}) aAdd(aCpoData, {'TMP_PRECO' , TamSx3('C7_PRECO')[3] , TamSx3('C7_PRECO')[1] , 0}) aAdd(aCpoData, {'TMP_TOTAL' , TamSx3('C7_TOTAL')[3] , TamSx3('C7_TOTAL')[1] , 0}) aAdd(aCpoData, {'TMP_QTDCON' , TamSx3('C7_QUANT')[3] , TamSx3('C7_QUANT')[1] , 0}) aAdd(aCpoData, {'TMP_QTDDIS' , TamSx3('C7_QUANT')[3] , TamSx3('C7_QUANT')[1] , 0}) aAdd(aCpoData, {'TMP_CC' , TamSx3('C7_CC')[3] , TamSx3('C7_CC')[1] , 0}) aAdd(aCpoData, {'TMP_DATA' , TamSx3('C7_DATPRF')[3] , TamSx3('C7_DATPRF')[1] , 0}) aAdd(aCpoData, {'TMP_CONDPA' , TamSx3('C7_COND')[3] , TamSx3('C7_COND')[1] , 0}) aAdd(aCpoData, {'TMP_LEAD' , TamSx3('ZYH_LEAD')[3] , TamSx3('ZYH_LEAD')[1] , 0}) aAdd(aCpoData, {'TMP_OBSERV' , TamSx3('ZYH_OBSERV')[3] , TamSx3('ZYH_OBSERV')[1] , 0}) For nI = 1 To Len(aCpoData) If(aCpoData[nI][1] 'TMP_OK' .and. aCpoData[nI][1] 'TMP_RECNO') aAdd(aCampos, FwBrwColumn()New()) aCampos[Len(aCampos)]SetData( &('{' + aCpoData[nI,1] + '}') ) aCampos[Len(aCampos)]SetTitle(aCpoInfo[nI,1]) aCampos[Len(aCampos)]SetPicture(aCpoInfo[nI,2]) aCampos[Len(aCampos)]SetSize(aCpoData[nI,3]) aCampos[Len(aCampos)]SetDecimal(aCpoData[nI,4]) aCampos[Len(aCampos)]SetAlign(aCpoInfo[nI,3]) EndIf Next nI oTableSetFields(aCpoData) oTableCreate() _cSQL = SELECT C7_FORNECE, C7_LOJA, C7_NUM, C7_ITEM, C7_PRODUTO,C7_DESCRI, C7_UM, C7_QUANT, C7_TOTAL, C7_CC, C7_DATPRF, C7_PRECO,C7_QUJE, ZYH_LEAD, ZYH_OBSERV, _cSQL += ISNULL(( _cSQL += SELECT SUM(ZV2_QUANT) FROM + RetSQLName(ZV2) + _cSQL += WHERE D_E_L_E_T_='' _cSQL += AND ZV2_COD=C7_PRODUTO _cSQL += AND ZV2_ITEMPC=C7_ITEM _cSQL += AND ZV2_FILIAL=C7_FILIAL _cSQL += AND ZV2_PEDIDO=C7_NUM),0) QTD_CONCILIADA _cSQL += FROM +RetSQLName(SC7)+ SC7 _cSQL += INNER JOIN +RetSQLName(ZYH)+ ZYH ON C7_FILENT = ZYH_FILIAL AND C7_NUM=ZYH_PEDIDO AND C7_PRODUTO = ZYH_CODPRO _cSQL += WHERE C7_FILENT = '+XFILIAL(SC7)+' AND C7_FORNECE ='000017' +_Fornece+' _cSQL += AND SC7.D_E_L_E_T_ = '' AND C7_CONAPRO='L' AND C7_RESIDUO='' _cSQL += AND ZYH.D_E_L_E_T_ = '' _cSQL += ORDER BY 1,5 if Select (mntArr) != 0 mntArr-(dbCloseArea()) endif TCQuery _cSQL NEw Alias mntArr While mntArr-(!EOF()) RecLock('TRB', .T.) TRB-TMP_FORNEC = mntArr- C7_FORNECE TRB-TMP_LOJA = mntArr- C7_LOJA TRB-TMP_PEDIDO = mntArr- C7_NUM TRB-TMP_ITEM = mntArr- C7_ITEM TRB-TMP_PRODUT = ALLTRIM(mntArr- C7_PRODUTO) TRB-TMP_DESCRI = mntArr- C7_DESCRI TRB-TMP_UM = mntArr- C7_UM TRB-TMP_QUANT = mntArr- C7_QUANT TRB-TMP_PRECO = mntArr- C7_PRECO TRB-TMP_TOTAL = mntArr- C7_TOTAL TRB-TMP_QTDCON = mntArr- QTD_CONCILIADA TRB-TMP_QTDDIS =mntArr- (C7_QUANT - QTD_CONCILIADA) TRB-TMP_CC = mntArr- C7_CC TRB-TMP_DATA = StoD(mntArr- C7_DATPRF) TRB-TMP_CONDPA = ALLTRIM(str(mntArr- C7_QUJE)) TRB-TMP_LEAD = mntArr- ZYH_LEAD TRB-TMP_OBSERV = ALLTRIM(mntArr- ZYH_OBSERVA) TRB-(MsUnlock()) mntArr-(DbSkip()) EndDo TRB-(DbGoTop()) mntArr-(DbCloseArea()) Return User Function COMP25PROC Local aAux = {} Local aAux2 = {} Local cProdut Local cQuanti Local nPreco Local cCC Local cFornec Local cLoja Local cObserva TRB-(DbGoTop()) While(!TRB-(EoF())) If(TRB-TMP_OK == oMarkBrowMark()) if len(aAux)==0 aAdd(aAux, {TRB-TMP_PRODUT, TRB-TMP_UM, TRB-TMP_QUANT, TRB-TMP_PRECO, TRB-TMP_CC, TRB-TMP_FORNEC, TRB-TMP_LOJA, TRB-TMP_OBSERV}) elseif aScan(aAux, {x x[1]==TRB-TMP_PRODUT}) 0 aAux[aScan(aAux, {x x[1]==TRB-TMP_PRODUT})][3] += TRB-TMP_QUANT cQuanti = TRB-TMP_QUANT else aAdd(aAux, {TRB-TMP_PRODUT, TRB-TMP_UM, TRB-TMP_QUANT, TRB-TMP_PRECO, TRB-TMP_CC}) Endif cProdut = aAux[1][1] nQuanti = aAux[1][3] nPreco = aAux[1][4] cCC = aAux[1][5] cFornec = aAux[1][6] cLoja = aAux[1][7] cObserva = aAux[1][8] aadd(aAux2,alltrim(cProdut)+';'+replace(cvaltochar(nQuanti),'.',',')+';'+replace(cvaltochar(nPreco),'.',',')+';'+Alltrim(cLoja)+';'+Alltrim(cFornec)+';'+Alltrim(cCC)+';'+ALLTRIM(cObserva)) EndIf TRB-(DbSkip()) EndDo Return aAux2 Return aadd(aAux,alltrim({1})+';'+replace(cvaltochar({3}),'.',',')+';'+replace(cvaltochar({4}),'.',',')+';'+cFornec+';'+cLoja+';'+substr(cFrete,1,1)+';'+cCCusto+';'+cCond+';'+cvaltochar(0)+';'+cOberseva )