1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Merge pull request #3914 from turbo124/v2

Fixes for migration
This commit is contained in:
David Bomba 2020-07-18 07:53:03 +10:00 committed by GitHub
commit ac9a4029a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 839 additions and 49 deletions

View File

@ -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;

View File

@ -0,0 +1,41 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Events\Credit;
use App\Models\Company;
use App\Models\Credit;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class CreditWasArchived
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $credit;
public $company;
public $event_vars;
/**
* Create a new event instance.
*
* @param Credit $credit
*/
public function __construct(Credit $credit, Company $company, array $event_vars)
{
$this->credit = $credit;
$this->company = $company;
$this->event_vars = $event_vars;
}
}

View File

@ -0,0 +1,44 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Events\Invoice;
use App\Models\Company;
use App\Models\InvoiceInvitation;
use Illuminate\Queue\SerializesModels;
/**
* Class InvoiceWasViewed.
*/
class InvoiceWasViewed
{
use SerializesModels;
/**
* @var Invoice
*/
public $invitation;
public $company;
public $event_vars;
/**
* Create a new event instance.
*
* @param Invoice $invoice
*/
public function __construct(InvoiceInvitation $invitation, Company $company, array $event_vars)
{
$this->invitation = $invitation;
$this->company = $company;
$this->event_vars = $event_vars;
}
}

View File

@ -0,0 +1,45 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Events\Payment;
use App\Models\Company;
use App\Models\Payment;
use Illuminate\Queue\SerializesModels;
/**
* Class PaymentWasUpdated.
*/
class PaymentWasUpdated
{
use SerializesModels;
/**
* @var Payment
*/
public $payment;
public $company;
public $event_vars;
/**
* Create a new event instance.
*
* @param Payment $payment
*/
public function __construct(Payment $payment, Company $company, array $event_vars)
{
$this->payment = $payment;
$this->company = $company;
$this->event_vars = $event_vars;
}
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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);},

View File

@ -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');

View File

@ -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']);

View File

@ -0,0 +1,53 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Activity;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Repositories\ActivityRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class ArchivedClientActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @return void
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$fields = new \stdClass;
$fields->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);
}
}

View File

@ -0,0 +1,53 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Activity;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Repositories\ActivityRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class CreatedCreditActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @return void
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$fields = new \stdClass;
$fields->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);
}
}

View File

@ -0,0 +1,56 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Activity;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Models\Invoice;
use App\Models\Payment;
use App\Repositories\ActivityRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class CreditArchivedActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @return void
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$fields = new \stdClass;
$fields->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);
}
}

View File

@ -0,0 +1,53 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Activity;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Repositories\ActivityRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class DeleteClientActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @return void
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$fields = new \stdClass;
$fields->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);
}
}

View File

@ -0,0 +1,70 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Activity;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Models\Invoice;
use App\Models\Payment;
use App\Repositories\ActivityRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class PaymentArchivedActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @return void
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$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);
}
}

View File

@ -0,0 +1,70 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Activity;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Models\Invoice;
use App\Models\Payment;
use App\Repositories\ActivityRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class PaymentUpdatedActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @return void
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$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);
// }
}
}

View File

@ -0,0 +1,53 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Activity;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Repositories\ActivityRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class RestoreClientActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @return void
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$fields = new \stdClass;
$fields->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);
}
}

View File

@ -0,0 +1,53 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Activity;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Repositories\ActivityRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class UpdatedCreditActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @return void
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$fields = new \stdClass;
$fields->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);
}
}

View File

@ -0,0 +1,57 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Invoice;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Models\ClientContact;
use App\Models\InvoiceInvitation;
use App\Repositories\ActivityRepository;
use App\Utils\Traits\MakesHash;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;
class InvoiceArchivedActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @return void
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$fields = new \stdClass;
$fields->invoice_id = $event->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);
}
}

View File

@ -0,0 +1,59 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Invoice;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Models\ClientContact;
use App\Models\InvoiceInvitation;
use App\Repositories\ActivityRepository;
use App\Utils\Traits\MakesHash;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;
class InvoiceViewedActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @return void
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$fields = new \stdClass;
$fields->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);
}
}

View File

@ -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;

View File

@ -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);
}
}

View File

@ -83,4 +83,9 @@ class Vendor extends BaseModel
{
return $this->hasMany(Activity::class);
}
public function company()
{
return $this->belongsTo(Company::class);
}
}

View File

@ -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 => [

View File

@ -86,7 +86,7 @@ class InvoiceRepository extends BaseRepository
$invoice->service()->handleCancellation()->save();
$invoice = $this->invoice_repo->delete($invoice);
$invoice = parent::delete($invoice);
return $invoice;
}

View File

@ -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) {

View File

@ -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;

View File

@ -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());
}
}

View File

@ -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' => '',