<?php

/**
 * Class that operate on table 'soldserialproduct'. Database Mysql.
 *
 * @author: http://phpdao.com
 * @date: 2013-12-11 13:02
 */
class SoldserialproductMySqlExtDAO extends SoldserialproductMySqlDAO {

    public function queryallExbyid($productserailid) {
        $sql = 'SELECT soldserialproduct.*,product.productName,product.productSellUnitPrice,productserial.startdate
			,productserial.enddate
			 FROM soldserialproduct

			join productserial
			on productserial.productserailid=soldserialproduct.productserailid
			join product
			on product.productId=productserial.productid
			where soldserialproduct.productserailid=' . $productserailid . '
			order by soldserialproduct.soldserialproductid  ';

        //print_r($sql."<br><br><br><br>");
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

    public function updatedel($soldserialproduct) {
        $sql = 'UPDATE soldserialproduct SET del = ?   where `quantity`= ?    and   `sellbilltype` =? and `sellbillid` = ';
        $sqlQuery = new SqlQuery($sql);

        $sqlQuery->setNumber($soldserialproduct->del);
        $sqlQuery->setNumber($soldserialproduct->quantity);
        $sqlQuery->setNumber($soldserialproduct->sellbilltype);
        $sqlQuery->setNumber($soldserialproduct->sellbillid);


        return $this->executeUpdate($sqlQuery);
    }

    public function updatedel2($soldserialproduct) {
        $sql = 'UPDATE soldserialproduct SET del = ?   where `productserailid`= ?    and   `sellbilltype` =? and `sellbillid` = ';
        $sqlQuery = new SqlQuery($sql);

        $sqlQuery->setNumber($soldserialproduct->del);
        $sqlQuery->setNumber($soldserialproduct->productserailid);
        $sqlQuery->setNumber($soldserialproduct->sellbilltype);
        $sqlQuery->setNumber($soldserialproduct->sellbillid);


        return $this->executeUpdate($sqlQuery);
    }

    public function selectsoldeserial($soldserialproduct) {
        $sql = 'SELECT *  from  soldserialproduct where `quantity`= ' . $soldserialproduct->quantity . '    and   `sellbilltype` = ' . $soldserialproduct->sellbilltype . ' and `sellbillid` = ' . $soldserialproduct->sellbillid . '';
        $sqlQuery = new SqlQuery($sql);

        print_r($sql);

        $sqlQuery = new SqlQuery($sql);
        return $this->getRow($sqlQuery);
    }

    public function selectsoldeserial2($soldserialproduct) {
        $sql = 'SELECT *  from  soldserialproduct where productserailid= ' . $soldserialproduct->productserailid . '    and   `sellbilltype` = ' . $soldserialproduct->sellbilltype . ' and `sellbillid` = ' . $soldserialproduct->sellbillid . '';
        $sqlQuery = new SqlQuery($sql);

        //print_r($sql);

        $sqlQuery = new SqlQuery($sql);
        return $this->getRow($sqlQuery);
    }

    public function queryByQueryString($queryString = '') {
        $sql = 'SELECT soldserialproduct.* ,clientname,productCatName,productName,size.name as sizeName,color.name as colorName,serialnumber,don
                FROM soldserialproduct
                join productserial on productserial.productserailid = soldserialproduct.productserailid
                join product on productserial.productid=product.productId
                join productcat on product.productCatId=productcat.productCatId
                join client on soldserialproduct.clientid=client.clientid

                left join sizecolor as size on size.id = productserial.sizeid
                left join sizecolor as color on color.id = productserial.colorid
                where don > 0 and soldserialproduct.del = 0 ' . $queryString;
        //echo $sql;
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

    public function queryByQueryStringSimple($queryString = '') {
        $sql = 'SELECT soldserialproduct.* ,clientname
                FROM soldserialproduct
                join productserial on productserial.productserailid = soldserialproduct.productserailid
                join client on soldserialproduct.clientid=client.clientid
                where don > 0 and soldserialproduct.del = 0 ' . $queryString;
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

}

?>