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]); }
public function run() { $this->truncate(); $faker = Faker::create(); factory(User::class, User::ROLE_ROOT)->create(); echo "Creating Companies..." . PHP_EOL; $no_companies = rand(2, 3); factory(Company::class, $no_companies)->create(); echo "Created {$no_companies} companies." . PHP_EOL; foreach (Company::all() as $company) { $company_id = $company->id; echo "Processing company {$company_id}..." . PHP_EOL; echo "Creating users ..." . PHP_EOL; factory(User::class, User::ROLE_MANAGER)->create(['company_id' => $company_id]); //Create the general admin $devs = factory(User::class, User::ROLE_DEV, rand(5, 7))->create(['company_id' => $company_id]); $clients = factory(User::class, User::ROLE_CLIENT, rand(1, 3))->create(['company_id' => $company_id]); echo "Creating projects ..." . PHP_EOL; foreach (range(1, rand(5, 9)) as $i) { factory(Project::class)->create(['company_id' => $company_id, 'client_id' => $faker->randomElement($clients->lists('id')->all())]); } $projects = $company->projects(); echo "Creating tasks ..." . PHP_EOL; foreach (range(1, rand(15, 20)) as $i) { $root = factory(Task::class)->create(['project_id' => $faker->randomElement($projects->lists('id')->all())]); for ($j = 1; $j <= rand(0, 3); $j++) { $task = factory(Task::class)->create(['project_id' => $root->project_id]); $task->makeChildOf($root); //Coin flip for subtask if ($faker->boolean()) { $subTask = factory(Task::class)->create(['project_id' => $root->project_id]); $subTask->makeChildOf($task); } } } echo "Creating activities and comments ..." . PHP_EOL; $tasks = Task::whereIn('project_id', $projects->lists('id')->all())->get(); foreach ($tasks as $task) { foreach (range(1, rand(2, 10)) as $i) { factory(Activity::class)->create(['project_id' => $task->project_id, 'task_id' => $task->id, 'user_id' => $faker->randomElement($devs->lists('id')->all())]); } foreach (range(1, rand(2, 10)) as $i) { factory(Comment::class)->create(['project_id' => $task->project_id, 'task_id' => $task->id, 'user_id' => $faker->randomElement($devs->lists('id')->all())]); } } foreach ($devs as $dev) { $dev->projects()->sync($faker->randomElements($projects->lists('id')->all(), rand(3, 4))); } echo "Creating invoices ..." . PHP_EOL; foreach (range(1, rand(40, 60)) as $i) { factory(Invoice::class)->create(['company_id' => $company_id, 'project_id' => $faker->randomElement($projects->lists('id')->all()), 'invoiceno' => $i]); } $company->update(['invoiceno' => ++$i]); echo "Company done." . PHP_EOL; } echo PHP_EOL . "Everything done, thanks for waiting!" . PHP_EOL; }
public function chart(Project $project) { $tasks = Task::getGanttHierarchy($project->tasks(true)->get()); $path = new CriticalPath($tasks); $dates = []; for ($cursor = $project->from; $cursor->lte($project->to); $cursor = $cursor->addDay()) { $dates[] = $cursor->format('Y-m-d'); } //dd($path->GetChart()); return view('manage/chart', ['dates' => $dates, 'tasks' => $path->GetChart(), 'project' => $project]); }
Route::delete('tasks/{task}', 'ManagerController@deleteTask')->name('manager.tasks.delete'); Route::get('{project}/timesheet', 'ManagerController@timesheet')->name('manager.timesheet'); Route::get('{project}/timesheet/create', 'ManagerController@createActivity')->name('manager.timesheet.create'); Route::get('{project}/timesheet/{activity}/edit', 'ManagerController@editActivity')->name('manager.timesheet.edit'); Route::post('{project}/timesheet', 'ManagerController@storeActivity')->name('manager.timesheet.store'); Route::put('{project}/timesheet/{activity}', 'ManagerController@updateActivity')->name('manager.timesheet.update'); Route::delete('timesheet/{activity}', 'ManagerController@deleteActivity')->name('manager.timesheet.delete'); Route::get('{project}/chart', 'ManagerController@chart')->name('manager.chart'); Route::get('{project}/feed', 'ManagerController@feed')->name('manager.feed'); }); Route::group(['prefix' => 'invoice'], function () { Route::get('/', 'InvoiceController@index')->name('invoices'); Route::get('create/{task}', 'InvoiceController@create')->name('invoice.create'); Route::post('/', 'InvoiceController@store')->name('invoice.store'); Route::get('{invoice}', 'InvoiceController@edit')->name('invoice.edit'); Route::put('{invoice}', 'InvoiceController@update')->name('invoice.update'); Route::delete('{invoice}', 'InvoiceController@destroy')->name('invoice.delete'); }); Route::group(['prefix' => 'settings'], function () { Route::get('/', 'SettingsController@userSettings')->name('settings.user'); Route::get('company', 'SettingsController@companySettings')->name('settings.company'); Route::post('{company}', 'SettingsController@updateCompany')->name('settings.company.update'); Route::post('{company}/user', 'SettingsController@storeUser')->name('settings.userstore'); Route::put('{company}/user/{user}', 'SettingsController@updateUser')->name('settings.userupdate'); }); }); Route::get('test', function () { $task = \Treabar\Models\Task::find(1); $task->delete(); dd($task, $task->activities); });