You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kwpayroll/app/Models/EmpPayTransIncomeDeductionM...

89 lines
3.0 KiB
PHP

<?php
namespace App\Models;
use CodeIgniter\Model;
class EmpPayTransIncomeDeductionModel extends Model
{
protected $table = 'emp_pay_trans_inded';
protected $primaryKey = 'emppaytransinded_id';
protected $useAutoIncrement = true;
protected $returnType = \App\Entities\EmpPayTransIncomeDeduction::class;
protected $useSoftDeletes = false;
protected $protectFields = true;
protected $allowedFields = ['emppaytrans_id',
'inded_id',
'payslip_display',
'inded_name',
'coa_code',
'is_income',
'is_taxable',
'include_in_gross',
'is_fixed_amt',
'is_percent_amt',
'amount',
'base_amount',
'is_override'];
protected bool $allowEmptyInserts = false;
// Dates
protected $useTimestamps = true;
protected $dateFormat = 'datetime';
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
protected $deletedField = 'deleted_at';
// Validation
protected $validationRules = [];
protected $validationMessages = [];
protected $skipValidation = false;
protected $cleanValidationRules = true;
// Callbacks
protected $allowCallbacks = true;
protected $beforeInsert = ['assignCreatedBy'];
protected $afterInsert = [];
protected $beforeUpdate = ['assignUpdatedBy'];
protected $afterUpdate = [];
protected $beforeFind = [];
protected $afterFind = [];
protected $beforeDelete = [];
protected $afterDelete = [];
public function assignCreatedBy(array $data)
{
$data['data']['created_by'] = auth()->user()->employee_id;
return $data;
}
public function assignUpdatedBy(array $data)
{
$data['data']['updated_by'] = auth()->user()->employee_id;
return $data;
}
public function getEmpPayTransInDedxInDedByEmpTransId($emptransid)
{
$builder = $this->db->table('emp_pay_trans_inded');
$builder->select('*');
$builder->join('pay_income_deduction', 'pay_income_deduction.inded_id = emp_pay_trans_inded.inded_id');
$builder->where('emp_pay_trans_inded.emppaytrans_id', $emptransid);
return $builder->get()->getResult();
}
public function getTotalIncomeDeduction($emppaytransid, $isincome, $istaxable)
{
$builder = $this->db->table('emp_pay_trans_inded');
$builder->selectSum('amount');
$builder->where(['emppaytrans_id'=>$emppaytransid,
'is_income'=>$isincome,
'is_taxable'=>$istaxable]);
$result = $builder->get()->getRow();
if($result->amount == null) return 0;
else return $result->amount;
}
}