<?php

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

    ///===================== available kemp===========================////////
    public function queryAlllimted($start, $end, $supplierID, $today) {
        $sql = 'SELECT kempiala.*  ,client.clientname  FROM kempiala
		join client on client.clientid=kempiala.clientID
		where supplierID= ' . $supplierID . ' and expiredate >= "' . $today . '"
		order by id desc limit ' . $start . ',' . $end . '';



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

    public function queryAllex($supplierID, $today) {
        $sql = 'SELECT * FROM kempiala where supplierID= ' . $supplierID . '  and expiredate >= "' . $today . '" ';
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

    ///===================== sold kemp===========================////////
    public function queryAllsoldlimted($start, $end, $supplierID) {
        $sql = 'SELECT kempiala.*  ,client.clientname  FROM kempiala
		join client on client.clientid=kempiala.clientID
		where supplierID != ' . $supplierID . '
		order by id desc limit ' . $start . ',' . $end . '';



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

    public function queryAllsold($supplierID) {
        $sql = 'SELECT * FROM kempiala where supplierID != ' . $supplierID . '   ';
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

///===================== expier kemp===========================////////
    public function queryAllexpier($supplierID, $today) {
        $sql = 'SELECT kempiala.*  ,client.clientname  FROM kempiala
		join client on client.clientid=kempiala.clientID
		where supplierID = ' . $supplierID . ' and expiredate < "' . $today . '"
		order by id desc';

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

    public function queryAllexpierlimted($start, $end, $supplierID, $today) {
        $sql = 'SELECT kempiala.*  ,client.clientname  FROM kempiala
		join client on client.clientid=kempiala.clientID
		where supplierID= ' . $supplierID . ' and expiredate < "' . $today . '"
		order by id desc  limit ' . $start . ',' . $end . '';



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

    ///===================== end   expier kemp===========================////////
    // load all kemp data
    public function loadEX($id) {
        $sql = 'SELECT kempiala.*  ,client.clientname,supplier.suppliername  FROM kempiala
		join client on client.clientid=kempiala.clientID
		 left join supplier on
		supplier.supplierid=kempiala.supplierID
		where kempiala.id=' . $id . '
		 ';



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

    public function updatekemp($kempiala, $clientcomment) {
        $sql = 'UPDATE kempiala SET  clientcomment = ?,  expiredate = ? WHERE id = ?';
        $sqlQuery = new SqlQuery($sql);
        $sqlQuery->setString2($clientcomment);
        $sqlQuery->set($kempiala->expiredate);


        $sqlQuery->setNumber($kempiala->id);
        return $this->executeUpdate($sqlQuery);
    }

    public function updatedel($kempiala) {

        $sql = 'UPDATE kempiala SET conditions = ?  WHERE id = ?';
        $sqlQuery = new SqlQuery($sql);

        $sqlQuery->setNumber($kempiala->conditions);


        $sqlQuery->setNumber($kempiala->id);
        return $this->executeUpdate($sqlQuery);
    }

    public function updatesell($kempiala, $suppliercomment) {
        $sql = 'UPDATE kempiala SET selling = ?,  supplierID = ?, sellingdate = ? , suppliercomment = ? WHERE id = ?';
        $sqlQuery = new SqlQuery($sql);

        $sqlQuery->setNumber($kempiala->selling);

        $sqlQuery->setNumber($kempiala->supplierID);
        $sqlQuery->set($kempiala->sellingdate);

        $sqlQuery->setString2($suppliercomment);

        $sqlQuery->setNumber($kempiala->id);
        return $this->executeUpdate($sqlQuery);
    }

    public function queryWithSellingAndConditions($selling) {
        $sql = 'SELECT * FROM kempiala where selling = ' . $selling . ' and conditions = 0';
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

    public function queryWithSellingAndConditionsExt($selling) {
        $sql = 'SELECT SUM(value) FROM kempiala
		where selling = ' . $selling . '
		and conditions = 0';
        $sqlQuery = new SqlQuery($sql);
        return $this->QuerySingleResult($sqlQuery);
    }

    public function queryAllkempila($today, $todayfor7days) {
        $sql = 'SELECT client.*,kempiala.* FROM kempiala JOIN client
		ON client.clientid=kempiala.clientID
		 where kempiala.conditions=0 and kempiala.selling=0
		  and kempiala.expiredate >=  "' . $today . '"  and  kempiala.expiredate <= "' . $todayfor7days . '" ';
        //print_r("<br>".$sql);
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

    public function queryAlllavilablekempila($supplierID, $today) {
        $sql = 'SELECT kempiala.* FROM kempiala
		where supplierID= ' . $supplierID . '
		and conditions =0 and expiredate >= "' . $today . '"';
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

    public function queryAlllavilablekempila2($supplierID, $today) {
        $sql = 'SELECT kempiala.* FROM kempiala
		where supplierID= ' . $supplierID . '
		and conditions =0 and expiredate > "' . $today . '"';
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

    public function queryAllexpierkempila($supplierID, $today) {
        $sql = 'SELECT kempiala.*   FROM kempiala
		where supplierID = ' . $supplierID . '
			and conditions =0 and expiredate < "' . $today . '"
		order by id desc';

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

    public function queryAllexpierkempila2($supplierID, $today) {
        $sql = 'SELECT kempiala.*   FROM kempiala
		where supplierID = ' . $supplierID . '
			and conditions =0 and expiredate < "' . $today . '"
		order by id desc';

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

}

?>