From 6d2e15cac7398e6270f4051d4cbba1d97a2210f4 Mon Sep 17 00:00:00 2001 From: Schneider Roland Date: Wed, 6 Jan 2016 21:20:21 +0100 Subject: [PATCH 1/8] add reception customer search, fix reception ticket types, fix card number routing, timezone changes --- backend/components/AdminMenuStructure.php | 6 +- changelog.txt | 5 ++ common/config/main.php | 5 +- common/config/params.php | 2 +- common/models/CardSearch.php | 88 +++++++++++++++++++ common/models/Transfer.php | 2 +- frontend/components/FrontendMenuStructure.php | 6 +- frontend/controllers/CardController.php | 10 +++ frontend/controllers/CustomerController.php | 3 +- frontend/controllers/TicketController.php | 2 +- frontend/models/ReceptionForm.php | 4 + frontend/views/card/_search.php | 38 ++++++++ frontend/views/card/index.php | 70 +++++++++++++++ frontend/views/common/_reception.php | 15 ++++ frontend/views/customer/reception.php | 6 ++ 15 files changed, 251 insertions(+), 11 deletions(-) create mode 100644 common/models/CardSearch.php create mode 100644 frontend/views/card/_search.php create mode 100644 frontend/views/card/index.php diff --git a/backend/components/AdminMenuStructure.php b/backend/components/AdminMenuStructure.php index 918a8c2..1a3bb1e 100644 --- a/backend/components/AdminMenuStructure.php +++ b/backend/components/AdminMenuStructure.php @@ -35,10 +35,10 @@ class AdminMenuStructure{ //$today = \Yii::$app->formatter->asDate( time() ); $today = \Yii::$app->formatter->asDate( strtotime('today UTC') ); - $tomorrow = \Yii::$app->formatter->asDate( ( 60 *60 *24 + time())); + $tomorrow = \Yii::$app->formatter->asDate( strtotime('tomorrow UTC') ); - $todayDatetime = \Yii::$app->formatter->asDatetime( strtotime('today') ); - $tomorrowDatetime = \Yii::$app->formatter->asDatetime( strtotime('tomorrow') ); + $todayDatetime = \Yii::$app->formatter->asDatetime( strtotime('today UTC') ); + $tomorrowDatetime = \Yii::$app->formatter->asDatetime( strtotime('tomorrow UTC') ); ///////////////////////////// diff --git a/changelog.txt b/changelog.txt index 40d21cd..30d726f 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,8 @@ +-0.0.18 + - reception customer search + - timezone changes + - reception card read redirect changes + - fix reception ticket visiblitity -0.0.17 - fix helper::fixascii function - admin pdf download diff --git a/common/config/main.php b/common/config/main.php index 0c3dd4d..5ceae8a 100644 --- a/common/config/main.php +++ b/common/config/main.php @@ -24,8 +24,9 @@ return [ 'datetimeFormat' => 'yyyy.MM.dd HH:mm', 'timeFormat' => 'HH:mm', 'locale' => 'hu-Hu', - 'timeZone' => 'Europe/Budapest', - 'defaultTimeZone' => 'UTC', +// 'timeZone' => 'Europe/Budapest', + 'timeZone' => 'UTC', +// 'defaultTimeZone' => 'UTC', 'nullDisplay' => "-", ], 'authManager' => [ diff --git a/common/config/params.php b/common/config/params.php index bb9dfb9..d095cd1 100644 --- a/common/config/params.php +++ b/common/config/params.php @@ -3,7 +3,7 @@ return [ 'adminEmail' => 'rocho02@gmail.com', 'supportEmail' => 'rocho02@gmail.com', 'user.passwordResetTokenExpire' => 3600, - 'version' => 'v0.0.17', + 'version' => 'v0.0.18', 'company' => 'movar',//gyor 'company_name' => "Freimann Kft.", 'product_visiblity' => 'account',// on reception which products to display. account or global diff --git a/common/models/CardSearch.php b/common/models/CardSearch.php new file mode 100644 index 0000000..414462b --- /dev/null +++ b/common/models/CardSearch.php @@ -0,0 +1,88 @@ +200], + ['number','string','max' =>200] + ]; + } + + /** + * @inheritdoc + */ + public function scenarios() + { + // bypass scenarios() implementation in the parent class + return Model::scenarios(); + } + + public function attributeLabels(){ + return ArrayHelper::merge(parent::attributeLabels(), + [ + 'card_number' => 'Kártya szám', + 'customerName' => 'Vendég' + ] + ); + + } + + /** + * Creates data provider instance with search query applied + * + * @param array $params + * + * @return ActiveDataProvider + */ + public function search($params) + { + + $query = new Query(); + $query->select(['card.number as card_number' , 'customer.name as customer_name', 'customer.email as customer_email','customer.phone as customer_phone']); + $query->from('card'); + $query->innerJoin('customer','card.id_card = customer.id_customer_card'); + $query->orderBy(['customer.name' => SORT_ASC]); + + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + ]); + + + + $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'); + return $dataProvider; + } + + $query->andFilterWhere([ +// 'lower(customer.name)' => $this->customerName + ]); + + $query->andFilterWhere(['like', 'customer.name', $this->customerName]); + + return $dataProvider; + } +} diff --git a/common/models/Transfer.php b/common/models/Transfer.php index b219313..57c6030 100644 --- a/common/models/Transfer.php +++ b/common/models/Transfer.php @@ -59,7 +59,7 @@ class Transfer extends \common\models\BaseFitnessActiveRecord return ArrayHelper::merge( [ [ 'class' => TimestampBehavior::className(), - 'value' => function(){ return date('Y-m-d H:i:s' ); } + 'value' => function(){ return date('Y-m-d H:i:s' ,\Yii::$app->formatter->asTimestamp(date('Y-d-m h:i:s')) ); } ], [ 'class' => DiscountAwareBehavior::className(), diff --git a/frontend/components/FrontendMenuStructure.php b/frontend/components/FrontendMenuStructure.php index 16b5687..485ebbf 100644 --- a/frontend/components/FrontendMenuStructure.php +++ b/frontend/components/FrontendMenuStructure.php @@ -23,8 +23,8 @@ class FrontendMenuStructure{ public function __construct(){ $this->menuItems = []; - $this->start = \Yii::$app->formatter->asDatetime( strtotime('today') ); - $this->tomorrow = Yii::$app->formatter->asDatetime( strtotime('tomorrow') ); + $this->start = \Yii::$app->formatter->asDatetime( strtotime('today UTC') ); + $this->tomorrow = Yii::$app->formatter->asDatetime( strtotime('tomorrow UTC') ); $this->startDate = Yii::$app->formatter->asDate( strtotime('today UTC') ); $this->tomorrowDate = Yii::$app->formatter->asDate( strtotime('tomorrow UTC') ); @@ -84,6 +84,8 @@ class FrontendMenuStructure{ $items[] = ['label' => Yii::t('frontend/transfer','Transfers'), 'url' => ['/transfer/index', 'TransferSearch[id_user]' =>\Yii::$app->user->id, 'TransferSearch[id_account]' => Account::readDefault(), 'TransferSearch[start]' => $this->start, 'TransferSearch[end]' => $this->tomorrow ] ]; $items[] = ['label' => Yii::t('frontend/collection','Collections'), 'url' => ['/collection/index' , 'CollectionSearch[start]' =>$this->start,'CollectionSearch[end]' => $this->tomorrow ] ]; } + + $items[] = ['label' => Yii::t('frontend/card','Vendégek'), 'url' => [ '/card/index' ] ]; $this->menuItems[] = ['label' => Yii::t('frontend/account', 'Account'), diff --git a/frontend/controllers/CardController.php b/frontend/controllers/CardController.php index b1ce3bf..e370207 100644 --- a/frontend/controllers/CardController.php +++ b/frontend/controllers/CardController.php @@ -81,6 +81,16 @@ class CardController extends Controller echo Json::encode ( $out ); } + public function actionIndex(){ + $searchModel = new \common\models\CardSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + } diff --git a/frontend/controllers/CustomerController.php b/frontend/controllers/CustomerController.php index cb18e55..8ba9b92 100644 --- a/frontend/controllers/CustomerController.php +++ b/frontend/controllers/CustomerController.php @@ -59,7 +59,8 @@ class CustomerController extends Controller if ( $model->isFreeCard() ){ return $this->redirect([ 'create', 'number' => $model->card->number ]); }else if ( $model->isCustomerWithTicket()){ - return $this->redirect([ 'product/sale', 'number' => $model->card->number ]); +// return $this->redirect([ 'product/sale', 'number' => $model->card->number ]); +// return $this->redirect([ 'customer/reception', 'number' => $model->card->number ]); }else if ( $model->isCardWithCustomer() ){ return $this->redirect([ 'ticket/create', 'number' => $model->card->number ]); } diff --git a/frontend/controllers/TicketController.php b/frontend/controllers/TicketController.php index 073a9b1..9306887 100644 --- a/frontend/controllers/TicketController.php +++ b/frontend/controllers/TicketController.php @@ -97,7 +97,7 @@ class TicketController extends FrontendController $discounts = Discount::read(); - $ticketTypes = TicketType::read(null, Account::readDefault()); + $ticketTypes = TicketType::read(null, null); $accounts = Account::readAccounts(); diff --git a/frontend/models/ReceptionForm.php b/frontend/models/ReceptionForm.php index 04af117..5d4159e 100644 --- a/frontend/models/ReceptionForm.php +++ b/frontend/models/ReceptionForm.php @@ -8,6 +8,7 @@ use common\models\Card; use common\models\Customer; use common\models\Ticket; use common\models\Account; +use common\models\CardSearch; /** * ContactForm is the model behind the contact form. @@ -19,6 +20,7 @@ class ReceptionForm extends Model public $customer; public $tickets; public $defaultAccount; + public $cardSearchModel; /** * @inheritdoc @@ -56,6 +58,8 @@ class ReceptionForm extends Model $this->defaultAccount = Account::findOne($defaultAccount); } + $this->cardSearchModel = new CardSearch(); + } public function getDefaultAccountName(){ diff --git a/frontend/views/card/_search.php b/frontend/views/card/_search.php new file mode 100644 index 0000000..9222da1 --- /dev/null +++ b/frontend/views/card/_search.php @@ -0,0 +1,38 @@ + + + + diff --git a/frontend/views/card/index.php b/frontend/views/card/index.php new file mode 100644 index 0000000..b1a2409 --- /dev/null +++ b/frontend/views/card/index.php @@ -0,0 +1,70 @@ +title = Yii::t('frontend/collection', 'Vendégek'); +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ render('_search', ['model' => $searchModel]); ?> + + + + $dataProvider, + 'columns' => [ + [ + 'attribute' => 'card_number', + 'label' => 'Kártyaszám', + ], + [ + 'attribute' => 'customer_name', + 'label' => 'Név', + ], + [ + 'attribute' => 'customer_phone', + 'label' => 'Tel', + ], + [ + 'attribute' => 'customer_email', + 'label' => 'E-mail', + ], +// [ +// 'attribute' => 'customer.name', +// 'value' => 'customer.name', +// ], + + + ['class' => 'yii\grid\ActionColumn', + 'template' => '{ticket} {ticket_history}', + 'buttons' => [ + 'ticket' => function ($url, $model, $key) { + return Html::a('Új bérlet', $url, ['class'=> 'btn btn-xs btn-success' ]) ; + }, + 'ticket_history' => function ($url, $model, $key) { + return Html::a('Befizetések', $url, ['class'=> 'btn btn-xs btn-success' ]) ; + }, + ], + 'urlCreator' => function ($action, $model, $key, $index){ + $url = ""; + if ( 'ticket' == $action ){ + $url = Url::to(['ticket/create','number' => $model['card_number']]); + }else if ( 'ticket_history' == $action ){ + $url = Url::to(['ticket/index','number' => $model['card_number']]); + } + return $url; + } + ], + ], + ]); ?> + +
diff --git a/frontend/views/common/_reception.php b/frontend/views/common/_reception.php index 72eb2ea..1f9d128 100644 --- a/frontend/views/common/_reception.php +++ b/frontend/views/common/_reception.php @@ -6,6 +6,8 @@ use frontend\components\ReceptionCardNumberTicketsWidget; use yii\base\Widget; use frontend\components\ReceptionTicketWidget; use frontend\components\ReceptionCustomerWidget; +use yii\widgets\ActiveForm; +use yii\helpers\Html; ?>
@@ -13,6 +15,19 @@ use frontend\components\ReceptionCustomerWidget; Aktuális kassza: getDefaultAccountName();?>
+ ['card/index'], + 'method' => 'get', + ]); ?> +
+ "form-control", 'placeholder' =>'Vendég neve']) ?> + +
+
+ 'btn btn-primary']) ?> +
+ +
diff --git a/frontend/views/customer/reception.php b/frontend/views/customer/reception.php index 1f4295c..2c82a29 100644 --- a/frontend/views/customer/reception.php +++ b/frontend/views/customer/reception.php @@ -6,3 +6,9 @@ use frontend\components\ReceptionWidget; ?>

Recepció

$model, 'route' => ['customer/reception'] ] )?> + + From 5ca82b89bd93c1428cd94beaf17d7cb42eb605f0 Mon Sep 17 00:00:00 2001 From: Schneider Roland Date: Wed, 6 Jan 2016 21:24:26 +0100 Subject: [PATCH 2/8] add minor changes --- frontend/views/common/_reception_form_card_number.php | 7 +++---- frontend/views/ticket/_form.php | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/frontend/views/common/_reception_form_card_number.php b/frontend/views/common/_reception_form_card_number.php index d551fbf..89285a7 100644 --- a/frontend/views/common/_reception_form_card_number.php +++ b/frontend/views/common/_reception_form_card_number.php @@ -26,8 +26,7 @@ if ( isset($model->card)){ } ?> - -
+
false, 'method' => 'get', @@ -35,7 +34,7 @@ if ( isset($model->card)){ ]); ?>
- 'form-control'])?> + 'form-control', 'placeholder' => 'Kártyaszám'])?>
@@ -44,7 +43,7 @@ if ( isset($model->card)){
-
+
diff --git a/frontend/views/ticket/_form.php b/frontend/views/ticket/_form.php index 6ef8532..04ec43c 100644 --- a/frontend/views/ticket/_form.php +++ b/frontend/views/ticket/_form.php @@ -68,7 +68,7 @@ use common\models\Account;
- 'btn btn-danger btn-block', 'id' => 'btn_sell'] );?> + 'btn btn-danger btn-block', 'id' => 'btn_sell'] );?>
'btn btn-success btn-block', 'id' => 'btn_add_to_user_cart'] );?> From d2bc8076ca36207e102f7364849e5911c7436c2a Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Thu, 7 Jan 2016 16:31:06 +0100 Subject: [PATCH 3/8] add import card rfid key --- backend/controllers/CardController.php | 381 +++++++++++++++---------- backend/models/CardImportRfidForm.php | 30 ++ backend/views/card/importRfid.php | 16 ++ 3 files changed, 276 insertions(+), 151 deletions(-) create mode 100644 backend/models/CardImportRfidForm.php create mode 100644 backend/views/card/importRfid.php diff --git a/backend/controllers/CardController.php b/backend/controllers/CardController.php index 07409dc..e8ced89 100644 --- a/backend/controllers/CardController.php +++ b/backend/controllers/CardController.php @@ -5,168 +5,247 @@ namespace backend\controllers; use Yii; use common\models\Card; use backend\models\CardSearch; -use yii\web\Controller; use yii\web\NotFoundHttpException; -use yii\filters\VerbFilter; -use yii\base\Object; use yii\db\Query; use common\models\Customer; use yii\helpers\Json; +use backend\models\CardImportRfidForm; +use yii\web\UploadedFile; +use common\components\Helper; /** * CardController implements the CRUD actions for Card model. */ -class CardController extends \backend\controllers\BackendController -{ - - public function behaviors() - { - return [ - 'access' => [ - 'class' => \yii\filters\AccessControl::className(), - 'rules' => [ - // allow authenticated users - [ - 'actions' => ['create','index','view','update','list'], - 'allow' => true, - 'roles' => ['@'], - ], - // everything else is denied - ], - ], +class CardController extends \backend\controllers\BackendController { + public function behaviors() { + return [ + 'access' => [ + 'class' => \yii\filters\AccessControl::className (), + 'rules' => [ + // allow authenticated users + [ + 'actions' => [ + 'create', + 'index', + 'view', + 'update', + 'list' , + 'import-rfid' + ], + 'allow' => true, + 'roles' => [ + '@' + ] + ] + ] + // everything else is denied + + ] ]; } - - /** - * Lists all Card models. - * @return mixed - */ - public function actionIndex() - { - $searchModel = new CardSearch(); - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - - return $this->render('index', [ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, - ]); - } - - /** - * Displays a single Card model. - * @param integer $id - * @return mixed - */ - public function actionView($id) - { - return $this->render('view', [ - 'model' => $this->findModel($id), - ]); - } - - /** - * Creates a new Card model. - * If creation is successful, the browser will be redirected to the 'view' page. - * @return mixed - */ - public function actionCreate() - { - $model = new Card(); + + /** + * Lists all Card models. + * + * @return mixed + */ + public function actionIndex() { + $searchModel = new CardSearch (); + $dataProvider = $searchModel->search ( Yii::$app->request->queryParams ); + + return $this->render ( 'index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider + ] ); + } + + /** + * Displays a single Card model. + * + * @param integer $id + * @return mixed + */ + public function actionView($id) { + return $this->render ( 'view', [ + 'model' => $this->findModel ( $id ) + ] ); + } + + /** + * Creates a new Card model. + * If creation is successful, the browser will be redirected to the 'view' page. + * + * @return mixed + */ + public function actionCreate() { + $model = new Card (); $model->status = Card::STATUS_ACTIVE; $model->type = Card::TYPE_RFID; - if ($model->load(Yii::$app->request->post()) && $model->save()) { - \Yii::$app->session->setFlash( 'success','Card created!' ); - if ( isset($_POST['create_next'])){ - return $this->redirect(['create' ]); - }else{ - return $this->redirect(['view', 'id' => $model->id_card]); - } - } else { - return $this->render('create', [ - 'model' => $model, - ]); - } - } + if ($model->load ( Yii::$app->request->post () ) && $model->save ()) { + \Yii::$app->session->setFlash ( 'success', 'Card created!' ); + if (isset ( $_POST ['create_next'] )) { + return $this->redirect ( [ + 'create' + ] ); + } else { + return $this->redirect ( [ + 'view', + 'id' => $model->id_card + ] ); + } + } else { + return $this->render ( 'create', [ + 'model' => $model + ] ); + } + } + + /** + * Updates an existing Card model. + * If update is successful, the browser will be redirected to the 'view' page. + * + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) { + $model = $this->findModel ( $id ); + + if ($model->load ( Yii::$app->request->post () ) && $model->save ()) { + return $this->redirect ( [ + 'index' + ] ); + // return $this->redirect(Yii::$app->request->referrer); + } else { + return $this->render ( 'update', [ + 'model' => $model + ] ); + } + } + + /** + * Deletes an existing Card model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * + * @param integer $id + * @return mixed + */ + public function actionDelete($id) { + $this->findModel ( $id )->delete (); + + return $this->redirect ( [ + 'index' + ] ); + } + + /** + * Finds the Card model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * @return Card the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) { + if (($model = Card::findOne ( $id )) !== null) { + return $model; + } else { + throw new NotFoundHttpException ( 'The requested page does not exist.' ); + } + } + + /** + * Your controller action to fetch the list + */ + public function actionList($search = null) { + $query = new Query (); + + $query->select ( [ + 'card.number as number', + 'customer.name as name', + "concat( card.number , case when customer.name is null then '' else customer.name end ) as txt " + ] )->from ( Card::tableName () )->join ( "left join", Customer::tableName (), 'card.id_card = customer.id_customer_card' )->where ( ' lower(number) LIKE "%' . strtolower ( $search ) . '%"' )->orderBy ( 'number' ); + + if (isset ( $_GET ['onlyFree'] ) && $_GET ['onlyFree'] == '1') { + $query->andWhere ( 'customer.id_customer is null' ); + } + + $command = $query->createCommand (); + $data = $command->queryAll (); + $out = [ ]; + foreach ( $data as $d ) { + $out [] = [ + 'number' => $d ['number'], + 'name' => $d ['name'], + 'txt' => $d ['txt'] + ]; + } + echo Json::encode ( $out ); + } + public function actionImportRfid() { + $model = new CardImportRfidForm (); + $arr = []; + + if (Yii::$app->request->isPost) { + $model->file = UploadedFile::getInstance($model, 'file'); - /** - * Updates an existing Card model. - * If update is successful, the browser will be redirected to the 'view' page. - * @param integer $id - * @return mixed - */ - public function actionUpdate($id) - { - $model = $this->findModel($id); - - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['index']); -// return $this->redirect(Yii::$app->request->referrer); - } else { - return $this->render('update', [ - 'model' => $model, - ]); - } - } - - /** - * Deletes an existing Card model. - * If deletion is successful, the browser will be redirected to the 'index' page. - * @param integer $id - * @return mixed - */ - public function actionDelete($id) - { - $this->findModel($id)->delete(); - - return $this->redirect(['index']); - } - - /** - * Finds the Card model based on its primary key value. - * If the model is not found, a 404 HTTP exception will be thrown. - * @param integer $id - * @return Card the loaded model - * @throws NotFoundHttpException if the model cannot be found - */ - protected function findModel($id) - { - if (($model = Card::findOne($id)) !== null) { - return $model; - } else { - throw new NotFoundHttpException('The requested page does not exist.'); - } - } - - - /** - * Your controller action to fetch the list - */ - public function actionList($search = null) { - $query = new Query(); - - $query->select ( [ - 'card.number as number', - 'customer.name as name', - "concat( card.number , case when customer.name is null then '' else customer.name end ) as txt ", - ] )->from (Card::tableName() )->join("left join", Customer::tableName(), 'card.id_card = customer.id_customer_card')->where ( ' lower(number) LIKE "%' . strtolower ( $search ) . '%"' )->orderBy ( 'number' ) ; - - if ( isset($_GET['onlyFree']) && $_GET['onlyFree'] == '1'){ - $query->andWhere( 'customer.id_customer is null' ); - } - - $command = $query->createCommand (); - $data = $command->queryAll (); - $out = [ ]; - foreach ( $data as $d ) { - $out [] = [ - 'number' => $d ['number'], - 'name' => $d ['name'], - 'txt' => $d ['txt'], - ]; - } - echo Json::encode ( $out ); - } - - - +// print_r($model->file); +// $model->message = "ok"; + $file = $model->file->tempName; + + $file = fopen ( $file , "r" ); + + $trans = null; + $i = 0; + $j = 0; + while ( ($data = fgetcsv ( $file, 0, "," )) != null ) { +// if ($i == 0) { +// $i ++; +// continue; +// } + $j++; + $number = $key = false; + if ( isset($data[0]) ){ + $number = $data[0]; + } + + if ( isset($data[1]) ){ + $key = $data[1]; + } + + if ( isset($number) && isset($key)){ + $item = []; + $item['number'] = $number; + $item['key'] = Helper::fixAsciiChars( $key); + $arr[] = $item; + } + + + } + + $failed = []; + $sqls = []; + foreach ($arr as $item ){ + $card = Card::find()->andWhere(['number' => $item['number']])->one(); + if ( $card != null ){ + $card->rfid_key = $item['key']; + $sql = "update card set rfid_key = '" .$item['key'] ."' where id_card = " .$card->id_card .";"; + $sqls[] = $sql; + $i++; + }else{ + $failed [] = $item; + } + } + + $model->message = "rows read: " .$j ." / ". "updated cards: " .$i; + $model->message .= "
array size: " . count($arr); + $model->message .= "
failed: " . print_r($failed,true); + $model->message .= "
sql:"; + $model->message .= "
". implode("
", $sqls); + + } + + return $this->render ( 'importRfid.php', [ + 'model' => $model + ] ); + } } diff --git a/backend/models/CardImportRfidForm.php b/backend/models/CardImportRfidForm.php new file mode 100644 index 0000000..d623b4e --- /dev/null +++ b/backend/models/CardImportRfidForm.php @@ -0,0 +1,30 @@ + + + ['enctype' => 'multipart/form-data']]) ?> + + field($model, 'file')->fileInput() ?> + + + message); + ?> + + + \ No newline at end of file From e8df61f12302d4a10afeb02de93dd87ce65ff15d Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Fri, 8 Jan 2016 14:06:55 +0100 Subject: [PATCH 4/8] add reception account state view and pdf export --- common/components/DailyListing.php | 43 +- .../accountstate/AccountStateWidget.php | 84 ++++ .../accountstate/BankNotesWidget.php | 96 +++++ common/components/total/TotalBaseWidget.php | 21 + .../TotalDetailedMoneyMovementWidget.php | 9 + .../total/TotalDetailedProductsWidget.php | 9 + .../total/TotalDetailedTicketsWidget.php | 9 + .../total/TotalDifferenceWidget.php | 68 +++ common/components/total/TotalEasyWidget.php | 22 + .../total/TotalMediumMoneyMovementsWidget.php | 9 + .../total/TotalMediumProductsWidget.php | 9 + .../total/TotalMediumTicketsWidget.php | 9 + common/models/AccountState.php | 9 + common/models/Transfer.php | 2 + .../views/account-state/account_state_pdf.php | 102 +++++ .../total/total_detailed_money_movement.php | 41 ++ common/views/total/total_detailed_product.php | 51 +++ common/views/total/total_detailed_ticket.php | 46 ++ common/views/total/total_difference.php | 1 + .../total/total_medium_money_movement.php | 26 ++ common/views/total/total_medium_product.php | 45 ++ common/views/total/total_medium_ticket.php | 27 ++ common/views/total/totaleasy.php | 46 ++ .../AccountStateBanknoteCountWidget.php | 59 +-- frontend/components/FrontendMenuStructure.php | 4 +- .../controllers/AccountStateController.php | 392 ++++++++++-------- frontend/models/AccountstateSearch.php | 25 +- frontend/views/account-state/_search.php | 75 ++-- frontend/views/account-state/index.php | 2 +- frontend/views/account-state/view.php | 137 ++++-- 30 files changed, 1190 insertions(+), 288 deletions(-) create mode 100644 common/components/accountstate/AccountStateWidget.php create mode 100644 common/components/accountstate/BankNotesWidget.php create mode 100644 common/components/total/TotalBaseWidget.php create mode 100644 common/components/total/TotalDetailedMoneyMovementWidget.php create mode 100644 common/components/total/TotalDetailedProductsWidget.php create mode 100644 common/components/total/TotalDetailedTicketsWidget.php create mode 100644 common/components/total/TotalDifferenceWidget.php create mode 100644 common/components/total/TotalEasyWidget.php create mode 100644 common/components/total/TotalMediumMoneyMovementsWidget.php create mode 100644 common/components/total/TotalMediumProductsWidget.php create mode 100644 common/components/total/TotalMediumTicketsWidget.php create mode 100644 common/views/account-state/account_state_pdf.php create mode 100644 common/views/total/total_detailed_money_movement.php create mode 100644 common/views/total/total_detailed_product.php create mode 100644 common/views/total/total_detailed_ticket.php create mode 100644 common/views/total/total_difference.php create mode 100644 common/views/total/total_medium_money_movement.php create mode 100644 common/views/total/total_medium_product.php create mode 100644 common/views/total/total_medium_ticket.php create mode 100644 common/views/total/totaleasy.php diff --git a/common/components/DailyListing.php b/common/components/DailyListing.php index c3013f6..7fad687 100644 --- a/common/components/DailyListing.php +++ b/common/components/DailyListing.php @@ -15,7 +15,8 @@ use common\components\RoleDefinition; class DailyListing { - public $mode = "reception";//reception or admin + public $mode = "reception";//reception or admin or accountstate + /** * string start date , inclusive * */ @@ -108,6 +109,25 @@ class DailyListing public $type; + public function readTotalEasy(){ + $this->readTicketMoney(); + $this->readProductsMoney(); + $this->readMoneyMovementMoney(); + $this->calcTotal(); + } + + public function readTotalDetailed(){ + $this->readTickets(); + $this->readProducts(); + $this->readMoneyMovements(); + } + public function readTotalMedium(){ + $this->readProductsByCategory(); + $this->readProductsByCategoryDetailed(); + $this->readTicketStas(); + $this->readMoneyMovementsStats(); + } + public function loadFilters($transfer){ $this->start = $transfer->start; $this->end = $transfer->end; @@ -119,9 +139,22 @@ class DailyListing $this->timestampEnd = $transfer->timestampEnd; } + public function loadAccountState($accountState){ + $this->mode = 'accountstate'; + $this->start = $accountState->start_date; + $this->end = $accountState->created_at; + $this->timestampStart = $accountState->start_date; + $this->timestampEnd =$accountState->created_at; + $this->id_account = $accountState->id_account; + $this->id_user = $accountState->id_user; + } + public function isModeAdmin(){ return $this->mode == 'admin'; } + public function isModeAccountState(){ + return $this->mode == 'accountstate'; + } public function calcTotal(){ @@ -139,11 +172,15 @@ class DailyListing public function addAccountConstraint($query){ - if (!$this->isModeAdmin() || !RoleDefinition::isAdmin() ){ + + if ( $this->isModeAccountState() ){ + $query->andWhere(['account.type' => Account::TYPE_ALL ]); + + }else if (!$this->isModeAdmin() || !RoleDefinition::isAdmin() ){ $query->innerJoin("user_account_assignment",'transfer.id_account = user_account_assignment.id_account' ); $query->andWhere(['user_account_assignment.id_user' => Yii::$app->user->id ]); - if ( RoleDefinition::isReception() || !$this->isModeAdmin()){ + if ( RoleDefinition::isReception() || !$this->isModeAdmin()){ $query->andWhere(['transfer.id_user' => Yii::$app->user->id ]); } diff --git a/common/components/accountstate/AccountStateWidget.php b/common/components/accountstate/AccountStateWidget.php new file mode 100644 index 0000000..d0fd53a --- /dev/null +++ b/common/components/accountstate/AccountStateWidget.php @@ -0,0 +1,84 @@ +model->isTypeOpen() ){ + $attributes = [ + [ + 'attribute' =>'account.name', + 'label' => 'Kassza' + ], + [ + 'attribute' =>'typeName', + 'label' => 'Típus' + ], + [ + 'attribute' =>'money', + 'value' => \Yii::$app->formatter->asInteger($this->model->money) ." Ft", + ], + 'user.username', + [ + 'attribute' => 'created_at', + 'label' => 'Nyitás ideje' + ], + ]; + }else{ + + $attributes = [ + [ + 'attribute' =>'account.name', + 'label' => 'Kassza' + ], + [ + 'attribute' =>'typeName', + 'label' => 'Típus' + ], + [ + 'attribute' =>'money', + 'value' => \Yii::$app->formatter->asInteger($this->model->money) ." Ft", + ], + 'user.username', + [ + 'attribute' => 'start_date', + 'label' => 'Előző nyitás ideje' + ], + [ + 'attribute' => 'created_at', + 'label' => 'Zárás ideje' + ], + ]; + } + + + + + echo DetailView::widget([ + 'model' => $this->model, + 'attributes' =>$attributes, + ]) ; + } + + + +} \ No newline at end of file diff --git a/common/components/accountstate/BankNotesWidget.php b/common/components/accountstate/BankNotesWidget.php new file mode 100644 index 0000000..93680bd --- /dev/null +++ b/common/components/accountstate/BankNotesWidget.php @@ -0,0 +1,96 @@ +generateNotes(); + } + + protected function generateNotes(){ + $s = ""; + $s .= Html::beginTag("div", ['class' => 'row', 'style' => 'margin-top: 6px;']); + $s .= Html::beginTag("div", ['class' => 'col-md-4']); + $s .= $this->generateBanknoteGrid( [ 'banknote_5_ft','banknote_10_ft','banknote_20_ft','banknote_50_ft' ]); + $s .= Html::endTag("div"); + $s .= Html::beginTag("div", ['class' => 'col-md-4']); + $s .= $this->generateBanknoteGrid( [ 'banknote_100_ft','banknote_200_ft','banknote_500_ft','banknote_1000_ft' ]); + $s .= Html::endTag("div"); + $s .= Html::beginTag("div", ['class' => 'col-md-4']); + $s .= $this->generateBanknoteGrid( [ 'banknote_2000_ft','banknote_5000_ft','banknote_10000_ft','banknote_20000_ft' ]); + $s .= Html::endTag("div"); + $s .= Html::endTag("div"); + return $s; + } + + protected function generateBanknoteGrid($attributes){ + + return $this->generateBanknoteColumn( $this->mkColumnData($attributes)); + } + + protected function mkColumnData( $attributes){ + + $values = AccountState::banknoteValues(); + $items = []; + foreach ($attributes as $note){ + $value = $values[$note]; + $count = $this->model->$note; + if ( !isset($count) || empty($count)){ + $count = 0; + } + $value = \Yii::$app->formatter->asInteger($value); + $item = [ + 'note' => $value . " Ft", + 'count' => $count + ]; + $items[] = $item; + } + + return $items; + } + + protected function generateBanknoteColumn($data){ + $dp = new ArrayDataProvider( + [ + 'allModels' => $data, + 'sort' => false, + 'pagination' => false + ] + ); + $s = GridView::widget([ + 'dataProvider' => $dp, + 'layout' => '{items}', + 'options' => ['class' => 'grid-view notes-view'], + 'columns' =>[ + [ + 'contentOptions' => ['class' => 'note-name'], + 'value' => 'note', + 'label' => 'Címlet' + ], + [ + 'value' => 'count', + 'label' => 'Db' + ], + ] + ]); + return $s; + } + +} \ No newline at end of file diff --git a/common/components/total/TotalBaseWidget.php b/common/components/total/TotalBaseWidget.php new file mode 100644 index 0000000..eca311b --- /dev/null +++ b/common/components/total/TotalBaseWidget.php @@ -0,0 +1,21 @@ +view = $this->viewPath . "/" . $this->viewFile; + } + + public function run(){ + echo $this->render($this->view,[ 'model' => $this->dailyListing ]); + } + +} \ No newline at end of file diff --git a/common/components/total/TotalDetailedMoneyMovementWidget.php b/common/components/total/TotalDetailedMoneyMovementWidget.php new file mode 100644 index 0000000..bf37326 --- /dev/null +++ b/common/components/total/TotalDetailedMoneyMovementWidget.php @@ -0,0 +1,9 @@ +generateDifference(); + } + + protected function generateDifference(){ + $s = ""; + if ( $this->model->hasDifferenceToPrevState()){ + + $ft = " Ft"; + $s .= DetailView::widget([ + 'model' => $this->model, + 'template' =>"{label}{value} ", + 'attributes' => [ + [ + 'label' => "Előző nyitás ideje", + 'value' => $this->model->prevObject ? \Yii::$app->formatter->asDatetime( $this->model->prevObject->created_at) : "-", + ], + [ + 'label' => "Előzőleg nyitott", + 'value' => $this->model->prevObject ? $this->model->user->username : "-", + ], + [ + 'label' => "Előző nyitás összege", + 'value' => $this->model->prev_money.$ft + ], + [ + 'label' => "Bevételek összesen előző nyitás óta", + 'value' => $this->model->collection_money .$ft + ], + [ + 'label' => "Zárás összege", + 'value' => $this->model->money.$ft + ], + [ + 'label' => "Várt összeg", + 'value' => $this->model->expected.$ft + ], + [ + 'label' => "Különbözet", + 'value' => $this->model->signedDiff.$ft + ], + ] + ]); + } + return $s; + } + + +} \ No newline at end of file diff --git a/common/components/total/TotalEasyWidget.php b/common/components/total/TotalEasyWidget.php new file mode 100644 index 0000000..ca0922a --- /dev/null +++ b/common/components/total/TotalEasyWidget.php @@ -0,0 +1,22 @@ +view = $this->viewPath . "/" . $this->viewFile; + } + + public function run(){ + echo $this->render($this->view,[ 'model' => $this->dailyListing ]); + } + + +} \ No newline at end of file diff --git a/common/components/total/TotalMediumMoneyMovementsWidget.php b/common/components/total/TotalMediumMoneyMovementsWidget.php new file mode 100644 index 0000000..b2f99f7 --- /dev/null +++ b/common/components/total/TotalMediumMoneyMovementsWidget.php @@ -0,0 +1,9 @@ +type == AccountState::TYPE_OPEN; + } + public function isTypeClose(){ + return $this->type == AccountState::TYPE_CLOSE; + } + public static function banknoteValues() { return [ diff --git a/common/models/Transfer.php b/common/models/Transfer.php index 57c6030..e575a44 100644 --- a/common/models/Transfer.php +++ b/common/models/Transfer.php @@ -712,6 +712,7 @@ class Transfer extends \common\models\BaseFitnessActiveRecord $query = (new \yii\db\Query()); $query->select(['coalesce(sum( case when transfer.direction = ' . Transfer::DIRECTION_IN. ' then transfer.money else -1 * transfer.money end ),0) AS transfer_money']); $query->from('transfer'); + $query->innerJoin("account","account.id_account = transfer.id_account"); $query->andWhere(['transfer.id_user' => $idUser ]); $created_condition = ['and',[ '>=', 'transfer.created_at', $start ] ,[ '<', 'transfer.created_at', $end ] ]; @@ -719,6 +720,7 @@ class Transfer extends \common\models\BaseFitnessActiveRecord $query->andFilterWhere(['or' , $created_condition , $paid_condition]); $query->andWhere(['transfer.status' => Transfer::STATUS_PAID]); + $query->andWhere(['account.type' => Account::TYPE_ALL]); return $query->scalar(); } diff --git a/common/views/account-state/account_state_pdf.php b/common/views/account-state/account_state_pdf.php new file mode 100644 index 0000000..6c3df5c --- /dev/null +++ b/common/views/account-state/account_state_pdf.php @@ -0,0 +1,102 @@ +type == AccountState::TYPE_OPEN ){ + $this->title = "Kassza nyitás"; +}else{ + $this->title = "Kassza zárás"; +} + + + +?> +'> + + + + + +

Címletek

+ $model]);?> + + +
\ No newline at end of file diff --git a/common/views/total/total_detailed_money_movement.php b/common/views/total/total_detailed_money_movement.php new file mode 100644 index 0000000..140fe2f --- /dev/null +++ b/common/views/total/total_detailed_money_movement.php @@ -0,0 +1,41 @@ +

Pénzmozgások

+ + + + + + + + + + + + + moneyMovements as $p ){?> + + + + + + + + + + + +
DátumKasszaFelhasználóNévTípusÖsszeg
formatter->asInteger( $p['signed_money'])?> Ft
+ moneyMovements ) == 0 ) { + ?> + Nincs találat + + +
+
+ Összesen: formatter->asInteger( $model->moneyMovementMoneis); ?> Ft + +
+
+ \ No newline at end of file diff --git a/common/views/total/total_detailed_product.php b/common/views/total/total_detailed_product.php new file mode 100644 index 0000000..85806c6 --- /dev/null +++ b/common/views/total/total_detailed_product.php @@ -0,0 +1,51 @@ + +

Termék eladások

+ + + + + + + + + + + + + + + + products as $p ){?> + + + + + + + + + + + + + + +
KiadvaFizetveKasszaFelhasználóKategóriaTermékEgység árMennyiségÖsszeg
Ft Dbformatter->asInteger( $p['product_money'])?> FT
+ products ) == 0 ) { + ?> + Nincs találat + + +
+
+ Összesen: formatter->asInteger( $model->productMoney); ?> Ft +
+
+ \ No newline at end of file diff --git a/common/views/total/total_detailed_ticket.php b/common/views/total/total_detailed_ticket.php new file mode 100644 index 0000000..cf58189 --- /dev/null +++ b/common/views/total/total_detailed_ticket.php @@ -0,0 +1,46 @@ +

Bérletek

+ + + + + + + + + + + + + + + tickets as $t ){?> + + + + + + + + + + + + + +
KiadvaFizetveKasszaFelhasználóBérlet típusEgység árMennyiségÖsszeg
Ft Dbformatter->asInteger( $t['ticket_money'])?> FT
+ tickets ) == 0 ) { + ?> + Nincs találat + + +
+
+ Összesen: formatter->asInteger( $model->ticketMoney); ?> Ft + +
+
+ + + + + Pénzmozgás típus + Mennyiség + Összeg + + + + moneyMovementsByType as $mmStat ) { + ?> + + + Db + formatter->asInteger( $mmStat['money_movement_money'])?> FT + + + + +
+
+ Összesen: formatter->asInteger( $model->moneyMovementMoneis); ?> Ft +
+
+ diff --git a/common/views/total/total_medium_product.php b/common/views/total/total_medium_product.php new file mode 100644 index 0000000..f6f14bf --- /dev/null +++ b/common/views/total/total_medium_product.php @@ -0,0 +1,45 @@ +productsByCategory ['categories'] as $categoryHolder ) { + + $products = $categoryHolder ['products']; + ?> +

+ + + + + + + + + + + + + + + + + + + + + + + + + +
TermékMennyiségÖsszeg
Dbformatter->asInteger( $p['product_money'])?> FT
formatter->asInteger( $categoryHolder['total'])?> FT
+ +
+
+ Összesen: + formatter->asInteger( $model->productsByCategory ['total']); + ?> Ft +
+
\ No newline at end of file diff --git a/common/views/total/total_medium_ticket.php b/common/views/total/total_medium_ticket.php new file mode 100644 index 0000000..ddc00ca --- /dev/null +++ b/common/views/total/total_medium_ticket.php @@ -0,0 +1,27 @@ + + + + + + + + + + ticketStats as $ticketStat ) { + ?> + + + + + + + +
Bérlet típusMennyiségÖsszeg
Dbformatter->asInteger( $ticketStat['ticket_money'])?> FT
+ +
+
+ Összesen: formatter->asInteger( $model->ticketMoney); ?> Ft + +
+
\ No newline at end of file diff --git a/common/views/total/totaleasy.php b/common/views/total/totaleasy.php new file mode 100644 index 0000000..276f18e --- /dev/null +++ b/common/views/total/totaleasy.php @@ -0,0 +1,46 @@ + + +render('_list_pdf_head',[ 'searchModel' =>$model, 'label' => 'Napi bevételek - Egyszerű','type' =>'easy']); +?> + +

Egyszerű összesítés

+ output) ){ + +// $pdfUrl = Url::current([ Html::getInputName($model, 'output') => 'pdf']); +// echo Html::a("Teljes PDF letöltése", $pdfUrl,['class' => 'btn btn-primary btn-all' ]); + +// $pdfUrl = Url::current([ Html::getInputName($model, 'output') => 'pdf', Html::getInputName($model, 'outputView') => 'easy']); +// echo Html::a("Egyszerű összesítő Pdf", $pdfUrl,['class' => 'btn btn-primary' ]); +// } + + +?> +

Bruttó

+ + + + + + + + + + + + + + + + + + + +
Bérletekformatter->asInteger( $model->ticketMoney)?> FT
Termékekformatter->asInteger( $model->productMoney)?> FT
Pénzmozgásokformatter->asInteger( $model->moneyMovementMoneis)?> FT
Végösszeg bruttóformatter->asInteger( $model->total)?> FT
+ diff --git a/frontend/components/AccountStateBanknoteCountWidget.php b/frontend/components/AccountStateBanknoteCountWidget.php index d824430..b4c05fd 100644 --- a/frontend/components/AccountStateBanknoteCountWidget.php +++ b/frontend/components/AccountStateBanknoteCountWidget.php @@ -9,7 +9,14 @@ use yii\grid\GridView; use yii\base\Object; use yii\data\ArrayDataProvider; use yii\helpers\Url; +use common\components\total\TotalDifferenceWidget; +/** + * Display account state widget + * + * @property common\models\AccountState $model the account state object + * @property int $index the current index in the list + * */ class AccountStateBanknoteCountWidget extends Widget{ public $model; @@ -37,53 +44,27 @@ class AccountStateBanknoteCountWidget extends Widget{ $s .= $this->generateInfoRow(); - $s .= $this->generateNotes(); - +// $s .= $this->generateNotes(); + if ( $this->model->hasDifferenceToPrevState()){ - - $ft = " Ft"; - $s .= DetailView::widget([ - 'model' => $this->model, - 'template' =>"{label}{value} ", - 'attributes' => [ - [ - 'label' => "Előző nyitás ideje", - 'value' => $this->model->prevObject ? \Yii::$app->formatter->asDatetime( $this->model->prevObject->created_at) : "-", - ], - [ - 'label' => "Előzőleg nyitott", - 'value' => $this->model->prevObject ? $this->model->user->username : "-", - ], - [ - 'label' => "Előző nyitás összege", - 'value' => $this->model->prev_money.$ft - ], - [ - 'label' => "Bevételek összesen utolsó nyitás óta", - 'value' => $this->model->collection_money .$ft - ], - [ - 'label' => "Zárás összege", - 'value' => $this->model->money.$ft - ], - [ - 'label' => "Várt összeg", - 'value' => $this->model->expected.$ft - ], - [ - 'label' => "Különbözet", - 'value' => $this->model->signedDiff.$ft - ], - ] - ]); + $s .= "

Különbözet

"; + $s .= TotalDifferenceWidget::widget(['model' => $this->model]); } + $s .= $this->generateComment(); $s .= Html::beginTag("div", ['class' => 'row', 'style' => 'margin-top: 6px;']); $s .= Html::beginTag("div", ['class' => 'col-md-12 text-right']); - $s .= Html::a('Törlés', Url::toRoute(['delete','id' =>$this->model->id_account_state]), [ + $s .= Html::a( Html::tag("span","",['class' =>'glyphicon glyphicon-download-alt']) ." Pdf", Url::to([ 'view', 'id' =>$this->model->id_account_state, 'output' =>'pdf']) ,['class' => 'btn btn-primary btn-pdf','style' =>'margin-bottom: 12px; margin-right: 6px;']); + + $s .= Html::a(' Részletek', Url::toRoute(['view','id' =>$this->model->id_account_state]), [ + 'title' => 'Részletek', + 'class' => 'btn btn-success', + 'style' =>'margin-bottom: 12px; margin-right: 6px;' + ]); + $s .= Html::a(' Törlés', Url::toRoute(['delete','id' =>$this->model->id_account_state]), [ 'title' => \Yii::t('yii', 'Delete'), 'data-confirm' =>\Yii::t('yii', 'Are you sure to delete this item?'), 'data-method' => 'post', diff --git a/frontend/components/FrontendMenuStructure.php b/frontend/components/FrontendMenuStructure.php index 485ebbf..0449231 100644 --- a/frontend/components/FrontendMenuStructure.php +++ b/frontend/components/FrontendMenuStructure.php @@ -19,10 +19,12 @@ class FrontendMenuStructure{ public $startDate;//start date public $tomorrowDate;//tomorrow date + public $yesterDay;//yesterday date public function __construct(){ $this->menuItems = []; + $this->yesterDay = \Yii::$app->formatter->asDatetime( strtotime('yesterday UTC') ); $this->start = \Yii::$app->formatter->asDatetime( strtotime('today UTC') ); $this->tomorrow = Yii::$app->formatter->asDatetime( strtotime('tomorrow UTC') ); $this->startDate = Yii::$app->formatter->asDate( strtotime('today UTC') ); @@ -66,7 +68,7 @@ class FrontendMenuStructure{ $items = [ ['label' => Yii::t('frontend/account-state','Default account'), 'url' => ['/account/select'] ], - ['label' => Yii::t('frontend/account-state', 'Account states'), 'url' => ['/account-state/index'] ], + ['label' => Yii::t('frontend/account-state', 'Account states'), 'url' => ['/account-state/index' ,'AccountstateSearch[id_account]' => Account::readDefault(), 'AccountstateSearch[start]' => $this->yesterDay] ], ['label' => Yii::t('frontend/account-state','Open account state'), 'url' => ['/account-state/open'] ], ['label' => Yii::t('frontend/account-state','Close account state'), 'url' => ['/account-state/close'] ], diff --git a/frontend/controllers/AccountStateController.php b/frontend/controllers/AccountStateController.php index 9f1c596..54d67f2 100644 --- a/frontend/controllers/AccountStateController.php +++ b/frontend/controllers/AccountStateController.php @@ -9,179 +9,231 @@ use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; use common\models\Account; +use common\components\DailyListing; +use common\models\User; /** * AccountStateController implements the CRUD actions for AccountState model. */ -class AccountStateController extends Controller -{ - public function behaviors() - { - return [ - 'access' => [ - 'class' => \yii\filters\AccessControl::className(), - 'only' => [ 'index','open','close'], - 'rules' => [ - // allow authenticated users - [ - 'allow' => true, - 'roles' => ['@'], - ], - // everything else is denied - ], - ], - ]; - } - - /** - * Lists all AccountState models. - * @return mixed - */ - public function actionIndex() - { - $searchModel = new AccountstateSearch(); - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - - return $this->render('index', [ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, - ]); - } - - - /** - * Creates a new AccountState model. - * If creation is successful, the browser will be redirected to the 'view' page. - * @return mixed - */ - public function actionOpen() - { - - $lastStates = AccountState::readLastForUser(AccountState::TYPE_CLOSE ); - $lastStates = AccountState::modelsToArray($lastStates); - - $model = new AccountState(); +class AccountStateController extends Controller { + public function behaviors() { + return [ + 'access' => [ + 'class' => \yii\filters\AccessControl::className (), + 'only' => [ + 'index', + 'open', + 'close', + 'view' + ], + 'rules' => [ + // allow authenticated users + [ + 'allow' => true, + 'roles' => [ + '@' + ] + ] + ] + ] + // everything else is denied + + + ]; + } + + /** + * Lists all AccountState models. + * + * @return mixed + */ + public function actionIndex() { + $searchModel = new AccountstateSearch (); + + $searchModel->accounts = Account::read (); + $searchModel->users = User::read (); + + $dataProvider = $searchModel->search ( Yii::$app->request->queryParams ); + + return $this->render ( 'index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider + ] ); + } + + /** + * Creates a new AccountState model. + * If creation is successful, the browser will be redirected to the 'view' page. + * + * @return mixed + */ + public function actionOpen() { + $lastStates = AccountState::readLastForUser ( AccountState::TYPE_CLOSE ); + $lastStates = AccountState::modelsToArray ( $lastStates ); + + $model = new AccountState (); $model->type = AccountState::TYPE_OPEN; - $model->id_user = Yii::$app->user->id; - $model->id_account = Account::readDefault(); - if ($model->load(Yii::$app->request->post()) && $model->save()) { -// return $this->redirect(['view', 'id' => $model->id_account_state]); - return $this->redirect(['index' ]); - } else { - - $accounts = Account::read(); - - return $this->render('open', [ - 'model' => $model, - 'accounts' => $accounts, - 'lastStates' => $lastStates, - ]); - } - } - /** - * Creates a new AccountState model. - * If creation is successful, the browser will be redirected to the 'view' page. - * @return mixed - */ - public function actionClose() - { - $lastStates = AccountState::readLastForUser(AccountState::TYPE_OPEN ); - $lastStates = AccountState::modelsToArray($lastStates); - $model = new AccountState(); - $model->type = AccountState::TYPE_CLOSE; - $model->id_user = Yii::$app->user->id; - $model->id_account = Account::readDefault(); - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['index' ]); -// return $this->redirect(['view', 'id' => $model->id_account_state]); - } else { - - $accounts = Account::read(); - - return $this->render('close', [ - 'model' => $model, - 'accounts' => $accounts, - 'lastStates' => $lastStates, - ]); - } - } - - - - - - /** - * Finds the AccountState model based on its primary key value. - * If the model is not found, a 404 HTTP exception will be thrown. - * @param integer $id - * @return AccountState the loaded model - * @throws NotFoundHttpException if the model cannot be found - */ - protected function findModel($id) - { - if (($model = AccountState::findOne($id)) !== null) { - return $model; - } else { - throw new NotFoundHttpException('The requested page does not exist.'); - } - } - /** - * Creates a new AccountState model. - * If creation is successful, the browser will be redirected to the 'view' page. - * @return mixed - public function actionCreate() - { - $model = new AccountState(); - - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->id_account_state]); - } else { - return $this->render('create', [ - 'model' => $model, - ]); - } - } - */ - /** - * Updates an existing AccountState model. - * If update is successful, the browser will be redirected to the 'view' page. - * @param integer $id - * @return mixed - public function actionUpdate($id) - { - $model = $this->findModel($id); - - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->id_account_state]); - } else { - return $this->render('update', [ - 'model' => $model, - ]); - } - } - */ - /** - * Deletes an existing AccountState model. - * If deletion is successful, the browser will be redirected to the 'index' page. - * @param integer $id - * @return mixed - */ - public function actionDelete($id) - { - $this->findModel($id)->delete(); - \Yii::$app->session->setFlash( 'success','Kassza művelet törölve' ); - return $this->redirect(Yii::$app->request->referrer); - } - /** - * Displays a single AccountState model. - * @param integer $id - * @return mixed - - public function actionView($id) - { - return $this->render('view', [ - 'model' => $this->findModel($id), - ]); - } - */ + $model->id_user = Yii::$app->user->id; + $model->id_account = Account::readDefault (); + if ($model->load ( Yii::$app->request->post () ) && $model->save ()) { + // return $this->redirect(['view', 'id' => $model->id_account_state]); + return $this->redirect ( [ + 'index' + ] ); + } else { + + $accounts = Account::read (); + + return $this->render ( 'open', [ + 'model' => $model, + 'accounts' => $accounts, + 'lastStates' => $lastStates + ] ); + } + } + /** + * Creates a new AccountState model. + * If creation is successful, the browser will be redirected to the 'view' page. + * + * @return mixed + */ + public function actionClose() { + $lastStates = AccountState::readLastForUser ( AccountState::TYPE_OPEN ); + $lastStates = AccountState::modelsToArray ( $lastStates ); + $model = new AccountState (); + $model->type = AccountState::TYPE_CLOSE; + $model->id_user = Yii::$app->user->id; + $model->id_account = Account::readDefault (); + if ($model->load ( Yii::$app->request->post () ) && $model->save ()) { + return $this->redirect ( [ + 'index' + ] ); + // return $this->redirect(['view', 'id' => $model->id_account_state]); + } else { + + $accounts = Account::read (); + + return $this->render ( 'close', [ + 'model' => $model, + 'accounts' => $accounts, + 'lastStates' => $lastStates + ] ); + } + } + + /** + * Finds the AccountState model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * @return AccountState the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) { + if (($model = AccountState::findOne ( $id )) !== null) { + return $model; + } else { + throw new NotFoundHttpException ( 'The requested page does not exist.' ); + } + } + /** + * Creates a new AccountState model. + * If creation is successful, the browser will be redirected to the 'view' page. + * + * @return mixed public function actionCreate() + * { + * $model = new AccountState(); + * + * if ($model->load(Yii::$app->request->post()) && $model->save()) { + * return $this->redirect(['view', 'id' => $model->id_account_state]); + * } else { + * return $this->render('create', [ + * 'model' => $model, + * ]); + * } + * } + */ + /** + * Updates an existing AccountState model. + * If update is successful, the browser will be redirected to the 'view' page. + * + * @param integer $id + * @return mixed public function actionUpdate($id) + * { + * $model = $this->findModel($id); + * + * if ($model->load(Yii::$app->request->post()) && $model->save()) { + * return $this->redirect(['view', 'id' => $model->id_account_state]); + * } else { + * return $this->render('update', [ + * 'model' => $model, + * ]); + * } + * } + */ + /** + * Deletes an existing AccountState model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * + * @param integer $id + * @return mixed + */ + public function actionDelete($id) { + $this->findModel ( $id )->delete (); + \Yii::$app->session->setFlash ( 'success', 'Kassza művelet törölve' ); + return $this->redirect ( Yii::$app->request->referrer ); + } + /* + * Displays a single AccountState model. + * @param integer $id + * $var common\models\AccountState $accountState + * @return mixed + */ + public function actionView($id) { + $accountState = $this->findModel ( $id ); + $output = Yii::$app->getRequest ()->getQueryParam ( 'output' ); + $details = null; + if ($accountState->isTypeClose ()) { + + $prev; + if ($accountState->type == AccountState::TYPE_CLOSE) { + if (isset ( $accountState->prev_state )) { + $prev = AccountState::findOne ( $accountState->prev_state ); + } + if (isset ( $prev )) { + $accountState->start_date = $prev->created_at; + } + } + $details = new DailyListing (); + $details->loadAccountState ( $accountState ); + + $details->readTotalEasy (); + $details->readTotalDetailed (); + $details->readTotalMedium (); + } + + if ($output == 'pdf') { + $user = User::findOne(\Yii::$app->user->id); + $mpdf=new \mPDF('utf-8', 'A4-L'); + $mpdf->useSubstitutions=false; + $mpdf->simpleTables = true; + $mpdf->SetHeader( \Yii::$app->params[ "company_name" ] . " - Létrehozva: " .$user->username . ", ".\Yii::$app->formatter->asDatetime(time()) ); + $mpdf->setFooter('{PAGENO} / {nb}'); + $mpdf->WriteHTML($this->renderPartial("@common/views/account-state/account_state_pdf", [ + 'model' => $accountState, + 'details' => $details + ])); + $type = $accountState->isTypeOpen() ? "kassza_nyitas" : "kassza_zaras"; + $dt= "_letrehozva_".date("Ymd_His"). "_" . $user->username; + $fn= $type .$dt.".pdf"; + $mpdf->Output($fn, 'D'); + + } else { + + return $this->render ( 'view', [ + 'model' => $accountState, + 'details' => $details + ] ); + } + } } diff --git a/frontend/models/AccountstateSearch.php b/frontend/models/AccountstateSearch.php index d18c225..e690752 100644 --- a/frontend/models/AccountstateSearch.php +++ b/frontend/models/AccountstateSearch.php @@ -12,12 +12,25 @@ use common\models\AccountState; */ class AccountstateSearch extends AccountState { + + public $start; + public $end; + + public $timestampStart; + public $timestampEnd; + + + public $accounts; + public $users; /** * @inheritdoc */ public function rules() { - return [ + return [ + [[ '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' ], + [ [ 'id_account','id_user' ,'type' ] , 'integer'], ]; } @@ -54,9 +67,19 @@ class AccountstateSearch extends AccountState return $dataProvider; } + $query->innerJoinWith('account'); $query->innerJoinWith('account.userAccountAssignments'); $query->andWhere(['user_account_assignment.id_user' => Yii::$app->user->id]); + $query->andFilterWhere([ + 'account_state.id_user' => $this->id_user, + 'account_state.type' => $this->type, + 'account_state.id_account' => $this->id_account, + ]); + + $query->andFilterWhere([ '>=', 'account_state.created_at', $this->timestampStart ] ); + $query->andFilterWhere([ '<', 'account_state.created_at', $this->timestampEnd ] ); + $query->orderBy( 'created_at desc' ); $query->limit = 20; diff --git a/frontend/views/account-state/_search.php b/frontend/views/account-state/_search.php index c68771e..5516097 100644 --- a/frontend/views/account-state/_search.php +++ b/frontend/views/account-state/_search.php @@ -2,12 +2,19 @@ use yii\helpers\Html; use yii\widgets\ActiveForm; +use kartik\widgets\DateTimePicker; +use frontend\components\HtmlHelper; +use common\models\AccountState; /* @var $this yii\web\View */ /* @var $model frontend\models\AccountstateSearch */ /* @var $form yii\widgets\ActiveForm */ ?> - +'Mind']+ HtmlHelper::mkAccountOptions( $model->accounts ); +$userOptions = ['' => 'Mind'] + HtmlHelper::mkOptions($model->users,'id','username'); +$typeOptions = ['' => 'Mind'] + AccountState::types(); +?> diff --git a/backend/views/layouts/content.php b/backend/views/layouts/content.php index e7c991c..f4c502f 100644 --- a/backend/views/layouts/content.php +++ b/backend/views/layouts/content.php @@ -1,6 +1,7 @@
@@ -15,7 +16,13 @@ use dmstr\widgets\Alert;
- + true, + 'type' => AlertBlock::TYPE_GROWL, + 'delay' => '1' + ]); + ?>
diff --git a/common/components/accountstate/AccountStateMail.php b/common/components/accountstate/AccountStateMail.php new file mode 100644 index 0000000..cf7bf77 --- /dev/null +++ b/common/components/accountstate/AccountStateMail.php @@ -0,0 +1,67 @@ +model ->isTypeClose ()) { + + $prev; + if ($this->model ->type == AccountState::TYPE_CLOSE) { + if (isset ( $accountState->prev_state )) { + $prev = AccountState::findOne ( $accountState->prev_state ); + } + if (isset ( $prev )) { + $this->model ->start_date = $prev->created_at; + } + } + $details = new DailyListing(); + $details->loadAccountState ( $this->model ); + + $details->readTotalEasy (); + $details->readTotalDetailed (); + $details->readTotalMedium (); + } + + $user = User::findOne($this->model->id_user); + $account = Account::findOne($this->model->id_account); + $subject = $this->model->isTypeOpen() ? "Kassza nyitás " : "Kassza zárás"; + $subject .= " - " . $user->username ." - ". $account->name; + + $mail = \Yii::$app->mailer->compose('account_state', [ + 'model' => $this->model, + 'details' => $details + ]); + $mail->setFrom('noreplay@fitnessadmin.hu') + ->setTo( \Yii::$app->params['notify_mail'] ) + ->setSubject($subject ) + ->send(); + + } + + + + +} \ No newline at end of file diff --git a/common/config/params.php b/common/config/params.php index 74b1f61..ad18215 100644 --- a/common/config/params.php +++ b/common/config/params.php @@ -7,4 +7,6 @@ return [ 'company' => 'movar',//gyor 'company_name' => "Freimann Kft.", 'product_visiblity' => 'account',// on reception which products to display. account or global + 'notify_mail' => ['rocho02@gmail.com' ], + 'mail_account_state_open' => true, ]; diff --git a/common/mail/account_state.php b/common/mail/account_state.php new file mode 100644 index 0000000..c0c627d --- /dev/null +++ b/common/mail/account_state.php @@ -0,0 +1,87 @@ +type == AccountState::TYPE_OPEN ){ + $this->title = "Kassza nyitás"; +}else{ + $this->title = "Kassza zárás"; +} +?> + + + \ No newline at end of file diff --git a/frontend/controllers/AccountStateController.php b/frontend/controllers/AccountStateController.php index 54d67f2..4c184b2 100644 --- a/frontend/controllers/AccountStateController.php +++ b/frontend/controllers/AccountStateController.php @@ -11,6 +11,7 @@ use yii\filters\VerbFilter; use common\models\Account; use common\components\DailyListing; use common\models\User; +use common\components\accountstate\AccountStateMail; /** * AccountStateController implements the CRUD actions for AccountState model. @@ -77,6 +78,12 @@ class AccountStateController extends Controller { $model->id_account = Account::readDefault (); if ($model->load ( Yii::$app->request->post () ) && $model->save ()) { // return $this->redirect(['view', 'id' => $model->id_account_state]); + + + $mail = new AccountStateMail(['model' => $model]); + $mail->sednMail(); + + return $this->redirect ( [ 'index' ] ); @@ -105,6 +112,11 @@ class AccountStateController extends Controller { $model->id_user = Yii::$app->user->id; $model->id_account = Account::readDefault (); if ($model->load ( Yii::$app->request->post () ) && $model->save ()) { + + + $mail = new AccountStateMail(['model' => $model]); + $mail->sednMail(); + return $this->redirect ( [ 'index' ] ); @@ -179,8 +191,20 @@ class AccountStateController extends Controller { * @return mixed */ public function actionDelete($id) { - $this->findModel ( $id )->delete (); - \Yii::$app->session->setFlash ( 'success', 'Kassza művelet törölve' ); + $model = $this->findModel ( $id ); + $delete = true; + if ( $model->isTypeOpen() ){ + $closeStates = AccountState::find()->andWhere(['prev_state' => $model->id_account_state])->all(); + if ( count($closeStates) > 0){ +// throw new \Exception("Nem lehet törölni a nyitást, mert van kapcsolódó zárás!"); + \Yii::$app->session->setFlash ( 'error', "Nem lehet törölni a nyitást, mert van kapcsolódó zárás!" ); + $delete = false; + } + } + if ( $delete == true){ + $model->delete(); + \Yii::$app->session->setFlash ( 'success', 'Kassza művelet törölve' ); + } return $this->redirect ( Yii::$app->request->referrer ); } /* @@ -219,6 +243,11 @@ class AccountStateController extends Controller { $mpdf->simpleTables = true; $mpdf->SetHeader( \Yii::$app->params[ "company_name" ] . " - Létrehozva: " .$user->username . ", ".\Yii::$app->formatter->asDatetime(time()) ); $mpdf->setFooter('{PAGENO} / {nb}'); + + $stylesheet = file_get_contents( \Yii::getAlias('@vendor'.'/bower/bootstrap/dist/css/bootstrap.css')); // external css + $mpdf->WriteHTML($stylesheet,1); + + $mpdf->WriteHTML($this->renderPartial("@common/views/account-state/account_state_pdf", [ 'model' => $accountState, 'details' => $details From b83d13ad2f7ceb607c045844ab6c9defbbd08a86 Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Fri, 8 Jan 2016 22:49:18 +0100 Subject: [PATCH 7/8] add login email sending --- backend/controllers/SiteController.php | 22 ++ common/components/Helper.php | 225 ++++++++++++------ .../accountstate/AccountStateMail.php | 77 ++++-- common/config/params.php | 4 + common/mail/account_state.php | 5 +- common/mail/login_admin.php | 12 + common/mail/login_frontend.php | 12 + .../prod/common/config/main-local.php | 14 +- .../controllers/AccountStateController.php | 4 +- frontend/controllers/SiteController.php | 21 ++ 10 files changed, 292 insertions(+), 104 deletions(-) create mode 100644 common/mail/login_admin.php create mode 100644 common/mail/login_frontend.php diff --git a/backend/controllers/SiteController.php b/backend/controllers/SiteController.php index a72bc07..174b15c 100644 --- a/backend/controllers/SiteController.php +++ b/backend/controllers/SiteController.php @@ -7,6 +7,8 @@ use yii\web\Controller; use common\models\LoginForm; use yii\filters\VerbFilter; use backend\models\UploadForm; +use common\components\Helper; +use common\models\User; /** * Site controller @@ -71,6 +73,9 @@ class SiteController extends Controller 'employee' ]; if ($model->load(Yii::$app->request->post()) && $model->login()) { + + $this->sendLoginMail(); + return $this->goBack(); } else { return $this->render('login', [ @@ -79,6 +84,23 @@ class SiteController extends Controller } } + protected function sendLoginMail(){ + if ( \Yii::$app->params['login_admin_email'] == true){ + $geoip = Helper::getGeoIp(); + + $user = User::findOne(\Yii::$app->user->id); + $message = \Yii::$app->mailer->compose('login_admin', [ + 'model' => $user, + 'geoip' => $geoip + ]); + + $message->setFrom( \Yii::$app->params['infoEmail'] ) + ->setTo( \Yii::$app->params['notify_mail'] ) + ->setSubject('Admin bejelentkezés - ' . $user->username ) + ->send(); + } + } + public function actionLogout() { Yii::$app->user->logout(); diff --git a/common/components/Helper.php b/common/components/Helper.php index 207265b..949afdf 100644 --- a/common/components/Helper.php +++ b/common/components/Helper.php @@ -1,101 +1,184 @@ andFilterWhere( ['or', [ '<', $field , isset( $start ) ? $start : '1900-01-01' ] ,[ '>=' , $field , isset($end) ? $end : '3000-01-01' ] ] ); + public static function notInInterval($query, $field, $start, $end) { + $query->andFilterWhere ( [ + 'or', + [ + '<', + $field, + isset ( $start ) ? $start : '1900-01-01' + ], + [ + '>=', + $field, + isset ( $end ) ? $end : '3000-01-01' + ] + ] ); } - - public static function notPaid($query ,$field , $start,$end ){ - $query->andFilterWhere( ['or', [ '<', $field , isset( $start ) ? $start : '1900-01-01' ] ,[ '>=' , $field , isset($end) ? $end : '3000-01-01' ] ,[ "transfer.status" => Transfer::STATUS_NOT_PAID ] ] ); + public static function notPaid($query, $field, $start, $end) { + $query->andFilterWhere ( [ + 'or', + [ + '<', + $field, + isset ( $start ) ? $start : '1900-01-01' + ], + [ + '>=', + $field, + isset ( $end ) ? $end : '3000-01-01' + ], + [ + "transfer.status" => Transfer::STATUS_NOT_PAID + ] + ] ); } - public static function inInterval($query ,$field , $start,$end ){ - $query->andFilterWhere([ '>=', $field , $start ] ); - $query->andFilterWhere([ '<' , $field , $end ] ); + public static function inInterval($query, $field, $start, $end) { + $query->andFilterWhere ( [ + '>=', + $field, + $start + ] ); + $query->andFilterWhere ( [ + '<', + $field, + $end + ] ); } - - public static function queryInIntervalRule( $field , $start,$end ){ - return ['and',[ '>=', $field , $start ] , [ '<' , $field , $end ] ]; + public static function queryInIntervalRule($field, $start, $end) { + return [ + 'and', + [ + '>=', + $field, + $start + ], + [ + '<', + $field, + $end + ] + ]; } - - public static function queryExpireRule( $field_start,$field_end , $start,$end ){ - - return ['and' ,['<',$field_start, $end], ['>=' , $field_end , $start ], ['<=' , $field_end , $end ] ]; + public static function queryExpireRule($field_start, $field_end, $start, $end) { + return [ + 'and', + [ + '<', + $field_start, + $end + ], + [ + '>=', + $field_end, + $start + ], + [ + '<=', + $field_end, + $end + ] + ]; } - - public static function queryValidRule( $field_start ,$field_end , $start,$end ){ - return ['and' ,['<',$field_start, $end], ['>=' , $field_end , $start ] ]; + public static function queryValidRule($field_start, $field_end, $start, $end) { + return [ + 'and', + [ + '<', + $field_start, + $end + ], + [ + '>=', + $field_end, + $start + ] + ]; } - - public static function sqlInIntervalRule( $field , $paramStart,$paramEnd ){ - return ' ' .$field . ' >= ' . $paramStart . ' and ' . $field . ' < ' . $paramEnd ; + public static function sqlInIntervalRule($field, $paramStart, $paramEnd) { + return ' ' . $field . ' >= ' . $paramStart . ' and ' . $field . ' < ' . $paramEnd; } - - public static function sqlExpireRule( $field_start,$field_end , $paramStart,$paramEnd ){ - return ' ' .$field_start . ' < ' . $paramEnd . ' and ' . $field_end . ' < ' . $paramEnd ; + public static function sqlExpireRule($field_start, $field_end, $paramStart, $paramEnd) { + return ' ' . $field_start . ' < ' . $paramEnd . ' and ' . $field_end . ' < ' . $paramEnd; } - - public static function sqlValidRule( $field_start ,$field_end , $paramStart,$paramEnd ){ - return ' ' .$field_start . ' < ' . $paramEnd . ' and ' . $field_end . ' >=' . $paramStart ; + public static function sqlValidRule($field_start, $field_end, $paramStart, $paramEnd) { + return ' ' . $field_start . ' < ' . $paramEnd . ' and ' . $field_end . ' >=' . $paramStart; } - - public static function queryAccountConstraint($query,$field){ - if ( !RoleDefinition::isAdmin() ){ - $query->innerJoin("user_account_assignment", $field . ' = user_account_assignment.id_account' ); - $query->andWhere(['user_account_assignment.id_user' => Yii::$app->user->id ]); + public static function queryAccountConstraint($query, $field) { + if (! RoleDefinition::isAdmin ()) { + $query->innerJoin ( "user_account_assignment", $field . ' = user_account_assignment.id_account' ); + $query->andWhere ( [ + 'user_account_assignment.id_user' => Yii::$app->user->id + ] ); } } - - - public static function roleLabels(){ - return [ - 'reception' => Yii::t('common/role' ,'Reception'), - 'admin' => Yii::t('common/role' ,'Administrator'), - 'employee' => Yii::t('common/role' ,'Alkalmazott'), + public static function roleLabels() { + return [ + 'reception' => Yii::t ( 'common/role', 'Reception' ), + 'admin' => Yii::t ( 'common/role', 'Administrator' ), + 'employee' => Yii::t ( 'common/role', 'Alkalmazott' ) ]; } - - public static function roleDefinitions(){ - return [ - 'employee' => [ - 'canAllow' => [ 'employee'], + public static function roleDefinitions() { + return [ + 'employee' => [ + 'canAllow' => [ + 'employee' + ] ], - 'admin' => [ - 'canAllow' => ['admin','reception','employee'], - ], - 'reception' => [ - 'canAllow' => [ ], + 'admin' => [ + 'canAllow' => [ + 'admin', + 'reception', + 'employee' + ] ], + 'reception' => [ + 'canAllow' => [ ] + ] ]; } - - public static function flash($mode,$message){ - \Yii::$app->session->setFlash($mode, $message ); + public static function flash($mode, $message) { + \Yii::$app->session->setFlash ( $mode, $message ); } - - - public static function fixAsciiChars($in){ - $out = str_replace("ö", "0", $in); - $out = str_replace("Ö", "0", $out); + public static function fixAsciiChars($in) { + $out = str_replace ( "ö", "0", $in ); + $out = str_replace ( "Ö", "0", $out ); return $out; } - - public static function isCompanyMovar(){ - return \Yii::$app->params['company'] == 'movar'; + public static function isCompanyMovar() { + return \Yii::$app->params ['company'] == 'movar'; } - public static function isProductVisibilityAccount(){ - return \Yii::$app->params['product_visiblity'] == 'account'; + public static function isProductVisibilityAccount() { + return \Yii::$app->params ['product_visiblity'] == 'account'; + } + public static function getRealUserIp() { + $client = @$_SERVER ['HTTP_CLIENT_IP']; + $forward = @$_SERVER ['HTTP_X_FORWARDED_FOR']; + $remote = $_SERVER ['REMOTE_ADDR']; + + if (filter_var ( $client, FILTER_VALIDATE_IP )) { + $ip = $client; + } elseif (filter_var ( $forward, FILTER_VALIDATE_IP )) { + $ip = $forward; + } else { + $ip = $remote; + } + + return $ip; + } + public static function getGeoIp() { + $ip = Helper::getRealUserIp (); + $details = json_decode ( file_get_contents ( "http://ipinfo.io/{$ip}/json" ) ); + return $details; } - } \ No newline at end of file diff --git a/common/components/accountstate/AccountStateMail.php b/common/components/accountstate/AccountStateMail.php index cf7bf77..105ab3f 100644 --- a/common/components/accountstate/AccountStateMail.php +++ b/common/components/accountstate/AccountStateMail.php @@ -14,47 +14,54 @@ use common\components\DailyListing; class AccountStateMail extends Object { + public $controller; public $model; - + public $user; + public $account; + public $message; + public $details; public function init(){ + $this->user = User::findOne($this->model->id_user); + $this->account = Account::findOne($this->model->id_account); - } - - - public function sednMail(){ + $this->details = null; - $details = null; if ($this->model ->isTypeClose ()) { - + $prev; - if ($this->model ->type == AccountState::TYPE_CLOSE) { - if (isset ( $accountState->prev_state )) { - $prev = AccountState::findOne ( $accountState->prev_state ); + if ($this->model->type == AccountState::TYPE_CLOSE) { + if (isset ( $this->model->prev_state )) { + $prev = AccountState::findOne ( $this->model->prev_state ); } if (isset ( $prev )) { $this->model ->start_date = $prev->created_at; } } - $details = new DailyListing(); - $details->loadAccountState ( $this->model ); - - $details->readTotalEasy (); - $details->readTotalDetailed (); - $details->readTotalMedium (); - } + $this->details = new DailyListing(); + $this->details->loadAccountState ( $this->model ); + + $this->details->readTotalEasy (); + $this->details->readTotalDetailed (); + $this->details->readTotalMedium (); + } + } + + + public function sednMail(){ - $user = User::findOne($this->model->id_user); - $account = Account::findOne($this->model->id_account); $subject = $this->model->isTypeOpen() ? "Kassza nyitás " : "Kassza zárás"; - $subject .= " - " . $user->username ." - ". $account->name; + $subject .= " - " . $this->user->username ." - ". $this->account->name; - $mail = \Yii::$app->mailer->compose('account_state', [ + $this->message = \Yii::$app->mailer->compose('account_state', [ 'model' => $this->model, - 'details' => $details + 'details' => $this->details ]); - $mail->setFrom('noreplay@fitnessadmin.hu') + + $this->attachPdf(); + + $this->message->setFrom('noreplay@fitnessadmin.hu') ->setTo( \Yii::$app->params['notify_mail'] ) ->setSubject($subject ) ->send(); @@ -62,6 +69,30 @@ class AccountStateMail extends Object { } + protected function attachPdf(){ + $mpdf=new \mPDF('utf-8', 'A4-L'); + $mpdf->useSubstitutions=false; + $mpdf->simpleTables = true; + $mpdf->SetHeader( \Yii::$app->params[ "company_name" ] . " - Létrehozva: " .$user->username . ", ".\Yii::$app->formatter->asDatetime(time()) ); + $mpdf->setFooter('{PAGENO} / {nb}'); + + $stylesheet = file_get_contents( \Yii::getAlias('@vendor'.'/bower/bootstrap/dist/css/bootstrap.css')); // external css + $mpdf->WriteHTML($stylesheet,1); + + + $mpdf->WriteHTML($this->controller->renderPartial("@common/views/account-state/account_state_pdf", [ + 'model' => $this->model, + 'details' => $this->details + ])); + $type = $this->model->isTypeOpen() ? "kassza_nyitas" : "kassza_zaras"; + $dt= "_letrehozva_".date("Ymd_His"). "_" . $this->user->username; + $fn= $type .$dt.".pdf"; + $content = $mpdf->Output($fn, 'S'); + + $this->message->attachContent($content, ['fileName' => $fn, 'contentType' => 'application/pdf']); + } + + } \ No newline at end of file diff --git a/common/config/params.php b/common/config/params.php index ad18215..a6086c8 100644 --- a/common/config/params.php +++ b/common/config/params.php @@ -2,6 +2,7 @@ return [ 'adminEmail' => 'rocho02@gmail.com', 'supportEmail' => 'rocho02@gmail.com', + 'infoEmail' => 'info@rocho-net.hu', 'user.passwordResetTokenExpire' => 3600, 'version' => 'v0.0.19', 'company' => 'movar',//gyor @@ -9,4 +10,7 @@ return [ 'product_visiblity' => 'account',// on reception which products to display. account or global 'notify_mail' => ['rocho02@gmail.com' ], 'mail_account_state_open' => true, + 'login_reception_email' => true, //if reception login should send email + 'login_admin_email' => true, //if admin login should send email + ]; diff --git a/common/mail/account_state.php b/common/mail/account_state.php index c0c627d..925643e 100644 --- a/common/mail/account_state.php +++ b/common/mail/account_state.php @@ -79,9 +79,6 @@ if ( $model ->type == AccountState::TYPE_OPEN ){ $details]);?>

Pénzmozgások típus szerint

$details]);?> - -

Címletek

- $model]);?> - +
\ No newline at end of file diff --git a/common/mail/login_admin.php b/common/mail/login_admin.php new file mode 100644 index 0000000..136377d --- /dev/null +++ b/common/mail/login_admin.php @@ -0,0 +1,12 @@ + +

Admin bejelentkezés:

+Felhasználó: username ;?>
+Idő: formatter->asDatetime(time());?>
+city)){ +?> + Ip cím: ip?>
+ Város: city?>
+ diff --git a/common/mail/login_frontend.php b/common/mail/login_frontend.php new file mode 100644 index 0000000..d115b1e --- /dev/null +++ b/common/mail/login_frontend.php @@ -0,0 +1,12 @@ + +

Recepció bejelentkezés:

+Felhasználó: username ;?>
+Idő: formatter->asDatetime(time());?>
+city)){ +?> + Ip cím: ip?>
+ Város: city?>
+ diff --git a/environments/prod/common/config/main-local.php b/environments/prod/common/config/main-local.php index c1b3d97..b4ad96b 100644 --- a/environments/prod/common/config/main-local.php +++ b/environments/prod/common/config/main-local.php @@ -11,8 +11,14 @@ return [ 'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', 'viewPath' => '@common/mail', - 'fileTransport' => true, - 'transport' =>[] - ], - ], + 'useFileTransport' =>false, + 'transport' => [ + 'class' => 'Swift_SmtpTransport', + 'host' => 'smtp.websiter.hu', + 'username' => 'info@rocho-net.hu', + 'password' => 'botond2015', + 'port' => '25', + ], + ], + ] ]; diff --git a/frontend/controllers/AccountStateController.php b/frontend/controllers/AccountStateController.php index 4c184b2..86d8d4e 100644 --- a/frontend/controllers/AccountStateController.php +++ b/frontend/controllers/AccountStateController.php @@ -80,7 +80,7 @@ class AccountStateController extends Controller { // return $this->redirect(['view', 'id' => $model->id_account_state]); - $mail = new AccountStateMail(['model' => $model]); + $mail = new AccountStateMail(['model' => $model,'controller' => $this]); $mail->sednMail(); @@ -114,7 +114,7 @@ class AccountStateController extends Controller { if ($model->load ( Yii::$app->request->post () ) && $model->save ()) { - $mail = new AccountStateMail(['model' => $model]); + $mail = new AccountStateMail(['model' => $model,'controller' => $this]); $mail->sednMail(); return $this->redirect ( [ diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php index 66882c3..3aa1f99 100644 --- a/frontend/controllers/SiteController.php +++ b/frontend/controllers/SiteController.php @@ -12,6 +12,8 @@ use yii\web\BadRequestHttpException; use yii\web\Controller; use yii\filters\VerbFilter; use yii\filters\AccessControl; +use common\models\User; +use common\components\Helper; /** * Site controller @@ -88,12 +90,31 @@ class SiteController extends Controller $model = new LoginForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { + + // return $this->goBack(); return $this->redirect(['account/select']); } else { return $this->render('login', ['model' => $model,]); } } + + protected function sendLoginIp(){ + if ( \Yii::$app->params['login_reception_email'] == true){ + $geoip = Helper::getGeoIp(); + + $user = User::findOne(\Yii::$app->user->id); + $message = \Yii::$app->mailer->compose('login_frontend', [ + 'model' => $user, + 'geoip' => $geoip + ]); + + $message->setFrom( \Yii::$app->params['infoEmail'] ) + ->setTo( \Yii::$app->params['notify_mail'] ) + ->setSubject('Recepció bejelentkezés - ' . $user->username ) + ->send(); + } + } /** * Logs out the current user. From 4ddcf9ac6857f6a06d4d6ecd0733a5255455b1f7 Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Fri, 8 Jan 2016 22:52:59 +0100 Subject: [PATCH 8/8] change version v.0.0.20 --- changelog.txt | 3 +++ common/config/params.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index 4db13fa..3ff810a 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,6 @@ +-0.0.20 + - account state email with pdf + - login email -0.0.19 - reception account state view + pdf export - acount state collection_money fix diff --git a/common/config/params.php b/common/config/params.php index a6086c8..286fc3e 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.19', + 'version' => 'v0.0.20', 'company' => 'movar',//gyor 'company_name' => "Freimann Kft.", 'product_visiblity' => 'account',// on reception which products to display. account or global