mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-05-30 11:14:59 -04:00
- Create BaseModel with getters for $table, $primaryKey, $allowedFields - All models now extend BaseModel instead of CodeIgniter\Model - Add type declarations to protected properties Closes #4489
38 lines
975 B
PHP
38 lines
975 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
class Rewards extends BaseModel
|
|
{
|
|
protected string $table = 'sales_reward_points';
|
|
protected string $primaryKey = 'id';
|
|
protected bool $useAutoIncrement = true;
|
|
protected bool $useSoftDeletes = false;
|
|
protected array $allowedFields = [
|
|
'sale_id',
|
|
'earned',
|
|
'used'
|
|
];
|
|
|
|
/**
|
|
* Inserts or updates a rewards
|
|
*/
|
|
public function save_value(array &$rewards_data, bool $rewards_id = false): bool
|
|
{
|
|
$builder = $this->db->table('sales_reward_points');
|
|
if (!$rewards_id || !$this->exists($rewards_id)) { // TODO: looks like we are missing the exists function in this class
|
|
if ($builder->insert($rewards_data)) {
|
|
$rewards_data['id'] = $this->db->insertID();
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
$builder->where('id', $rewards_id);
|
|
|
|
return $builder->update($rewards_data);
|
|
}
|
|
}
|