<?php

/**
 * Class that operate on table 'productionexecutionoutput'. Database Mysql.
 *
 * @author: http://phpdao.com
 * @date: 2018-11-28 13:58
 */
class ProductionexecutionoutputMySqlExtDAO extends ProductionexecutionoutputMySqlDAO {

    public function queryAllProductsByExecutionId($id) {
        $sql = 'SELECT productionexecutionoutput. * , product.productName ,product.productBuyPrice,size.name as sizeName,color.name as colorName
		FROM productionexecutionoutput
		JOIN product ON product.productId = productionexecutionoutput.productid

                left join sizecolor as size on size.id=productionexecutionoutput.sizeid
                left join sizecolor as color on color.id=productionexecutionoutput.colorid

		where productionexecutionoutput.exeutionid=' . $id . '
		';
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

    public function queryAllOutputEx($query) {
        $sql = 'SELECT productionexecutionoutput. *, productionexecution.orderId, productionexecution.orderdate, productionexecution.rentcost, productionexecution.othercost, product.productName
		FROM productionexecutionoutput
                JOIN productionexecution
                    ON productionexecutionoutput.exeutionid = productionexecution.id
		JOIN product
                    ON product.productId = productionexecutionoutput.productid
                    where 1 ' . $query . '
		';
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

    public function queryAllOutputGroupedEx($query) {
        $sql = 'SELECT productionexecutionoutput.*, sum(productionexecutionoutput.num) as num, sum(productionexecutionoutput.cost) cost, productionexecution.orderdate,
                sum(productionexecution.rentcost * productionexecutionoutput.num) rentcost, sum(productionexecution.othercost * productionexecutionoutput.num) othercost,
                product.productName
                FROM productionexecutionoutput
                JOIN productionexecution
                    ON productionexecutionoutput.exeutionid = productionexecution.id
                JOIN product
                    ON product.productId = productionexecutionoutput.productid
                where 1 ' . $query . '
                group by productionexecutionoutput.productid
		';
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

}

?>