diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index f7af10905986..57dbed634c15 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -76,7 +76,7 @@ class CheckData extends Command /** * @var string */ - protected $signature = 'ninja:check-data {--database=} {--fix=} {--client_id=} {--vendor_id=} {--paid_to_date=} {--client_balance=} {--ledger_balance=} {--balance_status=}'; + protected $signature = 'ninja:check-data {--database=} {--fix=} {--portal_url=} {--client_id=} {--vendor_id=} {--paid_to_date=} {--client_balance=} {--ledger_balance=} {--balance_status=}'; /** * @var string @@ -118,8 +118,10 @@ class CheckData extends Command $this->checkDuplicateRecurringInvoices(); $this->checkOauthSanity(); - if(Ninja::isHosted()) + if(Ninja::isHosted()){ $this->checkAccountStatuses(); + $this->checkNinjaPortalUrls(); + } if (! $this->option('client_id')) { $this->checkOAuth(); @@ -1003,4 +1005,31 @@ class CheckData extends Command $this->logMessage($this->wrong_paid_status." wrong invoices with bad balance state"); } + + public function checkNinjaPortalUrls() + { + + $wrong_count = CompanyUser::where('is_owner',1)->where('ninja_portal_url', '')->count(); + + $this->logMessage("Missing ninja portal Urls = {$wrong_count}"); + + if(!$this->option('portal_url')) + return; + + CompanyUser::where('is_owner',1)->where('ninja_portal_url', '')->cursor()->each(function ($cu){ + + $cc = ClientContact::on('db-ninja-01')->where('company_id', config('ninja.ninja_default_company_id'))->where('email', $cu->user->email)->first(); + + if($cc){ + $ninja_portal_url = "https://invoiceninja.invoicing.co/client/ninja/{$cc->contact_key}/{$cu->company->company_key}"; + + $cu->ninja_portal_url = $ninja_portal_url; + $cu->save(); + + $this->logMessage("Fixing - {$ninja_portal_url}"); + } + + }); + + } } \ No newline at end of file diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index ea6b7d56f0de..b85683a4a8e8 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -773,7 +773,8 @@ class BaseController extends Controller // 10-01-2022 need to ensure we snake case properly here to ensure permissions work as expected // 28-03-2022 this is definitely correct here, do not append _ to the view, it resolved correctly when snake cased if (auth()->user() && ! auth()->user()->hasPermission('view'.lcfirst(class_basename(Str::snake($this->entity_type))))) { - $query->where('user_id', '=', auth()->user()->id); + //03-09-2022 + $query->where('user_id', '=', auth()->user()->id)->orWhere('assigned_user_id', auth()->user()->id); } if (request()->has('updated_at') && request()->input('updated_at') > 0) { diff --git a/app/Http/Controllers/EmailController.php b/app/Http/Controllers/EmailController.php index 73b25465ce13..f752c6174e4b 100644 --- a/app/Http/Controllers/EmailController.php +++ b/app/Http/Controllers/EmailController.php @@ -131,7 +131,7 @@ class EmailController extends BaseController if(Ninja::isHosted() && !$entity_obj->company->account->account_sms_verified) return response(['message' => 'Please verify your account to send emails.'], 400); - if($entity == 'purchaseOrder' || $template == 'purchase_order'){ + if($entity == 'purchaseOrder' || $entity == 'purchase_order' || $template == 'purchase_order'){ return $this->sendPurchaseOrder($entity_obj, $data); } diff --git a/app/Mail/SupportMessageSent.php b/app/Mail/SupportMessageSent.php index 9d91ba9fd06d..5278d495cf84 100644 --- a/app/Mail/SupportMessageSent.php +++ b/app/Mail/SupportMessageSent.php @@ -70,8 +70,13 @@ class SupportMessageSent extends Mailable $trial = $account->isTrial() ? 'T' : ''; $plan = str_replace('_', ' ', $plan); + $plan_status = ''; + + if(Carbon::parse($account->plan_expires)->lt(now())) + $plan_status = 'Plan Expired'; + if (Ninja::isHosted()) { - $subject = "{$priority}Hosted-{$db}-{$is_large}{$platform}{$migrated}{$trial} :: {$plan} :: ".date('M jS, g:ia'); + $subject = "{$priority}Hosted-{$db}-{$is_large}{$platform}{$migrated}{$trial} :: {$plan} :: {$plan_status} ".date('M jS, g:ia'); } else { $subject = "{$priority}Self Hosted :: {$plan} :: {$is_large}{$platform}{$migrated} :: ".date('M jS, g:ia'); } diff --git a/app/Repositories/PaymentRepository.php b/app/Repositories/PaymentRepository.php index 84a77c49580b..85b296026d58 100644 --- a/app/Repositories/PaymentRepository.php +++ b/app/Repositories/PaymentRepository.php @@ -84,23 +84,23 @@ class PaymentRepository extends BaseRepository { $data['amount'] = array_sum(array_column($data['invoices'], 'amount')); } - // $client->service()->updatePaidToDate($data['amount'])->save(); - $client->paid_to_date += $data['amount']; + $client->service()->updatePaidToDate($data['amount'])->save(); + // $client->paid_to_date += $data['amount']; $client->save(); } else{ //this fixes an edge case with unapplied payments - // $client->service()->updatePaidToDate($data['amount'])->save(); - $client->paid_to_date += $data['amount']; + $client->service()->updatePaidToDate($data['amount'])->save(); + // $client->paid_to_date += $data['amount']; $client->save(); } if (array_key_exists('credits', $data) && is_array($data['credits']) && count($data['credits']) > 0) { $_credit_totals = array_sum(array_column($data['credits'], 'amount')); - // $client->service()->updatePaidToDate($_credit_totals)->save(); - $client->paid_to_date += $_credit_totals; + $client->service()->updatePaidToDate($_credit_totals)->save(); + // $client->paid_to_date += $_credit_totals; $client->save(); } diff --git a/app/Services/Client/ClientService.php b/app/Services/Client/ClientService.php index a5dd781f7d51..9fef778216c6 100644 --- a/app/Services/Client/ClientService.php +++ b/app/Services/Client/ClientService.php @@ -28,14 +28,46 @@ class ClientService public function updateBalance(float $amount) { - $this->client->balance += $amount; + // $this->client->balance += $amount; + + \DB::connection(config('database.default'))->transaction(function () use($amount) { + + $this->client = Client::where('id', $this->client->id)->lockForUpdate()->first(); + $this->client->balance += $amount; + $this->client->save(); + + }, 2); + + return $this; + } + + public function updateBalanceAndPaidToDate(float $balance, float $paid_to_date) + { + // $this->client->balance += $amount; + + \DB::connection(config('database.default'))->transaction(function () use($amount) { + + $this->client = Client::where('id', $this->client->id)->lockForUpdate()->first(); + $this->client->balance += $balance; + $this->client->paid_to_date += $paid_to_date; + $this->client->save(); + + }, 2); return $this; } public function updatePaidToDate(float $amount) { - $this->client->paid_to_date += $amount; + // $this->client->paid_to_date += $amount; + + \DB::connection(config('database.default'))->transaction(function () use($amount) { + + $this->client = Client::where('id', $this->client->id)->lockForUpdate()->first(); + $this->client->paid_to_date += $amount; + $this->client->save(); + + }, 2); return $this; } diff --git a/app/Utils/TemplateEngine.php b/app/Utils/TemplateEngine.php index 8eb0db321a22..ec6f9c75d78f 100644 --- a/app/Utils/TemplateEngine.php +++ b/app/Utils/TemplateEngine.php @@ -107,7 +107,7 @@ class TemplateEngine private function setSettingsObject() { - if($this->entity == 'purchaseOrder'){ + if($this->entity == 'purchaseOrder' || $this->entity == 'purchase_order'){ $this->settings_entity = auth()->user()->company(); $this->settings = $this->settings_entity->settings; } diff --git a/database/migrations/2022_09_05_024719_update_designs_for_tech_template.php b/database/migrations/2022_09_05_024719_update_designs_for_tech_template.php new file mode 100644 index 000000000000..f0f45d4a4bb2 --- /dev/null +++ b/database/migrations/2022_09_05_024719_update_designs_for_tech_template.php @@ -0,0 +1,28 @@ +
- $from_label: + $to_label:
- $to_label: + $from_label:
diff --git a/routes/vendor.php b/routes/vendor.php index b44e1b10c491..31d572bc7842 100644 --- a/routes/vendor.php +++ b/routes/vendor.php @@ -46,6 +46,7 @@ Route::group(['middleware' => ['auth:vendor', 'vendor_locale', 'domain_db'], 'pr Route::post('documents/download_multiple', [App\Http\Controllers\VendorPortal\DocumentController::class, 'downloadMultiple'])->name('documents.download_multiple'); Route::get('documents/{document}/download', [App\Http\Controllers\VendorPortal\DocumentController::class, 'download'])->name('documents.download'); + Route::get('documents/{document}/download_pdf', [App\Http\Controllers\VendorPortal\DocumentController::class, 'download'])->name('documents.download_pdf'); Route::resource('documents', App\Http\Controllers\VendorPortal\DocumentController::class)->only(['index', 'show']); });