Skip to content
This repository has been archived by the owner on Jun 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #344 from InfyOmLabs/develop
Browse files Browse the repository at this point in the history
Release V1.8.3-alpha
  • Loading branch information
mitulgolakiya authored Sep 10, 2019
2 parents 9b78c57 + e5f4021 commit 3f34648
Show file tree
Hide file tree
Showing 72 changed files with 628 additions and 306 deletions.
5 changes: 5 additions & 0 deletions app/Http/Controllers/ActivityTypeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ public function update(ActivityType $activityType, UpdateActivityTypeRequest $re
*/
public function destroy(ActivityType $activityType)
{
if ($activityType->timeEntries()->count() > 0) {
return $this->sendError('This activity has more than one time entry, so it can\'t be deleted.');
}

$activityType->update(['deleted_by' => getLoggedInUserId()]);
$activityType->delete();

return $this->sendSuccess('Activity Type deleted successfully.');
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ClientController.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function update(Client $client, UpdateClientRequest $request)
*/
public function destroy(Client $client)
{
$client->delete();
$this->clientRepository->delete($client->id);

return $this->sendSuccess('Client deleted successfully.');
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function update(Project $project, UpdateProjectRequest $request)
*/
public function destroy(Project $project)
{
$project->delete();
$this->projectRepository->delete($project->id);

return $this->sendSuccess('Project deleted successfully.');
}
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/TagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public function update(Tag $tag, UpdateTagRequest $request)
*/
public function destroy(Tag $tag)
{
$tag->deleted_by = getLoggedInUserId();
$tag->save();
$tag->delete();

return $this->sendSuccess('Tag deleted successfully.');
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ public function update(User $user, UpdateUserRequest $request)
*/
public function destroy(User $user)
{
$user->deleted_by = getLoggedInUserId();
$user->save();
$user->delete();

return $this->sendSuccess('User deleted successfully.');
Expand Down
14 changes: 11 additions & 3 deletions app/Models/ActivityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
* App\Models\ActivityType.
Expand All @@ -26,10 +27,11 @@
*/
class ActivityType extends Model
{
use SoftDeletes;
public $table = 'activity_types';

public $fillable = [
'name',
'name', 'created_by', 'deleted_by',
];

/**
Expand All @@ -38,8 +40,9 @@ class ActivityType extends Model
* @var array
*/
protected $casts = [
'id' => 'integer',
'name' => 'string',
'id' => 'integer',
'name' => 'string',
'created_by' => 'integer',
];

const ACTIVITY_TYPES = [
Expand Down Expand Up @@ -70,4 +73,9 @@ public function createdUser()
{
return $this->belongsTo(User::class, 'created_by');
}

public function timeEntries()
{
return $this->hasMany(TimeEntry::class, 'activity_type_id');
}
}
11 changes: 11 additions & 0 deletions app/Models/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
* App\Models\Client.
Expand Down Expand Up @@ -30,13 +31,15 @@
*/
class Client extends Model
{
use softDeletes;
public $table = 'clients';

public $fillable = [
'name',
'email',
'website',
'created_by',
'deleted_by',
];

/**
Expand Down Expand Up @@ -79,4 +82,12 @@ public function createdUser()
{
return $this->belongsTo(User::class, 'created_by');
}

/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function projects()
{
return $this->hasMany(Project::class);
}
}
11 changes: 11 additions & 0 deletions app/Models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
* App\Models\Project.
Expand Down Expand Up @@ -36,6 +37,7 @@
*/
class Project extends Model
{
use softDeletes;
const TEAM_ARR = ['1' => 'Backend', '2' => 'Frontend', '3' => 'Mobile', '4' => 'QA'];

public $table = 'projects';
Expand All @@ -46,6 +48,7 @@ class Project extends Model
'description',
'client_id',
'created_by',
'deleted_by',
'prefix',
];

Expand Down Expand Up @@ -111,4 +114,12 @@ public function createdUser()
{
return $this->belongsTo(User::class, 'created_by');
}

/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function tasks()
{
return $this->hasMany(Task::class);
}
}
4 changes: 4 additions & 0 deletions app/Models/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
* App\Models\Tag.
Expand All @@ -26,11 +27,13 @@
*/
class Tag extends Model
{
use softDeletes;
public $table = 'tags';

public $fillable = [
'name',
'created_by',
'deleted_by',
];

/**
Expand All @@ -42,6 +45,7 @@ class Tag extends Model
'id' => 'integer',
'name' => 'string',
'created_by' => 'integer',
'deleted_by' => 'integer',
];

/**
Expand Down
12 changes: 11 additions & 1 deletion app/Models/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function tags()
*/
public function project()
{
return $this->belongsTo(Project::class, 'project_id');
return $this->belongsTo(Project::class, 'project_id')->withTrashed();
}

/**
Expand Down Expand Up @@ -162,6 +162,16 @@ public function timeEntries()
return $this->hasMany(TimeEntry::class, 'task_id')->latest();
}

public static function boot()
{
parent::boot();

static::deleting(function ($task) {
$task->timeEntries()->update(['deleted_by' => getLoggedInUserId()]);
$task->timeEntries()->delete();
});
}

/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
Expand Down
12 changes: 10 additions & 2 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Notifications\MailResetPasswordNotification;
use App\Traits\ImageTrait;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Zizaco\Entrust\Traits\EntrustUserTrait;
Expand Down Expand Up @@ -60,10 +61,16 @@
*/
class User extends Authenticatable
{
use Notifiable, EntrustUserTrait, ImageTrait;
use Notifiable, ImageTrait, softDeletes, EntrustUserTrait {
SoftDeletes::restore insteadof EntrustUserTrait;
EntrustUserTrait::restore insteadof SoftDeletes;
}
use ImageTrait {
deleteImage as traitDeleteImage;
}
use SoftDeletes {
restore as restoreSoftDeletes;
}

public $table = 'users';
const IMAGE_PATH = 'users';
Expand All @@ -84,6 +91,7 @@ class User extends Authenticatable
'activation_code',
'is_active',
'image_path',
'deleted_by',
];

/**
Expand Down Expand Up @@ -175,7 +183,7 @@ public function getImagePathAttribute($value)
return $this->imageUrl(self::IMAGE_PATH.DIRECTORY_SEPARATOR.$value);
}

return asset('assets/img/user-avatar.png');
return getUserImageInitial($this->id, $this->name);
}

/**
Expand Down
22 changes: 13 additions & 9 deletions app/Queries/TimeEntryDataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,19 @@ function (Builder $q) use ($input) {
$q->where('activity_type_id', $input['filter_activity']);
});
$query->when(isset($input['filter_project']) && !empty($input['filter_project']),
function (Builder $q) use ($input) {
$filterUserId = (isset($input['filter_user']) && !empty($input['filter_user'])) ? $input['filter_user'] : getLoggedInUser()->id;
$taskIds = Task::whereProjectId($input['filter_project'])
->where(function ($q) use ($filterUserId) {
$q->whereHas('taskAssignee', function ($q) use ($filterUserId) {
$q->where('user_id', $filterUserId);
});
})->get()->pluck('id')->toArray();
$q->whereIn('task_id', $taskIds);
function (Builder $q) use ($input,$user) {
if ($user->can('manage_time_entries')) {
$taskIds = Task::whereProjectId($input['filter_project'])->get()->pluck('id')->toArray();
$q->whereIn('task_id', $taskIds);
} else {
$taskIds = Task::whereProjectId($input['filter_project'])
->where(function ($q) {
$q->whereHas('taskAssignee', function ($q) {
$q->where('user_id', getLoggedInUserId());
});
})->get()->pluck('id')->toArray();
$q->whereIn('task_id', $taskIds);
}
});
if (!$user->can('manage_time_entries')) {
return $query->OfCurrentUser();
Expand Down
30 changes: 30 additions & 0 deletions app/Repositories/ClientRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
namespace App\Repositories;

use App\Models\Client;
use App\Models\Project;
use App\Models\Task;
use App\Models\TimeEntry;

/**
* Class ClientRepository.
Expand Down Expand Up @@ -47,4 +50,31 @@ public function getClientList()
{
return Client::orderBy('name')->pluck('name', 'id');
}

/**
* @param int $clientId
*
* @throws \Exception
*
* @return bool|mixed|void|null
*/
public function delete($clientId)
{
$client = $this->find($clientId);

$projectIds = Project::where('client_id', '=', $client->id)->get()->pluck('id');
$taskIds = Task::whereIn('project_id', $projectIds)->get()->pluck('id');

TimeEntry::whereIn('task_id', $taskIds)->update(['deleted_by' => getLoggedInUserId()]);
TimeEntry::whereIn('task_id', $taskIds)->delete();

Task::whereIn('project_id', $projectIds)->update(['deleted_by' => getLoggedInUserId()]);
Task::whereIn('project_id', $projectIds)->delete();

$client->projects()->update(['deleted_by' => getLoggedInUserId()]);
$client->projects()->delete();

$client->update(['deleted_by' => getLoggedInUserId()]);
$client->delete();
}
}
24 changes: 24 additions & 0 deletions app/Repositories/ProjectRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace App\Repositories;

use App\Models\Project;
use App\Models\Task;
use App\Models\TimeEntry;
use Auth;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;
Expand Down Expand Up @@ -88,4 +90,26 @@ public function getProjectsList($clientId = null)

return $query->pluck('name', 'id');
}

/**
* @param int $id
*
* @throws \Exception
*
* @return bool|mixed|void|null
*/
public function delete($id)
{
$project = $this->find($id);

$taskIds = Task::whereProjectId($project->id)->pluck('id')->toArray();
TimeEntry::whereIn('task_id', $taskIds)->update(['deleted_by' => getLoggedInUserId()]);
TimeEntry::whereIn('task_id', $taskIds)->delete();

$project->tasks()->update(['deleted_by' => getLoggedInUserId()]);
$project->tasks()->delete();

$project->update(['deleted_by' => getLoggedInUserId()]);
$project->delete();
}
}
5 changes: 1 addition & 4 deletions app/Repositories/ReportRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,6 @@ public function getReport($report)
$project = $entry->task->project;
$client = $project->client;
$duration = $entry->duration;
$projectPrefix = $project->prefix;
$taskNumber = $entry->task->task_number;

// prepare client and duration
$result[$clientId]['name'] = $client->name;
Expand Down Expand Up @@ -308,8 +306,7 @@ public function getReport($report)
$time = $result[$clientId]['projects'][$project->id]['users'][$entry->user_id]['tasks'][$entry->task_id]['duration'] + $entry->duration;
$result[$clientId]['projects'][$project->id]['users'][$entry->user_id]['tasks'][$entry->task_id]['duration'] = $time;
$result[$clientId]['projects'][$project->id]['users'][$entry->user_id]['tasks'][$entry->task_id]['time'] = $this->getDurationTime($time);
$result[$clientId]['projects'][$project->id]['users'][$entry->user_id]['tasks'][$entry->task_id]['project_prefix'] = $projectPrefix;
$result[$clientId]['projects'][$project->id]['users'][$entry->user_id]['tasks'][$entry->task_id]['task_number'] = $taskNumber;
$result[$clientId]['projects'][$project->id]['users'][$entry->user_id]['tasks'][$entry->task_id]['task_id'] = $entry->task->id;
}

return $result;
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "infyomlabs/infy-tracker",
"type": "project",
"version": "1.8.2-alpha",
"version": "1.8.3-alpha",
"description": "Create Projects / Tasks, Track Time, Show Daily Reports",
"keywords": [
"time",
Expand Down
Loading

0 comments on commit 3f34648

Please sign in to comment.