Merge branch 'master' of github.com:akaunting/akaunting

This commit is contained in:
Cüneyt Şentürk
2023-05-31 14:40:15 +03:00
10 changed files with 139 additions and 23 deletions

View File

@ -34,6 +34,22 @@ class Uploads extends Controller
return $this->streamMedia($media);
}
public function inline($id)
{
try {
$media = Media::find($id);
} catch (\Exception $e) {
return response(null, 204);
}
// Get file path
if (!$this->getMediaPathOnStorage($media)) {
return response(null, 204);
}
return $this->streamMedia($media, 'inline');
}
/**
* Get the specified resource.
*

View File

@ -14,9 +14,10 @@ class CustomMail extends FormRequest
public function rules()
{
return [
'to' => 'required|email',
'subject' => 'required|string',
'body' => 'required|string',
'to' => 'required|email',
'subject' => 'required|string',
'body' => 'required|string',
'attachments.*' => 'nullable|boolean',
];
}
}

View File

@ -30,10 +30,15 @@ class SendDocumentAsCustomMail extends Job
$custom_mail['cc'] = user()->email;
}
$attachments = collect($this->request->get('attachments', []))
->filter(fn($value) => $value == true)
->keys()
->all();
$notification = config('type.document.' . $document->type . '.notification.class');
// Notify the contact
$document->contact->notify(new $notification($document, $this->template_alias, true, $custom_mail));
$document->contact->notify(new $notification($document, $this->template_alias, true, $custom_mail, $attachments));
event(new DocumentSent($document));
}

View File

@ -35,10 +35,17 @@ class Invoice extends Notification
*/
public $attach_pdf;
/**
* List of document attachments to attach when sending the email.
*
* @var array
*/
public $attachments;
/**
* Create a notification instance.
*/
public function __construct(Document $invoice = null, string $template_alias = null, bool $attach_pdf = false, array $custom_mail = [])
public function __construct(Document $invoice = null, string $template_alias = null, bool $attach_pdf = false, array $custom_mail = [], $attachments = [])
{
parent::__construct();
@ -46,6 +53,7 @@ class Invoice extends Notification
$this->template = EmailTemplate::alias($template_alias)->first();
$this->attach_pdf = $attach_pdf;
$this->custom_mail = $custom_mail;
$this->attachments = $attachments;
}
/**
@ -68,6 +76,17 @@ class Invoice extends Notification
]);
}
// Attach selected attachments
if (! empty($this->invoice->attachment)) {
foreach ($this->invoice->attachment as $attachment) {
if (in_array($attachment->id, $this->attachments)) {
$message->attach($attachment->getAbsolutePath(), [
'mime' => $attachment->mime_type,
]);
}
}
}
return $message;
}

View File

@ -118,7 +118,7 @@ trait Uploads
return $path;
}
public function streamMedia($media)
public function streamMedia($media, $disposition = 'attachment')
{
return response()->streamDownload(
function() use ($media) {
@ -133,6 +133,7 @@ trait Uploads
'Content-Type' => $media->mime_type,
'Content-Length' => $media->size,
],
$disposition,
);
}

View File

@ -20,11 +20,7 @@ class NumberDigit extends Form
if (empty($this->name)) {
$this->name = 'number_digit';
}
if (empty($this->label)) {
$this->label = trans('settings.invoice.digit');
}
$this->number_digits = [
'1' => '1',
'2' => '2',