46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Client;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Resources\Client\InvoiceResource;
|
|
use App\Models\Invoice;
|
|
use App\Services\Wallet\WalletService;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Inertia\Inertia;
|
|
|
|
class InvoiceController extends Controller
|
|
{
|
|
protected WalletService $walletService;
|
|
|
|
public function __construct(WalletService $walletService)
|
|
{
|
|
$this->walletService = $walletService;
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$invoices = Auth::user()->invoices()
|
|
->with('document')
|
|
->latest()
|
|
->paginate(10)
|
|
->withQueryString()
|
|
->onEachSide(1);
|
|
|
|
return Inertia::client('Dashboard/Invoices/Index', [
|
|
'invoices' => InvoiceResource::collection($invoices),
|
|
]);
|
|
}
|
|
|
|
public function payWithWallet(Invoice $invoice)
|
|
{
|
|
abort_unless($invoice->user_id === Auth::id(), 403);
|
|
|
|
$invoice = $this->walletService->payInvoice(Auth::user(), $invoice);
|
|
|
|
return response()->json([
|
|
'invoice' => new InvoiceResource($invoice),
|
|
]);
|
|
}
|
|
}
|