Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions modules/Ksef/Http/Admin/KsefController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,21 @@ public function index(Request $request)
}

if ($tab === 'sent') {
// A submission still pending, or one that failed on its first try,
// has no sent_at yet. It is listed in the month it was queued, so
// it stays visible and its Resend button reachable.
$records = KsefInvoice::with(['invoice.client', 'correction'])
->whereYear('sent_at', $year)
->whereMonth('sent_at', $month)
->orderByDesc('sent_at')
->where(function ($query) use ($year, $month): void {
$query->where(function ($sent) use ($year, $month): void {
$sent->whereYear('sent_at', $year)->whereMonth('sent_at', $month);
})->orWhere(function ($queued) use ($year, $month): void {
$queued->whereNull('sent_at')
->whereYear('created_at', $year)
->whereMonth('created_at', $month);
});
})
->orderByRaw('COALESCE(sent_at, created_at) DESC')
->orderByDesc('id')
->paginate(20);
} else {
$records = KsefImportedInvoice::query()
Expand Down
21 changes: 21 additions & 0 deletions tests/Feature/KsefImportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,24 @@ function ($token, $endpoint, $subject, $from, $to) use (&$ranges) {
->assertHeader('Content-Type', 'application/xml')
->assertSee('<Faktura>', false);
});

it('lists a pending or failed submission on the sent tab so it can be resent', function () {
$admin = Admin::factory()->create();
$client = Client::factory()->create();
$pending = Invoice::factory()->create(['client_id' => $client->id, 'total' => 10, 'invoice_num' => 'KSEF-PENDING-1']);
$failed = Invoice::factory()->create(['client_id' => $client->id, 'total' => 10, 'invoice_num' => 'KSEF-FAILED-1']);
$old = Invoice::factory()->create(['client_id' => $client->id, 'total' => 10, 'invoice_num' => 'KSEF-OLD-1']);

KsefInvoice::create(['invoice_id' => $pending->id, 'status' => 'pending']);
$error = KsefInvoice::create(['invoice_id' => $failed->id, 'status' => 'error', 'error_message' => 'timeout']);
$previous = KsefInvoice::create(['invoice_id' => $old->id, 'status' => 'error']);
$previous->forceFill(['created_at' => now()->subMonthsNoOverflow(2)])->save();

$this->actingAs($admin, 'admin')
->get(route('admin.ksef.index'))
->assertOk()
->assertSee('KSEF-PENDING-1')
->assertSee('KSEF-FAILED-1')
->assertSee(route('admin.ksef.resend', $error), false)
->assertDontSee('KSEF-OLD-1');
});
Loading