diff --git a/app/Http/Controllers/Common/Uploads.php b/app/Http/Controllers/Common/Uploads.php
index c29ce9159..ed7f809c0 100644
--- a/app/Http/Controllers/Common/Uploads.php
+++ b/app/Http/Controllers/Common/Uploads.php
@@ -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.
*
diff --git a/app/Http/Requests/Common/CustomMail.php b/app/Http/Requests/Common/CustomMail.php
index ce449794b..24d3133d6 100644
--- a/app/Http/Requests/Common/CustomMail.php
+++ b/app/Http/Requests/Common/CustomMail.php
@@ -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',
];
}
}
diff --git a/app/Jobs/Document/SendDocumentAsCustomMail.php b/app/Jobs/Document/SendDocumentAsCustomMail.php
index 986c69570..c5ca10fe7 100644
--- a/app/Jobs/Document/SendDocumentAsCustomMail.php
+++ b/app/Jobs/Document/SendDocumentAsCustomMail.php
@@ -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));
}
diff --git a/app/Notifications/Sale/Invoice.php b/app/Notifications/Sale/Invoice.php
index 4c0033915..8c5ebc97b 100644
--- a/app/Notifications/Sale/Invoice.php
+++ b/app/Notifications/Sale/Invoice.php
@@ -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;
}
diff --git a/app/Traits/Uploads.php b/app/Traits/Uploads.php
index 4c73bc920..3230abaa6 100644
--- a/app/Traits/Uploads.php
+++ b/app/Traits/Uploads.php
@@ -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,
);
}
diff --git a/app/View/Components/Form/Group/NumberDigit.php b/app/View/Components/Form/Group/NumberDigit.php
index 9078750fa..9323b8184 100644
--- a/app/View/Components/Form/Group/NumberDigit.php
+++ b/app/View/Components/Form/Group/NumberDigit.php
@@ -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',
diff --git a/resources/lang/en-GB/general.php b/resources/lang/en-GB/general.php
index 373f92d87..21be355d0 100644
--- a/resources/lang/en-GB/general.php
+++ b/resources/lang/en-GB/general.php
@@ -230,6 +230,7 @@ return [
'go_back' => 'Go back to :type',
'validation_error' => 'Validation error',
'dismiss' => 'Dismiss',
+ 'size' => 'Size',
'card' => [
'cards' => 'Card|Cards',
diff --git a/resources/views/modals/invoices/email.blade.php b/resources/views/modals/invoices/email.blade.php
index 3691c9d8e..db03c2da4 100644
--- a/resources/views/modals/invoices/email.blade.php
+++ b/resources/views/modals/invoices/email.blade.php
@@ -1,15 +1,91 @@
-
-
-
+
+
+
+ {{ trans('general.general') }}
+
-
-
-
-
-
-
-
+ @if ($invoice->attachment)
+
+ {{ trans_choice('general.attachments', 2) }}
+
+ @endif
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ @if ($invoice->attachment)
+
+
+
+
+
+
+
+
+
+
+
+ {{ trans('general.name') }}
+
+
+
+ {{ trans('general.size') }}
+
+
+
+
+
+ @foreach($invoice->attachment as $attachment)
+
+
+ form.attachments[e.target.name] = e.target.checked | 0">
+
+
+ @if ($attachment->aggregate_type == 'image')
+
+
 }})
+
+ @else
+
+ attach_file
+
+ @endif
+
+
+
+ {{ $attachment->basename }}
+
+
+
+ {{ $attachment->readableSize() }}
+
+
+ @endforeach
+
+
+
+ @endif
+
+
diff --git a/resources/views/settings/invoice/edit.blade.php b/resources/views/settings/invoice/edit.blade.php
index d27bb23f1..028ef7d37 100644
--- a/resources/views/settings/invoice/edit.blade.php
+++ b/resources/views/settings/invoice/edit.blade.php
@@ -14,7 +14,7 @@
-
+
diff --git a/routes/admin.php b/routes/admin.php
index be8a23405..76703b253 100644
--- a/routes/admin.php
+++ b/routes/admin.php
@@ -10,6 +10,7 @@ use Illuminate\Support\Facades\Route;
*/
Route::group(['as' => 'uploads.', 'prefix' => 'uploads'], function () {
+ Route::get('{id}/inline', 'Common\Uploads@inline')->name('inline');
Route::delete('{id}', 'Common\Uploads@destroy')->name('destroy');
});