<?php

/**
 * Class that operate on table 'restaurantrawdestruction'. Database Mysql.
 *
 * @author: http://phpdao.com
 * @date: 2018-05-22 14:34
 */
class RestaurantrawdestructionMySqlExtDAO extends RestaurantrawdestructionMySqlDAO {

    public function queryBySysdateBetween($startDate, $endDate) {
        $sql = 'SELECT * FROM restaurantrawdestruction WHERE sysdate >= "' . $startDate . '" and sysdate <= "' . $endDate . '"';
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

    public function queryByStore($storeId) {
        $sql = 'SELECT * FROM restaurantrawdestruction WHERE storeid = ' . $storeId . '';
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

    public function queryByQueryString($querySting = '') {
        $sql = 'SELECT r.*,user.employeename
                FROM restaurantrawdestruction r
                left join user on user.userid = r.userid
                WHERE 1 ' . $querySting;
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

    public function queryByQueryStringGather($querySting = '') {
        $sql = 'SELECT r.id,r.storeid,r.productid,sum(r.quantity) as quantity,sum(r.quantity*r.productBuyPrice) as productBuyPrice,sum(r.quantity*r.lastbuyprice) as lastbuyprice,sum(r.quantity*r.meanbuyprice) as meanbuyprice,sum(r.quantity*r.lastbuyprice_withDiscount) as lastbuyprice_withDiscount,sum(r.quantity*r.meanbuyprice_withDiscount) as meanbuyprice_withDiscount,
                sum(r.quantity*r.lastbuyprice_withTax) as lastbuyprice_withTax,sum(r.quantity*r.meanbuyprice_withTax) as meanbuyprice_withTax,
                r.operationNum,r.sysdate,r.userid,user.employeename
                FROM restaurantrawdestruction r
                left join user on user.userid = r.userid
                WHERE 1 ' . $querySting;
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

    public function getMaxOperationNum() {
        $sql = 'SELECT max(operationNum) FROM restaurantrawdestruction where conditions=0';
        $sqlQuery = new SqlQuery($sql);
        return $this->querySingleResult($sqlQuery);
    }

}

?>