Welcome Guest, Not a member yet? Register   Sign In
Attendance Form view
#1

(This post was last modified: 08-31-2023, 03:22 AM by ozornick. Edit Reason: Format code )

hello everyone, I have a problem with displaying the attendance form, I want to display the attendance form from Monday to Saturday, but what happens is that it doesn't appear on Saturday, what is the solution to this problem?

here are the codes

                                                                                                              controller - attendance.php

PHP Code:
<?php
defined
('BASEPATH') or exit('No direct script access allowed');

class 
Attendance extends CI_Controller
{
  public function __construct()
  {
    parent::__construct();
    is_weekends();
    is_logged_in();
    is_checked_in();
    is_checked_out();
    $this->load->library('form_validation');
    $this->load->model('Public_model');
    $this->load->model('Admin_model');
  }
  public function index()
  {
    // Attendance Form
    $d['title'] = 'Attendance Form';
    $d['account'] = $this->Public_model->getAccount($this->session->userdata['username']);
    $d['location'] = $this->db->get('location')->result_array();

    // If Weekends
    if (is_weekends() == true) {
      $d['weekends'] = true;
      $this->load->view('templates/header'$d);
      $this->load->view('templates/sidebar');
      $this->load->view('templates/topbar');
      $this->load->view('attendance/index'$d); // Attendance Form Page
      $this->load->view('templates/footer');
    } else {
      $d['in'] = true;
      $d['weekends'] = false;
      // If haven't Time In Today
      if (is_checked_in() == false) {
        $d['in'] = false;

        $this->form_validation->set_rules('work_shift''Work Shift''required|trim');
        $this->form_validation->set_rules('location''Location''required|trim');

        if ($this->form_validation->run() == false) {
          $shift $d['account']['shift'];
          $queryShift "SELECT * FROM `shift` WHERE `id` = $shift";
          $resultShift $this->db->query($queryShift)->row_array();
          $startTime $resultShift['start'];
          $endTime $resultShift['end'];
          $d['startTime'] = $startTime;
          $d['endTime'] = $endTime;

          $this->load->view('templates/header'$d);
          $this->load->view('templates/sidebar');
          $this->load->view('templates/topbar');
          $this->load->view('attendance/index'$d); // Attendance Form Page
          $this->load->view('templates/footer');
        } else {
          date_default_timezone_set('Asia/Manila');
          $shift $d['account']['shift'];
          $queryShift "SELECT * FROM `shift` WHERE `id` = $shift";
          $resultShift $this->db->query($queryShift)->row_array();
          $startTime $resultShift['start'];

          $username $this->session->userdata['username'];
          $employee_id $d['account']['id'];
          $department_id $d['account']['department_id'];
          $shift_id $this->input->post('work_shift');
          $location_id $this->input->post('location');
          $iTime time();
          $notes $this->input->post('notes');
          $lack 'None';

          // Time In Time
          if (date('H:i:s'$iTime) <= $startTime) {
            $inStatus 'On Time';
          } else {
            $inStatus 'Late';
          };

          // Check Notes
          if (!$notes) {
            $lack 'Notes';
          }

          // Config Upload
          $config['upload_path'] = './images/attendance/';
          $config['allowed_types'] = 'jpg|png|jpeg';
          $config['max_size'] = '2048';
          $config['file_name'] = 'item-' date('ymd') . '-' substr(md5(rand()), 010);

          // Load Upload Library and Pass Config
          $this->load->library('upload'$config);

          if ($_FILES['image']['name']) {
            if ($this->upload->do_upload('image')) {
              $image $this->upload->data('file_name');
              $value = [
                'username' => $username,
                'employee_id' => $employee_id,
                'department_id' => $department_id,
                'shift_id' => $shift_id,
                'location_id' => $location_id,
                'in_time' => $iTime,
                'notes' => $notes,
                'image' => $image,
                'lack_of' => $lack,
                'in_status' => $inStatus
              
];
            } else {
              $this->upload->display_errors();
            }
          } else {
            if ($lack != '') {
              $lack .= ',image';
            } else {
              $lack 'image';
            }
            $value = [
              'username' => $username,
              'employee_id' => $employee_id,
              'department_id' => $department_id,
              'shift_id' => $shift_id,
              'location_id' => $location_id,
              'in_time' => $iTime,
              'notes' => $notes,
              'lack_of' => $lack,
              'in_status' => $inStatus
            
];
          }
          $this->_checkIn($value);
        }
      }
      // End of Today Time In
      // If Checked In
      else {
        if (is_checked_out() == true) {
          $d['disable'] = true;
        } else {
          $d['disable'] = false;
        };
        $this->load->view('templates/header'$d);
        $this->load->view('templates/sidebar');
        $this->load->view('templates/topbar');
        $this->load->view('attendance/index'$d); // Attendance Form Page
        $this->load->view('templates/footer');
      }
    }
  }
  // Check Time In
  private function _checkIn($value)
  {
    $this->db->insert('attendance'$value);
    $rows $this->db->affected_rows();
    if ($rows 0) {
      $this->session->set_flashdata('message''<div class="alert alert-success" role="alert">
                                    Stamped attendance for today</div>'
);
    } else {
      $this->session->set_flashdata('message''<div class="alert alert-danger" role="alert">
                                    Failed to stamp your attendance!</div>'
);
    }
    redirect('attendance');
  }

  // Check Time Out
  public function checkOut()
  {
    $username $this->session->userdata['username'];
    $today date('Y-m-d'time());
    $querySelect "SELECT  attendance.username AS `username`,
                            attendance.employee_id AS `employee_id`,
                            attendance.shift_id AS `shift_id`,
                            attendance.in_time AS `in_time`,
                            shift.start AS `start`,
                            shift.end AS `end`
                      FROM  `attendance`
                INNER JOIN  `shift`
                        ON  attendance.shift_id = shift.id
                    WHERE  `username` = '
$username'
                      AND  FROM_UNIXTIME(`in_time`, '%Y-%m-%d') = '
$today'";
    $checkOut $this->db->query($querySelect)->row_array();

    $oTime time();

    // Time Out Time
    if (date('H:i:s'$oTime) >= $checkOut['end']) {
      $outStatus 'Over Time';
    } else {
      $outStatus 'Early';
    };

    $value = [
      'out_time' => $oTime,
      'out_status' => $outStatus
    
];

    $queryUpdate "UPDATE `attendance`
                      SET `out_time` ='" 
$value['out_time'] . "', `out_status` ='" $value['out_status'] . "' WHERE  `username` = '$username' AND  FROM_UNIXTIME(`in_time`, '%Y-%m-%d') = '$today'";
    $this->db->query($queryUpdate);
    redirect('attendance');
  }

  public function history()
  {
    $d['title'] = 'Attendance History';
    $d['account'] = $this->Public_model->getAccount($this->session->userdata['username']);
    $d['e_id'] = $d['account']['id'];
    $d['data'] = $this->attendance_details_data($d['e_id']);

    $this->load->view('templates/table_header'$d);
    $this->load->view('templates/sidebar');
    $this->load->view('templates/topbar');
    $this->load->view('attendance/history'$d);
    $this->load->view('templates/table_footer');
  }

  private function attendance_details_data($e_id)
  {
    $start $this->input->get('start');
    $end $this->input->get('end');

    $d['attendance'] = $this->Public_model->get_emp_attendance($e_id$start$end);

    $d['start'] = $start;
    $d['end'] = $end;

    return $d;
  }



                                                          code views - attendance - history.php

 
PHP Code:
    <!-- Begin Page Content -->
      <div class="container-fluid">

        <!-- Page Heading -->
        <div class="d-sm-flex align-items-center justify-content-between mb-4">
          <h1 class="h3 mb-0 text-gray-800"><?= $title?></h1>
        </div>

        <!-- Content Row -->
        <div class="row">

          <div class="col">
            <div class="row">

              <!-- Area Chart -->
              <div class="col-xl-12 col-lg-7">
                <div class="card shadow mb-4" style="min-height: 543px">
                  <!-- Card Header - Dropdown -->
                  <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
                    <h6 class="m-0 font-weight-bold text-dark">Stamp your Attendance!</h6>
                  </div>
                  <!-- Card Body -->
                  <div class="card-body">
                    <?php if ($weekends == true) : ?>
                      <h1 class="text-center my-3">THANK YOU FOR THIS WEEK!</h1>
                      <h5 class="card-title text-center mb-4 px-4">Have a Good Rest this <b>WEEKEND</b></h5>
                      <b><p class="text-center text-dark pt-3">See You on Monday!</p></b>
                      <div class="row">
                        <button disabled class="btn btn-danger rounded-0 btn-sm text-xs mx-auto" style="font-size: 35px; width: 200px; height: 200px">
                          <i class="fas fa-fw fa-sign-out-alt fa-2x"></i>
                        </button>
                      </div>
                    <?php else : ?>
                      <?php if ($in == false) : ?>
                        <?= form_open_multipart('attendance'?>
                        <div class="row mb-3">
                          <div class="col-lg-5">
                            <input type="hidden" name="work_shift" value="<?= $account['shift']; ?>">
                            <label for="work_shift" class="col-form-label">Work Shift</label>
                            <input class="form-control" type="text" placeholder="<?= date("h:i A"strtotime('2022-06-23 '.$startTime)); ?> - <?= date("h:i A"strtotime('2022-06-23 '.$endTime)); ?>" value="<?= date("h:i A"strtotime('2022-06-23 '.$startTime)); ?> - <?= date("h:i A"strtotime('2022-06-23 '.$endTime)); ?>"readonly>
                          </div>
                          <div class="col-lg-5 offset-lg-1">
                            <label for="location" class="col-form-label">Time In Location</label>
                            <select class="form-control" name="location" id="location">
                              <?php foreach ($location as $lct) : ?>
                                <option value="<?= $lct['id'?>"><?= $lct['id']; ?> = <?= $lct['name'?></option>
                              <?php endforeach; ?>
                            </select>
                          </div>
                        </div>
                        <div class="row mb-3">
                          <div class="col-lg-5 text-center">
                            <div class="row col">
                              <label for="image" class="col-form-label float-left">Upload Your Image</label>
                            </div>
                            <img id="output" style="max-height: 252px;" class="img-thumbnail rounded mb-2" src="<?= base_url('images/attendance/default.png'?>">
                            <input type="file" class="d-block" id=image name="image" accept="image/*" onchange="loadFile(event)">
                            <script>
                              var loadFile = function(event) {
                                var output = document.getElementById('output');
                                output.src = URL.createObjectURL(event.target.files[0]);
                                output.onload = function() {
                                  URL.revokeObjectURL(output.src) // free memory
                                }
                              };
                            </script>
                          </div>
                          <div class="col-lg-5 offset-lg-1 text-center">
                            <label for="notes" class="float-left">Notes</label>
                            <textarea maxlength="120" class="form-control mb-4" name="notes" id="notes" rows="3" style="resize: none;"></textarea>
                            <hr>
                            <button type="submit" class="btn btn-primary bg-gradient-primary px-5 btn-lg rounded-pill" >
                              <i class="fas fa-fw fa-sign-in-alt"></i> Time In
                            </button>
                            <hr>
                          </div>
                        </div>
                        <?= form_close() ?>
                      <?php else : ?>
                        <h3 class="text-center my-3">THANK YOU FOR TODAY</h3>
                        <h6 class="card-title text-center mb-4 px-4">The world of business survives less on leadership skills and more on the commitment and dedication of passionate employees like you.<br>Thank you for your hard work.</h6>
                        <?php if ($disable == false) : ?>
                          <div class="row">
                            <a href="<?= base_url('attendance/checkout'?>" onclick="return confirm('Time Out now? Make sure you are done with you work!')" class="btn btn-danger bg-gradient-danger rounded-pill px-5 btn-lg mx-auto">
                              <i class="fas fa-fw fa-sign-out-alt"></i> <b>Time Out</b>
                            </a>
                          <?php else : ?>
                            <b><p class="text-center text-dark pt-3">See You Tomorrow!</p></b>
                            
                            <?php endif; ?>
                          <?php endif; ?>
                        <?php endif; ?>
                          </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <!-- End  -->
        </div>
        <!-- /.container-fluid -->

      </div>
      <!-- End of Main Content --><!-- Begin Page Content -->
<div class="container-fluid">
  <!-- Page Heading -->
  <div class="d-flex w-100 align-items-center">
    <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
      <h1 class="h3 mb-0 text-gray-800"><?= $title?></h1>
    </div>
    <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 text-right">
    </div>
  </div>
  <hr>
  <div class="card rounded-0 shadow mb-3">
    <div class="card-body">
      <fieldset class="border rounded-0 px-2 pb-2">
        <legend class="ml-3 px-3 w-auto">Filter Report</legend>
        <form action="" method="GET">
          <div class="row">
            <div class="col-lg-3 col-md-6 col-sm-12">
              <input type="date" name="start" class="form-control form-control-sm rounded-0" value="<?= !empty($this->input->get('start')) ? $this->input->get('start') : '' ?>">
              <?= form_error('start''<small class="text-danger pl-3">''</small>'?>
            </div>
            <div class="col-lg-3 col-md-6 col-sm-12">
              <input type="date" name="end" class="form-control form-control-sm rounded-0" value="<?= !empty($this->input->get('end')) ? $this->input->get('end') : '' ?>">
              <?= form_error('end''<small class="text-danger pl-3">''</small>'?>
            </div>
            <div class="col-2">
              <button type="submit" class="btn btn-primary btn-sm rounded-0 bg-gradient-primary "><i class="fa fa-file"></i> Show Attendance</button>
            </div>
          </div>
        </form>
      </fieldset>
    </div>
  </div>

  <?php if ($data['attendance']) : ?>
    <div class="card shadow mb-4 rounded-0">
      <div class="card-header py-3">
        <h6 class="m-0 font-weight-bold text-dark">Data Attendance</h6>
      </div>
      <div class="card-body">
        <div class="table-responsive">
          <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
            <thead class="bg-gradient-primary text-white">
              <tr>
                <th>#</th>
                <th>Date</th>
                <th>Shift</th>
                <th>Time In</th>
                <th>Notes</th>
                <th>Image</th>
                <th>Lack Of</th>
                <th>In Status</th>
                <th>Time Out</th>
                <th>Out Status</th>
              </tr>
            </thead>
            <tbody>
              <?php
              
// looping attendance list
              $i 1;
              foreach ($data['attendance'] as $atd) :
              ?>
                <tr <?php if (date('l'$atd['date']) == 'Saturday' || date('l'$atd['date']) == 'Sunday') {
                      echo "class ='bg-secondary text-white'";
                    ?>>

                  <!-- Column 1 -->
                  <td><?= $i++; ?></td>
                  <?php

                  
// if WEEKENDS
                  if (date('l'$atd['date']) == 'Saturday' || date('l'$atd['date']) == 'Sunday') : ?>
                    <!-- Column 2 -->
                    <td colspan="6" class="text-center">OFF</td>
                  <?php

                  
// if WEEKDAYS
                  else : ?>
                    <!-- Column 2 (Date) -->
                    <td><?= date('l, d F Y'$atd['date']); ?></td>

                    <!-- Column 3 (Shift) -->
                    <td>
                    <div style="line-height:1em">
                        <div class="text-xs"><?= date("h:i A"strtotime('2022-06-23 '.$atd['start'])) ?></div>
                        <div class="text-xs"><?= date("h:i A"strtotime('2022-06-23 '.$atd['end'])) ?></div>
                      </div> 
                    </td>

                    <!-- Column 4 (Time In) -->
                    <td><?= date('h:i:s A'$atd['date']); ?></td>

                    <!-- Column 5 (Notes) -->
                    <td><?= $atd['notes']; ?></td>

                    <!-- Column 6 (Image) -->
                    <td><?php if ($atd['image']) : ?>
                        <img src="<?= base_url('images/attendance/') . $atd['image']; ?>" style="height: 70px">
                      <?php else : ?>
                        Image Not Found
                      <?php endif; ?>
                    </td>

                    <!-- Column 7 (Lack Of) -->
                    <td><?= $atd['lack_of']; ?></td>


                    <!-- Column 8 (In Status) -->
                    <td><?= $atd['in_status']; ?></td>

                    <!-- Column 9 (Time Out) -->
                    <td><?php if ($atd['out_time'] == 0) {
                          echo "Haven't Checked Out";
                        } else {
                          echo date('h:i:s A'$atd['out_time']);
                        }
                        ?>
                    </td>

                    <!-- Column 10 (Out Status) -->
                    <td><?= $atd['out_status']; ?></td>

                  <?php endif; ?>
                </tr>
              <?php endforeach; ?>
            </tbody>
          </table>
        </div>
      </div>
    </div>
  <?php else : ?>
    <h1 class="text-center">Please Pick Your Date</h1>
  <?php endif; ?>

</div>
<!-- /.container-fluid -->

</div>
<!-- End of Main Content --> 


                                                            code views - attendance - index.php

     
PHP Code:
<!-- Begin Page Content -->
      <div class="container-fluid">

        <!-- Page Heading -->
        <div class="d-sm-flex align-items-center justify-content-between mb-4">
          <h1 class="h3 mb-0 text-gray-800"><?= $title?></h1>
        </div>

        <!-- Content Row -->
        <div class="row">

          <div class="col">
            <div class="row">

              <!-- Area Chart -->
              <div class="col-xl-12 col-lg-7">
                <div class="card shadow mb-4" style="min-height: 543px">
                  <!-- Card Header - Dropdown -->
                  <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
                    <h6 class="m-0 font-weight-bold text-dark">Stamp your Attendance!</h6>
                  </div>
                  <!-- Card Body -->
                  <div class="card-body">
                    <?php if ($weekends == true) : ?>
                      <h1 class="text-center my-3">THANK YOU FOR THIS WEEK!</h1>
                      <h5 class="card-title text-center mb-4 px-4">Have a Good Rest this <b>WEEKEND</b></h5>
                      <b><p class="text-center text-dark pt-3">See You on Monday!</p></b>
                      <div class="row">
                        <button disabled class="btn btn-danger rounded-0 btn-sm text-xs mx-auto" style="font-size: 35px; width: 200px; height: 200px">
                          <i class="fas fa-fw fa-sign-out-alt fa-2x"></i>
                        </button>
                      </div>
                    <?php else : ?>
                      <?php if ($in == false) : ?>
                        <?= form_open_multipart('attendance'?>
                        <div class="row mb-3">
                          <div class="col-lg-5">
                            <input type="hidden" name="work_shift" value="<?= $account['shift']; ?>">
                            <label for="work_shift" class="col-form-label">Work Shift</label>
                            <input class="form-control" type="text" placeholder="<?= date("h:i A"strtotime('2022-06-23 '.$startTime)); ?> - <?= date("h:i A"strtotime('2022-06-23 '.$endTime)); ?>" value="<?= date("h:i A"strtotime('2022-06-23 '.$startTime)); ?> - <?= date("h:i A"strtotime('2022-06-23 '.$endTime)); ?>"readonly>
                          </div>
                          <div class="col-lg-5 offset-lg-1">
                            <label for="location" class="col-form-label">Time In Location</label>
                            <select class="form-control" name="location" id="location">
                              <?php foreach ($location as $lct) : ?>
                                <option value="<?= $lct['id'?>"><?= $lct['id']; ?> = <?= $lct['name'?></option>
                              <?php endforeach; ?>
                            </select>
                          </div>
                        </div>
                        <div class="row mb-3">
                          <div class="col-lg-5 text-center">
                            <div class="row col">
                              <label for="image" class="col-form-label float-left">Upload Your Image</label>
                            </div>
                            <img id="output" style="max-height: 252px;" class="img-thumbnail rounded mb-2" src="<?= base_url('images/attendance/default.png'?>">
                            <input type="file" class="d-block" id=image name="image" accept="image/*" onchange="loadFile(event)">
                            <script>
                              var loadFile = function(event) {
                                var output = document.getElementById('output');
                                output.src = URL.createObjectURL(event.target.files[0]);
                                output.onload = function() {
                                  URL.revokeObjectURL(output.src) // free memory
                                }
                              };
                            </script>
                          </div>
                          <div class="col-lg-5 offset-lg-1 text-center">
                            <label for="notes" class="float-left">Notes</label>
                            <textarea maxlength="120" class="form-control mb-4" name="notes" id="notes" rows="3" style="resize: none;"></textarea>
                            <hr>
                            <button type="submit" class="btn btn-primary bg-gradient-primary px-5 btn-lg rounded-pill" >
                              <i class="fas fa-fw fa-sign-in-alt"></i> Time In
                            </button>
                            <hr>
                          </div>
                        </div>
                        <?= form_close() ?>
                      <?php else : ?>
                        <h3 class="text-center my-3">THANK YOU FOR TODAY</h3>
                        <h6 class="card-title text-center mb-4 px-4">The world of business survives less on leadership skills and more on the commitment and dedication of passionate employees like you.<br>Thank you for your hard work.</h6>
                        <?php if ($disable == false) : ?>
                          <div class="row">
                            <a href="<?= base_url('attendance/checkout'?>" onclick="return confirm('Time Out now? Make sure you are done with you work!')" class="btn btn-danger bg-gradient-danger rounded-pill px-5 btn-lg mx-auto">
                              <i class="fas fa-fw fa-sign-out-alt"></i> <b>Time Out</b>
                            </a>
                          <?php else : ?>
                            <b><p class="text-center text-dark pt-3">See You Tomorrow!</p></b>
                            
                            <?php endif; ?>
                          <?php endif; ?>
                        <?php endif; ?>
                          </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <!-- End  -->
        </div>
        <!-- /.container-fluid -->

      </div>
      <!-- End of Main Content --> 



Please help me...Thanks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB