add backend transfer list changes
This commit is contained in:
@@ -77,7 +77,7 @@ class ProcurementSearch extends Procurement
|
||||
'id_product' => $this->id_product,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere([ '>=', 'created_at', $this->date_start ] );
|
||||
$query->andFilterWhere([ '>=', 'created_at', $this->timestampStart ] );
|
||||
$query->andFilterWhere([ '<', 'created_at', $this->timestampEnd ] );
|
||||
|
||||
|
||||
|
||||
@@ -6,20 +6,39 @@ use Yii;
|
||||
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;
|
||||
|
||||
/**
|
||||
* TransferSearch represents the model behind the search form about `common\models\Transfer`.
|
||||
*/
|
||||
class TransferSearch extends Transfer
|
||||
{
|
||||
public $searchObjectName;
|
||||
public $searchTypeName;
|
||||
public $searchUserName;
|
||||
public $start;
|
||||
public $end;
|
||||
|
||||
public $timestampStart;
|
||||
public $timestampEnd;
|
||||
|
||||
public $accountTotals;
|
||||
public $fullTotal;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id_transfer', 'id_discount', 'id_currency', 'id_object', 'status', 'type', 'item_price', 'count', 'money', 'money_currency', 'rate', 'id_user'], 'integer'],
|
||||
[['comment', 'created_at', 'updated_at'], 'safe'],
|
||||
[[ 'id_account','id_user', 'type'], 'integer'],
|
||||
[[ 'searchObjectName' ], 'string'],
|
||||
[[ 'start', ], 'date' , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
|
||||
[[ 'end' , ], 'date' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -47,33 +66,108 @@ class TransferSearch extends Transfer
|
||||
'query' => $query,
|
||||
]);
|
||||
|
||||
$selectObjectName = "";
|
||||
$selectObjectName .= " case when transfer.type = " .self::TYPE_PRODUCT ." then product.name else ticket_type.name end as object_name";
|
||||
|
||||
$query->addSelect( ['*', new Expression($selectObjectName) ]);
|
||||
$query->joinWith('ticket');
|
||||
$query->joinWith('ticketType');
|
||||
$query->joinWith('product');
|
||||
|
||||
$this->load($params);
|
||||
|
||||
if (!$this->validate()) {
|
||||
// uncomment the following line if you do not want to return any records when validation fails
|
||||
// $query->where('0=1');
|
||||
$query->where('0=1');
|
||||
return $dataProvider;
|
||||
}
|
||||
|
||||
$query->andFilterWhere([
|
||||
'id_transfer' => $this->id_transfer,
|
||||
'id_discount' => $this->id_discount,
|
||||
'id_currency' => $this->id_currency,
|
||||
'id_object' => $this->id_object,
|
||||
'status' => $this->status,
|
||||
'type' => $this->type,
|
||||
'item_price' => $this->item_price,
|
||||
'count' => $this->count,
|
||||
'money' => $this->money,
|
||||
'money_currency' => $this->money_currency,
|
||||
'rate' => $this->rate,
|
||||
'id_user' => $this->id_user,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
'transfer.id_account' => $this->id_account,
|
||||
'transfer.type' => $this->type,
|
||||
'transfer.id_user' => $this->id_user,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere([ '>=', 'transfer.created_at', $this->timestampStart ] );
|
||||
$query->andFilterWhere([ '<', 'transfer.created_at', $this->timestampEnd ] );
|
||||
|
||||
$query->andFilterWhere(['like', 'comment', $this->comment]);
|
||||
|
||||
if ( isset($this->searchObjectName))
|
||||
$query->andWhere( new Expression(" case when transfer.type = " .self::TYPE_PRODUCT ." then product.name else ticket_type.name end like '%" . $this->searchObjectName ."%'"));
|
||||
|
||||
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
|
||||
public function totals($params){
|
||||
$query = new Query();
|
||||
|
||||
$result = [ ];
|
||||
|
||||
$accountTotals = [];
|
||||
$fullTotal = [
|
||||
'label' => Yii::t('common/transfer', 'Total'),
|
||||
'money' => 0
|
||||
];
|
||||
|
||||
$query->addSelect( [ new Expression( 'transfer.id_account as account'), new Expression( ' COALESCE(sum( transfer.money ),0) as money' )]);
|
||||
$query->from('transfer');
|
||||
$query->leftJoin('ticket', 'transfer.type = ' .self::TYPE_TICKET .' and transfer.id_object = ticket.id_ticket ' );
|
||||
$query->leftJoin('ticket_type', 'ticket.id_ticket_type = ticket_type.id_ticket_type ' );
|
||||
$query->leftJoin('product', 'product.id_product = ' .self::TYPE_TICKET .' and transfer.id_object = ticket.id_ticket ' );
|
||||
|
||||
$this->load($params);
|
||||
|
||||
if (!$this->validate()) {
|
||||
return ;
|
||||
}
|
||||
|
||||
$query->andFilterWhere([
|
||||
'transfer.id_account' => $this->id_account,
|
||||
'transfer.type' => $this->type,
|
||||
'transfer.id_user' => $this->id_user,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere([ '>=', 'transfer.created_at', $this->timestampStart ] );
|
||||
$query->andFilterWhere([ '<', 'transfer.created_at', $this->timestampEnd ] );
|
||||
|
||||
|
||||
if ( isset($this->searchObjectName) && !empty($this->searchObjectName)){
|
||||
$query->andWhere( new Expression(" case when transfer.type = " .self::TYPE_PRODUCT ." then product.name else ticket_type.name end like '%" . $this->searchObjectName ."%'"));
|
||||
}
|
||||
|
||||
$query->groupBy('transfer.id_account');
|
||||
|
||||
$command = $query->createCommand();
|
||||
// $command->sql returns the actual SQL
|
||||
$result = $command->queryAll();
|
||||
|
||||
|
||||
$accounts = Account::find()->orderBy("name asc")->all();
|
||||
$accountMap = ArrayHelper::map( $accounts ,'id_account','name' );
|
||||
|
||||
|
||||
|
||||
foreach ($result as $item){
|
||||
$account = "";
|
||||
if ( array_key_exists($item['account'], $accountMap)){
|
||||
$account = $accountMap[$item['account']];
|
||||
}
|
||||
|
||||
$accountTotal = [
|
||||
'label' => $account,
|
||||
'money' => $item['money']
|
||||
];
|
||||
|
||||
$accountTotals[] = $accountTotal;
|
||||
|
||||
$fullTotal['money'] += $item['money'];
|
||||
}
|
||||
|
||||
$this->accountTotals = $accountTotals;
|
||||
$this->fullTotal = $fullTotal;
|
||||
|
||||
// return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user