102 lines
3.0 KiB
PHP
102 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class CommissionFilesModel extends Model
|
|
{
|
|
protected $table = 'commission_files';
|
|
protected $primaryKey = 'id';
|
|
|
|
protected $returnType = 'array';
|
|
protected $useSoftDeletes = false;
|
|
|
|
protected $allowedFields = [
|
|
'file_name',
|
|
'insurer_id',
|
|
'department',
|
|
'commission_month',
|
|
'file_status',
|
|
'is_active',
|
|
'created_by',
|
|
'updated_by',
|
|
'rules_count',
|
|
];
|
|
|
|
// Auto timestamps by CI4
|
|
protected $useTimestamps = true;
|
|
protected $createdField = 'created_at';
|
|
protected $updatedField = 'updated_at';
|
|
|
|
// Callbacks
|
|
protected $allowCallbacks = true;
|
|
protected $beforeInsert = ["checkAndADDCreatedByValue"];
|
|
protected $afterInsert = [];
|
|
protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"];
|
|
protected $afterUpdate = [];
|
|
protected $beforeFind = [];
|
|
protected $afterFind = [];
|
|
protected $beforeDelete = [];
|
|
protected $afterDelete = [];
|
|
|
|
protected function checkAndADDCreatedByValue(array $data)
|
|
{
|
|
// Check if 'updated_by' value is null or empty
|
|
if (empty($data['data']['created_by'])) {
|
|
// Set 'updated_by' value to the current session user ID
|
|
$data['data']['created_by'] = get_session_userid();
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
protected function checkAndUpdateUpdatedByValue(array $data)
|
|
{
|
|
// Check if 'updated_by' value is null or empty
|
|
if (empty($data['data']['updated_by'])) {
|
|
// Set 'updated_by' value to the current session user ID
|
|
$data['data']['updated_by'] = get_session_userid();
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
// Validation rules (optional)
|
|
// protected $validationRules = [
|
|
// 'file_name' => 'required|min_length[1]|max_length[100]',
|
|
// 'insurer_id' => 'permit_empty|integer',
|
|
// 'department' => 'permit_empty|max_length[45]',
|
|
// 'commission_month' => 'permit_empty|valid_date',
|
|
// 'file_status' => 'permit_empty|max_length[10]',
|
|
// 'is_active' => 'permit_empty|in_list[0,1]'
|
|
// ];
|
|
|
|
protected $validationMessages = [];
|
|
protected $skipValidation = false;
|
|
|
|
/**
|
|
* Get files with optional filters
|
|
*/
|
|
// public function getFiles($filters = [])
|
|
// {
|
|
// if (!empty($filters['insurer_id'])) {
|
|
// $this->where('insurer_id', $filters['insurer_id']);
|
|
// }
|
|
|
|
// if (!empty($filters['department'])) {
|
|
// $this->where('department', $filters['department']);
|
|
// }
|
|
|
|
// if (!empty($filters['file_status'])) {
|
|
// $this->where('file_status', $filters['file_status']);
|
|
// }
|
|
|
|
// if (isset($filters['is_active'])) {
|
|
// $this->where('is_active', $filters['is_active']);
|
|
// }
|
|
|
|
// return $this->orderBy('id', 'DESC')->findAll();
|
|
// }
|
|
}
|