Eu fiz algumas modificações na função GerarNFSe, mas a princípio todos os dados passados estão corretos.
// Função criada para arredondar valores quando a n Casa for maior ou igual a 5
// pois a função RoundTo arredonda quando a n Casa for maior ou igual a 6
function TForm1.RoundTo5(Valor: Double; Casas: Integer): Double;
var
xValor, xDecimais: String;
p, nCasas: Integer;
nValor: Double;
begin
nValor := Valor;
xValor := Trim(FloatToStr(Valor));
p := pos(',', xValor);
if Casas < 0 then nCasas := - Casas
else nCasas := Casas;
if p > 0 then
begin
xDecimais := Copy(xValor, p + 1, length(xValor));
if length(xDecimais) > nCasas then
begin
if xDecimais[nCasas + 1] >= '5' then SetRoundMode(rmUP)
else SetRoundMode(rmNearest);
end;
nValor := RoundTo(Valor, Casas);
end;
Result := nValor;
end;
{FUNÇÃO PRINCIPAL PARA GERAR A NFSe}
{ESTA FUNÇÃO CARREGA PARA O COMPONENTE ACBR OS VALORES NECESSÁRIOS PARA GERAÇÃO DA NFSe}
{NENHUMA OUTRA OPERAÇÃO ESTÁ CONTIDA NESTA FUNÇÃO}
procedure TForm1.GerarNFSe(NumNFSe: String);
var
ValorISS: Double;
begin
ACBR_NFSe.NotasFiscais.Clear;
with ACBR_NFSe do
begin
NotasFiscais.NumeroLote:='1';
with NotasFiscais.Add.NFSe do
begin
IdentificacaoRps.Numero := FormatFloat('#########0', StrToInt(NumNFSe));
IdentificacaoRps.Serie := 'UNICA';
IdentificacaoRps.Tipo := trRPS;
DataEmissao := Date;
NaturezaOperacao := noTributacaoNoMunicipio;
RegimeEspecialTributacao := retMicroempresaMunicipal;
OptanteSimplesNacional := snSim;
IncentivadorCultural := snSim;
Producao := snNao;
Status := srNormal;
OutrasInformacoes := 'Pagamento a Vista';
{VALORES FISCAIS}
Servico.Valores.ValorServicos := 1685.50;
Servico.Valores.ValorDeducoes := 0.00;
Servico.Valores.ValorPis := 0.00;
Servico.Valores.ValorCofins := 0.00;
Servico.Valores.ValorInss := 0.00;
Servico.Valores.ValorIr := 0.00;
Servico.Valores.ValorCsll := 0.00;
Servico.Valores.IssRetido := stNormal;
Servico.Valores.OutrasRetencoes := 0.00;
Servico.Valores.DescontoIncondicionado := 0.00;
Servico.Valores.DescontoCondicionado := 0.00;
Servico.Valores.BaseCalculo := Servico.Valores.ValorServicos -
Servico.Valores.ValorDeducoes -
Servico.Valores.DescontoIncondicionado;
Servico.Valores.Aliquota := 0.03;
if Servico.Valores.IssRetido = stNormal then
begin
ValorISS := Servico.Valores.BaseCalculo *
Servico.Valores.Aliquota;
Servico.Valores.ValorIss := RoundTo5(ValorISS, -2);
Servico.Valores.ValorIssRetido := 0.00;
end else
begin
ValorISS := Servico.Valores.BaseCalculo *
Servico.Valores.Aliquota;
Servico.Valores.ValorIss := 0.00;
Servico.Valores.ValorIssRetido := RoundTo5(ValorISS, -2);
end;
Servico.Valores.ValorLiquidoNfse := Servico.Valores.ValorServicos -
Servico.Valores.ValorPis -
Servico.Valores.ValorCofins -
Servico.Valores.ValorInss -
Servico.Valores.ValorIr -
Servico.Valores.ValorCsll -
Servico.Valores.OutrasRetencoes -
Servico.Valores.ValorIssRetido -
Servico.Valores.DescontoIncondicionado -
Servico.Valores.DescontoCondicionado;
Servico.ItemListaServico := '01.07';
Servico.CodigoTributacaoMunicipio := '118879';
Servico.Discriminacao := 'discriminacao';
Servico.CodigoMunicipio := '4314100';
Servico.ExigibilidadeISS := exiExigivel;
Servico.CodigoPais := 1058; // Brasil
Servico.MunicipioIncidencia := StrToIntDef('4314100', 0);
with Servico.ItemServico.Add do
begin
Descricao := 'SERVICO 1';
Quantidade := 1;
ValorUnitario := 15.00;
end;
{CARREGA DADOS DO EMISSOR}
Prestador.Cnpj := QuerySQL.FieldByName('CNPJ' ).AsString;
Prestador.InscricaoMunicipal := '56977'; //QuerySQL.FieldByName('' ).AsString;
Prestador.Senha := 'senha';
Prestador.FraseSecreta := 'frase secreta';
Prestador.cUF := 13; //QuerySQL.FieldByName('UF' ).AsInteger;
{CARREGA DADOS DO DESTINATÁRIO}
Tomador.IdentificacaoTomador.CpfCnpj := QuerySQL.FieldByName('NF_CNPJ' ).AsString;
Tomador.IdentificacaoTomador.InscricaoMunicipal := '43236'; //QuerySQL.FieldByName('' ).AsString;
Tomador.RazaoSocial := QueryCli.FieldByName('TBL_CLI_RAZAO' ).AsString;
Tomador.Endereco.Endereco := QueryCli.FieldByName('TBL_CLI_END' ).AsString;
Tomador.Endereco.Numero := QueryCli.FieldByName('TBL_CLI_NR_RESIDE').AsString;
Tomador.Endereco.Complemento := ''; //QuerySQL.FieldByName('' ).AsString;
Tomador.Endereco.Bairro := QuerySQL.FieldByName('NF_BAIRRO' ).AsString;
Tomador.Endereco.CodigoMunicipio := '4314100';//QuerySQL.FieldByName('' ).AsString;
Tomador.Endereco.UF := QuerySQL.FieldByName('NF_UF' ).AsString;
Tomador.Endereco.CEP := QueryCli.FieldByName('TBL_CLI_CEP' ).AsString;
Tomador.Endereco.xPais := 'BRASIL'; //QuerySQL.FieldByName('' ).AsString;
Tomador.IdentificacaoTomador.InscricaoEstadual := QuerySQL.FieldByName('NF_INSC_ESTADUAL' ).AsString;
Tomador.Contato.Telefone := QueryCli.FieldByName('TBL_CLI_FONE1' ).AsString;
Tomador.Contato.Email := QueryCli.FieldByName('TBL_CLI_EMAIL' ).AsString;
end;
end;
end;