add collection
This commit is contained in:
@@ -451,6 +451,82 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
|
||||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $mode The mode to load
|
||||
* Available modes
|
||||
* <ul>
|
||||
* <li>
|
||||
* <h2>created_at</h2>
|
||||
* <p>Load all transfer which were created </p>
|
||||
* </li>
|
||||
* <li>
|
||||
* <h2>paid_at</h2>
|
||||
* <p>Load all transfer which were paid </p>
|
||||
* </li>
|
||||
* <li>
|
||||
* <h2>created_at_paid</h2>
|
||||
* <p>Load all transfer which were created and paid </p>
|
||||
* </li>
|
||||
* <li>
|
||||
* <h2>created_at_not_paid</h2>
|
||||
* <p>Load all transfer which were created but not paid </p>
|
||||
* </li>
|
||||
* <li>
|
||||
* <h2>paid_at_not_created_at</h2>
|
||||
* <p>Load all transfer which were not created but paid . Works correctly only,
|
||||
* when start and end date given
|
||||
* </p>
|
||||
* </li>
|
||||
* </ul>
|
||||
*
|
||||
* */
|
||||
public static function mkTotalQuery($mode,$start,$end,$idUser,$types,$idAccount){
|
||||
|
||||
$query = new Query();
|
||||
|
||||
$query->addSelect( [
|
||||
new Expression( 'transfer.id_account as account'),
|
||||
new Expression( ' COALESCE(sum( ( case when direction = '.Transfer::DIRECTION_OUT.' then -1 else 1 end )* transfer.money ),0) as money' )
|
||||
|
||||
]);
|
||||
$query->from('transfer');
|
||||
|
||||
$query->andFilterWhere([
|
||||
'id_account' => $idAccount,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere(['id_user' => $idUser]);
|
||||
|
||||
$query->andFilterWhere(['in' ,'type', $types]);
|
||||
|
||||
|
||||
if ( $mode == 'created_at'){
|
||||
$query->andFilterWhere([ '>=', 'transfer.created_at' , $start] );
|
||||
$query->andFilterWhere([ '<' , 'transfer.created_at' , $end ] );
|
||||
}else if ( $mode == 'paid_at'){
|
||||
$query->andFilterWhere([ '>=', 'transfer.paid_at' , $start ] );
|
||||
$query->andFilterWhere([ '<' , 'transfer.paid_at' , $end ] );
|
||||
}else if ( $mode == 'created_at_not_paid'){
|
||||
$query->andFilterWhere([ "transfer.status" => Transfer::STATUS_NOT_PAID ] );
|
||||
$query->andFilterWhere([ '>=', 'transfer.created_at' , $start ] );
|
||||
$query->andFilterWhere([ '<' , 'transfer.created_at' , $end ] );
|
||||
}else if ( $mode == 'created_at_paid'){
|
||||
$query->andFilterWhere([ "transfer.status" => Transfer::STATUS_PAID ] );
|
||||
$query->andFilterWhere([ '>=', 'transfer.created_at' , $start ] );
|
||||
$query->andFilterWhere([ '<' , 'transfer.created_at' , $end ] );
|
||||
}else if ( $mode == 'paid_at_not_created_at'){
|
||||
$query->andFilterWhere([ "transfer.status" => Transfer::STATUS_PAID ] );
|
||||
$query->andFilterWhere([ '>=', 'transfer.paid_at' , $start ] );
|
||||
$query->andFilterWhere([ '<' , 'transfer.paid_at' , $end ] );
|
||||
$query->andFilterWhere( ['or', [ '<', 'transfer.created_at' , $start ] ,[ '>=' , 'transfer.created_at' , $end ] ] );
|
||||
}
|
||||
|
||||
$query->groupBy('transfer.id_account');
|
||||
|
||||
return $query;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user