<?php

/**
 * Class that operate on table 'assets'. Database Mysql.
 *
 * @author: http://phpdao.com
 * @date: 2013-04-06 10:57
 */
class AssetsMySqlExtDAO extends AssetsMySqlDAO {

    public function queryAllWithName($start, $end, $assetid) {
        $sql = 'SELECT * FROM assets where assetid=' . $assetid . ' order by assetid desc limit ' . $start . ',' . $end . '';
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

    public function loadimted($start, $end, $id) {
        $sql = 'SELECT * FROM assets WHERE assetId = ' . $id . '  order by assetid desc limit ' . $start . ',' . $end . '';
        $sqlQuery = new SqlQuery($sql);

        //print_r($sql);
        return $this->getList($sqlQuery);
    }

    public function showExt($id) {
        $sql = 'SELECT * FROM assets left join assetssale on assets.assetid = assetssale.assetsid WHERE assetId = ' . $id . '  order by assetid desc';
        $sqlQuery = new SqlQuery($sql);

        //print_r($sql);
        return $this->getList($sqlQuery);
    }

    public function queryAllWithLimit($start, $end) {
        $sql = 'SELECT * FROM assets left join assetssale on assets.assetid = assetssale.assetsid order by assetid desc limit ' . $start . ',' . $end . '';
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

    public function queryAllForShow() {
        $sql = 'SELECT * FROM assets order by assetid desc ';
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

    public function updateDele($asset) {
        $sql = 'UPDATE assets SET userid = ?, conditions = ?, assetsDate = ? WHERE assetId = ?';
        $sqlQuery = new SqlQuery($sql);

        $sqlQuery->setNumber($asset->userid);
        $sqlQuery->setNumber($asset->conditions);
        $sqlQuery->set($asset->assetsDate);

        $sqlQuery->setNumber($asset->assetId);
        return $this->executeUpdate($sqlQuery);
    }

    public function queryAllbycatid($catid) {
        $sql = 'SELECT * FROM assets where assetscatid=' . $catid . ' ';
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

    public function queryWithDateGroupByAssetscatId($startDate, $endDate) {
        $sql = 'SELECT SUM(assetsValue) as sumasset, assetscat.cattitel
		 FROM assets JOIN assetscat
		 ON assets.assetscatid = assetscat.assetscatid
		 where assets.conditions = 0 and assetscat.del = 0
		 and  assets.assetsDate >= "' . $startDate . '" and assets.assetsDate <= "' . $endDate . '"
		 GROUP BY assets.assetscatid';
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

    public function queryallassetcategory() {
        $sql = 'SELECT SUM(assetsValue) as sumasset, assetscat.cattitel
		 FROM assets JOIN assetscat
		 ON assets.assetscatid = assetscat.assetscatid
		 where assets.conditions = 0 and assetscat.del = 0
		 GROUP BY assets.assetscatid';
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

}

?>