From 7fb9877eca7c6504819ecbc8e884d236a35b4944 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 18 Nov 2020 21:46:36 +1100 Subject: [PATCH] Fixes for currency seeder --- app/Console/Commands/CheckData.php | 12 +---------- app/Console/Commands/ImportMigrations.php | 6 +++++- app/Jobs/Util/Import.php | 7 ++++--- app/Jobs/Util/StartMigration.php | 5 ++++- database/seeders/CurrenciesSeeder.php | 25 +++++++++++++++++++++++ 5 files changed, 39 insertions(+), 16 deletions(-) diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index 086f9a9371df..72074d85d401 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -383,17 +383,7 @@ class CheckData extends Command $wrong_paid_to_dates = 0; foreach (Client::cursor() as $client) { - $invoice_balance = $client->invoices->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; + $invoice_balance = $client->invoices->where('is_deleted', false)->sum('balance'); $ledger = CompanyLedger::where('client_id', $client->id)->orderBy('id', 'DESC')->first(); diff --git a/app/Console/Commands/ImportMigrations.php b/app/Console/Commands/ImportMigrations.php index ae9fa32c63a2..1e4604ba5671 100644 --- a/app/Console/Commands/ImportMigrations.php +++ b/app/Console/Commands/ImportMigrations.php @@ -17,6 +17,7 @@ use App\Models\Account; use App\Models\Company; use App\Models\CompanyToken; use App\Models\User; +use App\Utils\Traits\AppSetup; use App\Utils\Traits\MakesHash; use DirectoryIterator; use Faker\Factory; @@ -27,6 +28,8 @@ use Illuminate\Support\Str; class ImportMigrations extends Command { use MakesHash; + use AppSetup; + /** * The name and signature of the console command. * @@ -65,6 +68,8 @@ class ImportMigrations extends Command */ public function handle() { + $this->buildCache(); + $path = $this->option('path') ?? storage_path('migrations/import'); $directory = new DirectoryIterator($path); @@ -72,7 +77,6 @@ class ImportMigrations extends Command foreach ($directory as $file) { if ($file->getExtension() === 'zip') { $this->info('Started processing: '.$file->getBasename().' at '.now()); - info("dispatching"); StartMigration::dispatch($file->getRealPath(), $this->getUser(), $this->getUser()->companies()->first()); } } diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index 98e86fdd700f..0b0b7270b3dc 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -148,12 +148,13 @@ class Import implements ShouldQueue */ private $ids = []; - public $tries = 0; + public $tries = 1; public $timeout = 86400; public $backoff = 86430; + // public $maxExceptions = 2; /** * Create a new job instance. * @@ -175,7 +176,7 @@ class Import implements ShouldQueue * * @return bool */ - public function handle() :bool + public function handle() { set_time_limit(0); @@ -203,7 +204,6 @@ class Import implements ShouldQueue info('Completed🚀🚀🚀🚀🚀 at '.now()); - return true; } private function setInitialCompanyLedgerBalances() @@ -1246,6 +1246,7 @@ class Import implements ShouldQueue ->batch(); info(print_r($exception->getMessage(), 1)); + } } diff --git a/app/Jobs/Util/StartMigration.php b/app/Jobs/Util/StartMigration.php index 728b9aa182e0..3d2101bfc1eb 100644 --- a/app/Jobs/Util/StartMigration.php +++ b/app/Jobs/Util/StartMigration.php @@ -51,10 +51,12 @@ class StartMigration implements ShouldQueue * @param User $user * @param Company $company */ - public $tries = 0; + public $tries = 1; public $timeout = 86400; + // public $maxExceptions = 2; + //public $backoff = 86430; public function __construct($filepath, User $user, Company $company) @@ -124,5 +126,6 @@ class StartMigration implements ShouldQueue public function failed($exception = null) { + info(print_r($exception->getMessage(),1)); } } diff --git a/database/seeders/CurrenciesSeeder.php b/database/seeders/CurrenciesSeeder.php index 850511099278..a40f479c8e97 100644 --- a/database/seeders/CurrenciesSeeder.php +++ b/database/seeders/CurrenciesSeeder.php @@ -102,6 +102,31 @@ class CurrenciesSeeder extends Seeder ['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' => 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) {