<?php

/**
 * Class that operate on table 'employeeclosedayhistory'. Database Mysql.
 *
 * @author: http://phpdao.com
 * @date: 2020-11-20 02:16
 */
class EmployeeclosedayhistoryMySqlExtDAO extends EmployeeclosedayhistoryMySqlDAO {

    public function getEmployeeHistoryByQueryString($queryString = '') {
        $sql = 'SELECT * FROM employeeclosedayhistory WHERE 1 ' . $queryString;
        //echo $sql;
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

    public function getClosedEmployeeCountForSubGroupInADay($day, $employeesubgroupid) {
        $sql = 'SELECT count(*) as id
                FROM employeeclosedayhistory
                join employee on employee.employeeId = employeeclosedayhistory.employeeid
                WHERE day= "' . $day . '"
                and (isAbsent != 1 or (attendanceTime !="00:00:00" and departureTime !="00:00:00"))
                and del = 0
                and employeesubgroupid=' . $employeesubgroupid;
        //echo $sql;
        $sqlQuery = new SqlQuery($sql);
        return $this->querySingleResult($sqlQuery);
    }
    
    public function beginDayAttendance($day,$sysDate,$userid) {
        $sql = 'INSERT IGNORE INTO employeeclosedayhistory (employeeid, day, attendanceTime, departureTime, latePeriod, lateHasPermission, lateDiscount, isAbsent, absentHasPermission, absentDiscount, userid, sysdate, del, status)
                SELECT employeeId , "'.$day.'", "00:00:00" , "00:00:00" ,0 ,0 ,0 ,1 ,0 ,dayAbsenceWithoutPermissionDisount , '.$userid.', "'.$sysDate.'",0,-1
                from employee where conditions = 0 ';
        //echo $sql;
        $sqlQuery = new SqlQuery($sql);
        return $this->executeUpdate($sqlQuery);
    }
    
    public function dayAttendanceCount($day) {
        $sql = 'SELECT count(*) 
                from employeeclosedayhistory where day = "'.$day.'" ';
        //echo $sql;
        $sqlQuery = new SqlQuery($sql);
        return $this->querySingleResult($sqlQuery);
    }

}

?>