67 lines
1.8 KiB
PHP
67 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class InvoiceItemModel extends Model
|
|
{
|
|
protected $table = 'partner_invoice_items';
|
|
protected $primaryKey = 'id';
|
|
protected $useAutoIncrement = true;
|
|
|
|
protected $returnType = 'array';
|
|
protected $useSoftDeletes = false;
|
|
|
|
protected $allowedFields = [
|
|
'invoice_id',
|
|
'policy_id',
|
|
'policy_no',
|
|
'commission_amount',
|
|
'is_active',
|
|
'created_at',
|
|
'created_by',
|
|
'updated_at',
|
|
'updated_by'
|
|
];
|
|
|
|
protected $useTimestamps = false;
|
|
protected $createdField = 'created_at';
|
|
protected $updatedField = 'updated_at';
|
|
|
|
protected $validationRules = [
|
|
'invoice_id' => 'required|integer',
|
|
'policy_id' => 'required|integer',
|
|
'policy_no' => 'required|max_length[100]',
|
|
'commission_amount' => 'decimal'
|
|
];
|
|
|
|
protected $validationMessages = [];
|
|
protected $skipValidation = false;
|
|
|
|
protected $beforeInsert = ["checkAndAddCreatedByValue"];
|
|
protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"];
|
|
|
|
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;
|
|
}
|
|
}
|