2022-07-29 06:06:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2024-07-06 00:28:45 +00:00
|
|
|
use Clarkeash\Doorman\Exceptions\{ExpiredInviteCode,InvalidInviteCode,NotYourInviteCode};
|
|
|
|
use Clarkeash\Doorman\Facades\Doorman;
|
2024-08-10 00:14:47 +00:00
|
|
|
use Illuminate\Http\Request;
|
2022-07-29 06:06:19 +00:00
|
|
|
use Illuminate\View\View;
|
|
|
|
use Barryvdh\Snappy\Facades\SnappyPdf as PDF;
|
|
|
|
|
2024-08-10 00:14:47 +00:00
|
|
|
use App\Models\{Account,Invoice};
|
2022-07-29 06:06:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
{
|
2024-08-10 00:14:47 +00:00
|
|
|
/**
|
|
|
|
* Show a list of invoices to apply payments to
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
|
|
|
public function api_account_invoices(Request $request): \Illuminate\Contracts\View\View
|
|
|
|
{
|
|
|
|
session()->flashInput($request->post('old',[]));
|
|
|
|
|
|
|
|
return view('theme.backend.adminlte.payment.widget.invoices')
|
|
|
|
->with('pid',$request->post('pid'))
|
|
|
|
->with('o',Account::findOrFail($request->post('aid')));
|
|
|
|
}
|
|
|
|
|
2022-07-29 06:06:19 +00:00
|
|
|
/**
|
|
|
|
* Return the invoice in PDF format, ready to download
|
|
|
|
*
|
|
|
|
* @param Invoice $o
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function pdf(Invoice $o)
|
|
|
|
{
|
2024-07-04 05:03:11 +00:00
|
|
|
return PDF::loadView('theme.backend.adminlte.u.invoice.home',['o'=>$o])
|
|
|
|
->stream(sprintf('%s.pdf',$o->sid));
|
2022-07-29 06:06:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render a specific invoice for the user
|
|
|
|
*
|
|
|
|
* @param Invoice $o
|
2024-07-06 00:28:45 +00:00
|
|
|
* @param string|null $code
|
2022-07-29 06:06:19 +00:00
|
|
|
* @return View
|
|
|
|
*/
|
2024-07-06 00:28:45 +00:00
|
|
|
public function view(Invoice $o,string $code=NULL): View
|
2022-07-29 06:06:19 +00:00
|
|
|
{
|
2024-07-06 00:28:45 +00:00
|
|
|
if ($code) {
|
|
|
|
try {
|
|
|
|
Doorman::redeem($code,$o->account->user->email);
|
|
|
|
|
|
|
|
} catch (ExpiredInviteCode|InvalidInviteCode|NotYourInviteCode $e) {
|
|
|
|
abort(404);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-04 05:03:11 +00:00
|
|
|
return view('theme.backend.adminlte.invoice.view')
|
|
|
|
->with('o',$o);
|
2022-07-29 06:06:19 +00:00
|
|
|
}
|
|
|
|
}
|