mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-05 18:52:44 +01:00
Notification for quotes credits and invoices
This commit is contained in:
parent
7ba78cc342
commit
df9fe5677d
@ -11,7 +11,8 @@
|
||||
|
||||
namespace App\Events\Credit;
|
||||
|
||||
use App\Models\Credit;
|
||||
use App\Models\Company;
|
||||
use App\Models\CreditInvitation;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
@ -20,7 +21,7 @@ class CreditWasEmailed
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $credit;
|
||||
public $invitation;
|
||||
|
||||
public $company;
|
||||
|
||||
@ -33,9 +34,9 @@ class CreditWasEmailed
|
||||
* @param Company $company
|
||||
* @param array $event_vars
|
||||
*/
|
||||
public function __construct(Credit $credit, Company $company, array $event_vars)
|
||||
public function __construct(CreditInvitation $invitation, Company $company, array $event_vars)
|
||||
{
|
||||
$this->credit = $credit;
|
||||
$this->invitation = $invitation;
|
||||
$this->company = $company;
|
||||
$this->event_vars = $event_vars;
|
||||
}
|
||||
|
@ -27,8 +27,6 @@ class QuoteWasEmailed
|
||||
|
||||
public $company;
|
||||
|
||||
public $notes;
|
||||
|
||||
public $event_vars;
|
||||
|
||||
/**
|
||||
@ -39,10 +37,9 @@ class QuoteWasEmailed
|
||||
* @param Company $company
|
||||
* @param array $event_vars
|
||||
*/
|
||||
public function __construct(QuoteInvitation $invitation, string $notes, Company $company, array $event_vars)
|
||||
public function __construct(QuoteInvitation $invitation, Company $company, array $event_vars)
|
||||
{
|
||||
$this->invitation = $invitation;
|
||||
$this->notes = $notes;
|
||||
$this->company = $company;
|
||||
$this->event_vars = $event_vars;
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Events\Credit\CreditWasEmailed;
|
||||
use App\Events\Quote\QuoteWasEmailed;
|
||||
use App\Http\Requests\Email\SendEmailRequest;
|
||||
use App\Jobs\Entity\EmailEntity;
|
||||
@ -131,6 +132,8 @@ class EmailController extends BaseController
|
||||
}
|
||||
});
|
||||
|
||||
$entity_obj->service()->markSent()->save();
|
||||
|
||||
$entity_obj->last_sent_date = now();
|
||||
$entity_obj->save();
|
||||
|
||||
@ -152,13 +155,16 @@ class EmailController extends BaseController
|
||||
$this->entity_transformer = QuoteTransformer::class;
|
||||
|
||||
if($entity_obj->invitations->count() >= 1)
|
||||
event(new QuoteWasEmailed($entity_obj->invitations->first(), '', $entity_obj->company, Ninja::eventVars()));
|
||||
event(new QuoteWasEmailed($entity_obj->invitations->first(), $entity_obj->company, Ninja::eventVars()));
|
||||
|
||||
}
|
||||
|
||||
if ($entity_obj instanceof Credit) {
|
||||
$this->entity_type = Credit::class;
|
||||
$this->entity_transformer = CreditTransformer::class;
|
||||
|
||||
if($entity_obj->invitations->count() >= 1)
|
||||
event(new CreditWasEmailed($entity_obj->invitations->first(), $entity_obj->company, Ninja::eventVars()));
|
||||
}
|
||||
|
||||
if ($entity_obj instanceof RecurringInvoice) {
|
||||
|
63
app/Listeners/Credit/CreditEmailedNotification.php
Normal file
63
app/Listeners/Credit/CreditEmailedNotification.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?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\Credit;
|
||||
|
||||
use App\Jobs\Mail\EntitySentMailer;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Notifications\Admin\EntitySentNotification;
|
||||
use App\Utils\Traits\Notifications\UserNotifies;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class CreditEmailedNotification implements ShouldQueue
|
||||
{
|
||||
use UserNotifies;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param object $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle($event)
|
||||
{
|
||||
MultiDB::setDb($event->company->db);
|
||||
|
||||
$first_notification_sent = true;
|
||||
|
||||
$credit = $event->invitation->credit;
|
||||
$credit->last_sent_date = now();
|
||||
$credit->save();
|
||||
|
||||
foreach ($event->invitation->company->company_users as $company_user) {
|
||||
$user = $company_user->user;
|
||||
|
||||
$notification = new EntitySentNotification($event->invitation, 'credit');
|
||||
|
||||
$methods = $this->findUserNotificationTypes($event->invitation, $company_user, 'credit', ['all_notifications', 'credit_sent']);
|
||||
|
||||
if (($key = array_search('mail', $methods)) !== false && $first_notification_sent === true) {
|
||||
unset($methods[$key]);
|
||||
|
||||
EntitySentMailer::dispatch($event->invitation, 'credit', $user, $event->invitation->company);
|
||||
$first_notification_sent = false;
|
||||
}
|
||||
|
||||
$notification->method = $methods;
|
||||
|
||||
$user->notify($notification);
|
||||
}
|
||||
}
|
||||
}
|
@ -24,6 +24,7 @@ use App\Events\Contact\ContactLoggedIn;
|
||||
use App\Events\Credit\CreditWasArchived;
|
||||
use App\Events\Credit\CreditWasCreated;
|
||||
use App\Events\Credit\CreditWasDeleted;
|
||||
use App\Events\Credit\CreditWasEmailed;
|
||||
use App\Events\Credit\CreditWasEmailedAndFailed;
|
||||
use App\Events\Credit\CreditWasMarkedSent;
|
||||
use App\Events\Credit\CreditWasRestored;
|
||||
@ -110,6 +111,7 @@ use App\Listeners\Activity\VendorDeletedActivity;
|
||||
use App\Listeners\Activity\VendorRestoredActivity;
|
||||
use App\Listeners\Activity\VendorUpdatedActivity;
|
||||
use App\Listeners\Contact\UpdateContactLastLogin;
|
||||
use App\Listeners\Credit\CreditEmailedNotification;
|
||||
use App\Listeners\Credit\CreditRestoredActivity;
|
||||
use App\Listeners\Credit\CreditViewedActivity;
|
||||
use App\Listeners\Document\DeleteCompanyDocuments;
|
||||
@ -227,6 +229,7 @@ class EventServiceProvider extends ServiceProvider
|
||||
CreditWasEmailedAndFailed::class => [
|
||||
],
|
||||
CreditWasEmailed::class => [
|
||||
CreditEmailedNotification::class,
|
||||
],
|
||||
CreditWasMarkedSent::class => [
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user