diff --git a/app/Console/Commands/CreateSingleAccount.php b/app/Console/Commands/CreateSingleAccount.php index 0a106b63ce08..4f9c3fee6cd0 100644 --- a/app/Console/Commands/CreateSingleAccount.php +++ b/app/Console/Commands/CreateSingleAccount.php @@ -25,6 +25,9 @@ use App\Helpers\Invoice\InvoiceSum; use App\Jobs\Company\CreateCompanyTaskStatuses; use App\Libraries\MultiDB; use App\Models\Account; +use App\Models\BankIntegration; +use App\Models\BankTransaction; +use App\Models\BankTransactionRule; use App\Models\Client; use App\Models\ClientContact; use App\Models\Company; @@ -47,6 +50,7 @@ use App\Utils\Ninja; use App\Utils\Traits\GeneratesCounter; use App\Utils\Traits\MakesHash; use Carbon\Carbon; +use Database\Factories\BankTransactionRuleFactory; use Faker\Factory; use Illuminate\Console\Command; use Illuminate\Support\Facades\Cache; @@ -87,7 +91,7 @@ class CreateSingleAccount extends Command MultiDB::setDb($this->option('database')); $this->info(date('r').' Create Single Sample Account...'); - $this->count = 1; + $this->count = 5; $this->gateway = $this->argument('gateway'); $this->info('Warming up cache'); @@ -179,6 +183,22 @@ class CreateSingleAccount extends Command 'rate' => 5 ]); + $bi = BankIntegration::factory()->create([ + 'account_id' => $account->id, + 'company_id' => $company->id, + 'user_id' => $user->id, + ]); + + BankTransaction::factory()->count(50)->create([ + 'bank_integration_id' => $bi->id, + 'user_id' => $user->id, + 'company_id' => $company->id, + ]); + + $btr = BankTransactionRule::factory()->create([ + 'user_id' => $user->id, + 'company_id' => $company->id, + ]); $this->info('Creating '.$this->count.' clients'); @@ -358,7 +378,7 @@ class CreateSingleAccount extends Command private function createExpense($client) { - Expense::factory()->count(rand(1, 2))->create([ + Expense::factory()->count(rand(1, 20))->create([ 'user_id' => $client->user->id, 'client_id' => $client->id, 'company_id' => $client->company->id, diff --git a/database/factories/BankTransactionFactory.php b/database/factories/BankTransactionFactory.php index ddba2b428d2c..404f268d5787 100644 --- a/database/factories/BankTransactionFactory.php +++ b/database/factories/BankTransactionFactory.php @@ -34,7 +34,8 @@ class BankTransactionFactory extends Factory 'date' => $this->faker->date('Y-m-d') , 'bank_account_id' => 1 , 'description' =>$this->faker->words(5, true) , - 'status_id'=> 1 + 'status_id'=> 1, + 'base_type' => (bool)rand(0,1) ? 'CREDIT' : 'DEBIT', ]; } } diff --git a/database/factories/BankTransactionRuleFactory.php b/database/factories/BankTransactionRuleFactory.php index 24a5a38fb297..172bc5644626 100644 --- a/database/factories/BankTransactionRuleFactory.php +++ b/database/factories/BankTransactionRuleFactory.php @@ -25,7 +25,10 @@ class BankTransactionRuleFactory extends Factory public function definition() { return [ - 'name' =>$this->faker->name(), + 'name' => $this->faker->name(), + 'applies_to' => (bool)rand(0,1) ? 'CREDIT' : 'DEBIT', + 'matches_on_all' => (bool)rand(0,1), + 'auto_convert' => (bool)rand(0,1), ]; } } diff --git a/tests/Feature/PaymentTest.php b/tests/Feature/PaymentTest.php index 68aebdb37a4e..c2dae62ba3b3 100644 --- a/tests/Feature/PaymentTest.php +++ b/tests/Feature/PaymentTest.php @@ -263,12 +263,11 @@ class PaymentTest extends TestCase $payment_id = $arr['data']['id']; - $payment = Payment::find($this->decodePrimaryKey($payment_id))->first(); - $payment->load('invoices'); - + $payment = Payment::with('invoices')->find($this->decodePrimaryKey($payment_id)); + $this->assertNotNull($payment); $this->assertNotNull($payment->invoices()); - $this->assertEquals(1, $payment->invoices()->count()); + $this->assertEquals(1, $payment->invoices->count()); } } @@ -1345,7 +1344,7 @@ class PaymentTest extends TestCase $payment_id = $arr['data']['id']; - $payment = Payment::find($this->decodePrimaryKey($payment_id))->first(); + $payment = Payment::find($this->decodePrimaryKey($payment_id)); // nlog($payment); @@ -1527,7 +1526,7 @@ class PaymentTest extends TestCase public function testUniquePaymentNumbers() { $data = [ - 'amount' => $invoice->amount, + 'amount' => $this->invoice->amount, 'client_id' => $this->client->hashed_id, 'date' => '2020/12/12', 'number' => 'duplicate',