1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 23:52:33 +01:00
invoiceninja/app/Http/Controllers/ClientPortal/StatementController.php

60 lines
1.8 KiB
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2024-04-12 06:15:41 +02:00
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\Controllers\ClientPortal;
use App\Http\Controllers\Controller;
2021-09-15 17:23:07 +02:00
use App\Http\Requests\ClientPortal\Statements\ShowStatementRequest;
use Illuminate\Http\JsonResponse;
use Illuminate\View\View;
use Symfony\Component\HttpFoundation\StreamedResponse;
class StatementController extends Controller
{
2021-09-15 17:23:07 +02:00
/**
2021-09-16 14:21:29 +02:00
* Show the statement in the client portal.
*
2023-10-26 04:57:44 +02:00
* @return \Illuminate\View\View
2021-09-15 17:23:07 +02:00
*/
public function index(): View
2021-09-07 18:00:22 +02:00
{
return render('statement.index');
}
2021-09-15 17:23:07 +02:00
/**
2021-09-16 14:21:29 +02:00
* Show the raw stream of the PDF.
*
* @param ShowStatementRequest $request
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Routing\ResponseFactory|JsonResponse|\Illuminate\Http\Response|StreamedResponse
2021-09-15 17:23:07 +02:00
*/
public function raw(ShowStatementRequest $request)
{
$pdf = $request->client()->service()->statement(
2023-04-26 02:56:23 +02:00
$request->only(['start_date', 'end_date', 'show_payments_table', 'show_aging_table', 'show_credits_table', 'status'])
2021-09-15 17:23:07 +02:00
);
2021-09-16 14:21:29 +02:00
2021-09-15 17:23:07 +02:00
if ($pdf && $request->query('download')) {
return response()->streamDownload(function () use ($pdf) {
echo $pdf;
}, 'statement.pdf', ['Content-Type' => 'application/pdf']);
}
if ($pdf) {
return response($pdf, 200)->withHeaders([
'Content-Type' => 'application/pdf',
]);
}
return response()->json(['message' => 'Something went wrong. Please check logs.']);
}
}