diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index 79c98f656c7f..ba95b675c5dd 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -891,7 +891,7 @@ class CheckData extends Command $this->logMessage("Fixing country for # {$client->id}"); }); - Client::query()->whereNull("settings->currency_id")->cursor()->each(function ($client){ + Client::query()->whereNull("settings->currency_id")->cursor()->each(function ($client) { $settings = $client->settings; $settings->currency_id = (string)$client->company->settings->currency_id; $client->settings = $settings; @@ -901,7 +901,7 @@ class CheckData extends Command }); - Payment::withTrashed()->where('exchange_rate', 0)->cursor()->each(function ($payment){ + Payment::withTrashed()->where('exchange_rate', 0)->cursor()->each(function ($payment) { $payment->exchange_rate = 1; $payment->saveQuietly(); @@ -917,11 +917,11 @@ class CheckData extends Command $p->currency_id = $p->client->settings->currency_id; $p->saveQuietly(); - + $this->logMessage("Fixing currency for # {$p->id}"); }); - + Company::whereNull("subdomain") ->cursor() ->when(Ninja::isHosted()) @@ -942,7 +942,7 @@ class CheckData extends Command $i->partial_due_date = null; $i->saveQuietly(); - + $this->logMessage("Fixing partial due date for # {$i->id}"); }); diff --git a/app/Console/Commands/EncryptNinja.php b/app/Console/Commands/EncryptNinja.php index 162b574d8564..b1342b36940e 100644 --- a/app/Console/Commands/EncryptNinja.php +++ b/app/Console/Commands/EncryptNinja.php @@ -52,9 +52,10 @@ class EncryptNinja extends Command */ public function handle() { - if($this->option('encrypt')) + if($this->option('encrypt')) { return $this->encryptFiles(); - + } + if($this->option('decrypt')) { return $this->decryptFiles(); } @@ -80,4 +81,4 @@ class EncryptNinja extends Command Storage::disk('base')->put($file, $decrypted); } } -} \ No newline at end of file +} diff --git a/app/Console/Commands/OpenApiYaml.php b/app/Console/Commands/OpenApiYaml.php index 6cee6d48d411..5ea0ecfbbbe8 100644 --- a/app/Console/Commands/OpenApiYaml.php +++ b/app/Console/Commands/OpenApiYaml.php @@ -79,7 +79,7 @@ class OpenApiYaml extends Command Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents($path.'/components.yaml')); Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents($path.'/components/examples.yaml')); - + Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents($path.'/components/responses.yaml')); $directory = new DirectoryIterator($path . '/components/responses/'); diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index 0980ed8507f3..2ab9923962cb 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -494,7 +494,7 @@ class CompanySettings extends BaseSettings public $payment_email_all_contacts = false; public $show_pdfhtml_on_mobile = true; - + public static $casts = [ 'show_pdfhtml_on_mobile' => 'bool', 'payment_email_all_contacts' => 'bool', diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index ddb0ad957f1e..444733d814ee 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -105,8 +105,8 @@ class Handler extends ExceptionHandler if (Ninja::isHosted()) { // if($exception instanceof ThrottleRequestsException && class_exists(\Modules\Admin\Events\ThrottledExceptionRaised::class)) { - // $uri = urldecode(request()->getRequestUri()); - // event(new \Modules\Admin\Events\ThrottledExceptionRaised(auth()->user()?->account?->key, $uri, request()->ip())); + // $uri = urldecode(request()->getRequestUri()); + // event(new \Modules\Admin\Events\ThrottledExceptionRaised(auth()->user()?->account?->key, $uri, request()->ip())); // } Integration::configureScope(function (Scope $scope): void { diff --git a/app/Export/CSV/BaseExport.php b/app/Export/CSV/BaseExport.php index 91c1e8ebdb72..debee0f7dd38 100644 --- a/app/Export/CSV/BaseExport.php +++ b/app/Export/CSV/BaseExport.php @@ -451,17 +451,19 @@ class BaseExport { if (isset($this->input['client_id']) && $this->input['client_id'] != 'all') { - if(!is_int($this->input['client_id'])) + if(!is_int($this->input['client_id'])) { $this->input['client_id'] = $this->decodePrimaryKey($this->input['client_id']); + } $client = Client::withTrashed()->find($this->input['client_id']); - if(!$client) + if(!$client) { return $query; + } $this->client_description = $client->present()->name; return $query->where('client_id', $this->input['client_id']); - + } elseif(isset($this->input['clients']) && count($this->input['clients']) > 0) { $this->client_description = 'Multiple Clients'; @@ -844,64 +846,69 @@ class BaseExport } protected function addClientFilter($query, $clients): Builder - { - if(is_string($clients)) - $clients = explode(',', $clients); + { + if(is_string($clients)) { + $clients = explode(',', $clients); + } $transformed_clients = $this->transformKeys($clients); nlog($clients); nlog($transformed_clients); - if(count($transformed_clients) > 0) + if(count($transformed_clients) > 0) { $query->whereIn('client_id', $transformed_clients); - + } + return $query; } protected function addVendorFilter($query, $vendors): Builder - { - + { + if(is_string($vendors)) { $vendors = explode(',', $vendors); } - + $transformed_vendors = $this->transformKeys($vendors); - if(count($transformed_vendors) > 0) + if(count($transformed_vendors) > 0) { $query->whereIn('vendor_id', $transformed_vendors); - + } + return $query; } protected function addProjectFilter($query, $projects): Builder - { - + { + if(is_string($projects)) { $projects = explode(',', $projects); } $transformed_projects = $this->transformKeys($projects); - - if(count($transformed_projects) > 0) + + if(count($transformed_projects) > 0) { $query->whereIn('project_id', $transformed_projects); - + } + return $query; } protected function addCategoryFilter($query, $expense_categories): Builder - { - + { + if(is_string($expense_categories)) { $expense_categories = explode(',', $expense_categories); } $transformed_expense_categories = $this->transformKeys($expense_categories); - - if(count($transformed_expense_categories) > 0) + + if(count($transformed_expense_categories) > 0) { $query->whereIn('category_id', $transformed_expense_categories); - + } + return $query; } @@ -1299,12 +1306,12 @@ class BaseExport public function queueDocuments(Builder $query) { nlog("queue docs pls"); - if($query->getModel() instanceof Document) + if($query->getModel() instanceof Document) { $documents = $query->pluck('id')->toArray(); - else{ + } else { $documents = $query->cursor() - ->map(function ($entity){ - return $entity->documents()->pluck('id')->toArray(); + ->map(function ($entity) { + return $entity->documents()->pluck('id')->toArray(); })->flatten() ->toArray(); } @@ -1315,11 +1322,13 @@ class BaseExport $user = $this->company->owner(); - if(auth()->user() && auth()->user()->account_id == $this->company->account_id) + if(auth()->user() && auth()->user()->account_id == $this->company->account_id) { $user = auth()->user(); + } - if($this->input['user_id'] ?? false) + if($this->input['user_id'] ?? false) { $user = User::where('id', $this->input['user_id'])->where('account_id', $this->company->account_id)->first(); + } ZipDocuments::dispatch($documents, $this->company, $user); } diff --git a/app/Export/CSV/CreditExport.php b/app/Export/CSV/CreditExport.php index 1ef2af5fe70c..0973f7a70473 100644 --- a/app/Export/CSV/CreditExport.php +++ b/app/Export/CSV/CreditExport.php @@ -106,7 +106,7 @@ class CreditExport extends BaseExport ->where('is_deleted', 0); $query = $this->addDateRange($query); - + if($this->input['document_email_attachment'] ?? false) { $this->queueDocuments($query); } diff --git a/app/Export/CSV/DocumentExport.php b/app/Export/CSV/DocumentExport.php index cbe77f0f26ba..5822a1a8bbc0 100644 --- a/app/Export/CSV/DocumentExport.php +++ b/app/Export/CSV/DocumentExport.php @@ -77,7 +77,7 @@ class DocumentExport extends BaseExport $query = Document::query()->where('company_id', $this->company->id); $query = $this->addDateRange($query); - + if($this->input['document_email_attachment'] ?? false) { $this->queueDocuments($query); } diff --git a/app/Export/CSV/ExpenseExport.php b/app/Export/CSV/ExpenseExport.php index 3ab505511330..b5be8b4f8458 100644 --- a/app/Export/CSV/ExpenseExport.php +++ b/app/Export/CSV/ExpenseExport.php @@ -23,7 +23,6 @@ use League\Csv\Writer; class ExpenseExport extends BaseExport { - private $expense_transformer; private Decorator $decorator; @@ -103,7 +102,7 @@ class ExpenseExport extends BaseExport if(isset($this->input['categories'])) { $query = $this->addCategoryFilter($query, $this->input['categories']); } - + if($this->input['document_email_attachment'] ?? false) { $this->queueDocuments($query); } @@ -206,23 +205,21 @@ class ExpenseExport extends BaseExport if($expense->calculate_tax_by_amount) { $total_tax_amount = round($expense->tax_amount1 + $expense->tax_amount2 + $expense->tax_amount3, $precision); - } - else { - - if($expense->uses_inclusive_taxes){ - $total_tax_amount = ($this->calcInclusiveLineTax($expense->tax_rate1 ?? 0, $expense->amount,$precision)) + ($this->calcInclusiveLineTax($expense->tax_rate2 ?? 0, $expense->amount,$precision)) + ($this->calcInclusiveLineTax($expense->tax_rate3 ?? 0, $expense->amount,$precision)); + } else { + + if($expense->uses_inclusive_taxes) { + $total_tax_amount = ($this->calcInclusiveLineTax($expense->tax_rate1 ?? 0, $expense->amount, $precision)) + ($this->calcInclusiveLineTax($expense->tax_rate2 ?? 0, $expense->amount, $precision)) + ($this->calcInclusiveLineTax($expense->tax_rate3 ?? 0, $expense->amount, $precision)); $entity['expense.net_amount'] = round(($expense->amount - round($total_tax_amount, $precision)), $precision); - } - else{ - $total_tax_amount = ($expense->amount * (($expense->tax_rate1 ?? 0)/100)) + ($expense->amount * (($expense->tax_rate2 ?? 0)/100)) + ($expense->amount * (($expense->tax_rate3 ?? 0)/100)); + } else { + $total_tax_amount = ($expense->amount * (($expense->tax_rate1 ?? 0) / 100)) + ($expense->amount * (($expense->tax_rate2 ?? 0) / 100)) + ($expense->amount * (($expense->tax_rate3 ?? 0) / 100)); $entity['expense.net_amount'] = round(($expense->amount + round($total_tax_amount, $precision)), $precision); } } $entity['expense.tax_amount'] = round($total_tax_amount, $precision); - + return $entity; - + } private function calcInclusiveLineTax($tax_rate, $amount, $precision): float diff --git a/app/Export/CSV/InvoiceItemExport.php b/app/Export/CSV/InvoiceItemExport.php index e56eb7142e4c..b701b2faa2f1 100644 --- a/app/Export/CSV/InvoiceItemExport.php +++ b/app/Export/CSV/InvoiceItemExport.php @@ -76,7 +76,7 @@ class InvoiceItemExport extends BaseExport $query = $this->addDateRange($query); $query = $this->applyFilters($query); - + if($this->input['document_email_attachment'] ?? false) { $this->queueDocuments($query); } diff --git a/app/Export/CSV/PaymentExport.php b/app/Export/CSV/PaymentExport.php index d4646d143078..93550f9545c3 100644 --- a/app/Export/CSV/PaymentExport.php +++ b/app/Export/CSV/PaymentExport.php @@ -60,7 +60,7 @@ class PaymentExport extends BaseExport ->where('is_deleted', 0); $query = $this->addDateRange($query); - + if($this->input['document_email_attachment'] ?? false) { $this->queueDocuments($query); } diff --git a/app/Export/CSV/ProductExport.php b/app/Export/CSV/ProductExport.php index 5c2dd3401ebc..2c82efb9d43e 100644 --- a/app/Export/CSV/ProductExport.php +++ b/app/Export/CSV/ProductExport.php @@ -77,7 +77,7 @@ class ProductExport extends BaseExport ->where('is_deleted', 0); $query = $this->addDateRange($query); - + if($this->input['document_email_attachment'] ?? false) { $this->queueDocuments($query); } diff --git a/app/Export/CSV/PurchaseOrderExport.php b/app/Export/CSV/PurchaseOrderExport.php index 094fbc87fcbf..f1fa4501510b 100644 --- a/app/Export/CSV/PurchaseOrderExport.php +++ b/app/Export/CSV/PurchaseOrderExport.php @@ -107,7 +107,7 @@ class PurchaseOrderExport extends BaseExport ->where('is_deleted', 0); $query = $this->addDateRange($query); - + if($this->input['document_email_attachment'] ?? false) { $this->queueDocuments($query); } diff --git a/app/Export/CSV/QuoteItemExport.php b/app/Export/CSV/QuoteItemExport.php index b7b86c9a123f..bdb16061d53b 100644 --- a/app/Export/CSV/QuoteItemExport.php +++ b/app/Export/CSV/QuoteItemExport.php @@ -69,7 +69,7 @@ class QuoteItemExport extends BaseExport ->where('is_deleted', 0); $query = $this->addDateRange($query); - + if($this->input['document_email_attachment'] ?? false) { $this->queueDocuments($query); } diff --git a/app/Filters/ClientFilters.php b/app/Filters/ClientFilters.php index a3504cce4e45..b79a381da692 100644 --- a/app/Filters/ClientFilters.php +++ b/app/Filters/ClientFilters.php @@ -165,8 +165,7 @@ class ClientFilters extends QueryFilters $dir = ($sort_col[1] == 'asc') ? 'asc' : 'desc'; - if($sort_col[0] == 'number') - { + if($sort_col[0] == 'number') { return $this->builder->orderByRaw('ABS(number) ' . $dir); } diff --git a/app/Filters/InvoiceFilters.php b/app/Filters/InvoiceFilters.php index aa0c51f0defc..568fb03c9a4b 100644 --- a/app/Filters/InvoiceFilters.php +++ b/app/Filters/InvoiceFilters.php @@ -318,13 +318,12 @@ class InvoiceFilters extends QueryFilters if ($sort_col[0] == 'client_id') { - return $this->builder->orderBy(\App\Models\Client::select ('name') + return $this->builder->orderBy(\App\Models\Client::select('name') ->whereColumn('clients.id', 'invoices.client_id'), $dir); } - if($sort_col[0] == 'number') - { + if($sort_col[0] == 'number') { return $this->builder->orderByRaw('ABS(number) ' . $dir); } diff --git a/app/Filters/ProjectFilters.php b/app/Filters/ProjectFilters.php index cd4015596903..4f4ef99b2ca4 100644 --- a/app/Filters/ProjectFilters.php +++ b/app/Filters/ProjectFilters.php @@ -59,7 +59,7 @@ class ProjectFilters extends QueryFilters public function sort(string $sort = ''): Builder { $sort_col = explode('|', $sort); - + if (!is_array($sort_col) || count($sort_col) != 2) { return $this->builder; } diff --git a/app/Helpers/Bank/Nordigen/Transformer/TransactionTransformer.php b/app/Helpers/Bank/Nordigen/Transformer/TransactionTransformer.php index a18a9b4429cd..184e79546509 100644 --- a/app/Helpers/Bank/Nordigen/Transformer/TransactionTransformer.php +++ b/app/Helpers/Bank/Nordigen/Transformer/TransactionTransformer.php @@ -70,8 +70,9 @@ class TransactionTransformer implements BankRevenueInterface { $data = []; - if (!array_key_exists('transactions', $transactionResponse) || !array_key_exists('booked', $transactionResponse["transactions"])) + if (!array_key_exists('transactions', $transactionResponse) || !array_key_exists('booked', $transactionResponse["transactions"])) { throw new \Exception('invalid dataset'); + } foreach ($transactionResponse["transactions"]["booked"] as $transaction) { $data[] = $this->transformTransaction($transaction); @@ -83,11 +84,11 @@ class TransactionTransformer implements BankRevenueInterface { // depending on institution, the result can be different, so we load the first available unique id $transactionId = ''; - if (array_key_exists('transactionId', $transaction)) + if (array_key_exists('transactionId', $transaction)) { $transactionId = $transaction["transactionId"]; - else if (array_key_exists('internalTransactionId', $transaction)) + } elseif (array_key_exists('internalTransactionId', $transaction)) { $transactionId = $transaction["internalTransactionId"]; - else { + } else { nlog(`Invalid Input for nordigen transaction transformer: ` . $transaction); throw new \Exception('invalid dataset: missing transactionId - Please report this error to the developer'); } @@ -96,23 +97,25 @@ class TransactionTransformer implements BankRevenueInterface // description could be in varios places $description = ''; - if (array_key_exists('remittanceInformationStructured', $transaction)) + if (array_key_exists('remittanceInformationStructured', $transaction)) { $description = $transaction["remittanceInformationStructured"]; - else if (array_key_exists('remittanceInformationStructuredArray', $transaction)) + } elseif (array_key_exists('remittanceInformationStructuredArray', $transaction)) { $description = implode('\n', $transaction["remittanceInformationStructuredArray"]); - else if (array_key_exists('remittanceInformationUnstructured', $transaction)) + } elseif (array_key_exists('remittanceInformationUnstructured', $transaction)) { $description = $transaction["remittanceInformationUnstructured"]; - else if (array_key_exists('remittanceInformationUnstructuredArray', $transaction)) + } elseif (array_key_exists('remittanceInformationUnstructuredArray', $transaction)) { $description = implode('\n', $transaction["remittanceInformationUnstructuredArray"]); - else + } else { Log::warning("Missing description for the following transaction: " . json_encode($transaction)); + } // enrich description with currencyExchange informations - if (array_key_exists('currencyExchange', $transaction)) + if (array_key_exists('currencyExchange', $transaction)) { foreach ($transaction["currencyExchange"] as $exchangeRate) { $targetAmount = round($amount * (float) $exchangeRate["exchangeRate"], 2); $description .= '\nexchangeRate: ' . $amount . " " . $exchangeRate["sourceCurrency"] . " = " . $targetAmount . " " . $exchangeRate["targetCurrency"] . " (" . $exchangeRate["quotationDate"] . ")"; } + } // participant data $participant = array_key_exists('debtorAccount', $transaction) && array_key_exists('iban', $transaction["debtorAccount"]) ? @@ -153,8 +156,9 @@ class TransactionTransformer implements BankRevenueInterface return $item->code == $code; })->first(); - if ($currency) + if ($currency) { return $currency->id; + } return 1; diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 4db4198879d5..474a11b42389 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -62,7 +62,7 @@ class ActivityController extends BaseController $system = ctrans('texts.system'); $data = $activities->cursor()->map(function ($activity) { - + /** @var \App\Models\Activity $activity */ return $activity->activity_string(); diff --git a/app/Http/Controllers/BankTransactionController.php b/app/Http/Controllers/BankTransactionController.php index 7613bb9ce0ed..b47779d1a9fa 100644 --- a/app/Http/Controllers/BankTransactionController.php +++ b/app/Http/Controllers/BankTransactionController.php @@ -112,8 +112,9 @@ class BankTransactionController extends BaseController $this->bank_transaction_repo->convert_matched($bank_transactions); } else { $bank_transactions->each(function ($bank_transaction, $key) use ($action, $user) { - if($user->can('edit', $bank_transaction)) + if($user->can('edit', $bank_transaction)) { $this->bank_transaction_repo->{$action}($bank_transaction); + } }); } diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php index 9f19c338aaec..5f43373501e3 100644 --- a/app/Http/Controllers/ClientController.php +++ b/app/Http/Controllers/ClientController.php @@ -412,19 +412,19 @@ class ClientController extends BaseController } - public function documents(ClientDocumentsRequest $request, Client $client) + public function documents(ClientDocumentsRequest $request, Client $client) { - + $this->entity_type = Document::class; $this->entity_transformer = DocumentTransformer::class; - + $documents = Document::query() ->company() - ->whereHasMorph('documentable', [Invoice::class, Quote::class, Credit::class, Expense::class, Payment::class, Task::class], function ($query) use($client) { + ->whereHasMorph('documentable', [Invoice::class, Quote::class, Credit::class, Expense::class, Payment::class, Task::class], function ($query) use ($client) { $query->where('client_id', $client->id); }) - ->orWhereHasMorph('documentable', [Client::class], function ($query) use ($client){ + ->orWhereHasMorph('documentable', [Client::class], function ($query) use ($client) { $query->where('id', $client->id); }); diff --git a/app/Http/Controllers/ClientGatewayTokenController.php b/app/Http/Controllers/ClientGatewayTokenController.php index 87fb8aa9ab18..aa5792fdbb87 100644 --- a/app/Http/Controllers/ClientGatewayTokenController.php +++ b/app/Http/Controllers/ClientGatewayTokenController.php @@ -353,7 +353,7 @@ class ClientGatewayTokenController extends BaseController */ public function store(StoreClientGatewayTokenRequest $request) { - + /** @var \App\Models\User $user */ $user = auth()->user(); diff --git a/app/Http/Controllers/ClientPortal/DocumentController.php b/app/Http/Controllers/ClientPortal/DocumentController.php index 92c17bc32071..19a94182f28e 100644 --- a/app/Http/Controllers/ClientPortal/DocumentController.php +++ b/app/Http/Controllers/ClientPortal/DocumentController.php @@ -73,12 +73,13 @@ class DocumentController extends Controller { $hash = Cache::pull($hash); - - if(!$hash) + + if(!$hash) { abort(404); + } MultiDB::setDb($hash['db']); - + /** @var \App\Models\Document $document **/ $document = Document::where('hash', $hash['doc_hash'])->firstOrFail(); diff --git a/app/Http/Controllers/ClientPortal/EmailPreferencesController.php b/app/Http/Controllers/ClientPortal/EmailPreferencesController.php index 6fd5063756aa..5abf591f0602 100644 --- a/app/Http/Controllers/ClientPortal/EmailPreferencesController.php +++ b/app/Http/Controllers/ClientPortal/EmailPreferencesController.php @@ -58,4 +58,3 @@ class EmailPreferencesController extends Controller return back()->with('message', ctrans('texts.updated_settings')); } } - diff --git a/app/Http/Controllers/ClientPortal/InvoiceController.php b/app/Http/Controllers/ClientPortal/InvoiceController.php index e9ef3ba7aead..2fb5ea47d8b2 100644 --- a/app/Http/Controllers/ClientPortal/InvoiceController.php +++ b/app/Http/Controllers/ClientPortal/InvoiceController.php @@ -70,7 +70,7 @@ class InvoiceController extends Controller } $variables = ($invitation && auth()->guard('contact')->user()->client->getSetting('show_accept_invoice_terms')) ? (new HtmlEngine($invitation))->generateLabelsAndValues() : false; - + $data = [ 'invoice' => $invoice, 'invitation' => $invitation ?: $invoice->invitations->first(), @@ -224,8 +224,9 @@ class InvoiceController extends Controller $settings = auth()->guard('contact')->user()->client->getMergedSettings(); $variables = false; - if(($invitation = $invoices->first()->invitations()->first() ?? false) && $settings->show_accept_invoice_terms) + if(($invitation = $invoices->first()->invitations()->first() ?? false) && $settings->show_accept_invoice_terms) { $variables = (new HtmlEngine($invitation))->generateLabelsAndValues(); + } $data = [ 'settings' => $settings, diff --git a/app/Http/Controllers/ClientPortal/PaymentMethodController.php b/app/Http/Controllers/ClientPortal/PaymentMethodController.php index 5d131daad74d..bc5b0203b888 100644 --- a/app/Http/Controllers/ClientPortal/PaymentMethodController.php +++ b/app/Http/Controllers/ClientPortal/PaymentMethodController.php @@ -147,7 +147,7 @@ class PaymentMethodController extends Controller $payment_method->is_deleted = true; $payment_method->delete(); $payment_method->save(); - + } catch (Exception $e) { nlog($e->getMessage()); diff --git a/app/Http/Controllers/ClientPortal/QuoteController.php b/app/Http/Controllers/ClientPortal/QuoteController.php index 43d60122384c..b9251edc4a5b 100644 --- a/app/Http/Controllers/ClientPortal/QuoteController.php +++ b/app/Http/Controllers/ClientPortal/QuoteController.php @@ -215,7 +215,7 @@ class QuoteController extends Controller ->withSuccess('Quote(s) approved successfully.'); } - + $variables = false; if($invitation = $quotes->first()->invitations()->first() ?? false) { diff --git a/app/Http/Controllers/CompanyGatewayController.php b/app/Http/Controllers/CompanyGatewayController.php index 6b5b151b4071..6c58f090a248 100644 --- a/app/Http/Controllers/CompanyGatewayController.php +++ b/app/Http/Controllers/CompanyGatewayController.php @@ -149,7 +149,7 @@ class CompanyGatewayController extends BaseController */ public function create(CreateCompanyGatewayRequest $request) { - + /** @var \App\Models\User $user */ $user = auth()->user(); diff --git a/app/Http/Controllers/CompanyLedgerController.php b/app/Http/Controllers/CompanyLedgerController.php index 91eba243468e..1361e62c93db 100644 --- a/app/Http/Controllers/CompanyLedgerController.php +++ b/app/Http/Controllers/CompanyLedgerController.php @@ -64,7 +64,7 @@ class CompanyLedgerController extends BaseController */ public function index(ShowCompanyLedgerRequest $request) { - + /** @var \App\Models\User $user */ $user = auth()->user(); diff --git a/app/Http/Controllers/ConnectedAccountController.php b/app/Http/Controllers/ConnectedAccountController.php index 7d0aeb46d1fa..9fc1376cff49 100644 --- a/app/Http/Controllers/ConnectedAccountController.php +++ b/app/Http/Controllers/ConnectedAccountController.php @@ -121,7 +121,7 @@ class ConnectedAccountController extends BaseController 'email_verified_at' => now() ]; - + /** @var \App\Models\User $user */ $user = auth()->user(); diff --git a/app/Http/Controllers/ExpenseCategoryController.php b/app/Http/Controllers/ExpenseCategoryController.php index 51b8dc49a0f7..f4f5629508d8 100644 --- a/app/Http/Controllers/ExpenseCategoryController.php +++ b/app/Http/Controllers/ExpenseCategoryController.php @@ -128,7 +128,7 @@ class ExpenseCategoryController extends BaseController */ public function create(CreateExpenseCategoryRequest $request) { - + /** @var \App\Models\User $user */ $user = auth()->user(); diff --git a/app/Http/Controllers/HostedMigrationController.php b/app/Http/Controllers/HostedMigrationController.php index ea62dad70056..e2aca7f082ff 100644 --- a/app/Http/Controllers/HostedMigrationController.php +++ b/app/Http/Controllers/HostedMigrationController.php @@ -21,7 +21,7 @@ class HostedMigrationController extends Controller { public function checkStatus(Request $request) { - + if ($request->header('X-API-HOSTED-SECRET') != config('ninja.ninja_hosted_secret')) { return; } @@ -29,19 +29,20 @@ class HostedMigrationController extends Controller MultiDB::findAndSetDbByCompanyKey($request->company_key); $c = Company::where('company_key', $request->company_key)->first(); - if(!$c || $c->is_disabled) + if(!$c || $c->is_disabled) { return response()->json(['message' => 'ok'], 200); + } // if(\App\Models\Invoice::query()->where('company_id', $c->id)->where('created_at', '>', now()->subMonths(2))->first()) // return response()->json(['message' => 'New data exists, are you sure? Please log in here https://app.invoicing.co and delete the company if you really need to migrate again.'], 400); - - // if(\App\Models\Client::query()->where('company_id', $c->id)->where('created_at', '>', now()->subMonths(2))->first()) - // return response()->json(['message' => 'New data exists, are you sure? Please log in here https://app.invoicing.co and delete the company if you really need to migrate again.'], 400); - - // if(\App\Models\Quote::query()->where('company_id', $c->id)->where('created_at', '>', now()->subMonths(2))) + + // if(\App\Models\Client::query()->where('company_id', $c->id)->where('created_at', '>', now()->subMonths(2))->first()) // return response()->json(['message' => 'New data exists, are you sure? Please log in here https://app.invoicing.co and delete the company if you really need to migrate again.'], 400); - // if(\App\Models\RecurringInvoice::query()->where('company_id', $c->id)->where('created_at', '>', now()->subMonths(2))) + // if(\App\Models\Quote::query()->where('company_id', $c->id)->where('created_at', '>', now()->subMonths(2))) + // return response()->json(['message' => 'New data exists, are you sure? Please log in here https://app.invoicing.co and delete the company if you really need to migrate again.'], 400); + + // if(\App\Models\RecurringInvoice::query()->where('company_id', $c->id)->where('created_at', '>', now()->subMonths(2))) // return response()->json(['message' => 'New data exists, are you sure? Please log in here https://app.invoicing.co and delete the company if you really need to migrate again.'], 400); return response()->json(['message' => 'You have already activated this company on v5!!!!!! This migration may be a BAD idea. Contact us contact@invoiceninja.com to confirm this action.'], 400); diff --git a/app/Http/Controllers/MailgunWebhookController.php b/app/Http/Controllers/MailgunWebhookController.php index 812501d3eb27..341236caa85f 100644 --- a/app/Http/Controllers/MailgunWebhookController.php +++ b/app/Http/Controllers/MailgunWebhookController.php @@ -22,18 +22,22 @@ class MailgunWebhookController extends BaseController { private $invitation; - public function __construct() {} + public function __construct() + { + } public function webhook(Request $request) { $input = $request->all(); - if (\abs(\time() - $request['signature']['timestamp']) > 15) + if (\abs(\time() - $request['signature']['timestamp']) > 15) { return response()->json(['message' => 'Success'], 200); + } - if(\hash_equals(\hash_hmac('sha256', $input['signature']['timestamp'] . $input['signature']['token'], config('services.mailgun.webhook_signing_key')), $input['signature']['signature'])) + if(\hash_equals(\hash_hmac('sha256', $input['signature']['timestamp'] . $input['signature']['token'], config('services.mailgun.webhook_signing_key')), $input['signature']['signature'])) { ProcessMailgunWebhook::dispatch($request->all())->delay(10); + } return response()->json(['message' => 'Success.'], 200); } diff --git a/app/Http/Controllers/PaymentController.php b/app/Http/Controllers/PaymentController.php index 442a76319706..812885d60f61 100644 --- a/app/Http/Controllers/PaymentController.php +++ b/app/Http/Controllers/PaymentController.php @@ -520,7 +520,7 @@ class PaymentController extends BaseController if($action == 'template' && $user->can('view', $payments->first())) { $hash_or_response = request()->boolean('send_email') ? 'email sent' : \Illuminate\Support\Str::uuid(); - + TemplateAction::dispatch( $payments->pluck('hashed_id')->toArray(), $request->template_id, diff --git a/app/Http/Controllers/PreviewPurchaseOrderController.php b/app/Http/Controllers/PreviewPurchaseOrderController.php index ea6a0065f8d4..8ddf82d9360f 100644 --- a/app/Http/Controllers/PreviewPurchaseOrderController.php +++ b/app/Http/Controllers/PreviewPurchaseOrderController.php @@ -316,8 +316,8 @@ class PreviewPurchaseOrderController extends BaseController return; } - /** @var \App\Models\User $user */ - $user = auth()->user(); + /** @var \App\Models\User $user */ + $user = auth()->user(); //if phantom js...... inject here.. if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') { diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index f3f82132a473..e42c090c34bb 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -181,7 +181,7 @@ class ProductController extends BaseController */ public function store(StoreProductRequest $request) { - + /** @var \App\Models\User $user */ $user = auth()->user(); diff --git a/app/Http/Controllers/QuoteController.php b/app/Http/Controllers/QuoteController.php index b2af3a1b560e..78a5bf625247 100644 --- a/app/Http/Controllers/QuoteController.php +++ b/app/Http/Controllers/QuoteController.php @@ -399,7 +399,7 @@ class QuoteController extends BaseController $quote->service() ->triggeredActions($request); - + event(new QuoteWasUpdated($quote, $quote->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); return $this->itemResponse($quote); diff --git a/app/Http/Controllers/StripeConnectController.php b/app/Http/Controllers/StripeConnectController.php index 84080a9bc2ab..a8de13091bf4 100644 --- a/app/Http/Controllers/StripeConnectController.php +++ b/app/Http/Controllers/StripeConnectController.php @@ -86,7 +86,7 @@ class StripeConnectController extends BaseController ]); nlog($response); - + } catch (\Exception $e) { return view('auth.connect.access_denied'); } diff --git a/app/Http/Controllers/TwoFactorController.php b/app/Http/Controllers/TwoFactorController.php index a108d6c67012..083aea6ac011 100644 --- a/app/Http/Controllers/TwoFactorController.php +++ b/app/Http/Controllers/TwoFactorController.php @@ -84,7 +84,7 @@ class TwoFactorController extends BaseController public function disableTwoFactor() { - + /** @var \App\Models\User $user */ $user = auth()->user(); diff --git a/app/Http/Controllers/VendorController.php b/app/Http/Controllers/VendorController.php index 7802a8838f01..0f0328ec5a1e 100644 --- a/app/Http/Controllers/VendorController.php +++ b/app/Http/Controllers/VendorController.php @@ -499,7 +499,7 @@ class VendorController extends BaseController $ids = request()->input('ids'); $vendors = Vendor::withTrashed()->find($this->transformKeys($ids)); - + /** @var \App\Models\User $user */ $user = auth()->user(); diff --git a/app/Http/Requests/ClientPortal/PaymentMethod/CreatePaymentMethodRequest.php b/app/Http/Requests/ClientPortal/PaymentMethod/CreatePaymentMethodRequest.php index 5ba9c2fa104a..76ffa929dfd7 100644 --- a/app/Http/Requests/ClientPortal/PaymentMethod/CreatePaymentMethodRequest.php +++ b/app/Http/Requests/ClientPortal/PaymentMethod/CreatePaymentMethodRequest.php @@ -27,7 +27,7 @@ class CreatePaymentMethodRequest extends FormRequest ->filter(function ($method) use (&$available_methods) { $available_methods[] = $method['gateway_type_id']; }); - + if (in_array($this->query('method'), $available_methods)) { return true; } diff --git a/app/Http/Requests/ExpenseCategory/StoreExpenseCategoryRequest.php b/app/Http/Requests/ExpenseCategory/StoreExpenseCategoryRequest.php index 45c614b8fd7f..2fbf74bb2cfd 100644 --- a/app/Http/Requests/ExpenseCategory/StoreExpenseCategoryRequest.php +++ b/app/Http/Requests/ExpenseCategory/StoreExpenseCategoryRequest.php @@ -32,7 +32,7 @@ class StoreExpenseCategoryRequest extends Request public function rules() { - + /** @var \App\Models\User $user */ $user = auth()->user(); diff --git a/app/Http/Requests/ExpenseCategory/UpdateExpenseCategoryRequest.php b/app/Http/Requests/ExpenseCategory/UpdateExpenseCategoryRequest.php index 1ff371ff6920..f5b57df5a407 100644 --- a/app/Http/Requests/ExpenseCategory/UpdateExpenseCategoryRequest.php +++ b/app/Http/Requests/ExpenseCategory/UpdateExpenseCategoryRequest.php @@ -26,7 +26,7 @@ class UpdateExpenseCategoryRequest extends Request */ public function authorize(): bool { - + /** @var \App\Models\User $user */ $user = auth()->user(); @@ -35,7 +35,7 @@ class UpdateExpenseCategoryRequest extends Request public function rules() { - + /** @var \App\Models\User $user */ $user = auth()->user(); diff --git a/app/Http/Requests/Request.php b/app/Http/Requests/Request.php index 1a058e1eb50c..e70c7f6b3a55 100644 --- a/app/Http/Requests/Request.php +++ b/app/Http/Requests/Request.php @@ -198,18 +198,22 @@ class Request extends FormRequest } } - if(isset($input['public_notes'])) - $input['public_notes'] = str_replace("where('company_user.account_id', $user->account_id) ->join('users', 'users.id', '=', 'company_user.user_id') @@ -69,7 +69,7 @@ class CanAddUserRule implements Rule */ public function message() { - + /** @var \App\Models\User $user */ $user = auth()->user(); diff --git a/app/Http/ValidationRules/PaymentAppliedValidAmount.php b/app/Http/ValidationRules/PaymentAppliedValidAmount.php index 9c0ea741e79c..c6257fde8d1f 100644 --- a/app/Http/ValidationRules/PaymentAppliedValidAmount.php +++ b/app/Http/ValidationRules/PaymentAppliedValidAmount.php @@ -88,10 +88,9 @@ class PaymentAppliedValidAmount implements Rule nlog($inv->amount); nlog($invoice['amount']); - if($inv->status_id == Invoice::STATUS_DRAFT && $inv->amount >= $invoice['amount']){ + if($inv->status_id == Invoice::STATUS_DRAFT && $inv->amount >= $invoice['amount']) { - } - elseif ($inv->balance < $invoice['amount']) { + } elseif ($inv->balance < $invoice['amount']) { $this->message = 'Amount cannot be greater than invoice balance'; return false; diff --git a/app/Import/Providers/BaseImport.php b/app/Import/Providers/BaseImport.php index 56bda23e86af..297973e364ff 100644 --- a/app/Import/Providers/BaseImport.php +++ b/app/Import/Providers/BaseImport.php @@ -152,7 +152,7 @@ class BaseImport } } - + return $bestDelimiter ?? ','; } diff --git a/app/Import/Providers/Wave.php b/app/Import/Providers/Wave.php index 5d822c2092d2..03c0e00f1003 100644 --- a/app/Import/Providers/Wave.php +++ b/app/Import/Providers/Wave.php @@ -117,10 +117,8 @@ class Wave extends BaseImport implements ImportInterface $this->transformer = new InvoiceTransformer($this->company); - foreach($data as $key => $invoice) - { - if(!isset($invoice['Invoice Number']) || empty($invoice['Invoice Number'])) - { + foreach($data as $key => $invoice) { + if(!isset($invoice['Invoice Number']) || empty($invoice['Invoice Number'])) { unset($data[$key]); } } diff --git a/app/Jobs/Company/CompanyExport.php b/app/Jobs/Company/CompanyExport.php index 00b69d235bd7..7736a3fdca6b 100644 --- a/app/Jobs/Company/CompanyExport.php +++ b/app/Jobs/Company/CompanyExport.php @@ -72,13 +72,13 @@ class CompanyExport implements ShouldQueue $this->file_name = date('Y-m-d') . '_' . str_replace([" ", "/"], ["_",""], $this->company->present()->name() . '_' . $this->company->company_key . '.json'); -$this->writer = new File($this->file_name); + $this->writer = new File($this->file_name); set_time_limit(0); -$this->writer->value('app_version', config('ninja.app_version')); -$this->writer->value('storage_url', Storage::url('')); - + $this->writer->value('app_version', config('ninja.app_version')); + $this->writer->value('storage_url', Storage::url('')); + $this->export_data['activities'] = $this->company->all_activities->map(function ($activity) { $activity = $this->transformArrayOfKeys($activity, [ 'user_id', @@ -104,9 +104,9 @@ $this->writer->value('storage_url', Storage::url('')); })->makeHidden(['id'])->all(); -$x = $this->writer->collection('activities'); -$x->addItems($this->export_data['activities']); -$this->export_data = null; + $x = $this->writer->collection('activities'); + $x->addItems($this->export_data['activities']); + $this->export_data = null; $this->export_data['users'] = $this->company->users()->withTrashed()->cursor()->map(function ($user) { @@ -116,9 +116,9 @@ $this->export_data = null; -$x = $this->writer->collection('users'); -$x->addItems($this->export_data['users']); -$this->export_data = null; + $x = $this->writer->collection('users'); + $x->addItems($this->export_data['users']); + $this->export_data = null; $this->export_data['client_contacts'] = $this->company->client_contacts->map(function ($client_contact) { @@ -140,9 +140,9 @@ $this->export_data = null; })->all(); -$x = $this->writer->collection('client_contacts'); -$x->addItems($this->export_data['client_contacts']); -$this->export_data = null; + $x = $this->writer->collection('client_contacts'); + $x->addItems($this->export_data['client_contacts']); + $this->export_data = null; $this->export_data['client_gateway_tokens'] = $this->company->client_gateway_tokens->map(function ($client_gateway_token) { $client_gateway_token = $this->transformArrayOfKeys($client_gateway_token, ['company_id', 'client_id', 'company_gateway_id']); @@ -151,9 +151,9 @@ $this->export_data = null; })->all(); -$x = $this->writer->collection('client_gateway_tokens'); -$x->addItems($this->export_data['client_gateway_tokens']); -$this->export_data = null; + $x = $this->writer->collection('client_gateway_tokens'); + $x->addItems($this->export_data['client_gateway_tokens']); + $this->export_data = null; $this->export_data['clients'] = $this->company->clients()->orderBy('number', 'DESC')->cursor()->map(function ($client) { $client = $this->transformArrayOfKeys($client, ['company_id', 'user_id', 'assigned_user_id', 'group_settings_id']); @@ -162,18 +162,18 @@ $this->export_data = null; })->all(); -$x = $this->writer->collection('clients'); -$x->addItems($this->export_data['clients']); -$this->export_data = null; + $x = $this->writer->collection('clients'); + $x->addItems($this->export_data['clients']); + $this->export_data = null; // $this->export_data['company'] = $this->company->toArray(); // $this->export_data['company']['company_key'] = $this->createHash(); -$this->writer->value('company', $this->company->toJson(), encode: false); - -// $x = $this->writer->collection('company'); -// $x->addItems($this->export_data['company']); -// $this->export_data = null; + $this->writer->value('company', $this->company->toJson(), encode: false); + + // $x = $this->writer->collection('company'); + // $x->addItems($this->export_data['company']); + // $this->export_data = null; $this->export_data['company_gateways'] = $this->company->company_gateways()->withTrashed()->cursor()->map(function ($company_gateway) { @@ -184,11 +184,11 @@ $this->writer->value('company', $this->company->toJson(), encode: false); })->all(); -$x = $this->writer->collection('company_gateways'); -$x->addItems($this->export_data['company_gateways']); -$this->export_data = null; + $x = $this->writer->collection('company_gateways'); + $x->addItems($this->export_data['company_gateways']); + $this->export_data = null; + - $this->export_data['company_tokens'] = $this->company->tokens->map(function ($token) { @@ -198,9 +198,9 @@ $this->export_data = null; })->all(); -$x = $this->writer->collection('company_tokens'); -$x->addItems($this->export_data['company_tokens']); -$this->export_data = null; + $x = $this->writer->collection('company_tokens'); + $x->addItems($this->export_data['company_tokens']); + $this->export_data = null; $this->export_data['company_ledger'] = $this->company->ledger->map(function ($ledger) { @@ -210,20 +210,20 @@ $this->export_data = null; })->all(); -$x = $this->writer->collection('company_ledger'); -$x->addItems($this->export_data['company_ledger']); -$this->export_data = null; + $x = $this->writer->collection('company_ledger'); + $x->addItems($this->export_data['company_ledger']); + $this->export_data = null; + - $this->export_data['company_users'] = $this->company->company_users()->without(['user','account'])->cursor()->map(function ($company_user) { $company_user = $this->transformArrayOfKeys($company_user, ['company_id', 'account_id', 'user_id']); return $company_user; })->all(); -$x = $this->writer->collection('company_users'); -$x->addItems($this->export_data['company_users']); -$this->export_data = null; + $x = $this->writer->collection('company_users'); + $x->addItems($this->export_data['company_users']); + $this->export_data = null; $this->export_data['credits'] = $this->company->credits()->orderBy('number', 'DESC')->cursor()->map(function ($credit) { @@ -233,9 +233,9 @@ $this->export_data = null; return $credit->makeVisible(['id']); })->all(); -$x = $this->writer->collection('credits'); -$x->addItems($this->export_data['credits']); -$this->export_data = null; + $x = $this->writer->collection('credits'); + $x->addItems($this->export_data['credits']); + $this->export_data = null; $this->export_data['credit_invitations'] = CreditInvitation::query()->where('company_id', $this->company->id)->withTrashed()->cursor()->map(function ($credit) { @@ -244,18 +244,18 @@ $this->export_data = null; return $credit->makeVisible(['id']); })->all(); - -$x = $this->writer->collection('credit_invitations'); -$x->addItems($this->export_data['credit_invitations']); -$this->export_data = null; + + $x = $this->writer->collection('credit_invitations'); + $x->addItems($this->export_data['credit_invitations']); + $this->export_data = null; $this->export_data['designs'] = $this->company->user_designs->makeHidden(['id'])->all(); - -$x = $this->writer->collection('designs'); -$x->addItems($this->export_data['designs']); -$this->export_data = null; + + $x = $this->writer->collection('designs'); + $x->addItems($this->export_data['designs']); + $this->export_data = null; $this->export_data['documents'] = $this->company->all_documents->map(function ($document) { @@ -265,9 +265,9 @@ $this->export_data = null; return $document->makeVisible(['id']); })->all(); -$x = $this->writer->collection('documents'); -$x->addItems($this->export_data['documents']); -$this->export_data = null; + $x = $this->writer->collection('documents'); + $x->addItems($this->export_data['documents']); + $this->export_data = null; $this->export_data['expense_categories'] = $this->company->expense_categories()->cursor()->map(function ($expense_category) { $expense_category = $this->transformArrayOfKeys($expense_category, ['user_id', 'company_id']); @@ -275,9 +275,9 @@ $this->export_data = null; return $expense_category->makeVisible(['id']); })->all(); -$x = $this->writer->collection('expense_categories'); -$x->addItems($this->export_data['expense_categories']); -$this->export_data = null; + $x = $this->writer->collection('expense_categories'); + $x->addItems($this->export_data['expense_categories']); + $this->export_data = null; $this->export_data['expenses'] = $this->company->expenses()->orderBy('number', 'DESC')->cursor()->map(function ($expense) { @@ -288,9 +288,9 @@ $this->export_data = null; })->all(); -$x = $this->writer->collection('expenses'); -$x->addItems($this->export_data['expenses']); -$this->export_data = null; + $x = $this->writer->collection('expenses'); + $x->addItems($this->export_data['expenses']); + $this->export_data = null; $this->export_data['group_settings'] = $this->company->group_settings->map(function ($gs) { @@ -299,10 +299,10 @@ $this->export_data = null; return $gs->makeVisible(['id']); })->all(); - -$x = $this->writer->collection('group_settings'); -$x->addItems($this->export_data['group_settings']); -$this->export_data = null; + + $x = $this->writer->collection('group_settings'); + $x->addItems($this->export_data['group_settings']); + $this->export_data = null; $this->export_data['invoices'] = $this->company->invoices()->orderBy('number', 'DESC')->cursor()->map(function ($invoice) { @@ -318,9 +318,9 @@ $this->export_data = null; })->all(); -$x = $this->writer->collection('invoices'); -$x->addItems($this->export_data['invoices']); -$this->export_data = null; + $x = $this->writer->collection('invoices'); + $x->addItems($this->export_data['invoices']); + $this->export_data = null; $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']); @@ -329,9 +329,9 @@ $this->export_data = null; })->all(); -$x = $this->writer->collection('invoice_invitations'); -$x->addItems($this->export_data['invoice_invitations']); -$this->export_data = null; + $x = $this->writer->collection('invoice_invitations'); + $x->addItems($this->export_data['invoice_invitations']); + $this->export_data = null; $this->export_data['payment_terms'] = $this->company->user_payment_terms->map(function ($term) { @@ -340,10 +340,10 @@ $this->export_data = null; return $term; })->makeHidden(['id'])->all(); - -$x = $this->writer->collection('payment_terms'); -$x->addItems($this->export_data['payment_terms']); -$this->export_data = null; + + $x = $this->writer->collection('payment_terms'); + $x->addItems($this->export_data['payment_terms']); + $this->export_data = null; $this->export_data['payments'] = $this->company->payments()->orderBy('number', 'DESC')->cursor()->map(function ($payment) { @@ -357,9 +357,9 @@ $this->export_data = null; -$x = $this->writer->collection('payments'); -$x->addItems($this->export_data['payments']); -$this->export_data = null; + $x = $this->writer->collection('payments'); + $x->addItems($this->export_data['payments']); + $this->export_data = null; $this->export_data['products'] = $this->company->products->map(function ($product) { @@ -370,9 +370,9 @@ $this->export_data = null; })->all(); -$x = $this->writer->collection('products'); -$x->addItems($this->export_data['products']); -$this->export_data = null; + $x = $this->writer->collection('products'); + $x->addItems($this->export_data['products']); + $this->export_data = null; $this->export_data['projects'] = $this->company->projects()->orderBy('number', 'DESC')->cursor()->map(function ($project) { @@ -383,9 +383,9 @@ $this->export_data = null; })->all(); -$x = $this->writer->collection('projects'); -$x->addItems($this->export_data['projects']); -$this->export_data = null; + $x = $this->writer->collection('projects'); + $x->addItems($this->export_data['projects']); + $this->export_data = null; $this->export_data['quotes'] = $this->company->quotes()->orderBy('number', 'DESC')->cursor()->map(function ($quote) { @@ -395,10 +395,10 @@ $this->export_data = null; return $quote->makeVisible(['id']); })->all(); - -$x = $this->writer->collection('quotes'); -$x->addItems($this->export_data['quotes']); -$this->export_data = null; + + $x = $this->writer->collection('quotes'); + $x->addItems($this->export_data['quotes']); + $this->export_data = null; $this->export_data['quote_invitations'] = QuoteInvitation::query()->where('company_id', $this->company->id)->withTrashed()->cursor()->map(function ($quote) { @@ -408,9 +408,9 @@ $this->export_data = null; })->all(); -$x = $this->writer->collection('quote_invitations'); -$x->addItems($this->export_data['quote_invitations']); -$this->export_data = null; + $x = $this->writer->collection('quote_invitations'); + $x->addItems($this->export_data['quote_invitations']); + $this->export_data = null; $this->export_data['recurring_expenses'] = $this->company->recurring_expenses()->orderBy('number', 'DESC')->cursor()->map(function ($expense) { @@ -422,9 +422,9 @@ $this->export_data = null; -$x = $this->writer->collection('recurring_expenses'); -$x->addItems($this->export_data['recurring_expenses']); -$this->export_data = null; + $x = $this->writer->collection('recurring_expenses'); + $x->addItems($this->export_data['recurring_expenses']); + $this->export_data = null; $this->export_data['recurring_invoices'] = $this->company->recurring_invoices()->orderBy('number', 'DESC')->cursor()->map(function ($ri) { @@ -434,10 +434,10 @@ $this->export_data = null; return $ri->makeVisible(['id']); })->all(); - -$x = $this->writer->collection('recurring_invoices'); -$x->addItems($this->export_data['recurring_invoices']); -$this->export_data = null; + + $x = $this->writer->collection('recurring_invoices'); + $x->addItems($this->export_data['recurring_invoices']); + $this->export_data = null; $this->export_data['recurring_invoice_invitations'] = RecurringInvoiceInvitation::query()->where('company_id', $this->company->id)->withTrashed()->cursor()->map(function ($ri) { @@ -447,9 +447,9 @@ $this->export_data = null; })->all(); -$x = $this->writer->collection('recurring_invoice_invitations'); -$x->addItems($this->export_data['recurring_invoice_invitations']); -$this->export_data = null; + $x = $this->writer->collection('recurring_invoice_invitations'); + $x->addItems($this->export_data['recurring_invoice_invitations']); + $this->export_data = null; @@ -467,9 +467,9 @@ $this->export_data = null; })->all(); -$x = $this->writer->collection('subscriptions'); -$x->addItems($this->export_data['subscriptions']); -$this->export_data = null; + $x = $this->writer->collection('subscriptions'); + $x->addItems($this->export_data['subscriptions']); + $this->export_data = null; $this->export_data['system_logs'] = $this->company->system_logs->map(function ($log) { $log->client_id = $this->encodePrimaryKey($log->client_id); @@ -479,9 +479,9 @@ $this->export_data = null; })->makeHidden(['id'])->all(); -$x = $this->writer->collection('system_logs'); -$x->addItems($this->export_data['system_logs']); -$this->export_data = null; + $x = $this->writer->collection('system_logs'); + $x->addItems($this->export_data['system_logs']); + $this->export_data = null; $this->export_data['tasks'] = $this->company->tasks()->orderBy('number', 'DESC')->cursor()->map(function ($task) { @@ -493,9 +493,9 @@ $this->export_data = null; -$x = $this->writer->collection('tasks'); -$x->addItems($this->export_data['tasks']); -$this->export_data = null; + $x = $this->writer->collection('tasks'); + $x->addItems($this->export_data['tasks']); + $this->export_data = null; $this->export_data['task_statuses'] = $this->company->task_statuses->map(function ($status) { @@ -508,9 +508,9 @@ $this->export_data = null; -$x = $this->writer->collection('task_statuses'); -$x->addItems($this->export_data['task_statuses']); -$this->export_data = null; + $x = $this->writer->collection('task_statuses'); + $x->addItems($this->export_data['task_statuses']); + $this->export_data = null; $this->export_data['tax_rates'] = $this->company->tax_rates->map(function ($rate) { @@ -522,9 +522,9 @@ $this->export_data = null; -$x = $this->writer->collection('tax_rates'); -$x->addItems($this->export_data['tax_rates']); -$this->export_data = null; + $x = $this->writer->collection('tax_rates'); + $x->addItems($this->export_data['tax_rates']); + $this->export_data = null; $this->export_data['vendors'] = $this->company->vendors()->orderBy('number', 'DESC')->cursor()->map(function ($vendor) { @@ -532,10 +532,10 @@ $this->export_data = null; })->all(); - -$x = $this->writer->collection('vendors'); -$x->addItems($this->export_data['vendors']); -$this->export_data = null; + + $x = $this->writer->collection('vendors'); + $x->addItems($this->export_data['vendors']); + $this->export_data = null; $this->export_data['vendor_contacts'] = VendorContact::where('company_id', $this->company->id)->withTrashed()->cursor()->map(function ($vendor) { @@ -547,9 +547,9 @@ $this->export_data = null; -$x = $this->writer->collection('vendor_contacts'); -$x->addItems($this->export_data['vendor_contacts']); -$this->export_data = null; + $x = $this->writer->collection('vendor_contacts'); + $x->addItems($this->export_data['vendor_contacts']); + $this->export_data = null; $this->export_data['webhooks'] = $this->company->webhooks->map(function ($hook) { @@ -560,9 +560,9 @@ $this->export_data = null; })->makeHidden(['id'])->all(); -$x = $this->writer->collection('webhooks'); -$x->addItems($this->export_data['webhooks']); -$this->export_data = null; + $x = $this->writer->collection('webhooks'); + $x->addItems($this->export_data['webhooks']); + $this->export_data = null; $this->export_data['purchase_orders'] = $this->company->purchase_orders()->orderBy('number', 'DESC')->cursor()->map(function ($purchase_order) { @@ -578,9 +578,9 @@ $this->export_data = null; })->all(); -$x = $this->writer->collection('purchase_orders'); -$x->addItems($this->export_data['purchase_orders']); -$this->export_data = null; + $x = $this->writer->collection('purchase_orders'); + $x->addItems($this->export_data['purchase_orders']); + $this->export_data = null; @@ -591,9 +591,9 @@ $this->export_data = null; })->all(); -$x = $this->writer->collection('purchase_order_invitations'); -$x->addItems($this->export_data['purchase_order_invitations']); -$this->export_data = null; + $x = $this->writer->collection('purchase_order_invitations'); + $x->addItems($this->export_data['purchase_order_invitations']); + $this->export_data = null; $this->export_data['bank_integrations'] = $this->company->bank_integrations()->withTrashed()->orderBy('id', 'ASC')->cursor()->map(function ($bank_integration) { $bank_integration = $this->transformArrayOfKeys($bank_integration, ['account_id','company_id', 'user_id']); @@ -601,9 +601,9 @@ $this->export_data = null; return $bank_integration->makeVisible(['id','user_id','company_id','account_id','hashed_id']); })->all(); -$x = $this->writer->collection('bank_integrations'); -$x->addItems($this->export_data['bank_integrations']); -$this->export_data = null; + $x = $this->writer->collection('bank_integrations'); + $x->addItems($this->export_data['bank_integrations']); + $this->export_data = null; $this->export_data['bank_transactions'] = $this->company->bank_transactions()->withTrashed()->orderBy('id', 'ASC')->cursor()->map(function ($bank_transaction) { $bank_transaction = $this->transformArrayOfKeys($bank_transaction, ['company_id', 'user_id','bank_integration_id','expense_id','ninja_category_id','vendor_id']); @@ -611,9 +611,9 @@ $this->export_data = null; return $bank_transaction->makeVisible(['id','user_id','company_id']); })->all(); -$x = $this->writer->collection('bank_transactions'); -$x->addItems($this->export_data['bank_transactions']); -$this->export_data = null; + $x = $this->writer->collection('bank_transactions'); + $x->addItems($this->export_data['bank_transactions']); + $this->export_data = null; $this->export_data['schedulers'] = $this->company->schedulers()->withTrashed()->orderBy('id', 'ASC')->cursor()->map(function ($scheduler) { $scheduler = $this->transformArrayOfKeys($scheduler, ['company_id', 'user_id']); @@ -621,14 +621,14 @@ $this->export_data = null; return $scheduler->makeVisible(['id','user_id','company_id']); })->all(); -$x = $this->writer->collection('schedulers'); -$x->addItems($this->export_data['schedulers']); -$this->export_data = null; + $x = $this->writer->collection('schedulers'); + $x->addItems($this->export_data['schedulers']); + $this->export_data = null; //write to tmp and email to owner(); -$this->writer->end(); + $this->writer->end(); $this->zipAndSend(); @@ -680,20 +680,20 @@ $this->writer->end(); $zip->close(); - Storage::disk(config('filesystems.default'))->put('backups/'.str_replace(".json", ".zip",$this->file_name), file_get_contents($zip_path)); + Storage::disk(config('filesystems.default'))->put('backups/'.str_replace(".json", ".zip", $this->file_name), file_get_contents($zip_path)); if(file_exists($zip_path)) { unlink($zip_path); } - if(file_exists($this->file_name)){ + if(file_exists($this->file_name)) { unlink($this->file_name); } if(Ninja::isSelfHost()) { - $storage_path = 'backups/'.str_replace(".json", ".zip",$this->file_name); + $storage_path = 'backups/'.str_replace(".json", ".zip", $this->file_name); } else { - $storage_path = Storage::disk(config('filesystems.default'))->path('backups/'.str_replace(".json", ".zip",$this->file_name)); + $storage_path = Storage::disk(config('filesystems.default'))->path('backups/'.str_replace(".json", ".zip", $this->file_name)); } $url = Cache::get($this->hash); diff --git a/app/Jobs/Company/CompanyImport.php b/app/Jobs/Company/CompanyImport.php index 0fe90c3e229d..ca0c8d7adef6 100644 --- a/app/Jobs/Company/CompanyImport.php +++ b/app/Jobs/Company/CompanyImport.php @@ -338,7 +338,7 @@ class CompanyImport implements ShouldQueue private function unzipFile() { $path = TempFile::filePath(Storage::disk(config('filesystems.default'))->get($this->file_location), basename($this->file_location)); - + $zip = new ZipArchive(); $res = $zip->open($path); $file_path = sys_get_temp_dir().'/'.sha1(microtime()); @@ -357,7 +357,7 @@ class CompanyImport implements ShouldQueue } $file_path = "{$file_path}/backup.json"; - + nlog($file_path); if (! file_exists($file_path)) { diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index a9c0a65d2620..0330156f7419 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -99,10 +99,9 @@ class NinjaMailerJob implements ShouldQueue } $this->nmo->mailable->replyTo($this->nmo->settings->reply_to_email, $reply_to_name); - }elseif(isset($this->nmo->invitation->user)){ + } elseif(isset($this->nmo->invitation->user)) { $this->nmo->mailable->replyTo($this->nmo->invitation->user->email, $this->nmo->invitation->user->present()->name()); - } - else { + } else { $this->nmo->mailable->replyTo($this->company->owner()->email, $this->company->owner()->present()->name()); } @@ -135,7 +134,7 @@ class NinjaMailerJob implements ShouldQueue } $mailable = $this->nmo->mailable; - + /** May need to re-build it here */ if(Ninja::isHosted() && method_exists($mailable, 'build')) { $mailable->build(); @@ -269,14 +268,14 @@ class NinjaMailerJob implements ShouldQueue if(Ninja::isHosted() && $this->company->account->isPaid() && $this->nmo->settings->email_sending_method == 'default') { //check if outlook. - - try{ + + try { $email = $this->nmo->to_user->email; $domain = explode("@", $email)[1] ?? ""; $dns = dns_get_record($domain, DNS_MX); $server = $dns[0]["target"]; - if(stripos($server, "outlook.com") !== false){ - + if(stripos($server, "outlook.com") !== false) { + $this->mailer = 'postmark'; $this->client_postmark_secret = config('services.postmark-outlook.token'); @@ -286,8 +285,7 @@ class NinjaMailerJob implements ShouldQueue return $this; } - } - catch(\Exception $e){ + } catch(\Exception $e) { nlog($e->getMessage()); } } @@ -409,7 +407,7 @@ class NinjaMailerJob implements ShouldQueue private function setHostedMailgunMailer() { - + if (property_exists($this->nmo->settings, 'email_from_name') && strlen($this->nmo->settings->email_from_name) > 1) { $email_from_name = $this->nmo->settings->email_from_name; } else { diff --git a/app/Jobs/Mail/NinjaMailerObject.php b/app/Jobs/Mail/NinjaMailerObject.php index f2cf0f646111..6a1ba07dd81e 100644 --- a/app/Jobs/Mail/NinjaMailerObject.php +++ b/app/Jobs/Mail/NinjaMailerObject.php @@ -16,7 +16,6 @@ namespace App\Jobs\Mail; */ class NinjaMailerObject { - /* @var Illuminate\Mail\Mailable */ public $mailable; diff --git a/app/Jobs/Mailgun/ProcessMailgunWebhook.php b/app/Jobs/Mailgun/ProcessMailgunWebhook.php index 5b7182ecc298..3797d810214d 100644 --- a/app/Jobs/Mailgun/ProcessMailgunWebhook.php +++ b/app/Jobs/Mailgun/ProcessMailgunWebhook.php @@ -34,7 +34,10 @@ use App\Notifications\Ninja\EmailBounceNotification; class ProcessMailgunWebhook implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + use Dispatchable; + use InteractsWithQueue; + use Queueable; + use SerializesModels; public $tries = 1; @@ -89,8 +92,9 @@ class ProcessMailgunWebhook implements ShouldQueue { nlog($this->request); - if(!$this->request['event-data']['tags'][0]) + if(!$this->request['event-data']['tags'][0]) { return; + } MultiDB::findAndSetDbByCompanyKey($this->request['event-data']['tags'][0]); $company = Company::where('company_key', $this->request['event-data']['tags'][0])->first(); @@ -112,7 +116,7 @@ class ProcessMailgunWebhook implements ShouldQueue if (isset($this->request['event-details']['delivery-status']['message'])) { $this->invitation->email_error = $this->request['event-details']['delivery-status']['message']; } - + switch ($this->request['event-data']['event']) { case 'delivered': return $this->processDelivery(); @@ -128,50 +132,50 @@ class ProcessMailgunWebhook implements ShouldQueue } } -/* -{ - "signature": { - "token": "7f388cf8096aa0bca1477aee9d91e156c61f8fa8282c7f1c0c", - "timestamp": "1705376308", - "signature": "a22b7c3dd4861e27a1664cef3611a1954c0665cfcaca9b8f35ee216243a4ce3f" - }, - "event-data": { - "id": "Ase7i2zsRYeDXztHGENqRA", - "timestamp": 1521243339.873676, - "log-level": "info", - "event": "opened", - "message": { - "headers": { - "message-id": "20130503182626.18666.16540@mail.invoicing.co" + /* + { + "signature": { + "token": "7f388cf8096aa0bca1477aee9d91e156c61f8fa8282c7f1c0c", + "timestamp": "1705376308", + "signature": "a22b7c3dd4861e27a1664cef3611a1954c0665cfcaca9b8f35ee216243a4ce3f" + }, + "event-data": { + "id": "Ase7i2zsRYeDXztHGENqRA", + "timestamp": 1521243339.873676, + "log-level": "info", + "event": "opened", + "message": { + "headers": { + "message-id": "20130503182626.18666.16540@mail.invoicing.co" + } + }, + "recipient": "alice@example.com", + "recipient-domain": "example.com", + "ip": "50.56.129.169", + "geolocation": { + "country": "US", + "region": "CA", + "city": "San Francisco" + }, + "client-info": { + "client-os": "Linux", + "device-type": "desktop", + "client-name": "Chrome", + "client-type": "browser", + "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31" + }, + "campaigns": [], + "tags": [ + "my_tag_1", + "my_tag_2" + ], + "user-variables": { + "my_var_1": "Mailgun Variable #1", + "my-var-2": "awesome" + } } - }, - "recipient": "alice@example.com", - "recipient-domain": "example.com", - "ip": "50.56.129.169", - "geolocation": { - "country": "US", - "region": "CA", - "city": "San Francisco" - }, - "client-info": { - "client-os": "Linux", - "device-type": "desktop", - "client-name": "Chrome", - "client-type": "browser", - "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31" - }, - "campaigns": [], - "tags": [ - "my_tag_1", - "my_tag_2" - ], - "user-variables": { - "my_var_1": "Mailgun Variable #1", - "my-var-2": "awesome" } - } -} -*/ + */ private function processOpen() { $this->invitation->opened_date = now(); @@ -180,8 +184,9 @@ class ProcessMailgunWebhook implements ShouldQueue $sl = $this->getSystemLog($this->request['MessageID']); /** Prevents Gmail tracking from firing inappropriately */ - if($this->request['signature']['timestamp'] < $sl->log['signature']['timestamp'] + 3) + if($this->request['signature']['timestamp'] < $sl->log['signature']['timestamp'] + 3) { return; + } $event = [ 'bounce_id' => '', @@ -201,74 +206,74 @@ class ProcessMailgunWebhook implements ShouldQueue } -/* -{ - "signature": { - "token": "70b91a64ed0f1bdf90fb9c6ea7e3c31d5792a3d0945ffc20fe", - "timestamp": "1705376276", - "signature": "ba96f841fc236e1bf5840b02fad512d0bd15b0731b5e6b154764c7a05f7ee999" - }, - "event-data": { - "id": "CPgfbmQMTCKtHW6uIWtuVe", - "timestamp": 1521472262.908181, - "log-level": "info", - "event": "delivered", - "delivery-status": { - "tls": true, - "mx-host": "smtp-in.example.com", - "code": 250, - "description": "", - "session-seconds": 0.4331989288330078, - "utf8": true, - "attempt-no": 1, - "message": "OK", - "certificate-verified": true - }, - "flags": { - "is-routed": false, - "is-authenticated": true, - "is-system-test": false, - "is-test-mode": false - }, - "envelope": { - "transport": "smtp", - "sender": "bob@mail.invoicing.co", - "sending-ip": "209.61.154.250", - "targets": "alice@example.com" - }, - "message": { - "headers": { - "to": "Alice ", - "message-id": "20130503182626.18666.16540@mail.invoicing.co", - "from": "Bob ", - "subject": "Test delivered webhook" + /* + { + "signature": { + "token": "70b91a64ed0f1bdf90fb9c6ea7e3c31d5792a3d0945ffc20fe", + "timestamp": "1705376276", + "signature": "ba96f841fc236e1bf5840b02fad512d0bd15b0731b5e6b154764c7a05f7ee999" }, - "attachments": [], - "size": 111 - }, - "recipient": "alice@example.com", - "recipient-domain": "example.com", - "storage": { - "url": "https://se.api.mailgun.net/v3/domains/mail.invoicing.co/messages/message_key", - "key": "message_key" - }, - "campaigns": [], - "tags": [ - "my_tag_1", - "my_tag_2" - ], - "user-variables": { - "my_var_1": "Mailgun Variable #1", - "my-var-2": "awesome" + "event-data": { + "id": "CPgfbmQMTCKtHW6uIWtuVe", + "timestamp": 1521472262.908181, + "log-level": "info", + "event": "delivered", + "delivery-status": { + "tls": true, + "mx-host": "smtp-in.example.com", + "code": 250, + "description": "", + "session-seconds": 0.4331989288330078, + "utf8": true, + "attempt-no": 1, + "message": "OK", + "certificate-verified": true + }, + "flags": { + "is-routed": false, + "is-authenticated": true, + "is-system-test": false, + "is-test-mode": false + }, + "envelope": { + "transport": "smtp", + "sender": "bob@mail.invoicing.co", + "sending-ip": "209.61.154.250", + "targets": "alice@example.com" + }, + "message": { + "headers": { + "to": "Alice ", + "message-id": "20130503182626.18666.16540@mail.invoicing.co", + "from": "Bob ", + "subject": "Test delivered webhook" + }, + "attachments": [], + "size": 111 + }, + "recipient": "alice@example.com", + "recipient-domain": "example.com", + "storage": { + "url": "https://se.api.mailgun.net/v3/domains/mail.invoicing.co/messages/message_key", + "key": "message_key" + }, + "campaigns": [], + "tags": [ + "my_tag_1", + "my_tag_2" + ], + "user-variables": { + "my_var_1": "Mailgun Variable #1", + "my-var-2": "awesome" + } + } } - } -} -*/ + */ private function processDelivery() { $this->invitation->email_status = 'delivered'; $this->invitation->save(); - + $sl = $this->getSystemLog($this->request['MessageID']); if($sl) { @@ -384,47 +389,47 @@ class ProcessMailgunWebhook implements ShouldQueue } -/* -{ - "signature": { - "token": "d7be371deef49c8b187119df295e3eb17fd1974d513a4be2cb", - "timestamp": "1705376380", - "signature": "52f31c75b492d67be906423279e0effe563e28790ee65ba23a1b30006df649df" - }, - "event-data": { - "id": "-Agny091SquKnsrW2NEKUA", - "timestamp": 1521233123.501324, - "log-level": "warn", - "event": "complained", - "envelope": { - "sending-ip": "173.193.210.33" - }, - "flags": { - "is-test-mode": false - }, - "message": { - "headers": { - "to": "Alice ", - "message-id": "20110215055645.25246.63817@mail.invoicing.co", - "from": "Bob ", - "subject": "Test complained webhook" + /* + { + "signature": { + "token": "d7be371deef49c8b187119df295e3eb17fd1974d513a4be2cb", + "timestamp": "1705376380", + "signature": "52f31c75b492d67be906423279e0effe563e28790ee65ba23a1b30006df649df" }, - "attachments": [], - "size": 111 - }, - "recipient": "alice@example.com", - "campaigns": [], - "tags": [ - "my_tag_1", - "my_tag_2" - ], - "user-variables": { - "my_var_1": "Mailgun Variable #1", - "my-var-2": "awesome" + "event-data": { + "id": "-Agny091SquKnsrW2NEKUA", + "timestamp": 1521233123.501324, + "log-level": "warn", + "event": "complained", + "envelope": { + "sending-ip": "173.193.210.33" + }, + "flags": { + "is-test-mode": false + }, + "message": { + "headers": { + "to": "Alice ", + "message-id": "20110215055645.25246.63817@mail.invoicing.co", + "from": "Bob ", + "subject": "Test complained webhook" + }, + "attachments": [], + "size": 111 + }, + "recipient": "alice@example.com", + "campaigns": [], + "tags": [ + "my_tag_1", + "my_tag_2" + ], + "user-variables": { + "my_var_1": "Mailgun Variable #1", + "my-var-2": "awesome" + } + } } - } -} -*/ + */ private function processSpamComplaint() { $this->invitation->email_status = 'spam'; diff --git a/app/Jobs/Ninja/TaskScheduler.php b/app/Jobs/Ninja/TaskScheduler.php index af0c2efc9c58..ff200ba0f2ba 100644 --- a/app/Jobs/Ninja/TaskScheduler.php +++ b/app/Jobs/Ninja/TaskScheduler.php @@ -56,7 +56,7 @@ class TaskScheduler implements ShouldQueue ->where('next_run', '<=', now()) ->cursor() ->each(function ($scheduler) { - + nlog("Doing job {$scheduler->name}"); try { @@ -81,7 +81,7 @@ class TaskScheduler implements ShouldQueue ->where('next_run', '<=', now()) ->cursor() ->each(function ($scheduler) { - + nlog("Doing job {$scheduler->name}"); try { diff --git a/app/Jobs/Payment/EmailPayment.php b/app/Jobs/Payment/EmailPayment.php index c40f40de7905..e894408ed3f2 100644 --- a/app/Jobs/Payment/EmailPayment.php +++ b/app/Jobs/Payment/EmailPayment.php @@ -106,7 +106,7 @@ class EmailPayment implements ShouldQueue (new NinjaMailerJob($nmo))->handle(); event(new PaymentWasEmailed($this->payment, $this->payment->company, $this->contact, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); - + } private function emailAllContacts($email_builder): void diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index 06edfa791b30..2f8a9d315023 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -1144,7 +1144,7 @@ class Import implements ShouldQueue ); $key = "invoices_{$resource['id']}"; - + nlog($invoice->id); $this->ids['invoices'][$key] = [ @@ -1409,7 +1409,7 @@ class Import implements ShouldQueue } nlog($payment->id); - + $old_user_key = array_key_exists('user_id', $resource) ?? $this->user->id; $this->ids['payments'] = [ @@ -1528,8 +1528,8 @@ class Import implements ShouldQueue } } - - // throw new Exception("Resource invoice/quote document not available."); + + // throw new Exception("Resource invoice/quote document not available."); } if (array_key_exists('expense_id', $resource) && $resource['expense_id'] && array_key_exists('expenses', $this->ids)) { @@ -2078,7 +2078,7 @@ class Import implements ShouldQueue nlog(print_r($exception->getMessage(), 1)); // if (Ninja::isHosted()) { - app('sentry')->captureException($exception); + app('sentry')->captureException($exception); // } } diff --git a/app/Jobs/Util/ReminderJob.php b/app/Jobs/Util/ReminderJob.php index 2c79b7c67490..c299232d2e50 100644 --- a/app/Jobs/Util/ReminderJob.php +++ b/app/Jobs/Util/ReminderJob.php @@ -38,7 +38,7 @@ class ReminderJob implements ShouldQueue use SerializesModels; use MakesReminders; use MakesDates; - + public $tries = 1; public function __construct() diff --git a/app/Listeners/Invoice/InvoiceEmailFailedActivity.php b/app/Listeners/Invoice/InvoiceEmailFailedActivity.php index d2df49622fae..be8b1430e21d 100644 --- a/app/Listeners/Invoice/InvoiceEmailFailedActivity.php +++ b/app/Listeners/Invoice/InvoiceEmailFailedActivity.php @@ -59,7 +59,7 @@ class InvoiceEmailFailedActivity implements ShouldQueue $fields->company_id = $event->invitation->invoice->company_id; $fields->activity_type_id = Activity::EMAIL_INVOICE_FAILED; $fields->notes = $event->message ?? ''; - + $this->activity_repo->save($fields, $event->invitation->invoice, $event->event_vars); } } diff --git a/app/Listeners/Invoice/InvoiceFailedEmailNotification.php b/app/Listeners/Invoice/InvoiceFailedEmailNotification.php index f2d58edbe872..b830f9f5cf44 100644 --- a/app/Listeners/Invoice/InvoiceFailedEmailNotification.php +++ b/app/Listeners/Invoice/InvoiceFailedEmailNotification.php @@ -37,8 +37,9 @@ class InvoiceFailedEmailNotification { MultiDB::setDb($event->company->db); - if(Cache::has("invoice_failed_email_notification_{$event->invitation->key}")) + if(Cache::has("invoice_failed_email_notification_{$event->invitation->key}")) { return; + } $invoice = $event->invitation->invoice; diff --git a/app/Livewire/BillingPortalPurchase.php b/app/Livewire/BillingPortalPurchase.php index 8ba6fe855d35..2e11b6b258d3 100644 --- a/app/Livewire/BillingPortalPurchase.php +++ b/app/Livewire/BillingPortalPurchase.php @@ -326,7 +326,7 @@ class BillingPortalPurchase extends Component $this->contact = $contact; if ($contact->showRff()) { - return $this->rff(); + return $this->rff(); } Auth::guard('contact')->loginUsingId($contact->id, true); diff --git a/app/Livewire/PdfSlot.php b/app/Livewire/PdfSlot.php index 709b14940dca..047f8cc812d2 100644 --- a/app/Livewire/PdfSlot.php +++ b/app/Livewire/PdfSlot.php @@ -131,7 +131,7 @@ class PdfSlot extends Component $this->settings = $this->entity->client ? $this->entity->client->getMergedSettings() : $this->entity->company->settings; $this->html_entity_option = $this->entity->client ? $this->entity->client->getSetting('show_pdfhtml_on_mobile') : $this->entity->company->getSetting('show_pdfhtml_on_mobile'); - + $this->show_cost = in_array('$product.unit_cost', $this->settings->pdf_variables->product_columns); $this->show_line_total = in_array('$product.line_total', $this->settings->pdf_variables->product_columns); $this->show_quantity = in_array('$product.quantity', $this->settings->pdf_variables->product_columns); diff --git a/app/Mail/Admin/EntityCreatedObject.php b/app/Mail/Admin/EntityCreatedObject.php index baab3068db25..bc814c37e4ad 100644 --- a/app/Mail/Admin/EntityCreatedObject.php +++ b/app/Mail/Admin/EntityCreatedObject.php @@ -76,13 +76,13 @@ class EntityCreatedObject $mail_obj->text_view = 'email.template.text'; $content = ctrans( - $this->template_body, - [ + $this->template_body, + [ 'amount' => $mail_obj->amount, 'vendor' => $this->entity->vendor->present()->name(), 'purchase_order' => $this->entity->number, ] - ); + ); $mail_obj->data = [ 'title' => $mail_obj->subject, diff --git a/app/Mail/Admin/EntityFailedSendObject.php b/app/Mail/Admin/EntityFailedSendObject.php index 53ce0de33500..a6c9a4775bf3 100644 --- a/app/Mail/Admin/EntityFailedSendObject.php +++ b/app/Mail/Admin/EntityFailedSendObject.php @@ -132,15 +132,15 @@ class EntityFailedSendObject $html_variables = (new HtmlEngine($this->invitation))->makeValues(); $signature = str_replace(array_keys($html_variables), array_values($html_variables), $signature); $content = ctrans( - $this->template_body, - [ + $this->template_body, + [ 'amount' => $this->getAmount(), 'client' => $this->contact->present()->name(), 'invoice' => $this->entity->number, 'error' => $this->message_content ?? '', 'contact' => $this->contact->present()->name(), ] - ); + ); $data = [ "title" => $this->getSubject(), diff --git a/app/Mail/Admin/EntityNotificationMailer.php b/app/Mail/Admin/EntityNotificationMailer.php index fe131b3e4eec..007d8fc2b744 100644 --- a/app/Mail/Admin/EntityNotificationMailer.php +++ b/app/Mail/Admin/EntityNotificationMailer.php @@ -12,6 +12,7 @@ namespace App\Mail\Admin; use Illuminate\Mail\Mailable; + //@deprecated? class EntityNotificationMailer extends Mailable { diff --git a/app/Mail/Admin/EntityPaidObject.php b/app/Mail/Admin/EntityPaidObject.php index 143119d8af05..441ab58c3a96 100644 --- a/app/Mail/Admin/EntityPaidObject.php +++ b/app/Mail/Admin/EntityPaidObject.php @@ -85,8 +85,8 @@ class EntityPaidObject $invoice_texts = substr($invoice_texts, 0, -1); $content = ctrans( - 'texts.notification_payment_paid', - ['amount' => $amount, + 'texts.notification_payment_paid', + ['amount' => $amount, 'client' => $this->payment->client->present()->name(), 'invoice' => $invoice_texts, ] diff --git a/app/Mail/Admin/EntitySentObject.php b/app/Mail/Admin/EntitySentObject.php index 8ba5700eb270..6433f0a3f223 100644 --- a/app/Mail/Admin/EntitySentObject.php +++ b/app/Mail/Admin/EntitySentObject.php @@ -98,7 +98,7 @@ class EntitySentObject $mail_obj->markdown = 'email.admin.generic'; $mail_obj->tag = $this->company->company_key; } - + $mail_obj->text_view = 'email.template.text'; return $mail_obj; @@ -186,7 +186,7 @@ class EntitySentObject { $settings = $this->entity->client->getMergedSettings(); $content = $this->getMessage(); - + return [ 'title' => $this->getSubject(), 'content' => $content, diff --git a/app/Mail/Admin/EntityViewedObject.php b/app/Mail/Admin/EntityViewedObject.php index c9272fa98bf5..c88ee9547011 100644 --- a/app/Mail/Admin/EntityViewedObject.php +++ b/app/Mail/Admin/EntityViewedObject.php @@ -98,13 +98,13 @@ class EntityViewedObject } $content = ctrans( - "texts.notification_{$this->entity_type}_viewed", - [ + "texts.notification_{$this->entity_type}_viewed", + [ 'amount' => $this->getAmount(), 'client' => $this->contact->present()->name(), 'invoice' => $this->entity->number, ] - ); + ); $data = [ 'title' => $this->getSubject(), diff --git a/app/Mail/Admin/InventoryNotificationObject.php b/app/Mail/Admin/InventoryNotificationObject.php index b73fd181e4e8..8c40c25af0b3 100644 --- a/app/Mail/Admin/InventoryNotificationObject.php +++ b/app/Mail/Admin/InventoryNotificationObject.php @@ -60,12 +60,12 @@ class InventoryNotificationObject private function getData() { $content = ctrans( - 'texts.inventory_notification_body', - ['amount' => $this->getAmount(), + 'texts.inventory_notification_body', + ['amount' => $this->getAmount(), 'product' => $this->product->product_key.': '.$this->product->notes, ] ); - + $data = [ 'title' => $this->getSubject(), 'content' => $content, diff --git a/app/Mail/Admin/PaymentFailureObject.php b/app/Mail/Admin/PaymentFailureObject.php index 61fe41c71ef8..bd714b54a777 100644 --- a/app/Mail/Admin/PaymentFailureObject.php +++ b/app/Mail/Admin/PaymentFailureObject.php @@ -75,14 +75,14 @@ class PaymentFailureObject { $signature = $this->client->getSetting('email_signature'); $content = ctrans( - 'texts.notification_invoice_payment_failed', - [ + 'texts.notification_invoice_payment_failed', + [ 'client' => $this->client->present()->name(), 'invoice' => $this->getDescription(), 'amount' => Number::formatMoney($this->amount, $this->client), ] - ); - + ); + $data = [ 'title' => ctrans( 'texts.payment_failed_subject', diff --git a/app/Mail/Admin/PurchaseOrderAcceptedObject.php b/app/Mail/Admin/PurchaseOrderAcceptedObject.php index 00ae2b1b36ea..a8a1caf0ed43 100644 --- a/app/Mail/Admin/PurchaseOrderAcceptedObject.php +++ b/app/Mail/Admin/PurchaseOrderAcceptedObject.php @@ -74,14 +74,14 @@ class PurchaseOrderAcceptedObject $settings = $this->company->settings; $content = ctrans( - 'texts.notification_purchase_order_accepted', - [ + 'texts.notification_purchase_order_accepted', + [ 'amount' => $this->getAmount(), 'vendor' => $this->purchase_order->vendor->present()->name(), 'purchase_order' => $this->purchase_order->number, ] ); - + $data = [ 'title' => $this->getSubject(), 'content' => $content, diff --git a/app/Mail/Admin/QuoteApprovedObject.php b/app/Mail/Admin/QuoteApprovedObject.php index e3675dec19cf..2e5e1e9a050d 100644 --- a/app/Mail/Admin/QuoteApprovedObject.php +++ b/app/Mail/Admin/QuoteApprovedObject.php @@ -73,13 +73,13 @@ class QuoteApprovedObject { $settings = $this->quote->client->getMergedSettings(); $content = ctrans( - 'texts.notification_quote_approved', - [ + 'texts.notification_quote_approved', + [ 'amount' => $this->getAmount(), 'client' => $this->quote->client->present()->name(), 'invoice' => $this->quote->number, ] - ); + ); $data = [ 'title' => $this->getSubject(), diff --git a/app/Mail/Admin/QuoteExpiredObject.php b/app/Mail/Admin/QuoteExpiredObject.php index d07969a1384c..7411949e319f 100644 --- a/app/Mail/Admin/QuoteExpiredObject.php +++ b/app/Mail/Admin/QuoteExpiredObject.php @@ -73,13 +73,13 @@ class QuoteExpiredObject { $settings = $this->quote->client->getMergedSettings(); $content = ctrans( - 'texts.notification_quote_expired', - [ + 'texts.notification_quote_expired', + [ 'amount' => $this->getAmount(), 'client' => $this->quote->client->present()->name(), 'invoice' => $this->quote->number, ] - ); + ); $data = [ 'title' => $this->getSubject(), diff --git a/app/Mail/Engine/BaseEmailEngine.php b/app/Mail/Engine/BaseEmailEngine.php index a850dc804e21..3a5268d8395c 100644 --- a/app/Mail/Engine/BaseEmailEngine.php +++ b/app/Mail/Engine/BaseEmailEngine.php @@ -125,7 +125,7 @@ class BaseEmailEngine implements EngineInterface { if (! empty($this->variables)) { - + $text = str_replace(['$paymentLink', '$viewButton', '$view_button', '$viewLink', '$view_link'], '$view_url', $text); $text = str_replace(array_keys($this->variables), array_values($this->variables), $text); $text = str_replace(array_keys($this->variables), array_values($this->variables), $text); diff --git a/app/Mail/Engine/InvoiceEmailEngine.php b/app/Mail/Engine/InvoiceEmailEngine.php index 8c0593f43636..cadc1e21da53 100644 --- a/app/Mail/Engine/InvoiceEmailEngine.php +++ b/app/Mail/Engine/InvoiceEmailEngine.php @@ -134,9 +134,9 @@ class InvoiceEmailEngine extends BaseEmailEngine $this->setAttachments([['file' => base64_encode($pdf), 'name' => $this->invoice->numberFormatter().'.pdf']]); } -// $hash = Str::uuid(); -// $url = \Illuminate\Support\Facades\URL::temporarySignedRoute('protected_download', now()->addHour(), ['hash' => $hash]); -// Cache::put($hash, $url, now()->addHour()); + // $hash = Str::uuid(); + // $url = \Illuminate\Support\Facades\URL::temporarySignedRoute('protected_download', now()->addHour(), ['hash' => $hash]); + // Cache::put($hash, $url, now()->addHour()); //attach third party documents if ($this->client->getSetting('document_email_attachment') !== false && $this->invoice->company->account->hasFeature(Account::FEATURE_DOCUMENTS)) { @@ -155,7 +155,7 @@ class InvoiceEmailEngine extends BaseEmailEngine // Storage::url $this->invoice->documents()->where('is_public', true)->cursor()->each(function ($document) { if ($document->size > $this->max_attachment_size) { - + $hash = Str::random(64); Cache::put($hash, ['db' => $this->invoice->company->db, 'doc_hash' => $document->hash], now()->addDays(7)); @@ -193,9 +193,9 @@ class InvoiceEmailEngine extends BaseEmailEngine ->each(function ($expense) { $expense->documents()->where('is_public', true)->cursor()->each(function ($document) { if ($document->size > $this->max_attachment_size) { - - $hash = Str::random(64); - Cache::put($hash, ['db' => $this->invoice->company->db, 'doc_hash' => $document->hash], now()->addDays(7)); + + $hash = Str::random(64); + Cache::put($hash, ['db' => $this->invoice->company->db, 'doc_hash' => $document->hash], now()->addDays(7)); $this->setAttachmentLinks([" $hash]) ."'>". $document->name .""]); } else { @@ -217,9 +217,9 @@ class InvoiceEmailEngine extends BaseEmailEngine ->each(function ($task) { $task->documents()->where('is_public', true)->cursor()->each(function ($document) { if ($document->size > $this->max_attachment_size) { - - $hash = Str::random(64); - Cache::put($hash, ['db' => $this->invoice->company->db, 'doc_hash' => $document->hash], now()->addDays(7)); + + $hash = Str::random(64); + Cache::put($hash, ['db' => $this->invoice->company->db, 'doc_hash' => $document->hash], now()->addDays(7)); $this->setAttachmentLinks([" $hash]) ."'>". $document->name .""]); } else { diff --git a/app/Mail/Engine/QuoteEmailEngine.php b/app/Mail/Engine/QuoteEmailEngine.php index ace3f40512a4..f0dad52d58bf 100644 --- a/app/Mail/Engine/QuoteEmailEngine.php +++ b/app/Mail/Engine/QuoteEmailEngine.php @@ -125,7 +125,7 @@ class QuoteEmailEngine extends BaseEmailEngine // Storage::url $this->quote->documents()->where('is_public', true)->cursor()->each(function ($document) { if ($document->size > $this->max_attachment_size) { - + $hash = Str::random(64); Cache::put($hash, ['db' => $this->quote->company->db, 'doc_hash' => $document->hash], now()->addDays(7)); @@ -137,7 +137,7 @@ class QuoteEmailEngine extends BaseEmailEngine $this->quote->company->documents()->where('is_public', true)->cursor()->each(function ($document) { if ($document->size > $this->max_attachment_size) { - + $hash = Str::random(64); Cache::put($hash, ['db' => $this->quote->company->db, 'doc_hash' => $document->hash], now()->addDays(7)); diff --git a/app/Mail/User/UserLoggedIn.php b/app/Mail/User/UserLoggedIn.php index dd2a329f0080..98aca6acd190 100644 --- a/app/Mail/User/UserLoggedIn.php +++ b/app/Mail/User/UserLoggedIn.php @@ -19,7 +19,6 @@ use Illuminate\Support\Facades\App; class UserLoggedIn extends Mailable { - /** * Create a new message instance. * diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index 2d81fbfba56d..9e1c1b884d2e 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -316,7 +316,7 @@ class BaseModel extends Model return "data:application/pdf;base64,".base64_encode((new CreateRawPdf($invitation))->handle()); } - + /** * Takes a entity prop as first argument * along with an array of variables and performs @@ -328,9 +328,10 @@ class BaseModel extends Model */ public function parseHtmlVariables(string $field, array $variables): string { - if(!$this->{$field}) + if(!$this->{$field}) { return ''; - + } + $section = strtr($this->{$field}, $variables['labels']); return strtr($section, $variables['values']); diff --git a/app/Models/ClientContact.php b/app/Models/ClientContact.php index 04307dce367e..67abadeb873c 100644 --- a/app/Models/ClientContact.php +++ b/app/Models/ClientContact.php @@ -254,7 +254,7 @@ class ClientContact extends Authenticatable implements HasLocalePreference { return $this->hasMany(CreditInvitation::class); } - + public function sendPasswordResetNotification($token) { $this->token = $token; diff --git a/app/Models/CompanyUser.php b/app/Models/CompanyUser.php index c6811ddf3e3a..c9e3aa74b9cd 100644 --- a/app/Models/CompanyUser.php +++ b/app/Models/CompanyUser.php @@ -201,7 +201,8 @@ class CompanyUser extends Pivot * @return bool */ public function portalType(): bool - { nlog(isset($this->react_settings->react_notification_link) && $this->react_settings->react_notification_link); + { + nlog(isset($this->react_settings->react_notification_link) && $this->react_settings->react_notification_link); return isset($this->react_settings->react_notification_link) && $this->react_settings->react_notification_link; } diff --git a/app/Models/InvoiceInvitation.php b/app/Models/InvoiceInvitation.php index 58c191fc4a41..3b8b918a2531 100644 --- a/app/Models/InvoiceInvitation.php +++ b/app/Models/InvoiceInvitation.php @@ -101,7 +101,7 @@ class InvoiceInvitation extends BaseModel { return 'invoice'; } - + public function entityType() { return Invoice::class; diff --git a/app/Models/Payment.php b/app/Models/Payment.php index d43cacf6f043..5ce3805f6bca 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -325,8 +325,9 @@ class Payment extends BaseModel return '
'.ctrans('texts.payment_status_3').'
'; case self::STATUS_COMPLETED: - if($this->amount > $this->applied) + if($this->amount > $this->applied) { return '
' . ctrans('texts.partially_unapplied') . '
'; + } return '
'.ctrans('texts.payment_status_4').'
'; case self::STATUS_PARTIALLY_REFUNDED: diff --git a/app/PaymentDrivers/CheckoutCom/CreditCard.php b/app/PaymentDrivers/CheckoutCom/CreditCard.php index ec5bfeec1731..5c29b1e71139 100644 --- a/app/PaymentDrivers/CheckoutCom/CreditCard.php +++ b/app/PaymentDrivers/CheckoutCom/CreditCard.php @@ -231,7 +231,7 @@ class CreditCard implements MethodInterface try { $response = $this->checkout->gateway->getPaymentsClient()->requestPayment($paymentRequest); - + if($this->checkout->company_gateway->update_details && isset($response['customer'])) { $this->checkout->updateCustomer($response['customer']['id'] ?? ''); } diff --git a/app/PaymentDrivers/CheckoutComPaymentDriver.php b/app/PaymentDrivers/CheckoutComPaymentDriver.php index 469986059b33..176a763507b9 100644 --- a/app/PaymentDrivers/CheckoutComPaymentDriver.php +++ b/app/PaymentDrivers/CheckoutComPaymentDriver.php @@ -213,9 +213,10 @@ class CheckoutComPaymentDriver extends BaseDriver public function refund(Payment $payment, $amount, $return_client_response = false) { $this->init(); - - if($this->company_gateway->update_details) + + if($this->company_gateway->update_details) { $this->updateCustomer(); + } $request = new RefundRequest(); $request->reference = "{$payment->transaction_reference} ".now(); @@ -332,11 +333,12 @@ class CheckoutComPaymentDriver extends BaseDriver public function updateCustomer($customer_id = null) { - if(!$customer_id) + if(!$customer_id) { return; + } try { - + $request = new CustomerRequest(); $phone = new Phone(); @@ -387,7 +389,7 @@ class CheckoutComPaymentDriver extends BaseDriver $this->payment_hash = $payment_hash; $this->init(); - + $paymentRequest = $this->bootTokenRequest($cgt->token); $paymentRequest->amount = $this->convertToCheckoutAmount($amount, $this->client->getCurrencyCode()); $paymentRequest->reference = '#'.$invoice->number.' - '.now(); diff --git a/app/PaymentDrivers/GoCardlessPaymentDriver.php b/app/PaymentDrivers/GoCardlessPaymentDriver.php index 3b1fb23e9589..0ec94d1032c5 100644 --- a/app/PaymentDrivers/GoCardlessPaymentDriver.php +++ b/app/PaymentDrivers/GoCardlessPaymentDriver.php @@ -91,7 +91,7 @@ class GoCardlessPaymentDriver extends BaseDriver if ($this->client->currency()->code === 'GBP') { $types[] = GatewayType::INSTANT_BANK_PAY; } - + return $types; } diff --git a/app/PaymentDrivers/PayPalPPCPPaymentDriver.php b/app/PaymentDrivers/PayPalPPCPPaymentDriver.php index 5fcb5ab1c183..5b757d907600 100644 --- a/app/PaymentDrivers/PayPalPPCPPaymentDriver.php +++ b/app/PaymentDrivers/PayPalPPCPPaymentDriver.php @@ -272,10 +272,9 @@ class PayPalPPCPPaymentDriver extends BaseDriver //capture $orderID = $response['orderID']; - if($this->company_gateway->require_shipping_address) - { + if($this->company_gateway->require_shipping_address) { - $shipping_data = + $shipping_data = [[ "op" => "replace", "path" => "/purchase_units/@reference_id=='default'/shipping/address", @@ -288,7 +287,7 @@ class PayPalPPCPPaymentDriver extends BaseDriver "country_code" => $this->client->present()->shipping_country_code(), ], ]]; - + $r = $this->gatewayRequest("/v2/checkout/orders/{$orderID}", 'patch', $shipping_data); } @@ -497,7 +496,7 @@ class PayPalPPCPPaymentDriver extends BaseDriver "country_code" => $this->client->present()->shipping_country_code(), ], ] - + : null; } diff --git a/app/PaymentDrivers/PayPalRestPaymentDriver.php b/app/PaymentDrivers/PayPalRestPaymentDriver.php index 18ae5ce8113a..f08decd67501 100644 --- a/app/PaymentDrivers/PayPalRestPaymentDriver.php +++ b/app/PaymentDrivers/PayPalRestPaymentDriver.php @@ -42,7 +42,7 @@ class PayPalRestPaymentDriver extends BaseDriver private string $paypal_payment_method = ''; private ?int $gateway_type_id = null; - + protected mixed $access_token = null; protected ?Carbon $token_expiry = null; @@ -451,7 +451,7 @@ class PayPalRestPaymentDriver extends BaseDriver "country_code" => $this->client->present()->shipping_country_code(), ], ] - + : null; } diff --git a/app/Providers/MultiDBProvider.php b/app/Providers/MultiDBProvider.php index 4f01911ea087..9743e6c8b92a 100644 --- a/app/Providers/MultiDBProvider.php +++ b/app/Providers/MultiDBProvider.php @@ -33,7 +33,7 @@ class MultiDBProvider extends ServiceProvider */ public function register() { - + $this->app['events']->listen( JobProcessing::class, function ($event) { diff --git a/app/Repositories/ClientContactRepository.php b/app/Repositories/ClientContactRepository.php index 4434a8a80c8e..e2212e1523d6 100644 --- a/app/Repositories/ClientContactRepository.php +++ b/app/Repositories/ClientContactRepository.php @@ -85,14 +85,14 @@ class ClientContactRepository extends BaseRepository if (array_key_exists('password', $contact) && strlen($contact['password']) > 1 && strlen($update_contact->email) > 3) { //updating on a blank contact email will cause large table scanning $update_contact->password = Hash::make($contact['password']); - ClientContact::withTrashed() - ->where('company_id', $client->company_id) - ->where('client_id', $client->id) - ->where('email', $update_contact->email)->cursor() - ->each(function ($saveable_contact) use ($update_contact){ - $saveable_contact->password = $update_contact->password; - $saveable_contact->save(); - }); + ClientContact::withTrashed() + ->where('company_id', $client->company_id) + ->where('client_id', $client->id) + ->where('email', $update_contact->email)->cursor() + ->each(function ($saveable_contact) use ($update_contact) { + $saveable_contact->password = $update_contact->password; + $saveable_contact->save(); + }); } if (array_key_exists('email', $contact)) { diff --git a/app/Services/Client/ClientService.php b/app/Services/Client/ClientService.php index fe0f2381259c..2b65807a2822 100644 --- a/app/Services/Client/ClientService.php +++ b/app/Services/Client/ClientService.php @@ -26,7 +26,8 @@ use Illuminate\Database\QueryException; class ClientService { - use MakesDates, GeneratesCounter; + use MakesDates; + use GeneratesCounter; private string $client_start_date; @@ -153,9 +154,10 @@ class ClientService { $x = 1; - if(isset($this->client->number)) + if(isset($this->client->number)) { return $this; - + } + do { try { $this->client->number = $this->getNextClientNumber($this->client); diff --git a/app/Services/ClientPortal/InstantPayment.php b/app/Services/ClientPortal/InstantPayment.php index 8868a3df8ddc..660ed9a345e0 100644 --- a/app/Services/ClientPortal/InstantPayment.php +++ b/app/Services/ClientPortal/InstantPayment.php @@ -45,7 +45,7 @@ class InstantPayment public function run() { nlog($this->request->all()); - + $cc = auth()->guard('contact')->user(); $cc->first_name = $this->request->contact_first_name; diff --git a/app/Services/Email/Email.php b/app/Services/Email/Email.php index 7052dc5f56ee..a567839883d9 100644 --- a/app/Services/Email/Email.php +++ b/app/Services/Email/Email.php @@ -465,7 +465,7 @@ class Email implements ShouldQueue private function setHostedMailgunMailer() { - + if (property_exists($this->email_object->settings, 'email_from_name') && strlen($this->email_object->settings->email_from_name) > 1) { $email_from_name = $this->email_object->settings->email_from_name; } else { @@ -477,7 +477,7 @@ class Email implements ShouldQueue } - + /** * Sets the mail driver to use and applies any specific configuration * the the mailable @@ -495,7 +495,7 @@ class Email implements ShouldQueue if(Ninja::isHosted() && $this->company->account->isPaid() && $this->email_object->settings->email_sending_method == 'default') { try { - + $address_object = reset($this->email_object->to); $email = $address_object->address ?? ''; $domain = explode("@", $email)[1] ?? ""; diff --git a/app/Services/Email/EmailDefaults.php b/app/Services/Email/EmailDefaults.php index 8eb8765ca69b..9aadd3cd2ac5 100644 --- a/app/Services/Email/EmailDefaults.php +++ b/app/Services/Email/EmailDefaults.php @@ -211,17 +211,15 @@ class EmailDefaults $reply_to_email = $this->email->company->owner()->email; $reply_to_name = $this->email->company->owner()->present()->name(); - if(str_contains($this->email->email_object->settings->reply_to_email, "@")){ - $reply_to_email = $this->email->email_object->settings->reply_to_email; - } - elseif(isset($this->email->email_object->invitation->user)) { + if(str_contains($this->email->email_object->settings->reply_to_email, "@")) { + $reply_to_email = $this->email->email_object->settings->reply_to_email; + } elseif(isset($this->email->email_object->invitation->user)) { $reply_to_email = $this->email->email_object->invitation->user->email; } - + if(strlen($this->email->email_object->settings->reply_to_name) > 3) { - $reply_to_name =$this->email->email_object->settings->reply_to_name; - } - elseif(isset($this->email->email_object->invitation->user)) { + $reply_to_name = $this->email->email_object->settings->reply_to_name; + } elseif(isset($this->email->email_object->invitation->user)) { $reply_to_name = $this->email->email_object->invitation->user->present()->name(); } diff --git a/app/Services/Email/EmailMailable.php b/app/Services/Email/EmailMailable.php index fae76d738759..845be3308a34 100644 --- a/app/Services/Email/EmailMailable.php +++ b/app/Services/Email/EmailMailable.php @@ -84,8 +84,8 @@ class EmailMailable extends Mailable 'company' => $this->email_object->company, 'greeting' => '', 'links' => array_merge($this->email_object->links, $links->toArray()), - 'email_preferences' => (Ninja::isHosted() && in_array($this->email_object->settings->email_sending_method, ['default', 'mailgun']) && $this->email_object->invitation) - ? URL::signedRoute('client.email_preferences', ['entity' => $this->email_object->invitation->getEntityString(), 'invitation_key' => $this->email_object->invitation->key]) + 'email_preferences' => (Ninja::isHosted() && in_array($this->email_object->settings->email_sending_method, ['default', 'mailgun']) && $this->email_object->invitation) + ? URL::signedRoute('client.email_preferences', ['entity' => $this->email_object->invitation->getEntityString(), 'invitation_key' => $this->email_object->invitation->key]) : false, ] ); diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index 1c65aa6999d3..73eac355eefe 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -330,7 +330,7 @@ class AutoBillInvoice extends AbstractService $query->where('is_deleted', 0) ->where('deleted_at', null); })->orderBy('is_default', 'DESC') - ->get(); + ->get(); // $gateway_tokens = $this->client // ->gateway_tokens() diff --git a/app/Services/Invoice/EInvoice/RoEInvoice.php b/app/Services/Invoice/EInvoice/RoEInvoice.php index 43691d632d73..d01aae492022 100644 --- a/app/Services/Invoice/EInvoice/RoEInvoice.php +++ b/app/Services/Invoice/EInvoice/RoEInvoice.php @@ -34,7 +34,6 @@ use CleverIt\UBL\Invoice\Price; class RoEInvoice extends AbstractService { - public function __construct(public Invoice $invoice) { } diff --git a/app/Services/Payment/SendEmail.php b/app/Services/Payment/SendEmail.php index bb0872706dfc..d3551205ba58 100644 --- a/app/Services/Payment/SendEmail.php +++ b/app/Services/Payment/SendEmail.php @@ -18,7 +18,9 @@ use Illuminate\Database\QueryException; class SendEmail { - public function __construct(public Payment $payment, public ?ClientContact $contact) {} + public function __construct(public Payment $payment, public ?ClientContact $contact) + { + } /** * Builds the correct template to send. diff --git a/app/Services/Scheduler/EmailReport.php b/app/Services/Scheduler/EmailReport.php index bb06fdf69b2f..2351153bfff1 100644 --- a/app/Services/Scheduler/EmailReport.php +++ b/app/Services/Scheduler/EmailReport.php @@ -65,7 +65,7 @@ class EmailReport $data['end_date'] = $start_end_dates[1]; $data['date_range'] = $data['date_range'] ?? 'all'; $data['report_keys'] = $data['report_keys'] ?? []; - + $export = false; match($this->scheduler->parameters['report_name']) { diff --git a/app/Services/Subscription/ChangePlanInvoice.php b/app/Services/Subscription/ChangePlanInvoice.php index b732072e892a..6823bd62b7e1 100644 --- a/app/Services/Subscription/ChangePlanInvoice.php +++ b/app/Services/Subscription/ChangePlanInvoice.php @@ -24,7 +24,7 @@ use App\Repositories\InvoiceRepository; use App\Repositories\SubscriptionRepository; class ChangePlanInvoice extends AbstractService -{ +{ protected \App\Services\Subscription\SubscriptionStatus $status; public function __construct(protected RecurringInvoice $recurring_invoice, public Subscription $target, public string $hash) @@ -46,14 +46,15 @@ class ChangePlanInvoice extends AbstractService $invoice = $this->generateInvoice($refund); - if($refund >= $new_charge){ + if($refund >= $new_charge) { $invoice = $invoice->markPaid()->save(); //generate new recurring invoice at this point as we know the user has succeeded with their upgrade. } - - if($refund > $new_charge) + + if($refund > $new_charge) { return $this->generateCredit($refund - $new_charge); + } return $invoice; } @@ -125,4 +126,4 @@ class ChangePlanInvoice extends AbstractService return $invoice; } -} \ No newline at end of file +} diff --git a/app/Services/Subscription/InvoiceToRecurring.php b/app/Services/Subscription/InvoiceToRecurring.php index 8ba371a37bd7..240ed436b3dd 100644 --- a/app/Services/Subscription/InvoiceToRecurring.php +++ b/app/Services/Subscription/InvoiceToRecurring.php @@ -20,8 +20,7 @@ use App\Factory\RecurringInvoiceFactory; use App\Repositories\SubscriptionRepository; class InvoiceToRecurring extends AbstractService -{ - +{ protected \App\Services\Subscription\SubscriptionStatus $status; public function __construct(protected int $client_id, public Subscription $subscription, public array $bundle = []) @@ -67,4 +66,4 @@ class InvoiceToRecurring extends AbstractService return false; } -} \ No newline at end of file +} diff --git a/app/Services/Subscription/PaymentLinkService.php b/app/Services/Subscription/PaymentLinkService.php index d62e4f51a7c7..a87d3bfb6ceb 100644 --- a/app/Services/Subscription/PaymentLinkService.php +++ b/app/Services/Subscription/PaymentLinkService.php @@ -31,25 +31,25 @@ use App\Services\Subscription\ChangePlanInvoice; class PaymentLinkService { use MakesHash; - + public const WHITE_LABEL = 4316; public function __construct(public Subscription $subscription) { } - + /** * CompletePurchase * - * Perform the initial purchase of a one time + * Perform the initial purchase of a one time * or recurring product - * + * * @param PaymentHash $payment_hash * @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse|null */ public function completePurchase(PaymentHash $payment_hash): \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse|null { - + if (!property_exists($payment_hash->data, 'billing_context')) { throw new \Exception("Illegal entrypoint into method, payload must contain billing context"); } @@ -134,7 +134,7 @@ class PaymentLinkService */ public function isEligible(ClientContact $contact): array { - + $context = [ 'context' => 'is_eligible', 'subscription' => $this->subscription->hashed_id, @@ -187,7 +187,7 @@ class PaymentLinkService } $recurring_invoice = (new InvoiceToRecurring($client_contact->client_id, $this->subscription, $bundle))->run(); - + $recurring_invoice->next_send_date = now()->addSeconds($this->subscription->trial_duration); $recurring_invoice->next_send_date_client = now()->addSeconds($this->subscription->trial_duration); $recurring_invoice->backup = 'is_trial'; @@ -221,21 +221,21 @@ class PaymentLinkService return $this->handleRedirect('/client/recurring_invoices/' . $recurring_invoice->hashed_id); } - + /** * calculateUpdatePriceV2 * * Need to change the naming of the method - * + * * @param RecurringInvoice $recurring_invoice - The Current Recurring Invoice for the subscription. * @param Subscription $target - The new target subscription to move to * @return float - the upgrade price */ public function calculateUpgradePriceV2(RecurringInvoice $recurring_invoice, Subscription $target): ?float { - return (new UpgradePrice($recurring_invoice, $target))->run()->upgrade_price; + return (new UpgradePrice($recurring_invoice, $target))->run()->upgrade_price; } - + /** * When changing plans, we need to generate a pro rata invoice * @@ -244,11 +244,11 @@ class PaymentLinkService */ public function createChangePlanInvoice($data): Invoice | Credit { - $recurring_invoice = $data['recurring_invoice']; - $old_subscription = $data['subscription']; - $target_subscription = $data['target']; - $hash = $data['hash']; - + $recurring_invoice = $data['recurring_invoice']; + $old_subscription = $data['subscription']; + $target_subscription = $data['target']; + $hash = $data['hash']; + return (new ChangePlanInvoice($recurring_invoice, $target_subscription, $hash))->run(); } @@ -319,7 +319,7 @@ class PaymentLinkService $old_recurring_invoice->service()->stop()->save(); $recurring_invoice = (new InvoiceToRecurring($old_recurring_invoice->client_id, $this->subscription, []))->run(); - + $recurring_invoice->service() ->start() ->save(); @@ -361,7 +361,7 @@ class PaymentLinkService /** * Handles redirecting the user */ - private function handleRedirect($default_redirect): \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse + private function handleRedirect($default_redirect): \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse { if (array_key_exists('return_url', $this->subscription->webhook_configuration) && strlen($this->subscription->webhook_configuration['return_url']) >= 1) { return method_exists(redirect(), "send") ? redirect($this->subscription->webhook_configuration['return_url'])->send() : redirect($this->subscription->webhook_configuration['return_url']); @@ -466,4 +466,4 @@ class PaymentLinkService return array_merge($body, ['message' => $e->getMessage(), 'status_code' => 500]); } } -} \ No newline at end of file +} diff --git a/app/Services/Subscription/SubscriptionStatus.php b/app/Services/Subscription/SubscriptionStatus.php index 90633404a51f..bd6de8adff9b 100644 --- a/app/Services/Subscription/SubscriptionStatus.php +++ b/app/Services/Subscription/SubscriptionStatus.php @@ -19,20 +19,22 @@ use App\Services\AbstractService; class SubscriptionStatus extends AbstractService { - public function __construct(public Subscription $subscription, protected RecurringInvoice $recurring_invoice) {} - + public function __construct(public Subscription $subscription, protected RecurringInvoice $recurring_invoice) + { + } + /** @var bool $is_trial */ public bool $is_trial = false; - + /** @var bool $is_refundable */ public bool $is_refundable = false; - + /** @var bool $is_in_good_standing */ public bool $is_in_good_standing = false; - + /** @var Invoice $refundable_invoice */ public Invoice $refundable_invoice; - + public function run(): self { $this->checkTrial() @@ -41,7 +43,7 @@ class SubscriptionStatus extends AbstractService return $this; } - + /** * GetProRataRefund * @@ -65,18 +67,18 @@ class SubscriptionStatus extends AbstractService ->first(); $this->refundable_invoice = $primary_invoice; - - return $primary_invoice ? max(0, round(($primary_invoice->paid_to_date * $this->getProRataRatio()),2)) : 0; + + return $primary_invoice ? max(0, round(($primary_invoice->paid_to_date * $this->getProRataRatio()), 2)) : 0; } - + /** * GetProRataRatio * * The ratio of days used / days in interval * @return float */ - public function getProRataRatio():float + public function getProRataRatio(): float { $subscription_interval_end_date = Carbon::parse($this->recurring_invoice->next_send_date_client); @@ -93,9 +95,10 @@ class SubscriptionStatus extends AbstractService ->orderBy('id', 'desc') ->first(); - if(!$primary_invoice) + if(!$primary_invoice) { return 0; - + } + $subscription_start_date = Carbon::parse($primary_invoice->date)->startOfDay(); $days_of_subscription_used = $subscription_start_date->copy()->diffInDays(now()); @@ -106,9 +109,9 @@ class SubscriptionStatus extends AbstractService /** * CheckInGoodStanding - * + * * Are there any outstanding invoices? - * + * * @return self */ private function checkInGoodStanding(): self @@ -127,21 +130,22 @@ class SubscriptionStatus extends AbstractService return $this; } - + /** * CheckTrial * * Check if this subscription is in its trial window. - * + * * Trials do not have an invoice yet - only a pending recurring invoice. - * + * * @return self */ private function checkTrial(): self { - if(!$this->subscription->trial_enabled) + if(!$this->subscription->trial_enabled) { return $this->setIsTrial(false); + } $primary_invoice = Invoice::query() ->where('company_id', $this->recurring_invoice->company_id) @@ -153,7 +157,7 @@ class SubscriptionStatus extends AbstractService ->doesntExist(); if($primary_invoice && Carbon::parse($this->recurring_invoice->next_send_date_client)->gte(now()->startOfDay()->addSeconds($this->recurring_invoice->client->timezone_offset()))) { - return $this->setIsTrial(true); + return $this->setIsTrial(true); } $this->setIsTrial(false); @@ -170,9 +174,10 @@ class SubscriptionStatus extends AbstractService */ private function checkRefundable(): self { - if(!$this->recurring_invoice->subscription->refund_period || $this->recurring_invoice->subscription->refund_period === 0) + if(!$this->recurring_invoice->subscription->refund_period || $this->recurring_invoice->subscription->refund_period === 0) { return $this->setRefundable(false); - + } + $primary_invoice = $this->recurring_invoice ->invoices() ->where('is_deleted', 0) @@ -183,7 +188,7 @@ class SubscriptionStatus extends AbstractService if($primary_invoice && $primary_invoice->status_id == Invoice::STATUS_PAID && Carbon::parse($primary_invoice->date)->addSeconds($this->recurring_invoice->subscription->refund_period)->lte(now()->startOfDay()->addSeconds($primary_invoice->client->timezone_offset())) - ){ + ) { return $this->setRefundable(true); } diff --git a/app/Services/Subscription/UpgradePrice.php b/app/Services/Subscription/UpgradePrice.php index c4cc6e3e81e2..2a3832469624 100644 --- a/app/Services/Subscription/UpgradePrice.php +++ b/app/Services/Subscription/UpgradePrice.php @@ -18,7 +18,7 @@ use App\Models\RecurringInvoice; use App\Services\AbstractService; class UpgradePrice extends AbstractService -{ +{ protected \App\Services\Subscription\SubscriptionStatus $status; public float $upgrade_price = 0; @@ -38,13 +38,14 @@ class UpgradePrice extends AbstractService ->subscription ->status($this->recurring_invoice); - if($this->status->is_in_good_standing) + if($this->status->is_in_good_standing) { $this->calculateUpgrade(); - else + } else { $this->upgrade_price = $this->subscription->price; + } return $this; - + } private function calculateUpgrade(): self @@ -57,10 +58,10 @@ class UpgradePrice extends AbstractService ->where('is_proforma', 0) ->orderBy('id', 'desc') ->first(); - + $this->refund = $this->getRefundableAmount($last_invoice, $ratio); $this->outstanding_credit = $this->getCredits(); - + nlog("{$this->subscription->price} - {$this->refund} - {$this->outstanding_credit}"); $this->upgrade_price = $this->subscription->price - $this->refund - $this->outstanding_credit; @@ -70,10 +71,11 @@ class UpgradePrice extends AbstractService private function getRefundableAmount(?Invoice $invoice, float $ratio): float { - if (!$invoice || !$invoice->date || $invoice->status_id != Invoice::STATUS_PAID || $ratio == 0) + if (!$invoice || !$invoice->date || $invoice->status_id != Invoice::STATUS_PAID || $ratio == 0) { return 0; + } - return max(0, round(($invoice->paid_to_date*$ratio),2)); + return max(0, round(($invoice->paid_to_date * $ratio), 2)); } private function getCredits(): float @@ -82,8 +84,8 @@ class UpgradePrice extends AbstractService $use_credit_setting = $this->recurring_invoice->client->getSetting('use_credits_payment'); - if($use_credit_setting){ - + if($use_credit_setting) { + $outstanding_credits = Credit::query() ->where('client_id', $this->recurring_invoice->client_id) ->whereIn('status_id', [Credit::STATUS_SENT,Credit::STATUS_PARTIAL]) @@ -95,5 +97,5 @@ class UpgradePrice extends AbstractService return $outstanding_credits; } - -} \ No newline at end of file + +} diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index d1b3d601c872..db365f1e8dff 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -745,9 +745,10 @@ class HtmlEngine if((int)$this->client->country_id !== (int)$this->company->settings->country_id) { $tax_label .= ctrans('texts.intracommunity_tax_info') . "
"; - if($this->entity_calc->getTotalTaxes() > 0) + if($this->entity_calc->getTotalTaxes() > 0) { $tax_label = ''; - + } + } return $tax_label; diff --git a/app/Utils/SystemHealth.php b/app/Utils/SystemHealth.php index 1db1eaacbbd1..6b60a7d845e7 100644 --- a/app/Utils/SystemHealth.php +++ b/app/Utils/SystemHealth.php @@ -102,9 +102,9 @@ class SystemHealth return true; //fresh installs, there may be no DB connection, nor migrations could have run yet. } - $currency_count = $cs->unique('id')->filter(function ($value) { - return !is_null($value->id); - })->count(); + $currency_count = $cs->unique('id')->filter(function ($value) { + return !is_null($value->id); + })->count(); if ($currency_count > 1) { diff --git a/app/Utils/Traits/CleanLineItems.php b/app/Utils/Traits/CleanLineItems.php index bf144823864b..9cb96b913664 100644 --- a/app/Utils/Traits/CleanLineItems.php +++ b/app/Utils/Traits/CleanLineItems.php @@ -74,11 +74,13 @@ trait CleanLineItems } - if(isset($item['notes'])) + if(isset($item['notes'])) { $item['notes'] = str_replace("writeString($this->getPaymentLink(), 'utf-8'); - return $qr; + return $qr; } @@ -111,7 +111,7 @@ trait Inviteable // if(Ninja::isHosted()) // return 'https://router.invoiceninja.com/route/'.encrypt($domain.'/client/'.$entity_type.'/'.$this->key); // else - return $domain.'/client/'.$entity_type.'/'.$this->key; + return $domain.'/client/'.$entity_type.'/'.$this->key; break; case 'iframe': return $domain.'/client/'.$entity_type.'/'.$this->key;