Ejemplo n.º 1
0
 function networkdays($s, $e, $holidays = array())
 {
     // If the start and end dates are given in the wrong order, flip them.
     if ($s > $e) {
         return networkdays($e, $s, $holidays);
     }
     // Find the ISO-8601 day of the week for the two dates.
     $sd = date("N", $s);
     $ed = date("N", $e);
     // Find the number of weeks between the dates.
     $w = floor(($e - $s) / (86400 * 7));
     # Divide the difference in the two times by seven days to get the number of weeks.
     if ($ed >= $sd) {
         $w--;
     }
     # If the end date falls on the same day of the week or a later day of the week than the start date, subtract a week.
     // Calculate net working days.
     $nwd = max(6 - $sd, 0);
     # If the start day is Saturday or Sunday, add zero, otherewise add six minus the weekday number.
     $nwd += min($ed, 5);
     # If the end day is Saturday or Sunday, add five, otherwise add the weekday number.
     $nwd += $w * 5;
     # Add five days for each week in between.
     // Iterate through the array of holidays. For each holiday between the start and end dates that isn't a Saturday or a Sunday, remove one day.
     foreach ($holidays as $h) {
         $h = strtotime($h);
         if ($h > $s && $h < $e && date("N", $h) < 6) {
             $nwd--;
         }
     }
     return $nwd;
 }
Ejemplo n.º 2
0
 public function unesi_zahtjev_bolovanje()
 {
     $start = strtotime($this->input->post('pocetak'));
     $end = strtotime($this->input->post('kraj'));
     $radnih_dana = networkdays($start, $end);
     $s1 = $this->input->post('pocetak');
     $s2 = $this->input->post('kraj');
     $s1 = date("d.m.Y", strtotime($s1));
     $s2 = date("d.m.Y", strtotime($s2));
     $data = array('pk_podnosilac' => $this->session->userdata('user_id'), 'pocetak' => $s1, 'kraj' => $s2, 'dana' => $radnih_dana, 'napomena' => $this->input->post('komentar'), 'status' => '', 'tip' => 'Bolovanje');
     $this->db->insert('zahtjevi', $data);
     return true;
 }
Ejemplo n.º 3
0
Archivo: user.php Proyecto: BerinT/nsi
 public function validiraj_datume()
 {
     $start = strtotime($this->input->post('pocetak'));
     $end = strtotime($this->input->post('kraj'));
     $br_dana = networkdays($start, $end);
     //radni dani
     $preostalo_dana = $this->user_model->provjeri_br_dana();
     if ($br_dana > $preostalo_dana) {
         $this->form_validation->set_message('validiraj_datume', 'Uzeli ste vise dana odmora nego sto vam je preostalo!');
         $this->session->set_flashdata('verifi_msg', '<div class="alert alert-success text-center">Uzeli ste vise dana odmora nego sto vam je preostalo!</div>');
         return FALSE;
     }
     return TRUE;
 }