I have a form that i need to fill in order to fill out an allowance table. The allowance table contains Employee Code, Employee Name, Period of time, and days attended. The form only contains employee code, employee name, and period of time. So the days attended need to be filled automatically by counting on how many days attended from attendance table with condition based on the period of time.
This is the structure of the attendance table:
| id_attend | employee_id | employee_name | date | time_in | time_out |
| 1 | RYN | RYAN |01.01.2011| 07.00 | 19.00 |
Meanwhile this is the structure of allowance table
| id_allowance | employee_id | employee_name | period | days_attended |
| 1 | RYN | RYAN | 01.2011 | 1 |
So the days_attended should be filled by counting how many days attended based on employee_id and period. I tried this one in my model:
public function count_days_attended()
{
$this->db->select('*, COUNT(attendance.date) as allowance.days_attended');
$this->db->from('attendance');
$this->db->join('allowance','attendance.employee_id= allowance.employee_id');
$this->db->order_by('employee_id','DESC');
$this->db->where(MONTH('attendance.date'), MONTH('allowance.period'));
$query = $this->db->get();
return $query->result();
}
and this is my controller:
public function submit(){
$dateTime = new DateTime($this->input->post('period'));
$formatted_date = date_format($dateTime, 'Y-m-d' );
$data = array(
'employee_id'=>$this->input->post('employee_id'),
'employee_name'=>$this->input->post('employee_name'),
'period'=> $formatted_date,
);
$this->absengaji_m->count_days_attended;
$this->absengaji_m->insert($data);
redirect('absengaji');
}
There is no error, but the program is not even give any response to my code. Once i clicked the submit its still show 0 on days attended
Is there any way to fix this? :/