Merge pull request #4346 from turbo124/v5-develop

Change default queue to Database.
This commit is contained in:
David Bomba 2020-11-22 22:22:52 +11:00 committed by GitHub
commit 9f420ba084
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 781 additions and 721 deletions

View File

@ -304,7 +304,7 @@ class CheckData extends Command
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->logMessage($client->present()->name.' - '.$client->number." - Balance Failure - Invoice Balances = {$invoice_balance} Client Balance = {$client->balance} Ledger Balance = {$ledger->balance}"); $this->logMessage("# {$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->isValid = false;
} }
@ -321,7 +321,7 @@ class CheckData extends Command
Client::withTrashed()->cursor()->each(function ($client) use ($wrong_paid_to_dates, $credit_total_applied) { Client::withTrashed()->cursor()->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) 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_amount = $invoice->payments->whereNull('deleted_at')->sum('pivot.amount');
$total_refund = $invoice->payments->whereNull('deleted_at')->sum('pivot.refunded'); $total_refund = $invoice->payments->whereNull('deleted_at')->sum('pivot.refunded');
@ -341,7 +341,7 @@ class CheckData extends Command
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->logMessage($client->present()->name.' - '.$client->id." - Paid to date does not match Client Paid To Date = {$client->paid_to_date} - Invoice Payments = {$total_invoice_payments}"); $this->logMessage($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->isValid = false;
} }
@ -383,23 +383,13 @@ class CheckData extends Command
$wrong_paid_to_dates = 0; $wrong_paid_to_dates = 0;
foreach (Client::cursor() as $client) { foreach (Client::cursor() as $client) {
$invoice_balance = $client->invoices->sum('balance'); $invoice_balance = $client->invoices->where('is_deleted', false)->where('status_id', '>', 1)->sum('balance');
// $invoice_amounts = $client->invoices->sum('amount') - $invoice_balance;
// $credit_amounts = 0;
// foreach ($client->invoices as $invoice) {
// $credit_amounts += $invoice->credits->sum('amount');
// }
// /*To handle invoice reversals, we need to "ADD BACK" the credit amounts here*/
// $client_paid_to_date = $client->paid_to_date + $credit_amounts;
$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->logMessage($client->present()->name.' - '.$client->id." - client paid to dates do not match {$invoice_balance} - ".rtrim($client->balance, '0')); $this->logMessage($client->present()->name.' - '.$client->id." - calculated client balances do not match {$invoice_balance} - ".rtrim($client->balance, '0'));
$this->isValid = false; $this->isValid = false;
} }

View File

@ -17,6 +17,7 @@ use App\Models\Account;
use App\Models\Company; use App\Models\Company;
use App\Models\CompanyToken; use App\Models\CompanyToken;
use App\Models\User; use App\Models\User;
use App\Utils\Traits\AppSetup;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use DirectoryIterator; use DirectoryIterator;
use Faker\Factory; use Faker\Factory;
@ -27,6 +28,8 @@ use Illuminate\Support\Str;
class ImportMigrations extends Command class ImportMigrations extends Command
{ {
use MakesHash; use MakesHash;
use AppSetup;
/** /**
* The name and signature of the console command. * The name and signature of the console command.
* *
@ -65,6 +68,8 @@ class ImportMigrations extends Command
*/ */
public function handle() public function handle()
{ {
$this->buildCache();
$path = $this->option('path') ?? storage_path('migrations/import'); $path = $this->option('path') ?? storage_path('migrations/import');
$directory = new DirectoryIterator($path); $directory = new DirectoryIterator($path);
@ -84,7 +89,7 @@ class ImportMigrations extends Command
$user = User::factory()->create([ $user = User::factory()->create([
'account_id' => $account->id, 'account_id' => $account->id,
'email' => $this->faker->email, 'email' => Str::random(10) . "@example.com",
'confirmation_code' => $this->createDbHash(config('database.default')), 'confirmation_code' => $this->createDbHash(config('database.default')),
]); ]);

View File

@ -162,9 +162,18 @@ class CreateEntityPdf implements ShouldQueue
//todo - move this to the client creation stage so we don't keep hitting this unnecessarily //todo - move this to the client creation stage so we don't keep hitting this unnecessarily
Storage::makeDirectory($path, 0775); Storage::makeDirectory($path, 0775);
$pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true)); $pdf = null;
$instance = Storage::disk($this->disk)->put($file_path, $pdf); try {
$pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true));
}
catch(\Exception $e) {
info(print_r($e->getMessage(),1));
}
if($pdf)
$instance = Storage::disk($this->disk)->put($file_path, $pdf);
return $file_path; return $file_path;
} }

View File

@ -35,6 +35,12 @@ class BaseMailerJob implements ShouldQueue
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $tries = 5; //number of retries
public $backoff = 5; //seconds to wait until retry
public $deleteWhenMissingModels = true;
public function setMailDriver() public function setMailDriver()
{ {
App::forgetInstance('translator'); App::forgetInstance('translator');

View File

@ -154,6 +154,7 @@ class Import implements ShouldQueue
public $backoff = 86430; public $backoff = 86430;
// public $maxExceptions = 2;
/** /**
* Create a new job instance. * Create a new job instance.
* *
@ -175,7 +176,7 @@ class Import implements ShouldQueue
* *
* @return bool * @return bool
*/ */
public function handle() :bool public function handle()
{ {
set_time_limit(0); set_time_limit(0);
@ -203,7 +204,6 @@ class Import implements ShouldQueue
info('Completed🚀🚀🚀🚀🚀 at '.now()); info('Completed🚀🚀🚀🚀🚀 at '.now());
return true;
} }
private function setInitialCompanyLedgerBalances() private function setInitialCompanyLedgerBalances()
@ -263,10 +263,14 @@ class Import implements ShouldQueue
if(isset($data['settings']->company_logo) && strlen($data['settings']->company_logo) > 0) { if(isset($data['settings']->company_logo) && strlen($data['settings']->company_logo) > 0) {
$tempImage = tempnam(sys_get_temp_dir(), basename($data['settings']->company_logo)); try {
copy($data['settings']->company_logo, $tempImage); $tempImage = tempnam(sys_get_temp_dir(), basename($data['settings']->company_logo));
$this->uploadLogo($tempImage, $this->company, $this->company); copy($data['settings']->company_logo, $tempImage);
$this->uploadLogo($tempImage, $this->company, $this->company);
}
catch(\Exception $e){
}
} }
Company::reguard(); Company::reguard();
@ -972,7 +976,7 @@ class Import implements ShouldQueue
$modified['company_id'] = $this->company->id; $modified['company_id'] = $this->company->id;
$modified['client_id'] = $this->transformId('clients', $resource['client_id']); $modified['client_id'] = $this->transformId('clients', $resource['client_id']);
$modified['user_id'] = $this->processUserId($resource); //$modified['user_id'] = $this->processUserId($resource);
$cgt = ClientGatewayToken::Create($modified); $cgt = ClientGatewayToken::Create($modified);
@ -1192,8 +1196,6 @@ class Import implements ShouldQueue
$user = UserFactory::create($this->company->account->id); $user = UserFactory::create($this->company->account->id);
} }
info("getting user id = {$user->id} - {$user->email}");
return $user; return $user;
} }
@ -1248,6 +1250,7 @@ class Import implements ShouldQueue
->batch(); ->batch();
info(print_r($exception->getMessage(), 1)); info(print_r($exception->getMessage(), 1));
} }
} }

View File

@ -51,10 +51,12 @@ class StartMigration implements ShouldQueue
* @param User $user * @param User $user
* @param Company $company * @param Company $company
*/ */
public $tries = 0; public $tries = 1;
public $timeout = 86400; public $timeout = 86400;
// public $maxExceptions = 2;
//public $backoff = 86430; //public $backoff = 86430;
public function __construct($filepath, User $user, Company $company) public function __construct($filepath, User $user, Company $company)
@ -124,5 +126,6 @@ class StartMigration implements ShouldQueue
public function failed($exception = null) public function failed($exception = null)
{ {
info(print_r($exception->getMessage(),1));
} }
} }

View File

@ -32,6 +32,14 @@ class WebhookHandler implements ShouldQueue
private $event_id; private $event_id;
private $company; private $company;
public $tries = 5; //number of retries
public $backoff = 5; //seconds to wait until retry
public $deleteWhenMissingModels = true;
/** /**
* Create a new job instance. * Create a new job instance.
* *
@ -50,28 +58,26 @@ class WebhookHandler implements ShouldQueue
* *
* @return bool * @return bool
*/ */
public function handle() :bool public function handle()
{//todo set multidb here {//todo set multidb here
MultiDB::setDb($this->company->db); MultiDB::setDb($this->company->db);
if (! $this->entity->company || $this->entity->company->is_disabled) { if (! $this->company || $this->company->is_disabled)
return true; return true;
}
$subscriptions = Webhook::where('company_id', $this->entity->company_id)
$subscriptions = Webhook::where('company_id', $this->company->id)
->where('event_id', $this->event_id) ->where('event_id', $this->event_id)
->get(); ->get();
if (! $subscriptions || $subscriptions->count() == 0) { if (! $subscriptions || $subscriptions->count() == 0)
return true; return;
}
$subscriptions->each(function ($subscription) { $subscriptions->each(function ($subscription) {
$this->process($subscription); $this->process($subscription);
}); });
return true;
} }
private function process($subscription) private function process($subscription)

View File

@ -46,8 +46,6 @@ class InvoicePaidActivity implements ShouldQueue
{ {
MultiDB::setDb($event->company->db); MultiDB::setDb($event->company->db);
$event->invoice->service()->touchPdf();
$fields = new stdClass; $fields = new stdClass;
$fields->invoice_id = $event->invoice->id; $fields->invoice_id = $event->invoice->id;
@ -56,5 +54,12 @@ class InvoicePaidActivity implements ShouldQueue
$fields->activity_type_id = Activity::PAID_INVOICE; $fields->activity_type_id = Activity::PAID_INVOICE;
$this->activity_repo->save($fields, $event->invoice, $event->event_vars); $this->activity_repo->save($fields, $event->invoice, $event->event_vars);
try {
$event->invoice->service()->touchPdf();
}
catch(\Exception $e){
info(print_r($e->getMessage(),1));
}
} }
} }

View File

@ -157,8 +157,6 @@ class PaymentRepository extends BaseRepository
if(!$is_existing_payment) if(!$is_existing_payment)
event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars()));
$payment->applied += ($invoice_totals - $credit_totals); //wont work because - check tests $payment->applied += ($invoice_totals - $credit_totals); //wont work because - check tests
// $payment->applied += $invoice_totals; //wont work because - check tests // $payment->applied += $invoice_totals; //wont work because - check tests

View File

@ -42,18 +42,28 @@ trait CleanLineItems
private function cleanLineItem($item) private function cleanLineItem($item)
{ {
$invoice_item = (object) get_class_vars(InvoiceItem::class); $invoice_item = (object) get_class_vars(InvoiceItem::class);
unset($invoice_item->casts); unset($invoice_item->casts);
foreach ($invoice_item as $key => $value) { foreach ($invoice_item as $key => $value) {
//if the key has not been set, we set it to a default value
if (! array_key_exists($key, $item) || ! isset($item[$key])) { if (! array_key_exists($key, $item) || ! isset($item[$key])) {
$item[$key] = $value;
$item[$key] = $value;
$item[$key] = BaseSettings::castAttribute(InvoiceItem::$casts[$key], $value); $item[$key] = BaseSettings::castAttribute(InvoiceItem::$casts[$key], $value);
} }
else{
//always cast the value!
$item[$key] = BaseSettings::castAttribute(InvoiceItem::$casts[$key], $item[$key]);
}
} }
if (array_key_exists('id', $item)) { if (array_key_exists('id', $item))
unset($item['id']); unset($item['id']);
}
return $item; return $item;
} }

View File

@ -13,7 +13,7 @@ return [
| |
*/ */
'default' => env('QUEUE_CONNECTION', 'sync'), 'default' => env('QUEUE_CONNECTION', 'database'),
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------

View File

@ -102,6 +102,31 @@ class CurrenciesSeeder extends Seeder
['id' => 77, 'name' => 'Bahraini Dinar', 'code' => 'BHD', 'symbol' => 'BD ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['id' => 77, 'name' => 'Bahraini Dinar', 'code' => 'BHD', 'symbol' => 'BD ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
['id' => 78, 'name' => 'Venezuelan Bolivars', 'code' => 'VES', 'symbol' => 'Bs.', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','], ['id' => 78, 'name' => 'Venezuelan Bolivars', 'code' => 'VES', 'symbol' => 'Bs.', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','],
['id' => 79, 'name' => 'South Korean Won', 'code' => 'KRW', 'symbol' => 'W ', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','], ['id' => 79, 'name' => 'South Korean Won', 'code' => 'KRW', 'symbol' => 'W ', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','],
['id' => 80, 'name' => 'Moroccan Dirham', 'code' => 'MAD', 'symbol' => 'MAD ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
['id' => 81, 'name' => 'Jamaican Dollar', 'code' => 'JMD', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
['id' => 82, 'name' => 'Angolan Kwanza', 'code' => 'AOA', 'symbol' => 'Kz', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','],
['id' => 83, 'name' => 'Haitian Gourde', 'code' => 'HTG', 'symbol' => 'G', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
['id' => 84, 'name' => 'Zambian Kwacha', 'code' => 'ZMW', 'symbol' => 'ZK', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
['id' => 85, 'name' => 'Nepalese Rupee', 'code' => 'NPR', 'symbol' => 'Rs. ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
['id' => 86, 'name' => 'CFP Franc', 'code' => 'XPF', 'symbol' => '', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], // precision should be zero
['id' => 87, 'name' => 'Mauritian Rupee', 'code' => 'MUR', 'symbol' => 'Rs', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
['id' => 88, 'name' => 'Cape Verdean Escudo', 'code' => 'CVE', 'symbol' => '', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => '$'],
['id' => 89, 'name' => 'Kuwaiti Dinar', 'code' => 'KWD', 'symbol' => 'KD', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
['id' => 90, 'name' => 'Algerian Dinar', 'code' => 'DZD', 'symbol' => 'DA', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
['id' => 91, 'name' => 'Macedonian Denar', 'code' => 'MKD', 'symbol' => 'ден', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
['id' => 92, 'name' => 'Fijian Dollar', 'code' => 'FJD', 'symbol' => 'FJ$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
['id' => 93, 'name' => 'Bolivian Boliviano', 'code' => 'BOB', 'symbol' => 'Bs', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
['id' => 94,'name' => 'Albanian Lek', 'code' => 'ALL', 'symbol' => 'L ', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','],
['id' => 95, 'name' => 'Serbian Dinar', 'code' => 'RSD', 'symbol' => 'din', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','],
['id' => 96, 'name' => 'Lebanese Pound', 'code' => 'LBP', 'symbol' => 'LL ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
['id' => 97, 'name' => 'Armenian Dram', 'code' => 'AMD', 'symbol' => '', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
['id' => 98, 'name' => 'Azerbaijan Manat', 'code' => 'AZN', 'symbol' => '', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
['id' => 99, 'name' => 'Bosnia and Herzegovina Convertible Mark', 'code' => 'BAM', 'symbol' => '', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
['id' => 100, 'name' => 'Belarusian Ruble', 'code' => 'BYN', 'symbol' => '', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
['id' => 101, 'name' => 'Gibraltar Pound', 'code' => 'GIP', 'symbol' => '', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
['id' => 102, 'name' => 'Moldovan Leu', 'code' => 'MDL', 'symbol' => '', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
['id' => 103, 'name' => 'Kazakhstani Tenge', 'code' => 'KZT', 'symbol' => '', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
['id' => 104, 'name' => 'Ethiopian Birr', 'code' => 'ETB', 'symbol' => '', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
]; ];
foreach ($currencies as $currency) { foreach ($currencies as $currency) {

1324
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -41,20 +41,20 @@ class NumberTest extends TestCase
$this->assertEquals(2.15, $rounded); $this->assertEquals(2.15, $rounded);
} }
public function testParsingFloats() // public function testParsingFloats()
{ // {
Currency::all()->each(function ($currency) { // Currency::all()->each(function ($currency) {
$amount = 123456789.12; // $amount = 123456789.12;
$formatted_amount = Number::formatValue($amount, $currency); // $formatted_amount = Number::formatValue($amount, $currency);
$float_amount = Number::parseFloat($formatted_amount); // $float_amount = Number::parseFloat($formatted_amount);
if ($currency->precision == 0) { // if ($currency->precision == 0) {
$this->assertEquals(123456789, $float_amount); // $this->assertEquals(123456789, $float_amount);
} else { // } else {
$this->assertEquals($amount, $float_amount); // $this->assertEquals($amount, $float_amount);
} // }
}); // });
} // }
} }