diff --git a/app/Http/Livewire/Kanban.php b/app/Http/Livewire/Kanban.php
index 6b885e2..2099124 100644
--- a/app/Http/Livewire/Kanban.php
+++ b/app/Http/Livewire/Kanban.php
@@ -41,7 +41,12 @@ protected function records(): Collection
if (auth()->user()->can('View own tickets') && !auth()->user()->can('View all tickets')) {
$query->where(function ($query) {
$query->where('owner_id', auth()->user()->id)
- ->orWhere('responsible_id', auth()->user()->id);
+ ->orWhere('responsible_id', auth()->user()->id)
+ ->orWhereHas('project', function ($query) {
+ $query->whereHas('company', function ($query) {
+ $query->whereIn('companies.id', auth()->user()->ownCompanies->pluck('id')->toArray());
+ });
+ });
});
}
return $query->get()
@@ -55,15 +60,18 @@ protected function records(): Collection
' . ($type ? '
' : '') . '
' . ($priority ? '
label(__('Owner')),
+ TextColumn::make('company.name')
+ ->label(__('Company'))
+ ->sortable()
+ ->searchable(),
+
TextColumn::make('tickets_count')
->label(__('Tickets'))
->sortable(),
diff --git a/app/Http/Livewire/ProjectsDialog.php b/app/Http/Livewire/ProjectsDialog.php
index 80eaadc..e6fbec5 100644
--- a/app/Http/Livewire/ProjectsDialog.php
+++ b/app/Http/Livewire/ProjectsDialog.php
@@ -3,16 +3,17 @@
namespace App\Http\Livewire;
use App\Core\CrudDialogHelper;
+use App\Models\Company;
use App\Models\Project;
use App\Models\User;
use App\Notifications\ProjectCreatedNotification;
+use Closure;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
-use Filament\Notifications\Actions\Action;
use Filament\Notifications\Notification;
use Livewire\Component;
@@ -32,6 +33,7 @@ public function mount(): void
'ticket_prefix' => $this->project->ticket_prefix,
'description' => $this->project->description,
'owner_id' => $this->project->owner_id ?? auth()->user()->id,
+ 'company_id' => $this->project->company_id
]);
}
@@ -48,11 +50,40 @@ public function render()
protected function getFormSchema(): array
{
return [
- Select::make('owner_id')
- ->label(__('Owner'))
- ->required()
- ->searchable()
- ->options(User::all()->pluck('name', 'id')),
+ Grid::make()
+ ->schema([
+ Select::make('owner_id')
+ ->label(__('Owner'))
+ ->required()
+ ->searchable()
+ ->reactive()
+ ->options(function () {
+ $query = User::query();
+ if (auth()->user()->can('View company users') && !auth()->user()->can('View all users')) {
+ $query->whereHas(
+ 'companies',
+ fn($query) => $query->whereIn(
+ 'companies.id',
+ auth()->user()->ownCompanies->pluck('id')->toArray()
+ )
+ )->orWhere('id', auth()->user()->id);
+ }
+ return $query->get()->pluck('name', 'id')->toArray();
+ }),
+
+ Select::make('company_id')
+ ->label(__('Company'))
+ ->searchable()
+ ->options(function (Closure $get) {
+ $query = Company::query();
+ if ($get('owner_id')) {
+ $query->where('responsible_id', $get('owner_id'));
+ } elseif (auth()->user()->can('View own companies')) {
+ $query->where('responsible_id', auth()->user()->id);
+ }
+ return $query->get()->pluck('name', 'id')->toArray();
+ }),
+ ]),
Grid::make(3)
->schema([
@@ -92,7 +123,8 @@ public function save(): void
'name' => $data['name'],
'description' => $data['description'],
'owner_id' => $data['owner_id'],
- 'ticket_prefix' => $data['ticket_prefix']
+ 'ticket_prefix' => $data['ticket_prefix'],
+ 'company_id' => $data['company_id'],
]);
Notification::make()
->success()
@@ -103,6 +135,7 @@ public function save(): void
$this->project->name = $data['name'];
$this->project->description = $data['description'];
$this->project->owner_id = $data['owner_id'];
+ $this->project->company_id = $data['company_id'];
$this->project->ticket_prefix = $data['ticket_prefix'];
$this->project->save();
Notification::make()
diff --git a/app/Http/Livewire/Tickets.php b/app/Http/Livewire/Tickets.php
index 12ee473..62b47ec 100644
--- a/app/Http/Livewire/Tickets.php
+++ b/app/Http/Livewire/Tickets.php
@@ -52,7 +52,12 @@ public function render()
if (auth()->user()->can('View own tickets') && !auth()->user()->can('View all tickets')) {
$query->where(function ($query) {
$query->where('owner_id', auth()->user()->id)
- ->orWhere('responsible_id', auth()->user()->id);
+ ->orWhere('responsible_id', auth()->user()->id)
+ ->orWhereHas('project', function ($query) {
+ $query->whereHas('company', function ($query) {
+ $query->whereIn('companies.id', auth()->user()->ownCompanies->pluck('id')->toArray());
+ });
+ });
});
}
if ($this->activeMenu === 'Unassigned') {
diff --git a/app/Models/Project.php b/app/Models/Project.php
index 3f7edb8..ae089a2 100644
--- a/app/Models/Project.php
+++ b/app/Models/Project.php
@@ -20,7 +20,8 @@ class Project extends Model implements HasLogsActivity
'name',
'description',
'owner_id',
- 'ticket_prefix'
+ 'ticket_prefix',
+ 'company_id'
];
protected static function boot()
@@ -36,6 +37,11 @@ public function owner(): BelongsTo
return $this->belongsTo(User::class, 'owner_id')->withTrashed();
}
+ public function company(): BelongsTo
+ {
+ return $this->belongsTo(Company::class);
+ }
+
public function tickets(): HasMany
{
return $this->hasMany(Ticket::class);
diff --git a/database/migrations/2022_09_30_133603_add_company_id_to_projects.php b/database/migrations/2022_09_30_133603_add_company_id_to_projects.php
new file mode 100644
index 0000000..3813886
--- /dev/null
+++ b/database/migrations/2022_09_30_133603_add_company_id_to_projects.php
@@ -0,0 +1,32 @@
+foreignId('company_id')->nullable()->constrained('companies');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('projects', function (Blueprint $table) {
+ $table->dropForeign(['company_id']);
+ $table->dropColumn('company_id');
+ });
+ }
+};
diff --git a/docs/README.md b/docs/README.md
index 1b22994..765532f 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -4,7 +4,7 @@ Help Desk is a Laravel based project, that let you manage your support tickets a
> Help Desk is based on the latest version of Laravel and any other Open Source packages and technologies.
-- **Current version:** *v1.4.6*
+- **Current version:** *v1.4.7*
- **Last update:** *30 September, 2022*
## Features
diff --git a/docs/changelog.md b/docs/changelog.md
index d18a9bb..8359d93 100644
--- a/docs/changelog.md
+++ b/docs/changelog.md
@@ -2,6 +2,9 @@
See what's new added, changed, fixed, improved or updated in the latest versions.
+- **Version 1.4.7** *(30 September, 2022)*
+ - Project - Company integration
+
- **Version 1.4.6** *(30 September, 2022)*
- Bug-fix: assign all roles
diff --git a/lang/fr.json b/lang/fr.json
index 70e5c5e..afce366 100644
--- a/lang/fr.json
+++ b/lang/fr.json
@@ -286,6 +286,7 @@
"Type a message..": "Tapez un message..",
"Send": "Envoyer",
"No messages yet!": "Aucun message pour le moment !",
+ "Company": "Entreprise",
"Company name": "Nom de l'entreprise",
"Logo": "Logo",
"Companies": "Entreprises",