From d2cc1e4d6529afb28d22eacaf705049ceaef0354 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 17 Jul 2020 07:13:32 +1000 Subject: [PATCH 01/12] Fix for company not returning on refresh route --- app/Http/Controllers/BaseController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index 8d80a3bb3fa5..24af5f7a9bfc 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -145,7 +145,7 @@ class BaseController extends Controller $query->with( [ - 'company' => function ($query) use($updated_at){$query->where('updated_at', '>=', $updated_at);}, + 'company' => function ($query) use($updated_at){$query->where('updated_at', '>=', 0);}, 'company.activities' => function ($query) use($updated_at){$query->where('updated_at', '>=', $updated_at);}, 'company.clients' =>function ($query) use($updated_at){$query->where('updated_at', '>', $updated_at);}, 'company.tax_rates'=>function ($query) use($updated_at){$query->where('updated_at', '>', $updated_at);}, From 5eb9791c375e24ba117389c46b3b4f79a608e5dc Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 17 Jul 2020 07:15:30 +1000 Subject: [PATCH 02/12] fix for bug on bulk route of invoice repo --- app/Repositories/InvoiceRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Repositories/InvoiceRepository.php b/app/Repositories/InvoiceRepository.php index fca09eb897ab..b4735d77c747 100644 --- a/app/Repositories/InvoiceRepository.php +++ b/app/Repositories/InvoiceRepository.php @@ -86,7 +86,7 @@ class InvoiceRepository extends BaseRepository $invoice->service()->handleCancellation()->save(); - $invoice = $this->invoice_repo->delete($invoice); + $invoice = parent::delete($invoice); return $invoice; } From c0237474ef50c60f94a124bbb811e6203d5daf69 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 17 Jul 2020 07:50:02 +1000 Subject: [PATCH 03/12] Fixes for demo data --- app/Console/Commands/DemoMode.php | 46 +++++++++++++++++----------- app/Factory/QuoteFactory.php | 8 ++--- app/Models/Expense.php | 5 +++ app/Models/Vendor.php | 5 +++ database/factories/ClientFactory.php | 5 +-- 5 files changed, 45 insertions(+), 24 deletions(-) diff --git a/app/Console/Commands/DemoMode.php b/app/Console/Commands/DemoMode.php index 0ce75296603e..4cd84e8656ad 100644 --- a/app/Console/Commands/DemoMode.php +++ b/app/Console/Commands/DemoMode.php @@ -90,6 +90,8 @@ class DemoMode extends Command private function createSmallAccount() { + $faker = \Faker\Factory::create(); + $this->count = 10; $this->info('Creating Small Account and Company'); @@ -101,6 +103,20 @@ class DemoMode extends Command 'enabled_modules' => 4095, ]); + $settings = $company->settings; + + $settings->name = $faker->company; + $settings->address1 = $faker->buildingNumber; + $settings->address2 = $faker->streetAddress; + $settings->city = $faker->city; + $settings->state = $faker->state; + $settings->postal_code = $faker->postcode; + $settings->website = $faker->url; + $settings->vat_number = $faker->numberBetween(123456789, 987654321); + $settings->phone = $faker->phoneNumber; + + $company->settings = $settings; + $company->save(); $account->default_company_id = $company->id; $account->save(); @@ -258,9 +274,7 @@ class DemoMode extends Command $settings->currency_id = (string)rand(1,3); $client->settings = $settings; - $country = Country::all()->random(); - - $client->country_id = $country->id; + $client->country_id = array_rand([36,392,840,124,276,826]); $client->save(); } @@ -268,31 +282,31 @@ class DemoMode extends Command private function createExpense($client) { factory(\App\Models\Expense::class, rand(1, 5))->create([ - 'user_id' => $client->user->id, + 'user_id' => $client->user_id, 'client_id' => $client->id, - 'company_id' => $client->company->id + 'company_id' => $client->company_id ]); } private function createVendor($client) { $vendor = factory(\App\Models\Vendor::class)->create([ - 'user_id' => $client->user->id, - 'company_id' => $client->company->id + 'user_id' => $client->user_id, + 'company_id' => $client->company_id ]); factory(\App\Models\VendorContact::class, 1)->create([ 'user_id' => $client->user->id, 'vendor_id' => $vendor->id, - 'company_id' => $client->company->id, + 'company_id' => $client->company_id, 'is_primary' => 1 ]); factory(\App\Models\VendorContact::class, rand(1, 5))->create([ 'user_id' => $client->user->id, 'vendor_id' => $vendor->id, - 'company_id' => $client->company->id, + 'company_id' => $client->company_id, 'is_primary' => 0 ]); } @@ -301,7 +315,7 @@ class DemoMode extends Command { $vendor = factory(\App\Models\Task::class)->create([ 'user_id' => $client->user->id, - 'company_id' => $client->company->id + 'company_id' => $client->company_id ]); } @@ -309,7 +323,7 @@ class DemoMode extends Command { $vendor = factory(\App\Models\Project::class)->create([ 'user_id' => $client->user->id, - 'company_id' => $client->company->id + 'company_id' => $client->company_id ]); } @@ -427,19 +441,15 @@ class DemoMode extends Command private function createQuote($client) { - // for($x=0; $x<$this->count; $x++){ - // dispatch(new CreateTestQuoteJob($client)); - // } $faker = \Faker\Factory::create(); - //$quote = QuoteFactory::create($client->company->id, $client->user->id);//stub the company and user_id - $quote =factory(\App\Models\Quote::class)->create(['user_id' => $client->user->id, 'company_id' => $client->company->id, 'client_id' => $client->id]); + $quote =factory(\App\Models\Quote::class)->create(['user_id' => $client->user->id, 'company_id' => $client->company_id, 'client_id' => $client->id]); if((bool)rand(0,1)) - $dateable = Carbon::now()->subDays(rand(0, 90)); + $dateable = Carbon::now()->subDays(rand(1, 30)); else - $dateable = Carbon::now()->addDays(rand(0, 90)); + $dateable = Carbon::now()->addDays(rand(1, 30)); $quote->date = $dateable; $quote->client_id = $client->id; diff --git a/app/Factory/QuoteFactory.php b/app/Factory/QuoteFactory.php index dfe1eaeedaae..3b2a28cb20ca 100644 --- a/app/Factory/QuoteFactory.php +++ b/app/Factory/QuoteFactory.php @@ -40,10 +40,10 @@ class QuoteFactory $quote->tax_rate1 = 0; $quote->tax_name2 = ''; $quote->tax_rate2 = 0; - $quote->custom_value1 = 0; - $quote->custom_value2 = 0; - $quote->custom_value3 = 0; - $quote->custom_value4 = 0; + $quote->custom_value1 = ''; + $quote->custom_value2 = ''; + $quote->custom_value3 = ''; + $quote->custom_value4 = ''; $quote->amount = 0; $quote->balance = 0; $quote->partial = 0; diff --git a/app/Models/Expense.php b/app/Models/Expense.php index f9bb52251068..131b9ab07a17 100644 --- a/app/Models/Expense.php +++ b/app/Models/Expense.php @@ -76,4 +76,9 @@ class Expense extends BaseModel { return $this->belongsTo(User::class, 'assigned_user_id', 'id'); } + + public function company() + { + return $this->belongsTo(Company::class); + } } diff --git a/app/Models/Vendor.php b/app/Models/Vendor.php index 5a208842d805..5594e5e23db1 100644 --- a/app/Models/Vendor.php +++ b/app/Models/Vendor.php @@ -83,4 +83,9 @@ class Vendor extends BaseModel { return $this->hasMany(Activity::class); } + + public function company() + { + return $this->belongsTo(Company::class); + } } diff --git a/database/factories/ClientFactory.php b/database/factories/ClientFactory.php index 37e20c2c523c..38618ff630de 100644 --- a/database/factories/ClientFactory.php +++ b/database/factories/ClientFactory.php @@ -5,15 +5,16 @@ use App\DataMapper\CompanySettings; use Faker\Generator as Faker; $factory->define(App\Models\Client::class, function (Faker $faker) { + return [ 'name' => $faker->company(), 'website' => $faker->url, 'private_notes' => $faker->text(200), 'balance' => 0, 'paid_to_date' => 0, - 'vat_number' => $faker->text(25), + 'vat_number' => $faker->numberBetween(123456789, 987654321), 'id_number' => '', - 'custom_value1' => $faker->date('Y-m-d'), + 'custom_value1' => '', 'custom_value2' => '', 'custom_value3' => '', 'custom_value4' => '', From 668e3228341a3b1e85eec05df4c245c8aae75849 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 17 Jul 2020 07:58:10 +1000 Subject: [PATCH 04/12] working on demo data --- app/DataMapper/CompanySettings.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index 65c98a14a3c5..179c877ac5eb 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -27,7 +27,7 @@ class CompanySettings extends BaseSettings public $auto_archive_invoice = false; public $lock_sent_invoices = false; - public $lock_invoices = 'off'; //off,when_sent,when_paid + //public $lock_invoices = 'off'; //off,when_sent,when_paid public $enable_client_portal_tasks = false; public $enable_client_portal_password = false; @@ -238,7 +238,7 @@ class CompanySettings extends BaseSettings public $client_portal_privacy_policy = ''; public static $casts = [ - 'lock_invoices' => 'string', + // 'lock_invoices' => 'string', 'client_portal_terms' => 'string', 'client_portal_privacy_policy' => 'string', 'client_can_register' => 'bool', From 2191716115184200fdb4a34ef3008fe8c671d86d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 17 Jul 2020 08:05:46 +1000 Subject: [PATCH 05/12] Fixes for demo data --- app/Console/Commands/DemoMode.php | 10 +++++----- app/DataMapper/CompanySettings.php | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/Console/Commands/DemoMode.php b/app/Console/Commands/DemoMode.php index 4cd84e8656ad..6e62da7eff29 100644 --- a/app/Console/Commands/DemoMode.php +++ b/app/Console/Commands/DemoMode.php @@ -103,7 +103,7 @@ class DemoMode extends Command 'enabled_modules' => 4095, ]); - $settings = $company->settings; + $settings = $company->settings; $settings->name = $faker->company; $settings->address1 = $faker->buildingNumber; @@ -112,11 +112,11 @@ class DemoMode extends Command $settings->state = $faker->state; $settings->postal_code = $faker->postcode; $settings->website = $faker->url; - $settings->vat_number = $faker->numberBetween(123456789, 987654321); - $settings->phone = $faker->phoneNumber; + $settings->vat_number = (string)$faker->numberBetween(123456789, 987654321); + $settings->phone = (string)$faker->phoneNumber; - $company->settings = $settings; - $company->save(); + $company->settings = $settings; + $company->save(); $account->default_company_id = $company->id; $account->save(); diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index 179c877ac5eb..65c98a14a3c5 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -27,7 +27,7 @@ class CompanySettings extends BaseSettings public $auto_archive_invoice = false; public $lock_sent_invoices = false; - //public $lock_invoices = 'off'; //off,when_sent,when_paid + public $lock_invoices = 'off'; //off,when_sent,when_paid public $enable_client_portal_tasks = false; public $enable_client_portal_password = false; @@ -238,7 +238,7 @@ class CompanySettings extends BaseSettings public $client_portal_privacy_policy = ''; public static $casts = [ - // 'lock_invoices' => 'string', + 'lock_invoices' => 'string', 'client_portal_terms' => 'string', 'client_portal_privacy_policy' => 'string', 'client_can_register' => 'bool', From c593f2bd582b475cde48c75f1535df24acfe2a02 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 17 Jul 2020 10:31:19 +1000 Subject: [PATCH 06/12] Add event listeners --- .../Activity/ArchivedClientActivity.php | 53 +++++++++++++++++++ .../Activity/DeleteClientActivity.php | 53 +++++++++++++++++++ .../Activity/RestoreClientActivity.php | 53 +++++++++++++++++++ app/Models/Activity.php | 12 ++--- app/Providers/EventServiceProvider.php | 6 +++ 5 files changed, 171 insertions(+), 6 deletions(-) create mode 100644 app/Listeners/Activity/ArchivedClientActivity.php create mode 100644 app/Listeners/Activity/DeleteClientActivity.php create mode 100644 app/Listeners/Activity/RestoreClientActivity.php diff --git a/app/Listeners/Activity/ArchivedClientActivity.php b/app/Listeners/Activity/ArchivedClientActivity.php new file mode 100644 index 000000000000..e847b90d62a1 --- /dev/null +++ b/app/Listeners/Activity/ArchivedClientActivity.php @@ -0,0 +1,53 @@ +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->client_id = $event->client->id; + $fields->user_id = $event->client->user_id; + $fields->company_id = $event->client->company_id; + $fields->activity_type_id = Activity::ARCHIVE_CLIENT; + + $this->activity_repo->save($fields, $event->client, $event->event_vars); + } +} diff --git a/app/Listeners/Activity/DeleteClientActivity.php b/app/Listeners/Activity/DeleteClientActivity.php new file mode 100644 index 000000000000..bc8bfd9ba3c5 --- /dev/null +++ b/app/Listeners/Activity/DeleteClientActivity.php @@ -0,0 +1,53 @@ +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->client_id = $event->client->id; + $fields->user_id = $event->client->user_id; + $fields->company_id = $event->client->company_id; + $fields->activity_type_id = Activity::DELETE_CLIENT; + + $this->activity_repo->save($fields, $event->client, $event->event_vars); + } +} diff --git a/app/Listeners/Activity/RestoreClientActivity.php b/app/Listeners/Activity/RestoreClientActivity.php new file mode 100644 index 000000000000..35e4cd4bc5f9 --- /dev/null +++ b/app/Listeners/Activity/RestoreClientActivity.php @@ -0,0 +1,53 @@ +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->client_id = $event->client->id; + $fields->user_id = $event->client->user_id; + $fields->company_id = $event->client->company_id; + $fields->activity_type_id = Activity::RESTORE_CLIENT; + + $this->activity_repo->save($fields, $event->client, $event->event_vars); + } +} diff --git a/app/Models/Activity.php b/app/Models/Activity.php index a2f6487cb600..d31e92194d92 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -15,12 +15,12 @@ use Illuminate\Database\Eloquent\Model; class Activity extends StaticModel { - const CREATE_CLIENT=1; - const ARCHIVE_CLIENT=2; - const DELETE_CLIENT=3; - const CREATE_INVOICE=4; - const UPDATE_INVOICE=5; - const EMAIL_INVOICE=6; + const CREATE_CLIENT=1; // + const ARCHIVE_CLIENT=2; // + const DELETE_CLIENT=3; // + const CREATE_INVOICE=4; // + const UPDATE_INVOICE=5; // + const EMAIL_INVOICE=6; // const VIEW_INVOICE=7; const ARCHIVE_INVOICE=8; const DELETE_INVOICE=9; diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 9b8a3348f145..86e13b666212 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -41,11 +41,14 @@ use App\Events\Quote\QuoteWasApproved; use App\Events\User\UserLoggedIn; use App\Events\User\UserWasCreated; use App\Events\User\UserWasDeleted; +use App\Listeners\Activity\ArchivedClientActivity; use App\Listeners\Activity\CreatedClientActivity; +use App\Listeners\Activity\DeleteClientActivity; use App\Listeners\Activity\PaymentCreatedActivity; use App\Listeners\Activity\PaymentDeletedActivity; use App\Listeners\Activity\PaymentRefundedActivity; use App\Listeners\Activity\PaymentVoidedActivity; +use App\Listeners\Activity\RestoreClientActivity; use App\Listeners\Contact\UpdateContactLastLogin; use App\Listeners\Document\DeleteCompanyDocuments; use App\Listeners\Invoice\CreateInvoiceActivity; @@ -105,12 +108,15 @@ class EventServiceProvider extends ServiceProvider CreatedClientActivity::class, ], ClientWasArchived::class =>[ + ArchivedClientActivity::class, ], ClientWasUpdated::class =>[ ], ClientWasDeleted::class =>[ + DeleteClientActivity::class, ], ClientWasRestored::class =>[ + RestoreClientActivity::class, ], // Documents DocumentWasCreated::class =>[ From da8831941830bd71fb01287d733f7fa3179efc6c Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 17 Jul 2020 11:18:40 +1000 Subject: [PATCH 07/12] Event listener for invoice viewed --- app/Events/Invoice/InvoiceWasViewed.php | 44 ++++++++++++++ .../ClientPortal/InvitationController.php | 18 ++++++ .../Invoice/InvoiceViewedActivity.php | 59 +++++++++++++++++++ app/Providers/EventServiceProvider.php | 5 ++ 4 files changed, 126 insertions(+) create mode 100644 app/Events/Invoice/InvoiceWasViewed.php create mode 100644 app/Listeners/Invoice/InvoiceViewedActivity.php diff --git a/app/Events/Invoice/InvoiceWasViewed.php b/app/Events/Invoice/InvoiceWasViewed.php new file mode 100644 index 000000000000..34c26c4733b0 --- /dev/null +++ b/app/Events/Invoice/InvoiceWasViewed.php @@ -0,0 +1,44 @@ +invitation = $invitation; + $this->company = $company; + $this->event_vars = $event_vars; + } +} diff --git a/app/Http/Controllers/ClientPortal/InvitationController.php b/app/Http/Controllers/ClientPortal/InvitationController.php index 8061672d3c61..8453e788f76c 100644 --- a/app/Http/Controllers/ClientPortal/InvitationController.php +++ b/app/Http/Controllers/ClientPortal/InvitationController.php @@ -11,6 +11,7 @@ namespace App\Http\Controllers\ClientPortal; +use App\Events\Invoice\InvoiceWasViewed; use App\Events\Misc\InvitationWasViewed; use App\Http\Controllers\Controller; use App\Models\InvoiceInvitation; @@ -39,6 +40,7 @@ class InvitationController extends Controller $invitation = $entity_obj::whereRaw("BINARY `key`= ?", [$invitation_key])->first(); if ($invitation) { + if ((bool)$invitation->contact->client->getSetting('enable_client_portal_password') !== false) { $this->middleware('auth:contact'); } else { @@ -51,6 +53,8 @@ class InvitationController extends Controller $invitation->markViewed(); 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})]); @@ -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) { return redirect('client/'.$entity.'/'.$invitation_key.'/download_pdf'); diff --git a/app/Listeners/Invoice/InvoiceViewedActivity.php b/app/Listeners/Invoice/InvoiceViewedActivity.php new file mode 100644 index 000000000000..c3b0e52efecd --- /dev/null +++ b/app/Listeners/Invoice/InvoiceViewedActivity.php @@ -0,0 +1,59 @@ +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); + } +} diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 86e13b666212..ff955841ca74 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -32,6 +32,7 @@ use App\Events\Invoice\InvoiceWasMarkedSent; use App\Events\Invoice\InvoiceWasPaid; use App\Events\Invoice\InvoiceWasReversed; use App\Events\Invoice\InvoiceWasUpdated; +use App\Events\Invoice\InvoiceWasViewed; use App\Events\Misc\InvitationWasViewed; use App\Events\Payment\PaymentWasCreated; use App\Events\Payment\PaymentWasDeleted; @@ -59,6 +60,7 @@ use App\Listeners\Invoice\InvoiceDeletedActivity; use App\Listeners\Invoice\InvoiceEmailActivity; use App\Listeners\Invoice\InvoiceEmailFailedActivity; use App\Listeners\Invoice\InvoiceEmailedNotification; +use App\Listeners\Invoice\InvoiceViewedActivity; use App\Listeners\Invoice\UpdateInvoiceActivity; use App\Listeners\Invoice\UpdateInvoiceInvitations; use App\Listeners\Misc\InvitationViewedListener; @@ -159,6 +161,9 @@ class EventServiceProvider extends ServiceProvider InvoiceWasPaid::class => [ CreateInvoiceHtmlBackup::class, ], + InvoiceWasViewed::class = [ + InvoiceViewedActivity::class, + ], InvoiceWasEmailed::class => [ InvoiceEmailActivity::class, InvoiceEmailedNotification::class, From 1b79188b354d3c8499ee41c9cb2fa37a7439b3a9 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 17 Jul 2020 11:28:54 +1000 Subject: [PATCH 08/12] Adding more event listeners --- app/Events/Payment/PaymentWasUpdated.php | 45 ++++++++++++ .../Activity/PaymentArchivedActivity.php | 70 +++++++++++++++++++ .../Activity/PaymentUpdatedActivity.php | 70 +++++++++++++++++++ .../Invoice/InvoiceArchivedActivity.php | 57 +++++++++++++++ app/Models/Activity.php | 14 ++-- app/Providers/EventServiceProvider.php | 14 ++++ 6 files changed, 263 insertions(+), 7 deletions(-) create mode 100644 app/Events/Payment/PaymentWasUpdated.php create mode 100644 app/Listeners/Activity/PaymentArchivedActivity.php create mode 100644 app/Listeners/Activity/PaymentUpdatedActivity.php create mode 100644 app/Listeners/Invoice/InvoiceArchivedActivity.php diff --git a/app/Events/Payment/PaymentWasUpdated.php b/app/Events/Payment/PaymentWasUpdated.php new file mode 100644 index 000000000000..054e0a9f461b --- /dev/null +++ b/app/Events/Payment/PaymentWasUpdated.php @@ -0,0 +1,45 @@ +payment = $payment; + $this->company = $company; + $this->event_vars = $event_vars; + } +} diff --git a/app/Listeners/Activity/PaymentArchivedActivity.php b/app/Listeners/Activity/PaymentArchivedActivity.php new file mode 100644 index 000000000000..816e257efc3f --- /dev/null +++ b/app/Listeners/Activity/PaymentArchivedActivity.php @@ -0,0 +1,70 @@ +activity_repo = $activity_repo; + } + + /** + * Handle the event. + * + * @param object $event + * @return void + */ + public function handle($event) + { + MultiDB::setDb($event->company->db); + + $payment = $event->payment; + + $invoices = $payment->invoices; + + $fields = new \stdClass; + + $fields->payment_id = $payment->id; + $fields->user_id = $payment->user_id; + $fields->company_id = $payment->company_id; + $fields->activity_type_id = Activity::ARCHIVE_PAYMENT; + + // foreach ($invoices as $invoice) { //todo we may need to add additional logic if in the future we apply payments to other entity Types, not just invoices + // $fields->invoice_id = $invoice->id; + + // $this->activity_repo->save($fields, $invoice, $event->event_vars); + // } + + // if (count($invoices) == 0) { + // $this->activity_repo->save($fields, $payment, $event->event_vars); + // } + + $this->activity_repo->save($fields, $payment, $event->event_vars); + + } +} diff --git a/app/Listeners/Activity/PaymentUpdatedActivity.php b/app/Listeners/Activity/PaymentUpdatedActivity.php new file mode 100644 index 000000000000..5185b562147c --- /dev/null +++ b/app/Listeners/Activity/PaymentUpdatedActivity.php @@ -0,0 +1,70 @@ +activity_repo = $activity_repo; + } + + /** + * Handle the event. + * + * @param object $event + * @return void + */ + public function handle($event) + { + MultiDB::setDb($event->company->db); + + $payment = $event->payment; + + $invoices = $payment->invoices; + + $fields = new \stdClass; + + $fields->payment_id = $payment->id; + $fields->user_id = $payment->user_id; + $fields->company_id = $payment->company_id; + $fields->activity_type_id = Activity::UPDATE_PAYMENT; + + $this->activity_repo->save($fields, $payment, $event->event_vars); + + // foreach ($invoices as $invoice) { + // //todo we may need to add additional logic if in the future we apply payments to other entity Types, not just invoices + // $fields->invoice_id = $invoice->id; + + // $this->activity_repo->save($fields, $invoice, $event->event_vars); + // } + + // if (count($invoices) == 0) { + // $this->activity_repo->save($fields, $payment, $event->event_vars); + // } + } +} diff --git a/app/Listeners/Invoice/InvoiceArchivedActivity.php b/app/Listeners/Invoice/InvoiceArchivedActivity.php new file mode 100644 index 000000000000..c38db35b7589 --- /dev/null +++ b/app/Listeners/Invoice/InvoiceArchivedActivity.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::ARCHIVE_INVOICE; + + $this->activity_repo->save($fields, $event->invoice, $event->event_vars); + } +} diff --git a/app/Models/Activity.php b/app/Models/Activity.php index d31e92194d92..7e08f34ce7a7 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -21,13 +21,13 @@ class Activity extends StaticModel const CREATE_INVOICE=4; // const UPDATE_INVOICE=5; // const EMAIL_INVOICE=6; // - const VIEW_INVOICE=7; - const ARCHIVE_INVOICE=8; - const DELETE_INVOICE=9; - const CREATE_PAYMENT=10; - const UPDATE_PAYMENT=11; - const ARCHIVE_PAYMENT=12; - const DELETE_PAYMENT=13; + const VIEW_INVOICE=7; // + const ARCHIVE_INVOICE=8; // + const DELETE_INVOICE=9; // + const CREATE_PAYMENT=10; // + const UPDATE_PAYMENT=11; // + const ARCHIVE_PAYMENT=12; // + const DELETE_PAYMENT=13; // const CREATE_CREDIT=14; const UPDATE_CREDIT=15; const ARCHIVE_CREDIT=16; diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index ff955841ca74..9ba87ca4dc78 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -24,6 +24,7 @@ use App\Events\Contact\ContactLoggedIn; use App\Events\Credit\CreditWasEmailedAndFailed; use App\Events\Credit\CreditWasMarkedSent; use App\Events\Design\DesignWasArchived; +use App\Events\Invoice\InvoiceWasArchived; use App\Events\Invoice\InvoiceWasCancelled; use App\Events\Invoice\InvoiceWasCreated; use App\Events\Invoice\InvoiceWasDeleted; @@ -34,9 +35,11 @@ use App\Events\Invoice\InvoiceWasReversed; use App\Events\Invoice\InvoiceWasUpdated; use App\Events\Invoice\InvoiceWasViewed; use App\Events\Misc\InvitationWasViewed; +use App\Events\Payment\PaymentWasArchived; use App\Events\Payment\PaymentWasCreated; use App\Events\Payment\PaymentWasDeleted; use App\Events\Payment\PaymentWasRefunded; +use App\Events\Payment\PaymentWasUpdated; use App\Events\Payment\PaymentWasVoided; use App\Events\Quote\QuoteWasApproved; use App\Events\User\UserLoggedIn; @@ -48,6 +51,7 @@ use App\Listeners\Activity\DeleteClientActivity; use App\Listeners\Activity\PaymentCreatedActivity; use App\Listeners\Activity\PaymentDeletedActivity; use App\Listeners\Activity\PaymentRefundedActivity; +use App\Listeners\Activity\PaymentUpdatedActivity; use App\Listeners\Activity\PaymentVoidedActivity; use App\Listeners\Activity\RestoreClientActivity; use App\Listeners\Contact\UpdateContactLastLogin; @@ -56,6 +60,7 @@ use App\Listeners\Invoice\CreateInvoiceActivity; use App\Listeners\Invoice\CreateInvoiceHtmlBackup; use App\Listeners\Invoice\CreateInvoiceInvitation; use App\Listeners\Invoice\CreateInvoicePdf; +use App\Listeners\Invoice\InvoiceArchivedActivity; use App\Listeners\Invoice\InvoiceDeletedActivity; use App\Listeners\Invoice\InvoiceEmailActivity; use App\Listeners\Invoice\InvoiceEmailFailedActivity; @@ -99,6 +104,12 @@ class EventServiceProvider extends ServiceProvider PaymentWasDeleted::class => [ PaymentDeletedActivity::class, ], + PaymentWasArchived::class => [ + PaymentArchivedActivity::class, + ], + PaymentWasUpdated::class => [ + PaymentUpdatedActivity::class, + ], PaymentWasRefunded::class => [ PaymentRefundedActivity::class, ], @@ -174,6 +185,9 @@ class EventServiceProvider extends ServiceProvider InvoiceWasDeleted::class => [ InvoiceDeletedActivity::class, ], + InvoiceWasArchived::class => [ + InvoiceArchivedActivity::class, + ], InvoiceWasReversed::class => [ ], InvoiceWasCancelled::class => [ From 8fa1bd5c7a6c65e91838e9d2ddd0a1d7e6518c80 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 17 Jul 2020 11:47:37 +1000 Subject: [PATCH 09/12] Fixes for event service provideR --- app/Providers/EventServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 9ba87ca4dc78..03ad6995417c 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -172,7 +172,7 @@ class EventServiceProvider extends ServiceProvider InvoiceWasPaid::class => [ CreateInvoiceHtmlBackup::class, ], - InvoiceWasViewed::class = [ + InvoiceWasViewed::class => [ InvoiceViewedActivity::class, ], InvoiceWasEmailed::class => [ From cd5bebbe5f6d7787a2924c837dac31bd66652d2b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 17 Jul 2020 14:44:34 +1000 Subject: [PATCH 10/12] Credit events and listeners --- app/Events/Credit/CreditWasArchived.php | 41 ++++++++++++++ .../Activity/CreatedCreditActivity.php | 53 ++++++++++++++++++ .../Activity/CreditArchivedActivity.php | 56 +++++++++++++++++++ .../Activity/UpdatedCreditActivity.php | 53 ++++++++++++++++++ app/Models/Activity.php | 4 +- app/Providers/EventServiceProvider.php | 15 +++++ 6 files changed, 220 insertions(+), 2 deletions(-) create mode 100644 app/Events/Credit/CreditWasArchived.php create mode 100644 app/Listeners/Activity/CreatedCreditActivity.php create mode 100644 app/Listeners/Activity/CreditArchivedActivity.php create mode 100644 app/Listeners/Activity/UpdatedCreditActivity.php diff --git a/app/Events/Credit/CreditWasArchived.php b/app/Events/Credit/CreditWasArchived.php new file mode 100644 index 000000000000..fdfe6fae64e4 --- /dev/null +++ b/app/Events/Credit/CreditWasArchived.php @@ -0,0 +1,41 @@ +credit = $credit; + $this->company = $company; + $this->event_vars = $event_vars; + } +} diff --git a/app/Listeners/Activity/CreatedCreditActivity.php b/app/Listeners/Activity/CreatedCreditActivity.php new file mode 100644 index 000000000000..a2406e618c2a --- /dev/null +++ b/app/Listeners/Activity/CreatedCreditActivity.php @@ -0,0 +1,53 @@ +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::CREATE_CREDIT; + + $this->activity_repo->save($fields, $event->credit, $event->event_vars); + } +} diff --git a/app/Listeners/Activity/CreditArchivedActivity.php b/app/Listeners/Activity/CreditArchivedActivity.php new file mode 100644 index 000000000000..1936fda8ed1d --- /dev/null +++ b/app/Listeners/Activity/CreditArchivedActivity.php @@ -0,0 +1,56 @@ +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->credit->id; + $fields->user_id = $event->credit->user_id; + $fields->company_id = $event->credit->company_id; + $fields->activity_type_id = Activity::ARCHIVE_CREDIT; + + $this->activity_repo->save($fields, $$event->credit, $event->event_vars); + + } +} diff --git a/app/Listeners/Activity/UpdatedCreditActivity.php b/app/Listeners/Activity/UpdatedCreditActivity.php new file mode 100644 index 000000000000..fb18689803bd --- /dev/null +++ b/app/Listeners/Activity/UpdatedCreditActivity.php @@ -0,0 +1,53 @@ +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::UPDATE_CREDIT; + + $this->activity_repo->save($fields, $event->credit, $event->event_vars); + } +} diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 7e08f34ce7a7..25b259d8724b 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -28,8 +28,8 @@ class Activity extends StaticModel const UPDATE_PAYMENT=11; // const ARCHIVE_PAYMENT=12; // const DELETE_PAYMENT=13; // - const CREATE_CREDIT=14; - const UPDATE_CREDIT=15; + const CREATE_CREDIT=14; // + const UPDATE_CREDIT=15; // const ARCHIVE_CREDIT=16; const DELETE_CREDIT=17; const CREATE_QUOTE=18; diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 03ad6995417c..16ced64cc8cc 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -21,8 +21,11 @@ use App\Events\Client\DesignWasRestored; use App\Events\Client\DesignWasUpdated; use App\Events\Company\CompanyDocumentsDeleted; use App\Events\Contact\ContactLoggedIn; +use App\Events\Credit\CreditWasArchived; +use App\Events\Credit\CreditWasCreated; use App\Events\Credit\CreditWasEmailedAndFailed; use App\Events\Credit\CreditWasMarkedSent; +use App\Events\Credit\CreditWasUpdated; use App\Events\Design\DesignWasArchived; use App\Events\Invoice\InvoiceWasArchived; use App\Events\Invoice\InvoiceWasCancelled; @@ -47,6 +50,8 @@ use App\Events\User\UserWasCreated; use App\Events\User\UserWasDeleted; use App\Listeners\Activity\ArchivedClientActivity; use App\Listeners\Activity\CreatedClientActivity; +use App\Listeners\Activity\CreatedCreditActivity; +use App\Listeners\Activity\CreditArchivedActivity; use App\Listeners\Activity\DeleteClientActivity; use App\Listeners\Activity\PaymentCreatedActivity; use App\Listeners\Activity\PaymentDeletedActivity; @@ -54,6 +59,7 @@ use App\Listeners\Activity\PaymentRefundedActivity; use App\Listeners\Activity\PaymentUpdatedActivity; use App\Listeners\Activity\PaymentVoidedActivity; use App\Listeners\Activity\RestoreClientActivity; +use App\Listeners\Activity\UpdatedCreditActivity; use App\Listeners\Contact\UpdateContactLastLogin; use App\Listeners\Document\DeleteCompanyDocuments; use App\Listeners\Invoice\CreateInvoiceActivity; @@ -142,12 +148,21 @@ class EventServiceProvider extends ServiceProvider ], DocumentWasRestored::class =>[ ], + CreditWasCreated::class => [ + CreatedCreditActivity::class, + ], + CreditWasUpdated::class => [ + UpdatedCreditActivity::class, + ], CreditWasEmailedAndFailed::class => [ ], CreditWasEmailed::class => [ ], CreditWasMarkedSent::class => [ ], + CreditWasArchived::class => [ + CreditArchivedActivity::class, + ], //Designs DesignWasArchived::class => [ ], From 439424b9339fd178c72f4464da10a5c7c9703f37 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 17 Jul 2020 19:47:17 +1000 Subject: [PATCH 11/12] Fix for activity repo --- app/Console/Commands/DemoMode.php | 2 +- app/Factory/CompanyFactory.php | 2 +- app/Jobs/Util/Import.php | 1 + app/Repositories/Migration/PaymentMigrationRepository.php | 3 ++- app/Services/Payment/RefundPayment.php | 5 +++-- app/Utils/Traits/Payment/Refundable.php | 5 +++-- 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/Console/Commands/DemoMode.php b/app/Console/Commands/DemoMode.php index 6e62da7eff29..15093de71892 100644 --- a/app/Console/Commands/DemoMode.php +++ b/app/Console/Commands/DemoMode.php @@ -100,7 +100,7 @@ class DemoMode extends Command $company = factory(\App\Models\Company::class)->create([ 'account_id' => $account->id, 'slack_webhook_url' => config('ninja.notification.slack'), - 'enabled_modules' => 4095, + 'enabled_modules' => 8191, ]); $settings = $company->settings; diff --git a/app/Factory/CompanyFactory.php b/app/Factory/CompanyFactory.php index d5a164923180..da387a0efa54 100644 --- a/app/Factory/CompanyFactory.php +++ b/app/Factory/CompanyFactory.php @@ -34,7 +34,7 @@ class CompanyFactory //$company->custom_fields = (object) ['invoice1' => '1', 'invoice2' => '2', 'client1'=>'3']; $company->custom_fields = (object) []; $company->subdomain = ''; - $company->enabled_modules = 4095; //16383 + $company->enabled_modules = 8191; //4095 return $company; } diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index a0cb64afc84a..a7ff06bea75a 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -373,6 +373,7 @@ class Import implements ShouldQueue $modified['company_id'] = $this->company->id; $modified['user_id'] = $this->processUserId($resource); $modified['balance'] = $modified['balance'] ?: 0; + $modified['paid_to_date'] = $modified['paid_to_date'] ?: 0; unset($modified['id']); unset($modified['contacts']); diff --git a/app/Repositories/Migration/PaymentMigrationRepository.php b/app/Repositories/Migration/PaymentMigrationRepository.php index 2141646269c8..8c6c3197af33 100644 --- a/app/Repositories/Migration/PaymentMigrationRepository.php +++ b/app/Repositories/Migration/PaymentMigrationRepository.php @@ -23,6 +23,7 @@ use App\Models\Payment; use App\Repositories\ActivityRepository; use App\Repositories\BaseRepository; use App\Repositories\CreditRepository; +use App\Utils\Ninja; use App\Utils\Traits\MakesHash; use App\Utils\Traits\SavesDocuments; use Illuminate\Http\Request; @@ -128,7 +129,7 @@ class PaymentMigrationRepository extends BaseRepository foreach ($payment->invoices as $invoice) { $fields->invoice_id = $invoice->id; - $this->activity_repo->save($fields, $invoice); + $this->activity_repo->save($fields, $invoice, Ninja::eventVars()); } if (count($invoices) == 0) { diff --git a/app/Services/Payment/RefundPayment.php b/app/Services/Payment/RefundPayment.php index 560ceb08bb5f..bb020019bd18 100644 --- a/app/Services/Payment/RefundPayment.php +++ b/app/Services/Payment/RefundPayment.php @@ -21,6 +21,7 @@ use App\Models\Credit; use App\Models\Invoice; use App\Models\Payment; use App\Repositories\ActivityRepository; +use App\Utils\Ninja; class RefundPayment { @@ -114,10 +115,10 @@ class RefundPayment if (isset($this->refund_data['invoices'])) { foreach ($this->refund_data['invoices'] as $invoice) { $fields->invoice_id = $invoice['invoice_id']; - $activity_repo->save($fields, $this->payment); + $activity_repo->save($fields, $this->payment, Ninja::eventVars()); } } else { - $activity_repo->save($fields, $this->payment); + $activity_repo->save($fields, $this->payment, Ninja::eventVars()); } return $this; diff --git a/app/Utils/Traits/Payment/Refundable.php b/app/Utils/Traits/Payment/Refundable.php index df54f35d043c..c31f83ea7f3d 100644 --- a/app/Utils/Traits/Payment/Refundable.php +++ b/app/Utils/Traits/Payment/Refundable.php @@ -20,6 +20,7 @@ use App\Models\Credit; use App\Models\Invoice; use App\Models\Payment; use App\Repositories\ActivityRepository; +use App\Utils\Ninja; trait Refundable { @@ -209,10 +210,10 @@ trait Refundable foreach ($data['invoices'] as $invoice) { $fields->invoice_id = $invoice->id; - $activity_repo->save($fields, $this); + $activity_repo->save($fields, $this, Ninja::eventVars()); } } else { - $activity_repo->save($fields, $this); + $activity_repo->save($fields, $this, Ninja::eventVars()); } } From e06782118639fa069b1fd924b4e91bd84e6e4f54 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 18 Jul 2020 07:52:35 +1000 Subject: [PATCH 12/12] Fixes for migration --- app/Repositories/Migration/PaymentMigrationRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Repositories/Migration/PaymentMigrationRepository.php b/app/Repositories/Migration/PaymentMigrationRepository.php index 8c6c3197af33..ea9e9178a718 100644 --- a/app/Repositories/Migration/PaymentMigrationRepository.php +++ b/app/Repositories/Migration/PaymentMigrationRepository.php @@ -133,7 +133,7 @@ class PaymentMigrationRepository extends BaseRepository } if (count($invoices) == 0) { - $this->activity_repo->save($fields, $payment); + $this->activity_repo->save($fields, $payment, Ninja::eventVars()); } if ($invoice_totals == $payment->amount) {