Nachtrag zum Lieferschein-Fix (7d77314): Fehlte die Rechnungs-PDF auf der
Platte (Altdaten), brach MailLogistic::build() still ab — die Mail ging ohne
Anhänge bzw. gar nicht raus, obwohl das UI Erfolg meldete. Jetzt wird die
Rechnung wie der Lieferschein mit bestehender Rechnungsnummer regeneriert.
Hinweise-Doku und Plan-Protokoll fortgeschrieben.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
91 lines
3.2 KiB
PHP
91 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Mail;
|
|
|
|
use App\Models\ShoppingOrder;
|
|
use App\Repositories\InvoiceRepository;
|
|
use App\Services\Invoice;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Mail\Mailable;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Storage;
|
|
|
|
class MailLogistic extends Mailable
|
|
{
|
|
use Queueable, SerializesModels;
|
|
|
|
protected $shopping_order;
|
|
|
|
public $subject;
|
|
|
|
public function __construct(ShoppingOrder $shopping_order)
|
|
{
|
|
$this->shopping_order = $shopping_order;
|
|
$name = $shopping_order->shopping_user->billing_firstname.' '.$shopping_order->shopping_user->billing_lastname;
|
|
$company = $shopping_order->shopping_user->billing_company ?? '';
|
|
|
|
$hasWhiteLabel = $shopping_order->user_white_label || $shopping_order->hasWhitelabelProducts();
|
|
|
|
$this->subject = 'Partner';
|
|
if ($hasWhiteLabel) {
|
|
// Bei allen, die ein eigenes Logo haben
|
|
$this->subject .= ' (mit Logo)';
|
|
} else {
|
|
// Bei allen, die kein Tattoostudio sind
|
|
$this->subject = ' - ';
|
|
}
|
|
if ($shopping_order->shopping_user->same_as_billing) {
|
|
// Rechnungsadresse und Lieferadresse sind gleich
|
|
$this->subject = '';
|
|
} else {
|
|
// hat eine andere Lieferadresse
|
|
$this->subject = ' Lieferadresse';
|
|
}
|
|
$this->subject .= ' '.$company.' ('.$name.')';
|
|
|
|
}
|
|
|
|
public function build()
|
|
{
|
|
$title = false;
|
|
$copy1line = false;
|
|
|
|
$filename = Invoice::getFilename($this->shopping_order);
|
|
$path = Invoice::getDownloadPath($this->shopping_order);
|
|
if (! Storage::disk('public')->exists($path)) {
|
|
// Datei fehlt auf der Platte (Altdaten) — mit bestehender Nummer neu erzeugen
|
|
(new InvoiceRepository($this->shopping_order))->update([]);
|
|
}
|
|
if (! Storage::disk('public')->exists($path)) {
|
|
return;
|
|
}
|
|
$file = Storage::disk('public')->path($path);
|
|
$mime = Storage::disk('public')->mimeType($path);
|
|
|
|
$mail = $this->view('emails.logistic')->with([
|
|
'title' => $title,
|
|
'copy1line' => $copy1line,
|
|
])->attach($file, [
|
|
'as' => $filename,
|
|
'mime' => $mime,
|
|
]);
|
|
|
|
// Kundenanforderung 16.07.2026: Der Lieferschein (mit der Lieferadresse der
|
|
// Bestellung) wird IMMER mitgesendet — unabhängig von White-Label/Logo.
|
|
// Vorher hing er nur bei White-Label-Bestellungen an; Folge waren
|
|
// Fehlversände an die Rechnungsadresse.
|
|
$pathDelivery = Invoice::getDownloadPathDelivery($this->shopping_order);
|
|
if (! Storage::disk('public')->exists($pathDelivery)) {
|
|
// Datei fehlt auf der Platte (Altdaten) — mit bestehender Nummer neu erzeugen
|
|
(new InvoiceRepository($this->shopping_order))->update([]);
|
|
}
|
|
if (Storage::disk('public')->exists($pathDelivery)) {
|
|
$mail->attach(Storage::disk('public')->path($pathDelivery), [
|
|
'as' => Invoice::getDeliveryFilename($this->shopping_order),
|
|
'mime' => Storage::disk('public')->mimeType($pathDelivery),
|
|
]);
|
|
}
|
|
|
|
return $mail;
|
|
}
|
|
}
|