<?php

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

    public function queryAllMovements($query) {
        $sql = 'SELECT accountmovement.*, bank.bankname, bankaccount.accountname, bankaccount.accountnumber, accountmovementcomment,user.employeename
                FROM accountmovement, bank, bankaccount ,user
                where accountmovement.bankid = bank.bankid and accountmovement.accountid = bankaccount.accountid and accountmovement.userid=user.userid ' . $query;
        $sqlQuery = new SqlQuery($sql);
        //  print_r($sql);
        return $this->getList($sqlQuery);
    }

    public function queryAllMovements2($query) {
        $sql = 'SELECT accountmovement.*, bank.bankname, bankaccount.accountname, bankaccount.accountnumber, accountmovementcomment,user.employeename,client.clientname as clientName
        FROM accountmovement
        JOIN bank ON accountmovement.bankid = bank.bankid
        JOIN bankaccount ON accountmovement.accountid = bankaccount.accountid
        JOIN user ON accountmovement.userid = user.userid
        LEFT JOIN client ON client.clientid = accountmovement.clientid
        where 1 ' . $query;
        $sqlQuery = new SqlQuery($sql);
//        print_r($sql);
        return $this->getList($sqlQuery);
    }

    public function loadMovement($tablename, $modelid) {
        $sql = 'SELECT accountmovement.*, bank.bankname, bankaccount.accountname, bankaccount.accountnumber FROM accountmovement, bank, bankaccount where accountmovement.bankid = bank.bankid and accountmovement.accountid = bankaccount.accountid and tablename="' . $tablename . '" and accountmovementmodelid=' . $modelid;
        $sqlQuery = new SqlQuery($sql);
        //print_r($sqlQuery);
        return $this->getRow($sqlQuery);
    }

    public function loadMovementEX($id) {
        $sql = 'SELECT accountmovement.*, bank.bankname, bankaccount.accountname, bankaccount.accountnumber FROM accountmovement, bank, bankaccount where accountmovement.bankid = bank.bankid and accountmovement.accountid = bankaccount.accountid and accountmovement.accountmovementid=' . $id;
        $sqlQuery = new SqlQuery($sql);
        //print_r($sqlQuery);
        return $this->getRow($sqlQuery);
    }

    public function sumValOfVisaAccount() {
        $sql = 'SELECT sum(accountbeginingbalance) as accountmovementamount
                 FROM bankaccount
                 where bankaccount.visa = 1 and bankaccount.conditions = 0';
        $sqlQuery = new SqlQuery($sql);
        //  print_r($sql);
        return $this->querySingleResult($sqlQuery);
    }

    public function getBankPaymentDetaildWithClientDebtChangeId($id) {
        $sql = 'SELECT * FROM accountmovement WHERE clientdebtchangeidfk = ' . $id;
        $sqlQuery = new SqlQuery($sql);
        return $this->getRow($sqlQuery);
    }

}

?>