Example #1
0
    function file_cto($process = '', $id = '')
    {
        $employee_id = Input::get('employee_id');
        $month = Input::get('month');
        $year = Input::get('year');
        $allow_sat_sun = Input::get('allow_sat_sun');
        $process = Input::get('process');
        $multiple = Input::get('multiple');
        // If not approved_leave  replace dash with underscore
        if ($employee_id != 'approved_leave') {
            //$employee_id = str_replace('_','-',$employee_id);
        }
        $params = array('employee_id' => $employee_id, 'multiple' => $multiple, 'month' => $month, 'year' => $year, 'process' => $process, 'allow_sat_sun' => $allow_sat_sun);
        $this->load->library('cto', $params);
        if (Input::get('id') != '') {
            $cto_apps = CompensatoryTimeoff::find(Input::get('id'));
            $params = array('employee_id' => $cto_apps->employee_id, 'multiple' => $cto_apps->dates, 'month' => $cto_apps->month, 'year' => $cto_apps->year, 'process' => 2, 'allow_sat_sun' => 1);
            $process = 2;
            // Initilize and reset
            $this->cto->initialize($params);
            // Set the leave to approved
            CompensatoryTimeoff::setApproved(Input::get('id'));
            //exit;
        }
        if (!is_numeric($this->cto->employee_id)) {
            // Check if the employee id exists
            $is_employee_id_exists = $this->Employee->is_employee_id_exists($employee_id);
            if ($is_employee_id_exists == FALSE) {
                // If the process is approved dont exit
                if ($process == 2) {
                } else {
                    //echo $this->view_name($this->cto->employee_id);
                    exit;
                }
            }
        }
        $dates = explode(",", $this->cto->multiple);
        $name = $this->Employee->get_employee_info($this->cto->employee_id);
        //echo $name;
        if ($process != 2) {
            // Output name if exists
            $this->cto->is_employee($name);
        }
        $invalid = '';
        $this->cto->dates = $dates;
        $this->cto->process_dates();
        $this->cto->dates = array_unique($this->cto->date_process);
        echo $this->cto->count_leave . ' day(s) Compensatory Timeoff';
        //print_r($this->cto->dates);
        //exit;
        $office_id = $this->Employee->get_single_field('office_id', $this->cto->employee_id);
        // View only if not online apps
        if ($process != 2) {
            // 6.15.2011 5.33pm ===============
            //if ( $this->cto->leave_type_id == 21)
            //{
            $total_leave = $this->Leave_card->get_total_leave_credits($employee_id);
            $vbalance = $total_leave['vacation'];
            $sbalance = $total_leave['sick'];
            $total_leave_balance = $vbalance + $sbalance;
            //$this->cto->count_leave = $total_leave_balance;
            //}
            // ================================
            //echo $this->cto->count_leave.'<br><br>';
        }
        // If date is sat sun or holiday
        if ($this->cto->count_leave == 0) {
            echo '<input name="sat_sun" type="hidden" id="sat_sun" value="1" />';
        } else {
            echo '<input name="sat_sun" type="hidden" id="sat_sun" value="0" />';
        }
        if ($process || $process == 2) {
            if (Session::get('user_type') == 5) {
                $c = new CompensatoryTimeoff();
                $c->employee_id = $this->cto->employee_id;
                $c->office_id = $office_id;
                $c->month = $this->cto->month;
                $c->year = $this->cto->year;
                $c->days = $this->cto->count_leave;
                $c->dates = $this->cto->multiple;
                $c->date_file = date('Y-m-d');
                $c->type = 'spent';
                $c->status = 'inactive';
                $c->save();
                ?>
                <script>
               
				$('#messages').hide('slow');
				$('#messages').addClass("clean-green");
				$('#messages').html('CTO application was set for approval.<br>You may print your CTO application now. ' + '<a href="#" onClick="print_preview(<?php 
                echo intval($c->id);
                ?>
)">Print Preview</a>');
				$('#messages').slideDown('slow');
				$('#multiple').val("");
				$('#allow_sat_sun').attr("checked", false);
                </script>
               
				<?php 
                exit;
            }
            $c = new CompensatoryTimeoff();
            $c->employee_id = $this->cto->employee_id;
            $c->office_id = $office_id;
            $c->month = $this->cto->month;
            $c->year = $this->cto->year;
            $c->days = $this->cto->count_leave;
            $c->dates = $this->cto->multiple;
            $c->type = 'spent';
            $c->status = 'active';
            $c->save();
            //echo Input::get('id').'25333334455';
            //exit;
            foreach ($this->cto->dates as $date) {
                // If half day
                if (strlen($date) > 10) {
                    //get am or pm
                    $am_pm = strtolower(substr($date, -2));
                    $day = explode(" ", $date);
                    $day = $day[0];
                    if ($am_pm == 'am') {
                        $field = 'am_login';
                        $field2 = 'am_logout';
                    }
                    if ($am_pm == 'pm') {
                        $field = 'pm_login';
                        $field2 = 'pm_logout';
                    }
                    //Select if log_date exist in dtr
                    $is_log_date_exists = $this->Dtr->is_log_date_exists($this->cto->employee_id, $day);
                    //update
                    if ($is_log_date_exists == TRUE) {
                        $info = array($field => 'offset', $field2 => 'offset');
                        $this->Dtr->edit_dtr($info, $this->cto->employee_id, $day);
                    } else {
                        $info = array($field => 'offset', $field2 => 'offset', "log_date" => $day, "employee_id" => $this->cto->employee_id, "office_id" => $office_id, 'compensatory_timeoff_id' => Input::get('id'));
                        $this->Dtr->insert_dtr($info);
                        //use for use logs
                        $this->Logs->insert_logs('attendance', 'Compensatory Timeoff EVENT', '', $this->cto->employee_id);
                    }
                } else {
                    //Select if log_date exist in dtr
                    $is_log_date_exists = $this->Dtr->is_log_date_exists($this->cto->employee_id, $date);
                    //delete the data if the date and employee id exists
                    if ($is_log_date_exists == TRUE) {
                        //delete the data
                        $this->Dtr->delete_dtr($this->cto->employee_id, $date);
                    }
                    $info = array("employee_id" => $this->cto->employee_id, "log_date" => $date, 'compensatory_timeoff_id' => Input::get('id'), "am_login" => 'offset', "am_logout" => 'offset', "pm_login" => 'offset', "pm_logout" => 'offset', "office_id" => $office_id);
                    $this->Dtr->insert_dtr($info);
                }
            }
            if ($process == 2) {
                echo '<b>  has been approved!</b>';
                ?>
				<script>
				//$('#messages').addClass("clean-green");
				//$('.clean-green').show();
				</script>
				<?php 
            }
            ?>
			<script>
			$('#multiple').val("");
			$('#leave_card').load("<?php 
            echo base_url() . 'ajax/show_cto/';
            ?>
" + $('#employee_id').val());
			$('.clean-green').show();
			$('#allow_sat_sun').attr("checked", false);
			//$('#messages').hide();
			</script>
			<?php 
        }
    }