PHP code example of crdesign8 / laravel-rtc-calculator
1. Go to this page and download the library: Download crdesign8/laravel-rtc-calculator library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
crdesign8 / laravel-rtc-calculator example snippets
use Crdesign8\LaravelRtcCalculator\Facades\Rtc;
use Crdesign8\LaravelRtcCalculator\DTOs\ItemDTO;
use Crdesign8\LaravelRtcCalculator\Enums\UnidadeMedida;
$resultado = Rtc::make()
->paraFiscal(municipio: 4314902, uf: 'RS')
->emitidoEm('2027-01-01T03:00:00-03:00')
->addItem(
ItemDTO::make(numero: 1)
->ncm('24021000')
->quantidade(222)
->unidade(UnidadeMedida::VN)
->cst('550')
->baseCalculo(1111.00)
->cClassTrib('550020')
)
->calcular();
// Acessa os totais calculados
echo $resultado->getTotal()->getVIsTot(); // Imposto Seletivo total
echo $resultado->getTotal()->getVBcIbsCbs(); // Base de cálculo IBS+CBS
echo $resultado->getTotal()->getVCbsTot(); // CBS total
// Acessa um item específico pelo número
$item = $resultado->getItem(1);
echo $item->getCstIs(); // CST do Imposto Seletivo
echo $item->getVIs(); // Valor do IS
// Gera o XML com grupos RTC
$xmlRtc = Rtc::make()->gerarXml($resultado);
// Injeta na NFe existente
$nfeComRtc = Rtc::make()->injetarNfe(
xmlRtc: $xmlRtc,
xmlNfe: file_get_contents('nfe-sem-rtc.xml')
);
file_put_contents('nfe-com-rtc.xml', $nfeComRtc);
use Crdesign8\LaravelRtcCalculator\Events\RtcCalculated;
// Em qualquer EventServiceProvider ou via closure:
Event::listen(RtcCalculated::class, function (RtcCalculated $event) {
Log::info('RTC calculado', [
'municipio' => $event->dto->getMunicipio(),
'itens' => count($event->dto->getItens()),
'vIsTot' => $event->result->getTotal()->getVIsTot(),
'vCbsTot' => $event->result->getTotal()->getVCbsTot(),
]);
});
bash
php artisan rtc:calcular entrada.json
# Salvar o resultado em arquivo
php artisan rtc:calcular entrada.json --saida=resultado.json
bash
php artisan rtc:injetar nfe-sem-rtc.xml resultado.json nfe-com-rtc.xml
# Para CTe ou NFCe
php artisan rtc:injetar nota.xml resultado.json nota-com-rtc.xml --tipo=CTe
bash
php artisan rtc:healthcheck
# Testar uma URL diferente da configurada
php artisan rtc:healthcheck --url=http://meu-servidor:8080
bash
# Pré-requisito: calculadora Java em http://localhost:8080
# 1. Cálculo de tributos (IS + IBS + CBS) com tabela formatada
php examples/01-calcular-tributos.php
# 2. Geração do XML com grupos IS/IBSCBS/ISTot/IBSCBSTot
php examples/02-gerar-xml-rtc.php
# 3. Fluxo completo: calcular → gerar XML → injetar em uma NFe real
php examples/03-fluxo-completo-nfe.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.