Files
hub/app/Http/Controllers/Seller/InvoiceController.php
Jon Leopard 7e5ea2bc10 checkpoint: marketplace and operational features complete, ready for Week 4 data migration
Summary of completed work:
- Complete buyer portal (browse, cart, checkout, orders, invoices)
- Complete seller portal (orders, manifests, fleet, picking)
- Business onboarding wizards (buyer 4-step, seller 5-step)
- Email verification and registration flows
- Notification system for buyers and sellers
- Payment term surcharges and pickup/delivery workflows
- Filament admin resources (Business, Brand, Product, Order, Invoice, User)
- 51 migrations executed successfully

Renamed Company -> Business throughout codebase for consistency.
Unified authentication flows with password reset.
Added audit trail and telescope for debugging.

Next: Week 4 Data Migration (Days 22-28)
- Product migration (883 products from cannabrands_crm)
- Company migration (81 buyer companies)
- User migration (preserve password hashes)
- Order history migration
2025-10-15 11:17:15 -07:00

64 lines
1.9 KiB
PHP

<?php
namespace App\Http\Controllers\Seller;
use App\Http\Controllers\Controller;
use App\Models\Invoice;
use App\Services\InvoiceService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Symfony\Component\HttpFoundation\Response;
class InvoiceController extends Controller
{
/**
* Display a listing of the seller's invoices.
*/
public function index()
{
// For now, sellers can see all invoices (matches OrderController behavior)
$invoices = Invoice::with(['order', 'company'])
->latest()
->get();
$stats = [
'total' => $invoices->count(),
'unpaid' => $invoices->where('payment_status', 'unpaid')->count(),
'partially_paid' => $invoices->where('payment_status', 'partially_paid')->count(),
'paid' => $invoices->where('payment_status', 'paid')->count(),
'overdue' => $invoices->filter(fn($inv) => $inv->isOverdue())->count(),
];
return view('seller.invoices.index', compact('invoices', 'stats'));
}
/**
* Display the specified invoice.
*/
public function show(Invoice $invoice)
{
$invoice->load(['order.items', 'company']);
return view('seller.invoices.show', compact('invoice'));
}
/**
* Download invoice PDF.
*/
public function downloadPdf(Invoice $invoice, InvoiceService $invoiceService): Response
{
// Regenerate PDF if it doesn't exist
if (!$invoice->pdf_path || !Storage::disk('local')->exists($invoice->pdf_path)) {
$invoiceService->regeneratePdf($invoice);
$invoice->refresh();
}
$pdf = Storage::disk('local')->get($invoice->pdf_path);
return response($pdf, 200, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'inline; filename="' . $invoice->invoice_number . '.pdf"',
]);
}
}