mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Improve test data
This commit is contained in:
parent
918d58e0b6
commit
3d9b712fb7
@ -39,8 +39,8 @@ class CreateTestData extends Command
|
|||||||
* @param ExpenseRepository $expenseRepo
|
* @param ExpenseRepository $expenseRepo
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
ClientRepository $clientRepo,
|
ClientRepository $clientRepo,
|
||||||
InvoiceRepository $invoiceRepo,
|
InvoiceRepository $invoiceRepo,
|
||||||
PaymentRepository $paymentRepo,
|
PaymentRepository $paymentRepo,
|
||||||
VendorRepository $vendorRepo,
|
VendorRepository $vendorRepo,
|
||||||
ExpenseRepository $expenseRepo)
|
ExpenseRepository $expenseRepo)
|
||||||
@ -48,7 +48,7 @@ class CreateTestData extends Command
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->faker = Factory::create();
|
$this->faker = Factory::create();
|
||||||
|
|
||||||
$this->clientRepo = $clientRepo;
|
$this->clientRepo = $clientRepo;
|
||||||
$this->invoiceRepo = $invoiceRepo;
|
$this->invoiceRepo = $invoiceRepo;
|
||||||
$this->paymentRepo = $paymentRepo;
|
$this->paymentRepo = $paymentRepo;
|
||||||
@ -64,18 +64,18 @@ class CreateTestData extends Command
|
|||||||
if (Utils::isNinjaProd()) {
|
if (Utils::isNinjaProd()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->info(date('Y-m-d').' Running CreateTestData...');
|
$this->info(date('Y-m-d').' Running CreateTestData...');
|
||||||
|
|
||||||
Auth::loginUsingId(1);
|
Auth::loginUsingId(1);
|
||||||
$this->count = $this->argument('count');
|
$this->count = $this->argument('count');
|
||||||
|
|
||||||
$this->createClients();
|
$this->createClients();
|
||||||
$this->createVendors();
|
$this->createVendors();
|
||||||
|
|
||||||
$this->info('Done');
|
$this->info('Done');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createClients()
|
private function createClients()
|
||||||
{
|
{
|
||||||
for ($i=0; $i<$this->count; $i++) {
|
for ($i=0; $i<$this->count; $i++) {
|
||||||
@ -89,14 +89,14 @@ class CreateTestData extends Command
|
|||||||
'contacts' => [[
|
'contacts' => [[
|
||||||
'first_name' => $this->faker->firstName,
|
'first_name' => $this->faker->firstName,
|
||||||
'last_name' => $this->faker->lastName,
|
'last_name' => $this->faker->lastName,
|
||||||
'email' => $this->faker->safeEmail,
|
'email' => $this->faker->safeEmail,
|
||||||
'phone' => $this->faker->phoneNumber,
|
'phone' => $this->faker->phoneNumber,
|
||||||
]]
|
]]
|
||||||
];
|
];
|
||||||
|
|
||||||
$client = $this->clientRepo->save($data);
|
$client = $this->clientRepo->save($data);
|
||||||
$this->info('Client: ' . $client->name);
|
$this->info('Client: ' . $client->name);
|
||||||
|
|
||||||
$this->createInvoices($client);
|
$this->createInvoices($client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -105,10 +105,12 @@ class CreateTestData extends Command
|
|||||||
* @param $client
|
* @param $client
|
||||||
*/
|
*/
|
||||||
private function createInvoices($client)
|
private function createInvoices($client)
|
||||||
{
|
{
|
||||||
for ($i=0; $i<$this->count; $i++) {
|
for ($i=0; $i<$this->count; $i++) {
|
||||||
$data = [
|
$data = [
|
||||||
'client_id' => $client->id,
|
'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' => [[
|
'invoice_items' => [[
|
||||||
'product_key' => $this->faker->word,
|
'product_key' => $this->faker->word,
|
||||||
'qty' => $this->faker->randomDigit + 1,
|
'qty' => $this->faker->randomDigit + 1,
|
||||||
@ -119,7 +121,7 @@ class CreateTestData extends Command
|
|||||||
|
|
||||||
$invoice = $this->invoiceRepo->save($data);
|
$invoice = $this->invoiceRepo->save($data);
|
||||||
$this->info('Invoice: ' . $invoice->invoice_number);
|
$this->info('Invoice: ' . $invoice->invoice_number);
|
||||||
|
|
||||||
$this->createPayment($client, $invoice);
|
$this->createPayment($client, $invoice);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,12 +137,12 @@ class CreateTestData extends Command
|
|||||||
'client_id' => $client->id,
|
'client_id' => $client->id,
|
||||||
'amount' => $this->faker->randomFloat(2, 0, $invoice->amount)
|
'amount' => $this->faker->randomFloat(2, 0, $invoice->amount)
|
||||||
];
|
];
|
||||||
|
|
||||||
$payment = $this->paymentRepo->save($data);
|
$payment = $this->paymentRepo->save($data);
|
||||||
|
|
||||||
$this->info('Payment: ' . $payment->amount);
|
$this->info('Payment: ' . $payment->amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createVendors()
|
private function createVendors()
|
||||||
{
|
{
|
||||||
for ($i=0; $i<$this->count; $i++) {
|
for ($i=0; $i<$this->count; $i++) {
|
||||||
@ -154,14 +156,14 @@ class CreateTestData extends Command
|
|||||||
'vendor_contacts' => [[
|
'vendor_contacts' => [[
|
||||||
'first_name' => $this->faker->firstName,
|
'first_name' => $this->faker->firstName,
|
||||||
'last_name' => $this->faker->lastName,
|
'last_name' => $this->faker->lastName,
|
||||||
'email' => $this->faker->safeEmail,
|
'email' => $this->faker->safeEmail,
|
||||||
'phone' => $this->faker->phoneNumber,
|
'phone' => $this->faker->phoneNumber,
|
||||||
]]
|
]]
|
||||||
];
|
];
|
||||||
|
|
||||||
$vendor = $this->vendorRepo->save($data);
|
$vendor = $this->vendorRepo->save($data);
|
||||||
$this->info('Vendor: ' . $vendor->name);
|
$this->info('Vendor: ' . $vendor->name);
|
||||||
|
|
||||||
$this->createExpense($vendor);
|
$this->createExpense($vendor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,7 +180,7 @@ class CreateTestData extends Command
|
|||||||
'expense_date' => null,
|
'expense_date' => null,
|
||||||
'public_notes' => null,
|
'public_notes' => null,
|
||||||
];
|
];
|
||||||
|
|
||||||
$expense = $this->expenseRepo->save($data);
|
$expense = $this->expenseRepo->save($data);
|
||||||
$this->info('Expense: ' . $expense->amount);
|
$this->info('Expense: ' . $expense->amount);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user