add contraint , that everybody expect admin is limited to 3 days, Add card package

This commit is contained in:
2016-02-13 17:23:43 +01:00
parent 556bdc3066
commit 70f43468af
37 changed files with 1418 additions and 19 deletions

View File

@@ -0,0 +1,50 @@
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "card_card_package_assignment".
*
* @property integer $id_card_card_package_assignment
* @property integer $id_card_package
* @property integer $id_card
* @property integer $printed
* @property string $created_at
* @property string $updated_at
*/
class CardCardPackageAssignment extends \common\models\BaseFitnessActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'card_card_package_assignment';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id_card_package', 'id_card'], 'integer'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id_card_card_package_assignment' => Yii::t('common/card_package', 'Id Card Card Package Assignment'),
'id_card_package' => Yii::t('common/card_package', 'Id Card Package'),
'id_card' => Yii::t('common/card_package', 'Id Card'),
'created_at' => Yii::t('common/card_package', 'Created At'),
'updated_at' => Yii::t('common/card_package', 'Updated At'),
];
}
}

View File

@@ -0,0 +1,80 @@
<?php
namespace common\models;
use Yii;
use yii\behaviors\TimestampBehavior;
/**
* This is the model class for table "card_package".
*
* @property integer $id_card_package
* @property integer $id_user
* @property integer $count
* @property string $created_at
* @property string $updated_at
*/
class CardPackage extends \common\models\BaseFitnessActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'card_package';
}
public function getUser(){
return $this->hasOne(User::className(), ['id' => 'id_user' ]);
}
public function getCardAssignments(){
return $this->hasMany(CardCardPackageAssignment::className(), ['id_card_package' => 'id_card_package' ]);
}
public function getCards(){
return $this->hasMany(Card::className(), ['id_card' => 'id_card' ])->via('cardAssignments');
}
public function getUserName(){
$user = $this->user;
$result = "";
if ( isset($user) ){
$result = $this->user->username;
}
return $result;
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['count'], 'integer',"min" => 1 , "max" => 3000],
[['count'], 'required'],
];
}
public function getPrintedDate(){
if ( $this->printed > 0 ){
return $this->updated_at;
}
return null;
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id_card_package' => Yii::t('common/card_package', 'Kártya csomag azonosító'),
'id_user' => Yii::t('common/card_package', 'Felhasználó'),
'count' => Yii::t('common/card_package', 'Mennyiség'),
'printed' => Yii::t('common/card_package', 'Letöltve'),
'printedDate' => Yii::t('common/card_package', 'Utolsó letöltés ideje'),
'count' => Yii::t('common/card_package', 'Mennyiség'),
'created_at' => Yii::t('common/card_package', 'Létrehozva'),
'updated_at' => Yii::t('common/card_package', 'Nyomtatva'),
];
}
}

View File

@@ -671,6 +671,13 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
self::notInInterval ( $query, 'transfer.created_at', $start, $end );
}
echo "start date is: ". $start;
echo "start date is: " . gettype( $start );
if ( !RoleDefinition::isAdmin() ){
Helper::restrictIfNotAdminTheStartDate($query, $start);
}
$query->groupBy ( 'transfer.id_account' );
return $query;
@@ -837,6 +844,16 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
return $result;
}
/**
* Ezt a függvényt használjuk a zárások összegének kiszámolására!
* A számolás csak a következő feltételekkel bíró tranzakciókat
* tartalmazza:
* - trazakció típus: common\models\Account::TYPE_ALL
* - tranzakció fizetési módja: készpénz
* - tranzakció státusza: fizetve
* -
* */
public static function readPaid($start, $end, $idUser) {
$query = (new \yii\db\Query ());
$query->select ( [

View File

@@ -14,6 +14,7 @@ use common\models\Account;
use yii\helpers\ArrayHelper;
use common\models\MoneyMovement;
use common\components\RoleDefinition;
use common\components\Helper;
/**
* TransferSearch represents the model behind the search form about `common\models\Transfer`.
*/
@@ -168,6 +169,16 @@ class TransferSaleSearch extends Transfer
$query->andFilterWhere(['or' , $created_condition , $paid_condition]);
$needRestirct = false;
if ( $this->isModeAdmin() ){
$needRestirct = !RoleDefinition::isAdmin();
}else{
$needRestirct = true;
}
if ( $needRestirct ){
Helper::restrictIfNotAdminTheStartDate($query, $this->timestampStart);
}
// $query->andWhere(['transfer.status' => Transfer::STATUS_PAID]);

View File

@@ -14,12 +14,19 @@ use common\models\Account;
use yii\helpers\ArrayHelper;
use common\models\MoneyMovement;
use common\components\RoleDefinition;
use common\components\Helper;
/**
* TransferSearch represents the model behind the search form about `common\models\Transfer`.
*/
class TransferTicketSearch extends Transfer
{
/**
* if mode is recepion, date restriction will be used
* if mode is admin, date restriction will be used based on user role
* */
public $mode = 'reception';
public $start;
public $end;
@@ -126,6 +133,8 @@ class TransferTicketSearch extends Transfer
}
protected function calcTotal(){
$this->total = 0;
$this->total += $this->ticketMoney;
@@ -166,9 +175,24 @@ class TransferTicketSearch extends Transfer
$query->andWhere(['transfer.status' => Transfer::STATUS_PAID]);
$this->restrictStartDate($query);
}
function restrictStartDate($query){
$needRestriction = false;
if ( $this->mode == 'admin'){
$needRestriction = !RoleDefinition::isAdmin( ) ;
}else{
$needRestriction = true;
}
if ( $needRestriction ){
Helper::restrictIfNotAdminTheStartDate($query, $this->timestampStart);
}
}
protected function readTicketStas(){
$query = (new \yii\db\Query());