mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
Add createRecurringInvoice($client) in CreateSingleAccount.php
This commit is contained in:
parent
22acc8f14c
commit
a6dc7a99fb
@ -14,9 +14,11 @@ namespace App\Console\Commands;
|
|||||||
use App\DataMapper\CompanySettings;
|
use App\DataMapper\CompanySettings;
|
||||||
use App\DataMapper\FeesAndLimits;
|
use App\DataMapper\FeesAndLimits;
|
||||||
use App\Events\Invoice\InvoiceWasCreated;
|
use App\Events\Invoice\InvoiceWasCreated;
|
||||||
|
use App\Events\RecurringInvoice\RecurringInvoiceWasCreated;
|
||||||
use App\Factory\GroupSettingFactory;
|
use App\Factory\GroupSettingFactory;
|
||||||
use App\Factory\InvoiceFactory;
|
use App\Factory\InvoiceFactory;
|
||||||
use App\Factory\InvoiceItemFactory;
|
use App\Factory\InvoiceItemFactory;
|
||||||
|
use App\Factory\RecurringInvoiceFactory;
|
||||||
use App\Factory\SubscriptionFactory;
|
use App\Factory\SubscriptionFactory;
|
||||||
use App\Helpers\Invoice\InvoiceSum;
|
use App\Helpers\Invoice\InvoiceSum;
|
||||||
use App\Jobs\Company\CreateCompanyTaskStatuses;
|
use App\Jobs\Company\CreateCompanyTaskStatuses;
|
||||||
@ -48,6 +50,7 @@ use Illuminate\Console\Command;
|
|||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use stdClass;
|
||||||
|
|
||||||
class CreateSingleAccount extends Command
|
class CreateSingleAccount extends Command
|
||||||
{
|
{
|
||||||
@ -225,16 +228,19 @@ class CreateSingleAccount extends Command
|
|||||||
|
|
||||||
$client = $company->clients->random();
|
$client = $company->clients->random();
|
||||||
|
|
||||||
$this->info('creating task for client #'.$client->id);
|
$this->info('creating task for client #' . $client->id);
|
||||||
$this->createTask($client);
|
$this->createTask($client);
|
||||||
|
|
||||||
$client = $company->clients->random();
|
$client = $company->clients->random();
|
||||||
|
|
||||||
$this->info('creating project for client #'.$client->id);
|
$this->info('creating project for client #' . $client->id);
|
||||||
$this->createProject($client);
|
$this->createProject($client);
|
||||||
|
|
||||||
$this->info('creating credit for client #'.$client->id);
|
$this->info('creating credit for client #' . $client->id);
|
||||||
$this->createCredit($client);
|
$this->createCredit($client);
|
||||||
|
|
||||||
|
$this->info('creating recurring invoice for client # ' . $client->id);
|
||||||
|
$this->createRecurringInvoice($client);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->createGateways($company, $user);
|
$this->createGateways($company, $user);
|
||||||
@ -249,34 +255,34 @@ class CreateSingleAccount extends Command
|
|||||||
$gs->save();
|
$gs->save();
|
||||||
|
|
||||||
$p1 = Product::factory()->create([
|
$p1 = Product::factory()->create([
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
'company_id' => $company->id,
|
'company_id' => $company->id,
|
||||||
'product_key' => 'pro_plan',
|
'product_key' => 'pro_plan',
|
||||||
'notes' => 'The Pro Plan',
|
'notes' => 'The Pro Plan',
|
||||||
'cost' => 10,
|
'cost' => 10,
|
||||||
'price' => 10,
|
'price' => 10,
|
||||||
'quantity' => 1,
|
'quantity' => 1,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$p2 = Product::factory()->create([
|
$p2 = Product::factory()->create([
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
'company_id' => $company->id,
|
'company_id' => $company->id,
|
||||||
'product_key' => 'enterprise_plan',
|
'product_key' => 'enterprise_plan',
|
||||||
'notes' => 'The Enterprise Plan',
|
'notes' => 'The Enterprise Plan',
|
||||||
'cost' => 14,
|
'cost' => 14,
|
||||||
'price' => 14,
|
'price' => 14,
|
||||||
'quantity' => 1,
|
'quantity' => 1,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$p3 = Product::factory()->create([
|
$p3 = Product::factory()->create([
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
'company_id' => $company->id,
|
'company_id' => $company->id,
|
||||||
'product_key' => 'free_plan',
|
'product_key' => 'free_plan',
|
||||||
'notes' => 'The Free Plan',
|
'notes' => 'The Free Plan',
|
||||||
'cost' => 0,
|
'cost' => 0,
|
||||||
'price' => 0,
|
'price' => 0,
|
||||||
'quantity' => 1,
|
'quantity' => 1,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$webhook_config = [
|
$webhook_config = [
|
||||||
'post_purchase_url' => 'http://ninja.test:8000/api/admin/plan',
|
'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();
|
$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;
|
$fees_and_limits->{$gateway_types[0]} = new FeesAndLimits;
|
||||||
|
|
||||||
$cg->fees_and_limits = $fees_and_limits;
|
$cg->fees_and_limits = $fees_and_limits;
|
||||||
@ -642,7 +648,7 @@ class CreateSingleAccount extends Command
|
|||||||
|
|
||||||
$gateway_types = $cg->driver(new Client)->gatewayTypes();
|
$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;
|
$fees_and_limits->{$gateway_types[0]} = new FeesAndLimits;
|
||||||
|
|
||||||
$cg->fees_and_limits = $fees_and_limits;
|
$cg->fees_and_limits = $fees_and_limits;
|
||||||
@ -663,7 +669,7 @@ class CreateSingleAccount extends Command
|
|||||||
|
|
||||||
$gateway_types = $cg->driver(new Client)->gatewayTypes();
|
$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;
|
$fees_and_limits->{$gateway_types[0]} = new FeesAndLimits;
|
||||||
|
|
||||||
$cg->fees_and_limits = $fees_and_limits;
|
$cg->fees_and_limits = $fees_and_limits;
|
||||||
@ -684,11 +690,54 @@ class CreateSingleAccount extends Command
|
|||||||
|
|
||||||
$gateway_types = $cg->driver(new Client)->gatewayTypes();
|
$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;
|
$fees_and_limits->{$gateway_types[0]} = new FeesAndLimits;
|
||||||
|
|
||||||
$cg->fees_and_limits = $fees_and_limits;
|
$cg->fees_and_limits = $fees_and_limits;
|
||||||
$cg->save();
|
$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()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user