Merge branch 'v5-develop' into v5-develop

This commit is contained in:
Lars Kusch 2023-08-09 09:42:35 +02:00 committed by GitHub
commit c16478bc06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
248 changed files with 1071 additions and 944 deletions

View File

@ -1 +1 @@
5.6.26 5.6.28

View File

@ -185,6 +185,9 @@ class CheckData extends Command
if ($cu->company && $cu->user) { if ($cu->company && $cu->user) {
(new CreateCompanyToken($cu->company, $cu->user, 'System'))->handle(); (new CreateCompanyToken($cu->company, $cu->user, 'System'))->handle();
} }
else {
// $cu->forceDelete();
}
} }
}); });
} }

View File

@ -250,8 +250,8 @@ class Rule extends BaseRule implements RuleInterface
// $this->reduced_tax_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->company->country()->iso_3166_2}->reduced_tax_rate; // $this->reduced_tax_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->company->country()->iso_3166_2}->reduced_tax_rate;
// } // }
$this->tax_rate = $this->client->company->tax_data->regions->AU->subregions->{$this->client->company->country()->iso_3166_2}->tax_rate; $this->tax_rate = $this->client->company->tax_data->regions->AU->subregions->{$this->client->company->country()->iso_3166_2}->tax_rate ?? 0;
$this->reduced_tax_rate = $this->client->company->tax_data->regions->AU->subregions->{$this->client->company->country()->iso_3166_2}->tax_rate; $this->reduced_tax_rate = $this->client->company->tax_data->regions->AU->subregions->{$this->client->company->country()->iso_3166_2}->tax_rate ?? 0;
return $this; return $this;

View File

@ -94,7 +94,6 @@ class BaseExport
"state" => "client.state", "state" => "client.state",
"postal_code" => "client.postal_code", "postal_code" => "client.postal_code",
"country" => "client.country_id", "country" => "client.country_id",
"custom_value4" => "contact.custom_value4",
"shipping_address1" => "client.shipping_address1", "shipping_address1" => "client.shipping_address1",
"shipping_address2" => "client.shipping_address2", "shipping_address2" => "client.shipping_address2",
"shipping_city" => "client.shipping_city", "shipping_city" => "client.shipping_city",
@ -109,6 +108,15 @@ class BaseExport
"first_name" => "contact.first_name", "first_name" => "contact.first_name",
"last_name" => "contact.last_name", "last_name" => "contact.last_name",
"email" => "contact.email", "email" => "contact.email",
'custom_value1' => 'client.custom_value1',
'custom_value2' => 'client.custom_value2',
'custom_value3' => 'client.custom_value3',
'custom_value4' => 'client.custom_value4',
"contact_custom_value1" => "contact.custom_value1",
"contact_custom_value2" => "contact.custom_value2",
"contact_custom_value3" => "contact.custom_value3",
"contact_custom_value4" => "contact.custom_value4",
]; ];
protected array $invoice_report_keys = [ protected array $invoice_report_keys = [

View File

@ -85,7 +85,7 @@ class ProductSalesExport extends BaseExport
$t = app('translator'); $t = app('translator');
$t->replace(Ninja::transformTranslations($this->company->settings)); $t->replace(Ninja::transformTranslations($this->company->settings));
$this->products = Product::where('company_id', $this->company->id)->withTrashed()->get(); $this->products = Product::query()->where('company_id', $this->company->id)->withTrashed()->get();
//load the CSV document from a string //load the CSV document from a string
$this->csv = Writer::createFromString(); $this->csv = Writer::createFromString();
@ -187,6 +187,7 @@ class ProductSalesExport extends BaseExport
$product = $this->getProduct($entity['product_key']); $product = $this->getProduct($entity['product_key']);
$entity['cost'] = $product->cost ?? 0; $entity['cost'] = $product->cost ?? 0;
/** @var float $unit_cost */
$unit_cost = $entity['cost'] == 0 ? 1 : $entity['cost']; $unit_cost = $entity['cost'] == 0 ? 1 : $entity['cost'];
$entity['client'] = $invoice->client->present()->name(); $entity['client'] = $invoice->client->present()->name();

View File

@ -66,7 +66,6 @@ class RecurringInvoiceExport extends BaseExport
'vendor' => 'vendor_id', 'vendor' => 'vendor_id',
'project' => 'project_id', 'project' => 'project_id',
'frequency_id' => 'frequency_id', 'frequency_id' => 'frequency_id',
'next_send_date' => 'next_send_date'
]; ];
private array $decorate_keys = [ private array $decorate_keys = [

View File

@ -72,8 +72,8 @@ abstract class QueryFilters
/** /**
* Apply the filters to the builder. * Apply the filters to the builder.
* *
* @param Builder $builder * @param \Illuminate\Database\Eloquent\Builder $builder
* @return Builder * @return \Illuminate\Database\Eloquent\Builder
*/ */
public function apply(Builder $builder) public function apply(Builder $builder)
{ {
@ -239,7 +239,11 @@ abstract class QueryFilters
} }
} }
/**
*
* @param string $value
* @return \Illuminate\Database\Eloquent\Builder
*/
public function is_deleted($value = 'true') public function is_deleted($value = 'true')
{ {
if ($value == 'true') { if ($value == 'true') {

View File

@ -94,7 +94,7 @@ class InvoiceItemSumInclusive
protected RecurringInvoice | Invoice | Quote | Credit | PurchaseOrder | RecurringQuote $invoice; protected RecurringInvoice | Invoice | Quote | Credit | PurchaseOrder | RecurringQuote $invoice;
private $currency; private \App\Models\Currency $currency;
private $total_taxes; private $total_taxes;
@ -226,8 +226,10 @@ class InvoiceItemSumInclusive
$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / 100)); $amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / 100));
/** @var float $item_tax_rate1_total */
$item_tax_rate1_total = $this->calcInclusiveLineTax($this->item->tax_rate1, $amount); $item_tax_rate1_total = $this->calcInclusiveLineTax($this->item->tax_rate1, $amount);
/** @var float $item_tax */
$item_tax += $this->formatValue($item_tax_rate1_total, $this->currency->precision); $item_tax += $this->formatValue($item_tax_rate1_total, $this->currency->precision);
if (strlen($this->item->tax_name1) > 1) { if (strlen($this->item->tax_name1) > 1) {

View File

@ -33,6 +33,7 @@ class GmailTransport extends AbstractTransport
nlog("In Do Send"); nlog("In Do Send");
$message = MessageConverter::toEmail($message->getOriginalMessage()); $message = MessageConverter::toEmail($message->getOriginalMessage());
/** @phpstan-ignore-next-line **/
$token = $message->getHeaders()->get('gmailtoken')->getValue(); $token = $message->getHeaders()->get('gmailtoken')->getValue();
$message->getHeaders()->remove('gmailtoken'); $message->getHeaders()->remove('gmailtoken');
@ -52,6 +53,8 @@ class GmailTransport extends AbstractTransport
if ($bccs) { if ($bccs) {
$bcc_list = 'Bcc: '; $bcc_list = 'Bcc: ';
/** @phpstan-ignore-next-line **/
foreach ($bccs->getAddresses() as $address) { foreach ($bccs->getAddresses() as $address) {
$bcc_list .= $address->getAddress() .','; $bcc_list .= $address->getAddress() .',';
} }

View File

@ -28,6 +28,8 @@ class Office365MailTransport extends AbstractTransport
$symfony_message = MessageConverter::toEmail($message->getOriginalMessage()); $symfony_message = MessageConverter::toEmail($message->getOriginalMessage());
$graph = new Graph(); $graph = new Graph();
/** @phpstan-ignore-next-line **/
$token = $symfony_message->getHeaders()->get('gmailtoken')->getValue(); $token = $symfony_message->getHeaders()->get('gmailtoken')->getValue();
$symfony_message->getHeaders()->remove('gmailtoken'); $symfony_message->getHeaders()->remove('gmailtoken');
@ -38,6 +40,8 @@ class Office365MailTransport extends AbstractTransport
$bcc_list = ''; $bcc_list = '';
if ($bccs) { if ($bccs) {
/** @phpstan-ignore-next-line **/
foreach ($bccs->getAddresses() as $address) { foreach ($bccs->getAddresses() as $address) {
$bcc_list .= 'Bcc: "'.$address->getAddress().'" <'.$address->getAddress().'>\r\n'; $bcc_list .= 'Bcc: "'.$address->getAddress().'" <'.$address->getAddress().'>\r\n';
} }

View File

@ -40,7 +40,7 @@ class SubscriptionCalculator
*/ */
public function isPaidUp() :bool public function isPaidUp() :bool
{ {
$outstanding_invoices_exist = Invoice::whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) $outstanding_invoices_exist = Invoice::query()->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
->where('subscription_id', $this->invoice->subscription_id) ->where('subscription_id', $this->invoice->subscription_id)
->where('client_id', $this->invoice->client_id) ->where('client_id', $this->invoice->client_id)
->where('balance', '>', 0) ->where('balance', '>', 0)

View File

@ -530,10 +530,9 @@ class BaseController extends Controller
$paginator = $query->paginate($limit); $paginator = $query->paginate($limit);
/** @phpstan-ignore-next-line */ /** @phpstan-ignore-next-line **/
$query = $paginator->getCollection(); /** @phpstan-ignore-line */ $query = $paginator->getCollection();
$resource = new Collection($query, $transformer, $this->entity_type); $resource = new Collection($query, $transformer, $this->entity_type);
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
@ -636,7 +635,7 @@ class BaseController extends Controller
$paginator = $query->paginate($limit); $paginator = $query->paginate($limit);
/** @phpstan-ignore-next-line */ /** @phpstan-ignore-next-line **/
$query = $paginator->getCollection(); $query = $paginator->getCollection();
$resource = new Collection($query, $transformer, $this->entity_type); $resource = new Collection($query, $transformer, $this->entity_type);
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
@ -885,7 +884,7 @@ class BaseController extends Controller
$paginator = $query->paginate($limit); $paginator = $query->paginate($limit);
/** @phpstan-ignore-next-line */ /** @phpstan-ignore-next-line **/
$query = $paginator->getCollection(); $query = $paginator->getCollection();
$resource = new Collection($query, $transformer, $this->entity_type); $resource = new Collection($query, $transformer, $this->entity_type);

View File

@ -26,7 +26,8 @@ class ApplePayDomainController extends Controller
/* Self Host */ /* Self Host */
if (Ninja::isSelfHost()) { if (Ninja::isSelfHost()) {
$cgs = CompanyGateway::whereIn('gateway_key', $this->stripe_keys) $cgs = CompanyGateway::query()
->whereIn('gateway_key', $this->stripe_keys)
->where('is_deleted', false) ->where('is_deleted', false)
->get(); ->get();

View File

@ -71,7 +71,7 @@ class DocumentController extends Controller
public function downloadMultiple(DownloadMultipleDocumentsRequest $request) public function downloadMultiple(DownloadMultipleDocumentsRequest $request)
{ {
/** @var \Illuminate\Database\Eloquent\Collection<Document> $documents **/ /** @var \Illuminate\Database\Eloquent\Collection<Document> $documents **/
$documents = Document::whereIn('id', $this->transformKeys($request->file_hash)) $documents = Document::query()->whereIn('id', $this->transformKeys($request->file_hash))
->where('company_id', auth()->guard('contact')->user()->company_id) ->where('company_id', auth()->guard('contact')->user()->company_id)
->get(); ->get();

View File

@ -87,7 +87,8 @@ class InvoiceController extends Controller
public function showBlob($hash) public function showBlob($hash)
{ {
$data = Cache::get($hash); $data = Cache::get($hash);
$invitation = false;
match($data['entity_type']){ match($data['entity_type']){
'invoice' => $invitation = InvoiceInvitation::withTrashed()->find($data['invitation_id']), 'invoice' => $invitation = InvoiceInvitation::withTrashed()->find($data['invitation_id']),
'quote' => $invitation = QuoteInvitation::withTrashed()->find($data['invitation_id']), 'quote' => $invitation = QuoteInvitation::withTrashed()->find($data['invitation_id']),
@ -95,6 +96,10 @@ class InvoiceController extends Controller
'recurring_invoice' => $invitation = RecurringInvoiceInvitation::withTrashed()->find($data['invitation_id']), 'recurring_invoice' => $invitation = RecurringInvoiceInvitation::withTrashed()->find($data['invitation_id']),
}; };
if (! $invitation) {
return redirect('/');
}
$file = (new \App\Jobs\Entity\CreateRawPdf($invitation, $invitation->company->db))->handle(); $file = (new \App\Jobs\Entity\CreateRawPdf($invitation, $invitation->company->db))->handle();
$headers = ['Content-Type' => 'application/pdf']; $headers = ['Content-Type' => 'application/pdf'];
@ -128,7 +133,8 @@ class InvoiceController extends Controller
public function downloadInvoices($ids) public function downloadInvoices($ids)
{ {
$data['invoices'] = Invoice::whereIn('id', $ids) $data['invoices'] = Invoice::query()
->whereIn('id', $ids)
->whereClientId(auth()->guard('contact')->user()->client->id) ->whereClientId(auth()->guard('contact')->user()->client->id)
->withTrashed() ->withTrashed()
->get(); ->get();
@ -153,7 +159,8 @@ class InvoiceController extends Controller
*/ */
private function makePayment(array $ids) private function makePayment(array $ids)
{ {
$invoices = Invoice::whereIn('id', $ids) $invoices = Invoice::query()
->whereIn('id', $ids)
->whereClientId(auth()->guard('contact')->user()->client->id) ->whereClientId(auth()->guard('contact')->user()->client->id)
->withTrashed() ->withTrashed()
->get(); ->get();
@ -215,7 +222,8 @@ class InvoiceController extends Controller
*/ */
private function downloadInvoicePDF(array $ids) private function downloadInvoicePDF(array $ids)
{ {
$invoices = Invoice::whereIn('id', $ids) $invoices = Invoice::query()
->whereIn('id', $ids)
->withTrashed() ->withTrashed()
->whereClientId(auth()->guard('contact')->user()->client->id) ->whereClientId(auth()->guard('contact')->user()->client->id)
->get(); ->get();

View File

@ -40,13 +40,13 @@ class NinjaPlanController extends Controller
public function index(string $contact_key, string $account_or_company_key) public function index(string $contact_key, string $account_or_company_key)
{ {
MultiDB::findAndSetDbByCompanyKey($account_or_company_key); MultiDB::findAndSetDbByCompanyKey($account_or_company_key);
$company = Company::where('company_key', $account_or_company_key)->first(); $company = Company::query()->where('company_key', $account_or_company_key)->first();
if (! $company) { if (! $company) {
MultiDB::findAndSetDbByAccountKey($account_or_company_key); MultiDB::findAndSetDbByAccountKey($account_or_company_key);
/** @var \App\Models\Account $account **/ /** @var \App\Models\Account $account **/
$account = Account::where('key', $account_or_company_key)->first(); $account = Account::query()->where('key', $account_or_company_key)->first();
} else { } else {
$account = $company->account; $account = $company->account;
} }
@ -157,6 +157,8 @@ class NinjaPlanController extends Controller
//create recurring invoice //create recurring invoice
$subscription_repo = new SubscriptionRepository(); $subscription_repo = new SubscriptionRepository();
/** @var \App\Models\Subscription $subscription **/
$subscription = Subscription::find(6); $subscription = Subscription::find(6);
$recurring_invoice = RecurringInvoiceFactory::create($subscription->company_id, $subscription->user_id); $recurring_invoice = RecurringInvoiceFactory::create($subscription->company_id, $subscription->user_id);
@ -181,7 +183,7 @@ class NinjaPlanController extends Controller
->increment() ->increment()
->queue(); ->queue();
$old_recurring = RecurringInvoice::where('company_id', config('ninja.ninja_default_company_id')) $old_recurring = RecurringInvoice::query()->where('company_id', config('ninja.ninja_default_company_id'))
->where('client_id', $client->id) ->where('client_id', $client->id)
->where('id', '!=', $recurring_invoice->id) ->where('id', '!=', $recurring_invoice->id)
->first(); ->first();
@ -215,7 +217,7 @@ class NinjaPlanController extends Controller
$data['late_invoice'] = false; $data['late_invoice'] = false;
if (MultiDB::findAndSetDbByAccountKey(Auth::guard('contact')->user()->client->custom_value2)) { if (MultiDB::findAndSetDbByAccountKey(Auth::guard('contact')->user()->client->custom_value2)) {
$account = Account::where('key', Auth::guard('contact')->user()->client->custom_value2)->first(); $account = Account::query()->where('key', Auth::guard('contact')->user()->client->custom_value2)->first();
if ($account) { if ($account) {
//offer the option to have a free trial //offer the option to have a free trial

View File

@ -169,7 +169,7 @@ class PaymentController extends Controller
$payment = $payment->service()->applyCredits($payment_hash)->save(); $payment = $payment->service()->applyCredits($payment_hash)->save();
/** @var \Illuminate\Database\Eloquent\Collection<\App\Models\Invoice> $invoices */ /** @var \Illuminate\Database\Eloquent\Collection<\App\Models\Invoice> $invoices */
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id'))); $invoices = Invoice::query()->whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')));
$invoices->each(function ($invoice) { $invoices->each(function ($invoice) {
/** @var \App\Models\Invoice $invoice **/ /** @var \App\Models\Invoice $invoice **/

View File

@ -95,8 +95,9 @@ class QuoteController extends Controller
/** @var \App\Models\ClientContact $client_contact **/ /** @var \App\Models\ClientContact $client_contact **/
$client_contact = auth()->user(); $client_contact = auth()->user();
$data['quotes'] = Quote::whereIn('id', $ids) $data['quotes'] = Quote::query()
->whereClientId($client_contact->client->id) ->whereIn('id', $ids)
->where('client_id', $client_contact->client_id)
->withTrashed() ->withTrashed()
->get(); ->get();
@ -120,7 +121,8 @@ class QuoteController extends Controller
/** @var \App\Models\ClientContact $client_contact **/ /** @var \App\Models\ClientContact $client_contact **/
$client_contact = auth()->user(); $client_contact = auth()->user();
$quotes = Quote::whereIn('id', $ids) $quotes = Quote::query()
->whereIn('id', $ids)
->whereClientId($client_contact->client_id) ->whereClientId($client_contact->client_id)
->withTrashed() ->withTrashed()
->get(); ->get();
@ -168,7 +170,8 @@ class QuoteController extends Controller
protected function approve(array $ids, $process = false) protected function approve(array $ids, $process = false)
{ {
$quotes = Quote::whereIn('id', $ids) $quotes = Quote::query()
->whereIn('id', $ids)
->where('client_id', auth()->guard('contact')->user()->client->id) ->where('client_id', auth()->guard('contact')->user()->client->id)
->where('company_id', auth()->guard('contact')->user()->client->company_id) ->where('company_id', auth()->guard('contact')->user()->client->company_id)
->whereIn('status_id', [Quote::STATUS_DRAFT, Quote::STATUS_SENT]) ->whereIn('status_id', [Quote::STATUS_DRAFT, Quote::STATUS_SENT])
@ -195,10 +198,10 @@ class QuoteController extends Controller
} }
} }
if (count($ids) == 1) { if ($quotes->count() == 1) {
//forward client to the invoice if it exists //forward client to the invoice if it exists
if ($quote->invoice()->exists()) { if ($quotes->first()->invoice()->exists()) {
return redirect()->route('client.invoice.show', $quote->invoice->hashed_id); return redirect()->route('client.invoice.show', $quotes->first()->invoice->hashed_id);
} }
return redirect()->route('client.quote.show', $quotes->first()->hashed_id); return redirect()->route('client.quote.show', $quotes->first()->hashed_id);

View File

@ -148,10 +148,10 @@ class CreditController extends BaseController
*/ */
public function create(CreateCreditRequest $request) public function create(CreateCreditRequest $request)
{ {
/** @var \App\Models\User $user**/ /** @var \App\Models\User $user **/
$user = auth()->user(); $user = auth()->user();
$credit = CreditFactory::create($user->company()->id, auth()->user()->id); $credit = CreditFactory::create($user->company()->id, $user->id);
return $this->itemResponse($credit); return $this->itemResponse($credit);
} }
@ -197,11 +197,9 @@ class CreditController extends BaseController
public function store(StoreCreditRequest $request) public function store(StoreCreditRequest $request)
{ {
/** @var \App\Models\User $user**/ /** @var \App\Models\User $user **/
$user = auth()->user(); $user = auth()->user();
// $client = Client::find($request->input('client_id'));
$credit = $this->credit_repository->save($request->all(), CreditFactory::create($user->company()->id, $user->id)); $credit = $this->credit_repository->save($request->all(), CreditFactory::create($user->company()->id, $user->id));
$credit = $credit->service() $credit = $credit->service()
@ -506,7 +504,7 @@ class CreditController extends BaseController
public function bulk(BulkCreditRequest $request) public function bulk(BulkCreditRequest $request)
{ {
/** @var \App\Models\User $user**/ /** @var \App\Models\User $user **/
$user = auth()->user(); $user = auth()->user();
$action = $request->input('action'); $action = $request->input('action');
@ -725,7 +723,7 @@ class CreditController extends BaseController
* Update the specified resource in storage. * Update the specified resource in storage.
* *
* @param UploadCreditRequest $request * @param UploadCreditRequest $request
* @param Credit $client * @param Credit $credit
* @return Response * @return Response
* *
* *

View File

@ -128,7 +128,7 @@ class DocumentController extends BaseController
/** /**
* Show the form for editing the specified resource. * Show the form for editing the specified resource.
* *
* @param EditDocumentRegquest $request * @param EditDocumentRequest $request
* @param Document $document * @param Document $document
* @return Response * @return Response
*/ */

View File

@ -125,7 +125,6 @@ class EmailController extends BaseController
$this->entity_transformer = PurchaseOrderTransformer::class; $this->entity_transformer = PurchaseOrderTransformer::class;
} }
// @phpstan-ignore-next-line
return $this->itemResponse($entity_obj->fresh()); return $this->itemResponse($entity_obj->fresh());
} }

View File

@ -95,7 +95,7 @@ class PreviewPurchaseOrderController extends BaseController
return response()->json(['message' => ctrans('texts.invalid_design_object')], 400); return response()->json(['message' => ctrans('texts.invalid_design_object')], 400);
} }
$entity_obj = PurchaseOrder::whereId($this->decodePrimaryKey(request()->input('entity_id')))->company()->first(); $entity_obj = PurchaseOrder::query()->whereId($this->decodePrimaryKey(request()->input('entity_id')))->company()->first();
if (! $entity_obj) { if (! $entity_obj) {
return $this->blankEntity(); return $this->blankEntity();
@ -181,6 +181,7 @@ class PreviewPurchaseOrderController extends BaseController
DB::connection(config('database.default'))->beginTransaction(); DB::connection(config('database.default'))->beginTransaction();
if ($request->has('entity_id')) { if ($request->has('entity_id')) {
/** @var \App\Models\PurchaseOrder|\Illuminate\Database\Eloquent\Builder $entity_obj **/
$entity_obj = $class::on(config('database.default')) $entity_obj = $class::on(config('database.default'))
->with('vendor.company') ->with('vendor.company')
->where('id', $this->decodePrimaryKey($request->input('entity_id'))) ->where('id', $this->decodePrimaryKey($request->input('entity_id')))

View File

@ -327,8 +327,11 @@ class TaskController extends BaseController
* ) * )
*/ */
public function create(CreateTaskRequest $request) public function create(CreateTaskRequest $request)
{ {
$task = TaskFactory::create(auth()->user()->company()->id, auth()->user()->id); /** @var \App\Models\User $user */
$user = auth()->user();
$task = TaskFactory::create($user->company()->id, $user->id);
return $this->itemResponse($task); return $this->itemResponse($task);
} }
@ -373,10 +376,13 @@ class TaskController extends BaseController
*/ */
public function store(StoreTaskRequest $request) public function store(StoreTaskRequest $request)
{ {
$task = $this->task_repo->save($request->all(), TaskFactory::create(auth()->user()->company()->id, auth()->user()->id)); /** @var \App\Models\User $user */
$user = auth()->user();
$task = $this->task_repo->save($request->all(), TaskFactory::create($user->company()->id, $user->id));
$task = $this->task_repo->triggeredActions($request, $task); $task = $this->task_repo->triggeredActions($request, $task);
event(new TaskWasCreated($task, $task->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); event(new TaskWasCreated($task, $task->company, Ninja::eventVars($user->id)));
event('eloquent.created: App\Models\Task', $task); event('eloquent.created: App\Models\Task', $task);
@ -499,7 +505,9 @@ class TaskController extends BaseController
$tasks = Task::withTrashed()->find($this->transformKeys($ids)); $tasks = Task::withTrashed()->find($this->transformKeys($ids));
$tasks->each(function ($task, $key) use ($action) { $tasks->each(function ($task, $key) use ($action) {
if (auth()->user()->can('edit', $task)) { /** @var \App\Models\User $user */
$user = auth()->user();
if ($user->can('edit', $task)) {
$this->task_repo->{$action}($task); $this->task_repo->{$action}($task);
} }
}); });
@ -621,10 +629,13 @@ class TaskController extends BaseController
{ {
$task_statuses = $request->input('status_ids'); $task_statuses = $request->input('status_ids');
$tasks = $request->input('task_ids'); $tasks = $request->input('task_ids');
/** @var \App\Models\User $user */
$user = auth()->user();
collect($task_statuses)->each(function ($task_status_hashed_id, $key) { collect($task_statuses)->each(function ($task_status_hashed_id, $key) use($user){
$task_status = TaskStatus::where('id', $this->decodePrimaryKey($task_status_hashed_id)) $task_status = TaskStatus::query()->where('id', $this->decodePrimaryKey($task_status_hashed_id))
->where('company_id', auth()->user()->company()->id) ->where('company_id', $user->company()->id)
->withTrashed() ->withTrashed()
->first(); ->first();
@ -636,8 +647,8 @@ class TaskController extends BaseController
$sort_status_id = $this->decodePrimaryKey($key); $sort_status_id = $this->decodePrimaryKey($key);
foreach ($task_list as $key => $task) { foreach ($task_list as $key => $task) {
$task_record = Task::where('id', $this->decodePrimaryKey($task)) $task_record = Task::query()->where('id', $this->decodePrimaryKey($task))
->where('company_id', auth()->user()->company()->id) ->where('company_id', $user->company()->id)
->withTrashed() ->withTrashed()
->first(); ->first();

View File

@ -96,7 +96,7 @@ class DocumentController extends Controller
public function downloadMultiple(DownloadMultipleDocumentsRequest $request) public function downloadMultiple(DownloadMultipleDocumentsRequest $request)
{ {
/** @var \Illuminate\Database\Eloquent\Collection<Document> $documents */ /** @var \Illuminate\Database\Eloquent\Collection<Document> $documents */
$documents = Document::whereIn('id', $this->transformKeys($request->file_hash)) $documents = Document::query()->whereIn('id', $this->transformKeys($request->file_hash))
->where('company_id', auth()->guard('vendor')->user()->company_id) ->where('company_id', auth()->guard('vendor')->user()->company_id)
->get(); ->get();

View File

@ -203,7 +203,8 @@ class PurchaseOrderController extends Controller
public function downloadInvoices($ids) public function downloadInvoices($ids)
{ {
$purchase_orders = PurchaseOrder::whereIn('id', $ids) $purchase_orders = PurchaseOrder::query()
->whereIn('id', $ids)
->where('vendor_id', auth()->guard('vendor')->user()->vendor_id) ->where('vendor_id', auth()->guard('vendor')->user()->vendor_id)
->withTrashed() ->withTrashed()
->get(); ->get();

View File

@ -19,13 +19,17 @@ class VendorContactHashLoginController extends Controller
/** /**
* Logs a user into the client portal using their contact_key * Logs a user into the client portal using their contact_key
* @param string $contact_key The contact key * @param string $contact_key The contact key
* @return Auth|Redirect * @return Auth|\Illuminate\Support\Facades\Redirect
*/ */
public function login(string $contact_key) public function login(string $contact_key)
{ {
return redirect('/vendors/purchase_orders'); return redirect('/vendors/purchase_orders');
} }
/**
* @return \Illuminate\Support\Facades\Redirect
*/
public function magicLink(string $magic_link) public function magicLink(string $magic_link)
{ {
return redirect($this->setRedirectPath()); return redirect($this->setRedirectPath());

View File

@ -298,7 +298,10 @@ class WebhookController extends BaseController
*/ */
public function create(CreateWebhookRequest $request) public function create(CreateWebhookRequest $request)
{ {
$webhook = WebhookFactory::create(auth()->user()->company()->id, auth()->user()->id); /** @var \App\Models\User $user */
$user = auth()->user();
$webhook = WebhookFactory::create($user->company()->id, $user->id);
$webhook->fill($request->all()); $webhook->fill($request->all());
$webhook->save(); $webhook->save();
@ -483,7 +486,10 @@ class WebhookController extends BaseController
$webhooks = Webhook::withTrashed()->find($this->transformKeys($ids)); $webhooks = Webhook::withTrashed()->find($this->transformKeys($ids));
$webhooks->each(function ($webhook, $key) use ($action) { $webhooks->each(function ($webhook, $key) use ($action) {
if (auth()->user()->can('edit', $webhook)) { /** @var \App\Models\User $user */
$user = auth()->user();
if ($user->can('edit', $webhook)) {
$this->base_repo->{$action}($webhook); $this->base_repo->{$action}($webhook);
} }
}); });
@ -493,6 +499,8 @@ class WebhookController extends BaseController
public function retry(RetryWebhookRequest $request, Webhook $webhook) public function retry(RetryWebhookRequest $request, Webhook $webhook)
{ {
$includes = '';
match ($request->entity) { match ($request->entity) {
'invoice' => $includes ='client', 'invoice' => $includes ='client',
'payment' => $includes ='invoices,client', 'payment' => $includes ='invoices,client',
@ -504,13 +512,16 @@ class WebhookController extends BaseController
$class = 'App\Models\\'.ucfirst(Str::camel($request->entity)); $class = 'App\Models\\'.ucfirst(Str::camel($request->entity));
$entity = $class::withTrashed()->where('id', $this->decodePrimaryKey($request->entity_id))->company()->first(); $entity = $class::query()->withTrashed()->where('id', $this->decodePrimaryKey($request->entity_id))->company()->first();
if (!$entity) { if (!$entity) {
return response()->json(['message' => ctrans('texts.record_not_found')], 400); return response()->json(['message' => ctrans('texts.record_not_found')], 400);
} }
/** @var \App\Models\User $user */
$user = auth()->user();
WebhookSingle::dispatchSync($webhook->id, $entity, auth()->user()->company()->db, $includes); WebhookSingle::dispatchSync($webhook->id, $entity, $user->company()->db, $includes);
return $this->itemResponse($webhook); return $this->itemResponse($webhook);
} }

View File

@ -64,9 +64,9 @@ class BillingPortalPurchase extends Component
/** /**
* Instance of subscription. * Instance of subscription.
* *
* @var Subscription * @var \App\Models\Subscription $subscription
*/ */
public $subscription; public Subscription $subscription;
/** /**
* Instance of client contact. * Instance of client contact.
@ -78,7 +78,6 @@ class BillingPortalPurchase extends Component
/** /**
* Rules for validating the form. * Rules for validating the form.
* *
* @var \string[][]
*/ */
protected $rules = [ protected $rules = [
'email' => ['required', 'email'], 'email' => ['required', 'email'],
@ -156,7 +155,7 @@ class BillingPortalPurchase extends Component
public $request_data; public $request_data;
/** /**
* @var string * @var float
*/ */
public $price; public $price;
@ -187,7 +186,7 @@ class BillingPortalPurchase extends Component
{ {
MultiDB::setDb($this->db); MultiDB::setDb($this->db);
$this->subscription = Subscription::with('company')->find($this->subscription); $this->subscription = Subscription::query()->with('company')->find($this->subscription);
$this->company = $this->subscription->company; $this->company = $this->subscription->company;

View File

@ -53,7 +53,7 @@ class BillingPortalPurchasev2 extends Component
/** /**
* Instance of subscription. * Instance of subscription.
* *
* @var Subscription * @var \App\Models\Subscription
*/ */
public $subscription; public $subscription;
@ -122,7 +122,7 @@ class BillingPortalPurchasev2 extends Component
/** /**
* Instance of company. * Instance of company.
* *
* @var Company * @var \App\Models\Company
*/ */
public $company; public $company;
@ -165,7 +165,7 @@ class BillingPortalPurchasev2 extends Component
{ {
MultiDB::setDb($this->db); MultiDB::setDb($this->db);
$this->subscription = Subscription::with('company')->find($this->subscription); $this->subscription = Subscription::query()->with('company')->find($this->subscription);
$this->company = $this->subscription->company; $this->company = $this->subscription->company;
@ -424,7 +424,7 @@ class BillingPortalPurchasev2 extends Component
$client_repo = new ClientRepository(new ClientContactRepository()); $client_repo = new ClientRepository(new ClientContactRepository());
$data = [ $data = [
'name' => '', 'name' => '',
'group_id' => $this->encodePrimaryKey($this->subscription->group_id), 'group_settings_id' => $this->subscription->group_id,
'contacts' => [ 'contacts' => [
['email' => $this->email], ['email' => $this->email],
], ],
@ -498,7 +498,7 @@ class BillingPortalPurchasev2 extends Component
/** /**
* Method to handle events before payments. * Method to handle events before payments.
* *
* @return void * @return self
*/ */
public function handleBeforePaymentEvents() :self public function handleBeforePaymentEvents() :self
{ {

View File

@ -89,9 +89,12 @@ class InvoicesTable extends Component
->withTrashed() ->withTrashed()
->paginate($this->per_page); ->paginate($this->per_page);
/** @var \App\Models\ClientContact $client_contact */
$client_contact = auth()->user();
return render('components.livewire.invoices-table', [ return render('components.livewire.invoices-table', [
'invoices' => $query, 'invoices' => $query,
'gateway_available' => ! empty(auth()->user()->client->service()->getPaymentMethods(-1)), 'gateway_available' => ! empty($client_contact->client->service()->getPaymentMethods(-1)),
]); ]);
} }
} }

View File

@ -32,7 +32,7 @@ class UpdateDefaultMethod extends Component
MultiDB::setDb($this->company->db); MultiDB::setDb($this->company->db);
$this->is_disabled = $this->token->is_default; // $this->is_disabled = $this->token->is_default;
} }
public function makeDefault(): void public function makeDefault(): void

View File

@ -52,7 +52,7 @@ class RequiredClientInfo extends Component
public $contact; public $contact;
/** /**
* @var Client * @var \App\Models\Client
*/ */
public $client; public $client;
@ -227,6 +227,7 @@ class RequiredClientInfo extends Component
->push(); ->push();
if ($contact_update && $client_update) { if ($contact_update && $client_update) {
/** @var \App\Models\CompanyGateway $cg */
$cg = CompanyGateway::find($this->company_gateway_id); $cg = CompanyGateway::find($this->company_gateway_id);
if ($cg && $cg->update_details) { if ($cg && $cg->update_details) {

View File

@ -53,7 +53,7 @@ class WepaySignup extends Component
public $saved; public $saved;
public $company; public Company $company;
protected $rules = [ protected $rules = [
'first_name' => ['required'], 'first_name' => ['required'],
@ -71,7 +71,7 @@ class WepaySignup extends Component
MultiDB::setDb($this->company->db); MultiDB::setDb($this->company->db);
$user = User::find($this->user_id); $user = User::find($this->user_id);
$this->company = Company::where('company_key', $this->company->company_key)->first(); $this->company = Company::query()->where('company_key', $this->company->company_key)->first();
$this->fill([ $this->fill([
'wepay_payment_tos_agree' => '', 'wepay_payment_tos_agree' => '',
@ -100,7 +100,7 @@ class WepaySignup extends Component
$data = $this->validate($this->rules); $data = $this->validate($this->rules);
//need to create or get a new WePay CompanyGateway //need to create or get a new WePay CompanyGateway
$cg = CompanyGateway::where('gateway_key', '8fdeed552015b3c7b44ed6c8ebd9e992') $cg = CompanyGateway::query()->where('gateway_key', '8fdeed552015b3c7b44ed6c8ebd9e992')
->where('company_id', $this->company->id) ->where('company_id', $this->company->id)
->firstOrNew(); ->firstOrNew();
@ -165,6 +165,7 @@ class WepaySignup extends Component
} }
$wepay_account = $wepay->request('account/create/', $account_details); $wepay_account = $wepay->request('account/create/', $account_details);
$confirmation_required = false;
try { try {
$wepay->request('user/send_confirmation/', []); $wepay->request('user/send_confirmation/', []);
@ -173,6 +174,8 @@ class WepaySignup extends Component
if ($ex->getMessage() == 'This access_token is already approved.') { if ($ex->getMessage() == 'This access_token is already approved.') {
$confirmation_required = false; $confirmation_required = false;
} else { } else {
/** @phpstan-ignore-next-line */
request()->session()->flash('message', $ex->getMessage()); request()->session()->flash('message', $ex->getMessage());
} }
@ -195,6 +198,8 @@ class WepaySignup extends Component
$cg->save(); $cg->save();
if ($confirmation_required) { if ($confirmation_required) {
/** @phpstan-ignore-next-line **/
request()->session()->flash('message', trans('texts.created_wepay_confirmation_required')); request()->session()->flash('message', trans('texts.created_wepay_confirmation_required'));
} else { } else {
$update_uri = $wepay->request('/account/get_update_uri', [ $update_uri = $wepay->request('/account/get_update_uri', [

View File

@ -25,7 +25,10 @@ class ClientPortalEnabled
*/ */
public function handle($request, Closure $next) public function handle($request, Closure $next)
{ {
if (auth()->user()->client->getSetting('enable_client_portal') === false) { /** @var \App\Models\ClientContact $client_contact */
$client_contact = auth()->user();
if ($client_contact->client->getSetting('enable_client_portal') === false) {
return redirect()->route('client.error')->with(['title' => ctrans('texts.client_portal'), 'notification' => 'This section of the app has been disabled by the administrator.']); return redirect()->route('client.error')->with(['title' => ctrans('texts.client_portal'), 'notification' => 'This section of the app has been disabled by the administrator.']);
} }

View File

@ -28,6 +28,7 @@ class ContactAccount
public function handle($request, Closure $next) public function handle($request, Closure $next)
{ {
if (! Ninja::isHosted()) { if (! Ninja::isHosted()) {
/** @var \App\Models\Account $account */
$account = Account::first(); $account = Account::first();
session()->put('account_key', $account->key); session()->put('account_key', $account->key);

View File

@ -67,7 +67,7 @@ class ContactKeyLogin
} }
} elseif ($request->segment(3) && config('ninja.db.multi_db_enabled')) { } elseif ($request->segment(3) && config('ninja.db.multi_db_enabled')) {
if (MultiDB::findAndSetDbByContactKey($request->segment(3))) { if (MultiDB::findAndSetDbByContactKey($request->segment(3))) {
if ($client_contact = ClientContact::with('company')->where('contact_key', $request->segment(3))->first()) { if ($client_contact = ClientContact::query()->with('company')->where('contact_key', $request->segment(3))->first()) {
if ($client_contact->company->settings->enable_client_portal_password) { if ($client_contact->company->settings->enable_client_portal_password) {
return redirect()->route('client.login', ['company_key' => $client_contact->company->company_key]); return redirect()->route('client.login', ['company_key' => $client_contact->company->company_key]);
} }
@ -107,7 +107,7 @@ class ContactKeyLogin
} }
} elseif ($request->has('client_hash') && config('ninja.db.multi_db_enabled')) { } elseif ($request->has('client_hash') && config('ninja.db.multi_db_enabled')) {
if (MultiDB::findAndSetDbByClientHash($request->input('client_hash'))) { if (MultiDB::findAndSetDbByClientHash($request->input('client_hash'))) {
if ($client = Client::where('client_hash', $request->input('client_hash'))->first()) { if ($client = Client::query()->where('client_hash', $request->input('client_hash'))->first()) {
$primary_contact = $client->primary_contact()->first(); $primary_contact = $client->primary_contact()->first();
if (empty($primary_contact->email)) { if (empty($primary_contact->email)) {
@ -121,7 +121,7 @@ class ContactKeyLogin
} }
} }
} elseif ($request->has('client_hash')) { } elseif ($request->has('client_hash')) {
if ($client = Client::where('client_hash', $request->input('client_hash'))->first()) { if ($client = Client::query()->where('client_hash', $request->input('client_hash'))->first()) {
$primary_contact = $client->primary_contact()->first(); $primary_contact = $client->primary_contact()->first();
if (empty($primary_contact->email)) { if (empty($primary_contact->email)) {
@ -134,7 +134,7 @@ class ContactKeyLogin
return redirect($this->setRedirectPath()); return redirect($this->setRedirectPath());
} }
} elseif ($request->segment(3)) { } elseif ($request->segment(3)) {
if ($client_contact = ClientContact::with('company')->where('contact_key', $request->segment(3))->first()) { if ($client_contact = ClientContact::query()->with('company')->where('contact_key', $request->segment(3))->first()) {
if ($client_contact->company->settings->enable_client_portal_password) { if ($client_contact->company->settings->enable_client_portal_password) {
return redirect()->route('client.login', ['company_key' => $client_contact->company->company_key]); return redirect()->route('client.login', ['company_key' => $client_contact->company->company_key]);
} }

View File

@ -30,7 +30,7 @@ class ContactRegister
'portal_mode' => 'subdomain', 'portal_mode' => 'subdomain',
]; ];
$company = Company::where($query)->first(); $company = Company::query()->where($query)->first();
if ($company) { if ($company) {
if (! $company->client_can_register) { if (! $company->client_can_register) {
@ -50,7 +50,7 @@ class ContactRegister
'portal_mode' => 'domain', 'portal_mode' => 'domain',
]; ];
if ($company = Company::where($query)->first()) { if ($company = Company::query()->where($query)->first()) {
if (! $company->client_can_register) { if (! $company->client_can_register) {
abort(400, 'Registration disabled'); abort(400, 'Registration disabled');
} }
@ -65,7 +65,7 @@ class ContactRegister
// For self-hosted platforms with multiple companies, resolving is done using company key // For self-hosted platforms with multiple companies, resolving is done using company key
// if it doesn't resolve using a domain. // if it doesn't resolve using a domain.
if ($request->company_key && Ninja::isSelfHost() && $company = Company::where('company_key', $request->company_key)->first()) { if ($request->company_key && Ninja::isSelfHost() && $company = Company::query()->where('company_key', $request->company_key)->first()) {
if (! (bool) $company->client_can_register) { if (! (bool) $company->client_can_register) {
abort(400, 'Registration disabled'); abort(400, 'Registration disabled');
} }
@ -79,7 +79,7 @@ class ContactRegister
// As a fallback for self-hosted, it will use default company in the system // As a fallback for self-hosted, it will use default company in the system
// if key isn't provided in the url. // if key isn't provided in the url.
if (! $request->route()->parameter('company_key') && Ninja::isSelfHost()) { if (! $request->route()->parameter('company_key') && Ninja::isSelfHost()) {
$company = Account::first()->default_company; $company = Account::query()->first()->default_company;
if (! $company->client_can_register) { if (! $company->client_can_register) {
abort(400, 'Registration disabled'); abort(400, 'Registration disabled');

View File

@ -37,8 +37,9 @@ class PasswordProtection
'errors' => new stdClass, 'errors' => new stdClass,
]; ];
/** @var \App\Models\User auth()->user() */ /** @var \App\Models\User auth()->user() */
$timeout = auth()->user()->company()->default_password_timeout; $user = auth()->user();
$timeout = $user->company()->default_password_timeout;
if ($timeout == 0) { if ($timeout == 0) {
$timeout = 30*60*1000*1000; $timeout = 30*60*1000*1000;

View File

@ -49,7 +49,7 @@ class VendorContactKeyLogin
$contact_email = $payload['email']; $contact_email = $payload['email'];
if ($vendor_contact = VendorContact::where('email', $contact_email)->where('company_id', $payload['company_id'])->first()) { if ($vendor_contact = VendorContact::query()->where('email', $contact_email)->where('company_id', $payload['company_id'])->first()) {
if (empty($vendor_contact->email)) { if (empty($vendor_contact->email)) {
$vendor_contact->email = Str::random(15).'@example.com'; $vendor_contact->email = Str::random(15).'@example.com';
} }
@ -65,7 +65,7 @@ class VendorContactKeyLogin
} }
} elseif ($request->segment(3) && config('ninja.db.multi_db_enabled')) { } elseif ($request->segment(3) && config('ninja.db.multi_db_enabled')) {
if (MultiDB::findAndSetDbByVendorContactKey($request->segment(3))) { if (MultiDB::findAndSetDbByVendorContactKey($request->segment(3))) {
if ($vendor_contact = VendorContact::where('contact_key', $request->segment(3))->first()) { if ($vendor_contact = VendorContact::query()->where('contact_key', $request->segment(3))->first()) {
if (empty($vendor_contact->email)) { if (empty($vendor_contact->email)) {
$vendor_contact->email = Str::random(6).'@example.com'; $vendor_contact->email = Str::random(6).'@example.com';
} }
@ -81,7 +81,7 @@ class VendorContactKeyLogin
} }
} }
} elseif ($request->segment(2) && $request->segment(2) == 'key_login' && $request->segment(3)) { } elseif ($request->segment(2) && $request->segment(2) == 'key_login' && $request->segment(3)) {
if ($vendor_contact = VendorContact::where('contact_key', $request->segment(3))->first()) { if ($vendor_contact = VendorContact::query()->where('contact_key', $request->segment(3))->first()) {
if (empty($vendor_contact->email)) { if (empty($vendor_contact->email)) {
$vendor_contact->email = Str::random(6).'@example.com'; $vendor_contact->email = Str::random(6).'@example.com';
$vendor_contact->save(); $vendor_contact->save();
@ -97,7 +97,7 @@ class VendorContactKeyLogin
} }
} elseif ($request->has('vendor_hash') && config('ninja.db.multi_db_enabled')) { } elseif ($request->has('vendor_hash') && config('ninja.db.multi_db_enabled')) {
if (MultiDB::findAndSetDbByClientHash($request->input('vendor_hash'))) { if (MultiDB::findAndSetDbByClientHash($request->input('vendor_hash'))) {
if ($client = Vendor::where('vendor_hash', $request->input('vendor_hash'))->first()) { if ($client = Vendor::query()->where('vendor_hash', $request->input('vendor_hash'))->first()) {
$primary_contact = $client->primary_contact()->first(); $primary_contact = $client->primary_contact()->first();
if (empty($primary_contact->email)) { if (empty($primary_contact->email)) {
@ -111,7 +111,7 @@ class VendorContactKeyLogin
} }
} }
} elseif ($request->has('vendor_hash')) { } elseif ($request->has('vendor_hash')) {
if ($client = Vendor::where('vendor_hash', $request->input('vendor_hash'))->first()) { if ($client = Vendor::query()->where('vendor_hash', $request->input('vendor_hash'))->first()) {
$primary_contact = $client->primary_contact()->first(); $primary_contact = $client->primary_contact()->first();
if (empty($primary_contact->email)) { if (empty($primary_contact->email)) {
@ -124,7 +124,7 @@ class VendorContactKeyLogin
return redirect($this->setRedirectPath()); return redirect($this->setRedirectPath());
} }
} elseif ($request->segment(3)) { } elseif ($request->segment(3)) {
if ($vendor_contact = VendorContact::where('contact_key', $request->segment(3))->first()) { if ($vendor_contact = VendorContact::query()->where('contact_key', $request->segment(3))->first()) {
if (empty($vendor_contact->email)) { if (empty($vendor_contact->email)) {
$vendor_contact->email = Str::random(6).'@example.com'; $vendor_contact->email = Str::random(6).'@example.com';
$vendor_contact->save(); $vendor_contact->save();

View File

@ -18,7 +18,7 @@ class VerifyHash
public function handle($request, Closure $next) public function handle($request, Closure $next)
{ {
if ($request->has('payment_hash')) { if ($request->has('payment_hash')) {
$ph = PaymentHash::with('fee_invoice')->where('hash', $request->payment_hash)->first(); $ph = PaymentHash::query()->with('fee_invoice')->where('hash', $request->payment_hash)->first();
if ($ph) { if ($ph) {
auth()->guard('contact')->loginUsingId($ph->fee_invoice->invitations->first()->contact->id, true); auth()->guard('contact')->loginUsingId($ph->fee_invoice->invitations->first()->contact->id, true);

View File

@ -28,7 +28,7 @@ class ShowChartRequest extends Request
/**@var \App\Models\User auth()->user */ /**@var \App\Models\User auth()->user */
$user = auth()->user(); $user = auth()->user();
return $user->isAdmin(); return $user->isAdmin() || $user->hasPermission('view_dashboard');
} }
public function rules() public function rules()
@ -42,10 +42,14 @@ class ShowChartRequest extends Request
public function prepareForValidation() public function prepareForValidation()
{ {
/**@var \App\Models\User auth()->user */
$user = auth()->user();
$input = $this->all(); $input = $this->all();
if(isset($input['date_range'])) { if(isset($input['date_range'])) {
$dates = $this->calculateStartAndEndDates($input, auth()->user()->company()); $dates = $this->calculateStartAndEndDates($input, $user->company());
$input['start_date'] = $dates[0]; $input['start_date'] = $dates[0];
$input['end_date'] = $dates[1]; $input['end_date'] = $dates[1];
} }

View File

@ -66,15 +66,15 @@ class RegisterRequest extends FormRequest
{ {
//this should be all we need, the rest SHOULD be redundant because of our Middleware //this should be all we need, the rest SHOULD be redundant because of our Middleware
if ($this->key) { if ($this->key) {
return Company::where('company_key', $this->key)->first(); return Company::query()->where('company_key', $this->key)->first();
} }
if ($this->company_key) { if ($this->company_key) {
return Company::where('company_key', $this->company_key)->firstOrFail(); return Company::query()->where('company_key', $this->company_key)->firstOrFail();
} }
if (! $this->route()->parameter('company_key') && Ninja::isSelfHost()) { if (! $this->route()->parameter('company_key') && Ninja::isSelfHost()) {
$company = Account::first()->default_company; $company = Account::query()->first()->default_company;
if (! $company->client_can_register) { if (! $company->client_can_register) {
abort(403, 'This page is restricted'); abort(403, 'This page is restricted');

View File

@ -12,7 +12,6 @@
namespace App\Http\Requests\ClientPortal; namespace App\Http\Requests\ClientPortal;
use App\Http\Requests\Request; use App\Http\Requests\Request;
use Zend\Diactoros\Response\JsonResponse;
class StoreDocumentRequest extends Request class StoreDocumentRequest extends Request
{ {
@ -35,6 +34,6 @@ class StoreDocumentRequest extends Request
public function response(array $errors) public function response(array $errors)
{ {
return new JsonResponse(['error' => $errors], 400); return response()->json(['error' => $errors], 400);
} }
} }

View File

@ -22,6 +22,9 @@ class ShowCompanyRequest extends Request
*/ */
public function authorize() : bool public function authorize() : bool
{ {
return auth()->user()->can('view', $this->company); /** @var \App\Models\User $user */
$user = auth()->user();
return $user->company()->id == $this->company->id;
} }
} }

View File

@ -30,7 +30,9 @@ class StoreCompanyRequest extends Request
*/ */
public function authorize() : bool public function authorize() : bool
{ {
return auth()->user()->can('create', Company::class); /** @var \App\Models\User auth()->user */
$user = auth()->user();
return $user->can('create', Company::class);
} }
public function rules() public function rules()
@ -47,7 +49,7 @@ class StoreCompanyRequest extends Request
$rules['portal_domain'] = 'sometimes|url'; $rules['portal_domain'] = 'sometimes|url';
} else { } else {
if (Ninja::isHosted()) { if (Ninja::isHosted()) {
$rules['subdomain'] = ['nullable', 'regex:/^[a-zA-Z0-9][a-zA-Z0-9.-]+[a-zA-Z0-9]$/', new ValidSubdomain($this->all())]; $rules['subdomain'] = ['nullable', 'regex:/^[a-zA-Z0-9][a-zA-Z0-9.-]+[a-zA-Z0-9]$/', new ValidSubdomain()];
} else { } else {
$rules['subdomain'] = 'nullable|alpha_num'; $rules['subdomain'] = 'nullable|alpha_num';
} }

View File

@ -31,7 +31,10 @@ class StoreCreditRequest extends Request
*/ */
public function authorize() public function authorize()
{ {
return auth()->user()->can('create', Credit::class); /** @var \App\Models\User $user */
$user = auth()->user();
return $user->can('create', Credit::class);
} }
/** /**
@ -55,10 +58,13 @@ class StoreCreditRequest extends Request
$rules['file'] = $this->file_validation; $rules['file'] = $this->file_validation;
} }
$rules['client_id'] = 'required|exists:clients,id,company_id,'.auth()->user()->company()->id; /** @var \App\Models\User $user */
$user = auth()->user();
$rules['client_id'] = 'required|exists:clients,id,company_id,'.$user->company()->id;
// $rules['number'] = new UniqueCreditNumberRule($this->all()); // $rules['number'] = new UniqueCreditNumberRule($this->all());
$rules['number'] = ['nullable', Rule::unique('credits')->where('company_id', auth()->user()->company()->id)]; $rules['number'] = ['nullable', Rule::unique('credits')->where('company_id', $user->company()->id)];
$rules['discount'] = 'sometimes|numeric'; $rules['discount'] = 'sometimes|numeric';
$rules['is_amount_discount'] = ['boolean']; $rules['is_amount_discount'] = ['boolean'];
$rules['tax_rate1'] = 'bail|sometimes|numeric'; $rules['tax_rate1'] = 'bail|sometimes|numeric';
@ -67,7 +73,7 @@ class StoreCreditRequest extends Request
$rules['tax_name1'] = 'bail|sometimes|string|nullable'; $rules['tax_name1'] = 'bail|sometimes|string|nullable';
$rules['tax_name2'] = 'bail|sometimes|string|nullable'; $rules['tax_name2'] = 'bail|sometimes|string|nullable';
$rules['tax_name3'] = 'bail|sometimes|string|nullable'; $rules['tax_name3'] = 'bail|sometimes|string|nullable';
$rules['exchange_rate'] = 'bail|sometimes|gt:0'; $rules['exchange_rate'] = 'bail|sometimes|numeric';
if ($this->invoice_id) { if ($this->invoice_id) {
$rules['invoice_id'] = new ValidInvoiceCreditRule(); $rules['invoice_id'] = new ValidInvoiceCreditRule();

View File

@ -30,7 +30,10 @@ class UpdateCreditRequest extends Request
*/ */
public function authorize() : bool public function authorize() : bool
{ {
return auth()->user()->can('edit', $this->credit); /** @var \App\Models\User $user */
$user = auth()->user();
return $user->can('edit', $this->credit);
} }
/** /**
@ -40,6 +43,9 @@ class UpdateCreditRequest extends Request
*/ */
public function rules() public function rules()
{ {
/** @var \App\Models\User $user */
$user = auth()->user();
$rules = []; $rules = [];
if ($this->file('documents') && is_array($this->file('documents'))) { if ($this->file('documents') && is_array($this->file('documents'))) {
@ -55,7 +61,7 @@ class UpdateCreditRequest extends Request
} }
if ($this->number) { if ($this->number) {
$rules['number'] = Rule::unique('credits')->where('company_id', auth()->user()->company()->id)->ignore($this->credit->id); $rules['number'] = Rule::unique('credits')->where('company_id', $user->company()->id)->ignore($this->credit->id);
} }
$rules['line_items'] = 'array'; $rules['line_items'] = 'array';
@ -67,7 +73,7 @@ class UpdateCreditRequest extends Request
$rules['tax_name1'] = 'bail|sometimes|string|nullable'; $rules['tax_name1'] = 'bail|sometimes|string|nullable';
$rules['tax_name2'] = 'bail|sometimes|string|nullable'; $rules['tax_name2'] = 'bail|sometimes|string|nullable';
$rules['tax_name3'] = 'bail|sometimes|string|nullable'; $rules['tax_name3'] = 'bail|sometimes|string|nullable';
$rules['exchange_rate'] = 'bail|sometimes|gt:0'; $rules['exchange_rate'] = 'bail|sometimes|numeric';
return $rules; return $rules;
} }

View File

@ -72,7 +72,7 @@ class StoreInvoiceRequest extends Request
$rules['tax_name1'] = 'bail|sometimes|string|nullable'; $rules['tax_name1'] = 'bail|sometimes|string|nullable';
$rules['tax_name2'] = 'bail|sometimes|string|nullable'; $rules['tax_name2'] = 'bail|sometimes|string|nullable';
$rules['tax_name3'] = 'bail|sometimes|string|nullable'; $rules['tax_name3'] = 'bail|sometimes|string|nullable';
$rules['exchange_rate'] = 'bail|sometimes|gt:0'; $rules['exchange_rate'] = 'bail|sometimes|numeric';
return $rules; return $rules;
} }

View File

@ -40,6 +40,9 @@ class UpdateInvoiceRequest extends Request
public function rules() public function rules()
{ {
/** @var \App\Models\User $user */
$user = auth()->user();
$rules = []; $rules = [];
if ($this->file('documents') && is_array($this->file('documents'))) { if ($this->file('documents') && is_array($this->file('documents'))) {
@ -57,7 +60,7 @@ class UpdateInvoiceRequest extends Request
$rules['id'] = new LockedInvoiceRule($this->invoice); $rules['id'] = new LockedInvoiceRule($this->invoice);
if ($this->number) { if ($this->number) {
$rules['number'] = Rule::unique('invoices')->where('company_id', auth()->user()->company()->id)->ignore($this->invoice->id); $rules['number'] = Rule::unique('invoices')->where('company_id', $user->company()->id)->ignore($this->invoice->id);
} }
$rules['is_amount_discount'] = ['boolean']; $rules['is_amount_discount'] = ['boolean'];
@ -72,10 +75,7 @@ class UpdateInvoiceRequest extends Request
$rules['tax_name2'] = 'bail|sometimes|string|nullable'; $rules['tax_name2'] = 'bail|sometimes|string|nullable';
$rules['tax_name3'] = 'bail|sometimes|string|nullable'; $rules['tax_name3'] = 'bail|sometimes|string|nullable';
$rules['status_id'] = 'bail|sometimes|not_in:5'; //do not allow cancelled invoices to be modfified. $rules['status_id'] = 'bail|sometimes|not_in:5'; //do not allow cancelled invoices to be modfified.
$rules['exchange_rate'] = 'bail|sometimes|gt:0'; $rules['exchange_rate'] = 'bail|sometimes|numeric';
// not needed.
// $rules['partial_due_date'] = 'bail|sometimes|required_unless:partial,0,null';
return $rules; return $rules;
} }

View File

@ -39,7 +39,6 @@ class PaymentWebhookRequest extends Request
/** /**
* Resolve company gateway. * Resolve company gateway.
* *
* @param mixed $id
* @return null|\App\Models\CompanyGateway * @return null|\App\Models\CompanyGateway
*/ */
public function getCompanyGateway() public function getCompanyGateway()
@ -52,7 +51,6 @@ class PaymentWebhookRequest extends Request
/** /**
* Resolve payment hash. * Resolve payment hash.
* *
* @param string $hash
* @return null|\App\Models\PaymentHash * @return null|\App\Models\PaymentHash
*/ */
public function getPaymentHash() public function getPaymentHash()

View File

@ -29,7 +29,10 @@ class StorePurchaseOrderRequest extends Request
*/ */
public function authorize() public function authorize()
{ {
return auth()->user()->can('create', PurchaseOrder::class); /** @var \App\Models\User $user */
$user = auth()->user();
return $user->can('create', PurchaseOrder::class);
} }
/** /**
* Get the validation rules that apply to the request. * Get the validation rules that apply to the request.
@ -38,11 +41,14 @@ class StorePurchaseOrderRequest extends Request
*/ */
public function rules() public function rules()
{ {
/** @var \App\Models\User $user */
$user = auth()->user();
$rules = []; $rules = [];
$rules['vendor_id'] = 'bail|required|exists:vendors,id,company_id,'.auth()->user()->company()->id.',is_deleted,0'; $rules['vendor_id'] = 'bail|required|exists:vendors,id,company_id,'.$user->company()->id.',is_deleted,0';
$rules['number'] = ['nullable', Rule::unique('purchase_orders')->where('company_id', auth()->user()->company()->id)]; $rules['number'] = ['nullable', Rule::unique('purchase_orders')->where('company_id', $user->company()->id)];
$rules['discount'] = 'sometimes|numeric'; $rules['discount'] = 'sometimes|numeric';
$rules['is_amount_discount'] = ['boolean']; $rules['is_amount_discount'] = ['boolean'];
$rules['line_items'] = 'array'; $rules['line_items'] = 'array';
@ -60,7 +66,7 @@ class StorePurchaseOrderRequest extends Request
} }
$rules['status_id'] = 'nullable|integer|in:1,2,3,4,5'; $rules['status_id'] = 'nullable|integer|in:1,2,3,4,5';
$rules['exchange_rate'] = 'bail|sometimes|gt:0'; $rules['exchange_rate'] = 'bail|sometimes|numeric';
return $rules; return $rules;
} }

View File

@ -63,7 +63,7 @@ class UpdatePurchaseOrderRequest extends Request
} }
$rules['status_id'] = 'sometimes|integer|in:1,2,3,4,5'; $rules['status_id'] = 'sometimes|integer|in:1,2,3,4,5';
$rules['exchange_rate'] = 'bail|sometimes|gt:0'; $rules['exchange_rate'] = 'bail|sometimes|numeric';
return $rules; return $rules;
} }

View File

@ -30,14 +30,20 @@ class StoreQuoteRequest extends Request
*/ */
public function authorize() : bool public function authorize() : bool
{ {
return auth()->user()->can('create', Quote::class); /** @var \App\Models\User $user */
$user = auth()->user();
return $user->can('create', Quote::class);
} }
public function rules() public function rules()
{ {
/** @var \App\Models\User $user */
$user = auth()->user();
$rules = []; $rules = [];
$rules['client_id'] = 'required|exists:clients,id,company_id,'.auth()->user()->company()->id; $rules['client_id'] = 'required|exists:clients,id,company_id,'.$user->company()->id;
if ($this->file('documents') && is_array($this->file('documents'))) { if ($this->file('documents') && is_array($this->file('documents'))) {
$rules['documents.*'] = $this->file_validation; $rules['documents.*'] = $this->file_validation;
@ -51,11 +57,11 @@ class StoreQuoteRequest extends Request
$rules['file'] = $this->file_validation; $rules['file'] = $this->file_validation;
} }
$rules['number'] = ['nullable', Rule::unique('quotes')->where('company_id', auth()->user()->company()->id)]; $rules['number'] = ['nullable', Rule::unique('quotes')->where('company_id', $user->company()->id)];
$rules['discount'] = 'sometimes|numeric'; $rules['discount'] = 'sometimes|numeric';
$rules['is_amount_discount'] = ['boolean']; $rules['is_amount_discount'] = ['boolean'];
$rules['exchange_rate'] = 'bail|sometimes|gt:0'; $rules['exchange_rate'] = 'bail|sometimes|numeric';
// $rules['number'] = new UniqueQuoteNumberRule($this->all()); // $rules['number'] = new UniqueQuoteNumberRule($this->all());
$rules['line_items'] = 'array'; $rules['line_items'] = 'array';

View File

@ -57,7 +57,7 @@ class UpdateQuoteRequest extends Request
$rules['line_items'] = 'array'; $rules['line_items'] = 'array';
$rules['discount'] = 'sometimes|numeric'; $rules['discount'] = 'sometimes|numeric';
$rules['is_amount_discount'] = ['boolean']; $rules['is_amount_discount'] = ['boolean'];
$rules['exchange_rate'] = 'bail|sometimes|gt:0'; $rules['exchange_rate'] = 'bail|sometimes|numeric';
return $rules; return $rules;
} }

View File

@ -31,11 +31,18 @@ class StoreRecurringInvoiceRequest extends Request
*/ */
public function authorize() : bool public function authorize() : bool
{ {
return auth()->user()->can('create', RecurringInvoice::class);
/** @var \App\Models\User auth()->user() */
$user = auth()->user();
return $user->can('create', RecurringInvoice::class);
} }
public function rules() public function rules()
{ {
/** @var \App\Models\User $user */
$user = auth()->user();
$rules = []; $rules = [];
if ($this->file('documents') && is_array($this->file('documents'))) { if ($this->file('documents') && is_array($this->file('documents'))) {
@ -50,7 +57,7 @@ class StoreRecurringInvoiceRequest extends Request
$rules['file'] = $this->file_validation; $rules['file'] = $this->file_validation;
} }
$rules['client_id'] = 'required|exists:clients,id,company_id,'.auth()->user()->company()->id; $rules['client_id'] = 'required|exists:clients,id,company_id,'.$user->company()->id;
$rules['invitations.*.client_contact_id'] = 'distinct'; $rules['invitations.*.client_contact_id'] = 'distinct';
@ -67,7 +74,7 @@ class StoreRecurringInvoiceRequest extends Request
$rules['tax_name2'] = 'bail|sometimes|string|nullable'; $rules['tax_name2'] = 'bail|sometimes|string|nullable';
$rules['tax_name3'] = 'bail|sometimes|string|nullable'; $rules['tax_name3'] = 'bail|sometimes|string|nullable';
$rules['due_date_days'] = 'bail|sometimes|string'; $rules['due_date_days'] = 'bail|sometimes|string';
$rules['exchange_rate'] = 'bail|sometimes|gt:0'; $rules['exchange_rate'] = 'bail|sometimes|numeric';
return $rules; return $rules;
} }
@ -137,7 +144,8 @@ class StoreRecurringInvoiceRequest extends Request
if (isset($input['auto_bill'])) { if (isset($input['auto_bill'])) {
$input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']); $input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']);
} else { } else {
if (array_key_exists('client_id', $input) && $client = Client::find($input['client_id'])) { if (array_key_exists('client_id', $input) && $client = Client::query()->find($input['client_id'])) {
/** @var \App\Models\Client $client */
$input['auto_bill'] = $client->getSetting('auto_bill'); $input['auto_bill'] = $client->getSetting('auto_bill');
$input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']); $input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']);
} }

View File

@ -31,11 +31,17 @@ class UpdateRecurringInvoiceRequest extends Request
*/ */
public function authorize() : bool public function authorize() : bool
{ {
return auth()->user()->can('edit', $this->recurring_invoice); /** @var \App\Models\User auth()->user() */
$user = auth()->user();
return $user->can('edit', $this->recurring_invoice);
} }
public function rules() public function rules()
{ {
/** @var \App\Models\User auth()->user() */
$user = auth()->user();
$rules = []; $rules = [];
if ($this->file('documents') && is_array($this->file('documents'))) { if ($this->file('documents') && is_array($this->file('documents'))) {
@ -51,7 +57,7 @@ class UpdateRecurringInvoiceRequest extends Request
} }
if ($this->number) { if ($this->number) {
$rules['number'] = Rule::unique('recurring_invoices')->where('company_id', auth()->user()->company()->id)->ignore($this->recurring_invoice->id); $rules['number'] = Rule::unique('recurring_invoices')->where('company_id', $user->company()->id)->ignore($this->recurring_invoice->id);
} }
$rules['project_id'] = ['bail', 'sometimes', new ValidProjectForClient($this->all())]; $rules['project_id'] = ['bail', 'sometimes', new ValidProjectForClient($this->all())];
@ -61,7 +67,7 @@ class UpdateRecurringInvoiceRequest extends Request
$rules['tax_name1'] = 'bail|sometimes|string|nullable'; $rules['tax_name1'] = 'bail|sometimes|string|nullable';
$rules['tax_name2'] = 'bail|sometimes|string|nullable'; $rules['tax_name2'] = 'bail|sometimes|string|nullable';
$rules['tax_name3'] = 'bail|sometimes|string|nullable'; $rules['tax_name3'] = 'bail|sometimes|string|nullable';
$rules['exchange_rate'] = 'bail|sometimes|gt:0'; $rules['exchange_rate'] = 'bail|sometimes|numeric';
return $rules; return $rules;
} }
@ -126,7 +132,7 @@ class UpdateRecurringInvoiceRequest extends Request
unset($input['documents']); unset($input['documents']);
} }
if (array_key_exists('exchange_rate', $input) && (is_null($input['exchange_rate']) || $input['exchange_rate'] == 0)) { if (array_key_exists('exchange_rate', $input) && (is_null($input['exchange_rate']) || $input['exchange_rate'] == 0) || !isset($input['exchange_rate'])) {
$input['exchange_rate'] = 1; $input['exchange_rate'] = 1;
} }
@ -138,11 +144,11 @@ class UpdateRecurringInvoiceRequest extends Request
* off / optin / optout will reset the status of this field to off to allow * off / optin / optout will reset the status of this field to off to allow
* the client to choose whether to auto_bill or not. * the client to choose whether to auto_bill or not.
* *
* @param enum $auto_bill off/always/optin/optout * @param string $auto_bill off/always/optin/optout
* *
* @return bool * @return bool
*/ */
private function setAutoBillFlag($auto_bill) private function setAutoBillFlag($auto_bill): bool
{ {
if ($auto_bill == 'always' || $auto_bill == 'optout') { if ($auto_bill == 'always' || $auto_bill == 'optout') {
return true; return true;

View File

@ -30,11 +30,19 @@ class StoreRecurringQuoteRequest extends Request
*/ */
public function authorize() : bool public function authorize() : bool
{ {
return auth()->user()->can('create', RecurringQuote::class);
/** @var \App\Models\User auth()->user() */
$user = auth()->user();
return $user->can('create', RecurringQuote::class);
} }
public function rules() public function rules()
{ {
/** @var \App\Models\User auth()->user() */
$user = auth()->user();
$rules = []; $rules = [];
if ($this->file('documents') && is_array($this->file('documents'))) { if ($this->file('documents') && is_array($this->file('documents'))) {
@ -49,7 +57,7 @@ class StoreRecurringQuoteRequest extends Request
$rules['file'] = $this->file_validation; $rules['file'] = $this->file_validation;
} }
$rules['client_id'] = 'required|exists:clients,id,company_id,'.auth()->user()->company()->id; $rules['client_id'] = 'required|exists:clients,id,company_id,'.$user->company()->id;
$rules['invitations.*.client_contact_id'] = 'distinct'; $rules['invitations.*.client_contact_id'] = 'distinct';
@ -71,6 +79,7 @@ class StoreRecurringQuoteRequest extends Request
$input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']); $input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']);
} else { } else {
if ($client = Client::find($input['client_id'])) { if ($client = Client::find($input['client_id'])) {
/** @var \App\Models\Client $client */
$input['auto_bill'] = $client->getSetting('auto_bill'); $input['auto_bill'] = $client->getSetting('auto_bill');
$input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']); $input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']);
} }

View File

@ -74,7 +74,7 @@ class StoreShopClientRequest extends Request
public function prepareForValidation() public function prepareForValidation()
{ {
$this->company = Company::where('company_key', request()->header('X-API-COMPANY-KEY'))->firstOrFail(); $this->company = Company::query()->where('company_key', request()->header('X-API-COMPANY-KEY'))->firstOrFail();
$input = $this->all(); $input = $this->all();
@ -93,7 +93,7 @@ class StoreShopClientRequest extends Request
//is no settings->currency_id is set then lets dive in and find either a group or company currency all the below may be redundant!! //is no settings->currency_id is set then lets dive in and find either a group or company currency all the below may be redundant!!
if (! property_exists($settings, 'currency_id') && isset($input['group_settings_id'])) { if (! property_exists($settings, 'currency_id') && isset($input['group_settings_id'])) {
$input['group_settings_id'] = $this->decodePrimaryKey($input['group_settings_id']); $input['group_settings_id'] = $this->decodePrimaryKey($input['group_settings_id']);
$group_settings = GroupSetting::find($input['group_settings_id']); $group_settings = GroupSetting::query()->find($input['group_settings_id']);
if ($group_settings && property_exists($group_settings->settings, 'currency_id') && isset($group_settings->settings->currency_id)) { if ($group_settings && property_exists($group_settings->settings, 'currency_id') && isset($group_settings->settings->currency_id)) {
$settings->currency_id = (string) $group_settings->settings->currency_id; $settings->currency_id = (string) $group_settings->settings->currency_id;

View File

@ -57,6 +57,6 @@ class CreateStatementRequest extends Request
public function client(): ?Client public function client(): ?Client
{ {
return Client::without('company')->where('id', $this->client_id)->withTrashed()->first(); return Client::query()->without('company')->where('id', $this->client_id)->withTrashed()->first();
} }
} }

View File

@ -26,7 +26,9 @@ class ShowDocumentRequest extends FormRequest
*/ */
public function authorize() public function authorize()
{ {
return auth()->guard('vendor')->user()->client_id == $this->document->documentable_id
/** @var \App\Models\VendorContact auth()->guard('vendor')->user() */
return auth()->guard('vendor')->user()->vendor_id == $this->document->documentable_id
|| $this->document->company_id == auth()->guard('vendor')->user()->company_id; || $this->document->company_id == auth()->guard('vendor')->user()->company_id;
} }

View File

@ -49,7 +49,7 @@ class UniqueCreditNumberRule implements Rule
*/ */
private function checkIfCreditNumberUnique() : bool private function checkIfCreditNumberUnique() : bool
{ {
$credit = Credit::where('client_id', $this->input['client_id']) $credit = Credit::query()->where('client_id', $this->input['client_id'])
->where('number', $this->input['number']) ->where('number', $this->input['number'])
->withTrashed() ->withTrashed()
->exists(); ->exists();

View File

@ -53,7 +53,7 @@ class UniqueInvoiceNumberRule implements Rule
return true; return true;
} }
$invoice = Invoice::where('client_id', $this->input['client_id']) $invoice = Invoice::query()->where('client_id', $this->input['client_id'])
->where('number', $this->input['number']) ->where('number', $this->input['number'])
->withTrashed() ->withTrashed()
->exists(); ->exists();

View File

@ -19,13 +19,14 @@ use Illuminate\Contracts\Validation\Rule;
*/ */
class CanStoreClientsRule implements Rule class CanStoreClientsRule implements Rule
{ {
public $company_id;
public $company; /**
* @var \App\Models\Company $company
*/
public Company $company;
public function __construct($company_id) public function __construct(public int $company_id)
{ {
$this->company_id = $company_id;
} }
/** /**
@ -35,7 +36,7 @@ class CanStoreClientsRule implements Rule
*/ */
public function passes($attribute, $value) public function passes($attribute, $value)
{ {
$this->company = Company::find($this->company_id); $this->company = Company::query()->find($this->company_id);
return $this->company->clients()->count() < $this->company->account->hosted_client_count; return $this->company->clients()->count() < $this->company->account->hosted_client_count;
} }

View File

@ -46,8 +46,7 @@ class ValidRefundableRequest implements Rule
return false; return false;
} }
/**@var \App\Models\Payment $payment **/ $payment = Payment::query()->where('id', $this->input['id'])->withTrashed()->first();
$payment = Payment::where('id', $this->input['id'])->withTrashed()->first();
if (! $payment) { if (! $payment) {
$this->error_msg = ctrans('texts.unable_to_retrieve_payment'); $this->error_msg = ctrans('texts.unable_to_retrieve_payment');
@ -77,7 +76,7 @@ class ValidRefundableRequest implements Rule
private function checkInvoiceIsPaymentable($invoice, $payment) private function checkInvoiceIsPaymentable($invoice, $payment)
{ {
/**@var \App\Models\Invoice $invoice **/ /**@var \App\Models\Invoice $invoice **/
$invoice = Invoice::where('id', $invoice['invoice_id'])->where('company_id', $payment->company_id)->withTrashed()->first(); $invoice = Invoice::query()->where('id', $invoice['invoice_id'])->where('company_id', $payment->company_id)->withTrashed()->first();
if (! $invoice) { if (! $invoice) {
$this->error_msg = 'Invoice not found for refund'; $this->error_msg = 'Invoice not found for refund';

View File

@ -49,7 +49,7 @@ class UniqueQuoteNumberRule implements Rule
*/ */
private function checkIfQuoteNumberUnique() : bool private function checkIfQuoteNumberUnique() : bool
{ {
$quote = Quote::where('client_id', $this->input['client_id']) $quote = Quote::query()->where('client_id', $this->input['client_id'])
->where('number', $this->input['number']) ->where('number', $this->input['number'])
->withTrashed() ->withTrashed()
->exists(); ->exists();

View File

@ -53,7 +53,7 @@ class UniqueRecurringInvoiceNumberRule implements Rule
return true; return true;
} }
$invoice = RecurringInvoice::where('client_id', $this->input['client_id']) $invoice = RecurringInvoice::query()->where('client_id', $this->input['client_id'])
->where('number', $this->input['number']) ->where('number', $this->input['number'])
->withTrashed() ->withTrashed()
->exists(); ->exists();

View File

@ -53,7 +53,7 @@ class UniqueRecurringQuoteNumberRule implements Rule
return true; return true;
} }
$invoice = RecurringQuote::where('client_id', $this->input['client_id']) $invoice = RecurringQuote::query()->where('client_id', $this->input['client_id'])
->where('number', $this->input['number']) ->where('number', $this->input['number'])
->withTrashed() ->withTrashed()
->exists(); ->exists();

View File

@ -52,7 +52,7 @@ class ValidCreditsPresentRule implements Rule
//todo need to ensure the clients credits are here not random ones! //todo need to ensure the clients credits are here not random ones!
if (array_key_exists('credits', $this->input) && is_array($this->input['credits']) && count($this->input['credits']) > 0) { if (array_key_exists('credits', $this->input) && is_array($this->input['credits']) && count($this->input['credits']) > 0) {
$credit_collection = Credit::whereIn('id', array_column($this->input['credits'], 'credit_id'))->count(); $credit_collection = Credit::query()->whereIn('id', array_column($this->input['credits'], 'credit_id'))->count();
return $credit_collection == count($this->input['credits']); return $credit_collection == count($this->input['credits']);
} }

View File

@ -35,7 +35,7 @@ class ValidPayableInvoicesRule implements Rule
$invoices = []; $invoices = [];
if (is_array($value)) { if (is_array($value)) {
$invoices = Invoice::whereIn('id', array_column($value, 'invoice_id'))->company()->get(); $invoices = Invoice::query()->whereIn('id', array_column($value, 'invoice_id'))->company()->get();
} }
foreach ($invoices as $invoice) { foreach ($invoices as $invoice) {

View File

@ -58,7 +58,7 @@ class ValidRefundableInvoices implements Rule
$invoices = []; $invoices = [];
if (is_array($value)) { if (is_array($value)) {
$invoices = Invoice::whereIn('id', array_column($this->input['invoices'], 'invoice_id'))->company()->get(); $invoices = Invoice::query()->whereIn('id', array_column($this->input['invoices'], 'invoice_id'))->company()->get();
} else { } else {
return true; return true;
} }

View File

@ -26,7 +26,10 @@ class ValidUserForCompany implements Rule
*/ */
public function passes($attribute, $value) public function passes($attribute, $value)
{ {
return MultiDB::checkUserAndCompanyCoExist($value, auth()->user()->company()->company_key, auth()->user()->company()->id); /** @var \App\Models\User auth()->user() */
$user = auth()->user();
return MultiDB::checkUserAndCompanyCoExist($value, $user->company()->company_key);
} }
/** /**

View File

@ -95,6 +95,7 @@ class BaseImport
ini_set('auto_detect_line_endings', '1'); ini_set('auto_detect_line_endings', '1');
} }
/** @var string $base64_encoded_csv */
$base64_encoded_csv = Cache::pull($this->hash.'-'.$entity_type); $base64_encoded_csv = Cache::pull($this->hash.'-'.$entity_type);
if (empty($base64_encoded_csv)) { if (empty($base64_encoded_csv)) {
@ -103,7 +104,7 @@ class BaseImport
$csv = base64_decode($base64_encoded_csv); $csv = base64_decode($base64_encoded_csv);
$csv = mb_convert_encoding($csv, 'UTF-8', 'UTF-8'); $csv = mb_convert_encoding($csv, 'UTF-8', 'UTF-8');
nlog($csv);
$csv = Reader::createFromString($csv); $csv = Reader::createFromString($csv);
$csvdelimiter = self::detectDelimiter($csv); $csvdelimiter = self::detectDelimiter($csv);

View File

@ -189,7 +189,7 @@ class Wave extends BaseImport implements ImportInterface
$this->transformer = new ExpenseTransformer($this->company); $this->transformer = new ExpenseTransformer($this->company);
$expense_count = $this->ingestExpenses($data, $entity_type); $expense_count = $this->ingestExpenses($data);
$this->entity_count['expenses'] = $expense_count; $this->entity_count['expenses'] = $expense_count;
} }
@ -200,7 +200,7 @@ class Wave extends BaseImport implements ImportInterface
private function groupExpenses($csvData) private function groupExpenses($csvData)
{ {
$grouped_expense = []; $grouped = [];
$key = 'Transaction ID'; $key = 'Transaction ID';
foreach ($csvData as $expense) { foreach ($csvData as $expense) {

View File

@ -176,7 +176,7 @@ class BaseTransformer
public function getClient($client_name, $client_email) public function getClient($client_name, $client_email)
{ {
if (! empty($client_name)) { if (! empty($client_name)) {
$client_id_search = Client::where('company_id', $this->company->id) $client_id_search = Client::query()->where('company_id', $this->company->id)
->where('is_deleted', false) ->where('is_deleted', false)
->where('id_number', $client_name); ->where('id_number', $client_name);
@ -184,7 +184,7 @@ class BaseTransformer
return $client_id_search->first()->id; return $client_id_search->first()->id;
} }
$client_name_search = Client::where('company_id', $this->company->id) $client_name_search = Client::query()->where('company_id', $this->company->id)
->where('is_deleted', false) ->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ ->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $client_name)), strtolower(str_replace(' ', '', $client_name)),
@ -195,7 +195,7 @@ class BaseTransformer
} }
} }
if (! empty($client_email)) { if (! empty($client_email)) {
$contacts = ClientContact::whereHas('client', function ($query) { $contacts = ClientContact::query()->whereHas('client', function ($query) {
$query->where('is_deleted', false); $query->where('is_deleted', false);
}) })
->where('company_id', $this->company->id) ->where('company_id', $this->company->id)
@ -238,7 +238,7 @@ class BaseTransformer
*/ */
public function hasClient($name) public function hasClient($name)
{ {
return Client::where('company_id', $this->company->id) return Client::query()->where('company_id', $this->company->id)
->where('is_deleted', false) ->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ ->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)), strtolower(str_replace(' ', '', $name)),
@ -248,7 +248,7 @@ class BaseTransformer
public function hasClientIdNumber($id_number) public function hasClientIdNumber($id_number)
{ {
return Client::where('company_id', $this->company->id) return Client::query()->where('company_id', $this->company->id)
->where('is_deleted', false) ->where('is_deleted', false)
->where('id_number', trim($id_number)) ->where('id_number', trim($id_number))
->exists(); ->exists();
@ -262,7 +262,7 @@ class BaseTransformer
*/ */
public function hasVendor($name) public function hasVendor($name)
{ {
return Vendor::where('company_id', $this->company->id) return Vendor::query()->where('company_id', $this->company->id)
->where('is_deleted', false) ->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ ->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)), strtolower(str_replace(' ', '', $name)),
@ -277,7 +277,7 @@ class BaseTransformer
*/ */
public function hasProject($name) public function hasProject($name)
{ {
return Project::where('company_id', $this->company->id) return Project::query()->where('company_id', $this->company->id)
->where('is_deleted', false) ->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ ->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)), strtolower(str_replace(' ', '', $name)),
@ -292,7 +292,7 @@ class BaseTransformer
*/ */
public function hasProduct($key) public function hasProduct($key)
{ {
return Product::where('company_id', $this->company->id) return Product::query()->where('company_id', $this->company->id)
->where('is_deleted', false) ->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`product_key`, ' ' ,'')) = ?", [ ->whereRaw("LOWER(REPLACE(`product_key`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $key)), strtolower(str_replace(' ', '', $key)),
@ -341,7 +341,7 @@ class BaseTransformer
*/ */
public function getClientId($name) public function getClientId($name)
{ {
$client = Client::where('company_id', $this->company->id) $client = Client::query()->where('company_id', $this->company->id)
->where('is_deleted', false) ->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ ->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)), strtolower(str_replace(' ', '', $name)),
@ -358,7 +358,7 @@ class BaseTransformer
*/ */
public function getProduct($key) public function getProduct($key)
{ {
$product = Product::where('company_id', $this->company->id) $product = Product::query()->where('company_id', $this->company->id)
->where('is_deleted', false) ->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`product_key`, ' ' ,'')) = ?", [ ->whereRaw("LOWER(REPLACE(`product_key`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $key)), strtolower(str_replace(' ', '', $key)),
@ -375,7 +375,7 @@ class BaseTransformer
*/ */
public function getContact($email): ?ClientContact public function getContact($email): ?ClientContact
{ {
$contact = ClientContact::where('company_id', $this->company->id) $contact = ClientContact::query()->where('company_id', $this->company->id)
->whereRaw("LOWER(REPLACE(`email`, ' ' ,'')) = ?", [ ->whereRaw("LOWER(REPLACE(`email`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $email)), strtolower(str_replace(' ', '', $email)),
]) ])
@ -400,7 +400,7 @@ class BaseTransformer
return $this->getCountryIdBy2($name); return $this->getCountryIdBy2($name);
} }
$country = Country::whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ $country = Country::query()->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)), strtolower(str_replace(' ', '', $name)),
])->first(); ])->first();
@ -414,8 +414,8 @@ class BaseTransformer
*/ */
public function getCountryIdBy2($name) public function getCountryIdBy2($name)
{ {
return Country::where('iso_3166_2', $name)->exists() return Country::query()->where('iso_3166_2', $name)->exists()
? Country::where('iso_3166_2', $name)->first()->id ? Country::query()->where('iso_3166_2', $name)->first()->id
: null; : null;
} }
@ -428,7 +428,7 @@ class BaseTransformer
{ {
$name = strtolower(trim($name)); $name = strtolower(trim($name));
$tax_rate = TaxRate::where('company_id', $this->company->id) $tax_rate = TaxRate::query()->where('company_id', $this->company->id)
->where('is_deleted', false) ->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ ->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)), strtolower(str_replace(' ', '', $name)),
@ -447,7 +447,7 @@ class BaseTransformer
{ {
$name = strtolower(trim($name)); $name = strtolower(trim($name));
$tax_rate = TaxRate::where('company_id', $this->company->id) $tax_rate = TaxRate::query()->where('company_id', $this->company->id)
->where('is_deleted', false) ->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ ->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)), strtolower(str_replace(' ', '', $name)),
@ -495,7 +495,7 @@ class BaseTransformer
*/ */
public function getInvoiceId($invoice_number) public function getInvoiceId($invoice_number)
{ {
$invoice = Invoice::where('company_id', $this->company->id) $invoice = Invoice::query()->where('company_id', $this->company->id)
->where('is_deleted', false) ->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [ ->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $invoice_number)), strtolower(str_replace(' ', '', $invoice_number)),
@ -512,7 +512,7 @@ class BaseTransformer
*/ */
public function hasInvoice($invoice_number) public function hasInvoice($invoice_number)
{ {
return Invoice::where('company_id', $this->company->id) return Invoice::query()->where('company_id', $this->company->id)
->where('is_deleted', false) ->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [ ->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $invoice_number)), strtolower(str_replace(' ', '', $invoice_number)),
@ -528,7 +528,7 @@ class BaseTransformer
*/ */
public function hasRecurringInvoice($invoice_number) public function hasRecurringInvoice($invoice_number)
{ {
return RecurringInvoice::where('company_id', $this->company->id) return RecurringInvoice::query()->where('company_id', $this->company->id)
->where('is_deleted', false) ->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [ ->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $invoice_number)), strtolower(str_replace(' ', '', $invoice_number)),
@ -541,7 +541,7 @@ class BaseTransformer
*/ */
public function hasExpense($expense_number) public function hasExpense($expense_number)
{ {
return Expense::where('company_id', $this->company->id) return Expense::query()->where('company_id', $this->company->id)
->where('is_deleted', false) ->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [ ->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $expense_number)), strtolower(str_replace(' ', '', $expense_number)),
@ -556,7 +556,7 @@ class BaseTransformer
*/ */
public function hasQuote($quote_number) public function hasQuote($quote_number)
{ {
return Quote::where('company_id', $this->company->id) return Quote::query()->where('company_id', $this->company->id)
->where('is_deleted', false) ->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [ ->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $quote_number)), strtolower(str_replace(' ', '', $quote_number)),
@ -571,7 +571,7 @@ class BaseTransformer
*/ */
public function getInvoiceClientId($invoice_number) public function getInvoiceClientId($invoice_number)
{ {
$invoice = Invoice::where('company_id', $this->company->id) $invoice = Invoice::query()->where('company_id', $this->company->id)
->where('is_deleted', false) ->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [ ->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $invoice_number)), strtolower(str_replace(' ', '', $invoice_number)),
@ -588,7 +588,7 @@ class BaseTransformer
*/ */
public function getVendorId($name) public function getVendorId($name)
{ {
$vendor = Vendor::where('company_id', $this->company->id) $vendor = Vendor::query()->where('company_id', $this->company->id)
->where('is_deleted', false) ->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ ->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)), strtolower(str_replace(' ', '', $name)),
@ -626,7 +626,7 @@ class BaseTransformer
{ {
/** @var \App\Models\ExpenseCategory $ec */ /** @var \App\Models\ExpenseCategory $ec */
$ec = ExpenseCategory::where('company_id', $this->company->id) $ec = ExpenseCategory::query()->where('company_id', $this->company->id)
->where('is_deleted', false) ->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ ->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)), strtolower(str_replace(' ', '', $name)),
@ -669,7 +669,7 @@ class BaseTransformer
*/ */
public function getProjectId($name, $clientId = null) public function getProjectId($name, $clientId = null)
{ {
$project = Project::where('company_id', $this->company->id) $project = Project::query()->where('company_id', $this->company->id)
->where('is_deleted', false) ->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ ->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)), strtolower(str_replace(' ', '', $name)),
@ -700,7 +700,7 @@ class BaseTransformer
*/ */
public function getPaymentTypeId($name) public function getPaymentTypeId($name)
{ {
$pt = PaymentType::whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ $pt = PaymentType::query()->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)), strtolower(str_replace(' ', '', $name)),
])->first(); ])->first();

View File

@ -102,7 +102,7 @@ class InvoiceTransformer extends BaseTransformer
$client_name = $this->getString($invoice_data, 'Customer Name'); $client_name = $this->getString($invoice_data, 'Customer Name');
if(strlen($client_name) >= 2) { if(strlen($client_name) >= 2) {
$client_name_search = \App\Models\Client::where('company_id', $this->company->id) $client_name_search = \App\Models\Client::query()->where('company_id', $this->company->id)
->where('is_deleted', false) ->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ ->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $client_name)), strtolower(str_replace(' ', '', $client_name)),
@ -115,7 +115,7 @@ class InvoiceTransformer extends BaseTransformer
$customer_id = $this->getString($invoice_data, 'Customer ID'); $customer_id = $this->getString($invoice_data, 'Customer ID');
$client_id_search = \App\Models\Client::where('company_id', $this->company->id) $client_id_search = \App\Models\Client::query()->where('company_id', $this->company->id)
->where('is_deleted', false) ->where('is_deleted', false)
->where('id_number', trim($customer_id)); ->where('id_number', trim($customer_id));

View File

@ -47,10 +47,12 @@ class MatchBankTransactions implements ShouldQueue
private array $input; private array $input;
/** @var \App\Models\Company */
protected ?Company $company; protected ?Company $company;
public Invoice $invoice; public Invoice $invoice;
/** @var \App\Models\BankTransaction $bt */
private ?BankTransaction $bt; private ?BankTransaction $bt;
private $categories; private $categories;
@ -83,7 +85,7 @@ class MatchBankTransactions implements ShouldQueue
{ {
MultiDB::setDb($this->db); MultiDB::setDb($this->db);
$this->company = Company::find($this->company_id); $this->company = Company::query()->find($this->company_id);
if ($this->company->account->bank_integration_account_id) { if ($this->company->account->bank_integration_account_id) {
$yodlee = new Yodlee($this->company->account->bank_integration_account_id); $yodlee = new Yodlee($this->company->account->bank_integration_account_id);
@ -113,7 +115,7 @@ class MatchBankTransactions implements ShouldQueue
} }
} }
return BankTransaction::whereIn('id', $this->bts); return BankTransaction::query()->whereIn('id', $this->bts);
} }
private function getInvoices(string $invoice_hashed_ids): array private function getInvoices(string $invoice_hashed_ids): array
@ -193,7 +195,7 @@ class MatchBankTransactions implements ShouldQueue
private function linkPayment($input) private function linkPayment($input)
{ {
$this->bt = BankTransaction::find($input['id']); $this->bt = BankTransaction::query()->withTrashed()->find($input['id']);
if (!$this->bt || $this->bt->status_id == BankTransaction::STATUS_CONVERTED) { if (!$this->bt || $this->bt->status_id == BankTransaction::STATUS_CONVERTED) {
return $this; return $this;
@ -243,7 +245,7 @@ class MatchBankTransactions implements ShouldQueue
private function matchExpense($input) :self private function matchExpense($input) :self
{ {
//if there is a category id, pull it from Yodlee and insert - or just reuse!! //if there is a category id, pull it from Yodlee and insert - or just reuse!!
$this->bt = BankTransaction::find($input['id']); $this->bt = BankTransaction::query()->withTrashed()->find($input['id']);
if (!$this->bt || $this->bt->status_id == BankTransaction::STATUS_CONVERTED) { if (!$this->bt || $this->bt->status_id == BankTransaction::STATUS_CONVERTED) {
return $this; return $this;
@ -286,7 +288,7 @@ class MatchBankTransactions implements ShouldQueue
$this->available_balance = $amount; $this->available_balance = $amount;
\DB::connection(config('database.default'))->transaction(function () use ($invoices) { \DB::connection(config('database.default'))->transaction(function () use ($invoices) {
$invoices->each(function ($invoice) use ($invoices) { $invoices->each(function ($invoice) {
$this->invoice = Invoice::withTrashed()->where('id', $invoice->id)->lockForUpdate()->first(); $this->invoice = Invoice::withTrashed()->where('id', $invoice->id)->lockForUpdate()->first();
$_amount = false; $_amount = false;
@ -398,7 +400,7 @@ class MatchBankTransactions implements ShouldQueue
$category = $this->categories->firstWhere('highLevelCategoryId', $this->bt->category_id); $category = $this->categories->firstWhere('highLevelCategoryId', $this->bt->category_id);
$ec = ExpenseCategory::where('company_id', $this->bt->company_id)->where('bank_category_id', $this->bt->category_id)->first(); $ec = ExpenseCategory::query()->where('company_id', $this->bt->company_id)->where('bank_category_id', $this->bt->category_id)->first();
if ($ec) { if ($ec) {
return $ec->id; return $ec->id;

View File

@ -158,7 +158,7 @@ class ProcessBankTransactions implements ShouldQueue
$now = now(); $now = now();
foreach ($transactions as $transaction) { foreach ($transactions as $transaction) {
if (BankTransaction::where('transaction_id', $transaction['transaction_id'])->where('company_id', $this->company->id)->withTrashed()->exists()) { if (BankTransaction::query()->where('transaction_id', $transaction['transaction_id'])->where('company_id', $this->company->id)->withTrashed()->exists()) {
continue; continue;
} }

View File

@ -48,9 +48,9 @@ class CompanyExport implements ShouldQueue
/** /**
* Create a new job instance. * Create a new job instance.
* *
* @param Company $company * @param \App\Models\Company $company
* @param User $user * @param \App\Models\User $user
* @param string $custom_token_name * @param string $hash
*/ */
public function __construct(public Company $company, private User $user, public string $hash) public function __construct(public Company $company, private User $user, public string $hash)
{ {
@ -65,7 +65,7 @@ class CompanyExport implements ShouldQueue
{ {
MultiDB::setDb($this->company->db); MultiDB::setDb($this->company->db);
$this->company = Company::where('company_key', $this->company->company_key)->first(); $this->company = Company::query()->where('company_key', $this->company->company_key)->first();
set_time_limit(0); set_time_limit(0);
@ -187,7 +187,7 @@ class CompanyExport implements ShouldQueue
})->all(); })->all();
$this->export_data['credit_invitations'] = CreditInvitation::where('company_id', $this->company->id)->withTrashed()->cursor()->map(function ($credit) { $this->export_data['credit_invitations'] = CreditInvitation::query()->where('company_id', $this->company->id)->withTrashed()->cursor()->map(function ($credit) {
$credit = $this->transformArrayOfKeys($credit, ['company_id', 'user_id', 'client_contact_id', 'credit_id']); $credit = $this->transformArrayOfKeys($credit, ['company_id', 'user_id', 'client_contact_id', 'credit_id']);
return $credit->makeVisible(['id']); return $credit->makeVisible(['id']);
@ -236,7 +236,7 @@ class CompanyExport implements ShouldQueue
})->all(); })->all();
$this->export_data['invoice_invitations'] = InvoiceInvitation::where('company_id', $this->company->id)->withTrashed()->cursor()->map(function ($invoice) { $this->export_data['invoice_invitations'] = InvoiceInvitation::query()->where('company_id', $this->company->id)->withTrashed()->cursor()->map(function ($invoice) {
$invoice = $this->transformArrayOfKeys($invoice, ['company_id', 'user_id', 'client_contact_id', 'invoice_id']); $invoice = $this->transformArrayOfKeys($invoice, ['company_id', 'user_id', 'client_contact_id', 'invoice_id']);
return $invoice->makeVisible(['id']); return $invoice->makeVisible(['id']);
@ -280,7 +280,7 @@ class CompanyExport implements ShouldQueue
})->all(); })->all();
$this->export_data['quote_invitations'] = QuoteInvitation::where('company_id', $this->company->id)->withTrashed()->cursor()->map(function ($quote) { $this->export_data['quote_invitations'] = QuoteInvitation::query()->where('company_id', $this->company->id)->withTrashed()->cursor()->map(function ($quote) {
$quote = $this->transformArrayOfKeys($quote, ['company_id', 'user_id', 'client_contact_id', 'quote_id']); $quote = $this->transformArrayOfKeys($quote, ['company_id', 'user_id', 'client_contact_id', 'quote_id']);
return $quote->makeVisible(['id']); return $quote->makeVisible(['id']);
@ -301,7 +301,7 @@ class CompanyExport implements ShouldQueue
})->all(); })->all();
$this->export_data['recurring_invoice_invitations'] = RecurringInvoiceInvitation::where('company_id', $this->company->id)->withTrashed()->cursor()->map(function ($ri) { $this->export_data['recurring_invoice_invitations'] = RecurringInvoiceInvitation::query()->where('company_id', $this->company->id)->withTrashed()->cursor()->map(function ($ri) {
$ri = $this->transformArrayOfKeys($ri, ['company_id', 'user_id', 'client_contact_id', 'recurring_invoice_id']); $ri = $this->transformArrayOfKeys($ri, ['company_id', 'user_id', 'client_contact_id', 'recurring_invoice_id']);
return $ri; return $ri;
@ -381,7 +381,7 @@ class CompanyExport implements ShouldQueue
'company_id',]); 'company_id',]);
})->all(); })->all();
$this->export_data['purchase_order_invitations'] = PurchaseOrderInvitation::where('company_id', $this->company->id)->withTrashed()->cursor()->map(function ($purchase_order) { $this->export_data['purchase_order_invitations'] = PurchaseOrderInvitation::query()->where('company_id', $this->company->id)->withTrashed()->cursor()->map(function ($purchase_order) {
$purchase_order = $this->transformArrayOfKeys($purchase_order, ['company_id', 'user_id', 'vendor_contact_id', 'purchase_order_id']); $purchase_order = $this->transformArrayOfKeys($purchase_order, ['company_id', 'user_id', 'vendor_contact_id', 'purchase_order_id']);
return $purchase_order->makeVisible(['id']); return $purchase_order->makeVisible(['id']);

View File

@ -244,7 +244,7 @@ class CompanyImport implements ShouldQueue
{ {
MultiDB::setDb($this->company->db); MultiDB::setDb($this->company->db);
$this->company = Company::where('company_key', $this->company->company_key)->firstOrFail(); $this->company = Company::query()->where('company_key', $this->company->company_key)->firstOrFail();
$this->account = $this->company->account; $this->account = $this->company->account;
$this->company_owner = $this->company->owner(); $this->company_owner = $this->company->owner();
@ -280,7 +280,7 @@ class CompanyImport implements ShouldQueue
'errors' => [] 'errors' => []
]; ];
$_company = Company::find($this->company->id); $_company = Company::query()->find($this->company->id);
$nmo = new NinjaMailerObject; $nmo = new NinjaMailerObject;
$nmo->mailable = new ImportCompleted($_company, $data); $nmo->mailable = new ImportCompleted($_company, $data);
@ -591,6 +591,7 @@ class CompanyImport implements ShouldQueue
unset($obj_array['id']); unset($obj_array['id']);
unset($obj_array['tax_rate_id']); unset($obj_array['tax_rate_id']);
/** @var \App\Models\TaxRate $new_obj */
$new_obj = TaxRate::firstOrNew( $new_obj = TaxRate::firstOrNew(
['name' => $obj->name, 'company_id' => $this->company->id, 'rate' => $obj->rate], ['name' => $obj->name, 'company_id' => $this->company->id, 'rate' => $obj->rate],
$obj_array, $obj_array,
@ -1427,7 +1428,7 @@ class CompanyImport implements ShouldQueue
if ($class == 'App\Models\Subscription') { if ($class == 'App\Models\Subscription') {
$obj_array['product_ids'] = $this->recordProductIds($obj_array['product_ids']); $obj_array['product_ids'] = $this->recordProductIds($obj_array['product_ids']);
$obj_array['recurring_product_ids'] = $this->recordProductIds($obj_array['recurring_product_ids']); $obj_array['recurring_product_ids'] = $this->recordProductIds($obj_array['recurring_product_ids']);
$obj_array['webhook_configuration'] = json_encode($obj_array['webhook_configuration']); $obj_array['webhook_configuration'] = \json_encode($obj_array['webhook_configuration']);
} }
$new_obj = $class::firstOrNew( $new_obj = $class::firstOrNew(

View File

@ -62,9 +62,6 @@ class ZipCredits implements ShouldQueue
* Execute the job. * Execute the job.
* *
* @return void * @return void
* @throws \ZipStream\Exception\FileNotFoundException
* @throws \ZipStream\Exception\FileNotReadableException
* @throws \ZipStream\Exception\OverflowException
*/ */
public function handle() public function handle()
{ {

View File

@ -49,7 +49,8 @@ class AutoBillCron
Auth::logout(); Auth::logout();
if (! config('ninja.db.multi_db_enabled')) { if (! config('ninja.db.multi_db_enabled')) {
$auto_bill_partial_invoices = Invoice::whereDate('partial_due_date', '<=', now()) $auto_bill_partial_invoices = Invoice::query()
->whereDate('partial_due_date', '<=', now())
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) ->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
->where('auto_bill_enabled', true) ->where('auto_bill_enabled', true)
->where('auto_bill_tries', '<', 3) ->where('auto_bill_tries', '<', 3)
@ -70,7 +71,8 @@ class AutoBillCron
sleep(2); sleep(2);
}); });
$auto_bill_invoices = Invoice::whereDate('due_date', '<=', now()) $auto_bill_invoices = Invoice::query()
->whereDate('due_date', '<=', now())
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) ->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
->where('auto_bill_enabled', true) ->where('auto_bill_enabled', true)
->where('auto_bill_tries', '<', 3) ->where('auto_bill_tries', '<', 3)
@ -95,7 +97,8 @@ class AutoBillCron
foreach (MultiDB::$dbs as $db) { foreach (MultiDB::$dbs as $db) {
MultiDB::setDB($db); MultiDB::setDB($db);
$auto_bill_partial_invoices = Invoice::whereDate('partial_due_date', '<=', now()) $auto_bill_partial_invoices = Invoice::query()
->whereDate('partial_due_date', '<=', now())
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) ->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
->where('auto_bill_enabled', true) ->where('auto_bill_enabled', true)
->where('auto_bill_tries', '<', 3) ->where('auto_bill_tries', '<', 3)
@ -116,7 +119,8 @@ class AutoBillCron
sleep(2); sleep(2);
}); });
$auto_bill_invoices = Invoice::whereDate('due_date', '<=', now()) $auto_bill_invoices = Invoice::query()
->whereDate('due_date', '<=', now())
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) ->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
->where('auto_bill_enabled', true) ->where('auto_bill_enabled', true)
->where('auto_bill_tries', '<', 3) ->where('auto_bill_tries', '<', 3)

View File

@ -25,21 +25,11 @@ class SendCompanyRecurring
public $tries = 1; public $tries = 1;
/** /** @var \App\Models\Company $company */
* Create a new job instance.
*
* @return void
*/
public $company; public $company;
public $db; public function __construct(private int $company_id, private string $db)
public function __construct($company_id, $db)
{ {
$this->company_id = $company_id;
$this->db = $db;
} }
/** /**

View File

@ -43,7 +43,7 @@ class UpdateCalculatedFields
if (! config('ninja.db.multi_db_enabled')) { if (! config('ninja.db.multi_db_enabled')) {
Project::with('tasks')->whereHas('tasks', function ($query){ Project::query()->with('tasks')->whereHas('tasks', function ($query){
$query->where('updated_at', '>', now()->subHours(2)); $query->where('updated_at', '>', now()->subHours(2));
}) })
->cursor() ->cursor()
@ -61,7 +61,7 @@ class UpdateCalculatedFields
MultiDB::setDB($db); MultiDB::setDB($db);
Project::with('tasks')->whereHas('tasks', function ($query){ Project::query()->with('tasks')->whereHas('tasks', function ($query){
$query->where('updated_at', '>', now()->subHours(2)); $query->where('updated_at', '>', now()->subHours(2));
}) })
->cursor() ->cursor()

View File

@ -85,7 +85,7 @@ class ZipDocuments implements ShouldQueue
$path = $this->company->file_path(); $path = $this->company->file_path();
try { try {
$documents = Document::whereIn('id', $this->document_ids)->get(); $documents = Document::query()->whereIn('id', $this->document_ids)->get();
foreach ($documents as $document) { foreach ($documents as $document) {
$zipFile->addFromString($this->buildFileName($document), $document->getFile()); $zipFile->addFromString($this->buildFileName($document), $document->getFile());

View File

@ -48,19 +48,19 @@ class CreateEntityPdf implements ShouldQueue
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker, MakesHash, PageNumbering; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker, MakesHash, PageNumbering;
public $entity; public \App\Models\Invoice | \App\Models\Quote | \App\Models\Credit | \App\Models\RecurringInvoice | null $entity;
public $company; public \App\Models\Company | null $company;
public $contact; public \App\Models\ClientContact | null $contact;
private $disk; private $disk;
public $invitation; public \App\Models\InvoiceInvitation | \App\Models\QuoteInvitation | \App\Models\CreditInvitation | \App\Models\RecurringInvoiceInvitation | null $invitation;
public $entity_string = ''; public string $entity_string = '';
public $client; public \App\Models\Client | null $client;
public $deleteWhenMissingModels = true; public $deleteWhenMissingModels = true;
@ -136,6 +136,7 @@ class CreateEntityPdf implements ShouldQueue
$entity_design_id = $this->entity->design_id ? $this->entity->design_id : $this->decodePrimaryKey($this->client->getSetting($entity_design_id)); $entity_design_id = $this->entity->design_id ? $this->entity->design_id : $this->decodePrimaryKey($this->client->getSetting($entity_design_id));
/** @var \App\Models\Design $design */
$design = Design::withTrashed()->find($entity_design_id); $design = Design::withTrashed()->find($entity_design_id);
/* Catch all in case migration doesn't pass back a valid design */ /* Catch all in case migration doesn't pass back a valid design */

View File

@ -123,11 +123,11 @@ class CreateRawPdf implements ShouldQueue
$entity_design_id = $this->entity->design_id ? $this->entity->design_id : $this->decodePrimaryKey($this->entity->client->getSetting($entity_design_id)); $entity_design_id = $this->entity->design_id ? $this->entity->design_id : $this->decodePrimaryKey($this->entity->client->getSetting($entity_design_id));
$design = Design::withTrashed()->find($entity_design_id); $design = Design::query()->withTrashed()->find($entity_design_id);
/* Catch all in case migration doesn't pass back a valid design */ /* Catch all in case migration doesn't pass back a valid design */
if (! $design) { if (! $design) {
$design = Design::find(2); $design = Design::query()->find(2);
} }
$html = new HtmlEngine($this->invitation); $html = new HtmlEngine($this->invitation);

View File

@ -71,7 +71,7 @@ class AdjustProductInventory implements ShouldQueue
collect($this->invoice->line_items)->filter(function ($item) { collect($this->invoice->line_items)->filter(function ($item) {
return $item->type_id == '1'; return $item->type_id == '1';
})->each(function ($i) { })->each(function ($i) {
$p = Product::where('product_key', $i->product_key)->where('company_id', $this->company->id)->first(); $p = Product::query()->where('product_key', $i->product_key)->where('company_id', $this->company->id)->first();
if ($p) { if ($p) {
$p->in_stock_quantity += $i->quantity; $p->in_stock_quantity += $i->quantity;
@ -88,7 +88,7 @@ class AdjustProductInventory implements ShouldQueue
collect($this->invoice->line_items)->filter(function ($item) { collect($this->invoice->line_items)->filter(function ($item) {
return $item->type_id == '1'; return $item->type_id == '1';
})->each(function ($i) { })->each(function ($i) {
$p = Product::where('product_key', $i->product_key)->where('company_id', $this->company->id)->first(); $p = Product::query()->where('product_key', $i->product_key)->where('company_id', $this->company->id)->first();
if ($p) { if ($p) {
$p->in_stock_quantity -= $i->quantity; $p->in_stock_quantity -= $i->quantity;
@ -109,7 +109,7 @@ class AdjustProductInventory implements ShouldQueue
collect($this->invoice->line_items)->filter(function ($item) { collect($this->invoice->line_items)->filter(function ($item) {
return $item->type_id == '1'; return $item->type_id == '1';
})->each(function ($i) { })->each(function ($i) {
$p = Product::where('product_key', $i->product_key)->where('company_id', $this->company->id)->first(); $p = Product::query()->where('product_key', $i->product_key)->where('company_id', $this->company->id)->first();
if ($p) { if ($p) {
$p->in_stock_quantity -= $i->quantity; $p->in_stock_quantity -= $i->quantity;
@ -131,7 +131,7 @@ class AdjustProductInventory implements ShouldQueue
collect($this->old_invoice)->filter(function ($item) { collect($this->old_invoice)->filter(function ($item) {
return $item->type_id == '1'; return $item->type_id == '1';
})->each(function ($i) { })->each(function ($i) {
$p = Product::where('product_key', $i->product_key)->where('company_id', $this->company->id)->first(); $p = Product::query()->where('product_key', $i->product_key)->where('company_id', $this->company->id)->first();
if ($p) { if ($p) {
$p->in_stock_quantity += $i->quantity; $p->in_stock_quantity += $i->quantity;

View File

@ -45,7 +45,7 @@ class MarkOpened implements ShouldQueue
* Execute the job. * Execute the job.
* *
* *
* @return false * @return void
*/ */
public function handle() public function handle()
{ {

View File

@ -197,6 +197,7 @@ class CreateUbl implements ShouldQueue
if ($this->invoice->discount != 0) { if ($this->invoice->discount != 0) {
if ($this->invoice->is_amount_discount) { if ($this->invoice->is_amount_discount) {
/** @var float $invoice_total */
if ($invoice_total + $this->invoice->discount != 0) { if ($invoice_total + $this->invoice->discount != 0) {
$total -= $invoice_total ? ($total / ($invoice_total + $this->invoice->discount) * $this->invoice->discount) : 0; $total -= $invoice_total ? ($total / ($invoice_total + $this->invoice->discount) * $this->invoice->discount) : 0;
} }

View File

@ -12,37 +12,17 @@ use Illuminate\Foundation\Bus\Dispatchable;
class InjectSignature implements ShouldQueue class InjectSignature implements ShouldQueue
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* @var \App\Models\Invoice | \App\Models\Quote | \App\Models\Credit | \App\Models\PurchaseOrder
*/
public $entity;
/**
* @var string
*/
public $signature;
public $contact_id;
public $ip;
/** /**
* Create a new job instance. * Create a new job instance.
* *
* @param $entity * @param \App\Models\Invoice | \App\Models\Quote | \App\Models\Credit | \App\Models\PurchaseOrder $entity
* @param int $contact_id
* @param string $signature * @param string $signature
* @param string $ip
*/ */
public function __construct($entity, $contact_id, string $signature, ?string $ip) public function __construct(public \App\Models\Invoice | \App\Models\Quote | \App\Models\Credit | \App\Models\PurchaseOrder $entity, private int $contact_id, private string $signature, private ?string $ip)
{ {
$this->entity = $entity;
$this->contact_id = $contact_id;
$this->signature = $signature;
$this->ip = $ip;
} }
/** /**

View File

@ -25,8 +25,6 @@ class InvoiceWorkflowSettings implements ShouldQueue
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $invoice;
public $client; public $client;
private $base_repository; private $base_repository;
@ -35,11 +33,9 @@ class InvoiceWorkflowSettings implements ShouldQueue
* Create a new job instance. * Create a new job instance.
* *
* @param Invoice $invoice * @param Invoice $invoice
* @param Client|null $client
*/ */
public function __construct(Invoice $invoice) public function __construct(public Invoice $invoice)
{ {
$this->invoice = $invoice;
$this->base_repository = new BaseRepository(); $this->base_repository = new BaseRepository();
} }

View File

@ -43,16 +43,16 @@ class ClientLedgerBalanceUpdate implements ShouldQueue
MultiDB::setDb($this->company->db); MultiDB::setDb($this->company->db);
CompanyLedger::where('balance', 0)->where('client_id', $this->client->id)->orderBy('updated_at', 'ASC')->cursor()->each(function ($company_ledger) { CompanyLedger::query()->where('balance', 0)->where('client_id', $this->client->id)->orderBy('updated_at', 'ASC')->cursor()->each(function ($company_ledger) {
if ($company_ledger->balance == 0) { if ($company_ledger->balance == 0) {
$last_record = CompanyLedger::where('client_id', $company_ledger->client_id) $last_record = CompanyLedger::query()->where('client_id', $company_ledger->client_id)
->where('company_id', $company_ledger->company_id) ->where('company_id', $company_ledger->company_id)
->where('balance', '!=', 0) ->where('balance', '!=', 0)
->orderBy('id', 'DESC') ->orderBy('id', 'DESC')
->first(); ->first();
if (! $last_record) { if (! $last_record) {
$last_record = CompanyLedger::where('client_id', $company_ledger->client_id) $last_record = CompanyLedger::query()->where('client_id', $company_ledger->client_id)
->where('company_id', $company_ledger->company_id) ->where('company_id', $company_ledger->company_id)
->orderBy('id', 'DESC') ->orderBy('id', 'DESC')
->first(); ->first();

View File

@ -51,7 +51,7 @@ class NinjaMailerJob implements ShouldQueue
public $override; public $override;
/* @var Company $company*/ /** @var \App\Models\Company $company | null **/
public ?Company $company; public ?Company $company;
private $mailer; private $mailer;
@ -83,7 +83,7 @@ class NinjaMailerJob implements ShouldQueue
MultiDB::setDb($this->nmo->company->db); MultiDB::setDb($this->nmo->company->db);
/* Serializing models from other jobs wipes the primary key */ /* Serializing models from other jobs wipes the primary key */
$this->company = Company::where('company_key', $this->nmo->company->company_key)->first(); $this->company = Company::query()->where('company_key', $this->nmo->company->company_key)->first();
/* If any pre conditions fail, we return early here */ /* If any pre conditions fail, we return early here */
if (!$this->company || $this->preFlightChecksFail()) { if (!$this->company || $this->preFlightChecksFail()) {
@ -552,7 +552,7 @@ class NinjaMailerJob implements ShouldQueue
* Logs any errors to the SystemLog * Logs any errors to the SystemLog
* *
* @param string $errors * @param string $errors
* @param App\Models\User | App\Models\Client | null $recipient_object * @param \App\Models\User | \App\Models\Client | null $recipient_object
* @return void * @return void
*/ */
private function logMailError($errors, $recipient_object) :void private function logMailError($errors, $recipient_object) :void

View File

@ -81,7 +81,7 @@ class PaymentFailedMailer implements ShouldQueue
if ($this->payment_hash) { if ($this->payment_hash) {
// $amount = array_sum(array_column($this->payment_hash->invoices(), 'amount')) + $this->payment_hash->fee_total; // $amount = array_sum(array_column($this->payment_hash->invoices(), 'amount')) + $this->payment_hash->fee_total;
$amount =$this->payment_hash?->amount_with_fee() ?: 0; $amount =$this->payment_hash?->amount_with_fee() ?: 0;
$invoice = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->withTrashed()->first(); $invoice = Invoice::query()->whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->withTrashed()->first();
} }
//iterate through company_users //iterate through company_users

View File

@ -84,7 +84,14 @@ class PaymentFailureMailer implements ShouldQueue
if (($key = array_search('mail', $methods)) !== false) { if (($key = array_search('mail', $methods)) !== false) {
unset($methods[$key]); unset($methods[$key]);
$mail_obj = (new PaymentFailureObject($this->client, $this->error, $this->company, $this->amount, null))->build(); $use_react_link = false;
if(isset($company_user->react_settings->react_notification_link) && $company_user->react_settings->react_notification_link) {
$use_react_link = true;
}
$mail_obj = (new PaymentFailureObject($this->client, $this->error, $this->company, $this->amount, null, $use_react_link))->build();
$nmo = new NinjaMailerObject; $nmo = new NinjaMailerObject;
$nmo->mailable = new NinjaMailer($mail_obj); $nmo->mailable = new NinjaMailer($mail_obj);

View File

@ -39,20 +39,14 @@ class ProcessPostmarkWebhook implements ShouldQueue
public $tries = 1; public $tries = 1;
private array $request;
public $invitation; public $invitation;
/** /**
* Create a new job instance. * Create a new job instance.
* *
* @param Payment $payment
* @param $email_builder
* @param $contact
* @param $company
*/ */
public function __construct(array $request) public function __construct(private array $request)
{ {
$this->request = $request;
} }
/** /**

View File

@ -78,6 +78,7 @@ class UpdateOrCreateProduct implements ShouldQueue
return $item->type_id == 1; return $item->type_id == 1;
}); });
/** @var \App\DataMapper\InvoiceItem $item */
foreach ($updateable_products as $item) { foreach ($updateable_products as $item) {
if (empty($item->product_key)) { if (empty($item->product_key)) {
continue; continue;
@ -106,13 +107,6 @@ class UpdateOrCreateProduct implements ShouldQueue
$product->quantity = isset($item->quantity) ? $item->quantity : 0; $product->quantity = isset($item->quantity) ? $item->quantity : 0;
} }
// $product->tax_name1 = isset($item->tax_name1) ? $item->tax_name1 : '';
// $product->tax_rate1 = isset($item->tax_rate1) ? $item->tax_rate1 : 0;
// $product->tax_name2 = isset($item->tax_name2) ? $item->tax_name2 : '';
// $product->tax_rate2 = isset($item->tax_rate2) ? $item->tax_rate2 : 0;
// $product->tax_name3 = isset($item->tax_name3) ? $item->tax_name3 : '';
// $product->tax_rate3 = isset($item->tax_rate3) ? $item->tax_rate3 : 0;
if (isset($item->custom_value1) && strlen($item->custom_value1) >=1) { if (isset($item->custom_value1) && strlen($item->custom_value1) >=1) {
$product->custom_value1 = $item->custom_value1; $product->custom_value1 = $item->custom_value1;
} }

View File

@ -42,7 +42,7 @@ class UpdateRecurring implements ShouldQueue
$this->user->setCompany($this->company); $this->user->setCompany($this->company);
RecurringInvoice::where('company_id', $this->company->id) RecurringInvoice::query()->where('company_id', $this->company->id)
->whereIn('id', $this->ids) ->whereIn('id', $this->ids)
->chunk(100, function ($recurring_invoices) { ->chunk(100, function ($recurring_invoices) {
foreach ($recurring_invoices as $recurring_invoice) { foreach ($recurring_invoices as $recurring_invoice) {

View File

@ -30,26 +30,17 @@ class UserEmailChanged implements ShouldQueue
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $new_user;
protected $old_user;
protected $company;
public $settings; public $settings;
/** /**
* Create a new job instance. * Create a new job instance.
* *
* @param string $new_email * @param \App\Models\User $new_user
* @param string $old_email * @param \App\Models\User $old_user
* @param Company $company * @param \App\Models\Company $company
*/ */
public function __construct(User $new_user, $old_user, Company $company) public function __construct(protected User $new_user, protected User $old_user, protected Company $company)
{ {
$this->new_user = $new_user;
$this->old_user = $old_user;
$this->company = $company;
$this->settings = $this->company->settings; $this->settings = $this->company->settings;
} }

View File

@ -37,7 +37,7 @@ class VerifyPhone implements ShouldQueue
/** /**
* Execute the job. * Execute the job.
* *
* @return User|null * @return void
*/ */
public function handle() : void public function handle() : void
{ {

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