1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-22 01:11:34 +02:00

Merge pull request #8701 from turbo124/v5-stable

v5.6.27
This commit is contained in:
David Bomba 2023-08-08 17:57:31 +10:00 committed by GitHub
commit 44b01b94ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
208 changed files with 778 additions and 764 deletions

View File

@ -1 +1 @@
5.6.26
5.6.27

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->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;
$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 ?? 0;
return $this;

View File

@ -94,7 +94,6 @@ class BaseExport
"state" => "client.state",
"postal_code" => "client.postal_code",
"country" => "client.country_id",
"custom_value4" => "contact.custom_value4",
"shipping_address1" => "client.shipping_address1",
"shipping_address2" => "client.shipping_address2",
"shipping_city" => "client.shipping_city",
@ -109,6 +108,15 @@ class BaseExport
"first_name" => "contact.first_name",
"last_name" => "contact.last_name",
"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 = [

View File

@ -85,7 +85,7 @@ class ProductSalesExport extends BaseExport
$t = app('translator');
$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
$this->csv = Writer::createFromString();
@ -187,6 +187,7 @@ class ProductSalesExport extends BaseExport
$product = $this->getProduct($entity['product_key']);
$entity['cost'] = $product->cost ?? 0;
/** @var float $unit_cost */
$unit_cost = $entity['cost'] == 0 ? 1 : $entity['cost'];
$entity['client'] = $invoice->client->present()->name();

View File

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

View File

@ -72,8 +72,8 @@ abstract class QueryFilters
/**
* Apply the filters to the builder.
*
* @param Builder $builder
* @return Builder
* @param \Illuminate\Database\Eloquent\Builder $builder
* @return \Illuminate\Database\Eloquent\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')
{
if ($value == 'true') {

View File

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

View File

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

View File

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

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

@ -530,9 +530,8 @@ class BaseController extends Controller
$paginator = $query->paginate($limit);
/** @phpstan-ignore-next-line */
$query = $paginator->getCollection(); /** @phpstan-ignore-line */
/** @phpstan-ignore-next-line **/
$query = $paginator->getCollection();
$resource = new Collection($query, $transformer, $this->entity_type);
@ -636,7 +635,7 @@ class BaseController extends Controller
$paginator = $query->paginate($limit);
/** @phpstan-ignore-next-line */
/** @phpstan-ignore-next-line **/
$query = $paginator->getCollection();
$resource = new Collection($query, $transformer, $this->entity_type);
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
@ -885,7 +884,7 @@ class BaseController extends Controller
$paginator = $query->paginate($limit);
/** @phpstan-ignore-next-line */
/** @phpstan-ignore-next-line **/
$query = $paginator->getCollection();
$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,6 +87,7 @@ 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']),
@ -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;
}
@ -157,6 +157,8 @@ class NinjaPlanController extends Controller
//create recurring invoice
$subscription_repo = new SubscriptionRepository();
/** @var \App\Models\Subscription $subscription **/
$subscription = Subscription::find(6);
$recurring_invoice = RecurringInvoiceFactory::create($subscription->company_id, $subscription->user_id);
@ -181,7 +183,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();
@ -215,7 +217,7 @@ class NinjaPlanController extends Controller
$data['late_invoice'] = false;
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) {
//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();
/** @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,8 +95,9 @@ class QuoteController extends Controller
/** @var \App\Models\ClientContact $client_contact **/
$client_contact = auth()->user();
$data['quotes'] = Quote::whereIn('id', $ids)
->whereClientId($client_contact->client->id)
$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])
@ -195,10 +198,10 @@ class QuoteController extends Controller
}
}
if (count($ids) == 1) {
if ($quotes->count() == 1) {
//forward client to the invoice if it exists
if ($quote->invoice()->exists()) {
return redirect()->route('client.invoice.show', $quote->invoice->hashed_id);
if ($quotes->first()->invoice()->exists()) {
return redirect()->route('client.invoice.show', $quotes->first()->invoice->hashed_id);
}
return redirect()->route('client.quote.show', $quotes->first()->hashed_id);

View File

@ -151,7 +151,7 @@ class CreditController extends BaseController
/** @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);
}
@ -200,8 +200,6 @@ class CreditController extends BaseController
/** @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()
@ -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

@ -125,7 +125,6 @@ class EmailController extends BaseController
$this->entity_transformer = PurchaseOrderTransformer::class;
}
// @phpstan-ignore-next-line
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);
}
$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();
@ -181,6 +181,7 @@ class PreviewPurchaseOrderController extends BaseController
DB::connection(config('database.default'))->beginTransaction();
if ($request->has('entity_id')) {
/** @var \App\Models\PurchaseOrder|\Illuminate\Database\Eloquent\Builder $entity_obj **/
$entity_obj = $class::on(config('database.default'))
->with('vendor.company')
->where('id', $this->decodePrimaryKey($request->input('entity_id')))

View File

@ -328,7 +328,10 @@ class TaskController extends BaseController
*/
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);
}
@ -373,10 +376,13 @@ class TaskController extends BaseController
*/
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);
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);
@ -499,7 +505,9 @@ class TaskController extends BaseController
$tasks = Task::withTrashed()->find($this->transformKeys($ids));
$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);
}
});
@ -622,9 +630,12 @@ class TaskController extends BaseController
$task_statuses = $request->input('status_ids');
$tasks = $request->input('task_ids');
collect($task_statuses)->each(function ($task_status_hashed_id, $key) {
$task_status = TaskStatus::where('id', $this->decodePrimaryKey($task_status_hashed_id))
->where('company_id', auth()->user()->company()->id)
/** @var \App\Models\User $user */
$user = auth()->user();
collect($task_statuses)->each(function ($task_status_hashed_id, $key) use($user){
$task_status = TaskStatus::query()->where('id', $this->decodePrimaryKey($task_status_hashed_id))
->where('company_id', $user->company()->id)
->withTrashed()
->first();
@ -636,8 +647,8 @@ class TaskController extends BaseController
$sort_status_id = $this->decodePrimaryKey($key);
foreach ($task_list as $key => $task) {
$task_record = Task::where('id', $this->decodePrimaryKey($task))
->where('company_id', auth()->user()->company()->id)
$task_record = Task::query()->where('id', $this->decodePrimaryKey($task))
->where('company_id', $user->company()->id)
->withTrashed()
->first();

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,13 +19,17 @@ 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)
{
return redirect('/vendors/purchase_orders');
}
/**
* @return \Illuminate\Support\Facades\Redirect
*/
public function magicLink(string $magic_link)
{
return redirect($this->setRedirectPath());

View File

@ -298,7 +298,10 @@ class WebhookController extends BaseController
*/
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->save();
@ -483,7 +486,10 @@ class WebhookController extends BaseController
$webhooks = Webhook::withTrashed()->find($this->transformKeys($ids));
$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);
}
});
@ -493,6 +499,8 @@ class WebhookController extends BaseController
public function retry(RetryWebhookRequest $request, Webhook $webhook)
{
$includes = '';
match ($request->entity) {
'invoice' => $includes ='client',
'payment' => $includes ='invoices,client',
@ -504,13 +512,16 @@ class WebhookController extends BaseController
$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) {
return response()->json(['message' => ctrans('texts.record_not_found')], 400);
}
WebhookSingle::dispatchSync($webhook->id, $entity, auth()->user()->company()->db, $includes);
/** @var \App\Models\User $user */
$user = auth()->user();
WebhookSingle::dispatchSync($webhook->id, $entity, $user->company()->db, $includes);
return $this->itemResponse($webhook);
}

View File

@ -78,7 +78,6 @@ class BillingPortalPurchase extends Component
/**
* Rules for validating the form.
*
* @var \string[][]
*/
protected $rules = [
'email' => ['required', 'email'],
@ -187,7 +186,7 @@ class BillingPortalPurchase extends Component
{
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;

View File

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

View File

@ -89,9 +89,12 @@ class InvoicesTable extends Component
->withTrashed()
->paginate($this->per_page);
/** @var \App\Models\ClientContact $client_contact */
$client_contact = auth()->user();
return render('components.livewire.invoices-table', [
'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);
$this->is_disabled = $this->token->is_default;
// $this->is_disabled = $this->token->is_default;
}
public function makeDefault(): void

View File

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

View File

@ -53,7 +53,7 @@ class WepaySignup extends Component
public $saved;
public $company;
public Company $company;
protected $rules = [
'first_name' => ['required'],
@ -71,7 +71,7 @@ class WepaySignup extends Component
MultiDB::setDb($this->company->db);
$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([
'wepay_payment_tos_agree' => '',
@ -100,7 +100,7 @@ class WepaySignup extends Component
$data = $this->validate($this->rules);
//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)
->firstOrNew();
@ -165,6 +165,7 @@ class WepaySignup extends Component
}
$wepay_account = $wepay->request('account/create/', $account_details);
$confirmation_required = false;
try {
$wepay->request('user/send_confirmation/', []);
@ -173,6 +174,8 @@ class WepaySignup extends Component
if ($ex->getMessage() == 'This access_token is already approved.') {
$confirmation_required = false;
} else {
/** @phpstan-ignore-next-line */
request()->session()->flash('message', $ex->getMessage());
}
@ -195,6 +198,8 @@ class WepaySignup extends Component
$cg->save();
if ($confirmation_required) {
/** @phpstan-ignore-next-line **/
request()->session()->flash('message', trans('texts.created_wepay_confirmation_required'));
} else {
$update_uri = $wepay->request('/account/get_update_uri', [

View File

@ -25,7 +25,10 @@ class ClientPortalEnabled
*/
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.']);
}

View File

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

View File

@ -67,7 +67,7 @@ class ContactKeyLogin
}
} elseif ($request->segment(3) && config('ninja.db.multi_db_enabled')) {
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) {
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')) {
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();
if (empty($primary_contact->email)) {
@ -121,7 +121,7 @@ class ContactKeyLogin
}
}
} 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();
if (empty($primary_contact->email)) {
@ -134,7 +134,7 @@ class ContactKeyLogin
return redirect($this->setRedirectPath());
}
} 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) {
return redirect()->route('client.login', ['company_key' => $client_contact->company->company_key]);
}

View File

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

View File

@ -38,7 +38,8 @@ class PasswordProtection
];
/** @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) {
$timeout = 30*60*1000*1000;

View File

@ -49,7 +49,7 @@ class VendorContactKeyLogin
$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)) {
$vendor_contact->email = Str::random(15).'@example.com';
}
@ -65,7 +65,7 @@ class VendorContactKeyLogin
}
} elseif ($request->segment(3) && config('ninja.db.multi_db_enabled')) {
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)) {
$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)) {
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)) {
$vendor_contact->email = Str::random(6).'@example.com';
$vendor_contact->save();
@ -97,7 +97,7 @@ class VendorContactKeyLogin
}
} elseif ($request->has('vendor_hash') && config('ninja.db.multi_db_enabled')) {
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();
if (empty($primary_contact->email)) {
@ -111,7 +111,7 @@ class VendorContactKeyLogin
}
}
} 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();
if (empty($primary_contact->email)) {
@ -124,7 +124,7 @@ class VendorContactKeyLogin
return redirect($this->setRedirectPath());
}
} 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)) {
$vendor_contact->email = Str::random(6).'@example.com';
$vendor_contact->save();

View File

@ -18,7 +18,7 @@ class VerifyHash
public function handle($request, Closure $next)
{
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) {
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 */
$user = auth()->user();
return $user->isAdmin();
return $user->isAdmin() || $user->hasPermission('view_dashboard');
}
public function rules()
@ -42,10 +42,14 @@ class ShowChartRequest extends Request
public function prepareForValidation()
{
/**@var \App\Models\User auth()->user */
$user = auth()->user();
$input = $this->all();
if(isset($input['date_range'])) {
$dates = $this->calculateStartAndEndDates($input, auth()->user()->company());
$dates = $this->calculateStartAndEndDates($input, $user->company());
$input['start_date'] = $dates[0];
$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
if ($this->key) {
return Company::where('company_key', $this->key)->first();
return Company::query()->where('company_key', $this->key)->first();
}
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()) {
$company = Account::first()->default_company;
$company = Account::query()->first()->default_company;
if (! $company->client_can_register) {
abort(403, 'This page is restricted');

View File

@ -12,7 +12,6 @@
namespace App\Http\Requests\ClientPortal;
use App\Http\Requests\Request;
use Zend\Diactoros\Response\JsonResponse;
class StoreDocumentRequest extends Request
{
@ -35,6 +34,6 @@ class StoreDocumentRequest extends Request
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
{
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
{
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()
@ -47,7 +49,7 @@ class StoreCompanyRequest extends Request
$rules['portal_domain'] = 'sometimes|url';
} else {
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 {
$rules['subdomain'] = 'nullable|alpha_num';
}

View File

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

View File

@ -31,7 +31,11 @@ class StoreRecurringInvoiceRequest extends Request
*/
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()
@ -137,7 +141,8 @@ class StoreRecurringInvoiceRequest extends Request
if (isset($input['auto_bill'])) {
$input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']);
} 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_enabled'] = $this->setAutoBillFlag($input['auto_bill']);
}

View File

@ -31,11 +31,17 @@ class UpdateRecurringInvoiceRequest extends Request
*/
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()
{
/** @var \App\Models\User auth()->user() */
$user = auth()->user();
$rules = [];
if ($this->file('documents') && is_array($this->file('documents'))) {
@ -51,7 +57,7 @@ class UpdateRecurringInvoiceRequest extends Request
}
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())];
@ -138,7 +144,7 @@ class UpdateRecurringInvoiceRequest extends Request
* off / optin / optout will reset the status of this field to off to allow
* 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
*/

View File

@ -30,11 +30,19 @@ class StoreRecurringQuoteRequest extends Request
*/
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()
{
/** @var \App\Models\User auth()->user() */
$user = auth()->user();
$rules = [];
if ($this->file('documents') && is_array($this->file('documents'))) {
@ -49,7 +57,7 @@ class StoreRecurringQuoteRequest extends Request
$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';
@ -71,6 +79,7 @@ class StoreRecurringQuoteRequest extends Request
$input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']);
} else {
if ($client = Client::find($input['client_id'])) {
/** @var \App\Models\Client $client */
$input['auto_bill'] = $client->getSetting('auto_bill');
$input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']);
}

View File

@ -74,7 +74,7 @@ class StoreShopClientRequest extends Request
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();
@ -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!!
if (! property_exists($settings, 'currency_id') && isset($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)) {
$settings->currency_id = (string) $group_settings->settings->currency_id;

View File

@ -57,6 +57,6 @@ class CreateStatementRequest extends Request
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()
{
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;
}

View File

@ -49,7 +49,7 @@ class UniqueCreditNumberRule implements Rule
*/
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'])
->withTrashed()
->exists();

View File

@ -53,7 +53,7 @@ class UniqueInvoiceNumberRule implements Rule
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'])
->withTrashed()
->exists();

View File

@ -19,13 +19,14 @@ use Illuminate\Contracts\Validation\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)
{
$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;
}

View File

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

View File

@ -49,7 +49,7 @@ class UniqueQuoteNumberRule implements Rule
*/
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'])
->withTrashed()
->exists();

View File

@ -53,7 +53,7 @@ class UniqueRecurringInvoiceNumberRule implements Rule
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'])
->withTrashed()
->exists();

View File

@ -53,7 +53,7 @@ class UniqueRecurringQuoteNumberRule implements Rule
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'])
->withTrashed()
->exists();

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

@ -26,7 +26,10 @@ class ValidUserForCompany implements Rule
*/
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');
}
/** @var string $base64_encoded_csv */
$base64_encoded_csv = Cache::pull($this->hash.'-'.$entity_type);
if (empty($base64_encoded_csv)) {
@ -103,7 +104,7 @@ class BaseImport
$csv = base64_decode($base64_encoded_csv);
$csv = mb_convert_encoding($csv, 'UTF-8', 'UTF-8');
nlog($csv);
$csv = Reader::createFromString($csv);
$csvdelimiter = self::detectDelimiter($csv);

View File

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

View File

@ -176,7 +176,7 @@ class BaseTransformer
public function getClient($client_name, $client_email)
{
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('id_number', $client_name);
@ -184,7 +184,7 @@ class BaseTransformer
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)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $client_name)),
@ -195,7 +195,7 @@ class BaseTransformer
}
}
if (! empty($client_email)) {
$contacts = ClientContact::whereHas('client', function ($query) {
$contacts = ClientContact::query()->whereHas('client', function ($query) {
$query->where('is_deleted', false);
})
->where('company_id', $this->company->id)
@ -238,7 +238,7 @@ class BaseTransformer
*/
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)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
@ -248,7 +248,7 @@ class BaseTransformer
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('id_number', trim($id_number))
->exists();
@ -262,7 +262,7 @@ class BaseTransformer
*/
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)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
@ -277,7 +277,7 @@ class BaseTransformer
*/
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)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
@ -292,7 +292,7 @@ class BaseTransformer
*/
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)
->whereRaw("LOWER(REPLACE(`product_key`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $key)),
@ -341,7 +341,7 @@ class BaseTransformer
*/
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)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
@ -358,7 +358,7 @@ class BaseTransformer
*/
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)
->whereRaw("LOWER(REPLACE(`product_key`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $key)),
@ -375,7 +375,7 @@ class BaseTransformer
*/
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`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $email)),
])
@ -400,7 +400,7 @@ class BaseTransformer
return $this->getCountryIdBy2($name);
}
$country = Country::whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
$country = Country::query()->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
])->first();
@ -414,8 +414,8 @@ class BaseTransformer
*/
public function getCountryIdBy2($name)
{
return Country::where('iso_3166_2', $name)->exists()
? Country::where('iso_3166_2', $name)->first()->id
return Country::query()->where('iso_3166_2', $name)->exists()
? Country::query()->where('iso_3166_2', $name)->first()->id
: null;
}
@ -428,7 +428,7 @@ class BaseTransformer
{
$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)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
@ -447,7 +447,7 @@ class BaseTransformer
{
$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)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
@ -495,7 +495,7 @@ class BaseTransformer
*/
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)
->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $invoice_number)),
@ -512,7 +512,7 @@ class BaseTransformer
*/
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)
->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $invoice_number)),
@ -528,7 +528,7 @@ class BaseTransformer
*/
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)
->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $invoice_number)),
@ -541,7 +541,7 @@ class BaseTransformer
*/
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)
->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $expense_number)),
@ -556,7 +556,7 @@ class BaseTransformer
*/
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)
->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $quote_number)),
@ -571,7 +571,7 @@ class BaseTransformer
*/
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)
->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $invoice_number)),
@ -588,7 +588,7 @@ class BaseTransformer
*/
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)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
@ -626,7 +626,7 @@ class BaseTransformer
{
/** @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)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
@ -669,7 +669,7 @@ class BaseTransformer
*/
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)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
@ -700,7 +700,7 @@ class BaseTransformer
*/
public function getPaymentTypeId($name)
{
$pt = PaymentType::whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
$pt = PaymentType::query()->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
])->first();

View File

@ -102,7 +102,7 @@ class InvoiceTransformer extends BaseTransformer
$client_name = $this->getString($invoice_data, 'Customer Name');
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)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $client_name)),
@ -115,7 +115,7 @@ class InvoiceTransformer extends BaseTransformer
$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('id_number', trim($customer_id));

View File

@ -47,10 +47,12 @@ class MatchBankTransactions implements ShouldQueue
private array $input;
/** @var \App\Models\Company */
protected ?Company $company;
public Invoice $invoice;
/** @var \App\Models\BankTransaction $bt */
private ?BankTransaction $bt;
private $categories;
@ -83,7 +85,7 @@ class MatchBankTransactions implements ShouldQueue
{
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) {
$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
@ -193,7 +195,7 @@ class MatchBankTransactions implements ShouldQueue
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) {
return $this;
@ -243,7 +245,7 @@ class MatchBankTransactions implements ShouldQueue
private function matchExpense($input) :self
{
//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) {
return $this;

View File

@ -158,7 +158,7 @@ class ProcessBankTransactions implements ShouldQueue
$now = now();
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;
}

View File

@ -48,9 +48,9 @@ class CompanyExport implements ShouldQueue
/**
* Create a new job instance.
*
* @param Company $company
* @param User $user
* @param string $custom_token_name
* @param \App\Models\Company $company
* @param \App\Models\User $user
* @param 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);
$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);
@ -187,7 +187,7 @@ class CompanyExport implements ShouldQueue
})->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']);
return $credit->makeVisible(['id']);
@ -236,7 +236,7 @@ class CompanyExport implements ShouldQueue
})->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']);
return $invoice->makeVisible(['id']);
@ -280,7 +280,7 @@ class CompanyExport implements ShouldQueue
})->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']);
return $quote->makeVisible(['id']);
@ -301,7 +301,7 @@ class CompanyExport implements ShouldQueue
})->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']);
return $ri;
@ -381,7 +381,7 @@ class CompanyExport implements ShouldQueue
'company_id',]);
})->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']);
return $purchase_order->makeVisible(['id']);

View File

@ -244,7 +244,7 @@ class CompanyImport implements ShouldQueue
{
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->company_owner = $this->company->owner();
@ -591,6 +591,7 @@ class CompanyImport implements ShouldQueue
unset($obj_array['id']);
unset($obj_array['tax_rate_id']);
/** @var \App\Models\TaxRate $new_obj */
$new_obj = TaxRate::firstOrNew(
['name' => $obj->name, 'company_id' => $this->company->id, 'rate' => $obj->rate],
$obj_array,
@ -1427,7 +1428,7 @@ class CompanyImport implements ShouldQueue
if ($class == 'App\Models\Subscription') {
$obj_array['product_ids'] = $this->recordProductIds($obj_array['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(

View File

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

View File

@ -49,7 +49,8 @@ class AutoBillCron
Auth::logout();
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])
->where('auto_bill_enabled', true)
->where('auto_bill_tries', '<', 3)
@ -70,7 +71,8 @@ class AutoBillCron
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])
->where('auto_bill_enabled', true)
->where('auto_bill_tries', '<', 3)
@ -95,7 +97,8 @@ class AutoBillCron
foreach (MultiDB::$dbs as $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])
->where('auto_bill_enabled', true)
->where('auto_bill_tries', '<', 3)
@ -116,7 +119,8 @@ class AutoBillCron
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])
->where('auto_bill_enabled', true)
->where('auto_bill_tries', '<', 3)

View File

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

View File

@ -43,7 +43,7 @@ class UpdateCalculatedFields
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));
})
->cursor()
@ -61,7 +61,7 @@ class UpdateCalculatedFields
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));
})
->cursor()

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

@ -47,19 +47,19 @@ class CreateEntityPdf implements ShouldQueue
{
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;
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;
@ -135,6 +135,7 @@ class CreateEntityPdf implements ShouldQueue
$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);
/* Catch all in case migration doesn't pass back a valid design */

View File

@ -71,7 +71,7 @@ class AdjustProductInventory implements ShouldQueue
collect($this->invoice->line_items)->filter(function ($item) {
return $item->type_id == '1';
})->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) {
$p->in_stock_quantity += $i->quantity;
@ -88,7 +88,7 @@ class AdjustProductInventory implements ShouldQueue
collect($this->invoice->line_items)->filter(function ($item) {
return $item->type_id == '1';
})->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) {
$p->in_stock_quantity -= $i->quantity;
@ -109,7 +109,7 @@ class AdjustProductInventory implements ShouldQueue
collect($this->invoice->line_items)->filter(function ($item) {
return $item->type_id == '1';
})->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) {
$p->in_stock_quantity -= $i->quantity;

View File

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

View File

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

View File

@ -25,8 +25,6 @@ class InvoiceWorkflowSettings implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $invoice;
public $client;
private $base_repository;
@ -35,11 +33,9 @@ class InvoiceWorkflowSettings implements ShouldQueue
* Create a new job instance.
*
* @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();
}

View File

@ -51,7 +51,7 @@ class NinjaMailerJob implements ShouldQueue
public $override;
/* @var Company $company*/
/* @var \App\Models\Company $company*/
public ?Company $company;
private $mailer;

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

@ -39,20 +39,14 @@ class ProcessPostmarkWebhook implements ShouldQueue
public $tries = 1;
private array $request;
public $invitation;
/**
* 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;
});
/** @var \App\DataMapper\InvoiceItem $item */
foreach ($updateable_products as $item) {
if (empty($item->product_key)) {
continue;
@ -106,13 +107,6 @@ class UpdateOrCreateProduct implements ShouldQueue
$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) {
$product->custom_value1 = $item->custom_value1;
}

View File

@ -30,26 +30,17 @@ class UserEmailChanged implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $new_user;
protected $old_user;
protected $company;
public $settings;
/**
* Create a new job instance.
*
* @param string $new_email
* @param string $old_email
* @param Company $company
* @param \App\Models\User $new_user
* @param \App\Models\User $old_user
* @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;
}

View File

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

View File

@ -173,10 +173,11 @@ class Import implements ShouldQueue
/**
* Create a new job instance.
*
* @param array $data
* @param string $file_path
* @param Company $company
* @param User $user
* @param array $resources
* @param bool $silent_migration
*/
public function __construct(string $file_path, Company $company, User $user, array $resources = [], $silent_migration = false)
{
@ -195,7 +196,6 @@ class Import implements ShouldQueue
/**
* Execute the job.
*
* @return bool
*/
public function handle()
{
@ -302,7 +302,7 @@ class Import implements ShouldQueue
// 10/02/21
foreach ($client->payments as $payment) {
$credit_total_applied += $payment->paymentables()->where('paymentable_type', App\Models\Credit::class)->get()->sum(\DB::raw('amount'));
$credit_total_applied += $payment->paymentables()->where('paymentable_type', \App\Models\Credit::class)->get()->sum(\DB::raw('amount'));
}
if ($credit_total_applied < 0) {
@ -319,7 +319,7 @@ class Import implements ShouldQueue
private function setInitialCompanyLedgerBalances()
{
Client::where('company_id', $this->company->id)->cursor()->each(function ($client) {
Client::query()->where('company_id', $this->company->id)->cursor()->each(function ($client) {
$invoice_balances = $client->invoices->where('is_deleted', false)->where('status_id', '>', 1)->sum('balance');
$company_ledger = CompanyLedgerFactory::create($client->company_id, $client->user_id);
@ -954,6 +954,7 @@ class Import implements ShouldQueue
$modified['vendor_id'] = $this->transformId('vendors', $resource['vendor_id']);
}
/** @var \App\Models\Expense $expense */
$expense = RecurringExpense::create($modified);
if (array_key_exists('created_at', $modified)) {
@ -1482,7 +1483,7 @@ class Import implements ShouldQueue
try {
$invoice_id = $this->transformId('invoices', $resource['invoice_id']);
$entity = Invoice::where('id', $invoice_id)->withTrashed()->first();
$entity = Invoice::query()->where('id', $invoice_id)->withTrashed()->first();
} catch(\Exception $e) {
nlog("i couldn't find the invoice document {$resource['invoice_id']}, perhaps it is a quote?");
nlog($e->getMessage());
@ -1493,7 +1494,7 @@ class Import implements ShouldQueue
if ($try_quote && array_key_exists('quotes', $this->ids)) {
try {
$quote_id = $this->transformId('quotes', $resource['invoice_id']);
$entity = Quote::where('id', $quote_id)->withTrashed()->first();
$entity = Quote::query()->where('id', $quote_id)->withTrashed()->first();
} catch(\Exception $e) {
nlog("i couldn't find the quote document {$resource['invoice_id']}, perhaps it is a quote?");
nlog($e->getMessage());
@ -1509,7 +1510,7 @@ class Import implements ShouldQueue
if (array_key_exists('expense_id', $resource) && $resource['expense_id'] && array_key_exists('expenses', $this->ids)) {
$expense_id = $this->transformId('expenses', $resource['expense_id']);
$entity = Expense::where('id', $expense_id)->withTrashed()->first();
$entity = Expense::query()->where('id', $expense_id)->withTrashed()->first();
}
$file_url = $resource['url'];
@ -1622,7 +1623,7 @@ class Import implements ShouldQueue
$modified['gateway_key'] = 'd14dd26a37cecc30fdd65700bfb55b23';
}
/** @var \App\Models\CompanyGateway $company_gateway */
$company_gateway = CompanyGateway::create($modified);
$key = "company_gateways_{$resource['id']}";

View File

@ -38,13 +38,13 @@ class VersionCheck implements ShouldQueue
$version_file = trim(@file_get_contents(config('ninja.version_url')));
if (Ninja::isSelfHost() && $version_file) {
/** @var \App\Models\Account $account **/
Account::whereNotNull('id')->update(['latest_version' => $version_file]);
Account::query()->whereNotNull('id')->update(['latest_version' => $version_file]);
}
if (Ninja::isSelfHost()) {
nlog("latest version = {$version_file}");
/** @var \App\Models\Account $account **/
$account = Account::first();
if (! $account) {

View File

@ -71,13 +71,12 @@ class WebhookSingle implements ShouldQueue
/**
* Execute the job.
*
* @return bool
*/
public function handle()
{
MultiDB::setDb($this->db);
$subscription = Webhook::with('company')->find($this->subscription_id);
$subscription = Webhook::query()->with('company')->find($this->subscription_id);
if ($subscription) {
// nlog("firing event ID {$subscription->event_id} company_id {$subscription->company_id}");

View File

@ -124,6 +124,7 @@ class CreatePurchaseOrderPdf implements ShouldQueue
/* Catch all in case migration doesn't pass back a valid design */
if (!$design) {
/** @var \App\Models\Design $design */
$design = Design::find(2);
}

View File

@ -40,7 +40,7 @@ class OAuth
const SOCIAL_APPLE = 8;
/**
* @param Socialite $user
* @param \Laravel\Socialite\Facades\Socialite $socialite_user
* @return bool | \App\Models\User | \App\Models\User | null
*/
public static function handleAuth($socialite_user, $provider)

View File

@ -45,7 +45,6 @@ class PaymentRefundedActivity implements ShouldQueue
$user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->payment->user_id;
$fields->client_id = $event->payment->id;
$fields->client_id = $event->payment->client_id;
$fields->user_id = $user_id;
$fields->company_id = $event->payment->company_id;

View File

@ -47,6 +47,7 @@ class InvoicePaidActivity implements ShouldQueue
$fields->user_id = $user_id;
$fields->invoice_id = $event->invoice->id;
$fields->client_id = $event->invoice->client_id;
$fields->company_id = $event->invoice->company_id;
$fields->activity_type_id = Activity::PAID_INVOICE;
$fields->payment_id = $event->payment->id;

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

@ -36,7 +36,7 @@ class DownloadBackup extends Mailable
{
App::setLocale($this->company->getLocale());
$company = Company::where('company_key', $this->company->company_key)->first();
$company = Company::query()->where('company_key', $this->company->company_key)->first();
return $this->from(config('mail.from.address'), config('mail.from.name'))
->subject(ctrans('texts.download_backup_subject', ['company' => $company->present()->name()]))

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,34 +35,37 @@ 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
* @property \App\Models\Vendor $vendor
* @method static BaseModel find($value)
* @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 on(?string $connection = null)
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel exclude($columns)
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel with($value)
* @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)
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel without($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

@ -47,9 +47,9 @@ use Illuminate\Contracts\Translation\HasLocalePreference;
* @property string|null $logo
* @property string|null $phone
* @property string|null $routing_id
* @property string $balance
* @property string $paid_to_date
* @property string $credit_balance
* @property float $balance
* @property float $paid_to_date
* @property float $credit_balance
* @property int|null $last_login
* @property int|null $industry_id
* @property int|null $size_id
@ -79,50 +79,35 @@ use Illuminate\Contracts\Translation\HasLocalePreference;
* @property int|null $updated_at
* @property int|null $deleted_at
* @property string|null $id_number
* @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\Company $company
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CompanyLedger> $company_ledger
* @property-read int|null $company_ledger_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\ClientContact> $contacts
* @property-read int|null $contacts_count
* @property-read \App\Models\Country|null $country
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Credit> $credits
* @property-read int|null $credits_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
* @property-read int|null $documents_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Expense> $expenses
* @property-read int|null $expenses_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\ClientGatewayToken> $gateway_tokens
* @property-read int|null $gateway_tokens_count
* @property-read mixed $hashed_id
* @property-read \App\Models\User|null $assigned_user
* @property-read \App\Models\User $user
* @property-read \App\Models\Company $company
* @property-read \App\Models\Country|null $country
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Activity> $activities
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CompanyLedger> $company_ledger
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\ClientContact> $contacts
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Credit> $credits
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Expense> $expenses
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\ClientGatewayToken> $gateway_tokens
* @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\CompanyLedger> $ledger
* @property-read int|null $ledger_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Payment> $payments
* @property-read int|null $payments_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\ClientContact> $primary_contact
* @property-read int|null $primary_contact_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Project> $projects
* @property-read int|null $projects_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Quote> $quotes
* @property-read int|null $quotes_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\RecurringExpense> $recurring_expenses
* @property-read int|null $recurring_expenses_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\RecurringInvoice> $recurring_invoices
* @property-read int|null $recurring_invoices_count
* @property-read \App\Models\Country|null $shipping_country
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\SystemLog> $system_logs
* @property-read int|null $system_logs_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Task> $tasks
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\RecurringInvoice> $recurring_invoices
* @property-read int|null $tasks_count
* @property-read \App\Models\User $user
* @method static \Illuminate\Database\Eloquent\Builder|Client exclude($columns)
* @method static \Database\Factories\ClientFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder|Client filter(\App\Filters\QueryFilters $filters)
* @method static \Illuminate\Database\Eloquent\Builder|Client without()
* @method static \Illuminate\Database\Eloquent\Builder|Client find()
* @method static \Illuminate\Database\Eloquent\Builder|Client select()
* @property string $payment_balance
* @property mixed $tax_data
* @property int $is_tax_exempt
@ -248,7 +233,7 @@ class Client extends BaseModel implements HasLocalePreference
return self::class;
}
public function ledger()
public function ledger(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(CompanyLedger::class)->orderBy('id', 'desc');
}
@ -258,17 +243,17 @@ class Client extends BaseModel implements HasLocalePreference
return $this->morphMany(CompanyLedger::class, 'company_ledgerable');
}
public function gateway_tokens()
public function gateway_tokens(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(ClientGatewayToken::class)->orderBy('is_default', 'DESC');
}
public function expenses()
public function expenses(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(Expense::class)->withTrashed();
}
public function projects()
public function projects(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(Project::class)->withTrashed();
}
@ -292,17 +277,17 @@ class Client extends BaseModel implements HasLocalePreference
->first();
}
public function credits()
public function credits(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(Credit::class)->withTrashed();
}
public function purgeable_activities()
public function purgeable_activities(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(Activity::class);
}
public function activities()
public function activities(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(Activity::class)->take(50)->orderBy('id', 'desc');
}
@ -367,7 +352,7 @@ class Client extends BaseModel implements HasLocalePreference
return $this->hasMany(RecurringExpense::class)->withTrashed();
}
public function shipping_country()
public function shipping_country():\Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Country::class, 'shipping_country_id', 'id');
}

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