From 41de4ee6a7eadd80734476fdca5cf817f56dc401 Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Tue, 2 Feb 2016 22:05:29 +0100 Subject: [PATCH] add limit, that users can see only 3 days old data --- changelog.txt | 2 + common/components/DailyListing.php | 32 +++++++++++ common/components/Helper.php | 5 ++ common/config/params.php | 6 ++- common/models/TransferListSearch.php | 79 +++++++++++++++++++++++----- frontend/views/transfer/list.php | 8 +++ 6 files changed, 118 insertions(+), 14 deletions(-) diff --git a/changelog.txt b/changelog.txt index 66c3a21..c86a532 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,5 @@ +-0.0.31 + - Add transfer list and daily list to see only may 3 days old data -0.0.30 - fix discount to integer ( using floor ) -0.0.29 diff --git a/common/components/DailyListing.php b/common/components/DailyListing.php index b45f6cc..e59fb88 100644 --- a/common/components/DailyListing.php +++ b/common/components/DailyListing.php @@ -118,6 +118,23 @@ class DailyListing public $accountState; //the cassa object for we load the data + + protected function calcStartDaysSinceToday(){ + $start = $this->timestampStart; + $now = time(); + + $d = \DateTime::createFromFormat("Y-m-d H:i", $start)->getTimeStamp(); + $days_between = ceil(abs($now - $d) / 86400); + + return $days_between; + } + + protected function isStartDateToEarly(){ + $days_visiblity = Helper::getReceptionVisibilityDays(); + $days_between = $this->calcStartDaysSinceToday(); + return $days_between > $days_visiblity; + } + public function readTotalEasy(){ $this->readTicketMoney(); $this->readProductsMoney(); @@ -173,9 +190,11 @@ class DailyListing public function isModeAdmin(){ return $this->mode == 'admin'; } + public function isModeAccountState(){ return $this->mode == 'accountstate'; } + public function isModeReception(){ return $this->mode == 'reception'; } @@ -255,6 +274,19 @@ class DailyListing if ( $this->isModeReception() || $this->isModeAccountState() ){ $query->andWhere(['transfer.payment_method' => Transfer::PAYMENT_METHOD_CASH]); } + + if ( !RoleDefinition::isAdmin() ){ + + if ( $this->isStartDateToEarly() ){ + + $time = date( "Y-m-d H:i:s", strtotime("today -3 day") ); + + $start_date_condition = ['or',[ '>=', 'transfer.created_at', $time ] ,[ '>=', 'transfer.paid_at', $time] ]; + + $query->andFilterWhere( $start_date_condition ); + + } + } } diff --git a/common/components/Helper.php b/common/components/Helper.php index a288ebe..0ce872e 100644 --- a/common/components/Helper.php +++ b/common/components/Helper.php @@ -182,6 +182,11 @@ class Helper { public static function isAccountStateClosePreloadMoney() { return \Yii::$app->params ['account_state_close_preload_money'] == true; } + + public static function getReceptionVisibilityDays() { + return \Yii::$app->params ['reception_visibility_days'] ; + } + public static function getRealUserIp() { $client = @$_SERVER ['HTTP_CLIENT_IP']; $forward = @$_SERVER ['HTTP_X_FORWARDED_FOR']; diff --git a/common/config/params.php b/common/config/params.php index 302adb7..99a2507 100644 --- a/common/config/params.php +++ b/common/config/params.php @@ -4,7 +4,7 @@ return [ 'supportEmail' => 'rocho02@gmail.com', 'infoEmail' => 'info@rocho-net.hu', 'user.passwordResetTokenExpire' => 3600, - 'version' => 'v0.0.30', + 'version' => 'v0.0.31', 'company' => 'movar',//gyor 'company_name' => "Freimann Kft.", 'product_visiblity' => 'account',// on reception which products to display. account or global @@ -20,4 +20,8 @@ return [ //vagy mindent //értékek user|all 'user_cart_item_visibility' => 'user', + /** + * Hány napig láthatják visszamenőleg a recepciósok az adatokat + * */ + 'reception_visibility_days' => 3 ]; diff --git a/common/models/TransferListSearch.php b/common/models/TransferListSearch.php index 1bbe1d5..da9ef82 100644 --- a/common/models/TransferListSearch.php +++ b/common/models/TransferListSearch.php @@ -48,51 +48,51 @@ class TransferListSearch extends Transfer /** * all money gained with ticket sell * */ - public $ticketMoney; + public $ticketMoney = 0; /** * all money gained with product sell * */ - public $productMoney; + public $productMoney = 0; /** * all money gained with product sell * */ - public $productMoneyNetto; + public $productMoneyNetto = 0; /** * all money gained with product sell grouped by category * */ - public $productMoneies; + public $productMoneies = []; /** * all money lost by money movement * */ - public $moneyMovementMoneis; - public $moneyMovementMoney; + public $moneyMovementMoneis = 0; + public $moneyMovementMoney = 0; /** * total gained money brutto * */ - public $total; + public $total = 0; /** * total gained money netto * */ - public $totalNetto; + public $totalNetto = 0; /** * ticket sale statisitc * */ - public $ticketStats; + public $ticketStats =[]; /** * money movements by type * */ - public $moneyMovementsByType; + public $moneyMovementsByType = []; public $tickets; /** * all product transfer * */ - public $products; - public $moneyMovements; + public $products = []; + public $moneyMovements = []; - public $productsByCategory; + public $productsByCategory = []; public $currentUser; public $currentAccount; @@ -112,14 +112,43 @@ class TransferListSearch extends Transfer [[ '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' ], + [['start','end' ], 'required'], [ [ 'id_account','id_user' ] , 'integer'], ['types', 'each', 'rule' => ['integer']], ['output', 'safe' ], ['outputView', 'safe' ], +// ['start', 'validateStart'] ]; } + public function validateStart($attribute,$param){ + + + + if ( $this->isStartDateToEarly() ){ + $this->addError($attribute,"Érvénytelen kezdő dátum"); + } + + } + + protected function calcStartDaysSinceToday(){ + $start = $this->timestampStart; + $now = time(); + + $d = \DateTime::createFromFormat("Y-m-d H:i", $start)->getTimeStamp(); + $days_between = ceil(abs($now - $d) / 86400); + + return $days_between; + } + + protected function isStartDateToEarly(){ + $days_visiblity = Helper::getReceptionVisibilityDays(); + $days_between = $this->calcStartDaysSinceToday(); + return $days_between > $days_visiblity; + } + + public function isModeAdmin(){ return $this->mode == 'admin'; } @@ -253,9 +282,33 @@ class TransferListSearch extends Transfer $query->andFilterWhere(['or' , $created_condition , $paid_condition]); $query->andWhere(['transfer.status' => Transfer::STATUS_PAID]); + if ( !$this->isModeAdmin()){ $query->andWhere(['transfer.payment_method' => Transfer::PAYMENT_METHOD_CASH]); + + } + + + + if ( !RoleDefinition::isAdmin() ){ + /** + * Csak az admin láthat minden adatot + * ha a start dátum korábbi, mint ahogy azt a recepciósok láthatják, + * hozzáadjuk a querykhez a dátum korlátozást + * */ + if ( $this->isStartDateToEarly() ){ + + $days = Helper::getReceptionVisibilityDays(); + $time = date( "Y-m-d H:i:s", strtotime("today -$days day") ); + + $start_date_condition = ['or',[ '>=', 'transfer.created_at', $time ] ,[ '>=', 'transfer.paid_at', $time] ]; + + $query->andFilterWhere( $start_date_condition ); + + } + } + } diff --git a/frontend/views/transfer/list.php b/frontend/views/transfer/list.php index f8f00b0..6632f95 100644 --- a/frontend/views/transfer/list.php +++ b/frontend/views/transfer/list.php @@ -46,6 +46,14 @@ td.name{ } + +

title) ?>