add frontend collection
This commit is contained in:
26
common/components/AccountTotalWidget.php
Normal file
26
common/components/AccountTotalWidget.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace common\components;
|
||||
|
||||
use yii\base\Widget;
|
||||
|
||||
class AccountTotalWidget extends Widget{
|
||||
|
||||
public $totalHeading = 'Össesen';
|
||||
public $panelHeading = 'Össesen';
|
||||
public $panelType = 'panel-info';
|
||||
|
||||
public $statistic = ['total' => 0, 'accounts' => [] ];
|
||||
|
||||
|
||||
public $viewFile = '@common/views/common/_account_total';
|
||||
|
||||
public function init(){
|
||||
parent::init();
|
||||
|
||||
}
|
||||
|
||||
public function run(){
|
||||
echo $this->render($this->viewFile,[ 'model' => $this ]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace common\models;
|
||||
|
||||
use Yii;
|
||||
use yii\behaviors\TimestampBehavior;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
/**
|
||||
* This is the model class for table "account".
|
||||
@@ -174,4 +175,8 @@ class Account extends \yii\db\ActiveRecord
|
||||
return $accounts;
|
||||
}
|
||||
|
||||
public static function toAccaountMap($accounts){
|
||||
return ArrayHelper::map( $accounts,'id_account','name' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ use common\components\AccountAwareBehavior;
|
||||
use common\components\UserAwareBehavior;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\behaviors\TimestampBehavior;
|
||||
use yii\db\Query;
|
||||
use yii\db\Expression;
|
||||
|
||||
/**
|
||||
* This is the model class for table "collection".
|
||||
@@ -104,4 +106,98 @@ class Collection extends \common\models\BaseFitnessActiveRecord
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* */
|
||||
public static function mkTotalQuery($mode = 'reception', $start,$end,$idUser,$types,$idAccount){
|
||||
|
||||
$query = new Query();
|
||||
|
||||
$query->addSelect( [
|
||||
new Expression( ' collection.id_account as account'),
|
||||
new Expression( ' COALESCE(sum( collection.money ) ,0) as money /** collections total money */' )
|
||||
|
||||
]);
|
||||
$query->from('collection');
|
||||
|
||||
$query->andFilterWhere([
|
||||
'id_account' => $idAccount,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere(['id_user' => $idUser]);
|
||||
$query->andFilterWhere(['in' ,'type', $types]);
|
||||
self::inInterval($query, 'collection.end' , $start, $end);
|
||||
|
||||
$query->groupBy('collection.id_account');
|
||||
|
||||
return $query;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static function mkTotalsResultWithAllAvailableAccount($queryResult,$accounts,$accountMap,$idAccount){
|
||||
|
||||
$totals = [];
|
||||
$totals['total'] = 0;
|
||||
|
||||
$totals['accounts'] = [];
|
||||
|
||||
foreach ($accounts as $account){
|
||||
if ( isset($idAccount) && is_numeric($idAccount) && $idAccount != $account->id_account ){
|
||||
continue ;
|
||||
}
|
||||
|
||||
$accountTotal = [
|
||||
'id_account' => $account->id_account,
|
||||
'label' => $account->name,
|
||||
'money' => 0,
|
||||
];
|
||||
|
||||
$item = self::findByAccountInQueryResult($queryResult, $account);
|
||||
|
||||
if ( isset($item)){
|
||||
$accountTotal['money'] = $item['money'];
|
||||
}
|
||||
|
||||
$totals['accounts'][] = $accountTotal;
|
||||
$totals['total'] += $accountTotal['money'];
|
||||
}
|
||||
return $totals;
|
||||
}
|
||||
|
||||
public static function findByAccountInQueryResult( $queryResult, $account ){
|
||||
$result = null;
|
||||
foreach ($queryResult as $item){
|
||||
if( $item['account'] == $account->id_account ){
|
||||
$result = $item;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function inInterval($query ,$field , $start,$end ){
|
||||
$query->andFilterWhere([ '>=', $field , $start ] );
|
||||
$query->andFilterWhere([ '<' , $field , $end ] );
|
||||
}
|
||||
|
||||
|
||||
/**create and execute a "total" query*/
|
||||
public static function exTotalQuery($mode,$start,$end,$idUser,$types,$idAccount){
|
||||
$query = self::mkTotalQuery($mode, $start, $end, $idUser, $types, $idAccount );
|
||||
$command = $query->createCommand();
|
||||
$result = $command->queryAll();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*find all transfers which were paid in the period
|
||||
* */
|
||||
public static function mkReceptionTotal( $start, $end, $idUser, $types, $idAccount, $accounts, $accountMap){
|
||||
$result = [];
|
||||
$queryResult = self::exTotalQuery('reception', $start, $end, $idUser, $types, $idAccount );
|
||||
$result = self::mkTotalsResultWithAllAvailableAccount($queryResult, $accounts, $accountMap, $idAccount);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ class CollectionCreate extends \common\models\Collection
|
||||
public $accountMap;
|
||||
public $account;
|
||||
public $totals;
|
||||
public $userCartTotal;
|
||||
|
||||
public $timestampEnd;
|
||||
public $timestampStart;
|
||||
@@ -38,7 +39,10 @@ class CollectionCreate extends \common\models\Collection
|
||||
public function rules(){
|
||||
return [
|
||||
['end','required'],
|
||||
[[ 'end' , ], 'date' ,'format' =>Yii::$app->formatter->datetimeFormat , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd HH:mm' ,'timeZone' => 'UTC' ],
|
||||
/**enable seconds*/
|
||||
[[ 'end' , ], 'date' ,'format' => 'yyyy-MM-dd HH:mm:ss' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd HH:mm:ss' ,'timeZone' => 'UTC' ],
|
||||
/*enable only minutes*/
|
||||
// [[ 'end' , ], 'date' ,'format' => 'yyyy-MM-dd HH:mm' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd HH:mm' ,'timeZone' => 'UTC' ],
|
||||
[[ 'end' ], 'validateEndDate' ]
|
||||
];
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
use yii\db\Query;
|
||||
use yii\db\Expression;
|
||||
|
||||
/**
|
||||
* This is the model class for table "user_sold_item".
|
||||
@@ -60,6 +62,29 @@ class UserSoldItem extends \yii\db\ActiveRecord
|
||||
|
||||
}
|
||||
|
||||
public static function readTotalForAccount($idUser,$idAccount){
|
||||
|
||||
$query = new Query();
|
||||
|
||||
$query->addSelect( [
|
||||
new Expression( ' COALESCE(sum( transfer.money ) ,0) as money /** total unpaid reception cart */' )
|
||||
|
||||
]);
|
||||
$query->innerJoin('transfer',['user_sold_item.id_transfer' =>'transfer.id_transfer']);
|
||||
|
||||
$query->from('user_sold_item');
|
||||
|
||||
$query->andFilterWhere([
|
||||
'transfer.id_account' => $idAccount,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere(['user_sold_item.id_user' => $idUser]);
|
||||
|
||||
|
||||
return $query->scalar();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param common\models\User $user
|
||||
|
||||
17
common/views/common/_account_total.php
Normal file
17
common/views/common/_account_total.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<div class="panel <?=$model->panelType ?>">
|
||||
<div class="panel-heading"><?php echo $model->panelHeading?></div>
|
||||
<div class="panel-body">
|
||||
<dl class="dl-horizontal dl-totals">
|
||||
<?php
|
||||
foreach ($model->statistic['accounts'] as $acc ){
|
||||
?>
|
||||
<dt><?php echo $acc['label'] ?></dt>
|
||||
<dd class="text-right"><?php echo $acc['money'] ?></dd>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<dt><?php echo $model->totalHeading ?></dt>
|
||||
<dd class="text-right"><?php echo $model->statistic['total'] ?></dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user