2025-10-29 11:08:38 +07:00
|
|
|
<?php
|
|
|
|
|
namespace App\Models\Organization;
|
|
|
|
|
use App\Models\BaseModel;
|
2026-01-12 16:53:41 +07:00
|
|
|
use App\Libraries\ValueSet;
|
2025-10-29 11:08:38 +07:00
|
|
|
|
|
|
|
|
class WorkstationModel extends BaseModel {
|
|
|
|
|
protected $table = 'workstation';
|
|
|
|
|
protected $primaryKey = 'WorkstationID';
|
|
|
|
|
protected $allowedFields = ['DepartmentID', 'WorkstationCode', 'WorkstationName', 'Type', 'LinkTo', 'Enable',
|
|
|
|
|
'EquipmentID', 'CreateDate', 'EndDate'];
|
|
|
|
|
|
|
|
|
|
protected $useTimestamps = true;
|
|
|
|
|
protected $createdField = 'CreateDate';
|
|
|
|
|
protected $updatedField = '';
|
|
|
|
|
protected $useSoftDeletes = true;
|
|
|
|
|
protected $deletedField = 'EndDate';
|
2026-01-12 16:53:41 +07:00
|
|
|
|
2025-12-02 09:29:42 +07:00
|
|
|
public function getWorkstations($filter = []) {
|
|
|
|
|
$this->select('workstation.*, department.DepartmentName, wst1.WorkstationName as LinkToName')
|
2025-11-06 12:28:42 +07:00
|
|
|
->join('workstation wst1', 'workstation.LinkTo=wst1.WorkstationID', 'left')
|
2025-12-02 09:29:42 +07:00
|
|
|
->join('department', 'department.DepartmentID=workstation.DepartmentID', 'left');
|
2026-01-12 16:53:41 +07:00
|
|
|
|
2025-12-02 09:29:42 +07:00
|
|
|
if (!empty($filter['WorkstationCode'])) {
|
|
|
|
|
$this->like('workstation.WorkstationCode', $filter['WorkstationCode'], 'both');
|
|
|
|
|
}
|
|
|
|
|
if (!empty($filter['WorkstationName'])) {
|
|
|
|
|
$this->like('workstation.WorkstationName', $filter['WorkstationName'], 'both');
|
|
|
|
|
}
|
|
|
|
|
$rows = $this->findAll();
|
2025-11-06 12:28:42 +07:00
|
|
|
return $rows;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getWorkstation($WorkstationID) {
|
2026-01-12 16:53:41 +07:00
|
|
|
$row = $this->select("workstation.*, department.DepartmentName, wst1.WorkstationName as LinkToName")
|
2025-11-06 12:28:42 +07:00
|
|
|
->join('workstation wst1', 'workstation.LinkTo=wst1.WorkstationID', 'left')
|
|
|
|
|
->join('department', 'department.DepartmentID=workstation.DepartmentID', 'left')
|
|
|
|
|
->where('workstation.WorkstationID', $WorkstationID)
|
2025-12-29 12:55:31 +07:00
|
|
|
->first();
|
2026-01-12 16:53:41 +07:00
|
|
|
|
|
|
|
|
if (!$row) return null;
|
|
|
|
|
|
|
|
|
|
$row = ValueSet::transformLabels([$row], [
|
|
|
|
|
'Type' => 'ws_type',
|
|
|
|
|
'Enable' => 'enable_disable',
|
|
|
|
|
])[0];
|
|
|
|
|
|
2025-12-29 12:55:31 +07:00
|
|
|
return $row;
|
2025-11-06 12:28:42 +07:00
|
|
|
}
|
2025-10-29 11:08:38 +07:00
|
|
|
}
|