1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-17 16:42:48 +01:00

Merge pull request #5429 from turbo124/v5-stable

v5.1.44
This commit is contained in:
David Bomba 2021-04-14 07:48:37 +10:00 committed by GitHub
commit 0793d08781
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
144 changed files with 380492 additions and 373321 deletions

View File

@ -19,4 +19,5 @@ DB_HOST=127.0.0.1
NINJA_ENVIRONMENT=hosted NINJA_ENVIRONMENT=hosted
COMPOSER_AUTH='{"github-oauth": {"github.com": "${{ secrets.GITHUB_TOKEN }}"}}' COMPOSER_AUTH='{"github-oauth": {"github.com": "${{ secrets.GITHUB_TOKEN }}"}}'
TRAVIS=true TRAVIS=true
API_SECRET=superdoopersecrethere API_SECRET=superdoopersecrethere
PHANTOMJS_PDF_GENERATION=false

View File

@ -3,7 +3,24 @@
## [Unreleased (daily channel)](https://github.com/invoiceninja/invoiceninja/tree/v5-develop) ## [Unreleased (daily channel)](https://github.com/invoiceninja/invoiceninja/tree/v5-develop)
### Added: ### Added:
- Subscriptions are now going to show the frequency in the table (#5412)
- Subscriptions: During upgrade webhook request message will be shown for easier debugging (#5411)
- PDF: Custom fields now will be shared across invoices, quotes & credits (#5410)
- Client portal: Invoices are now sorted in the descending order (#5408)
- Payments: ACH notification after the initial bank account connecting process (#5405)
### Fixed: ### 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)
### Removed: ### Removed:
- Removed one-time payments table (#5412)
## v5.1.43
### Fixed:
- Whitelabel regression.

View File

@ -1 +1 @@
5.1.43 5.1.44

View File

@ -14,8 +14,10 @@ namespace App\Console\Commands;
use App\DataMapper\CompanySettings; use App\DataMapper\CompanySettings;
use App\DataMapper\FeesAndLimits; use App\DataMapper\FeesAndLimits;
use App\Events\Invoice\InvoiceWasCreated; use App\Events\Invoice\InvoiceWasCreated;
use App\Factory\GroupSettingFactory;
use App\Factory\InvoiceFactory; use App\Factory\InvoiceFactory;
use App\Factory\InvoiceItemFactory; use App\Factory\InvoiceItemFactory;
use App\Factory\SubscriptionFactory;
use App\Helpers\Invoice\InvoiceSum; use App\Helpers\Invoice\InvoiceSum;
use App\Jobs\Company\CreateCompanyTaskStatuses; use App\Jobs\Company\CreateCompanyTaskStatuses;
use App\Models\Account; use App\Models\Account;
@ -201,6 +203,57 @@ class CreateSingleAccount extends Command
} }
$this->createGateways($company, $user); $this->createGateways($company, $user);
$this->createSubsData($company, $user);
}
private function createSubsData($company, $user)
{
$gs = GroupSettingFactory::create($company->id, $user->id);
$gs->name = "plans";
$gs->save();
$p1 = Product::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
'product_key' => 'pro_plan',
'notes' => 'The Pro Plan',
'cost' => 10,
'price' => 10,
'quantity' => 1,
]);
$p2 = Product::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
'product_key' => 'enterprise_plan',
'notes' => 'The Pro Plan',
'cost' => 10,
'price' => 10,
'quantity' => 1,
]);
$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);
$sub->name = "Pro Plan";
$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);
$sub->name = "Enterprise Plan";
$sub->group_id = $gs->id;
$sub->recurring_product_ids = "{$p2->hashed_id}";
$sub->webhook_configuration = $webhook_config;
$sub->allow_plan_changes = true;
$sub->save();
} }
private function createClient($company, $user) private function createClient($company, $user)

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

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

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

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

View File

@ -0,0 +1,10 @@
<?php
namespace App\Exceptions;
use Exception;
class FilePermissionsFailure extends Exception
{
// ..
}

View File

@ -11,6 +11,9 @@
namespace App\Exceptions; namespace App\Exceptions;
use App\Exceptions\FilePermissionsFailure;
use App\Exceptions\InternalPDFFailure;
use App\Exceptions\PhantomPDFFailure;
use Exception; use Exception;
use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Auth\AuthenticationException; 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); parent::report($exception);
} }
@ -134,6 +137,12 @@ class Handler extends ExceptionHandler
{ {
if ($exception instanceof ModelNotFoundException && $request->expectsJson()) { if ($exception instanceof ModelNotFoundException && $request->expectsJson()) {
return response()->json(['message'=>$exception->getMessage()], 400); 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()) { } elseif ($exception instanceof ThrottleRequestsException && $request->expectsJson()) {
return response()->json(['message'=>'Too many requests'], 429); return response()->json(['message'=>'Too many requests'], 429);
} elseif ($exception instanceof FatalThrowableError && $request->expectsJson()) { } elseif ($exception instanceof FatalThrowableError && $request->expectsJson()) {
@ -152,8 +161,7 @@ class Handler extends ExceptionHandler
} elseif ($exception instanceof MethodNotAllowedHttpException && $request->expectsJson()) { } elseif ($exception instanceof MethodNotAllowedHttpException && $request->expectsJson()) {
return response()->json(['message'=>'Method not support for this route'], 404); return response()->json(['message'=>'Method not support for this route'], 404);
} elseif ($exception instanceof ValidationException && $request->expectsJson()) { } 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); return response()->json(['message' => 'The given data was invalid.', 'errors' => $exception->validator->getMessageBag()], 422);
} elseif ($exception instanceof RelationNotFoundException && $request->expectsJson()) { } elseif ($exception instanceof RelationNotFoundException && $request->expectsJson()) {
return response()->json(['message' => $exception->getMessage()], 400); return response()->json(['message' => $exception->getMessage()], 400);
@ -161,9 +169,7 @@ class Handler extends ExceptionHandler
return response()->json(['message' => $exception->getMessage()], 400); return response()->json(['message' => $exception->getMessage()], 400);
} elseif ($exception instanceof GenericPaymentDriverFailure) { } elseif ($exception instanceof GenericPaymentDriverFailure) {
$data['message'] = $exception->getMessage(); $data['message'] = $exception->getMessage();
//dd($data); }
// return view('errors.layout', $data);
}
return parent::render($request, $exception); return parent::render($request, $exception);
} }

View File

@ -0,0 +1,10 @@
<?php
namespace App\Exceptions;
use Exception;
class InternalPDFFailure extends Exception
{
// ..
}

View File

@ -0,0 +1,10 @@
<?php
namespace App\Exceptions;
use Exception;
class PhantomPDFFailure extends Exception
{
// ..
}

View File

@ -11,17 +11,21 @@
namespace App\Factory; namespace App\Factory;
use App\Models\Client;
use App\Models\GroupSetting; use App\Models\GroupSetting;
class GroupSettingFactory class GroupSettingFactory
{ {
public static function create(int $company_id, int $user_id) :GroupSetting public static function create(int $company_id, int $user_id) :GroupSetting
{ {
$settings = new \stdClass;
$settings->entity = Client::class;
$gs = new GroupSetting; $gs = new GroupSetting;
$gs->name = ''; $gs->name = '';
$gs->company_id = $company_id; $gs->company_id = $company_id;
$gs->user_id = $user_id; $gs->user_id = $user_id;
$gs->settings = '{}'; $gs->settings = $settings;
return $gs; return $gs;
} }

View File

@ -12,6 +12,7 @@
namespace App\Helpers\Invoice; namespace App\Helpers\Invoice;
use App\Models\Invoice; use App\Models\Invoice;
use App\Models\TaxRate;
use App\Utils\Traits\NumberFormatter; use App\Utils\Traits\NumberFormatter;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
@ -90,16 +91,16 @@ class InvoiceSum
private function calculateCustomValues() private function calculateCustomValues()
{ {
$this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge1, $this->invoice->custom_surcharge_tax1); // $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge1, $this->invoice->custom_surcharge_tax1);
$this->total_custom_values += $this->valuer($this->invoice->custom_surcharge1); $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge1);
$this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge2, $this->invoice->custom_surcharge_tax2); // $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge2, $this->invoice->custom_surcharge_tax2);
$this->total_custom_values += $this->valuer($this->invoice->custom_surcharge2); $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge2);
$this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge3, $this->invoice->custom_surcharge_tax3); // $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge3, $this->invoice->custom_surcharge_tax3);
$this->total_custom_values += $this->valuer($this->invoice->custom_surcharge3); $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge3);
$this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge4, $this->invoice->custom_surcharge_tax4); // $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge4, $this->invoice->custom_surcharge_tax4);
$this->total_custom_values += $this->valuer($this->invoice->custom_surcharge4); $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge4);
$this->total += $this->total_custom_values; $this->total += $this->total_custom_values;
@ -112,18 +113,24 @@ class InvoiceSum
if (strlen($this->invoice->tax_name1) > 1) { if (strlen($this->invoice->tax_name1) > 1) {
$tax = $this->taxer($this->total, $this->invoice->tax_rate1); $tax = $this->taxer($this->total, $this->invoice->tax_rate1);
$tax += $this->getSurchargeTaxTotalForKey($this->invoice->tax_name1, $this->invoice->tax_rate1);
$this->total_taxes += $tax; $this->total_taxes += $tax;
$this->total_tax_map[] = ['name' => $this->invoice->tax_name1.' '.floatval($this->invoice->tax_rate1).'%', 'total' => $tax]; $this->total_tax_map[] = ['name' => $this->invoice->tax_name1.' '.floatval($this->invoice->tax_rate1).'%', 'total' => $tax];
} }
if (strlen($this->invoice->tax_name2) > 1) { if (strlen($this->invoice->tax_name2) > 1) {
$tax = $this->taxer($this->total, $this->invoice->tax_rate2); $tax = $this->taxer($this->total, $this->invoice->tax_rate2);
$tax += $this->getSurchargeTaxTotalForKey($this->invoice->tax_name2, $this->invoice->tax_rate2);
$this->total_taxes += $tax; $this->total_taxes += $tax;
$this->total_tax_map[] = ['name' => $this->invoice->tax_name2.' '.floatval($this->invoice->tax_rate2).'%', 'total' => $tax]; $this->total_tax_map[] = ['name' => $this->invoice->tax_name2.' '.floatval($this->invoice->tax_rate2).'%', 'total' => $tax];
} }
if (strlen($this->invoice->tax_name3) > 1) { if (strlen($this->invoice->tax_name3) > 1) {
$tax = $this->taxer($this->total, $this->invoice->tax_rate3); $tax = $this->taxer($this->total, $this->invoice->tax_rate3);
$tax += $this->getSurchargeTaxTotalForKey($this->invoice->tax_name3, $this->invoice->tax_rate3);
$this->total_taxes += $tax; $this->total_taxes += $tax;
$this->total_tax_map[] = ['name' => $this->invoice->tax_name3.' '.floatval($this->invoice->tax_rate3).'%', 'total' => $tax]; $this->total_tax_map[] = ['name' => $this->invoice->tax_name3.' '.floatval($this->invoice->tax_rate3).'%', 'total' => $tax];
} }
@ -300,6 +307,37 @@ class InvoiceSum
return $this; return $this;
} }
private function getSurchargeTaxTotalForKey($key, $rate)
{
$tax_component = 0;
if($this->invoice->custom_surcharge_tax1)
{
$tax_component += round($this->invoice->custom_surcharge1 * ($rate / 100), 2);
}
if($this->invoice->custom_surcharge_tax2)
{
$tax_component += round($this->invoice->custom_surcharge2 * ($rate / 100), 2);
}
if($this->invoice->custom_surcharge_tax3)
{
$tax_component += round($this->invoice->custom_surcharge3 * ($rate / 100), 2);
}
if($this->invoice->custom_surcharge_tax4)
{
$tax_component += round($this->invoice->custom_surcharge4 * ($rate / 100), 2);
}
return $tax_component;
}
public function getTaxMap() public function getTaxMap()
{ {
return $this->tax_map; return $this->tax_map;

View File

@ -282,7 +282,7 @@ class ClientController extends BaseController
$this->uploadLogo($request->file('company_logo'), $client->company, $client); $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()); return $this->itemResponse($client->fresh());
} }
@ -380,7 +380,7 @@ class ClientController extends BaseController
$this->uploadLogo($request->file('company_logo'), $client->company, $client); $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); return $this->itemResponse($client);
} }

View File

@ -89,29 +89,6 @@ class PaymentMethodController extends Controller
]); ]);
} }
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return void
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param int $id
* @return void
*/
public function update(Request $request, $id)
{
//
}
public function verify(ClientGatewayToken $payment_method) public function verify(ClientGatewayToken $payment_method)
{ {
$gateway = $this->getClientGateway(); $gateway = $this->getClientGateway();
@ -148,10 +125,10 @@ class PaymentMethodController extends Controller
->detach($payment_method); ->detach($payment_method);
try { 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(); $payment_method->delete();
} catch (Exception $e) { } catch (Exception $e) {
nlog($e->getMessage()); nlog($e->getMessage());
return back(); return back();

View File

@ -14,6 +14,7 @@ namespace App\Http\Controllers\ClientPortal;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Http\Requests\ClientPortal\Subscriptions\ShowPlanSwitchRequest; use App\Http\Requests\ClientPortal\Subscriptions\ShowPlanSwitchRequest;
use App\Models\RecurringInvoice;
use App\Models\Subscription; use App\Models\Subscription;
use Illuminate\Http\Request; use Illuminate\Http\Request;
@ -23,15 +24,32 @@ class SubscriptionPlanSwitchController extends Controller
* Show the page for switching between plans. * Show the page for switching between plans.
* *
* @param ShowPlanSwitchRequest $request * @param ShowPlanSwitchRequest $request
* @param Subscription $subscription * @param RecurringInvoice $recurring_invoice
* @param string $target * @param string $target
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/ */
public function index(ShowPlanSwitchRequest $request, Subscription $subscription, Subscription $target) public function index(ShowPlanSwitchRequest $request, RecurringInvoice $recurring_invoice, Subscription $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', [ return render('subscriptions.switch', [
'subscription' => $subscription, 'subscription' => $recurring_invoice->subscription,
'recurring_invoice' => $recurring_invoice,
'target' => $target, 'target' => $target,
'amount' => $amount,
]); ]);
} }
} }

View File

@ -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)); $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); return $this->itemResponse($client_subscription);
} }

View File

@ -201,7 +201,7 @@ class CreditController extends BaseController
->fillDefaults() ->fillDefaults()
->save(); ->save();
event(new CreditWasCreated($credit, $credit->company, Ninja::eventVars())); event(new CreditWasCreated($credit, $credit->company, Ninja::eventVars(auth()->user()->id)));
return $this->itemResponse($credit); return $this->itemResponse($credit);
} }
@ -378,7 +378,7 @@ class CreditController extends BaseController
$credit->service()->deletePdf(); $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); return $this->itemResponse($credit);
} }

View File

@ -157,7 +157,7 @@ class EmailController extends BaseController
$this->entity_transformer = QuoteTransformer::class; $this->entity_transformer = QuoteTransformer::class;
if ($entity_obj->invitations->count() >= 1) 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; $this->entity_transformer = CreditTransformer::class;
if ($entity_obj->invitations->count() >= 1) 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'));
} }

View File

@ -279,7 +279,7 @@ class ExpenseController extends BaseController
$this->uploadLogo($request->file('company_logo'), $expense->company, $expense); $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()); 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)); $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); return $this->itemResponse($expense);
} }

View File

@ -218,7 +218,7 @@ class InvoiceController extends BaseController
->triggeredActions($request) ->triggeredActions($request)
->save(); ->save();
event(new InvoiceWasCreated($invoice, $invoice->company, Ninja::eventVars())); event(new InvoiceWasCreated($invoice, $invoice->company, Ninja::eventVars(auth()->user()->id)));
return $this->itemResponse($invoice); return $this->itemResponse($invoice);
} }
@ -399,7 +399,7 @@ class InvoiceController extends BaseController
$invoice->service()->deletePdf(); $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); return $this->itemResponse($invoice);
} }

View File

@ -382,7 +382,7 @@ class PaymentController extends BaseController
$payment = $this->payment_repo->save($request->all(), $payment); $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); return $this->itemResponse($payment);
} }

View File

@ -211,7 +211,7 @@ class QuoteController extends BaseController
$quote = $quote->service()->fillDefaults()->save(); $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); return $this->itemResponse($quote);
} }
@ -389,7 +389,7 @@ class QuoteController extends BaseController
$quote->service()->deletePdf(); $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); return $this->itemResponse($quote);
} }

View File

@ -11,6 +11,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Exceptions\FilePermissionsFailure;
use App\Utils\Ninja; use App\Utils\Ninja;
use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
@ -61,6 +62,9 @@ class SelfUpdateController extends BaseController
return response()->json(['message' => ctrans('texts.self_update_not_available')], 403); 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 // Check if new version is available
if($updater->source()->isNewVersionAvailable()) { 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() public function checkVersion()
{ {
return trim(file_get_contents(config('ninja.version_url'))); return trim(file_get_contents(config('ninja.version_url')));

View File

@ -85,7 +85,7 @@ class ClientController extends BaseController
$this->uploadLogo($request->file('company_logo'), $company, $client); $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); return $this->itemResponse($client);
} }

View File

@ -85,7 +85,7 @@ class InvoiceController extends BaseController
$invoice = $invoice->service()->triggeredActions($request)->save(); $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); return $this->itemResponse($invoice);
} }

View File

@ -13,6 +13,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Events\Subscription\SubscriptionWasCreated; use App\Events\Subscription\SubscriptionWasCreated;
use App\Events\Subscription\SubscriptionWasUpdated;
use App\Factory\SubscriptionFactory; use App\Factory\SubscriptionFactory;
use App\Http\Requests\Subscription\CreateSubscriptionRequest; use App\Http\Requests\Subscription\CreateSubscriptionRequest;
use App\Http\Requests\Subscription\DestroySubscriptionRequest; use App\Http\Requests\Subscription\DestroySubscriptionRequest;
@ -24,9 +25,12 @@ use App\Models\Subscription;
use App\Repositories\SubscriptionRepository; use App\Repositories\SubscriptionRepository;
use App\Transformers\SubscriptionTransformer; use App\Transformers\SubscriptionTransformer;
use App\Utils\Ninja; use App\Utils\Ninja;
use App\Utils\Traits\MakesHash;
class SubscriptionController extends BaseController class SubscriptionController extends BaseController
{ {
use MakesHash;
protected $entity_type = Subscription::class; protected $entity_type = Subscription::class;
protected $entity_transformer = SubscriptionTransformer::class; protected $entity_transformer = SubscriptionTransformer::class;
@ -173,7 +177,7 @@ class SubscriptionController extends BaseController
{ {
$subscription = $this->subscription_repo->save($request->all(), SubscriptionFactory::create(auth()->user()->company()->id, auth()->user()->id)); $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); return $this->itemResponse($subscription);
} }
@ -348,6 +352,8 @@ class SubscriptionController extends BaseController
$subscription = $this->subscription_repo->save($request->all(), $subscription); $subscription = $this->subscription_repo->save($request->all(), $subscription);
event(new SubscriptionWasUpdated($subscription, $subscription->company, Ninja::eventVars(auth()->user()->id)));
return $this->itemResponse($subscription); return $this->itemResponse($subscription);
} }
@ -407,4 +413,72 @@ class SubscriptionController extends BaseController
return $this->itemResponse($subscription->fresh()); return $this->itemResponse($subscription->fresh());
} }
/**
* Perform bulk actions on the list view.
*
* @return Response
*
*
* @OA\Post(
* path="/api/v1/subscriptions/bulk",
* operationId="bulkSubscriptions",
* tags={"subscriptions"},
* summary="Performs bulk actions on an array of subscriptions",
* description="",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/index"),
* @OA\RequestBody(
* description="User credentials",
* required=true,
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* type="array",
* @OA\Items(
* type="integer",
* description="Array of hashed IDs to be bulk 'actioned",
* example="[0,1,2,3]",
* ),
* )
* )
* ),
* @OA\Response(
* response=200,
* description="The Subscription response",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/Subscription"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*/
public function bulk()
{
$action = request()->input('action');
$ids = request()->input('ids');
$subscriptions = Subscription::withTrashed()->find($this->transformKeys($ids));
$subscriptions->each(function ($subscription, $key) use ($action) {
if (auth()->user()->can('edit', $subscription)) {
$this->subscription_repo->{$action}($subscription);
}
});
return $this->listResponse(Subscription::withTrashed()->whereIn('id', $this->transformKeys($ids)));
}
} }

View File

@ -279,10 +279,10 @@ class TaskController extends BaseController
$task = $this->task_repo->save($request->all(), $task); $task = $this->task_repo->save($request->all(), $task);
if($task->status_order != $old_task->status_order) // if($task->status_order != $old_task->status_order)
$this->task_repo->sortStatuses($old_task, $task); // $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()); 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)); $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); return $this->itemResponse($task);
} }

View File

@ -211,7 +211,7 @@ class UserController extends BaseController
nlog("in the store method of the usercontroller class"); 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()); return $this->itemResponse($user->fresh());
} }
@ -401,7 +401,7 @@ class UserController extends BaseController
$user->company_user()->update(["permissions_updated_at" => now()]); $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); return $this->itemResponse($user);
} }
@ -474,7 +474,7 @@ class UserController extends BaseController
/* If the user passes the company user we archive the company user */ /* If the user passes the company user we archive the company user */
$user = $this->user_repo->delete($request->all(), $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()); return $this->itemResponse($user->fresh());
} }

View File

@ -278,7 +278,7 @@ class VendorController extends BaseController
$this->uploadLogo($request->file('company_logo'), $vendor->company, $vendor); $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()); return $this->itemResponse($vendor->fresh());
} }
@ -376,7 +376,7 @@ class VendorController extends BaseController
$this->uploadLogo($request->file('company_logo'), $vendor->company, $vendor); $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); return $this->itemResponse($vendor);
} }

View File

@ -111,6 +111,7 @@ class BillingPortalPurchase extends Component
'discount_applied' => false, 'discount_applied' => false,
'show_loading_bar' => false, 'show_loading_bar' => false,
'not_eligible' => null, 'not_eligible' => null,
'not_eligible_message' => null,
]; ];
/** /**
@ -327,6 +328,7 @@ class BillingPortalPurchase extends Component
if (is_array($is_eligible)) { if (is_array($is_eligible)) {
$this->steps['not_eligible'] = true; $this->steps['not_eligible'] = true;
$this->steps['not_eligible_message'] = $is_eligible['exception'];
$this->steps['show_loading_bar'] = false; $this->steps['show_loading_bar'] = false;
return; return;

View File

@ -26,6 +26,11 @@ class InvoicesTable extends Component
public $status = []; public $status = [];
public function mount()
{
$this->sort_asc = false;
}
public function render() public function render()
{ {
$local_status = []; $local_status = [];
@ -62,6 +67,7 @@ class InvoicesTable extends Component
$query = $query $query = $query
->where('client_id', auth('contact')->user()->client->id) ->where('client_id', auth('contact')->user()->client->id)
->where('status_id', '<>', Invoice::STATUS_DRAFT) ->where('status_id', '<>', Invoice::STATUS_DRAFT)
->withTrashed()
->paginate($this->per_page); ->paginate($this->per_page);
return render('components.livewire.invoices-table', [ return render('components.livewire.invoices-table', [

View File

@ -1,40 +0,0 @@
<?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\Http\Livewire;
use App\Models\Invoice;
use App\Utils\Traits\WithSorting;
use Livewire\Component;
use Livewire\WithPagination;
class SubscriptionInvoicesTable extends Component
{
use WithPagination;
use WithSorting;
public $per_page = 10;
public function render()
{
$query = Invoice::query()
->where('client_id', auth('contact')->user()->client->id)
->whereNotNull('subscription_id')
->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc')
->where('balance', '=', 0)
->paginate($this->per_page);
return render('components.livewire.subscriptions-invoices-table', [
'invoices' => $query,
]);
}
}

View File

@ -19,11 +19,21 @@ use Livewire\Component;
class SubscriptionPlanSwitch extends Component class SubscriptionPlanSwitch extends Component
{ {
/**
* @var RecurringInvoice
*/
public $recurring_invoice;
/** /**
* @var Subscription * @var Subscription
*/ */
public $subscription; public $subscription;
/**
* @var ?float
*/
public $amount;
/** /**
* @var Subscription * @var Subscription
*/ */
@ -62,7 +72,7 @@ class SubscriptionPlanSwitch extends Component
public function mount() 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); $this->methods = $this->contact->client->service()->getPaymentMethods(100);
@ -74,6 +84,7 @@ class SubscriptionPlanSwitch extends Component
$this->state['show_loading_bar'] = true; $this->state['show_loading_bar'] = true;
$this->state['invoice'] = $this->subscription->service()->createChangePlanInvoice([ $this->state['invoice'] = $this->subscription->service()->createChangePlanInvoice([
'recurring_invoice' => $this->recurring_invoice,
'subscription' => $this->subscription, 'subscription' => $this->subscription,
'target' => $this->target, 'target' => $this->target,
]); ]);

View File

@ -17,7 +17,7 @@ class ShowPlanSwitchRequest extends FormRequest
*/ */
public function authorize() public function authorize()
{ {
return (bool)$this->subscription->allow_plan_changes; return (bool)$this->recurring_invoice->subscription->allow_plan_changes;
} }
/** /**

View File

@ -84,7 +84,7 @@ class ValidInvoicesRules implements Rule
} }
else if($invoice['amount'] > $inv->balance) { else if($invoice['amount'] > $inv->balance) {
$this->error_msg = ctrans('texts.amount_greater_than_balance'); $this->error_msg = ctrans('texts.amount_greater_than_balance_v5');
return false; return false;
} }

View File

@ -12,6 +12,7 @@
namespace App\Jobs\Entity; namespace App\Jobs\Entity;
use App\Exceptions\FilePermissionsFailure;
use App\Models\Account; use App\Models\Account;
use App\Models\Credit; use App\Models\Credit;
use App\Models\CreditInvitation; use App\Models\CreditInvitation;
@ -168,6 +169,7 @@ class CreateEntityPdf implements ShouldQueue
else { else {
$pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true)); $pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true));
} }
} catch (\Exception $e) { } catch (\Exception $e) {
nlog(print_r($e->getMessage(), 1)); nlog(print_r($e->getMessage(), 1));
} }
@ -176,8 +178,20 @@ class CreateEntityPdf implements ShouldQueue
info($maker->getCompiledHTML()); info($maker->getCompiledHTML());
} }
if ($pdf) { if ($pdf) {
Storage::disk($this->disk)->put($file_path, $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; return $file_path;

View File

@ -142,7 +142,7 @@ class EmailEntity implements ShouldQueue
{ {
switch ($this->entity_string) { switch ($this->entity_string) {
case 'invoice': 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; break;
default: default:

View File

@ -105,10 +105,10 @@ class NinjaMailerJob implements ShouldQueue
switch ($class) { switch ($class) {
case Invoice::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; break;
case Payment::class: 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; break;
default: default:
# code... # code...

View File

@ -91,7 +91,7 @@ class EmailPayment implements ShouldQueue
NinjaMailerJob::dispatch($nmo); 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)));
} }
} }
} }

View File

@ -84,7 +84,7 @@ class CreateUser
if(!Ninja::isSelfHost()){ if(!Ninja::isSelfHost()){
nlog("in the create user class"); 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; return $user;

View File

@ -192,6 +192,7 @@ class MultiDB
return true; return true;
} }
self::setDefaultDatabase();
return false; return false;
} }
@ -205,6 +206,7 @@ class MultiDB
return true; return true;
} }
} }
self::setDefaultDatabase();
return false; return false;
} }
@ -218,6 +220,7 @@ class MultiDB
return true; return true;
} }
} }
self::setDefaultDatabase();
return false; return false;
} }
@ -230,6 +233,7 @@ class MultiDB
return true; return true;
} }
} }
self::setDefaultDatabase();
return false; return false;
} }
@ -242,16 +246,20 @@ class MultiDB
return true; return true;
} }
} }
self::setDefaultDatabase();
return false; return false;
} }
public static function findAndSetDbByDomain($subdomain) :bool public static function findAndSetDbByDomain($subdomain) :bool
{ {
if (! config('ninja.db.multi_db_enabled'))
return (Company::whereSubdomain($subdomain)->exists() === true);
foreach (self::$dbs as $db) { foreach (self::$dbs as $db) {
if ($company = Company::on($db)->whereSubdomain($subdomain)->first()) { if ($company = Company::on($db)->whereSubdomain($subdomain)->first()) {
self::setDb($company->db); self::setDb($company->db);
return true; return true;
} }
} }

View File

@ -43,8 +43,10 @@ class ArchivedClientActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->client->user_id;
$fields->client_id = $event->client->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->company_id = $event->client->company_id;
$fields->activity_type_id = Activity::ARCHIVE_CLIENT; $fields->activity_type_id = Activity::ARCHIVE_CLIENT;

View File

@ -45,8 +45,10 @@ class ClientUpdatedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->client->user_id;
$fields->client_id = $client->id; $fields->client_id = $client->id;
$fields->user_id = $client->user_id; $fields->user_id = $user_id;
$fields->company_id = $client->company_id; $fields->company_id = $client->company_id;
$fields->activity_type_id = Activity::UPDATE_CLIENT; $fields->activity_type_id = Activity::UPDATE_CLIENT;

View File

@ -43,8 +43,10 @@ class CreatedClientActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->client->user_id;
$fields->client_id = $event->client->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->company_id = $event->client->company_id;
$fields->activity_type_id = Activity::CREATE_CLIENT; $fields->activity_type_id = Activity::CREATE_CLIENT;

View File

@ -43,8 +43,10 @@ class CreatedCreditActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->credit->user_id;
$fields->credit_id = $event->credit->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->client_id = $event->credit->client_id;
$fields->company_id = $event->credit->company_id; $fields->company_id = $event->credit->company_id;

View File

@ -43,8 +43,11 @@ class CreatedExpenseActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->expense->user_id;
$fields->expense_id = $event->expense->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->company_id = $event->expense->company_id;
$fields->activity_type_id = Activity::CREATE_EXPENSE; $fields->activity_type_id = Activity::CREATE_EXPENSE;

View File

@ -43,9 +43,11 @@ class CreatedQuoteActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->quote->user_id;
$fields->quote_id = $event->quote->id; $fields->quote_id = $event->quote->id;
$fields->client_id = $event->quote->client_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->company_id = $event->quote->company_id;
$fields->activity_type_id = Activity::CREATE_QUOTE; $fields->activity_type_id = Activity::CREATE_QUOTE;

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

View File

@ -43,8 +43,10 @@ class CreatedTaskActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->task->user_id;
$fields->task_id = $event->task->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->company_id = $event->task->company_id;
$fields->activity_type_id = Activity::CREATE_TASK; $fields->activity_type_id = Activity::CREATE_TASK;

View File

@ -43,8 +43,10 @@ class CreatedVendorActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->vendor->user_id;
$fields->vendor_id = $event->vendor->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->company_id = $event->vendor->company_id;
$fields->activity_type_id = Activity::CREATE_VENDOR; $fields->activity_type_id = Activity::CREATE_VENDOR;

View File

@ -43,9 +43,11 @@ class CreditArchivedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->credit->user_id;
$fields->payment_id = $event->credit->id; $fields->payment_id = $event->credit->id;
$fields->client_id = $event->credit->client_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->company_id = $event->credit->company_id;
$fields->activity_type_id = Activity::ARCHIVE_CREDIT; $fields->activity_type_id = Activity::ARCHIVE_CREDIT;

View File

@ -43,8 +43,10 @@ class DeleteClientActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->client->user_id;
$fields->client_id = $event->client->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->company_id = $event->client->company_id;
$fields->activity_type_id = Activity::DELETE_CLIENT; $fields->activity_type_id = Activity::DELETE_CLIENT;

View File

@ -43,9 +43,11 @@ class DeleteCreditActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->credit->user_id;
$fields->client_id = $event->credit->client_id; $fields->client_id = $event->credit->client_id;
$fields->credit_id = $event->credit->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->company_id = $event->credit->company_id;
$fields->activity_type_id = Activity::DELETE_CREDIT; $fields->activity_type_id = Activity::DELETE_CREDIT;

View File

@ -45,8 +45,10 @@ class ExpenseArchivedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->expense->user_id;
$fields->expense_id = $expense->id; $fields->expense_id = $expense->id;
$fields->user_id = $expense->user_id; $fields->user_id = $user_id;
$fields->company_id = $expense->company_id; $fields->company_id = $expense->company_id;
$fields->activity_type_id = Activity::ARCHIVE_EXPENSE; $fields->activity_type_id = Activity::ARCHIVE_EXPENSE;

View File

@ -43,8 +43,10 @@ class ExpenseDeletedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->expense->user_id;
$fields->expense_id = $event->expense->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->company_id = $event->expense->company_id;
$fields->activity_type_id = Activity::DELETE_VENDOR; $fields->activity_type_id = Activity::DELETE_VENDOR;

View File

@ -43,8 +43,10 @@ class ExpenseRestoredActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->expense->user_id;
$fields->expense_id = $event->expense->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->company_id = $event->expense->company_id;
$fields->activity_type_id = Activity::RESTORE_EXPENSE; $fields->activity_type_id = Activity::RESTORE_EXPENSE;

View File

@ -43,10 +43,12 @@ class ExpenseUpdatedActivity implements ShouldQueue
$expense = $event->expense; $expense = $event->expense;
$user_id = $event->event_vars['user_id'] ?: $event->expense->user_id;
$fields = new stdClass; $fields = new stdClass;
$fields->expense_id = $expense->id; $fields->expense_id = $expense->id;
$fields->user_id = $expense->user_id; $fields->user_id = $user_id;
$fields->company_id = $expense->company_id; $fields->company_id = $expense->company_id;
$fields->activity_type_id = Activity::UPDATE_EXPENSE; $fields->activity_type_id = Activity::UPDATE_EXPENSE;

View File

@ -48,9 +48,11 @@ class PaymentArchivedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->payment->user_id;
$fields->payment_id = $payment->id; $fields->payment_id = $payment->id;
$fields->client_id = $payment->client_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->company_id = $payment->company_id;
$fields->activity_type_id = Activity::ARCHIVE_PAYMENT; $fields->activity_type_id = Activity::ARCHIVE_PAYMENT;

View File

@ -43,13 +43,15 @@ class PaymentCreatedActivity implements ShouldQueue
$payment = $event->payment; $payment = $event->payment;
$user_id = $event->event_vars['user_id'] ?: $event->payment->user_id;
$invoices = $payment->invoices; $invoices = $payment->invoices;
$fields = new stdClass; $fields = new stdClass;
$fields->payment_id = $payment->id; $fields->payment_id = $payment->id;
$fields->client_id = $payment->client_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->company_id = $payment->company_id;
$fields->activity_type_id = Activity::CREATE_PAYMENT; $fields->activity_type_id = Activity::CREATE_PAYMENT;

View File

@ -43,13 +43,15 @@ class PaymentDeletedActivity implements ShouldQueue
$payment = $event->payment; $payment = $event->payment;
$user_id = $event->event_vars['user_id'] ?: $event->payment->user_id;
$invoices = $payment->invoices; $invoices = $payment->invoices;
$fields = new stdClass; $fields = new stdClass;
$fields->payment_id = $payment->id; $fields->payment_id = $payment->id;
$fields->client_id = $payment->client_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->company_id = $payment->company_id;
$fields->activity_type_id = Activity::DELETE_PAYMENT; $fields->activity_type_id = Activity::DELETE_PAYMENT;

View File

@ -43,9 +43,11 @@ class PaymentRefundedActivity implements ShouldQueue
$fields = new stdClass; $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->id;
$fields->client_id = $event->payment->client_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->company_id = $event->payment->company_id;
$fields->activity_type_id = Activity::REFUNDED_PAYMENT; $fields->activity_type_id = Activity::REFUNDED_PAYMENT;
$fields->payment_id = $event->payment->id; $fields->payment_id = $event->payment->id;

View File

@ -48,9 +48,11 @@ class PaymentUpdatedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->payment->user_id;
$fields->payment_id = $payment->id; $fields->payment_id = $payment->id;
$fields->client_id = $payment->client_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->company_id = $payment->company_id;
$fields->activity_type_id = Activity::UPDATE_PAYMENT; $fields->activity_type_id = Activity::UPDATE_PAYMENT;

View File

@ -43,8 +43,10 @@ class PaymentVoidedActivity implements ShouldQueue
$fields = new stdClass; $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->id;
$fields->user_id = $event->payment->user_id; $fields->user_id = $user_id;
$fields->company_id = $event->payment->company_id; $fields->company_id = $event->payment->company_id;
$fields->activity_type_id = Activity::VOIDED_PAYMENT; $fields->activity_type_id = Activity::VOIDED_PAYMENT;
$fields->payment_id = $event->payment->id; $fields->payment_id = $event->payment->id;

View File

@ -45,9 +45,11 @@ class QuoteUpdatedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->quote->user_id;
$fields->quote_id = $quote->id; $fields->quote_id = $quote->id;
$fields->client_id = $quote->client_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->company_id = $quote->company_id;
$fields->activity_type_id = Activity::UPDATE_QUOTE; $fields->activity_type_id = Activity::UPDATE_QUOTE;

View File

@ -43,8 +43,10 @@ class RestoreClientActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->client->user_id;
$fields->client_id = $event->client->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->company_id = $event->client->company_id;
$fields->activity_type_id = Activity::RESTORE_CLIENT; $fields->activity_type_id = Activity::RESTORE_CLIENT;

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

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

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

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

View File

@ -45,8 +45,10 @@ class TaskArchivedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->task->user_id;
$fields->task_id = $task->id; $fields->task_id = $task->id;
$fields->user_id = $task->user_id; $fields->user_id = $user_id;
$fields->company_id = $task->company_id; $fields->company_id = $task->company_id;
$fields->activity_type_id = Activity::ARCHIVE_TASK; $fields->activity_type_id = Activity::ARCHIVE_TASK;

View File

@ -43,8 +43,10 @@ class TaskDeletedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->task->user_id;
$fields->task_id = $event->task->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->company_id = $event->task->company_id;
$fields->activity_type_id = Activity::DELETE_TASK; $fields->activity_type_id = Activity::DELETE_TASK;

View File

@ -43,8 +43,10 @@ class TaskRestoredActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->task->user_id;
$fields->task_id = $event->task->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->company_id = $event->task->company_id;
$fields->activity_type_id = Activity::RESTORE_TASK; $fields->activity_type_id = Activity::RESTORE_TASK;

View File

@ -45,8 +45,10 @@ class TaskUpdatedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->task->user_id;
$fields->task_id = $task->id; $fields->task_id = $task->id;
$fields->user_id = $task->user_id; $fields->user_id = $user_id;
$fields->company_id = $task->company_id; $fields->company_id = $task->company_id;
$fields->activity_type_id = Activity::UPDATE_TASK; $fields->activity_type_id = Activity::UPDATE_TASK;

View File

@ -43,9 +43,11 @@ class UpdatedCreditActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->credit->user_id;
$fields->credit_id = $event->credit->id; $fields->credit_id = $event->credit->id;
$fields->client_id = $event->credit->client_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->company_id = $event->credit->company_id;
$fields->activity_type_id = Activity::UPDATE_CREDIT; $fields->activity_type_id = Activity::UPDATE_CREDIT;

View File

@ -45,8 +45,10 @@ class VendorArchivedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->vendor->user_id;
$fields->vendor_id = $vendor->id; $fields->vendor_id = $vendor->id;
$fields->user_id = $vendor->user_id; $fields->user_id = $user_id;
$fields->company_id = $vendor->company_id; $fields->company_id = $vendor->company_id;
$fields->activity_type_id = Activity::ARCHIVE_VENDOR; $fields->activity_type_id = Activity::ARCHIVE_VENDOR;

View File

@ -43,8 +43,10 @@ class VendorDeletedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->vendor->user_id;
$fields->vendor_id = $event->vendor->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->company_id = $event->vendor->company_id;
$fields->activity_type_id = Activity::DELETE_VENDOR; $fields->activity_type_id = Activity::DELETE_VENDOR;

View File

@ -43,8 +43,10 @@ class VendorRestoredActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->vendor->user_id;
$fields->vendor_id = $event->vendor->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->company_id = $event->vendor->company_id;
$fields->activity_type_id = Activity::RESTORE_VENDOR; $fields->activity_type_id = Activity::RESTORE_VENDOR;

View File

@ -45,8 +45,10 @@ class VendorUpdatedActivity implements ShouldQueue
$fields = new stdClass; $fields = new stdClass;
$user_id = $event->event_vars['user_id'] ?: $event->vendor->user_id;
$fields->vendor_id = $vendor->id; $fields->vendor_id = $vendor->id;
$fields->user_id = $vendor->user_id; $fields->user_id = $user_id;
$fields->company_id = $vendor->company_id; $fields->company_id = $vendor->company_id;
$fields->activity_type_id = Activity::UPDATE_VENDOR; $fields->activity_type_id = Activity::UPDATE_VENDOR;

View File

@ -0,0 +1,43 @@
<?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\Mail\Gateways;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class ACHVerificationNotification extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('email.gateways.ach-verification-notification');
}
}

View File

@ -49,6 +49,10 @@ class TemplateEmail extends Mailable
{ {
$template_name = 'email.template.'.$this->build_email->getTemplate(); $template_name = 'email.template.'.$this->build_email->getTemplate();
if($this->build_email->getTemplate() == 'custom') {
$this->build_email->setBody(str_replace('$body', $this->build_email->getBody(), $this->client->getSetting('email_style_custom')));
}
$settings = $this->client->getMergedSettings(); $settings = $this->client->getMergedSettings();
$company = $this->client->company; $company = $this->client->company;

View File

@ -84,6 +84,12 @@ class Activity extends StaticModel
const INVOICE_REMINDER3_SENT = 65; const INVOICE_REMINDER3_SENT = 65;
const INVOICE_REMINDER_ENDLESS_SENT = 66; 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 = [ protected $casts = [
'is_system' => 'boolean', 'is_system' => 'boolean',
'updated_at' => 'timestamp', 'updated_at' => 'timestamp',

View File

@ -255,10 +255,10 @@ class Credit extends BaseModel
} }
if (! $invitation) { 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()); CreateEntityPdf::dispatchNow($this->invitations->first());
} else { } else {
event(new CreditWasUpdated($this, $this->company, Ninja::eventVars())); event(new CreditWasUpdated($this, $this->company, Ninja::eventVars(auth()->user()->id)));
CreateEntityPdf::dispatchNow($invitation); CreateEntityPdf::dispatchNow($invitation);
} }

View File

@ -129,7 +129,7 @@ class CreditInvitation extends BaseModel
$storage_path = Storage::url($this->credit->client->quote_filepath().$this->credit->numberFormatter().'.pdf'); $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')) { 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); CreateEntityPdf::dispatchNow($this);
} }

View File

@ -397,7 +397,7 @@ class Invoice extends BaseModel
$storage_path = Storage::$type($this->client->invoice_filepath().$this->numberFormatter().'.pdf'); $storage_path = Storage::$type($this->client->invoice_filepath().$this->numberFormatter().'.pdf');
if (! Storage::exists($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); CreateEntityPdf::dispatchNow($invitation);
} }

View File

@ -143,7 +143,7 @@ class InvoiceInvitation extends BaseModel
$storage_path = Storage::url($this->invoice->client->invoice_filepath().$this->invoice->numberFormatter().'.pdf'); $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')) { 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); CreateEntityPdf::dispatchNow($this);
} }

View File

@ -243,7 +243,7 @@ class Payment extends BaseModel
$this->status_id = $this->refunded == $this->amount ? self::STATUS_REFUNDED : self::STATUS_PARTIALLY_REFUNDED; $this->status_id = $this->refunded == $this->amount ? self::STATUS_REFUNDED : self::STATUS_PARTIALLY_REFUNDED;
$this->save(); $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; return true;
@ -280,7 +280,7 @@ class Payment extends BaseModel
$this->status_id = self::STATUS_CANCELLED; $this->status_id = self::STATUS_CANCELLED;
$this->save(); $this->save();
event(new PaymentWasVoided($this, $this->company, Ninja::eventVars())); event(new PaymentWasVoided($this, $this->company, Ninja::eventVars(auth()->user()->id)));
} }
public function getLink() public function getLink()

View File

@ -213,7 +213,7 @@ class Quote extends BaseModel
nlog($storage_path); nlog($storage_path);
if (! Storage::exists($this->client->quote_filepath().$this->numberFormatter().'.pdf')) { 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); CreateEntityPdf::dispatchNow($invitation);
} }

View File

@ -133,7 +133,7 @@ class QuoteInvitation extends BaseModel
$storage_path = Storage::url($this->quote->client->quote_filepath().$this->quote->numberFormatter().'.pdf'); $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')) { 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); CreateEntityPdf::dispatchNow($this);
} }

View File

@ -184,7 +184,7 @@ class RecurringInvoice extends BaseModel
public function invoices() public function invoices()
{ {
return $this->hasMany(Invoice::class, 'id', 'recurring_id')->withTrashed(); return $this->hasMany(Invoice::class, 'recurring_id', 'id')->withTrashed();
} }
public function invitations() public function invitations()

View File

@ -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->data = array_merge((array)$this->checkout->payment_hash->data, ['checkout_payment_ref' => $payment]);
$this->checkout->payment_hash->save(); $this->checkout->payment_hash->save();
if ($this->checkout->client->currency()->code === 'EUR') { if ($this->checkout->client->currency()->code == 'EUR') {
$payment->{'3ds'} = ['enabled' => true]; $payment->{'3ds'} = ['enabled' => true];
$payment->{'success_url'} = route('payment_webhook', [ $payment->{'success_url'} = route('payment_webhook', [

View File

@ -209,7 +209,8 @@ class CheckoutComPaymentDriver extends BaseDriver
$payment = new \Checkout\Models\Payments\Payment($method, $this->client->getCurrencyCode()); $payment = new \Checkout\Models\Payments\Payment($method, $this->client->getCurrencyCode());
$payment->amount = $this->convertToCheckoutAmount($amount, $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 = new PaymentResponseRequest();
$request->setMethod('POST'); $request->setMethod('POST');

View File

@ -11,6 +11,12 @@
namespace App\PaymentDrivers; 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; use App\Utils\Traits\MakesHash;
class DriverTemplate extends BaseDriver class DriverTemplate extends BaseDriver

View File

@ -14,8 +14,11 @@ namespace App\PaymentDrivers\Stripe;
use App\Exceptions\PaymentFailed; use App\Exceptions\PaymentFailed;
use App\Http\Requests\Request; use App\Http\Requests\Request;
use App\Jobs\Mail\NinjaMailerJob;
use App\Jobs\Mail\NinjaMailerObject;
use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger; use App\Jobs\Util\SystemLogger;
use App\Mail\Gateways\ACHVerificationNotification;
use App\Models\ClientGatewayToken; use App\Models\ClientGatewayToken;
use App\Models\GatewayType; use App\Models\GatewayType;
use App\Models\Payment; use App\Models\Payment;
@ -47,7 +50,7 @@ class ACH
return render('gateways.stripe.ach.authorize', array_merge($data)); return render('gateways.stripe.ach.authorize', array_merge($data));
} }
public function authorizeResponse($request) public function authorizeResponse(Request $request)
{ {
$this->stripe->init(); $this->stripe->init();
@ -63,6 +66,14 @@ class ACH
$client_gateway_token = $this->storePaymentMethod($source, $request->input('method'), $customer); $client_gateway_token = $this->storePaymentMethod($source, $request->input('method'), $customer);
$mailer = new NinjaMailerObject();
$mailer->mailable = new ACHVerificationNotification();
$mailer->company = auth('contact')->user()->client->company;
$mailer->settings = auth('contact')->user()->client->company->settings;
$mailer->to_user = auth('contact')->user();
NinjaMailerJob::dispatchNow($mailer);
return redirect()->route('client.payment_methods.verification', ['payment_method' => $client_gateway_token->hashed_id, 'method' => GatewayType::BANK_TRANSFER]); return redirect()->route('client.payment_methods.verification', ['payment_method' => $client_gateway_token->hashed_id, 'method' => GatewayType::BANK_TRANSFER]);
} }

View File

@ -67,6 +67,11 @@ use App\Events\Quote\QuoteWasEmailed;
use App\Events\Quote\QuoteWasRestored; use App\Events\Quote\QuoteWasRestored;
use App\Events\Quote\QuoteWasUpdated; use App\Events\Quote\QuoteWasUpdated;
use App\Events\Quote\QuoteWasViewed; 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\TaskWasArchived;
use App\Events\Task\TaskWasCreated; use App\Events\Task\TaskWasCreated;
use App\Events\Task\TaskWasDeleted; use App\Events\Task\TaskWasDeleted;
@ -89,6 +94,7 @@ use App\Listeners\Activity\CreatedClientActivity;
use App\Listeners\Activity\CreatedCreditActivity; use App\Listeners\Activity\CreatedCreditActivity;
use App\Listeners\Activity\CreatedExpenseActivity; use App\Listeners\Activity\CreatedExpenseActivity;
use App\Listeners\Activity\CreatedQuoteActivity; use App\Listeners\Activity\CreatedQuoteActivity;
use App\Listeners\Activity\CreatedSubscriptionActivity;
use App\Listeners\Activity\CreatedTaskActivity; use App\Listeners\Activity\CreatedTaskActivity;
use App\Listeners\Activity\CreatedVendorActivity; use App\Listeners\Activity\CreatedVendorActivity;
use App\Listeners\Activity\CreditArchivedActivity; use App\Listeners\Activity\CreditArchivedActivity;
@ -106,6 +112,10 @@ use App\Listeners\Activity\PaymentUpdatedActivity;
use App\Listeners\Activity\PaymentVoidedActivity; use App\Listeners\Activity\PaymentVoidedActivity;
use App\Listeners\Activity\QuoteUpdatedActivity; use App\Listeners\Activity\QuoteUpdatedActivity;
use App\Listeners\Activity\RestoreClientActivity; 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\TaskArchivedActivity;
use App\Listeners\Activity\TaskDeletedActivity; use App\Listeners\Activity\TaskDeletedActivity;
use App\Listeners\Activity\TaskRestoredActivity; use App\Listeners\Activity\TaskRestoredActivity;
@ -396,6 +406,21 @@ class EventServiceProvider extends ServiceProvider
TaskWasRestored::class => [ TaskWasRestored::class => [
TaskRestoredActivity::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 => [ VendorWasCreated::class => [
CreatedVendorActivity::class, CreatedVendorActivity::class,
], ],

View File

@ -55,7 +55,7 @@ class BaseRepository
$className = $this->getEventClass($entity, 'Archived'); $className = $this->getEventClass($entity, 'Archived');
if (class_exists($className)) { 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'); $className = $this->getEventClass($entity, 'Restored');
if (class_exists($className)) { 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'); $className = $this->getEventClass($entity, 'Deleted');
if (class_exists($className) && ! ($entity instanceof Company)) { 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)));
} }
} }

View File

@ -155,7 +155,7 @@ class PaymentRepository extends BaseRepository {
} }
if ( ! $is_existing_payment && ! $this->import_mode ) { 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}"); nlog("payment amount = {$payment->amount}");
@ -205,7 +205,7 @@ class PaymentRepository extends BaseRepository {
$payment = $payment->service()->deletePayment(); $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 $payment;
//return parent::delete($payment); //return parent::delete($payment);

View File

@ -123,7 +123,7 @@ class UserRepository extends BaseRepository
$cu->forceDelete(); $cu->forceDelete();
} }
event(new UserWasDeleted($user, $company, Ninja::eventVars())); event(new UserWasDeleted($user, $company, Ninja::eventVars(auth()->user()->id)));
$user->delete(); $user->delete();
@ -146,7 +146,7 @@ class UserRepository extends BaseRepository
$cu->delete(); $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->is_deleted = true;
$user->save(); $user->save();
@ -164,7 +164,7 @@ class UserRepository extends BaseRepository
$user->delete(); $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(); $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)));
} }
} }

View File

@ -144,11 +144,11 @@ class ApplyPayment
->ledger() ->ledger()
->updateCreditBalance(($this->amount_applied * -1), "Credit payment applied to Invoice {$this->invoice->number}"); ->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) { if ((int)$this->invoice->balance == 0) {
$this->invoice->service()->deletePdf(); $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)));
} }
} }
} }

Some files were not shown because too many files have changed in this diff Show More