mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Merge pull request #5425 from turbo124/v5-develop
Subscriptions and custom exceptions
This commit is contained in:
commit
ed83f27537
1
.env.ci
1
.env.ci
@ -20,3 +20,4 @@ NINJA_ENVIRONMENT=hosted
|
||||
COMPOSER_AUTH='{"github-oauth": {"github.com": "${{ secrets.GITHUB_TOKEN }}"}}'
|
||||
TRAVIS=true
|
||||
API_SECRET=superdoopersecrethere
|
||||
PHANTOMJS_PDF_GENERATION=false
|
||||
|
@ -12,6 +12,8 @@
|
||||
### Fixed:
|
||||
- Fixes for counters where patterns without {$counter} could causes endless recursion.
|
||||
- Fixes for surcharge tax displayed amount on PDF.
|
||||
- Fixes for custom designs not rendering the custom template
|
||||
- Fixes for missing bulk actions on Subscriptions
|
||||
- Fixes CSS padding on the show page for recurring invoices (#5412)
|
||||
- Fixes for rendering invalid HTML & parsing invalid XML (#5395)
|
||||
|
||||
|
@ -236,6 +236,7 @@ class CreateSingleAccount extends Command
|
||||
$webhook_config = [
|
||||
'post_purchase_url' => 'http://ninja.test:8000/api/admin/plan',
|
||||
'post_purchase_rest_method' => 'POST',
|
||||
'post_purchase_headers' => [],
|
||||
];
|
||||
|
||||
$sub = SubscriptionFactory::create($company->id, $user->id);
|
||||
@ -243,6 +244,7 @@ class CreateSingleAccount extends Command
|
||||
$sub->group_id = $gs->id;
|
||||
$sub->recurring_product_ids = "{$p1->hashed_id}";
|
||||
$sub->webhook_configuration = $webhook_config;
|
||||
$sub->allow_plan_changes = true;
|
||||
$sub->save();
|
||||
|
||||
$sub = SubscriptionFactory::create($company->id, $user->id);
|
||||
@ -250,6 +252,7 @@ class CreateSingleAccount extends Command
|
||||
$sub->group_id = $gs->id;
|
||||
$sub->recurring_product_ids = "{$p2->hashed_id}";
|
||||
$sub->webhook_configuration = $webhook_config;
|
||||
$sub->allow_plan_changes = true;
|
||||
$sub->save();
|
||||
}
|
||||
|
||||
|
47
app/Events/Subscription/SubscriptionWasArchived.php
Normal file
47
app/Events/Subscription/SubscriptionWasArchived.php
Normal 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\Subscription;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\Subscription;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class SubscriptionWasArchived.
|
||||
*/
|
||||
class SubscriptionWasArchived
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* @var Subscription
|
||||
*/
|
||||
public $subscription;
|
||||
|
||||
public $company;
|
||||
|
||||
public $event_vars;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param Subscription $subscription
|
||||
* @param Company $company
|
||||
* @param array $event_vars
|
||||
*/
|
||||
public function __construct(Subscription $subscription, Company $company, array $event_vars)
|
||||
{
|
||||
$this->subscription = $subscription;
|
||||
$this->company = $company;
|
||||
$this->event_vars = $event_vars;
|
||||
}
|
||||
}
|
47
app/Events/Subscription/SubscriptionWasDeleted.php
Normal file
47
app/Events/Subscription/SubscriptionWasDeleted.php
Normal 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\Subscription;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\Subscription;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class SubscriptionWasDeleted.
|
||||
*/
|
||||
class SubscriptionWasDeleted
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* @var Subscription
|
||||
*/
|
||||
public $subscription;
|
||||
|
||||
public $company;
|
||||
|
||||
public $event_vars;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param Subscription $subscription
|
||||
* @param Company $company
|
||||
* @param array $event_vars
|
||||
*/
|
||||
public function __construct(Subscription $subscription, Company $company, array $event_vars)
|
||||
{
|
||||
$this->subscription = $subscription;
|
||||
$this->company = $company;
|
||||
$this->event_vars = $event_vars;
|
||||
}
|
||||
}
|
49
app/Events/Subscription/SubscriptionWasRestored.php
Normal file
49
app/Events/Subscription/SubscriptionWasRestored.php
Normal 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\Subscription;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\Subscription;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class SubscriptionWasRestored.
|
||||
*/
|
||||
class SubscriptionWasRestored
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* @var Subscription
|
||||
*/
|
||||
public $subscription;
|
||||
|
||||
public $company;
|
||||
|
||||
public $event_vars;
|
||||
|
||||
public $fromDeleted;
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param Subscription $subscription
|
||||
* @param Company $company
|
||||
* @param array $event_vars
|
||||
*/
|
||||
public function __construct(Subscription $subscription, $fromDeleted, Company $company, array $event_vars)
|
||||
{
|
||||
$this->subscription = $subscription;
|
||||
$this->fromDeleted = $fromDeleted;
|
||||
$this->company = $company;
|
||||
$this->event_vars = $event_vars;
|
||||
}
|
||||
}
|
47
app/Events/Subscription/SubscriptionWasUpdated.php
Normal file
47
app/Events/Subscription/SubscriptionWasUpdated.php
Normal 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\Subscription;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\Subscription;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class SubscriptionWasUpdated.
|
||||
*/
|
||||
class SubscriptionWasUpdated
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* @var Subscription
|
||||
*/
|
||||
public $subscription;
|
||||
|
||||
public $company;
|
||||
|
||||
public $event_vars;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param Subscription $subscription
|
||||
* @param Company $company
|
||||
* @param array $event_vars
|
||||
*/
|
||||
public function __construct(Subscription $subscription, Company $company, array $event_vars)
|
||||
{
|
||||
$this->subscription = $subscription;
|
||||
$this->company = $company;
|
||||
$this->event_vars = $event_vars;
|
||||
}
|
||||
}
|
10
app/Exceptions/FilePermissionsFailure.php
Normal file
10
app/Exceptions/FilePermissionsFailure.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class FilePermissionsFailure extends Exception
|
||||
{
|
||||
// ..
|
||||
}
|
@ -11,6 +11,9 @@
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use App\Exceptions\FilePermissionsFailure;
|
||||
use App\Exceptions\InternalPDFFailure;
|
||||
use App\Exceptions\PhantomPDFFailure;
|
||||
use Exception;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
@ -94,7 +97,7 @@ class Handler extends ExceptionHandler
|
||||
}
|
||||
}
|
||||
|
||||
if(config('ninja.expanded_logging'))
|
||||
// if(config('ninja.expanded_logging'))
|
||||
parent::report($exception);
|
||||
|
||||
}
|
||||
@ -134,6 +137,12 @@ class Handler extends ExceptionHandler
|
||||
{
|
||||
if ($exception instanceof ModelNotFoundException && $request->expectsJson()) {
|
||||
return response()->json(['message'=>$exception->getMessage()], 400);
|
||||
}elseif($exception instanceof InternalPDFFailure && $request->expectsJson()){
|
||||
return response()->json(['message' => $exception->getMessage()], 500);
|
||||
}elseif($exception instanceof PhantomPDFFailure && $request->expectsJson()){
|
||||
return response()->json(['message' => $exception->getMessage()], 500);
|
||||
}elseif($exception instanceof FilePermissionsFailure) {
|
||||
return response()->json(['message' => $exception->getMessage()], 500);
|
||||
} elseif ($exception instanceof ThrottleRequestsException && $request->expectsJson()) {
|
||||
return response()->json(['message'=>'Too many requests'], 429);
|
||||
} elseif ($exception instanceof FatalThrowableError && $request->expectsJson()) {
|
||||
@ -152,8 +161,7 @@ class Handler extends ExceptionHandler
|
||||
} elseif ($exception instanceof MethodNotAllowedHttpException && $request->expectsJson()) {
|
||||
return response()->json(['message'=>'Method not support for this route'], 404);
|
||||
} elseif ($exception instanceof ValidationException && $request->expectsJson()) {
|
||||
info(print_r($exception->validator->getMessageBag(), 1));
|
||||
|
||||
nlog($exception->validator->getMessageBag());
|
||||
return response()->json(['message' => 'The given data was invalid.', 'errors' => $exception->validator->getMessageBag()], 422);
|
||||
} elseif ($exception instanceof RelationNotFoundException && $request->expectsJson()) {
|
||||
return response()->json(['message' => $exception->getMessage()], 400);
|
||||
@ -161,8 +169,6 @@ class Handler extends ExceptionHandler
|
||||
return response()->json(['message' => $exception->getMessage()], 400);
|
||||
} elseif ($exception instanceof GenericPaymentDriverFailure) {
|
||||
$data['message'] = $exception->getMessage();
|
||||
//dd($data);
|
||||
// return view('errors.layout', $data);
|
||||
}
|
||||
|
||||
return parent::render($request, $exception);
|
||||
|
10
app/Exceptions/InternalPDFFailure.php
Normal file
10
app/Exceptions/InternalPDFFailure.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class InternalPDFFailure extends Exception
|
||||
{
|
||||
// ..
|
||||
}
|
10
app/Exceptions/PhantomPDFFailure.php
Normal file
10
app/Exceptions/PhantomPDFFailure.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class PhantomPDFFailure extends Exception
|
||||
{
|
||||
// ..
|
||||
}
|
@ -282,7 +282,7 @@ class ClientController extends BaseController
|
||||
|
||||
$this->uploadLogo($request->file('company_logo'), $client->company, $client);
|
||||
|
||||
event(new ClientWasUpdated($client, $client->company, Ninja::eventVars()));
|
||||
event(new ClientWasUpdated($client, $client->company, Ninja::eventVars(auth()->user()->id)));
|
||||
|
||||
return $this->itemResponse($client->fresh());
|
||||
}
|
||||
@ -380,7 +380,7 @@ class ClientController extends BaseController
|
||||
|
||||
$this->uploadLogo($request->file('company_logo'), $client->company, $client);
|
||||
|
||||
event(new ClientWasCreated($client, $client->company, Ninja::eventVars()));
|
||||
event(new ClientWasCreated($client, $client->company, Ninja::eventVars(auth()->user()->id)));
|
||||
|
||||
return $this->itemResponse($client);
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ class PaymentMethodController extends Controller
|
||||
->detach($payment_method);
|
||||
|
||||
try {
|
||||
event(new MethodDeleted($payment_method, auth('contact')->user()->company, Ninja::eventVars()));
|
||||
event(new MethodDeleted($payment_method, auth('contact')->user()->company, Ninja::eventVars(auth('contact')->user()->id)));
|
||||
$payment_method->delete();
|
||||
} catch (Exception $e) {
|
||||
|
||||
|
@ -30,12 +30,24 @@ class SubscriptionPlanSwitchController extends Controller
|
||||
*/
|
||||
public function index(ShowPlanSwitchRequest $request, RecurringInvoice $recurring_invoice, Subscription $target)
|
||||
{
|
||||
//calculate whether a payment is required or whether we pass through a credit for this.
|
||||
|
||||
$amount = $recurring_invoice->subscription->service()->calculateUpgradePrice($recurring_invoice, $target);
|
||||
$amount = $recurring_invoice->subscription
|
||||
->service()
|
||||
->calculateUpgradePrice($recurring_invoice, $target);
|
||||
|
||||
/**
|
||||
*
|
||||
* Null value here is a proxy for
|
||||
* denying the user a change plan option
|
||||
*
|
||||
*/
|
||||
if(is_null($amount))
|
||||
render('subscriptions.denied');
|
||||
|
||||
|
||||
return render('subscriptions.switch', [
|
||||
'subscription' => $subscription,
|
||||
'subscription' => $recurring_invoice->subscription,
|
||||
'recurring_invoice' => $recurring_invoice,
|
||||
'target' => $target,
|
||||
'amount' => $amount,
|
||||
]);
|
||||
|
@ -173,7 +173,7 @@ class ClientSubscriptionController extends BaseController
|
||||
{
|
||||
$client_subscription = $this->client_subscription_repo->save($request->all(), ClientSubscriptionFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
||||
|
||||
event(new ClientsubscriptionWasCreated($client_subscription, $client_subscription->company, Ninja::eventVars()));
|
||||
event(new ClientsubscriptionWasCreated($client_subscription, $client_subscription->company, Ninja::eventVars(auth()->user()->id)));
|
||||
|
||||
return $this->itemResponse($client_subscription);
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ class CreditController extends BaseController
|
||||
->fillDefaults()
|
||||
->save();
|
||||
|
||||
event(new CreditWasCreated($credit, $credit->company, Ninja::eventVars()));
|
||||
event(new CreditWasCreated($credit, $credit->company, Ninja::eventVars(auth()->user()->id)));
|
||||
|
||||
return $this->itemResponse($credit);
|
||||
}
|
||||
@ -378,7 +378,7 @@ class CreditController extends BaseController
|
||||
|
||||
$credit->service()->deletePdf();
|
||||
|
||||
event(new CreditWasUpdated($credit, $credit->company, Ninja::eventVars()));
|
||||
event(new CreditWasUpdated($credit, $credit->company, Ninja::eventVars(auth()->user()->id)));
|
||||
|
||||
return $this->itemResponse($credit);
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ class EmailController extends BaseController
|
||||
$this->entity_transformer = QuoteTransformer::class;
|
||||
|
||||
if ($entity_obj->invitations->count() >= 1)
|
||||
event(new QuoteWasEmailed($entity_obj->invitations->first(), $entity_obj->company, Ninja::eventVars(), 'quote'));
|
||||
event(new QuoteWasEmailed($entity_obj->invitations->first(), $entity_obj->company, Ninja::eventVars(auth()->user()->id), 'quote'));
|
||||
|
||||
}
|
||||
|
||||
@ -166,7 +166,7 @@ class EmailController extends BaseController
|
||||
$this->entity_transformer = CreditTransformer::class;
|
||||
|
||||
if ($entity_obj->invitations->count() >= 1)
|
||||
event(new CreditWasEmailed($entity_obj->invitations->first(), $entity_obj->company, Ninja::eventVars(), 'credit'));
|
||||
event(new CreditWasEmailed($entity_obj->invitations->first(), $entity_obj->company, Ninja::eventVars(auth()->user()->id), 'credit'));
|
||||
|
||||
}
|
||||
|
||||
|
@ -279,7 +279,7 @@ class ExpenseController extends BaseController
|
||||
|
||||
$this->uploadLogo($request->file('company_logo'), $expense->company, $expense);
|
||||
|
||||
event(new ExpenseWasUpdated($expense, $expense->company, Ninja::eventVars()));
|
||||
event(new ExpenseWasUpdated($expense, $expense->company, Ninja::eventVars(auth()->user()->id)));
|
||||
|
||||
return $this->itemResponse($expense->fresh());
|
||||
}
|
||||
@ -373,7 +373,7 @@ class ExpenseController extends BaseController
|
||||
{
|
||||
$expense = $this->expense_repo->save($request->all(), ExpenseFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
||||
|
||||
event(new ExpenseWasCreated($expense, $expense->company, Ninja::eventVars()));
|
||||
event(new ExpenseWasCreated($expense, $expense->company, Ninja::eventVars(auth()->user()->id)));
|
||||
|
||||
return $this->itemResponse($expense);
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ class InvoiceController extends BaseController
|
||||
->triggeredActions($request)
|
||||
->save();
|
||||
|
||||
event(new InvoiceWasCreated($invoice, $invoice->company, Ninja::eventVars()));
|
||||
event(new InvoiceWasCreated($invoice, $invoice->company, Ninja::eventVars(auth()->user()->id)));
|
||||
|
||||
return $this->itemResponse($invoice);
|
||||
}
|
||||
@ -399,7 +399,7 @@ class InvoiceController extends BaseController
|
||||
|
||||
$invoice->service()->deletePdf();
|
||||
|
||||
event(new InvoiceWasUpdated($invoice, $invoice->company, Ninja::eventVars()));
|
||||
event(new InvoiceWasUpdated($invoice, $invoice->company, Ninja::eventVars(auth()->user()->id)));
|
||||
|
||||
return $this->itemResponse($invoice);
|
||||
}
|
||||
|
@ -382,7 +382,7 @@ class PaymentController extends BaseController
|
||||
|
||||
$payment = $this->payment_repo->save($request->all(), $payment);
|
||||
|
||||
event(new PaymentWasUpdated($payment, $payment->company, Ninja::eventVars()));
|
||||
event(new PaymentWasUpdated($payment, $payment->company, Ninja::eventVars(auth()->user()->id)));
|
||||
return $this->itemResponse($payment);
|
||||
}
|
||||
|
||||
|
@ -211,7 +211,7 @@ class QuoteController extends BaseController
|
||||
|
||||
$quote = $quote->service()->fillDefaults()->save();
|
||||
|
||||
event(new QuoteWasCreated($quote, $quote->company, Ninja::eventVars()));
|
||||
event(new QuoteWasCreated($quote, $quote->company, Ninja::eventVars(auth()->user()->id)));
|
||||
|
||||
return $this->itemResponse($quote);
|
||||
}
|
||||
@ -389,7 +389,7 @@ class QuoteController extends BaseController
|
||||
|
||||
$quote->service()->deletePdf();
|
||||
|
||||
event(new QuoteWasUpdated($quote, $quote->company, Ninja::eventVars()));
|
||||
event(new QuoteWasUpdated($quote, $quote->company, Ninja::eventVars(auth()->user()->id)));
|
||||
|
||||
return $this->itemResponse($quote);
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Exceptions\FilePermissionsFailure;
|
||||
use App\Utils\Ninja;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
@ -61,6 +62,9 @@ class SelfUpdateController extends BaseController
|
||||
return response()->json(['message' => ctrans('texts.self_update_not_available')], 403);
|
||||
}
|
||||
|
||||
if(!$this->testWritable())
|
||||
throw new FilePermissionsFailure('Cannot update system because files are not writable!');
|
||||
|
||||
// Check if new version is available
|
||||
if($updater->source()->isNewVersionAvailable()) {
|
||||
|
||||
@ -90,6 +94,19 @@ class SelfUpdateController extends BaseController
|
||||
|
||||
}
|
||||
|
||||
private function testWritable()
|
||||
{
|
||||
$directoryIterator = new \RecursiveDirectoryIterator(base_path());
|
||||
|
||||
foreach (new \RecursiveIteratorIterator($directoryIterator) as $file) {
|
||||
if ($file->isFile() && ! $file->isWritable()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkVersion()
|
||||
{
|
||||
return trim(file_get_contents(config('ninja.version_url')));
|
||||
|
@ -85,7 +85,7 @@ class ClientController extends BaseController
|
||||
|
||||
$this->uploadLogo($request->file('company_logo'), $company, $client);
|
||||
|
||||
event(new ClientWasCreated($client, $company, Ninja::eventVars()));
|
||||
event(new ClientWasCreated($client, $company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||
|
||||
return $this->itemResponse($client);
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ class InvoiceController extends BaseController
|
||||
|
||||
$invoice = $invoice->service()->triggeredActions($request)->save();
|
||||
|
||||
event(new InvoiceWasCreated($invoice, $company, Ninja::eventVars()));
|
||||
event(new InvoiceWasCreated($invoice, $company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||
|
||||
return $this->itemResponse($invoice);
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Events\Subscription\SubscriptionWasCreated;
|
||||
use App\Events\Subscription\SubscriptionWasUpdated;
|
||||
use App\Factory\SubscriptionFactory;
|
||||
use App\Http\Requests\Subscription\CreateSubscriptionRequest;
|
||||
use App\Http\Requests\Subscription\DestroySubscriptionRequest;
|
||||
@ -176,7 +177,7 @@ class SubscriptionController extends BaseController
|
||||
{
|
||||
$subscription = $this->subscription_repo->save($request->all(), SubscriptionFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
||||
|
||||
event(new SubscriptionWasCreated($subscription, $subscription->company, Ninja::eventVars()));
|
||||
event(new SubscriptionWasCreated($subscription, $subscription->company, Ninja::eventVars(auth()->user()->id)));
|
||||
|
||||
return $this->itemResponse($subscription);
|
||||
}
|
||||
@ -351,6 +352,8 @@ class SubscriptionController extends BaseController
|
||||
|
||||
$subscription = $this->subscription_repo->save($request->all(), $subscription);
|
||||
|
||||
event(new SubscriptionWasUpdated($subscription, $subscription->company, Ninja::eventVars(auth()->user()->id)));
|
||||
|
||||
return $this->itemResponse($subscription);
|
||||
}
|
||||
|
||||
|
@ -282,7 +282,7 @@ class TaskController extends BaseController
|
||||
if($task->status_order != $old_task->status_order)
|
||||
$this->task_repo->sortStatuses($old_task, $task);
|
||||
|
||||
event(new TaskWasUpdated($task, $task->company, Ninja::eventVars()));
|
||||
event(new TaskWasUpdated($task, $task->company, Ninja::eventVars(auth()->user()->id)));
|
||||
|
||||
return $this->itemResponse($task->fresh());
|
||||
}
|
||||
@ -376,7 +376,7 @@ class TaskController extends BaseController
|
||||
{
|
||||
$task = $this->task_repo->save($request->all(), TaskFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
||||
|
||||
event(new TaskWasCreated($task, $task->company, Ninja::eventVars()));
|
||||
event(new TaskWasCreated($task, $task->company, Ninja::eventVars(auth()->user()->id)));
|
||||
|
||||
return $this->itemResponse($task);
|
||||
}
|
||||
|
@ -211,7 +211,7 @@ class UserController extends BaseController
|
||||
|
||||
nlog("in the store method of the usercontroller class");
|
||||
|
||||
event(new UserWasCreated($user, auth()->user(), $company, Ninja::eventVars()));
|
||||
event(new UserWasCreated($user, auth()->user(), $company, Ninja::eventVars(auth()->user()->id)));
|
||||
|
||||
return $this->itemResponse($user->fresh());
|
||||
}
|
||||
@ -401,7 +401,7 @@ class UserController extends BaseController
|
||||
$user->company_user()->update(["permissions_updated_at" => now()]);
|
||||
}
|
||||
|
||||
event(new UserWasUpdated($user, auth()->user(), auth()->user()->company, Ninja::eventVars()));
|
||||
event(new UserWasUpdated($user, auth()->user(), auth()->user()->company, Ninja::eventVars(auth()->user()->id)));
|
||||
|
||||
return $this->itemResponse($user);
|
||||
}
|
||||
@ -474,7 +474,7 @@ class UserController extends BaseController
|
||||
/* If the user passes the company user we archive the company user */
|
||||
$user = $this->user_repo->delete($request->all(), $user);
|
||||
|
||||
event(new UserWasDeleted($user, auth()->user(), auth()->user()->company, Ninja::eventVars()));
|
||||
event(new UserWasDeleted($user, auth()->user(), auth()->user()->company, Ninja::eventVars(auth()->user()->id)));
|
||||
|
||||
return $this->itemResponse($user->fresh());
|
||||
}
|
||||
|
@ -278,7 +278,7 @@ class VendorController extends BaseController
|
||||
|
||||
$this->uploadLogo($request->file('company_logo'), $vendor->company, $vendor);
|
||||
|
||||
event(new VendorWasUpdated($vendor, $vendor->company, Ninja::eventVars()));
|
||||
event(new VendorWasUpdated($vendor, $vendor->company, Ninja::eventVars(auth()->user()->id)));
|
||||
|
||||
return $this->itemResponse($vendor->fresh());
|
||||
}
|
||||
@ -376,7 +376,7 @@ class VendorController extends BaseController
|
||||
|
||||
$this->uploadLogo($request->file('company_logo'), $vendor->company, $vendor);
|
||||
|
||||
event(new VendorWasCreated($vendor, $vendor->company, Ninja::eventVars()));
|
||||
event(new VendorWasCreated($vendor, $vendor->company, Ninja::eventVars(auth()->user()->id)));
|
||||
|
||||
return $this->itemResponse($vendor);
|
||||
}
|
||||
|
@ -19,11 +19,21 @@ use Livewire\Component;
|
||||
|
||||
class SubscriptionPlanSwitch extends Component
|
||||
{
|
||||
/**
|
||||
* @var RecurringInvoice
|
||||
*/
|
||||
public $recurring_invoice;
|
||||
|
||||
/**
|
||||
* @var Subscription
|
||||
*/
|
||||
public $subscription;
|
||||
|
||||
/**
|
||||
* @var ?float
|
||||
*/
|
||||
public $amount;
|
||||
|
||||
/**
|
||||
* @var Subscription
|
||||
*/
|
||||
@ -62,7 +72,7 @@ class SubscriptionPlanSwitch extends Component
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->total = $this->subscription->service()->getPriceBetweenSubscriptions($this->subscription, $this->target);
|
||||
$this->total = $this->amount;
|
||||
|
||||
$this->methods = $this->contact->client->service()->getPaymentMethods(100);
|
||||
|
||||
@ -74,6 +84,7 @@ class SubscriptionPlanSwitch extends Component
|
||||
$this->state['show_loading_bar'] = true;
|
||||
|
||||
$this->state['invoice'] = $this->subscription->service()->createChangePlanInvoice([
|
||||
'recurring_invoice' => $this->recurring_invoice,
|
||||
'subscription' => $this->subscription,
|
||||
'target' => $this->target,
|
||||
]);
|
||||
|
@ -17,7 +17,7 @@ class ShowPlanSwitchRequest extends FormRequest
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return (bool)$this->subscription->allow_plan_changes;
|
||||
return (bool)$this->recurring_invoice->subscription->allow_plan_changes;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
namespace App\Jobs\Entity;
|
||||
|
||||
use App\Exceptions\FilePermissionsFailure;
|
||||
use App\Models\Account;
|
||||
use App\Models\Credit;
|
||||
use App\Models\CreditInvitation;
|
||||
@ -168,6 +169,7 @@ class CreateEntityPdf implements ShouldQueue
|
||||
else {
|
||||
$pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true));
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
nlog(print_r($e->getMessage(), 1));
|
||||
}
|
||||
@ -176,8 +178,20 @@ class CreateEntityPdf implements ShouldQueue
|
||||
info($maker->getCompiledHTML());
|
||||
}
|
||||
|
||||
|
||||
if ($pdf) {
|
||||
|
||||
try{
|
||||
|
||||
Storage::disk($this->disk)->put($file_path, $pdf);
|
||||
|
||||
}
|
||||
catch(\Exception $e)
|
||||
{
|
||||
|
||||
throw new FilePermissionsFailure('Could not write the PDF, permission issues!');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $file_path;
|
||||
|
@ -142,7 +142,7 @@ class EmailEntity implements ShouldQueue
|
||||
{
|
||||
switch ($this->entity_string) {
|
||||
case 'invoice':
|
||||
event(new InvoiceWasEmailedAndFailed($this->invitation, $this->company, $message, $this->reminder_template, Ninja::eventVars()));
|
||||
event(new InvoiceWasEmailedAndFailed($this->invitation, $this->company, $message, $this->reminder_template, Ninja::eventVars(auth()->user()->id)));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -105,10 +105,10 @@ class NinjaMailerJob implements ShouldQueue
|
||||
|
||||
switch ($class) {
|
||||
case Invoice::class:
|
||||
event(new InvoiceWasEmailedAndFailed($this->nmo->invitation, $this->nmo->company, $message, $this->nmo->reminder_template, Ninja::eventVars()));
|
||||
event(new InvoiceWasEmailedAndFailed($this->nmo->invitation, $this->nmo->company, $message, $this->nmo->reminder_template, Ninja::eventVars(auth()->user()->id)));
|
||||
break;
|
||||
case Payment::class:
|
||||
event(new PaymentWasEmailedAndFailed($this->nmo->entity, $this->nmo->company, $message, Ninja::eventVars()));
|
||||
event(new PaymentWasEmailedAndFailed($this->nmo->entity, $this->nmo->company, $message, Ninja::eventVars(auth()->user()->id)));
|
||||
break;
|
||||
default:
|
||||
# code...
|
||||
|
@ -91,7 +91,7 @@ class EmailPayment implements ShouldQueue
|
||||
|
||||
NinjaMailerJob::dispatch($nmo);
|
||||
|
||||
event(new PaymentWasEmailed($this->payment, $this->payment->company, Ninja::eventVars()));
|
||||
event(new PaymentWasEmailed($this->payment, $this->payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ class CreateUser
|
||||
|
||||
if(!Ninja::isSelfHost()){
|
||||
nlog("in the create user class");
|
||||
event(new UserWasCreated($user, $user, $this->company, Ninja::eventVars()));
|
||||
event(new UserWasCreated($user, $user, $this->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||
}
|
||||
|
||||
return $user;
|
||||
|
@ -192,6 +192,7 @@ class MultiDB
|
||||
return true;
|
||||
|
||||
}
|
||||
self::setDefaultDatabase();
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -205,6 +206,7 @@ class MultiDB
|
||||
return true;
|
||||
}
|
||||
}
|
||||
self::setDefaultDatabase();
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -218,6 +220,7 @@ class MultiDB
|
||||
return true;
|
||||
}
|
||||
}
|
||||
self::setDefaultDatabase();
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -230,6 +233,7 @@ class MultiDB
|
||||
return true;
|
||||
}
|
||||
}
|
||||
self::setDefaultDatabase();
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -242,16 +246,20 @@ class MultiDB
|
||||
return true;
|
||||
}
|
||||
}
|
||||
self::setDefaultDatabase();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function findAndSetDbByDomain($subdomain) :bool
|
||||
{
|
||||
|
||||
if (! config('ninja.db.multi_db_enabled'))
|
||||
return (Company::whereSubdomain($subdomain)->exists() === true);
|
||||
|
||||
foreach (self::$dbs as $db) {
|
||||
if ($company = Company::on($db)->whereSubdomain($subdomain)->first()) {
|
||||
self::setDb($company->db);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -43,8 +43,10 @@ class ArchivedClientActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->client->user_id;
|
||||
|
||||
$fields->client_id = $event->client->id;
|
||||
$fields->user_id = $event->client->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $event->client->company_id;
|
||||
$fields->activity_type_id = Activity::ARCHIVE_CLIENT;
|
||||
|
||||
|
@ -45,8 +45,10 @@ class ClientUpdatedActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->client->user_id;
|
||||
|
||||
$fields->client_id = $client->id;
|
||||
$fields->user_id = $client->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $client->company_id;
|
||||
$fields->activity_type_id = Activity::UPDATE_CLIENT;
|
||||
|
||||
|
@ -43,8 +43,10 @@ class CreatedClientActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->client->user_id;
|
||||
|
||||
$fields->client_id = $event->client->id;
|
||||
$fields->user_id = $event->client->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $event->client->company_id;
|
||||
$fields->activity_type_id = Activity::CREATE_CLIENT;
|
||||
|
||||
|
@ -43,8 +43,10 @@ class CreatedCreditActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->credit->user_id;
|
||||
|
||||
$fields->credit_id = $event->credit->id;
|
||||
$fields->user_id = $event->credit->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->client_id = $event->credit->client_id;
|
||||
|
||||
$fields->company_id = $event->credit->company_id;
|
||||
|
@ -43,8 +43,11 @@ class CreatedExpenseActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->expense->user_id;
|
||||
|
||||
$fields->expense_id = $event->expense->id;
|
||||
$fields->user_id = $event->expense->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $event->expense->company_id;
|
||||
$fields->activity_type_id = Activity::CREATE_EXPENSE;
|
||||
|
||||
|
@ -43,9 +43,11 @@ class CreatedQuoteActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->quote->user_id;
|
||||
|
||||
$fields->quote_id = $event->quote->id;
|
||||
$fields->client_id = $event->quote->client_id;
|
||||
$fields->user_id = $event->quote->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $event->quote->company_id;
|
||||
$fields->activity_type_id = Activity::CREATE_QUOTE;
|
||||
|
||||
|
55
app/Listeners/Activity/CreatedSubscriptionActivity.php
Normal file
55
app/Listeners/Activity/CreatedSubscriptionActivity.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?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\Activity;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Activity;
|
||||
use App\Repositories\ActivityRepository;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use stdClass;
|
||||
|
||||
class CreatedSubscriptionActivity 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;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->subscription->user_id;
|
||||
|
||||
$fields->subscription_id = $event->subscription->id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $event->subscription->company_id;
|
||||
$fields->activity_type_id = Activity::CREATE_SUBSCRIPTION;
|
||||
|
||||
$this->activity_repo->save($fields, $event->subscription, $event->event_vars);
|
||||
}
|
||||
}
|
@ -43,8 +43,10 @@ class CreatedTaskActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->task->user_id;
|
||||
|
||||
$fields->task_id = $event->task->id;
|
||||
$fields->user_id = $event->task->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $event->task->company_id;
|
||||
$fields->activity_type_id = Activity::CREATE_TASK;
|
||||
|
||||
|
@ -43,8 +43,10 @@ class CreatedVendorActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->vendor->user_id;
|
||||
|
||||
$fields->vendor_id = $event->vendor->id;
|
||||
$fields->user_id = $event->vendor->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $event->vendor->company_id;
|
||||
$fields->activity_type_id = Activity::CREATE_VENDOR;
|
||||
|
||||
|
@ -43,9 +43,11 @@ class CreditArchivedActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->credit->user_id;
|
||||
|
||||
$fields->payment_id = $event->credit->id;
|
||||
$fields->client_id = $event->credit->client_id;
|
||||
$fields->user_id = $event->credit->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $event->credit->company_id;
|
||||
$fields->activity_type_id = Activity::ARCHIVE_CREDIT;
|
||||
|
||||
|
@ -43,8 +43,10 @@ class DeleteClientActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->client->user_id;
|
||||
|
||||
$fields->client_id = $event->client->id;
|
||||
$fields->user_id = $event->client->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $event->client->company_id;
|
||||
$fields->activity_type_id = Activity::DELETE_CLIENT;
|
||||
|
||||
|
@ -43,9 +43,11 @@ class DeleteCreditActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->credit->user_id;
|
||||
|
||||
$fields->client_id = $event->credit->client_id;
|
||||
$fields->credit_id = $event->credit->id;
|
||||
$fields->user_id = $event->credit->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $event->credit->company_id;
|
||||
$fields->activity_type_id = Activity::DELETE_CREDIT;
|
||||
|
||||
|
@ -45,8 +45,10 @@ class ExpenseArchivedActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->expense->user_id;
|
||||
|
||||
$fields->expense_id = $expense->id;
|
||||
$fields->user_id = $expense->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $expense->company_id;
|
||||
$fields->activity_type_id = Activity::ARCHIVE_EXPENSE;
|
||||
|
||||
|
@ -43,8 +43,10 @@ class ExpenseDeletedActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->expense->user_id;
|
||||
|
||||
$fields->expense_id = $event->expense->id;
|
||||
$fields->user_id = $event->expense->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $event->expense->company_id;
|
||||
$fields->activity_type_id = Activity::DELETE_VENDOR;
|
||||
|
||||
|
@ -43,8 +43,10 @@ class ExpenseRestoredActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->expense->user_id;
|
||||
|
||||
$fields->expense_id = $event->expense->id;
|
||||
$fields->user_id = $event->expense->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $event->expense->company_id;
|
||||
$fields->activity_type_id = Activity::RESTORE_EXPENSE;
|
||||
|
||||
|
@ -43,10 +43,12 @@ class ExpenseUpdatedActivity implements ShouldQueue
|
||||
|
||||
$expense = $event->expense;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->expense->user_id;
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$fields->expense_id = $expense->id;
|
||||
$fields->user_id = $expense->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $expense->company_id;
|
||||
$fields->activity_type_id = Activity::UPDATE_EXPENSE;
|
||||
|
||||
|
@ -48,9 +48,11 @@ class PaymentArchivedActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->payment->user_id;
|
||||
|
||||
$fields->payment_id = $payment->id;
|
||||
$fields->client_id = $payment->client_id;
|
||||
$fields->user_id = $payment->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $payment->company_id;
|
||||
$fields->activity_type_id = Activity::ARCHIVE_PAYMENT;
|
||||
|
||||
|
@ -43,13 +43,15 @@ class PaymentCreatedActivity implements ShouldQueue
|
||||
|
||||
$payment = $event->payment;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->payment->user_id;
|
||||
|
||||
$invoices = $payment->invoices;
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$fields->payment_id = $payment->id;
|
||||
$fields->client_id = $payment->client_id;
|
||||
$fields->user_id = $payment->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $payment->company_id;
|
||||
$fields->activity_type_id = Activity::CREATE_PAYMENT;
|
||||
|
||||
|
@ -43,13 +43,15 @@ class PaymentDeletedActivity implements ShouldQueue
|
||||
|
||||
$payment = $event->payment;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->payment->user_id;
|
||||
|
||||
$invoices = $payment->invoices;
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$fields->payment_id = $payment->id;
|
||||
$fields->client_id = $payment->client_id;
|
||||
$fields->user_id = $payment->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $payment->company_id;
|
||||
$fields->activity_type_id = Activity::DELETE_PAYMENT;
|
||||
|
||||
|
@ -43,9 +43,11 @@ class PaymentRefundedActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->payment->user_id;
|
||||
|
||||
$fields->client_id = $event->payment->id;
|
||||
$fields->client_id = $event->payment->client_id;
|
||||
$fields->user_id = $event->payment->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $event->payment->company_id;
|
||||
$fields->activity_type_id = Activity::REFUNDED_PAYMENT;
|
||||
$fields->payment_id = $event->payment->id;
|
||||
|
@ -48,9 +48,11 @@ class PaymentUpdatedActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->payment->user_id;
|
||||
|
||||
$fields->payment_id = $payment->id;
|
||||
$fields->client_id = $payment->client_id;
|
||||
$fields->user_id = $payment->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $payment->company_id;
|
||||
$fields->activity_type_id = Activity::UPDATE_PAYMENT;
|
||||
|
||||
|
@ -43,8 +43,10 @@ class PaymentVoidedActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->payment->user_id;
|
||||
|
||||
$fields->client_id = $event->payment->id;
|
||||
$fields->user_id = $event->payment->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $event->payment->company_id;
|
||||
$fields->activity_type_id = Activity::VOIDED_PAYMENT;
|
||||
$fields->payment_id = $event->payment->id;
|
||||
|
@ -45,9 +45,11 @@ class QuoteUpdatedActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->quote->user_id;
|
||||
|
||||
$fields->quote_id = $quote->id;
|
||||
$fields->client_id = $quote->client_id;
|
||||
$fields->user_id = $quote->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $quote->company_id;
|
||||
$fields->activity_type_id = Activity::UPDATE_QUOTE;
|
||||
|
||||
|
@ -43,8 +43,10 @@ class RestoreClientActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->client->user_id;
|
||||
|
||||
$fields->client_id = $event->client->id;
|
||||
$fields->user_id = $event->client->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $event->client->company_id;
|
||||
$fields->activity_type_id = Activity::RESTORE_CLIENT;
|
||||
|
||||
|
57
app/Listeners/Activity/SubscriptionArchivedActivity.php
Normal file
57
app/Listeners/Activity/SubscriptionArchivedActivity.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?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\Activity;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Activity;
|
||||
use App\Repositories\ActivityRepository;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use stdClass;
|
||||
|
||||
class SubscriptionArchivedActivity 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);
|
||||
|
||||
$subscription = $event->subscription;
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->subscription->user_id;
|
||||
|
||||
$fields->subscription_id = $subscription->id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $subscription->company_id;
|
||||
$fields->activity_type_id = Activity::ARCHIVE_SUBSCRIPTIOn;
|
||||
|
||||
$this->activity_repo->save($fields, $subscription, $event->event_vars);
|
||||
}
|
||||
}
|
55
app/Listeners/Activity/SubscriptionDeletedActivity.php
Normal file
55
app/Listeners/Activity/SubscriptionDeletedActivity.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?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\Activity;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Activity;
|
||||
use App\Repositories\ActivityRepository;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use stdClass;
|
||||
|
||||
class SubscriptionDeletedActivity 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;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->subscription->user_id;
|
||||
|
||||
$fields->subscription_id = $event->subscription->id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $event->subscription->company_id;
|
||||
$fields->activity_type_id = Activity::DELETE_SUBSCRIPTION;
|
||||
|
||||
$this->activity_repo->save($fields, $event->subscription, $event->event_vars);
|
||||
}
|
||||
}
|
55
app/Listeners/Activity/SubscriptionRestoredActivity.php
Normal file
55
app/Listeners/Activity/SubscriptionRestoredActivity.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?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\Activity;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Activity;
|
||||
use App\Repositories\ActivityRepository;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use stdClass;
|
||||
|
||||
class SubscriptionRestoredActivity 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;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->subscription->user_id;
|
||||
|
||||
$fields->subscription_id = $event->subscription->id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $event->subscription->company_id;
|
||||
$fields->activity_type_id = Activity::RESTORE_SUBSCRIPTION;
|
||||
|
||||
$this->activity_repo->save($fields, $event->subscription, $event->event_vars);
|
||||
}
|
||||
}
|
57
app/Listeners/Activity/SubscriptionUpdatedActivity.php
Normal file
57
app/Listeners/Activity/SubscriptionUpdatedActivity.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?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\Activity;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Activity;
|
||||
use App\Repositories\ActivityRepository;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use stdClass;
|
||||
|
||||
class SubscriptionUpdatedActivity 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);
|
||||
|
||||
$subscription = $event->subscription;
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->subscription->user_id;
|
||||
|
||||
$fields->subscription_id = $subscription->id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $subscription->company_id;
|
||||
$fields->activity_type_id = Activity::UPDATE_SUBSCRIPTION;
|
||||
|
||||
$this->activity_repo->save($fields, $subscription, $event->event_vars);
|
||||
}
|
||||
}
|
@ -45,8 +45,10 @@ class TaskArchivedActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->task->user_id;
|
||||
|
||||
$fields->task_id = $task->id;
|
||||
$fields->user_id = $task->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $task->company_id;
|
||||
$fields->activity_type_id = Activity::ARCHIVE_TASK;
|
||||
|
||||
|
@ -43,8 +43,10 @@ class TaskDeletedActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->task->user_id;
|
||||
|
||||
$fields->task_id = $event->task->id;
|
||||
$fields->user_id = $event->task->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $event->task->company_id;
|
||||
$fields->activity_type_id = Activity::DELETE_TASK;
|
||||
|
||||
|
@ -43,8 +43,10 @@ class TaskRestoredActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->task->user_id;
|
||||
|
||||
$fields->task_id = $event->task->id;
|
||||
$fields->user_id = $event->task->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $event->task->company_id;
|
||||
$fields->activity_type_id = Activity::RESTORE_TASK;
|
||||
|
||||
|
@ -45,8 +45,10 @@ class TaskUpdatedActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->task->user_id;
|
||||
|
||||
$fields->task_id = $task->id;
|
||||
$fields->user_id = $task->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $task->company_id;
|
||||
$fields->activity_type_id = Activity::UPDATE_TASK;
|
||||
|
||||
|
@ -43,9 +43,11 @@ class UpdatedCreditActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->credit->user_id;
|
||||
|
||||
$fields->credit_id = $event->credit->id;
|
||||
$fields->client_id = $event->credit->client_id;
|
||||
$fields->user_id = $event->credit->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $event->credit->company_id;
|
||||
$fields->activity_type_id = Activity::UPDATE_CREDIT;
|
||||
|
||||
|
@ -45,8 +45,10 @@ class VendorArchivedActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->vendor->user_id;
|
||||
|
||||
$fields->vendor_id = $vendor->id;
|
||||
$fields->user_id = $vendor->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $vendor->company_id;
|
||||
$fields->activity_type_id = Activity::ARCHIVE_VENDOR;
|
||||
|
||||
|
@ -43,8 +43,10 @@ class VendorDeletedActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->vendor->user_id;
|
||||
|
||||
$fields->vendor_id = $event->vendor->id;
|
||||
$fields->user_id = $event->vendor->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $event->vendor->company_id;
|
||||
$fields->activity_type_id = Activity::DELETE_VENDOR;
|
||||
|
||||
|
@ -43,8 +43,10 @@ class VendorRestoredActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->vendor->user_id;
|
||||
|
||||
$fields->vendor_id = $event->vendor->id;
|
||||
$fields->user_id = $event->vendor->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $event->vendor->company_id;
|
||||
$fields->activity_type_id = Activity::RESTORE_VENDOR;
|
||||
|
||||
|
@ -45,8 +45,10 @@ class VendorUpdatedActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = $event->event_vars['user_id'] ?: $event->vendor->user_id;
|
||||
|
||||
$fields->vendor_id = $vendor->id;
|
||||
$fields->user_id = $vendor->user_id;
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $vendor->company_id;
|
||||
$fields->activity_type_id = Activity::UPDATE_VENDOR;
|
||||
|
||||
|
@ -84,6 +84,12 @@ class Activity extends StaticModel
|
||||
const INVOICE_REMINDER3_SENT = 65;
|
||||
const INVOICE_REMINDER_ENDLESS_SENT = 66;
|
||||
|
||||
const CREATE_SUBSCRIPTION = 80;
|
||||
const UPDATE_SUBSCRIPTION = 81;
|
||||
const ARCHIVE_SUBSCRIPTION = 82;
|
||||
const DELETE_SUBSCRIPTION = 83;
|
||||
const RESTORE_SUBSCRIPTION = 84;
|
||||
|
||||
protected $casts = [
|
||||
'is_system' => 'boolean',
|
||||
'updated_at' => 'timestamp',
|
||||
|
@ -255,10 +255,10 @@ class Credit extends BaseModel
|
||||
}
|
||||
|
||||
if (! $invitation) {
|
||||
event(new CreditWasUpdated($this, $this->company, Ninja::eventVars()));
|
||||
event(new CreditWasUpdated($this, $this->company, Ninja::eventVars(auth()->user()->id)));
|
||||
CreateEntityPdf::dispatchNow($this->invitations->first());
|
||||
} else {
|
||||
event(new CreditWasUpdated($this, $this->company, Ninja::eventVars()));
|
||||
event(new CreditWasUpdated($this, $this->company, Ninja::eventVars(auth()->user()->id)));
|
||||
CreateEntityPdf::dispatchNow($invitation);
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ class CreditInvitation extends BaseModel
|
||||
$storage_path = Storage::url($this->credit->client->quote_filepath().$this->credit->numberFormatter().'.pdf');
|
||||
|
||||
if (! Storage::exists($this->credit->client->credit_filepath().$this->credit->numberFormatter().'.pdf')) {
|
||||
event(new CreditWasUpdated($this, $this->company, Ninja::eventVars()));
|
||||
event(new CreditWasUpdated($this, $this->company, Ninja::eventVars(auth()->user()->id)));
|
||||
CreateEntityPdf::dispatchNow($this);
|
||||
}
|
||||
|
||||
|
@ -397,7 +397,7 @@ class Invoice extends BaseModel
|
||||
$storage_path = Storage::$type($this->client->invoice_filepath().$this->numberFormatter().'.pdf');
|
||||
|
||||
if (! Storage::exists($this->client->invoice_filepath().$this->numberFormatter().'.pdf')) {
|
||||
event(new InvoiceWasUpdated($this, $this->company, Ninja::eventVars()));
|
||||
event(new InvoiceWasUpdated($this, $this->company, Ninja::eventVars(auth()->user()->id)));
|
||||
CreateEntityPdf::dispatchNow($invitation);
|
||||
}
|
||||
|
||||
|
@ -143,7 +143,7 @@ class InvoiceInvitation extends BaseModel
|
||||
$storage_path = Storage::url($this->invoice->client->invoice_filepath().$this->invoice->numberFormatter().'.pdf');
|
||||
|
||||
if (! Storage::exists($this->invoice->client->invoice_filepath().$this->invoice->numberFormatter().'.pdf')) {
|
||||
event(new InvoiceWasUpdated($this->invoice, $this->company, Ninja::eventVars()));
|
||||
event(new InvoiceWasUpdated($this->invoice, $this->company, Ninja::eventVars(auth()->user()->id)));
|
||||
CreateEntityPdf::dispatchNow($this);
|
||||
}
|
||||
|
||||
|
@ -243,7 +243,7 @@ class Payment extends BaseModel
|
||||
$this->status_id = $this->refunded == $this->amount ? self::STATUS_REFUNDED : self::STATUS_PARTIALLY_REFUNDED;
|
||||
$this->save();
|
||||
|
||||
event(new PaymentWasRefunded($this, $refund_change, $this->company, Ninja::eventVars()));
|
||||
event(new PaymentWasRefunded($this, $refund_change, $this->company, Ninja::eventVars(auth()->user()->id)));
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -280,7 +280,7 @@ class Payment extends BaseModel
|
||||
$this->status_id = self::STATUS_CANCELLED;
|
||||
$this->save();
|
||||
|
||||
event(new PaymentWasVoided($this, $this->company, Ninja::eventVars()));
|
||||
event(new PaymentWasVoided($this, $this->company, Ninja::eventVars(auth()->user()->id)));
|
||||
}
|
||||
|
||||
public function getLink()
|
||||
|
@ -213,7 +213,7 @@ class Quote extends BaseModel
|
||||
nlog($storage_path);
|
||||
|
||||
if (! Storage::exists($this->client->quote_filepath().$this->numberFormatter().'.pdf')) {
|
||||
event(new QuoteWasUpdated($this, $this->company, Ninja::eventVars()));
|
||||
event(new QuoteWasUpdated($this, $this->company, Ninja::eventVars(auth()->user()->id)));
|
||||
CreateEntityPdf::dispatchNow($invitation);
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ class QuoteInvitation extends BaseModel
|
||||
$storage_path = Storage::url($this->quote->client->quote_filepath().$this->quote->numberFormatter().'.pdf');
|
||||
|
||||
if (! Storage::exists($this->quote->client->quote_filepath().$this->quote->numberFormatter().'.pdf')) {
|
||||
event(new QuoteWasUpdated($this->quote, $this->company, Ninja::eventVars()));
|
||||
event(new QuoteWasUpdated($this->quote, $this->company, Ninja::eventVars(auth()->user()->id)));
|
||||
CreateEntityPdf::dispatchNow($this);
|
||||
}
|
||||
|
||||
|
@ -184,7 +184,7 @@ class RecurringInvoice extends BaseModel
|
||||
|
||||
public function invoices()
|
||||
{
|
||||
return $this->hasMany(Invoice::class, 'id', 'recurring_id')->withTrashed();
|
||||
return $this->hasMany(Invoice::class, 'recurring_id', 'id')->withTrashed();
|
||||
}
|
||||
|
||||
public function invitations()
|
||||
|
@ -141,7 +141,7 @@ class CreditCard
|
||||
$this->checkout->payment_hash->data = array_merge((array)$this->checkout->payment_hash->data, ['checkout_payment_ref' => $payment]);
|
||||
$this->checkout->payment_hash->save();
|
||||
|
||||
if ($this->checkout->client->currency()->code === 'EUR') {
|
||||
if ($this->checkout->client->currency()->code == 'EUR') {
|
||||
$payment->{'3ds'} = ['enabled' => true];
|
||||
|
||||
$payment->{'success_url'} = route('payment_webhook', [
|
||||
|
@ -209,7 +209,8 @@ class CheckoutComPaymentDriver extends BaseDriver
|
||||
|
||||
$payment = new \Checkout\Models\Payments\Payment($method, $this->client->getCurrencyCode());
|
||||
$payment->amount = $this->convertToCheckoutAmount($amount, $this->client->getCurrencyCode());
|
||||
$payment->reference = $cgt->meta->last4 . '-' . now();
|
||||
//$payment->reference = $cgt->meta->last4 . '-' . now();
|
||||
$payment->reference = $invoice->number . '-' . now();
|
||||
|
||||
$request = new PaymentResponseRequest();
|
||||
$request->setMethod('POST');
|
||||
|
@ -11,6 +11,12 @@
|
||||
|
||||
namespace App\PaymentDrivers;
|
||||
|
||||
use App\Models\ClientGatewayToken;
|
||||
use App\Models\GatewayType;
|
||||
use App\Models\Payment;
|
||||
use App\Models\PaymentHash;
|
||||
use App\Models\SystemLog;
|
||||
use App\PaymentDrivers\Stripe\CreditCard;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
|
||||
class DriverTemplate extends BaseDriver
|
||||
|
@ -67,6 +67,11 @@ use App\Events\Quote\QuoteWasEmailed;
|
||||
use App\Events\Quote\QuoteWasRestored;
|
||||
use App\Events\Quote\QuoteWasUpdated;
|
||||
use App\Events\Quote\QuoteWasViewed;
|
||||
use App\Events\Subscription\SubscriptionWasArchived;
|
||||
use App\Events\Subscription\SubscriptionWasCreated;
|
||||
use App\Events\Subscription\SubscriptionWasDeleted;
|
||||
use App\Events\Subscription\SubscriptionWasRestored;
|
||||
use App\Events\Subscription\SubscriptionWasUpdated;
|
||||
use App\Events\Task\TaskWasArchived;
|
||||
use App\Events\Task\TaskWasCreated;
|
||||
use App\Events\Task\TaskWasDeleted;
|
||||
@ -89,6 +94,7 @@ use App\Listeners\Activity\CreatedClientActivity;
|
||||
use App\Listeners\Activity\CreatedCreditActivity;
|
||||
use App\Listeners\Activity\CreatedExpenseActivity;
|
||||
use App\Listeners\Activity\CreatedQuoteActivity;
|
||||
use App\Listeners\Activity\CreatedSubscriptionActivity;
|
||||
use App\Listeners\Activity\CreatedTaskActivity;
|
||||
use App\Listeners\Activity\CreatedVendorActivity;
|
||||
use App\Listeners\Activity\CreditArchivedActivity;
|
||||
@ -106,6 +112,10 @@ use App\Listeners\Activity\PaymentUpdatedActivity;
|
||||
use App\Listeners\Activity\PaymentVoidedActivity;
|
||||
use App\Listeners\Activity\QuoteUpdatedActivity;
|
||||
use App\Listeners\Activity\RestoreClientActivity;
|
||||
use App\Listeners\Activity\SubscriptionArchivedActivity;
|
||||
use App\Listeners\Activity\SubscriptionDeletedActivity;
|
||||
use App\Listeners\Activity\SubscriptionRestoredActivity;
|
||||
use App\Listeners\Activity\SubscriptionUpdatedActivity;
|
||||
use App\Listeners\Activity\TaskArchivedActivity;
|
||||
use App\Listeners\Activity\TaskDeletedActivity;
|
||||
use App\Listeners\Activity\TaskRestoredActivity;
|
||||
@ -396,6 +406,21 @@ class EventServiceProvider extends ServiceProvider
|
||||
TaskWasRestored::class => [
|
||||
TaskRestoredActivity::class,
|
||||
],
|
||||
SubscriptionWasCreated::class => [
|
||||
CreatedSubscriptionActivity::class,
|
||||
],
|
||||
SubscriptionWasUpdated::class => [
|
||||
SubscriptionUpdatedActivity::class,
|
||||
],
|
||||
SubscriptionWasArchived::class => [
|
||||
SubscriptionArchivedActivity::class,
|
||||
],
|
||||
SubscriptionWasDeleted::class => [
|
||||
SubscriptionDeletedActivity::class,
|
||||
],
|
||||
SubscriptionWasRestored::class => [
|
||||
SubscriptionRestoredActivity::class,
|
||||
],
|
||||
VendorWasCreated::class => [
|
||||
CreatedVendorActivity::class,
|
||||
],
|
||||
|
@ -55,7 +55,7 @@ class BaseRepository
|
||||
$className = $this->getEventClass($entity, 'Archived');
|
||||
|
||||
if (class_exists($className)) {
|
||||
event(new $className($entity, $entity->company, Ninja::eventVars()));
|
||||
event(new $className($entity, $entity->company, Ninja::eventVars(auth()->user()->id)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ class BaseRepository
|
||||
$className = $this->getEventClass($entity, 'Restored');
|
||||
|
||||
if (class_exists($className)) {
|
||||
event(new $className($entity, $fromDeleted, $entity->company, Ninja::eventVars()));
|
||||
event(new $className($entity, $fromDeleted, $entity->company, Ninja::eventVars(auth()->user()->id)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,7 +102,7 @@ class BaseRepository
|
||||
$className = $this->getEventClass($entity, 'Deleted');
|
||||
|
||||
if (class_exists($className) && ! ($entity instanceof Company)) {
|
||||
event(new $className($entity, $entity->company, Ninja::eventVars()));
|
||||
event(new $className($entity, $entity->company, Ninja::eventVars(auth()->user()->id)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,7 +155,7 @@ class PaymentRepository extends BaseRepository {
|
||||
}
|
||||
|
||||
if ( ! $is_existing_payment && ! $this->import_mode ) {
|
||||
event( new PaymentWasCreated( $payment, $payment->company, Ninja::eventVars() ) );
|
||||
event( new PaymentWasCreated( $payment, $payment->company, Ninja::eventVars(auth()->user()->id) ) );
|
||||
}
|
||||
|
||||
nlog("payment amount = {$payment->amount}");
|
||||
@ -205,7 +205,7 @@ class PaymentRepository extends BaseRepository {
|
||||
|
||||
$payment = $payment->service()->deletePayment();
|
||||
|
||||
event(new PaymentWasDeleted($payment, $payment->company, Ninja::eventVars()));
|
||||
event(new PaymentWasDeleted($payment, $payment->company, Ninja::eventVars(auth()->user()->id)));
|
||||
|
||||
return $payment;
|
||||
//return parent::delete($payment);
|
||||
|
@ -123,7 +123,7 @@ class UserRepository extends BaseRepository
|
||||
$cu->forceDelete();
|
||||
}
|
||||
|
||||
event(new UserWasDeleted($user, $company, Ninja::eventVars()));
|
||||
event(new UserWasDeleted($user, $company, Ninja::eventVars(auth()->user()->id)));
|
||||
|
||||
$user->delete();
|
||||
|
||||
@ -146,7 +146,7 @@ class UserRepository extends BaseRepository
|
||||
$cu->delete();
|
||||
}
|
||||
|
||||
event(new UserWasDeleted($user, auth()->user(), $company, Ninja::eventVars()));
|
||||
event(new UserWasDeleted($user, auth()->user(), $company, Ninja::eventVars(auth()->user()->id)));
|
||||
|
||||
$user->is_deleted = true;
|
||||
$user->save();
|
||||
@ -164,7 +164,7 @@ class UserRepository extends BaseRepository
|
||||
|
||||
$user->delete();
|
||||
|
||||
event(new UserWasArchived($user, auth()->user(), auth()->user()->company, Ninja::eventVars()));
|
||||
event(new UserWasArchived($user, auth()->user(), auth()->user()->company, Ninja::eventVars(auth()->user()->id)));
|
||||
|
||||
}
|
||||
|
||||
@ -189,7 +189,7 @@ class UserRepository extends BaseRepository
|
||||
|
||||
$cu->restore();
|
||||
|
||||
event(new UserWasRestored($user, auth()->user(), auth()->user()->company, Ninja::eventVars()));
|
||||
event(new UserWasRestored($user, auth()->user(), auth()->user()->company, Ninja::eventVars(auth()->user()->id)));
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -144,11 +144,11 @@ class ApplyPayment
|
||||
->ledger()
|
||||
->updateCreditBalance(($this->amount_applied * -1), "Credit payment applied to Invoice {$this->invoice->number}");
|
||||
|
||||
event(new InvoiceWasUpdated($this->invoice, $this->invoice->company, Ninja::eventVars()));
|
||||
event(new InvoiceWasUpdated($this->invoice, $this->invoice->company, Ninja::eventVars(auth()->user()->id)));
|
||||
|
||||
if ((int)$this->invoice->balance == 0) {
|
||||
$this->invoice->service()->deletePdf();
|
||||
event(new InvoiceWasPaid($this->invoice, $payment, $this->payment->company, Ninja::eventVars()));
|
||||
event(new InvoiceWasPaid($this->invoice, $payment, $this->payment->company, Ninja::eventVars(auth()->user()->id)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ class MarkSent
|
||||
|
||||
$this->credit->markInvitationsSent();
|
||||
|
||||
event(new CreditWasMarkedSent($this->credit, $this->credit->company, Ninja::eventVars()));
|
||||
event(new CreditWasMarkedSent($this->credit, $this->credit->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||
|
||||
$this->credit
|
||||
->service()
|
||||
|
@ -50,7 +50,7 @@ class HandleCancellation extends AbstractService
|
||||
//adjust client balance
|
||||
$this->invoice->client->service()->updateBalance($adjustment)->save();
|
||||
|
||||
event(new InvoiceWasCancelled($this->invoice, $this->invoice->company, Ninja::eventVars()));
|
||||
event(new InvoiceWasCancelled($this->invoice, $this->invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||
|
||||
return $this->invoice;
|
||||
}
|
||||
|
@ -81,8 +81,8 @@ class MarkPaid extends AbstractService
|
||||
$payment->service()->sendEmail();
|
||||
|
||||
/* Update Invoice balance */
|
||||
event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars()));
|
||||
event(new InvoiceWasPaid($this->invoice, $payment, $payment->company, Ninja::eventVars()));
|
||||
event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||
event(new InvoiceWasPaid($this->invoice, $payment, $payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||
|
||||
$payment->ledger()
|
||||
->updatePaymentBalance($payment->amount * -1);
|
||||
|
@ -54,7 +54,7 @@ class MarkSent extends AbstractService
|
||||
|
||||
$this->invoice->ledger()->updateInvoiceBalance($this->invoice->balance, "Invoice {$this->invoice->number} marked as sent.");
|
||||
|
||||
event(new InvoiceWasUpdated($this->invoice, $this->invoice->company, Ninja::eventVars()));
|
||||
event(new InvoiceWasUpdated($this->invoice, $this->invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||
|
||||
return $this->invoice->fresh();
|
||||
}
|
||||
|
@ -112,10 +112,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, Ninja::eventVars());
|
||||
$activity_repo->save($fields, $this->payment, Ninja::eventVars(auth()->user()->id));
|
||||
}
|
||||
} else {
|
||||
$activity_repo->save($fields, $this->payment, Ninja::eventVars());
|
||||
$activity_repo->save($fields, $this->payment, Ninja::eventVars(auth()->user()->id));
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
@ -45,7 +45,7 @@ class MarkSent
|
||||
$this->quote->due_date = Carbon::parse($this->quote->date)->addDays($this->quote->client->getSetting('valid_until'));
|
||||
}
|
||||
|
||||
event(new QuoteWasMarkedSent($this->quote, $this->quote->company, Ninja::eventVars()));
|
||||
event(new QuoteWasMarkedSent($this->quote, $this->quote->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||
|
||||
$this->quote
|
||||
->service()
|
||||
|
@ -183,20 +183,21 @@ class SubscriptionService
|
||||
return redirect('/client/recurring_invoices/'.$recurring_invoice->hashed_id);
|
||||
}
|
||||
|
||||
public function calculateUpgradePrice(RecurringInvoice $recurring_invoice, Subscription $target)
|
||||
public function calculateUpgradePrice(RecurringInvoice $recurring_invoice, Subscription $target) :?float
|
||||
{
|
||||
//calculate based on daily prices
|
||||
|
||||
$current_amount = $recurring_invoice->amount;
|
||||
$currency_frequency = $recurring_invoice->frequency_id;
|
||||
|
||||
$outstanding = $recurring_invoice->invoices
|
||||
$outstanding = $recurring_invoice->invoices()
|
||||
->where('is_deleted', 0)
|
||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||
->where('balance', '>', 0);
|
||||
|
||||
$outstanding_amounts = $outstanding->sum('balance');
|
||||
$outstanding_invoices = $outstanding->get();
|
||||
// $outstanding_invoices = $outstanding->get();
|
||||
$outstanding_invoices = $outstanding;
|
||||
|
||||
if ($outstanding->count() == 0){
|
||||
//nothing outstanding
|
||||
@ -206,14 +207,17 @@ class SubscriptionService
|
||||
//user has multiple amounts outstanding
|
||||
return $target->price - $this->calculateProRataRefund($outstanding->first());
|
||||
}
|
||||
elseif ($outstanding->count > 1) {
|
||||
elseif ($outstanding->count() > 1) {
|
||||
//user is changing plan mid frequency cycle
|
||||
//we cannot handle this if there are more than one invoice outstanding.
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
private function calculateProRataRefund($invoice)
|
||||
private function calculateProRataRefund($invoice) :float
|
||||
{
|
||||
//determine the start date
|
||||
|
||||
@ -234,11 +238,25 @@ class SubscriptionService
|
||||
//Data array structure
|
||||
/**
|
||||
* [
|
||||
* 'recurring_invoice' => RecurringInvoice::class,
|
||||
* 'subscription' => Subscription::class,
|
||||
* 'target' => Subscription::class
|
||||
* ]
|
||||
*/
|
||||
|
||||
$outstanding_invoice = $recurring_invoice->invoices()
|
||||
->where('is_deleted', 0)
|
||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||
->where('balance', '>', 0)
|
||||
->first();
|
||||
|
||||
|
||||
// we calculate the pro rata refund for this invoice.
|
||||
if($outstanding_invoice)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//logic
|
||||
|
||||
// Is the user paid up to date? ie are there any outstanding invoices for this subscription
|
||||
|
@ -111,12 +111,13 @@ class Ninja
|
||||
curl_close($ch);
|
||||
}
|
||||
|
||||
public static function eventVars()
|
||||
public static function eventVars($user_id = null)
|
||||
{
|
||||
return [
|
||||
'ip' => request()->getClientIp(),
|
||||
'token' => request()->header('X-API-TOKEN'),
|
||||
'is_system' => app()->runningInConsole(),
|
||||
'user_id' => $user_id,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Utils\PhantomJS;
|
||||
|
||||
use App\Exceptions\PhantomPDFFailure;
|
||||
use App\Jobs\Util\SystemLogger;
|
||||
use App\Models\CreditInvitation;
|
||||
use App\Models\Design;
|
||||
@ -91,8 +92,6 @@ class Phantom
|
||||
|
||||
$instance = Storage::disk(config('filesystems.default'))->put($file_path, $pdf);
|
||||
|
||||
// nlog($instance);
|
||||
// nlog($file_path);
|
||||
return $file_path;
|
||||
}
|
||||
|
||||
@ -128,6 +127,8 @@ class Phantom
|
||||
SystemLog::TYPE_PDF_FAILURE,
|
||||
$invitation->contact->client
|
||||
);
|
||||
|
||||
throw new PhantomPDFFailure('There was an error generating the PDF with Phantom JS');
|
||||
}
|
||||
else {
|
||||
|
||||
|
@ -211,10 +211,10 @@ trait Refundable
|
||||
foreach ($data['invoices'] as $invoice) {
|
||||
$fields->invoice_id = $invoice->id;
|
||||
|
||||
$activity_repo->save($fields, $this, Ninja::eventVars());
|
||||
$activity_repo->save($fields, $this, Ninja::eventVars(auth()->user()->id));
|
||||
}
|
||||
} else {
|
||||
$activity_repo->save($fields, $this, Ninja::eventVars());
|
||||
$activity_repo->save($fields, $this, Ninja::eventVars(auth()->user()->id));
|
||||
}
|
||||
}
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user