diff --git a/backend/components/AdminMenuStructure.php b/backend/components/AdminMenuStructure.php index 1a3bb1e..9fd2042 100644 --- a/backend/components/AdminMenuStructure.php +++ b/backend/components/AdminMenuStructure.php @@ -76,6 +76,7 @@ class AdminMenuStructure{ $items[] = ['label' => 'Vendégek', 'url' => ['/customer/index'] , 'target_url' => ['/customer/index' ,'/customer/view','/ticket/index-customer'] ]; $items[] = ['label' => 'Bérletkártyák', 'url' => ['/card/index'] ]; $items[] = ['label' => 'Bérletek', 'url' => ['/ticket/index' , 'TicketSearch[start]' =>$today,'TicketSearch[end]' => $tomorrow ] ]; + $items[] = ['label' => 'Statisztika', 'url' => ['/ticket/statistics' , 'TicketSearchStatisitcs[start]' =>$today,'TicketSearchStatisitcs[end]' => $tomorrow ] ]; $this->menuItems[] = ['label' => 'Bérletek/Vendégek', 'url' => $this->emptyUrl, 'items' => $items ]; @@ -98,7 +99,7 @@ class AdminMenuStructure{ // $items[] = ['label' => 'Bevétel', 'url' => ['/transfer/summary' , 'TransferSummarySearch[start]' =>$today,'TransferSummarySearch[end]' => $tomorrow ] ]; $items[] = ['label' => 'Napi bevételek', 'url' => ['/transfer/list', 'TransferListSearch[start]' =>$todayDatetime,'TransferListSearch[end]' => $tomorrowDatetime ] ]; $items[] = ['label' => 'Kassza müveletek', 'url' => ['/account-state/index'] ]; - $items[] = ['label' => 'Zárások', 'url' => ['/collection/index' , 'CollectionSearch[start]' =>$todayDatetime,'CollectionSearch[end]' => $tomorrowDatetime ] ]; + //$items[] = ['label' => 'Zárások', 'url' => ['/collection/index' , 'CollectionSearch[start]' =>$todayDatetime,'CollectionSearch[end]' => $tomorrowDatetime ] ]; $this->menuItems[] = ['label' => 'Pénzügy', 'url' => $this->emptyUrl, 'items' => $items ]; diff --git a/backend/controllers/TicketController.php b/backend/controllers/TicketController.php index 68793a6..8adc0e6 100644 --- a/backend/controllers/TicketController.php +++ b/backend/controllers/TicketController.php @@ -14,173 +14,227 @@ use common\models\Account; use common\models\User; use common\models\Customer; use common\models\Card; +use backend\models\TicketSearchStatisitcs; /** * TicketController implements the CRUD actions for Ticket model. */ -class TicketController extends \backend\controllers\BackendController -{ - - - public function behaviors() - { - return [ - 'access' => [ - 'class' => \yii\filters\AccessControl::className(), - 'rules' => [ - // allow authenticated users - [ - 'actions' => ['create','index','view','update','index-customer'], - 'allow' => true, - 'roles' => ['admin','employee','reception'], - ], +class TicketController extends \backend\controllers\BackendController { + public function behaviors() { + return [ + 'access' => [ + 'class' => \yii\filters\AccessControl::className (), + 'rules' => [ + // allow authenticated users + [ + 'actions' => [ + 'create', + 'index', + 'view', + 'update', + 'index-customer', + 'statistics' + ], + 'allow' => true, + 'roles' => [ + 'admin', + 'employee', + 'reception' + ] + ] + ] // everything else is denied - ], - ], + + ] ]; } - /** - * Lists all Ticket models. - * @return mixed - */ - public function actionIndex() - { - $searchModel = new TicketSearch(); - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - $searchModel->searchTotals(); - - $searchModel->users = User::read(); - $searchModel->accounts = Account::read(); - $searchModel->ticketTypes = TicketType::read(); - - - - return $this->render('index', [ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, - ]); - } - - - /** - * Lists all Ticket models. - * @return mixed - */ - public function actionIndexCustomer($id) - { - - $customer = Customer::findOne($id); - $card = Card::findOne($id); - - - if ( $customer == null ){ - throw new NotFoundHttpException('The requested page does not exist.'); - } - - $searchModel = new TicketSearch(); - $searchModel->id_card = $customer->id_customer_card; - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - $searchModel->searchTotals(); - - $searchModel->users = User::read(); - $searchModel->accounts = Account::read(); - $searchModel->ticketTypes = TicketType::read(); - - - - return $this->render('index_customer', [ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, - 'customer' => $customer, - 'card' => $card - ]); - } - - - /** - * Displays a single Ticket model. - * @param integer $id - * @return mixed - */ - public function actionView($id) - { - return $this->render('view', [ - 'model' => $this->findModel($id), - ]); - } - - /** - * Creates a new Ticket model. - * If creation is successful, the browser will be redirected to the 'view' page. - * @return mixed - */ - public function actionCreate() - { - $model = new Ticket(); - - $discounts = Discount::read(); - $ticketTypes = TicketType::read(); - $accounts = Account::readAccounts(); - - - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->id_ticket]); - } else { - return $this->render('create', [ - 'model' => $model, - 'discounts' => $discounts, - 'ticketTypes' => $ticketTypes, - 'accounts' => $accounts, - ]); - } - } - - /** - * Updates an existing Ticket 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_ticket]); - } else { - return $this->render('update', [ - 'model' => $model, - ]); - } - } - - /** - * Deletes an existing Ticket 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 Ticket model based on its primary key value. - * If the model is not found, a 404 HTTP exception will be thrown. - * @param integer $id - * @return Ticket the loaded model - * @throws NotFoundHttpException if the model cannot be found - */ - protected function findModel($id) - { - if (($model = Ticket::findOne($id)) !== null) { - return $model; - } else { - throw new NotFoundHttpException('The requested page does not exist.'); - } - } + /** + * Lists all Ticket models. + * + * @return mixed + */ + public function actionIndex() { + $searchModel = new TicketSearch (); + $dataProvider = $searchModel->search ( Yii::$app->request->queryParams ); + $searchModel->searchTotals (); + + $searchModel->users = User::read (); + $searchModel->accounts = Account::read (); + $searchModel->ticketTypes = TicketType::read (); + + return $this->render ( 'index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider + ] ); + } + + /** + * Lists all Ticket models. + * + * @return mixed + */ + public function actionStatistics() { + $searchModel = new TicketSearchStatisitcs(); + $searchModel->search ( Yii::$app->request->queryParams ); + $searchModel->searchTotals (); + + $searchModel->users = User::read (); + $searchModel->accounts = Account::read (); + $searchModel->ticketTypes = TicketType::read (); + + if ($searchModel->output == 'pdf') { + $user = User::findOne ( \Yii::$app->user->id ); + $mpdf = new \mPDF ( 'utf-8', 'A4-L' ); + $fn = ""; + $ov = '_total_content_pdf'; + $dt = "_letrehozva_" . date ( "Ymd_His" ) . "_" . $user->username; + $interval = ""; + $account = ""; + $currentUser = ""; + $fn = $fn . $interval . $dt . $account . $currentUser . ".pdf"; + + $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->renderPartial ( 'statistics_pdf', [ + 'searchModel' => $searchModel + ] ) ); + $mpdf->Output ( $fn, 'D' ); + exit (); + } else { + + return $this->render ( 'statistics', [ + 'searchModel' => $searchModel + ] ); + } + } + + /** + * Lists all Ticket models. + * + * @return mixed + */ + public function actionIndexCustomer($id) { + $customer = Customer::findOne ( $id ); + $card = Card::findOne ( $id ); + + if ($customer == null) { + throw new NotFoundHttpException ( 'The requested page does not exist.' ); + } + + $searchModel = new TicketSearch (); + $searchModel->id_card = $customer->id_customer_card; + $dataProvider = $searchModel->search ( Yii::$app->request->queryParams ); + $searchModel->searchTotals (); + + $searchModel->users = User::read (); + $searchModel->accounts = Account::read (); + $searchModel->ticketTypes = TicketType::read (); + + return $this->render ( 'index_customer', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'customer' => $customer, + 'card' => $card + ] ); + } + + /** + * Displays a single Ticket model. + * + * @param integer $id + * @return mixed + */ + public function actionView($id) { + return $this->render ( 'view', [ + 'model' => $this->findModel ( $id ) + ] ); + } + + /** + * Creates a new Ticket model. + * If creation is successful, the browser will be redirected to the 'view' page. + * + * @return mixed + */ + public function actionCreate() { + $model = new Ticket (); + + $discounts = Discount::read (); + $ticketTypes = TicketType::read (); + $accounts = Account::readAccounts (); + + if ($model->load ( Yii::$app->request->post () ) && $model->save ()) { + return $this->redirect ( [ + 'view', + 'id' => $model->id_ticket + ] ); + } else { + return $this->render ( 'create', [ + 'model' => $model, + 'discounts' => $discounts, + 'ticketTypes' => $ticketTypes, + 'accounts' => $accounts + ] ); + } + } + + /** + * Updates an existing Ticket 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_ticket + ] ); + } else { + return $this->render ( 'update', [ + 'model' => $model + ] ); + } + } + + /** + * Deletes an existing Ticket 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 Ticket model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * @return Ticket the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) { + if (($model = Ticket::findOne ( $id )) !== null) { + return $model; + } else { + throw new NotFoundHttpException ( 'The requested page does not exist.' ); + } + } } diff --git a/backend/models/TicketSearchStatisitcs.php b/backend/models/TicketSearchStatisitcs.php new file mode 100644 index 0000000..c8ccbd7 --- /dev/null +++ b/backend/models/TicketSearchStatisitcs.php @@ -0,0 +1,162 @@ + 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ], + [[ 'end' , ], 'date' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ], + [['valid_in_interval','created_in_interval','expire_in_interval'],'boolean'] , + + ]; + } + + /** + * @inheritdoc + */ + public function scenarios() + { + // bypass scenarios() implementation in the parent class + return Model::scenarios(); + } + + public function attributeLabels(){ + return ArrayHelper::merge(parent::attributeLabels(), [ + 'start' => Yii::t('backend/ticket','Start of interval'), + 'end' => Yii::t('backend/ticket','End of interval'), + 'valid_in_interval' => Yii::t('backend/ticket','Valid in interval'), + 'created_in_interval' => Yii::t('backend/ticket','Created in interval'), + 'expire_in_interval' => Yii::t('backend/ticket','Expire in interval'), + ]); + } + + public function afterValidate(){ + + if ( !isset($this->timestampStart)) { + $this->timestampStart ='1900-01-01'; + } + + if ( !isset($this->timestampEnd)) { + $this->timestampEnd ='3000-01-01'; + } + + } + + /** + * Creates data provider instance with search query applied + * + * @param array $params + * + * @return ActiveDataProvider + */ + public function search($params) + { + $this->load($params); + $this->validate(); + + + } + + + + public function searchTotals(){ + $query = Ticket::mkStatisticQuery($this->timestampStart, $this->timestampEnd,$this->id_card); + $this->statistics = $query->all(); + + $this->statisticsTotal =[ + 'valid' => 0, + 'created' => 0, + 'created_at_money' => 0, + 'expired' => 0, + ]; + + $this->statisticsTotal['valid'] = array_sum(array_column($this->statistics, 'valid')); + $this->statisticsTotal['created'] = array_sum(array_column($this->statistics, 'created')); + $this->statisticsTotal['created_money'] = array_sum(array_column($this->statistics, 'created_money')); + $this->statisticsTotal['expired'] = array_sum(array_column($this->statistics, 'expired')); + } + + + public static function mkSearchCondition( $timestampStart, $timestampEnd, $id_user,$id_ticket_tpye,$id_account,$valid_in_interval ,$expire_in_interval,$created_in_interval ){ + $query = Ticket::find(); + + Helper::queryAccountConstraint($query, 'ticket.id_account'); + + $query->with('ticketType' ); + $query->with('user'); + $query->with('customer'); + + $query->andFilterWhere([ + 'id_user' => $id_user, + 'id_ticket_type' => $id_ticket_type, + 'id_account' => $id_account, + ]); + + $all = (!($valid_in_interval) && !($expire_in_interval) && !($created_in_interval) ) + || + ($valid_in_interval == true && $expire_in_interval == true && $created_in_interval); + + $dateConditions = []; + $start = $timestampStart; + $end = $timestampEnd; + + if( $all || $created_in_interval ){ + $dateConditions[] = Helper::queryInIntervalRule('ticket.created_at', $start, $end); + } + + if ( $all || $valid_in_interval ){ + $dateConditions[] = Helper::queryValidRule('ticket.start', 'ticket.end', $start, $end); + } + + if ( $all || $expire_in_interval ){ + $dateConditions[] = Helper::queryExpireRule('ticket.start', 'ticket.end', $start, $end); + } + + if ( count($dateConditions) == 1 ){ + $query->andWhere($dateConditions[0]); + }else if ( count($dateConditions) > 1 ){ + $cond = ['or']; + foreach ($dateConditions as $c){ + $cond[] = $c; + } + $query->andWhere($cond); + } + } + +} diff --git a/backend/models/TransferSearch.php b/backend/models/TransferSearch.php index 671ac5b..7c75095 100644 --- a/backend/models/TransferSearch.php +++ b/backend/models/TransferSearch.php @@ -87,7 +87,7 @@ class TransferSearch extends Transfer ]); - $query->addSelect( ['*' ]); +// $query->addSelect( ['*' ]); $this->load($params); @@ -103,6 +103,8 @@ class TransferSearch extends Transfer 'transfer.id_user' => $this->id_user, ]); + $query->andFilterWhere(['in' ,'transfer.type', $this->types]); + $created_condition = ['and',[ '>=', 'transfer.created_at', $this->timestampStart ] ,[ '<', 'transfer.created_at', $this->timestampEnd ] ]; $paid_condition = ['and',[ '>=', 'transfer.paid_at', $this->timestampStart ] ,[ '<', 'transfer.paid_at', $this->timestampEnd ] ]; diff --git a/backend/views/ticket/_search_statistics.php b/backend/views/ticket/_search_statistics.php new file mode 100644 index 0000000..791f2d6 --- /dev/null +++ b/backend/views/ticket/_search_statistics.php @@ -0,0 +1,65 @@ + + + 'Mind'] + ArrayHelper::map($model->ticketTypes, 'id_ticket_type', 'name'); +$accountOptions = ['' => 'Mind'] + ArrayHelper::map($model->accounts, 'id_account', 'name'); +$userOptions = ['' => 'Mind'] + ArrayHelper::map($model->users, 'id', 'username'); + +?> + + diff --git a/backend/views/ticket/statistics.php b/backend/views/ticket/statistics.php new file mode 100644 index 0000000..487683f --- /dev/null +++ b/backend/views/ticket/statistics.php @@ -0,0 +1,88 @@ +title = Yii::t('common/ticket', 'Statisztika'); +$this->params['breadcrumbs'][] = $this->title; + + + +?> + +
+ +

title) ?>

+ render('_search_statistics', ['model' => $searchModel]); ?> + + + +
+
Bérlet statisztika
+
+

Bérlet statisztika a kiválasztott időszakra

+ + output) ){ + + $pdfUrl = Url::current([ Html::getInputName($searchModel, 'output') => 'pdf']); + echo Html::a("PDF letöltése", $pdfUrl,['class' => 'btn btn-primary btn-all' ]); + } + + +?> + new ArrayDataProvider([ + 'allModels' => $searchModel->statistics, + 'sort' => false, + 'pagination' => false, + ]), + 'showFooter'=>TRUE, + 'footerRowOptions'=>['style'=>'font-weight:bold; '], + 'columns' =>[ + [ + 'attribute' => 'name', + 'label' => 'Bérlet', + 'footer' => 'Összesen' + ], + [ + 'attribute' => 'created', + 'label' => 'Kiadva (Db)', + 'footer' => $searchModel->statisticsTotal['created'] + ], + [ + 'attribute' => 'created_money', + 'label' => 'Kiadott érték (Ft)', + 'footer' => $searchModel->statisticsTotal['created_money'] + ], + [ + 'attribute' => 'valid', + 'label' => 'Érvényes (Db)', + 'footer' => $searchModel->statisticsTotal['valid'] + + ], + [ + 'attribute' => 'expired', + 'label' => 'Lejár az adott időszakban (Db)', + 'footer' => $searchModel->statisticsTotal['expired'] + ] + + ] + ]); + + ?> +
+
+ + +
diff --git a/backend/views/ticket/statistics_pdf.php b/backend/views/ticket/statistics_pdf.php new file mode 100644 index 0000000..fa488e3 --- /dev/null +++ b/backend/views/ticket/statistics_pdf.php @@ -0,0 +1,89 @@ + + + + +
+ +

Bérlet statisztika a kiválasztott időszakra

+ + new ArrayDataProvider ( [ + 'allModels' => $searchModel->statistics, + 'sort' => false, + 'pagination' => false + ] ), + 'showFooter' => TRUE, + 'footerRowOptions' => [ + 'style' => 'font-weight:bold; ' + ], + 'columns' => [ + [ + 'attribute' => 'name', + 'label' => 'Bérlet', + 'footer' => 'Összesen' , + 'contentOptions' => [ 'class' => 'ticket-name'] + ], + [ + 'attribute' => 'created', + 'label' => 'Kiadva (Db)', + 'footer' => $searchModel->statisticsTotal ['created'] , + 'contentOptions' => [ 'class' => 'number'] + ], + [ + 'attribute' => 'created_money', + 'label' => 'Kiadott érték (Ft)', + 'footer' => $searchModel->statisticsTotal ['created_money'], + 'contentOptions' => [ 'class' => 'number'] + ], + [ + 'attribute' => 'valid', + 'label' => 'Érvényes (Db)', + 'footer' => $searchModel->statisticsTotal ['valid'], + 'contentOptions' => [ 'class' => 'number'] + ] + , + [ + 'attribute' => 'expired', + 'label' => 'Lejár az adott időszakban (Db)', + 'footer' => $searchModel->statisticsTotal ['expired'] , + 'contentOptions' => [ 'class' => 'number'] + ] + ] + + ] ); + + ?> +
diff --git a/backend/views/transfer/view.php b/backend/views/transfer/view.php index d2f58e3..6b1ac83 100644 --- a/backend/views/transfer/view.php +++ b/backend/views/transfer/view.php @@ -36,6 +36,14 @@ $this->params['breadcrumbs'][] = $this->title; 'attribute' => 'id_user', 'value' => $model->userName, ], + [ + 'attribute' => 'id_discount', + 'value' => $model->discountName, + ], + [ + 'attribute' => 'payment_method', + 'value' => $model->paymentMethodName, + ], 'item_price', 'count', 'money', diff --git a/common/models/Ticket.php b/common/models/Ticket.php index 52357e9..3986101 100644 --- a/common/models/Ticket.php +++ b/common/models/Ticket.php @@ -75,6 +75,7 @@ class Ticket extends \common\models\BaseFitnessActiveRecord 'updated_at' => Yii::t('common/ticket', 'Updated At'), 'id_card' => Yii::t('backend/ticket','Card'), 'id_customer' => Yii::t('backend/ticket','Customer'), + 'payment_method' => Yii::t('common/transfer', 'Fizetési mód'), ]; } diff --git a/common/models/Transfer.php b/common/models/Transfer.php index e575a44..2e79258 100644 --- a/common/models/Transfer.php +++ b/common/models/Transfer.php @@ -50,6 +50,8 @@ class Transfer extends \common\models\BaseFitnessActiveRecord const DIRECTION_OUT = 10;// MONEY GOES OUT FROM ACCOUNT ( COMPANY LOST MONEY ) const DIRECTION_IN = 20;//MONEY GOES IN TO THE ACCOUNT ( COMPANY EARN MONEY ) + const PAYMENT_METHOD_CASH = 10; + const PAYMENT_METHOD_TRANSFER = 20; /** * @inheritdoc @@ -118,6 +120,7 @@ class Transfer extends \common\models\BaseFitnessActiveRecord 'types' => Yii::t('common/transfer', 'Types'), 'start' => Yii::t('common/transfer', 'Start'), 'end' => Yii::t('common/transfer', 'End'), + 'payment_method' => Yii::t('common/transfer', 'Fizetési mód'), ]; } @@ -457,6 +460,12 @@ class Transfer extends \common\models\BaseFitnessActiveRecord self::TYPE_TICKET => Yii::t('common/transfer','Ticket'), ]; } + public static function paymentMethods( ) { + return [ + self::PAYMENT_METHOD_CASH=> Yii::t('common/transfer','Készpénz'), + self::PAYMENT_METHOD_TRANSFER => Yii::t('common/transfer','Bankkártyás fizetés'), + ]; + } public static function statuses( ) { return [ self::STATUS_NOT_PAID => Yii::t('common/transfer','Nincs fizetve'), @@ -471,6 +480,14 @@ class Transfer extends \common\models\BaseFitnessActiveRecord } return $status; } + public function getPaymentMethodName( ) { + $status = null; + $statuses = self::paymentMethods(); + if ( array_key_exists($this->payment_method, $statuses)){ + $status = $statuses[$this->payment_method]; + } + return $status; + } public function beforeDelete(){ parent::beforeDelete(); @@ -721,6 +738,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]); + $query->andWhere(['transfer.payment_method' => Transfer::PAYMENT_METHOD_CASH]); return $query->scalar(); } diff --git a/common/models/TransferListSearch.php b/common/models/TransferListSearch.php index 3bae835..e399eee 100644 --- a/common/models/TransferListSearch.php +++ b/common/models/TransferListSearch.php @@ -254,6 +254,9 @@ 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]); + } } @@ -379,6 +382,7 @@ class TransferListSearch extends Transfer $query->select(['coalesce(sum(transfer.count * GREATEST(( product.sale_price - coalesce(product.purchase_price,0)),0)),0) AS product_money' ]); $query->from('transfer'); $query->andWhere(['transfer.type' => Transfer::TYPE_PRODUCT]); + $query->andWhere(['transfer.payment_method' => Transfer::PAYMENT_METHOD_CASH]); $query->innerJoin("sale", "sale.id_sale = transfer.id_object"); $query->innerJoin("product", "sale.id_product = product.id_product"); $this->addQueryFilters($query); diff --git a/console/migrations/m160117_122835_alter_table_transfer_add_column_payment_method.php b/console/migrations/m160117_122835_alter_table_transfer_add_column_payment_method.php new file mode 100644 index 0000000..892aa0e --- /dev/null +++ b/console/migrations/m160117_122835_alter_table_transfer_add_column_payment_method.php @@ -0,0 +1,30 @@ +addColumn("transfer", "payment_method", "int"); + $this->execute("update transfer set payment_method = 10"); + } + + public function down() + { + + return true; + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ +} diff --git a/frontend/models/ProductSaleForm.php b/frontend/models/ProductSaleForm.php index d5a8005..f52601f 100644 --- a/frontend/models/ProductSaleForm.php +++ b/frontend/models/ProductSaleForm.php @@ -78,14 +78,16 @@ class ProductSaleForm extends Model public $products; + public $payment_method; + /** * @inheritdoc */ public function rules() { return [ - [['id_product','count','id_account'], 'required'], - [['id_product','id_currency','id_account', 'id_discount','count'], 'integer'], + [['id_product','count','id_account','payment_method'], 'required'], + [['id_product','id_currency','id_account', 'id_discount','count','payment_method'], 'integer'], [['comment'], 'string' ,'max' => 255], [['cart'], 'string' ,'max' => 20], [['id_product' ], 'validateProduct'], @@ -108,6 +110,7 @@ class ProductSaleForm extends Model 'id_account' => Yii::t("frontend/product", "Account"), 'id_discount' => Yii::t("frontend/product", "Discount"), 'comment' => Yii::t("frontend/product", "Comment"), + 'payment_method' => Yii::t('common/transfer', 'Fizetési mód'), ]; } @@ -199,6 +202,7 @@ class ProductSaleForm extends Model } $this->transfer = Transfer::createProductTransfer($this->sale,$this->account, $this->discount, $this->currency, $this->count, $this->product,$status,$customer); + $this->transfer->payment_method = $this->payment_method; if ( isset($this->comment)){ $this->transfer->comment = $this->comment; } diff --git a/frontend/models/TicketCreate.php b/frontend/models/TicketCreate.php index 8345d90..fac7c47 100644 --- a/frontend/models/TicketCreate.php +++ b/frontend/models/TicketCreate.php @@ -32,6 +32,8 @@ class TicketCreate extends Ticket{ public $cart; + public $payment_method; + public function rules() { return [ @@ -48,6 +50,11 @@ class TicketCreate extends Ticket{ [[ 'id_account'], 'integer'], [[ 'id_account'], 'validateAccount'], ///////////////////// + //payment_method + ///////////////////// + [[ 'payment_method'], 'required'], + [[ 'payment_method'], 'integer'], + ///////////////////// //id_discount ///////////////////// [[ 'id_discount'], 'integer'], @@ -123,7 +130,7 @@ class TicketCreate extends Ticket{ $transfer->paid_by = \Yii::$app->user->id; } $transfer->status = $status; - + $transfer->payment_method = $this->payment_method; if ( isset($this->comment)){ $transfer->comment = $this->comment; diff --git a/frontend/views/product/_sale_form.php b/frontend/views/product/_sale_form.php index 0baa923..4c4a046 100644 --- a/frontend/views/product/_sale_form.php +++ b/frontend/views/product/_sale_form.php @@ -2,6 +2,7 @@ use yii\helpers\Html; use yii\bootstrap\ActiveForm; use yii\helpers\ArrayHelper; +use common\models\Transfer; /* @var $this yii\web\View */ /* @var $model frontend\models\ProductSaleForm */ @@ -94,6 +95,11 @@ $discountOptions = mkOptions( ArrayHelper::map($discounts, 'id_discount', 'name' field($model,'id_discount')->dropDownList($discountOptions) ?> +
+
+ field($model,'payment_method')->dropDownList(Transfer::paymentMethods()) ?> +
+
field( $model,'comment' )->textarea() ?> diff --git a/frontend/views/ticket/_form.php b/frontend/views/ticket/_form.php index 04ec43c..7ff151f 100644 --- a/frontend/views/ticket/_form.php +++ b/frontend/views/ticket/_form.php @@ -5,6 +5,7 @@ use yii\widgets\ActiveForm; use frontend\components\HtmlHelper; use kartik\widgets\DatePicker; use common\models\Account; +use common\models\Transfer; /* @var $this yii\web\View */ /* @var $model common\models\Ticket */ @@ -43,7 +44,9 @@ use common\models\Account; field($model, 'id_account')->dropDownList($accountOptions) ?> - field($model, 'id_discount')->dropDownList($discountOptions) ?> + field($model,'payment_method')->dropDownList(Transfer::paymentMethods()) ?> + + field($model, 'id_discount')->dropDownList($discountOptions) ?> field($model, 'start')->widget(DatePicker::classname(), [ 'pluginOptions' => [ diff --git a/frontend/views/ticket/create.php b/frontend/views/ticket/create.php index d5ff2e2..d500230 100644 --- a/frontend/views/ticket/create.php +++ b/frontend/views/ticket/create.php @@ -40,6 +40,15 @@ if ( isset($receptionForm->card) ){ $options['customer_cart'] = $model->customerCart; } +$discountItems = []; +foreach ($discounts as $d){ + $item = []; + $item['id_discount'] = $d->id_discount; + $item['value'] = $d->value; + $discountItems[] = $item; +} +$options['discounts'] = $discountItems; + $this->registerJs ( 'new TicketSell( '. json_encode($options).');' ); ?>
diff --git a/frontend/views/transfer/_view.php b/frontend/views/transfer/_view.php index 6417d0c..f04328b 100644 --- a/frontend/views/transfer/_view.php +++ b/frontend/views/transfer/_view.php @@ -31,6 +31,9 @@ $formatter = Yii::$app->formatter;
getAttributeLabel( 'status') ?>
+ +
getAttributeLabel( 'payment_method') ?>
+
diff --git a/frontend/web/js/product.sell.js b/frontend/web/js/product.sell.js index cfe746a..ab66928 100644 --- a/frontend/web/js/product.sell.js +++ b/frontend/web/js/product.sell.js @@ -541,7 +541,7 @@ function ProductSell(o){ function normalizePrice( price ){ var result; // result = hufRound(price); - return result; + return price; } function hufRound(x) diff --git a/frontend/web/js/ticket.sell.js b/frontend/web/js/ticket.sell.js index 79fecab..6d6903a 100644 --- a/frontend/web/js/ticket.sell.js +++ b/frontend/web/js/ticket.sell.js @@ -21,6 +21,7 @@ function TicketSell(o){ }, ], selector_type: '#ticketcreate-id_ticket_type', + selector_discount: '#ticketcreate-id_discount', selector_start: '#ticketcreate-start', selector_end: '#ticketcreate-end', selector_account: '#ticketcreate-id_account', @@ -47,6 +48,8 @@ function TicketSell(o){ url_pay_user_cart: '', url_delete_transaction: '', url_pay_transaction: '', + discounts : [], + discount: null, }; @@ -55,6 +58,7 @@ function TicketSell(o){ function init(){ $.extend(app.defaults, o ); addBehaviourTypeChangedListener(); + addBehaviourDiscountChangedListener(); useDefaults(); createCarts(); addPayoutButtons(); @@ -187,6 +191,9 @@ function TicketSell(o){ function addBehaviourTypeChangedListener(){ $(app.defaults.selector_type).change(change); } + function addBehaviourDiscountChangedListener(){ + $(app.defaults.selector_discount).change(typeChanged); + } function change(event){ if ( '#'+event.target.id == app.defaults.selector_type ){ @@ -204,6 +211,7 @@ function TicketSell(o){ validateStartDate(); validateEndDate(); validateMaxUsageCount(); + validateDiscount(); validatePriceBrutto(); validateAccount(); } @@ -221,6 +229,22 @@ function TicketSell(o){ } } + function validateDiscount(){ + var discount; + discount = +$(app.defaults.selector_discount).val(); + app.defaults.discount = null; + console.info( app.defaults.discounts ); + for ( var i = 0; i < app.defaults.discounts.length; i++ ){ + if ( app.defaults.discounts[i].id_discount == discount){ + app.defaults.discount = app.defaults.discounts[i]; + break; + } + + } + console.info( 'discount found:'); + console.info( app.defaults.discount ); + } + function validateStartDate(){ app.defaults.start_date = moment( $( app.defaults.selector_start ).val(), app.defaults.date_format_moment) ; @@ -258,6 +282,11 @@ function TicketSell(o){ function validatePriceBrutto(){ app.defaults.price = app.defaults.ticket_type.price_brutto; + if ( app.defaults.discount != null ){ + var d = app.defaults.price * app.defaults.discount['value'] /100; + d = Math.floor( d ); + app.defaults.price = app.defaults.price - d; + } } function validateAccount(){ app.defaults.id_account = $('#ticketcreate-id_account').val();