Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

akaunting/akaunting

9348 stars
3 code files
View akaunting/akaunting on GitHub

app/Abstracts/Notification.php

Open in GitHub
use Illuminate\Notifications\Notification as BaseNotification;
 
abstract class Notification extends BaseNotification
{
public function initMessage()
{
app('url')->defaults(['company_id' => company_id()]);
 
$message = (new MailMessage)
->from(config('mail.from.address'), config('mail.from.name'))
->subject($this->getSubject())
->view('partials.email.body', ['body' => $this->getBody()]);
 
return $message;
}
}

app/Notifications/Sale/Invoice.php

Open in GitHub
use App\Abstracts\Notification;
use App\Models\Common\EmailTemplate;
 
class Invoice extends Notification
{
public $invoice;
 
public $template;
 
public $attach_pdf;
 
public function __construct($invoice = null, $template_alias = null, $attach_pdf = false)
{
parent::__construct();
 
$this->invoice = $invoice;
$this->template = EmailTemplate::alias($template_alias)->first();
$this->attach_pdf = $attach_pdf;
}
 
public function toMail($notifiable)
{
$message = $this->initMessage();
 
// Attach the PDF file
if ($this->attach_pdf) {
$message->attach($this->storeDocumentPdfAndGetPath($this->invoice), [
'mime' => 'application/pdf',
]);
}
 
return $message;
}
}

app/Http/Controllers/Sales/Invoices.php

Open in GitHub
use App\Notifications\Sale\Invoice as Notification;
use App\Abstracts\Http\Controller;
 
class Invoices extends Controller
{
//
public function emailInvoice(Document $invoice)
{
if (empty($invoice->contact_email)) {
return redirect()->back();
}
 
// Notify the customer
$invoice->contact->notify(new Notification($invoice, 'invoice_new_customer', true));
 
event(new \App\Events\Document\DocumentSent($invoice));
 
flash(trans('documents.messages.email_sent', ['type' => trans_choice('general.invoices', 1)]))->success();
 
return redirect()->back();
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.