<?php

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

    //
    public function queryAllbillsettings($billnameid) {
        $sql = 'SELECT billsettings.* ,billproperty.billpropertyname ,billproperty.billpropertyid   FROM billsettings
			 right join billproperty on
			billproperty.billpropertyid=billsettings.billpropertyid
			AND billsettings.billnameid= ' . $billnameid . '
			';
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

    public function queryAllbillsettingsNotDeleted($billnameid) {
        $sql = 'SELECT billsettings.* ,billproperty.billpropertyname ,billproperty.billpropertyid   FROM billsettings
			  join billproperty on
			billproperty.billpropertyid=billsettings.billpropertyid
			AND billsettings.billnameid= ' . $billnameid . '
			AND billproperty.conditions = 0
			order by billproperty.billpropertyid ASC';
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

    public function queryAllbillsettingsNotDeleted_f($billnameid) {
        $sql = 'SELECT billsettings.* ,billproperty.billpropertyname ,billproperty.billpropertyid
                FROM billproperty
                left join billsettings on
		billproperty.billpropertyid=billsettings.billpropertyid
		AND billsettings.billnameid= ' . $billnameid . '
		AND billproperty.conditions = 0
		order by billproperty.billpropertyid ASC';
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

    public function queryAllbillsettingsNew_f($billnameid) {
        $sql = 'SELECT billproperty.billpropertyid FROM billproperty WHERE NOT EXISTS (
                                SELECT 1 FROM billsettings
                                WHERE billsettings.billpropertyid =billproperty.billpropertyid
                                AND billproperty.conditions = 0
                                and billsettings.billnameid= ' . $billnameid . ')';
//        $sql = 'SELECT billproperty.billpropertyid
//                FROM billproperty
//                left join billsettings on
//		billproperty.billpropertyid=billsettings.billpropertyid
//		AND billsettings.billnameid= ' . $billnameid . '
//		AND billproperty.conditions = 0
//                AND billsettings.billsettingsid IS Null';
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

    public function queryWithBillnameId($billnameid) {
        $sql = 'SELECT billsettings.*, billproperty.billpropertyname
		 FROM billsettings JOIN billproperty
		 ON billsettings.billpropertyid = billproperty.billpropertyid JOIN billname
		 ON billsettings.billnameid = billname.billnameid
		 where billproperty.conditions = 0 AND billname.conditions = 0
		 and billsettings.billnameid =' . $billnameid . '
		 order by billsettings.billpropertyid ASC';


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

    public function queryByBillidAndBillpropertyid($billnameid, $billpropertyid) {
        $sql = 'SELECT *   FROM billsettings where billnameid= ' . $billnameid . ' and billpropertyid = ' . $billpropertyid . '';
        $sqlQuery = new SqlQuery($sql);
        // print_r($sqlQuery);
        return $this->getList($sqlQuery);
    }

    public function queryByBillnameidSimple($billnameid) {
        $sql = 'SELECT * FROM billsettings WHERE billnameid = ' . $billnameid . ' ';
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

}

?>