diff --git a/app/Events/Credit/CreditWasRestored.php b/app/Events/Credit/CreditWasRestored.php new file mode 100644 index 000000000000..4884c3749dc7 --- /dev/null +++ b/app/Events/Credit/CreditWasRestored.php @@ -0,0 +1,45 @@ +credit = $credit; + $this->company = $company; + $this->event_vars = $event_vars; + + } +} diff --git a/app/Events/Quote/QuoteWasApproved.php b/app/Events/Quote/QuoteWasApproved.php index ee8ba01cec2a..bea13b86a602 100644 --- a/app/Events/Quote/QuoteWasApproved.php +++ b/app/Events/Quote/QuoteWasApproved.php @@ -25,6 +25,8 @@ class QuoteWasApproved { use Dispatchable, InteractsWithSockets, SerializesModels; + public $contact; + public $quote; public $company; @@ -35,8 +37,9 @@ class QuoteWasApproved * * @return void */ - public function __construct(Quote $quote, Company $company, array $event_vars) + public function __construct(ClientContact $contact, Quote $quote, Company $company, array $event_vars) { + $this->contact = $contact; $this->quote = $quote; $this->company = $company; $this->event_vars = $event_vars; diff --git a/app/Http/Controllers/ClientPortal/QuoteController.php b/app/Http/Controllers/ClientPortal/QuoteController.php index 2358eac02b32..511fb41b35de 100644 --- a/app/Http/Controllers/ClientPortal/QuoteController.php +++ b/app/Http/Controllers/ClientPortal/QuoteController.php @@ -109,7 +109,7 @@ class QuoteController extends Controller if ($process) { foreach ($quotes as $quote) { $quote->service()->approve()->save(); - event(new QuoteWasApproved($quote, $quote->company, Ninja::eventVars())); + event(new QuoteWasApproved(auth()->user(), $quote, $quote->company, Ninja::eventVars())); } return redirect() diff --git a/app/Jobs/Quote/QuoteWorkflowSettings.php b/app/Jobs/Quote/QuoteWorkflowSettings.php index 54288c0fd604..cd155cc498ae 100644 --- a/app/Jobs/Quote/QuoteWorkflowSettings.php +++ b/app/Jobs/Quote/QuoteWorkflowSettings.php @@ -49,14 +49,15 @@ class QuoteWorkflowSettings implements ShouldQueue */ public function handle() { - if ($this->client->getSetting('auto_archive_quote')) { - $this->base_repository->archive($this->quote); - } if ($this->client->getSetting('auto_email_quote')) { $this->quote->invitations->each(function ($invitation, $key) { $this->quote->service()->sendEmail($invitation->contact); }); } + + if ($this->client->getSetting('auto_archive_quote')) { + $this->base_repository->archive($this->quote); + } } } diff --git a/app/Listeners/Credit/CreditRestoredActivity.php b/app/Listeners/Credit/CreditRestoredActivity.php new file mode 100644 index 000000000000..4920fb343dfe --- /dev/null +++ b/app/Listeners/Credit/CreditRestoredActivity.php @@ -0,0 +1,58 @@ +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->credit_id = $event->credit->id; + $fields->user_id = $event->credit->user_id; + $fields->company_id = $event->credit->company_id; + $fields->activity_type_id = Activity::RESTORE_CREDIT; + + $this->activity_repo->save($fields, $event->credit, $event->event_vars); + + } +} diff --git a/app/Listeners/Invoice/InvoiceRestoredActivity.php b/app/Listeners/Invoice/InvoiceRestoredActivity.php new file mode 100644 index 000000000000..1832ccdc873b --- /dev/null +++ b/app/Listeners/Invoice/InvoiceRestoredActivity.php @@ -0,0 +1,57 @@ +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->invoice->id; + $fields->user_id = $event->invoice->user_id; + $fields->company_id = $event->invoice->company_id; + $fields->activity_type_id = Activity::RESTORE_INVOICE; + + $this->activity_repo->save($fields, $event->invoice, $event->event_vars); + } +} diff --git a/app/Listeners/Payment/PaymentRestoredActivity.php b/app/Listeners/Payment/PaymentRestoredActivity.php new file mode 100644 index 000000000000..828a0b046640 --- /dev/null +++ b/app/Listeners/Payment/PaymentRestoredActivity.php @@ -0,0 +1,57 @@ +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->payment_id = $event->payment->id; + $fields->user_id = $event->payment->user_id; + $fields->company_id = $event->payment->company_id; + $fields->activity_type_id = Activity::RESTORE_PAYMENT; + + $this->activity_repo->save($fields, $event->payment, $event->event_vars); + } +} diff --git a/app/Listeners/Quote/QuoteApprovedActivity.php b/app/Listeners/Quote/QuoteApprovedActivity.php new file mode 100644 index 000000000000..5ac5c14d49a8 --- /dev/null +++ b/app/Listeners/Quote/QuoteApprovedActivity.php @@ -0,0 +1,58 @@ +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->quote_id = $event->quote->id; + $fields->user_id = $event->quote->user_id; + $fields->client_contact_id = $event->contact->id; + $fields->company_id = $event->payment->company_id; + $fields->activity_type_id = Activity::RESTORE_PAYMENT; + + $this->activity_repo->save($fields, $event->payment, $event->event_vars); + } +} diff --git a/app/Listeners/Quote/QuoteArchivedActivity.php b/app/Listeners/Quote/QuoteArchivedActivity.php new file mode 100644 index 000000000000..ea8cfb7d8a1b --- /dev/null +++ b/app/Listeners/Quote/QuoteArchivedActivity.php @@ -0,0 +1,57 @@ +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->quote_id = $event->quote->id; + $fields->user_id = $event->quote->user_id; + $fields->company_id = $event->quote->company_id; + $fields->activity_type_id = Activity::ARCHIVE_QUOTE; + + $this->activity_repo->save($fields, $event->quote, $event->event_vars); + } +} diff --git a/app/Listeners/Quote/QuoteDeletedActivity.php b/app/Listeners/Quote/QuoteDeletedActivity.php new file mode 100644 index 000000000000..f20f12a83a27 --- /dev/null +++ b/app/Listeners/Quote/QuoteDeletedActivity.php @@ -0,0 +1,57 @@ +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->quote_id = $event->quote->id; + $fields->user_id = $event->quote->user_id; + $fields->company_id = $event->quote->company_id; + $fields->activity_type_id = Activity::DELETE_QUOTE; + + $this->activity_repo->save($fields, $event->quote, $event->event_vars); + } +} diff --git a/app/Listeners/Quote/QuoteRestoredActivity.php b/app/Listeners/Quote/QuoteRestoredActivity.php new file mode 100644 index 000000000000..9c15bd9114f4 --- /dev/null +++ b/app/Listeners/Quote/QuoteRestoredActivity.php @@ -0,0 +1,57 @@ +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->quote_id = $event->quote->id; + $fields->user_id = $event->quote->user_id; + $fields->company_id = $event->quote->company_id; + $fields->activity_type_id = Activity::RESTORE_QUOTE; + + $this->activity_repo->save($fields, $event->quote, $event->event_vars); + } +} diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 79432dabbc3a..8c56b8d41561 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -36,14 +36,14 @@ class Activity extends StaticModel const UPDATE_QUOTE=19; // const EMAIL_QUOTE=20; // const VIEW_QUOTE=21; // - const ARCHIVE_QUOTE=22; - const DELETE_QUOTE=23; - const RESTORE_QUOTE=24; - const RESTORE_INVOICE=25; - const RESTORE_CLIENT=26; - const RESTORE_PAYMENT=27; - const RESTORE_CREDIT=28; - const APPROVE_QUOTE=29; + const ARCHIVE_QUOTE=22; // + const DELETE_QUOTE=23; // + const RESTORE_QUOTE=24; // + const RESTORE_INVOICE=25; // + const RESTORE_CLIENT=26; // + const RESTORE_PAYMENT=27; // + const RESTORE_CREDIT=28; // + const APPROVE_QUOTE=29; // const CREATE_VENDOR=30; const ARCHIVE_VENDOR=31; const DELETE_VENDOR=32; diff --git a/app/Models/Payment.php b/app/Models/Payment.php index d76b283905c2..cc161528a9f1 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -65,7 +65,8 @@ class Payment extends BaseModel 'date', 'transaction_reference', 'number', - 'is_manual' + 'is_manual', + 'private_notes', ]; protected $casts = [ diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 574f94adc39d..d94e889d73b6 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -26,6 +26,7 @@ use App\Events\Credit\CreditWasCreated; use App\Events\Credit\CreditWasDeleted; use App\Events\Credit\CreditWasEmailedAndFailed; use App\Events\Credit\CreditWasMarkedSent; +use App\Events\Credit\CreditWasRestored; use App\Events\Credit\CreditWasUpdated; use App\Events\Design\DesignWasArchived; use App\Events\Invoice\InvoiceWasArchived; @@ -35,6 +36,7 @@ use App\Events\Invoice\InvoiceWasDeleted; use App\Events\Invoice\InvoiceWasEmailed; use App\Events\Invoice\InvoiceWasMarkedSent; use App\Events\Invoice\InvoiceWasPaid; +use App\Events\Invoice\InvoiceWasRestored; use App\Events\Invoice\InvoiceWasReversed; use App\Events\Invoice\InvoiceWasUpdated; use App\Events\Invoice\InvoiceWasViewed; @@ -43,11 +45,15 @@ use App\Events\Payment\PaymentWasArchived; use App\Events\Payment\PaymentWasCreated; use App\Events\Payment\PaymentWasDeleted; use App\Events\Payment\PaymentWasRefunded; +use App\Events\Payment\PaymentWasRestored; use App\Events\Payment\PaymentWasUpdated; use App\Events\Payment\PaymentWasVoided; use App\Events\Quote\QuoteWasApproved; +use App\Events\Quote\QuoteWasArchived; use App\Events\Quote\QuoteWasCreated; +use App\Events\Quote\QuoteWasDeleted; use App\Events\Quote\QuoteWasEmailed; +use App\Events\Quote\QuoteWasRestored; use App\Events\Quote\QuoteWasUpdated; use App\Events\Quote\QuoteWasViewed; use App\Events\User\UserLoggedIn; @@ -69,6 +75,7 @@ use App\Listeners\Activity\QuoteUpdatedActivity; use App\Listeners\Activity\RestoreClientActivity; use App\Listeners\Activity\UpdatedCreditActivity; use App\Listeners\Contact\UpdateContactLastLogin; +use App\Listeners\Credit\CreditRestoredActivity; use App\Listeners\Document\DeleteCompanyDocuments; use App\Listeners\Invoice\CreateInvoiceActivity; use App\Listeners\Invoice\CreateInvoiceHtmlBackup; @@ -79,12 +86,17 @@ use App\Listeners\Invoice\InvoiceDeletedActivity; use App\Listeners\Invoice\InvoiceEmailActivity; use App\Listeners\Invoice\InvoiceEmailFailedActivity; use App\Listeners\Invoice\InvoiceEmailedNotification; +use App\Listeners\Invoice\InvoiceRestoredActivity; use App\Listeners\Invoice\InvoiceViewedActivity; use App\Listeners\Invoice\UpdateInvoiceActivity; use App\Listeners\Invoice\UpdateInvoiceInvitations; use App\Listeners\Misc\InvitationViewedListener; use App\Listeners\Payment\PaymentNotification; +use App\Listeners\Payment\PaymentRestoredActivity; +use App\Listeners\Quote\QuoteArchivedActivity; +use App\Listeners\Quote\QuoteDeletedActivity; use App\Listeners\Quote\QuoteEmailActivity; +use App\Listeners\Quote\QuoteRestoredActivity; use App\Listeners\Quote\QuoteViewedActivity; use App\Listeners\Quote\ReachWorkflowSettings; use App\Listeners\SendVerificationNotification; @@ -132,6 +144,9 @@ class EventServiceProvider extends ServiceProvider PaymentWasVoided::class => [ PaymentVoidedActivity::class, ], + PaymentWasRestored::class =>[ + PaymentRestoredActivity::class, + ], // Clients ClientWasCreated::class =>[ CreatedClientActivity::class, @@ -176,6 +191,9 @@ class EventServiceProvider extends ServiceProvider CreditWasArchived::class => [ CreditArchivedActivity::class, ], + CreditWasRestored::class => [ + CreditRestoredActivity::class, + ], //Designs DesignWasArchived::class => [ ], @@ -216,6 +234,9 @@ class EventServiceProvider extends ServiceProvider InvoiceWasArchived::class => [ InvoiceArchivedActivity::class, ], + InvoiceWasRestored::class => [ + InvoiceRestoredActivity::class, + ], InvoiceWasReversed::class => [ ], InvoiceWasCancelled::class => [ @@ -241,6 +262,15 @@ class EventServiceProvider extends ServiceProvider QuoteWasViewed::class => [ QuoteViewedActivity::class, ], + QuoteWasArchived::class => [ + QuoteArchivedActivity::class, + ], + QuoteWasDeleted::class => [ + QuoteDeletedActivity::class, + ], + QuoteWasRestored::class => [ + QuoteRestoredActivity::class, + ], ]; /**