Skip to content

Commit 3ac31d3

Browse files
authored
feat: federal taxation settings UI, percentage_profile mode, and emission integration (#80)
* feat(db): add codigo_tributacao_nacional column to nfse_company_services Signed-off-by: Vitor Mattos <vitor@php.rio> * feat(routes): register company services CRUD and settings federal routes Signed-off-by: Vitor Mattos <vitor@php.rio> * feat(controller): add CompanyServiceController for service CRUD management Signed-off-by: Vitor Mattos <vitor@php.rio> * feat(i18n): add pt-BR labels for federal taxation settings fields Signed-off-by: Vitor Mattos <vitor@php.rio> * feat(i18n): add en-GB labels for federal taxation settings fields Signed-off-by: Vitor Mattos <vitor@php.rio> * feat(settings): persist federal taxation fields in updateFederal endpoint Add validation and persistence for PIS/COFINS situacao tributaria, tipo retencao, base calculo, aliquotas, valores, IRRF, CSLL, CP, and tributos percentage profiles. Also persist tributacao_federal_mode radio selection (per_invoice_amounts | percentage_profile). Signed-off-by: Vitor Mattos <vitor@php.rio> * feat(invoice): integrate federal taxation mode into DPS emission - federalPayloadValues now accepts invoiceAmount for mode-aware calculation - In percentage_profile mode: baseCalculo=invoiceAmount, valorPis and valorCofins calculated from stored aliquotas * invoiceAmount / 100 - Compute indicadorTributacao: 2 when any tributos_* percent setting is non-empty, otherwise 0 - Pass indicadorTributacao to DpsData in both emit() and reemit() Signed-off-by: Vitor Mattos <vitor@php.rio> * feat(settings-view): add federal taxation tab with mode-conditional visibility - Add PIS/COFINS situacao tributaria and tipo retencao selects - Add base calculo, aliquota and valor PIS/COFINS inputs - Add IRRF, CSLL, CP retention fields - Add tributacao_federal_mode radio (per_invoice_amounts/percentage_profile) - Add syncFederalMode() JS to toggle BC/valor fields vs tributos% rows - Add tributos percentage profile rows for Perfil padrao and Simples Nacional - Attach HTML ids to toggle targets Signed-off-by: Vitor Mattos <vitor@php.rio> * feat(invoices-view): update pending invoices view Signed-off-by: Vitor Mattos <vitor@php.rio> * test(settings): cover federal taxation fields persistence in updateFederal Signed-off-by: Vitor Mattos <vitor@php.rio> * test(view): cover federal taxation tab field ids and inputs Signed-off-by: Vitor Mattos <vitor@php.rio> * test(invoice): cover percentage_profile mode and indicadorTributacao emission Add tests for: - percentage_profile mode calculates valorPis and valorCofins from aliquotas x invoiceAmount and sets baseCalculo = invoiceAmount - indicadorTributacao is set to 2 when any tributos_* percent setting is non-empty, and 0 otherwise - Fix testCompanyServiceSelectionSupport to use source inspection instead of runtime check (Eloquent not available in module vendor) Signed-off-by: Vitor Mattos <vitor@php.rio> * test(routes): cover company service CRUD route registration Signed-off-by: Vitor Mattos <vitor@php.rio> * chore(gitignore): exclude .env.e2e from version control Signed-off-by: Vitor Mattos <vitor@php.rio> * chore(e2e): add .env.e2e.example template for end-to-end test configuration Signed-off-by: Vitor Mattos <vitor@php.rio> * test(e2e): add Playwright auth helper for NFS-e E2E tests Signed-off-by: Vitor Mattos <vitor@php.rio> * test(e2e): add Playwright settings spec for NFS-e federal taxation tab Signed-off-by: Vitor Mattos <vitor@php.rio> * test(e2e): add Playwright emission spec for NFS-e invoice emission flow Signed-off-by: Vitor Mattos <vitor@php.rio> * test(integration): update nfse_endpoints Behat feature with federal routes Signed-off-by: Vitor Mattos <vitor@php.rio> * fix(invoice): fallback item lista service to settings when default service is unavailable When company service selection is supported but no default service is resolved, keep emission readiness by falling back to nfse.item_lista_servico and nfse.codigo_tributacao_nacional settings. Signed-off-by: Vitor Mattos <vitor@php.rio> * test(invoice): align national tax code fallback expectation Update isolation test to assert fallback to nfse.codigo_tributacao_nacional when default service national tax code is missing. Signed-off-by: Vitor Mattos <vitor@php.rio> --------- Signed-off-by: Vitor Mattos <vitor@php.rio>
1 parent d286dc7 commit 3ac31d3

19 files changed

Lines changed: 1362 additions & 173 deletions

.env.e2e.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
NFSE_E2E_BASE_URL="http://localhost:8082"
55
NFSE_E2E_EMAIL=""
66
NFSE_E2E_PASSWORD=""
7+
NFSE_E2E_REAL_EMIT_FLOW="0"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
/node_modules/
77
/playwright-report/
88
/test-results/
9+
.env.e2e
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
// SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
4+
// SPDX-License-Identifier: AGPL-3.0-or-later
5+
6+
declare(strict_types=1);
7+
8+
use Illuminate\Database\Migrations\Migration;
9+
use Illuminate\Database\Schema\Blueprint;
10+
use Illuminate\Support\Facades\Schema;
11+
12+
return new class () extends Migration {
13+
public function up(): void
14+
{
15+
if (!Schema::hasTable('nfse_company_services')) {
16+
return;
17+
}
18+
19+
if (Schema::hasColumn('nfse_company_services', 'codigo_tributacao_nacional')) {
20+
return;
21+
}
22+
23+
Schema::table('nfse_company_services', function (Blueprint $table): void {
24+
$table->string('codigo_tributacao_nacional', 6)
25+
->nullable()
26+
->after('item_lista_servico');
27+
});
28+
}
29+
30+
public function down(): void
31+
{
32+
if (!Schema::hasTable('nfse_company_services')) {
33+
return;
34+
}
35+
36+
if (!Schema::hasColumn('nfse_company_services', 'codigo_tributacao_nacional')) {
37+
return;
38+
}
39+
40+
Schema::table('nfse_company_services', function (Blueprint $table): void {
41+
$table->dropColumn('codigo_tributacao_nacional');
42+
});
43+
}
44+
};

Http/Controllers/CompanyServiceController.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,6 @@ public function update(Request $request, CompanyService $service): RedirectRespo
119119

120120
$service->update($validated);
121121

122-
if ($service->is_default) {
123-
$this->syncDefaultServiceSettings($service);
124-
}
125-
126122
return redirect()->route('nfse.settings.edit', ['tab' => 'services'])
127123
->with('success', trans('nfse::general.settings.services.service_updated'));
128124
}
@@ -244,18 +240,5 @@ private function setDefaultService(CompanyService $service): void
244240
->update(['is_default' => false]);
245241

246242
$service->update(['is_default' => true]);
247-
248-
$this->syncDefaultServiceSettings($service);
249-
}
250-
251-
private function syncDefaultServiceSettings(CompanyService $service): void
252-
{
253-
setting([
254-
'nfse.item_lista_servico' => (string) $service->item_lista_servico,
255-
'nfse.codigo_tributacao_nacional' => (string) $service->codigo_tributacao_nacional,
256-
'nfse.aliquota' => number_format((float) $service->aliquota, 2, '.', ''),
257-
]);
258-
259-
setting()->save();
260243
}
261244
}

0 commit comments

Comments
 (0)