Merge pull request #4862 from turbo124/v5-develop

Working on MultiDb
This commit is contained in:
David Bomba 2021-02-10 14:18:56 +11:00 committed by GitHub
commit ff6f66e5c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 197 additions and 130 deletions

View File

@ -73,6 +73,7 @@ class CheckData extends Command
protected $description = 'Check/fix data'; protected $description = 'Check/fix data';
protected $log = ''; protected $log = '';
protected $isValid = true; protected $isValid = true;
public function handle() public function handle()
@ -90,13 +91,10 @@ class CheckData extends Command
$this->checkContacts(); $this->checkContacts();
$this->checkCompanyData(); $this->checkCompanyData();
//$this->checkLogoFiles();
if (! $this->option('client_id')) { if (! $this->option('client_id')) {
$this->checkOAuth(); $this->checkOAuth();
//$this->checkInvitations(); //$this->checkFailedJobs();
$this->checkFailedJobs();
} }
$this->logMessage('Done: '.strtoupper($this->isValid ? Account::RESULT_SUCCESS : Account::RESULT_FAILURE)); $this->logMessage('Done: '.strtoupper($this->isValid ? Account::RESULT_SUCCESS : Account::RESULT_FAILURE));
@ -298,8 +296,6 @@ class CheckData extends Command
$total_invoice_payments = 0; $total_invoice_payments = 0;
foreach ($client->invoices->where('is_deleted', false)->where('status_id', '>', 1) as $invoice) { foreach ($client->invoices->where('is_deleted', false)->where('status_id', '>', 1) as $invoice) {
// $total_amount = $invoice->payments->whereNull('deleted_at')->sum('pivot.amount');
// $total_refund = $invoice->payments->whereNull('deleted_at')->sum('pivot.refunded');
$total_amount = $invoice->payments->where('is_deleted', false)->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED])->sum('pivot.amount'); $total_amount = $invoice->payments->where('is_deleted', false)->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_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, Payment::STATUS_REFUNDED])->sum('pivot.refunded'); $total_refund = $invoice->payments->where('is_deleted', false)->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED])->sum('pivot.refunded');
@ -307,15 +303,15 @@ class CheckData extends Command
$total_invoice_payments += ($total_amount - $total_refund); $total_invoice_payments += ($total_amount - $total_refund);
} }
foreach ($client->payments as $payment) { //10/02/21
$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) { // if ($credit_total_applied < 0) {
$total_invoice_payments += $credit_total_applied; // $total_invoice_payments += $credit_total_applied;
} //todo this is contentious // }
// nlog("total invoice payments = {$total_invoice_payments} with client paid to date of of {$client->paid_to_date}");
if (round($total_invoice_payments, 2) != round($client->paid_to_date, 2)) { if (round($total_invoice_payments, 2) != round($client->paid_to_date, 2)) {
$wrong_paid_to_dates++; $wrong_paid_to_dates++;

View File

@ -11,6 +11,7 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use App\Libraries\MultiDB;
use App\Models\Design; use App\Models\Design;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use stdClass; use stdClass;
@ -47,6 +48,23 @@ class DesignUpdate extends Command
* @return mixed * @return mixed
*/ */
public function handle() public function handle()
{
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);
}
}
}
private function handleOnDb()
{ {
foreach (Design::whereIsCustom(false)->get() as $design) { foreach (Design::whereIsCustom(false)->get() as $design) {
$invoice_design = new \App\Services\PdfMaker\Design(strtolower($design->name)); $invoice_design = new \App\Services\PdfMaker\Design(strtolower($design->name));

View File

@ -13,6 +13,7 @@ namespace App\Console\Commands;
use App\Jobs\Ninja\SendReminders; use App\Jobs\Ninja\SendReminders;
use App\Jobs\Util\WebHookHandler; use App\Jobs\Util\WebHookHandler;
use App\Libraries\MultiDB;
use App\Models\Invoice; use App\Models\Invoice;
use App\Models\Quote; use App\Models\Quote;
use App\Models\Webhook; use App\Models\Webhook;
@ -58,6 +59,24 @@ class SendRemindersCron extends Command
} }
private function webHookOverdueInvoices() private function webHookOverdueInvoices()
{
if (! config('ninja.db.multi_db_enabled')) {
$this->executeWebhooks();
} else {
//multiDB environment, need to
foreach (MultiDB::$dbs as $db) {
MultiDB::setDB($db);
$this->executeWebhooks();
}
}
}
private function executeWebhooks()
{ {
$invoices = Invoice::where('is_deleted', 0) $invoices = Invoice::where('is_deleted', 0)
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) ->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
@ -68,10 +87,7 @@ class SendRemindersCron extends Command
$invoices->each(function ($invoice) { $invoices->each(function ($invoice) {
WebHookHandler::dispatch(Webhook::EVENT_LATE_INVOICE, $invoice, $invoice->company); WebHookHandler::dispatch(Webhook::EVENT_LATE_INVOICE, $invoice, $invoice->company);
}); });
}
private function webHookExpiredQuotes()
{
$quotes = Quote::where('is_deleted', 0) $quotes = Quote::where('is_deleted', 0)
->where('status_id', Quote::STATUS_SENT) ->where('status_id', Quote::STATUS_SENT)
->whereDate('due_date', '<=', now()->subDays(1)->startOfDay()) ->whereDate('due_date', '<=', now()->subDays(1)->startOfDay())
@ -81,4 +97,6 @@ class SendRemindersCron extends Command
WebHookHandler::dispatch(Webhook::EVENT_EXPIRED_QUOTE, $quote, $quote->company); WebHookHandler::dispatch(Webhook::EVENT_EXPIRED_QUOTE, $quote, $quote->company);
}); });
} }
} }

View File

@ -42,7 +42,10 @@ class BaseMailerJob implements ShouldQueue
public function setMailDriver() public function setMailDriver()
{ {
/* Singletons need to be rebooted each time just in case our Locale is changing*/
App::forgetInstance('translator'); App::forgetInstance('translator');
/* Inject custom translations if any exist */
Lang::replace(Ninja::transformTranslations($this->settings)); Lang::replace(Ninja::transformTranslations($this->settings));
switch ($this->settings->email_sending_method) { switch ($this->settings->email_sending_method) {
@ -96,7 +99,7 @@ class BaseMailerJob implements ShouldQueue
public function failed($exception = null) public function failed($exception = null)
{ {
nlog('the job failed'); nlog('mailer job failed');
nlog($exception->getMessage()); nlog($exception->getMessage());
$job_failure = new EmailFailure(); $job_failure = new EmailFailure();

View File

@ -41,7 +41,7 @@ class CheckCompanyData implements ShouldQueue
* *
* @return void * @return void
*/ */
public function __construct(Company $company, string $hash) public function __construct(Company $company, string $hash = '')
{ {
$this->company = $company; $this->company = $company;
$this->hash = $hash; $this->hash = $hash;
@ -72,8 +72,16 @@ class CheckCompanyData implements ShouldQueue
Cache::put($this->hash, $cache_instance, now()->addMinutes(30)); Cache::put($this->hash, $cache_instance, now()->addMinutes(30));
nlog(Cache::get($this->hash)); nlog(Cache::get($this->hash));
nlog($this->company_data);
if(!$this->isValid)
$this->company_data['status'] = 'errors';
else
$this->company_data['status'] = 'success';
return $this->company_data;
} }
@ -88,25 +96,26 @@ class CheckCompanyData implements ShouldQueue
$wrong_balances = 0; $wrong_balances = 0;
$wrong_paid_to_dates = 0; $wrong_paid_to_dates = 0;
foreach ($this->company->clients->where('is_deleted', 0)->cursor() as $client) { foreach ($this->company->clients->where('is_deleted', 0) as $client) {
$invoice_balance = $client->invoices->where('is_deleted', false)->where('status_id', '>', 1)->sum('balance'); $invoice_balance = $client->invoices->where('is_deleted', false)->where('status_id', '>', 1)->sum('balance');
$credit_balance = $client->credits->where('is_deleted', false)->sum('balance'); //$credit_balance = $client->credits->where('is_deleted', false)->sum('balance');
if($client->balance != $invoice_balance) // if($client->balance != $invoice_balance)
$invoice_balance -= $credit_balance;//doesn't make sense to remove the credit amount // $invoice_balance -= $credit_balance;//doesn't make sense to remove the credit amount
$ledger = CompanyLedger::where('client_id', $client->id)->orderBy('id', 'DESC')->first(); $ledger = CompanyLedger::where('client_id', $client->id)->orderBy('id', 'DESC')->first();
if ($ledger && number_format($invoice_balance, 4) != number_format($client->balance, 4)) { if ($ledger && number_format($invoice_balance, 4) != number_format($client->balance, 4)) {
$wrong_balances++; $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}"; $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->isValid = false; $this->isValid = false;
} }
} }
$this->logMessage("{$wrong_balances} clients with incorrect balances"); $this->company_data[] = "{$wrong_balances} clients with incorrect balances\n";
} }
private function checkInvoicePayments() private function checkInvoicePayments()
@ -114,7 +123,7 @@ class CheckCompanyData implements ShouldQueue
$wrong_balances = 0; $wrong_balances = 0;
$wrong_paid_to_dates = 0; $wrong_paid_to_dates = 0;
$this->company->clients->where('is_deleted', 0)->cursor()->each(function ($client) use ($wrong_balances) { $this->company->clients->where('is_deleted', 0)->each(function ($client) use ($wrong_balances) {
$client->invoices->where('is_deleted', false)->whereIn('status_id', '!=', Invoice::STATUS_DRAFT)->each(function ($invoice) use ($wrong_balances, $client) { $client->invoices->where('is_deleted', false)->whereIn('status_id', '!=', Invoice::STATUS_DRAFT)->each(function ($invoice) use ($wrong_balances, $client) {
$total_amount = $invoice->payments->whereIn('status_id', [Payment::STATUS_PAID, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED])->sum('pivot.amount'); $total_amount = $invoice->payments->whereIn('status_id', [Payment::STATUS_PAID, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED])->sum('pivot.amount');
$total_refund = $invoice->payments->whereIn('status_id', [Payment::STATUS_PAID, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED])->sum('pivot.refunded'); $total_refund = $invoice->payments->whereIn('status_id', [Payment::STATUS_PAID, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED])->sum('pivot.refunded');
@ -126,14 +135,14 @@ class CheckCompanyData implements ShouldQueue
if ((string)$total_paid != (string)($invoice->amount - $invoice->balance - $total_credit)) { if ((string)$total_paid != (string)($invoice->amount - $invoice->balance - $total_credit)) {
$wrong_balances++; $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}"; $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->isValid = false; $this->isValid = false;
} }
}); });
}); });
$this->company_data[] = "{$wrong_balances} clients with incorrect invoice balances"; $this->company_data[] = "{$wrong_balances} clients with incorrect invoice balances\n";
} }
private function checkPaidToDates() private function checkPaidToDates()
@ -141,12 +150,11 @@ class CheckCompanyData implements ShouldQueue
$wrong_paid_to_dates = 0; $wrong_paid_to_dates = 0;
$credit_total_applied = 0; $credit_total_applied = 0;
$this->company->clients->where('is_deleted', 0)->cursor()->each(function ($client) use ($wrong_paid_to_dates, $credit_total_applied) { $this->company->clients->where('is_deleted', 0)->each(function ($client) use ($wrong_paid_to_dates, $credit_total_applied) {
$total_invoice_payments = 0; $total_invoice_payments = 0;
foreach ($client->invoices->where('is_deleted', false)->where('status_id', '>', 1) as $invoice) { foreach ($client->invoices->where('is_deleted', false)->where('status_id', '>', 1) as $invoice) {
// $total_amount = $invoice->payments->whereNull('deleted_at')->sum('pivot.amount');
// $total_refund = $invoice->payments->whereNull('deleted_at')->sum('pivot.refunded');
$total_amount = $invoice->payments->where('is_deleted', false)->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED])->sum('pivot.amount'); $total_amount = $invoice->payments->where('is_deleted', false)->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_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, Payment::STATUS_REFUNDED])->sum('pivot.refunded'); $total_refund = $invoice->payments->where('is_deleted', false)->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED])->sum('pivot.refunded');
@ -154,20 +162,21 @@ class CheckCompanyData implements ShouldQueue
$total_invoice_payments += ($total_amount - $total_refund); $total_invoice_payments += ($total_amount - $total_refund);
} }
foreach ($client->payments as $payment) { //10/02/21
$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) { // if ($credit_total_applied < 0) {
$total_invoice_payments += $credit_total_applied; // $total_invoice_payments += $credit_total_applied;
} //todo this is contentious // } //todo this is contentious
// nlog("total invoice payments = {$total_invoice_payments} with client paid to date of of {$client->paid_to_date}"); // nlog("total invoice payments = {$total_invoice_payments} with client paid to date of of {$client->paid_to_date}");
if (round($total_invoice_payments, 2) != round($client->paid_to_date, 2)) { if (round($total_invoice_payments, 2) != round($client->paid_to_date, 2)) {
$wrong_paid_to_dates++; $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}"; $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->isValid = false; $this->isValid = false;
} }
@ -182,55 +191,56 @@ class CheckCompanyData implements ShouldQueue
$wrong_balances = 0; $wrong_balances = 0;
$wrong_paid_to_dates = 0; $wrong_paid_to_dates = 0;
foreach ($this->company->clients->where('is_deleted', 0)->cursor() as $client) { foreach ($this->company->clients->where('is_deleted', 0) as $client) {
//$invoice_balance = $client->invoices->where('is_deleted', false)->where('status_id', '>', 1)->sum('balance'); //$invoice_balance = $client->invoices->where('is_deleted', false)->where('status_id', '>', 1)->sum('balance');
$invoice_balance = Invoice::where('client_id', $client->id)->where('is_deleted', false)->where('status_id', '>', 1)->withTrashed()->sum('balance'); $invoice_balance = Invoice::where('client_id', $client->id)->where('is_deleted', false)->where('status_id', '>', 1)->withTrashed()->sum('balance');
$credit_balance = Credit::where('client_id', $client->id)->where('is_deleted', false)->withTrashed()->sum('balance'); $credit_balance = Credit::where('client_id', $client->id)->where('is_deleted', false)->withTrashed()->sum('balance');
/*Legacy - V4 will add credits to the balance - we may need to reverse engineer this and remove the credits from the client balance otherwise we need this hack here and in the invoice balance check.*/ //10/02/21
if($client->balance != $invoice_balance) // Legacy - V4 will add credits to the balance - we may need to reverse engineer this and remove the credits from the client balance otherwise we need this hack here and in the invoice balance check.
$invoice_balance -= $credit_balance; // if($client->balance != $invoice_balance)
// $invoice_balance -= $credit_balance;
$ledger = CompanyLedger::where('client_id', $client->id)->orderBy('id', 'DESC')->first(); $ledger = CompanyLedger::where('client_id', $client->id)->orderBy('id', 'DESC')->first();
if ($ledger && (string) $invoice_balance != (string) $client->balance) { if ($ledger && (string) $invoice_balance != (string) $client->balance) {
$wrong_paid_to_dates++; $wrong_paid_to_dates++;
$this->company_data[] = $client->present()->name.' - '.$client->id." - calculated client balances do not match {$invoice_balance} - ".rtrim($client->balance, '0'); $this->company_data[] = $client->present()->name.' - '.$client->id." - calculated client balances do not match {$invoice_balance} - ".rtrim($client->balance, '0')."\n";
$this->isValid = false; $this->isValid = false;
} }
} }
$this->company_data[] = "{$wrong_paid_to_dates} clients with incorrect client balances"; $this->company_data[] = "{$wrong_paid_to_dates} clients with incorrect client balances\n";
} }
private function checkContacts() private function checkContacts()
{ {
// check for contacts with the contact_key value set // check for contacts with the contact_key value set
$contacts = DB::table('client_contacts') $contacts = DB::table('client_contacts')
->where('company_id', $this->company_id) ->where('company_id', $this->company->id)
->whereNull('contact_key') ->whereNull('contact_key')
->orderBy('id') ->orderBy('id')
->get(['id']); ->get(['id']);
$this->company_data[] = $contacts->count().' contacts without a contact_key'; $this->company_data[] = $contacts->count().' contacts without a contact_key\n';
if ($contacts->count() > 0) { if ($contacts->count() > 0) {
$this->isValid = false; $this->isValid = false;
} }
if ($this->option('fix') == 'true') { // if ($this->option('fix') == 'true') {
foreach ($contacts as $contact) { // foreach ($contacts as $contact) {
DB::table('client_contacts') // DB::table('client_contacts')
->where('company_id', $this->company->id) // ->where('company_id', $this->company->id)
->where('id', '=', $contact->id) // ->where('id', '=', $contact->id)
->whereNull('contact_key') // ->whereNull('contact_key')
->update([ // ->update([
'contact_key' => str_random(config('ninja.key_length')), // 'contact_key' => str_random(config('ninja.key_length')),
]); // ]);
} // }
} // }
// check for missing contacts // check for missing contacts
$clients = DB::table('clients') $clients = DB::table('clients')
@ -242,34 +252,34 @@ class CheckCompanyData implements ShouldQueue
->groupBy('clients.id', 'clients.user_id', 'clients.company_id') ->groupBy('clients.id', 'clients.user_id', 'clients.company_id')
->havingRaw('count(client_contacts.id) = 0'); ->havingRaw('count(client_contacts.id) = 0');
if ($this->option('client_id')) { // if ($this->option('client_id')) {
$clients->where('clients.id', '=', $this->option('client_id')); // $clients->where('clients.id', '=', $this->option('client_id'));
} // }
$clients = $clients->get(['clients.id', 'clients.user_id', 'clients.company_id']); $clients = $clients->get(['clients.id', 'clients.user_id', 'clients.company_id']);
$this->company_data[] = $clients->count().' clients without any contacts'; $this->company_data[] = $clients->count().' clients without any contacts\n';
if ($clients->count() > 0) { if ($clients->count() > 0) {
$this->isValid = false; $this->isValid = false;
} }
if ($this->option('fix') == 'true') { // if ($this->option('fix') == 'true') {
foreach ($clients as $client) { // foreach ($clients as $client) {
$contact = new ClientContact(); // $contact = new ClientContact();
$contact->company_id = $client->company_id; // $contact->company_id = $client->company_id;
$contact->user_id = $client->user_id; // $contact->user_id = $client->user_id;
$contact->client_id = $client->id; // $contact->client_id = $client->id;
$contact->is_primary = true; // $contact->is_primary = true;
$contact->send_invoice = true; // $contact->send_invoice = true;
$contact->contact_key = str_random(config('ninja.key_length')); // $contact->contact_key = str_random(config('ninja.key_length'));
$contact->save(); // $contact->save();
} // }
} // }
// check for more than one primary contact // check for more than one primary contact
$clients = DB::table('clients') $clients = DB::table('clients')
->where('company_id', $this->company->id) ->where('clients.company_id', $this->company->id)
->leftJoin('client_contacts', function ($join) { ->leftJoin('client_contacts', function ($join) {
$join->on('client_contacts.client_id', '=', 'clients.id') $join->on('client_contacts.client_id', '=', 'clients.id')
->where('client_contacts.is_primary', '=', true) ->where('client_contacts.is_primary', '=', true)
@ -278,12 +288,12 @@ class CheckCompanyData implements ShouldQueue
->groupBy('clients.id') ->groupBy('clients.id')
->havingRaw('count(client_contacts.id) != 1'); ->havingRaw('count(client_contacts.id) != 1');
if ($this->option('client_id')) { // if ($this->option('client_id')) {
$clients->where('clients.id', '=', $this->option('client_id')); // $clients->where('clients.id', '=', $this->option('client_id'));
} // }
$clients = $clients->get(['clients.id', DB::raw('count(client_contacts.id)')]); $clients = $clients->get(['clients.id', DB::raw('count(client_contacts.id)')]);
$this->company_data[] = $clients->count().' clients without a single primary contact'; $this->company_data[] = $clients->count().' clients without a single primary contact\n';
if ($clients->count() > 0) { if ($clients->count() > 0) {
$this->isValid = false; $this->isValid = false;
@ -326,7 +336,7 @@ class CheckCompanyData implements ShouldQueue
if ($records->count()) { if ($records->count()) {
$this->isValid = false; $this->isValid = false;
$this->company_data[] = $records->count()." {$table} records with incorrect {$entityType} company id"; $this->company_data[] = $records->count()." {$table} records with incorrect {$entityType} company id\n";
} }
} }
} }

View File

@ -14,6 +14,7 @@ namespace App\Jobs\Util;
use App\DataMapper\Analytics\MigrationFailure; use App\DataMapper\Analytics\MigrationFailure;
use App\DataMapper\CompanySettings; use App\DataMapper\CompanySettings;
use App\Exceptions\MigrationValidatorFailed; use App\Exceptions\MigrationValidatorFailed;
use App\Exceptions\ProcessingMigrationArchiveFailed;
use App\Exceptions\ResourceDependencyMissing; use App\Exceptions\ResourceDependencyMissing;
use App\Exceptions\ResourceNotAvailableForMigration; use App\Exceptions\ResourceNotAvailableForMigration;
use App\Factory\ClientFactory; use App\Factory\ClientFactory;
@ -31,6 +32,7 @@ use App\Http\Requests\Company\UpdateCompanyRequest;
use App\Http\ValidationRules\ValidCompanyGatewayFeesAndLimitsRule; use App\Http\ValidationRules\ValidCompanyGatewayFeesAndLimitsRule;
use App\Http\ValidationRules\ValidUserForCompany; use App\Http\ValidationRules\ValidUserForCompany;
use App\Jobs\Company\CreateCompanyToken; use App\Jobs\Company\CreateCompanyToken;
use App\Jobs\Ninja\CheckCompanyData;
use App\Jobs\Ninja\CompanySizeCheck; use App\Jobs\Ninja\CompanySizeCheck;
use App\Libraries\MultiDB; use App\Libraries\MultiDB;
use App\Mail\MigrationCompleted; use App\Mail\MigrationCompleted;
@ -206,9 +208,14 @@ class Import implements ShouldQueue
$this->setInitialCompanyLedgerBalances(); $this->setInitialCompanyLedgerBalances();
// $this->fixClientBalances(); // $this->fixClientBalances();
$check_data = CheckCompanyData::dispatchNow($this->company, md5(time()));
if($check_data['status'] == 'errors')
throw new ProcessingMigrationArchiveFailed($check_data);
Mail::to($this->user) Mail::to($this->user)
->send(new MigrationCompleted($this->company)); ->send(new MigrationCompleted($this->company, $check_data));
/*After a migration first some basic jobs to ensure the system is up to date*/ /*After a migration first some basic jobs to ensure the system is up to date*/
VersionCheck::dispatch(); VersionCheck::dispatch();

View File

@ -108,15 +108,16 @@ class StartMigration implements ShouldQueue
throw new NonExistingMigrationFile('Migration file does not exist, or it is corrupted.'); throw new NonExistingMigrationFile('Migration file does not exist, or it is corrupted.');
} }
//$data = json_decode(file_get_contents($file), 1);
//Import::dispatchNow($data['data'], $this->company, $this->user);
Import::dispatchNow($file, $this->company, $this->user); Import::dispatchNow($file, $this->company, $this->user);
} catch (NonExistingMigrationFile | ProcessingMigrationArchiveFailed | ResourceNotAvailableForMigration | MigrationValidatorFailed | ResourceDependencyMissing $e) { } catch (NonExistingMigrationFile | ProcessingMigrationArchiveFailed | ResourceNotAvailableForMigration | MigrationValidatorFailed | ResourceDependencyMissing $e) {
Mail::to($this->user)->send(new MigrationFailed($e, $e->getMessage())); Mail::to($this->user)->send(new MigrationFailed($e, $e->getMessage()));
if (app()->environment() !== 'production') { if (app()->environment() !== 'production') {
info($e->getMessage()); info($e->getMessage());
} }
} }
//always make sure we unset the migration as running //always make sure we unset the migration as running

View File

@ -13,14 +13,17 @@ class MigrationCompleted extends Mailable
public $company; public $company;
public $check_data;
/** /**
* Create a new message instance. * Create a new message instance.
* *
* @return void * @return void
*/ */
public function __construct(Company $company) public function __construct(Company $company, $check_data = '')
{ {
$this->company = $company; $this->company = $company;
$this->check_data = $check_data;
} }
/** /**
@ -33,7 +36,8 @@ class MigrationCompleted extends Mailable
$data['settings'] = $this->company->settings; $data['settings'] = $this->company->settings;
$data['company'] = $this->company; $data['company'] = $this->company;
$data['whitelabel'] = $this->company->account->isPaid() ? true : false; $data['whitelabel'] = $this->company->account->isPaid() ? true : false;
$data['check_data'] = $this->check_data;
$result = $this->from(config('mail.from.address'), config('mail.from.name')) $result = $this->from(config('mail.from.address'), config('mail.from.name'))
->view('email.import.completed', $data); ->view('email.import.completed', $data);

View File

@ -22,6 +22,7 @@ class MigrationFailed extends Mailable
public function __construct($exception, $content = null) public function __construct($exception, $content = null)
{ {
$this->exception = $exception; $this->exception = $exception;
$this->content = $content;
} }
/** /**

View File

@ -64,7 +64,8 @@
"stripe/stripe-php": "^7.50", "stripe/stripe-php": "^7.50",
"turbo124/beacon": "^1", "turbo124/beacon": "^1",
"turbo124/laravel-gmail": "^5.0", "turbo124/laravel-gmail": "^5.0",
"webpatser/laravel-countries": "dev-master#75992ad" "webpatser/laravel-countries": "dev-master#75992ad",
"wildbit/swiftmailer-postmark": "^3.3"
}, },
"require-dev": { "require-dev": {
"php": "^7.4", "php": "^7.4",
@ -79,8 +80,7 @@
"mockery/mockery": "^1.3.1", "mockery/mockery": "^1.3.1",
"nunomaduro/collision": "^5.0", "nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^9.0", "phpunit/phpunit": "^9.0",
"vimeo/psalm": "^4.0", "vimeo/psalm": "^4.0"
"wildbit/postmark-php": "^4.0"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

84
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "49484c0e046a5663433fef2353ee6ee8", "content-hash": "7b93ec16ae5791e0767c92eaf7061cc7",
"packages": [ "packages": [
{ {
"name": "asgrim/ofxparser", "name": "asgrim/ofxparser",
@ -9735,6 +9735,50 @@
"source": "https://github.com/webpatser/laravel-countries" "source": "https://github.com/webpatser/laravel-countries"
}, },
"time": "2019-07-12T14:06:05+00:00" "time": "2019-07-12T14:06:05+00:00"
},
{
"name": "wildbit/swiftmailer-postmark",
"version": "3.3.0",
"source": {
"type": "git",
"url": "https://github.com/wildbit/swiftmailer-postmark.git",
"reference": "44ccab7834de8b220d292647ecb2cb683f9962ee"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/wildbit/swiftmailer-postmark/zipball/44ccab7834de8b220d292647ecb2cb683f9962ee",
"reference": "44ccab7834de8b220d292647ecb2cb683f9962ee",
"shasum": ""
},
"require": {
"guzzlehttp/guzzle": "^6.0|^7.0",
"swiftmailer/swiftmailer": "^6.0.0"
},
"require-dev": {
"phpunit/phpunit": "^6.0.0"
},
"type": "library",
"autoload": {
"psr-0": {
"Postmark\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Postmark",
"email": "support@postmarkapp.com"
}
],
"description": "A Swiftmailer Transport for Postmark.",
"support": {
"issues": "https://github.com/wildbit/swiftmailer-postmark/issues",
"source": "https://github.com/wildbit/swiftmailer-postmark/tree/3.3.0"
},
"time": "2020-09-10T10:54:20+00:00"
} }
], ],
"packages-dev": [ "packages-dev": [
@ -13629,44 +13673,6 @@
}, },
"time": "2015-12-17T08:42:14+00:00" "time": "2015-12-17T08:42:14+00:00"
}, },
{
"name": "wildbit/postmark-php",
"version": "4.0.0",
"source": {
"type": "git",
"url": "https://github.com/wildbit/postmark-php.git",
"reference": "136e3d0884411ca23d0bac02470cfa1d14be676c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/wildbit/postmark-php/zipball/136e3d0884411ca23d0bac02470cfa1d14be676c",
"reference": "136e3d0884411ca23d0bac02470cfa1d14be676c",
"shasum": ""
},
"require": {
"guzzlehttp/guzzle": "^6.0|^7.0",
"php": ">=7.0.0"
},
"require-dev": {
"phpunit/phpunit": "^6.0.0"
},
"type": "library",
"autoload": {
"psr-0": {
"Postmark\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "The officially supported client for Postmark (http://postmarkapp.com)",
"support": {
"issues": "https://github.com/wildbit/postmark-php/issues",
"source": "https://github.com/wildbit/postmark-php/tree/4.0.0"
},
"time": "2020-09-10T16:36:51+00:00"
},
{ {
"name": "zircote/swagger-php", "name": "zircote/swagger-php",
"version": "3.1.0", "version": "3.1.0",

View File

@ -36,10 +36,9 @@ return [
'gmail' => [ 'gmail' => [
'token' => '', 'token' => '',
], ],
'postmark' => env('POSTMARK_API_TOKEN', ''), 'postmark' => [
'postmark_ticket' => env('POSTMARK_API_TICKET_TOKEN'), 'token' => env('POSTMARK_API_TOKEN', ''),
'postmark_ticket_2' => env('POSTMARK_API_TICKET_TOKEN_2'), ],
'stripe' => [ 'stripe' => [
'model' => App\Models\User::class, 'model' => App\Models\User::class,
'key' => env('STRIPE_KEY'), 'key' => env('STRIPE_KEY'),

View File

@ -73,6 +73,10 @@
<p><b>Documents Imported:</b> {{ count($company->documents) }} </p> <p><b>Documents Imported:</b> {{ count($company->documents) }} </p>
@endif @endif
<p><b>Data Quality:</b></p>
<p> {{ $check_data }} </p>
<a href="{{ url('/') }}" target="_blank" class="button">{{ ctrans('texts.account_login')}}</a> <a href="{{ url('/') }}" target="_blank" class="button">{{ ctrans('texts.account_login')}}</a>
<p>{{ ctrans('texts.email_signature')}}<br/> {{ ctrans('texts.email_from') }}</p> <p>{{ ctrans('texts.email_signature')}}<br/> {{ ctrans('texts.email_from') }}</p>