;** RP_0373 ********************************************************************
;*  Recibo de Recebimento Cliente / Contas a Receber   ** Floren‡a Tecidos     *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 22/06/2016 por Anivel Augusto Rodrigues
;Ultima Alteracao:   /  /     por  
;Motivo Alteracao: 

;*******************************************************************************
;* Rotina para impressao do recibo de recebimento                           ****
;*****************+*************************************************************
Proc IMPRP()

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

If Not IsAssigned(Sys_Reset_Impressora)
   Then Sys_Reset_Impressora=""
EndIf

Obs()

Print File ARQIMP Sys_ReSet_Impressora
Print File ARQIMP CI_8LPP

If cliant<>[Duplic->Codigo do Destinatario]
   Then If cliant<>"****"
           Then Rodape()
        EndIf   
        cliant=[Duplic->Codigo do Destinatario]
        VR_RECIBO=0
        Cabecalho()
EndIf   
ITENS()

If ULTIMA_BAIXA 
   Then RODAPE()
EndIF

EndProc ;IMPRP()

;*******************************************************************************
;* Cabe‡alho                                                                   *
;*******************************************************************************
Proc CABECALHO()

Print File ARQIMP "\n\n"
Print File ARQIMP CI_FEXP
Print File ARQIMP CI_FNEG
Print File ARQIMP CI_15CPP
Print File ARQIMP Fill("=",136)+"\n"
Print File ARQIMP CI_10CPP
Print File ARQIMP CI_IEXP
Print File ARQIMP CI_INEG

Print File ARQIMP "         RECIBO DE RECEBIMENTO"
Print File ARQIMP CI_15CPP
Print File ARQIMP CI_FEXP
Print File ARQIMP CI_FNEG+"\n"

;;;;;;Print File ARQIMP "EMISSAO: "+Format("D13",Today())+"-"+Time()+"\n"
Print File ARQIMP Fill("-",136)+"\n"
Print File ARQIMP "NOME..............: "+Format("W20,AL",[Duplic->Nome Fantasia EmitDest])

If IsAssigned(RG)
   Then Print File ARQIMP Spaces(02)+"RG: "+RG+"\n"
   Else Print File ARQIMP "\n" 
EndIf

Print File ARQIMP "ENDERE€O..........: " + Format("W40,AL",ENDERECO)+"\n"
Print File ARQIMP "BAIRRO............: " + Format("W20,AL",BAIRRO)+Spaces(05)+"FONE: " + Format("W20,AL",TELEFONE)+"\n"
Print File ARQIMP "CIDADE............: " + Format("W20,AL",CIDADE)+"\n"
Print File ARQIMP "CENTRO DE CUSTO...: " + [DupBaixa->Codigo CCusto]+Spaces(1)+Format("W30,AL",[DupBaixa->Descricao CCusto])+"\n\n"

ESCEXT([DupBaixa->Valor do Recebimento])
EXTENSO=" ("+SubStr(EXTENSO,2,97)+")"  
Print File ARQIMP "VALOR DO RECEBIMENTO: " + Format("W10.2,EIC",[Valor do Recebimento])+ Format("W100",SubStr(EXTENSO,1,100))+ "\n\n"

Print File ARQIMP "Referente.........: "+Format("W15,AL",[Duplic->Documento Referente])+"\n"

For i From 1 To Cont_Obs
  Print File ARQIMP SubStr(Observacao[i],4,Len(Observacao[i])) 
EndFor 
Print File ARQIMP "\n\n"

Print File ARQIMP Spaces(01)+"                                            -------------------------------------- Valores --------------------------------------\n"
Print File ARQIMP Spaces(01)+"          N§ Lancamento         Documento           Original            Juros/Multa               Desconto                  Total\n"
Print File ARQIMP Spaces(01)+"       ---------------- ----------------- ------------------ ---------------------- ---------------------- ----------------------\n"

EndProc ;CABECALHO()      xxxxxxxxx.xx
                                  
;*******************************************************************************
;* Impressao dos Itens                                                      *
;*******************************************************************************
Proc ITENS()

Print File ARQIMP CI_15CPP
Print File ARQIMP CI_FEXP
Print File ARQIMP CI_FNEG

Print File ARQIMP Spaces(18)+Format("W06,AL",[Duplic->Numero do Lancamento])
Print File ARQIMP Spaces(03)+Format("W04,AL",[Duplic->Tipo do Documento])
Print File ARQIMP Spaces(01)+Format("W10,AL",[Duplic->Numero do Documento])
Print File ARQIMP Spaces(06)+Format("W13.2,EIC",([Valor do Recebimento]+[Valor do Desconto])-[Valor do Juros])
; VERIFICAR O CALCULO COM ANIVEL
Print File ARQIMP Spaces(11)+Format("W12.2,EIC",[Valor do Juros])
Print File ARQIMP Spaces(11)+Format("W12.2,EIC",[Valor do Desconto])
Print File ARQIMP Spaces(11)+Format("W12.2,EIC",[Valor do Recebimento])+"\n"

VR_RECIBO=VR_RECIBO+[Valor do Recebimento]
        
EndProc ;ITENS()

;*******************************************************************************
;* Impressao dos Rodap‚                                                        *
;*******************************************************************************
Proc RODAPE()

Print File ARQIMP CI_15CPP
Print File ARQIMP CI_FEXP
Print File ARQIMP CI_FNEG

Print File ARQIMP Fill("-",136)+"\n"

Print File ARQIMP Spaces(39)+Format("W19,AL","Data do Recebimento: ")
Print File ARQIMP Spaces(01)+Format("D13",[Data do Pagamento])
                                    
Print File ARQIMP Spaces(05)+"Valor Recebimento: "+LTrim(Format("W11.2,EIC",VR_RECIBO))+"\n\n"

Print File ARQIMP Format("W136,AC","   /   /     -                                                         ")+"\n"
Print File ARQIMP Format("W136,AC","-----------------------------------------------------------------------")+"\n"
Print File ARQIMP Format("W136,AC","Data e Assinatura")+"\n";Spaces(17)++"\n"

Print File ARQIMP Fill("=",136)
If Not ULTIMA_BAIXA
   THEN PRINT FILE ARQIMP "\N\N"
   ELSE If RECB_AUT
           Then If SALTA_PAGINA
                   Then Print File ARQIMP "\f"
                   Else Print File ARQIMP "\n\n"
                EndIf   
           Else PRINT FILE ARQIMP FILL("\N",20)
        EndIf
ENDIF

Print File ARQIMP CI_10CPP
Print File ARQIMP CI_6LPP

EndProc ;RODAPE()

;*******************************************************************************
;* Observa‡Æo                                                                  *
;*******************************************************************************
Proc Obs()  
Private OBS,QTD,LABEL_OBS,LINHA,Pos_Inicio,OBS_AUX,QTD_AUX,QTD_LINHA,wia

OBS        = [Duplic->Observacoes]
LABEL_OBS  = "Observacoes.......: "
LINHA      = 0   
     
Pos_Inicio=SearchFrom("\n",OBS,1) 
While True
 If Pos_Inicio > 0
    Then OBS_AUX   = SubStr(OBS,1,Pos_Inicio-1)
    Else OBS_AUX   = OBS
 EndIf   
 OBS       = SubStr(OBS,Pos_Inicio+1,Len(OBS)) 
 QTD_AUX   = Len(OBS_AUX)
 QTD_LINHA = Round(QTD_AUX/NUM_CARACTERES_OBS,0)                     
 If ((QTD_AUX/NUM_CARACTERES_OBS) - QTD_LINHA) > 0
    Then QTD_LINHA = QTD_LINHA + 1
 EndIf   
 For wia From 1 To QTD_LINHA 
   Cont_Obs = Cont_Obs + 1
   
   If LINHA = 0 
      Then LINHA = LABEL_OBS
      Else LINHA = Spaces(Len(LABEL_OBS))
   EndIf
   Observacao[Cont_Obs] = AlinhM(StrVal(Cont_Obs),3)+LINHA
   
   LINHA = Substr(OBS_AUX,((wia-1)*NUM_CARACTERES_OBS)+1,NUM_CARACTERES_OBS)
   Observacao[Cont_Obs] = Observacao[Cont_Obs]+"\27E"+LINHA+"\27F"+"\n"   
 EndFor
 If Pos_Inicio = 0 Then Quitloop EndIf
 Pos_Inicio=SearchFrom("\n",OBS,1)                
EndWhile  
LINHA = ""  
                               
EndProc ;Obs()
 
;*******************************************************************************
;* Rotina Principal                                                            *
;*****************+*************************************************************
AGUARDE("Imprimindo Recibo de Recebimento-> "+[Duplic->Numero do Lancamento])
If Not IsAssigned(RECB_AUT)      Then RECB_AUT=False       EndIf
If Not IsAssigned (SALTA_PAGINA) Then SALTA_PAGINA = False EndIf
       
Release Vars Observacao       
DynArray Observacao[]       
                                                          
NUM_CARACTERES_OBS = 111
LINHAS_OBS         = False
Cont_Obs           = 0
                                                          
IMPRP()
LIMPAGUARDE()

Release Procs IMPRP, RODAPE, ITENS, CABECALHO, COMPLEMENTO