GL-FW-1: add created/payed filter to transfer/index and transfer/list
This commit is contained in:
@@ -7,7 +7,6 @@ use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use common\models\Transfer;
|
||||
use yii\db\Expression;
|
||||
use yii\base\Object;
|
||||
use yii\db\Query;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use common\models\Account;
|
||||
@@ -19,9 +18,7 @@ use common\components\RoleDefinition;
|
||||
*/
|
||||
class TransferSearch extends Transfer
|
||||
{
|
||||
public $searchObjectName;
|
||||
public $searchTypeName;
|
||||
public $searchUserName;
|
||||
|
||||
public $start;
|
||||
public $end;
|
||||
@@ -42,6 +39,9 @@ class TransferSearch extends Transfer
|
||||
|
||||
public $output;
|
||||
|
||||
public $bought_in_interval = false;
|
||||
public $payed_in_interval = false;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@@ -50,12 +50,12 @@ class TransferSearch extends Transfer
|
||||
return [
|
||||
[['id_account', 'id_user', 'type', 'status', 'payment_method','paid_by'], 'integer'],
|
||||
[['customer_name','output','transfer_name', 'card_number' ], 'safe'],
|
||||
// [[ 'searchObjectName' ], 'string'],
|
||||
// [[ 'start', ], 'date' , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
|
||||
// [[ 'end' , ], 'date' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
|
||||
[['start',], 'date', 'format' => Yii::$app->formatter->datetimeFormat, 'timestampAttribute' => 'timestampStart', 'timestampAttributeFormat' => 'yyyy-MM-dd HH:mm', 'timeZone' => 'UTC'],
|
||||
[['end',], 'date', 'format' => Yii::$app->formatter->datetimeFormat, 'timestampAttribute' => 'timestampEnd', 'timestampAttributeFormat' => 'yyyy-MM-dd HH:mm', 'timeZone' => 'UTC'],
|
||||
['types', 'each', 'rule' => ['integer']],
|
||||
[['bought_in_interval','payed_in_interval'],'boolean'] ,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -73,12 +73,12 @@ class TransferSearch extends Transfer
|
||||
* @return Expression the payment method expression
|
||||
*/
|
||||
private function buildPaymentMethodExpression(){
|
||||
$s = "case";
|
||||
$s = 'case';
|
||||
$arr = Transfer::paymentMethods();
|
||||
foreach ( $arr as $key =>$value ){
|
||||
$s .= " when transfer.payment_method = $key then '$value' ";
|
||||
}
|
||||
$s .=" end as transfer_payment_method";
|
||||
$s .= ' end as transfer_payment_method';
|
||||
return new Expression($s);
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ class TransferSearch extends Transfer
|
||||
{
|
||||
$query = new Query();
|
||||
|
||||
if ($mode == 'select') {
|
||||
if ($mode === 'select') {
|
||||
$query->select([
|
||||
'transfer.id_transfer as transfer_id_transfer',
|
||||
new Expression('case
|
||||
@@ -134,22 +134,22 @@ class TransferSearch extends Transfer
|
||||
when transfer.type = ' . Transfer::TYPE_PRODUCT . ' then sale.comment
|
||||
when transfer.type = ' . Transfer::TYPE_MONEY_MOVEMENT_OUT . ' then money_movement.comment end as all_comment'),
|
||||
]);
|
||||
}else if ( $mode == 'total'){
|
||||
}else if ( $mode === 'total'){
|
||||
$query->select([
|
||||
new Expression('coalesce(sum(transfer.count),0) as total_count'),
|
||||
new Expression('coalesce(sum(transfer.money),0) as total_money'),
|
||||
]);
|
||||
}
|
||||
$query->from("transfer");
|
||||
$query->from('transfer');
|
||||
$query->innerJoin('account', 'account.id_account = transfer.id_account');
|
||||
$query->innerJoin('user', " user.id = transfer.id_user");
|
||||
$query->leftJoin('customer', " transfer.id_customer = customer.id_customer");
|
||||
$query->leftJoin('card', " card.id_card = customer.id_customer_card");
|
||||
$query->leftJoin('user as paid_by', " paid_by.id = transfer.paid_by");
|
||||
$query->leftJoin('ticket', "ticket.id_ticket = transfer.id_object and transfer.type = " . Transfer::TYPE_TICKET);
|
||||
$query->leftJoin('sale', "sale.id_sale = transfer.id_object and transfer.type = " . Transfer::TYPE_PRODUCT);
|
||||
$query->leftJoin('money_movement', "money_movement.id_money_movement = transfer.id_object and transfer.type = " . Transfer::TYPE_MONEY_MOVEMENT_OUT);
|
||||
$query->leftJoin('ticket_type', "ticket_type.id_ticket_type = ticket.id_ticket_type");
|
||||
$query->innerJoin('user', ' user.id = transfer.id_user');
|
||||
$query->leftJoin('customer', ' transfer.id_customer = customer.id_customer');
|
||||
$query->leftJoin('card', ' card.id_card = customer.id_customer_card');
|
||||
$query->leftJoin('user as paid_by', ' paid_by.id = transfer.paid_by');
|
||||
$query->leftJoin('ticket', 'ticket.id_ticket = transfer.id_object and transfer.type = ' . Transfer::TYPE_TICKET);
|
||||
$query->leftJoin('sale', 'sale.id_sale = transfer.id_object and transfer.type = ' . Transfer::TYPE_PRODUCT);
|
||||
$query->leftJoin('money_movement', 'money_movement.id_money_movement = transfer.id_object and transfer.type = ' . Transfer::TYPE_MONEY_MOVEMENT_OUT);
|
||||
$query->leftJoin('ticket_type', 'ticket_type.id_ticket_type = ticket.id_ticket_type');
|
||||
$query->leftJoin('product', 'product.id_product = sale.id_product');
|
||||
|
||||
if (!$valid) {
|
||||
@@ -158,7 +158,7 @@ class TransferSearch extends Transfer
|
||||
}
|
||||
|
||||
if (!RoleDefinition::isAdmin()) {
|
||||
$query->innerJoin("user_account_assignment", 'transfer.id_account = user_account_assignment.id_account');
|
||||
$query->innerJoin('user_account_assignment', 'transfer.id_account = user_account_assignment.id_account');
|
||||
$query->andWhere(['user_account_assignment.id_user' => Yii::$app->user->id]);
|
||||
$query->andWhere(['account.type' => Account::TYPE_ALL]);
|
||||
|
||||
@@ -180,10 +180,29 @@ class TransferSearch extends Transfer
|
||||
}
|
||||
$query->andFilterWhere(['in', 'transfer.type', $this->types]);
|
||||
|
||||
$created_condition = ['and', ['>=', 'transfer.created_at', $this->timestampStart], ['<', 'transfer.created_at', $this->timestampEnd]];
|
||||
$paid_condition = ['and', ['>=', 'transfer.paid_at', $this->timestampStart], ['<', 'transfer.paid_at', $this->timestampEnd]];
|
||||
|
||||
$query->andFilterWhere(['or', $created_condition, $paid_condition]);
|
||||
$all = ($this->bought_in_interval && $this->payed_in_interval)
|
||||
|| ( !$this->bought_in_interval && !$this->payed_in_interval);
|
||||
|
||||
|
||||
$orConditions = [];
|
||||
|
||||
if ( $all || $this->bought_in_interval){
|
||||
$created_condition = ['and', ['>=', 'transfer.created_at', $this->timestampStart], ['<', 'transfer.created_at', $this->timestampEnd]];
|
||||
$orConditions[] = $created_condition;
|
||||
}
|
||||
|
||||
if ( $all || $this->payed_in_interval ){
|
||||
$paid_condition = ['and', ['>=', 'transfer.paid_at', $this->timestampStart], ['<', 'transfer.paid_at', $this->timestampEnd]];
|
||||
$orConditions[] = $paid_condition;
|
||||
}
|
||||
|
||||
|
||||
if ( count($orConditions) === 2){
|
||||
$query->andFilterWhere(['or', $orConditions[0], $orConditions[1]]);
|
||||
}else if ( count($orConditions) === 1 ){
|
||||
$query->andFilterWhere($orConditions[0]);
|
||||
}
|
||||
|
||||
if (isset($this->id_user)) {
|
||||
$query->andFilterWhere([
|
||||
@@ -250,24 +269,17 @@ class TransferSearch extends Transfer
|
||||
]
|
||||
];
|
||||
|
||||
if ($this->output == 'pdf' || $this->output == 'xls') {
|
||||
if ($this->output === 'pdf' || $this->output === 'xls') {
|
||||
$dataProviderSetup['pagination'] = false;
|
||||
};
|
||||
|
||||
$dataProvider = new ActiveDataProvider($dataProviderSetup);
|
||||
return new ActiveDataProvider($dataProviderSetup);
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
|
||||
|
||||
public function totalsTransfers()
|
||||
{
|
||||
$accountTotals = [];
|
||||
$fullTotal = [
|
||||
'label' => Yii::t('common/transfer', 'Total'),
|
||||
'money' => 0
|
||||
];
|
||||
|
||||
|
||||
$accounts = Account::read();
|
||||
$accountMap = ArrayHelper::map($accounts, 'id_account', 'name');
|
||||
@@ -276,7 +288,7 @@ class TransferSearch extends Transfer
|
||||
/**mk totals need date time format*/
|
||||
$start = $this->timestampStart;
|
||||
if (isset($start) && !empty($start)) {
|
||||
$start .= " 00:00";
|
||||
$start .= ' 00:00';
|
||||
}
|
||||
|
||||
|
||||
@@ -285,5 +297,17 @@ class TransferSearch extends Transfer
|
||||
|
||||
}
|
||||
|
||||
public function attributeLabels()
|
||||
{
|
||||
return
|
||||
array_merge(
|
||||
parent::attributeLabels() ,
|
||||
[
|
||||
'bought_in_interval' => 'Kiadva az időszakban',
|
||||
'payed_in_interval' => 'Fizetve az időszakban',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user