diff --git a/VERSION.txt b/VERSION.txt index 3fc3a24531b5..b046aad771ea 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.0.9 \ No newline at end of file +5.0.10 \ No newline at end of file diff --git a/app/Console/Commands/CreateTestData.php b/app/Console/Commands/CreateTestData.php index 675a00f36019..46bf28984805 100644 --- a/app/Console/Commands/CreateTestData.php +++ b/app/Console/Commands/CreateTestData.php @@ -20,6 +20,7 @@ use App\Jobs\Quote\CreateQuoteInvitations; use App\Listeners\Credit\CreateCreditInvitation; use App\Listeners\Invoice\CreateInvoiceInvitation; use App\Models\CompanyToken; +use App\Models\Country; use App\Models\Payment; use App\Models\PaymentType; use App\Models\Product; @@ -396,6 +397,14 @@ class CreateTestData extends Command ]); $client->id_number = $this->getNextClientNumber($client); + + $settings = $client->settings; + $settings->currency_id = (string)rand(1,79); + $client->settings = $settings; + + $country = Country::all()->random(); + + $client->country_id = $country->id; $client->save(); } diff --git a/app/Console/Commands/DemoMode.php b/app/Console/Commands/DemoMode.php index 3f90cbbe5c86..202a5073ca30 100644 --- a/app/Console/Commands/DemoMode.php +++ b/app/Console/Commands/DemoMode.php @@ -2,17 +2,37 @@ namespace App\Console\Commands; +use App\DataMapper\CompanySettings; +use App\Events\Invoice\InvoiceWasCreated; +use App\Factory\InvoiceFactory; +use App\Factory\InvoiceItemFactory; +use App\Helpers\Invoice\InvoiceSum; +use App\Models\CompanyToken; +use App\Models\Country; +use App\Models\Product; +use App\Models\User; +use App\Repositories\InvoiceRepository; +use App\Utils\Traits\GeneratesCounter; +use App\Utils\Traits\MakesHash; +use Carbon\Carbon; use Composer\Composer; +use Composer\Console\Application; use Composer\Factory; use Composer\IO\NullIO; use Composer\Installer; use Illuminate\Console\Command; use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Facades\Schema; +use Illuminate\Support\Str; use Symfony\Component\Console\Input\ArrayInput; -use Composer\Console\Application; class DemoMode extends Command { + use MakesHash, GeneratesCounter; + + private $count; protected $name = 'ninja:demo-mode'; /** @@ -29,6 +49,15 @@ class DemoMode extends Command */ protected $description = 'Setup demo mode'; + protected $invoice_repo; + + public function __construct(InvoiceRepository $invoice_repo) + { + parent::__construct(); + + $this->invoice_repo = $invoice_repo; + } + /** * Execute the console command. * @@ -38,9 +67,446 @@ class DemoMode extends Command { set_time_limit(0); - Artisan::call('migrate:fresh'); - Artisan::call('db:seed'); - Artisan::call('db:seed --class=RandomDataSeeder'); + $this->info("Migrating"); + Artisan::call('migrate:fresh --force'); + + $this->info("Seeding"); + Artisan::call('db:seed --force'); + + $this->info("Seeding Random Data"); + $this->createSmallAccount(); + } + + + + + private function createSmallAccount() + { + $this->count = 10; + + $this->info('Creating Small Account and Company'); + + $account = factory(\App\Models\Account::class)->create(); + $company = factory(\App\Models\Company::class)->create([ + 'account_id' => $account->id, + 'slack_webhook_url' => config('ninja.notification.slack'), + ]); + + + $account->default_company_id = $company->id; + $account->save(); + + $user = User::whereEmail('small@example.com')->first(); + + if (!$user) { + $user = factory(\App\Models\User::class)->create([ + 'account_id' => $account->id, + 'email' => 'small@example.com', + 'confirmation_code' => $this->createDbHash(config('database.default')) + ]); + } + + $company_token = new CompanyToken; + $company_token->user_id = $user->id; + $company_token->company_id = $company->id; + $company_token->account_id = $account->id; + $company_token->name = 'test token'; + $company_token->token = Str::random(64); + $company_token->save(); + + $user->companies()->attach($company->id, [ + 'account_id' => $account->id, + 'is_owner' => 1, + 'is_admin' => 1, + 'is_locked' => 0, + 'notifications' => CompanySettings::notificationDefaults(), + // 'permissions' => '', + 'settings' => null, + ]); + + $u2 = User::where('email', 'demo@invoiceninja.com')->first(); + + if(!$u2){ + + $u2 = factory(\App\Models\User::class)->create([ + 'email' => 'demo@invoiceninja.com', + 'password' => Hash::make('demo'), + 'account_id' => $account->id, + 'confirmation_code' => $this->createDbHash(config('database.default')) + ]); + + $company_token = new CompanyToken; + $company_token->user_id = $u2->id; + $company_token->company_id = $company->id; + $company_token->account_id = $account->id; + $company_token->name = 'test token'; + $company_token->token = 'TOKEN'; + $company_token->save(); + + $u2->companies()->attach($company->id, [ + 'account_id' => $account->id, + 'is_owner' => 1, + 'is_admin' => 1, + 'is_locked' => 0, + 'notifications' => CompanySettings::notificationDefaults(), + 'permissions' => '', + 'settings' => null, + ]); + } + + + factory(\App\Models\Product::class, 50)->create([ + 'user_id' => $user->id, + 'company_id' => $company->id, + ]); + + $this->info('Creating '.$this->count. ' clients'); + + for ($x=0; $x<$this->count; $x++) { + $z = $x+1; + $this->info("Creating client # ".$z); + + $this->createClient($company, $user); + } + + for($x=0; $x<$this->count; $x++) + { + $client = $company->clients->random(); + + $this->info('creating invoice for client #'.$client->id); + $this->createInvoice($client); + + $client = $company->clients->random(); + + $this->info('creating credit for client #'.$client->id); + $this->createCredit($client); + + $client = $company->clients->random(); + + $this->info('creating quote for client #'.$client->id); + $this->createQuote($client); + + $client = $company->clients->random(); + + $this->info('creating expense for client #'.$client->id); + $this->createExpense($client); + + $client = $company->clients->random(); + + $this->info('creating vendor for client #'.$client->id); + $this->createVendor($client); + + $client = $company->clients->random(); + + $this->info('creating task for client #'.$client->id); + $this->createTask($client); + + $client = $company->clients->random(); + + $this->info('creating project for client #'.$client->id); + $this->createProject($client); + } } + + private function createClient($company, $user) + { + + // dispatch(function () use ($company, $user) { + + // }); + $client = factory(\App\Models\Client::class)->create([ + 'user_id' => $user->id, + 'company_id' => $company->id + ]); + + factory(\App\Models\ClientContact::class, 1)->create([ + 'user_id' => $user->id, + 'client_id' => $client->id, + 'company_id' => $company->id, + 'is_primary' => 1 + ]); + + factory(\App\Models\ClientContact::class, rand(1, 5))->create([ + 'user_id' => $user->id, + 'client_id' => $client->id, + 'company_id' => $company->id + ]); + + $client->id_number = $this->getNextClientNumber($client); + + $settings = $client->settings; + $settings->currency_id = (string)rand(1,79); + $client->settings = $settings; + + $country = Country::all()->random(); + + $client->country_id = $country->id; + $client->save(); + + } + + private function createExpense($client) + { + factory(\App\Models\Expense::class, rand(1, 5))->create([ + 'user_id' => $client->user->id, + 'client_id' => $client->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 + ]); + + + factory(\App\Models\VendorContact::class, 1)->create([ + 'user_id' => $client->user->id, + 'vendor_id' => $vendor->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, + 'is_primary' => 0 + ]); + } + + private function createTask($client) + { + $vendor = factory(\App\Models\Task::class)->create([ + 'user_id' => $client->user->id, + 'company_id' => $client->company->id + ]); + } + + private function createProject($client) + { + $vendor = factory(\App\Models\Project::class)->create([ + 'user_id' => $client->user->id, + 'company_id' => $client->company->id + ]); + } + + private function createInvoice($client) + { + // for($x=0; $x<$this->count; $x++){ + // dispatch(new CreateTestInvoiceJob($client)); + // } + + $faker = \Faker\Factory::create(); + + $invoice = InvoiceFactory::create($client->company->id, $client->user->id);//stub the company and user_id + $invoice->client_id = $client->id; +// $invoice->date = $faker->date(); + $dateable = Carbon::now()->subDays(rand(0, 90)); + $invoice->date = $dateable; + + $invoice->line_items = $this->buildLineItems(rand(1, 10)); + $invoice->uses_inclusive_taxes = false; + + if (rand(0, 1)) { + $invoice->tax_name1 = 'GST'; + $invoice->tax_rate1 = 10.00; + } + + if (rand(0, 1)) { + $invoice->tax_name2 = 'VAT'; + $invoice->tax_rate2 = 17.50; + } + + if (rand(0, 1)) { + $invoice->tax_name3 = 'CA Sales Tax'; + $invoice->tax_rate3 = 5; + } + + $invoice->custom_value1 = $faker->date; + $invoice->custom_value2 = rand(0, 1) ? 'yes' : 'no'; + + $invoice->save(); + + $invoice_calc = new InvoiceSum($invoice); + $invoice_calc->build(); + + $invoice = $invoice_calc->getInvoice(); + + $invoice->save(); + $invoice->service()->createInvitations()->markSent(); + + $this->invoice_repo->markSent($invoice); + + if (rand(0, 1)) { + + $invoice = $invoice->service()->markPaid()->save(); + + } + //@todo this slow things down, but gives us PDFs of the invoices for inspection whilst debugging. + event(new InvoiceWasCreated($invoice, $invoice->company)); + } + + private function createCredit($client) + { + // for($x=0; $x<$this->count; $x++){ + + // dispatch(new CreateTestCreditJob($client)); + + // } + $faker = \Faker\Factory::create(); + + $credit = factory(\App\Models\Credit::class)->create(['user_id' => $client->user->id, 'company_id' => $client->company->id, 'client_id' => $client->id]); + + $dateable = Carbon::now()->subDays(rand(0, 90)); + $credit->date = $dateable; + + $credit->line_items = $this->buildLineItems(rand(1, 10)); + $credit->uses_inclusive_taxes = false; + + if (rand(0, 1)) { + $credit->tax_name1 = 'GST'; + $credit->tax_rate1 = 10.00; + } + + if (rand(0, 1)) { + $credit->tax_name2 = 'VAT'; + $credit->tax_rate2 = 17.50; + } + + if (rand(0, 1)) { + $credit->tax_name3 = 'CA Sales Tax'; + $credit->tax_rate3 = 5; + } + + $credit->save(); + + $invoice_calc = new InvoiceSum($credit); + $invoice_calc->build(); + + $credit = $invoice_calc->getCredit(); + + $credit->save(); + $credit->service()->markSent()->save(); + $credit->service()->createInvitations(); + } + + 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->date = $faker->date(); + $quote->client_id = $client->id; + + $quote->setRelation('client', $client); + + $quote->line_items = $this->buildLineItems(rand(1, 10)); + $quote->uses_inclusive_taxes = false; + + if (rand(0, 1)) { + $quote->tax_name1 = 'GST'; + $quote->tax_rate1 = 10.00; + } + + if (rand(0, 1)) { + $quote->tax_name2 = 'VAT'; + $quote->tax_rate2 = 17.50; + } + + if (rand(0, 1)) { + $quote->tax_name3 = 'CA Sales Tax'; + $quote->tax_rate3 = 5; + } + + $quote->save(); + + $quote_calc = new InvoiceSum($quote); + $quote_calc->build(); + + $quote = $quote_calc->getQuote(); + + $quote->save(); + + $quote->service()->markSent()->save(); + $quote->service()->createInvitations(); + } + + private function buildLineItems($count = 1) + { + $line_items = []; + + for ($x=0; $x<$count; $x++) { + $item = InvoiceItemFactory::create(); + $item->quantity = 1; + //$item->cost = 10; + + if (rand(0, 1)) { + $item->tax_name1 = 'GST'; + $item->tax_rate1 = 10.00; + } + + if (rand(0, 1)) { + $item->tax_name1 = 'VAT'; + $item->tax_rate1 = 17.50; + } + + if (rand(0, 1)) { + $item->tax_name1 = 'Sales Tax'; + $item->tax_rate1 = 5; + } + + $product = Product::all()->random(); + + $item->cost = (float)$product->cost; + $item->product_key = $product->product_key; + $item->notes = $product->notes; + $item->custom_value1 = $product->custom_value1; + $item->custom_value2 = $product->custom_value2; + $item->custom_value3 = $product->custom_value3; + $item->custom_value4 = $product->custom_value4; + + + + $line_items[] = $item; + } + + return $line_items; + } + + private function warmCache() + { + /* Warm up the cache !*/ + $cached_tables = config('ninja.cached_tables'); + + foreach ($cached_tables as $name => $class) { + if (! Cache::has($name)) { + // check that the table exists in case the migration is pending + if (! Schema::hasTable((new $class())->getTable())) { + continue; + } + if ($name == 'payment_terms') { + $orderBy = 'num_days'; + } elseif ($name == 'fonts') { + $orderBy = 'sort_order'; + } elseif (in_array($name, ['currencies', 'industries', 'languages', 'countries', 'banks'])) { + $orderBy = 'name'; + } else { + $orderBy = 'id'; + } + $tableData = $class::orderBy($orderBy)->get(); + if ($tableData->count()) { + Cache::forever($name, $tableData); + } + } + } + } } diff --git a/app/Events/Account/AccountCreated.php b/app/Events/Account/AccountCreated.php index e641c04ccb8c..463050f8d2f3 100644 --- a/app/Events/Account/AccountCreated.php +++ b/app/Events/Account/AccountCreated.php @@ -32,14 +32,16 @@ class AccountCreated */ public $user; + public $company; /** * Create a new event instance. * * @return void */ - public function __construct($user) + public function __construct($user, $company) { $this->user = $user; + $this->company = $company; } /** diff --git a/app/Events/Client/ClientWasArchived.php b/app/Events/Client/ClientWasArchived.php index 83430c3d72a0..550b7516ea48 100644 --- a/app/Events/Client/ClientWasArchived.php +++ b/app/Events/Client/ClientWasArchived.php @@ -12,13 +12,14 @@ namespace App\Events\Client; use App\Models\Client; +use App\Models\Company; use Illuminate\Broadcasting\Channel; -use Illuminate\Queue\SerializesModels; -use Illuminate\Broadcasting\PrivateChannel; -use Illuminate\Broadcasting\PresenceChannel; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Broadcasting\InteractsWithSockets; +use Illuminate\Broadcasting\PresenceChannel; +use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; +use Illuminate\Foundation\Events\Dispatchable; +use Illuminate\Queue\SerializesModels; /** * Class ClientWasArchived. @@ -32,14 +33,16 @@ class ClientWasArchived */ public $client; + public $company; /** * Create a new event instance. * * @param Client $client */ - public function __construct(Client $client) + public function __construct(Client $client, Company $company) { $this->client = $client; + $this->company = $company; } /** diff --git a/app/Events/Client/ClientWasCreated.php b/app/Events/Client/ClientWasCreated.php index 94c7e6c3b7c3..4e1a50044c34 100644 --- a/app/Events/Client/ClientWasCreated.php +++ b/app/Events/Client/ClientWasCreated.php @@ -12,6 +12,7 @@ namespace App\Events\Client; use App\Models\Client; +use App\Models\Company; use Illuminate\Queue\SerializesModels; /** @@ -26,13 +27,15 @@ class ClientWasCreated */ public $client; + public $company; /** * Create a new event instance. * * @param Client $client */ - public function __construct(Client $client) + public function __construct(Client $client, Company $company) { $this->client = $client; + $this->company = $company; } } diff --git a/app/Events/Client/ClientWasDeleted.php b/app/Events/Client/ClientWasDeleted.php index 1766ed586299..e788f7ace92f 100644 --- a/app/Events/Client/ClientWasDeleted.php +++ b/app/Events/Client/ClientWasDeleted.php @@ -26,13 +26,15 @@ class ClientWasDeleted */ public $client; + public $company; /** * Create a new event instance. * * @param Client $client */ - public function __construct(Client $client) + public function __construct(Client $client, Company $company) { $this->client = $client; + $this->company = $company; } } diff --git a/app/Events/Client/ClientWasRestored.php b/app/Events/Client/ClientWasRestored.php index 464e6045e1df..81a3d1a14e67 100644 --- a/app/Events/Client/ClientWasRestored.php +++ b/app/Events/Client/ClientWasRestored.php @@ -26,13 +26,15 @@ class ClientWasRestored */ public $client; + public $company; /** * Create a new event instance. * * @param Client $client */ - public function __construct(Client $client) + public function __construct(Client $client, Company $company) { $this->client = $client; + $this->company = $company; } } diff --git a/app/Events/Client/ClientWasUpdated.php b/app/Events/Client/ClientWasUpdated.php index 0dbd33c813e8..e761a7148ab4 100644 --- a/app/Events/Client/ClientWasUpdated.php +++ b/app/Events/Client/ClientWasUpdated.php @@ -26,13 +26,15 @@ class ClientWasUpdated */ public $client; + public $company; /** * Create a new event instance. * * @param Client $client */ - public function __construct(Client $client) + public function __construct(Client $client, Company $company) { $this->client = $client; + $this->company = $company; } } diff --git a/app/Events/CompanyToken/CompanyTokenWasDeleted.php b/app/Events/CompanyToken/CompanyTokenWasDeleted.php deleted file mode 100644 index c6e914951841..000000000000 --- a/app/Events/CompanyToken/CompanyTokenWasDeleted.php +++ /dev/null @@ -1,42 +0,0 @@ -company_token = $company_token; - } - - /** - * Get the channels the event should broadcast on. - * - * @return \Illuminate\Broadcasting\Channel|array - */ - public function broadcastOn() - { - return new PrivateChannel('channel-name'); - } -} diff --git a/app/Events/Contact/ContactLoggedIn.php b/app/Events/Contact/ContactLoggedIn.php index 4f7a7626a312..447dd2c31ccb 100644 --- a/app/Events/Contact/ContactLoggedIn.php +++ b/app/Events/Contact/ContactLoggedIn.php @@ -33,14 +33,17 @@ class ContactLoggedIn */ public $client_contact; + public $company; + /** * Create a new event instance. * * @return void */ - public function __construct(ClientContact $client_contact) + public function __construct(ClientContact $client_contact, $company) { $this->client_contact = $client_contact; + $this->company = $company; } /** diff --git a/app/Events/Credit/CreditWasEmailed.php b/app/Events/Credit/CreditWasEmailed.php index 377226a48d24..0cddca9deefc 100644 --- a/app/Events/Credit/CreditWasEmailed.php +++ b/app/Events/Credit/CreditWasEmailed.php @@ -13,13 +13,16 @@ class CreditWasEmailed public $credit; + public $company; + /** * Create a new event instance. * * @return void */ - public function __construct(Credit $credit) + public function __construct(Credit $credit, $company) { $this->credit = $credit; + $this->company = $company; } } diff --git a/app/Events/Credit/CreditWasEmailedAndFailed.php b/app/Events/Credit/CreditWasEmailedAndFailed.php index 66ba51a78617..a780282a5752 100644 --- a/app/Events/Credit/CreditWasEmailedAndFailed.php +++ b/app/Events/Credit/CreditWasEmailedAndFailed.php @@ -15,10 +15,14 @@ class CreditWasEmailedAndFailed public $errors; - public function __construct(Credit $credit, array $errors) + public $company; + + public function __construct(Credit $credit, $company, array $errors) { $this->credit = $credit; + $this->company = $company; + $this->errors = $errors; } } diff --git a/app/Events/Design/DesignWasArchived.php b/app/Events/Design/DesignWasArchived.php index c41303db150d..8207d1671a84 100644 --- a/app/Events/Design/DesignWasArchived.php +++ b/app/Events/Design/DesignWasArchived.php @@ -32,14 +32,17 @@ class DesignWasArchived */ public $design; + public $company; /** * Create a new event instance. * * @param Design $design */ - public function __construct(Design $design) + public function __construct(Design $design, $company) { $this->design = $design; + + $this->company = $company; } /** diff --git a/app/Events/Design/DesignWasCreated.php b/app/Events/Design/DesignWasCreated.php index 6ed1669144ce..9e2b0bed6998 100644 --- a/app/Events/Design/DesignWasCreated.php +++ b/app/Events/Design/DesignWasCreated.php @@ -26,14 +26,17 @@ class DesignWasCreated */ public $design; + public $company; /** * Create a new event instance. * * @param Design $design */ - public function __construct(Design $design) + public function __construct(Design $design, $company) { $this->design = $design; + + $this->company = $company; } /** diff --git a/app/Events/Design/DesignWasDeleted.php b/app/Events/Design/DesignWasDeleted.php index 93602e8248ff..7944333d4bf7 100644 --- a/app/Events/Design/DesignWasDeleted.php +++ b/app/Events/Design/DesignWasDeleted.php @@ -26,14 +26,17 @@ class DesignWasDeleted */ public $design; + public $company; /** * Create a new event instance. * * @param Design $design */ - public function __construct(Design $design) + public function __construct(Design $design, $company) { $this->design = $design; + + $this->company = $company; } /** diff --git a/app/Events/Design/DesignWasRestored.php b/app/Events/Design/DesignWasRestored.php index c9f66c882319..3de5053c3b8c 100644 --- a/app/Events/Design/DesignWasRestored.php +++ b/app/Events/Design/DesignWasRestored.php @@ -26,14 +26,17 @@ class DesignWasRestored */ public $design; + public $company; /** * Create a new event instance. * * @param Design $design */ - public function __construct(Design $design) + public function __construct(Design $design, $company) { $this->design = $design; + + $this->company = $company; } /** diff --git a/app/Events/Design/DesignWasUpdated.php b/app/Events/Design/DesignWasUpdated.php index 04c7c6b62ed8..25bd8f164833 100644 --- a/app/Events/Design/DesignWasUpdated.php +++ b/app/Events/Design/DesignWasUpdated.php @@ -26,14 +26,17 @@ class DesignWasUpdated */ public $design; + public $company; /** * Create a new event instance. * * @param Design $design */ - public function __construct(Design $design) + public function __construct(Design $design, $company) { $this->design = $design; + + $this->company = $company; } /** diff --git a/app/Events/Document/DocumentWasArchived.php b/app/Events/Document/DocumentWasArchived.php index e613e6a40175..70cb9d524750 100644 --- a/app/Events/Document/DocumentWasArchived.php +++ b/app/Events/Document/DocumentWasArchived.php @@ -32,14 +32,16 @@ class DocumentWasArchived */ public $document; + public $company; /** * Create a new event instance. * * @param Document $document */ - public function __construct(Document $document) + public function __construct(Document $document, $company) { $this->document = $document; + $this->company = $company; } /** diff --git a/app/Events/Document/DocumentWasCreated.php b/app/Events/Document/DocumentWasCreated.php index 442f7a7b49eb..caf45ac264f1 100644 --- a/app/Events/Document/DocumentWasCreated.php +++ b/app/Events/Document/DocumentWasCreated.php @@ -26,13 +26,15 @@ class DocumentWasCreated */ public $document; + public $company; /** * Create a new event instance. * * @param Document $document */ - public function __construct(Document $document) + public function __construct(Document $document, $company) { $this->document = $document; + $this->company = $company; } } diff --git a/app/Events/Document/DocumentWasDeleted.php b/app/Events/Document/DocumentWasDeleted.php index 92d0856e9943..3d0f9f4357a1 100644 --- a/app/Events/Document/DocumentWasDeleted.php +++ b/app/Events/Document/DocumentWasDeleted.php @@ -26,13 +26,15 @@ class DocumentWasDeleted */ public $document; + public $company; /** * Create a new event instance. * * @param Document $document */ - public function __construct(Document $document) + public function __construct(Document $document, $company) { $this->document = $document; + $this->company = $company; } } diff --git a/app/Events/Document/DocumentWasRestored.php b/app/Events/Document/DocumentWasRestored.php index 4e6cd6aebc11..ab138a647857 100644 --- a/app/Events/Document/DocumentWasRestored.php +++ b/app/Events/Document/DocumentWasRestored.php @@ -26,13 +26,15 @@ class DocumentWasRestored */ public $document; + public $company; /** * Create a new event instance. * * @param Document $document */ - public function __construct(Document $document) + public function __construct(Document $document, $company) { $this->document = $document; + $this->company = $company; } } diff --git a/app/Events/Document/DocumentWasUpdated.php b/app/Events/Document/DocumentWasUpdated.php index 12c10d55feb8..1797b61353bf 100644 --- a/app/Events/Document/DocumentWasUpdated.php +++ b/app/Events/Document/DocumentWasUpdated.php @@ -26,13 +26,15 @@ class DocumentWasUpdated */ public $document; + public $company; /** * Create a new event instance. * * @param Document $document */ - public function __construct(Document $document) + public function __construct(Document $document, $company) { $this->document = $document; + $this->company = $company; } } diff --git a/app/Events/Expense/ExpenseWasArchived.php b/app/Events/Expense/ExpenseWasArchived.php index 803bf8494c80..195daa295a4c 100644 --- a/app/Events/Expense/ExpenseWasArchived.php +++ b/app/Events/Expense/ExpenseWasArchived.php @@ -26,13 +26,15 @@ class ExpenseWasArchived */ public $expense; + public $company; /** * Create a new event instance. * * @param Expense $expense */ - public function __construct(Expense $expense) + public function __construct(Expense $expense, $company) { $this->expense = $expense; + $this->company = $company; } } diff --git a/app/Events/Expense/ExpenseWasCreated.php b/app/Events/Expense/ExpenseWasCreated.php index f689e198c434..5cb4351deaa2 100644 --- a/app/Events/Expense/ExpenseWasCreated.php +++ b/app/Events/Expense/ExpenseWasCreated.php @@ -26,13 +26,15 @@ class ExpenseWasCreated */ public $expense; + public $company; /** * Create a new event instance. * * @param Expense $expense */ - public function __construct(Expense $expense) + public function __construct(Expense $expense, $company) { $this->expense = $expense; + $this->company = $company; } } diff --git a/app/Events/Expense/ExpenseWasDeleted.php b/app/Events/Expense/ExpenseWasDeleted.php index 429419762e5d..d79d78498d90 100644 --- a/app/Events/Expense/ExpenseWasDeleted.php +++ b/app/Events/Expense/ExpenseWasDeleted.php @@ -26,13 +26,15 @@ class ExpenseWasDeleted */ public $expense; + public $company; /** * Create a new event instance. * * @param Expense $expense */ - public function __construct(Expense $expense) + public function __construct(Expense $expense, $company) { $this->expense = $expense; + $this->company = $company; } } diff --git a/app/Events/Expense/ExpenseWasRestored.php b/app/Events/Expense/ExpenseWasRestored.php index f7e455010704..84f8843ae48b 100644 --- a/app/Events/Expense/ExpenseWasRestored.php +++ b/app/Events/Expense/ExpenseWasRestored.php @@ -26,13 +26,15 @@ class ExpenseWasRestored */ public $expense; + public $company; /** * Create a new event instance. * * @param Expense $expense */ - public function __construct(Expense $expense) + public function __construct(Expense $expense, $company) { $this->expense = $expense; + $this->company = $company; } } diff --git a/app/Events/Expense/ExpenseWasUpdated.php b/app/Events/Expense/ExpenseWasUpdated.php index 3d4bbec8b925..6a1029b7266a 100644 --- a/app/Events/Expense/ExpenseWasUpdated.php +++ b/app/Events/Expense/ExpenseWasUpdated.php @@ -26,13 +26,15 @@ class ExpenseWasUpdated */ public $expense; + public $company; /** * Create a new event instance. * * @param Expense $expense */ - public function __construct(Expense $expense) + public function __construct(Expense $expense, $company) { $this->expense = $expense; + $this->company = $company; } } diff --git a/app/Events/Invoice/InvoiceWasArchived.php b/app/Events/Invoice/InvoiceWasArchived.php index aff1242358c7..7b59934ff42d 100644 --- a/app/Events/Invoice/InvoiceWasArchived.php +++ b/app/Events/Invoice/InvoiceWasArchived.php @@ -26,13 +26,15 @@ class InvoiceWasArchived */ public $invoice; + public $company; /** * Create a new event instance. * * @param Invoice $invoice */ - public function __construct(Invoice $invoice) + public function __construct(Invoice $invoice, $company) { $this->invoice = $invoice; + $this->company = $company; } } diff --git a/app/Events/Invoice/InvoiceWasCancelled.php b/app/Events/Invoice/InvoiceWasCancelled.php index 399738515c58..b6ce0f72db87 100644 --- a/app/Events/Invoice/InvoiceWasCancelled.php +++ b/app/Events/Invoice/InvoiceWasCancelled.php @@ -26,13 +26,15 @@ class InvoiceWasCancelled */ public $invoice; + public $company; /** * Create a new event instance. * * @param Invoice $invoice */ - public function __construct(Invoice $invoice) + public function __construct(Invoice $invoice, $company) { $this->invoice = $invoice; + $this->company = $company; } } diff --git a/app/Events/Invoice/InvoiceWasDeleted.php b/app/Events/Invoice/InvoiceWasDeleted.php index 12575aa0603f..3515d916e2f5 100644 --- a/app/Events/Invoice/InvoiceWasDeleted.php +++ b/app/Events/Invoice/InvoiceWasDeleted.php @@ -26,13 +26,15 @@ class InvoiceWasDeleted */ public $invoice; + public $company; /** * Create a new event instance. * * @param Invoice $invoice */ - public function __construct(Invoice $invoice) + public function __construct(Invoice $invoice, $company) { $this->invoice = $invoice; + $this->company = $company; } } diff --git a/app/Events/Invoice/InvoiceWasEmailed.php b/app/Events/Invoice/InvoiceWasEmailed.php index 4263c2864508..8e31ccfe7a79 100644 --- a/app/Events/Invoice/InvoiceWasEmailed.php +++ b/app/Events/Invoice/InvoiceWasEmailed.php @@ -26,13 +26,15 @@ class InvoiceWasEmailed */ public $invitation; + public $company; /** * Create a new event instance. * * @param Invoice $invoice */ - public function __construct(InvoiceInvitation $invitation) + public function __construct(InvoiceInvitation $invitation, $company) { $this->invitation = $invitation; + $this->company = $company; } } diff --git a/app/Events/Invoice/InvoiceWasEmailedAndFailed.php b/app/Events/Invoice/InvoiceWasEmailedAndFailed.php index b9f0e34f76b0..26a909914008 100644 --- a/app/Events/Invoice/InvoiceWasEmailedAndFailed.php +++ b/app/Events/Invoice/InvoiceWasEmailedAndFailed.php @@ -31,15 +31,19 @@ class InvoiceWasEmailedAndFailed */ public $errors; + + public $company; /** * Create a new event instance. * * @param Invoice $invoice */ - public function __construct(Invoice $invoice, array $errors) + public function __construct(Invoice $invoice, $company, array $errors) { $this->invoice = $invoice; + $this->company = $company; + $this->errors = $errors; } } diff --git a/app/Events/Invoice/InvoiceWasRestored.php b/app/Events/Invoice/InvoiceWasRestored.php index 56c16f06eb29..bd0592a932df 100644 --- a/app/Events/Invoice/InvoiceWasRestored.php +++ b/app/Events/Invoice/InvoiceWasRestored.php @@ -28,15 +28,17 @@ class InvoiceWasRestored public $fromDeleted; + public $company; /** * Create a new event instance. * * @param Invoice $invoice * @param $fromDeleted */ - public function __construct(Invoice $invoice, $fromDeleted) + public function __construct(Invoice $invoice, $fromDeleted, $company) { $this->invoice = $invoice; $this->fromDeleted = $fromDeleted; + $this->company = $company; } } diff --git a/app/Events/Invoice/InvoiceWasReversed.php b/app/Events/Invoice/InvoiceWasReversed.php index c23510014995..3e76f334bc49 100644 --- a/app/Events/Invoice/InvoiceWasReversed.php +++ b/app/Events/Invoice/InvoiceWasReversed.php @@ -26,13 +26,15 @@ class InvoiceWasReversed */ public $invoice; + public $company; /** * Create a new event instance. * * @param Invoice $invoice */ - public function __construct(Invoice $invoice) + public function __construct(Invoice $invoice, $company) { $this->invoice = $invoice; + $this->company = $company; } } diff --git a/app/Events/Misc/InvitationWasViewed.php b/app/Events/Misc/InvitationWasViewed.php index 0f5a5463affe..25b8dffe15be 100644 --- a/app/Events/Misc/InvitationWasViewed.php +++ b/app/Events/Misc/InvitationWasViewed.php @@ -27,14 +27,17 @@ class InvitationWasViewed public $invitation; public $entity; + + public $company; /** * Create a new event instance. * * @param Invoice $invoice */ - public function __construct($entity, $invitation) + public function __construct($entity, $invitation, $company) { $this->entity = $entity; $this->invitation = $invitation; + $this->company = $company; } } diff --git a/app/Events/Payment/Methods/MethodDeleted.php b/app/Events/Payment/Methods/MethodDeleted.php index b0dd9cce95cd..508f1d86be82 100644 --- a/app/Events/Payment/Methods/MethodDeleted.php +++ b/app/Events/Payment/Methods/MethodDeleted.php @@ -20,14 +20,16 @@ class MethodDeleted */ private $payment_method; + public $company; /** * Create a new event instance. * * @param ClientGatewayToken $payment_method */ - public function __construct(ClientGatewayToken $payment_method) + public function __construct(ClientGatewayToken $payment_method, $company) { $this->payment_method = $payment_method; + $this->company = $company; } /** diff --git a/app/Events/Payment/PaymentCompleted.php b/app/Events/Payment/PaymentCompleted.php index d94fc13e9ea0..6476dc2919d3 100644 --- a/app/Events/Payment/PaymentCompleted.php +++ b/app/Events/Payment/PaymentCompleted.php @@ -26,13 +26,15 @@ class PaymentCompleted */ public $payment; + public $company /** * Create a new event instance. * * @param Payment $payment */ - public function __construct(Payment $payment) + public function __construct(Payment $payment, $company) { $this->payment = $payment; + $this->company = $company; } } diff --git a/app/Events/Payment/PaymentFailed.php b/app/Events/Payment/PaymentFailed.php index e7575b6f426a..f39b7ce953f8 100644 --- a/app/Events/Payment/PaymentFailed.php +++ b/app/Events/Payment/PaymentFailed.php @@ -26,13 +26,15 @@ class PaymentFailed */ public $payment; + public $company /** * Create a new event instance. * * @param Payment $payment */ - public function __construct(Payment $payment) + public function __construct(Payment $payment, $company) { $this->payment = $payment; + $this->company = $company; } } diff --git a/app/Events/Payment/PaymentWasArchived.php b/app/Events/Payment/PaymentWasArchived.php index 64e527cb273b..3b05d9ea8e60 100644 --- a/app/Events/Payment/PaymentWasArchived.php +++ b/app/Events/Payment/PaymentWasArchived.php @@ -26,13 +26,15 @@ class PaymentWasArchived */ public $payment; + public $company /** * Create a new event instance. * * @param Payment $payment */ - public function __construct(Payment $payment) + public function __construct(Payment $payment, $company) { $this->payment = $payment; + $this->company = $company; } } diff --git a/app/Events/Payment/PaymentWasDeleted.php b/app/Events/Payment/PaymentWasDeleted.php index 3315de999eb6..0fdb7f228bb6 100644 --- a/app/Events/Payment/PaymentWasDeleted.php +++ b/app/Events/Payment/PaymentWasDeleted.php @@ -26,13 +26,15 @@ class PaymentWasDeleted */ public $payment; + public $company /** * Create a new event instance. * * @param Payment $payment */ - public function __construct(Payment $payment) + public function __construct(Payment $payment, $company) { $this->payment = $payment; + $this->company = $company; } } diff --git a/app/Events/Payment/PaymentWasEmailed.php b/app/Events/Payment/PaymentWasEmailed.php index d828b105e91e..9f165d206052 100644 --- a/app/Events/Payment/PaymentWasEmailed.php +++ b/app/Events/Payment/PaymentWasEmailed.php @@ -26,12 +26,15 @@ class PaymentWasEmailed */ public $payment; + public $company /** - * PaymentWasEmailed constructor. + * Create a new event instance. + * * @param Payment $payment */ - public function __construct(Payment $payment) + public function __construct(Payment $payment, $company) { $this->payment = $payment; + $this->company = $company; } } diff --git a/app/Events/Payment/PaymentWasEmailedAndFailed.php b/app/Events/Payment/PaymentWasEmailedAndFailed.php index 5a56119fa956..c4059cec2de8 100644 --- a/app/Events/Payment/PaymentWasEmailedAndFailed.php +++ b/app/Events/Payment/PaymentWasEmailedAndFailed.php @@ -31,15 +31,18 @@ class PaymentWasEmailedAndFailed */ public $errors; + public $company; /** * PaymentWasEmailedAndFailed constructor. * @param Payment $payment * @param array $errors */ - public function __construct(Payment $payment, array $errors) + public function __construct(Payment $payment, $company, array $errors) { $this->payment = $payment; $this->errors = $errors; + + $this->company = $company; } } diff --git a/app/Events/Payment/PaymentWasRefunded.php b/app/Events/Payment/PaymentWasRefunded.php index 5bf2dbfa624a..eed020b5ee38 100644 --- a/app/Events/Payment/PaymentWasRefunded.php +++ b/app/Events/Payment/PaymentWasRefunded.php @@ -28,15 +28,17 @@ class PaymentWasRefunded public $refund_amount; + public $company; /** * Create a new event instance. * * @param Payment $payment * @param $refund_amount */ - public function __construct(Payment $payment, $refund_amount) + public function __construct(Payment $payment, $refund_amount, $company) { $this->payment = $payment; $this->refund_amount = $refund_amount; + $this->company = $company; } } diff --git a/app/Events/Payment/PaymentWasRestored.php b/app/Events/Payment/PaymentWasRestored.php index caf993c55609..5a20d46ea50b 100644 --- a/app/Events/Payment/PaymentWasRestored.php +++ b/app/Events/Payment/PaymentWasRestored.php @@ -26,16 +26,17 @@ class PaymentWasRestored */ public $payment; public $fromDeleted; - + public $company; /** * Create a new event instance. * * @param Payment $payment * @param $fromDeleted */ - public function __construct(Payment $payment, $fromDeleted) + public function __construct(Payment $payment, $fromDeleted, $company) { $this->payment = $payment; $this->fromDeleted = $fromDeleted; + $this->company = $company; } } diff --git a/app/Events/Payment/PaymentWasVoided.php b/app/Events/Payment/PaymentWasVoided.php index a718253e2bc0..555f30c8d9e4 100644 --- a/app/Events/Payment/PaymentWasVoided.php +++ b/app/Events/Payment/PaymentWasVoided.php @@ -26,13 +26,15 @@ class PaymentWasVoided */ public $payment; + public $company /** * Create a new event instance. * * @param Payment $payment */ - public function __construct(Payment $payment) + public function __construct(Payment $payment, $company) { $this->payment = $payment; + $this->company = $company; } } diff --git a/app/Events/Product/ProductWasCreated.php b/app/Events/Product/ProductWasCreated.php index 07b1fcf113a4..54cea9bd9903 100644 --- a/app/Events/Product/ProductWasCreated.php +++ b/app/Events/Product/ProductWasCreated.php @@ -28,14 +28,17 @@ class ProductWasCreated **/ public $input; + public $company; + /** * Create a new event instance. * * @return void */ - public function __construct(Product $product, $input = null) + public function __construct(Product $product, $input = null, $company) { $this->product = $product; $this->input = $input; + $this->company = $company; } } diff --git a/app/Events/Product/ProductWasDeleted.php b/app/Events/Product/ProductWasDeleted.php index 3c4dae126363..8ae67cefe06d 100644 --- a/app/Events/Product/ProductWasDeleted.php +++ b/app/Events/Product/ProductWasDeleted.php @@ -23,13 +23,15 @@ class ProductWasDeleted */ public $product; + public $company; /** * Create a new event instance. * * @return void */ - public function __construct(Product $product) + public function __construct(Product $product, $company) { $this->product = $product; + $this->company = $company; } } diff --git a/app/Events/Product/ProductWasUpdated.php b/app/Events/Product/ProductWasUpdated.php index 2aa27106aeb7..4473bf801400 100644 --- a/app/Events/Product/ProductWasUpdated.php +++ b/app/Events/Product/ProductWasUpdated.php @@ -28,14 +28,17 @@ class ProductWasUpdated **/ public $input; + public $company; + /** * Create a new event instance. * * @return void */ - public function __construct(Product $product, $input = null) + public function __construct(Product $product, $input = null, $company) { $this->product = $product; $this->input = $input; + $this->company = $company; } } diff --git a/app/Events/Quote/QuoteWasApproved.php b/app/Events/Quote/QuoteWasApproved.php index 421911d2ddab..a879db7c3cbc 100644 --- a/app/Events/Quote/QuoteWasApproved.php +++ b/app/Events/Quote/QuoteWasApproved.php @@ -17,13 +17,15 @@ class QuoteWasApproved public $quote; + public $company; /** * Create a new event instance. * * @return void */ - public function __construct(Quote $quote) + public function __construct(Quote $quote, $company) { $this->quote = $quote; + $this->company = $company; } } diff --git a/app/Events/Quote/QuoteWasArchived.php b/app/Events/Quote/QuoteWasArchived.php index 3a1b2745a7e1..7dd633434854 100644 --- a/app/Events/Quote/QuoteWasArchived.php +++ b/app/Events/Quote/QuoteWasArchived.php @@ -18,14 +18,15 @@ class QuoteWasArchived use SerializesModels; public $quote; - + public $company; /** * Create a new event instance. * - * @param $quote + * @return void */ - public function __construct($quote) + public function __construct(Quote $quote, $company) { $this->quote = $quote; + $this->company = $company; } } diff --git a/app/Events/Quote/QuoteWasCreated.php b/app/Events/Quote/QuoteWasCreated.php index 94cfb2ffc8e0..4d9ac9d11d74 100644 --- a/app/Events/Quote/QuoteWasCreated.php +++ b/app/Events/Quote/QuoteWasCreated.php @@ -19,15 +19,17 @@ use Illuminate\Queue\SerializesModels; class QuoteWasCreated { use SerializesModels; + public $quote; - + public $company; /** * Create a new event instance. * - * @param $quote + * @return void */ - public function __construct($quote) + public function __construct(Quote $quote, $company) { $this->quote = $quote; + $this->company = $company; } } diff --git a/app/Events/Quote/QuoteWasDeleted.php b/app/Events/Quote/QuoteWasDeleted.php index c037180a7cc5..06cb17a247ec 100644 --- a/app/Events/Quote/QuoteWasDeleted.php +++ b/app/Events/Quote/QuoteWasDeleted.php @@ -21,13 +21,15 @@ class QuoteWasDeleted use SerializesModels; public $quote; + public $company; /** * Create a new event instance. * - * @param $quote + * @return void */ - public function __construct($quote) + public function __construct(Quote $quote, $company) { $this->quote = $quote; + $this->company = $company; } } diff --git a/app/Events/Quote/QuoteWasEmailed.php b/app/Events/Quote/QuoteWasEmailed.php index db0bd4c08f06..3c1895c65434 100644 --- a/app/Events/Quote/QuoteWasEmailed.php +++ b/app/Events/Quote/QuoteWasEmailed.php @@ -19,8 +19,11 @@ use Illuminate\Queue\SerializesModels; class QuoteWasEmailed { use SerializesModels; + public $quote; + public $company; + /** * @var string */ @@ -31,9 +34,11 @@ class QuoteWasEmailed * * @param $quote */ - public function __construct($quote, $notes) + public function __construct($quote, $notes, $company) { $this->quote = $quote; $this->notes = $notes; + $this->company = $company; } + } diff --git a/app/Events/Quote/QuoteWasEmailedAndFailed.php b/app/Events/Quote/QuoteWasEmailedAndFailed.php index 97075e678692..a6326f90c847 100644 --- a/app/Events/Quote/QuoteWasEmailedAndFailed.php +++ b/app/Events/Quote/QuoteWasEmailedAndFailed.php @@ -26,6 +26,8 @@ class QuoteWasEmailedAndFailed */ public $quote; + public $company; + /** * @var array */ @@ -36,10 +38,12 @@ class QuoteWasEmailedAndFailed * @param Quote $quote * @param array $errors */ - public function __construct(Quote $quote, array $errors) + public function __construct(Quote $quote, array $errors, $company) { $this->quote = $quote; $this->errors = $errors; + + $this->company = $company; } } diff --git a/app/Events/Quote/QuoteWasRestored.php b/app/Events/Quote/QuoteWasRestored.php index 7af7fb27cee3..c98173af65e3 100644 --- a/app/Events/Quote/QuoteWasRestored.php +++ b/app/Events/Quote/QuoteWasRestored.php @@ -21,13 +21,15 @@ class QuoteWasRestored use SerializesModels; public $quote; + public $company; /** * Create a new event instance. * - * @param $quote + * @return void */ - public function __construct($quote) + public function __construct(Quote $quote, $company) { $this->quote = $quote; + $this->company = $company; } } diff --git a/app/Events/Quote/QuoteWasUpdated.php b/app/Events/Quote/QuoteWasUpdated.php index 38300cf2baab..540a9056f0fb 100644 --- a/app/Events/Quote/QuoteWasUpdated.php +++ b/app/Events/Quote/QuoteWasUpdated.php @@ -21,13 +21,14 @@ class QuoteWasUpdated use SerializesModels; public $quote; + public $company; /** * Create a new event instance. * - * @param $quote + * @return void */ - public function __construct($quote) + public function __construct(Quote $quote, $company) { $this->quote = $quote; + $this->company = $company; } -} diff --git a/app/Events/Task/TaskWasArchived.php b/app/Events/Task/TaskWasArchived.php index 7bc3d39d3b46..19ef5edcdac6 100644 --- a/app/Events/Task/TaskWasArchived.php +++ b/app/Events/Task/TaskWasArchived.php @@ -26,13 +26,16 @@ class TaskWasArchived */ public $task; + public $company; + /** * Create a new event instance. * * @param Task $task */ - public function __construct(Task $task) + public function __construct(Task $task, $company) { $this->task = $task; + $this->company = $company; } } diff --git a/app/Events/Task/TaskWasCreated.php b/app/Events/Task/TaskWasCreated.php index 5ae3f4d214e4..704805fa5f1c 100644 --- a/app/Events/Task/TaskWasCreated.php +++ b/app/Events/Task/TaskWasCreated.php @@ -26,13 +26,16 @@ class TaskWasCreated */ public $task; + public $company; + /** * Create a new event instance. * * @param Task $task */ - public function __construct(Task $task) + public function __construct(Task $task, $company) { $this->task = $task; + $this->company = $company; } } diff --git a/app/Events/Task/TaskWasDeleted.php b/app/Events/Task/TaskWasDeleted.php index 9cc8b3379d4b..17da40f6b54a 100644 --- a/app/Events/Task/TaskWasDeleted.php +++ b/app/Events/Task/TaskWasDeleted.php @@ -26,13 +26,16 @@ class TaskWasDeleted */ public $task; + public $company; + /** * Create a new event instance. * * @param Task $task */ - public function __construct(Task $task) + public function __construct(Task $task, $company) { $this->task = $task; + $this->company = $company; } } diff --git a/app/Events/Task/TaskWasRestored.php b/app/Events/Task/TaskWasRestored.php index 4abd979844cb..a028cc3f504e 100644 --- a/app/Events/Task/TaskWasRestored.php +++ b/app/Events/Task/TaskWasRestored.php @@ -26,13 +26,16 @@ class TaskWasRestored */ public $task; + public $company; + /** * Create a new event instance. * * @param Task $task */ - public function __construct(Task $task) + public function __construct(Task $task, $company) { $this->task = $task; + $this->company = $company; } } diff --git a/app/Events/Task/TaskWasUpdated.php b/app/Events/Task/TaskWasUpdated.php index 688c6bf0538c..8b913f39250b 100644 --- a/app/Events/Task/TaskWasUpdated.php +++ b/app/Events/Task/TaskWasUpdated.php @@ -26,13 +26,16 @@ class TaskWasUpdated */ public $task; + public $company; + /** * Create a new event instance. * * @param Task $task */ - public function __construct(Task $task) + public function __construct(Task $task, $company) { $this->task = $task; + $this->company = $company; } } diff --git a/app/Events/User/UserLoggedIn.php b/app/Events/User/UserLoggedIn.php index 3e23ed79d980..e27b352f67f0 100644 --- a/app/Events/User/UserLoggedIn.php +++ b/app/Events/User/UserLoggedIn.php @@ -32,14 +32,16 @@ class UserLoggedIn */ public $user; + public $company; /** * Create a new event instance. * * @return void */ - public function __construct($user) + public function __construct($user, $company) { $this->user = $user; + $this->company = $company; } /** diff --git a/app/Events/Vendor/VendorWasArchived.php b/app/Events/Vendor/VendorWasArchived.php index 754d626ea611..96c10ee9a7d3 100644 --- a/app/Events/Vendor/VendorWasArchived.php +++ b/app/Events/Vendor/VendorWasArchived.php @@ -27,13 +27,15 @@ class VendorWasArchived */ public $vendor; + public $company; /** * Create a new event instance. * * @param Vendor $vendor */ - public function __construct(Vendor $vendor) + public function __construct(Vendor $vendor, $company) { $this->vendor = $vendor; + $this->company = $company; } } diff --git a/app/Events/Vendor/VendorWasCreated.php b/app/Events/Vendor/VendorWasCreated.php index ee7d7260a1ba..cbe164bb8630 100644 --- a/app/Events/Vendor/VendorWasCreated.php +++ b/app/Events/Vendor/VendorWasCreated.php @@ -26,13 +26,15 @@ class VendorWasCreated */ public $vendor; + public $company; /** * Create a new event instance. * * @param Vendor $vendor */ - public function __construct(Vendor $vendor) + public function __construct(Vendor $vendor, $company) { $this->vendor = $vendor; + $this->company = $company; } } diff --git a/app/Events/Vendor/VendorWasDeleted.php b/app/Events/Vendor/VendorWasDeleted.php index afc6cbefde13..abfe4e2a9f56 100644 --- a/app/Events/Vendor/VendorWasDeleted.php +++ b/app/Events/Vendor/VendorWasDeleted.php @@ -26,13 +26,15 @@ class VendorWasDeleted */ public $vendor; + public $company; /** * Create a new event instance. * * @param Vendor $vendor */ - public function __construct(Vendor $vendor) + public function __construct(Vendor $vendor, $company) { $this->vendor = $vendor; + $this->company = $company; } } diff --git a/app/Events/Vendor/VendorWasRestored.php b/app/Events/Vendor/VendorWasRestored.php index 8f00f495d095..c2d27fe1afd8 100644 --- a/app/Events/Vendor/VendorWasRestored.php +++ b/app/Events/Vendor/VendorWasRestored.php @@ -26,13 +26,15 @@ class VendorWasRestored */ public $vendor; + public $company; /** * Create a new event instance. * * @param Vendor $vendor */ - public function __construct(Vendor $vendor) + public function __construct(Vendor $vendor, $company) { $this->vendor = $vendor; + $this->company = $company; } } diff --git a/app/Events/Vendor/VendorWasUpdated.php b/app/Events/Vendor/VendorWasUpdated.php index 1ae648d5fa3b..2f9192d24329 100644 --- a/app/Events/Vendor/VendorWasUpdated.php +++ b/app/Events/Vendor/VendorWasUpdated.php @@ -26,13 +26,15 @@ class VendorWasUpdated */ public $vendor; + public $company; /** * Create a new event instance. * * @param Vendor $vendor */ - public function __construct(Vendor $vendor) + public function __construct(Vendor $vendor, $company) { $this->vendor = $vendor; + $this->company = $company; } } diff --git a/app/Http/Controllers/Auth/ContactLoginController.php b/app/Http/Controllers/Auth/ContactLoginController.php index c292b87aeffa..5a1a805008e7 100644 --- a/app/Http/Controllers/Auth/ContactLoginController.php +++ b/app/Http/Controllers/Auth/ContactLoginController.php @@ -63,7 +63,7 @@ class ContactLoginController extends Controller { Auth::guard('contact')->login($client, true); - event(new ContactLoggedIn($client)); + event(new ContactLoggedIn($client, $client->company)); if (session()->get('url.intended')) { return redirect(session()->get('url.intended')); diff --git a/app/Http/Controllers/ClientPortal/InvitationController.php b/app/Http/Controllers/ClientPortal/InvitationController.php index fe06f648af7a..f833cdbd3021 100644 --- a/app/Http/Controllers/ClientPortal/InvitationController.php +++ b/app/Http/Controllers/ClientPortal/InvitationController.php @@ -47,7 +47,7 @@ class InvitationController extends Controller if (!request()->has('silent')) { $invitation->markViewed(); - event(new InvitationWasViewed($entity, $invitation)); + event(new InvitationWasViewed($entity, $invitation, $entity->company)); } return redirect()->route('client.'.$entity.'.show', [$entity => $this->encodePrimaryKey($invitation->{$key})]); diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index fa22c7ac82da..c2a3e946bef4 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -716,7 +716,7 @@ class InvoiceController extends BaseController }); if ($invoice->invitations->count() > 0) { - event(new InvoiceWasEmailed($invoice->invitations->first())); + event(new InvoiceWasEmailed($invoice->invitations->first(), $invoice->company)); } if (!$bulk) { diff --git a/app/Http/Middleware/ContactTokenAuth.php b/app/Http/Middleware/ContactTokenAuth.php index b0c7ec4b7a06..96f06d0fb085 100644 --- a/app/Http/Middleware/ContactTokenAuth.php +++ b/app/Http/Middleware/ContactTokenAuth.php @@ -53,7 +53,7 @@ class ContactTokenAuth //stateless, don't remember the contact. auth()->guard('contact')->login($client_contact, false); - event(new ContactLoggedIn($client_contact)); //todo + event(new ContactLoggedIn($client_contact, $client_contact->company)); //todo } else { $error = [ 'message' => 'Invalid token', diff --git a/app/Http/Middleware/TokenAuth.php b/app/Http/Middleware/TokenAuth.php index bfa3169560bc..28e18655c1dc 100644 --- a/app/Http/Middleware/TokenAuth.php +++ b/app/Http/Middleware/TokenAuth.php @@ -67,7 +67,7 @@ class TokenAuth //stateless, don't remember the user. auth()->login($user, false); - event(new UserLoggedIn($user)); + event(new UserLoggedIn($user, $company_token->company)); } else { $error = [ 'message' => 'Invalid token', diff --git a/app/Jobs/Account/CreateAccount.php b/app/Jobs/Account/CreateAccount.php index 2c9a74e6b937..daedb63e4fb3 100644 --- a/app/Jobs/Account/CreateAccount.php +++ b/app/Jobs/Account/CreateAccount.php @@ -72,7 +72,7 @@ class CreateAccount $sp2d97e8 = CreateCompanyToken::dispatchNow($sp035a66, $spaa9f78, $spafe62e); if ($spaa9f78) { - event(new AccountCreated($spaa9f78)); + event(new AccountCreated($spaa9f78, $sp035a66)); } $spaa9f78->fresh(); diff --git a/app/Jobs/Credit/EmailCredit.php b/app/Jobs/Credit/EmailCredit.php index f4a66f2200b1..c045b4e5305a 100644 --- a/app/Jobs/Credit/EmailCredit.php +++ b/app/Jobs/Credit/EmailCredit.php @@ -69,13 +69,13 @@ class EmailCredit implements ShouldQueue ->send(new TemplateEmail($message_array, $template_style, $invitation->contact->user, $invitation->contact->client)); if (count(Mail::failures()) > 0) { - event(new CreditWasEmailedAndFailed($this->credit, Mail::failures())); + event(new CreditWasEmailedAndFailed($this->credit, $this->credit->company, Mail::failures())); return $this->logMailError($errors); } //fire any events - event(new CreditWasEmailed($this->credit)); + event(new CreditWasEmailed($this->credit, $this->company)); //sleep(5); } diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index 426b386a0888..bcf921576e78 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -347,7 +347,8 @@ class Import implements ShouldQueue $modified = $resource; $modified['company_id'] = $this->company->id; $modified['user_id'] = $this->processUserId($resource); - + $modified['balance'] = $modified['balance'] ?: 0; + unset($modified['id']); unset($modified['contacts']); diff --git a/app/Jobs/Util/ReminderJob.php b/app/Jobs/Util/ReminderJob.php index 19bc52081f8f..0c1510af3733 100644 --- a/app/Jobs/Util/ReminderJob.php +++ b/app/Jobs/Util/ReminderJob.php @@ -74,7 +74,7 @@ class ReminderJob implements ShouldQueue }); if ($invoice->invitations->count() > 0) { - event(new InvoiceWasEmailed($invoice->invitations->first())); + event(new InvoiceWasEmailed($invoice->invitations->first(), $invoice->company)); } } else { diff --git a/app/Listeners/Activity/CreatedClientActivity.php b/app/Listeners/Activity/CreatedClientActivity.php index e12d29f5cdcf..932aabfe5440 100644 --- a/app/Listeners/Activity/CreatedClientActivity.php +++ b/app/Listeners/Activity/CreatedClientActivity.php @@ -11,6 +11,7 @@ namespace App\Listeners\Activity; +use App\Libraries\MultiDB; use App\Models\Activity; use App\Repositories\ActivityRepository; use Illuminate\Contracts\Queue\ShouldQueue; @@ -19,6 +20,7 @@ use Illuminate\Queue\InteractsWithQueue; class CreatedClientActivity implements ShouldQueue { protected $activity_repo; + /** * Create the event listener. * @@ -37,6 +39,8 @@ class CreatedClientActivity implements ShouldQueue */ public function handle($event) { + MultiDB::setDb($event->company->db); + $fields = new \stdClass; $fields->client_id = $event->client->id; diff --git a/app/Listeners/Activity/PaymentCreatedActivity.php b/app/Listeners/Activity/PaymentCreatedActivity.php index 68f0b939e771..fb1d4e4e38a3 100644 --- a/app/Listeners/Activity/PaymentCreatedActivity.php +++ b/app/Listeners/Activity/PaymentCreatedActivity.php @@ -12,6 +12,7 @@ namespace App\Listeners\Activity; use App\Jobs\Invoice\InvoiceWorkflowSettings; +use App\Libraries\MultiDB; use App\Models\Activity; use App\Models\Invoice; use App\Models\Payment; @@ -21,15 +22,15 @@ use Illuminate\Queue\InteractsWithQueue; class PaymentCreatedActivity implements ShouldQueue { - protected $activityRepo; + protected $activity_repo; /** * Create the event listener. * * @return void */ - public function __construct(ActivityRepository $activityRepo) + public function __construct(ActivityRepository $activity_repo) { - $this->activityRepo = $activityRepo; + $this->activity_repo = $activity_repo; } /** @@ -40,6 +41,8 @@ class PaymentCreatedActivity implements ShouldQueue */ public function handle($event) { + MultiDB::setDb($event->company->db); + $payment = $event->payment; $invoices = $payment->invoices; @@ -57,11 +60,11 @@ class PaymentCreatedActivity implements ShouldQueue InvoiceWorkflowSettings::dispatchNow($invoice); - $this->activityRepo->save($fields, $invoice); + $this->activity_repo->save($fields, $invoice); } if (count($invoices) == 0) { - $this->activityRepo->save($fields, $payment); + $this->activity_repo->save($fields, $payment); } } } diff --git a/app/Listeners/Activity/PaymentDeletedActivity.php b/app/Listeners/Activity/PaymentDeletedActivity.php index b37b05ffa21e..9655eb672efa 100644 --- a/app/Listeners/Activity/PaymentDeletedActivity.php +++ b/app/Listeners/Activity/PaymentDeletedActivity.php @@ -11,6 +11,7 @@ namespace App\Listeners\Activity; +use App\Libraries\MultiDB; use App\Models\Activity; use App\Models\Invoice; use App\Models\Payment; @@ -20,15 +21,16 @@ use Illuminate\Queue\InteractsWithQueue; class PaymentDeletedActivity implements ShouldQueue { - protected $activityRepo; + protected $activity_repo; + /** * Create the event listener. * * @return void */ - public function __construct(ActivityRepository $activityRepo) + public function __construct(ActivityRepository $activity_repo) { - $this->activityRepo = $activityRepo; + $this->activity_repo = $activity_repo; } /** @@ -39,6 +41,8 @@ class PaymentDeletedActivity implements ShouldQueue */ public function handle($event) { + MultiDB::setDb($event->company->db); + $payment = $event->payment; $invoices = $payment->invoices; @@ -54,11 +58,11 @@ class PaymentDeletedActivity implements ShouldQueue 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->activityRepo->save($fields, $invoice); + $this->activity_repo->save($fields, $invoice); } if (count($invoices) == 0) { - $this->activityRepo->save($fields, $payment); + $this->activity_repo->save($fields, $payment); } } } diff --git a/app/Listeners/Activity/PaymentRefundedActivity.php b/app/Listeners/Activity/PaymentRefundedActivity.php index 660461887c8a..be19507a4ead 100644 --- a/app/Listeners/Activity/PaymentRefundedActivity.php +++ b/app/Listeners/Activity/PaymentRefundedActivity.php @@ -11,6 +11,7 @@ namespace App\Listeners\Activity; +use App\Libraries\MultiDB; use App\Models\Activity; use App\Repositories\ActivityRepository; use Illuminate\Contracts\Queue\ShouldQueue; @@ -37,6 +38,8 @@ class PaymentRefundedActivity implements ShouldQueue */ public function handle($event) { + MultiDB::setDb($event->company->db); + $fields = new \stdClass; $fields->client_id = $event->payment->id; diff --git a/app/Listeners/Activity/PaymentVoidedActivity.php b/app/Listeners/Activity/PaymentVoidedActivity.php index 1dd6e56f4c76..e82ab32148bb 100644 --- a/app/Listeners/Activity/PaymentVoidedActivity.php +++ b/app/Listeners/Activity/PaymentVoidedActivity.php @@ -11,6 +11,7 @@ namespace App\Listeners\Activity; +use App\Libraries\MultiDB; use App\Models\Activity; use App\Repositories\ActivityRepository; use Illuminate\Contracts\Queue\ShouldQueue; @@ -19,6 +20,7 @@ use Illuminate\Queue\InteractsWithQueue; class PaymentVoidedActivity implements ShouldQueue { protected $activity_repo; + /** * Create the event listener. * @@ -37,6 +39,8 @@ class PaymentVoidedActivity implements ShouldQueue */ public function handle($event) { + MultiDB::setDb($event->company->db); + $fields = new \stdClass; $fields->client_id = $event->payment->id; diff --git a/app/Listeners/Contact/UpdateContactLastLogin.php b/app/Listeners/Contact/UpdateContactLastLogin.php index 66cd422b9bc5..16002cc6afc1 100644 --- a/app/Listeners/Contact/UpdateContactLastLogin.php +++ b/app/Listeners/Contact/UpdateContactLastLogin.php @@ -11,6 +11,7 @@ namespace App\Listeners\Contact; +use App\Libraries\MultiDB; use App\Models\Activity; use App\Repositories\ActivityRepository; use Illuminate\Contracts\Queue\ShouldQueue; @@ -35,6 +36,8 @@ class UpdateContactLastLogin implements ShouldQueue */ public function handle($event) { + MultiDB::setDb($event->company->db); + $client_contact = $event->client_contact; $client_contact->last_login = now(); diff --git a/app/Listeners/Credit/CreateCreditInvitation.php b/app/Listeners/Credit/CreateCreditInvitation.php index cafeb182869a..8a3a0d5504d5 100644 --- a/app/Listeners/Credit/CreateCreditInvitation.php +++ b/app/Listeners/Credit/CreateCreditInvitation.php @@ -13,6 +13,7 @@ namespace App\Listeners\Credit; use App\Factory\CreditInvitationFactory; use App\Factory\InvoiceInvitationFactory; +use App\Libraries\MultiDB; use App\Models\CreditInvitation; use App\Models\InvoiceInvitation; use App\Utils\Traits\MakesHash; @@ -34,6 +35,8 @@ class CreateCreditInvitation implements ShouldQueue */ public function handle($event) { + MultiDB::setDb($event->company->db); + $credit = $event->credit; $contacts = $credit->client->contacts; diff --git a/app/Listeners/Document/DeleteCompanyDocuments.php b/app/Listeners/Document/DeleteCompanyDocuments.php index e8c4d701bace..1e81d3627c0d 100644 --- a/app/Listeners/Document/DeleteCompanyDocuments.php +++ b/app/Listeners/Document/DeleteCompanyDocuments.php @@ -3,6 +3,7 @@ namespace App\Listeners\Document; use App\Events\Company\CompanyWasDeleted; +use App\Libraries\MultiDB; use App\Models\Document; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Filesystem\Filesystem; @@ -29,7 +30,10 @@ class DeleteCompanyDocuments */ public function handle(CompanyWasDeleted $event) { - $path = sprintf('%s/%s', storage_path('app/public'), $event->company->company_key); + + MultiDB::setDb($event->company->db); + + $path = sprintf('%s/%s', storage_path('app/public'), $event->company->company_key); // Remove all files & folders, under company's path. // This will delete directory itself, as well. diff --git a/app/Listeners/Invoice/CreateInvoiceActivity.php b/app/Listeners/Invoice/CreateInvoiceActivity.php index 18cfe2f0601e..ed5f56cc8f00 100644 --- a/app/Listeners/Invoice/CreateInvoiceActivity.php +++ b/app/Listeners/Invoice/CreateInvoiceActivity.php @@ -11,6 +11,7 @@ namespace App\Listeners\Invoice; +use App\Libraries\MultiDB; use App\Models\Activity; use App\Models\ClientContact; use App\Models\InvoiceInvitation; @@ -41,6 +42,8 @@ class CreateInvoiceActivity implements ShouldQueue */ public function handle($event) { + MultiDB::setDb($event->company->db); + $fields = new \stdClass; $fields->invoice_id = $event->invoice->id; diff --git a/app/Listeners/Invoice/CreateInvoiceInvitation.php b/app/Listeners/Invoice/CreateInvoiceInvitation.php index a489a6679e3f..5fa64e389fa7 100644 --- a/app/Listeners/Invoice/CreateInvoiceInvitation.php +++ b/app/Listeners/Invoice/CreateInvoiceInvitation.php @@ -12,6 +12,7 @@ namespace App\Listeners\Invoice; use App\Factory\InvoiceInvitationFactory; +use App\Libraries\MultiDB; use App\Models\InvoiceInvitation; use App\Utils\Traits\MakesHash; use Illuminate\Contracts\Queue\ShouldQueue; @@ -32,6 +33,8 @@ class CreateInvoiceInvitation implements ShouldQueue */ public function handle($event) { + MultiDB::setDb($event->company->db); + $invoice = $event->invoice; $contacts = $invoice->client->contacts; diff --git a/app/Listeners/Invoice/CreateInvoicePdf.php b/app/Listeners/Invoice/CreateInvoicePdf.php index b7ca4eeb33ea..3654f2e39ba6 100644 --- a/app/Listeners/Invoice/CreateInvoicePdf.php +++ b/app/Listeners/Invoice/CreateInvoicePdf.php @@ -12,6 +12,7 @@ namespace App\Listeners\Invoice; use App\Jobs\Invoice\CreateInvoicePdf as PdfCreator; +use App\Libraries\MultiDB; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; @@ -35,6 +36,9 @@ class CreateInvoicePdf implements ShouldQueue */ public function handle($event) { + + MultiDB::setDb($event->company->db); + $event->invoice->invitations->each(function ($invitation) { PdfCreator::dispatch($invitation); diff --git a/app/Listeners/Invoice/InvoiceCancelledActivity.php b/app/Listeners/Invoice/InvoiceCancelledActivity.php index 3836f1c5ba9e..3c267a1c2342 100644 --- a/app/Listeners/Invoice/InvoiceCancelledActivity.php +++ b/app/Listeners/Invoice/InvoiceCancelledActivity.php @@ -11,6 +11,7 @@ namespace App\Listeners\Invoice; +use App\Libraries\MultiDB; use App\Models\Activity; use App\Models\ClientContact; use App\Models\InvoiceInvitation; @@ -41,7 +42,10 @@ class InvoiceCancelledActivity implements ShouldQueue */ public function handle($event) { - $fields = new \stdClass; + + MultiDB::setDb($event->company->db); + + $fields = new \stdClass; $fields->invoice_id = $event->invoice->id; $fields->user_id = $event->invoice->user_id; diff --git a/app/Listeners/Invoice/InvoiceDeletedActivity.php b/app/Listeners/Invoice/InvoiceDeletedActivity.php index ee7ad683df5f..f304d55c3afd 100644 --- a/app/Listeners/Invoice/InvoiceDeletedActivity.php +++ b/app/Listeners/Invoice/InvoiceDeletedActivity.php @@ -11,6 +11,7 @@ namespace App\Listeners\Invoice; +use App\Libraries\MultiDB; use App\Models\Activity; use App\Models\ClientContact; use App\Models\InvoiceInvitation; @@ -41,6 +42,9 @@ class InvoiceDeletedActivity implements ShouldQueue */ public function handle($event) { + + MultiDB::setDb($event->company->db); + $fields = new \stdClass; $fields->invoice_id = $event->invoice->id; diff --git a/app/Listeners/Invoice/InvoiceEmailActivity.php b/app/Listeners/Invoice/InvoiceEmailActivity.php index f0ca3d408676..0d583e3a858d 100644 --- a/app/Listeners/Invoice/InvoiceEmailActivity.php +++ b/app/Listeners/Invoice/InvoiceEmailActivity.php @@ -11,6 +11,7 @@ namespace App\Listeners\Invoice; +use App\Libraries\MultiDB; use App\Models\Activity; use App\Models\ClientContact; use App\Models\InvoiceInvitation; @@ -41,6 +42,8 @@ class InvoiceEmailActivity implements ShouldQueue */ public function handle($event) { + MultiDB::setDb($event->company->db); + $fields = new \stdClass; $fields->invoice_id = $event->invitation->invoice->id; diff --git a/app/Listeners/Invoice/InvoiceEmailFailedActivity.php b/app/Listeners/Invoice/InvoiceEmailFailedActivity.php index f7c098fc76e8..069853539c63 100644 --- a/app/Listeners/Invoice/InvoiceEmailFailedActivity.php +++ b/app/Listeners/Invoice/InvoiceEmailFailedActivity.php @@ -11,6 +11,7 @@ namespace App\Listeners\Invoice; +use App\Libraries\MultiDB; use App\Models\Activity; use App\Models\ClientContact; use App\Models\InvoiceInvitation; @@ -41,6 +42,8 @@ class InvoiceEmailFailedActivity implements ShouldQueue */ public function handle($event) { + MultiDB::setDb($event->company->db); + $fields = new \stdClass; $fields->invoice_id = $event->invoice->id; diff --git a/app/Listeners/Invoice/InvoiceEmailedNotification.php b/app/Listeners/Invoice/InvoiceEmailedNotification.php index aa1490387c8b..5673afb03778 100644 --- a/app/Listeners/Invoice/InvoiceEmailedNotification.php +++ b/app/Listeners/Invoice/InvoiceEmailedNotification.php @@ -12,6 +12,7 @@ namespace App\Listeners\Invoice; use App\Jobs\Mail\EntitySentMailer; +use App\Libraries\MultiDB; use App\Models\Activity; use App\Models\ClientContact; use App\Models\InvoiceInvitation; @@ -41,7 +42,8 @@ class InvoiceEmailedNotification implements ShouldQueue */ public function handle($event) { - $invitation = $event->invitation; + MultiDB::setDb($event->company->db); + foreach ($invitation->company->company_users as $company_user) { diff --git a/app/Listeners/Invoice/InvoiceReversedActivity.php b/app/Listeners/Invoice/InvoiceReversedActivity.php index 3bf956058a69..ecaee30ad19c 100644 --- a/app/Listeners/Invoice/InvoiceReversedActivity.php +++ b/app/Listeners/Invoice/InvoiceReversedActivity.php @@ -11,6 +11,7 @@ namespace App\Listeners\Invoice; +use App\Libraries\MultiDB; use App\Models\Activity; use App\Models\ClientContact; use App\Models\InvoiceInvitation; @@ -41,6 +42,8 @@ class InvoiceReversedActivity implements ShouldQueue */ public function handle($event) { + MultiDB::setDb($event->company->db); + $fields = new \stdClass; $fields->invoice_id = $event->invoice->id; diff --git a/app/Listeners/Invoice/UpdateInvoiceInvitations.php b/app/Listeners/Invoice/UpdateInvoiceInvitations.php index 83572299027e..52141fdd53a5 100644 --- a/app/Listeners/Invoice/UpdateInvoiceInvitations.php +++ b/app/Listeners/Invoice/UpdateInvoiceInvitations.php @@ -11,6 +11,7 @@ namespace App\Listeners\Invoice; +use App\Libraries\MultiDB; use App\Models\Invoice; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; @@ -35,6 +36,8 @@ class UpdateInvoiceInvitations implements ShouldQueue */ public function handle($event) { + MultiDB::setDb($event->company->db); + $payment = $event->payment; $invoices = $payment->invoices; diff --git a/app/Listeners/Misc/InvitationViewedListener.php b/app/Listeners/Misc/InvitationViewedListener.php index 2b517a5d4c34..394474432058 100644 --- a/app/Listeners/Misc/InvitationViewedListener.php +++ b/app/Listeners/Misc/InvitationViewedListener.php @@ -12,6 +12,7 @@ namespace App\Listeners\Misc; use App\Jobs\Mail\EntityViewedMailer; +use App\Libraries\MultiDB; use App\Notifications\Admin\EntityViewedNotification; use App\Utils\Traits\Notifications\UserNotifies; use Illuminate\Contracts\Queue\ShouldQueue; @@ -39,7 +40,9 @@ class InvitationViewedListener implements ShouldQueue */ public function handle($event) { - $entity_name = $event->entity; + MultiDB::setDb($event->company->db); + + $entity_name = $event->entity; $invitation = $event->invitation; $notification = new EntityViewedNotification($invitation, $entity_name); diff --git a/app/Listeners/Payment/PaymentNotification.php b/app/Listeners/Payment/PaymentNotification.php index 039b02e75dfb..99f30b210050 100644 --- a/app/Listeners/Payment/PaymentNotification.php +++ b/app/Listeners/Payment/PaymentNotification.php @@ -12,6 +12,7 @@ namespace App\Listeners\Payment; use App\Jobs\Mail\EntityPaidMailer; +use App\Libraries\MultiDB; use App\Models\Activity; use App\Models\Invoice; use App\Models\Payment; @@ -43,7 +44,9 @@ class PaymentNotification implements ShouldQueue */ public function handle($event) { - $payment = $event->payment; + MultiDB::setDb($event->company->db); + + $payment = $event->payment; /*User notifications*/ foreach ($payment->company->company_users as $company_user) { diff --git a/app/Listeners/Quote/CreateQuoteInvitation.php b/app/Listeners/Quote/CreateQuoteInvitation.php index 8d67a1ac7d23..7344fba339a9 100644 --- a/app/Listeners/Quote/CreateQuoteInvitation.php +++ b/app/Listeners/Quote/CreateQuoteInvitation.php @@ -14,6 +14,7 @@ namespace App\Listeners\Quote; use App\Factory\CreditInvitationFactory; use App\Factory\InvoiceInvitationFactory; use App\Factory\QuoteInvitationFactory; +use App\Libraries\MultiDB; use App\Models\InvoiceInvitation; use App\Models\QuoteInvitation; use App\Utils\Traits\MakesHash; @@ -35,6 +36,8 @@ class CreateQuoteInvitation implements ShouldQueue */ public function handle($event) { + MultiDB::setDb($event->company->db); + $quote = $event->credit; $contacts = $quote->client->contacts; diff --git a/app/Listeners/Quote/ReachWorkflowSettings.php b/app/Listeners/Quote/ReachWorkflowSettings.php index 9cd54bbac131..2fc0cd19f893 100644 --- a/app/Listeners/Quote/ReachWorkflowSettings.php +++ b/app/Listeners/Quote/ReachWorkflowSettings.php @@ -3,6 +3,7 @@ namespace App\Listeners\Quote; use App\Jobs\Quote\QuoteWorkflowSettings; +use App\Libraries\MultiDB; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; @@ -26,6 +27,8 @@ class ReachWorkflowSettings */ public function handle($event) { + MultiDB::setDb($event->company->db); + QuoteWorkflowSettings::dispatchNow($event->quote); } } diff --git a/app/Listeners/User/ArchivedUserActivity.php b/app/Listeners/User/ArchivedUserActivity.php index 887454229fc4..1680987a4311 100644 --- a/app/Listeners/User/ArchivedUserActivity.php +++ b/app/Listeners/User/ArchivedUserActivity.php @@ -11,6 +11,7 @@ namespace App\Listeners\User; +use App\Libraries\MultiDB; use App\Models\Activity; use App\Repositories\ActivityRepository; use Illuminate\Contracts\Queue\ShouldQueue; @@ -37,6 +38,8 @@ class ArchivedUserActivity implements ShouldQueue */ public function handle($event) { + MultiDB::setDb($event->company->db); + $fields = new \stdClass; if (auth()->user()->id) { diff --git a/app/Listeners/User/CreatedUserActivity.php b/app/Listeners/User/CreatedUserActivity.php index ada9fb56d672..0c80966b38aa 100644 --- a/app/Listeners/User/CreatedUserActivity.php +++ b/app/Listeners/User/CreatedUserActivity.php @@ -11,6 +11,7 @@ namespace App\Listeners\User; +use App\Libraries\MultiDB; use App\Models\Activity; use App\Repositories\ActivityRepository; use Illuminate\Contracts\Queue\ShouldQueue; @@ -37,6 +38,8 @@ class CreatedUserActivity implements ShouldQueue */ public function handle($event) { + MultiDB::setDb($event->company->db); + $fields = new \stdClass; if (auth()->user()) { diff --git a/app/Listeners/User/DeletedUserActivity.php b/app/Listeners/User/DeletedUserActivity.php index 298b705f5234..9774696521f6 100644 --- a/app/Listeners/User/DeletedUserActivity.php +++ b/app/Listeners/User/DeletedUserActivity.php @@ -11,6 +11,7 @@ namespace App\Listeners\User; +use App\Libraries\MultiDB; use App\Models\Activity; use App\Repositories\ActivityRepository; use Illuminate\Broadcasting\InteractsWithSockets; @@ -42,7 +43,9 @@ class DeletedUserActivity implements ShouldQueue */ public function handle($event) { - $fields = new \stdClass; + MultiDB::setDb($event->company->db); + + $fields = new \stdClass; if (auth()->user()->id) { $fields->user_id = auth()->user()->id; diff --git a/app/Listeners/User/RestoredUserActivity.php b/app/Listeners/User/RestoredUserActivity.php index d3e035af63df..ce23094b9c99 100644 --- a/app/Listeners/User/RestoredUserActivity.php +++ b/app/Listeners/User/RestoredUserActivity.php @@ -11,6 +11,7 @@ namespace App\Listeners\User; +use App\Libraries\MultiDB; use App\Models\Activity; use App\Repositories\ActivityRepository; use Illuminate\Contracts\Queue\ShouldQueue; @@ -37,6 +38,8 @@ class RestoredUserActivity implements ShouldQueue */ public function handle($event) { + MultiDB::setDb($event->company->db); + $fields = new \stdClass; if (auth()->user()->id) { diff --git a/app/Listeners/User/UpdateUserLastLogin.php b/app/Listeners/User/UpdateUserLastLogin.php index f9a8afe5839f..79e91c665cdd 100644 --- a/app/Listeners/User/UpdateUserLastLogin.php +++ b/app/Listeners/User/UpdateUserLastLogin.php @@ -11,12 +11,13 @@ namespace App\Listeners\User; +use App\Libraries\MultiDB; use App\Models\Activity; use App\Repositories\ActivityRepository; -use Illuminate\Contracts\Queue\ShouldQueue; -use Illuminate\Queue\InteractsWithQueue; use Illuminate\Broadcasting\InteractsWithSockets; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Events\Dispatchable; +use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; class UpdateUserLastLogin implements ShouldQueue @@ -40,6 +41,8 @@ class UpdateUserLastLogin implements ShouldQueue */ public function handle($event) { + MultiDB::setDb($event->company->db); + $user = $event->user; $user->last_login = now(); diff --git a/app/Listeners/User/UpdatedUserActivity.php b/app/Listeners/User/UpdatedUserActivity.php index 1d9f656f213c..e33a06c8c13e 100644 --- a/app/Listeners/User/UpdatedUserActivity.php +++ b/app/Listeners/User/UpdatedUserActivity.php @@ -11,6 +11,7 @@ namespace App\Listeners\User; +use App\Libraries\MultiDB; use App\Models\Activity; use App\Repositories\ActivityRepository; use Illuminate\Contracts\Queue\ShouldQueue; @@ -37,6 +38,8 @@ class UpdatedUserActivity implements ShouldQueue */ public function handle($event) { + MultiDB::setDb($event->company->db); + $fields = new \stdClass; if (auth()->user()->id) { diff --git a/app/Observers/ClientObserver.php b/app/Observers/ClientObserver.php index 47405f438242..3a5d86512ef7 100644 --- a/app/Observers/ClientObserver.php +++ b/app/Observers/ClientObserver.php @@ -26,7 +26,7 @@ class ClientObserver */ public function created(Client $client) { - event(new ClientWasCreated($client)); + event(new ClientWasCreated($client, $client->company)); SubscriptionHandler::dispatch(Subscription::EVENT_CREATE_CLIENT, $client); } diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index df8fc4cad950..3e1f1718bdd1 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -21,6 +21,7 @@ use App\Events\Client\DesignWasRestored; use App\Events\Client\DesignWasUpdated; use App\Events\Company\CompanyWasDeleted; use App\Events\Contact\ContactLoggedIn; +use App\Events\Credit\CreditWasEmailedAndFailed; use App\Events\Credit\CreditWasMarkedSent; use App\Events\Design\DesignWasArchived; use App\Events\Invoice\InvoiceWasCancelled; @@ -122,6 +123,10 @@ class EventServiceProvider extends ServiceProvider ], DocumentWasRestored::class =>[ ], + CreditWasEmailedAndFailed::class => [ + ], + CreditWasEmailed::class => [ + ], CreditWasMarkedSent::class => [ ], //Designs diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index a3cc6e5ed1ce..cacea5dd9511 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -78,7 +78,7 @@ class BaseRepository $className = $this->getEventClass($entity, 'Archived'); if (class_exists($className)) { - event(new $className($entity)); + event(new $className($entity, $entity->company)); } } @@ -104,7 +104,7 @@ class BaseRepository $className = $this->getEventClass($entity, 'Restored'); if (class_exists($className)) { - event(new $className($entity, $fromDeleted)); + event(new $className($entity, $fromDeleted, $entity->company)); } } @@ -125,7 +125,7 @@ class BaseRepository $className = $this->getEventClass($entity, 'Deleted'); if (class_exists($className)) { - event(new $className($entity)); + event(new $className($entity, $entity->company)); } } @@ -302,16 +302,27 @@ class BaseRepository $model->client->service()->updateBalance(($state['finished_amount'] - $state['starting_amount']))->save(); } + if(!$model->design_id) + $model->design_id = $this->decodePrimaryKey($client->getSetting('invoice_design_id')); + + info("model design id = {$model->design_id}"); + event(new InvoiceWasUpdated($model, $model->company)); } if ($class->name == Credit::class) { $model = $model->calc()->getCredit(); + + if(!$model->design_id) + $model->design_id = $this->decodePrimaryKey($client->getSetting('credit_design_id')); } if ($class->name == Quote::class) { $model = $model->calc()->getQuote(); + + if(!$model->design_id) + $model->design_id = $this->decodePrimaryKey($client->getSetting('quote_design_id')); } $model->save(); diff --git a/app/Repositories/InvoiceRepository.php b/app/Repositories/InvoiceRepository.php index e5f828f8ac47..8a1d0a0ca6d7 100644 --- a/app/Repositories/InvoiceRepository.php +++ b/app/Repositories/InvoiceRepository.php @@ -89,7 +89,7 @@ class InvoiceRepository extends BaseRepository $invoice->delete(); - event(new InvoiceWasDeleted($invoice)); + event(new InvoiceWasDeleted($invoice, $invoice->company)); return $invoice; } diff --git a/app/Services/Invoice/HandleCancellation.php b/app/Services/Invoice/HandleCancellation.php index 4b206867ea34..9ec42f86c412 100644 --- a/app/Services/Invoice/HandleCancellation.php +++ b/app/Services/Invoice/HandleCancellation.php @@ -57,7 +57,7 @@ class HandleCancellation extends AbstractService //adjust client balance $this->invoice->client->service()->updateBalance($adjustment)->save(); - event(new InvoiceWasCancelled($this->invoice)); + event(new InvoiceWasCancelled($this->invoice, $this->invoice->company)); return $this->invoice; diff --git a/app/Services/Invoice/HandleReversal.php b/app/Services/Invoice/HandleReversal.php index 0e66f3020044..961dfd6d18f8 100644 --- a/app/Services/Invoice/HandleReversal.php +++ b/app/Services/Invoice/HandleReversal.php @@ -109,7 +109,7 @@ class HandleReversal extends AbstractService ->updatePaidToDate($total_paid*-1) ->save(); - event(new InvoiceWasReversed($this->invoice)); + event(new InvoiceWasReversed($this->invoice, $this->invoice->company)); return $this->invoice; //create a ledger row for this with the resulting Credit ( also include an explanation in the notes section ) diff --git a/config/ninja.php b/config/ninja.php index c863062feb48..180e9ce47aba 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -12,7 +12,7 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => env('APP_URL', ''), 'app_domain' => env('APP_DOMAIN', ''), - 'app_version' => '5.0.9', + 'app_version' => '5.0.10', 'minimum_client_version' => '5.0.11', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', ''),