1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00

Merge pull request #5655 from turbo124/v5-develop

Recurring Invoice Activities
This commit is contained in:
David Bomba 2021-05-10 20:21:19 +10:00 committed by GitHub
commit cfe8b3f3c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 678 additions and 40 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -30,6 +30,7 @@ function nlog($output, $context = []): void
}
$trace = debug_backtrace();
//nlog( debug_backtrace()[1]['function']);
// \Illuminate\Support\Facades\Log::channel('invoiceninja')->info(print_r($trace[1]['class'],1), []);
\Illuminate\Support\Facades\Log::channel('invoiceninja')->info($output, $context);

View File

@ -334,8 +334,6 @@ class BaseController extends Controller
'company.task_statuses'=> function ($query) use ($updated_at, $user) {
$query->where('updated_at', '>=', $updated_at);
if(!$user->isAdmin())
$query->where('task_statuses.user_id', $user->id);
},
'company.activities'=> function ($query) use($user) {
@ -518,9 +516,6 @@ class BaseController extends Controller
'company.task_statuses'=> function ($query) use ($created_at, $user) {
$query->where('created_at', '>=', $created_at);
if(!$user->isAdmin())
$query->where('task_statuses.user_id', $user->id);
},
'company.activities'=> function ($query) use($user) {

View File

@ -11,6 +11,8 @@
namespace App\Http\Controllers;
use App\Events\RecurringInvoice\RecurringInvoiceWasCreated;
use App\Events\RecurringInvoice\RecurringInvoiceWasUpdated;
use App\Factory\RecurringInvoiceFactory;
use App\Filters\RecurringInvoiceFilters;
use App\Http\Requests\RecurringInvoice\ActionRecurringInvoiceRequest;
@ -25,6 +27,7 @@ use App\Models\Account;
use App\Models\RecurringInvoice;
use App\Repositories\RecurringInvoiceRepository;
use App\Transformers\RecurringInvoiceTransformer;
use App\Utils\Ninja;
use App\Utils\Traits\MakesHash;
use App\Utils\Traits\SavesDocuments;
use Illuminate\Http\Request;
@ -200,6 +203,8 @@ class RecurringInvoiceController extends BaseController
{
$recurring_invoice = $this->recurring_invoice_repo->save($request->all(), RecurringInvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id));
event(new RecurringInvoiceWasCreated($recurring_invoice, $recurring_invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
return $this->itemResponse($recurring_invoice);
}
@ -376,6 +381,8 @@ class RecurringInvoiceController extends BaseController
$recurring_invoice->service()->deletePdf()->save();
event(new RecurringInvoiceWasUpdated($recurring_invoice, $recurring_invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
return $this->itemResponse($recurring_invoice);
}

View File

@ -59,12 +59,8 @@ class StripeConnectController extends BaseController
$account = Account::create($data);
nlog($account);
$link = Account::link($account->id, $token);
nlog($link);
if(!$company_gateway)
$company_gateway = CompanyGatewayFactory::create($request->getCompany()->id, $request->getContact()->id);

View File

@ -37,10 +37,6 @@ class ContactKeyLogin
if (Auth::guard('contact')->check()) {
Auth::guard('contact')->logout();
}
nlog("merp");
nlog($request->has('magic_link'));
nlog($request->input('magic_link'));
nlog($request->all());
if ($request->segment(3) && config('ninja.db.multi_db_enabled')) {
if (MultiDB::findAndSetDbByContactKey($request->segment(3))) {
@ -71,7 +67,6 @@ nlog($request->all());
}
} elseif ($request->segment(2) && $request->segment(2) == 'magic_link' && $request->segment(3)) {
$contact_email = Cache::get($request->segment(3));
nlog("double merp");
if($client_contact = ClientContact::where('email', $contact_email)->first()){
Auth::guard('contact')->login($client_contact, true);
@ -83,7 +78,6 @@ nlog("double merp");
}
}
nlog("exit");
return $next($request);
}

View File

@ -22,15 +22,6 @@ class Cors
return Response::make('OK', 200, $headers);
}
/* Work around for file downloads where the response cannot contain have headers set */
// if($request instanceOf BinaryFileResponse)
// return $next($request);
// else
// return $next($request)
// ->header('Access-Control-Allow-Origin', '*')
// ->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
// ->header('Access-Control-Allow-Headers', 'X-API-SECRET,X-API-TOKEN,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range');
$response = $next($request);
$response->headers->set('Access-Control-Allow-Origin', '*');

View File

@ -53,7 +53,6 @@ class QueryLogging
$time = $timeEnd - $timeStart;
nlog($request->method().' - '.urldecode($request->url()).": $count queries - ".$time);
// nlog($request->method().' - '.urldecode($request->fullUrl()).": $count queries - ".$time);
// if($count > 50)
//nlog($queries);

View File

@ -64,16 +64,6 @@ class StoreRecurringInvoiceRequest extends Request
{
$input = $this->all();
// foreach($this->input('documents') as $document)
// {
// if($document instanceof UploadedFile){
// nlog("i am an uploaded file");
// nlog($document);
// }
// else
// nlog($document);
// }
if (array_key_exists('design_id', $input) && is_string($input['design_id'])) {
$input['design_id'] = $this->decodePrimaryKey($input['design_id']);
}

View File

@ -59,10 +59,6 @@ class StoreUserRequest extends Request
//unique user rule - check company_user table for user_id / company_id / account_id if none exist we can add the user. ELSE return false
//nlog($this->all());
//nlog($this->input('company_user.account'));
// nlog($this->input('company_user.account.id'));
// nlog($this->input('company_user.account.id'));
if (isset($input['company_user'])) {
if (! isset($input['company_user']['is_admin'])) {

View File

@ -0,0 +1,54 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\RecurringInvoice;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Repositories\ActivityRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use stdClass;
class CreateRecurringInvoiceActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @param ActivityRepository $activity_repo
*/
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->recurring_invoice_id = $event->recurring_invoice->id;
$fields->client_id = $event->recurring_invoice->client_id;
$fields->user_id = $event->recurring_invoice->user_id;
$fields->company_id = $event->recurring_invoice->company_id;
$fields->activity_type_id = Activity::CREATE_RECURRING_INVOICE;
$this->activity_repo->save($fields, $event->recurring_invoice, $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) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\RecurringInvoice;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Repositories\ActivityRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use stdClass;
class RecurringInvoiceArchivedActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @param ActivityRepository $activity_repo
*/
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);
$event->recurring_invoice->service()->deletePdf();
$fields = new stdClass;
$fields->recurring_invoice_id = $event->recurring_invoice->id;
$fields->client_id = $event->recurring_invoice->client_id;
$fields->user_id = $event->recurring_invoice->user_id;
$fields->company_id = $event->recurring_invoice->company_id;
$fields->activity_type_id = Activity::ARCHIVE_RECURRING_INVOICE;
$this->activity_repo->save($fields, $event->recurring_invoice, $event->event_vars);
}
}

View File

@ -0,0 +1,54 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\RecurringInvoice;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Repositories\ActivityRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use stdClass;
class RecurringInvoiceDeletedActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @param ActivityRepository $activity_repo
*/
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->recurring_invoice_id = $event->recurring_invoice->id;
$fields->client_id = $event->recurring_invoice->client_id;
$fields->user_id = $event->recurring_invoice->user_id;
$fields->company_id = $event->recurring_invoice->company_id;
$fields->activity_type_id = Activity::DELETE_RECURRING_INVOICE;
$this->activity_repo->save($fields, $event->recurring_invoice, $event->event_vars);
}
}

View File

@ -0,0 +1,54 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\RecurringInvoice;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Repositories\ActivityRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use stdClass;
class RecurringInvoiceRestoredActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @param ActivityRepository $activity_repo
*/
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->recurring_invoice_id = $event->recurring_invoice->id;
$fields->client_id = $event->recurring_invoice->client_id;
$fields->user_id = $event->recurring_invoice->user_id;
$fields->company_id = $event->recurring_invoice->company_id;
$fields->activity_type_id = Activity::RESTORE_RECURRING_INVOICE;
$this->activity_repo->save($fields, $event->recurring_invoice, $event->event_vars);
}
}

View File

@ -0,0 +1,54 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\RecurringInvoice;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Repositories\ActivityRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use stdClass;
class UpdateRecurringInvoiceActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @param ActivityRepository $activity_repo
*/
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->recurring_invoice->client_id;
$fields->user_id = $event->recurring_invoice->user_id;
$fields->company_id = $event->recurring_invoice->company_id;
$fields->activity_type_id = Activity::UPDATE_RECURRING_INVOICE;
$fields->recurring_invoice_id = $event->recurring_invoice->id;
$this->activity_repo->save($fields, $event->recurring_invoice, $event->event_vars);
}
}

View File

@ -90,6 +90,12 @@ class Activity extends StaticModel
const DELETE_SUBSCRIPTION = 83;
const RESTORE_SUBSCRIPTION = 84;
const CREATE_RECURRING_INVOICE = 100;
const UPDATE_RECURRING_INVOICE = 101;
const ARCHIVE_RECURRING_INVOICE = 102;
const DELETE_RECURRING_INVOICE = 103;
const RESTORE_RECURRING_INVOICE = 104;
protected $casts = [
'is_system' => 'boolean',
'updated_at' => 'timestamp',

View File

@ -157,6 +157,16 @@ class RecurringInvoice extends BaseModel
return $value;
}
public function activities()
{
return $this->hasMany(Activity::class)->orderBy('id', 'DESC')->take(300);
}
public function history()
{
return $this->hasManyThrough(Backup::class, Activity::class);
}
public function company()
{
return $this->belongsTo(Company::class);

View File

@ -68,6 +68,11 @@ use App\Events\Quote\QuoteWasEmailed;
use App\Events\Quote\QuoteWasRestored;
use App\Events\Quote\QuoteWasUpdated;
use App\Events\Quote\QuoteWasViewed;
use App\Events\RecurringInvoice\RecurringInvoiceWasArchived;
use App\Events\RecurringInvoice\RecurringInvoiceWasCreated;
use App\Events\RecurringInvoice\RecurringInvoiceWasDeleted;
use App\Events\RecurringInvoice\RecurringInvoiceWasRestored;
use App\Events\RecurringInvoice\RecurringInvoiceWasUpdated;
use App\Events\Subscription\SubscriptionWasArchived;
use App\Events\Subscription\SubscriptionWasCreated;
use App\Events\Subscription\SubscriptionWasDeleted;
@ -164,6 +169,11 @@ use App\Listeners\Quote\QuoteEmailedNotification;
use App\Listeners\Quote\QuoteRestoredActivity;
use App\Listeners\Quote\QuoteViewedActivity;
use App\Listeners\Quote\ReachWorkflowSettings;
use App\Listeners\RecurringInvoice\CreateRecurringInvoiceActivity;
use App\Listeners\RecurringInvoice\RecurringInvoiceArchivedActivity;
use App\Listeners\RecurringInvoice\RecurringInvoiceDeletedActivity;
use App\Listeners\RecurringInvoice\RecurringInvoiceRestoredActivity;
use App\Listeners\RecurringInvoice\UpdateRecurringInvoiceActivity;
use App\Listeners\SendVerificationNotification;
use App\Listeners\User\ArchivedUserActivity;
use App\Listeners\User\CreatedUserActivity;
@ -400,6 +410,21 @@ class EventServiceProvider extends ServiceProvider
QuoteWasRestored::class => [
QuoteRestoredActivity::class,
],
RecurringInvoiceWasUpdated::class => [
UpdateRecurringInvoiceActivity::class,
],
RecurringInvoiceWasCreated::class => [
CreateRecurringInvoiceActivity::class,
],
RecurringInvoiceWasDeleted::class => [
RecurringInvoiceDeletedActivity::class,
],
RecurringInvoiceWasArchived::class => [
RecurringInvoiceArchivedActivity::class,
],
RecurringInvoiceWasRestored::class => [
RecurringInvoiceRestoredActivity::class,
],
TaskWasCreated::class => [
CreatedTaskActivity::class,
],

View File

@ -80,7 +80,11 @@ class ActivityRepository extends BaseRepository
$backup = new Backup();
if (get_class($entity) == Invoice::class || get_class($entity) == Quote::class || get_class($entity) == Credit::class) {
if (get_class($entity) == Invoice::class
|| get_class($entity) == Quote::class
|| get_class($entity) == Credit::class
|| get_class($entity) == RecurringInvoice::class
) {
$contact = $entity->client->primary_contact()->first();
$backup->html_backup = $this->generateHtml($entity);
$backup->amount = $entity->amount;

View File

@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddRecurringInvoiceIdToActivitiesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('activities', function (Blueprint $table) {
$table->unsignedInteger('recurring_invoice_id')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
}

View File

@ -4240,6 +4240,11 @@ $LANG = array(
'migration_already_completed' => 'Company already migrated',
'migration_already_completed_desc' => 'Looks like you already migrated <b> :company_name </b>to the V5 version of the Invoice Ninja. In case you want to start over, you can force migrate to wipe existing data.',
'activity_100' => ':user created recurring invoice :recurring_invoice',
'activity_101' => ':user updated recurring invoice :recurring_invoice',
'activity_102' => ':user archived recurring invoice :recurring_invoice',
'activity_103' => ':user deleted recurring invoice :recurring_invoice',
'activity_104' => ':user restored recurring invoice :recurring_invoice',
);
return $LANG;

View File

@ -41,6 +41,11 @@ use App\Events\Quote\QuoteWasCreated;
use App\Events\Quote\QuoteWasDeleted;
use App\Events\Quote\QuoteWasRestored;
use App\Events\Quote\QuoteWasUpdated;
use App\Events\RecurringInvoice\RecurringInvoiceWasArchived;
use App\Events\RecurringInvoice\RecurringInvoiceWasCreated;
use App\Events\RecurringInvoice\RecurringInvoiceWasDeleted;
use App\Events\RecurringInvoice\RecurringInvoiceWasRestored;
use App\Events\RecurringInvoice\RecurringInvoiceWasUpdated;
use App\Events\Subscription\SubscriptionWasArchived;
use App\Events\Subscription\SubscriptionWasCreated;
use App\Events\Subscription\SubscriptionWasDeleted;
@ -68,6 +73,7 @@ use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Validation\ValidationException;
use Tests\MockAccountData;
use Tests\TestCase;
@ -538,6 +544,76 @@ class EventTest extends TestCase
}
public function testRecurringInvoiceEvents()
{
/* Test fire new invoice */
$data = [
'client_id' => $this->client->hashed_id,
'number' => 'dudex',
'frequency_id' => 1,
];
$this->expectsEvents([
RecurringInvoiceWasCreated::class,
RecurringInvoiceWasUpdated::class,
RecurringInvoiceWasArchived::class,
RecurringInvoiceWasRestored::class,
RecurringInvoiceWasDeleted::class,
]);
try {
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/recurring_invoices/', $data);
} catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1);
}
$response->assertStatus(200);
$arr = $response->json();
$data = [
'client_id' => $this->client->hashed_id,
'number' => 'dude2',
'frequency_id' => 1,
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->put('/api/v1/recurring_invoices/' . $arr['data']['id'], $data)
->assertStatus(200);
$data = [
'ids' => [$arr['data']['id']],
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/recurring_invoices/bulk?action=archive', $data)
->assertStatus(200);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/recurring_invoices/bulk?action=restore', $data)
->assertStatus(200);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/recurring_invoices/bulk?action=delete', $data)
->assertStatus(200);
}
public function testClientEvents()
{
$this->expectsEvents([