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