Skip to content

Commit b59c085

Browse files
authored
Merge pull request #123 from devaslanphp/dev
Project - Company integration
2 parents e08af44 + f49470c commit b59c085

File tree

9 files changed

+107
-14
lines changed

9 files changed

+107
-14
lines changed

app/Http/Livewire/Kanban.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ protected function records(): Collection
4141
if (auth()->user()->can('View own tickets') && !auth()->user()->can('View all tickets')) {
4242
$query->where(function ($query) {
4343
$query->where('owner_id', auth()->user()->id)
44-
->orWhere('responsible_id', auth()->user()->id);
44+
->orWhere('responsible_id', auth()->user()->id)
45+
->orWhereHas('project', function ($query) {
46+
$query->whereHas('company', function ($query) {
47+
$query->whereIn('companies.id', auth()->user()->ownCompanies->pluck('id')->toArray());
48+
});
49+
});
4550
});
4651
}
4752
return $query->get()
@@ -55,15 +60,18 @@ protected function records(): Collection
5560
<div class="w-full flex items-center gap-2">
5661
' . ($type ? '
5762
<div title="' . $type['title'] . '"
58-
class="text-xs rounded-full w-6 h-6 flex items-center justify-center text-center"
59-
style="color: ' . $type->text_color . '; background-color: ' . $type->bg_color . ';"
63+
class="text-xs rounded-full w-6 h-6 flex items-center
64+
justify-center text-center"
65+
style="color: ' . $type->text_color . ';
66+
background-color: ' . $type->bg_color . ';"
6067
>
6168
<i class="fa ' . $type['icon'] . '"></i>
6269
</div>
6370
' : '') . '
6471
' . ($priority ? '
6572
<div title="' . $priority['title'] . '"
66-
class="text-xs rounded-full w-6 h-6 flex items-center justify-center text-center"
73+
class="text-xs rounded-full w-6 h-6 flex items-center
74+
justify-center text-center"
6775
style="
6876
color: ' . $priority->text_color . ';
6977
background-color: ' . $priority->bg_color . ';

app/Http/Livewire/Projects.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ class="' . $btnClass . '"
9292
UserColumn::make('owner')
9393
->label(__('Owner')),
9494

95+
TextColumn::make('company.name')
96+
->label(__('Company'))
97+
->sortable()
98+
->searchable(),
99+
95100
TextColumn::make('tickets_count')
96101
->label(__('Tickets'))
97102
->sortable(),

app/Http/Livewire/ProjectsDialog.php

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
namespace App\Http\Livewire;
44

55
use App\Core\CrudDialogHelper;
6+
use App\Models\Company;
67
use App\Models\Project;
78
use App\Models\User;
89
use App\Notifications\ProjectCreatedNotification;
10+
use Closure;
911
use Filament\Forms\Components\Grid;
1012
use Filament\Forms\Components\RichEditor;
1113
use Filament\Forms\Components\Select;
1214
use Filament\Forms\Components\TextInput;
1315
use Filament\Forms\Concerns\InteractsWithForms;
1416
use Filament\Forms\Contracts\HasForms;
15-
use Filament\Notifications\Actions\Action;
1617
use Filament\Notifications\Notification;
1718
use Livewire\Component;
1819

@@ -32,6 +33,7 @@ public function mount(): void
3233
'ticket_prefix' => $this->project->ticket_prefix,
3334
'description' => $this->project->description,
3435
'owner_id' => $this->project->owner_id ?? auth()->user()->id,
36+
'company_id' => $this->project->company_id
3537
]);
3638
}
3739

@@ -48,11 +50,40 @@ public function render()
4850
protected function getFormSchema(): array
4951
{
5052
return [
51-
Select::make('owner_id')
52-
->label(__('Owner'))
53-
->required()
54-
->searchable()
55-
->options(User::all()->pluck('name', 'id')),
53+
Grid::make()
54+
->schema([
55+
Select::make('owner_id')
56+
->label(__('Owner'))
57+
->required()
58+
->searchable()
59+
->reactive()
60+
->options(function () {
61+
$query = User::query();
62+
if (auth()->user()->can('View company users') && !auth()->user()->can('View all users')) {
63+
$query->whereHas(
64+
'companies',
65+
fn($query) => $query->whereIn(
66+
'companies.id',
67+
auth()->user()->ownCompanies->pluck('id')->toArray()
68+
)
69+
)->orWhere('id', auth()->user()->id);
70+
}
71+
return $query->get()->pluck('name', 'id')->toArray();
72+
}),
73+
74+
Select::make('company_id')
75+
->label(__('Company'))
76+
->searchable()
77+
->options(function (Closure $get) {
78+
$query = Company::query();
79+
if ($get('owner_id')) {
80+
$query->where('responsible_id', $get('owner_id'));
81+
} elseif (auth()->user()->can('View own companies')) {
82+
$query->where('responsible_id', auth()->user()->id);
83+
}
84+
return $query->get()->pluck('name', 'id')->toArray();
85+
}),
86+
]),
5687

5788
Grid::make(3)
5889
->schema([
@@ -92,7 +123,8 @@ public function save(): void
92123
'name' => $data['name'],
93124
'description' => $data['description'],
94125
'owner_id' => $data['owner_id'],
95-
'ticket_prefix' => $data['ticket_prefix']
126+
'ticket_prefix' => $data['ticket_prefix'],
127+
'company_id' => $data['company_id'],
96128
]);
97129
Notification::make()
98130
->success()
@@ -103,6 +135,7 @@ public function save(): void
103135
$this->project->name = $data['name'];
104136
$this->project->description = $data['description'];
105137
$this->project->owner_id = $data['owner_id'];
138+
$this->project->company_id = $data['company_id'];
106139
$this->project->ticket_prefix = $data['ticket_prefix'];
107140
$this->project->save();
108141
Notification::make()

app/Http/Livewire/Tickets.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ public function render()
5252
if (auth()->user()->can('View own tickets') && !auth()->user()->can('View all tickets')) {
5353
$query->where(function ($query) {
5454
$query->where('owner_id', auth()->user()->id)
55-
->orWhere('responsible_id', auth()->user()->id);
55+
->orWhere('responsible_id', auth()->user()->id)
56+
->orWhereHas('project', function ($query) {
57+
$query->whereHas('company', function ($query) {
58+
$query->whereIn('companies.id', auth()->user()->ownCompanies->pluck('id')->toArray());
59+
});
60+
});
5661
});
5762
}
5863
if ($this->activeMenu === 'Unassigned') {

app/Models/Project.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class Project extends Model implements HasLogsActivity
2020
'name',
2121
'description',
2222
'owner_id',
23-
'ticket_prefix'
23+
'ticket_prefix',
24+
'company_id'
2425
];
2526

2627
protected static function boot()
@@ -36,6 +37,11 @@ public function owner(): BelongsTo
3637
return $this->belongsTo(User::class, 'owner_id')->withTrashed();
3738
}
3839

40+
public function company(): BelongsTo
41+
{
42+
return $this->belongsTo(Company::class);
43+
}
44+
3945
public function tickets(): HasMany
4046
{
4147
return $this->hasMany(Ticket::class);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration {
8+
/**
9+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up()
14+
{
15+
Schema::table('projects', function (Blueprint $table) {
16+
$table->foreignId('company_id')->nullable()->constrained('companies');
17+
});
18+
}
19+
20+
/**
21+
* Reverse the migrations.
22+
*
23+
* @return void
24+
*/
25+
public function down()
26+
{
27+
Schema::table('projects', function (Blueprint $table) {
28+
$table->dropForeign(['company_id']);
29+
$table->dropColumn('company_id');
30+
});
31+
}
32+
};

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Help Desk is a Laravel based project, that let you manage your support tickets a
44

55
> Help Desk is based on the latest version of Laravel and any other Open Source packages and technologies.
66
7-
- **Current version:** *v1.4.6*
7+
- **Current version:** *v1.4.7*
88
- **Last update:** *30 September, 2022*
99

1010
## Features

docs/changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
See what's new added, changed, fixed, improved or updated in the latest versions.
44

5+
- **Version 1.4.7** *(30 September, 2022)*
6+
- Project - Company integration
7+
58
- **Version 1.4.6** *(30 September, 2022)*
69
- Bug-fix: assign all roles
710

lang/fr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@
286286
"Type a message..": "Tapez un message..",
287287
"Send": "Envoyer",
288288
"No messages yet!": "Aucun message pour le moment !",
289+
"Company": "Entreprise",
289290
"Company name": "Nom de l'entreprise",
290291
"Logo": "Logo",
291292
"Companies": "Entreprises",

0 commit comments

Comments
 (0)