From 3d9b712fb7520418be7ef933044f551ff1db4363 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 14 Aug 2016 22:29:34 +0300 Subject: [PATCH] Improve test data --- app/Console/Commands/CreateTestData.php | 36 +++++++++++++------------ 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/app/Console/Commands/CreateTestData.php b/app/Console/Commands/CreateTestData.php index a75922635f..da3c861157 100644 --- a/app/Console/Commands/CreateTestData.php +++ b/app/Console/Commands/CreateTestData.php @@ -39,8 +39,8 @@ class CreateTestData extends Command * @param ExpenseRepository $expenseRepo */ public function __construct( - ClientRepository $clientRepo, - InvoiceRepository $invoiceRepo, + ClientRepository $clientRepo, + InvoiceRepository $invoiceRepo, PaymentRepository $paymentRepo, VendorRepository $vendorRepo, ExpenseRepository $expenseRepo) @@ -48,7 +48,7 @@ class CreateTestData extends Command parent::__construct(); $this->faker = Factory::create(); - + $this->clientRepo = $clientRepo; $this->invoiceRepo = $invoiceRepo; $this->paymentRepo = $paymentRepo; @@ -64,18 +64,18 @@ class CreateTestData extends Command if (Utils::isNinjaProd()) { return false; } - + $this->info(date('Y-m-d').' Running CreateTestData...'); Auth::loginUsingId(1); $this->count = $this->argument('count'); - + $this->createClients(); $this->createVendors(); - + $this->info('Done'); } - + private function createClients() { for ($i=0; $i<$this->count; $i++) { @@ -89,14 +89,14 @@ class CreateTestData extends Command 'contacts' => [[ 'first_name' => $this->faker->firstName, 'last_name' => $this->faker->lastName, - 'email' => $this->faker->safeEmail, + 'email' => $this->faker->safeEmail, 'phone' => $this->faker->phoneNumber, ]] ]; $client = $this->clientRepo->save($data); $this->info('Client: ' . $client->name); - + $this->createInvoices($client); } } @@ -105,10 +105,12 @@ class CreateTestData extends Command * @param $client */ private function createInvoices($client) - { + { for ($i=0; $i<$this->count; $i++) { $data = [ 'client_id' => $client->id, + 'invoice_date_sql' => date_create()->modify(rand(-100, 100) . ' days')->format('Y-m-d'), + 'due_date_sql' => date_create()->modify(rand(-100, 100) . ' days')->format('Y-m-d'), 'invoice_items' => [[ 'product_key' => $this->faker->word, 'qty' => $this->faker->randomDigit + 1, @@ -119,7 +121,7 @@ class CreateTestData extends Command $invoice = $this->invoiceRepo->save($data); $this->info('Invoice: ' . $invoice->invoice_number); - + $this->createPayment($client, $invoice); } } @@ -135,12 +137,12 @@ class CreateTestData extends Command 'client_id' => $client->id, 'amount' => $this->faker->randomFloat(2, 0, $invoice->amount) ]; - + $payment = $this->paymentRepo->save($data); - + $this->info('Payment: ' . $payment->amount); } - + private function createVendors() { for ($i=0; $i<$this->count; $i++) { @@ -154,14 +156,14 @@ class CreateTestData extends Command 'vendor_contacts' => [[ 'first_name' => $this->faker->firstName, 'last_name' => $this->faker->lastName, - 'email' => $this->faker->safeEmail, + 'email' => $this->faker->safeEmail, 'phone' => $this->faker->phoneNumber, ]] ]; $vendor = $this->vendorRepo->save($data); $this->info('Vendor: ' . $vendor->name); - + $this->createExpense($vendor); } } @@ -178,7 +180,7 @@ class CreateTestData extends Command 'expense_date' => null, 'public_notes' => null, ]; - + $expense = $this->expenseRepo->save($data); $this->info('Expense: ' . $expense->amount); }