<?php
/**
 * Class that operate on table 'm_maintenancereceipt'. Database Mysql.
 *
 * @author: http://phpdao.com
 * @date: 2014-09-07 16:06
 */
class MMaintenancereceiptMySqlExtDAO extends MMaintenancereceiptMySqlDAO{
	
	
	public function queryallByclientIdEX($clientId){
		$sql = 'SELECT m_maintenancereceipt.maintenanceReceiptId ,m_comreceipt.receiptserial,m_maintenancereceipt.totalCost
		FROM m_maintenancereceipt
		JOIN m_comreceipt ON m_comreceipt.id  = m_maintenancereceipt.receiptId
		Where m_comreceipt.clientid = ?
		AND m_maintenancereceipt.del = 0';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->setNumber($clientId);
		return $this->getList($sqlQuery);
	}
	
	
	public function getTotalCostEX($Id){
		$sql = 'SELECT m_comreceipt.totalCost
		FROM m_maintenancereceipt
		JOIN m_comreceipt ON m_comreceipt.id =m_maintenancereceipt.receiptId
		Where maintenanceReceiptId = ?';
		$sqlQuery = new SqlQuery($sql);
		$sqlQuery->setNumber($Id);
		return $this->querySingleResult($sqlQuery);
	}
	
	public function updateMaintenanceReceiptType($type,$maintenanceReceiptId){
		$sql = 'UPDATE m_maintenancereceipt SET type = ? WHERE maintenanceReceiptId = ?';
		$sqlQuery = new SqlQuery($sql);
		
		$sqlQuery->setNumber($type);
		$sqlQuery->setNumber($maintenanceReceiptId);
		
		return $this->executeUpdate($sqlQuery);
	}
	
	
	public function updatemantannce($mMaintenancereceipt){
		$sql = 'UPDATE m_maintenancereceipt SET  totalCost = ?, type = ?, userId = ?, branchId = ?, maintenanceReceiptDAte = ?, del = ? WHERE receiptId = ?';
		$sqlQuery = new SqlQuery($sql);
		
		
		$sqlQuery->set($mMaintenancereceipt->totalCost);
		$sqlQuery->setNumber($mMaintenancereceipt->type);
		$sqlQuery->setNumber($mMaintenancereceipt->userId);
		$sqlQuery->setNumber($mMaintenancereceipt->branchId);
		$sqlQuery->set($mMaintenancereceipt->maintenanceReceiptDAte);
		$sqlQuery->setNumber($mMaintenancereceipt->del);

		$sqlQuery->setNumber($mMaintenancereceipt->receiptId);
		return $this->executeUpdate($sqlQuery);
	}
	
	
	public function updatedelete($mMaintenancereceipt){
		$sql = 'UPDATE m_maintenancereceipt SET  userId = ?, branchId = ?, maintenanceReceiptDAte = ?, del = ? WHERE receiptId = ?';
		$sqlQuery = new SqlQuery($sql);
		
		$sqlQuery->setNumber($mMaintenancereceipt->userId);
		$sqlQuery->setNumber($mMaintenancereceipt->branchId);
		$sqlQuery->set($mMaintenancereceipt->maintenanceReceiptDAte);
		$sqlQuery->setNumber($mMaintenancereceipt->del);

		$sqlQuery->setNumber($mMaintenancereceipt->receiptId);
		return $this->executeUpdate($sqlQuery);
	}


}
?>