diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index 7130c1a9a1ab..15b9c693d67b 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -332,16 +332,16 @@ class CheckData extends Command $total_amount = $invoice->payments->where('is_deleted', false)->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED])->sum('pivot.amount'); $total_refund = $invoice->payments->where('is_deleted', false)->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED])->sum('pivot.refunded'); - $total_invoice_payments += ($total_amount - $total_refund); + $total_invoice_payments += ($total_amount - $total_refund); } - foreach($client->payments as $payment) - { - $credit_total_applied += $payment->paymentables->where('paymentable_type', App\Models\Credit::class)->sum(DB::raw('amount')); + foreach ($client->payments as $payment) { + $credit_total_applied += $payment->paymentables->where('paymentable_type', App\Models\Credit::class)->sum(DB::raw('amount')); } - if($credit_total_applied < 0) - $total_invoice_payments += $credit_total_applied; //todo this is contentious + if ($credit_total_applied < 0) { + $total_invoice_payments += $credit_total_applied; + } //todo this is contentious info("total invoice payments = {$total_invoice_payments} with client paid to date of of {$client->paid_to_date}"); diff --git a/app/Console/Commands/CreateSingleAccount.php b/app/Console/Commands/CreateSingleAccount.php index f500accc6db4..98e7d311faca 100644 --- a/app/Console/Commands/CreateSingleAccount.php +++ b/app/Console/Commands/CreateSingleAccount.php @@ -100,7 +100,6 @@ class CreateSingleAccount extends Command $this->warmCache(); $this->createSmallAccount(); - } private function createSmallAccount() @@ -205,7 +204,6 @@ class CreateSingleAccount extends Command $this->info('creating credit for client #'.$client->id); $this->createCredit($client); - } $this->createGateways($company, $user); @@ -299,7 +297,6 @@ class CreateSingleAccount extends Command private function createInvoice($client) { - $faker = Factory::create(); $invoice = InvoiceFactory::create($client->company->id, $client->user->id); //stub the company and user_id @@ -369,7 +366,6 @@ class CreateSingleAccount extends Command private function createQuote($client) { - $faker = Factory::create(); $quote = Quote::factory()->create(['user_id' => $client->user->id, 'company_id' => $client->company->id, 'client_id' => $client->id]); @@ -414,21 +410,21 @@ class CreateSingleAccount extends Command { $line_items = []; - $item = InvoiceItemFactory::create(); - $item->quantity = 1; - $item->cost = 1000; + $item = InvoiceItemFactory::create(); + $item->quantity = 1; + $item->cost = 1000; - $product = Product::all()->random(); + $product = Product::all()->random(); - $item->cost = (float) $product->cost; - $item->product_key = $product->product_key; - $item->notes = $product->notes; - $item->custom_value1 = $product->custom_value1; - $item->custom_value2 = $product->custom_value2; - $item->custom_value3 = $product->custom_value3; - $item->custom_value4 = $product->custom_value4; + $item->cost = (float) $product->cost; + $item->product_key = $product->product_key; + $item->notes = $product->notes; + $item->custom_value1 = $product->custom_value1; + $item->custom_value2 = $product->custom_value2; + $item->custom_value3 = $product->custom_value3; + $item->custom_value4 = $product->custom_value4; - $line_items[] = $item; + $line_items[] = $item; return $line_items; @@ -505,7 +501,6 @@ class CreateSingleAccount extends Command private function createGateways($company, $user) { - if (config('ninja.testvars.stripe') && ($this->gateway == 'all' || $this->gateway == 'stripe')) { $cg = new CompanyGateway; $cg->company_id = $company->id; diff --git a/app/Console/Commands/CreateTestData.php b/app/Console/Commands/CreateTestData.php index 6b1172ebf1df..5d0e07dd4240 100644 --- a/app/Console/Commands/CreateTestData.php +++ b/app/Console/Commands/CreateTestData.php @@ -471,7 +471,6 @@ class CreateTestData extends Command private function createInvoice($client) { - $faker = Factory::create(); $invoice = InvoiceFactory::create($client->company->id, $client->user->id); //stub the company and user_id @@ -522,7 +521,6 @@ class CreateTestData extends Command private function createCredit($client) { - $faker = Factory::create(); $credit = Credit::factory()->create(['user_id' => $client->user->id, 'company_id' => $client->company->id, 'client_id' => $client->id]); @@ -562,7 +560,6 @@ class CreateTestData extends Command private function createQuote($client) { - $faker = Factory::create(); //$quote = QuoteFactory::create($client->company->id, $client->user->id);//stub the company and user_id diff --git a/app/Console/Commands/DemoMode.php b/app/Console/Commands/DemoMode.php index 10b89a551b7c..ae18b2081533 100644 --- a/app/Console/Commands/DemoMode.php +++ b/app/Console/Commands/DemoMode.php @@ -303,7 +303,7 @@ class DemoMode extends Command 'is_primary' => 1, ]); - ClientContact::factory()->count(rand(1,5))->create([ + ClientContact::factory()->count(rand(1, 5))->create([ 'user_id' => $user->id, 'client_id' => $client->id, 'company_id' => $company->id, @@ -325,7 +325,7 @@ class DemoMode extends Command private function createExpense($client) { - Expense::factory()->count(rand(1,5))->create([ + Expense::factory()->count(rand(1, 5))->create([ 'user_id' => $client->user_id, 'client_id' => $client->id, 'company_id' => $client->company_id, @@ -346,7 +346,7 @@ class DemoMode extends Command 'is_primary' => 1, ]); - VendorContact::factory()->count(rand(1,5))->create([ + VendorContact::factory()->count(rand(1, 5))->create([ 'user_id' => $client->user->id, 'vendor_id' => $vendor->id, 'company_id' => $client->company_id, @@ -376,7 +376,6 @@ class DemoMode extends Command private function createInvoice($client, $assigned_user_id = null) { - $faker = \Faker\Factory::create(); $invoice = InvoiceFactory::create($client->company->id, $client->user->id); //stub the company and user_id @@ -441,7 +440,6 @@ class DemoMode extends Command private function createCredit($client, $assigned_user_id = null) { - $faker = \Faker\Factory::create(); $credit = Credit::factory()->create(['user_id' => $client->user->id, 'company_id' => $client->company->id, 'client_id' => $client->id]); diff --git a/app/Console/Commands/PostUpdate.php b/app/Console/Commands/PostUpdate.php index a10654a3fc88..2f3f32e3f123 100644 --- a/app/Console/Commands/PostUpdate.php +++ b/app/Console/Commands/PostUpdate.php @@ -46,7 +46,6 @@ class PostUpdate extends Command */ public function handle() { - set_time_limit(0); info('running post update'); @@ -73,6 +72,5 @@ class PostUpdate extends Command $application->run($input); echo "Done."; - } } diff --git a/app/Console/Commands/SendRemindersCron.php b/app/Console/Commands/SendRemindersCron.php index 9ad36e5434c6..e3f4ccb89970 100644 --- a/app/Console/Commands/SendRemindersCron.php +++ b/app/Console/Commands/SendRemindersCron.php @@ -65,10 +65,9 @@ class SendRemindersCron extends Command ->whereDate('due_date', now()->subDays(1)->startOfDay()) ->cursor(); - $invoices->each(function ($invoice){ + $invoices->each(function ($invoice) { WebHookHandler::dispatch(Webhook::EVENT_LATE_INVOICE, $invoice, $invoice->company); }); - } private function webHookExpiredQuotes() @@ -78,7 +77,7 @@ class SendRemindersCron extends Command ->whereDate('due_date', now()->subDays(1)->startOfDay()) ->cursor(); - $quotes->each(function ($quote){ + $quotes->each(function ($quote) { WebHookHandler::dispatch(Webhook::EVENT_EXPIRED_QUOTE, $quote, $quote->company); }); } diff --git a/app/Console/Commands/SendTestEmails.php b/app/Console/Commands/SendTestEmails.php index c775dce2f27d..e1fd223e6b21 100644 --- a/app/Console/Commands/SendTestEmails.php +++ b/app/Console/Commands/SendTestEmails.php @@ -82,7 +82,6 @@ class SendTestEmails extends Command $user = User::whereEmail('user@example.com')->first(); if (! $user) { - $account = Account::factory()->create(); $user = User::factory()->create([ diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index 4efc296a13e5..3d9a8639069d 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -175,13 +175,13 @@ class CompanySettings extends BaseSettings public $email_template_reminder3 = ''; //@implemented public $email_template_reminder_endless = ''; //@implemented public $email_signature = ''; //@implemented - public $enable_email_markup = true; //@TODO - + public $enable_email_markup = true; //@TODO - public $email_subject_custom1 = ''; //@TODO public $email_subject_custom2 = ''; //@TODO public $email_subject_custom3 = ''; //@TODO - public $email_template_custom1 = ''; //@TODO + public $email_template_custom1 = ''; //@TODO public $email_template_custom2 = ''; //@TODO public $email_template_custom3 = ''; //@TODO @@ -195,7 +195,7 @@ class CompanySettings extends BaseSettings public $num_days_reminder3 = 0;//@implmemented public $schedule_reminder1 = ''; // (enum: after_invoice_date, before_due_date, after_due_date) implmemented - public $schedule_reminder2 = ''; // (enum: after_invoice_date, before_due_date, after_due_date) implmemented + public $schedule_reminder2 = ''; // (enum: after_invoice_date, before_due_date, after_due_date) implmemented public $schedule_reminder3 = ''; // (enum: after_invoice_date, before_due_date, after_due_date) implmemented public $reminder_send_time = 32400; //number of seconds from UTC +0 to send reminders @TODO @@ -511,7 +511,7 @@ class CompanySettings extends BaseSettings /** * Provides class defaults on init. - * + * * @return stdClass */ public static function defaults(): stdClass @@ -544,7 +544,7 @@ class CompanySettings extends BaseSettings * set new properties to the object prior to being returned. * * @param $settings - * + * * @return stdClass */ public static function setProperties($settings): stdClass @@ -562,7 +562,7 @@ class CompanySettings extends BaseSettings /** * Stubs the notification defaults - * + * * @return stdClass */ public static function notificationDefaults() :stdClass @@ -575,7 +575,7 @@ class CompanySettings extends BaseSettings /** * Defines entity variables for PDF generation - * + * * @return stdClass The stdClass of PDF variables */ private static function getEntityVariableDefaults() :stdClass diff --git a/app/DataMapper/EmailTemplateDefaults.php b/app/DataMapper/EmailTemplateDefaults.php index 0ab17319ade8..2c64b80eb6bf 100644 --- a/app/DataMapper/EmailTemplateDefaults.php +++ b/app/DataMapper/EmailTemplateDefaults.php @@ -148,11 +148,9 @@ class EmailTemplateDefaults public static function emailPaymentTemplate() { - $payment_message = '
'.self::transformText('payment_message').'
$view_link
'; return $payment_message; - } public static function emailCreditTemplate() @@ -164,11 +162,9 @@ class EmailTemplateDefaults public static function emailPaymentPartialTemplate() { - $payment_message = ''.self::transformText('payment_message').'
$view_link
'; return $payment_message; - } public static function emailPaymentPartialSubject() diff --git a/app/Factory/TaskFactory.php b/app/Factory/TaskFactory.php index e0d43b02e94c..64e47ddefee1 100644 --- a/app/Factory/TaskFactory.php +++ b/app/Factory/TaskFactory.php @@ -24,9 +24,9 @@ class TaskFactory $task->company_id = $company_id; $task->user_id = $user_id; $task->time_log = '[]'; - $task->is_running = false; - $task->is_deleted = false; - $task->duration = 0; + $task->is_running = false; + $task->is_deleted = false; + $task->duration = 0; return $task; } diff --git a/app/Filters/SystemLogFilters.php b/app/Filters/SystemLogFilters.php index 388d941e8446..3e6ef9a1893a 100644 --- a/app/Filters/SystemLogFilters.php +++ b/app/Filters/SystemLogFilters.php @@ -51,13 +51,11 @@ class SystemLogFilters extends QueryFilters */ public function filter(string $filter = '') : Builder { - if (strlen($filter) == 0) { return $this->builder; } return $this->builder; - } /** diff --git a/app/Helpers/Invoice/InvoiceItemSum.php b/app/Helpers/Invoice/InvoiceItemSum.php index ee66fddc67cc..b031909aafb2 100644 --- a/app/Helpers/Invoice/InvoiceItemSum.php +++ b/app/Helpers/Invoice/InvoiceItemSum.php @@ -231,7 +231,7 @@ class InvoiceItemSum } //$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / $this->sub_total)); - $amount = ( $this->sub_total > 0 ) ? $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / $this->sub_total)) : 0; + $amount = ($this->sub_total > 0) ? $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / $this->sub_total)) : 0; $item_tax_rate1_total = $this->calcAmountLineTax($this->item->tax_rate1, $amount); @@ -264,7 +264,7 @@ class InvoiceItemSum /** * Sets default casts for the values in the line_items. - * + * * @return $this */ private function cleanLineItem() diff --git a/app/Helpers/Invoice/InvoiceSum.php b/app/Helpers/Invoice/InvoiceSum.php index 3a9d4bab6685..a3c496dcde87 100644 --- a/app/Helpers/Invoice/InvoiceSum.php +++ b/app/Helpers/Invoice/InvoiceSum.php @@ -160,17 +160,21 @@ class InvoiceSum { $this->total += $this->total_taxes; - if(is_numeric($this->invoice->custom_value1) && $this->invoice->custom_value1 > 0) + if (is_numeric($this->invoice->custom_value1) && $this->invoice->custom_value1 > 0) { $this->total += $this->invoice->custom_value1; + } - if(is_numeric($this->invoice->custom_value2) && $this->invoice->custom_value2 > 0) + if (is_numeric($this->invoice->custom_value2) && $this->invoice->custom_value2 > 0) { $this->total += $this->invoice->custom_value2; + } - if(is_numeric($this->invoice->custom_value3) && $this->invoice->custom_value3 > 0) + if (is_numeric($this->invoice->custom_value3) && $this->invoice->custom_value3 > 0) { $this->total += $this->invoice->custom_value3; + } - if(is_numeric($this->invoice->custom_value4) && $this->invoice->custom_value4 > 0) + if (is_numeric($this->invoice->custom_value4) && $this->invoice->custom_value4 > 0) { $this->total += $this->invoice->custom_value4; + } return $this; } @@ -202,7 +206,6 @@ class InvoiceSum public function getRecurringInvoice() { - $this->invoice->amount = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision); $this->invoice->total_taxes = $this->getTotalTaxes(); $this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision); @@ -220,8 +223,7 @@ class InvoiceSum { /* If amount != balance then some money has been paid on the invoice, need to subtract this difference from the total to set the new balance */ - if($this->invoice->status_id != Invoice::STATUS_DRAFT) - { + if ($this->invoice->status_id != Invoice::STATUS_DRAFT) { if ($this->invoice->amount != $this->invoice->balance) { $paid_to_date = $this->invoice->amount - $this->invoice->balance; @@ -318,7 +320,6 @@ class InvoiceSum public function purgeTaxes() { - $this->tax_rate1 = 0; $this->tax_name1 = ''; @@ -332,7 +333,7 @@ class InvoiceSum $line_items = collect($this->invoice->line_items); - $items = $line_items->map(function ($item){ + $items = $line_items->map(function ($item) { $item->tax_rate1 = 0; $item->tax_rate2 = 0; $item->tax_rate3 = 0; @@ -350,5 +351,4 @@ class InvoiceSum return $this; } - } diff --git a/app/Helpers/Invoice/InvoiceSumInclusive.php b/app/Helpers/Invoice/InvoiceSumInclusive.php index 95d2492b7354..f04818f62f52 100644 --- a/app/Helpers/Invoice/InvoiceSumInclusive.php +++ b/app/Helpers/Invoice/InvoiceSumInclusive.php @@ -66,7 +66,7 @@ class InvoiceSumInclusive ->calculateCustomValues() ->calculateInvoiceTaxes() ->setTaxMap() - ->calculateTotals() //just don't add the taxes!! + ->calculateTotals() //just don't add the taxes!! ->calculateBalance() ->calculatePartial(); @@ -172,24 +172,27 @@ class InvoiceSumInclusive { //$this->total += $this->total_taxes; - if(is_numeric($this->invoice->custom_value1) && $this->invoice->custom_value1 > 0) + if (is_numeric($this->invoice->custom_value1) && $this->invoice->custom_value1 > 0) { $this->total += $this->invoice->custom_value1; + } - if(is_numeric($this->invoice->custom_value2) && $this->invoice->custom_value2 > 0) + if (is_numeric($this->invoice->custom_value2) && $this->invoice->custom_value2 > 0) { $this->total += $this->invoice->custom_value2; + } - if(is_numeric($this->invoice->custom_value3) && $this->invoice->custom_value3 > 0) + if (is_numeric($this->invoice->custom_value3) && $this->invoice->custom_value3 > 0) { $this->total += $this->invoice->custom_value3; + } - if(is_numeric($this->invoice->custom_value4) && $this->invoice->custom_value4 > 0) - $this->total += $this->invoice->custom_value4; + if (is_numeric($this->invoice->custom_value4) && $this->invoice->custom_value4 > 0) { + $this->total += $this->invoice->custom_value4; + } return $this; } public function getRecurringInvoice() { - $this->invoice->amount = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision); $this->invoice->total_taxes = $this->getTotalTaxes(); $this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision); @@ -329,7 +332,6 @@ class InvoiceSumInclusive public function purgeTaxes() { - return $this; } } diff --git a/app/Http/Controllers/Auth/ContactLoginController.php b/app/Http/Controllers/Auth/ContactLoginController.php index 2bcf310dfa04..8168052aab85 100644 --- a/app/Http/Controllers/Auth/ContactLoginController.php +++ b/app/Http/Controllers/Auth/ContactLoginController.php @@ -80,5 +80,4 @@ class ContactLoginController extends Controller return redirect('/client/login'); } - } diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 63aa19aec955..dcaa7460b3df 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -173,8 +173,7 @@ class LoginController extends BaseController $cu = CompanyUser::query() ->where('user_id', auth()->user()->id); - return $this->listResponse($cu); - + return $this->listResponse($cu); } else { LightLogs::create(new LoginFailure()) ->increment() diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index 095e96f24503..a6b2c962db75 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -207,12 +207,12 @@ class BaseController extends Controller $updated_at = date('Y-m-d H:i:s', $updated_at); $query->with( - [ + [ 'company' => function ($query) use ($updated_at) { $query->whereNotNull('updated_at')->with('documents'); }, 'company.clients' => function ($query) use ($updated_at) { - $query->where('clients.updated_at', '>=', $updated_at)->with('contacts.company', 'gateway_tokens','documents'); + $query->where('clients.updated_at', '>=', $updated_at)->with('contacts.company', 'gateway_tokens', 'documents'); }, 'company.company_gateways' => function ($query) { $query->whereNotNull('updated_at'); @@ -236,7 +236,7 @@ class BaseController extends Controller $query->where('updated_at', '>=', $updated_at)->with('invitations', 'documents'); }, 'company.payments'=> function ($query) use ($updated_at) { - $query->where('updated_at', '>=', $updated_at)->with('paymentables','documents'); + $query->where('updated_at', '>=', $updated_at)->with('paymentables', 'documents'); }, 'company.payment_terms'=> function ($query) use ($updated_at) { $query->where('updated_at', '>=', $updated_at); @@ -245,7 +245,7 @@ class BaseController extends Controller $query->where('updated_at', '>=', $updated_at)->with('documents'); }, 'company.projects'=> function ($query) use ($updated_at) { - $query->where('updated_at', '>=', $updated_at)->with('documents' ); + $query->where('updated_at', '>=', $updated_at)->with('documents'); }, 'company.quotes'=> function ($query) use ($updated_at) { $query->where('updated_at', '>=', $updated_at)->with('invitations', 'documents'); @@ -254,13 +254,13 @@ class BaseController extends Controller $query->where('updated_at', '>=', $updated_at)->with('invitations', 'documents'); }, 'company.tasks'=> function ($query) use ($updated_at) { - $query->where('updated_at', '>=', $updated_at)->with('documents' ); + $query->where('updated_at', '>=', $updated_at)->with('documents'); }, 'company.tax_rates' => function ($query) use ($updated_at) { $query->where('updated_at', '>=', $updated_at); }, 'company.vendors'=> function ($query) use ($updated_at) { - $query->where('updated_at', '>=', $updated_at)->with('contacts','documents'); + $query->where('updated_at', '>=', $updated_at)->with('contacts', 'documents'); }, 'company.expense_categories'=> function ($query) use ($updated_at) { $query->where('updated_at', '>=', $updated_at); @@ -297,14 +297,17 @@ class BaseController extends Controller $query->with($includes); - if (auth()->user() && ! auth()->user()->hasPermission('view_'.lcfirst(class_basename($this->entity_type)))) + if (auth()->user() && ! auth()->user()->hasPermission('view_'.lcfirst(class_basename($this->entity_type)))) { $query->where('user_id', '=', auth()->user()->id); + } - if (request()->has('updated_at') && request()->input('updated_at') > 0) + if (request()->has('updated_at') && request()->input('updated_at') > 0) { $query->where('updated_at', '>=', date('Y-m-d H:i:s', intval(request()->input('updated_at')))); + } - if ($this->serializer && $this->serializer != EntityTransformer::API_SERIALIZER_JSON) + if ($this->serializer && $this->serializer != EntityTransformer::API_SERIALIZER_JSON) { $this->entity_type = null; + } if ($query instanceof Builder) { $limit = request()->input('per_page', 20); @@ -317,7 +320,6 @@ class BaseController extends Controller } return $this->response($this->manager->createData($resource)->toArray()); - } protected function response($response) @@ -357,13 +359,15 @@ class BaseController extends Controller $transformer = new $this->entity_transformer(request()->input('serializer')); - if ($this->serializer && $this->serializer != EntityTransformer::API_SERIALIZER_JSON) + if ($this->serializer && $this->serializer != EntityTransformer::API_SERIALIZER_JSON) { $this->entity_type = null; + } $resource = new Item($item, $transformer, $this->entity_type); - if (auth()->user() && request()->include_static) + if (auth()->user() && request()->include_static) { $data['static'] = Statics::company(auth()->user()->getCompany()->getLocale()); + } return $this->response($this->manager->createData($resource)->toArray()); } @@ -407,7 +411,6 @@ class BaseController extends Controller public function flutterRoute() { - if ((bool) $this->checkAppSetup() !== false && $account = Account::first()) { if (config('ninja.require_https') && ! request()->isSecure()) { return redirect()->secure(request()->getRequestUri()); diff --git a/app/Http/Controllers/ClientPortal/ContactHashLoginController.php b/app/Http/Controllers/ClientPortal/ContactHashLoginController.php index 3a64b9f1d36d..7ba208a4557b 100644 --- a/app/Http/Controllers/ClientPortal/ContactHashLoginController.php +++ b/app/Http/Controllers/ClientPortal/ContactHashLoginController.php @@ -25,11 +25,6 @@ class ContactHashLoginController extends Controller */ public function login(string $contact_key) { - return redirect('/client/login'); - } - } - - diff --git a/app/Http/Controllers/ClientPortal/InvitationController.php b/app/Http/Controllers/ClientPortal/InvitationController.php index 1e4e4efc22d4..344889f8ce98 100644 --- a/app/Http/Controllers/ClientPortal/InvitationController.php +++ b/app/Http/Controllers/ClientPortal/InvitationController.php @@ -37,7 +37,6 @@ class InvitationController extends Controller public function router(string $entity, string $invitation_key) { - $key = $entity.'_id'; $entity_obj = 'App\Models\\'.ucfirst(Str::camel($entity)).'Invitation'; @@ -48,18 +47,15 @@ class InvitationController extends Controller /* Return early if we have the correct client_hash embedded */ - if(request()->has('client_hash') && request()->input('client_hash') == $invitation->contact->client->client_hash) { + if (request()->has('client_hash') && request()->input('client_hash') == $invitation->contact->client->client_hash) { auth()->guard('contact')->login($invitation->contact, true); - } - else if ((bool) $invitation->contact->client->getSetting('enable_client_portal_password') !== false) { + } elseif ((bool) $invitation->contact->client->getSetting('enable_client_portal_password') !== false) { $this->middleware('auth:contact'); - } - else { + } else { auth()->guard('contact')->login($invitation->contact, true); } if (auth()->guard('contact') && ! request()->has('silent') && ! $invitation->viewed_date) { - $invitation->markViewed(); event(new InvitationWasViewed($invitation->{$entity}, $invitation, $invitation->{$entity}->company, Ninja::eventVars())); @@ -68,8 +64,6 @@ class InvitationController extends Controller } return redirect()->route('client.'.$entity.'.show', [$entity => $this->encodePrimaryKey($invitation->{$key})]); - - } private function fireEntityViewedEvent($invitation, $entity_string) diff --git a/app/Http/Controllers/ClientPortal/PaymentController.php b/app/Http/Controllers/ClientPortal/PaymentController.php index 1cac29ad5560..c58186a8c674 100644 --- a/app/Http/Controllers/ClientPortal/PaymentController.php +++ b/app/Http/Controllers/ClientPortal/PaymentController.php @@ -77,8 +77,9 @@ class PaymentController extends Controller $is_credit_payment = false; $token = false; - if($request->input('company_gateway_id') == CompanyGateway::GATEWAY_CREDIT) + if ($request->input('company_gateway_id') == CompanyGateway::GATEWAY_CREDIT) { $is_credit_payment = true; + } $gateway = CompanyGateway::find($request->input('company_gateway_id')); @@ -94,10 +95,8 @@ class PaymentController extends Controller $invoices = Invoice::whereIn('id', $this->transformKeys($payable_invoices->pluck('invoice_id')->toArray()))->get(); /* pop non payable invoice from the $payable_invoices array */ - $payable_invoices = $payable_invoices->filter(function ($payable_invoice) use ($invoices){ - + $payable_invoices = $payable_invoices->filter(function ($payable_invoice) use ($invoices) { return $invoices->where('hashed_id', $payable_invoice['invoice_id'])->first()->isPayable(); - }); /*return early if no invoices*/ @@ -110,8 +109,7 @@ class PaymentController extends Controller $settings = auth()->user()->client->getMergedSettings(); /*iterate through invoices and add gateway fees and other payment metadata*/ - $payable_invoices = $payable_invoices->map(function($payable_invoice) use($invoices, $settings){ - + $payable_invoices = $payable_invoices->map(function ($payable_invoice) use ($invoices, $settings) { $payable_invoice['amount'] = Number::parseFloat($payable_invoice['amount']); $invoice = $invoices->first(function ($inv) use ($payable_invoice) { @@ -167,7 +165,6 @@ class PaymentController extends Controller $payable_invoice['additional_info'] = $additional_info; return $payable_invoice; - }); if (request()->has('signature') && !is_null(request()->signature) && !empty(request()->signature)) { @@ -182,8 +179,9 @@ class PaymentController extends Controller $credit_totals = $first_invoice->client->getSetting('use_credits_payment') == 'off' ? 0 : $first_invoice->client->service()->getCreditBalance(); $starting_invoice_amount = $first_invoice->amount; - if($gateway) + if ($gateway) { $first_invoice->service()->addGatewayFee($gateway, $payment_method_id, $invoice_totals)->save(); + } /** * Gateway fee is calculated @@ -192,8 +190,9 @@ class PaymentController extends Controller */ $fee_totals = $first_invoice->amount - $starting_invoice_amount; - if($gateway) + if ($gateway) { $token = auth()->user()->client->gateway_token($gateway->id, $payment_method_id); + } $payment_hash = new PaymentHash; $payment_hash->hash = Str::random(128); @@ -218,7 +217,7 @@ class PaymentController extends Controller 'amount_with_fee' => $invoice_totals + $fee_totals, ]; - if($is_credit_payment) { + if ($is_credit_payment) { return $this->processCreditPayment($request, $data); } @@ -252,9 +251,9 @@ class PaymentController extends Controller $payment_hash = PaymentHash::whereRaw('BINARY `hash`= ?', [$request->input('payment_hash')])->first(); /* Hydrate the $payment */ - if($payment_hash->payment()->exists()) + if ($payment_hash->payment()->exists()) { $payment = $payment_hash->payment; - else { + } else { $payment = PaymentFactory::create($payment_hash->fee_invoice->company_id, $payment_hash->fee_invoice->user_id); $payment->client_id = $payment_hash->fee_invoice->client_id; $payment->save(); @@ -264,8 +263,7 @@ class PaymentController extends Controller } /* Iterate through the invoices and apply credits to them */ - collect($payment_hash->invoices())->each(function ($payable_invoice) use ($payment, $payment_hash){ - + collect($payment_hash->invoices())->each(function ($payable_invoice) use ($payment, $payment_hash) { $invoice = Invoice::find($this->decodePrimaryKey($payable_invoice->invoice_id)); $amount = $payable_invoice->amount; @@ -274,35 +272,31 @@ class PaymentController extends Controller ->service() ->getCredits(); - foreach($credits as $credit) - { - //starting invoice balance - $invoice_balance = $invoice->balance; + foreach ($credits as $credit) { + //starting invoice balance + $invoice_balance = $invoice->balance; - //credit payment applied - $credit->service()->applyPayment($invoice, $amount, $payment); + //credit payment applied + $credit->service()->applyPayment($invoice, $amount, $payment); - //amount paid from invoice calculated - $remaining_balance = ($invoice_balance - $invoice->fresh()->balance); + //amount paid from invoice calculated + $remaining_balance = ($invoice_balance - $invoice->fresh()->balance); - //reduce the amount to be paid on the invoice from the NEXT credit - $amount -= $remaining_balance; + //reduce the amount to be paid on the invoice from the NEXT credit + $amount -= $remaining_balance; - //break if the invoice is no longer PAYABLE OR there is no more amount to be applied - if(!$invoice->isPayable() || (int)$amount == 0) - break; + //break if the invoice is no longer PAYABLE OR there is no more amount to be applied + if (!$invoice->isPayable() || (int)$amount == 0) { + break; } - + } }); return redirect()->route('client.payments.show', ['payment' => $this->encodePrimaryKey($payment->id)]); - } public function processCreditPayment(Request $request, array $data) { - return render('gateways.credit.index', $data); - } } diff --git a/app/Http/Controllers/CompanyController.php b/app/Http/Controllers/CompanyController.php index 2ccf9a6012b7..42e5c1451975 100644 --- a/app/Http/Controllers/CompanyController.php +++ b/app/Http/Controllers/CompanyController.php @@ -408,9 +408,9 @@ class CompanyController extends BaseController */ public function update(UpdateCompanyRequest $request, Company $company) { - - if($request->hasFile('company_logo') || (is_array($request->input('settings')) && !array_key_exists('company_logo', $request->input('settings')))) + if ($request->hasFile('company_logo') || (is_array($request->input('settings')) && !array_key_exists('company_logo', $request->input('settings')))) { $this->removeLogo($company); + } $company = $this->company_repo->save($request->all(), $company); @@ -490,7 +490,6 @@ class CompanyController extends BaseController LightLogs::create(new AccountDeleted()) ->increment() ->batch(); - } else { $company_id = $company->id; $company->delete(); diff --git a/app/Http/Controllers/CreditController.php b/app/Http/Controllers/CreditController.php index acf081363458..f35efd2c5d40 100644 --- a/app/Http/Controllers/CreditController.php +++ b/app/Http/Controllers/CreditController.php @@ -187,7 +187,7 @@ class CreditController extends BaseController $credit = $this->credit_repository->save($request->all(), CreditFactory::create(auth()->user()->company()->id, auth()->user()->id)); - $credit = $credit->service() + $credit = $credit->service() ->fillDefaults() ->save(); diff --git a/app/Http/Controllers/EmailController.php b/app/Http/Controllers/EmailController.php index 04f10b0cccc9..e7abdeaae4c5 100644 --- a/app/Http/Controllers/EmailController.php +++ b/app/Http/Controllers/EmailController.php @@ -120,18 +120,14 @@ class EmailController extends BaseController $template = str_replace("email_template_", "", $template); $entity_obj->invitations->each(function ($invitation) use ($subject, $body, $entity_string, $entity_obj, $template) { - if ($invitation->contact->send_email && $invitation->contact->email) { - $data = [ 'subject' => $subject, 'body' => $body ]; EmailEntity::dispatchNow($invitation, $invitation->company, $template, $data); - } - }); $entity_obj->last_sent_date = now(); diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 62092a73bd63..a6903e983035 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -396,7 +396,7 @@ class InvoiceController extends BaseController $invoice = $this->invoice_repo->save($request->all(), $invoice); - UnlinkFile::dispatchNow(config('filesystems.default'),$invoice->client->invoice_filepath().$invoice->number.'.pdf'); + UnlinkFile::dispatchNow(config('filesystems.default'), $invoice->client->invoice_filepath().$invoice->number.'.pdf'); event(new InvoiceWasUpdated($invoice, $invoice->company, Ninja::eventVars())); @@ -731,7 +731,6 @@ class InvoiceController extends BaseController $invoice->invitations->load('contact.client.country', 'invoice.client.country', 'invoice.company')->each(function ($invitation) use ($invoice) { info("firing email"); EmailEntity::dispatch($invitation, $invoice->company, $this->reminder_template); - }); if (! $bulk) { diff --git a/app/Http/Controllers/MigrationController.php b/app/Http/Controllers/MigrationController.php index de7e14fa9514..6ca47a94ceab 100644 --- a/app/Http/Controllers/MigrationController.php +++ b/app/Http/Controllers/MigrationController.php @@ -219,7 +219,6 @@ class MigrationController extends BaseController */ public function startMigration(Request $request) { - $companies = json_decode($request->companies); if (app()->environment() === 'local') { @@ -227,7 +226,6 @@ class MigrationController extends BaseController } foreach ($companies as $company) { - $is_valid = $request->file($company->company_index)->isValid(); if (!$is_valid) { diff --git a/app/Http/Controllers/OpenAPI/TaskSchema.php b/app/Http/Controllers/OpenAPI/TaskSchema.php index 72c6d473ca9b..23acb2649e06 100644 --- a/app/Http/Controllers/OpenAPI/TaskSchema.php +++ b/app/Http/Controllers/OpenAPI/TaskSchema.php @@ -27,4 +27,4 @@ * @OA\Property(property="updated_at", type="number", format="integer", example="1434342123", description="Timestamp"), * @OA\Property(property="archived_at", type="number", format="integer", example="1434342123", description="Timestamp"), * ) - */ \ No newline at end of file + */ diff --git a/app/Http/Controllers/PingController.php b/app/Http/Controllers/PingController.php index 41f8886880ef..a265815e53e6 100644 --- a/app/Http/Controllers/PingController.php +++ b/app/Http/Controllers/PingController.php @@ -45,7 +45,9 @@ class PingController extends BaseController return response()->json( ['company_name' => auth()->user()->getCompany()->present()->name(), 'user_name' => auth()->user()->present()->name(), - ], 200); + ], + 200 + ); } /** diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 371b2004791b..67276ddf3e87 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -363,7 +363,7 @@ class ProjectController extends BaseController $project->fill($request->all()); $project->save(); - if(empty($project->number)){ + if (empty($project->number)) { $project->number = $this->getNextProjectNumber($project); $project->save(); } diff --git a/app/Http/Controllers/QuoteController.php b/app/Http/Controllers/QuoteController.php index 9aba18ada4a6..9d6a49cd55bb 100644 --- a/app/Http/Controllers/QuoteController.php +++ b/app/Http/Controllers/QuoteController.php @@ -670,22 +670,25 @@ class QuoteController extends BaseController case 'restore': $this->quote_repo->restore($quote); - if (!$bulk) + if (!$bulk) { return $this->listResponse($quote); + } break; case 'archive': $this->quote_repo->archive($quote); - if (!$bulk) + if (!$bulk) { return $this->listResponse($quote); + } break; case 'delete': $this->quote_repo->delete($quote); - if (!$bulk) + if (!$bulk) { return $this->listResponse($quote); + } break; case 'email': @@ -700,7 +703,6 @@ class QuoteController extends BaseController return $this->itemResponse($quote); } break; - // no break default: return response()->json(['message' => "The requested action `{$action}` is not available."], 400); break; diff --git a/app/Http/Controllers/RecurringInvoiceController.php b/app/Http/Controllers/RecurringInvoiceController.php index 7fe473520f03..2074062e7b38 100644 --- a/app/Http/Controllers/RecurringInvoiceController.php +++ b/app/Http/Controllers/RecurringInvoiceController.php @@ -628,6 +628,5 @@ class RecurringInvoiceController extends BaseController // code... break; } - } } diff --git a/app/Http/Controllers/SelfUpdateController.php b/app/Http/Controllers/SelfUpdateController.php index 338c79b2097f..5f4de1a7c0f2 100644 --- a/app/Http/Controllers/SelfUpdateController.php +++ b/app/Http/Controllers/SelfUpdateController.php @@ -74,7 +74,6 @@ class SelfUpdateController extends BaseController try { $res = $repo->pull(); } catch (GitException $e) { - info($e->getMessage()); return response()->json(['message'=>$e->getMessage()], 500); } diff --git a/app/Http/Controllers/SystemLogController.php b/app/Http/Controllers/SystemLogController.php index c96637e58714..524ca6303362 100644 --- a/app/Http/Controllers/SystemLogController.php +++ b/app/Http/Controllers/SystemLogController.php @@ -63,8 +63,9 @@ class SystemLogController extends BaseController { $system_logs = SystemLog::filter($filters); - if(auth()->user()->isAdmin()) + if (auth()->user()->isAdmin()) { return $this->listResponse($system_logs); + } return $this->errorResponse('Insufficient permissions', 403); } diff --git a/app/Http/Livewire/Profile/Settings/General.php b/app/Http/Livewire/Profile/Settings/General.php index 249c832458aa..48e7bd08764c 100644 --- a/app/Http/Livewire/Profile/Settings/General.php +++ b/app/Http/Livewire/Profile/Settings/General.php @@ -65,9 +65,9 @@ class General extends Component $data = $this->validate($this->rules); - if (!empty($this->password)) { - $this->profile->password = Hash::make($this->password); - } + if (!empty($this->password)) { + $this->profile->password = Hash::make($this->password); + } $this->profile ->fill($data) diff --git a/app/Http/Middleware/ApiSecretCheck.php b/app/Http/Middleware/ApiSecretCheck.php index dfe057768a4d..de0b80c8c707 100644 --- a/app/Http/Middleware/ApiSecretCheck.php +++ b/app/Http/Middleware/ApiSecretCheck.php @@ -27,9 +27,9 @@ class ApiSecretCheck */ public function handle($request, Closure $next) { - - if(! config('ninja.api_secret')) + if (! config('ninja.api_secret')) { return $next($request); + } if ($request->header('X-API-SECRET') && ($request->header('X-API-SECRET') == config('ninja.api_secret'))) { return $next($request); diff --git a/app/Http/Middleware/ContactKeyLogin.php b/app/Http/Middleware/ContactKeyLogin.php index 50444c5178bd..1be35211c59b 100644 --- a/app/Http/Middleware/ContactKeyLogin.php +++ b/app/Http/Middleware/ContactKeyLogin.php @@ -34,47 +34,32 @@ class ContactKeyLogin */ public function handle($request, Closure $next) { - - if(Auth::guard('contact')->check()) + if (Auth::guard('contact')->check()) { Auth::guard('contact')->logout(); + } if ($request->segment(3) && config('ninja.db.multi_db_enabled')) { - if (MultiDB::findAndSetDbByContactKey($request->segment(3))) { - $client_contact = ClientContact::where('contact_key', $request->segment(3))->first(); Auth::guard('contact')->login($client_contact, true); return redirect()->to('client/dashboard'); - } - - } - else if ($request->has('contact_key')) { - - if($client_contact = ClientContact::where('contact_key', $request->segment(3))->first()){ + } elseif ($request->has('contact_key')) { + if ($client_contact = ClientContact::where('contact_key', $request->segment(3))->first()) { Auth::guard('contact')->login($client_contact, true); return redirect()->to('client/dashboard'); } - - } - else if($request->has('client_hash') && config('ninja.db.multi_db_enabled')){ - + } elseif ($request->has('client_hash') && config('ninja.db.multi_db_enabled')) { if (MultiDB::findAndSetDbByClientHash($request->input('client_hash'))) { - $client = Client::where('client_hash', $request->input('client_hash'))->first(); Auth::guard('contact')->login($client->primary_contact()->first(), true); return redirect()->to('client/dashboard'); - } - - } - else if($request->has('client_hash')){ - - if($client = Client::where('client_hash', $request->input('client_hash'))->first()){ + } elseif ($request->has('client_hash')) { + if ($client = Client::where('client_hash', $request->input('client_hash'))->first()) { Auth::guard('contact')->login($client->primary_contact()->first(), true); return redirect()->to('client/dashboard'); } - } return $next($request); diff --git a/app/Http/Middleware/ContactTokenAuth.php b/app/Http/Middleware/ContactTokenAuth.php index 86e6175fd299..33759d2be039 100644 --- a/app/Http/Middleware/ContactTokenAuth.php +++ b/app/Http/Middleware/ContactTokenAuth.php @@ -55,7 +55,7 @@ class ContactTokenAuth //stateless, don't remember the contact. auth()->guard('contact')->login($client_contact, false); - event(new ContactLoggedIn($client_contact, $client_contact->company, Ninja::eventVars())); + event(new ContactLoggedIn($client_contact, $client_contact->company, Ninja::eventVars())); } else { $error = [ 'message' => 'Invalid token', diff --git a/app/Http/Middleware/QueryLogging.php b/app/Http/Middleware/QueryLogging.php index bf71e2969221..4843070dc947 100644 --- a/app/Http/Middleware/QueryLogging.php +++ b/app/Http/Middleware/QueryLogging.php @@ -31,7 +31,6 @@ class QueryLogging */ public function handle(Request $request, Closure $next) { - $timeStart = microtime(true); // Enable query logging for development @@ -54,7 +53,6 @@ class QueryLogging // if($count > 50) // Log::info($queries); - } } diff --git a/app/Http/Middleware/SetEmailDb.php b/app/Http/Middleware/SetEmailDb.php index ec22cacae3d3..024a221e7e7c 100644 --- a/app/Http/Middleware/SetEmailDb.php +++ b/app/Http/Middleware/SetEmailDb.php @@ -38,7 +38,7 @@ class SetEmailDb if (! MultiDB::userFindAndSetDb($request->input('email'))) { return response()->json($error, 400); } - } + } // else { // return response()->json($error, 403); // } diff --git a/app/Http/Middleware/StartupCheck.php b/app/Http/Middleware/StartupCheck.php index 48f2517fdeb7..fe0c79a7533c 100644 --- a/app/Http/Middleware/StartupCheck.php +++ b/app/Http/Middleware/StartupCheck.php @@ -69,8 +69,9 @@ class StartupCheck /*Build template cache*/ - if ($request->has('clear_cache') || ! Cache::has('templates')) + if ($request->has('clear_cache') || ! Cache::has('templates')) { $this->buildTemplates(); + } $response = $next($request); diff --git a/app/Http/Middleware/TrustProxies.php b/app/Http/Middleware/TrustProxies.php index 82fd6890763e..1d8b76576121 100644 --- a/app/Http/Middleware/TrustProxies.php +++ b/app/Http/Middleware/TrustProxies.php @@ -36,12 +36,12 @@ class TrustProxies extends Middleware * * @param \Illuminate\Contracts\Config\Repository $config */ - public function __construct(Repository $config) { - - parent::__construct($config); - - if (config('ninja.trusted_proxies')) - $this->proxies = config('ninja.trusted_proxies'); + public function __construct(Repository $config) + { + parent::__construct($config); + if (config('ninja.trusted_proxies')) { + $this->proxies = config('ninja.trusted_proxies'); + } } } diff --git a/app/Http/Requests/Expense/UpdateExpenseRequest.php b/app/Http/Requests/Expense/UpdateExpenseRequest.php index bbaddc7ad89a..05f3cb5af5b1 100644 --- a/app/Http/Requests/Expense/UpdateExpenseRequest.php +++ b/app/Http/Requests/Expense/UpdateExpenseRequest.php @@ -42,8 +42,9 @@ class UpdateExpenseRequest extends Request //$rules['id_number'] = 'unique:clients,id_number,,id,company_id,' . auth()->user()->company()->id; $rules['contacts.*.email'] = 'nullable|distinct'; - if(isset($this->number)) + if (isset($this->number)) { $rules['number'] = Rule::unique('expenses')->where('company_id', auth()->user()->company()->id)->ignore($this->expense->id); + } return $this->globalRules($rules); } diff --git a/app/Http/Requests/ExpenseCategory/UpdateExpenseCategoryRequest.php b/app/Http/Requests/ExpenseCategory/UpdateExpenseCategoryRequest.php index 27d1f2c83c2c..aaf661f7558c 100644 --- a/app/Http/Requests/ExpenseCategory/UpdateExpenseCategoryRequest.php +++ b/app/Http/Requests/ExpenseCategory/UpdateExpenseCategoryRequest.php @@ -13,6 +13,7 @@ namespace App\Http\Requests\ExpenseCategory; use App\Http\Requests\Request; use App\Utils\Traits\ChecksEntityStatus; + class UpdateExpenseCategoryRequest extends Request { use ChecksEntityStatus; @@ -29,13 +30,12 @@ class UpdateExpenseCategoryRequest extends Request public function rules() { - $rules = []; - if ($this->input('name')) + if ($this->input('name')) { $rules['name'] = 'unique:expense_categories,name,'.$this->id.',id,company_id,'.$this->expense_category->company_id; + } return $rules; } - } diff --git a/app/Http/Requests/GroupSetting/StoreGroupSettingRequest.php b/app/Http/Requests/GroupSetting/StoreGroupSettingRequest.php index 844e309eb525..0beb6ed7988e 100644 --- a/app/Http/Requests/GroupSetting/StoreGroupSettingRequest.php +++ b/app/Http/Requests/GroupSetting/StoreGroupSettingRequest.php @@ -31,7 +31,6 @@ class StoreGroupSettingRequest extends Request public function rules() { - $rules['name'] = 'required|unique:group_settings,name,null,null,company_id,'.auth()->user()->companyId(); $rules['settings'] = new ValidClientGroupSettingsRule(); diff --git a/app/Http/Requests/Payment/StorePaymentRequest.php b/app/Http/Requests/Payment/StorePaymentRequest.php index 93afbd206cdf..b2ea76a15db9 100644 --- a/app/Http/Requests/Payment/StorePaymentRequest.php +++ b/app/Http/Requests/Payment/StorePaymentRequest.php @@ -39,7 +39,7 @@ class StorePaymentRequest extends Request { $input = $this->all(); - // info(print_r($input,1)); + // info(print_r($input,1)); $invoices_total = 0; $credits_total = 0; @@ -77,7 +77,7 @@ class StorePaymentRequest extends Request } if (! isset($input['amount']) || $input['amount'] == 0) { - $input['amount'] = $invoices_total - $credits_total; + $input['amount'] = $invoices_total - $credits_total; } $input['is_manual'] = true; diff --git a/app/Http/Requests/Payment/UpdatePaymentRequest.php b/app/Http/Requests/Payment/UpdatePaymentRequest.php index 961fd3e93274..182fccd83a81 100644 --- a/app/Http/Requests/Payment/UpdatePaymentRequest.php +++ b/app/Http/Requests/Payment/UpdatePaymentRequest.php @@ -35,8 +35,7 @@ class UpdatePaymentRequest extends Request public function rules() { - - $rules = [ + $rules = [ 'number' => 'nullable|unique:payments,number,'.$this->id.',id,company_id,'.$this->payment->company_id, 'invoices' => ['array', new PaymentAppliedValidAmount, new ValidCreditsPresentRule], 'invoices.*.invoice_id' => 'distinct', diff --git a/app/Http/Requests/Project/StoreProjectRequest.php b/app/Http/Requests/Project/StoreProjectRequest.php index a59dbbadb10f..a7f77e9d2c67 100644 --- a/app/Http/Requests/Project/StoreProjectRequest.php +++ b/app/Http/Requests/Project/StoreProjectRequest.php @@ -34,16 +34,16 @@ class StoreProjectRequest extends Request { $rules = []; - $rules['name'] = 'required'; - $rules['client_id'] = 'required|exists:clients,id,company_id,'.auth()->user()->company()->id; - $rules['number'] = 'unique:projects,number,'.$this->id.',id,company_id,'.auth()->user()->company()->id; + $rules['name'] = 'required'; + $rules['client_id'] = 'required|exists:clients,id,company_id,'.auth()->user()->company()->id; + $rules['number'] = 'unique:projects,number,'.$this->id.',id,company_id,'.auth()->user()->company()->id; return $this->globalRules($rules); } protected function prepareForValidation() { - $input = $this->decodePrimaryKeys($this->all()); + $input = $this->decodePrimaryKeys($this->all()); $this->replace($input); } diff --git a/app/Http/Requests/Project/UpdateProjectRequest.php b/app/Http/Requests/Project/UpdateProjectRequest.php index 48c4e947a140..89bc1d468176 100644 --- a/app/Http/Requests/Project/UpdateProjectRequest.php +++ b/app/Http/Requests/Project/UpdateProjectRequest.php @@ -33,18 +33,20 @@ class UpdateProjectRequest extends Request { $rules = []; - if(isset($this->number)) + if (isset($this->number)) { $rules['number'] = Rule::unique('projects')->where('company_id', auth()->user()->company()->id)->ignore($this->project->id); + } return $this->globalRules($rules); } protected function prepareForValidation() { - $input = $this->decodePrimaryKeys($this->all()); + $input = $this->decodePrimaryKeys($this->all()); - if(isset($input['client_id'])) + if (isset($input['client_id'])) { unset($input['client_id']); + } $this->replace($input); } diff --git a/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php b/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php index 6c5fca03ccda..cba0442356a7 100644 --- a/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php +++ b/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php @@ -100,29 +100,30 @@ class StoreRecurringInvoiceRequest extends Request $input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : []; - if(isset($input['auto_bill'])) + if (isset($input['auto_bill'])) { $input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']); - else{ - - if($client = Client::find($input['client_id'])) + } else { + if ($client = Client::find($input['client_id'])) { $input['auto_bill'] = $client->getSetting('auto_bill'); + } } - $this->replace($input); + $this->replace($input); } private function setAutoBillFlag($auto_bill) { - if($auto_bill == 'always') + if ($auto_bill == 'always') { return true; + } - if($auto_bill == 'off') + if ($auto_bill == 'off') { return false; - + } } - public function messages() - { - return []; - } + public function messages() + { + return []; + } } diff --git a/app/Http/Requests/RecurringInvoice/UpdateRecurringInvoiceRequest.php b/app/Http/Requests/RecurringInvoice/UpdateRecurringInvoiceRequest.php index cd512f03f09b..a02fa5a989b0 100644 --- a/app/Http/Requests/RecurringInvoice/UpdateRecurringInvoiceRequest.php +++ b/app/Http/Requests/RecurringInvoice/UpdateRecurringInvoiceRequest.php @@ -36,7 +36,6 @@ class UpdateRecurringInvoiceRequest extends Request public function rules() { - $rules = []; if ($this->input('documents') && is_array($this->input('documents'))) { @@ -90,33 +89,32 @@ class UpdateRecurringInvoiceRequest extends Request $input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : []; - if(isset($input['auto_bill'])) + if (isset($input['auto_bill'])) { $input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']); + } $this->replace($input); } /** * if($auto_bill == '') - * off / optin / optout will reset the status of this field to off to allow + * off / optin / optout will reset the status of this field to off to allow * the client to choose whether to auto_bill or not. - * + * * @param enum $auto_bill off/always/optin/optout * * @return bool */ private function setAutoBillFlag($auto_bill) :bool { - - if($auto_bill == 'always') + if ($auto_bill == 'always') { return true; + } // if($auto_bill == '') - // off / optin / optout will reset the status of this field to off to allow + // off / optin / optout will reset the status of this field to off to allow // the client to choose whether to auto_bill or not. return false; - } - } diff --git a/app/Http/Requests/Request.php b/app/Http/Requests/Request.php index 5e31c967e522..5b30670aa357 100644 --- a/app/Http/Requests/Request.php +++ b/app/Http/Requests/Request.php @@ -17,7 +17,7 @@ use Illuminate\Foundation\Http\FormRequest; class Request extends FormRequest { - use MakesHash; + use MakesHash; /** * Get the validation rules that apply to the request. @@ -31,22 +31,22 @@ class Request extends FormRequest public function globalRules($rules) { - $merge_rules = []; + $merge_rules = []; - foreach($this->all() as $key => $value) - { - if(method_exists($this, $key)) - $merge_rules = $this->{$key}($rules); - } + foreach ($this->all() as $key => $value) { + if (method_exists($this, $key)) { + $merge_rules = $this->{$key}($rules); + } + } - return array_merge($merge_rules, $rules); + return array_merge($merge_rules, $rules); } private function assigned_user_id($rules) - { - $rules['assigned_user_id'] = [ - 'bail' , - 'sometimes', + { + $rules['assigned_user_id'] = [ + 'bail' , + 'sometimes', 'nullable', new RelatedUserRule($this->all()) ]; @@ -70,7 +70,6 @@ class Request extends FormRequest public function decodePrimaryKeys($input) { - if (array_key_exists('assigned_user_id', $input) && is_string($input['assigned_user_id'])) { $input['assigned_user_id'] = $this->decodePrimaryKey($input['assigned_user_id']); } @@ -81,15 +80,15 @@ class Request extends FormRequest if (array_key_exists('vendor_id', $input) && is_string($input['vendor_id'])) { $input['vendor_id'] = $this->decodePrimaryKey($input['vendor_id']); - } + } if (array_key_exists('client_id', $input) && is_string($input['client_id'])) { $input['client_id'] = $this->decodePrimaryKey($input['client_id']); - } + } if (array_key_exists('invoice_id', $input) && is_string($input['invoice_id'])) { $input['invoice_id'] = $this->decodePrimaryKey($input['invoice_id']); - } + } if (array_key_exists('design_id', $input) && is_string($input['design_id'])) { $input['design_id'] = $this->decodePrimaryKey($input['design_id']); @@ -146,6 +145,6 @@ class Request extends FormRequest } } - return $input; + return $input; } } diff --git a/app/Http/Requests/Task/StoreTaskRequest.php b/app/Http/Requests/Task/StoreTaskRequest.php index 6bd1bce41387..a7813c7a9c23 100644 --- a/app/Http/Requests/Task/StoreTaskRequest.php +++ b/app/Http/Requests/Task/StoreTaskRequest.php @@ -38,17 +38,18 @@ class StoreTaskRequest extends Request { $rules = []; - if(isset($this->number)) + if (isset($this->number)) { $rules['number'] = Rule::unique('tasks')->where('company_id', auth()->user()->company()->id); + } - return $this->globalRules($rules); + return $this->globalRules($rules); } protected function prepareForValidation() { $input = $this->all(); - $input = $this->decodePrimaryKeys($this->all()); + $input = $this->decodePrimaryKeys($this->all()); if (array_key_exists('status_id', $input) && is_string($input['status_id'])) { $input['status_id'] = $this->decodePrimaryKey($input['status_id']); @@ -56,5 +57,4 @@ class StoreTaskRequest extends Request $this->replace($input); } - } diff --git a/app/Http/Requests/Task/UpdateTaskRequest.php b/app/Http/Requests/Task/UpdateTaskRequest.php index 16a1e3882e1f..1610800efb49 100644 --- a/app/Http/Requests/Task/UpdateTaskRequest.php +++ b/app/Http/Requests/Task/UpdateTaskRequest.php @@ -38,15 +38,16 @@ class UpdateTaskRequest extends Request { $rules = []; - if(isset($this->number)) + if (isset($this->number)) { $rules['number'] = Rule::unique('tasks')->where('company_id', auth()->user()->company()->id)->ignore($this->task->id); + } return $this->globalRules($rules); } protected function prepareForValidation() { - $input = $this->decodePrimaryKeys($this->all()); + $input = $this->decodePrimaryKeys($this->all()); if (array_key_exists('status_id', $input) && is_string($input['status_id'])) { $input['status_id'] = $this->decodePrimaryKey($input['status_id']); diff --git a/app/Http/Requests/TaskStatus/UpdateTaskStatusRequest.php b/app/Http/Requests/TaskStatus/UpdateTaskStatusRequest.php index d6e550427f98..b0d822ca3af1 100644 --- a/app/Http/Requests/TaskStatus/UpdateTaskStatusRequest.php +++ b/app/Http/Requests/TaskStatus/UpdateTaskStatusRequest.php @@ -33,10 +33,10 @@ class UpdateTaskStatusRequest extends Request { $rules = []; - if ($this->input('name')) - $rules['name'] = 'unique:task_statuses,name,'.$this->id.',id,company_id,'.$this->task_status->company_id; + if ($this->input('name')) { + $rules['name'] = 'unique:task_statuses,name,'.$this->id.',id,company_id,'.$this->task_status->company_id; + } - return $rules; + return $rules; } - } diff --git a/app/Http/ValidationRules/Credit/CreditsSumRule.php b/app/Http/ValidationRules/Credit/CreditsSumRule.php index 134a8bbe76b9..5da527372f96 100644 --- a/app/Http/ValidationRules/Credit/CreditsSumRule.php +++ b/app/Http/ValidationRules/Credit/CreditsSumRule.php @@ -41,12 +41,11 @@ class CreditsSumRule implements Rule private function checkCreditTotals() { - - if( array_sum(array_column($this->input['credits'],'amount')) > array_sum(array_column($this->input['invoices'], 'amount'))) + if (array_sum(array_column($this->input['credits'], 'amount')) > array_sum(array_column($this->input['invoices'], 'amount'))) { return false; + } return true; - } /** diff --git a/app/Http/ValidationRules/Expense/UniqueExpenseNumberRule.php b/app/Http/ValidationRules/Expense/UniqueExpenseNumberRule.php index dc1c0c5195f4..1e7ea875dd24 100644 --- a/app/Http/ValidationRules/Expense/UniqueExpenseNumberRule.php +++ b/app/Http/ValidationRules/Expense/UniqueExpenseNumberRule.php @@ -51,8 +51,9 @@ class UniqueExpenseNumberRule implements Rule */ private function checkIfExpenseNumberUnique() : bool { - if(empty($this->input['number'])) + if (empty($this->input['number'])) { return true; + } $expense = Expense::query() ->where('number', $this->input['number']) diff --git a/app/Http/ValidationRules/Invoice/UniqueInvoiceNumberRule.php b/app/Http/ValidationRules/Invoice/UniqueInvoiceNumberRule.php index 1cecd095cf2b..cc45ff9d1206 100644 --- a/app/Http/ValidationRules/Invoice/UniqueInvoiceNumberRule.php +++ b/app/Http/ValidationRules/Invoice/UniqueInvoiceNumberRule.php @@ -51,8 +51,9 @@ class UniqueInvoiceNumberRule implements Rule */ private function checkIfInvoiceNumberUnique() : bool { - if(empty($this->input['number'])) + if (empty($this->input['number'])) { return true; + } $invoice = Invoice::where('client_id', $this->input['client_id']) ->where('number', $this->input['number']) diff --git a/app/Http/ValidationRules/PaymentAmountsBalanceRule.php b/app/Http/ValidationRules/PaymentAmountsBalanceRule.php index cc9ff5251b21..35146355c7e1 100644 --- a/app/Http/ValidationRules/PaymentAmountsBalanceRule.php +++ b/app/Http/ValidationRules/PaymentAmountsBalanceRule.php @@ -73,8 +73,8 @@ class PaymentAmountsBalanceRule implements Rule return true; } // if no invoices are present, then this is an unapplied payment, let this pass validation! -// info("payment amounts = {$payment_amounts}"); -// info("invoice amounts = {$invoice_amounts}"); + // info("payment amounts = {$payment_amounts}"); + // info("invoice amounts = {$invoice_amounts}"); return $payment_amounts >= $invoice_amounts; } diff --git a/app/Http/ValidationRules/Project/ValidProjectForClient.php b/app/Http/ValidationRules/Project/ValidProjectForClient.php index e33d5366a2bd..2118686a1155 100644 --- a/app/Http/ValidationRules/Project/ValidProjectForClient.php +++ b/app/Http/ValidationRules/Project/ValidProjectForClient.php @@ -35,11 +35,13 @@ class ValidProjectForClient implements Rule */ public function passes($attribute, $value) { - if(empty($this->input['project_id'])) + if (empty($this->input['project_id'])) { return true; + } - if(is_string($this->input['project_id'])) + if (is_string($this->input['project_id'])) { $this->input['project_id'] = $this->decodePrimaryKey($this->input['project_id']); + } $project = Project::findOrFail($this->input['project_id']); @@ -53,6 +55,4 @@ class ValidProjectForClient implements Rule { return "Project client does not match entity client"; } - - } diff --git a/app/Http/ValidationRules/Recurring/UniqueRecurringInvoiceNumberRule.php b/app/Http/ValidationRules/Recurring/UniqueRecurringInvoiceNumberRule.php index d37cbcfa05ea..124118bbc90a 100644 --- a/app/Http/ValidationRules/Recurring/UniqueRecurringInvoiceNumberRule.php +++ b/app/Http/ValidationRules/Recurring/UniqueRecurringInvoiceNumberRule.php @@ -52,8 +52,9 @@ class UniqueRecurringInvoiceNumberRule implements Rule */ private function checkIfInvoiceNumberUnique() : bool { - if(empty($this->input['number'])) + if (empty($this->input['number'])) { return true; + } $invoice = RecurringInvoice::where('client_id', $this->input['client_id']) ->where('number', $this->input['number']) diff --git a/app/Http/ValidationRules/User/RelatedUserRule.php b/app/Http/ValidationRules/User/RelatedUserRule.php index 43958e7a49b9..f554684b3edc 100644 --- a/app/Http/ValidationRules/User/RelatedUserRule.php +++ b/app/Http/ValidationRules/User/RelatedUserRule.php @@ -50,9 +50,9 @@ class RelatedUserRule implements Rule */ private function checkUserIsRelated($user_id) : bool { - - if(empty($user_id)) + if (empty($user_id)) { return true; + } return User::query() ->where('id', $user_id) diff --git a/app/Http/ValidationRules/ValidCreditsPresentRule.php b/app/Http/ValidationRules/ValidCreditsPresentRule.php index 46d1de283e51..6f24b1b0f181 100644 --- a/app/Http/ValidationRules/ValidCreditsPresentRule.php +++ b/app/Http/ValidationRules/ValidCreditsPresentRule.php @@ -60,7 +60,6 @@ class ValidCreditsPresentRule implements Rule if (request()->input('credits') && is_array(request()->input('credits'))) { - $credit_collection = Credit::whereIn('id', $this->transformKeys(array_column(request()->input('credits'), 'credit_id'))) ->where('balance', '>', 0) ->get(); diff --git a/app/Http/ViewComposers/PortalComposer.php b/app/Http/ViewComposers/PortalComposer.php index 5f1a172ef57b..5d36d37c4e89 100644 --- a/app/Http/ViewComposers/PortalComposer.php +++ b/app/Http/ViewComposers/PortalComposer.php @@ -32,8 +32,9 @@ class PortalComposer { $view->with($this->portalData()); - if(auth()->user()) + if (auth()->user()) { Lang::replace(Ninja::transformTranslations(auth()->user()->client->getMergedSettings())); + } } /** @@ -73,7 +74,7 @@ class PortalComposer $data[] = ['title' => ctrans('texts.documents'), 'url' => 'client.documents.index', 'icon' => 'download']; if (auth()->user('contact')->client->getSetting('enable_client_portal_tasks')) { - $data[] = ['title' => ctrans('texts.tasks'), 'url' => 'client.dashboard', 'icon' => 'clock']; + $data[] = ['title' => ctrans('texts.tasks'), 'url' => 'client.dashboard', 'icon' => 'clock']; // TODO: Update when 'tasks' module is available in client portal. } diff --git a/app/Jobs/Cron/RecurringInvoicesCron.php b/app/Jobs/Cron/RecurringInvoicesCron.php index 6927648d0b0c..efc441756cde 100644 --- a/app/Jobs/Cron/RecurringInvoicesCron.php +++ b/app/Jobs/Cron/RecurringInvoicesCron.php @@ -22,7 +22,7 @@ use Illuminate\Support\Facades\Log; class RecurringInvoicesCron { - use Dispatchable; + use Dispatchable; /** * Create a new job instance. @@ -44,27 +44,23 @@ class RecurringInvoicesCron info("Sending recurring invoices ".Carbon::now()->format('Y-m-d h:i:s')); if (! config('ninja.db.multi_db_enabled')) { - - $recurring_invoices = RecurringInvoice::whereDate('next_send_date', '=', now()) + $recurring_invoices = RecurringInvoice::whereDate('next_send_date', '=', now()) ->where('status_id', RecurringInvoice::STATUS_ACTIVE) ->with('company') ->cursor(); - Log::info(now()->format('Y-m-d') . ' Sending Recurring Invoices. Count = '.$recurring_invoices->count()); - - $recurring_invoices->each(function ($recurring_invoice, $key) { + Log::info(now()->format('Y-m-d') . ' Sending Recurring Invoices. Count = '.$recurring_invoices->count()); + $recurring_invoices->each(function ($recurring_invoice, $key) { info("Current date = " . now()->format("Y-m-d") . " Recurring date = " .$recurring_invoice->next_send_date); - if(!$recurring_invoice->company->is_disabled) + if (!$recurring_invoice->company->is_disabled) { SendRecurring::dispatchNow($recurring_invoice, $recurring_invoice->company->db); - + } }); - } else { //multiDB environment, need to foreach (MultiDB::$dbs as $db) { - MultiDB::setDB($db); $recurring_invoices = RecurringInvoice::whereDate('next_send_date', '=', now()) @@ -75,12 +71,11 @@ class RecurringInvoicesCron Log::info(now()->format('Y-m-d') . ' Sending Recurring Invoices. Count = '.$recurring_invoices->count().' On Database # '.$db); $recurring_invoices->each(function ($recurring_invoice, $key) { - info("Current date = " . now()->format("Y-m-d") . " Recurring date = " .$recurring_invoice->next_send_date); - if(!$recurring_invoice->company->is_disabled) + if (!$recurring_invoice->company->is_disabled) { SendRecurring::dispatchNow($recurring_invoice, $recurring_invoice->company->db); - + } }); } } diff --git a/app/Jobs/Entity/CreateEntityPdf.php b/app/Jobs/Entity/CreateEntityPdf.php index a3847da9fe4c..982eadc06c38 100644 --- a/app/Jobs/Entity/CreateEntityPdf.php +++ b/app/Jobs/Entity/CreateEntityPdf.php @@ -72,19 +72,16 @@ class CreateEntityPdf implements ShouldQueue { $this->invitation = $invitation; - if($invitation instanceof InvoiceInvitation){ + if ($invitation instanceof InvoiceInvitation) { $this->entity = $invitation->invoice; $this->entity_string = 'invoice'; - } - elseif($invitation instanceof QuoteInvitation){ + } elseif ($invitation instanceof QuoteInvitation) { $this->entity = $invitation->quote; $this->entity_string = 'quote'; - } - elseif($invitation instanceof CreditInvitation){ + } elseif ($invitation instanceof CreditInvitation) { $this->entity = $invitation->credit; $this->entity_string = 'credit'; - } - elseif($invitation instanceof RecurringInvoiceInvitation){ + } elseif ($invitation instanceof RecurringInvoiceInvitation) { $this->entity = $invitation->recurring_invoice; $this->entity_string = 'recurring_invoice'; } @@ -98,7 +95,6 @@ class CreateEntityPdf implements ShouldQueue public function handle() { - if (config('ninja.phantomjs_key')) { return (new Phantom)->generate($this->invitation); } @@ -108,15 +104,13 @@ class CreateEntityPdf implements ShouldQueue $entity_design_id = ''; - if($this->entity instanceof Invoice){ + if ($this->entity instanceof Invoice) { $path = $this->entity->client->invoice_filepath(); $entity_design_id = 'invoice_design_id'; - } - elseif($this->entity instanceof Quote){ + } elseif ($this->entity instanceof Quote) { $path = $this->entity->client->quote_filepath(); $entity_design_id = 'quote_design_id'; - } - elseif($this->entity instanceof Credit){ + } elseif ($this->entity instanceof Credit) { $path = $this->entity->client->credit_filepath(); $entity_design_id = 'credit_design_id'; } @@ -131,12 +125,12 @@ class CreateEntityPdf implements ShouldQueue $html = new HtmlEngine($this->invitation); if ($design->is_custom) { - $options = [ + $options = [ 'custom_partials' => json_decode(json_encode($design->design), true) ]; - $template = new PdfMakerDesign(PdfDesignModel::CUSTOM, $options); + $template = new PdfMakerDesign(PdfDesignModel::CUSTOM, $options); } else { - $template = new PdfMakerDesign(strtolower($design->name)); + $template = new PdfMakerDesign(strtolower($design->name)); } $state = [ @@ -165,15 +159,14 @@ class CreateEntityPdf implements ShouldQueue $pdf = null; try { - $pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true)); - } - catch(\Exception $e) { - info(print_r($e->getMessage(),1)); + } catch (\Exception $e) { + info(print_r($e->getMessage(), 1)); } - if($pdf) + if ($pdf) { $instance = Storage::disk($this->disk)->put($file_path, $pdf); + } return $file_path; } diff --git a/app/Jobs/Entity/EmailEntity.php b/app/Jobs/Entity/EmailEntity.php index c6ab3c30f197..1daf8e0bf61a 100644 --- a/app/Jobs/Entity/EmailEntity.php +++ b/app/Jobs/Entity/EmailEntity.php @@ -88,7 +88,6 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue $this->template_data = $template_data; $this->email_entity_builder = $this->resolveEmailBuilder(); - } /** @@ -99,8 +98,9 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue */ public function handle() { - if($this->company->is_disabled) + if ($this->company->is_disabled) { return true; + } MultiDB::setDB($this->company->db); @@ -132,14 +132,15 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue private function resolveEntityString() :string { - if($this->invitation instanceof InvoiceInvitation) + if ($this->invitation instanceof InvoiceInvitation) { return 'invoice'; - elseif($this->invitation instanceof QuoteInvitation) + } elseif ($this->invitation instanceof QuoteInvitation) { return 'quote'; - elseif($this->invitation instanceof CreditInvitation) + } elseif ($this->invitation instanceof CreditInvitation) { return 'credit'; - elseif($this->invitation instanceof RecurringInvoiceInvitation) + } elseif ($this->invitation instanceof RecurringInvoiceInvitation) { return 'recurring_invoice'; + } } private function entityEmailFailed($message) @@ -153,7 +154,6 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue # code... break; } - } private function entityEmailSucceeded() diff --git a/app/Jobs/Invoice/ZipInvoices.php b/app/Jobs/Invoice/ZipInvoices.php index ad3619923105..e614352c5701 100644 --- a/app/Jobs/Invoice/ZipInvoices.php +++ b/app/Jobs/Invoice/ZipInvoices.php @@ -97,10 +97,8 @@ class ZipInvoices extends BaseMailerJob implements ShouldQueue try { Mail::to($this->email) ->send(new DownloadInvoices(Storage::disk(config('filesystems.default'))->url($path.$file_name), $this->company)); - } - catch (\Exception $e) { + } catch (\Exception $e) { $this->failed($e); - } UnlinkFile::dispatch(config('filesystems.default'), $path.$file_name)->delay(now()->addHours(1)); diff --git a/app/Jobs/Mail/BaseMailerJob.php b/app/Jobs/Mail/BaseMailerJob.php index a938086e133b..303591d0c435 100644 --- a/app/Jobs/Mail/BaseMailerJob.php +++ b/app/Jobs/Mail/BaseMailerJob.php @@ -104,6 +104,5 @@ class BaseMailerJob implements ShouldQueue LightLogs::create($job_failure) ->batch(); - } } diff --git a/app/Jobs/Mail/EntityPaidMailer.php b/app/Jobs/Mail/EntityPaidMailer.php index 2ca18b4a8916..f5ba0d8b7aa4 100644 --- a/app/Jobs/Mail/EntityPaidMailer.php +++ b/app/Jobs/Mail/EntityPaidMailer.php @@ -72,8 +72,9 @@ class EntityPaidMailer extends BaseMailerJob implements ShouldQueue public function handle() { /*If we are migrating data we don't want to fire these notification*/ - if ($this->company->is_disabled) + if ($this->company->is_disabled) { return true; + } //Set DB MultiDB::setDb($this->company->db); @@ -82,18 +83,15 @@ class EntityPaidMailer extends BaseMailerJob implements ShouldQueue $this->setMailDriver(); try { - $mail_obj = (new EntityPaidObject($this->payment))->build(); $mail_obj->from = [$this->user->email, $this->user->present()->name()]; //send email Mail::to($this->user->email) ->send(new EntityNotificationMailer($mail_obj)); - } catch (\Exception $e) { $this->failed($e); $this->logMailError($e->getMessage(), $this->payment->client); } - } } diff --git a/app/Jobs/Mail/EntitySentMailer.php b/app/Jobs/Mail/EntitySentMailer.php index 88b120913ee4..a21b052f243f 100644 --- a/app/Jobs/Mail/EntitySentMailer.php +++ b/app/Jobs/Mail/EntitySentMailer.php @@ -76,8 +76,9 @@ class EntitySentMailer extends BaseMailerJob implements ShouldQueue public function handle() { /*If we are migrating data we don't want to fire these notification*/ - if ($this->company->is_disabled) + if ($this->company->is_disabled) { return true; + } //Set DB MultiDB::setDb($this->company->db); @@ -91,12 +92,9 @@ class EntitySentMailer extends BaseMailerJob implements ShouldQueue try { Mail::to($this->user->email) ->send(new EntityNotificationMailer($mail_obj)); - }catch(\Exception $e) { - + } catch (\Exception $e) { $this->failed($e); $this->logMailError($e->getMessage(), $this->entity->client); - } - } } diff --git a/app/Jobs/Mail/EntityViewedMailer.php b/app/Jobs/Mail/EntityViewedMailer.php index ba01dd8b88f1..278531ee8f4c 100644 --- a/app/Jobs/Mail/EntityViewedMailer.php +++ b/app/Jobs/Mail/EntityViewedMailer.php @@ -76,8 +76,9 @@ class EntityViewedMailer extends BaseMailerJob implements ShouldQueue public function handle() { /*If we are migrating data we don't want to fire these notification*/ - if ($this->company->is_disabled) + if ($this->company->is_disabled) { return true; + } //Set DB MultiDB::setDb($this->company->db); @@ -89,15 +90,12 @@ class EntityViewedMailer extends BaseMailerJob implements ShouldQueue $mail_obj->from = [$this->entity->user->email, $this->entity->user->present()->name()]; //send email - try{ + try { Mail::to($this->user->email) ->send(new EntityNotificationMailer($mail_obj)); - } - catch (\Exception $e) { - + } catch (\Exception $e) { $this->failed($e); $this->logMailError($e->getMessage(), $this->entity->client); - } } } diff --git a/app/Jobs/Mail/MailRouter.php b/app/Jobs/Mail/MailRouter.php index e0dcd4b31020..a532de21b477 100644 --- a/app/Jobs/Mail/MailRouter.php +++ b/app/Jobs/Mail/MailRouter.php @@ -67,8 +67,9 @@ class MailRouter extends BaseMailerJob implements ShouldQueue public function handle() { /*If we are migrating data we don't want to fire these notification*/ - if ($this->company->is_disabled) + if ($this->company->is_disabled) { return true; + } MultiDB::setDb($this->company->db); @@ -79,13 +80,9 @@ class MailRouter extends BaseMailerJob implements ShouldQueue try { Mail::to($this->to_user->email) ->send($this->mailable); - } - catch (\Exception $e) { - + } catch (\Exception $e) { $this->failed($e); $this->logMailError($e->getMessage(), $this->to_user); - } - } } diff --git a/app/Jobs/Mail/PaymentFailureMailer.php b/app/Jobs/Mail/PaymentFailureMailer.php index 1c405d477ce8..3828bfc5c666 100644 --- a/app/Jobs/Mail/PaymentFailureMailer.php +++ b/app/Jobs/Mail/PaymentFailureMailer.php @@ -77,8 +77,9 @@ class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue public function handle() { /*If we are migrating data we don't want to fire these notification*/ - if ($this->company->is_disabled) + if ($this->company->is_disabled) { return true; + } //Set DB MultiDB::setDb($this->company->db); @@ -103,14 +104,10 @@ class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue try { Mail::to($company_user->user->email) ->send(new EntityNotificationMailer($mail_obj)); - } - catch(\Exception $e) { - + } catch (\Exception $e) { $this->failed($e); $this->logMailError($e->getMessage(), $this->client); - } - } }); } diff --git a/app/Jobs/Ninja/RefundCancelledAccount.php b/app/Jobs/Ninja/RefundCancelledAccount.php index 9bc2e40ea74c..0a1154d153c6 100644 --- a/app/Jobs/Ninja/RefundCancelledAccount.php +++ b/app/Jobs/Ninja/RefundCancelledAccount.php @@ -41,16 +41,19 @@ class RefundCancelledAccount implements ShouldQueue $plan_details = $this->account->getPlanDetails(); - if(!$plan_details) + if (!$plan_details) { return; + } /* Trial user cancelling early.... */ - if ($plan_details['trial_plan']) + if ($plan_details['trial_plan']) { return; + } /* Is the plan Active? */ - if (! $plan_details['active']) + if (! $plan_details['active']) { return; + } /* Refundable client! */ diff --git a/app/Jobs/Ninja/SendReminders.php b/app/Jobs/Ninja/SendReminders.php index 6120332cd4c9..299dd1e0f607 100644 --- a/app/Jobs/Ninja/SendReminders.php +++ b/app/Jobs/Ninja/SendReminders.php @@ -47,26 +47,18 @@ class SendReminders implements ShouldQueue */ public function handle() { - info("Sending reminders ".Carbon::now()->format('Y-m-d h:i:s')); if (! config('ninja.db.multi_db_enabled')) { - $this->sendReminderEmails(); - - } else { //multiDB environment, need to - foreach (MultiDB::$dbs as $db) - { - + foreach (MultiDB::$dbs as $db) { MultiDB::setDB($db); $this->sendReminderEmails(); } - } - } @@ -80,21 +72,17 @@ class SendReminders implements ShouldQueue ->cursor(); //we only need invoices that are payable - $invoices->filter(function ($invoice){ - + $invoices->filter(function ($invoice) { return $invoice->isPayable(); + })->each(function ($invoice) { + $reminder_template = $invoice->calculateTemplate('invoice'); - })->each(function ($invoice){ - - $reminder_template = $invoice->calculateTemplate('invoice'); - - info("hitting a reminder for {$invoice->number} with template {$reminder_template}"); + info("hitting a reminder for {$invoice->number} with template {$reminder_template}"); - if(in_array($reminder_template, ['reminder1', 'reminder2', 'reminder3', 'endless_reminder'])) - $this->sendReminder($invoice, $reminder_template); - + if (in_array($reminder_template, ['reminder1', 'reminder2', 'reminder3', 'endless_reminder'])) { + $this->sendReminder($invoice, $reminder_template); + } }); - } private function checkSendSetting($invoice, $template) @@ -111,7 +99,7 @@ class SendReminders implements ShouldQueue break; case 'endless_reminder': return $invoice->client->getSetting('enable_reminder_endless'); - break; + break; default: return false; break; @@ -121,9 +109,9 @@ class SendReminders implements ShouldQueue /** * Create a collection of all possible reminder dates * and pass back the first one in chronology - * + * * @param Invoice $invoice - * @return Carbon $date + * @return Carbon $date */ private function calculateNextSendDate($invoice) { @@ -135,41 +123,41 @@ class SendReminders implements ShouldQueue $set_reminder2 = false; $set_reminder3 = false; - if((int)$settings->schedule_reminder1 > 0){ - + if ((int)$settings->schedule_reminder1 > 0) { $next_reminder_date = $this->calculateScheduledDate($invoice, (int)$settings->schedule_reminder1, (int)$settings->num_days_reminder1); - if($next_reminder_date->gt(Carbon::parse($invoice->last_sent_date))); - $dates->push($next_reminder_date); + if ($next_reminder_date->gt(Carbon::parse($invoice->last_sent_date))); + $dates->push($next_reminder_date); - if(!$invoice->reminder1_sent) + if (!$invoice->reminder1_sent) { $set_reminder1 = true; + } } - if((int)$settings->num_days_reminder2 > 0){ - + if ((int)$settings->num_days_reminder2 > 0) { $next_reminder_date = $this->calculateScheduledDate($invoice, (int)$settings->schedule_reminder2, (int)$settings->num_days_reminder2); - if($next_reminder_date->gt(Carbon::parse($invoice->last_sent_date))); - $dates->push($next_reminder_date); + if ($next_reminder_date->gt(Carbon::parse($invoice->last_sent_date))); + $dates->push($next_reminder_date); - if(!$invoice->reminder2_sent) + if (!$invoice->reminder2_sent) { $set_reminder3 = true; + } } - if((int)$settings->num_days_reminder3 > 0){ - + if ((int)$settings->num_days_reminder3 > 0) { $next_reminder_date = $this->calculateScheduledDate($invoice, (int)$settings->schedule_reminder3, (int)$settings->num_days_reminder3); - if($next_reminder_date->gt(Carbon::parse($invoice->last_sent_date))); - $dates->push($next_reminder_date); + if ($next_reminder_date->gt(Carbon::parse($invoice->last_sent_date))); + $dates->push($next_reminder_date); - if(!$invoice->reminder3_sent) + if (!$invoice->reminder3_sent) { $set_reminder3 = true; + } } //If all the available reminders have fired, we then start to fire the endless reminders - if((int)$settings->endless_reminder_frequency_id > 0 && !$set_reminder1 && !$set_reminder2 && !$set_reminder3) { + if ((int)$settings->endless_reminder_frequency_id > 0 && !$set_reminder1 && !$set_reminder2 && !$set_reminder3) { $dates->push($this->addTimeInterval($invoice->last_sent_date, (int)$settings->endless_reminder_frequency_id)); } @@ -179,10 +167,10 @@ class SendReminders implements ShouldQueue /** * Helper method which switches values based on the $schedule_reminder - * @param Invoice $invoice - * @param string $schedule_reminder - * @param int $num_days_reminder - * @return Carbon $date + * @param Invoice $invoice + * @param string $schedule_reminder + * @param int $num_days_reminder + * @return Carbon $date */ private function calculateScheduledDate($invoice, $schedule_reminder, $num_days_reminder) :?Carbon { @@ -204,48 +192,46 @@ class SendReminders implements ShouldQueue /** * Sends the reminder and/or late fee for the invoice. - * - * @param Invoice $invoice - * @param string $template - * @return void + * + * @param Invoice $invoice + * @param string $template + * @return void */ private function sendReminder($invoice, $template) :void { $invoice = $this->calcLateFee($invoice, $template); - $invoice->invitations->each(function ($invitation) use($template, $invoice){ + $invoice->invitations->each(function ($invitation) use ($template, $invoice) { //only send if enable_reminder setting is toggled to yes - if($this->checkSendSetting($invoice, $template)) { - + if ($this->checkSendSetting($invoice, $template)) { info("firing email"); EmailEntity::dispatchNow($invitation, $invitation->company, $template); - } - - }); - if($this->checkSendSetting($invoice, $template)) - event(new InvoiceWasEmailed($invoice->invitations->first(), $invoice->company, Ninja::eventVars())); + if ($this->checkSendSetting($invoice, $template)) { + event(new InvoiceWasEmailed($invoice->invitations->first(), $invoice->company, Ninja::eventVars())); + } - $invoice->last_sent_date = now(); - $invoice->next_send_date = $this->calculateNextSendDate($invoice); + $invoice->last_sent_date = now(); + $invoice->next_send_date = $this->calculateNextSendDate($invoice); - if(in_array($template, ['reminder1', 'reminder2', 'reminder3'])) - $invoice->{$template."_sent"} = now(); + if (in_array($template, ['reminder1', 'reminder2', 'reminder3'])) { + $invoice->{$template."_sent"} = now(); + } - $invoice->save(); + $invoice->save(); } /** * Calculates the late if - if any - and rebuilds the invoice - * - * @param Invoice $invoice - * @param string $template - * @return Invoice + * + * @param Invoice $invoice + * @param string $template + * @return Invoice */ private function calcLateFee($invoice, $template) :Invoice { @@ -268,7 +254,7 @@ class SendReminders implements ShouldQueue case 'endless_reminder': $late_fee_amount = $invoice->client->getSetting('late_fee_endless_amount'); $late_fee_percent = $invoice->client->getSetting('late_fee_endless_percent'); - break; + break; default: $late_fee_amount = 0; $late_fee_percent = 0; @@ -276,31 +262,32 @@ class SendReminders implements ShouldQueue } return $this->setLateFee($invoice, $late_fee_amount, $late_fee_percent); - } /** * Applies the late fee to the invoice line items - * - * @param Invoice $invoice + * + * @param Invoice $invoice * @param float $amount The fee amount * @param float $percent The fee percentage amount - * - * @return Invoice + * + * @return Invoice */ private function setLateFee($invoice, $amount, $percent) :Invoice { $temp_invoice_balance = $invoice->balance; - if ($amount <= 0 && $percent <= 0) + if ($amount <= 0 && $percent <= 0) { return $invoice; + } $fee = $amount; - if ($invoice->partial > 0) + if ($invoice->partial > 0) { $fee += round($invoice->partial * $percent / 100, 2); - else + } else { $fee += round($invoice->balance * $percent / 100, 2); + } $invoice_item = new InvoiceItem; $invoice_item->type_id = '5'; @@ -321,7 +308,5 @@ class SendReminders implements ShouldQueue $this->invoice->ledger()->updateInvoiceBalance($this->invoice->balance - $temp_invoice_balance); return $invoice; - } - -} \ No newline at end of file +} diff --git a/app/Jobs/Payment/EmailPayment.php b/app/Jobs/Payment/EmailPayment.php index 5e751b333f79..4bbaafc9f3c5 100644 --- a/app/Jobs/Payment/EmailPayment.php +++ b/app/Jobs/Payment/EmailPayment.php @@ -73,37 +73,29 @@ class EmailPayment extends BaseMailerJob implements ShouldQueue */ public function handle() { - - if($this->company->is_disabled) + if ($this->company->is_disabled) { return true; + } if ($this->contact->email) { - - MultiDB::setDb($this->company->db); + MultiDB::setDb($this->company->db); //if we need to set an email driver do it now $this->setMailDriver(); $email_builder = (new PaymentEmailEngine($this->payment, $this->contact))->build(); - try{ - + try { $mail = Mail::to($this->contact->email, $this->contact->present()->name()); $mail->send(new TemplateEmail($email_builder, $this->contact->user, $this->contact->client)); - - }catch(\Exception $e) { - + } catch (\Exception $e) { info("mailing failed with message " . $e->getMessage()); event(new PaymentWasEmailedAndFailed($this->payment, $this->company, Mail::failures(), Ninja::eventVars())); $this->failed($e); return $this->logMailError($e->getMessage(), $this->payment->client); - } event(new PaymentWasEmailed($this->payment, $this->payment->company, Ninja::eventVars())); - } } - - } diff --git a/app/Jobs/Product/UpdateOrCreateProduct.php b/app/Jobs/Product/UpdateOrCreateProduct.php index 4f7098b34ae8..bb655aa245f2 100644 --- a/app/Jobs/Product/UpdateOrCreateProduct.php +++ b/app/Jobs/Product/UpdateOrCreateProduct.php @@ -60,9 +60,7 @@ class UpdateOrCreateProduct implements ShouldQueue //only update / create products - not tasks or gateway fees $updateable_products = collect($this->products)->filter(function ($item) { - return $item->type_id == 1; - }); foreach ($updateable_products as $item) { @@ -98,6 +96,6 @@ class UpdateOrCreateProduct implements ShouldQueue public function failed($exception = null) { info("update create failed with = "); - info(print_r($exception->getMessage(),1)); + info(print_r($exception->getMessage(), 1)); } } diff --git a/app/Jobs/RecurringInvoice/SendRecurring.php b/app/Jobs/RecurringInvoice/SendRecurring.php index 3df78415c903..30c28d0783be 100644 --- a/app/Jobs/RecurringInvoice/SendRecurring.php +++ b/app/Jobs/RecurringInvoice/SendRecurring.php @@ -67,19 +67,18 @@ class SendRecurring implements ShouldQueue ->createInvitations() ->save(); - info("Invoice {$invoice->number} created"); + info("Invoice {$invoice->number} created"); $invoice->invitations->each(function ($invitation) use ($invoice) { - - if($invitation->contact && strlen($invitation->contact->email) >=1){ + if ($invitation->contact && strlen($invitation->contact->email) >=1) { EmailEntity::dispatch($invitation, $invoice->company); info("Firing email for invoice {$invoice->number}"); } - }); - if($invoice->client->getSetting('auto_bill_date') == 'on_send_date' && $this->recurring_invoice->auto_bill_enabled) + if ($invoice->client->getSetting('auto_bill_date') == 'on_send_date' && $this->recurring_invoice->auto_bill_enabled) { $invoice->service()->autoBill()->save(); + } info("updating recurring invoice dates"); /* Set next date here to prevent a recurring loop forming */ @@ -88,8 +87,9 @@ class SendRecurring implements ShouldQueue $this->recurring_invoice->last_sent_date = date('Y-m-d'); /* Set completed if we don't have any more cycles remaining*/ - if ($this->recurring_invoice->remaining_cycles == 0) + if ($this->recurring_invoice->remaining_cycles == 0) { $this->recurring_invoice->setCompleted(); + } info("next send date = " . $this->recurring_invoice->next_send_date); info("remaining cycles = " . $this->recurring_invoice->remaining_cycles); @@ -100,7 +100,6 @@ class SendRecurring implements ShouldQueue //this is duplicated!! // if ($invoice->invitations->count() > 0) // event(new InvoiceWasEmailed($invoice->invitations->first(), $invoice->company, Ninja::eventVars())); - } public function failed($exception = null) @@ -116,5 +115,4 @@ class SendRecurring implements ShouldQueue info(print_r($exception->getMessage(), 1)); } - } diff --git a/app/Jobs/User/UserEmailChanged.php b/app/Jobs/User/UserEmailChanged.php index fb3a963d84a6..05cbda539ee6 100644 --- a/app/Jobs/User/UserEmailChanged.php +++ b/app/Jobs/User/UserEmailChanged.php @@ -54,8 +54,9 @@ class UserEmailChanged extends BaseMailerJob implements ShouldQueue public function handle() { - if($this->company->is_disabled) + if ($this->company->is_disabled) { return true; + } //Set DB MultiDB::setDb($this->company->db); @@ -74,19 +75,15 @@ class UserEmailChanged extends BaseMailerJob implements ShouldQueue //Send email via a Mailable class // try { - Mail::to($this->old_email) + Mail::to($this->old_email) ->send(new UserNotificationMailer($mail_obj)); - Mail::to($this->new_email) + Mail::to($this->new_email) ->send(new UserNotificationMailer($mail_obj)); - } - catch (\Exception $e) { - + } catch (\Exception $e) { $this->failed($e); $this->logMailError($e->getMessage(), $this->company->owner()); - } - } private function getData() diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index 5e26f3ceb784..197370068703 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -156,7 +156,7 @@ class Import implements ShouldQueue // public $backoff = 86430; - // public $maxExceptions = 2; + // public $maxExceptions = 2; /** * Create a new job instance. * @@ -178,16 +178,15 @@ class Import implements ShouldQueue * * @return bool */ - public function handle() + public function handle() { set_time_limit(0); - // $jsonStream = \JsonMachine\JsonMachine::fromFile($this->file_path, "/data"); + // $jsonStream = \JsonMachine\JsonMachine::fromFile($this->file_path, "/data"); $array = json_decode(file_get_contents($this->file_path), 1); $data = $array['data']; foreach ($this->available_imports as $import) { - if (! array_key_exists($import, $data)) { //throw new ResourceNotAvailableForMigration("Resource {$key} is not available for migration."); info("Resource {$import} is not available for migration."); @@ -210,7 +209,6 @@ class Import implements ShouldQueue CompanySizeCheck::dispatch(); info('Completed🚀🚀🚀🚀🚀 at '.now()); - } private function setInitialCompanyLedgerBalances() @@ -268,15 +266,12 @@ class Import implements ShouldQueue $company_repository = new CompanyRepository(); $company_repository->save($data, $this->company); - if(isset($data['settings']->company_logo) && strlen($data['settings']->company_logo) > 0) { - + if (isset($data['settings']->company_logo) && strlen($data['settings']->company_logo) > 0) { try { $tempImage = tempnam(sys_get_temp_dir(), basename($data['settings']->company_logo)); copy($data['settings']->company_logo, $tempImage); $this->uploadLogo($tempImage, $this->company, $this->company); - } - catch(\Exception $e){ - + } catch (\Exception $e) { } } @@ -596,7 +591,6 @@ class Import implements ShouldQueue $invoice_repository = new InvoiceMigrationRepository(); foreach ($data as $key => $resource) { - $modified = $resource; if (array_key_exists('client_id', $resource) && ! array_key_exists('clients', $this->ids)) { @@ -621,7 +615,6 @@ class Import implements ShouldQueue 'old' => $resource['id'], 'new' => $invoice->id, ]; - } RecurringInvoice::reguard(); @@ -629,7 +622,6 @@ class Import implements ShouldQueue /*Improve memory handling by setting everything to null when we have finished*/ $data = null; $invoice_repository = null; - } private function processInvoices(array $data): void @@ -785,7 +777,6 @@ class Import implements ShouldQueue private function processPayments(array $data): void { - Payment::reguard(); $rules = [ @@ -818,14 +809,12 @@ class Import implements ShouldQueue if (isset($modified['invoices'])) { foreach ($modified['invoices'] as $key => $invoice) { - - if($this->tryTransformingId('invoices', $invoice['invoice_id'])) + if ($this->tryTransformingId('invoices', $invoice['invoice_id'])) { $modified['invoices'][$key]['invoice_id'] = $this->transformId('invoices', $invoice['invoice_id']); - else{ + } else { $modified['credits'][$key]['credit_id'] = $this->transformId('credits', $invoice['invoice_id']); $modified['credits'][$key]['amount'] = $modified['invoices'][$key]['amount']; } - } } @@ -886,12 +875,12 @@ class Import implements ShouldQueue $payment->status_id = Payment::STATUS_PARTIALLY_REFUNDED; $payment->save(); return $payment; - break; + break; case 6: $payment->status_id = Payment::STATUS_REFUNDED; $payment->save(); return $payment; - break; + break; default: return $payment; @@ -901,11 +890,10 @@ class Import implements ShouldQueue private function processDocuments(array $data): void { - // Document::unguard(); + // Document::unguard(); /* No validators since data provided by database is already valid. */ - foreach($data as $resource) - { + foreach ($data as $resource) { $modified = $resource; if (array_key_exists('invoice_id', $resource) && $resource['invoice_id'] && ! array_key_exists('invoices', $this->ids)) { @@ -927,7 +915,6 @@ class Import implements ShouldQueue } $this->saveDocument(file_get_contents($resource['url']), $entity, $is_public = true); - } // foreach ($data as $resource) { @@ -1079,7 +1066,8 @@ class Import implements ShouldQueue } private function processTaskStatuses(array $data) :void - {info('in task statuses'); + { + info('in task statuses'); TaskStatus::unguard(); foreach ($data as $resource) { @@ -1149,17 +1137,21 @@ class Import implements ShouldQueue $modified['company_id'] = $this->company->id; $modified['user_id'] = $this->processUserId($resource); - if(isset($modified['client_id'])) + if (isset($modified['client_id'])) { $modified['client_id'] = $this->transformId('clients', $resource['client_id']); + } - if(isset($modified['invoice_id'])) + if (isset($modified['invoice_id'])) { $modified['invoice_id'] = $this->transformId('invoices', $resource['invoice_id']); + } - if(isset($modified['project_id'])) + if (isset($modified['project_id'])) { $modified['project_id'] = $this->transformId('projects', $resource['project_id']); + } - if(isset($modified['status_id'])) + if (isset($modified['status_id'])) { $modified['status_id'] = $this->transformId('task_statuses', $resource['status_id']); + } $task = Task::Create($modified); @@ -1190,8 +1182,9 @@ class Import implements ShouldQueue $modified['company_id'] = $this->company->id; $modified['user_id'] = $this->processUserId($resource); - if(isset($modified['client_id'])) + if (isset($modified['client_id'])) { $modified['client_id'] = $this->transformId('clients', $resource['client_id']); + } $project = Project::Create($modified); @@ -1201,7 +1194,6 @@ class Import implements ShouldQueue 'old' => $resource['id'], 'new' => $project->id, ]; - } Project::reguard(); @@ -1211,7 +1203,6 @@ class Import implements ShouldQueue private function processExpenses(array $data) :void { - Expense::unguard(); foreach ($data as $resource) { @@ -1222,20 +1213,25 @@ class Import implements ShouldQueue $modified['company_id'] = $this->company->id; $modified['user_id'] = $this->processUserId($resource); - if(isset($resource['client_id'])) + if (isset($resource['client_id'])) { $modified['client_id'] = $this->transformId('clients', $resource['client_id']); + } - if(isset($resource['category_id'])) + if (isset($resource['category_id'])) { $modified['category_id'] = $this->transformId('expense_categories', $resource['category_id']); + } - if(isset($resource['invoice_id'])) + if (isset($resource['invoice_id'])) { $modified['invoice_id'] = $this->transformId('invoices', $resource['invoice_id']); + } - if(isset($resource['project_id'])) + if (isset($resource['project_id'])) { $modified['project_id'] = $this->transformId('projects', $resource['project_id']); + } - if(isset($resource['vendor_id'])) + if (isset($resource['vendor_id'])) { $modified['vendor_id'] = $this->transformId('vendors', $resource['vendor_id']); + } $expense = Expense::Create($modified); @@ -1252,7 +1248,6 @@ class Import implements ShouldQueue Expense::reguard(); $data = null; - } /** * |-------------------------------------------------------------------------- @@ -1289,7 +1284,7 @@ class Import implements ShouldQueue public function transformId($resource, string $old): int { if (! array_key_exists($resource, $this->ids)) { - info(print_r($resource,1)); + info(print_r($resource, 1)); throw new Exception("Resource {$resource} not available."); } @@ -1345,7 +1340,5 @@ class Import implements ShouldQueue ->batch(); info(print_r($exception->getMessage(), 1)); - } - } diff --git a/app/Jobs/Util/ReminderJob.php b/app/Jobs/Util/ReminderJob.php index 4ad02907e345..2cbc6251e050 100644 --- a/app/Jobs/Util/ReminderJob.php +++ b/app/Jobs/Util/ReminderJob.php @@ -55,37 +55,27 @@ class ReminderJob implements ShouldQueue $this->processReminders($db); } } - } private function processReminders($db = null) { - Invoice::where('next_send_date', Carbon::today()->format('Y-m-d'))->with('invitations')->cursor()->each(function ($invoice) { - if ($invoice->isPayable()) { - - $reminder_template = $invoice->calculateTemplate('invoice'); + $reminder_template = $invoice->calculateTemplate('invoice'); $invoice->service()->touchReminder($this->reminder_template)->save(); $invoice->invitations->each(function ($invitation) use ($invoice, $reminder_template) { - EmailEntity::dispatch($invitation, $invitation->company, $reminder_template); info("Firing email for invoice {$invoice->number}"); }); - if ($invoice->invitations->count() > 0) + if ($invoice->invitations->count() > 0) { event(new InvoiceWasEmailed($invoice->invitations->first(), $invoice->company, Ninja::eventVars())); - - + } } else { - $invoice->next_send_date = null; $invoice->save(); - } - }); - } } diff --git a/app/Jobs/Util/SendFailedEmails.php b/app/Jobs/Util/SendFailedEmails.php index 19281c19a1e7..2882c11c0a19 100644 --- a/app/Jobs/Util/SendFailedEmails.php +++ b/app/Jobs/Util/SendFailedEmails.php @@ -55,7 +55,6 @@ class SendFailedEmails implements ShouldQueue private function processEmails() { - $email_jobs = SystemLog::where('event_id', SystemLog::EVENT_MAIL_RETRY_QUEUE)->get(); $email_jobs->each(function ($job) { @@ -64,7 +63,6 @@ class SendFailedEmails implements ShouldQueue $invitation = $job_meta_array['entity_name']::where('key', $job_meta_array['invitation_key'])->with('contact')->first(); if ($invitation->invoice) { - if ($invitation->contact->send_email && $invitation->contact->email) { EmailEntity::dispatch($invitation, $invitation->company, $job_meta_array['reminder_template']); } diff --git a/app/Jobs/Util/StartMigration.php b/app/Jobs/Util/StartMigration.php index e782549ae958..78eabfe608da 100644 --- a/app/Jobs/Util/StartMigration.php +++ b/app/Jobs/Util/StartMigration.php @@ -55,7 +55,7 @@ class StartMigration implements ShouldQueue public $timeout = 0; - // public $maxExceptions = 2; + // public $maxExceptions = 2; //public $backoff = 86430; @@ -111,7 +111,6 @@ class StartMigration implements ShouldQueue //Import::dispatchNow($data['data'], $this->company, $this->user); Import::dispatchNow($file, $this->company, $this->user); } catch (NonExistingMigrationFile | ProcessingMigrationArchiveFailed | ResourceNotAvailableForMigration | MigrationValidatorFailed | ResourceDependencyMissing $e) { - Mail::to($this->user)->send(new MigrationFailed($e, $e->getMessage())); if (app()->environment() !== 'production') { @@ -126,6 +125,6 @@ class StartMigration implements ShouldQueue public function failed($exception = null) { - info(print_r($exception->getMessage(),1)); + info(print_r($exception->getMessage(), 1)); } } diff --git a/app/Jobs/Util/WebhookHandler.php b/app/Jobs/Util/WebhookHandler.php index 11ec72cff38e..44abb02574b2 100644 --- a/app/Jobs/Util/WebhookHandler.php +++ b/app/Jobs/Util/WebhookHandler.php @@ -63,21 +63,22 @@ class WebhookHandler implements ShouldQueue MultiDB::setDb($this->company->db); - if (! $this->company || $this->company->is_disabled) + if (! $this->company || $this->company->is_disabled) { return true; + } $subscriptions = Webhook::where('company_id', $this->company->id) ->where('event_id', $this->event_id) ->get(); - if (! $subscriptions || $subscriptions->count() == 0) + if (! $subscriptions || $subscriptions->count() == 0) { return; + } $subscriptions->each(function ($subscription) { $this->process($subscription); }); - } private function process($subscription) diff --git a/app/Listeners/Invoice/InvoiceEmailedNotification.php b/app/Listeners/Invoice/InvoiceEmailedNotification.php index 95dec6fe1c2d..f1197397d2da 100644 --- a/app/Listeners/Invoice/InvoiceEmailedNotification.php +++ b/app/Listeners/Invoice/InvoiceEmailedNotification.php @@ -62,7 +62,6 @@ class InvoiceEmailedNotification implements ShouldQueue EntitySentMailer::dispatch($event->invitation, 'invoice', $user, $event->invitation->company); $first_notification_sent = false; - } $notification->method = $methods; diff --git a/app/Listeners/Invoice/InvoicePaidActivity.php b/app/Listeners/Invoice/InvoicePaidActivity.php index c90bf32afbb5..415dc13978bc 100644 --- a/app/Listeners/Invoice/InvoicePaidActivity.php +++ b/app/Listeners/Invoice/InvoicePaidActivity.php @@ -57,9 +57,8 @@ class InvoicePaidActivity implements ShouldQueue try { $event->invoice->service()->touchPdf(); - } - catch(\Exception $e){ - info(print_r($e->getMessage(),1)); + } catch (\Exception $e) { + info(print_r($e->getMessage(), 1)); } } } diff --git a/app/Listeners/Payment/PaymentEmailFailureActivity.php b/app/Listeners/Payment/PaymentEmailFailureActivity.php index 78920d20da35..c4a7c628de74 100644 --- a/app/Listeners/Payment/PaymentEmailFailureActivity.php +++ b/app/Listeners/Payment/PaymentEmailFailureActivity.php @@ -50,8 +50,6 @@ class PaymentEmailFailureActivity implements ShouldQueue $payment = $event->payment; info("i failed emailing {$payment->number}"); - // info(print_r($event->errors,1)); - + // info(print_r($event->errors,1)); } } - diff --git a/app/Listeners/Payment/PaymentEmailedActivity.php b/app/Listeners/Payment/PaymentEmailedActivity.php index 60bc6e8785e1..938296fb04d4 100644 --- a/app/Listeners/Payment/PaymentEmailedActivity.php +++ b/app/Listeners/Payment/PaymentEmailedActivity.php @@ -52,4 +52,3 @@ class PaymentEmailedActivity implements ShouldQueue info("i succeeded in emailing payment {$payment->number}"); } } - diff --git a/app/Listeners/Payment/PaymentNotification.php b/app/Listeners/Payment/PaymentNotification.php index 07f194170169..854357ec9650 100644 --- a/app/Listeners/Payment/PaymentNotification.php +++ b/app/Listeners/Payment/PaymentNotification.php @@ -55,7 +55,6 @@ class PaymentNotification implements ShouldQueue /*User notifications*/ foreach ($payment->company->company_users as $company_user) { - $user = $company_user->user; $methods = $this->findUserEntityNotificationType($payment, $company_user, ['all_notifications']); @@ -64,7 +63,6 @@ class PaymentNotification implements ShouldQueue unset($methods[$key]); EntityPaidMailer::dispatch($payment, $payment->company, $user); - } $notification = new NewPaymentNotification($payment, $payment->company); diff --git a/app/Listeners/SendVerificationNotification.php b/app/Listeners/SendVerificationNotification.php index 2c1eb8a4f983..9e6457079d23 100644 --- a/app/Listeners/SendVerificationNotification.php +++ b/app/Listeners/SendVerificationNotification.php @@ -51,11 +51,8 @@ class SendVerificationNotification implements ShouldQueue $event->user->notify(new VerifyUser($event->user, $event->company)); Ninja::registerNinjaUser($event->user); - } catch (Exception $e) { - info("I couldn't send the email " . $e->getMessage()); - } } } diff --git a/app/Mail/DownloadInvoices.php b/app/Mail/DownloadInvoices.php index 21c8a4990085..6d07768ae419 100644 --- a/app/Mail/DownloadInvoices.php +++ b/app/Mail/DownloadInvoices.php @@ -40,6 +40,5 @@ class DownloadInvoices extends Mailable 'logo' => $this->company->present()->logo, ] ); - } } diff --git a/app/Mail/Engine/BaseEmailEngine.php b/app/Mail/Engine/BaseEmailEngine.php index 4b41dd965266..37c13c1f263b 100644 --- a/app/Mail/Engine/BaseEmailEngine.php +++ b/app/Mail/Engine/BaseEmailEngine.php @@ -13,129 +13,132 @@ namespace App\Mail\Engine; class BaseEmailEngine implements EngineInterface { - public $footer; + public $footer; - public $variables; + public $variables; - public $contact; + public $contact; - public $subject; + public $subject; - public $body; + public $body; - public $template_style; + public $template_style; - public $attachments; + public $attachments; - public $link; + public $link; - public $text; + public $text; public function setFooter($footer) { - $this->footer = $footer; + $this->footer = $footer; - return $this; + return $this; } public function setVariables($variables) { - $this->variables = $variables; + $this->variables = $variables; - return $this; + return $this; } public function setContact($contact) { - $this->contact = $contact; + $this->contact = $contact; - return $this; + return $this; } public function setSubject($subject) { - if (! empty($this->variables)) + if (! empty($this->variables)) { $subject = str_replace(array_keys($this->variables), array_values($this->variables), $subject); + } - $this->subject = $subject; + $this->subject = $subject; - return $this; + return $this; } public function setBody($body) { - if (! empty($this->variables)) + if (! empty($this->variables)) { $body = str_replace(array_keys($this->variables), array_values($this->variables), $body); + } - $this->body = $body; + $this->body = $body; - return $this; + return $this; } public function setTemplate($template_style) { - $this->template_style = $template_style; + $this->template_style = $template_style; - return $this; + return $this; } public function setAttachments($attachments) { - $this->attachments = $attachments; + $this->attachments = $attachments; - return $this; + return $this; } public function setViewLink($link) { - $this->link = $link; + $this->link = $link; - return $this; + return $this; } public function setViewText($text) { - $this->text = $text; + $this->text = $text; - return $this; + return $this; } public function getSubject() { - return $this->subject; + return $this->subject; } public function getBody() { - return $this->body; + return $this->body; } public function getAttachments() { - return $this->attachments; + return $this->attachments; } public function getFooter() { - return $this->footer; + return $this->footer; } public function getTemplate() { - return $this->template_style; + return $this->template_style; } public function getViewLink() { - return $this->link; + return $this->link; } public function getViewText() { - return $this->text; + return $this->text; } - public function build(){} - -} \ No newline at end of file + public function build() + { + } +} diff --git a/app/Mail/Engine/CreditEmailEngine.php b/app/Mail/Engine/CreditEmailEngine.php index 7529767001eb..7cbcbc0ec44b 100644 --- a/app/Mail/Engine/CreditEmailEngine.php +++ b/app/Mail/Engine/CreditEmailEngine.php @@ -14,15 +14,15 @@ namespace App\Mail\Engine; use App\Utils\HtmlEngine; use App\Utils\Number; -class CreditEmailEngine extends BaseEmailEngine +class CreditEmailEngine extends BaseEmailEngine { - public $invitation; + public $invitation; - public $client; + public $client; - public $credit; + public $credit; - public $contact; + public $contact; public $reminder_template; @@ -30,7 +30,7 @@ class CreditEmailEngine extends BaseEmailEngine public function __construct($invitation, $reminder_template, $template_data) { - $this->invitation = $invitation; + $this->invitation = $invitation; $this->reminder_template = $reminder_template; $this->client = $invitation->contact->client; $this->credit = $invitation->credit; @@ -40,11 +40,11 @@ class CreditEmailEngine extends BaseEmailEngine public function build() { - - if(is_array($this->template_data) && array_key_exists('body', $this->template_data) && strlen($this->template_data['body']) > 0) + if (is_array($this->template_data) && array_key_exists('body', $this->template_data) && strlen($this->template_data['body']) > 0) { $body_template = $this->template_data['body']; - else + } else { $body_template = $this->client->getSetting('email_template_'.$this->reminder_template); + } /* Use default translations if a custom message has not been set*/ if (iconv_strlen($body_template) == 0) { @@ -60,13 +60,13 @@ class CreditEmailEngine extends BaseEmailEngine ); } - if(is_array($this->template_data) && array_key_exists('subject', $this->template_data) && strlen($this->template_data['subject']) > 0) + if (is_array($this->template_data) && array_key_exists('subject', $this->template_data) && strlen($this->template_data['subject']) > 0) { $subject_template = $this->template_data['subject']; - else + } else { $subject_template = $this->client->getSetting('email_subject_'.$this->reminder_template); + } if (iconv_strlen($subject_template) == 0) { - $subject_template = trans( 'texts.credit_subject', [ @@ -76,7 +76,6 @@ class CreditEmailEngine extends BaseEmailEngine null, $this->client->locale() ); - } $this->setTemplate($this->client->getSetting('email_style')) @@ -93,8 +92,5 @@ class CreditEmailEngine extends BaseEmailEngine } return $this; - } - } - diff --git a/app/Mail/Engine/EngineInterface.php b/app/Mail/Engine/EngineInterface.php index 9196b1a1619a..8518ffe8b535 100644 --- a/app/Mail/Engine/EngineInterface.php +++ b/app/Mail/Engine/EngineInterface.php @@ -13,7 +13,6 @@ namespace App\Mail\Engine; interface EngineInterface { - public function setFooter($footer); public function setVariables($variables); @@ -47,5 +46,4 @@ interface EngineInterface public function getViewText(); public function build(); - -} \ No newline at end of file +} diff --git a/app/Mail/Engine/InvoiceEmailEngine.php b/app/Mail/Engine/InvoiceEmailEngine.php index 3a455925f846..af72ac485fe9 100644 --- a/app/Mail/Engine/InvoiceEmailEngine.php +++ b/app/Mail/Engine/InvoiceEmailEngine.php @@ -15,15 +15,15 @@ use App\DataMapper\EmailTemplateDefaults; use App\Utils\HtmlEngine; use App\Utils\Number; -class InvoiceEmailEngine extends BaseEmailEngine +class InvoiceEmailEngine extends BaseEmailEngine { - public $invitation; + public $invitation; - public $client; + public $client; - public $invoice; + public $invoice; - public $contact; + public $contact; public $reminder_template; @@ -31,7 +31,7 @@ class InvoiceEmailEngine extends BaseEmailEngine public function __construct($invitation, $reminder_template, $template_data) { - $this->invitation = $invitation; + $this->invitation = $invitation; $this->reminder_template = $reminder_template; $this->client = $invitation->contact->client; $this->invoice = $invitation->invoice; @@ -41,12 +41,11 @@ class InvoiceEmailEngine extends BaseEmailEngine public function build() { - - if(is_array($this->template_data) && array_key_exists('body', $this->template_data) && strlen($this->template_data['body']) > 0) + if (is_array($this->template_data) && array_key_exists('body', $this->template_data) && strlen($this->template_data['body']) > 0) { $body_template = $this->template_data['body']; - elseif(strlen($this->client->getSetting('email_template_'.$this->reminder_template)) > 0) + } elseif (strlen($this->client->getSetting('email_template_'.$this->reminder_template)) > 0) { $body_template = $this->client->getSetting('email_template_'.$this->reminder_template); - else{ + } else { $body_template = EmailTemplateDefaults::getDefaultTemplate('email_template_'.$this->reminder_template, $this->client->locale()); } @@ -64,22 +63,19 @@ class InvoiceEmailEngine extends BaseEmailEngine ); } - if(is_array($this->template_data) && array_key_exists('subject', $this->template_data) && strlen($this->template_data['subject']) > 0){ + if (is_array($this->template_data) && array_key_exists('subject', $this->template_data) && strlen($this->template_data['subject']) > 0) { $subject_template = $this->template_data['subject']; info("subject = template data"); - } - elseif(strlen($this->client->getSetting('email_subject_'.$this->reminder_template)) > 0){ + } elseif (strlen($this->client->getSetting('email_subject_'.$this->reminder_template)) > 0) { $subject_template = $this->client->getSetting('email_subject_'.$this->reminder_template); info("subject = settings var"); - } - else{ + } else { info("subject = default template " . 'email_subject_'.$this->reminder_template); $subject_template = EmailTemplateDefaults::getDefaultTemplate('email_subject_'.$this->reminder_template, $this->client->locale()); - // $subject_template = $this->client->getSetting('email_subject_'.$this->reminder_template); + // $subject_template = $this->client->getSetting('email_subject_'.$this->reminder_template); } if (iconv_strlen($subject_template) == 0) { - $subject_template = trans( 'texts.invoice_subject', [ @@ -89,7 +85,6 @@ class InvoiceEmailEngine extends BaseEmailEngine null, $this->client->locale() ); - } $this->setTemplate($this->client->getSetting('email_style')) @@ -106,8 +101,5 @@ class InvoiceEmailEngine extends BaseEmailEngine } return $this; - } - } - diff --git a/app/Mail/Engine/PaymentEmailEngine.php b/app/Mail/Engine/PaymentEmailEngine.php index 48724998d6bd..c0662f9f7855 100644 --- a/app/Mail/Engine/PaymentEmailEngine.php +++ b/app/Mail/Engine/PaymentEmailEngine.php @@ -16,13 +16,13 @@ use App\Utils\HtmlEngine; use App\Utils\Number; use App\Utils\Traits\MakesDates; -class PaymentEmailEngine extends BaseEmailEngine +class PaymentEmailEngine extends BaseEmailEngine { use MakesDates; - public $client; + public $client; - public $payment; + public $payment; public $template_data; @@ -44,12 +44,11 @@ class PaymentEmailEngine extends BaseEmailEngine public function build() { - - if(is_array($this->template_data) && array_key_exists('body', $this->template_data) && strlen($this->template_data['body']) > 0) + if (is_array($this->template_data) && array_key_exists('body', $this->template_data) && strlen($this->template_data['body']) > 0) { $body_template = $this->template_data['body']; - elseif(strlen($this->client->getSetting('email_template_payment')) > 0) + } elseif (strlen($this->client->getSetting('email_template_payment')) > 0) { $body_template = $this->client->getSetting('email_template_payment'); - else{ + } else { $body_template = EmailTemplateDefaults::getDefaultTemplate('email_template_payment', $this->client->locale()); } @@ -63,13 +62,11 @@ class PaymentEmailEngine extends BaseEmailEngine ); } - if(is_array($this->template_data) && array_key_exists('subject', $this->template_data) && strlen($this->template_data['subject']) > 0){ + if (is_array($this->template_data) && array_key_exists('subject', $this->template_data) && strlen($this->template_data['subject']) > 0) { $subject_template = $this->template_data['subject']; - } - elseif(strlen($this->client->getSetting('email_subject_payment')) > 0){ + } elseif (strlen($this->client->getSetting('email_subject_payment')) > 0) { $subject_template = $this->client->getSetting('email_subject_payment'); - } - else{ + } else { $subject_template = EmailTemplateDefaults::getDefaultTemplate('email_subject_payment', $this->client->locale()); } @@ -92,7 +89,6 @@ class PaymentEmailEngine extends BaseEmailEngine ->setViewText(''); return $this; - } @@ -115,7 +111,7 @@ class PaymentEmailEngine extends BaseEmailEngine $data['$payment2'] = ['value' => $this->formatCustomFieldValue('payment2', $this->payment->custom_value2) ?: ' ', 'label' => $this->makeCustomField('payment2')]; $data['$payment3'] = ['value' => $this->formatCustomFieldValue('payment3', $this->payment->custom_value3) ?: ' ', 'label' => $this->makeCustomField('payment3')]; $data['$payment4'] = ['value' => $this->formatCustomFieldValue('payment4', $this->payment->custom_value4) ?: ' ', 'label' => $this->makeCustomField('payment4')]; - // $data['$type'] = ['value' => $this->payment->type->name ?: '', 'label' => ctrans('texts.payment_type')]; + // $data['$type'] = ['value' => $this->payment->type->name ?: '', 'label' => ctrans('texts.payment_type')]; $data['$client1'] = ['value' => $this->formatCustomFieldValue('client1', $this->client->custom_value1) ?: ' ', 'label' => $this->makeCustomField('client1')]; $data['$client2'] = ['value' => $this->formatCustomFieldValue('client2', $this->client->custom_value2) ?: ' ', 'label' => $this->makeCustomField('client2')]; @@ -200,8 +196,7 @@ class PaymentEmailEngine extends BaseEmailEngine { $invoice_list = ''; - foreach($this->payment->invoices as $invoice) - { + foreach ($this->payment->invoices as $invoice) { $invoice_list .= ctrans('texts.invoice_number_short') . " {$invoice->number} - " . Number::formatMoney($invoice->pivot->amount, $this->client) . "