Merge pull request #7802 from turbo124/v5-develop

Fixes for tech template
This commit is contained in:
David Bomba 2022-09-05 12:49:04 +10:00 committed by GitHub
commit 0b37f42db8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 112 additions and 16 deletions

View File

@ -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}");
}
});
}
}

View File

@ -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) {

View File

@ -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);
}

View File

@ -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');
}

View File

@ -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();
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
\Illuminate\Support\Facades\Artisan::call('ninja:design-update');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
};

View File

@ -325,12 +325,12 @@
<div class="hero-section">
<div class="hero-contact-section">
<div class="client-details">
<span class="client-details-to-label">$from_label:</span>
<span class="client-details-to-label">$to_label:</span>
<div id="client-details"></div>
<div id="vendor-details"></div>
</div>
<div class="company-details">
<span class="client-details-to-label">$to_label:</span>
<span class="client-details-to-label">$from_label:</span>
<div class="company-details-wrapper">
<div id="company-details"></div>
<div id="company-address"></div>

View File

@ -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']);
});