|
@@ -4,51 +4,80 @@
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
+use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * @property int $id
|
|
|
|
|
- * @property int $unit_id
|
|
|
|
|
- * @property string $title
|
|
|
|
|
|
|
+ * @property int $id
|
|
|
|
|
+ * @property int|null $unit_id Unidade que criou o card (nulo para Matriz)
|
|
|
|
|
+ * @property string $title
|
|
|
* @property string|null $description
|
|
* @property string|null $description
|
|
|
- * @property int $kanban_status_id
|
|
|
|
|
|
|
+ * @property string $phase a_fazer|em_progresso|em_revisao|concluido|demandas_especiais
|
|
|
|
|
+ * @property string $priority alta|normal|baixa
|
|
|
|
|
+ * @property string $origin matriz|unit
|
|
|
|
|
+ * @property string $scope internal|all|specific
|
|
|
|
|
+ * @property string|null $sector
|
|
|
|
|
+ * @property string|null $due_date
|
|
|
|
|
+ * @property int|null $responsible_user_id
|
|
|
|
|
+ * @property int|null $created_by_user_id
|
|
|
|
|
+ * @property int|null $target_unit_id
|
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
|
* @property string|null $deleted_at
|
|
* @property string|null $deleted_at
|
|
|
- * @method static \Illuminate\Database\Eloquent\Builder<static>|Kanban newModelQuery()
|
|
|
|
|
- * @method static \Illuminate\Database\Eloquent\Builder<static>|Kanban newQuery()
|
|
|
|
|
- * @method static \Illuminate\Database\Eloquent\Builder<static>|Kanban query()
|
|
|
|
|
- * @method static \Illuminate\Database\Eloquent\Builder<static>|Kanban whereCreatedAt($value)
|
|
|
|
|
- * @method static \Illuminate\Database\Eloquent\Builder<static>|Kanban whereDeletedAt($value)
|
|
|
|
|
- * @method static \Illuminate\Database\Eloquent\Builder<static>|Kanban whereDescription($value)
|
|
|
|
|
- * @method static \Illuminate\Database\Eloquent\Builder<static>|Kanban whereId($value)
|
|
|
|
|
- * @method static \Illuminate\Database\Eloquent\Builder<static>|Kanban whereKanbanStatusId($value)
|
|
|
|
|
- * @method static \Illuminate\Database\Eloquent\Builder<static>|Kanban whereTitle($value)
|
|
|
|
|
- * @method static \Illuminate\Database\Eloquent\Builder<static>|Kanban whereUnitId($value)
|
|
|
|
|
- * @method static \Illuminate\Database\Eloquent\Builder<static>|Kanban whereUpdatedAt($value)
|
|
|
|
|
* @mixin \Eloquent
|
|
* @mixin \Eloquent
|
|
|
*/
|
|
*/
|
|
|
class Kanban extends Model
|
|
class Kanban extends Model
|
|
|
{
|
|
{
|
|
|
- use HasFactory;
|
|
|
|
|
|
|
+ use HasFactory, SoftDeletes;
|
|
|
|
|
|
|
|
protected $table = 'kanbans';
|
|
protected $table = 'kanbans';
|
|
|
|
|
|
|
|
- protected $guarded = [
|
|
|
|
|
- 'id', // Add more fields that shouldn't be edited here
|
|
|
|
|
- ];
|
|
|
|
|
|
|
+ protected $guarded = ['id'];
|
|
|
|
|
|
|
|
protected $casts = [
|
|
protected $casts = [
|
|
|
'created_at' => 'datetime',
|
|
'created_at' => 'datetime',
|
|
|
'updated_at' => 'datetime',
|
|
'updated_at' => 'datetime',
|
|
|
- // Add your casts here (e.g., 'is_active' => 'boolean')
|
|
|
|
|
|
|
+ 'due_date' => 'date',
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
// Relationships
|
|
// Relationships
|
|
|
|
|
|
|
|
- // Business Logic Methods
|
|
|
|
|
|
|
+ public function applicantUnit()
|
|
|
|
|
+ {
|
|
|
|
|
+ return $this->belongsTo(Unit::class, 'unit_id');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function targetUnit()
|
|
|
|
|
+ {
|
|
|
|
|
+ return $this->belongsTo(Unit::class, 'target_unit_id');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function responsibleUser()
|
|
|
|
|
+ {
|
|
|
|
|
+ return $this->belongsTo(User::class, 'responsible_user_id');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function createdByUser()
|
|
|
|
|
+ {
|
|
|
|
|
+ return $this->belongsTo(User::class, 'created_by_user_id');
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // Custom Finders
|
|
|
|
|
|
|
+ public function replies()
|
|
|
|
|
+ {
|
|
|
|
|
+ return $this->hasMany(KanbanReply::class, 'kanban_id');
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// Query Scopes
|
|
// Query Scopes
|
|
|
|
|
|
|
|
|
|
+ public function scopeVisibleToUnit($query, int $unitId)
|
|
|
|
|
+ {
|
|
|
|
|
+ return $query->where(function ($q) use ($unitId) {
|
|
|
|
|
+ // Cards created by this unit (origin = unit)
|
|
|
|
|
+ $q->where('unit_id', $unitId)
|
|
|
|
|
+ // Cards explicitly targeted at this unit (specific or broadcast-per-unit)
|
|
|
|
|
+ ->orWhere('target_unit_id', $unitId);
|
|
|
|
|
+ // Note: scope='all' is NOT used here — when broadcasting the controller
|
|
|
|
|
+ // already creates one card per unit each with its own target_unit_id,
|
|
|
|
|
+ // so filtering by target_unit_id is sufficient and correct.
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|