mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-09-01 21:00:58 +00:00
* refactor: stabilize model identities for domain migration * refactor: extract module platform context * refactor: assign models to domain contexts * refactor: extract ai platform context * refactor: extract storage platform context * refactor: extract mail platform context * refactor: extract pdf platform context * refactor: extract operations platform context * refactor: move installation into operations platform * refactor: extract money domain context * refactor: extract taxation domain context * refactor: extract catalog domain context * refactor: extract metadata domain context * refactor: extract reporting domain context * refactor: extract purchases domain context * refactor: extract receivables domain context * refactor: extract accounts domain context * refactor: complete reporting statement boundary * refactor: extract contacts domain context * refactor: extract sales domain context * refactor: remove legacy application layers * fix: migrate legacy bouncer role identities
65 lines
2.4 KiB
PHP
65 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Sales\Http\Controllers\CustomerPortal;
|
|
|
|
use App\Domains\Accounts\Models\CompanySetting;
|
|
use App\Domains\Contacts\Models\Customer;
|
|
use App\Domains\Sales\Http\Resources\CustomerPortal\InvoiceResource as CustomerInvoiceResource;
|
|
use App\Domains\Sales\Mail\InvoiceViewedMail;
|
|
use App\Domains\Sales\Models\Invoice;
|
|
use App\Platform\Http\Controller;
|
|
use App\Platform\Mail\Models\EmailLog;
|
|
use Illuminate\Http\Request;
|
|
|
|
class InvoicePdfController extends Controller
|
|
{
|
|
public function getPdf(EmailLog $emailLog, Request $request)
|
|
{
|
|
// Resolve the document through the morph relation and enforce the
|
|
// expected type — a token issued for another mailable type (or whose
|
|
// numeric id collides) must not disclose an invoice.
|
|
$invoice = $emailLog->mailable;
|
|
abort_unless($invoice instanceof Invoice, 404);
|
|
abort_if($emailLog->isExpired(), 403, 'Link Expired.');
|
|
|
|
if ($invoice->status == Invoice::STATUS_SENT || $invoice->status == Invoice::STATUS_DRAFT) {
|
|
$invoice->status = Invoice::STATUS_VIEWED;
|
|
$invoice->viewed = true;
|
|
$invoice->save();
|
|
$notifyInvoiceViewed = CompanySetting::getSetting(
|
|
'notify_invoice_viewed',
|
|
$invoice->company_id
|
|
);
|
|
|
|
if ($notifyInvoiceViewed == 'YES') {
|
|
$data['invoice'] = Invoice::findOrFail($invoice->id)->toArray();
|
|
$data['user'] = Customer::find($invoice->customer_id)->toArray();
|
|
$notificationEmail = CompanySetting::getSetting(
|
|
'notification_email',
|
|
$invoice->company_id
|
|
);
|
|
|
|
\Mail::to($notificationEmail)->send(new InvoiceViewedMail($data));
|
|
}
|
|
}
|
|
|
|
if ($request->has('pdf')) {
|
|
return $invoice->getGeneratedPDFOrStream('invoice');
|
|
}
|
|
|
|
return view('app')->with([
|
|
'customer_logo' => get_company_setting('customer_portal_logo', $invoice->company_id),
|
|
'current_theme' => get_company_setting('customer_portal_theme', $invoice->company_id),
|
|
]);
|
|
}
|
|
|
|
public function getInvoice(EmailLog $emailLog)
|
|
{
|
|
$invoice = $emailLog->mailable;
|
|
abort_unless($invoice instanceof Invoice, 404);
|
|
abort_if($emailLog->isExpired(), 403, 'Link Expired.');
|
|
|
|
return new CustomerInvoiceResource($invoice);
|
|
}
|
|
}
|