Migration for dashboard permissions

This commit is contained in:
David Bomba 2023-08-06 17:03:12 +10:00
parent 5dfb031621
commit b13783d75b
57 changed files with 161 additions and 97 deletions

View File

@ -40,7 +40,7 @@ class SubscriptionCalculator
*/
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('client_id', $this->invoice->client_id)
->where('balance', '>', 0)

View File

@ -532,7 +532,7 @@ class BaseController extends Controller
/** @phpstan-ignore-next-line */
$query = $paginator->getCollection(); /** @phpstan-ignore-line */
/** @phpstan-ignore-line */
$resource = new Collection($query, $transformer, $this->entity_type);

View File

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

View File

@ -71,7 +71,7 @@ class DocumentController extends Controller
public function downloadMultiple(DownloadMultipleDocumentsRequest $request)
{
/** @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)
->get();

View File

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

View File

@ -40,13 +40,13 @@ class NinjaPlanController extends Controller
public function index(string $contact_key, string $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) {
MultiDB::findAndSetDbByAccountKey($account_or_company_key);
/** @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 {
$account = $company->account;
}
@ -181,7 +181,7 @@ class NinjaPlanController extends Controller
->increment()
->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('id', '!=', $recurring_invoice->id)
->first();

View File

@ -169,7 +169,7 @@ class PaymentController extends Controller
$payment = $payment->service()->applyCredits($payment_hash)->save();
/** @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) {
/** @var \App\Models\Invoice $invoice **/

View File

@ -95,7 +95,8 @@ class QuoteController extends Controller
/** @var \App\Models\ClientContact $client_contact **/
$client_contact = auth()->user();
$data['quotes'] = Quote::whereIn('id', $ids)
$data['quotes'] = Quote::query()
->whereIn('id', $ids)
->where('client_id', $client_contact->client_id)
->withTrashed()
->get();
@ -120,7 +121,8 @@ class QuoteController extends Controller
/** @var \App\Models\ClientContact $client_contact **/
$client_contact = auth()->user();
$quotes = Quote::whereIn('id', $ids)
$quotes = Quote::query()
->whereIn('id', $ids)
->whereClientId($client_contact->client_id)
->withTrashed()
->get();
@ -168,7 +170,8 @@ class QuoteController extends Controller
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('company_id', auth()->guard('contact')->user()->client->company_id)
->whereIn('status_id', [Quote::STATUS_DRAFT, Quote::STATUS_SENT])

View File

@ -148,10 +148,10 @@ class CreditController extends BaseController
*/
public function create(CreateCreditRequest $request)
{
/** @var \App\Models\User $user**/
/** @var \App\Models\User $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);
}
@ -197,11 +197,9 @@ class CreditController extends BaseController
public function store(StoreCreditRequest $request)
{
/** @var \App\Models\User $user**/
/** @var \App\Models\User $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 = $credit->service()
@ -506,7 +504,7 @@ class CreditController extends BaseController
public function bulk(BulkCreditRequest $request)
{
/** @var \App\Models\User $user**/
/** @var \App\Models\User $user **/
$user = auth()->user();
$action = $request->input('action');
@ -725,7 +723,7 @@ class CreditController extends BaseController
* Update the specified resource in storage.
*
* @param UploadCreditRequest $request
* @param Credit $client
* @param Credit $credit
* @return Response
*
*

View File

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

View File

@ -95,7 +95,7 @@ class PreviewPurchaseOrderController extends BaseController
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) {
return $this->blankEntity();

View File

@ -96,7 +96,7 @@ class DocumentController extends Controller
public function downloadMultiple(DownloadMultipleDocumentsRequest $request)
{
/** @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)
->get();

View File

@ -203,7 +203,8 @@ class PurchaseOrderController extends Controller
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)
->withTrashed()
->get();

View File

@ -19,7 +19,7 @@ class VendorContactHashLoginController extends Controller
/**
* Logs a user into the client portal using their contact_key
* @param string $contact_key The contact key
* @return Auth|Redirect
* @return Auth|\Illuminate\Support\Facades\Redirect
*/
public function login(string $contact_key)
{

View File

@ -52,7 +52,7 @@ class ValidCreditsPresentRule implements Rule
//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) {
$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']);
}

View File

@ -35,7 +35,7 @@ class ValidPayableInvoicesRule implements Rule
$invoices = [];
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) {

View File

@ -58,7 +58,7 @@ class ValidRefundableInvoices implements Rule
$invoices = [];
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 {
return true;
}

View File

@ -113,7 +113,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

View File

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

View File

@ -81,7 +81,7 @@ class PaymentFailedMailer implements ShouldQueue
if ($this->payment_hash) {
// $amount = array_sum(array_column($this->payment_hash->invoices(), 'amount')) + $this->payment_hash->fee_total;
$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

View File

@ -63,7 +63,7 @@ class AutoBillingFailureObject
/* Set customized translations _NOW_ */
$t->replace(Ninja::transformTranslations($this->company->settings));
$this->invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->get();
$this->invoices = Invoice::query()->whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->get();
$mail_obj = new stdClass;
$mail_obj->amount = $this->getAmount();

View File

@ -171,7 +171,7 @@ class InvoiceEmailEngine extends BaseEmailEngine
}
if (count($expense_ids) > 0) {
$expenses = Expense::whereIn('id', $this->transformKeys($expense_ids))
$expenses = Expense::query()->whereIn('id', $this->transformKeys($expense_ids))
->where('invoice_documents', 1)
->cursor()
->each(function ($expense) {
@ -192,7 +192,7 @@ class InvoiceEmailEngine extends BaseEmailEngine
}
if (count($task_ids) > 0 && $this->invoice->company->invoice_task_documents) {
$tasks = Task::whereIn('id', $this->transformKeys($task_ids))
$tasks = Task::query()->whereIn('id', $this->transformKeys($task_ids))
->cursor()
->each(function ($task) {
foreach ($task->documents as $document) {

View File

@ -87,6 +87,7 @@ use Laracasts\Presenter\PresentableTrait;
* @method static \Illuminate\Database\Eloquent\Builder|Account first()
* @method static \Illuminate\Database\Eloquent\Builder|Account with()
* @method static \Illuminate\Database\Eloquent\Builder|Account count()
* @method static \Illuminate\Database\Eloquent\Builder|Account where($query)
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\BankIntegration> $bank_integrations
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Company> $companies
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CompanyUser> $company_users
@ -215,7 +216,11 @@ class Account extends BaseModel
return $this->hasMany(CompanyUser::class);
}
public function owner(): \Illuminate\Database\Eloquent\Relations\HasMany
/**
* Returns the owner of the Account - not a HasMany relation
* @return \App\Models\User | bool
*/
public function owner()
{
return $this->hasMany(CompanyUser::class)->where('is_owner', true)->first() ? $this->hasMany(CompanyUser::class)->where('is_owner', true)->first()->user : false;
}

View File

@ -156,7 +156,7 @@ class BankTransaction extends BaseModel
public function account(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Account::class)->withTrashed();
return $this->belongsTo(Account::class);
}
public function payment(): \Illuminate\Database\Eloquent\Relations\BelongsTo

View File

@ -35,7 +35,11 @@ use Illuminate\Database\Eloquent\ModelNotFoundException as ModelNotFoundExceptio
* @property int $id
* @property int $user_id
* @property int $assigned_user_id
* @method BaseModel service()
* @property \App\Models\Company $company
* @method static BaseModel find($value)
* @method BaseModel company()
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel<static> company()
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel|Illuminate\Database\Eloquent\Relations\BelongsTo|\Awobaz\Compoships\Database\Eloquent\Relations\BelongsTo|\App\Models\Company company()
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel|Illuminate\Database\Eloquent\Relations\HasMany|BaseModel orderBy()
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel exclude($columns)
@ -43,26 +47,23 @@ use Illuminate\Database\Eloquent\ModelNotFoundException as ModelNotFoundExceptio
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel newModelQuery($query)
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel newQuery($query)
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel query()
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel exclude(array $excludeable)
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel|\Illuminate\Database\Query\Builder withTrashed(bool $withTrashed = true)
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel scopeExclude($query)
* @method static BaseModel find($value)
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel whereId($query)
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel whereIn($query)
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel where($query)
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel count()
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel create($query)
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel insert($query)
* @method BaseModel service()
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel orderBy($column, $direction)
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel invitations()
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel whereHas($query)
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\InvoiceInvitation | \App\Models\CreditInvitation | \App\Models\QuoteInvitation | \App\Models\RecurringInvoiceInvitation> $invitations
* @property-read int|null $invitations_count
* @method static \Illuminate\Database\Eloquent\Builder<static> company()
* @method int companyId()
* @method createInvitations()
* @method Builder scopeCompany(Builder $builder)
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel|\Illuminate\Database\Query\Builder withTrashed(bool $withTrashed = true)
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel|\Illuminate\Database\Query\Builder onlyTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel|\Illuminate\Database\Query\Builder withoutTrashed()
* @mixin \Eloquent
* @mixin \Illuminate\Database\Eloquent\Builder
*/

View File

@ -199,6 +199,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Vendor> $vendors
* @property-read int|null $vendors_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Webhook> $webhooks
* @method static \Illuminate\Database\Eloquent\Builder|Company where($query)
* @property-read int|null $webhooks_count
* @property int $calculate_taxes
* @property mixed $tax_data
@ -439,7 +440,7 @@ class Company extends BaseModel
return $this->encodePrimaryKey($this->id);
}
public function account()
public function account(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Account::class);
}
@ -449,7 +450,7 @@ class Company extends BaseModel
return $this->hasMany(ClientContact::class)->withTrashed();
}
public function users()
public function users(): \Illuminate\Database\Eloquent\Relations\HasManyThrough
{
return $this->hasManyThrough(User::class, CompanyUser::class, 'company_id', 'id', 'id', 'user_id')->withTrashed();
}

View File

@ -51,8 +51,8 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @property-read \App\Models\Company $company
* @property-read \App\Models\Gateway $gateway
* @property-read mixed $hashed_id
* @method getConfigField(string $field)
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel company()
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel exclude($columns)
* @method static \Illuminate\Database\Eloquent\Builder|CompanyGateway filter(\App\Filters\QueryFilters $filters)
* @method static \Illuminate\Database\Eloquent\Builder|CompanyGateway newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|CompanyGateway newQuery()

View File

@ -678,7 +678,7 @@ class Invoice extends BaseModel
}
}
return Expense::whereIn('id', $this->transformKeys($expense_ids))
return Expense::query()->whereIn('id', $this->transformKeys($expense_ids))
->where('invoice_documents', 1)
->where('company_id', $this->company_id)
->cursor();
@ -696,7 +696,7 @@ class Invoice extends BaseModel
}
}
return Task::whereIn('id', $this->transformKeys($task_ids))
return Task::query()->whereIn('id', $this->transformKeys($task_ids))
->whereHas('company', function ($query) {
$query->where('invoice_task_documents', 1);
})

View File

@ -86,29 +86,19 @@ use Illuminate\Support\Facades\Storage;
* @property int|null $updated_at
* @property int|null $expense_id
* @property int|null $currency_id
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Activity> $activities
* @property-read int|null $activities_count
* @property-read \App\Models\User|null $assigned_user
* @property-read \App\Models\Client|null $client
* @property-read \App\Models\Company $company
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
* @property-read int|null $documents_count
* @property-read \App\Models\Expense|null $expense
* @property-read mixed $hashed_id
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Backup> $history
* @property-read int|null $history_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\PurchaseOrderInvitation> $invitations
* @property-read int|null $invitations_count
* @property-read \App\Models\Invoice|null $invoice
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Invoice> $invoices
* @property-read int|null $invoices_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Payment> $payments
* @property-read int|null $payments_count
* @property-read \App\Models\Project|null $project
* @property-read \App\Models\User $user
* @property \App\Models\Vendor|null $vendor
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel company()
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel exclude($columns)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder company()
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder exclude($columns)
* @method static \Database\Factories\PurchaseOrderFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder filter(\App\Filters\QueryFilters $filters)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder newModelQuery()

View File

@ -108,7 +108,9 @@ use Laracasts\Presenter\PresentableTrait;
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Backup> $history
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\QuoteInvitation> $invitations
*
* @mixin \Eloquent
* @mixin \Illuminate\Database\Eloquent\Builder
*/
class Quote extends BaseModel
{

View File

@ -14,6 +14,8 @@ namespace App\Models\Traits;
use Illuminate\Support\Facades\Schema;
/**
* @method static Builder scopeExclude(Builder $builder)
* @method static Builder exclude(Builder $builder)
* @template TModelClass of \Illuminate\Database\Eloquent\Model
* @extends \Illuminate\Database\Eloquent\Builder<TModelClass>
* @mixin \Illuminate\Database\Eloquent\Builder
@ -33,6 +35,10 @@ trait Excludable
/**
* Exclude an array of elements from the result.
*
* @method static \Illuminate\Database\Eloquent\Builder<static> exclude($columns)
* @method static \Illuminate\Database\Eloquent\Builder<static> exclude($columns)
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $columns
*

View File

@ -280,7 +280,7 @@ class User extends Authenticatable implements MustVerifyEmail
*
* @return \App\Models\Company $company
*/
public function company(): Company
public function company(): \App\Models\Company
{
return $this->getCompany();
}

View File

@ -60,7 +60,7 @@ class AuthorizeTransaction
if ($this->authorize->payment_hash->data) {
$invoice_numbers = collect($this->authorize->payment_hash->data->invoices)->pluck('invoice_number')->implode(',');
$invObj = Invoice::whereIn('id', $this->transformKeys(array_column($this->authorize->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get();
$invObj = Invoice::query()->whereIn('id', $this->transformKeys(array_column($this->authorize->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get();
$po_numbers = $invObj->pluck('po_number')->implode(',');

View File

@ -56,7 +56,7 @@ class ChargePaymentProfile
if ($this->authorize->payment_hash->data) {
$invoice_numbers = collect($this->authorize->payment_hash->data->invoices)->pluck('invoice_number')->implode(',');
$invObj = Invoice::whereIn('id', $this->transformKeys(array_column($this->authorize->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get();
$invObj = Invoice::query()->whereIn('id', $this->transformKeys(array_column($this->authorize->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get();
$po_numbers = $invObj->pluck('po_number')->implode(',');

View File

@ -279,7 +279,7 @@ class BaseDriver extends AbstractPaymentDriver
public function attachInvoices(Payment $payment, PaymentHash $payment_hash): Payment
{
$paid_invoices = $payment_hash->invoices();
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($paid_invoices, 'invoice_id')))->withTrashed()->get();
$invoices = Invoice::query()->whereIn('id', $this->transformKeys(array_column($paid_invoices, 'invoice_id')))->withTrashed()->get();
$payment->invoices()->sync($invoices);
$payment->service()->applyNumber()->save();
@ -392,7 +392,7 @@ class BaseDriver extends AbstractPaymentDriver
$fee_total = $this->payment_hash->fee_total;
/*Hydrate invoices*/
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($payment_invoices, 'invoice_id')))->withTrashed()->get();
$invoices = Invoice::query()->whereIn('id', $this->transformKeys(array_column($payment_invoices, 'invoice_id')))->withTrashed()->get();
$invoices->each(function ($invoice) {
if (collect($invoice->line_items)->contains('type_id', '3')) {
@ -410,7 +410,7 @@ class BaseDriver extends AbstractPaymentDriver
*/
public function unWindGatewayFees(PaymentHash $payment_hash)
{
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->get();
$invoices = Invoice::query()->whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->get();
$invoices->each(function ($invoice) {
$invoice->service()->removeUnpaidGatewayFees();
@ -522,7 +522,7 @@ class BaseDriver extends AbstractPaymentDriver
$nmo->company = $this->client->company;
$nmo->settings = $this->client->company->settings;
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get();
$invoices = Invoice::query()->whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get();
$invoices->each(function ($invoice) {
$invoice->service()->deletePdf();
@ -567,7 +567,7 @@ class BaseDriver extends AbstractPaymentDriver
$nmo->company = $this->client->company;
$nmo->settings = $this->client->company->settings;
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get();
$invoices = Invoice::query()->whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get();
$invoices->each(function ($invoice) {
$invoice->service()->deletePdf();

View File

@ -238,7 +238,7 @@ class BraintreePaymentDriver extends BaseDriver
{
$amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total;
$invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first();
$invoice = Invoice::query()->whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first();
if ($invoice) {
$description = "Invoice {$invoice->number} for {$amount} for client {$this->client->present()->name()}";

View File

@ -324,7 +324,7 @@ class CheckoutComPaymentDriver extends BaseDriver
public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash)
{
$amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total;
$invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first();
$invoice = Invoice::query()->whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first();
$this->init();

View File

@ -163,7 +163,7 @@ class ACH implements MethodInterface
{
$this->go_cardless->ensureMandateIsReady($request->source);
$invoice = Invoice::whereIn('id', $this->transformKeys(array_column($this->go_cardless->payment_hash->invoices(), 'invoice_id')))
$invoice = Invoice::query()->whereIn('id', $this->transformKeys(array_column($this->go_cardless->payment_hash->invoices(), 'invoice_id')))
->withTrashed()
->first();

View File

@ -257,7 +257,7 @@ class DirectDebit implements MethodInterface
{
$this->go_cardless->ensureMandateIsReady($request->source);
$invoice = Invoice::whereIn('id', $this->transformKeys(array_column($this->go_cardless->payment_hash->invoices(), 'invoice_id')))
$invoice = Invoice::query()->whereIn('id', $this->transformKeys(array_column($this->go_cardless->payment_hash->invoices(), 'invoice_id')))
->withTrashed()
->first();

View File

@ -162,7 +162,7 @@ class SEPA implements MethodInterface
{
$this->go_cardless->ensureMandateIsReady($request->source);
$invoice = Invoice::whereIn('id', $this->transformKeys(array_column($this->go_cardless->payment_hash->invoices(), 'invoice_id')))
$invoice = Invoice::query()->whereIn('id', $this->transformKeys(array_column($this->go_cardless->payment_hash->invoices(), 'invoice_id')))
->withTrashed()
->first();

View File

@ -327,7 +327,7 @@ class GoCardlessPaymentDriver extends BaseDriver
);
if ($billing_request->status === 'fulfilled') {
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($hash->invoices(), 'invoice_id')))->withTrashed()->get();
$invoices = Invoice::query()->whereIn('id', $this->transformKeys(array_column($hash->invoices(), 'invoice_id')))->withTrashed()->get();
$this->client = $invoices->first()->client;

View File

@ -194,7 +194,7 @@ class MolliePaymentDriver extends BaseDriver
public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash)
{
$amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total;
$invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first();
$invoice = Invoice::query()->whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first();
if ($invoice) {
$description = "Invoice {$invoice->number} for {$amount} for client {$this->client->present()->name()}";

View File

@ -114,7 +114,7 @@ class SquarePaymentDriver extends BaseDriver
$amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total;
$amount = $this->convertAmount($amount);
$invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first();
$invoice = Invoice::query()->whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first();
if ($invoice) {
$description = "Invoice {$invoice->number} for {$amount} for client {$this->client->present()->name()}";

View File

@ -52,7 +52,7 @@ class BankTransactionRepository extends BaseRepository
$bt->payment_id = null;
}
$e = Expense::whereIn('id', $this->transformKeys(explode(",", $bt->expense_id)))
$e = Expense::query()->whereIn('id', $this->transformKeys(explode(",", $bt->expense_id)))
->cursor()
->each(function ($expense){

View File

@ -120,7 +120,7 @@ class PaymentMigrationRepository extends BaseRepository
$invoice_totals = array_sum(array_column($data['invoices'], 'amount'));
$refund_totals = array_sum(array_column($data['invoices'], 'refunded'));
$invoices = Invoice::whereIn('id', array_column($data['invoices'], 'invoice_id'))->withTrashed()->get();
$invoices = Invoice::query()->whereIn('id', array_column($data['invoices'], 'invoice_id'))->withTrashed()->get();
$payment->invoices()->saveMany($invoices); // 1:1 relationship so this is ok
@ -150,7 +150,7 @@ class PaymentMigrationRepository extends BaseRepository
/** @var float $credit_totals **/
$credit_totals = array_sum(array_column($data['credits'], 'amount'));
$credits = Credit::whereIn('id', array_column($data['credits'], 'credit_id'))->withTrashed()->get();
$credits = Credit::query()->whereIn('id', array_column($data['credits'], 'credit_id'))->withTrashed()->get();
$payment->credits()->saveMany($credits);

View File

@ -170,7 +170,7 @@ class PaymentRepository extends BaseRepository
if (array_key_exists('credits', $data) && is_array($data['credits'])) {
$credit_totals = array_sum(array_column($data['credits'], 'amount'));
$credits = Credit::whereIn('id', array_column($data['credits'], 'credit_id'))->get();
$credits = Credit::query()->whereIn('id', array_column($data['credits'], 'credit_id'))->get();
//todo optimize into a single query
foreach ($data['credits'] as $paid_credit) {

View File

@ -60,7 +60,7 @@ class InstantPayment
* ['invoice_id' => xxx, 'amount' => 22.00]
*/
$payable_invoices = collect($this->request->payable_invoices);
$invoices = Invoice::whereIn('id', $this->transformKeys($payable_invoices->pluck('invoice_id')->toArray()))->withTrashed()->get();
$invoices = Invoice::query()->whereIn('id', $this->transformKeys($payable_invoices->pluck('invoice_id')->toArray()))->withTrashed()->get();
$invoices->each(function ($invoice) {
$invoice->service()

View File

@ -42,7 +42,8 @@ class CreateInvitations extends AbstractService
}
$contacts->each(function ($contact) {
$invitation = CreditInvitation::whereCompanyId($this->credit->company_id)
$invitation = CreditInvitation::query()
->where('company_id', $this->credit->company_id)
->whereClientContactId($contact->id)
->whereCreditId($this->credit->id)
->withTrashed()

View File

@ -361,7 +361,7 @@ class EmailDefaults
}
if (count($expense_ids) > 0) {
Expense::whereIn('id', $this->transformKeys($expense_ids))
Expense::query()->whereIn('id', $this->transformKeys($expense_ids))
->where('invoice_documents', 1)
->cursor()
->each(function ($expense) {
@ -370,7 +370,7 @@ class EmailDefaults
}
if (count($task_ids) > 0 && $this->email->company->invoice_task_documents) {
Task::whereIn('id', $this->transformKeys($task_ids))
Task::query()->whereIn('id', $this->transformKeys($task_ids))
->cursor()
->each(function ($task) {
$this->email->email_object->documents = array_merge($this->email->email_object->documents, $task->documents->pluck('id')->toArray());

View File

@ -57,7 +57,7 @@ class EmailMailable extends Mailable
*/
public function content()
{
$links = Document::whereIn('id', $this->email_object->documents)
$links = Document::query()->whereIn('id', $this->email_object->documents)
->where('size', '>', $this->max_attachment_size)
->cursor()
->map(function ($document) {
@ -94,7 +94,7 @@ class EmailMailable extends Mailable
return Attachment::fromData(fn () => base64_decode($file['file']), $file['name']);
});
$documents = Document::whereIn('id', $this->email_object->documents)
$documents = Document::query()->whereIn('id', $this->email_object->documents)
->where('size', '<', $this->max_attachment_size)
->cursor()
->map(function ($document) {

View File

@ -541,8 +541,8 @@ class InvoiceService
return $item;
});
Task::whereIn('id', $tasks->pluck('task_id'))->update(['invoice_id' => $this->invoice->id]);
Expense::whereIn('id', $tasks->pluck('expense_id'))->update(['invoice_id' => $this->invoice->id]);
Task::query()->whereIn('id', $tasks->pluck('task_id'))->update(['invoice_id' => $this->invoice->id]);
Expense::query()->whereIn('id', $tasks->pluck('expense_id'))->update(['invoice_id' => $this->invoice->id]);
return $this;
}

View File

@ -38,7 +38,7 @@ class UpdateInvoicePayment
{
$paid_invoices = $this->payment_hash->invoices();
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($paid_invoices, 'invoice_id')))->withTrashed()->get();
$invoices = Invoice::query()->whereIn('id', $this->transformKeys(array_column($paid_invoices, 'invoice_id')))->withTrashed()->get();
$client = $this->payment->client;

View File

@ -41,7 +41,8 @@ class CreateInvitations
}
$contacts->each(function ($contact) {
$invitation = QuoteInvitation::whereCompanyId($this->quote->company_id)
$invitation = QuoteInvitation::query()
->where('company_id',$this->quote->company_id)
->whereClientContactId($contact->id)
->whereQuoteId($this->quote->id)
->withTrashed()

View File

@ -574,7 +574,7 @@ class SubscriptionService
$credit = false;
/* Get last invoice */
$last_invoice = Invoice::where('subscription_id', $recurring_invoice->subscription_id)
$last_invoice = Invoice::query()->where('subscription_id', $recurring_invoice->subscription_id)
->where('client_id', $recurring_invoice->client_id)
->where('is_proforma', 0)
->where('is_deleted', 0)
@ -1166,7 +1166,7 @@ class SubscriptionService
$keys = $this->transformKeys(explode(",", $this->subscription->product_ids));
if (is_array($keys)) {
return Product::whereIn('id', $keys)->get();
return Product::query()->whereIn('id', $keys)->get();
} else {
return Product::where('id', $keys)->get();
}
@ -1186,7 +1186,7 @@ class SubscriptionService
$keys = $this->transformKeys(explode(",", $this->subscription->recurring_product_ids));
if (is_array($keys)) {
return Product::whereIn('id', $keys)->get();
return Product::query()->whereIn('id', $keys)->get();
} else {
return Product::where('id', $keys)->get();
}
@ -1207,7 +1207,7 @@ class SubscriptionService
$keys = $this->transformKeys(explode(",", $this->subscription->optional_product_ids));
if (is_array($keys)) {
return Product::whereIn('id', $keys)->get();
return Product::query()->whereIn('id', $keys)->get();
} else {
return Product::where('id', $keys)->get();
}
@ -1227,7 +1227,7 @@ class SubscriptionService
$keys = $this->transformKeys(explode(",", $this->subscription->optional_recurring_product_ids));
if (is_array($keys)) {
return Product::whereIn('id', $keys)->get();
return Product::query()->whereIn('id', $keys)->get();
} else {
return Product::where('id', $keys)->get();
}

View File

@ -69,7 +69,7 @@ trait GeneratesConvertedQuoteCounter
$number = $this->applyNumberPattern($invoice, $number, $pattern);
$check = Invoice::whereCompanyId($client->company_id)->whereNumber($number)->withTrashed()->exists();
$check = Invoice::query()->whereCompanyId($client->company_id)->whereNumber($number)->withTrashed()->exists();
if ($check) {
return false;

View File

@ -0,0 +1,45 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
\App\Models\CompanyUser::where('is_admin', 0)->cursor()->each(function ($cu) {
$permissions = $cu->permissions;
if (!$permissions || strlen($permissions) == 0) {
$permissions = 'view_dashboard';
$cu->permissions = $permissions;
$cu->save();
} else {
$permissions_array = explode(',', $permissions);
$permissions_array[] = 'view_dashboard';
$modified_permissions_string = implode(",", $permissions_array);
$cu->permissions = $modified_permissions_string;
$cu->save();
}
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
};

View File

@ -18,4 +18,5 @@ parameters:
- '#Call to an undefined method [a-zA-Z0-9\\_]+::company\(\)#'
- '#Call to an undefined method [a-zA-Z0-9\\_]+::entityFilter\(\)#'
- '#Call to an undefined method [a-zA-Z0-9\\_]+::withTrashed\(\)#'
- '#Call to an undefined method [a-zA-Z0-9\\_]+::exclude\(\)#'
- '#Undefined method#'