<?php

/**
 * Class that operate on table 'productionrateproduct'. Database Mysql.
 *
 * @author: http://phpdao.com
 * @date: 2014-04-01 11:09
 */
class ProductionrateproductMySqlExtDAO extends ProductionrateproductMySqlDAO {

    public function queryAllByProductionRateId($id) {
        $sql = 'SELECT productionrateproduct. * , product.productName,productcat.productCatName ,product.productBuyPrice , unit.unitName
                ,productBuyPrice,lastbuyprice,lastbuyprice_withDiscount,meanbuyprice,meanbuyprice_withDiscount,overAllAveragePrice,lastbuyprice_withTax,meanbuyprice_withTax
                ,productnumber,size.name as sizeName,color.name as colorName
		FROM productionrateproduct
		JOIN product
			 ON product.productId = productionrateproduct.productId
		JOIN productcat
                        ON product.productCatId = productcat.productCatId
		JOIN productunit
			 ON  productunit.productunitid=productionrateproduct.unitId
		JOIN unit
         	 ON unit.unitId= productunit.unitid

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

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

    public function insertWithId($productionrateproduct) {
        $sql = 'INSERT INTO productionrateproduct (productionRateProductId, productionRateId, productId, unitId, rate, quantity, userId, thedate, conditions,sizeid,colorid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?,?,?)';
        $sqlQuery = new SqlQuery($sql);

        $sqlQuery->setNumber($productionrateproduct->productionRateProductId);
        $sqlQuery->setNumber($productionrateproduct->productionRateId);
        $sqlQuery->setNumber($productionrateproduct->productId);
        $sqlQuery->setNumber($productionrateproduct->unitId);
        $sqlQuery->set($productionrateproduct->rate);
        $sqlQuery->set($productionrateproduct->quantity);
        $sqlQuery->setNumber($productionrateproduct->userId);
        $sqlQuery->set($productionrateproduct->thedate);
        $sqlQuery->setNumber($productionrateproduct->conditions);
        $sqlQuery->setNumber((int) $productionrateproduct->sizeid);
        $sqlQuery->setNumber((int) $productionrateproduct->colorid);

        $id = $this->executeInsert($sqlQuery);
        $productionrateproduct->productionRateProductId = $id;
        return $id;
    }

}

?>