mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-14 07:02:34 +01:00
43e57d0117
* minor fix for payment notifications * styleci * Limit Self updating to self hosters only : * Fixes for designs * Minor fixes for self-update
136 lines
3.4 KiB
PHP
136 lines
3.4 KiB
PHP
<?php
|
|
/**
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
*
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
*
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
|
*
|
|
* @license https://opensource.org/licenses/AAL
|
|
*/
|
|
|
|
namespace App\Console\Commands\TestData;
|
|
|
|
use App\Events\Invoice\InvoiceWasCreated;
|
|
use App\Events\Payment\PaymentWasCreated;
|
|
use App\Factory\InvoiceFactory;
|
|
use App\Factory\InvoiceItemFactory;
|
|
use App\Factory\PaymentFactory;
|
|
use App\Helpers\Invoice\InvoiceSum;
|
|
use App\Jobs\Quote\CreateQuoteInvitations;
|
|
use App\Models\Client;
|
|
use App\Models\Payment;
|
|
use App\Models\PaymentType;
|
|
use App\Models\Product;
|
|
use App\Utils\Traits\MakesHash;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class CreateTestQuoteJob implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, MakesHash;
|
|
|
|
protected $client;
|
|
|
|
|
|
/**
|
|
* Create a new job instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
|
|
public function __construct(Client $client)
|
|
{
|
|
$this->client = $client;
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function handle()
|
|
{
|
|
$faker = \Faker\Factory::create();
|
|
|
|
$quote =factory(\App\Models\Quote::class)->create(['user_id' => $this->client->user->id, 'company_id' => $this->client->company->id, 'client_id' => $this->client->id]);
|
|
$quote->date = $faker->date();
|
|
|
|
$quote->line_items = $this->buildLineItems(rand(1, 10));
|
|
$quote->uses_inclusive_taxes = false;
|
|
|
|
if (rand(0, 1)) {
|
|
$quote->tax_name1 = 'GST';
|
|
$quote->tax_rate1 = 10.00;
|
|
}
|
|
|
|
if (rand(0, 1)) {
|
|
$quote->tax_name2 = 'VAT';
|
|
$quote->tax_rate2 = 17.50;
|
|
}
|
|
|
|
if (rand(0, 1)) {
|
|
$quote->tax_name3 = 'CA Sales Tax';
|
|
$quote->tax_rate3 = 5;
|
|
}
|
|
|
|
$quote->save();
|
|
|
|
$quote_calc = new InvoiceSum($quote);
|
|
$quote_calc->build();
|
|
|
|
$quote = $quote_calc->getQuote();
|
|
$quote->service()->markSent()->save();
|
|
|
|
CreateQuoteInvitations::dispatch($quote, $quote->company);
|
|
}
|
|
|
|
|
|
|
|
private function buildLineItems($count = 1)
|
|
{
|
|
$line_items = [];
|
|
|
|
for ($x=0; $x<$count; $x++) {
|
|
$item = InvoiceItemFactory::create();
|
|
$item->quantity = 1;
|
|
//$item->cost = 10;
|
|
|
|
if (rand(0, 1)) {
|
|
$item->tax_name1 = 'GST';
|
|
$item->tax_rate1 = 10.00;
|
|
}
|
|
|
|
if (rand(0, 1)) {
|
|
$item->tax_name1 = 'VAT';
|
|
$item->tax_rate1 = 17.50;
|
|
}
|
|
|
|
if (rand(0, 1)) {
|
|
$item->tax_name1 = 'Sales Tax';
|
|
$item->tax_rate1 = 5;
|
|
}
|
|
|
|
$product = Product::all()->random();
|
|
|
|
$item->cost = (float)$product->cost;
|
|
$item->product_key = $product->product_key;
|
|
$item->notes = $product->notes;
|
|
$item->custom_value1 = $product->custom_value1;
|
|
$item->custom_value2 = $product->custom_value2;
|
|
$item->custom_value3 = $product->custom_value3;
|
|
$item->custom_value4 = $product->custom_value4;
|
|
|
|
|
|
|
|
$line_items[] = $item;
|
|
}
|
|
|
|
return $line_items;
|
|
}
|
|
}
|