1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-22 01:11:34 +02:00
invoiceninja/database/seeds/RandomDataSeeder.php

234 lines
7.8 KiB
PHP
Raw Normal View History

<?php
use App\DataMapper\ClientSettings;
2019-09-10 04:30:43 +02:00
use App\DataMapper\CompanySettings;
use App\DataMapper\DefaultSettings;
use App\Events\Invoice\InvoiceWasMarkedSent;
2019-09-20 07:13:58 +02:00
use App\Events\Invoice\InvoiceWasUpdated;
2019-10-04 08:22:22 +02:00
use App\Events\Payment\PaymentWasCreated;
use App\Helpers\Invoice\InvoiceSum;
2019-10-01 11:59:32 +02:00
use App\Jobs\Company\UpdateCompanyLedgerWithInvoice;
2019-10-04 08:22:22 +02:00
use App\Jobs\Invoice\UpdateInvoicePayment;
2019-10-01 07:54:21 +02:00
use App\Listeners\Invoice\CreateInvoiceInvitation;
use App\Models\Account;
use App\Models\Client;
use App\Models\ClientContact;
2019-09-14 14:34:05 +02:00
use App\Models\CompanyGateway;
2019-03-27 05:50:13 +01:00
use App\Models\CompanyToken;
2019-09-14 14:34:05 +02:00
use App\Models\GatewayType;
2019-09-10 04:30:43 +02:00
use App\Models\GroupSetting;
2019-09-20 07:13:58 +02:00
use App\Models\Invoice;
2019-10-10 13:08:02 +02:00
use App\Models\Payment;
2019-10-04 08:22:22 +02:00
use App\Models\PaymentType;
use App\Models\User;
use App\Models\UserAccount;
2019-10-01 07:54:21 +02:00
use App\Repositories\InvoiceRepository;
use Illuminate\Database\Seeder;
class RandomDataSeeder extends Seeder
{
use \App\Utils\Traits\MakesHash;
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
2019-10-01 08:03:57 +02:00
$this->command->info('Running RandomDataSeeder');
Eloquent::unguard();
$faker = Faker\Factory::create();
$account = factory(\App\Models\Account::class)->create();
$company = factory(\App\Models\Company::class)->create([
'account_id' => $account->id,
'domain' => config('ninja.site_url'),
]);
$account->default_company_id = $company->id;
$account->save();
$user = factory(\App\Models\User::class)->create([
'email' => $faker->email,
2019-05-10 08:08:33 +02:00
// 'account_id' => $account->id,
'confirmation_code' => $this->createDbHash(config('database.default'))
]);
2019-03-27 05:50:13 +01:00
$company_token = CompanyToken::create([
'user_id' => $user->id,
'company_id' => $company->id,
'account_id' => $account->id,
'name' => 'test token',
2019-09-26 15:00:51 +02:00
'token' => \Illuminate\Support\Str::random(64),
2019-03-27 05:50:13 +01:00
]);
$user->companies()->attach($company->id, [
'account_id' => $account->id,
'is_owner' => 1,
'is_admin' => 1,
'is_locked' => 0,
'permissions' => json_encode([]),
'settings' => json_encode(DefaultSettings::userSettings()),
]);
$client = factory(\App\Models\Client::class)->create([
'user_id' => $user->id,
'company_id' => $company->id
]);
ClientContact::create([
'first_name' => $faker->firstName,
'last_name' => $faker->lastName,
2019-08-29 00:13:26 +02:00
'email' => config('ninja.testvars.username'),
'company_id' => $company->id,
'password' => Hash::make(config('ninja.testvars.password')),
'email_verified_at' => now(),
'client_id' =>$client->id,
]);
2019-06-03 07:31:20 +02:00
factory(\App\Models\Client::class, 6)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){
factory(\App\Models\ClientContact::class,1)->create([
'user_id' => $user->id,
'client_id' => $c->id,
'company_id' => $company->id,
'is_primary' => 1
]);
factory(\App\Models\ClientContact::class,10)->create([
'user_id' => $user->id,
'client_id' => $c->id,
'company_id' => $company->id
]);
});
2019-04-03 02:09:22 +02:00
/** Product Factory */
factory(\App\Models\Product::class,50)->create(['user_id' => $user->id, 'company_id' => $company->id]);
2019-04-04 03:38:17 +02:00
/** Invoice Factory */
2019-10-17 00:51:05 +02:00
factory(\App\Models\Invoice::class,50)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id, 'settings' => ClientSettings::buildClientSettings($company->settings, $client->settings)]);
2019-04-04 03:38:17 +02:00
2019-09-20 07:13:58 +02:00
$invoices = Invoice::all();
2019-10-01 07:54:21 +02:00
$invoice_repo = new InvoiceRepository();
2019-09-20 07:13:58 +02:00
2019-10-04 08:22:22 +02:00
$invoices->each(function ($invoice) use($invoice_repo, $user, $company, $client){
2019-10-17 00:51:05 +02:00
2019-10-17 02:25:57 +02:00
//$settings = $invoice->settings;
//$settings->inclusive_taxes = (bool)random_int(0, 1);
//$invoice->settings = $settings;
2019-10-17 00:51:05 +02:00
$invoice_calc = new InvoiceSum($invoice, $invoice->settings);
2019-09-20 07:13:58 +02:00
2019-10-01 07:54:21 +02:00
$invoice = $invoice_calc->build()->getInvoice();
$invoice->save();
event(new CreateInvoiceInvitation($invoice));
2019-10-01 11:59:32 +02:00
UpdateCompanyLedgerWithInvoice::dispatchNow($invoice, $invoice->balance);
2019-10-01 07:54:21 +02:00
$invoice_repo->markSent($invoice);
2019-10-01 07:54:21 +02:00
event(new InvoiceWasMarkedSent($invoice));
2019-10-04 08:22:22 +02:00
if(rand(0, 1)) {
$payment = App\Models\Payment::create([
2019-10-10 13:08:02 +02:00
'payment_date' => now(),
'user_id' => $user->id,
'company_id' => $company->id,
'client_id' => $client->id,
'amount' => $invoice->balance,
'transaction_reference' => rand(0,500),
'payment_type_id' => PaymentType::CREDIT_CARD_OTHER,
2019-10-10 13:08:02 +02:00
'status_id' => Payment::STATUS_COMPLETED,
]);
$payment->invoices()->save($invoice);
event(new PaymentWasCreated($payment));
UpdateInvoicePayment::dispatchNow($payment);
}
2019-09-20 07:13:58 +02:00
});
2019-08-15 13:10:02 +02:00
/** Recurring Invoice Factory */
factory(\App\Models\RecurringInvoice::class,20)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]);
// factory(\App\Models\Payment::class,20)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id, 'settings' => ClientSettings::buildClientSettings($company->settings, $client->settings)]);
2019-08-15 13:10:02 +02:00
2019-05-10 08:08:33 +02:00
$clients = Client::all();
2019-05-10 08:08:33 +02:00
foreach($clients as $client)
{
2019-08-15 13:10:02 +02:00
//$client->getNextClientNumber($client);
$client->id_number = $client->getNextClientNumber($client);
2019-05-10 08:08:33 +02:00
$client->save();
}
2019-06-03 07:31:20 +02:00
2019-09-10 04:30:43 +02:00
GroupSetting::create([
'company_id' => $company->id,
'user_id' => $user->id,
2019-09-19 07:50:05 +02:00
'settings' => ClientSettings::buildClientSettings(CompanySettings::defaults(), ClientSettings::defaults()),
2019-09-10 04:30:43 +02:00
'name' => 'Default Client Settings',
]);
2019-09-14 14:34:05 +02:00
if(config('ninja.testvars.stripe'))
{
2019-09-15 13:40:46 +02:00
2019-09-14 14:34:05 +02:00
$cg = new CompanyGateway;
$cg->company_id = $company->id;
$cg->user_id = $user->id;
$cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23';
2019-09-14 14:34:05 +02:00
$cg->require_cvv = true;
$cg->show_address = true;
$cg->show_shipping_address = true;
$cg->update_details = true;
2019-09-16 04:05:30 +02:00
$cg->config = encrypt(config('ninja.testvars.stripe'));
2019-09-14 14:34:05 +02:00
$cg->priority_id = 1;
$cg->save();
2019-09-15 13:40:46 +02:00
2019-09-18 14:43:37 +02:00
$cg = new CompanyGateway;
$cg->company_id = $company->id;
$cg->user_id = $user->id;
$cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23';
2019-09-18 14:43:37 +02:00
$cg->require_cvv = true;
$cg->show_address = true;
$cg->show_shipping_address = true;
$cg->update_details = true;
$cg->config = encrypt(config('ninja.testvars.stripe'));
2019-09-30 01:26:37 +02:00
$cg->priority_id = 2;
$cg->save();
}
if(config('ninja.testvars.paypal'))
{
$cg = new CompanyGateway;
$cg->company_id = $company->id;
$cg->user_id = $user->id;
$cg->gateway_key = '38f2c48af60c7dd69e04248cbb24c36e';
$cg->require_cvv = true;
$cg->show_address = true;
$cg->show_shipping_address = true;
$cg->update_details = true;
$cg->config = encrypt(config('ninja.testvars.paypal'));
$cg->priority_id = 3;
2019-09-18 14:43:37 +02:00
$cg->save();
2019-09-14 14:34:05 +02:00
}
}
2019-09-14 14:34:05 +02:00
}