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; } }