Мне нужно вернуть все InstallmentDate
S вместе с возвращенными данными, проблема здесь у меня же OrderInstallmentDetailsId
для нескольких InstallmentDate
s.
$select = $this->select()
->setIntegrityCheck(false)
->from(array('j' => DB_TABLE_PREFIX . 'finance_journal'), array(
'*',
'JournalCreatedDate' => 'CreatedDate'
))
->join(array('jr' => DB_TABLE_PREFIX . 'finance_journal_reference'), 'j.JournalId = jr.JournalId', array(
'totalDebitAmount' => 'SUM(DebitAmount)',
'totalCreditAmount' => 'SUM(CreditAmount)',
'debitBalanceAmount' => 'SUM(DebitAmount) - SUM(CreditAmount)',
))
->join(array('a' => DB_TABLE_PREFIX . 'finance_account'), 'jr.AccountId = a.AccountId', array(
'AccountId',
'AccountGroupId',
'AccountCode',
'AccountPath',
'AccountName'
))
->join(array('ja' => DB_TABLE_PREFIX . 'finance_journal_approved_user'), 'j.JournalId = ja.JournalId', array())
->join(array('c' => DB_TABLE_PREFIX . 'customer'), 'a.AccountId = c.AccountId', array(
'CustomerId',
'CustomerAccountId' => 'AccountId'
))
->join(array('O' => DB_TABLE_PREFIX . 'order'), 'O.UserId = c .CustomerId', array(
'OrderId'
,'OrderInstallmentId'))
->join(array('oi' => DB_TABLE_PREFIX . 'order_installment'), 'oi.OrderInstallmentId = O.OrderInstallmentId', array(
'OrderInstallmentId',
'InstallmentId',
'NumberOfInstallments'
))
->join(array('oid' => DB_TABLE_PREFIX . 'order_installment_details'), 'oid.OrderInstallmentId = oi.OrderInstallmentId', array(
'OrderInstallmentDetailsId',
'InstallmentDate'
))
->join(array('f' => DB_TABLE_PREFIX . 'firm'), 'f.FirmId = c.FirmId', array('FirmName'))
->join(array('u' => DB_TABLE_PREFIX . 'user'), 'u.UserId = c.CustomerId', array('FirstName', 'LastName'))
->group('a.AccountId')
->order('j.CreatedDate ASC');
//->order('oid.OrderInstallmentDetailsId DESC');
if ($this->_authUser->sessionBranch() > 0) {
$select->where('j.BranchId = ?', $this->_authUser->sessionBranch());
}
if ($firmId > 0) {
$select->where('f.FirmId = ?', $firmId);
}
if (empty($fromDate)) {
$fromDate = strtotime('-30 days');
} else {
$select->where('j.JournalDate >= ?', Utils_Converter::mysqlDate($fromDate));
}
if (!empty($toDate)) {
$select->where('j.JournalDate <= ?', Utils_Converter::mysqlDate($toDate));
}
if ($minimumDebitBalance == 0) {
$select->having('debitBalanceAmount > ?', $minimumDebitBalance);
} else {
$select->having('debitBalanceAmount >= ?', $minimumDebitBalance);
}
if ($maximumDebitBalance == 0) {
} else {
$select->having('debitBalanceAmount < ?', $maximumDebitBalance);
}
//echo $select;exit;
$returnData = array();
foreach ($this->fetchAll($select) as $row) {
//if($row['debitBalanceAmount'] >= $minimumDebitBalance){
$returnData[$row['AccountId']] = $row->toArray();
//}
}
return $returnData;
}
Моя главная цель — получить максимальную дату из массива дат.
->join(array('oid' => DB_TABLE_PREFIX . 'order_installment_details'), 'oid.OrderInstallmentId = oi.OrderInstallmentId', array(
'OrderInstallmentDetailsId',
'lastInstallmentDate' => new Zend_Db_Expr('MAX(InstallmentDate)')
))
->join(array('f' => DB_TABLE_PREFIX . 'firm'), 'f.FirmId = c.FirmId', array('FirmName'))
->join(array('u' => DB_TABLE_PREFIX . 'user'), 'u.UserId = c.CustomerId', array('FirstName', 'LastName'))
->group('a.AccountId')
->order('j.CreatedDate ASC');
Других решений пока нет …