invoice_items() public method

public invoice_items ( ) : mixed
return mixed
Ejemplo n.º 1
0
 public function createNinjaInvoice($client)
 {
     $account = $this->getNinjaAccount();
     $lastInvoice = Invoice::withTrashed()->whereAccountId($account->id)->orderBy('public_id', 'DESC')->first();
     $publicId = $lastInvoice ? $lastInvoice->public_id + 1 : 1;
     $invoice = new Invoice();
     $invoice->account_id = $account->id;
     $invoice->user_id = $account->users()->first()->id;
     $invoice->public_id = $publicId;
     $invoice->client_id = $client->id;
     $invoice->invoice_number = $account->getNextInvoiceNumber();
     $invoice->invoice_date = date_create()->format('Y-m-d');
     $invoice->amount = PRO_PLAN_PRICE;
     $invoice->balance = PRO_PLAN_PRICE;
     $invoice->save();
     $item = new InvoiceItem();
     $item->account_id = $account->id;
     $item->user_id = $account->users()->first()->id;
     $item->public_id = $publicId;
     $item->qty = 1;
     $item->cost = PRO_PLAN_PRICE;
     $item->notes = trans('texts.pro_plan_description');
     $item->product_key = trans('texts.pro_plan_product');
     $invoice->invoice_items()->save($item);
     $invitation = new Invitation();
     $invitation->account_id = $account->id;
     $invitation->user_id = $account->users()->first()->id;
     $invitation->public_id = $publicId;
     $invitation->invoice_id = $invoice->id;
     $invitation->contact_id = $client->contacts()->first()->id;
     $invitation->invitation_key = str_random(RANDOM_KEY_LENGTH);
     $invitation->save();
     return $invitation;
 }