I have this mistake in advpl

Asked

Viewed 172 times

0

I have the image error when I print the sales order on Totvs. But it only presents this error the third time I make the print, I print once ok right, the second time too, now the third time presents the error.inserir a descrição da imagem aqui

Follow the code of the Printing

#INCLUDE "FWPrintSetup.ch"
#INCLUDE "topconn.ch"
#INCLUDE "Protheus.ch"
#INCLUDE "TBICONN.CH"
#INCLUDE "rwmake.ch

User Function TSTREL()

Local cQuery   := ""
Local cNum     := ""
Local nTotal   := 0
Local nIpi     := 0
Local nIcmsSub := 0
Local nTotalF  := 0
Private oPrinter
Private oFont1
Private oFont2
Private oHGRAY := TBrush():New( , CLR_HGRAY)
Private lPreview
Private cLogo := FisxLogo("1")


RPCSetType(3)
If cEmpAnt == "01"
     Prepare Environment Empresa "01" Filial "01"
Else
     Prepare Environment Empresa "02" Filial "01"
EndIf

//RPCSetEnv("99","01")



    /*** FONTES ***/
Private oFont18T    := TFont():New("Courier New",,18,,.T.,,,,,.F.)
Private oFont16T    := TFont():New("Courier New",,16,,.T.,,,,,.F.)
Private oFont14TC   := TFont():New("Courier New",,14,,.T.,,,,,.F.)
Private oFont14T    := TFont():New("Arial"      ,,14,,.T.,,,,,.F.)
Private oFont18TA   := TFont():New("Arial"      ,,18,,.T.,,,,,.F.)
Private oFont14TI   := TFont():New("Arial"      ,,13,,.T.,,,,.T.,.F.)
Private oFont11F    := TFont():New("Arial"      ,,11,,.F.,,,,,.F.)
Private oFont13T    := TFont():New("Arial"      ,,12,,.T.,,,,,.F.)
Private oFont13F    := TFont():New("Arial"      ,,12,,.F.,,,,,.F.)
Private oFont10FA   := TFont():New("Arial"      ,,10,,.F.,,,,,.F.)
Private oFont10F    := TFont():New("Courier New",,10,,.F.,,,,,.F.)
Private oFont11FA   := TFont():New("Arial"      ,,11,,.F.,,,,,.F.)

Private oFont09T    := TFont():New("Courier New",,09,,.T.,,,,,.F.)
Private oFont07F    := TFont():New("Courier New",,07,,.F.,,,,,.F.)
Private oFont09F    := TFont():New("Courier New",,09,,.F.,,,,,.F.)
Private oFont09FA   := TFont():New("Arial",,09,,.F.,,,,,.F.)

Private oFont7TA    := TFont():New("Courier New",,07,,.T.,,,,,.F.)
Private oFont12F    := TFont():New("Courier New",,12,,.F.,,,,,.F.)
Private oFont10T    := TFont():New("Courier New",,10,,.T.,,,,,.F.)
Private oFont09F    := TFont():New("Courier New",,09,,.F.,,,,,.F.)
Private oFont09T    := TFont():New("Courier New",,09,,.T.,,,,,.F.)
Private oFont14N    := TFont():New("Courier New",14,14,,.T.,,,,.T.,.F.)

Private oFont10AT   := TFont():New("Arial"      ,,10,,.T.,,,,,.F.)
Private oFont10AF   := TFont():New("Arial"      ,,10,,.F.,,,,,.F.)

Private  nLin       := 350
Private  NSpace10   := 10
Private  NSpace20   := 20
Private  NSpace30   := 30
Private  NSpace40   := 40
Private  NSpace50   := 50



If oPrinter == Nil
    lPreview := .T.
    oPrinter      := FWMSPrinter():New(SC5->C5_NUM ,6,.F.,,.T.)
    oPrinter:SetResolution(72) //Tamanho estipulado para a Danfe
    oPrinter:SetPortrait()
    oPrinter:SetPaperSize(9)
    oPrinter:SetMargin(60,60,60,60)
    oPrinter:cPathPDF :="C:\TEMP\"    
EndIf



oPrinter:StartPage()
//oPrinter:Box (60, 60, 830, 530)

If cEmpAnt == "01"
oPrinter:SayBitmap( 50, 30, cLogo , 100, 100)
oPrinter:Say(80,180,"PIC-QUÍMICA E FARMACÊUTICA LTDA",                                         oFont14TC)
oPrinter:Say(100,150,"Morada da Estrelas, 65 - Jd. Nova Itapevi - ITAPEVI - SP",              oFont09F)
oPrinter:Say(108,150, "Fone: 11 4151-9000 - CNPJ: 03.421.909/0001-01 - I.E: 373.083.103.117",  oFont09F)
oPrinter:Say(116,150, "www.pic-web.com.br.com.br - [email protected]",                     oFont09F)
oPrinter:Say(140,210, "PEDIDO DE VENDA Nº:" + SC5->C5_NUM ,                                    oFont14TC)
Else
oPrinter:SayBitmap( 80, 20, cLogo , 110, 60)
oPrinter:Say(80,80,"PHARMASPECIAL ESTEPCIALIDADES QUIMÍCAS E FARMACEUTICAS LTDA",              oFont14TC)
oPrinter:Say(100, 150,"Morada da Estrelas, 55 - Jd. Nova Itapevi - ITAPEVI - SP",              oFont09F)
oPrinter:Say(108,150, "Fone: 11 4151-9000 - CNPJ: 65.678.617/0001-06 - I.E: 373.083.103.117",  oFont09F)
oPrinter:Say(116,150, "www.pharmaspecial.com.br - [email protected]",                oFont09F)
oPrinter:Say(140,210, "PEDIDO DE VENDA Nº:" + SC5->C5_NUM ,                                    oFont14TC)
EndIf



oPrinter:Line(150,05,150,550)

cQuery += " SELECT  SC5.C5_FILIAL,SC5.C5_EMISSAO,SC5.C5_FECENT,SC5.C5_NUM,SC5.C5_CLIENTE,SC5.C5_TPFRETE,SC5.C5_MOEDA,SC5.C5_TXMOEDA,SC5.C5_PESOL,SC5.C5_PBRUTO," + CRLF
cQuery += " SA1.A1_NOME,SA1.A1_END,SA1.A1_BAIRRO,SA1.A1_CEP,SA1.A1_MUN,SA1.A1_EST,SA1.A1_DDD,SA1.A1_TEL,SA1.A1_CONTATO,SA1.A1_CGC,SA1.A1_INSCR,SA1.A1_EMAIL," + CRLF
cQuery += " SC5.C5_TRANSP,SA4.A4_NOME,SA4.A4_END,SA4.A4_BAIRRO,SA4.A4_CEP,SA4.A4_MUN,SA4.A4_EST,SA4.A4_DDD,SA4.A4_TEL,SA4.A4_CONTATO,SA3.A3_NOME,SC5.C5_CONDPAG," + CRLF
cQuery += " SE4.E4_COND,SE4.E4_DESCRI,SC6.C6_ITEM,SC6.C6_DESCRI,SC6.C6_QTDVEN,SC6.C6_UM,SC6.C6_PRCVEN,SC6.C6_XIPI,SC6.C6_XICMSRT,SC6.C6_VALOR,SC6.C6_XPROCLI," + CRLF
cQuery += " SC6.C6_PEDCLI,SC5.C5_MENNOTA,SC5.C5_XOBS" + CRLF"
cQuery += " FROM " +RetSqlName("SC5")+ " SC5(NOLOCK), " + CRLF
cQuery += "      " +RetSqlName("SA1")+ " SA1(NOLOCK), " + CRLF
cQuery += "      " +RetSqlName("SA4")+ " SA4(NOLOCK), " + CRLF
cQuery += "      " +RetSqlName("SA3")+ " SA3(NOLOCK), " + CRLF
cQuery += "      " +RetSqlName("SE4")+ " SE4(NOLOCK), " + CRLF
cQuery += "      " +RetSqlName("SC6")+ " SC6(NOLOCK)  " + CRLF
cQuery += " WHERE SC5.C5_NUM =" + SC5->C5_NUM + CRLF
cQuery += " AND SC5.C5_FILIAL = '" + xFilial ("SC5") + "'" + CRLF
cQuery += " AND SA1.A1_FILIAL = '" + xFilial ("SA1") + "'" + CRLF
cQuery += " AND SA1.A1_COD = SC5.C5_CLIENTE              " + CRLF
cQuery += " AND SA1.A1_LOJA = SC5.C5_LOJACLI             " + CRLF
cQuery += " AND SA4.A4_COD = SC5.C5_TRANSP               " + CRLF
cQuery += " AND SA3.A3_COD = SC5.C5_VEND1                " + CRLF
cQuery += " AND SE4.E4_CODIGO = SC5.C5_CONDPAG           " + CRLF
cQuery += " AND SC6.C6_NUM = SC5.C5_NUM                  " + CRLF
cQuery += " AND SA1.D_E_L_E_T_ = ' '                     " + CRLF
cQuery += " AND SC5.D_E_L_E_T_ = ' '                     " + CRLF
cQuery += " AND SA4.D_E_L_E_T_ = ' '                     " + CRLF
cQuery += " AND SA3.D_E_L_E_T_ = ' '                     " + CRLF
cQuery += " AND SE4.D_E_L_E_T_ = ' '                     " + CRLF
cQuery += " AND SC6.D_E_L_E_T_ = ' '                     " + CRLF

If Select("QRY") > 0
    Dbselectarea("QRY")
    QRY->(DbClosearea())
EndIf

TcQuery cQuery New Alias "QRY"

//Tratamento para campo data
TCSetField( 'QRY', "C5_EMISSAO", "D" )
TCSetField( 'QRY', "C5_FECENT", "D" )

//Tratamento para tarzer a descrição da moeda
_cMoeda := QRY->C5_MOEDA
DbSelectArea('SM2');SM2->(DbSetOrder(1));SM2->(DbSeek(DtoS(dDataBase)))
oPrinter:Say(310,iIF(_cMoeda==1,2200,2000),OemToAnsi('Moeda: '+GetMV("MV_SIMB"+cValToChar(_cMoeda),.F.,'') + iIF(_cMoeda==1,'',' - Taxa: '+TransForm(&("SM2->M2_MOEDA"+cValToChar(_cMoeda)),'@e 99.9999')) ),oFont09T)


oPrinter:Say(130, 435, "EMISSÃO: " +OemToAnsi(Dtoc(QRY->C5_EMISSAO)),                                                           oFont13T)
oPrinter:Say(140, 433, "ENTREGA: " +OemToAnsi(Dtoc(QRY->C5_FECENT)),                                                            oFont13T)
oPrinter:Say(160, 200, "DADOS DO CLIENTE ENTREGA",                                                                              oFont14TC)
oPrinter:Say(170, 10, "CLIENTE: ",                                                                                              oFont10T)
oPrinter:Say(170, 50, +ALLTRIM(QRY->C5_CLIENTE)+ ' - ' +ALLTRIM(QRY->A1_NOME),                                                  oFont10F)
oPrinter:Say(180, 10, "ENDEREÇO: ",                                                                                             oFont10T)
oPrinter:Say(180, 55, +ALLTRIM(QRY->A1_END),                                                                                    oFont10F)
oPrinter:Say(190, 10, "BAIRRO: ",                                                                                               oFont10T)
oPrinter:Say(190, 45, +ALLTRIM(QRY->A1_BAIRRO),                                                                                 oFont10F)
oPrinter:Say(190, 300, "CEP: ",                                                                                                 oFont10T)
oPrinter:Say(190, 320, +ALLTRIM(QRY->A1_CEP),                                                                                   oFont10F)
oPrinter:Say(200, 10, "CIDADE: ",                                                                                               oFont10T)
oPrinter:Say(200, 45, +ALLTRIM(QRY->A1_MUN),                                                                                    oFont10F)
oPrinter:Say(200, 300, "UF: ",                                                                                                  oFont10T)
oPrinter:Say(200, 320, +ALLTRIM(QRY->A1_EST),                                                                                   oFont10F)
oPrinter:Say(190, 400, "INSC. EST.: ",                                                                                          oFont10T)
oPrinter:Say(190, 455, +ALLTRIM(TransForm(QRY->A1_INSCR, '@r 999.999.999-99')),                                                 oFont10F)
oPrinter:Say(200, 425, "CNPJ: ",                                                                                                oFont10T)
oPrinter:Say(200, 455, +ALLTRIM(TransForm(QRY->A1_CGC, '@r 99.999.999/9999-99')),                                               oFont10F)
oPrinter:Say(210, 10, "CONTATO: ",                                                                                              oFont10T)
oPrinter:Say(210, 50, +ALLTRIM(QRY->A1_CONTATO),                                                                                oFont10F)
oPrinter:Say(210, 200, "TEL: ",                                                                                                 oFont10T)
oPrinter:Say(210, 220, '('+ALLTRIM(QRY->A1_DDD)+')'+ALLTRIM(TransForm(QRY->A1_TEL, '@r 9999-9999')),                            oFont10F)
oPrinter:Say(210, 300, "E-MAIL: ",                                                                                              oFont10T)
oPrinter:Say(210, 335, +ALLTRIM(QRY->A1_EMAIL),                                                                                 oFont10F)

oPrinter:Line(215,05,215,550)

oPrinter:Say(225,200, " DADOS DO TRANSPORTE",                                                                                   oFont14TC)
oPrinter:Say(235, 10, "TRANSPORTADORA: ",                                                                                       oFont10T)
oPrinter:Say(235, 80, +ALLTRIM(QRY->C5_TRANSP)+ ' - ' +ALLTRIM(QRY->A4_NOME),                                                   oFont10F)
oPrinter:Say(245, 10, "ENDEREÇO: ",                                                                                             oFont10T)
oPrinter:Say(245, 55, +ALLTRIM(QRY->A4_END),                                                                                    oFont10F)
oPrinter:Say(255, 10, "BAIRRO: ",                                                                                               oFont10T)
oPrinter:Say(255, 45, +ALLTRIM(QRY->A4_BAIRRO),                                                                                 oFont10F)
oPrinter:Say(255, 300, "CEP: ",                                                                                                 oFont10T)
oPrinter:Say(255, 320, +ALLTRIM(QRY->A4_CEP),                                                                                   oFont10F)
oPrinter:Say(265, 10, "CIDADE: ",                                                                                               oFont10T)
oPrinter:Say(265, 45, +ALLTRIM(QRY->A4_MUN),                                                                                    oFont10F)
oPrinter:Say(265, 300, "UF: ",                                                                                                  oFont10T)
oPrinter:Say(265, 320, +ALLTRIM(QRY->A4_EST),                                                                                   oFont10F)
oPrinter:Say(275, 10, "CONTATO: ",                                                                                              oFont10T)
oPrinter:Say(275, 50, +ALLTRIM(QRY->A4_CONTATO),                                                                                oFont10F)
oPrinter:Say(275, 200, "TEL: ",                                                                                                 oFont10T)
oPrinter:Say(275, 220, '('+ALLTRIM(QRY->A4_DDD)+')'+ALLTRIM(TransForm(QRY->A4_TEL, '@r 9999-9999')),                            oFont10F)

oPrinter:Line(280,05,280,550)

 oPrinter:Say(290,200, " DADOS INTERNOS",                                                                                       oFont14TC)
 oPrinter:Say(300, 10, "VENDEDOR(A): ",                                                                                         oFont10T)
 oPrinter:Say(300, 70, +ALLTRIM(QRY->A3_NOME),                                                                                  oFont10F)
 oPrinter:Say(300, 220, "COND. PGTO.: ",                                                                                        oFont10T)
 oPrinter:Say(300, 280, +ALLTRIM(QRY->E4_COND)+ '/' +ALLTRIM(QRY->E4_DESCRI),                                                   oFont10F)
 oPrinter:Say(300, 430, "TIPO FRETE: ",                                                                                         oFont10T)
 oPrinter:Say(300, 485, +ALLTRIM(QRY->C5_TPFRETE),                                                                              oFont10F)
 oPrinter:Say(310, 10,  "MOEDA: ",                                                                                              oFont10T)
 oPrinter:Say(310, 40,  OemToAnsi(GetMV("MV_SIMB"+cValToChar(QRY->C5_MOEDA),.F.,'')),                                           oFont10F)
 oPrinter:Say(310, 55, ' - ' +cValTochar(QRY->C5_TXMOEDA),                                                                      oFont10F)
 oPrinter:Say(310, 190, "PED. CLIENTE: ",                                                                                       oFont10T)
 oPrinter:Say(310, 255, +ALLTRIM(QRY->C6_PEDCLI),                                                                               oFont10F)
 oPrinter:Say(310, 400, "PROD. CLIENTE: ",                                                                                      oFont10T)
 oPrinter:Say(310, 470, +ALLTRIM(QRY->C6_XPROCLI),                                                                              oFont10F)
 oPrinter:Say(320, 10, "OBSERVAÇÃO: ",                                                                                          oFont10T)
 oPrinter:Say(320, 65, +ALLTRIM(QRY->C5_XOBS),                                                                                  oFont10F)
 oPrinter:Say(330, 10, "MENSAG. NOTA: ",                                                                                        oFont10T)
 oPrinter:Say(330, 75, +ALLTRIM(QRY->C5_MENNOTA),                                                                               oFont10F)

oPrinter:Line(335,05,335,550)

oPrinter:Say(345,200, " ITENS DO PEDIDO ",                                                                                      oFont14TC)

//nLin += NSpace30

oPrinter:FillRect({350, 05, 350+010, 550}, oHGRAY)
oPrinter:Line( 335      ,05 , 60,     05)
oPrinter:Line( 60       ,05 , 60,     550)
oPrinter:Line( 335      ,550 , 60,     550)
oPrinter:Line( 350      ,05 , 350   , 550)
oPrinter:Line( 350+10   ,05 , 350+10, 550)
oPrinter:Line( 350      ,05 , 350+10,  05)
oPrinter:Line( 350      ,05 , 350+10,  05)
// Linhas horizontais
oPrinter:Line( 350      ,40  , 350+10,  40)
oPrinter:Line( 350      ,260 , 350+10,  260)
oPrinter:Line( 350      ,310 , 350+10,  310)
oPrinter:Line( 350      ,340 , 350+10,  340)
oPrinter:Line( 350      ,400 , 350+10,  400)
oPrinter:Line( 350      ,430 , 350+10,  430)
oPrinter:Line( 350      ,480 , 350+10,  480)
oPrinter:Line( 350      ,550 , 350+10,  550)

oPrinter:Say(357, 12, "ITENS",                                                                                                   oFont7TA)
oPrinter:Say(357, 45, "DESCRIÇÃO - PRODUTOS",                                                                                    oFont7TA)
oPrinter:Say(357, 277, "QTDA.",                                                                                                  oFont7TA)
oPrinter:Say(357, 317, "UNID.",                                                                                                  oFont7TA)
oPrinter:Say(357, 353, "VLR. UNIT.",                                                                                             oFont7TA)
oPrinter:Say(357, 409, "% IPI",                                                                                                  oFont7TA)
oPrinter:Say(357, 442, "ICMSRET",                                                                                                oFont7TA)
oPrinter:Say(357, 505, "TOTAL",                                                                                                  oFont7TA)

nLinha1 := 360
nLinha2 := 367    
nLinha  := 370

While !("QRY")->(EOF())


   oPrinter:Line( nLinha  ,05 , nLinha   , 550)

   oPrinter:Line( nLinha1 ,05  , nLinha1+10,  05)
   oPrinter:Line( nLinha1 ,40  , nLinha1+10,  40)
   oPrinter:Line( nLinha1 ,260 , nLinha1+10,  260)
   oPrinter:Line( nLinha1 ,310 , nLinha1+10,  310)
   oPrinter:Line( nLinha1 ,340 , nLinha1+10,  340)
   oPrinter:Line( nLinha1 ,400 , nLinha1+10,  400)
   oPrinter:Line( nLinha1 ,430 , nLinha1+10,  430)
   oPrinter:Line( nLinha1 ,480 , nLinha1+10,  480)
   oPrinter:Line( nLinha1 ,550 , nLinha1+10,  550)   
   oPrinter:Say( nLinha2, 15, +ALLTRIM(("QRY")->C6_ITEM),                                                                            oFont09F )
   oPrinter:Say( nLinha2, 45, +ALLTRIM(("QRY")->C6_DESCRI),                                                                          oFont09F )
   oPrinter:Say( nLinha2, 275, +TRANSFORM(("QRY")->C6_QTDVEN,'@e 999.99'),                                                           oFont09F )
   oPrinter:Say( nLinha2, 320, +ALLTRIM(("QRY")->C6_UM),                                                                             oFont09F )
   oPrinter:Say( nLinha2, 350, +TRANSFORM(("QRY")->C6_PRCVEN,'@E 999,999.999'),                                                      oFont09F )
   oPrinter:Say( nLinha2, 400, +TRANSFORM(("QRY")->C6_XIPI,'@E 999.99'),                                                             oFont09F )
   oPrinter:Say( nLinha2, 420, +TRANSFORM(("QRY")->C6_XICMSRT,'@E 999,999.999'),                                                     oFont09F )
   oPrinter:Say( nLinha2, 490, +TRANSFORM(("QRY")->C6_VALOR,'@E 999,999.999'),                                                       oFont09F )
   nLinha1 += 10 
   nLinha2 += 10      
   nLinha  += 10

   nTotal    += QRY->C6_VALOR
   nIpi      += (QRY->C6_VALOR * QRY->C6_XIPI)/100
   nIcmsSub  += QRY->C6_XICMSRT

   QRY->(DbSkip())

EndDo

nTotalF   += (nTotal + nIpi + nIcmsSub)

oPrinter:Box(nLinha1,    05, nLinha1+80, 550)
oPrinter:Line( nLinha+55  ,05 , nLinha+55   , 550)
oPrinter:Say(nLinha1+15, 15, "SUBTOTAL: ",                                                                                           oFont14TC)
oPrinter:Say(nLinha1+15, 90, +TRANSFORM(nTotal,'@E 999,999.999'),                                                                    oFont14TC)
oPrinter:Say(nLinha1+30, 15, "TOTAL IPI: ",                                                                                          oFont14TC)
oPrinter:Say(nLinha1+30, 90, +TRANSFORM(nIpi,'@E 999,999.999'),                                                                      oFont14TC)
oPrinter:Say(nLinha1+45, 15, "ICMS SUB.: ",                                                                                          oFont14TC)
oPrinter:Say(nLinha1+45, 90, +TRANSFORM(nIcmsSub,'@E 999,999.999'),                                                                  oFont14TC)
oPrinter:Say(nLinha1+60, 15, "TOTAL FAT.: ",                                                                                         oFont14TC)
oPrinter:Say(nLinha1+60, 90, +TRANSFORM(nTotalF,'@E 999,999.999'),                                                                   oFont14TC)

oPrinter:Say(nLinha+65,  45, "PESO LIQUIDO: ",                                                                                       oFont10T)
oPrinter:Say(nLinha+65,  90,  +TRANSFORM(SC5->C5_PESOL,'@E 999,999.999'),                                                            oFont10F)
oPrinter:Say(nLinha+65,  355, "PESO BRUTO: ",                                                                                        oFont10T)
oPrinter:Say(nLinha+65,  390, +TRANSFORM(SC5->C5_PBRUTO,'@E 999,999.999'),                                                           oFont10F)       

oPrinter:EndPage()

If lPreview
     oPrinter:Preview()
EndIf                      

FreeObj(oPrinter)
oPrinter := Nil


Return .T.

1 answer

3


I believe the cause of the error lies in the fact that you are re-executing a PREPARE ENVIRONMENT, within a function ( U_TSTREL ) that is being called from a Menu or Browse option, where you already have the environment / ERP execution context already prepared. I recommend removing the unnecessary Rpcsetenv() and Prepare Environment calls in this case, and make sure that this solves the problem.

  • Thank you very much, I removed this part of my function and it worked no more error appeared.... Thank you very much

Browser other questions tagged

You are not signed in. Login or sign up in order to post.