Esempio n. 1
0
 public function create(Task $task)
 {
     if ($task->invoice_id) {
         return redirect()->route('invoice.edit', $task->invoice_id);
     }
     $client = $task->project->client ? $task->project->client->name : '';
     $invoice = new Invoice(['name' => ($client ?: 'Invoice') . ' ' . date('Y-m-d'), 'issued_at' => date('Y-m-d'), 'invoiceno' => $task->project->company->invoiceno + 1, 'client_name' => $client ?: '', 'company_name' => $task->project->company->name, 'items' => [['name' => $task->name, 'description' => $task->description, 'rate' => 10, 'hours' => round($task->loggedTotal()), 'total' => 0]], 'company_id' => $task->project->company_id, 'client_id' => $task->project->client_id, 'project_id' => $task->project_id]);
     $task->project->company->update(['invoiceno' => $task->project->company->invoiceno + 1]);
     $invoice->save();
     $task->invoice_id = $invoice->id;
     $task->save();
     return view('invoice.editor', ['invoice' => $invoice]);
 }