diff --git a/app/Console/Commands/DesignUpdate.php b/app/Console/Commands/DesignUpdate.php
index c0d1ac8c5a4a..a5de9a59eaa4 100644
--- a/app/Console/Commands/DesignUpdate.php
+++ b/app/Console/Commands/DesignUpdate.php
@@ -49,19 +49,26 @@ class DesignUpdate extends Command
*/
public function handle()
{
+ //always return state to first DB
+ $current_db = config('database.default');
if (! config('ninja.db.multi_db_enabled')) {
$this->handleOnDb();
} else {
+
//multiDB environment, need to
foreach (MultiDB::$dbs as $db) {
MultiDB::setDB($db);
$this->handleOnDb($db);
}
+
+ MultiDB::setDB($current_db);
+
}
+
}
private function handleOnDb()
diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php
index 9e08392db093..fe3b7144a1f3 100644
--- a/app/Http/Controllers/Auth/LoginController.php
+++ b/app/Http/Controllers/Auth/LoginController.php
@@ -289,7 +289,7 @@ class LoginController extends BaseController
$client = new Google_Client();
$client->setClientId(config('ninja.auth.google.client_id'));
$client->setClientSecret(config('ninja.auth.google.client_secret'));
-
+ $client->setRedirectUri(config('ninja.app_url'));
$token = $client->authenticate(request()->input('server_auth_code'));
$refresh_token = '';
diff --git a/app/Jobs/Ninja/CheckCompanyData.php b/app/Jobs/Ninja/CheckCompanyData.php
index 35bf20201016..27912c84eb21 100644
--- a/app/Jobs/Ninja/CheckCompanyData.php
+++ b/app/Jobs/Ninja/CheckCompanyData.php
@@ -25,6 +25,7 @@ use Illuminate\Queue\Middleware\RateLimited;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\DB;
use Turbo124\Beacon\Jobs\Database\MySQL\DbStatus;
+use Illuminate\Support\Facades\Cache;
class CheckCompanyData implements ShouldQueue
{
@@ -36,6 +37,7 @@ class CheckCompanyData implements ShouldQueue
public $company_data = [];
+ public $is_valid;
/**
* Create a new job instance.
*
@@ -54,6 +56,7 @@ class CheckCompanyData implements ShouldQueue
*/
public function handle()
{
+ $this->is_valid = true;
$this->checkInvoiceBalances();
$this->checkInvoicePayments();
@@ -68,15 +71,14 @@ class CheckCompanyData implements ShouldQueue
else
$cache_instance = Cache::add($this->hash, '');
- $cache_instance[$this->company->company_hash] = $this->company_data;
+ $this->company_data['company_hash'] = $this->company->company_hash;
Cache::put($this->hash, $cache_instance, now()->addMinutes(30));
nlog(Cache::get($this->hash));
-
nlog($this->company_data);
- if(!$this->isValid)
+ if(!$this->is_valid)
$this->company_data['status'] = 'errors';
else
$this->company_data['status'] = 'success';
@@ -109,13 +111,13 @@ class CheckCompanyData implements ShouldQueue
$wrong_balances++;
- $this->company_data[] = "# {$client->id} " . $client->present()->name.' - '.$client->number." - Balance Failure - Invoice Balances = {$invoice_balance} Client Balance = {$client->balance} Ledger Balance = {$ledger->balance} \n";
+ $this->company_data[] = "# {$client->id} " . $client->present()->name.' - '.$client->number." - Balance Failure - Invoice Balances = {$invoice_balance} Client Balance = {$client->balance} Ledger Balance = {$ledger->balance} ";
- $this->isValid = false;
+ $this->is_valid = false;
}
}
- $this->company_data[] = "{$wrong_balances} clients with incorrect balances\n";
+ $this->company_data[] = "{$wrong_balances} clients with incorrect balances";
}
private function checkInvoicePayments()
@@ -135,14 +137,14 @@ class CheckCompanyData implements ShouldQueue
if ((string)$total_paid != (string)($invoice->amount - $invoice->balance - $total_credit)) {
$wrong_balances++;
- $this->company_data[] = $client->present()->name.' - '.$client->id." - Total Amount = {$total_amount} != Calculated Total = {$calculated_paid_amount} - Total Refund = {$total_refund} Total credit = {$total_credit}\n";
+ $this->company_data[] = $client->present()->name.' - '.$client->id." - Total Amount = {$total_amount} != Calculated Total = {$calculated_paid_amount} - Total Refund = {$total_refund} Total credit = {$total_credit}";
- $this->isValid = false;
+ $this->is_valid = false;
}
});
});
- $this->company_data[] = "{$wrong_balances} clients with incorrect invoice balances\n";
+ $this->company_data[] = "{$wrong_balances} clients with incorrect invoice balances";
}
private function checkPaidToDates()
@@ -176,9 +178,9 @@ class CheckCompanyData implements ShouldQueue
if (round($total_invoice_payments, 2) != round($client->paid_to_date, 2)) {
$wrong_paid_to_dates++;
- $this->company_data[] = $client->present()->name.'id = # '.$client->id." - Paid to date does not match Client Paid To Date = {$client->paid_to_date} - Invoice Payments = {$total_invoice_payments}\n";
+ $this->company_data[] = $client->present()->name.'id = # '.$client->id." - Paid to date does not match Client Paid To Date = {$client->paid_to_date} - Invoice Payments = {$total_invoice_payments}";
- $this->isValid = false;
+ $this->is_valid = false;
}
});
@@ -206,13 +208,13 @@ class CheckCompanyData implements ShouldQueue
if ($ledger && (string) $invoice_balance != (string) $client->balance) {
$wrong_paid_to_dates++;
- $this->company_data[] = $client->present()->name.' - '.$client->id." - calculated client balances do not match {$invoice_balance} - ".rtrim($client->balance, '0')."\n";
+ $this->company_data[] = $client->present()->name.' - '.$client->id." - calculated client balances do not match {$invoice_balance} - ".rtrim($client->balance, '0')."";
- $this->isValid = false;
+ $this->is_valid = false;
}
}
- $this->company_data[] = "{$wrong_paid_to_dates} clients with incorrect client balances\n";
+ $this->company_data[] = "{$wrong_paid_to_dates} clients with incorrect client balances";
}
private function checkContacts()
@@ -224,10 +226,10 @@ class CheckCompanyData implements ShouldQueue
->orderBy('id')
->get(['id']);
- $this->company_data[] = $contacts->count().' contacts without a contact_key\n';
+ $this->company_data[] = $contacts->count().' contacts without a contact_key';
if ($contacts->count() > 0) {
- $this->isValid = false;
+ $this->is_valid = false;
}
// if ($this->option('fix') == 'true') {
@@ -244,7 +246,7 @@ class CheckCompanyData implements ShouldQueue
// check for missing contacts
$clients = DB::table('clients')
- ->where('company_id', $this->company->id)
+ ->where('clients.company_id', $this->company->id)
->leftJoin('client_contacts', function ($join) {
$join->on('client_contacts.client_id', '=', 'clients.id')
->whereNull('client_contacts.deleted_at');
@@ -258,10 +260,10 @@ class CheckCompanyData implements ShouldQueue
$clients = $clients->get(['clients.id', 'clients.user_id', 'clients.company_id']);
- $this->company_data[] = $clients->count().' clients without any contacts\n';
+ $this->company_data[] = $clients->count().' clients without any contacts';
if ($clients->count() > 0) {
- $this->isValid = false;
+ $this->is_valid = false;
}
// if ($this->option('fix') == 'true') {
@@ -293,10 +295,10 @@ class CheckCompanyData implements ShouldQueue
// }
$clients = $clients->get(['clients.id', DB::raw('count(client_contacts.id)')]);
- $this->company_data[] = $clients->count().' clients without a single primary contact\n';
+ $this->company_data[] = $clients->count().' clients without a single primary contact';
if ($clients->count() > 0) {
- $this->isValid = false;
+ $this->is_valid = false;
}
}
@@ -335,11 +337,20 @@ class CheckCompanyData implements ShouldQueue
->get(["{$table}.id"]);
if ($records->count()) {
- $this->isValid = false;
- $this->company_data[] = $records->count()." {$table} records with incorrect {$entityType} company id\n";
+ $this->is_valid = false;
+ $this->company_data[] = $records->count()." {$table} records with incorrect {$entityType} company id";
}
}
}
}
+
+ public function pluralizeEntityType($type)
+ {
+ if ($type === 'company') {
+ return 'companies';
+ }
+
+ return $type.'s';
+ }
}
diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php
index 427e10510a16..a5b6d619546b 100644
--- a/app/Jobs/Util/Import.php
+++ b/app/Jobs/Util/Import.php
@@ -210,12 +210,11 @@ class Import implements ShouldQueue
// $this->fixClientBalances();
$check_data = CheckCompanyData::dispatchNow($this->company, md5(time()));
-
- if($check_data['status'] == 'errors')
- throw new ProcessingMigrationArchiveFailed($check_data);
+ // if($check_data['status'] == 'errors')
+ // throw new ProcessingMigrationArchiveFailed(implode("\n", $check_data));
Mail::to($this->user)
- ->send(new MigrationCompleted($this->company, $check_data));
+ ->send(new MigrationCompleted($this->company, implode("
",$check_data)));
/*After a migration first some basic jobs to ensure the system is up to date*/
VersionCheck::dispatch();
diff --git a/app/Mail/MigrationCompleted.php b/app/Mail/MigrationCompleted.php
index 5e7baf470f87..e81f72356496 100644
--- a/app/Mail/MigrationCompleted.php
+++ b/app/Mail/MigrationCompleted.php
@@ -34,7 +34,7 @@ class MigrationCompleted extends Mailable
public function build()
{
$data['settings'] = $this->company->settings;
- $data['company'] = $this->company;
+ $data['company'] = $this->company->fresh();
$data['whitelabel'] = $this->company->account->isPaid() ? true : false;
$data['check_data'] = $this->check_data;
diff --git a/phpunit.xml b/phpunit.xml
index e1b0575994e1..e1ef466e8b20 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -22,7 +22,7 @@
Clients Imported: {{ count($company->clients) }}
+ @if(isset($company) && $company->clients->count() >=1) +Clients Imported: {{ $company->clients->count() }}
@endif @if(isset($company) && count($company->products) >=1) @@ -75,7 +75,7 @@Data Quality:
-{{ $check_data }}
+{!! $check_data !!}
{{ ctrans('texts.account_login')}} diff --git a/tests/Unit/InvitationTest.php b/tests/Unit/InvitationTest.php index 76db0cd24020..0bee7f83e1d1 100644 --- a/tests/Unit/InvitationTest.php +++ b/tests/Unit/InvitationTest.php @@ -34,6 +34,7 @@ class InvitationTest extends TestCase public function testInvitationSanity() { + $this->assertEquals($this->invoice->invitations->count(), 2); $invitations = $this->invoice->invitations()->get(); @@ -46,11 +47,20 @@ class InvitationTest extends TestCase $this->invoice->line_items = []; + $response = null; + + try { + $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, - ])->put('/api/v1/invoices/'.$this->encodePrimaryKey($this->invoice->id), $this->invoice->toArray()) - ->assertStatus(200); + ])->put('/api/v1/invoices/'.$this->encodePrimaryKey($this->invoice->id), $this->invoice->toArray()); + } catch (\Exception $e) { + + nlog($e->getMessage()); + } + + $response->assertStatus(200); $arr = $response->json();