1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00

Add createRecurringInvoice($client) in CreateSingleAccount.php

This commit is contained in:
Benjamin Beganović 2021-07-05 11:49:01 +02:00
parent 22acc8f14c
commit a6dc7a99fb

View File

@ -14,9 +14,11 @@ namespace App\Console\Commands;
use App\DataMapper\CompanySettings;
use App\DataMapper\FeesAndLimits;
use App\Events\Invoice\InvoiceWasCreated;
use App\Events\RecurringInvoice\RecurringInvoiceWasCreated;
use App\Factory\GroupSettingFactory;
use App\Factory\InvoiceFactory;
use App\Factory\InvoiceItemFactory;
use App\Factory\RecurringInvoiceFactory;
use App\Factory\SubscriptionFactory;
use App\Helpers\Invoice\InvoiceSum;
use App\Jobs\Company\CreateCompanyTaskStatuses;
@ -48,6 +50,7 @@ use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Str;
use stdClass;
class CreateSingleAccount extends Command
{
@ -117,7 +120,7 @@ class CreateSingleAccount extends Command
$company->settings = $settings;
$company->save();
$account->default_company_id = $company->id;
$account->save();
@ -165,7 +168,7 @@ class CreateSingleAccount extends Command
TaxRate::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
'company_id' => $company->id,
'name' => 'VAT',
'rate' => 17.5
]);
@ -176,7 +179,7 @@ class CreateSingleAccount extends Command
'name' => 'CA Sales Tax',
'rate' => 5
]);
$this->info('Creating '.$this->count.' clients');
@ -225,16 +228,19 @@ class CreateSingleAccount extends Command
$client = $company->clients->random();
$this->info('creating task for client #'.$client->id);
$this->info('creating task for client #' . $client->id);
$this->createTask($client);
$client = $company->clients->random();
$this->info('creating project for client #'.$client->id);
$this->info('creating project for client #' . $client->id);
$this->createProject($client);
$this->info('creating credit for client #'.$client->id);
$this->info('creating credit for client #' . $client->id);
$this->createCredit($client);
$this->info('creating recurring invoice for client # ' . $client->id);
$this->createRecurringInvoice($client);
}
$this->createGateways($company, $user);
@ -249,34 +255,34 @@ class CreateSingleAccount extends Command
$gs->save();
$p1 = Product::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
'product_key' => 'pro_plan',
'notes' => 'The Pro Plan',
'cost' => 10,
'price' => 10,
'quantity' => 1,
]);
'user_id' => $user->id,
'company_id' => $company->id,
'product_key' => 'pro_plan',
'notes' => 'The Pro Plan',
'cost' => 10,
'price' => 10,
'quantity' => 1,
]);
$p2 = Product::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
'product_key' => 'enterprise_plan',
'notes' => 'The Enterprise Plan',
'cost' => 14,
'price' => 14,
'quantity' => 1,
]);
'user_id' => $user->id,
'company_id' => $company->id,
'product_key' => 'enterprise_plan',
'notes' => 'The Enterprise Plan',
'cost' => 14,
'price' => 14,
'quantity' => 1,
]);
$p3 = Product::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
'product_key' => 'free_plan',
'notes' => 'The Free Plan',
'cost' => 0,
'price' => 0,
'quantity' => 1,
]);
'user_id' => $user->id,
'company_id' => $company->id,
'product_key' => 'free_plan',
'notes' => 'The Free Plan',
'cost' => 0,
'price' => 0,
'quantity' => 1,
]);
$webhook_config = [
'post_purchase_url' => 'http://ninja.test:8000/api/admin/plan',
@ -619,7 +625,7 @@ class CreateSingleAccount extends Command
$gateway_types = $cg->driver(new Client)->gatewayTypes();
$fees_and_limits = new \stdClass;
$fees_and_limits = new stdClass;
$fees_and_limits->{$gateway_types[0]} = new FeesAndLimits;
$cg->fees_and_limits = $fees_and_limits;
@ -642,7 +648,7 @@ class CreateSingleAccount extends Command
$gateway_types = $cg->driver(new Client)->gatewayTypes();
$fees_and_limits = new \stdClass;
$fees_and_limits = new stdClass;
$fees_and_limits->{$gateway_types[0]} = new FeesAndLimits;
$cg->fees_and_limits = $fees_and_limits;
@ -663,7 +669,7 @@ class CreateSingleAccount extends Command
$gateway_types = $cg->driver(new Client)->gatewayTypes();
$fees_and_limits = new \stdClass;
$fees_and_limits = new stdClass;
$fees_and_limits->{$gateway_types[0]} = new FeesAndLimits;
$cg->fees_and_limits = $fees_and_limits;
@ -684,11 +690,54 @@ class CreateSingleAccount extends Command
$gateway_types = $cg->driver(new Client)->gatewayTypes();
$fees_and_limits = new \stdClass;
$fees_and_limits = new stdClass;
$fees_and_limits->{$gateway_types[0]} = new FeesAndLimits;
$cg->fees_and_limits = $fees_and_limits;
$cg->save();
}
}
private function createRecurringInvoice($client)
{
$faker = Factory::create();
$invoice = RecurringInvoiceFactory::create($client->company->id, $client->user->id); //stub the company and user_id
$invoice->client_id = $client->id;
$dateable = Carbon::now()->subDays(rand(0, 90));
$invoice->date = $dateable;
$invoice->line_items = $this->buildLineItems(rand(1, 10));
$invoice->uses_inclusive_taxes = false;
if (rand(0, 1)) {
$invoice->tax_name1 = 'GST';
$invoice->tax_rate1 = 10.00;
}
if (rand(0, 1)) {
$invoice->tax_name2 = 'VAT';
$invoice->tax_rate2 = 17.50;
}
if (rand(0, 1)) {
$invoice->tax_name3 = 'CA Sales Tax';
$invoice->tax_rate3 = 5;
}
$invoice->custom_value1 = $faker->date;
$invoice->custom_value2 = rand(0, 1) ? 'yes' : 'no';
$invoice->status_id = RecurringInvoice::STATUS_ACTIVE;
$invoice->save();
$invoice_calc = new InvoiceSum($invoice);
$invoice_calc->build();
$invoice = $invoice_calc->getInvoice();
$invoice->save();
event(new RecurringInvoiceWasCreated($invoice, $invoice->company, Ninja::eventVars()));
}
}