;** Pd_0438 ********************************************************************
;** Imprime a Digitacao do Pedido                         ** JOFRAN **         *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 23/08/2019 por Anivel Augusto Rodrigues
;Ultima Alteracao: 04/10/2019 por Anivel Augusto Rodrigues 
;Motivo Alteracao: Ajusets nÆo sair ICMS ST

;*******************************************************************************
;* Rotina para Impressao do Relatorio                                          *
;*******************************************************************************
Proc IMPPED()

;************************* IMPRESSAO DO CABECALHO *****************************
If Not IsAssigned(NOMEMPRESA)
   Then NOMEMPRESA=""
EndIf

Print File ARQIMP CI_15CPP
Print File ARQIMP "\n"
Print File ARQIMP  "  ------------------------------------------------------------------------------------------------------------------------------------" + "\n"
Print File ARQIMP  Format("W40,AL",NOMEMPRESA)+Spaces(15)+"Pedido de Venda"+Spaces(34)+"Impressao: "+Format("D13",Today())+"-"+Time()+ "\n"
Print File ARQIMP  "  ------------------------------------------------------------------------------------------------------------------------------------" + "\n\n"

Print File ARQIMP Spaces(02)+"Cliente: "
Print File ARQIMP Format("W05,AL",[Codigo])
Print File ARQIMP Format("W95,AL",[Razao Social])
Print File ARQIMP "N§ Pedido "+CI_IEXP+CI_INEG+Format("W06.3,AL",[Numero do Pedido])+CI_FEXP+CI_FNEG+"\n"

Print File ARQIMP Spaces(16)+Format("W40,AL",[Endereco])
Print File ARQIMP Format("W18,AL",[CGC])+Spaces(07)+"Emissao: "
Print File ARQIMP Format("D13",[Data de Emissao])+"\n"

Print File ARQIMP Spaces(16)+Format("W20,AL",[Bairro])
Print File ARQIMP Format("W20,AL",[CEP])
Print File ARQIMP Format("W25,AL",[IE])
Print File ARQIMP "Entrega: "+Format("D13",[Data de Entrega])+"\n"

Print File ARQIMP Spaces(16)+Format("W20,AL",[Cidade])
Print File ARQIMP Format("W20,AL",[UF])
Print File ARQIMP Format("W25,AL",[Telefone])
Print File ARQIMP "Empresa: "+Format("W05,AL",[Codigo da Empresa])+Format("W20,AL",[Nome Fantasia Empresa])+"\n\n"

Print File ARQIMP Spaces(02)+"Representante: "+Format("W05,AL",[Codigo do Representante])
Print File ARQIMP Format("W25,AL",[Nome Fantasia Represent])
Print File ARQIMP "Destinacao: "+Format("W04,AL",[Codigo da Destinacao])
Print File ARQIMP Format("W25,AL",[Descricao da Destinacao])
Print File ARQIMP "CFO: "+Format("W09,AL",[CFO])
Print File ARQIMP "TabPreco: "+Format("W06,AL",[Codigo da Tabela])+"\n"

Print File ARQIMP Spaces(02)+"Transportador: "+Format("W05,AL",[Codigo da Transportadora])
Print File ARQIMP Format("W28,AL",[Nome Fantasia Transport])
Print File ARQIMP "Veiculo: "+Format("W08,AL",[Placa do Veiculo])+"-"+Format("W08,AL",[UF Veiculo])
Print File ARQIMP "Frete por Conta: "+Format("W15,AL",[Frete por Conta])+"\n\n"

;********************* IMPRESSAO DOS ITENS ********************************
Print File ARQIMP Spaces(02)+"Sq Item                                                Cor/Tecido                "
Print File ARQIMP "Tm  Quantidade Un PrUnitario    PrTotal     ICMS ST"+"\n"
Print File ARQIMP Spaces(02)+"-- --------------------------------------------------- ------------------------- "
Print File ARQIMP "-- ----------- -- ---------- ---------- -----------"+"\n"
Moveto "PedidoI"
Cont=1
Scan
   Print File ARQIMP Spaces(02)+Format("W03,AL",[Item do Pedido])
   Print File ARQIMP Format("W11,AL",[Codigo do Item])
   Print File ARQIMP Format("W41,AL",[Descricao do Item])
   Print File ARQIMP Format("W05,AL",[Codigo da Cor_Tecido])
   Print File ARQIMP Format("W21,AL",[Descricao da Cor_Tecido])
   Print File ARQIMP Format("W03,AR",[Tamanho])
   Print File ARQIMP Format("W11.3,EIC",[Quantidade])
   Print File ARQIMP Format("W03,AR",[Unidade Fiscal])
   Print File ARQIMP Format("W11.2,EIC",[Preco Unitario])
   Print File ARQIMP Format("W11.2,EIC",[Preco Total])
   Print File ARQIMP Format("W12.2,EIC",[ICMS_ST_Valor])+"\n"
   Cont=Cont+1
   If Cont=49
     Then
     Print File ARQIMP "\n\n\n"
   EndIf
EndScan

;********************* IMPRESSAO DOS TOTAIS **************************
Moveto "PedidoC"
Print File ARQIMP "\n"
Print File ARQIMP "  Mecadorias         Desconto     Liquido    Frete    Seguro   Desp.Aces                   Total     BC.ICMS        ICMS"+"\n"
;;9.999.999,99888.88%777.777,776.666.666,6644.444,44111.111,112.222.222,223.333/333,334.444.444,445.555.555,551.111.111,11

Print File ARQIMP  Format("W12.2,EIC",[Valor Mercadoria])
Print File ARQIMP Format("W06.2,EIC",[Taxa de Desconto])+"%"
Print File ARQIMP Format("W10.2,EIC",[Valor do Desconto])
Print File ARQIMP Format("W12.2,EIC",[Valor Mercadoria Liquido])
Print File ARQIMP Format("W09.2,EIC",[Valor do Frete])
Print File ARQIMP Format("W10.2,EIC",[Valor do Seguro])
Print File ARQIMP Format("W012.2,EIC",[Valor Despesas Acessorias])
Print File ARQIMP Format("W012.2,EIC",blankNum())
Print File ARQIMP Format("W012.2,EIC",[Valor Nota Fiscal])
Print File ARQIMP Format("W012.2,EIC",[Valor BCICMS])
Print File ARQIMP Format("W012.2,EIC",[Valor ICMS])+"\n\n"

Print File ARQIMP Spaces(02)+"Cond. Pagamento.: "+[Descricao CondPagto]
Print File ARQIMP "   NP: "+StrVal([Numero de Parcelas])
Print File ARQIMP "   CD: "+[Composicao de Dias]
Print File ARQIMP "   N.Volumes.: "+LTrim(Format("W06,EIC",[PedidoC->Numero de Volumes]))
Print File ARQIMP "   Peso Liquido: "+LTrim(Format("W11.3,EIC",[PedidoC->Peso Liquido]))
Print File ARQIMP "   Peso Bruto: "+LTrim(Format("W11.3,EIC",[PedidoC->Peso Bruto]))+"\n"

;********************* IMPRESSAO DOS VENCIMENTOS **************************
Vencimentos()
Print File ARQIMP "\n"

;************************* IMPRESSAO DO RODAPE ********************************
Moveto "PedidoC"
imprimeobs()

Print File ARQIMP Spaces(02)+"Local p/ Entrega: "+Format("W20,AL",[Endereco de Entrega])+"\n"
Print File ARQIMP Spaces(20)+Format("W15,AL",[Bairro de Entrega])+Format("W11,AL",[CEP de Entrega])
Print File ARQIMP Spaces(40)+"_______________________________________________"+"\n"
Print File ARQIMP Spaces(20)+Format("W15,AL",[Cidade de Entrega])+Format("W03,AL",[UF de Entrega])
Print File ARQIMP Spaces(60)+"Data/Assinatura Responsavel"+"\n\n"
Print File ARQIMP "  ------------------------------------------------------------------------------------------------------------------------------------"
Print File ARQIMP CI_10CPP
Print File ARQIMP "\f"+"\n"
EndProc

;*******************************************************************************
;* Rotina de Impressao dos Vencimentos                                         *
;*******************************************************************************
Proc Vencimentos()
private s1,s2,s3, kv

s1="  Vencimentos.....: "
s2="                    "
s3="                    "
kv=0

Moveto "PedidoV"
Scan
 if kv=10
    then Print File ARQIMP s1+"\n"
         Print File ARQIMP s2+"\n"
         Print File ARQIMP s3+"\n"

         kv=0
         s1="                  "
         s2="                  "
         s3="                  "
 endif

 kv=kv+1
 s1=s1+spaces(08)+[Forma de Pagamento]+Spaces(02)
 s2=s2+Format("D13",[Data])+Spaces(02)
 s3=s3+Format("W10.2,EIC",[Valor])+Spaces(02)

endscan
if kv>0
  then Print File ARQIMP s1+"\n"
       Print File ARQIMP s2+"\n"
       Print File ARQIMP s3+"\n"
endif
endproc

;*******************************************************************************
;* Rotina de Impressao de Observa‡äes                                          *
;*******************************************************************************
proc imprimeobs()
private TamObs, nlobs, posobs, i, s

TamObs=80

s="  Observacoes.....: "+Tira_QuebraLinha([Observacao do Pedido])

nlobs=Len(s)/tamobs
If nlobs-Int(nlobs)>0
   Then nlobs=Int(nlobs)+1
   Else nlobs=Int(nlobs)
EndIf

posobs=1
For i from 1 to nlobs
  Print File ARQIMP CI_INEG+SubStr(s,posobs,tamobs)+CI_FNEG+"\n"
  posobs=posobs+tamobs
EndFor

endproc

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
AGUARDE("Imprimindo Pedido -> "+PEDIDO)

ArqImp=PrivDir()+"PD_0438.Txt"
If IsFile(ArqImp)
   Then Deleta_Arquivo(ARQIMP)
EndIf

IMPPED()
ImpriArq(ARQIMP)

Release Vars cont 
Release Procs IMPPED,Vencimentos,imprimeobs

