732 lines
25 KiB
PHP
732 lines
25 KiB
PHP
<?php
|
|
|
|
use App\Models\Fornitore;
|
|
use App\Models\Stabile;
|
|
use App\Models\User;
|
|
use App\Models\Amministratore;
|
|
use App\Models\GestioneContabile;
|
|
use App\Models\DatiBancari;
|
|
use App\Models\VoceSpesa;
|
|
use App\Modules\Contabilita\Models\RegolaPrimaNota;
|
|
use App\Modules\Contabilita\Models\MovimentoBanca;
|
|
use App\Modules\Contabilita\Models\Registrazione;
|
|
use App\Filament\Pages\Contabilita\DebitiPagareHub;
|
|
use App\Filament\Pages\Contabilita\CasseBancheRiepilogo;
|
|
use App\Filament\Pages\Condomini\RiscaldamentoStabileArchivio;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
test('it loads payments hub with correct details and description', function () {
|
|
$user = User::factory()->create();
|
|
$user->assignRole('super-admin');
|
|
$this->actingAs($user);
|
|
|
|
$amministratore = Amministratore::create([
|
|
'user_id' => $user->id,
|
|
'nome' => 'Admin',
|
|
'cognome' => 'Test',
|
|
'denominazione' => 'Amministrazione Test',
|
|
'codice_fiscale' => '12345678901',
|
|
]);
|
|
|
|
$stabile = Stabile::create([
|
|
'amministratore_id' => $amministratore->id,
|
|
'codice_stabile' => '9999',
|
|
'denominazione' => 'Condominio Test Contabilita',
|
|
'codice_fiscale' => '12345678901',
|
|
'indirizzo' => 'Via Test 1',
|
|
'citta' => 'Roma',
|
|
'cap' => '00100',
|
|
'provincia' => 'RM',
|
|
'codice_destinatario_sdi' => '0000000',
|
|
]);
|
|
|
|
$gestione = GestioneContabile::create([
|
|
'tenant_id' => 'default',
|
|
'stabile_id' => $stabile->id,
|
|
'anno_gestione' => 2026,
|
|
'tipo_gestione' => 'ordinaria',
|
|
'denominazione' => 'Gestione Ordinaria 2026',
|
|
'data_inizio' => '2026-01-01',
|
|
'data_fine' => '2026-12-31',
|
|
'stato' => 'aperta',
|
|
'protocollo_prefix' => 'O2026',
|
|
]);
|
|
|
|
$fornitore = Fornitore::create([
|
|
'amministratore_id' => $amministratore->id,
|
|
'ragione_sociale' => 'ENEL ENERGIA SPA',
|
|
'codice_fiscale' => '00325478911',
|
|
'partita_iva' => '00325478911',
|
|
'iban' => 'IT99X00000000000000000001234',
|
|
]);
|
|
|
|
DB::table('contabilita_fatture_fornitori')->insert([
|
|
'id' => 888,
|
|
'stabile_id' => $stabile->id,
|
|
'gestione_id' => $gestione->id,
|
|
'fornitore_id' => $fornitore->id,
|
|
'numero_documento' => '2026-INV-99',
|
|
'totale' => 750.50,
|
|
'netto_da_pagare' => 750.50,
|
|
'stato' => 'da_pagare',
|
|
'data_documento' => '2026-06-15',
|
|
]);
|
|
|
|
session(['netgescon.stabile_attivo_id' => $stabile->id]);
|
|
|
|
$page = new DebitiPagareHub();
|
|
$page->mount();
|
|
|
|
expect($page->debiti)->toHaveCount(1);
|
|
$debito = $page->debiti[0];
|
|
expect($debito['id'])->toBe(888);
|
|
expect($debito['numero_documento'])->toBe('2026-INV-99');
|
|
expect($debito['totale'])->toBe(750.50);
|
|
expect($debito['iban'])->toBe('IT99X00000000000000000001234');
|
|
expect($debito['descrizione_bonifico'])->toContain('FAT-ID:888');
|
|
expect($debito['descrizione_bonifico'])->toContain('ENEL ENERGIA SPA');
|
|
});
|
|
|
|
test('it reconciles automatically via tracking tag FAT-ID', function () {
|
|
$user = User::factory()->create();
|
|
$user->assignRole('super-admin');
|
|
$this->actingAs($user);
|
|
|
|
$amministratore = Amministratore::create([
|
|
'user_id' => $user->id,
|
|
'nome' => 'Admin',
|
|
'cognome' => 'Test',
|
|
'denominazione' => 'Amministrazione Test',
|
|
'codice_fiscale' => '12345678901',
|
|
]);
|
|
|
|
$stabile = Stabile::create([
|
|
'amministratore_id' => $amministratore->id,
|
|
'codice_stabile' => '9999',
|
|
'denominazione' => 'Condominio Test Contabilita',
|
|
'codice_fiscale' => '12345678901',
|
|
'indirizzo' => 'Via Test 1',
|
|
'citta' => 'Roma',
|
|
'cap' => '00100',
|
|
'provincia' => 'RM',
|
|
'codice_destinatario_sdi' => '0000000',
|
|
]);
|
|
|
|
$gestione = GestioneContabile::create([
|
|
'tenant_id' => 'default',
|
|
'stabile_id' => $stabile->id,
|
|
'anno_gestione' => 2026,
|
|
'tipo_gestione' => 'riscaldamento',
|
|
'denominazione' => 'Gestione Riscaldamento 2026',
|
|
'data_inizio' => '2026-01-01',
|
|
'data_fine' => '2026-12-31',
|
|
'stato' => 'aperta',
|
|
'protocollo_prefix' => 'R2026',
|
|
]);
|
|
|
|
$conto = DatiBancari::create([
|
|
'stabile_id' => $stabile->id,
|
|
'tipo_conto' => 'corrente',
|
|
'denominazione_banca' => 'Unicredit',
|
|
'numero_conto' => '123456',
|
|
'iban' => 'IT02X0000000000000000000',
|
|
'saldo_iniziale' => 10000.00,
|
|
'stato_conto' => 'attivo',
|
|
'is_nostro_conto' => true,
|
|
]);
|
|
|
|
$fornitore = Fornitore::create([
|
|
'amministratore_id' => $amministratore->id,
|
|
'ragione_sociale' => 'A2A ENERGIA',
|
|
'codice_fiscale' => '00325478955',
|
|
'partita_iva' => '00325478955',
|
|
'old_id' => '9991',
|
|
]);
|
|
|
|
// Create service to allow finding this supplier
|
|
\App\Models\StabileServizio::create([
|
|
'stabile_id' => $stabile->id,
|
|
'fornitore_id' => $fornitore->id,
|
|
'tipo' => 'riscaldamento',
|
|
'nome' => 'Riscaldamento',
|
|
'attivo' => true,
|
|
]);
|
|
|
|
DB::table('contabilita_fatture_fornitori')->insert([
|
|
'id' => 777,
|
|
'stabile_id' => $stabile->id,
|
|
'gestione_id' => $gestione->id,
|
|
'fornitore_id' => $fornitore->id,
|
|
'numero_documento' => 'FATT-A2A-1',
|
|
'totale' => 1500.00,
|
|
'netto_da_pagare' => 1500.00,
|
|
'stato' => 'da_pagare',
|
|
'data_documento' => '2026-06-01',
|
|
]);
|
|
|
|
DB::table('contabilita_movimenti_banca')->insert([
|
|
'id' => 303,
|
|
'stabile_id' => $stabile->id,
|
|
'conto_id' => $conto->id,
|
|
'gestione_id' => $gestione->id,
|
|
'iban' => 'IT02X0000000000000000000',
|
|
'data' => '2026-06-15',
|
|
'valuta' => '2026-06-15',
|
|
'descrizione' => 'Bonifico a A2A ENERGIA ref FAT-ID:777',
|
|
'descrizione_estesa' => 'Bonifico a A2A ENERGIA ref FAT-ID:777',
|
|
'importo' => -1500.00,
|
|
'fornitore_id' => $fornitore->id,
|
|
'row_hash' => md5('test_movement_303'),
|
|
]);
|
|
|
|
session(['netgescon.stabile_attivo_id' => $stabile->id]);
|
|
|
|
$page = new RiscaldamentoStabileArchivio();
|
|
$page->riconciliaAutomaticamentePagamenti();
|
|
|
|
$updatedInvoice = DB::table('contabilita_fatture_fornitori')->where('id', 777)->first();
|
|
expect($updatedInvoice->stato)->toBe('pagato');
|
|
expect($updatedInvoice->movimento_pagamento_id)->toBe(303);
|
|
});
|
|
|
|
test('it configures interbank mapping and auto registers bank costs and CBILL bollettini', function () {
|
|
$user = User::factory()->create();
|
|
$user->assignRole('super-admin');
|
|
$this->actingAs($user);
|
|
|
|
$amministratore = Amministratore::create([
|
|
'user_id' => $user->id,
|
|
'nome' => 'Admin',
|
|
'cognome' => 'Test',
|
|
'denominazione' => 'Amministrazione Test',
|
|
'codice_fiscale' => '12345678901',
|
|
]);
|
|
|
|
$stabile = Stabile::create([
|
|
'amministratore_id' => $amministratore->id,
|
|
'codice_stabile' => '9999',
|
|
'denominazione' => 'Condominio Test Contabilita',
|
|
'codice_fiscale' => '12345678901',
|
|
'indirizzo' => 'Via Test 1',
|
|
'citta' => 'Roma',
|
|
'cap' => '00100',
|
|
'provincia' => 'RM',
|
|
'codice_destinatario_sdi' => '0000000',
|
|
]);
|
|
|
|
$gestione = GestioneContabile::create([
|
|
'tenant_id' => 'default',
|
|
'stabile_id' => $stabile->id,
|
|
'anno_gestione' => 2026,
|
|
'tipo_gestione' => 'ordinaria',
|
|
'denominazione' => 'Gestione Ordinaria 2026',
|
|
'data_inizio' => '2026-01-01',
|
|
'data_fine' => '2026-12-31',
|
|
'stato' => 'aperta',
|
|
'protocollo_prefix' => 'O2026',
|
|
]);
|
|
|
|
$contoBancario = DatiBancari::create([
|
|
'stabile_id' => $stabile->id,
|
|
'tipo_conto' => 'corrente',
|
|
'denominazione_banca' => 'Unicredit',
|
|
'numero_conto' => '123456',
|
|
'iban' => 'IT02X0000000000000000000',
|
|
'saldo_iniziale' => 10000.00,
|
|
'stato_conto' => 'attivo',
|
|
'is_nostro_conto' => true,
|
|
]);
|
|
|
|
// 1. Setup global chart accounts
|
|
// Ensure PianoConti accounts 7 (Banca) and 27 (Oneri) exist
|
|
DB::table('contabilita_piano_conti')->insertOrIgnore([
|
|
'id' => 7,
|
|
'codice' => '1020',
|
|
'denominazione' => 'Banca c/c',
|
|
'tipo_conto' => 'ATTIVO',
|
|
'attivo' => 1,
|
|
'livello' => 2,
|
|
'codice_padre' => '100',
|
|
'saldo_iniziale' => 0.00,
|
|
]);
|
|
|
|
DB::table('contabilita_piano_conti')->insertOrIgnore([
|
|
'id' => 27,
|
|
'codice' => '5150',
|
|
'denominazione' => 'Oneri bancari e postali',
|
|
'tipo_conto' => 'COSTO',
|
|
'attivo' => 1,
|
|
'livello' => 2,
|
|
'codice_padre' => '500',
|
|
'saldo_iniziale' => 0.00,
|
|
]);
|
|
|
|
session(['netgescon.stabile_attivo_id' => $stabile->id]);
|
|
|
|
$page = new CasseBancheRiepilogo();
|
|
|
|
// Propose mappings
|
|
$page->interbankMappings = [
|
|
'198' => 27, // Map code 198 to account 27
|
|
'219' => 27, // Map code 219 to account 27
|
|
'012' => 27,
|
|
];
|
|
$page->saveInterbankMappings();
|
|
|
|
// Verify rules were persisted
|
|
$rule198 = RegolaPrimaNota::where('stabile_id', $stabile->id)
|
|
->where('origine', 'banca')
|
|
->where('chiave', '198')
|
|
->first();
|
|
|
|
expect($rule198)->not->toBeNull();
|
|
expect((int)$rule198->conto_avere_id)->toBe(27);
|
|
|
|
// Mock direct bank movements
|
|
DB::table('contabilita_movimenti_banca')->insert([
|
|
'id' => 401,
|
|
'stabile_id' => $stabile->id,
|
|
'conto_id' => $contoBancario->id,
|
|
'gestione_id' => $gestione->id,
|
|
'iban' => 'IT02X0000000000000000000',
|
|
'data' => '2026-07-01',
|
|
'valuta' => '2026-07-01',
|
|
'descrizione' => 'IMPRENDO CONDOMINIO LIGHT COSTO FISSO MESE DI GIUGNO 2026',
|
|
'descrizione_estesa' => 'IMPRENDO CONDOMINIO LIGHT COSTO FISSO MESE DI GIUGNO 2026',
|
|
'importo' => -22.00,
|
|
'causale' => '198',
|
|
'row_hash' => md5('test_movement_401'),
|
|
]);
|
|
|
|
// Mock a CBILL utility payment movement (causale 012)
|
|
$fornitoreCbill = Fornitore::create([
|
|
'amministratore_id' => $amministratore->id,
|
|
'ragione_sociale' => 'ACEA ATO 2 SPA',
|
|
'codice_fiscale' => '00325478977',
|
|
'partita_iva' => '00325478977',
|
|
]);
|
|
|
|
DB::table('contabilita_fatture_fornitori')->insert([
|
|
'id' => 999,
|
|
'stabile_id' => $stabile->id,
|
|
'gestione_id' => $gestione->id,
|
|
'fornitore_id' => $fornitoreCbill->id,
|
|
'numero_documento' => 'ACEA-BOL-2',
|
|
'totale' => 1310.76,
|
|
'netto_da_pagare' => 1310.76,
|
|
'stato' => 'da_pagare',
|
|
'data_documento' => '2026-05-01',
|
|
]);
|
|
|
|
DB::table('contabilita_movimenti_banca')->insert([
|
|
'id' => 402,
|
|
'stabile_id' => $stabile->id,
|
|
'conto_id' => $contoBancario->id,
|
|
'gestione_id' => $gestione->id,
|
|
'iban' => 'IT02X0000000000000000000',
|
|
'data' => '2026-05-11',
|
|
'valuta' => '2026-05-11',
|
|
'descrizione' => 'DISPOSIZIONE DI ADDEBITO GENERICA BOLLETTINO ACEA ATO 2 S.P.A. (PROFILO PAGOPA)',
|
|
'descrizione_estesa' => 'DISPOSIZIONE DI ADDEBITO GENERICA BOLLETTINO ACEA ATO 2 S.P.A. (PROFILO PAGOPA)',
|
|
'importo' => -1310.76,
|
|
'causale' => '012',
|
|
'row_hash' => md5('test_movement_402'),
|
|
]);
|
|
|
|
// Run batch reconciliation
|
|
$page->riconciliaSpeseBancarieAutomaticamente();
|
|
|
|
// Verify 401 has been registered in Prima Nota
|
|
$m401 = MovimentoBanca::find(401);
|
|
expect($m401->registrazione_id)->not->toBeNull();
|
|
|
|
// Verify 402 has matched and paid the Acea invoice
|
|
$invoiceAcea = DB::table('contabilita_fatture_fornitori')->where('id', 999)->first();
|
|
expect($invoiceAcea->stato)->toBe('pagato');
|
|
expect($invoiceAcea->movimento_pagamento_id)->toBe(402);
|
|
});
|
|
|
|
test('it renders the operations staging query even if the table does not exist', function () {
|
|
$user = User::factory()->create();
|
|
$user->assignRole('super-admin');
|
|
$this->actingAs($user);
|
|
|
|
$amministratore = Amministratore::create([
|
|
'user_id' => $user->id,
|
|
'nome' => 'Admin',
|
|
'cognome' => 'Test',
|
|
'denominazione' => 'Amministrazione Test',
|
|
'codice_fiscale' => '12345678901',
|
|
]);
|
|
|
|
$stabile = Stabile::create([
|
|
'amministratore_id' => $amministratore->id,
|
|
'codice_stabile' => '9999',
|
|
'denominazione' => 'Condominio Test Contabilita',
|
|
'codice_fiscale' => '12345678901',
|
|
'indirizzo' => 'Via Test 1',
|
|
'citta' => 'Roma',
|
|
'cap' => '00100',
|
|
'provincia' => 'RM',
|
|
'codice_destinatario_sdi' => '0000000',
|
|
]);
|
|
|
|
session(['netgescon.stabile_attivo_id' => $stabile->id]);
|
|
|
|
$page = new \App\Filament\Pages\Gescon\Ordinarie();
|
|
$page->netgesconWorkflowMode = false;
|
|
|
|
// Verify calling getOperazioniProperty() does NOT crash, even though operations table is not in sqlite test db
|
|
$result = $page->getOperazioniProperty();
|
|
expect($result)->not->toBeNull();
|
|
});
|
|
|
|
test('it loads movements and debiti storici tab contents correctly', function () {
|
|
$user = User::factory()->create();
|
|
$user->assignRole('super-admin');
|
|
$this->actingAs($user);
|
|
|
|
$amministratore = Amministratore::create([
|
|
'user_id' => $user->id,
|
|
'nome' => 'Admin',
|
|
'cognome' => 'Test',
|
|
'denominazione' => 'Amministrazione Test',
|
|
'codice_fiscale' => '12345678901',
|
|
]);
|
|
|
|
$stabile = Stabile::create([
|
|
'amministratore_id' => $amministratore->id,
|
|
'codice_stabile' => '9999',
|
|
'denominazione' => 'Condominio Test Contabilita',
|
|
'codice_fiscale' => '12345678901',
|
|
'indirizzo' => 'Via Test 1',
|
|
'citta' => 'Roma',
|
|
'cap' => '00100',
|
|
'provincia' => 'RM',
|
|
'codice_destinatario_sdi' => '0000000',
|
|
]);
|
|
|
|
$gestione = GestioneContabile::create([
|
|
'tenant_id' => 'default',
|
|
'stabile_id' => $stabile->id,
|
|
'anno_gestione' => 2026,
|
|
'tipo_gestione' => 'ordinaria',
|
|
'denominazione' => 'Gestione Ordinaria 2026',
|
|
'data_inizio' => '2026-01-01',
|
|
'data_fine' => '2026-12-31',
|
|
'stato' => 'aperta',
|
|
'protocollo_prefix' => 'O2026',
|
|
]);
|
|
|
|
$fornitore = Fornitore::create([
|
|
'amministratore_id' => $amministratore->id,
|
|
'ragione_sociale' => 'A2A ENERGIA',
|
|
'codice_fiscale' => '00325478955',
|
|
'partita_iva' => '00325478955',
|
|
]);
|
|
|
|
// 1. Invoice 1: Document date 2026-06-01, paid late on 2027-01-15
|
|
DB::table('contabilita_fatture_fornitori')->insert([
|
|
'id' => 991,
|
|
'stabile_id' => $stabile->id,
|
|
'gestione_id' => $gestione->id,
|
|
'fornitore_id' => $fornitore->id,
|
|
'numero_documento' => 'A2A-LATE-1',
|
|
'totale' => 500.00,
|
|
'netto_da_pagare' => 500.00,
|
|
'stato' => 'pagato',
|
|
'data_documento' => '2026-06-01',
|
|
'data_pagamento' => '2027-01-15',
|
|
]);
|
|
|
|
// 2. Invoice 2: Document date 2026-06-02, still unpaid
|
|
DB::table('contabilita_fatture_fornitori')->insert([
|
|
'id' => 992,
|
|
'stabile_id' => $stabile->id,
|
|
'gestione_id' => $gestione->id,
|
|
'fornitore_id' => $fornitore->id,
|
|
'numero_documento' => 'A2A-UNPAID',
|
|
'totale' => 600.00,
|
|
'netto_da_pagare' => 600.00,
|
|
'stato' => 'da_pagare',
|
|
'data_documento' => '2026-06-02',
|
|
]);
|
|
|
|
// 3. Invoice 3: Document date after management period, e.g. 2027-01-01
|
|
DB::table('contabilita_fatture_fornitori')->insert([
|
|
'id' => 993,
|
|
'stabile_id' => $stabile->id,
|
|
'gestione_id' => $gestione->id,
|
|
'fornitore_id' => $fornitore->id,
|
|
'numero_documento' => 'A2A-FUTURE',
|
|
'totale' => 300.00,
|
|
'netto_da_pagare' => 300.00,
|
|
'stato' => 'da_pagare',
|
|
'data_documento' => '2027-01-01',
|
|
]);
|
|
|
|
// 4. Mock bank movement
|
|
$conto = DatiBancari::create([
|
|
'stabile_id' => $stabile->id,
|
|
'tipo_conto' => 'corrente',
|
|
'denominazione_banca' => 'Unicredit',
|
|
'numero_conto' => '123456',
|
|
'iban' => 'IT02X0000000000000000000',
|
|
'saldo_iniziale' => 10000.00,
|
|
'stato_conto' => 'attivo',
|
|
'is_nostro_conto' => true,
|
|
]);
|
|
|
|
DB::table('contabilita_movimenti_banca')->insert([
|
|
'id' => 501,
|
|
'stabile_id' => $stabile->id,
|
|
'conto_id' => $conto->id,
|
|
'gestione_id' => $gestione->id,
|
|
'iban' => 'IT02X0000000000000000000',
|
|
'data' => '2026-07-01',
|
|
'valuta' => '2026-07-01',
|
|
'descrizione' => 'Test movement unreconciled',
|
|
'importo' => -100.00,
|
|
'row_hash' => md5('test_movement_501'),
|
|
]);
|
|
|
|
session(['netgescon.stabile_attivo_id' => $stabile->id]);
|
|
|
|
$page = new DebitiPagareHub();
|
|
$page->mount();
|
|
|
|
// Verify movements tab loads correctly
|
|
$page->setTab('movimenti');
|
|
expect($page->movimenti)->toHaveCount(1);
|
|
expect($page->movimenti[0]['id'])->toBe(501);
|
|
expect($page->movimenti[0]['stato'])->toBe('da_quadrare');
|
|
|
|
// Verify historical debts at target date (2026-12-31)
|
|
$page->setTab('stato_debiti');
|
|
$page->targetDate = '2026-12-31';
|
|
$page->loadDebitiStorici();
|
|
|
|
// 991 (paid late on 2027-01-15) and 992 (unpaid) are debts at 2026-12-31.
|
|
// 993 (dated 2027-01-01) is NOT a debt at 2026-12-31.
|
|
expect($page->debitiStorici)->toHaveCount(2);
|
|
|
|
$ids = collect($page->debitiStorici)->pluck('id')->all();
|
|
expect($ids)->toContain(991);
|
|
expect($ids)->toContain(992);
|
|
expect($ids)->not->toContain(993);
|
|
|
|
// Verify pay dates/closures
|
|
$invoice992 = collect($page->debitiStorici)->firstWhere('id', 992);
|
|
expect($invoice992['data_chiusura'])->toBe('Ancora aperto');
|
|
|
|
expect($page->totaleDebitiStorici)->toBe(1100.0);
|
|
});
|
|
|
|
test('it automatically reconciles F24 withholding tax and CBILL via numeric code and fallback text', function () {
|
|
$user = User::factory()->create();
|
|
$user->assignRole('super-admin');
|
|
$this->actingAs($user);
|
|
|
|
$amministratore = Amministratore::create([
|
|
'user_id' => $user->id,
|
|
'nome' => 'Admin',
|
|
'cognome' => 'Test',
|
|
'denominazione' => 'Amministrazione Test',
|
|
'codice_fiscale' => '12345678901',
|
|
]);
|
|
|
|
$stabile = Stabile::create([
|
|
'amministratore_id' => $amministratore->id,
|
|
'codice_stabile' => '9999',
|
|
'denominazione' => 'Condominio Test Contabilita',
|
|
'codice_fiscale' => '12345678901',
|
|
'indirizzo' => 'Via Test 1',
|
|
'citta' => 'Roma',
|
|
'cap' => '00100',
|
|
'provincia' => 'RM',
|
|
'codice_destinatario_sdi' => '0000000',
|
|
]);
|
|
|
|
$gestione = GestioneContabile::create([
|
|
'tenant_id' => 'default',
|
|
'stabile_id' => $stabile->id,
|
|
'anno_gestione' => 2026,
|
|
'tipo_gestione' => 'ordinaria',
|
|
'denominazione' => 'Gestione Ordinaria 2026',
|
|
'data_inizio' => '2026-01-01',
|
|
'data_fine' => '2026-12-31',
|
|
'stato' => 'aperta',
|
|
'protocollo_prefix' => 'O2026',
|
|
]);
|
|
|
|
$conto = DatiBancari::create([
|
|
'stabile_id' => $stabile->id,
|
|
'tipo_conto' => 'corrente',
|
|
'denominazione_banca' => 'Unicredit',
|
|
'numero_conto' => '123456',
|
|
'iban' => 'IT02X0000000000000000000',
|
|
'saldo_iniziale' => 10000.00,
|
|
'stato_conto' => 'attivo',
|
|
'is_nostro_conto' => true,
|
|
]);
|
|
|
|
// Create a rule for F24 and Bollo/Competenze cost accounts
|
|
DB::table('contabilita_piano_conti')->insertOrIgnore([
|
|
['id' => 7, 'codice' => '1020', 'denominazione' => 'Banca c/c', 'tipo_conto' => 'ATTIVO', 'attivo' => 1, 'livello' => 2, 'codice_padre' => '100', 'saldo_iniziale' => 0.00],
|
|
['id' => 822, 'codice' => '822', 'denominazione' => 'Spese postali e bolli', 'tipo_conto' => 'COSTO', 'attivo' => 1, 'livello' => 1, 'codice_padre' => null, 'saldo_iniziale' => 0.00],
|
|
['id' => 198, 'codice' => '1980', 'denominazione' => 'Spese tenuta conto', 'tipo_conto' => 'COSTO', 'attivo' => 1, 'livello' => 1, 'codice_padre' => null, 'saldo_iniziale' => 0.00],
|
|
['id' => 900, 'codice' => '900', 'denominazione' => 'Erario c/ritenute', 'tipo_conto' => 'PASSIVO', 'attivo' => 1, 'livello' => 1, 'codice_padre' => null, 'saldo_iniziale' => 0.00],
|
|
]);
|
|
|
|
RegolaPrimaNota::create([
|
|
'stabile_id' => $stabile->id,
|
|
'origine' => 'banca',
|
|
'chiave' => '219', // Bollo
|
|
'conto_dare_id' => 7,
|
|
'conto_avere_id' => 822,
|
|
'attiva' => true,
|
|
'label' => 'Bollo',
|
|
]);
|
|
|
|
RegolaPrimaNota::create([
|
|
'stabile_id' => $stabile->id,
|
|
'origine' => 'banca',
|
|
'chiave' => '198', // Competenze
|
|
'conto_dare_id' => 7,
|
|
'conto_avere_id' => 198,
|
|
'attiva' => true,
|
|
'label' => 'Competenze',
|
|
]);
|
|
|
|
RegolaPrimaNota::create([
|
|
'stabile_id' => $stabile->id,
|
|
'origine' => 'banca',
|
|
'chiave' => 'F24', // F24
|
|
'conto_dare_id' => 7,
|
|
'conto_avere_id' => 900,
|
|
'attiva' => true,
|
|
'label' => 'F24',
|
|
]);
|
|
|
|
$fornitore = Fornitore::create([
|
|
'amministratore_id' => $amministratore->id,
|
|
'ragione_sociale' => 'ACEA ATO 2 SPA',
|
|
'codice_fiscale' => '00325478955',
|
|
'partita_iva' => '00325478955',
|
|
]);
|
|
|
|
// Mock Withholding Tax (RA) record
|
|
$ra = \App\Models\RegistroRitenuteAcconto::create([
|
|
'tenant_id' => 'default',
|
|
'gestione_id' => $gestione->id,
|
|
'fornitore_id' => $fornitore->id,
|
|
'numero_progressivo' => 1,
|
|
'data_competenza' => '2026-06-15',
|
|
'imponibile' => 1000.00,
|
|
'aliquota_ritenuta' => 20.00,
|
|
'importo_ritenuta' => 200.00,
|
|
'stato_versamento' => 'da_versare',
|
|
'data_scadenza_versamento' => '2026-07-16',
|
|
]);
|
|
|
|
// 1. Bank movement for F24
|
|
DB::table('contabilita_movimenti_banca')->insert([
|
|
'id' => 601,
|
|
'stabile_id' => $stabile->id,
|
|
'conto_id' => $conto->id,
|
|
'gestione_id' => $gestione->id,
|
|
'iban' => 'IT02X0000000000000000000',
|
|
'data' => '2026-07-15',
|
|
'valuta' => '2026-07-15',
|
|
'descrizione' => 'PAGAMENTO DELEGHE F23/F24 PRENOTATE PAGAMENTO FISCO/INPS/REGIONI DA ENTRATEL',
|
|
'importo' => -200.00,
|
|
'causale' => '', // Empty causale to test text fallback!
|
|
'row_hash' => md5('test_601'),
|
|
]);
|
|
|
|
// 2. Bank movement for stamp duty with different code but text match
|
|
DB::table('contabilita_movimenti_banca')->insert([
|
|
'id' => 602,
|
|
'stabile_id' => $stabile->id,
|
|
'conto_id' => $conto->id,
|
|
'gestione_id' => $gestione->id,
|
|
'iban' => 'IT02X0000000000000000000',
|
|
'data' => '2026-07-01',
|
|
'valuta' => '2026-07-01',
|
|
'descrizione' => 'IMPOSTA BOLLO CONTO CORRENTE DPR642/72-DM24/5/2012',
|
|
'importo' => -29.41,
|
|
'causale' => '822', // Mismatched code but description matches
|
|
'row_hash' => md5('test_602'),
|
|
]);
|
|
|
|
$fe = \App\Models\FatturaElettronica::create([
|
|
'tenant_id' => 'default',
|
|
'stabile_id' => $stabile->id,
|
|
'fornitore_id' => $fornitore->id,
|
|
'numero_fattura' => '2026-CBILL-9',
|
|
'data_fattura' => '2026-06-12',
|
|
'fornitore_piva' => '00325478955',
|
|
'fornitore_denominazione' => 'ACEA ATO 2 SPA',
|
|
'imponibile' => 1266.97,
|
|
'iva' => 278.73,
|
|
'totale' => 1545.70,
|
|
'pagamento_cbill' => '125007300041415467',
|
|
'pagamento_tipo' => 'MP08',
|
|
'file_nome' => 'test.xml',
|
|
]);
|
|
|
|
DB::table('contabilita_fatture_fornitori')->insert([
|
|
'id' => 995,
|
|
'stabile_id' => $stabile->id,
|
|
'gestione_id' => $gestione->id,
|
|
'fornitore_id' => $fornitore->id,
|
|
'fattura_elettronica_id' => $fe->id,
|
|
'numero_documento' => '2026-CBILL-9',
|
|
'totale' => 1545.70,
|
|
'netto_da_pagare' => 1545.70,
|
|
'stato' => 'da_pagare',
|
|
'data_documento' => '2026-06-12',
|
|
]);
|
|
|
|
DB::table('contabilita_movimenti_banca')->insert([
|
|
'id' => 603,
|
|
'stabile_id' => $stabile->id,
|
|
'conto_id' => $conto->id,
|
|
'gestione_id' => $gestione->id,
|
|
'iban' => 'IT02X0000000000000000000',
|
|
'data' => '2026-07-20',
|
|
'valuta' => '2026-07-20',
|
|
'descrizione' => 'DISPOSIZIONE DI ADDEBITO GENERICA BOLLETTINO ACEA ATO2 SPA - 125007300041415467',
|
|
'importo' => -1545.70,
|
|
'causale' => '012',
|
|
'row_hash' => md5('test_603'),
|
|
]);
|
|
|
|
session(['netgescon.stabile_attivo_id' => $stabile->id]);
|
|
|
|
$page = new CasseBancheRiepilogo();
|
|
$page->riconciliaSpeseBancarieAutomaticamente();
|
|
|
|
// 1. Verify RA F24 payment was reconciled
|
|
$raReloaded = \App\Models\RegistroRitenuteAcconto::find($ra->id);
|
|
expect($raReloaded->stato_versamento)->toBe('versata');
|
|
expect($raReloaded->data_versamento->toDateString())->toBe('2026-07-15');
|
|
expect($raReloaded->f24_riferimento)->toContain('ENTRATEL');
|
|
|
|
// 2. Verify 601 and 602 got a contabile registration (Prima Nota)
|
|
$m601 = MovimentoBanca::find(601);
|
|
expect($m601->registrazione_id)->not->toBeNull();
|
|
|
|
$m602 = MovimentoBanca::find(602);
|
|
expect($m602->registrazione_id)->not->toBeNull();
|
|
|
|
// 3. Verify CBILL numeric code matched and paid the invoice
|
|
$invoice = DB::table('contabilita_fatture_fornitori')->where('id', 995)->first();
|
|
expect($invoice->stato)->toBe('pagato');
|
|
expect($invoice->movimento_pagamento_id)->toBe(603);
|
|
});
|