Welcome Guest, Not a member yet? Register   Sign In
Coming up with a business logic helper class
#11

[eluser]afro[/eluser]
so how will i pass these results from the model to the view(the staffname, reportback date of that particular staff.)
as a message, the check_staff_on_leave function is in the leave_model.
#12

[eluser]toopay[/eluser]
in your model, it should be...
Code:
function check_staff_on_leave()
{
      $this->db->select('Department, COUNT(*) AS on_leave', FALSE);
      $this->db->from('checkoff');
      $this->db->where('Department', $this->input->post('department'));
      $this->db->group_by('Department');
      $this->db->having('COUNT(*) >', 2);  
      $result = $this->db->get();
      if($result->num_rows() > 0)
      {
              $rows = $result->result_array();
              // Generating query to table 2
              $this->db->select('MIN(Date),StaffName,ReportBack');
              $this->db->from('appliedleaves');
              $this->db->where('Department', $rows[0]['Department']);
              $res = $this->db->get();
              // This variable should give you matched result from table 2
              $result = $res->result_array();
              
       }
       else
       {
              $result = 'No result';
       }  
       return $result;
}
then in your controller, you can use it like
Code:
...
$this->load->model('leave_model');
$data['staff'] = $this->leave_model->check_staff_on_leave();
$this->load->view('some_view',$data);
...
and in your 'some_view' file, you can check the result like...
Code:
...
<?php var_dump($staff); ?>
...
#13

[eluser]afro[/eluser]
my controller looks like this
Code:
$this->load->model('Leave_model');
                
$query = $this->Leave_model->appliedleave();
                

if($query)
                {
                $data['message'] = $this->input->get_post('staffname').' your application has been successfully sent.'. '<br>'. 'You will receive an email as soon as it has been approved.';
                $this->load->view('leavesuccess',$data);
                }
            //in case where more than three staff from one department apply for a leave//
                else
                {
                $data['reportdate'] = $this->Leave_model->check_staff_on_leave();
            $data['staff'] = $this->Leave_model->check_staff_on_leave();
                

            $data['message'] = $this->input->get_post('staffname'). 'three staffs from your department have already on leave applied for leaves.'.'<br>'.'You should retry appling after '.$staff.' expected on'.$reportdate.'';
            $this->load->view('leavesuccess',$data);    
}
#14

[eluser]toopay[/eluser]
What your question? try to check the $data['staff'] value in your view files first, so you'll know how to put it in your $data['staff']. in 'leavesuccess' view file, put this code to check the $data['staff'] value...
Code:
&lt;?php var_dump($staff); ?&gt;
Write what you get, here, if you still need help.
#15

[eluser]afro[/eluser]
bool(false)
#16

[eluser]afro[/eluser]
i want the system to tell the current applicant the employee who first went on leave
and when he/she is expected to come back from the leave, that is StaffName and ReportingBack
fields
#17

[eluser]toopay[/eluser]
Modify your model into example i write above!




Theme © iAndrew 2016 - Forum software by © MyBB