mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Rendering PDF stream in client portal
This commit is contained in:
parent
77f9c95139
commit
7be7d2a9da
@ -13,11 +13,47 @@
|
||||
namespace App\Http\Controllers\ClientPortal;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\ClientPortal\Statements\ShowStatementRequest;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\View\View;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
class StatementController extends Controller
|
||||
{
|
||||
public function index()
|
||||
/**
|
||||
* Show the statement in the client portal.
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
return render('statement.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the raw stream of statement PDF.
|
||||
*
|
||||
* @param ShowStatementRequest $request
|
||||
* @return StreamedResponse|JsonResponse
|
||||
*/
|
||||
public function raw(ShowStatementRequest $request)
|
||||
{
|
||||
$pdf = $request->client()->service()->statement(
|
||||
$request->only(['start_date', 'end_date', 'show_payments_table', 'show_aging_table'])
|
||||
);
|
||||
|
||||
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.']);
|
||||
}
|
||||
}
|
||||
|
@ -12,12 +12,38 @@
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use Illuminate\View\View;
|
||||
use Livewire\Component;
|
||||
|
||||
class Statement extends Component
|
||||
{
|
||||
public function render()
|
||||
public string $url;
|
||||
|
||||
public array $options = [
|
||||
'show_payments_table' => 0,
|
||||
'show_aging_table' => 0,
|
||||
];
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->options['start_date'] = now()->startOfYear()->format('Y-m-d');
|
||||
$this->options['end_date'] = now()->format('Y-m-d');
|
||||
}
|
||||
|
||||
protected function getCurrentUrl(): string
|
||||
{
|
||||
return route('client.statement.raw', $this->options);
|
||||
}
|
||||
|
||||
public function download()
|
||||
{
|
||||
return redirect()->route('client.statement.raw', \array_merge($this->options, ['download' => 1]));
|
||||
}
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
$this->url = route('client.statement.raw', $this->options);
|
||||
|
||||
return render('components.statement');
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\ClientPortal\Statements;
|
||||
|
||||
use App\Models\Client;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ShowStatementRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'show_payments_table' => $this->has('show_payments_table') ? \boolval($this->show_payments_table) : false,
|
||||
'show_aging_table' => $this->has('show_aging_table') ? \boolval($this->show_aging_table) : false,
|
||||
]);
|
||||
}
|
||||
|
||||
public function client(): Client
|
||||
{
|
||||
return auth('contact')->user()->client;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user