2018-11-02 11:54:46 +01:00
|
|
|
<?php
|
|
|
|
|
2019-08-29 14:47:45 +02:00
|
|
|
use App\DataMapper\ClientSettings;
|
2019-09-10 04:30:43 +02:00
|
|
|
use App\DataMapper\CompanySettings;
|
2019-07-09 02:01:29 +02:00
|
|
|
use App\DataMapper\DefaultSettings;
|
2018-11-02 11:54:46 +01:00
|
|
|
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;
|
2018-11-02 11:54:46 +01:00
|
|
|
use App\Models\User;
|
|
|
|
use App\Models\UserAccount;
|
|
|
|
use Illuminate\Database\Seeder;
|
2019-08-29 14:47:45 +02:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2018-11-02 11:54:46 +01:00
|
|
|
|
|
|
|
class RandomDataSeeder extends Seeder
|
|
|
|
{
|
|
|
|
use \App\Utils\Traits\MakesHash;
|
|
|
|
/**
|
|
|
|
* Run the database seeds.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function run()
|
|
|
|
{
|
|
|
|
|
|
|
|
$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,
|
2019-07-12 07:03:30 +02:00
|
|
|
'domain' => 'ninja.test',
|
2018-11-02 11:54:46 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
$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,
|
2018-11-02 11:54:46 +01:00
|
|
|
'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',
|
|
|
|
'token' => str_random(64),
|
|
|
|
]);
|
|
|
|
|
2018-11-02 11:54:46 +01:00
|
|
|
$user->companies()->attach($company->id, [
|
|
|
|
'account_id' => $account->id,
|
|
|
|
'is_owner' => 1,
|
|
|
|
'is_admin' => 1,
|
|
|
|
'is_locked' => 0,
|
2019-07-09 02:01:29 +02:00
|
|
|
'permissions' => json_encode([]),
|
|
|
|
'settings' => json_encode(DefaultSettings::userSettings()),
|
2018-11-02 11:54:46 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
$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'),
|
2018-11-02 11:54:46 +01:00
|
|
|
'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){
|
2018-11-02 11:54:46 +01:00
|
|
|
|
|
|
|
factory(\App\Models\ClientContact::class,1)->create([
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'client_id' => $c->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'is_primary' => 1
|
|
|
|
]);
|
|
|
|
|
2018-11-03 02:01:40 +01:00
|
|
|
factory(\App\Models\ClientContact::class,10)->create([
|
2018-11-02 11:54:46 +01:00
|
|
|
'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-09-02 07:08:26 +02:00
|
|
|
factory(\App\Models\Invoice::class,500)->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-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]);
|
|
|
|
|
2019-09-02 07:08:26 +02:00
|
|
|
// 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)]);
|
|
|
|
|
|
|
|
factory(\App\Models\Payment::class,20)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]);
|
|
|
|
|
2019-08-15 13:10:02 +02:00
|
|
|
|
2019-05-10 08:08:33 +02:00
|
|
|
$clients = Client::all();
|
2018-11-02 11:54:46 +01:00
|
|
|
|
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,
|
|
|
|
'settings' => ClientSettings::buildClientSettings(new CompanySettings(CompanySettings::defaults()), new ClientSettings(ClientSettings::defaults())),
|
|
|
|
'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_id = 20;
|
|
|
|
$cg->gateway_type_id = GatewayType::CREDIT_CARD;
|
|
|
|
$cg->require_cvv = true;
|
|
|
|
$cg->show_address = true;
|
|
|
|
$cg->show_shipping_address = true;
|
|
|
|
$cg->update_details = true;
|
2019-09-15 13:40:46 +02:00
|
|
|
$cg->config = encrypt(json_encode(config('ninja.testvars.stripe'),true));
|
2019-09-14 14:34:05 +02:00
|
|
|
$cg->priority_id = 1;
|
|
|
|
$cg->save();
|
2019-09-15 13:40:46 +02:00
|
|
|
|
|
|
|
\Log::error(decrypt($cg->config));
|
|
|
|
|
2019-09-14 14:34:05 +02:00
|
|
|
}
|
|
|
|
|
2018-11-02 11:54:46 +01:00
|
|
|
}
|
2019-09-14 14:34:05 +02:00
|
|
|
|
|
|
|
|
2018-11-02 11:54:46 +01:00
|
|
|
}
|