20-02-2026
This commit is contained in:
parent
7325edebbd
commit
4a8f4b4abc
250 changed files with 28575 additions and 8889 deletions
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Services\Invoice;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\UserInvoice;
|
||||
use Illuminate\Bus\Queueable;
|
||||
|
|
@ -14,39 +14,83 @@ class MailInvoice extends Mailable
|
|||
use Queueable, SerializesModels;
|
||||
|
||||
protected $shopping_order;
|
||||
|
||||
protected $user_invoice;
|
||||
|
||||
public $subject;
|
||||
|
||||
|
||||
public function __construct(ShoppingOrder $shopping_order, UserInvoice $user_invoice)
|
||||
{
|
||||
$this->shopping_order = $shopping_order;
|
||||
$this->user_invoice = $user_invoice;
|
||||
$this->subject = __('email.invoice_subject').': '.$shopping_order->getLastShoppingPayment('reference') ;
|
||||
|
||||
// Unterscheide zwischen Stornorechnung und normaler Rechnung
|
||||
$isCancellation = $user_invoice->cancellation && ! $user_invoice->cancellation_id;
|
||||
|
||||
if ($isCancellation) {
|
||||
$this->subject = __('email.cancellation_invoice_subject').': '.$shopping_order->getLastShoppingPayment('reference');
|
||||
} else {
|
||||
$this->subject = __('email.invoice_subject').': '.$shopping_order->getLastShoppingPayment('reference');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function build()
|
||||
{
|
||||
$title = __('email.invoice_title');
|
||||
$copy1line = __('email.invoice_copy1line').$this->shopping_order->getLastShoppingPayment('reference');
|
||||
// Unterscheide zwischen Stornorechnung und normaler Rechnung
|
||||
$isCancellation = $this->user_invoice->cancellation && ! $this->user_invoice->cancellation_id;
|
||||
|
||||
$filename = $this->user_invoice->filename;
|
||||
$disk = $this->user_invoice->disk;
|
||||
$path = $this->user_invoice->getDownloadPath();
|
||||
if (!Storage::disk($disk)->exists($path)) {
|
||||
if ($isCancellation) {
|
||||
$title = __('email.cancellation_invoice_title');
|
||||
$copy1line = __('email.cancellation_invoice_copy1line').$this->shopping_order->getLastShoppingPayment('reference');
|
||||
} else {
|
||||
$title = __('email.invoice_title');
|
||||
$copy1line = __('email.invoice_copy1line').$this->shopping_order->getLastShoppingPayment('reference');
|
||||
}
|
||||
|
||||
$disk = $this->user_invoice->disk;
|
||||
|
||||
// 1. Deutsches Original immer anhängen
|
||||
$pathDe = $this->user_invoice->getDownloadPath();
|
||||
$filenameDe = $this->user_invoice->filename;
|
||||
|
||||
if (! Storage::disk($disk)->exists($pathDe)) {
|
||||
return;
|
||||
}
|
||||
$file = Storage::disk($disk)->path($path);
|
||||
$file = str_replace('//', '/', $file);
|
||||
$mime = Storage::disk($disk)->mimeType($path);
|
||||
|
||||
return $this->view('emails.blank')->with([
|
||||
$fileDe = Storage::disk($disk)->path($pathDe);
|
||||
$fileDe = str_replace('//', '/', $fileDe);
|
||||
$mimeDe = Storage::disk($disk)->mimeType($pathDe);
|
||||
|
||||
$mail = $this->view('emails.blank')->with([
|
||||
'title' => $title,
|
||||
'copy1line' => $copy1line,
|
||||
])->attach($file,[
|
||||
'as' => $filename,
|
||||
'mime' => $mime,
|
||||
]); // attach file;
|
||||
'copy1line' => $copy1line,
|
||||
])->attach($fileDe, [
|
||||
'as' => $filenameDe,
|
||||
'mime' => $mimeDe,
|
||||
]);
|
||||
|
||||
// 2. Lokalisierte Version zusätzlich anhängen (wenn vorhanden und != DE)
|
||||
$locale = $this->shopping_order->shopping_user
|
||||
? $this->shopping_order->shopping_user->getLocale()
|
||||
: 'de';
|
||||
|
||||
if ($locale && $locale !== 'de') {
|
||||
$pathLocale = $this->user_invoice->getDownloadPathLocale($locale);
|
||||
$filenameLocale = $this->user_invoice->getFilenameLocale($locale);
|
||||
|
||||
// Nur anhängen wenn lokalisierte Version existiert und nicht gleich dem Original ist
|
||||
if (Storage::disk($disk)->exists($pathLocale) && $pathLocale !== $pathDe) {
|
||||
$fileLocale = Storage::disk($disk)->path($pathLocale);
|
||||
$fileLocale = str_replace('//', '/', $fileLocale);
|
||||
$mimeLocale = Storage::disk($disk)->mimeType($pathLocale);
|
||||
|
||||
$mail->attach($fileLocale, [
|
||||
'as' => $filenameLocale,
|
||||
'mime' => $mimeLocale,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return $mail;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue