osb/app/Http/Controllers/InvoiceController.php
Deon George d662328903
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 35s
Create Docker Image / Final Docker Image Manifest (push) Successful in 10s
Temporarily fix invoice emailing
2024-07-06 10:37:44 +10:00

55 lines
1.2 KiB
PHP

<?php
namespace App\Http\Controllers;
use Clarkeash\Doorman\Exceptions\{ExpiredInviteCode,InvalidInviteCode,NotYourInviteCode};
use Clarkeash\Doorman\Facades\Doorman;
use Illuminate\View\View;
use Barryvdh\Snappy\Facades\SnappyPdf as PDF;
use App\Models\Invoice;
/**
* Class InvoiceController
* This controller manages invoices
*
* The methods to this controller should be projected by the route
*
* @package App\Http\Controllers
*/
class InvoiceController extends Controller
{
/**
* Return the invoice in PDF format, ready to download
*
* @param Invoice $o
* @return mixed
*/
public function pdf(Invoice $o)
{
return PDF::loadView('theme.backend.adminlte.u.invoice.home',['o'=>$o])
->stream(sprintf('%s.pdf',$o->sid));
}
/**
* Render a specific invoice for the user
*
* @param Invoice $o
* @param string|null $code
* @return View
*/
public function view(Invoice $o,string $code=NULL): View
{
if ($code) {
try {
Doorman::redeem($code,$o->account->user->email);
} catch (ExpiredInviteCode|InvalidInviteCode|NotYourInviteCode $e) {
abort(404);
}
}
return view('theme.backend.adminlte.invoice.view')
->with('o',$o);
}
}