diff --git a/common/config/i18n.php b/common/config/i18n.php index 1366edf..54f5c84 100644 --- a/common/config/i18n.php +++ b/common/config/i18n.php @@ -43,6 +43,7 @@ return [ '.hgignore', '.hgkeep', '/messages', + 'node_modules' ], // 'php' output format is for saving messages to php files. diff --git a/common/messages/hu/common/customer.php b/common/messages/hu/common/customer.php index 0885b09..f478dfb 100644 --- a/common/messages/hu/common/customer.php +++ b/common/messages/hu/common/customer.php @@ -19,7 +19,7 @@ return [ 'Bérlet kártya nem üres vagy hibás kártyaszám' => 'Bérlet kártya nem üres vagy hibás kártyaszám', 'Password' => 'Jelszó', - 'Update customer:' => 'Jelszó újra', + 'Update customer:' => 'Vendég módosítása:', 'Address' => 'Cím', 'Birthdate' => 'Születésnap', 'Card number' => 'Kártyaszám', diff --git a/common/messages/hu/common/ticket.php b/common/messages/hu/common/ticket.php new file mode 100644 index 0000000..fd7c80a --- /dev/null +++ b/common/messages/hu/common/ticket.php @@ -0,0 +1,44 @@ + 'Biztosan törölni szeretné a bérletet?', + 'Comment' => 'Megjegyzés', + 'Create' => 'Mentés', + 'Create Ticket' => 'Új bérlet', + 'Create and add to cart' => 'Mentés és kosárba helyezés', + 'Created At' => 'Hozzáadva', + 'Delete' => 'Törlés', + 'End' => 'Érvényesség vége', + 'Id Account' => 'Kassza', + 'Id Discount' => 'Kedvezmény', + 'Id Ticket' => 'Bérlet', + 'Id Ticket Type' => 'Bérlet típus', + 'Id User' => 'Felhasználó', + 'Max Usage Count' => 'Max alkalmak', + 'Price Brutto' => 'Bruttó ár', + 'Reset' => '', + 'Search' => 'Keresés', + 'Start' => 'Érvényesség kezdete', + 'Status' => 'Státusz', + 'Tickets' => 'Bérletek', + 'Update' => 'Módosítás', + 'Update {modelClass}: ' => '{modelClass} módosítva: ', + 'Updated At' => 'Módosítás', + 'Usage Count' => 'Felhasznált alkalmak', +]; diff --git a/common/messages/hu/frontend/card.php b/common/messages/hu/frontend/card.php new file mode 100644 index 0000000..2c0a972 --- /dev/null +++ b/common/messages/hu/frontend/card.php @@ -0,0 +1,21 @@ + 'Keresés', +]; diff --git a/common/messages/hu/frontend/ticket.php b/common/messages/hu/frontend/ticket.php new file mode 100644 index 0000000..6dc2eec --- /dev/null +++ b/common/messages/hu/frontend/ticket.php @@ -0,0 +1,27 @@ + 'Kosár', + 'Invalid discount' => 'Érvénytelen kedvezmény', + 'Invalid ticket type' => 'Érvénytelen bérlet típus', + 'Invalid transfer' => 'Érvénytelen transfer', + 'The requested card does not exist.' => 'A megadott bérlet kártya nem található', + 'Ticket added to customer' => 'Bérlet hozzárendelve vendéghez', + 'Update ticket' => 'Bérlet módosítása', +]; diff --git a/common/messages/hu/frontend/transfer.php b/common/messages/hu/frontend/transfer.php index d5286ac..90f460b 100644 --- a/common/messages/hu/frontend/transfer.php +++ b/common/messages/hu/frontend/transfer.php @@ -17,11 +17,12 @@ * NOTE: this file must be saved in UTF-8 encoding. */ return [ - 'Are you sure you want to delete this item?' => '', + 'Are you sure you want to delete this item?' => 'Biztosan törölni szeretné a bérletet?', + 'Reset' => '', + 'Ticket' => 'Bérlet', 'Create' => 'Mentés', 'Create Transfer' => 'Új pénzmozgás', 'Delete' => 'Törlés', - 'Reset' => '', 'Search' => 'Keresés', 'Termékeladás' => 'Termékeladás', 'Transfers' => 'Pénzmozgások', diff --git a/common/models/Customer.php b/common/models/Customer.php index 70522e9..2e7862a 100644 --- a/common/models/Customer.php +++ b/common/models/Customer.php @@ -92,6 +92,7 @@ class Customer extends \yii\db\ActiveRecord 'created_at' => Yii::t('common/customer', 'Created At'), 'updated_at' => Yii::t('common/customer', 'Updated At'), 'customerCardNumber' => Yii::t('common/customer', 'Card number'), + 'cardNumber' => Yii::t('common/customer', 'Card number'), ]; } diff --git a/common/models/Transfer.php b/common/models/Transfer.php index 74a37a4..295409e 100644 --- a/common/models/Transfer.php +++ b/common/models/Transfer.php @@ -82,9 +82,12 @@ class Transfer extends \yii\db\ActiveRecord public function getProduct(){ return $this->hasOne( Product::className(), ["id_product" =>"id_object" ] ); } + public function getTicket(){ + return $this->hasOne( Ticket::className(), ["id_ticket" =>"id_object" ] ); + } public function getAccount(){ - return $this->hasOne( Account::className(), ["id_account" =>"id_account" ] ); + return $this->hasOne( Account::className(), ["id_account" =>"id_account" ] ) ; } public function getCurrency(){ @@ -206,14 +209,18 @@ class Transfer extends \yii\db\ActiveRecord 'product_name' => function ($transfer) { $result = ""; if ( $transfer->type == Transfer::TYPE_TICKET ){ - $result = $transfer->ticket->type->name; + $result = $transfer->ticket->ticketTypeName; }else{ $result = $transfer->product->name; } return $result; }, 'category' => function ($transfer) { - return $transfer->product->productCategoryName; + if ( $transfer->type == Transfer::TYPE_TICKET ){ + return Yii::t('frontend/transfer','Ticket'); + }else{ + return $transfer->product->productCategoryName; + } }, ], ]); @@ -225,8 +232,8 @@ class Transfer extends \yii\db\ActiveRecord $query = Transfer::find(); -// $query->innerJoinWith('userSoldItem'); - $query->andWhere(['transfer.id_user' => $user->id ]); + $query->innerJoinWith('userSoldItem'); + $query->andWhere(['user_sold_item.id_user' => $user->id ]); $transfers = $query->all(); return $transfers; diff --git a/console/migrations/m151008_065256_alter__table__ticket__add_columns.php b/console/migrations/m151008_065256_alter__table__ticket__add_columns.php index bca41ac..89fbee1 100644 --- a/console/migrations/m151008_065256_alter__table__ticket__add_columns.php +++ b/console/migrations/m151008_065256_alter__table__ticket__add_columns.php @@ -16,9 +16,9 @@ class m151008_065256_alter__table__ticket__add_columns extends Migration public function down() { - echo "m151008_065256_alter__table__ticket__add_columns cannot be reverted.\n"; +// echo "m151008_065256_alter__table__ticket__add_columns cannot be reverted.\n"; - return false; +// return false; } /* diff --git a/frontend/components/FrontendMenuStructure.php b/frontend/components/FrontendMenuStructure.php index 058b36e..c6f39dc 100644 --- a/frontend/components/FrontendMenuStructure.php +++ b/frontend/components/FrontendMenuStructure.php @@ -22,11 +22,15 @@ class FrontendMenuStructure{ } + protected function isLogged(){ + return Yii::$app->user->isGuest; + } - - protected function addUserMainMenu(){ - $this->menuItems[] = ['label' => 'Recepcio', 'url' => ['/customer/reception'] ]; + protected function addRecepcio(){ + if ( $this->isLogged() ){ + $this->menuItems[] = ['label' => 'Recepcio', 'url' => ['/customer/reception'] ]; + } } @@ -45,7 +49,7 @@ class FrontendMenuStructure{ public function run(){ - $this->addUserMainMenu(); + $this->addRecepcio(); $this->addLoginMainMenu(); return $this->menuItems; } diff --git a/frontend/controllers/CustomerController.php b/frontend/controllers/CustomerController.php index b28c568..2cf5187 100644 --- a/frontend/controllers/CustomerController.php +++ b/frontend/controllers/CustomerController.php @@ -31,6 +31,19 @@ class CustomerController extends Controller 'delete' => ['post'], ], ], + 'access' => [ + 'class' => \yii\filters\AccessControl::className(), + 'only' => ['create', 'update','reception'], + 'rules' => [ + // allow authenticated users + [ + 'allow' => true, + 'roles' => ['@'], + ], + // everything else is denied + ], + ], + ]; } @@ -51,6 +64,7 @@ class CustomerController extends Controller * Lists all Customer models. * @return mixed */ + /* public function actionIndex() { $searchModel = new CustomerSearch(); @@ -61,19 +75,20 @@ class CustomerController extends Controller 'dataProvider' => $dataProvider, ]); } - +*/ /** * Displays a single Customer model. * @param integer $id * @return mixed */ + /* public function actionView($id) { return $this->render('view', [ 'model' => $this->findModel($id), ]); } - +*/ /** * Creates a new Customer model. * If creation is successful, the browser will be redirected to the 'view' page. @@ -147,13 +162,14 @@ class CustomerController extends Controller * @param integer $id * @return mixed */ + /* public function actionDelete($id) { $this->findModel($id)->delete(); return $this->redirect(['index']); } - +*/ /** * Finds the Customer model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. diff --git a/frontend/controllers/TicketController.php b/frontend/controllers/TicketController.php index 8f95402..0f77ecc 100644 --- a/frontend/controllers/TicketController.php +++ b/frontend/controllers/TicketController.php @@ -107,7 +107,7 @@ class TicketController extends Controller if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->setFlash('success', Yii::t('frontend/ticket', 'Ticket added to customer') ); - return $this->redirect(['index', 'number' => $receptionForm->card->number]); + return $this->redirect(['product/sale', 'number' => $receptionForm->card->number]); } else { $userTransfers = Transfer::modelsToArray( Transfer::readUserSoldTransfers($user) ); diff --git a/frontend/models/TicketCreate.php b/frontend/models/TicketCreate.php index fd7cbbf..97be293 100644 --- a/frontend/models/TicketCreate.php +++ b/frontend/models/TicketCreate.php @@ -6,12 +6,17 @@ use common\models\TicketType; use common\models\Account; use common\models\Discount; use common\models\Transfer; +use common\models\UserSoldItem; +use yii\base\Object; class TicketCreate extends Ticket{ public $_currency; public $_account; public $_discount; + public $_transfer; + + public $cart; public function rules() { @@ -51,7 +56,11 @@ class TicketCreate extends Ticket{ ///////////////////// //comment ///////////////////// - [['comment'], 'string', 'max' => 255] + [['comment'], 'string', 'max' => 255], + ///////////////////// + //cart + ///////////////////// + [['cart'], 'string', 'max' => 10] ]; } @@ -78,10 +87,39 @@ class TicketCreate extends Ticket{ } public function afterSave($insert, $changedAttributes){ + $this->addTransfer(); + $this->addToCart(); + + } + + protected function addTransfer(){ $transfer = Transfer::createTicketTransfer($this->_account, $this->_discount, null, 1, $this); - + $transfer->status = Transfer::STATUS_PAID; + if ( isset($this->comment)){ + $transfer->comment = $this->comment; + } + $transfer->id_user = \Yii::$app->user->id; + $transfer->save(); + $this->_transfer = $transfer; + } + + protected function addToCart(){ + if ( $this->isAddToCart()){ + $item = new UserSoldItem(); + $item->id_transfer = $this->_transfer->id_transfer; + $item->id_user = \Yii::$app->user->id; + $item->save(false); + } } + public function isAddToCart(){ + $result = false; + if ( isset( $this->cart ) && $this->cart == 'add' ){ + $result = true; + } + return $result; + } + } \ No newline at end of file diff --git a/frontend/views/common/_form_card_number.php b/frontend/views/common/_form_card_number.php index 02e05e8..15ffe85 100644 --- a/frontend/views/common/_form_card_number.php +++ b/frontend/views/common/_form_card_number.php @@ -33,7 +33,7 @@ if ( isset($customer) ){