Jump to content
Fivewin Brasil

Exemplo de Geração do Speed conforme minha base


Wellington Vieira

Recommended Posts


#include "FiveWin.ch"

#include "common.ch"

#include "postgres.ch"

#include "Folder.ch"

#include "report.ch"

#include "barcode.ch"

//#include "vget.ch"

//#include "vbtnbmp.ch"

#Define clr_vermelho nRGB( 127, 058, 017 )

#define btn_width 12

#define btn_height 10

function spedfiscal()

define brush obrush color mtela

DEFINE BITMAP otpContador FILENAME "spedfiscal.bmp"

define dialog spedfis title "EFD - Escrituracao Fiscal Digital" from 010,010 to 438,790 pixel brush oBrush

define font mtahoma name "Tahoma" size 5.5,13

define font mtahoma1 name "Tahoma" size 08,22

define font oFont name 'MS Sans Serif' size 6,15

define font ofontL name "Courier" size 11,11

mbldg = 0

mblvs = space(03) // versÆo do layout

mfinl = "Remessa do arquivo original"

afinl = {"Remessa do arquivo original","Remessa do arquivo substituto"}

mperf = "B - Perfil B"

aperf = {"A - Perfil A","B - Perfil B","C - Perfil C"}

mindi = "1 - Outros"

aindi = {"0 - Industrial ou equiparado a industrial","1 - Outros"}

mdtin = ctod("")

mdtfi = ctod("")

minvt = .f.

// para os registros de entrada que foram lancados no sistema..........

mbaseCalculoICMS = .t.

mvaloICMSentrada = .t.

mbaseCalculoICMSSt = .t.

mvaloICMSStentrada = .t.

mvalorIPI = .t.

finvt = ""

ainvt = {}

cQuery := "select * from n60300000 where"+;

" wemp = " + alltrim(str(memp))+;

" and wstd = " + "'"+"I"+"'"+;

" order by wndc asc;"

oQuery := oServer:Query(cQuery)

aadd(ainvt,space(06))

DO WHILE ! oQuery:Eof()

nwstd = oQuery:Fieldget(oQuery:Fieldpos('wstd'))

if !empty(nwstd)

nwndc = oQuery:Fieldget(oQuery:Fieldpos('wndc'))

if empty(ainvt)

aadd(ainvt,nwndc)

else

msn = "N"

for tt = 1 to len(ainvt)

if alltrim(nwndc) = alltrim(ainvt[tt])

msn = "S"

exit

endif

next

if msn = "N"

aadd(ainvt,nwndc)

endif

endif

endif

oQuery:Skip()

END

oQuery:destroy()

@ 35.5,002 say "Versao do leiaute Ato Cotepe" of spedfis font mtahoma color mcolorAA,mcolorAB pixel

@ 035 ,100 get oblvs var mblvs picture "@!" font mtahoma size 016,9 of spedfis color mcolorCA,mcolorCB pixel

@ 50,002 say "Finalidade do arquivo Magnetico" of spedfis font mtahoma color mcolorAA,mcolorAB pixel

@ 60,002 combobox ofinl var mfinl items afinl font mtahoma size 250,90 of spedfis color mcolorCA,mcolorCB pixel

@ 75,002 say "Perfil de apresentacao do arquivo fiscal" of spedfis font mtahoma color mcolorAA,mcolorAB pixel

@ 85,002 combobox operf var mperf items aperf font mtahoma size 250,90 of spedfis color mcolorCA,mcolorCB pixel

@ 100,002 say "Indicador do tipo de atividade" of spedfis font mtahoma color mcolorAA,mcolorAB pixel

@ 110,002 combobox oindi var mindi items aindi font mtahoma size 250,90 of spedfis color mcolorCA,mcolorCB pixel

@ 125, 002 say "Período a ser gerado" of spedfis font mtahoma color mcolorAA,mcolorAB pixel

@ 135, 002 say "Data inicial:" of spedfis font mtahoma color mcolorAA,mcolorAB pixel

@ 135, 040 get odtin var mdtin font mtahoma size 32,9 of spedfis color mcolorCA,mcolorCB pixel

@ 145, 002 say "Data final:" of spedfis font mtahoma color mcolorAA,mcolorAB pixel

@ 145, 040 get odtfi var mdtfi font mtahoma size 32,9 of spedfis color mcolorCA,mcolorCB pixel

@ 165,002 checkbox oinvt var minvt prompt "&Gerar o inventario";

font mtahoma colors mcolorAA,mcolorAB size 64, 11 of spedfis pixel

@ 178,002 combobox oinvt var finvt items ainvt font mtahoma size 250,90 of spedfis color mcolorCA,mcolorCB pixel when iif(minvt = .t.,.t.,.f.)

@ 050,265 say "Registro a serem gerados para a Entrada" of spedfis font mtahoma color mcolorAA,mcolorAB pixel

@ 060,265 checkbox obaseCalculoICMS var mbaseCalculoICMS prompt "Com base de calculo do ICMS";

font mtahoma colors mcolorAA,mcolorAB size 100, 11 of spedfis pixel

@ 070,265 checkbox ovaloICMSentrada var mvaloICMSentrada prompt "Com valor de ICMS ";

font mtahoma colors mcolorAA,mcolorAB size 100, 11 of spedfis pixel

@ 080,265 checkbox obaseCalculoICMSSt var mbaseCalculoICMSSt prompt "Com base de calculo do ICMS ST";

font mtahoma colors mcolorAA,mcolorAB size 100, 11 of spedfis pixel

@ 090,265 checkbox ovaloICMSStentrada var mvaloICMSStentrada prompt "Com valor de ICMS ST";

font mtahoma colors mcolorAA,mcolorAB size 100, 11 of spedfis pixel

@ 100,265 checkbox ovalorIPI var mvalorIPI prompt "Com valor de IPI";

font mtahoma colors mcolorAA,mcolorAB size 100, 11 of spedfis pixel

@ 200,004 button orombut0 prompt "Gerar " size 040,12 font oFont OF spedfis pixel action ( gera_efd_fiscal() )

@ 200,047 button orombut1 prompt "Contador" size 040,12 font oFont OF spedfis pixel action ( contador() )

@ 200,090 button orombut2 prompt "Inventario" size 040,12 font oFont OF spedfis pixel action ( n6030008(1) )

@ 200,133 button orombut3 prompt "" size 040,12 font oFont OF spedfis pixel

@ 200,176 button orombut4 prompt "" size 040,12 font oFont OF spedfis pixel

@ 200,219 button orombut5 prompt "" size 040,12 font oFont OF spedfis pixel

@ 200,262 button orombut6 prompt "" size 040,12 font oFont OF spedfis pixel

@ 200,305 button orombut7 prompt "" size 040,12 font oFont OF spedfis pixel

@ 200,348 button orombut8 prompt "Sair " size 040,12 font oFont OF spedfis pixel action ( spedfis:end() )

activate dialog spedfis center on Init ( busca_gera_efd_fiscal() ) on Paint ( WndBoxIn(spedfis:Hdc, 064, 001, 066, 790) ,;

WndBoxIn(spedfis:Hdc, 391, 001, 393, 790) ,;

sayBitmapContador() )

return nil

function sayBitmapContador()

spedfis:SayBitmap( (((spedfis:nTop+spedfis:nbottom)/2)-190) -(otpContador:nHeight()/2),((spedfis:nLeft+spedfis:nRight)/2)-(otpContador:nWidth()/2),otpContador,otpContador:nWidth(),otpContador:nHeight())

return nil

function busca_gera_efd_fiscal()

cQuery := "select * from r20200000"+;

" order by bldg asc;"

oQuery := oServer:Query(cQuery)

mbldg = 0

mblvs = space(03) // versÆo do layout

DO WHILE ! oQuery:Eof()

mbldg = oQuery:Fieldget(oQuery:Fieldpos('bldg'))

if !empty(mbldg)

mblvs = oQuery:Fieldget(oQuery:Fieldpos('blvs'))

oblvs:ctext := mblvs

endif

oQuery:Skip()

END

oQuery:destroy()

return nil

// Geracao do arquivo magnetico do EFD - Escritura‡Æo Fiscal Digital............

function gera_efd_fiscal()

if empty(mblvs)

msgstop("Versao do leiaute nao informado.","Atencao")

return nil

endif

if empty(mdtin)

msgstop("Data inicial nao foi informada.","Atencao")

return nil

endif

if empty(mdtfi)

msgstop("Data final nao foi informada.","Atencao")

return nil

endif

if mbldg = 0

cQuery := "insert into r20200000(blvs)"

cQuery += "values("+"'"+mblvs+"'"+")"

oQuery := oServer:Query(cQuery)

if oQuery:neterr()

msgStop("Não foi possível realizar a inclusão.","ATENÇÃO")

//oQuery:error()

endif

oQuery:destroy()

oServer:Commit()

else

cQuery := "Update r20200000 set "+;

"blvs = " + "'"+mblvs+"'"+;

" where " + " bldg = " + alltrim(str(mbldg))

oQuery := oServer:Query(cQuery)

if oQuery:neterr()

msgStop("Não foi possível realizar a alteração.","ATENÇÃO")

//oQuery:error()

endif

oQuery:destroy()

oServer:Commit()

endif

// validacoes a serem consideradas para emissao do sped fiscal........

if empty(zaden)

msgstop("Razao social do contribuinte vazio.","Atencao")

return nil

endif

if empty(zaest)

msgstop("Estado do contribuinte vazio.","Atencao")

return nil

endif

if empty(zaies)

msgstop("Inscricao Estadual do contribuinte vazio.","Atencao")

return nil

endif

if empty(zaibg)

msgstop("Codigo do municipio do IBGE do contribuinte vazio.","Atencao")

return nil

endif

if empty(zatf1)

msgstop("Numero do telefone do contribuinte vazio.","Atencao")

return nil

endif

if empty(zatfx)

msgstop("Numero do fax do contribuinte vazio.","Atencao")

return nil

endif

// verifica os dados do contador .....................................

cQuery := "select * from r20100000"+;

" order by ctnm asc;"

oQuery := oServer:Query(cQuery)

mctdg = 0

DO WHILE ! oQuery:Eof()

mctdg = oQuery:Fieldget(oQuery:Fieldpos('ctdg'))

if !empty(mctdg)

mctnm = oQuery:Fieldget(oQuery:Fieldpos('ctnm'))

mctcf = oQuery:Fieldget(oQuery:Fieldpos('ctcf'))

mctrc = oQuery:Fieldget(oQuery:Fieldpos('ctrc'))

mctpj = oQuery:Fieldget(oQuery:Fieldpos('ctpj'))

mctcp = oQuery:Fieldget(oQuery:Fieldpos('ctcp'))

mctlg = oQuery:Fieldget(oQuery:Fieldpos('ctlg'))

mctnr = oQuery:Fieldget(oQuery:Fieldpos('ctnr'))

mctdc = oQuery:Fieldget(oQuery:Fieldpos('ctdc'))

mctbr = oQuery:Fieldget(oQuery:Fieldpos('ctbr'))

mcttf = oQuery:Fieldget(oQuery:Fieldpos('cttf'))

mctfx = oQuery:Fieldget(oQuery:Fieldpos('ctfx'))

mctml = oQuery:Fieldget(oQuery:Fieldpos('ctml'))

maibg = oQuery:Fieldget(oQuery:Fieldpos('ctbg'))

endif

oQuery:Skip()

END

oQuery:destroy()

if empty(mctdg)

msgstop("Preencha os dados do contabilista.","Atencao")

return nil

endif

// comeca a geracao do arquivo do sped fiscal ........................

cDirXML = "spedfiscal-" + substr(dtos(mdtin),5,2) + "-" + substr(dtos(mdtin),1,4) + ".txt"

Bloco0totallinhas = 0

BlocoCtotallinhas = 0

BlocoDtotallinhas = 0

BlocoEtotallinhas = 0

BlocoGtotallinhas = 0

BlocoHtotallinhas = 0

Bloco1totallinhas = 0

Bloco9totallinhas = 0

mreg0000 = 0

mreg0001 = 0

mreg0005 = 0

mreg0100 = 0

mreg0150 = 0

mreg0190 = 0

mreg0200 = 0

mreg0400 = 0

mreg0990 = 0

mregC001 = 0

mregC100 = 0

mregC170 = 0

mregC190 = 0

mregC990 = 0

mregD001 = 0

mregD990 = 0

mregE001 = 0

mregE100 = 0

mregE110 = 0

//mregE200 = 0

//mregE210 = 0

mregE990 = 0

mregG001 = 0

mregG990 = 0

mregH001 = 0

mregH005 = 0

mregH010 = 0

mregH990 = 0

mreg1001 = 0

mreg1990 = 0

mreg9001 = 0

mreg9900 = 0

mreg9990 = 0

mreg9999 = 0

campoE = {}

mtotalICMS = 0

mtotalICMSst = 0

lh := 0

oPrn := TDosPrn():New(cDirXML)

oPrn:StartPage()

oPrn:lZeraBuffer:=.T.

// B L O C O 0

// registro 0000......................................................

mlinha = "|" + "0000" + "|" + mblvs + "|" + iif(mfinl = "Remessa do arquivo original","0","1") +;

"|" + substr(dtos(mdtin),7,2) + substr(dtos(mdtin),5,2) + substr(dtos(mdtin),1,4) +;

"|" + substr(dtos(mdtfi),7,2) + substr(dtos(mdtfi),5,2) + substr(dtos(mdtfi),1,4) +;

"|" + alltrim(zaden) + "|" + zandn + "|" + "|" + zaest + "|" + alltrim(substr(zaies,1,14)) +;

"|" + alltrim(substr(zaibg,1,7)) + "|" + "|" + "|"+;

iif(mperf = "A - Perfil A","A",iif(mperf = "B - Perfil B","B","C")) + "|"+;

iif(mindi = "1 - Outros","1","0") + "|" + CRLF

oPrn:Say(lh,000,mlinha)

++Bloco0totallinhas

++mreg0000

// registro 0001......................................................

mlinha = "|" + "0001" + "|" + "0" + "|" + CRLF

oPrn:Say(lh,000,mlinha)

++Bloco0totallinhas

++mreg0001

// registro 0005......................................................

// obs.. para o nome fantasia depois ver um modo de pegar alguns dados

// do nome da empresa..

mlinha = "|" + "0005" + "|" + substr(zaden,1,17) + "|" + zacep + "|" + alltrim(zaend) +;

"|" + alltrim(str(zanro)) + "|" + alltrim(zacpl) + "|" + alltrim(zabai)+;

"|" + alltrim(zatf1) + "|" + alltrim(zatfx) + "|" + "|" + CRLF

oPrn:Say(lh,000,mlinha)

++Bloco0totallinhas

++mreg0005

// registro 0100

mlinha = "|" + "0100" + "|" + alltrim(mctnm) + "|" + alltrim(mctcf) + "|" +;

alltrim(mctrc) + "|" + alltrim(mctpj) + "|" + mctcp + "|" +;

alltrim(mctlg) + "|" + alltrim(mctnr) + "|" + alltrim(mctdc) +;

"|" + alltrim(mctbr) + "|" + mcttf + "|" + mctfx + "|" + ;

alltrim(mctml) + "|" + maibg + "|" + CRLF

oPrn:Say(lh,000,mlinha)

++Bloco0totallinhas

++mreg0100

// registro 0150

// para clientes......................................................

acliautorizada := {}

aprodutosusado := {}

aunidadeusadas := {}

acfoputilizado := {}

// se for utilizar o inventario.......................................

if minvt = .t.

finvt = alltrim(finvt)

if !empty(finvt)

ntotv = 0

cQuery := "select * from n60300000 where"+;

" wemp = " + alltrim(str(memp))+;

" and wndc = " + "'"+alltrim(finvt)+"'"+;

" and wstd = " + "'"+"I"+"'"+;

" order by wndc asc;"

oQuery := oServer:Query(cQuery)

DO WHILE ! oQuery:Eof()

nwstd = oQuery:Fieldget(oQuery:Fieldpos('wstd'))

if !empty(nwstd)

if nwstd != "I"

oQuery:Skip()

loop

endif

iwbcf = oQuery:Fieldget(oQuery:Fieldpos('wbcf')) // codigo normal

iwqit = oQuery:Fieldget(oQuery:Fieldpos('wqit')) // quantidade a ser fabricada

iwvlr = oQuery:Fieldget(oQuery:Fieldpos('wvlr')) // valor..

ntotv = ntotv + ( iwqit * iwvlr )

wQuery := "select * from e40100000 where"

wQuery += " bcdg = " + "'"+alltrim(iwbcf)+"'"

wQuery += " order by bcdg asc;"

owQuery := oServer:Query(wQuery)

nqnpc = owQuery:Fieldget(owQuery:Fieldpos('bcdg'))

nqund = owQuery:Fieldget(owQuery:Fieldpos('bund'))

nqund = alltrim(nqund)

nqdpr = owQuery:Fieldget(owQuery:Fieldpos('bprd'))

nqcap = owQuery:Fieldget(owQuery:Fieldpos('bcap'))

owQuery:destroy()

cyQuery := "select * from e40200000 where "+;

"cemp = " + alltrim(str(memp)) +;

" and ccap = " + alltrim(str(nqcap)) + " order by ccap asc;"

oyQuery := oServer:Query(cyQuery)

nqcdcl = oyQuery:Fieldget(oyQuery:Fieldpos('cdcl'))

nqcdcl = substr(alltrim(nqcdcl),1,8)

oyQuery:destroy()

// para as unidades de medidas existentes no sistema............

if upper(nqund) = "PC"

ncdund = "1"

elseif upper(nqund) = "KG"

ncdund = "2"

elseif upper(nqund) = "MT"

ncdund = "3"

elseif upper(nqund) = "UN"

ncdund = "4"

elseif upper(nqund) = "UND"

ncdund = "5"

endif

if empty(aunidadeusadas)

aadd(aunidadeusadas,{ncdund,nqund})

else

msn = "S"

for tt = 1 to len(aunidadeusadas)

if aunidadeusadas[tt,1] = ncdund

msn = "N"

exit

endif

next

if msn = "S"

aadd(aunidadeusadas,{ncdund,nqund})

endif

endif

// para produtos que estao usados no inventario...........

if empty(aprodutosusado)

aadd(aprodutosusado,{nqnpc,alltrim(nqdpr),"","",ncdund,"00",nqcdcl,"","","",""})

else

msn = "S"

for tt = 1 to len(aprodutosusado)

if aprodutosusado[tt,1] = nqnpc

msn = "N"

exit

endif

next

if msn = "S"

aadd(aprodutosusado,{nqnpc,alltrim(nqdpr),"","",ncdund,"00",nqcdcl,"","","",""})

endif

endif

endif

oQuery:Skip()

END

oQuery:destroy()

endif

endif

nsaidas := nentradas := 0

ndtin = substr(dtos(mdtin),1,4)+"-"+substr(dtos(mdtin),5,2)+"-"+substr(dtos(mdtin),7,2)

ndtfi = substr(dtos(mdtfi),1,4)+"-"+substr(dtos(mdtfi),5,2)+"-"+substr(dtos(mdtfi),7,2)

if mdtin = mdtfi

cQuery := "select * from f50900000 where"+;

" p035 = " + "'"+ndtin+"'"

else

cQuery := "select * from f50900000 where"+;

" p035 >= " + "'"+ndtin+"'" + " and"+;

" p035 <= " + "'"+ndtfi+"'"

endif

cQuery += " order by p035 desc;"

oQuery := oServer:Query(cQuery)

DO WHILE ! oQuery:Eof()

pasq = oQuery:Fieldget(oQuery:Fieldpos('pasq'))

p051 = oQuery:Fieldget(oQuery:Fieldpos('p051'))

p094 = oQuery:Fieldget(oQuery:Fieldpos('p094')) // Entrada ou Saida..

nsta = oQuery:Fieldget(oQuery:Fieldpos('pstu')) // Situacao da nota

mp016 = oQuery:Fieldget(oQuery:Fieldpos('p016')) // numero do pedido ou romaneio..

mp016 = alltrim(mp016)

nrnop = oQuery:Fieldget(oQuery:Fieldpos('p062'))

np062 = oQuery:Fieldget(oQuery:Fieldpos('p062'))

np062 = alltrim(substr(np062,1,4))

nrdno = ""

cqQuery := "select * from f51100000 "+;

"where rnop = " + alltrim(nrnop)+;

" order by rnop asc;"

oqQuery := oServer:Query(cqQuery)

nrdno = oqQuery:Fieldget(oqQuery:Fieldpos('rdno'))

oqQuery:destroy()

if empty(pasq)

oQuery:Skip()

loop

endif

if nsta != 5

if nsta = 6

if empty(acliautorizada)

aadd(acliautorizada,p051)

else

msn = "S"

for tt = 1 to len(acliautorizada)

if acliautorizada[tt] = p051

msn = "N"

exit

endif

next

if msn = "S"

aadd(acliautorizada,p051)

endif

endif

endif

oQuery:Skip()

loop

endif

if empty(acliautorizada)

aadd(acliautorizada,p051)

else

msn = "S"

for tt = 1 to len(acliautorizada)

if acliautorizada[tt] = p051

msn = "N"

exit

endif

next

if msn = "S"

aadd(acliautorizada,p051)

endif

endif

if p094 = "S"

++nsaidas

elseif p094 = "E"

++nentradas

endif

// acrescenta os cfops.. usados nas saidas e entradas..............

//if empt(acfoputilizado)

// aadd(acfoputilizado,{np062,nrdno})

//else

// msn = "S"

// for tt = 1 to len(acfoputilizado)

// if acfoputilizado[tt,1] = np062

// msn = "N"

// exit

// endif

// next

// if msn = "S"

// aadd(acfoputilizado,{np062,nrdno})

// endif

//endif

// Detalha os produtos e seus impostos................................

czQuery := "select * from f51000000 where"+;

" qnpd = " + "'"+mp016+"'"+;

" order by qnpd asc;"

ozQuery := oServer:Query(czQuery)

DO WHILE !ozQuery:Eof()

nqcap = ozQuery:Fieldget(ozQuery:Fieldpos('qcap')) // codigo de acesso ao produto

cwQuery := "select * from e40100000 where "+;

"bcap = " + alltrim(str(nqcap)) + " order by bcap asc;"

owQuery := oServer:Query(cwQuery)

nqnpc = owQuery:Fieldget(owQuery:Fieldpos('bcdg')) // numero da pe‡a

nqdpr = owQuery:Fieldget(owQuery:Fieldpos('bprd')) // descricao do produto

nqund = owQuery:Fieldget(owQuery:Fieldpos('bund')) // unidade do produto

nqund = alltrim(nqund)

owQuery:destroy()

cyQuery := "select * from e40200000 where "+;

"cemp = " + alltrim(str(memp)) +;

" and ccap = " + alltrim(str(nqcap)) + " order by ccap asc;"

oyQuery := oServer:Query(cyQuery)

nqcdcl = oyQuery:Fieldget(oyQuery:Fieldpos('cdcl'))

nqcdcl = substr(alltrim(nqcdcl),1,8)

oyQuery:destroy()

// para as unidades de medidas existentes no sistema............

if upper(nqund) = "PC"

ncdund = "1"

elseif upper(nqund) = "KG"

ncdund = "2"

elseif upper(nqund) = "MT"

ncdund = "3"

elseif upper(nqund) = "UN"

ncdund = "4"

elseif upper(nqund) = "UND"

ncdund = "5"

endif

if empty(aunidadeusadas)

aadd(aunidadeusadas,{ncdund,nqund})

else

msn = "S"

for tt = 1 to len(aunidadeusadas)

if aunidadeusadas[tt,1] = ncdund

msn = "N"

exit

endif

next

if msn = "S"

aadd(aunidadeusadas,{ncdund,nqund})

endif

endif

// para os produtos que foram usados nas transacoes.............

//if empty(aprodutosusado)

// aadd(aprodutosusado,{nqnpc,alltrim(nqdpr),"","",ncdund,"00",nqcdcl,"","","",""})

//else

// msn = "S"

// for tt = 1 to len(aprodutosusado)

// if aprodutosusado[tt,1] = nqnpc

// msn = "N"

// exit

// endif

// next

// if msn = "S"

// aadd(aprodutosusado,{nqnpc,alltrim(nqdpr),"","",ncdund,"00",nqcdcl,"","","",""})

// endif

//endif

ozQuery:Skip()

END

ozQuery:destroy()

oQuery:Skip()

END

oQuery:destroy()

for tt = 1 to len(acliautorizada)

cQuery := "select * from r20000000 where "+;

"acdc = " + alltrim(str(val(acliautorizada[tt])))

cQuery += " order by acdc asc;"

oQuery := oServer:Query(cQuery)

ncod_part = oQuery:Fieldget(oQuery:Fieldpos('acdc'))

ncod_part = alltrim(str(ncod_part))

nnome = oQuery:Fieldget(oQuery:Fieldpos('anrs'))

nnome = alltrim(nnome)

ncod_pais = "01058"

napfj = oQuery:Fieldget(oQuery:Fieldpos('apfj'))

if napfj = "F"

ncnpj = ""

ncnpf = oQuery:Fieldget(oQuery:Fieldpos('andn'))

else

ncnpj = oQuery:Fieldget(oQuery:Fieldpos('andn'))

ncnpf = ""

endif

nie = oQuery:Fieldget(oQuery:Fieldpos('andl'))

nie = alltrim(substr(nie,1,14))

ncod_mun = oQuery:Fieldget(oQuery:Fieldpos('aibg'))

ncod_mun = substr(ncod_mun,1,7)

nsuframa = ""

nend = oQuery:Fieldget(oQuery:Fieldpos('aend'))

nend = alltrim(nend)

nnum = oQuery:Fieldget(oQuery:Fieldpos('anro'))

nnum = alltrim(nnum)

ncompl = oQuery:Fieldget(oQuery:Fieldpos('acmp'))

ncompl = alltrim(ncompl)

nbairro = oQuery:Fieldget(oQuery:Fieldpos('abai'))

nbairro = alltrim(nbairro)

mlinha = "|" + "0150" + "|" + ncod_part + "|" + nnome + "|" + ncod_pais +;

"|" + ncnpj + "|" + ncnpf + "|" + nie + "|" + ncod_mun +;

"|" + nsuframa + "|" + nend + "|" + nnum + "|" + ncompl+;

"|" + nbairro + "|" + CRLF

oPrn:Say(lh,000,mlinha)

++Bloco0totallinhas

++mreg0150

next

// para fornecedores..................................................

aforautorizada := {}

ndtin = substr(dtos(mdtin),1,4)+"-"+substr(dtos(mdtin),5,2)+"-"+substr(dtos(mdtin),7,2)

ndtfi = substr(dtos(mdtfi),1,4)+"-"+substr(dtos(mdtfi),5,2)+"-"+substr(dtos(mdtfi),7,2)

if mdtin = mdtfi

cQuery := "select * from f60900000 where"+;

" pent = " + "'"+ndtin+"'"

else

cQuery := "select * from f60900000 where"+;

" pent >= " + "'"+ndtin+"'" + " and"+;

" pent <= " + "'"+ndtfi+"'"

endif

cQuery += " order by pent desc;"

oQuery := oServer:Query(cQuery)

DO WHILE ! oQuery:Eof()

pasq = oQuery:Fieldget(oQuery:Fieldpos('pasq'))

p051 = oQuery:Fieldget(oQuery:Fieldpos('pclf'))

p051 = alltrim(strzero(p051,5))

mpncd = oQuery:Fieldget(oQuery:Fieldpos('pncd'))

p094 = "E"

nrnop = oQuery:Fieldget(oQuery:Fieldpos('pcfo'))

nrnop = alltrim(str(nrnop))

np062 = oQuery:Fieldget(oQuery:Fieldpos('pcfo'))

np062 = alltrim(str(np062))

nrdno = ""

cqQuery := "select * from f51100000 "+;

"where substr(rnop,1,4) = " + alltrim(nrnop)+;

" order by rnop asc;"

oqQuery := oServer:Query(cqQuery)

nrdno = oqQuery:Fieldget(oqQuery:Fieldpos('rdno'))

oqQuery:destroy()

if empty(pasq)

oQuery:Skip()

loop

endif

if empty(aforautorizada)

aadd(aforautorizada,p051)

else

msn = "S"

for tt = 1 to len(aforautorizada)

if aforautorizada[tt] = p051

msn = "N"

exit

endif

next

if msn = "S"

aadd(aforautorizada,p051)

endif

endif

++nentradas

// acrescenta os cfops.. usados nas saidas e entradas..............

if empt(acfoputilizado)

aadd(acfoputilizado,{np062,nrdno})

else

msn = "S"

for tt = 1 to len(acfoputilizado)

if acfoputilizado[tt,1] = np062

msn = "N"

exit

endif

next

if msn = "S"

aadd(acfoputilizado,{np062,nrdno})

endif

endif

// Detalha os produtos e seus impostos................................

czQuery := "select * from f61000000 where"+;

" qncd = " + alltrim(str(mpncd))+;

" order by qncd asc;"

ozQuery := oServer:Query(czQuery)

DO WHILE !ozQuery:Eof()

nqcap = ozQuery:Fieldget(ozQuery:Fieldpos('qcap')) // codigo de acesso ao produto

cwQuery := "select * from e40100000 where "+;

"bcap = " + alltrim(str(nqcap)) + " order by bcap asc;"

owQuery := oServer:Query(cwQuery)

nqnpc = owQuery:Fieldget(owQuery:Fieldpos('bcdg')) // numero da pe‡a

nqdpr = owQuery:Fieldget(owQuery:Fieldpos('bprd')) // descricao do produto

nqund = owQuery:Fieldget(owQuery:Fieldpos('bund')) // unidade do produto

nqund = alltrim(nqund)

owQuery:destroy()

cyQuery := "select * from e40200000 where "+;

"cemp = " + alltrim(str(memp)) +;

" and ccap = " + alltrim(str(nqcap)) + " order by ccap asc;"

oyQuery := oServer:Query(cyQuery)

nqcdcl = oyQuery:Fieldget(oyQuery:Fieldpos('cdcl'))

nqcdcl = substr(alltrim(nqcdcl),1,8)

oyQuery:destroy()

// para as unidades de medidas existentes no sistema............

if upper(nqund) = "PC"

ncdund = "1"

elseif upper(nqund) = "KG"

ncdund = "2"

elseif upper(nqund) = "MT"

ncdund = "3"

elseif upper(nqund) = "UN"

ncdund = "4"

elseif upper(nqund) = "UND"

ncdund = "5"

endif

if empty(aunidadeusadas)

aadd(aunidadeusadas,{ncdund,nqund})

else

msn = "S"

for tt = 1 to len(aunidadeusadas)

if aunidadeusadas[tt,1] = ncdund

msn = "N"

exit

endif

next

if msn = "S"

aadd(aunidadeusadas,{ncdund,nqund})

endif

endif

// para os produtos que foram usados nas transacoes.............

if empty(aprodutosusado)

aadd(aprodutosusado,{nqnpc,alltrim(nqdpr),"","",ncdund,"00",nqcdcl,"","","",""})

else

msn = "S"

for tt = 1 to len(aprodutosusado)

if aprodutosusado[tt,1] = nqnpc

msn = "N"

exit

endif

next

if msn = "S"

aadd(aprodutosusado,{nqnpc,alltrim(nqdpr),"","",ncdund,"00",nqcdcl,"","","",""})

endif

endif

ozQuery:Skip()

END

ozQuery:destroy()

oQuery:Skip()

END

oQuery:destroy()

for tt = 1 to len(aforautorizada)

cQuery := "select * from r10000000 where "+;

"acdg = " + alltrim(str(val(aforautorizada[tt])))

cQuery += " order by acdg asc;"

oQuery := oServer:Query(cQuery)

ncod_part = oQuery:Fieldget(oQuery:Fieldpos('acdg'))

ncod_part = "FOR-" + alltrim(str(ncod_part))

nnome = oQuery:Fieldget(oQuery:Fieldpos('anrs'))

nnome = alltrim(nnome)

ncod_pais = "01058"

napfj = oQuery:Fieldget(oQuery:Fieldpos('andn'))

napfj = alltrim(napfj)

if len(napfj) <= 11

ncnpj = ""

ncnpf = oQuery:Fieldget(oQuery:Fieldpos('andn'))

else

ncnpj = oQuery:Fieldget(oQuery:Fieldpos('andn'))

ncnpf = ""

endif

nie = oQuery:Fieldget(oQuery:Fieldpos('andl'))

nie = alltrim(substr(nie,1,14))

ncod_mun = oQuery:Fieldget(oQuery:Fieldpos('aibg'))

ncod_mun = substr(ncod_mun,1,7)

nsuframa = ""

nend = oQuery:Fieldget(oQuery:Fieldpos('aend'))

nend = alltrim(nend)

nnum = oQuery:Fieldget(oQuery:Fieldpos('anro'))

nnum = alltrim(nnum)

ncompl = ""

nbairro = oQuery:Fieldget(oQuery:Fieldpos('abai'))

nbairro = alltrim(nbairro)

mlinha = "|" + "0150" + "|" + ncod_part + "|" + nnome + "|" + ncod_pais +;

"|" + ncnpj + "|" + ncnpf + "|" + nie + "|" + ncod_mun +;

"|" + nsuframa + "|" + nend + "|" + nnum + "|" + ncompl+;

"|" + nbairro + "|" + CRLF

oPrn:Say(lh,000,mlinha)

++Bloco0totallinhas

++mreg0150

next

// registro 0190

for tt = 1 to len(aunidadeusadas)

mlinha = "|" + "0190" + "|" + aunidadeusadas[tt,1] + "|" + aunidadeusadas[tt,2] + "|" + CRLF

oPrn:Say(lh,000,mlinha)

++Bloco0totallinhas

++mreg0190

next

// registro 0200

for tt = 1 to len(aprodutosusado)

mlinha = "|" + "0200" + "|" + aprodutosusado[tt,1] + "|" + aprodutosusado[tt,2];

+ "|" + aprodutosusado[tt,3] + "|" + aprodutosusado[tt,4];

+ "|" + aprodutosusado[tt,5] + "|" + aprodutosusado[tt,6];

+ "|" + aprodutosusado[tt,7] + "|" + aprodutosusado[tt,8];

+ "|" + aprodutosusado[tt,9] + "|" + aprodutosusado[tt,10];

+ "|" + aprodutosusado[tt,11] + "|" + CRLF

oPrn:Say(lh,000,mlinha)

++Bloco0totallinhas

++mreg0200

next

// registro 0400

for tt = 1 to len(acfoputilizado)

mlinha = "|" + "0400" + "|" + acfoputilizado[tt,1] + "|" + alltrim(acfoputilizado[tt,2]) + "|" + CRLF

oPrn:Say(lh,000,mlinha)

++Bloco0totallinhas

++mreg0400

next

// registro 0990

++Bloco0totallinhas

++mreg0990

mlinha = "|" + "0990" + "|" + alltrim(str(Bloco0totallinhas)) + "|" + CRLF

oPrn:Say(lh,000,mlinha)

// B L O C O C

if nsaidas = 0 .and. nentradas = 0

// registro c001

mlinha = "|" + "C001" + "|" + "1" + CRLF

oPrn:Say(lh,000,mlinha)

++BlocoCtotallinhas

++mregC001

// registro c990

++BlocoCtotallinhas

++mregC990

mlinha = "|" + "C990" + "|" + alltrim(str(BlocoCtotallinhas)) + CRLF

oPrn:Say(lh,000,mlinha)

else

mlinha = "|" + "C001" + "|" + "0" + "|"+ CRLF

oPrn:Say(lh,000,mlinha)

++BlocoCtotallinhas

++mregC001

// registro c001

// Notas fiscais eletronica de saida e entrada emissao propria

ndtin = substr(dtos(mdtin),1,4)+"-"+substr(dtos(mdtin),5,2)+"-"+substr(dtos(mdtin),7,2)

ndtfi = substr(dtos(mdtfi),1,4)+"-"+substr(dtos(mdtfi),5,2)+"-"+substr(dtos(mdtfi),7,2)

for pt = 1 to 2

if pt = 1

ntipodenota = "S"

elseif pt = 2

ntipodenota = "E"

endif

if mdtin = mdtfi

cQuery := "select * from f50900000 where"+;

" p035 = " + "'"+ndtin+"'"

else

cQuery := "select * from f50900000 where"+;

" p035 >= " + "'"+ndtin+"'" + " and"+;

" p035 <= " + "'"+ndtfi+"'"

endif

cQuery += " and p094 = " + "'"+ntipodenota+"'"

cQuery += " order by p034 asc;"

oQuery := oServer:Query(cQuery)

pasq = oQuery:Fieldget(oQuery:Fieldpos('pasq'))

if !empty(pasq)

DO WHILE ! oQuery:Eof()

psql = oQuery:Fieldget(oQuery:Fieldpos('pasq'))

pstu = oQuery:Fieldget(oQuery:Fieldpos('pstu')) // Situacao da nota

p016 = oQuery:Fieldget(oQuery:Fieldpos('p016')) // numero do pedido

p051 = oQuery:Fieldget(oQuery:Fieldpos('p051')) // codigo do cliente

psnf = oQuery:Fieldget(oQuery:Fieldpos('psnf')) // serie da nota fiscal

p034 = oQuery:Fieldget(oQuery:Fieldpos('p034')) // numero da nota fiscal

pchv = oQuery:Fieldget(oQuery:Fieldpos('pchv')) // chave de acesso da nota fiscal eletronica

p035 = oQuery:Fieldget(oQuery:Fieldpos('p035')) // data de emissao

p033 = oQuery:Fieldget(oQuery:Fieldpos('p033')) // data de saida

p026 = oQuery:Fieldget(oQuery:Fieldpos('p026')) // valor do documento

p089 = oQuery:Fieldget(oQuery:Fieldpos('p089')) // tipo de pagamento

p024 = oQuery:Fieldget(oQuery:Fieldpos('p024')) // valor total dos produtos

p069 = oQuery:Fieldget(oQuery:Fieldpos('p069')) // frete

p021 = oQuery:Fieldget(oQuery:Fieldpos('p021')) // valor do frete

p022 = oQuery:Fieldget(oQuery:Fieldpos('p022')) // valor do seguro

p063 = oQuery:Fieldget(oQuery:Fieldpos('p063')) // outras despesas e acessorios

p053 = oQuery:Fieldget(oQuery:Fieldpos('p053')) // base de calculo

p054 = oQuery:Fieldget(oQuery:Fieldpos('p054')) // valor do icms.

p055 = oQuery:Fieldget(oQuery:Fieldpos('p055'))

p056 = oQuery:Fieldget(oQuery:Fieldpos('p056'))

p025 = oQuery:Fieldget(oQuery:Fieldpos('p025'))

if pstu < 5

oQuery:Skip()

loop

endif

ind_oper = iif(ntipodenota = "S","1","0")

ind_emit = "0"

if pstu = 6

cod_part = ""

else

cod_part = alltrim(str(val(p051)))

endif

cod_mod = "55"

if pstu = 6

cod_sit = "02"

else

cod_sit = "00"

endif

ser = alltrim(psnf)

num_doc = alltrim(str(val(p034)))

chv_nfe = alltrim(pchv)

if pstu = 6

dt_doc = ""

dt_e_s = ""

vl_doc = ""

ind_pgto = ""

vl_desc = ""

vl_abat_nt = ""

vl_merc = ""

ind_frt = ""

vl_frt = ""

vl_seg = ""

vl_out_da = ""

vl_bc_icms = ""

vl_icms = ""

vl_bc_icmsst = ""

vl_icms_st = ""

vl_ipi = ""

vl_pis = ""

vl_cofins = ""

vl_pis_st = ""

vl_cofins_st = ""

else

dt_doc = substr(dtos(p035),7,2) + substr(dtos(p035),5,2) + substr(dtos(p035),1,4)

if empty(p033)

dt_e_s = ""

else

dt_e_s = substr(dtos(p033),7,2) + substr(dtos(p033),5,2) + substr(dtos(p033),1,4)

endif

vl_doc = alltrim(transform(p026,"@e 999999999.99"))

if p089 = "0"

ind_pgto = "0"

elseif p089 = "1"

ind_pgto = "1"

elseif p089 = "2"

ind_pgto = "9"

endif

vl_desc = "0,00"

vl_abat_nt = "0,00"

vl_merc = alltrim(transform(p024,"@e 999999999.99"))

ind_frt = iif(p069 = "1","1","2")

vl_frt = iif(!empty(p021),alltrim(transform(p021,"@e 999999999.99")),"0,00")

vl_seg = iif(!empty(p022),alltrim(transform(p022,"@e 999999999.99")),"0,00")

vl_out_da = iif(!empty(p063),alltrim(transform(p063,"@e 999999999.99")),"0,00")

vl_bc_icms = iif(!empty(p053),alltrim(transform(p053,"@e 999999999.99")),"0,00")

vl_icms = iif(!empty(p054),alltrim(transform(p054,"@e 999999999.99")),"0,00")

vl_bc_icmsst = iif(!empty(p055),alltrim(transform(p055,"@e 999999999.99")),"0,00")

vl_icms_st = iif(!empty(p056),alltrim(transform(p056,"@e 999999999.99")),"0,00")

vl_ipi = iif(!empty(p025),alltrim(transform(p025,"@e 999999999.99")),"0,00")

vl_pis = "0,00"

vl_cofins = "0,00"

vl_pis_st = "0,00"

vl_cofins_st = "0,00"

endif

mlinha = "|" + "C100" + "|" + ind_oper + "|" + ind_emit;

+ "|" + cod_part + "|" + cod_mod + "|" + cod_sit;

+ "|" + ser + "|" + num_doc + "|" + chv_nfe;

+ "|" + dt_doc + "|" + dt_e_s + "|" + vl_doc;

+ "|" + ind_pgto + "|" + vl_desc + "|" + vl_abat_nt;

+ "|" + vl_merc + "|" + ind_frt + "|" + vl_frt;

+ "|" + vl_seg + "|" + vl_out_da + "|" + vl_bc_icms;

+ "|" + vl_icms + "|" + vl_bc_icmsst + "|" + vl_icms_st;

+ "|" + vl_ipi + "|" + vl_pis + "|" + vl_cofins;

+ "|" + vl_pis_st + "|" + vl_cofins_st + "|" + CRLF

oPrn:Say(lh,000,mlinha)

++BlocoCtotallinhas

++mregC100

if pstu = 6

else

// obs.. o array abaixo sera usado quando a operacao

// tiver cst, cfop e icms diferenciados..

rc190:= {} // array para o registro c190

czQuery := "select * from f51000000 where"+;

" qnpd = " + "'"+p016+"'"+;

" order by qnpd asc;"

ozQuery := oServer:Query(czQuery)

DO WHILE !ozQuery:Eof()

nqcap = ozQuery:Fieldget(ozQuery:Fieldpos('qcap')) // codigo de acesso ao produto

nqcfo = ozQuery:Fieldget(ozQuery:Fieldpos('qcfo')) // cfop

nqqtd = ozQuery:Fieldget(ozQuery:Fieldpos('qqtd')) // quantidade

nquni = ozQuery:Fieldget(ozQuery:Fieldpos('quni')) // unidade

nqvru = ozQuery:Fieldget(ozQuery:Fieldpos('qvru')) // valor unitario

nqvti = ozQuery:Fieldget(ozQuery:Fieldpos('qvti')) // valor total

nqvti = iif(!empty(nqvti),alltrim(transform(nqvti,"@e 999999999.99")),"0,00")

nqcst = ozQuery:Fieldget(ozQuery:Fieldpos('qcst')) // situacao tributaria

nqbci = ozQuery:Fieldget(ozQuery:Fieldpos('qbci')) // base de calculo do i.c.m

nqbci = iif(!empty(nqbci),alltrim(transform(nqbci,"@e 999999999.99")),"0,00")

nqaic = ozQuery:Fieldget(ozQuery:Fieldpos('qaic')) // aliquota de icm

nqvic = ozQuery:Fieldget(ozQuery:Fieldpos('qvic')) // valor do icm

nqvic = iif(!empty(nqvic),alltrim(transform(nqvic,"@e 999999999.99")),"0,00")

nqisn = ozQuery:Fieldget(ozQuery:Fieldpos('qisn')) // isento

nqtrs = ozQuery:Fieldget(ozQuery:Fieldpos('qtrs')) // tributacao na saida

nqadc = ozQuery:Fieldget(ozQuery:Fieldpos('qadc')) // classificacao fiscal

nqads = ozQuery:Fieldget(ozQuery:Fieldpos('qads')) // aliquota diferenciada

//cwQuery := "select * from e40100000 where "+;

// "bcap = " + alltrim(str(nqcap)) + " order by bcap asc;"

//owQuery := oServer:Query(cwQuery)

//nqnpc = owQuery:Fieldget(owQuery:Fieldpos('bcdg')) // numero da pe‡a

//nqdpr = owQuery:Fieldget(owQuery:Fieldpos('bprd')) // descricao do produto

//nqund = owQuery:Fieldget(owQuery:Fieldpos('bund')) // unidade do produto

//nqund = alltrim(nqund)

//owQuery:destroy()

//

//cyQuery := "select * from e40200000 where "+;

// "cemp = " + alltrim(str(memp)) +;

// " and ccap = " + alltrim(str(nqcap)) + " order by ccap asc;"

//oyQuery := oServer:Query(cyQuery)

//nqcdcl = oyQuery:Fieldget(oyQuery:Fieldpos('cdcl'))

//nqcdcl = substr(alltrim(nqcdcl),1,8)

//oyQuery:destroy()

ozQuery:Skip()

END

ozQuery:destroy()

mlinha = "|" + "C190" + "|" + substr(nqcst,1,3) + "|" +;

substr(nqcfo,1,4) + "|" + iif(!empty(nqaic),alltrim(transform(nqaic,"@e 999.99")),"0,00");

+ "|" + vl_doc + "|" + vl_bc_icms;

+ "|" + vl_icms + "|" + vl_bc_icmsst + "|" + vl_icms_st + "|";

+ "0,00" + "|" + "0,00" + "|" + "" + "|" + CRLF

oPrn:Say(lh,000,mlinha)

++BlocoCtotallinhas

++mregC190

endif

oQuery:Skip()

END

endif

oQuery:destroy()

next

// Notas fisciais de entrada ... Lancamento manual.................

if mdtin = mdtfi

cQuery := "select * from f60900000 where"+;

" pent = " + "'"+ndtin+"'"

else

cQuery := "select * from f60900000 where"+;

" pent >= " + "'"+ndtin+"'" + " and"+;

" pent <= " + "'"+ndtfi+"'"

endif

cQuery += " order by pemi asc;"

oQuery := oServer:Query(cQuery)

pasq = oQuery:Fieldget(oQuery:Fieldpos('pasq'))

if !empty(pasq)

DO WHILE ! oQuery:Eof()

psql = oQuery:Fieldget(oQuery:Fieldpos('pasq'))

mpncd = oQuery:Fieldget(oQuery:Fieldpos('pncd'))

p051 = oQuery:Fieldget(oQuery:Fieldpos('pclf')) // codigo do fornecedor

p051 = "FOR-" + alltrim(str(p051))

nNatureza = ""

p062 = oQuery:Fieldget(oQuery:Fieldpos('pcfo'))

p062 = alltrim(str(p062))

for tt = 1 to len(acfoputilizado)

if acfoputilizado[tt,1] = p062

nNatureza = acfoputilizado[tt,2]

exit

endif

next

psnf = oQuery:Fieldget(oQuery:Fieldpos('pser')) // serie da nota fiscal

p034 = oQuery:Fieldget(oQuery:Fieldpos('pnur')) // numero da nota fiscal

p034 = alltrim(str(p034))

pchv = "" // chave de acesso da nota fiscal eletronica

p035 = oQuery:Fieldget(oQuery:Fieldpos('pemi')) // data de emissao

p033 = oQuery:Fieldget(oQuery:Fieldpos('pemi')) // data de saida

p089 = oQuery:Fieldget(oQuery:Fieldpos('pprz')) // tipo de pagamento

p089 = iif(p089 = .t.,"1","0" )

mntmv = oQuery:Fieldget(oQuery:Fieldpos('ptmv'))

// verifica se movimenta o estoque...............................

cwQuery := "select * from e40700000 where "+;

"lcmv = " + alltrim(str(mntmv))

cwQuery += " order by lcmv asc;"

owQuery := oServer:Query(cwQuery)

nlmve = owQuery:Fieldget(owQuery:Fieldpos('lmve'))

owQuery:destroy()

nlmve = iif(nlmve = .t.,"y","n")

pest = oQuery:Fieldget(oQuery:Fieldpos('pest')) // estado da federacao

ptnf = oQuery:Fieldget(oQuery:Fieldpos('ptnf')) // total da nota

if mbaseCalculoICMS = .t.

pbas = oQuery:Fieldget(oQuery:Fieldpos('pbas')) // total da base

else

pbas = 0

endif

if mvaloICMSentrada = .t.

picm = oQuery:Fieldget(oQuery:Fieldpos('picm')) // total do icms

else

picm = 0

endif

pist = oQuery:Fieldget(oQuery:Fieldpos('pist')) // total do isento

pout = oQuery:Fieldget(oQuery:Fieldpos('pout')) // total outros

if mvalorIPI = .t.

pipi = oQuery:Fieldget(oQuery:Fieldpos('pipi')) // total ipi

else

pipi = 0

endif

ptpr = oQuery:Fieldget(oQuery:Fieldpos('ptpr')) // total dos produtos

pfre = oQuery:Fieldget(oQuery:Fieldpos('pfre')) // total frete

pseg = oQuery:Fieldget(oQuery:Fieldpos('pseg')) // total seguro

palq = oQuery:Fieldget(oQuery:Fieldpos('palq')) // aliquota icms

pdes = oQuery:Fieldget(oQuery:Fieldpos('pdes')) // despesa

if mbaseCalculoICMSSt

pbst = oQuery:Fieldget(oQuery:Fieldpos('pbst')) // base substituicao

else

pbst = 0

endif

if mvaloICMSStentrada = .t.

pict = oQuery:Fieldget(oQuery:Fieldpos('pict')) // icms substituicao

else

pict = 0

endif

ind_oper = "0"

ind_emit = "1"

cod_part = p051

cod_mod = "55"

cod_sit = "00"

ser = alltrim(psnf)

num_doc = p034

chv_nfe = pchv

dt_doc = substr(dtos(p035),7,2) + substr(dtos(p035),5,2) + substr(dtos(p035),1,4)

if empty(p033)

dt_e_s = ""

else

dt_e_s = substr(dtos(p033),7,2) + substr(dtos(p033),5,2) + substr(dtos(p033),1,4)

endif

vl_doc = alltrim(transform(ptnf,"@e 999999999.99"))

if p089 = "0"

ind_pgto = "0"

elseif p089 = "1"

ind_pgto = "1"

elseif p089 = "2"

ind_pgto = "9"

endif

vl_desc = "0,00"

vl_abat_nt = "0,00"

vl_merc = alltrim(transform(ptpr,"@e 999999999.99"))

ind_frt = "1"

vl_frt = iif(!empty(pfre),alltrim(transform(pfre,"@e 999999999.99")),"0,00")

vl_seg = iif(!empty(pseg),alltrim(transform(pseg,"@e 999999999.99")),"0,00")

vl_out_da = iif(!empty(pout),alltrim(transform(pout,"@e 999999999.99")),"0,00")

vl_bc_icms = iif(!empty(pbas),alltrim(transform(pbas,"@e 999999999.99")),"0,00")

vl_icms = iif(!empty(picm),alltrim(transform(picm,"@e 999999999.99")),"0,00")

vl_bc_icmsst = iif(!empty(pbst),alltrim(transform(pbst,"@e 999999999.99")),"0,00")

vl_icms_st = iif(!empty(pict),alltrim(transform(pict,"@e 999999999.99")),"0,00")

vl_ipi = iif(!empty(pipi),alltrim(transform(pipi,"@e 999999999.99")),"0,00")

vl_pis = "0,00"

vl_cofins = "0,00"

vl_pis_st = "0,00"

vl_cofins_st = "0,00"

//mtotalICMS = mtotalICMS + picm

//mtotalICMSst = mtotalICMSst + pict

// verifica se gera o campo E100 e o E200....................

//if pict > 0

if empty(campoE)

aadd(campoE,pest)

else

msn = "S"

for tt = 1 to len(campoE)

if campoE[tt] = pest

msn = "N"

exit

endif

next

if msn = "S"

aadd(campoE,pest)

endif

endif

//endif

mlinha = "|" + "C100" + "|" + ind_oper + "|" + ind_emit;

+ "|" + cod_part + "|" + cod_mod + "|" + cod_sit;

+ "|" + ser + "|" + num_doc + "|" + chv_nfe;

+ "|" + dt_doc + "|" + dt_e_s + "|" + vl_doc;

+ "|" + ind_pgto + "|" + vl_desc + "|" + vl_abat_nt;

+ "|" + vl_merc + "|" + ind_frt + "|" + vl_frt;

+ "|" + vl_seg + "|" + vl_out_da + "|" + vl_bc_icms;

+ "|" + vl_icms + "|" + vl_bc_icmsst + "|" + vl_icms_st;

+ "|" + vl_ipi + "|" + vl_pis + "|" + vl_cofins;

+ "|" + vl_pis_st + "|" + vl_cofins_st + "|" + CRLF

oPrn:Say(lh,000,mlinha)

++BlocoCtotallinhas

++mregC100

// obs.. o array abaixo sera usado quando a operacao

// tiver cst, cfop e icms diferenciados..

rc190:= {} // array para o registro c190

czQuery := "select * from f61000000 where"+;

" qncd = " + alltrim(str(mpncd))+;

" order by qncd asc;"

ozQuery := oServer:Query(czQuery)

num_item = 1

DO WHILE !ozQuery:Eof()

nqcap = ozQuery:Fieldget(ozQuery:Fieldpos('qcap')) // codigo de acesso ao produto

nqcfo = ozQuery:Fieldget(ozQuery:Fieldpos('qcfo')) // cfop

nqqtd = ozQuery:Fieldget(ozQuery:Fieldpos('qqtd')) // quantidade

nquni = ozQuery:Fieldget(ozQuery:Fieldpos('quni')) // unidade

nqvru = ozQuery:Fieldget(ozQuery:Fieldpos('qvru')) // valor unitario

nqvti = ozQuery:Fieldget(ozQuery:Fieldpos('qvti')) // valor total

nqvti = iif(!empty(nqvti),alltrim(transform(nqvti,"@e 999999999.99")),"0,00")

nqcst = ozQuery:Fieldget(ozQuery:Fieldpos('qcst')) // situacao tributaria

if mbaseCalculoICMS

nqbci = ozQuery:Fieldget(ozQuery:Fieldpos('qbci')) // base de calculo do i.c.m

nqbci = iif(!empty(nqbci),alltrim(transform(nqbci,"@e 999999999.99")),"0,00")

else

nqbci = "0,00"

endif

nqaic = ozQuery:Fieldget(ozQuery:Fieldpos('qaic')) // aliquota de icm

nqaic = iif(!empty(nqaic),alltrim(transform(nqaic,"@e 999999999.99")),"0,00")

if mvaloICMSentrada = .t.

nqvic = ozQuery:Fieldget(ozQuery:Fieldpos('qvic')) // valor do icm

nqvic = iif(!empty(nqvic),alltrim(transform(nqvic,"@e 999999999.99")),"0,00")

else

nqvic = "0,00"

endif

nqisn = ozQuery:Fieldget(ozQuery:Fieldpos('qisn')) // isento

nqtrs = ozQuery:Fieldget(ozQuery:Fieldpos('qtrs')) // tributacao na saida

if mbaseCalculoICMSSt = .t.

nqbcs = ozQuery:Fieldget(ozQuery:Fieldpos('qbcs')) // base de substituicao

nqbcs = iif(!empty(nqbcs),alltrim(transform(nqbcs,"@e 999999999.99")),"0,00")

else

nqbcs = "0,00"

endif

if mvaloICMSStentrada = .t.

nqvcs = ozQuery:Fieldget(ozQuery:Fieldpos('qvcs')) // valor da substituicao

nqvcs = iif(!empty(nqbcs),alltrim(transform(nqvcs,"@e 999999999.99")),"0,00")

else

nqvcs = "0,00"

endif

nqaip = ozQuery:Fieldget(ozQuery:Fieldpos('qaip')) // aliquota do ipi

nqaip = iif(!empty(nqaip),alltrim(transform(nqaip,"@e 999999999.99")),"0,00")

if mvalorIPI = .t.

nqipi = ozQuery:Fieldget(ozQuery:Fieldpos('qipi')) // valor do ipi

nqipi = iif(!empty(nqipi),alltrim(transform(nqipi,"@e 999999999.99")),"0,00")

else

nqipi = "0,00"

endif

nqadc = ozQuery:Fieldget(ozQuery:Fieldpos('qadc')) // classificacao fiscal

nqads = ozQuery:Fieldget(ozQuery:Fieldpos('qads')) // aliquota diferenciada

cwQuery := "select * from e40100000 where "+;

"bcap = " + alltrim(str(nqcap)) + " order by bcap asc;"

owQuery := oServer:Query(cwQuery)

nqnpc = owQuery:Fieldget(owQuery:Fieldpos('bcdg')) // numero da pe‡a

nqdpr = owQuery:Fieldget(owQuery:Fieldpos('bprd')) // descricao do produto

nqund = owQuery:Fieldget(owQuery:Fieldpos('bund')) // unidade do produto

nqund = alltrim(nqund)

owQuery:destroy()

//cyQuery := "select * from e40200000 where "+;

// "cemp = " + alltrim(str(memp)) +;

// " and ccap = " + alltrim(str(nqcap)) + " order by ccap asc;"

//oyQuery := oServer:Query(cyQuery)

//nqcdcl = oyQuery:Fieldget(oyQuery:Fieldpos('cdcl'))

//nqcdcl = substr(alltrim(nqcdcl),1,8)

//oyQuery:destroy()

// para as unidades de medidas existentes no sistema............

if upper(nqund) = "PC"

ncdund = "1"

elseif upper(nqund) = "KG"

ncdund = "2"

elseif upper(nqund) = "MT"

ncdund = "3"

elseif upper(nqund) = "UN"

ncdund = "4"

elseif upper(nqund) = "UND"

ncdund = "5"

endif

cwQuery := "select * from r50000000 where "+;

"aesq = " + alltrim(str(memp)) +" order by aesq asc;"

owQuery := oServer:Query(cwQuery)

paest = owQuery:Fieldget(owQuery:Fieldpos('aest'))

owQuery:destroy()

cwQuery := "select * from f50300000 where "+;

"cses = " + "'"+upper(paest)+"'"

cwQuery += " order by cses asc;"

owQuery := oServer:Query(cwQuery)

maliq = owQuery:Fieldget(owQuery:Fieldpos('caic'))

maliq = iif(!empty(maliq),alltrim(transform(maliq,"@e 999999999.99")),"0,00")

owQuery:dest

Link to comment
Share on other sites


#include "FiveWin.ch"

#include "common.ch"

#include "postgres.ch"

#include "Folder.ch"

#include "report.ch"

#include "barcode.ch"

//#include "vget.ch"

//#include "vbtnbmp.ch"

#Define clr_vermelho nRGB( 127, 058, 017 )

#define btn_width 12

#define btn_height 10

function spedfiscal()

define brush obrush color mtela

DEFINE BITMAP otpContador FILENAME "spedfiscal.bmp"

define dialog spedfis title "EFD - Escrituracao Fiscal Digital" from 010,010 to 438,790 pixel brush oBrush

define font mtahoma name "Tahoma" size 5.5,13

define font mtahoma1 name "Tahoma" size 08,22

define font oFont name 'MS Sans Serif' size 6,15

define font ofontL name "Courier" size 11,11

mbldg = 0

mblvs = space(03) // versÆo do layout

mfinl = "Remessa do arquivo original"

afinl = {"Remessa do arquivo original","Remessa do arquivo substituto"}

mperf = "B - Perfil B"

aperf = {"A - Perfil A","B - Perfil B","C - Perfil C"}

mindi = "1 - Outros"

aindi = {"0 - Industrial ou equiparado a industrial","1 - Outros"}

mdtin = ctod("")

mdtfi = ctod("")

minvt = .f.

// para os registros de entrada que foram lancados no sistema..........

mbaseCalculoICMS = .t.

mvaloICMSentrada = .t.

mbaseCalculoICMSSt = .t.

mvaloICMSStentrada = .t.

mvalorIPI = .t.

finvt = ""

ainvt = {}

cQuery := "select * from n60300000 where"+;

" wemp = " + alltrim(str(memp))+;

" and wstd = " + "'"+"I"+"'"+;

" order by wndc asc;"

oQuery := oServer:Query(cQuery)

aadd(ainvt,space(06))

DO WHILE ! oQuery:Eof()

nwstd = oQuery:Fieldget(oQuery:Fieldpos('wstd'))

if !empty(nwstd)

nwndc = oQuery:Fieldget(oQuery:Fieldpos('wndc'))

if empty(ainvt)

aadd(ainvt,nwndc)

else

msn = "N"

for tt = 1 to len(ainvt)

if alltrim(nwndc) = alltrim(ainvt[tt])

msn = "S"

exit

endif

next

if msn = "N"

aadd(ainvt,nwndc)

endif

endif

endif

oQuery:Skip()

END

oQuery:destroy()

@ 35.5,002 say "Versao do leiaute Ato Cotepe" of spedfis font mtahoma color mcolorAA,mcolorAB pixel

@ 035 ,100 get oblvs var mblvs picture "@!" font mtahoma size 016,9 of spedfis color mcolorCA,mcolorCB pixel

@ 50,002 say "Finalidade do arquivo Magnetico" of spedfis font mtahoma color mcolorAA,mcolorAB pixel

@ 60,002 combobox ofinl var mfinl items afinl font mtahoma size 250,90 of spedfis color mcolorCA,mcolorCB pixel

@ 75,002 say "Perfil de apresentacao do arquivo fiscal" of spedfis font mtahoma color mcolorAA,mcolorAB pixel

@ 85,002 combobox operf var mperf items aperf font mtahoma size 250,90 of spedfis color mcolorCA,mcolorCB pixel

@ 100,002 say "Indicador do tipo de atividade" of spedfis font mtahoma color mcolorAA,mcolorAB pixel

@ 110,002 combobox oindi var mindi items aindi font mtahoma size 250,90 of spedfis color mcolorCA,mcolorCB pixel

@ 125, 002 say "Período a ser gerado" of spedfis font mtahoma color mcolorAA,mcolorAB pixel

@ 135, 002 say "Data inicial:" of spedfis font mtahoma color mcolorAA,mcolorAB pixel

@ 135, 040 get odtin var mdtin font mtahoma size 32,9 of spedfis color mcolorCA,mcolorCB pixel

@ 145, 002 say "Data final:" of spedfis font mtahoma color mcolorAA,mcolorAB pixel

@ 145, 040 get odtfi var mdtfi font mtahoma size 32,9 of spedfis color mcolorCA,mcolorCB pixel

@ 165,002 checkbox oinvt var minvt prompt "&Gerar o inventario";

font mtahoma colors mcolorAA,mcolorAB size 64, 11 of spedfis pixel

@ 178,002 combobox oinvt var finvt items ainvt font mtahoma size 250,90 of spedfis color mcolorCA,mcolorCB pixel when iif(minvt = .t.,.t.,.f.)

@ 050,265 say "Registro a serem gerados para a Entrada" of spedfis font mtahoma color mcolorAA,mcolorAB pixel

@ 060,265 checkbox obaseCalculoICMS var mbaseCalculoICMS prompt "Com base de calculo do ICMS";

font mtahoma colors mcolorAA,mcolorAB size 100, 11 of spedfis pixel

@ 070,265 checkbox ovaloICMSentrada var mvaloICMSentrada prompt "Com valor de ICMS ";

font mtahoma colors mcolorAA,mcolorAB size 100, 11 of spedfis pixel

@ 080,265 checkbox obaseCalculoICMSSt var mbaseCalculoICMSSt prompt "Com base de calculo do ICMS ST";

font mtahoma colors mcolorAA,mcolorAB size 100, 11 of spedfis pixel

@ 090,265 checkbox ovaloICMSStentrada var mvaloICMSStentrada prompt "Com valor de ICMS ST";

font mtahoma colors mcolorAA,mcolorAB size 100, 11 of spedfis pixel

@ 100,265 checkbox ovalorIPI var mvalorIPI prompt "Com valor de IPI";

font mtahoma colors mcolorAA,mcolorAB size 100, 11 of spedfis pixel

@ 200,004 button orombut0 prompt "Gerar " size 040,12 font oFont OF spedfis pixel action ( gera_efd_fiscal() )

@ 200,047 button orombut1 prompt "Contador" size 040,12 font oFont OF spedfis pixel action ( contador() )

@ 200,090 button orombut2 prompt "Inventario" size 040,12 font oFont OF spedfis pixel action ( n6030008(1) )

@ 200,133 button orombut3 prompt "" size 040,12 font oFont OF spedfis pixel

@ 200,176 button orombut4 prompt "" size 040,12 font oFont OF spedfis pixel

@ 200,219 button orombut5 prompt "" size 040,12 font oFont OF spedfis pixel

@ 200,262 button orombut6 prompt "" size 040,12 font oFont OF spedfis pixel

@ 200,305 button orombut7 prompt "" size 040,12 font oFont OF spedfis pixel

@ 200,348 button orombut8 prompt "Sair " size 040,12 font oFont OF spedfis pixel action ( spedfis:end() )

activate dialog spedfis center on Init ( busca_gera_efd_fiscal() ) on Paint ( WndBoxIn(spedfis:Hdc, 064, 001, 066, 790) ,;

WndBoxIn(spedfis:Hdc, 391, 001, 393, 790) ,;

sayBitmapContador() )

return nil

function sayBitmapContador()

spedfis:SayBitmap( (((spedfis:nTop+spedfis:nbottom)/2)-190) -(otpContador:nHeight()/2),((spedfis:nLeft+spedfis:nRight)/2)-(otpContador:nWidth()/2),otpContador,otpContador:nWidth(),otpContador:nHeight())

return nil

function busca_gera_efd_fiscal()

cQuery := "select * from r20200000"+;

" order by bldg asc;"

oQuery := oServer:Query(cQuery)

mbldg = 0

mblvs = space(03) // versÆo do layout

DO WHILE ! oQuery:Eof()

mbldg = oQuery:Fieldget(oQuery:Fieldpos('bldg'))

if !empty(mbldg)

mblvs = oQuery:Fieldget(oQuery:Fieldpos('blvs'))

oblvs:ctext := mblvs

endif

oQuery:Skip()

END

oQuery:destroy()

return nil

// Geracao do arquivo magnetico do EFD - Escritura‡Æo Fiscal Digital............

function gera_efd_fiscal()

if empty(mblvs)

msgstop("Versao do leiaute nao informado.","Atencao")

return nil

endif

if empty(mdtin)

msgstop("Data inicial nao foi informada.","Atencao")

return nil

endif

if empty(mdtfi)

msgstop("Data final nao foi informada.","Atencao")

return nil

endif

if mbldg = 0

cQuery := "insert into r20200000(blvs)"

cQuery += "values("+"'"+mblvs+"'"+")"

oQuery := oServer:Query(cQuery)

if oQuery:neterr()

msgStop("Não foi possível realizar a inclusão.","ATENÇÃO")

//oQuery:error()

endif

oQuery:destroy()

oServer:Commit()

else

cQuery := "Update r20200000 set "+;

"blvs = " + "'"+mblvs+"'"+;

" where " + " bldg = " + alltrim(str(mbldg))

oQuery := oServer:Query(cQuery)

if oQuery:neterr()

msgStop("Não foi possível realizar a alteração.","ATENÇÃO")

//oQuery:error()

endif

oQuery:destroy()

oServer:Commit()

endif

// validacoes a serem consideradas para emissao do sped fiscal........

if empty(zaden)

msgstop("Razao social do contribuinte vazio.","Atencao")

return nil

endif

if empty(zaest)

msgstop("Estado do contribuinte vazio.","Atencao")

return nil

endif

if empty(zaies)

msgstop("Inscricao Estadual do contribuinte vazio.","Atencao")

return nil

endif

if empty(zaibg)

msgstop("Codigo do municipio do IBGE do contribuinte vazio.","Atencao")

return nil

endif

if empty(zatf1)

msgstop("Numero do telefone do contribuinte vazio.","Atencao")

return nil

endif

if empty(zatfx)

msgstop("Numero do fax do contribuinte vazio.","Atencao")

return nil

endif

// verifica os dados do contador .....................................

cQuery := "select * from r20100000"+;

" order by ctnm asc;"

oQuery := oServer:Query(cQuery)

mctdg = 0

DO WHILE ! oQuery:Eof()

mctdg = oQuery:Fieldget(oQuery:Fieldpos('ctdg'))

if !empty(mctdg)

mctnm = oQuery:Fieldget(oQuery:Fieldpos('ctnm'))

mctcf = oQuery:Fieldget(oQuery:Fieldpos('ctcf'))

mctrc = oQuery:Fieldget(oQuery:Fieldpos('ctrc'))

mctpj = oQuery:Fieldget(oQuery:Fieldpos('ctpj'))

mctcp = oQuery:Fieldget(oQuery:Fieldpos('ctcp'))

mctlg = oQuery:Fieldget(oQuery:Fieldpos('ctlg'))

mctnr = oQuery:Fieldget(oQuery:Fieldpos('ctnr'))

mctdc = oQuery:Fieldget(oQuery:Fieldpos('ctdc'))

mctbr = oQuery:Fieldget(oQuery:Fieldpos('ctbr'))

mcttf = oQuery:Fieldget(oQuery:Fieldpos('cttf'))

mctfx = oQuery:Fieldget(oQuery:Fieldpos('ctfx'))

mctml = oQuery:Fieldget(oQuery:Fieldpos('ctml'))

maibg = oQuery:Fieldget(oQuery:Fieldpos('ctbg'))

endif

oQuery:Skip()

END

oQuery:destroy()

if empty(mctdg)

msgstop("Preencha os dados do contabilista.","Atencao")

return nil

endif

// comeca a geracao do arquivo do sped fiscal ........................

cDirXML = "spedfiscal-" + substr(dtos(mdtin),5,2) + "-" + substr(dtos(mdtin),1,4) + ".txt"

Bloco0totallinhas = 0

BlocoCtotallinhas = 0

BlocoDtotallinhas = 0

BlocoEtotallinhas = 0

BlocoGtotallinhas = 0

BlocoHtotallinhas = 0

Bloco1totallinhas = 0

Bloco9totallinhas = 0

mreg0000 = 0

mreg0001 = 0

mreg0005 = 0

mreg0100 = 0

mreg0150 = 0

mreg0190 = 0

mreg0200 = 0

mreg0400 = 0

mreg0990 = 0

mregC001 = 0

mregC100 = 0

mregC170 = 0

mregC190 = 0

mregC990 = 0

mregD001 = 0

mregD990 = 0

mregE001 = 0

mregE100 = 0

mregE110 = 0

//mregE200 = 0

//mregE210 = 0

mregE990 = 0

mregG001 = 0

mregG990 = 0

mregH001 = 0

mregH005 = 0

mregH010 = 0

mregH990 = 0

mreg1001 = 0

mreg1990 = 0

mreg9001 = 0

mreg9900 = 0

mreg9990 = 0

mreg9999 = 0

campoE = {}

mtotalICMS = 0

mtotalICMSst = 0

lh := 0

oPrn := TDosPrn():New(cDirXML)

oPrn:StartPage()

oPrn:lZeraBuffer:=.T.

// B L O C O 0

// registro 0000......................................................

mlinha = "|" + "0000" + "|" + mblvs + "|" + iif(mfinl = "Remessa do arquivo original","0","1") +;

"|" + substr(dtos(mdtin),7,2) + substr(dtos(mdtin),5,2) + substr(dtos(mdtin),1,4) +;

"|" + substr(dtos(mdtfi),7,2) + substr(dtos(mdtfi),5,2) + substr(dtos(mdtfi),1,4) +;

"|" + alltrim(zaden) + "|" + zandn + "|" + "|" + zaest + "|" + alltrim(substr(zaies,1,14)) +;

"|" + alltrim(substr(zaibg,1,7)) + "|" + "|" + "|"+;

iif(mperf = "A - Perfil A","A",iif(mperf = "B - Perfil B","B","C")) + "|"+;

iif(mindi = "1 - Outros","1","0") + "|" + CRLF

oPrn:Say(lh,000,mlinha)

++Bloco0totallinhas

++mreg0000

// registro 0001......................................................

mlinha = "|" + "0001" + "|" + "0" + "|" + CRLF

oPrn:Say(lh,000,mlinha)

++Bloco0totallinhas

++mreg0001

// registro 0005......................................................

// obs.. para o nome fantasia depois ver um modo de pegar alguns dados

// do nome da empresa..

mlinha = "|" + "0005" + "|" + substr(zaden,1,17) + "|" + zacep + "|" + alltrim(zaend) +;

"|" + alltrim(str(zanro)) + "|" + alltrim(zacpl) + "|" + alltrim(zabai)+;

"|" + alltrim(zatf1) + "|" + alltrim(zatfx) + "|" + "|" + CRLF

oPrn:Say(lh,000,mlinha)

++Bloco0totallinhas

++mreg0005

// registro 0100

mlinha = "|" + "0100" + "|" + alltrim(mctnm) + "|" + alltrim(mctcf) + "|" +;

alltrim(mctrc) + "|" + alltrim(mctpj) + "|" + mctcp + "|" +;

alltrim(mctlg) + "|" + alltrim(mctnr) + "|" + alltrim(mctdc) +;

"|" + alltrim(mctbr) + "|" + mcttf + "|" + mctfx + "|" + ;

alltrim(mctml) + "|" + maibg + "|" + CRLF

oPrn:Say(lh,000,mlinha)

++Bloco0totallinhas

++mreg0100

// registro 0150

// para clientes......................................................

acliautorizada := {}

aprodutosusado := {}

aunidadeusadas := {}

acfoputilizado := {}

// se for utilizar o inventario.......................................

if minvt = .t.

finvt = alltrim(finvt)

if !empty(finvt)

ntotv = 0

cQuery := "select * from n60300000 where"+;

" wemp = " + alltrim(str(memp))+;

" and wndc = " + "'"+alltrim(finvt)+"'"+;

" and wstd = " + "'"+"I"+"'"+;

" order by wndc asc;"

oQuery := oServer:Query(cQuery)

DO WHILE ! oQuery:Eof()

nwstd = oQuery:Fieldget(oQuery:Fieldpos('wstd'))

if !empty(nwstd)

if nwstd != "I"

oQuery:Skip()

loop

endif

iwbcf = oQuery:Fieldget(oQuery:Fieldpos('wbcf')) // codigo normal

iwqit = oQuery:Fieldget(oQuery:Fieldpos('wqit')) // quantidade a ser fabricada

iwvlr = oQuery:Fieldget(oQuery:Fieldpos('wvlr')) // valor..

ntotv = ntotv + ( iwqit * iwvlr )

wQuery := "select * from e40100000 where"

wQuery += " bcdg = " + "'"+alltrim(iwbcf)+"'"

wQuery += " order by bcdg asc;"

owQuery := oServer:Query(wQuery)

nqnpc = owQuery:Fieldget(owQuery:Fieldpos('bcdg'))

nqund = owQuery:Fieldget(owQuery:Fieldpos('bund'))

nqund = alltrim(nqund)

nqdpr = owQuery:Fieldget(owQuery:Fieldpos('bprd'))

nqcap = owQuery:Fieldget(owQuery:Fieldpos('bcap'))

owQuery:destroy()

cyQuery := "select * from e40200000 where "+;

"cemp = " + alltrim(str(memp)) +;

" and ccap = " + alltrim(str(nqcap)) + " order by ccap asc;"

oyQuery := oServer:Query(cyQuery)

nqcdcl = oyQuery:Fieldget(oyQuery:Fieldpos('cdcl'))

nqcdcl = substr(alltrim(nqcdcl),1,8)

oyQuery:destroy()

// para as unidades de medidas existentes no sistema............

if upper(nqund) = "PC"

ncdund = "1"

elseif upper(nqund) = "KG"

ncdund = "2"

elseif upper(nqund) = "MT"

ncdund = "3"

elseif upper(nqund) = "UN"

ncdund = "4"

elseif upper(nqund) = "UND"

ncdund = "5"

endif

if empty(aunidadeusadas)

aadd(aunidadeusadas,{ncdund,nqund})

else

msn = "S"

for tt = 1 to len(aunidadeusadas)

if aunidadeusadas[tt,1] = ncdund

msn = "N"

exit

endif

next

if msn = "S"

aadd(aunidadeusadas,{ncdund,nqund})

endif

endif

// para produtos que estao usados no inventario...........

if empty(aprodutosusado)

aadd(aprodutosusado,{nqnpc,alltrim(nqdpr),"","",ncdund,"00",nqcdcl,"","","",""})

else

msn = "S"

for tt = 1 to len(aprodutosusado)

if aprodutosusado[tt,1] = nqnpc

msn = "N"

exit

endif

next

if msn = "S"

aadd(aprodutosusado,{nqnpc,alltrim(nqdpr),"","",ncdund,"00",nqcdcl,"","","",""})

endif

endif

endif

oQuery:Skip()

END

oQuery:destroy()

endif

endif

nsaidas := nentradas := 0

ndtin = substr(dtos(mdtin),1,4)+"-"+substr(dtos(mdtin),5,2)+"-"+substr(dtos(mdtin),7,2)

ndtfi = substr(dtos(mdtfi),1,4)+"-"+substr(dtos(mdtfi),5,2)+"-"+substr(dtos(mdtfi),7,2)

if mdtin = mdtfi

cQuery := "select * from f50900000 where"+;

" p035 = " + "'"+ndtin+"'"

else

cQuery := "select * from f50900000 where"+;

" p035 >= " + "'"+ndtin+"'" + " and"+;

" p035 <= " + "'"+ndtfi+"'"

endif

cQuery += " order by p035 desc;"

oQuery := oServer:Query(cQuery)

DO WHILE ! oQuery:Eof()

pasq = oQuery:Fieldget(oQuery:Fieldpos('pasq'))

p051 = oQuery:Fieldget(oQuery:Fieldpos('p051'))

p094 = oQuery:Fieldget(oQuery:Fieldpos('p094')) // Entrada ou Saida..

nsta = oQuery:Fieldget(oQuery:Fieldpos('pstu')) // Situacao da nota

mp016 = oQuery:Fieldget(oQuery:Fieldpos('p016')) // numero do pedido ou romaneio..

mp016 = alltrim(mp016)

nrnop = oQuery:Fieldget(oQuery:Fieldpos('p062'))

np062 = oQuery:Fieldget(oQuery:Fieldpos('p062'))

np062 = alltrim(substr(np062,1,4))

nrdno = ""

cqQuery := "select * from f51100000 "+;

"where rnop = " + alltrim(nrnop)+;

" order by rnop asc;"

oqQuery := oServer:Query(cqQuery)

nrdno = oqQuery:Fieldget(oqQuery:Fieldpos('rdno'))

oqQuery:destroy()

if empty(pasq)

oQuery:Skip()

loop

endif

if nsta != 5

if nsta = 6

if empty(acliautorizada)

aadd(acliautorizada,p051)

else

msn = "S"

for tt = 1 to len(acliautorizada)

if acliautorizada[tt] = p051

msn = "N"

exit

endif

next

if msn = "S"

aadd(acliautorizada,p051)

endif

endif

endif

oQuery:Skip()

loop

endif

if empty(acliautorizada)

aadd(acliautorizada,p051)

else

msn = "S"

for tt = 1 to len(acliautorizada)

if acliautorizada[tt] = p051

msn = "N"

exit

endif

next

if msn = "S"

aadd(acliautorizada,p051)

endif

endif

if p094 = "S"

++nsaidas

elseif p094 = "E"

++nentradas

endif

// acrescenta os cfops.. usados nas saidas e entradas..............

//if empt(acfoputilizado)

// aadd(acfoputilizado,{np062,nrdno})

//else

// msn = "S"

// for tt = 1 to len(acfoputilizado)

// if acfoputilizado[tt,1] = np062

// msn = "N"

// exit

// endif

// next

// if msn = "S"

// aadd(acfoputilizado,{np062,nrdno})

// endif

//endif

// Detalha os produtos e seus impostos................................

czQuery := "select * from f51000000 where"+;

" qnpd = " + "'"+mp016+"'"+;

" order by qnpd asc;"

ozQuery := oServer:Query(czQuery)

DO WHILE !ozQuery:Eof()

nqcap = ozQuery:Fieldget(ozQuery:Fieldpos('qcap')) // codigo de acesso ao produto

cwQuery := "select * from e40100000 where "+;

"bcap = " + alltrim(str(nqcap)) + " order by bcap asc;"

owQuery := oServer:Query(cwQuery)

nqnpc = owQuery:Fieldget(owQuery:Fieldpos('bcdg')) // numero da pe‡a

nqdpr = owQuery:Fieldget(owQuery:Fieldpos('bprd')) // descricao do produto

nqund = owQuery:Fieldget(owQuery:Fieldpos('bund')) // unidade do produto

nqund = alltrim(nqund)

owQuery:destroy()

cyQuery := "select * from e40200000 where "+;

"cemp = " + alltrim(str(memp)) +;

" and ccap = " + alltrim(str(nqcap)) + " order by ccap asc;"

oyQuery := oServer:Query(cyQuery)

nqcdcl = oyQuery:Fieldget(oyQuery:Fieldpos('cdcl'))

nqcdcl = substr(alltrim(nqcdcl),1,8)

oyQuery:destroy()

// para as unidades de medidas existentes no sistema............

if upper(nqund) = "PC"

ncdund = "1"

elseif upper(nqund) = "KG"

ncdund = "2"

elseif upper(nqund) = "MT"

ncdund = "3"

elseif upper(nqund) = "UN"

ncdund = "4"

elseif upper(nqund) = "UND"

ncdund = "5"

endif

if empty(aunidadeusadas)

aadd(aunidadeusadas,{ncdund,nqund})

else

msn = "S"

for tt = 1 to len(aunidadeusadas)

if aunidadeusadas[tt,1] = ncdund

msn = "N"

exit

endif

next

if msn = "S"

aadd(aunidadeusadas,{ncdund,nqund})

endif

endif

// para os produtos que foram usados nas transacoes.............

//if empty(aprodutosusado)

// aadd(aprodutosusado,{nqnpc,alltrim(nqdpr),"","",ncdund,"00",nqcdcl,"","","",""})

//else

// msn = "S"

// for tt = 1 to len(aprodutosusado)

// if aprodutosusado[tt,1] = nqnpc

// msn = "N"

// exit

// endif

// next

// if msn = "S"

// aadd(aprodutosusado,{nqnpc,alltrim(nqdpr),"","",ncdund,"00",nqcdcl,"","","",""})

// endif

//endif

ozQuery:Skip()

END

ozQuery:destroy()

oQuery:Skip()

END

oQuery:destroy()

for tt = 1 to len(acliautorizada)

cQuery := "select * from r20000000 where "+;

"acdc = " + alltrim(str(val(acliautorizada[tt])))

cQuery += " order by acdc asc;"

oQuery := oServer:Query(cQuery)

ncod_part = oQuery:Fieldget(oQuery:Fieldpos('acdc'))

ncod_part = alltrim(str(ncod_part))

nnome = oQuery:Fieldget(oQuery:Fieldpos('anrs'))

nnome = alltrim(nnome)

ncod_pais = "01058"

napfj = oQuery:Fieldget(oQuery:Fieldpos('apfj'))

if napfj = "F"

ncnpj = ""

ncnpf = oQuery:Fieldget(oQuery:Fieldpos('andn'))

else

ncnpj = oQuery:Fieldget(oQuery:Fieldpos('andn'))

ncnpf = ""

endif

nie = oQuery:Fieldget(oQuery:Fieldpos('andl'))

nie = alltrim(substr(nie,1,14))

ncod_mun = oQuery:Fieldget(oQuery:Fieldpos('aibg'))

ncod_mun = substr(ncod_mun,1,7)

nsuframa = ""

nend = oQuery:Fieldget(oQuery:Fieldpos('aend'))

nend = alltrim(nend)

nnum = oQuery:Fieldget(oQuery:Fieldpos('anro'))

nnum = alltrim(nnum)

ncompl = oQuery:Fieldget(oQuery:Fieldpos('acmp'))

ncompl = alltrim(ncompl)

nbairro = oQuery:Fieldget(oQuery:Fieldpos('abai'))

nbairro = alltrim(nbairro)

mlinha = "|" + "0150" + "|" + ncod_part + "|" + nnome + "|" + ncod_pais +;

"|" + ncnpj + "|" + ncnpf + "|" + nie + "|" + ncod_mun +;

"|" + nsuframa + "|" + nend + "|" + nnum + "|" + ncompl+;

"|" + nbairro + "|" + CRLF

oPrn:Say(lh,000,mlinha)

++Bloco0totallinhas

++mreg0150

next

// para fornecedores..................................................

aforautorizada := {}

ndtin = substr(dtos(mdtin),1,4)+"-"+substr(dtos(mdtin),5,2)+"-"+substr(dtos(mdtin),7,2)

ndtfi = substr(dtos(mdtfi),1,4)+"-"+substr(dtos(mdtfi),5,2)+"-"+substr(dtos(mdtfi),7,2)

if mdtin = mdtfi

cQuery := "select * from f60900000 where"+;

" pent = " + "'"+ndtin+"'"

else

cQuery := "select * from f60900000 where"+;

" pent >= " + "'"+ndtin+"'" + " and"+;

" pent <= " + "'"+ndtfi+"'"

endif

cQuery += " order by pent desc;"

oQuery := oServer:Query(cQuery)

DO WHILE ! oQuery:Eof()

pasq = oQuery:Fieldget(oQuery:Fieldpos('pasq'))

p051 = oQuery:Fieldget(oQuery:Fieldpos('pclf'))

p051 = alltrim(strzero(p051,5))

mpncd = oQuery:Fieldget(oQuery:Fieldpos('pncd'))

p094 = "E"

nrnop = oQuery:Fieldget(oQuery:Fieldpos('pcfo'))

nrnop = alltrim(str(nrnop))

np062 = oQuery:Fieldget(oQuery:Fieldpos('pcfo'))

np062 = alltrim(str(np062))

nrdno = ""

cqQuery := "select * from f51100000 "+;

"where substr(rnop,1,4) = " + alltrim(nrnop)+;

" order by rnop asc;"

oqQuery := oServer:Query(cqQuery)

nrdno = oqQuery:Fieldget(oqQuery:Fieldpos('rdno'))

oqQuery:destroy()

if empty(pasq)

oQuery:Skip()

loop

endif

if empty(aforautorizada)

aadd(aforautorizada,p051)

else

msn = "S"

for tt = 1 to len(aforautorizada)

if aforautorizada[tt] = p051

msn = "N"

exit

endif

next

if msn = "S"

aadd(aforautorizada,p051)

endif

endif

++nentradas

// acrescenta os cfops.. usados nas saidas e entradas..............

if empt(acfoputilizado)

aadd(acfoputilizado,{np062,nrdno})

else

msn = "S"

for tt = 1 to len(acfoputilizado)

if acfoputilizado[tt,1] = np062

msn = "N"

exit

endif

next

if msn = "S"

aadd(acfoputilizado,{np062,nrdno})

endif

endif

// Detalha os produtos e seus impostos................................

czQuery := "select * from f61000000 where"+;

" qncd = " + alltrim(str(mpncd))+;

" order by qncd asc;"

ozQuery := oServer:Query(czQuery)

DO WHILE !ozQuery:Eof()

nqcap = ozQuery:Fieldget(ozQuery:Fieldpos('qcap')) // codigo de acesso ao produto

cwQuery := "select * from e40100000 where "+;

"bcap = " + alltrim(str(nqcap)) + " order by bcap asc;"

owQuery := oServer:Query(cwQuery)

nqnpc = owQuery:Fieldget(owQuery:Fieldpos('bcdg')) // numero da pe‡a

nqdpr = owQuery:Fieldget(owQuery:Fieldpos('bprd')) // descricao do produto

nqund = owQuery:Fieldget(owQuery:Fieldpos('bund')) // unidade do produto

nqund = alltrim(nqund)

owQuery:destroy()

cyQuery := "select * from e40200000 where "+;

"cemp = " + alltrim(str(memp)) +;

" and ccap = " + alltrim(str(nqcap)) + " order by ccap asc;"

oyQuery := oServer:Query(cyQuery)

nqcdcl = oyQuery:Fieldget(oyQuery:Fieldpos('cdcl'))

nqcdcl = substr(alltrim(nqcdcl),1,8)

oyQuery:destroy()

// para as unidades de medidas existentes no sistema............

if upper(nqund) = "PC"

ncdund = "1"

elseif upper(nqund) = "KG"

ncdund = "2"

elseif upper(nqund) = "MT"

ncdund = "3"

elseif upper(nqund) = "UN"

ncdund = "4"

elseif upper(nqund) = "UND"

ncdund = "5"

endif

if empty(aunidadeusadas)

aadd(aunidadeusadas,{ncdund,nqund})

else

msn = "S"

for tt = 1 to len(aunidadeusadas)

if aunidadeusadas[tt,1] = ncdund

msn = "N"

exit

endif

next

if msn = "S"

aadd(aunidadeusadas,{ncdund,nqund})

endif

endif

// para os produtos que foram usados nas transacoes.............

if empty(aprodutosusado)

aadd(aprodutosusado,{nqnpc,alltrim(nqdpr),"","",ncdund,"00",nqcdcl,"","","",""})

else

msn = "S"

for tt = 1 to len(aprodutosusado)

if aprodutosusado[tt,1] = nqnpc

msn = "N"

exit

endif

next

if msn = "S"

aadd(aprodutosusado,{nqnpc,alltrim(nqdpr),"","",ncdund,"00",nqcdcl,"","","",""})

endif

endif

ozQuery:Skip()

END

ozQuery:destroy()

oQuery:Skip()

END

oQuery:destroy()

for tt = 1 to len(aforautorizada)

cQuery := "select * from r10000000 where "+;

"acdg = " + alltrim(str(val(aforautorizada[tt])))

cQuery += " order by acdg asc;"

oQuery := oServer:Query(cQuery)

ncod_part = oQuery:Fieldget(oQuery:Fieldpos('acdg'))

ncod_part = "FOR-" + alltrim(str(ncod_part))

nnome = oQuery:Fieldget(oQuery:Fieldpos('anrs'))

nnome = alltrim(nnome)

ncod_pais = "01058"

napfj = oQuery:Fieldget(oQuery:Fieldpos('andn'))

napfj = alltrim(napfj)

if len(napfj) <= 11

ncnpj = ""

ncnpf = oQuery:Fieldget(oQuery:Fieldpos('andn'))

else

ncnpj = oQuery:Fieldget(oQuery:Fieldpos('andn'))

ncnpf = ""

endif

nie = oQuery:Fieldget(oQuery:Fieldpos('andl'))

nie = alltrim(substr(nie,1,14))

ncod_mun = oQuery:Fieldget(oQuery:Fieldpos('aibg'))

ncod_mun = substr(ncod_mun,1,7)

nsuframa = ""

nend = oQuery:Fieldget(oQuery:Fieldpos('aend'))

nend = alltrim(nend)

nnum = oQuery:Fieldget(oQuery:Fieldpos('anro'))

nnum = alltrim(nnum)

ncompl = ""

nbairro = oQuery:Fieldget(oQuery:Fieldpos('abai'))

nbairro = alltrim(nbairro)

mlinha = "|" + "0150" + "|" + ncod_part + "|" + nnome + "|" + ncod_pais +;

"|" + ncnpj + "|" + ncnpf + "|" + nie + "|" + ncod_mun +;

"|" + nsuframa + "|" + nend + "|" + nnum + "|" + ncompl+;

"|" + nbairro + "|" + CRLF

oPrn:Say(lh,000,mlinha)

++Bloco0totallinhas

++mreg0150

next

// registro 0190

for tt = 1 to len(aunidadeusadas)

mlinha = "|" + "0190" + "|" + aunidadeusadas[tt,1] + "|" + aunidadeusadas[tt,2] + "|" + CRLF

oPrn:Say(lh,000,mlinha)

++Bloco0totallinhas

++mreg0190

next

// registro 0200

for tt = 1 to len(aprodutosusado)

mlinha = "|" + "0200" + "|" + aprodutosusado[tt,1] + "|" + aprodutosusado[tt,2];

+ "|" + aprodutosusado[tt,3] + "|" + aprodutosusado[tt,4];

+ "|" + aprodutosusado[tt,5] + "|" + aprodutosusado[tt,6];

+ "|" + aprodutosusado[tt,7] + "|" + aprodutosusado[tt,8];

+ "|" + aprodutosusado[tt,9] + "|" + aprodutosusado[tt,10];

+ "|" + aprodutosusado[tt,11] + "|" + CRLF

oPrn:Say(lh,000,mlinha)

++Bloco0totallinhas

++mreg0200

next

// registro 0400

for tt = 1 to len(acfoputilizado)

mlinha = "|" + "0400" + "|" + acfoputilizado[tt,1] + "|" + alltrim(acfoputilizado[tt,2]) + "|" + CRLF

oPrn:Say(lh,000,mlinha)

++Bloco0totallinhas

++mreg0400

next

// registro 0990

++Bloco0totallinhas

++mreg0990

mlinha = "|" + "0990" + "|" + alltrim(str(Bloco0totallinhas)) + "|" + CRLF

oPrn:Say(lh,000,mlinha)

// B L O C O C

if nsaidas = 0 .and. nentradas = 0

// registro c001

mlinha = "|" + "C001" + "|" + "1" + CRLF

oPrn:Say(lh,000,mlinha)

++BlocoCtotallinhas

++mregC001

// registro c990

++BlocoCtotallinhas

++mregC990

mlinha = "|" + "C990" + "|" + alltrim(str(BlocoCtotallinhas)) + CRLF

oPrn:Say(lh,000,mlinha)

else

mlinha = "|" + "C001" + "|" + "0" + "|"+ CRLF

oPrn:Say(lh,000,mlinha)

++BlocoCtotallinhas

++mregC001

// registro c001

// Notas fiscais eletronica de saida e entrada emissao propria

ndtin = substr(dtos(mdtin),1,4)+"-"+substr(dtos(mdtin),5,2)+"-"+substr(dtos(mdtin),7,2)

ndtfi = substr(dtos(mdtfi),1,4)+"-"+substr(dtos(mdtfi),5,2)+"-"+substr(dtos(mdtfi),7,2)

for pt = 1 to 2

if pt = 1

ntipodenota = "S"

elseif pt = 2

ntipodenota = "E"

endif

if mdtin = mdtfi

cQuery := "select * from f50900000 where"+;

" p035 = " + "'"+ndtin+"'"

else

cQuery := "select * from f50900000 where"+;

" p035 >= " + "'"+ndtin+"'" + " and"+;

" p035 <= " + "'"+ndtfi+"'"

endif

cQuery += " and p094 = " + "'"+ntipodenota+"'"

cQuery += " order by p034 asc;"

oQuery := oServer:Query(cQuery)

pasq = oQuery:Fieldget(oQuery:Fieldpos('pasq'))

if !empty(pasq)

DO WHILE ! oQuery:Eof()

psql = oQuery:Fieldget(oQuery:Fieldpos('pasq'))

pstu = oQuery:Fieldget(oQuery:Fieldpos('pstu')) // Situacao da nota

p016 = oQuery:Fieldget(oQuery:Fieldpos('p016')) // numero do pedido

p051 = oQuery:Fieldget(oQuery:Fieldpos('p051')) // codigo do cliente

psnf = oQuery:Fieldget(oQuery:Fieldpos('psnf')) // serie da nota fiscal

p034 = oQuery:Fieldget(oQuery:Fieldpos('p034')) // numero da nota fiscal

pchv = oQuery:Fieldget(oQuery:Fieldpos('pchv')) // chave de acesso da nota fiscal eletronica

p035 = oQuery:Fieldget(oQuery:Fieldpos('p035')) // data de emissao

p033 = oQuery:Fieldget(oQuery:Fieldpos('p033')) // data de saida

p026 = oQuery:Fieldget(oQuery:Fieldpos('p026')) // valor do documento

p089 = oQuery:Fieldget(oQuery:Fieldpos('p089')) // tipo de pagamento

p024 = oQuery:Fieldget(oQuery:Fieldpos('p024')) // valor total dos produtos

p069 = oQuery:Fieldget(oQuery:Fieldpos('p069')) // frete

p021 = oQuery:Fieldget(oQuery:Fieldpos('p021')) // valor do frete

p022 = oQuery:Fieldget(oQuery:Fieldpos('p022')) // valor do seguro

p063 = oQuery:Fieldget(oQuery:Fieldpos('p063')) // outras despesas e acessorios

p053 = oQuery:Fieldget(oQuery:Fieldpos('p053')) // base de calculo

p054 = oQuery:Fieldget(oQuery:Fieldpos('p054')) // valor do icms.

p055 = oQuery:Fieldget(oQuery:Fieldpos('p055'))

p056 = oQuery:Fieldget(oQuery:Fieldpos('p056'))

p025 = oQuery:Fieldget(oQuery:Fieldpos('p025'))

if pstu < 5

oQuery:Skip()

loop

endif

ind_oper = iif(ntipodenota = "S","1","0")

ind_emit = "0"

if pstu = 6

cod_part = ""

else

cod_part = alltrim(str(val(p051)))

endif

cod_mod = "55"

if pstu = 6

cod_sit = "02"

else

cod_sit = "00"

endif

ser = alltrim(psnf)

num_doc = alltrim(str(val(p034)))

chv_nfe = alltrim(pchv)

if pstu = 6

dt_doc = ""

dt_e_s = ""

vl_doc = ""

ind_pgto = ""

vl_desc = ""

vl_abat_nt = ""

vl_merc = ""

ind_frt = ""

vl_frt = ""

vl_seg = ""

vl_out_da = ""

vl_bc_icms = ""

vl_icms = ""

vl_bc_icmsst = ""

vl_icms_st = ""

vl_ipi = ""

vl_pis = ""

vl_cofins = ""

vl_pis_st = ""

vl_cofins_st = ""

else

dt_doc = substr(dtos(p035),7,2) + substr(dtos(p035),5,2) + substr(dtos(p035),1,4)

if empty(p033)

dt_e_s = ""

else

dt_e_s = substr(dtos(p033),7,2) + substr(dtos(p033),5,2) + substr(dtos(p033),1,4)

endif

vl_doc = alltrim(transform(p026,"@e 999999999.99"))

if p089 = "0"

ind_pgto = "0"

elseif p089 = "1"

ind_pgto = "1"

elseif p089 = "2"

ind_pgto = "9"

endif

vl_desc = "0,00"

vl_abat_nt = "0,00"

vl_merc = alltrim(transform(p024,"@e 999999999.99"))

ind_frt = iif(p069 = "1","1","2")

vl_frt = iif(!empty(p021),alltrim(transform(p021,"@e 999999999.99")),"0,00")

vl_seg = iif(!empty(p022),alltrim(transform(p022,"@e 999999999.99")),"0,00")

vl_out_da = iif(!empty(p063),alltrim(transform(p063,"@e 999999999.99")),"0,00")

vl_bc_icms = iif(!empty(p053),alltrim(transform(p053,"@e 999999999.99")),"0,00")

vl_icms = iif(!empty(p054),alltrim(transform(p054,"@e 999999999.99")),"0,00")

vl_bc_icmsst = iif(!empty(p055),alltrim(transform(p055,"@e 999999999.99")),"0,00")

vl_icms_st = iif(!empty(p056),alltrim(transform(p056,"@e 999999999.99")),"0,00")

vl_ipi = iif(!empty(p025),alltrim(transform(p025,"@e 999999999.99")),"0,00")

vl_pis = "0,00"

vl_cofins = "0,00"

vl_pis_st = "0,00"

vl_cofins_st = "0,00"

endif

mlinha = "|" + "C100" + "|" + ind_oper + "|" + ind_emit;

+ "|" + cod_part + "|" + cod_mod + "|" + cod_sit;

+ "|" + ser + "|" + num_doc + "|" + chv_nfe;

+ "|" + dt_doc + "|" + dt_e_s + "|" + vl_doc;

+ "|" + ind_pgto + "|" + vl_desc + "|" + vl_abat_nt;

+ "|" + vl_merc + "|" + ind_frt + "|" + vl_frt;

+ "|" + vl_seg + "|" + vl_out_da + "|" + vl_bc_icms;

+ "|" + vl_icms + "|" + vl_bc_icmsst + "|" + vl_icms_st;

+ "|" + vl_ipi + "|" + vl_pis + "|" + vl_cofins;

+ "|" + vl_pis_st + "|" + vl_cofins_st + "|" + CRLF

oPrn:Say(lh,000,mlinha)

++BlocoCtotallinhas

++mregC100

if pstu = 6

else

// obs.. o array abaixo sera usado quando a operacao

// tiver cst, cfop e icms diferenciados..

rc190:= {} // array para o registro c190

czQuery := "select * from f51000000 where"+;

" qnpd = " + "'"+p016+"'"+;

" order by qnpd asc;"

ozQuery := oServer:Query(czQuery)

DO WHILE !ozQuery:Eof()

nqcap = ozQuery:Fieldget(ozQuery:Fieldpos('qcap')) // codigo de acesso ao produto

nqcfo = ozQuery:Fieldget(ozQuery:Fieldpos('qcfo')) // cfop

nqqtd = ozQuery:Fieldget(ozQuery:Fieldpos('qqtd')) // quantidade

nquni = ozQuery:Fieldget(ozQuery:Fieldpos('quni')) // unidade

nqvru = ozQuery:Fieldget(ozQuery:Fieldpos('qvru')) // valor unitario

nqvti = ozQuery:Fieldget(ozQuery:Fieldpos('qvti')) // valor total

nqvti = iif(!empty(nqvti),alltrim(transform(nqvti,"@e 999999999.99")),"0,00")

nqcst = ozQuery:Fieldget(ozQuery:Fieldpos('qcst')) // situacao tributaria

nqbci = ozQuery:Fieldget(ozQuery:Fieldpos('qbci')) // base de calculo do i.c.m

nqbci = iif(!empty(nqbci),alltrim(transform(nqbci,"@e 999999999.99")),"0,00")

nqaic = ozQuery:Fieldget(ozQuery:Fieldpos('qaic')) // aliquota de icm

nqvic = ozQuery:Fieldget(ozQuery:Fieldpos('qvic')) // valor do icm

nqvic = iif(!empty(nqvic),alltrim(transform(nqvic,"@e 999999999.99")),"0,00")

nqisn = ozQuery:Fieldget(ozQuery:Fieldpos('qisn')) // isento

nqtrs = ozQuery:Fieldget(ozQuery:Fieldpos('qtrs')) // tributacao na saida

nqadc = ozQuery:Fieldget(ozQuery:Fieldpos('qadc')) // classificacao fiscal

nqads = ozQuery:Fieldget(ozQuery:Fieldpos('qads')) // aliquota diferenciada

//cwQuery := "select * from e40100000 where "+;

// "bcap = " + alltrim(str(nqcap)) + " order by bcap asc;"

//owQuery := oServer:Query(cwQuery)

//nqnpc = owQuery:Fieldget(owQuery:Fieldpos('bcdg')) // numero da pe‡a

//nqdpr = owQuery:Fieldget(owQuery:Fieldpos('bprd')) // descricao do produto

//nqund = owQuery:Fieldget(owQuery:Fieldpos('bund')) // unidade do produto

//nqund = alltrim(nqund)

//owQuery:destroy()

//

//cyQuery := "select * from e40200000 where "+;

// "cemp = " + alltrim(str(memp)) +;

// " and ccap = " + alltrim(str(nqcap)) + " order by ccap asc;"

//oyQuery := oServer:Query(cyQuery)

//nqcdcl = oyQuery:Fieldget(oyQuery:Fieldpos('cdcl'))

//nqcdcl = substr(alltrim(nqcdcl),1,8)

//oyQuery:destroy()

ozQuery:Skip()

END

ozQuery:destroy()

mlinha = "|" + "C190" + "|" + substr(nqcst,1,3) + "|" +;

substr(nqcfo,1,4) + "|" + iif(!empty(nqaic),alltrim(transform(nqaic,"@e 999.99")),"0,00");

+ "|" + vl_doc + "|" + vl_bc_icms;

+ "|" + vl_icms + "|" + vl_bc_icmsst + "|" + vl_icms_st + "|";

+ "0,00" + "|" + "0,00" + "|" + "" + "|" + CRLF

oPrn:Say(lh,000,mlinha)

++BlocoCtotallinhas

++mregC190

endif

oQuery:Skip()

END

endif

oQuery:destroy()

next

// Notas fisciais de entrada ... Lancamento manual.................

if mdtin = mdtfi

cQuery := "select * from f60900000 where"+;

" pent = " + "'"+ndtin+"'"

else

cQuery := "select * from f60900000 where"+;

" pent >= " + "'"+ndtin+"'" + " and"+;

" pent <= " + "'"+ndtfi+"'"

endif

cQuery += " order by pemi asc;"

oQuery := oServer:Query(cQuery)

pasq = oQuery:Fieldget(oQuery:Fieldpos('pasq'))

if !empty(pasq)

DO WHILE ! oQuery:Eof()

psql = oQuery:Fieldget(oQuery:Fieldpos('pasq'))

mpncd = oQuery:Fieldget(oQuery:Fieldpos('pncd'))

p051 = oQuery:Fieldget(oQuery:Fieldpos('pclf')) // codigo do fornecedor

p051 = "FOR-" + alltrim(str(p051))

nNatureza = ""

p062 = oQuery:Fieldget(oQuery:Fieldpos('pcfo'))

p062 = alltrim(str(p062))

for tt = 1 to len(acfoputilizado)

if acfoputilizado[tt,1] = p062

nNatureza = acfoputilizado[tt,2]

exit

endif

next

psnf = oQuery:Fieldget(oQuery:Fieldpos('pser')) // serie da nota fiscal

p034 = oQuery:Fieldget(oQuery:Fieldpos('pnur')) // numero da nota fiscal

p034 = alltrim(str(p034))

pchv = "" // chave de acesso da nota fiscal eletronica

p035 = oQuery:Fieldget(oQuery:Fieldpos('pemi')) // data de emissao

p033 = oQuery:Fieldget(oQuery:Fieldpos('pemi')) // data de saida

p089 = oQuery:Fieldget(oQuery:Fieldpos('pprz')) // tipo de pagamento

p089 = iif(p089 = .t.,"1","0" )

mntmv = oQuery:Fieldget(oQuery:Fieldpos('ptmv'))

// verifica se movimenta o estoque...............................

cwQuery := "select * from e40700000 where "+;

"lcmv = " + alltrim(str(mntmv))

cwQuery += " order by lcmv asc;"

owQuery := oServer:Query(cwQuery)

nlmve = owQuery:Fieldget(owQuery:Fieldpos('lmve'))

owQuery:destroy()

nlmve = iif(nlmve = .t.,"y","n")

pest = oQuery:Fieldget(oQuery:Fieldpos('pest')) // estado da federacao

ptnf = oQuery:Fieldget(oQuery:Fieldpos('ptnf')) // total da nota

if mbaseCalculoICMS = .t.

pbas = oQuery:Fieldget(oQuery:Fieldpos('pbas')) // total da base

else

pbas = 0

endif

if mvaloICMSentrada = .t.

picm = oQuery:Fieldget(oQuery:Fieldpos('picm')) // total do icms

else

picm = 0

endif

pist = oQuery:Fieldget(oQuery:Fieldpos('pist')) // total do isento

pout = oQuery:Fieldget(oQuery:Fieldpos('pout')) // total outros

if mvalorIPI = .t.

pipi = oQuery:Fieldget(oQuery:Fieldpos('pipi')) // total ipi

else

pipi = 0

endif

ptpr = oQuery:Fieldget(oQuery:Fieldpos('ptpr')) // total dos produtos

pfre = oQuery:Fieldget(oQuery:Fieldpos('pfre')) // total frete

pseg = oQuery:Fieldget(oQuery:Fieldpos('pseg')) // total seguro

palq = oQuery:Fieldget(oQuery:Fieldpos('palq')) // aliquota icms

pdes = oQuery:Fieldget(oQuery:Fieldpos('pdes')) // despesa

if mbaseCalculoICMSSt

pbst = oQuery:Fieldget(oQuery:Fieldpos('pbst')) // base substituicao

else

pbst = 0

endif

if mvaloICMSStentrada = .t.

pict = oQuery:Fieldget(oQuery:Fieldpos('pict')) // icms substituicao

else

pict = 0

endif

ind_oper = "0"

ind_emit = "1"

cod_part = p051

cod_mod = "55"

cod_sit = "00"

ser = alltrim(psnf)

num_doc = p034

chv_nfe = pchv

dt_doc = substr(dtos(p035),7,2) + substr(dtos(p035),5,2) + substr(dtos(p035),1,4)

if empty(p033)

dt_e_s = ""

else

dt_e_s = substr(dtos(p033),7,2) + substr(dtos(p033),5,2) + substr(dtos(p033),1,4)

endif

vl_doc = alltrim(transform(ptnf,"@e 999999999.99"))

if p089 = "0"

ind_pgto = "0"

elseif p089 = "1"

ind_pgto = "1"

elseif p089 = "2"

ind_pgto = "9"

endif

vl_desc = "0,00"

vl_abat_nt = "0,00"

vl_merc = alltrim(transform(ptpr,"@e 999999999.99"))

ind_frt = "1"

vl_frt = iif(!empty(pfre),alltrim(transform(pfre,"@e 999999999.99")),"0,00")

vl_seg = iif(!empty(pseg),alltrim(transform(pseg,"@e 999999999.99")),"0,00")

vl_out_da = iif(!empty(pout),alltrim(transform(pout,"@e 999999999.99")),"0,00")

vl_bc_icms = iif(!empty(pbas),alltrim(transform(pbas,"@e 999999999.99")),"0,00")

vl_icms = iif(!empty(picm),alltrim(transform(picm,"@e 999999999.99")),"0,00")

vl_bc_icmsst = iif(!empty(pbst),alltrim(transform(pbst,"@e 999999999.99")),"0,00")

vl_icms_st = iif(!empty(pict),alltrim(transform(pict,"@e 999999999.99")),"0,00")

vl_ipi = iif(!empty(pipi),alltrim(transform(pipi,"@e 999999999.99")),"0,00")

vl_pis = "0,00"

vl_cofins = "0,00"

vl_pis_st = "0,00"

vl_cofins_st = "0,00"

//mtotalICMS = mtotalICMS + picm

//mtotalICMSst = mtotalICMSst + pict

// verifica se gera o campo E100 e o E200....................

//if pict > 0

if empty(campoE)

aadd(campoE,pest)

else

msn = "S"

for tt = 1 to len(campoE)

if campoE[tt] = pest

msn = "N"

exit

endif

next

if msn = "S"

aadd(campoE,pest)

endif

endif

//endif

mlinha = "|" + "C100" + "|" + ind_oper + "|" + ind_emit;

+ "|" + cod_part + "|" + cod_mod + "|" + cod_sit;

+ "|" + ser + "|" + num_doc + "|" + chv_nfe;

+ "|" + dt_doc + "|" + dt_e_s + "|" + vl_doc;

+ "|" + ind_pgto + "|" + vl_desc + "|" + vl_abat_nt;

+ "|" + vl_merc + "|" + ind_frt + "|" + vl_frt;

+ "|" + vl_seg + "|" + vl_out_da + "|" + vl_bc_icms;

+ "|" + vl_icms + "|" + vl_bc_icmsst + "|" + vl_icms_st;

+ "|" + vl_ipi + "|" + vl_pis + "|" + vl_cofins;

+ "|" + vl_pis_st + "|" + vl_cofins_st + "|" + CRLF

oPrn:Say(lh,000,mlinha)

++BlocoCtotallinhas

++mregC100

// obs.. o array abaixo sera usado quando a operacao

// tiver cst, cfop e icms diferenciados..

rc190:= {} // array para o registro c190

czQuery := "select * from f61000000 where"+;

" qncd = " + alltrim(str(mpncd))+;

" order by qncd asc;"

ozQuery := oServer:Query(czQuery)

num_item = 1

DO WHILE !ozQuery:Eof()

nqcap = ozQuery:Fieldget(ozQuery:Fieldpos('qcap')) // codigo de acesso ao produto

nqcfo = ozQuery:Fieldget(ozQuery:Fieldpos('qcfo')) // cfop

nqqtd = ozQuery:Fieldget(ozQuery:Fieldpos('qqtd')) // quantidade

nquni = ozQuery:Fieldget(ozQuery:Fieldpos('quni')) // unidade

nqvru = ozQuery:Fieldget(ozQuery:Fieldpos('qvru')) // valor unitario

nqvti = ozQuery:Fieldget(ozQuery:Fieldpos('qvti')) // valor total

nqvti = iif(!empty(nqvti),alltrim(transform(nqvti,"@e 999999999.99")),"0,00")

nqcst = ozQuery:Fieldget(ozQuery:Fieldpos('qcst')) // situacao tributaria

if mbaseCalculoICMS

nqbci = ozQuery:Fieldget(ozQuery:Fieldpos('qbci')) // base de calculo do i.c.m

nqbci = iif(!empty(nqbci),alltrim(transform(nqbci,"@e 999999999.99")),"0,00")

else

nqbci = "0,00"

endif

nqaic = ozQuery:Fieldget(ozQuery:Fieldpos('qaic')) // aliquota de icm

nqaic = iif(!empty(nqaic),alltrim(transform(nqaic,"@e 999999999.99")),"0,00")

if mvaloICMSentrada = .t.

nqvic = ozQuery:Fieldget(ozQuery:Fieldpos('qvic')) // valor do icm

nqvic = iif(!empty(nqvic),alltrim(transform(nqvic,"@e 999999999.99")),"0,00")

else

nqvic = "0,00"

endif

nqisn = ozQuery:Fieldget(ozQuery:Fieldpos('qisn')) // isento

nqtrs = ozQuery:Fieldget(ozQuery:Fieldpos('qtrs')) // tributacao na saida

if mbaseCalculoICMSSt = .t.

nqbcs = ozQuery:Fieldget(ozQuery:Fieldpos('qbcs')) // base de substituicao

nqbcs = iif(!empty(nqbcs),alltrim(transform(nqbcs,"@e 999999999.99")),"0,00")

else

nqbcs = "0,00"

endif

if mvaloICMSStentrada = .t.

nqvcs = ozQuery:Fieldget(ozQuery:Fieldpos('qvcs')) // valor da substituicao

nqvcs = iif(!empty(nqbcs),alltrim(transform(nqvcs,"@e 999999999.99")),"0,00")

else

nqvcs = "0,00"

endif

nqaip = ozQuery:Fieldget(ozQuery:Fieldpos('qaip')) // aliquota do ipi

nqaip = iif(!empty(nqaip),alltrim(transform(nqaip,"@e 999999999.99")),"0,00")

if mvalorIPI = .t.

nqipi = ozQuery:Fieldget(ozQuery:Fieldpos('qipi')) // valor do ipi

nqipi = iif(!empty(nqipi),alltrim(transform(nqipi,"@e 999999999.99")),"0,00")

else

nqipi = "0,00"

endif

nqadc = ozQuery:Fieldget(ozQuery:Fieldpos('qadc')) // classificacao fiscal

nqads = ozQuery:Fieldget(ozQuery:Fieldpos('qads')) // aliquota diferenciada

cwQuery := "select * from e40100000 where "+;

"bcap = " + alltrim(str(nqcap)) + " order by bcap asc;"

owQuery := oServer:Query(cwQuery)

nqnpc = owQuery:Fieldget(owQuery:Fieldpos('bcdg')) // numero da pe‡a

nqdpr = owQuery:Fieldget(owQuery:Fieldpos('bprd')) // descricao do produto

nqund = owQuery:Fieldget(owQuery:Fieldpos('bund')) // unidade do produto

nqund = alltrim(nqund)

owQuery:destroy()

//cyQuery := "select * from e40200000 where "+;

// "cemp = " + alltrim(str(memp)) +;

// " and ccap = " + alltrim(str(nqcap)) + " order by ccap asc;"

//oyQuery := oServer:Query(cyQuery)

//nqcdcl = oyQuery:Fieldget(oyQuery:Fieldpos('cdcl'))

//nqcdcl = substr(alltrim(nqcdcl),1,8)

//oyQuery:destroy()

// para as unidades de medidas existentes no sistema............

if upper(nqund) = "PC"

ncdund = "1"

elseif upper(nqund) = "KG"

ncdund = "2"

elseif upper(nqund) = "MT"

ncdund = "3"

elseif upper(nqund) = "UN"

ncdund = "4"

elseif upper(nqund) = "UND"

ncdund = "5"

endif

cwQuery := "select * from r50000000 where "+;

"aesq = " + alltrim(str(memp)) +" order by aesq asc;"

owQuery := oServer:Query(cwQuery)

paest = owQuery:Fieldget(owQuery:Fieldpos('aest'))

owQuery:destroy()

cwQuery := "select * from f50300000 where "+;

"cses = " + "'"+upper(paest)+"'"

cwQuery += " order by cses asc;"

owQuery := oServer:Query(cwQuery)

maliq = owQuery:Fieldget(owQuery:Fieldpos('caic'))

maliq = iif(!empty(maliq),alltrim(transform(maliq,"@e 999999999.99")),"0,00")

owQuery:dest

Link to comment
Share on other sites

Olá Wellington!!!!

Como vc desenvolverá o registro E110??

Infelizmente o manual do SPED coloca esse registro com obrigatório e faz a consistencia de valores desse registro.

Um grande abraço, Parabens pelo código.

Itaocara - RJ

Clipper 5.3b - Fw 2.6 - DBFCDX

xHb 1.1.0 - FwxH 8.02 - DBFCDX

Link to comment
Share on other sites

Bom dia,

Sim esta em funcionamento de janeiro/2011, lembrando que este é um exemplo pois a forma de geração dos dados no Speed, dependerá do tipo de empresa que esta gerando.

O registro E110 - Apuração do ICMS - Operações próprias é obrigatório, mas os dados em seu conteúdo, depende exclusivamente do tipo de empresa e operações que ela exerce.

No exemplo acima:

A empresa é REGIME NORMAL, que compra produtos com Substituição Tributária - CST 010, ou seja paga na fonte, e revende os produtos em CST 060, não tendo assim destaque de ICMS, ou seja a empresa é substituído. Então o registro E110, como é obrigatório neste caso ficará todo zerado. (lembrando ainda que esta empresa no caso ainda tem certos incentivos do governo) para os produtos que comercializa.

MAS ISSO DEPENDERÃ DO TIPO DE EMPRESA QUE ESTA GERANDO O SPEED, DEPENDENDO ASSIM DOS MOLDES FISCAIS DA EMPRESA..

obs.. E olha que são muitas as variações de empresa para empresa,, esse é o BRASIL,, infelizmente...

wellington

fwh/xharbour0.99.71 Bd. Postgresql

Systemup@bol.com.br

Link to comment
Share on other sites

Lembrando ainda, que no caso acima. conforme a consistência do registro E110, no ato da geração do SPEED, não permitir que se gere os valores de ICMS e ICMS/ST na entradas, somente as suas respectivas bases de cálculo..

OBS. Este layout do manual do Speed, ainda como está não esta totalmente 100%, acredito que muita coisa nele ainda mudará.

wellington

fwh/xharbour0.99.71 Bd. Postgresql

Systemup@bol.com.br

Link to comment
Share on other sites

  • 1 month later...

Olá Wellington,

Preciso fazer um sped a um cliente de material de construção em clipper p/começar a funcionar em Julho.

Ví este exemplo que vc postou, parabéns, com certeza está ajudando e ajudará muitos.

Estou iniciando a leitura do guia prático mas, como é muita informação e o prazo p/ mim está pouco, precisarei estudar códigos de exemplo como este seu p/ assimilar mais rápido, ou seja, ir mais direto ao assunto, lógico que precisarei tbém estudar o manual.

Como vc postou em Março, com certeza teve muitas mudanças neste código, se não for difícil, por gentileza, me manda um código atualizado pois este servirá como base p/ eu estudar e começar a desenvolver.

Desde já agradeço.

Link to comment
Share on other sites

Aqui vai um link que me ajudou bastante e em relacao a apuracao de icm vai um dica de como estou fazendo. Essa parte ficou cargo do contador ja que existem varias situacoes a serem verificadas nessa etapa e ainda para quem emite NFE não é necessario gerar os itens da mesma somente cabecalho e resumo por cfop.

http://www.pctoledo.com.br/forum/viewtopic.php?f=4&t=11718&p=67011&hilit=sped#p67011

CHARLES

Link to comment
Share on other sites

Caso ainda esteja em tempo, fica a dica de você estruturar como uma classe ao invés de uma função, pois assim você terá mais facilidade de dar manutenção...

SamirSSabreu@gmail.com

samirabreu@hotmail.com

Skype: SamirAbreu

xHarbour 1.10/1.21 + FwXh 8.02/10.6

"Acreditar é mais fácil do que pensar: Daí existem muito mais crentes do que pensadores.†Bruce Calvert

Link to comment
Share on other sites

Bem diferente... com a classe seria possível dar manutenção muito mais facilmente e seria muito mais simples a implementação/alteração de um dos requisitos....

SamirSSabreu@gmail.com

samirabreu@hotmail.com

Skype: SamirAbreu

xHarbour 1.10/1.21 + FwXh 8.02/10.6

"Acreditar é mais fácil do que pensar: Daí existem muito mais crentes do que pensadores.†Bruce Calvert

Link to comment
Share on other sites

Samir desculpe-me,

Como programei a vida inteira em clipper ainda não tem noção de como ficaria com classe, ia começar um curso de Java semana passada, mas devido o trabalho deste sped, vou fazer na próxima turma.

Poderia, por gentileza, me dar algumas dicas e se possível exemplos ?

Como estou iniciando, esta tua dica com certeza será válida pois, um sistema, principalmente esta EFD, bem estruturado a manutenção ficará fácil.

Editado por - josadac on 18/05/2011 11:41:41

Link to comment
Share on other sites


/***************************************************************************

* Programa ....: DataHora.PRG

* Autor .......: Samir

* Data ........: 2/3/2010 às 10:30:13

* Revisado em .: 2/3/2010 às 10:30:13

*

* Classe para tratar uma data e hora em conjunto

*

***************************************************************************/

#include 'FiveWin.ch'

CLASS TDataHora

//-- Propriedades -----------------------------------------------------//

//-- Atributos a serem acessados

DATA Data AS Date INIT Date() READONLY

DATA Hora AS Character INIT Time() READONLY

DATA Secs AS Numeric Init 0 READONLY

//-- Uso interno da classe

DATA nSecsMinuto AS Numeric Init 0 HIDDEN

DATA nSecsHora AS Numeric Init 0 HIDDEN

DATA nSecsDia AS Numeric Init 0 HIDDEN

DATA nSecsMes AS Numeric Init 0 HIDDEN

DATA nSecsAno AS Numeric Init 0 HIDDEN

//-- Métodos ----------------------------------------------------------//

//-- Construção

METHOD New(cDataIni,cHoraIni) CONSTRUCTOR

METHOD End()

METHOD Absoluto(dDataReferencia)

//-- Uso Interno

METHOD Verifica() HIDDEN

METHOD AtualizaVariaveis() HIDDEN

//-- Modificar atributos da classe

METHOD AtuData(dData) INLINE ( ::Data := dData )

METHOD AtuHora(cHora) INLINE ( ::Hora := cHora, ::Secs := Secs(cHora) )

//-- Adicionar Tempo

METHOD AddHora(nHora) //PUBLIC

METHOD AddMinuto(nMinuto) //PUBLIC

METHOD AddSegundo(nSegundo) //PUBLIC

//-- Adicionar Data

METHOD AddDia(nDia) //PUBLIC

METHOD AddMes(nMes) //PUBLIC

METHOD AddAno(nAno) //PUBLIC

//-- Remover Tempo

METHOD RemHora(nHora) //PUBLIC

METHOD RemMinuto(nMinuto) //PUBLIC

METHOD RemSegundo(nSegundo) //PUBLIC

//-- Remover Data

METHOD RemDia(nDia) //PUBLIC

METHOD RemMes(nMes) //PUBLIC

METHOD RemAno(nAno) //PUBLIC

//-- Compatibilidade ( Aceitar comandos no plural ) -------------------//

//-- Adicionar Tempo

METHOD AddHoras(nHora) INLINE ::AddHora(nHora)

METHOD AddMinutos(nMinuto) INLINE ::AddMinuto(nMinuto)

METHOD AddSegundos(nSegundo) INLINE ::AddSegundo(nSegundo)

//-- Adicionar Data

METHOD AddDias(nDia) INLINE ::AddDias(nDia)

METHOD AddMeses(nMes) INLINE ::AddMes(nMes)

METHOD AddAnos(nAno) INLINE ::AddAno(nAno)

//-- Remover Tempo

METHOD RemHoras(nHora) INLINE ::RemHora(nHora)

METHOD RemMinutos(nMinuto) INLINE ::RemMinuto(nMinuto)

METHOD RemSegundos(nSegundo) INLINE ::RemSegundo(nSegundo)

//-- Remover Data

METHOD RemDias(nDia) INLINE ::RemDia(nDia)

METHOD RemMeses(nMes) INLINE ::RemMes(nMes)

METHOD RemAnos(nAno) INLINE ::RemAno(nAno)

ENDCLASS

/*------------------------------------------------------------------------*/

****************************************************************************

METHOD New(xDataIni,cHoraIni) CLASS TDataHora

****************************************************************************

*

* Instanciar objeto

* Parametros: Nenhum

* Retorno: Self (Object)

*

* Autor .......: Samir

* Data ........: 2/3/2010 às 10:30:20

*

****************************************************************************

Default xDataIni := Date(), cHoraIni := Time()

If ValType(xDataIni) = "C"

::Data := cTod(xDataIni)

elseif ValType(xDataIni) = "D"

::Data := xDataIni

else

::Data := Date()

end

::Hora := cHoraIni

::Secs := Secs(cHoraIni)

::nSecsMinuto := 60 //-- FIXO

::nSecsHora := ::nSecsMinuto * 60 //-- FIXO

::nSecsDia := ::nSecsHora * 24 //-- FIXO

//-- Atualizar segundos do mês/ano

::AtualizaVariaveis()

return Self

/*------------------------------------------------------------------------*/

****************************************************************************

METHOD End() CLASS TDataHora

****************************************************************************

*

* Liberar da memória o objeto

* Parametros: Nenhum

* Retorno: Nil

*

* Autor .......: Samir

* Data ........: 2/3/2010 às 10:30:20

*

****************************************************************************

Self := Nil

return nil

/*------------------------------------------------------------------------*/

****************************************************************************

METHOD AtualizaVariaveis() CLASS TDataHora

****************************************************************************

*

* Atualizar as variaveis de contagem de segundos

* Parametros:

* Retorno: Nil

*

* Autor: Samir

* 2/3/2010 - 13:52:18

*

****************************************************************************

::nSecsMes := ::nSecsDia * LastDay(::Data)

::nSecsAno := ::nSecsDia * If ( IsBissexto(::Data), 366, 365 )

return nil

/*------------------------------------------------------------------------*/

****************************************************************************

METHOD Verifica() CLASS TDataHora

****************************************************************************

*

* Verificar se houve mudança na data de acordo com o total de segundos

* Parametros: Nenhum

* Retorno: Nil

*

* Autor .......: Samir

* Data ........: 2/3/2010 às 10:30:20

*

****************************************************************************

Local lRetrocede := .F.

//-- Verificar se é negativo ou positivo

If ::Secs < 0

lRetrocede := .T.

::Secs := Abs(::Secs)

end

//-- Incrementos

If !lRetrocede

//-- Verificar se incrementa o dia

While ::Secs > ::nSecsDia

::Secs -= ::nSecsDia

::AddDia()

end

//-- Atualizar a hora com o restante

::Hora := TString(::Secs)

//-- Decrementos

else

//-- Verificar se decrementa o dia

While ::Secs > ::nSecsDia

::Secs -= ::nSecsDia

::RemDia()

end

//-- Se a horá é negativa, faz referência ao dia anterior

::RemDia()

//-- Atualizar a hora com o restante

::Hora := TString(::nSecsDia - ::Secs)

end

::AtualizaVariaveis()

return nil

/*------------------------------------------------------------------------*/

****************************************************************************

METHOD AddHora(nHora) CLASS TDataHora

****************************************************************************

*

* Adicionar hora

* Parametros: nHora

* Retorno: NIL

*

* Autor: Anderson

* 2/3/2010 - 10:33:57

*

****************************************************************************

Default nHora := 1

::Secs += nHora * ::nSecsHora

::Verifica()

return nil

/*------------------------------------------------------------------------*/

****************************************************************************

METHOD AddMinuto(nMinuto) CLASS TDataHora

****************************************************************************

*

* Adicionar minuto

* Parametros: nMinuto

* Retorno: NIL

*

* Autor: Anderson

* 2/3/2010 - 10:34:30

*

****************************************************************************

Default nMinuto := 1

::Secs += nMinuto * ::nSecsMinuto

::Verifica()

return nil

/*------------------------------------------------------------------------*/

****************************************************************************

METHOD AddSegundo(nSegundo) CLASS TDataHora

****************************************************************************

*

* Adicionar segundo

* Parametros: nSegundo

* Retorno: NIL

*

* Autor: Anderson

* 2/3/2010 - 10:34:58

*

****************************************************************************

local Result := nil

Default nSegundo := 1

::Secs += nSegundo

::Verifica()

return nil

/*------------------------------------------------------------------------*/

****************************************************************************

METHOD AddDia(nDia) CLASS TDataHora

****************************************************************************

*

* Adicionar dia

* Parametros: nDia

* Retorno: NIL

*

* Autor: Anderson

* 2/3/2010 - 10:37:46

*

****************************************************************************

local Result := nil, nMax := 0, nFimMes := 0, nAux := 0, cAux := ""

Default nDia := 1

::Data := ::Data + nDia

return nil

/*------------------------------------------------------------------------*/

****************************************************************************

METHOD AddMes(nMes) CLASS TDataHora

****************************************************************************

*

* Adicionar mes

* Parametros: nMes

* Retorno: NIL

*

* Autor: Anderson

* 2/3/2010 - 10:34:30

*

****************************************************************************

local Result := nil

Default nMes := 1

::Data := IncMonth(::Data,nMes)

return nil

/*------------------------------------------------------------------------*/

****************************************************************************

METHOD AddAno(nAno) CLASS TDataHora

****************************************************************************

*

* Adicionar Ano

* Parametros: nAno

* Retorno: NIL

*

* Autor: Anderson

* 2/3/2010 - 10:34:58

*

****************************************************************************

local Result := nil, nDiaAux := 0, nMesAux := 0, nAnoAux := 0, cDataAux := ""

Default nAno := 1

nDiaAux := Day( ::Data())

nMesAux := Month(::Data())

nAnoAux := Year( ::Data())

nAnoAux += nAno

cDataAux += StrZero(nDiaAux,2) + "/"

cDataAux += StrZero(nMesAux,2) + "/"

cDataAux += StrZero(nAnoAux,4)

::Data := CtoD(cDataAux)

return nil

/*------------------------------------------------------------------------*/

****************************************************************************

METHOD RemHora(nHora) CLASS TDataHora

****************************************************************************

*

* Adicionar hora

* Parametros: nHora

* Retorno: NIL

*

* Autor: Anderson

* 2/3/2010 - 10:33:57

*

****************************************************************************

local Result := nil

Default nHora := 1

::Secs -= nHora * ::nSecsHora

::Verifica()

return nil

/*------------------------------------------------------------------------*/

****************************************************************************

METHOD RemMinuto(nMinuto) CLASS TDataHora

****************************************************************************

*

* Adicionar minuto

* Parametros: nMinuto

* Retorno: NIL

*

* Autor: Anderson

* 2/3/2010 - 10:34:30

*

****************************************************************************

local Result := nil

Default nMinuto := 1

::Secs -= nMinuto * ::nSecsMinuto

::Verifica()

return nil

/*------------------------------------------------------------------------*/

****************************************************************************

METHOD RemSegundo(nSegundo) CLASS TDataHora

****************************************************************************

*

* Adicionar segundo

* Parametros: nSegundo

* Retorno: NIL

*

* Autor: Anderson

* 2/3/2010 - 10:34:58

*

****************************************************************************

local Result := nil

Default nSegundo := 1

::Secs -= nSegundo

::Verifica()

return nil

/*------------------------------------------------------------------------*/

****************************************************************************

METHOD RemDia(nDia) CLASS TDataHora

****************************************************************************

*

* Adicionar dia

* Parametros: nDia

* Retorno: NIL

*

* Autor: Anderson

* 2/3/2010 - 10:37:46

*

****************************************************************************

local nMax := 0

Default nDia := 1

::Data := ::Data - nDia

return nil

/*------------------------------------------------------------------------*/

****************************************************************************

METHOD RemMes(nMes) CLASS TDataHora

****************************************************************************

*

* Adicionar mes

* Parametros: nMes

* Retorno: NIL

*

* Autor: Anderson

* 2/3/2010 - 10:34:30

*

****************************************************************************

Default nMes := 1

::Data := DecMonth(::Data,nMes)

return nil

/*------------------------------------------------------------------------*/

****************************************************************************

METHOD RemAno(nAno) CLASS TDataHora

****************************************************************************

*

* Adicionar Ano

* Parametros: nAno

* Retorno: NIL

*

* Autor: Anderson

* 2/3/2010 - 10:34:58

*

****************************************************************************

local nDiaAux := 0, nMesAux := 0, nAnoAux := 0, cDataAux := ""

Default nAno := 1

nDiaAux := Day(::Data())

nMesAux := Month(::Data())

nAnoAux := Year(::Data())

nAnoAux -= nAno

cDataAux += StrZero(nDiaAux,2) + "/"

cDataAux += StrZero(nMesAux,2) + "/"

cDataAux += StrZero(nAnoAux,4)

::Data := CtoD(cDataAux)

return nil

/*------------------------------------------------------------------------*/

****************************************************************************

METHOD Absoluto(dDataReferencia) CLASS TDataHora

****************************************************************************

*

* Obter um valor absoluto em segundos da data mais hora

* Parametros: dDataReferencia

* Retorno: nValorAbsoluto

*

* Autor: Samir

* 17/11/2010 - 10:51:08

*

****************************************************************************

local nValorAbsoluto := 0, nDias := 0

Default dDataReferencia := cTod("01/01/1920")

nDias := Abs( ::Data - dDataReferencia)

nValorAbsoluto := nDias * ::nSecsDia

nValorAbsoluto += ::Secs

return nValorAbsoluto

/*------------------------------------------------------------------------*/

****************************************************************************

static function IsBissexto(xData)

****************************************************************************

*

* Verificar se um ano é bissexto ou não

* Parametros: xData

* Retorno: lResult

*

* Autor: Samir

* 2/3/2010 - 11:15:02

*

****************************************************************************

local lResult := .T., nAno := 0

If ValType(xData) = "D"

nAno := Year(xData)

elseif ValType(xData) = "N"

nAno := xData

elseif ValType(xData) = "C"

If IsDigit(xData)

If Len(xData) = 2 .or. Len(xData) = 4

nAno := Val(xData)

else

lResult := .F.

end

else

lResult := .F.

end

else

lResult := .F.

end

If lResult

If nAno % 4 = 0 .and. nAno % 100 != 0

lResult := .T.

Elseif nAno % 100 = 0 .and. nAno % 400 = 0

lResult := .T.

Else

lResult := .F.

End

else

Msg("Parâmetro de data inválida")

end

Return lResult

/*------------------------------------------------------------------------*/

id=code>id=code>

SamirSSabreu@gmail.com

samirabreu@hotmail.com

Skype: SamirAbreu

xHarbour 1.10/1.21 + FwXh 8.02/10.6

"Acreditar é mais fácil do que pensar: Daí existem muito mais crentes do que pensadores.†Bruce Calvert

Link to comment
Share on other sites

  • 4 months later...

provavelmente , é o arquivo da contrib do [x]Harbour.

oserver é a variavel de inicializacao da conexao.

de uma olhada na contrib do seu [x]Harbour la tem os .ch

Gilmar Silva Santos

Programador - Goiânia Go

Não Recuarei, Nada Temerei, Comigo Está o Senhor.

Email : gilmarss2010@gmail.com

FWH 10.8, DBF, MED EDITOR, UESTUDIO, XHB 1.2, BCC 5.82

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...