client = $client; } /** * Execute the job. * * @return void */ public function handle() { $faker = \Faker\Factory::create(); $credit = factory(\App\Models\Credit::class)->create(['user_id' => $this->client->user->id, 'company_id' => $this->client->company->id, 'client_id' => $this->client->id]); //$invoice = InvoiceFactory::create($this->client->company->id, $this->client->user->id);//stub the company and user_id //$invoice->client_id = $this->client->id; // $invoice->date = $faker->date(); $dateable = Carbon::now()->subDays(rand(0, 90)); $credit->date = $dateable; $credit->line_items = $this->buildLineItems(rand(1, 10)); $credit->uses_inclusive_taxes = false; if (rand(0, 1)) { $credit->tax_name1 = 'GST'; $credit->tax_rate1 = 10.00; } if (rand(0, 1)) { $credit->tax_name2 = 'VAT'; $credit->tax_rate2 = 17.50; } if (rand(0, 1)) { $credit->tax_name3 = 'CA Sales Tax'; $credit->tax_rate3 = 5; } $credit->save(); $invoice_calc = new InvoiceSum($credit); $invoice_calc->build(); $credit = $invoice_calc->getCredit(); $credit->save(); event(new CreateCreditInvitation($credit, $credit->company, Ninja::eventVars())); } 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; } }