diff --git a/app/Console/Commands/SampleData.php b/app/Console/Commands/SampleData.php new file mode 100755 index 000000000..e5017865a --- /dev/null +++ b/app/Console/Commands/SampleData.php @@ -0,0 +1,47 @@ +laravel->make(SampleDataSeeder::class); + + $seeder = $class->setContainer($this->laravel)->setCommand($this); + + $seeder->__invoke(); + } +} diff --git a/database/seeds/SampleData.php b/database/seeds/SampleData.php new file mode 100755 index 000000000..8183449b1 --- /dev/null +++ b/database/seeds/SampleData.php @@ -0,0 +1,109 @@ +command->option('count'); + + for ($i = 0; $i < $count; $i++) { + $this->dispatch(new CreateContact(factory(Contact::class)->raw())); + } + + for ($i = 0; $i < $count; $i++) { + $this->dispatch(new CreateItem(factory(Item::class)->raw())); + } + + for ($i = 0; $i < $count; $i++) { + $this->dispatch(new CreateAccount(factory(Account::class)->raw())); + } + + for ($i = 0; $i < $count; $i++) { + $this->dispatch(new CreateBill(factory(Bill::class)->state('items')->raw())); + } + + for ($i = 0; $i < $count; $i++) { + $this->dispatch(new CreateInvoice(factory(Invoice::class)->state('items')->raw())); + } + + for ($i = 0; $i < $count; $i++) { + $amount = $faker->randomFloat(2, 1, 1000); + $invoices = Invoice::where('status', 'sent')->get(); + + if (0 === $invoices->count()) { + continue; + } + + $invoice = $invoices->random(1)->first(); + + $this->dispatch( + new CreateDocumentTransaction( + $invoice, + factory(Transaction::class)->state('income')->raw( + [ + 'contact_id' => $invoice->contact_id, + 'document_id' => $invoice->id, + 'amount' => $amount > $invoice->amount ? $invoice->amount : $amount, + ] + ) + ) + ); + } + + for ($i = 0; $i < $count; $i++) { + $amount = $faker->randomFloat(2, 1, 1000); + $bills = Bill::where('status', 'received')->get(); + + if (0 === $bills->count()) { + continue; + } + + $bill = $bills->random(1)->first(); + + $this->dispatch( + new CreateDocumentTransaction( + $bill, + factory(Transaction::class)->state('expense')->raw( + [ + 'contact_id' => $bill->contact_id, + 'document_id' => $bill->id, + 'amount' => $amount > $bill->amount ? $bill->amount : $amount, + ] + ) + ) + ); + } + + Model::unguard(); + } +}