mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-29 03:10:51 +00:00
invoice to mail
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Http\Resources\Oasis\OasisInvoiceResource;
|
||||
use App\Models\Oasis\Client;
|
||||
use App\Models\Oasis\Invoice;
|
||||
use App\Notifications\Oasis\InvoiceDeliveryNotification;
|
||||
use App\Notifications\SharedSendViaEmail;
|
||||
use Auth;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||
@@ -96,12 +97,13 @@ class InvoiceController extends Controller
|
||||
->setPaper('a4')
|
||||
->setOrientation('portrait')
|
||||
->save(
|
||||
storage_path("/app/files/{$request->user()->id}/invoice-{$invoice->id}.pdf")
|
||||
storage_path("app/files/{$request->user()->id}/invoice-{$invoice->id}.pdf")
|
||||
);
|
||||
|
||||
if ($request->send_invoice && $invoice->client['email']) {
|
||||
Notification::route('mail', $invoice->client['email'])
|
||||
->notify(new InvoiceDeliveryNotification($request->user()));
|
||||
Notification::route('mail', $invoice->client['email'])->notify(
|
||||
new InvoiceDeliveryNotification($request->user(), $invoice)
|
||||
);
|
||||
}
|
||||
|
||||
return response(
|
||||
|
||||
@@ -15,19 +15,30 @@ function is_route($name)
|
||||
* @param $filepath
|
||||
* @return string
|
||||
*/
|
||||
function get_storage_path($filepath)
|
||||
function base64_from_storage_image($filepath)
|
||||
{
|
||||
if (is_null($filepath)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! Storage::exists($filepath)) {
|
||||
if (!Storage::exists($filepath)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return 'data:' . Storage::mimeType($filepath) . ';base64,' . base64_encode(Storage::get($filepath));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return invoice path to storage
|
||||
*
|
||||
* @param $invoice
|
||||
* @return string
|
||||
*/
|
||||
function invoice_path($invoice)
|
||||
{
|
||||
return "files/{$invoice->user_id}/invoice-{$invoice->id}.pdf";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get only tax for single invoice item
|
||||
*
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Notifications\Oasis;
|
||||
|
||||
use App\Models\Oasis\Invoice;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
@@ -11,14 +12,19 @@ class InvoiceDeliveryNotification extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
private $invoice;
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @param $user
|
||||
* @param $invoice
|
||||
*/
|
||||
public function __construct($user)
|
||||
public function __construct($user, $invoice)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->invoice = $invoice;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,7 +50,11 @@ class InvoiceDeliveryNotification extends Notification
|
||||
->subject('New invoice')
|
||||
->greeting(__t('mail_greeting'))
|
||||
->line($this->user->settings->name . ' sent you an invoice.')
|
||||
->salutation(__t('mail_salutation'));
|
||||
->salutation(__t('mail_salutation'))
|
||||
->attach(storage_path("app/" . invoice_path($this->invoice)), [
|
||||
'as' => 'name.pdf',
|
||||
'mime' => 'application/pdf',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
<div class="col-left">
|
||||
|
||||
{{--TODO: klientske logo--}}
|
||||
<img class="logo" src="{{ get_storage_path('system/5YDehSGh-vuefilemanager-horizontal-logo.svg') }}">
|
||||
<img class="logo" src="{{ base64_from_storage_image('system/5YDehSGh-vuefilemanager-horizontal-logo.svg') }}">
|
||||
|
||||
<b class="email">{{ $user->email }}</b>
|
||||
<b class="phone">{{ $user->settings->phone_number }}</b>
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Tests\Feature\Oasis;
|
||||
|
||||
use App\Models\Oasis\Client;
|
||||
use App\Notifications\Oasis\InvoiceDeliveryNotification;
|
||||
use PDF;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use App\Models\Oasis\Invoice;
|
||||
@@ -123,7 +124,7 @@ class OasisInvoiceTest extends TestCase
|
||||
[
|
||||
'description' => 'Test 1',
|
||||
'amount' => 1,
|
||||
'tax_rate' => 20,
|
||||
'tax_rate' => 0,
|
||||
'price' => 200,
|
||||
],
|
||||
]
|
||||
@@ -204,8 +205,8 @@ class OasisInvoiceTest extends TestCase
|
||||
public function user_create_new_invoice_with_storing_new_client()
|
||||
{
|
||||
Notification::fake();
|
||||
//Storage::fake('local');
|
||||
//PDF::fake();
|
||||
Storage::fake('local');
|
||||
PDF::fake();
|
||||
|
||||
$avatar = UploadedFile::fake()
|
||||
->image('fake-image.jpg');
|
||||
@@ -235,7 +236,6 @@ class OasisInvoiceTest extends TestCase
|
||||
'delivery_at' => Carbon::now()->addWeek(),
|
||||
'store_client' => true,
|
||||
'send_invoice' => true,
|
||||
|
||||
'client' => 'others',
|
||||
'client_avatar' => $avatar,
|
||||
'client_name' => 'VueFileManager Inc.',
|
||||
@@ -268,10 +268,7 @@ class OasisInvoiceTest extends TestCase
|
||||
Client::first()->getRawOriginal('avatar')
|
||||
);
|
||||
|
||||
Storage::disk('local')
|
||||
->assertExists(
|
||||
'files/' . $user->id . '/invoice-' . Invoice::first()->id . '.pdf'
|
||||
);
|
||||
PDF::assertFileNameIs(storage_path("app/" . invoice_path(Invoice::first())));
|
||||
|
||||
Notification::assertTimesSent(1, InvoiceDeliveryNotification::class);
|
||||
}
|
||||
@@ -282,6 +279,7 @@ class OasisInvoiceTest extends TestCase
|
||||
public function user_create_new_invoice_with_storing_new_client_without_avatar_and_mail()
|
||||
{
|
||||
Notification::fake();
|
||||
PDF::fake();
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create(['role' => 'user']);
|
||||
@@ -324,6 +322,8 @@ class OasisInvoiceTest extends TestCase
|
||||
'name' => 'VueFileManager Inc.',
|
||||
]);
|
||||
|
||||
PDF::assertFileNameIs(storage_path("app/" . invoice_path(Invoice::first())));
|
||||
|
||||
Notification::assertNothingSent();
|
||||
}
|
||||
|
||||
@@ -333,6 +333,7 @@ class OasisInvoiceTest extends TestCase
|
||||
public function user_create_new_invoice_without_storing_client_without_avatar_and_mail()
|
||||
{
|
||||
Notification::fake();
|
||||
PDF::fake();
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create(['role' => 'user']);
|
||||
@@ -376,6 +377,8 @@ class OasisInvoiceTest extends TestCase
|
||||
'name' => 'VueFileManager Inc.',
|
||||
]);
|
||||
|
||||
PDF::assertFileNameIs(storage_path("app/" . invoice_path(Invoice::first())));
|
||||
|
||||
Notification::assertNothingSent();
|
||||
}
|
||||
|
||||
@@ -385,6 +388,7 @@ class OasisInvoiceTest extends TestCase
|
||||
public function user_create_new_invoice_without_storing_client()
|
||||
{
|
||||
Notification::fake();
|
||||
PDF::fake();
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create(['role' => 'user']);
|
||||
@@ -427,6 +431,8 @@ class OasisInvoiceTest extends TestCase
|
||||
'email' => 'howdy@hi5ve.digital',
|
||||
]);
|
||||
|
||||
PDF::assertFileNameIs(storage_path("app/" . invoice_path(Invoice::first())));
|
||||
|
||||
Notification::assertTimesSent(1, InvoiceDeliveryNotification::class);
|
||||
}
|
||||
|
||||
@@ -436,6 +442,7 @@ class OasisInvoiceTest extends TestCase
|
||||
public function user_create_new_invoice_with_existing_client()
|
||||
{
|
||||
Notification::fake();
|
||||
PDF::fake();
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create(['role' => 'user']);
|
||||
@@ -468,6 +475,8 @@ class OasisInvoiceTest extends TestCase
|
||||
'items' => json_encode($this->items),
|
||||
]);
|
||||
|
||||
PDF::assertFileNameIs(storage_path("app/" . invoice_path(Invoice::first())));
|
||||
|
||||
Notification::assertTimesSent(1, InvoiceDeliveryNotification::class);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user