mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-30 23:04:34 -04:00
Event listener for invoice viewed
This commit is contained in:
parent
c593f2bd58
commit
da88319418
44
app/Events/Invoice/InvoiceWasViewed.php
Normal file
44
app/Events/Invoice/InvoiceWasViewed.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Events\Invoice;
|
||||||
|
|
||||||
|
use App\Models\Company;
|
||||||
|
use App\Models\InvoiceInvitation;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class InvoiceWasViewed.
|
||||||
|
*/
|
||||||
|
class InvoiceWasViewed
|
||||||
|
{
|
||||||
|
use SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Invoice
|
||||||
|
*/
|
||||||
|
public $invitation;
|
||||||
|
|
||||||
|
public $company;
|
||||||
|
|
||||||
|
public $event_vars;
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @param Invoice $invoice
|
||||||
|
*/
|
||||||
|
public function __construct(InvoiceInvitation $invitation, Company $company, array $event_vars)
|
||||||
|
{
|
||||||
|
$this->invitation = $invitation;
|
||||||
|
$this->company = $company;
|
||||||
|
$this->event_vars = $event_vars;
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\ClientPortal;
|
namespace App\Http\Controllers\ClientPortal;
|
||||||
|
|
||||||
|
use App\Events\Invoice\InvoiceWasViewed;
|
||||||
use App\Events\Misc\InvitationWasViewed;
|
use App\Events\Misc\InvitationWasViewed;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\InvoiceInvitation;
|
use App\Models\InvoiceInvitation;
|
||||||
@ -39,6 +40,7 @@ class InvitationController extends Controller
|
|||||||
$invitation = $entity_obj::whereRaw("BINARY `key`= ?", [$invitation_key])->first();
|
$invitation = $entity_obj::whereRaw("BINARY `key`= ?", [$invitation_key])->first();
|
||||||
|
|
||||||
if ($invitation) {
|
if ($invitation) {
|
||||||
|
|
||||||
if ((bool)$invitation->contact->client->getSetting('enable_client_portal_password') !== false) {
|
if ((bool)$invitation->contact->client->getSetting('enable_client_portal_password') !== false) {
|
||||||
$this->middleware('auth:contact');
|
$this->middleware('auth:contact');
|
||||||
} else {
|
} else {
|
||||||
@ -51,6 +53,8 @@ class InvitationController extends Controller
|
|||||||
$invitation->markViewed();
|
$invitation->markViewed();
|
||||||
|
|
||||||
event(new InvitationWasViewed($invitation->{$entity}, $invitation, $invitation->{$entity}->company, Ninja::eventVars()));
|
event(new InvitationWasViewed($invitation->{$entity}, $invitation, $invitation->{$entity}->company, Ninja::eventVars()));
|
||||||
|
|
||||||
|
$this->fireEntityViewedEvent($invitation->{$entity}, $entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->route('client.'.$entity.'.show', [$entity => $this->encodePrimaryKey($invitation->{$key})]);
|
return redirect()->route('client.'.$entity.'.show', [$entity => $this->encodePrimaryKey($invitation->{$key})]);
|
||||||
@ -59,6 +63,20 @@ class InvitationController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function fireEntityViewedEvent($invitation, $entity_string)
|
||||||
|
{
|
||||||
|
|
||||||
|
switch ($entity_string) {
|
||||||
|
case 'invoice':
|
||||||
|
event(new InvoiceWasViewed($invitation, $invitation->company, Ninja::eventVars()));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
# code...
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function routerForDownload(string $entity, string $invitation_key)
|
public function routerForDownload(string $entity, string $invitation_key)
|
||||||
{
|
{
|
||||||
return redirect('client/'.$entity.'/'.$invitation_key.'/download_pdf');
|
return redirect('client/'.$entity.'/'.$invitation_key.'/download_pdf');
|
||||||
|
59
app/Listeners/Invoice/InvoiceViewedActivity.php
Normal file
59
app/Listeners/Invoice/InvoiceViewedActivity.php
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Listeners\Invoice;
|
||||||
|
|
||||||
|
use App\Libraries\MultiDB;
|
||||||
|
use App\Models\Activity;
|
||||||
|
use App\Models\ClientContact;
|
||||||
|
use App\Models\InvoiceInvitation;
|
||||||
|
use App\Repositories\ActivityRepository;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
class InvoiceViewedActivity implements ShouldQueue
|
||||||
|
{
|
||||||
|
protected $activity_repo;
|
||||||
|
/**
|
||||||
|
* Create the event listener.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(ActivityRepository $activity_repo)
|
||||||
|
{
|
||||||
|
$this->activity_repo = $activity_repo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param object $event
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle($event)
|
||||||
|
{
|
||||||
|
MultiDB::setDb($event->company->db);
|
||||||
|
|
||||||
|
$fields = new \stdClass;
|
||||||
|
|
||||||
|
$fields->user_id = $event->invoice->user_id;
|
||||||
|
$fields->company_id = $event->invoice->company_id;
|
||||||
|
$fields->activity_type_id = Activity::VIEW_INVOICE;
|
||||||
|
$fields->client_id = $event->invitation->client_id;
|
||||||
|
$fields->client_contact_id = $event->invitation->client_contact_id;
|
||||||
|
$fields->invitation_id = $event->invitation->id;
|
||||||
|
$fields->invoice_id = $event->invitation->invoice_id;
|
||||||
|
|
||||||
|
$this->activity_repo->save($fields, $event->invoice, $event->event_vars);
|
||||||
|
}
|
||||||
|
}
|
@ -32,6 +32,7 @@ use App\Events\Invoice\InvoiceWasMarkedSent;
|
|||||||
use App\Events\Invoice\InvoiceWasPaid;
|
use App\Events\Invoice\InvoiceWasPaid;
|
||||||
use App\Events\Invoice\InvoiceWasReversed;
|
use App\Events\Invoice\InvoiceWasReversed;
|
||||||
use App\Events\Invoice\InvoiceWasUpdated;
|
use App\Events\Invoice\InvoiceWasUpdated;
|
||||||
|
use App\Events\Invoice\InvoiceWasViewed;
|
||||||
use App\Events\Misc\InvitationWasViewed;
|
use App\Events\Misc\InvitationWasViewed;
|
||||||
use App\Events\Payment\PaymentWasCreated;
|
use App\Events\Payment\PaymentWasCreated;
|
||||||
use App\Events\Payment\PaymentWasDeleted;
|
use App\Events\Payment\PaymentWasDeleted;
|
||||||
@ -59,6 +60,7 @@ use App\Listeners\Invoice\InvoiceDeletedActivity;
|
|||||||
use App\Listeners\Invoice\InvoiceEmailActivity;
|
use App\Listeners\Invoice\InvoiceEmailActivity;
|
||||||
use App\Listeners\Invoice\InvoiceEmailFailedActivity;
|
use App\Listeners\Invoice\InvoiceEmailFailedActivity;
|
||||||
use App\Listeners\Invoice\InvoiceEmailedNotification;
|
use App\Listeners\Invoice\InvoiceEmailedNotification;
|
||||||
|
use App\Listeners\Invoice\InvoiceViewedActivity;
|
||||||
use App\Listeners\Invoice\UpdateInvoiceActivity;
|
use App\Listeners\Invoice\UpdateInvoiceActivity;
|
||||||
use App\Listeners\Invoice\UpdateInvoiceInvitations;
|
use App\Listeners\Invoice\UpdateInvoiceInvitations;
|
||||||
use App\Listeners\Misc\InvitationViewedListener;
|
use App\Listeners\Misc\InvitationViewedListener;
|
||||||
@ -159,6 +161,9 @@ class EventServiceProvider extends ServiceProvider
|
|||||||
InvoiceWasPaid::class => [
|
InvoiceWasPaid::class => [
|
||||||
CreateInvoiceHtmlBackup::class,
|
CreateInvoiceHtmlBackup::class,
|
||||||
],
|
],
|
||||||
|
InvoiceWasViewed::class = [
|
||||||
|
InvoiceViewedActivity::class,
|
||||||
|
],
|
||||||
InvoiceWasEmailed::class => [
|
InvoiceWasEmailed::class => [
|
||||||
InvoiceEmailActivity::class,
|
InvoiceEmailActivity::class,
|
||||||
InvoiceEmailedNotification::class,
|
InvoiceEmailedNotification::class,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user