<?php
/**
 * Class that operate on table 'm_externalmaintenance'. Database Mysql.
 *
 * @author: http://phpdao.com
 * @date: 2014-09-07 16:06
 */
class MExternalmaintenanceMySqlExtDAO extends MExternalmaintenanceMySqlDAO{

	public function queryByOurSerialEX($value){
		$sql = 'SELECT supplierCost 
		FROM m_externalmaintenance 
		WHERE ourSerial = ?
		AND del =0';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->set($value);
		return $this->getList($sqlQuery);
	}

	public function updateMExternalMaintenanceEX($externalMintenanceId,$externalmaintenanceReturn,$returnComment,$supplierCost,$returnedDate){
		$sql = 'UPDATE m_externalmaintenance SET externalmaintenanceReturn = ?, returnComment = ?, supplierCost = ?, returnedDate = ? WHERE externalmaintenanceId = ?';
		$sqlQuery = new SqlQuery($sql);
		
		
		$sqlQuery->setNumber($externalmaintenanceReturn);
		$sqlQuery->setString2($returnComment);
		$sqlQuery->set($supplierCost);
		$sqlQuery->set($returnedDate);


		$sqlQuery->setNumber($externalMintenanceId);
		return $this->executeUpdate($sqlQuery);
	}
	
	public function queryByExternalmaintenanceReturnEX($queryString){
		$sql = 'SELECT externalmaintenanceId
		FROM m_externalmaintenance 
		JOIN supplier ON supplier.supplierid = m_externalmaintenance.supplierId
		JOIN m_comreceiptdetail
		 ON m_comreceiptdetail.ourserial=m_externalmaintenance.ourSerial
		'.$queryString.'';
		$sqlQuery = new SqlQuery($sql);
		
		//print_r($sql);
		return $this->getList($sqlQuery);
	}
	
	public function queryByExternalmaintenanceReturnEXWithLimit($queryString,$start,$end){
		$sql = 'SELECT externalmaintenanceId,m_externalmaintenance.ourSerial,m_externalmaintenance.supplierId,suppliername,m_comreceiptdetail.productserial,productName
		FROM m_externalmaintenance 
		JOIN supplier ON supplier.supplierid = m_externalmaintenance.supplierId
		JOIN m_comreceiptdetail
		 ON m_comreceiptdetail.ourserial=m_externalmaintenance.ourSerial
		 JOIN product ON product.productId = m_comreceiptdetail.productId
		'.$queryString.'
		limit '.$start.', '.$end.'';
		$sqlQuery = new SqlQuery($sql);
		
		//print_r($sql);
		return $this->getList($sqlQuery);
	}
	
	
}
?>