diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index 202f37280504..42cc3f86ee05 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -12,36 +12,37 @@ namespace App\Console\Commands; use App; +use Exception; +use App\Models\User; +use App\Utils\Ninja; +use App\Models\Quote; +use App\Models\Client; +use App\Models\Credit; +use App\Models\Vendor; +use App\Models\Account; +use App\Models\Company; +use App\Models\Contact; +use App\Models\Invoice; +use App\Models\Payment; +use App\Models\CompanyUser; +use Illuminate\Support\Str; +use App\Models\CompanyToken; +use App\Models\ClientContact; +use App\Models\CompanyLedger; +use App\Models\PurchaseOrder; +use App\Models\VendorContact; +use App\Models\BankTransaction; +use App\Models\QuoteInvitation; +use Illuminate\Console\Command; +use App\Models\CreditInvitation; +use App\Models\InvoiceInvitation; use App\DataMapper\ClientSettings; +use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Mail; use App\Factory\ClientContactFactory; use App\Factory\VendorContactFactory; use App\Jobs\Company\CreateCompanyToken; -use App\Models\Account; -use App\Models\Client; -use App\Models\ClientContact; -use App\Models\Company; -use App\Models\CompanyLedger; -use App\Models\CompanyToken; -use App\Models\CompanyUser; -use App\Models\Contact; -use App\Models\Credit; -use App\Models\CreditInvitation; -use App\Models\Invoice; -use App\Models\InvoiceInvitation; -use App\Models\Payment; -use App\Models\PurchaseOrder; -use App\Models\Quote; -use App\Models\QuoteInvitation; use App\Models\RecurringInvoiceInvitation; -use App\Models\User; -use App\Models\Vendor; -use App\Models\VendorContact; -use App\Utils\Ninja; -use Exception; -use Illuminate\Console\Command; -use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Mail; -use Illuminate\Support\Str; use Symfony\Component\Console\Input\InputOption; /* @@ -81,7 +82,7 @@ class CheckData extends Command /** * @var string */ - protected $signature = 'ninja:check-data {--database=} {--fix=} {--portal_url=} {--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=} {--bank_transaction=}'; /** * @var string @@ -136,6 +137,10 @@ class CheckData extends Command $this->checkOAuth(); } + if($this->option('bank_transaction')) { + $this->fixBankTransactions(); + } + $this->logMessage('Done: '.strtoupper($this->isValid ? Account::RESULT_SUCCESS : Account::RESULT_FAILURE)); $this->logMessage('Total execution time in seconds: ' . (microtime(true) - $time_start)); @@ -1090,4 +1095,23 @@ class CheckData extends Command } }); } + + public function fixBankTransactions() + { + $this->logMessage("checking bank transactions"); + + BankTransaction::with('payment')->withTrashed()->where('invoice_ids', ',,,,,,,,')->cursor()->each(function ($bt){ + + if($bt->payment->exists()) { + + $bt->invoice_ids = collect($bt->payment->invoices)->pluck('hashed_id')->implode(','); + $bt->save(); + + $this->logMessage("Fixing - {$bt->id}"); + + } + + }); + + } } diff --git a/app/Models/BankTransaction.php b/app/Models/BankTransaction.php index b07e817c7d83..9b0f76abbd7d 100644 --- a/app/Models/BankTransaction.php +++ b/app/Models/BankTransaction.php @@ -180,6 +180,11 @@ class BankTransaction extends BaseModel return $this->belongsTo(Account::class)->withTrashed(); } + public function payment() + { + return $this->belongsTo(Payment::class)->withTrashed(); + } + public function service() :BankService { return new BankService($this);