Вы находитесь на странице: 1из 27

// ============================================================================= // // Gerar Lote de CTe // // ============================================================================= procedure TfrmMovEmitirCNT.

GerarLoteCTe; var i, j, k, l, CodigoMunicipio: Integer; IE: String; OkConversao: Boolean; begin with DMCTE.CTe.Conhecimentos.Add.CTe do begin // // Dados de Identificao do CT-e // Ide.cUF := DM_CTA.EmpresaCodigoEstado.AsInteger; Ide.cCT := DM_CNT.ConhecimentoCTChave.AsInteger; // Cdigo Aleatrio Ide.CFOP := DM_CNT.ConhecimentoCFOP.AsInteger; Ide.natOp := 'PRESTAO DE SERVIO'; if DM_CNT.ConhecimentoForPag.AsInteger=0 then Ide.forPag := fpPago else Ide.forPag := fpAPagar; Ide.modelo Ide.serie Ide.nCT Ide.dhEmi Ide.tpImp := := := := := '57'; DM_CNT.ConhecimentoSerie.AsInteger; DM_CNT.ConhecimentoNumero.AsInteger; Now; tiRetrato;

// TpcnTipoEmissao = (teNormal, teContingencia, teSCAN, teDPEC, teFSDA, teSVC RS, teSVCSP); case rgTipoEmissao.ItemIndex of 0: Ide.tpEmis := teNormal; 1: Ide.tpEmis := teFSDA; // Contingencia FSDA 2: Ide.tpEmis := teSVCRS; 3: Ide.tpEmis := teSVCSP; end; // TpcnTipoAmbiente = (taProducao, taHomologacao); case DM_CTA.ParamDFeWSAmbiente.AsInteger of 0: Ide.tpAmb := taHomologacao; 1: Ide.tpAmb := taProducao; end; // TpcteTipoCTe = (tcNormal, tcComplemento, tcAnulacao, tcSubstituto); case DM_CNT.ConhecimentoTipoCTe.AsInteger of 0: Ide.tpCTe := tcNormal; 1: Ide.tpCTe := tcComplemento; 2: Ide.tpCTe := tcAnulacao; 3: Ide.tpCTe := tcSubstituto; end; // TpcnProcessoEmissao = (peAplicativoContribuinte, peAvulsaFisco, peAvulsaCo ntribuinte, peContribuinteAplicativoFisco); Ide.procEmi := peAplicativoContribuinte; Ide.verProc Ide.refCTE := '4.0'; := trim(DM_CNT.ConhecimentoRefCTe.AsString); // Chave de Aces

so do CT-e Referenciado CodigoMunicipio := DM_CTA.EmpresaCodigoEstado.AsInteger * 100000 + DM_CTA.EmpresaCodigoMunicipio.AsInteger; Ide.cMunEnv := CodigoMunicipio; Ide.xMunEnv := DM_CTA.EmpresaCidade.AsString; Ide.UFEnv := DM_CTA.EmpresaEstado.AsString; // TpcteModal = (mdRodoviario, mdAereo, mdAquaviario, mdFerroviario, mdDutovi ario); Ide.modal := mdRodoviario; // TpcteTipoServico = (tsNormal, tsSubcontratacao, tsRedespacho, tsIntermedia rio); case DM_CNT.ConhecimentoTipoServico.AsInteger of 0: Ide.tpServ := tsNormal; 1: Ide.tpServ := tsSubcontratacao; 2: Ide.tpServ := tsRedespacho; 3: Ide.tpServ := tsIntermediario; end; // Origem da Prestao Ide.cMunIni := DM_CNT.ConhecimentoCodCidadeColeta.AsInteger; Ide.xMunIni := DM_CNT.ConhecimentoNomeCidadeColeta.AsString; Ide.UFIni := DM_CNT.ConhecimentoEstadoColeta.AsString; // Destino da Prestao Ide.cMunFim := DM_CNT.ConhecimentoCodCidadeEntrega.AsInteger; Ide.xMunFim := DM_CNT.ConhecimentoNomeCidadeEntrega.AsString; Ide.UFFim := DM_CNT.ConhecimentoEstadoEntrega.AsString; // TpcteRetira = (rtSim, rtNao); Ide.retira := rtSim; Ide.xdetretira := ''; case DM_CNT.ConhecimentoTomadorServico.AsInteger of 0: Ide.Toma03.Toma := tmRemetente; 1: Ide.Toma03.Toma := tmExpedidor; 2: Ide.Toma03.Toma := tmRecebedor; 3: Ide.Toma03.Toma := tmDestinatario; 4: Ide.Toma03.Toma := tmRemetente; end; // Totamdor do Servio no CTe 4 = Outros if DM_CNT.ConhecimentoTomadorServico.AsInteger = 4 then begin DM_CTA.PessoaFJ.Close; DM_CTA.PessoaFJ.SQL.Clear; DM_CTA.PessoaFJ.SQL.Add('Select * From Sis_PessoaFJ'); DM_CTA.PessoaFJ.SQL.Add('Where CGC = :xCGC'); DM_CTA.PessoaFJ.Params[0].AsString := DM_CNT.ConhecimentoOutros.AsString; DM_CTA.PessoaFJ.Active := True; DM_CTA.PessoaFJ.Open; Ide.Toma4.Toma:=tmOutros; if copy(DM_CTA.PessoaFJCGC.AsString,10,4) <> '0000' then begin Ide.Toma4.CNPJCPF := Copy(DM_CTA.PessoaFJCGC.AsString, 2, 14); IE := DM_CTA.PessoaFJIEstadual.AsString; end else begin

Ide.Toma4.CNPJCPF := Copy(DM_CTA.PessoaFJCGC.AsString, 1, 9) + Copy(DM_CTA.PessoaFJCGC.AsString, 14, 2); IE := 'ISENTO'; end; Ide.Toma4.IE Ide.Toma4.xNome Ide.Toma4.xFant Ide.Toma4.fone Ide.Toma4.EnderToma.xLgr Ide.Toma4.EnderToma.nro Ide.Toma4.EnderToma.xCpl Ide.Toma4.EnderToma.xBairro CodigoMunicipio 00 + Ide.Toma4.EnderToma.cMun Ide.Toma4.EnderToma.xMun Ide.Toma4.EnderToma.CEP Ide.Toma4.EnderToma.UF Ide.Toma4.EnderToma.cPais Ide.Toma4.EnderToma.xPais end; := := := := := := DM_CTA.PessoaFJCodigoMunicipio.AsInteger; CodigoMunicipio; DM_CTA.PessoaFJCidade.AsString; StrToIntDef(DM_CTA.PessoaFJCEP.AsString, 0); DM_CTA.PessoaFJEstado.AsString; DM_CTA.PessoaFJCodigoPais.AsInteger; DM_CTA.PessoaFJPais.AsString; := := := := := := := := := IE; DM_CTA.PessoaFJRSocial.AsString; DM_CTA.PessoaFJFantasia.AsString; DM_CTA.PessoaFJTelefone.AsString; DM_CTA.PessoaFJEndereco.AsString; DM_CTA.PessoaFJNumero.AsString; DM_CTA.PessoaFJComplemento.AsString; DM_CTA.PessoaFJBairro.AsString; DM_CTA.PessoaFJCodigoEstado.AsInteger * 1000

if rgTipoEmissao.ItemIndex = 1 then begin Ide.dhCont := StrToDateTime(edtDataCont.Text+' '+edtHoraCont.Text+':00'); Ide.xJust := edtJustificativa.Text; end; // // Informaes // compl.xCaracAd compl.xCaracSer compl.xEmi Complementares do CTe := Trim(DM_CNT.ConhecimentoCaracAdTrans.AsString); := Trim(DM_CNT.ConhecimentoCaracAdServ.AsString); := Trim(DM_CNT.ConhecimentoFuncioEmissorCTe.AsString);

compl.fluxo.xOrig := Trim(DM_CNT.ConhecimentoFluxoOrigem.AsString); if Trim(DM_CNT.ConhecimentoFluxoPassagem.AsString) <> '' then begin with compl.fluxo.pass.Add do begin xPass := Trim(DM_CNT.ConhecimentoFluxoPassagem.AsString); end; end; compl.fluxo.xDest := Trim(DM_CNT.ConhecimentoFluxoDestino.AsString); compl.fluxo.xRota := Trim(DM_CNT.ConhecimentoFluxoRota.AsString); compl.Entrega.TipoData := StrToTpDataPeriodo(okConversao, IntToStr(DM_CNT.Con hecimentoEntregaTipoData.AsInteger)); case DM_CNT.ConhecimentoEntregaTipoData.AsInteger of 0: compl.Entrega.semData.tpPer := tdSemData; 1,2,3: begin compl.Entrega.comData.tpPer := StrToTpDataPeriodo(okConversao, IntTo Str(DM_CNT.ConhecimentoEntregaTipoData.AsInteger)); compl.Entrega.comData.dProg := DM_CNT.ConhecimentoEntregaDataI.AsDat eTime; end; 4: begin compl.Entrega.noPeriodo.tpPer := tdNoPeriodo;

compl.Entrega.noPeriodo.dIni := DM_CNT.ConhecimentoEntregaDataI.AsD ateTime; compl.Entrega.noPeriodo.dFim := DM_CNT.ConhecimentoEntregaDataF.AsD ateTime; end; end; compl.Entrega.TipoHora := StrToTpHorarioIntervalo(okConversao, IntToStr(DM_CN T.ConhecimentoEntregaTipoHora.AsInteger)); case DM_CNT.ConhecimentoEntregaTipoHora.AsInteger of 0: compl.Entrega.semHora.tpHor := thSemHorario; 1,2,3: begin compl.Entrega.comHora.tpHor := StrToTpHorarioIntervalo(okConversao, IntToStr(DM_CNT.ConhecimentoEntregaTipoHora.AsInteger)); compl.Entrega.comHora.hProg := StrToTime(DM_CNT.ConhecimentoEntregaH oraI.AsString); end; 4: begin compl.Entrega.noInter.tpHor := thNoIntervalo; compl.Entrega.noInter.hIni := StrToTime(DM_CNT.ConhecimentoEntregaH oraI.AsString); compl.Entrega.noInter.hFim := StrToTime(DM_CNT.ConhecimentoEntregaH oraF.AsString); end; end; compl.origCalc := DM_CNT.ConhecimentoNomeCidadeColeta.AsString; compl.destCalc := DM_CNT.ConhecimentoNomeCidadeEntrega.AsString; compl.xObs := DM_CNT.ConhecimentoMensagem.AsString; DM_CNT.Tabelas.Close; DM_CNT.Tabelas.SQL.Clear; DM_CNT.Tabelas.SQL.Add('Select * From Cnt_Tabelas'); DM_CNT.Tabelas.SQL.Add('Where Codigo = :xTabela'); DM_CNT.Tabelas.Params[0].AsString := DM_CNT.ConhecimentoTabela.AsString; DM_CNT.Tabelas.Active := True; DM_CNT.Tabelas.Open; if DM_CNT.TabelasCST.AsInteger = 41 then compl.xObs := compl.xObs + ';Documento emitido por ME ou EPP optante pelo Simples Nacional' + ';Nao gera direito a credito fiscal de ICMS'; // Obs do Contribuinte if (trim(DM_CNT.ConhecimentoObsContCampo.AsString) <> '') and (trim(DM_CNT.ConhecimentoObsContTexto.AsString) <> '') then begin with compl.ObsCont.Add do begin xCampo := DM_CNT.ConhecimentoObsContCampo.AsString; xTexto := DM_CNT.ConhecimentoObsContTexto.AsString; end; end; // Obs para o Fisco if (trim(DM_CNT.ConhecimentoObsFiscoCampo.AsString) <> '') and (trim(DM_CNT.ConhecimentoObsFiscoTexto.AsString) <> '') then begin with compl.ObsFisco.Add do begin

xCampo := DM_CNT.ConhecimentoObsFiscoCampo.AsString; xTexto := DM_CNT.ConhecimentoObsFiscoTexto.AsString; end; end; // // Dados do Emitente // DM_CTA.Empresa.Close; DM_CTA.Empresa.SQL.Clear; DM_CTA.Empresa.SQL.Add('Select * From Sis_Empresa'); DM_CTA.Empresa.SQL.Add('Where Codigo = :xCodigo'); DM_CTA.Empresa.Params[0].AsString := DM_CTA.ParamDFeEmitente.AsString; DM_CTA.Empresa.Active := True; DM_CTA.Empresa.Open; if copy(DM_CTA.EmpresaCNPJ.AsString,10,4) <> '0000' then Emit.CNPJ := Copy(DM_CTA.EmpresaCNPJ.AsString, 2, 14) else Emit.CNPJ := Copy(DM_CTA.EmpresaCNPJ.AsString, 1, 9) + Copy(DM_CTA.EmpresaCNPJ.AsString, 14, 2); if (trim(DM_CTA.EmpresaInscEstadual.AsString) = '') or (trim(DM_CTA.EmpresaInscEstadual.AsString) = 'ISENTO') then Emit.IE := '1234567890' else Emit.IE := trim(DM_CTA.EmpresaInscEstadual.AsString); Emit.xNome Emit.xFant Emit.EnderEmit.xLgr Emit.EnderEmit.nro Emit.EnderEmit.xCpl Emit.EnderEmit.xBairro CodigoMunicipio Emit.EnderEmit.cMun Emit.EnderEmit.xMun Emit.EnderEmit.CEP Emit.EnderEmit.UF Emit.EnderEmit.fone := := := := := := := := := := := := DM_CTA.EmpresaNome.AsString; DM_CTA.EmpresaFantasia.AsString; DM_CTA.EmpresaEndereco.AsString; DM_CTA.EmpresaNumero.AsString; DM_CTA.EmpresaComplemento.AsString; DM_CTA.EmpresaBairro.AsString; DM_CTA.EmpresaCodigoEstado.AsInteger * 100000 + DM_CTA.EmpresaCodigoMunicipio.AsInteger; CodigoMunicipio; DM_CTA.EmpresaCidade.AsString; StrToIntDef(DM_CTA.EmpresaCEP.AsString, 0); DM_CTA.EmpresaEstado.AsString; DM_CTA.EmpresaTelefone.AsString;

// // Dados do Remetente // if trim(DM_CNT.ConhecimentoRemetente.AsString) <> '' then begin DM_CTA.PessoaFJ.Close; DM_CTA.PessoaFJ.SQL.Clear; DM_CTA.PessoaFJ.SQL.Add('Select * From Sis_PessoaFJ'); DM_CTA.PessoaFJ.SQL.Add('Where CGC = :xCGC'); DM_CTA.PessoaFJ.Params[0].AsString := DM_CNT.ConhecimentoRemetente.AsString ; DM_CTA.PessoaFJ.Active := True; DM_CTA.PessoaFJ.Open; DM_CTA.PessoaFJE.Close; DM_CTA.PessoaFJE.SQL.Clear; DM_CTA.PessoaFJE.SQL.Add('Select * From Sis_PessoaFJEmail'); DM_CTA.PessoaFJE.SQL.Add('Where CNPJ = :xCNPJ'); DM_CTA.PessoaFJE.SQL.Add('and Modulo = :xModulo'); DM_CTA.PessoaFJE.Params[0].AsString := DM_CTA.PessoaFJCGC.AsString;

DM_CTA.PessoaFJE.Params[1].AsString := 'DFE'; DM_CTA.PessoaFJE.Active := True; DM_CTA.PessoaFJE.Open; if (DM_CTA.PessoaFJECNPJ.AsString = DM_CTA.PessoaFJCGC.AsString) and (DM_CTA.PessoaFJEModulo.AsString = 'DFE') then Rem.email := Trim(DM_CTA.PessoaFJEEmail.AsString) else Rem.email := ''; Rem.xNome Rem.xFant Rem.EnderReme.xLgr Rem.EnderReme.nro Rem.EnderReme.xCpl Rem.EnderReme.xBairro CodigoMunicipio Rem.EnderReme.cMun Rem.EnderReme.xMun Rem.EnderReme.CEP Rem.EnderReme.UF Rem.EnderReme.cPais Rem.EnderReme.xPais {$IFDEF PL_200} // Local da Coleta if trim(DM_CNT.NotasCNPJRet.AsString) <> '' then begin DM_CTA.PessoaFJ.Close; DM_CTA.PessoaFJ.SQL.Clear; DM_CTA.PessoaFJ.SQL.Add('Select * From Sis_PessoaFJ'); DM_CTA.PessoaFJ.SQL.Add('Where CGC = :xCGC'); DM_CTA.PessoaFJ.Params[0].AsString := DM_CNT.NotasCNPJRet.AsString; DM_CTA.PessoaFJ.Active := True; DM_CTA.PessoaFJ.Open; if copy(DM_CTA.PessoaFJCGC.AsString,10,4) <> '0000' then Rem.locColeta.CNPJCPF := Copy(DM_CTA.PessoaFJCGC.AsString, 2, 14) else Rem.locColeta.CNPJCPF := Copy(DM_CTA.PessoaFJCGC.AsString, 1, 9) + Copy(DM_CTA.PessoaFJCGC.AsString, 14, 2); Rem.locColeta.xNome Rem.locColeta.xLgr Rem.locColeta.nro Rem.locColeta.xCpl Rem.locColeta.xBairro CodigoMunicipio + Rem.locColeta.cMun Rem.locColeta.xMun Rem.locColeta.UF end; {$ENDIF} DM_CTA.PessoaFJCodigoMunicipio.AsInteger; := CodigoMunicipio; := DM_CTA.PessoaFJCidade.AsString; := DM_CTA.PessoaFJEstado.AsString; := := := := := := DM_CTA.PessoaFJRSocial.AsString; DM_CTA.PessoaFJEndereco.AsString; DM_CTA.PessoaFJNumero.AsString; DM_CTA.PessoaFJComplemento.AsString; DM_CTA.PessoaFJBairro.AsString; DM_CTA.PessoaFJCodigoEstado.AsInteger * 100000 := := := := := := := := := := := := := DM_CTA.PessoaFJRSocial.AsString; DM_CTA.PessoaFJFantasia.AsString; DM_CTA.PessoaFJEndereco.AsString; DM_CTA.PessoaFJNumero.AsString; DM_CTA.PessoaFJComplemento.AsString; DM_CTA.PessoaFJBairro.AsString; DM_CTA.PessoaFJCodigoEstado.AsInteger * 100000 + DM_CTA.PessoaFJCodigoMunicipio.AsInteger; CodigoMunicipio; DM_CTA.PessoaFJCidade.AsString; StrToIntDef(DM_CTA.PessoaFJCEP.AsString, 0); DM_CTA.PessoaFJEstado.AsString; DM_CTA.PessoaFJCodigoPais.AsInteger; DM_CTA.PessoaFJPais.AsString;

if copy(DM_CTA.PessoaFJCGC.AsString,10,4) <> '0000' then begin Rem.CNPJCPF := Copy(DM_CTA.PessoaFJCGC.AsString, 2, 14); IE := DM_CTA.PessoaFJIEstadual.AsString;

end else begin Rem.CNPJCPF := Copy(DM_CTA.PessoaFJCGC.AsString, 1, 9) + Copy(DM_CTA.PessoaFJCGC.AsString, 14, 2); IE := 'ISENTO'; end; Rem.IE := IE; Rem.fone := DM_CTA.PessoaFJTelefone.AsString; // // Relao das Notas Fiscais // DM_CNT.Notas.Close; DM_CNT.Notas.SQL.Clear; DM_CNT.Notas.SQL.Add('Select * From Cnt_Notas'); DM_CNT.Notas.SQL.Add('Where Codigo = :xCodigo'); DM_CNT.Notas.SQL.Add('and Serie = :xSerie'); DM_CNT.Notas.SQL.Add('and Numero = :xNumero'); DM_CNT.Notas.SQL.Add('Order By Tipo'); DM_CNT.Notas.Params[0].AsInteger := DM_CNT.ConhecimentoCodigo.AsInteger; DM_CNT.Notas.Params[1].AsInteger := DM_CNT.ConhecimentoSerie.AsInteger; DM_CNT.Notas.Params[2].AsInteger := DM_CNT.ConhecimentoNumero.AsInteger; DM_CNT.Notas.Active := True; DM_CNT.Notas.Open; DM_CNT.Notas.Last; j := DM_CNT.Notas.RecordCount; if j > 0 then begin DM_CNT.Notas.First; for i := 1 to j do begin case DM_CNT.NotasTipo.AsInteger of 0: begin // Nota Fiscal {$IFDEF PL_200} with infCTeNorm.infDoc.infNF.Add do {$ELSE} with Rem.InfNF.Add do {$ENDIF} begin nRoma := DM_CNT.NotasRomaneioNF.AsString; nPed := DM_CNT.NotasPedidoNF.AsString; Modelo := moNF011AAvulsa; serie := DM_CNT.NotasSerieNF.AsString; nDoc := DM_CNT.NotasNumeroNF.AsString; dEmi := DM_CNT.NotasEmissaoNF.AsDateTime; vBC := RoundTo(DM_CNT.NotasValorBCICMS.AsFloat, -2); vICMS := RoundTo(DM_CNT.NotasValorICMS.AsFloat, -2); vBCST := RoundTo(DM_CNT.NotasValorBCICMSST.AsFloat, -2); vST := RoundTo(DM_CNT.NotasValorICMSST.AsFloat, -2); vProd := RoundTo(DM_CNT.NotasValorProdutos.AsFloat, -2); vNF := RoundTo(DM_CNT.NotasValorNF.AsFloat, -2); nCFOP := DM_CNT.NotasCFOPNF.AsInteger; nPeso := RoundTo(DM_CNT.NotasPesoKg.AsFloat, -2); PIN := DM_CNT.NotasPinSuframa.AsString; {$IFNDEF PL_200} // Local de Retirada

if trim(DM_CNT.NotasCNPJRet.AsString) <> '' then begin DM_CTA.PessoaFJ.Close; DM_CTA.PessoaFJ.SQL.Clear; DM_CTA.PessoaFJ.SQL.Add('Select * From Sis_PessoaFJ'); DM_CTA.PessoaFJ.SQL.Add('Where CGC = :xCGC'); DM_CTA.PessoaFJ.Params[0].AsString := DM_CNT.NotasCNPJRet.AsSt ring; DM_CTA.PessoaFJ.Active := True; DM_CTA.PessoaFJ.Open; if copy(DM_CTA.PessoaFJCGC.AsString,10,4) <> '0000' then locRet.CNPJCPF := Copy(DM_CTA.PessoaFJCGC.AsString, 2, 1 4) else locRet.CNPJCPF := Copy(DM_CTA.PessoaFJCGC.AsString, 1, 9 ) + Copy(DM_CTA.PessoaFJCGC.AsString, 14, 2); locRet.xNome locRet.xLgr locRet.nro locRet.xCpl locRet.xBairro CodigoMunicipio 000 + DM_CTA.PessoaFJCodigoMunicipio.AsInteger; locRet.cMun := CodigoMunicipio; locRet.xMun := DM_CTA.PessoaFJCidade.AsString; locRet.UF := DM_CTA.PessoaFJEstado.AsString; end; {$ENDIF} end; end; 1: begin // Nota Fiscal Eletrnica {$IFDEF PL_200} with infCTeNorm.infDoc.infNFe.Add do {$ELSE} with Rem.InfNFe.Add do {$ENDIF} begin chave := DM_CNT.NotasChaveNFe.AsString; PIN := DM_CNT.NotasPinSuframa.AsString; end; end; 2: begin // Outros Tipos de Documentos {$IFDEF PL_200} with infCTeNorm.infDoc.infOutros.Add do {$ELSE} with Rem.InfOutros.Add do {$ENDIF} begin if DM_CNT.NotasTipoOutros.AsInteger = 0 then tpDoc := tdDeclaracao else begin tpDoc := tdOutros; descOutros := DM_CNT.NotasDescricao.AsString; end; := := := := := := DM_CTA.PessoaFJRSocial.AsString; DM_CTA.PessoaFJEndereco.AsString; DM_CTA.PessoaFJNumero.AsString; DM_CTA.PessoaFJComplemento.AsString; DM_CTA.PessoaFJBairro.AsString; DM_CTA.PessoaFJCodigoEstado.AsInteger * 100

nDoc := DM_CNT.NotasNumeroNF.AsString; dEmi := DM_CNT.NotasEmissaoNF.AsDateTime; vDocFisc := RoundTo(DM_CNT.NotasValorNF.AsFloat, -2); end; end; end; DM_CNT.Notas.Next; end; end; end; // // Dados do Destinatario // if trim(DM_CNT.ConhecimentoDestinatario.AsString) <> '' then begin DM_CTA.PessoaFJ.Close; DM_CTA.PessoaFJ.SQL.Clear; DM_CTA.PessoaFJ.SQL.Add('Select * From Sis_PessoaFJ'); DM_CTA.PessoaFJ.SQL.Add('Where CGC = :xCGC'); DM_CTA.PessoaFJ.Params[0].AsString := DM_CNT.ConhecimentoDestinatario.AsStr ing; DM_CTA.PessoaFJ.Active := True; DM_CTA.PessoaFJ.Open; DM_CTA.PessoaFJE.Close; DM_CTA.PessoaFJE.SQL.Clear; DM_CTA.PessoaFJE.SQL.Add('Select * From Sis_PessoaFJEmail'); DM_CTA.PessoaFJE.SQL.Add('Where CNPJ = :xCNPJ'); DM_CTA.PessoaFJE.SQL.Add('and Modulo = :xModulo'); DM_CTA.PessoaFJE.Params[0].AsString := DM_CTA.PessoaFJCGC.AsString; DM_CTA.PessoaFJE.Params[1].AsString := 'DFE'; DM_CTA.PessoaFJE.Active := True; DM_CTA.PessoaFJE.Open; if (DM_CTA.PessoaFJECNPJ.AsString = DM_CTA.PessoaFJCGC.AsString) and (DM_CTA.PessoaFJEModulo.AsString = 'DFE') then Dest.email := Trim(DM_CTA.PessoaFJEEmail.AsString) else Dest.email := ''; Dest.xNome Dest.EnderDest.xLgr Dest.EnderDest.nro Dest.EnderDest.xCpl Dest.EnderDest.xBairro CodigoMunicipio Dest.EnderDest.cMun Dest.EnderDest.xMun Dest.EnderDest.CEP Dest.EnderDest.UF Dest.EnderDest.cPais Dest.EnderDest.xPais := := := := := := := := := := := := DM_CTA.PessoaFJRSocial.AsString; DM_CTA.PessoaFJEndereco.AsString; DM_CTA.PessoaFJNumero.AsString; DM_CTA.PessoaFJComplemento.AsString; DM_CTA.PessoaFJBairro.AsString; DM_CTA.PessoaFJCodigoEstado.AsInteger * 100000 + DM_CTA.PessoaFJCodigoMunicipio.AsInteger; CodigoMunicipio; DM_CTA.PessoaFJCidade.AsString; StrToIntDef(DM_CTA.PessoaFJCEP.AsString, 0); DM_CTA.PessoaFJEstado.AsString; DM_CTA.PessoaFJCodigoPais.AsInteger; DM_CTA.PessoaFJPais.AsString;

if copy(DM_CTA.PessoaFJCGC.AsString,10,4) <> '0000' then begin Dest.CNPJCPF := Copy(DM_CTA.PessoaFJCGC.AsString, 2, 14); IE := DM_CTA.PessoaFJIEstadual.AsString; end else begin

Dest.CNPJCPF := Copy(DM_CTA.PessoaFJCGC.AsString, 1, 9) + Copy(DM_CTA.PessoaFJCGC.AsString, 14, 2); IE := 'ISENTO'; end; Dest.IE := IE; Dest.fone := DM_CTA.PessoaFJTelefone.AsString; Dest.ISUF := Trim(DM_CTA.PessoaFJInscSUF.AsString); // Local de Entrega if trim(DM_CNT.ConhecimentoCNPJEnt.AsString) <> '' then begin DM_CTA.PessoaFJ.Close; DM_CTA.PessoaFJ.SQL.Clear; DM_CTA.PessoaFJ.SQL.Add('Select * From Sis_PessoaFJ'); DM_CTA.PessoaFJ.SQL.Add('Where CGC = :xCGC'); DM_CTA.PessoaFJ.Params[0].AsString := DM_CNT.ConhecimentoCNPJEnt.AsString ; DM_CTA.PessoaFJ.Active := True; DM_CTA.PessoaFJ.Open; if copy(DM_CTA.PessoaFJCGC.AsString,10,4) <> '0000' then Dest.locEnt.CNPJCPF := Copy(DM_CTA.PessoaFJCGC.AsString, 2, 14) else Dest.locEnt.CNPJCPF := Copy(DM_CTA.PessoaFJCGC.AsString, 1, 9) + Copy(DM_CTA.PessoaFJCGC.AsString, 14, 2); Dest.locEnt.xNome Dest.locEnt.xLgr Dest.locEnt.nro Dest.locEnt.xCpl Dest.locEnt.xBairro CodigoMunicipio Dest.locEnt.cMun Dest.locEnt.xMun Dest.locEnt.UF end; end; := := := := := := DM_CTA.PessoaFJRSocial.AsString; DM_CTA.PessoaFJEndereco.AsString; DM_CTA.PessoaFJNumero.AsString; DM_CTA.PessoaFJComplemento.AsString; DM_CTA.PessoaFJBairro.AsString; DM_CTA.PessoaFJCodigoEstado.AsInteger * 100000 + DM_CTA.PessoaFJCodigoMunicipio.AsInteger; := CodigoMunicipio; := DM_CTA.PessoaFJCidade.AsString; := DM_CTA.PessoaFJEstado.AsString;

// // Dados do Expedidor // if trim(DM_CNT.ConhecimentoExpedidor.AsString) <> '' then begin DM_CTA.PessoaFJ.Close; DM_CTA.PessoaFJ.SQL.Clear; DM_CTA.PessoaFJ.SQL.Add('Select * From Sis_PessoaFJ'); DM_CTA.PessoaFJ.SQL.Add('Where CGC = :xCGC'); DM_CTA.PessoaFJ.Params[0].AsString := DM_CNT.ConhecimentoExpedidor.AsString ; DM_CTA.PessoaFJ.Active := True; DM_CTA.PessoaFJ.Open; DM_CTA.PessoaFJE.Close; DM_CTA.PessoaFJE.SQL.Clear; DM_CTA.PessoaFJE.SQL.Add('Select * From Sis_PessoaFJEmail'); DM_CTA.PessoaFJE.SQL.Add('Where CNPJ = :xCNPJ'); DM_CTA.PessoaFJE.SQL.Add('and Modulo = :xModulo'); DM_CTA.PessoaFJE.Params[0].AsString := DM_CTA.PessoaFJCGC.AsString; DM_CTA.PessoaFJE.Params[1].AsString := 'DFE';

DM_CTA.PessoaFJE.Active := True; DM_CTA.PessoaFJE.Open; if (DM_CTA.PessoaFJECNPJ.AsString = DM_CTA.PessoaFJCGC.AsString) and (DM_CTA.PessoaFJEModulo.AsString = 'DFE') then Exped.email := Trim(DM_CTA.PessoaFJEEmail.AsString) else Exped.email := ''; Exped.xNome Exped.EnderExped.xLgr Exped.EnderExped.nro Exped.EnderExped.xCpl Exped.EnderExped.xBairro CodigoMunicipio + Exped.EnderExped.cMun Exped.EnderExped.xMun Exped.EnderExped.CEP Exped.EnderExped.UF Exped.EnderExped.cPais Exped.EnderExped.xPais := := := := := := DM_CTA.PessoaFJCodigoMunicipio.AsInteger; CodigoMunicipio; DM_CTA.PessoaFJCidade.AsString; StrToIntDef(DM_CTA.PessoaFJCEP.AsString, 0); DM_CTA.PessoaFJEstado.AsString; DM_CTA.PessoaFJCodigoPais.AsInteger; DM_CTA.PessoaFJPais.AsString; := := := := := := DM_CTA.PessoaFJRSocial.AsString; DM_CTA.PessoaFJEndereco.AsString; DM_CTA.PessoaFJNumero.AsString; DM_CTA.PessoaFJComplemento.AsString; DM_CTA.PessoaFJBairro.AsString; DM_CTA.PessoaFJCodigoEstado.AsInteger * 100000

if copy(DM_CTA.PessoaFJCGC.AsString,10,4) <> '0000' then begin Exped.CNPJCPF := Copy(DM_CTA.PessoaFJCGC.AsString, 2, 14); IE := DM_CTA.PessoaFJIEstadual.AsString; end else begin Exped.CNPJCPF := Copy(DM_CTA.PessoaFJCGC.AsString, 1, 9) + Copy(DM_CTA.PessoaFJCGC.AsString, 14, 2); IE := 'ISENTO'; end; Exped.IE := IE; Exped.fone := DM_CTA.PessoaFJTelefone.AsString; end; // // Dados do Recebedor // if trim(DM_CNT.ConhecimentoExpedidor.AsString) <> '' then begin DM_CTA.PessoaFJ.Close; DM_CTA.PessoaFJ.SQL.Clear; DM_CTA.PessoaFJ.SQL.Add('Select * From Sis_PessoaFJ'); DM_CTA.PessoaFJ.SQL.Add('Where CGC = :xCGC'); DM_CTA.PessoaFJ.Params[0].AsString := DM_CNT.ConhecimentoExpedidor.AsString ; DM_CTA.PessoaFJ.Active := True; DM_CTA.PessoaFJ.Open; DM_CTA.PessoaFJE.Close; DM_CTA.PessoaFJE.SQL.Clear; DM_CTA.PessoaFJE.SQL.Add('Select * From Sis_PessoaFJEmail'); DM_CTA.PessoaFJE.SQL.Add('Where CNPJ = :xCNPJ'); DM_CTA.PessoaFJE.SQL.Add('and Modulo = :xModulo'); DM_CTA.PessoaFJE.Params[0].AsString := DM_CTA.PessoaFJCGC.AsString; DM_CTA.PessoaFJE.Params[1].AsString := 'DFE'; DM_CTA.PessoaFJE.Active := True;

DM_CTA.PessoaFJE.Open; if (DM_CTA.PessoaFJECNPJ.AsString = DM_CTA.PessoaFJCGC.AsString) and (DM_CTA.PessoaFJEModulo.AsString = 'DFE') then Receb.email := Trim(DM_CTA.PessoaFJEEmail.AsString) else Receb.email := ''; Receb.xNome Receb.EnderReceb.xLgr Receb.EnderReceb.nro Receb.EnderReceb.xCpl Receb.EnderReceb.xBairro CodigoMunicipio + Receb.EnderReceb.cMun Receb.EnderReceb.xMun Receb.EnderReceb.CEP Receb.EnderReceb.UF Receb.EnderReceb.cPais Receb.EnderReceb.xPais := := := := := := DM_CTA.PessoaFJCodigoMunicipio.AsInteger; CodigoMunicipio; DM_CTA.PessoaFJCidade.AsString; StrToIntDef(DM_CTA.PessoaFJCEP.AsString, 0); DM_CTA.PessoaFJEstado.AsString; DM_CTA.PessoaFJCodigoPais.AsInteger; DM_CTA.PessoaFJPais.AsString; := := := := := := DM_CTA.PessoaFJRSocial.AsString; DM_CTA.PessoaFJEndereco.AsString; DM_CTA.PessoaFJNumero.AsString; DM_CTA.PessoaFJComplemento.AsString; DM_CTA.PessoaFJBairro.AsString; DM_CTA.PessoaFJCodigoEstado.AsInteger * 100000

if copy(DM_CTA.PessoaFJCGC.AsString,10,4) <> '0000' then begin Receb.CNPJCPF := Copy(DM_CTA.PessoaFJCGC.AsString, 2, 14); IE := DM_CTA.PessoaFJIEstadual.AsString; end else begin Receb.CNPJCPF := Copy(DM_CTA.PessoaFJCGC.AsString, 1, 9) + Copy(DM_CTA.PessoaFJCGC.AsString, 14, 2); IE := 'ISENTO'; end; Receb.IE := IE; Receb.fone := DM_CTA.PessoaFJTelefone.AsString; end; // // Valores da Prestao de Servio // vPrest.vTPrest := RoundTo(DM_CNT.ConhecimentoValorTotal.AsFloat, -2); vPrest.vRec := RoundTo(DM_CNT.ConhecimentoValorTotal.AsFloat, -2); // // Relao dos Componentes da Prestao de Servio // DM_CNT.Componentes.Close; DM_CNT.Componentes.SQL.Clear; DM_CNT.Componentes.SQL.Add('Select * From Cnt_Componentes'); DM_CNT.Componentes.SQL.Add('Where Codigo = :xCodigo'); DM_CNT.Componentes.SQL.Add('and Serie = :xSerie'); DM_CNT.Componentes.SQL.Add('and Numero = :xNumero'); DM_CNT.Componentes.SQL.Add('and Complemento <> :xComplemento'); DM_CNT.Componentes.SQL.Add('Order By Item'); DM_CNT.Componentes.Params[0].AsInteger := DM_CNT.ConhecimentoCodigo.AsInteger ; DM_CNT.Componentes.Params[1].AsInteger := DM_CNT.ConhecimentoSerie.AsInteger; DM_CNT.Componentes.Params[2].AsInteger := DM_CNT.ConhecimentoNumero.AsInteger ; DM_CNT.Componentes.Params[3].AsString := 'S';

DM_CNT.Componentes.Active := True; DM_CNT.Componentes.Open; DM_CNT.Componentes.Last; j := DM_CNT.Componentes.RecordCount; if j > 0 then begin DM_CNT.Componentes.First; for i := 1 to j do begin if DM_CNT.ComponentesValor.AsFloat > 0.0 then begin with vPrest.comp.Add do begin xNome := DM_CNT.ComponentesDescricao.AsString; vComp := RoundTo(DM_CNT.ComponentesValor.AsFloat, -2); end; end; DM_CNT.Componentes.Next; end; end; // // Valores dos Impostos // // TpcnCSTIcms = (cst00, cst10, cst20, cst30, cst40, cst41, cst45, cst50, cst 51, // // penas para CTe cst60, cst70, cst80, cst81, cst90, cstPart10, cstPart90, cstRep41, cstVazio, cstICMSOutraUF, cstICMSSN); //80 e 81 a

case DM_CNT.ConhecimentoCSTICMS.AsInteger of 00: begin Imp.ICMS.SituTrib := cst00; Imp.ICMS.ICMS00.CST := cst00; // Tributao Normal ICMS Imp.ICMS.ICMS00.vBC := RoundTo(DM_CNT.ConhecimentoBaseCalc.AsFloat, -2 ); Imp.ICMS.ICMS00.pICMS := RoundTo(DM_CNT.ConhecimentoAliqICMS.AsFloat, -2 ); Imp.ICMS.ICMS00.vICMS := RoundTo(DM_CNT.ConhecimentoValorICMS.AsFloat, 2); end; 20: begin Imp.ICMS.SituTrib := cst20; Imp.ICMS.ICMS20.CST := cst20; // Tributao com BC reduzida do ICMS Imp.ICMS.ICMS20.pRedBC := RoundTo(DM_CNT.ConhecimentoReducaoICMS.AsFloat , -2); Imp.ICMS.ICMS20.vBC := RoundTo(DM_CNT.ConhecimentoBaseCalc.AsFloat, 2); Imp.ICMS.ICMS20.pICMS := RoundTo(DM_CNT.ConhecimentoAliqICMS.AsFloat, 2); Imp.ICMS.ICMS20.vICMS := RoundTo(DM_CNT.ConhecimentoValorICMS.AsFloat, -2); end; 40: begin Imp.ICMS.SituTrib := cst40; Imp.ICMS.ICMS45.CST := cst40; // ICMS Isento end; 41: begin Imp.ICMS.SituTrib := cst41; Imp.ICMS.ICMS45.CST := cst41; // ICMS no Tributada

end; 51: begin Imp.ICMS.SituTrib := cst51; Imp.ICMS.ICMS45.CST := cst51; // ICMS diferido end; 60: begin Imp.ICMS.SituTrib := cst60; Imp.ICMS.ICMS60.CST := cst60; // Tributao atribuida ao tomador ou 3 . por ST Imp.ICMS.ICMS60.vBCSTRet := RoundTo(DM_CNT.ConhecimentoBaseCalc.AsFloa t, -2); Imp.ICMS.ICMS60.pICMSSTRet := RoundTo(DM_CNT.ConhecimentoAliqICMS.AsFloa t, -2); Imp.ICMS.ICMS60.vICMSSTRet := RoundTo(DM_CNT.ConhecimentoValorICMS.AsFlo at, -2); Imp.ICMS.ICMS60.vCred := RoundTo(DM_CNT.ConhecimentoCreditoICMS.AsF loat, -2); end; 90: begin Imp.ICMS.SituTrib := cst90; Imp.ICMS.ICMS90.CST := cst90; // ICMS Outros Imp.ICMS.ICMS90.pRedBC := RoundTo(DM_CNT.ConhecimentoReducaoICMS.AsFloat , -2); Imp.ICMS.ICMS90.vBC := RoundTo(DM_CNT.ConhecimentoBaseCalc.AsFloat, 2); Imp.ICMS.ICMS90.pICMS := RoundTo(DM_CNT.ConhecimentoAliqICMS.AsFloat, 2); Imp.ICMS.ICMS90.vICMS := RoundTo(DM_CNT.ConhecimentoValorICMS.AsFloat, -2); Imp.ICMS.ICMS90.vCred := RoundTo(DM_CNT.ConhecimentoCreditoICMS.AsFloat , -2); end; end; // Valor Total dos Tributos imp.vTotTrib := RoundTo(DM_CNT.ConhecimentovTotTrib.AsFloat, -2); // Obs do Contribuinte if (imp.vTotTrib <> 0.0) then begin with compl.ObsCont.Add do begin xCampo := 'Lei da Transparencia'; xTexto := 'O valor aproximado de tributos incidentes sobre o preo deste se rvico e de R$ ' + FormatFloat('##0.00', imp.vTotTrib) + ' (' + FormatFloat('#0.00', DM_CNT.ConhecimentoAliqNBS.AsFloat) + '%) ' + 'Fonte: IBPT'; end; end; case DM_CNT.ConhecimentoTipoCTe.AsInteger of 0,3: begin // // Informaes do Detalhamento do CTe Normal // // // Informaes da Carga //

{$IFDEF PL_200} infCTeNorm.infCarga.vCarga := RoundTo(DM_CNT.ConhecimentoValorTotalNF .AsFloat, -2); infCTeNorm.infCarga.proPred := DM_CNT.ConhecimentoEspecie.AsString; infCTeNorm.infCarga.xOutCat := DM_CNT.ConhecimentoNatureza.AsString; // UnidMed = (uM3,uKG, uTON, uUNIDADE, uLITROS); with infCTeNorm.infCarga.InfQ.Add do begin cUnid := uKg; tpMed := 'Kg'; qCarga := RoundTo(DM_CNT.ConhecimentoPesoTotal.AsFloat, -2); end; with infCTeNorm.infCarga.InfQ.Add do begin cUnid := uUnidade; tpMed := DM_CNT.ConhecimentoNatureza.AsString; qCarga := RoundTo(DM_CNT.ConhecimentoVolume.AsFloat, -2); end; {$ELSE} infCarga.vCarga := RoundTo(DM_CNT.ConhecimentoValorTotalNF.AsFloat, 2); infCarga.proPred := DM_CNT.ConhecimentoEspecie.AsString; infCarga.xOutCat := DM_CNT.ConhecimentoNatureza.AsString; // UnidMed = (uM3,uKG, uTON, uUNIDADE, uLITROS); with infCarga.InfQ.Add do begin cUnid := uKg; tpMed := 'Kg'; qCarga := RoundTo(DM_CNT.ConhecimentoPesoTotal.AsFloat, -2); end; with infCarga.InfQ.Add do begin cUnid := uUnidade; tpMed := DM_CNT.ConhecimentoNatureza.AsString; qCarga := RoundTo(DM_CNT.ConhecimentoVolume.AsFloat, -2); end; {$ENDIF} // // Informaes dos Containers // // // Informaes de Documentos de Transporte Anterior // // TpcteTipoServico = (tsNormal, tsSubcontratacao, tsRedespacho, tsInt ermediario); if ide.tpServ <> tsNormal then begin {$IFDEF PL_200} with infCTeNorm.docAnt.emiDocAnt.Add do {$ELSE} with infCTeNorm.emiDocAnt.Add do {$ENDIF} begin // Dados do Emissor do Documento Anterior CNPJCPF := Exped.CNPJCPF; IE := Exped.IE; UF := Exped.EnderExped.UF; xNome := Exped.xNome;

with idDocAnt.Add do begin // // Relao de Documentos Anteriores // DM_CNT.Notas.Close; DM_CNT.Notas.SQL.Clear; DM_CNT.Notas.SQL.Add('Select * From Cnt_Notas'); DM_CNT.Notas.SQL.Add('Where Codigo = :xCodigo'); DM_CNT.Notas.SQL.Add('and Serie = :xSerie'); DM_CNT.Notas.SQL.Add('and Numero = :xNumero'); DM_CNT.Notas.SQL.Add('Order By Tipo'); DM_CNT.Notas.Params[0].AsInteger := DM_CNT.ConhecimentoCodigo.As Integer; DM_CNT.Notas.Params[1].AsInteger := DM_CNT.ConhecimentoSerie.AsI nteger; DM_CNT.Notas.Params[2].AsInteger := DM_CNT.ConhecimentoNumero.As Integer; DM_CNT.Notas.Active := True; DM_CNT.Notas.Open; DM_CNT.Notas.Last; j := DM_CNT.Notas.RecordCount; if j > 0 then begin DM_CNT.Notas.First; for i := 1 to j do begin case DM_CNT.NotasTipo.AsInteger of 3: begin // Documentos Anteriores de Papel with idDocAntPap.Add do begin // TpcteTipoDocumentoAnterior = (daCTRC, daCTAC, daAC T, daNF7, daNF27, daCAN, daCTMC, daATRE, daDTA, daCAI, daCCPI, daCA, daTIF, daOu tros); case DM_CNT.NotasModelo.AsInteger of 00: tpDoc := daCTRC; 01: tpDoc := daCTAC; 02: tpDoc := daACT; 03: tpDoc := daNF7; 04: tpDoc := daNF27; 05: tpDoc := daCAN; 06: tpDoc := daCTMC; 07: tpDoc := daATRE; 08: tpDoc := daDTA; 09: tpDoc := daCAI; 10: tpDoc := daCCPI; 11: tpDoc := daCA; 12: tpDoc := daTIF; 99: tpDoc := daOutros; end; serie := DM_CNT.NotasSerieNF.AsString; subser := DM_CNT.NotasSubSerie.AsString; nDoc := DM_CNT.NotasNumeroNF.AsInteger; dEmi := DM_CNT.NotasEmissaoNF.AsDateTime; end; end; 4: begin // Documentos Anteriores Eletrnico with idDocAntEle.Add do

begin chave := DM_CNT.NotasChaveNFe.AsString; end; end; end; DM_CNT.Notas.Next; end; end; end; end; end; // // Informaes da Seguradora // {$IFDEF PL_200} with infCTeNorm.seg.Add do {$ELSE} with infseg.Add do {$ENDIF} begin case DM_CNT.ConhecimentoRespSeguro.AsInteger of 0: respSeg := rsRemetente; 1: respSeg := rsExpedidor; 2: respSeg := rsRecebedor; 3: respSeg := rsDestinatario; 4: respSeg := rsEmitenteCTe; 5: respSeg := rsTomadorServico; end; if trim(DM_CTA.ParamDFeSeguradora.AsString) <> '' then begin DM_CTA.PessoaFJ.Close; DM_CTA.PessoaFJ.SQL.Clear; DM_CTA.PessoaFJ.SQL.Add('Select * From Sis_PessoaFJ'); DM_CTA.PessoaFJ.SQL.Add('Where CGC = :xCGC'); DM_CTA.PessoaFJ.Params[0].AsString := DM_CTA.ParamDFeSeguradora.As String; DM_CTA.PessoaFJ.Active := True; DM_CTA.PessoaFJ.Open; xSeg := Copy(trim(DM_CTA.PessoaFJRSocial.AsString), 1, 30); end; nApol := Copy(trim(DM_CTA.ParamDFeNumApolice.AsString), 1, 20); nAver := DM_CTA.ParamDFeNumAverbacao.AsString; end; // // Dados do Modal Rodovirio // {$IFDEF PL_200} infCTeNorm.rodo.RNTRC := DM_CTA.ParamDFeRNTRC.AsString; infCTeNorm.Rodo.dPrev := (DM_CNT.ConhecimentoData.AsDateTime+1); // TpcteLotacao = (ltNao, ltSim); case DM_CNT.ConhecimentoLotacao.AsInteger of 0: infCTeNorm.Rodo.Lota := ltNao; 1: infCTeNorm.Rodo.Lota := ltSim; end; infCTeNorm.Rodo.CIOT := Trim(DM_CTA.ParamDFeCIOT.AsString); {$ELSE} Rodo.RNTRC := DM_CTA.ParamDFeRNTRC.AsString; Rodo.dPrev := (DM_CNT.ConhecimentoData.AsDateTime+1);

// TpcteLotacao = (ltNao, ltSim); case DM_CNT.ConhecimentoLotacao.AsInteger of 0: Rodo.Lota := ltNao; 1: Rodo.Lota := ltSim; end; Rodo.CIOT := Trim(DM_CTA.ParamDFeCIOT.AsString); {$ENDIF} // // Ordem de Coleta Associados (OCC) //

// // Lacres //

if DM_CNT.ConhecimentoLotacao.AsInteger = 1 // Lotao then begin // // Informaes do Vale Pedgio // // // Dados dos Veculos // DM_CNT.LotaVeic.Close; DM_CNT.LotaVeic.SQL.Clear; DM_CNT.LotaVeic.SQL.Add('Select * From Cnt_LotaVeic'); DM_CNT.LotaVeic.SQL.Add('Where Codigo = :xCodigo'); DM_CNT.LotaVeic.SQL.Add('and Serie = :xSerie'); DM_CNT.LotaVeic.SQL.Add('and Numero = :xNumero'); DM_CNT.LotaVeic.SQL.Add('Order By Item'); DM_CNT.LotaVeic.Params[0].AsInteger := DM_CNT.ConhecimentoCodigo.AsI nteger; DM_CNT.LotaVeic.Params[1].AsInteger := DM_CNT.ConhecimentoSerie.AsIn teger; DM_CNT.LotaVeic.Params[2].AsInteger := DM_CNT.ConhecimentoNumero.AsI nteger; DM_CNT.LotaVeic.Active := True; DM_CNT.LotaVeic.Open; DM_CNT.LotaVeic.Last; j := DM_CNT.LotaVeic.RecordCount; if j > 0 then begin DM_CNT.LotaVeic.First; for i := 1 to j do begin {$IFDEF PL_200} with infCTeNorm.rodo.veic.Add do {$ELSE} with rodo.veic.Add do {$ENDIF} begin DM_CNT.Frota.Close; DM_CNT.Frota.SQL.Clear; DM_CNT.Frota.SQL.Add('Select * From Cnt_Frota');

DM_CNT.Frota.SQL.Add('Where Codigo = :xCodigo'); DM_CNT.Frota.Params[0].AsInteger:=DM_CNT.LotaVeicVeiculo.AsInt eger; DM_CNT.Frota.Active:=True; DM_CNT.Frota.Open; cInt RENAVAM placa tara capKg capM3 := := := := := := IntToStr(DM_CNT.LotaVeicVeiculo.AsInteger); DM_CNT.FrotaRENAVAM.AsString; DM_CNT.FrotaPlaca.AsString; DM_CNT.FrotaTara.AsInteger; DM_CNT.FrotaCapKg.AsInteger; DM_CNT.FrotaCapM3.AsInteger;

// TpcteTipoVeiculo = (tvTracao, tvReboque); case DM_CNT.FrotaTipo.AsInteger of 0: tpVeic := tvTracao; 1: tpVeic := tvReboque; end; // TpcteTipoRodado = (trNaoAplicavel, trTruck, trToco, trCaval oMecanico, trVAN, trUtilitario, trOutros); case DM_CNT.FrotaTipoRodado.AsInteger of 0: tpRod := trNaoAplicavel; 1: tpRod := trTruck; 2: tpRod := trToco; 3: tpRod := trCavaloMecanico; 4: tpRod := trVAN; 5: tpRod := trUtilitario; 6: tpRod := trOutros; end; // TpcteTipoCarroceria = (tcNaoAplicavel, tcAberta, tcFechada, tcGraneleira, tcPortaContainer, tcSider); case DM_CNT.FrotaTipoCarroceria.AsInteger of 0: tpCar := tcNaoAplicavel; 1: tpCar := tcAberta; 2: tpCar := tcFechada; 3: tpCar := tcGraneleira; 4: tpCar := tcPortaContainer; 5: tpCar := tcSider; end; UF := DM_CNT.FrotaUF.AsString; // TpcteTipoPropriedade = (tpProprio, tpTerceiro); if DM_CNT.FrotaProprietario.AsString = 'S' then tpProp := tpProprio else begin tpProp := tpTerceiro; DM_CTA.PessoaFJ.Close; DM_CTA.PessoaFJ.SQL.Clear; DM_CTA.PessoaFJ.SQL.Add('Select * From Sis_PessoaFJ'); DM_CTA.PessoaFJ.SQL.Add('Where CGC = :xCGC'); DM_CTA.PessoaFJ.Params[0].AsString:=DM_CNT.FrotaCNPJProp.AsS tring; DM_CTA.PessoaFJ.Active:=True; DM_CTA.PessoaFJ.Open; if copy(DM_CNT.FrotaCNPJProp.AsString,10,4) <> '0000'

then begin prop.CNPJCPF := Copy(DM_CNT.FrotaCNPJProp.AsString, 2, 14) ; prop.IE := DM_CTA.PessoaFJIEstadual.AsString; end else begin prop.CNPJCPF := Copy(DM_CNT.FrotaCNPJProp.AsString, 1, 9) + Copy(DM_CNT.FrotaCNPJProp.AsString, 14, 2) ; prop.IE end; prop.RNTRC prop.xNome prop.UF := 'ISENTO'; := DM_CNT.FrotaRNTRC.AsString; := DM_CTA.PessoaFJRSocial.AsString; := DM_CTA.PessoaFJEstado.AsString;

// TpcteProp = (tpTACAgregado, tpTACIndependente, tpOutros); case DM_CNT.FrotaTipoProp.AsInteger of 0: prop.tpProp := tpTACAgregado; 1: prop.tpProp := tpTACIndependente; 2: prop.tpProp := tpOutros; end; end; end; DM_CNT.LotaVeic.Next; end; end; // // Informaes do(s) Motorista(s) // DM_CNT.LotaMoto.Close; DM_CNT.LotaMoto.SQL.Clear; DM_CNT.LotaMoto.SQL.Add('Select * From Cnt_LotaMoto'); DM_CNT.LotaMoto.SQL.Add('Where Codigo = :xCodigo'); DM_CNT.LotaMoto.SQL.Add('and Serie = :xSerie'); DM_CNT.LotaMoto.SQL.Add('and Numero = :xNumero'); DM_CNT.LotaMoto.SQL.Add('Order By Item'); DM_CNT.LotaMoto.Params[0].AsInteger := DM_CNT.ConhecimentoCodigo.AsI DM_CNT.LotaMoto.Params[1].AsInteger := DM_CNT.ConhecimentoSerie.AsIn teger; DM_CNT.LotaMoto.Params[2].AsInteger := DM_CNT.ConhecimentoNumero.AsI nteger; DM_CNT.LotaMoto.Active := True; DM_CNT.LotaMoto.Open; DM_CNT.LotaMoto.Last; j := DM_CNT.LotaMoto.RecordCount; if j > 0 then begin DM_CNT.LotaMoto.First; for i := 1 to j do begin {$IFDEF PL_200} with infCTeNorm.rodo.moto.Add do {$ELSE} with rodo.moto.Add do {$ENDIF} begin

// nteger;

DM_CNT.Condutores.Close; DM_CNT.Condutores.SQL.Clear; DM_CNT.Condutores.SQL.Add('Select * From Cnt_Condutores'); DM_CNT.Condutores.SQL.Add('Where CPF = :xCPF'); DM_CNT.Condutores.Params[0].AsString:=DM_CNT.LotaMotoCPF.AsStr ing; DM_CNT.Condutores.Active:=True; DM_CNT.Condutores.Open; xNome := DM_CNT.CondutoresNome.AsString; CPF := DM_CNT.CondutoresCPF.AsString; end; DM_CNT.LotaMoto.Next; end; end; end; // // Informaes sobre os produtos Perigosos // DM_CNT.Produtos.Close; DM_CNT.Produtos.SQL.Clear; DM_CNT.Produtos.SQL.Add('Select * From Cnt_Produtos'); DM_CNT.Produtos.SQL.Add('Where Codigo = :xCodigo'); DM_CNT.Produtos.SQL.Add('and Serie = :xSerie'); DM_CNT.Produtos.SQL.Add('and Numero = :xNumero'); DM_CNT.Produtos.SQL.Add('Order By Item'); DM_CNT.Produtos.Params[0].AsInteger := DM_CNT.ConhecimentoCodigo.AsInt eger; DM_CNT.Produtos.Params[1].AsInteger := DM_CNT.ConhecimentoSerie.AsInte ger; DM_CNT.Produtos.Params[2].AsInteger := DM_CNT.ConhecimentoNumero.AsInt eger; DM_CNT.Produtos.Active := True; DM_CNT.Produtos.Open; DM_CNT.Produtos.Last; j := DM_CNT.Produtos.RecordCount; if j > 0 then begin DM_CNT.Produtos.First; for i := 1 to j do begin {$IFDEF PL_200} with infCTeNorm.peri.Add do {$ELSE} with peri.Add do {$ENDIF} begin nONU := DM_CNT.ProdutosNumeroONU.AsString; xNomeAE := Trim(DM_CNT.ProdutosNome.AsString); xClaRisco := Trim(DM_CNT.ProdutosClasse.AsString); grEmb := Trim(DM_CNT.ProdutosGrupo.AsString); qTotProd := Trim(DM_CNT.ProdutosQtde.AsString); qVolTipo := Trim(DM_CNT.ProdutosVolumes.AsString); PontoFulgor := Trim(DM_CNT.ProdutosFulgor.AsString); end; DM_CNT.Produtos.Next; end; end;

// // Informaes sobre os veculos novos transportados // DM_CNT.Veiculos.Close; DM_CNT.Veiculos.SQL.Clear; DM_CNT.Veiculos.SQL.Add('Select * From Cnt_VeiculosNovos'); DM_CNT.Veiculos.SQL.Add('Where Codigo = :xCodigo'); DM_CNT.Veiculos.SQL.Add('and Serie = :xSerie'); DM_CNT.Veiculos.SQL.Add('and Numero = :xNumero'); DM_CNT.Veiculos.SQL.Add('Order By Item'); DM_CNT.Veiculos.Params[0].AsInteger := DM_CNT.ConhecimentoCodigo.AsInt eger; DM_CNT.Veiculos.Params[1].AsInteger := DM_CNT.ConhecimentoSerie.AsInte ger; DM_CNT.Veiculos.Params[2].AsInteger := DM_CNT.ConhecimentoNumero.AsInt eger; DM_CNT.Veiculos.Active := True; DM_CNT.Veiculos.Open; DM_CNT.Veiculos.Last; j := DM_CNT.Veiculos.RecordCount; if j > 0 then begin DM_CNT.Veiculos.First; for i := 1 to j do begin {$IFDEF PL_200} with infCTeNorm.veicNovos.Add do {$ELSE} with veicNovos.Add do {$ENDIF} begin chassi := DM_CNT.VeiculosChassi.AsString; cCor := Trim(DM_CNT.VeiculosCodigoCor.AsString); xCor := Trim(DM_CNT.VeiculosDescCor.AsString); cMod := Trim(DM_CNT.VeiculosModelo.AsString); vUnit := RoundTo(DM_CNT.VeiculosValor.AsFloat, -2); vFrete := RoundTo(DM_CNT.VeiculosFrete.AsFloat, -2); end; DM_CNT.Veiculos.Next; end; end; if DM_CNT.ConhecimentoTipoCTe.AsInteger = 3 then begin // // Informaes do Detalhamento do CTe Substituto // {$IFDEF PL_200} with infCTeNorm.infCteSub do {$ELSE} with infCTeSub do {$ENDIF} begin chCte := DM_CNT.ConhecimentoSubstituiCTe.AsString; if trim(DM_CNT.ConhecimentoNFeTomador.AsString) <> '' then tomaICMS.refNFe := DM_CNT.ConhecimentoNFeTomador.AsString else begin if DM_CNT.ConhecimentoNFNumero.AsInteger>0 then begin {$IFDEF PL_200}

tomaICMS.refNF.CNPJCPF {$ELSE} tomaICMS.refNF.CNPJ {$ENDIF} tomaICMS.refNF.modelo tomaICMS.refNF.serie ; ger; tomaICMS.refNF.nro r; tomaICMS.refNF.valor tomaICMS.refNF.dEmi ime;

:= DM_CNT.ConhecimentoNFCNPJ.AsString; := DM_CNT.ConhecimentoNFCNPJ.AsString; := DM_CNT.ConhecimentoNFMod.AsString; := DM_CNT.ConhecimentoNFSerie.AsInteger

tomaICMS.refNF.subserie := DM_CNT.ConhecimentoNFSubSerie.AsInte := DM_CNT.ConhecimentoNFNumero.AsIntege := DM_CNT.ConhecimentoNFValor.AsFloat; := DM_CNT.ConhecimentoNFEmissao.AsDateT

end else begin if trim(DM_CNT.ConhecimentoCTeTomador.AsString) <> '' then tomaICMS.refCte := DM_CNT.ConhecimentoCTeTomador.As String else tomaNaoICMS.refCteAnu := DM_CNT.ConhecimentoAnuladoCTe.As String; end; end; end; end; end; 1: begin // // Informaes do Detalhamento do CTe Complementado // DM_CNT.Complemento.Close; DM_CNT.Complemento.SQL.Clear; DM_CNT.Complemento.SQL.Add('Select * From Cnt_Complemento'); DM_CNT.Complemento.SQL.Add('Where Codigo = :xCodigo'); DM_CNT.Complemento.SQL.Add('and Serie = :xSerie'); DM_CNT.Complemento.SQL.Add('and Numero = :xNumero'); DM_CNT.Complemento.SQL.Add('Order By Item'); DM_CNT.Complemento.Params[0].AsInteger := DM_CNT.ConhecimentoCodigo.As Integer; DM_CNT.Complemento.Params[1].AsInteger := DM_CNT.ConhecimentoSerie.AsI nteger; DM_CNT.Complemento.Params[2].AsInteger := DM_CNT.ConhecimentoNumero.As Integer; DM_CNT.Complemento.Active := True; DM_CNT.Complemento.Open; DM_CNT.Complemento.Last; j := DM_CNT.Complemento.RecordCount; if j > 0 then begin DM_CNT.Complemento.First; for i := 1 to j do begin if DM_CNT.ComplementoValorTotal.AsFloat > 0.0 then begin {$IFDEF PL_200} with infCTeComp do // 1-1 {$ELSE} with infCTeComp.Add do // 1-10 {$ENDIF}

begin chave := DM_CNT.ComplementoCTe.AsString; vPresComp.vTPrest := RoundTo(DM_CNT.ComplementoValorTotal.AsFl oat, -2); // // Informaes dos Componentes Complementados // DM_CNT.Componentes.Close; DM_CNT.Componentes.SQL.Clear; DM_CNT.Componentes.SQL.Add('Select * From Cnt_Componentes'); DM_CNT.Componentes.SQL.Add('Where Codigo = :xCodigo'); DM_CNT.Componentes.SQL.Add('and Serie = :xSerie'); DM_CNT.Componentes.SQL.Add('and Numero = :xNumero'); DM_CNT.Componentes.SQL.Add('and Complemento = :xComplemento'); DM_CNT.Componentes.SQL.Add('Order By Item'); DM_CNT.Componentes.Params[0].AsInteger := DM_CNT.ConhecimentoC odigo.AsInteger; DM_CNT.Componentes.Params[1].AsInteger := DM_CNT.ConhecimentoS erie.AsInteger; DM_CNT.Componentes.Params[2].AsInteger := DM_CNT.ConhecimentoN umero.AsInteger; DM_CNT.Componentes.Params[3].AsString := 'S'; DM_CNT.Componentes.Active := True; DM_CNT.Componentes.Open; DM_CNT.Componentes.Last; l := DM_CNT.Componentes.RecordCount; if l > 0 then begin DM_CNT.Componentes.First; for k := 1 to l do begin if DM_CNT.ComponentesValor.AsFloat > 0.0 then begin with vPresComp.compComp.Add do begin xNome := DM_CNT.ComponentesDescricao.AsString; vComp := RoundTo(DM_CNT.ComponentesValor.AsFloat, -2); end; end; DM_CNT.Componentes.Next; end; end; // // Informaes relativas ao Impostos Complementados // // TpcnCSTIcms = (cst00, cst10, cst20, cst30, cst40, cst41, cs t45, cst50, cst51, cst60, cst70, cst80, cst81, cst90); // 80 e 81 apenas para CTe case DM_CNT.ComplementoCST.AsInteger of 00: begin ImpComp.ICMSComp.SituTrib := cst00; ImpComp.ICMSComp.ICMS00.CST := cst00; // Tributao Normal ICMS ImpComp.ICMSComp.ICMS00.vBC := RoundTo(DM_CNT.Complemen toBC.AsFloat, -2); ImpComp.ICMSComp.ICMS00.pICMS := RoundTo(DM_CNT.Complemen toAliq.AsFloat, -2); ImpComp.ICMSComp.ICMS00.vICMS := RoundTo(DM_CNT.Complemen toValorICMS.AsFloat, -2); end;

20: begin ImpComp.ICMSComp.SituTrib ImpComp.ICMSComp.ICMS20.CST reduzida do ICMS

:= cst20; := cst20; // Tributao com BC

ImpComp.ICMSComp.ICMS20.pRedBC := RoundTo(DM_CNT.Compleme ntoReducao.AsFloat, -2); ImpComp.ICMSComp.ICMS20.vBC := RoundTo(DM_CNT.Compleme ntoBC.AsFloat, -2); ImpComp.ICMSComp.ICMS20.pICMS := RoundTo(DM_CNT.Compleme ntoAliq.AsFloat, -2); ImpComp.ICMSComp.ICMS20.vICMS := RoundTo(DM_CNT.Compleme ntoValorICMS.AsFloat, -2); end; 40: begin ImpComp.ICMSComp.SituTrib := cst40; ImpComp.ICMSComp.ICMS45.CST := cst40; // ICMS Isento end; 41: begin ImpComp.ICMSComp.SituTrib := cst41; ImpComp.ICMSComp.ICMS45.CST := cst41; // ICMS no Tributada end; 51: begin ImpComp.ICMSComp.SituTrib := cst51; ImpComp.ICMSComp.ICMS45.CST := cst51; // ICMS diferido end; 60: begin ImpComp.ICMSComp.SituTrib := cst60; ImpComp.ICMSComp.ICMS60.CST := cst60; // Tributao at ribuida ao tomador ou 3. por ST ImpComp.ICMSComp.ICMS60.vBCSTRet := RoundTo(DM_CNT.Comp lementoBC.AsFloat, -2); ImpComp.ICMSComp.ICMS60.pICMSSTRet := RoundTo(DM_CNT.Comp lementoAliq.AsFloat, -2); ImpComp.ICMSComp.ICMS60.vICMSSTRet := RoundTo(DM_CNT.Comp lementoValorICMS.AsFloat, -2); ImpComp.ICMSComp.ICMS60.vCred := RoundTo(DM_CNT.Comp lementoCredito.AsFloat, -2); end; 90: begin ImpComp.ICMSComp.SituTrib := cst90; ImpComp.ICMSComp.ICMS90.CST := cst90; // ICMS Outros ImpComp.ICMSComp.ICMS90.pRedBC := RoundTo(DM_CNT.Compleme ntoReducao.AsFloat, -2); ImpComp.ICMSComp.ICMS90.vBC := RoundTo(DM_CNT.Compleme ntoBC.AsFloat, -2); ImpComp.ICMSComp.ICMS90.pICMS := RoundTo(DM_CNT.Compleme ntoAliq.AsFloat, -2); ImpComp.ICMSComp.ICMS90.vICMS := RoundTo(DM_CNT.Compleme ntoValorICMS.AsFloat, -2); ImpComp.ICMSComp.ICMS90.vCred := RoundTo(DM_CNT.Compleme ntoCredito.AsFloat, -2); end; end; // Valor Total dos Tributos ImpComp.vTotTrib := RoundTo(DM_CNT.ConhecimentovTotTrib.AsFloa t, -2); // Obs do Contribuinte if (impComp.vTotTrib <> 0.0)

then begin with compl.ObsCont.Add do begin xCampo := 'Lei da Transparencia'; xTexto := 'O valor aproximado de tributos incidentes sobre o preo deste servico e de R$ ' + FormatFloat('##0.00', impComp.vTotTrib) + ' (' + FormatFloat('#0.00', DM_CNT.ConhecimentoAliqNBS. AsFloat) + '%) ' + 'Fonte: IBPT'; end; end; end; end; DM_CNT.Complemento.Next; end; end; end; 2: begin // // Informaes do Detalhamento do CTe do tipo Anulao de Valores // {$IFDEF PL_200} infCTeAnu.chCTe := DM_CNT.ConhecimentoAnuladoCTe.AsString; infCTeAnu.dEmi := DM_CNT.ConhecimentoAnuladoData.AsDateTime; {$ELSE} infCTeAnuEnt.chCTe := DM_CNT.ConhecimentoAnuladoCTe.AsString; infCTeAnuEnt.dEmi := DM_CNT.ConhecimentoAnuladoData.AsDateTime; {$ENDIF} end; end; // fim do case {$IFDEF PL_200} DM_CTA.PessoaFJ.Close; DM_CTA.PessoaFJ.SQL.Clear; DM_CTA.PessoaFJ.SQL.Add('Select * From Sis_PessoaFJ'); DM_CTA.PessoaFJ.SQL.Add('Where DownloadXML = :xXML'); DM_CTA.PessoaFJ.Params[0].AsString := 'S'; DM_CTA.PessoaFJ.Active := True; DM_CTA.PessoaFJ.Open; DM_CTA.PessoaFJ.Last; j := DM_CTA.PessoaFJ.RecordCount; if j > 0 then begin DM_CTA.PessoaFJ.First; for i := 1 to j do begin with autXML.Add do begin if copy(DM_CTA.PessoaFJCGC.AsString,10,4) <> '0000' then CNPJCPF := Copy(DM_CTA.PessoaFJCGC.AsString, 2, 14) else CNPJCPF := Copy(DM_CTA.PessoaFJCGC.AsString, 1, 9) + Copy(DM_CTA.PessoaFJCGC.AsString, 14, 2); end; DM_CTA.PessoaFJ.Next; end; end; {$ENDIF}

end; // fim da adio do conhecimento ao compomente end;

Вам также может понравиться