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;
|
2019-09-23 05:10:51 +02:00
|
|
|
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;
|
2019-09-20 07:13:58 +02:00
|
|
|
use App\Helpers\Invoice\InvoiceCalc;
|
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;
|
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;
|
2019-09-20 07:13:58 +02:00
|
|
|
use App\Models\Invoice;
|
2019-10-04 08:22:22 +02:00
|
|
|
use App\Models\PaymentType;
|
2018-11-02 11:54:46 +01:00
|
|
|
use App\Models\User;
|
|
|
|
use App\Models\UserAccount;
|
2019-10-01 07:54:21 +02:00
|
|
|
use App\Repositories\InvoiceRepository;
|
2018-11-02 11:54:46 +01:00
|
|
|
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
|
|
|
|
2018-11-02 11:54:46 +01: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,
|
2019-09-23 13:29:30 +02:00
|
|
|
'domain' => config('ninja.site_url'),
|
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',
|
2019-09-26 15:00:51 +02:00
|
|
|
'token' => \Illuminate\Support\Str::random(64),
|
2019-03-27 05:50:13 +01:00
|
|
|
]);
|
|
|
|
|
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-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-09-23 05:10:51 +02:00
|
|
|
|
2019-10-01 07:54:21 +02:00
|
|
|
$invoice_calc = new InvoiceCalc($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-09-23 05:10:51 +02:00
|
|
|
|
2019-10-01 07:54:21 +02:00
|
|
|
event(new InvoiceWasMarkedSent($invoice));
|
2019-10-04 08:22:22 +02:00
|
|
|
|
|
|
|
$payment = App\Models\Payment::create([
|
|
|
|
'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,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$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]);
|
|
|
|
|
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)]);
|
|
|
|
|
|
|
|
|
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,
|
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;
|
2019-09-24 13:22:41 +02:00
|
|
|
$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;
|
2019-09-24 13:22:41 +02:00
|
|
|
$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
|
|
|
}
|
|
|
|
|
2018-11-02 11:54:46 +01:00
|
|
|
}
|
2019-09-14 14:34:05 +02:00
|
|
|
|
|
|
|
|
2018-11-02 11:54:46 +01:00
|
|
|
}
|