mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Updates for Static Analysis
This commit is contained in:
parent
a0fab8d22d
commit
b09f1a7d07
@ -120,6 +120,7 @@ class PaymentFilters extends QueryFilters
|
||||
*/
|
||||
public function match_transactions($value = 'true'): Builder
|
||||
{
|
||||
|
||||
if ($value == 'true') {
|
||||
return $this->builder
|
||||
->where('is_deleted', 0)
|
||||
|
@ -101,7 +101,11 @@ class ContactForgotPasswordController extends Controller
|
||||
|
||||
$this->validateEmail($request);
|
||||
|
||||
|
||||
if (Ninja::isHosted() && $company = Company::where('company_key', $request->input('company_key'))->first()) {
|
||||
/** @var \App\Models\Company $company **/
|
||||
|
||||
/** @var \App\Models\ClientContact $contact **/
|
||||
$contact = ClientContact::where(['email' => $request->input('email'), 'company_id' => $company->id])
|
||||
->whereHas('client', function ($query) {
|
||||
$query->where('is_deleted', 0);
|
||||
|
@ -52,6 +52,7 @@ class ContactLoginController extends Controller
|
||||
$company = Company::where('company_key', $company_key)->first();
|
||||
}
|
||||
|
||||
/** @var \App\Models\Company $company **/
|
||||
if ($company) {
|
||||
$account = $company->account;
|
||||
} elseif (! $company && strpos($request->getHost(), 'invoicing.co') !== false) {
|
||||
@ -63,6 +64,7 @@ class ContactLoginController extends Controller
|
||||
|
||||
$company = Company::where('portal_domain', $request->getSchemeAndHttpHost())->first();
|
||||
} elseif (Ninja::isSelfHost()) {
|
||||
/** @var \App\Models\Account $account **/
|
||||
$account = Account::first();
|
||||
$company = $account->default_company;
|
||||
} else {
|
||||
@ -97,6 +99,7 @@ class ContactLoginController extends Controller
|
||||
}
|
||||
|
||||
if (Ninja::isHosted() && $request->has('password') && $company = Company::where('company_key', $request->input('company_key'))->first()) {
|
||||
/** @var \App\Models\Company $company **/
|
||||
$contact = ClientContact::where(['email' => $request->input('email'), 'company_id' => $company->id])
|
||||
->whereHas('client', function ($query) {
|
||||
$query->where('is_deleted', 0);
|
||||
|
@ -39,7 +39,8 @@ class ContactRegisterController extends Controller
|
||||
} else {
|
||||
$key = request()->session()->has('company_key') ? request()->session()->get('company_key') : $company_key;
|
||||
}
|
||||
|
||||
|
||||
/** @var \App\Models\Company $company **/
|
||||
$company = Company::where('company_key', $key)->firstOrFail();
|
||||
|
||||
App::forgetInstance('translator');
|
||||
|
@ -71,6 +71,8 @@ class ContactResetPasswordController extends Controller
|
||||
{
|
||||
if ($request->session()->has('company_key')) {
|
||||
MultiDB::findAndSetDbByCompanyKey($request->session()->get('company_key'));
|
||||
|
||||
/** @var \App\Models\Company $company **/
|
||||
$company = Company::where('company_key', $request->session()->get('company_key'))->first();
|
||||
$db = $company->db;
|
||||
$account = $company->account;
|
||||
@ -79,10 +81,12 @@ class ContactResetPasswordController extends Controller
|
||||
|
||||
if ($account_key) {
|
||||
MultiDB::findAndSetDbByAccountKey($account_key);
|
||||
/** @var \App\Models\Account $account **/
|
||||
$account = Account::where('key', $account_key)->first();
|
||||
$db = $account->companies->first()->db;
|
||||
$company = $account->companies->first();
|
||||
} else {
|
||||
/** @var \App\Models\Account $account **/
|
||||
$account = Account::first();
|
||||
$db = $account->companies->first()->db;
|
||||
$company = $account->companies->first();
|
||||
|
@ -82,6 +82,7 @@ class ForgotPasswordController extends Controller
|
||||
{
|
||||
if ($request->has('company_key')) {
|
||||
MultiDB::findAndSetDbByCompanyKey($request->input('company_key'));
|
||||
/** @var \App\Models\Company $company **/
|
||||
$company = Company::where('company_key', $request->input('company_key'))->first();
|
||||
$account = $company->account;
|
||||
} else {
|
||||
|
@ -60,6 +60,7 @@ class ResetPasswordController extends Controller
|
||||
|
||||
if (Ninja::isHosted()) {
|
||||
MultiDB::findAndSetDbByCompanyKey($request->session()->get('company_key'));
|
||||
/** @var \App\Models\Company $company **/
|
||||
$company = Company::where('company_key', $request->session()->get('company_key'))->first();
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ class BankTransactionRuleController extends BaseController
|
||||
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
||||
* ),
|
||||
* )
|
||||
* @param BankTransactionFilters $filter
|
||||
* @param BankTransactionRuleFilters $filters
|
||||
* @return Response|mixed
|
||||
*/
|
||||
public function index(BankTransactionRuleFilters $filters)
|
||||
@ -302,7 +302,9 @@ class BankTransactionRuleController extends BaseController
|
||||
*/
|
||||
public function create(CreateBankTransactionRuleRequest $request)
|
||||
{
|
||||
$bank_transaction_rule = BankTransactionRuleFactory::create(auth()->user()->company()->id, auth()->user()->id, auth()->user()->account_id);
|
||||
/** @var \App\Models\User $user **/
|
||||
$user = auth()->user();
|
||||
$bank_transaction_rule = BankTransactionRuleFactory::create($user->company()->id, $user->id);
|
||||
|
||||
return $this->itemResponse($bank_transaction_rule);
|
||||
}
|
||||
@ -347,8 +349,11 @@ class BankTransactionRuleController extends BaseController
|
||||
*/
|
||||
public function store(StoreBankTransactionRuleRequest $request)
|
||||
{
|
||||
//stub to store the model
|
||||
$bank_transaction_rule = $this->bank_transaction_repo->save($request->all(), BankTransactionRuleFactory::create(auth()->user()->company()->id, auth()->user()->id, auth()->user()->account_id));
|
||||
|
||||
/** @var \App\Models\User $user **/
|
||||
$user = auth()->user();
|
||||
|
||||
$bank_transaction_rule = $this->bank_transaction_repo->save($request->all(), BankTransactionRuleFactory::create($user->company()->id, $user->id));
|
||||
|
||||
return $this->itemResponse($bank_transaction_rule);
|
||||
}
|
||||
|
@ -27,7 +27,12 @@ class ContactHashLoginController extends Controller
|
||||
public function login(string $contact_key)
|
||||
{
|
||||
if (request()->has('subscription') && request()->subscription == 'true') {
|
||||
$recurring_invoice = RecurringInvoice::where('client_id', auth()->guard('contact')->client->id)
|
||||
|
||||
/** @var \App\Models\ClientContact $client_contact **/
|
||||
$client_contact = auth()->guard('contact');
|
||||
|
||||
/** @var \App\Models\RecurringInvoice $recurring_invoice **/
|
||||
$recurring_invoice = RecurringInvoice::where('client_id', $client_contact->client->id)
|
||||
->whereNotNull('subscription_id')
|
||||
->whereNull('deleted_at')
|
||||
->first();
|
||||
|
@ -56,6 +56,7 @@ class DocumentController extends Controller
|
||||
{
|
||||
MultiDB::documentFindAndSetDb($document_hash);
|
||||
|
||||
/** @var \App\Models\Document $document **/
|
||||
$document = Document::where('hash', $document_hash)->firstOrFail();
|
||||
|
||||
$headers = ['Cache-Control:' => 'no-cache'];
|
||||
@ -69,6 +70,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))
|
||||
->where('company_id', auth()->guard('contact')->user()->company_id)
|
||||
->get();
|
||||
|
@ -212,7 +212,10 @@ class InvitationController extends Controller
|
||||
|
||||
public function paymentRouter(string $contact_key, string $payment_id)
|
||||
{
|
||||
/** @var \App\Models\ClientContact $contact **/
|
||||
$contact = ClientContact::withTrashed()->where('contact_key', $contact_key)->firstOrFail();
|
||||
|
||||
/** @var \App\Models\Payment $payment **/
|
||||
$payment = Payment::find($this->decodePrimaryKey($payment_id));
|
||||
|
||||
if ($payment->client_id != $contact->client_id) {
|
||||
|
@ -97,13 +97,6 @@ class InvoiceController extends Controller
|
||||
|
||||
$file = (new \App\Jobs\Entity\CreateRawPdf($invitation, $invitation->company->db))->handle();
|
||||
|
||||
// $headers = ['Content-Type' => 'application/pdf'];
|
||||
// $entity_string = $data['entity_type'];
|
||||
// $file_name = $invitation->{$entity_string}->numberFormatter().'.pdf';
|
||||
// return response()->streamDownload(function () use ($file) {
|
||||
// echo $file;
|
||||
// }, $file_name, $headers);
|
||||
|
||||
$headers = ['Content-Type' => 'application/pdf'];
|
||||
return response()->make($file, 200, $headers);
|
||||
|
||||
|
@ -44,6 +44,8 @@ class NinjaPlanController extends Controller
|
||||
|
||||
if (! $company) {
|
||||
MultiDB::findAndSetDbByAccountKey($account_or_company_key);
|
||||
|
||||
/** @var \App\Models\Account $account **/
|
||||
$account = Account::where('key', $account_or_company_key)->first();
|
||||
} else {
|
||||
$account = $company->account;
|
||||
|
@ -111,6 +111,7 @@ class PaymentController extends Controller
|
||||
|
||||
public function response(PaymentResponseRequest $request)
|
||||
{
|
||||
/** @var \App\Models\CompanyGateway $gateway **/
|
||||
$gateway = CompanyGateway::findOrFail($request->input('company_gateway_id'));
|
||||
$payment_hash = PaymentHash::where('hash', $request->payment_hash)->firstOrFail();
|
||||
$invoice = Invoice::with('client')->find($payment_hash->fee_invoice_id);
|
||||
|
@ -55,9 +55,13 @@ class PaymentMethodController extends Controller
|
||||
$gateway = $this->getClientGateway();
|
||||
|
||||
$data['gateway'] = $gateway;
|
||||
$data['client'] = auth()->user()->client;
|
||||
|
||||
/** @var \App\Models\ClientContact auth()->user() **/
|
||||
$client_contact = auth()->user();
|
||||
$data['client'] = $client_contact->client;
|
||||
|
||||
return $gateway
|
||||
->driver(auth()->user()->client)
|
||||
->driver($client_contact->client)
|
||||
->setPaymentMethod($request->query('method'))
|
||||
->checkRequirements()
|
||||
->authorizeView($data);
|
||||
@ -73,8 +77,11 @@ class PaymentMethodController extends Controller
|
||||
{
|
||||
$gateway = $this->getClientGateway();
|
||||
|
||||
/** @var \App\Models\ClientContact auth()->user() **/
|
||||
$client_contact = auth()->user();
|
||||
|
||||
return $gateway
|
||||
->driver(auth()->user()->client)
|
||||
->driver($client_contact->client)
|
||||
->setPaymentMethod($request->query('method'))
|
||||
->checkRequirements()
|
||||
->authorizeResponse($request);
|
||||
@ -95,18 +102,23 @@ class PaymentMethodController extends Controller
|
||||
|
||||
public function verify(ClientGatewayToken $payment_method)
|
||||
{
|
||||
|
||||
/** @var \App\Models\ClientContact auth()->user() **/
|
||||
$client_contact = auth()->user();
|
||||
|
||||
return $payment_method->gateway
|
||||
->driver(auth()->user()->client)
|
||||
->driver($client_contact->client)
|
||||
->setPaymentMethod(request()->query('method'))
|
||||
->verificationView($payment_method);
|
||||
}
|
||||
|
||||
public function processVerification(Request $request, ClientGatewaytoken $payment_method)
|
||||
{
|
||||
// $gateway = $this->getClientGateway();
|
||||
/** @var \App\Models\ClientContact auth()->user() **/
|
||||
$client_contact = auth()->user();
|
||||
|
||||
return $payment_method->gateway
|
||||
->driver(auth()->user()->client)
|
||||
->driver($client_contact->client)
|
||||
->setPaymentMethod(request()->query('method'))
|
||||
->processVerification($request, $payment_method);
|
||||
}
|
||||
@ -119,9 +131,12 @@ class PaymentMethodController extends Controller
|
||||
*/
|
||||
public function destroy(ClientGatewayToken $payment_method)
|
||||
{
|
||||
/** @var \App\Models\ClientContact auth()->user() **/
|
||||
$client_contact = auth()->user();
|
||||
|
||||
if ($payment_method->gateway()->exists()) {
|
||||
$payment_method->gateway
|
||||
->driver(auth()->user()->client)
|
||||
->driver($client_contact->client)
|
||||
->setPaymentMethod(request()->query('method'))
|
||||
->detach($payment_method);
|
||||
}
|
||||
@ -143,15 +158,18 @@ class PaymentMethodController extends Controller
|
||||
|
||||
private function getClientGateway()
|
||||
{
|
||||
/** @var \App\Models\ClientContact auth()->user() **/
|
||||
$client_contact = auth()->user();
|
||||
|
||||
if (request()->query('method') == GatewayType::CREDIT_CARD) {
|
||||
return auth()->user()->client->getCreditCardGateway();
|
||||
return $client_contact->client->getCreditCardGateway();
|
||||
}
|
||||
if (request()->query('method') == GatewayType::BACS) {
|
||||
return auth()->user()->client->getBACSGateway();
|
||||
return $client_contact->client->getBACSGateway();
|
||||
}
|
||||
|
||||
if (in_array(request()->query('method'), [GatewayType::BANK_TRANSFER, GatewayType::DIRECT_DEBIT, GatewayType::SEPA])) {
|
||||
return auth()->user()->client->getBankTransferGateway();
|
||||
return $client_contact->client->getBankTransferGateway();
|
||||
}
|
||||
|
||||
abort(404, 'Gateway not found.');
|
||||
|
@ -50,8 +50,6 @@ class ProfileController extends Controller
|
||||
|
||||
$client_contact->save();
|
||||
|
||||
// auth()->user()->fresh();
|
||||
|
||||
return back()->withSuccess(
|
||||
ctrans('texts.profile_updated_successfully')
|
||||
);
|
||||
@ -63,7 +61,7 @@ class ProfileController extends Controller
|
||||
|
||||
//update avatar if needed
|
||||
if ($request->file('logo')) {
|
||||
$path = (new UploadAvatar($request->file('logo'), auth()->user()->client->client_hash))->handle();
|
||||
$path = (new UploadAvatar($request->file('logo'), $client->client_hash))->handle();
|
||||
|
||||
if ($path) {
|
||||
$client->logo = $path;
|
||||
|
@ -83,7 +83,7 @@ class QuoteController extends Controller
|
||||
return $this->downloadQuotes((array) $transformed_ids);
|
||||
}
|
||||
|
||||
if ($request->action = 'approve') {
|
||||
if ($request->action == 'approve') {
|
||||
return $this->approve((array) $transformed_ids, $request->has('process'));
|
||||
}
|
||||
|
||||
@ -92,8 +92,11 @@ class QuoteController extends Controller
|
||||
|
||||
public function downloadQuotes($ids)
|
||||
{
|
||||
/** @var \App\Models\ClientContact $client_contact **/
|
||||
$client_contact = auth()->user();
|
||||
|
||||
$data['quotes'] = Quote::whereIn('id', $ids)
|
||||
->whereClientId(auth()->user()->client->id)
|
||||
->whereClientId($client_contact->client->id)
|
||||
->withTrashed()
|
||||
->get();
|
||||
|
||||
@ -113,8 +116,12 @@ class QuoteController extends Controller
|
||||
|
||||
protected function downloadQuotePdf(array $ids)
|
||||
{
|
||||
|
||||
/** @var \App\Models\ClientContact $client_contact **/
|
||||
$client_contact = auth()->user();
|
||||
|
||||
$quotes = Quote::whereIn('id', $ids)
|
||||
->whereClientId(auth()->user()->client->id)
|
||||
->whereClientId($client_contact->client_id)
|
||||
->withTrashed()
|
||||
->get();
|
||||
|
||||
|
@ -30,7 +30,11 @@ class UploadController extends Controller
|
||||
*/
|
||||
public function __invoke(StoreUploadRequest $request)
|
||||
{
|
||||
$this->saveDocuments($request->getFile(), auth()->user()->client, true);
|
||||
|
||||
/** @var \App\Models\ClientContact $client_contact **/
|
||||
$client_contact = auth()->user();
|
||||
|
||||
$this->saveDocuments($request->getFile(), $client_contact->client, true);
|
||||
|
||||
return response([], 200);
|
||||
}
|
||||
|
@ -547,6 +547,8 @@ class CompanyController extends BaseController
|
||||
|
||||
//If we are deleting the default companies, we'll need to make a new company the default.
|
||||
if ($account->default_company_id == $company_id) {
|
||||
|
||||
/** @var \App\Models\Company $new_default_company **/
|
||||
$new_default_company = Company::whereAccountId($account->id)->first();
|
||||
$account->default_company_id = $new_default_company->id;
|
||||
$account->save();
|
||||
@ -560,7 +562,7 @@ class CompanyController extends BaseController
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param UploadCompanyRequest $request
|
||||
* @param Company $client
|
||||
* @param Company $company
|
||||
* @return Response
|
||||
*
|
||||
*
|
||||
@ -622,7 +624,7 @@ class CompanyController extends BaseController
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param UploadCompanyRequest $request
|
||||
* @param DefaultCompanyRequest $request
|
||||
* @param Company $company
|
||||
* @return Response
|
||||
*
|
||||
|
@ -111,7 +111,10 @@ class CompanyUserController extends BaseController
|
||||
*/
|
||||
public function update(UpdateCompanyUserRequest $request, User $user)
|
||||
{
|
||||
$company = auth()->user()->company();
|
||||
/** @var \App\Models\User $logged_in_user */
|
||||
$logged_in_user = auth()->user();
|
||||
|
||||
$company = $logged_in_user->company();
|
||||
|
||||
$company_user = CompanyUser::whereUserId($user->id)->whereCompanyId($company->id)->first();
|
||||
|
||||
@ -121,7 +124,7 @@ class CompanyUserController extends BaseController
|
||||
return;
|
||||
}
|
||||
|
||||
if (auth()->user()->isAdmin()) {
|
||||
if ($logged_in_user->isAdmin()) {
|
||||
$company_user->fill($request->input('company_user'));
|
||||
} else {
|
||||
$company_user->settings = $request->input('company_user')['settings'];
|
||||
@ -136,7 +139,8 @@ class CompanyUserController extends BaseController
|
||||
public function updatePreferences(UpdateCompanyUserPreferencesRequest $request, User $user)
|
||||
{
|
||||
/** @var \App\Models\User $logged_in_user */
|
||||
$company = auth()->user()->company();
|
||||
$logged_in_user = auth()->user();
|
||||
$company = $logged_in_user->company();
|
||||
|
||||
$company_user = CompanyUser::whereUserId($user->id)->whereCompanyId($company->id)->first();
|
||||
|
||||
|
@ -148,7 +148,10 @@ class CreditController extends BaseController
|
||||
*/
|
||||
public function create(CreateCreditRequest $request)
|
||||
{
|
||||
$credit = CreditFactory::create(auth()->user()->company()->id, auth()->user()->id);
|
||||
/** @var \App\Models\User $user**/
|
||||
$user = auth()->user();
|
||||
|
||||
$credit = CreditFactory::create($user->company()->id, auth()->user()->id);
|
||||
|
||||
return $this->itemResponse($credit);
|
||||
}
|
||||
@ -193,9 +196,13 @@ class CreditController extends BaseController
|
||||
*/
|
||||
public function store(StoreCreditRequest $request)
|
||||
{
|
||||
$client = Client::find($request->input('client_id'));
|
||||
|
||||
$credit = $this->credit_repository->save($request->all(), CreditFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
||||
/** @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()
|
||||
->fillDefaults()
|
||||
@ -207,7 +214,7 @@ class CreditController extends BaseController
|
||||
$credit->client->service()->updatePaidToDate(-1 * $credit->balance)->save();
|
||||
}
|
||||
|
||||
event(new CreditWasCreated($credit, $credit->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||
event(new CreditWasCreated($credit, $credit->company, Ninja::eventVars($user->id)));
|
||||
|
||||
return $this->itemResponse($credit);
|
||||
}
|
||||
@ -383,7 +390,10 @@ class CreditController extends BaseController
|
||||
->triggeredActions($request)
|
||||
->deletePdf();
|
||||
|
||||
event(new CreditWasUpdated($credit, $credit->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||
/** @var \App\Models\User $user**/
|
||||
$user = auth()->user();
|
||||
|
||||
event(new CreditWasUpdated($credit, $credit->company, Ninja::eventVars($user->id)));
|
||||
|
||||
return $this->itemResponse($credit);
|
||||
}
|
||||
@ -495,9 +505,13 @@ class CreditController extends BaseController
|
||||
*/
|
||||
public function bulk(BulkCreditRequest $request)
|
||||
{
|
||||
|
||||
/** @var \App\Models\User $user**/
|
||||
$user = auth()->user();
|
||||
|
||||
$action = $request->input('action');
|
||||
|
||||
if (Ninja::isHosted() && (stripos($action, 'email') !== false) && !auth()->user()->company()->account->account_sms_verified) {
|
||||
if (Ninja::isHosted() && (stripos($action, 'email') !== false) && !$user->company()->account->account_sms_verified) {
|
||||
return response(['message' => 'Please verify your account to send emails.'], 400);
|
||||
}
|
||||
|
||||
@ -515,20 +529,20 @@ class CreditController extends BaseController
|
||||
*/
|
||||
|
||||
if ($action == 'bulk_download' && $credits->count() > 1) {
|
||||
$credits->each(function ($credit) {
|
||||
if (auth()->user()->cannot('view', $credit)) {
|
||||
$credits->each(function ($credit) use($user){
|
||||
if ($user->cannot('view', $credit)) {
|
||||
nlog('access denied');
|
||||
|
||||
return response()->json(['message' => ctrans('text.access_denied')]);
|
||||
}
|
||||
});
|
||||
|
||||
ZipCredits::dispatch($credits, $credits->first()->company, auth()->user());
|
||||
ZipCredits::dispatch($credits, $credits->first()->company, $user);
|
||||
|
||||
return response()->json(['message' => ctrans('texts.sent_message')], 200);
|
||||
}
|
||||
|
||||
if ($action == 'bulk_print' && auth()->user()->can('view', $credits->first())) {
|
||||
if ($action == 'bulk_print' && $user->can('view', $credits->first())) {
|
||||
$paths = $credits->map(function ($credit) {
|
||||
return $credit->service()->getCreditPdf($credit->invitations->first());
|
||||
});
|
||||
@ -540,8 +554,8 @@ class CreditController extends BaseController
|
||||
}, 'print.pdf', ['Content-Type' => 'application/pdf']);
|
||||
}
|
||||
|
||||
$credits->each(function ($credit, $key) use ($action) {
|
||||
if (auth()->user()->can('edit', $credit)) {
|
||||
$credits->each(function ($credit, $key) use ($action, $user) {
|
||||
if ($user->can('edit', $credit)) {
|
||||
$this->performAction($credit, $action, true);
|
||||
}
|
||||
});
|
||||
|
@ -111,7 +111,7 @@ class SendRecurring implements ShouldQueue
|
||||
nlog("attempting to autobill {$invoice->number}");
|
||||
AutoBill::dispatch($invoice->id, $this->db, true)->delay(rand(1, 2));
|
||||
|
||||
//edge case to support where online payment notifications are not enabled
|
||||
//04-08-2023 edge case to support where online payment notifications are not enabled
|
||||
if(!$invoice->client->getSetting('client_online_payment_notification')){
|
||||
$this->sendRecurringEmails($invoice);
|
||||
}
|
||||
@ -120,7 +120,7 @@ class SendRecurring implements ShouldQueue
|
||||
nlog("attempting to autobill {$invoice->number}");
|
||||
AutoBill::dispatch($invoice->id, $this->db, true)->delay(rand(1, 2));
|
||||
|
||||
//edge case to support where online payment notifications are not enabled
|
||||
//04-08-2023 edge case to support where online payment notifications are not enabled
|
||||
if(!$invoice->client->getSetting('client_online_payment_notification')) {
|
||||
$this->sendRecurringEmails($invoice);
|
||||
}
|
||||
@ -130,10 +130,16 @@ class SendRecurring implements ShouldQueue
|
||||
$this->sendRecurringEmails($invoice);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function sendRecurringEmails(Invoice $invoice)
|
||||
/**
|
||||
* Sends the recurring invoice emails to
|
||||
* the designated contacts
|
||||
*
|
||||
* @param Invoice $invoice
|
||||
* @return void
|
||||
*/
|
||||
private function sendRecurringEmails(Invoice $invoice): void
|
||||
{
|
||||
//Admin notification for recurring invoice sent.
|
||||
if ($invoice->invitations->count() >= 1) {
|
||||
|
@ -185,42 +185,42 @@ class Account extends BaseModel
|
||||
return self::class;
|
||||
}
|
||||
|
||||
public function users()
|
||||
public function users(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(User::class)->withTrashed();
|
||||
}
|
||||
|
||||
public function default_company()
|
||||
public function default_company(): \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
{
|
||||
return $this->hasOne(Company::class, 'id', 'default_company_id');
|
||||
}
|
||||
|
||||
public function payment()
|
||||
public function payment(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Payment::class)->withTrashed();
|
||||
}
|
||||
|
||||
public function companies()
|
||||
public function companies(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Company::class);
|
||||
}
|
||||
|
||||
public function bank_integrations()
|
||||
public function bank_integrations(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(BankIntegration::class);
|
||||
}
|
||||
|
||||
public function company_users()
|
||||
public function company_users(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(CompanyUser::class);
|
||||
}
|
||||
|
||||
public function owner()
|
||||
public function owner(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(CompanyUser::class)->where('is_owner', true)->first() ? $this->hasMany(CompanyUser::class)->where('is_owner', true)->first()->user : false;
|
||||
}
|
||||
|
||||
public function tokens()
|
||||
public function tokens(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(CompanyToken::class)->withTrashed();
|
||||
}
|
||||
@ -293,12 +293,12 @@ class Account extends BaseModel
|
||||
}
|
||||
}
|
||||
|
||||
public function isPaid()
|
||||
public function isPaid(): bool
|
||||
{
|
||||
return Ninja::isNinja() ? ($this->isPaidHostedClient() && ! $this->isTrial()) : $this->hasFeature(self::FEATURE_WHITE_LABEL);
|
||||
}
|
||||
|
||||
public function isPaidHostedClient()
|
||||
public function isPaidHostedClient(): bool
|
||||
{
|
||||
if (! Ninja::isNinja()) {
|
||||
return false;
|
||||
@ -312,7 +312,7 @@ class Account extends BaseModel
|
||||
return $this->plan == 'pro' || $this->plan == 'enterprise';
|
||||
}
|
||||
|
||||
public function isFreeHostedClient()
|
||||
public function isFreeHostedClient(): bool
|
||||
{
|
||||
if (! Ninja::isNinja()) {
|
||||
return false;
|
||||
@ -325,7 +325,7 @@ class Account extends BaseModel
|
||||
return $this->plan == 'free' || is_null($this->plan) || empty($this->plan);
|
||||
}
|
||||
|
||||
public function isEnterpriseClient()
|
||||
public function isEnterpriseClient(): bool
|
||||
{
|
||||
if (! Ninja::isNinja()) {
|
||||
return false;
|
||||
@ -334,7 +334,7 @@ class Account extends BaseModel
|
||||
return $this->plan == 'enterprise';
|
||||
}
|
||||
|
||||
public function isTrial()
|
||||
public function isTrial(): bool
|
||||
{
|
||||
if (! Ninja::isNinja()) {
|
||||
return false;
|
||||
@ -345,7 +345,7 @@ class Account extends BaseModel
|
||||
return $plan_details && $plan_details['trial'];
|
||||
}
|
||||
|
||||
public function startTrial($plan)
|
||||
public function startTrial($plan): void
|
||||
{
|
||||
if (! Ninja::isNinja()) {
|
||||
return;
|
||||
|
@ -11,22 +11,23 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Utils\Ninja;
|
||||
use Illuminate\Support\Carbon;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\Traits\MakesDates;
|
||||
use App\Helpers\Invoice\InvoiceSum;
|
||||
use App\Helpers\Invoice\InvoiceSumInclusive;
|
||||
use App\Jobs\Entity\CreateEntityPdf;
|
||||
use App\Models\Presenters\CreditPresenter;
|
||||
use App\Utils\Traits\MakesReminders;
|
||||
use App\Services\Credit\CreditService;
|
||||
use App\Services\Ledger\LedgerService;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\Traits\MakesDates;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\Traits\MakesInvoiceValues;
|
||||
use App\Utils\Traits\MakesReminders;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Utils\Traits\MakesInvoiceValues;
|
||||
use Laracasts\Presenter\PresentableTrait;
|
||||
use App\Models\Presenters\CreditPresenter;
|
||||
use App\Helpers\Invoice\InvoiceSumInclusive;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
|
||||
/**
|
||||
* App\Models\Credit
|
||||
@ -215,32 +216,32 @@ class Credit extends BaseModel
|
||||
return $this->dateMutator($value);
|
||||
}
|
||||
|
||||
public function assigned_user()
|
||||
public function assigned_user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed();
|
||||
}
|
||||
|
||||
public function vendor()
|
||||
public function vendor(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Vendor::class);
|
||||
}
|
||||
|
||||
public function history()
|
||||
public function history(): \Illuminate\Database\Eloquent\Relations\HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(Backup::class, Activity::class);
|
||||
}
|
||||
|
||||
public function activities()
|
||||
public function activities(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Activity::class)->orderBy('id', 'DESC')->take(50);
|
||||
}
|
||||
|
||||
public function company()
|
||||
public function company(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Company::class);
|
||||
}
|
||||
|
||||
public function user()
|
||||
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class)->withTrashed();
|
||||
}
|
||||
@ -250,17 +251,12 @@ class Credit extends BaseModel
|
||||
return $this->belongsTo(Client::class)->withTrashed();
|
||||
}
|
||||
|
||||
// public function contacts()
|
||||
// {
|
||||
// return $this->hasManyThrough(ClientContact::class, Client::class);
|
||||
// }
|
||||
|
||||
public function invitations()
|
||||
public function invitations(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(CreditInvitation::class);
|
||||
}
|
||||
|
||||
public function project()
|
||||
public function project(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Project::class)->withTrashed();
|
||||
}
|
||||
@ -268,17 +264,17 @@ class Credit extends BaseModel
|
||||
/**
|
||||
* The invoice which the credit has been created from.
|
||||
*/
|
||||
public function invoice()
|
||||
public function invoice(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Invoice::class);
|
||||
}
|
||||
|
||||
public function company_ledger()
|
||||
public function company_ledger(): \Illuminate\Database\Eloquent\Relations\MorphMany
|
||||
{
|
||||
return $this->morphMany(CompanyLedger::class, 'company_ledgerable');
|
||||
}
|
||||
|
||||
public function ledger()
|
||||
public function ledger(): \App\Services\Ledger\LedgerService
|
||||
{
|
||||
return new LedgerService($this);
|
||||
}
|
||||
@ -287,17 +283,17 @@ class Credit extends BaseModel
|
||||
* The invoice/s which the credit has
|
||||
* been applied to.
|
||||
*/
|
||||
public function invoices()
|
||||
public function invoices(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Invoice::class)->using(Paymentable::class);
|
||||
}
|
||||
|
||||
public function payments()
|
||||
public function payments(): \Illuminate\Database\Eloquent\Relations\MorphToMany
|
||||
{
|
||||
return $this->morphToMany(Payment::class, 'paymentable');
|
||||
}
|
||||
|
||||
public function documents()
|
||||
public function documents(): \Illuminate\Database\Eloquent\Relations\MorphMany
|
||||
{
|
||||
return $this->morphMany(Document::class, 'documentable');
|
||||
}
|
||||
@ -320,7 +316,7 @@ class Credit extends BaseModel
|
||||
return $credit_calc->build();
|
||||
}
|
||||
|
||||
public function service()
|
||||
public function service(): \App\Services\Credit\CreditService
|
||||
{
|
||||
return new CreditService($this);
|
||||
}
|
||||
@ -423,12 +419,12 @@ class Credit extends BaseModel
|
||||
];
|
||||
}
|
||||
|
||||
public function translate_entity()
|
||||
public function translate_entity(): string
|
||||
{
|
||||
return ctrans('texts.credit');
|
||||
}
|
||||
|
||||
public static function stringStatus(int $status)
|
||||
public static function stringStatus(int $status): string
|
||||
{
|
||||
switch ($status) {
|
||||
case self::STATUS_DRAFT:
|
||||
|
@ -56,32 +56,6 @@ use Illuminate\Support\Facades\Storage;
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document onlyTrashed()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel scope()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document whereAssignedUserId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document whereCompanyId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document whereCustomValue1($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document whereCustomValue2($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document whereCustomValue3($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document whereCustomValue4($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document whereDeletedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document whereDisk($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document whereDocumentableId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document whereDocumentableType($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document whereHash($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document whereHeight($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document whereIsDefault($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document whereIsPublic($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document whereName($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document wherePreview($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document whereProjectId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document whereSize($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document whereType($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document whereUpdatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document whereUrl($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document whereUserId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document whereVendorId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document whereWidth($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document withTrashed()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Document withoutTrashed()
|
||||
* @mixin \Eloquent
|
||||
|
@ -107,42 +107,27 @@ class InvoiceInvitation extends BaseModel
|
||||
return Invoice::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function invoice()
|
||||
public function invoice(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Invoice::class)->withTrashed();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getEntity()
|
||||
public function getEntity(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Invoice::class)->withTrashed();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function contact()
|
||||
public function contact(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ClientContact::class, 'client_contact_id', 'id')->withTrashed();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function user()
|
||||
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class)->withTrashed();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function company()
|
||||
public function company(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Company::class);
|
||||
}
|
||||
@ -156,24 +141,24 @@ class InvoiceInvitation extends BaseModel
|
||||
return sprintf('<img src="data:image/svg+xml;base64,%s"></img><p/>%s: %s', $this->signature_base64, ctrans('texts.signed'), $this->createClientDate($this->signature_date, $this->contact->client->timezone()->name));
|
||||
}
|
||||
|
||||
public function getName()
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->key;
|
||||
}
|
||||
|
||||
public function markViewed()
|
||||
public function markViewed(): void
|
||||
{
|
||||
$this->viewed_date = Carbon::now();
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function markOpened()
|
||||
public function markOpened(): void
|
||||
{
|
||||
$this->opened_date = Carbon::now();
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function pdf_file_path()
|
||||
public function pdf_file_path(): string
|
||||
{
|
||||
$storage_path = Storage::url($this->invoice->client->invoice_filepath($this).$this->invoice->numberFormatter().'.pdf');
|
||||
|
||||
|
@ -283,7 +283,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
return $this->getCompany();
|
||||
}
|
||||
|
||||
public function company_users()
|
||||
public function company_users(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(CompanyUser::class)->withTrashed();
|
||||
}
|
||||
@ -313,8 +313,6 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
|
||||
return $this->token()->cu;
|
||||
|
||||
// return $this->hasOneThrough(CompanyUser::class, CompanyToken::class, 'user_id', 'user_id', 'id', 'user_id')
|
||||
// ->withTrashed();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -327,7 +325,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
return $this->company()->id;
|
||||
}
|
||||
|
||||
public function clients()
|
||||
public function clients(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Client::class);
|
||||
}
|
||||
@ -352,7 +350,6 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
{
|
||||
return json_decode($this->token()->cu->settings);
|
||||
|
||||
//return json_decode($this->company_user->settings);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -364,14 +361,12 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
{
|
||||
return $this->token()->cu->is_admin;
|
||||
|
||||
// return $this->company_user->is_admin;
|
||||
}
|
||||
|
||||
public function isOwner() : bool
|
||||
{
|
||||
return $this->token()->cu->is_owner;
|
||||
|
||||
// return $this->company_user->is_owner;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -389,7 +384,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function contacts()
|
||||
public function contacts(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(ClientContact::class);
|
||||
}
|
||||
@ -581,12 +576,12 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
return false;
|
||||
}
|
||||
|
||||
public function documents()
|
||||
public function documents(): \Illuminate\Database\Eloquent\Relations\MorphMany
|
||||
{
|
||||
return $this->morphMany(Document::class, 'documentable');
|
||||
}
|
||||
|
||||
public function isVerified()
|
||||
public function isVerified(): bool
|
||||
{
|
||||
return is_null($this->email_verified_at) ? false : true;
|
||||
}
|
||||
|
@ -174,7 +174,9 @@ class WePayPaymentDriver extends BaseDriver
|
||||
$config = $this->company_gateway->getConfig();
|
||||
|
||||
$accountId = $this->company_gateway->getConfigField('accountId');
|
||||
|
||||
$objectId = false;
|
||||
$objectType = '';
|
||||
|
||||
foreach (array_keys($input) as $key) {
|
||||
if ('_id' == substr($key, -3)) {
|
||||
$objectType = substr($key, 0, -3);
|
||||
@ -183,7 +185,7 @@ class WePayPaymentDriver extends BaseDriver
|
||||
}
|
||||
}
|
||||
|
||||
if (! isset($objectType)) {
|
||||
if (! $objectId) {
|
||||
throw new \Exception('Could not find object id parameter');
|
||||
}
|
||||
|
||||
@ -226,12 +228,13 @@ class WePayPaymentDriver extends BaseDriver
|
||||
|
||||
return ['message' => 'Processed successfully'];
|
||||
} elseif ($objectType == 'checkout') {
|
||||
/** @var \App\Models\Payment $payment */
|
||||
$payment = Payment::where('company_id', $this->company_gateway->company_id)
|
||||
->where('transaction_reference', '=', $objectId)
|
||||
->first();
|
||||
|
||||
if (! $payment) {
|
||||
throw new Exception('Unknown payment');
|
||||
throw new \Exception('Unknown payment');
|
||||
}
|
||||
|
||||
if ($payment->is_deleted) {
|
||||
|
@ -38,9 +38,9 @@ class ActivityRepository extends BaseRepository
|
||||
/**
|
||||
* Save the Activity.
|
||||
*
|
||||
* @param stdClass $fields The fields
|
||||
* @param Collection $entity The entity that you wish to have backed up (typically Invoice, Quote etc etc rather than Payment)
|
||||
* @param $event_vars
|
||||
* @param \stdClass $fields The fields
|
||||
* @param \App\Models\Invoice | \App\Models\Quote | \App\Models\Credit | \App\Models\PurchaseOrder $entity
|
||||
* @param array $event_vars
|
||||
*/
|
||||
public function save($fields, $entity, $event_vars)
|
||||
{
|
||||
@ -69,8 +69,8 @@ class ActivityRepository extends BaseRepository
|
||||
/**
|
||||
* Creates a backup.
|
||||
*
|
||||
* @param Collection $entity The entity
|
||||
* @param Collection $activity The activity
|
||||
* @param \App\Models\Invoice | \App\Models\Quote | \App\Models\Credit | \App\Models\PurchaseOrder $entity
|
||||
* @param \App\Models\Activity $activity The activity
|
||||
*/
|
||||
public function createBackup($entity, $activity)
|
||||
{
|
||||
@ -98,6 +98,7 @@ class ActivityRepository extends BaseRepository
|
||||
public function getTokenId(array $event_vars)
|
||||
{
|
||||
if ($event_vars['token']) {
|
||||
/** @var \App\Models\CompanyToken $company_token **/
|
||||
$company_token = CompanyToken::where('token', $event_vars['token'])->first();
|
||||
|
||||
if ($company_token) {
|
||||
|
@ -52,8 +52,9 @@ class UserRepository extends BaseRepository
|
||||
if ($unset_company_user) {
|
||||
unset($details['company_user']);
|
||||
}
|
||||
|
||||
$company = auth()->user()->company();
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
$company = $user->company();
|
||||
$account = $company->account;
|
||||
|
||||
// if(array_key_exists('oauth_provider_id', $details))
|
||||
|
Loading…
x
Reference in New Issue
Block a user