mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Fixes for emails and reminders
This commit is contained in:
parent
be2f83cfea
commit
9174b7e628
50
app/Events/Invoice/InvoiceReminderWasEmailed.php
Normal file
50
app/Events/Invoice/InvoiceReminderWasEmailed.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?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 InvoiceReminderWasEmailed.
|
||||
*/
|
||||
class InvoiceReminderWasEmailed
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* @var Invoice
|
||||
*/
|
||||
public $invitation;
|
||||
|
||||
public $reminder;
|
||||
|
||||
public $company;
|
||||
|
||||
public $event_vars;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param InvoiceInvitation $invitation
|
||||
* @param Company $company
|
||||
* @param array $event_vars
|
||||
*/
|
||||
public function __construct(InvoiceInvitation $invitation, Company $company, array $event_vars, string $reminder)
|
||||
{
|
||||
$this->invitation = $invitation;
|
||||
$this->company = $company;
|
||||
$this->event_vars = $event_vars;
|
||||
$this->reminder = $reminder;
|
||||
}
|
||||
}
|
@ -138,9 +138,8 @@ class EmailController extends BaseController
|
||||
$entity_obj->save();
|
||||
|
||||
/*Only notify the admin ONCE, not once per contact/invite*/
|
||||
$invitation = $entity_obj->invitations->first();
|
||||
|
||||
EntitySentMailer::dispatch($invitation, $entity_string, $entity_obj->user, $invitation->company);
|
||||
// $invitation = $entity_obj->invitations->first();
|
||||
// EntitySentMailer::dispatch($invitation, $entity_string, $entity_obj->user, $invitation->company);
|
||||
|
||||
if ($entity_obj instanceof Invoice) {
|
||||
$this->entity_type = Invoice::class;
|
||||
|
@ -28,7 +28,7 @@ class ShowDocumentRequest extends FormRequest
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return auth()->user('contact')->client->id === $this->document->documentable->id;
|
||||
return auth()->user('contact')->client->id == $this->document->documentable_id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -12,12 +12,14 @@
|
||||
namespace App\Jobs\Entity;
|
||||
|
||||
use App\DataMapper\Analytics\EmailInvoiceFailure;
|
||||
use App\Events\Invoice\InvoiceReminderWasEmailed;
|
||||
use App\Events\Invoice\InvoiceWasEmailed;
|
||||
use App\Events\Invoice\InvoiceWasEmailedAndFailed;
|
||||
use App\Jobs\Mail\BaseMailerJob;
|
||||
use App\Jobs\Utils\SystemLogger;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Mail\TemplateEmail;
|
||||
use App\Models\Activity;
|
||||
use App\Models\Company;
|
||||
use App\Models\CreditInvitation;
|
||||
use App\Models\Invoice;
|
||||
@ -169,11 +171,22 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue
|
||||
|
||||
private function entityEmailSucceeded()
|
||||
{
|
||||
switch ($this->entity_string) {
|
||||
switch ($this->reminder_template) {
|
||||
case 'invoice':
|
||||
event(new InvoiceWasEmailed($this->invitation, $this->company, Ninja::eventVars()));
|
||||
break;
|
||||
|
||||
case 'reminder1':
|
||||
event(new InvoiceReminderWasEmailed($this->invitation, $this->company, Ninja::eventVars(), Activity::INVOICE_REMINDER1_SENT));
|
||||
break;
|
||||
case 'reminder2':
|
||||
event(new InvoiceReminderWasEmailed($this->invitation, $this->company, Ninja::eventVars(), Activity::INVOICE_REMINDER2_SENT));
|
||||
break;
|
||||
case 'reminder3':
|
||||
event(new InvoiceReminderWasEmailed($this->invitation, $this->company, Ninja::eventVars(), Activity::INVOICE_REMINDER3_SENT));
|
||||
break;
|
||||
case 'reminder_endless':
|
||||
event(new InvoiceReminderWasEmailed($this->invitation, $this->company, Ninja::eventVars(), Activity::INVOICE_REMINDER_ENDLESS_SENT));
|
||||
break;
|
||||
default:
|
||||
# code...
|
||||
break;
|
||||
|
59
app/Listeners/Invoice/InvoiceReminderEmailActivity.php
Normal file
59
app/Listeners/Invoice/InvoiceReminderEmailActivity.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;
|
||||
use stdClass;
|
||||
|
||||
class InvoiceReminderEmailActivity implements ShouldQueue
|
||||
{
|
||||
protected $activity_repo;
|
||||
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @param ActivityRepository $activity_repo
|
||||
*/
|
||||
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->invoice_id = $event->invitation->invoice->id;
|
||||
$fields->user_id = $event->invitation->invoice->user_id;
|
||||
$fields->company_id = $event->invitation->invoice->company_id;
|
||||
$fields->client_contact_id = $event->invitation->invoice->client_contact_id;
|
||||
$fields->activity_type_id = $event->reminder;
|
||||
|
||||
$this->activity_repo->save($fields, $event->invitation->invoice, $event->event_vars);
|
||||
}
|
||||
}
|
@ -35,6 +35,7 @@ use App\Events\Expense\ExpenseWasCreated;
|
||||
use App\Events\Expense\ExpenseWasDeleted;
|
||||
use App\Events\Expense\ExpenseWasRestored;
|
||||
use App\Events\Expense\ExpenseWasUpdated;
|
||||
use App\Events\Invoice\InvoiceReminderWasEmailed;
|
||||
use App\Events\Invoice\InvoiceWasArchived;
|
||||
use App\Events\Invoice\InvoiceWasCancelled;
|
||||
use App\Events\Invoice\InvoiceWasCreated;
|
||||
@ -121,6 +122,7 @@ use App\Listeners\Invoice\InvoiceEmailActivity;
|
||||
use App\Listeners\Invoice\InvoiceEmailFailedActivity;
|
||||
use App\Listeners\Invoice\InvoiceEmailedNotification;
|
||||
use App\Listeners\Invoice\InvoicePaidActivity;
|
||||
use App\Listeners\Invoice\InvoiceReminderEmailActivity;
|
||||
use App\Listeners\Invoice\InvoiceRestoredActivity;
|
||||
use App\Listeners\Invoice\InvoiceReversedActivity;
|
||||
use App\Listeners\Invoice\InvoiceViewedActivity;
|
||||
@ -285,6 +287,9 @@ class EventServiceProvider extends ServiceProvider
|
||||
InvoiceWasEmailedAndFailed::class => [
|
||||
InvoiceEmailFailedActivity::class,
|
||||
],
|
||||
InvoiceReminderWasEmailed::class => [
|
||||
InvoiceReminderEmailActivity::class,
|
||||
],
|
||||
InvoiceWasDeleted::class => [
|
||||
InvoiceDeletedActivity::class,
|
||||
CreateInvoicePdf::class,
|
||||
|
@ -53,28 +53,25 @@ class ClientRepository extends BaseRepository
|
||||
*/
|
||||
public function save(array $data, Client $client) : ?Client
|
||||
{
|
||||
$client->fill($data);
|
||||
|
||||
$client->save();
|
||||
|
||||
if ($client->id_number == '' || ! $client->id_number) {
|
||||
$client->id_number = $this->getNextClientNumber($client);
|
||||
/* When uploading documents, only the document array is sent, so we must return early*/
|
||||
if (array_key_exists('documents', $data) && count($data['documents']) >=1) {
|
||||
$this->saveDocuments($data['documents'], $client);
|
||||
return $client;
|
||||
}
|
||||
|
||||
$client->fill($data);
|
||||
|
||||
if (!isset($client->id_number))
|
||||
$client->id_number = $this->getNextClientNumber($client);
|
||||
|
||||
if (empty($data['name']))
|
||||
$data['name'] = $client->present()->name();
|
||||
|
||||
$client->save();
|
||||
|
||||
$this->contact_repo->save($data, $client);
|
||||
|
||||
if (empty($data['name'])) {
|
||||
$data['name'] = $client->present()->name();
|
||||
}
|
||||
|
||||
//info("{$client->present()->name} has a balance of {$client->balance} with a paid to date of {$client->paid_to_date}");
|
||||
|
||||
if (array_key_exists('documents', $data)) {
|
||||
$this->saveDocuments($data['documents'], $client);
|
||||
}
|
||||
|
||||
return $client;
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ use App\Models\Company;
|
||||
|
||||
trait SavesDocuments
|
||||
{
|
||||
public function saveDocuments($document_array, $entity, $is_public = false)
|
||||
public function saveDocuments($document_array, $entity, $is_public = true)
|
||||
{
|
||||
if ($entity instanceof Company) {
|
||||
$account = $entity->account;
|
||||
|
Loading…
x
Reference in New Issue
Block a user