diff --git a/app/Console/Commands/DemoMode.php b/app/Console/Commands/DemoMode.php index 0ce75296603e..15093de71892 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'); @@ -98,9 +100,23 @@ 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; + + $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 = (string)$faker->numberBetween(123456789, 987654321); + $settings->phone = (string)$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/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/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/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/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/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/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);}, 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/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/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/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/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/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/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/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/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/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/Models/Activity.php b/app/Models/Activity.php index a2f6487cb600..25b259d8724b 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -15,21 +15,21 @@ 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 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 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; // + 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; const DELETE_CREDIT=17; const CREATE_QUOTE=18; 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/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 9b8a3348f145..16ced64cc8cc 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -21,9 +21,13 @@ 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; use App\Events\Invoice\InvoiceWasCreated; use App\Events\Invoice\InvoiceWasDeleted; @@ -32,30 +36,42 @@ 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\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; 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; 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; 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; 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; @@ -94,6 +110,12 @@ class EventServiceProvider extends ServiceProvider PaymentWasDeleted::class => [ PaymentDeletedActivity::class, ], + PaymentWasArchived::class => [ + PaymentArchivedActivity::class, + ], + PaymentWasUpdated::class => [ + PaymentUpdatedActivity::class, + ], PaymentWasRefunded::class => [ PaymentRefundedActivity::class, ], @@ -105,12 +127,15 @@ class EventServiceProvider extends ServiceProvider CreatedClientActivity::class, ], ClientWasArchived::class =>[ + ArchivedClientActivity::class, ], ClientWasUpdated::class =>[ ], ClientWasDeleted::class =>[ + DeleteClientActivity::class, ], ClientWasRestored::class =>[ + RestoreClientActivity::class, ], // Documents DocumentWasCreated::class =>[ @@ -123,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 => [ ], @@ -153,6 +187,9 @@ class EventServiceProvider extends ServiceProvider InvoiceWasPaid::class => [ CreateInvoiceHtmlBackup::class, ], + InvoiceWasViewed::class => [ + InvoiceViewedActivity::class, + ], InvoiceWasEmailed::class => [ InvoiceEmailActivity::class, InvoiceEmailedNotification::class, @@ -163,6 +200,9 @@ class EventServiceProvider extends ServiceProvider InvoiceWasDeleted::class => [ InvoiceDeletedActivity::class, ], + InvoiceWasArchived::class => [ + InvoiceArchivedActivity::class, + ], InvoiceWasReversed::class => [ ], InvoiceWasCancelled::class => [ 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; } diff --git a/app/Repositories/Migration/PaymentMigrationRepository.php b/app/Repositories/Migration/PaymentMigrationRepository.php index 2141646269c8..ea9e9178a718 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,11 +129,11 @@ 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) { - $this->activity_repo->save($fields, $payment); + $this->activity_repo->save($fields, $payment, Ninja::eventVars()); } if ($invoice_totals == $payment->amount) { 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()); } } 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' => '',