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) ){
- 'btn btn-primary']); ?> + 'btn btn-primary']); ?>
diff --git a/frontend/views/customer/_form_create.php b/frontend/views/customer/_form_create.php index 036d453..22c0fc3 100644 --- a/frontend/views/customer/_form_create.php +++ b/frontend/views/customer/_form_create.php @@ -23,7 +23,7 @@ use kartik\widgets\DatePicker; field($model, 'cardNumber')->widget(CardNumberTypeahead::className(),[]) ?>
- field($model, 'partnerCardNumber')->textInput() ?> + field($model, 'partnerCardNumber')->textInput() ?>
@@ -40,7 +40,7 @@ use kartik\widgets\DatePicker; - +
field($model, 'password_plain')->passwordInput(['maxlength' => true]) ?> @@ -49,7 +49,7 @@ use kartik\widgets\DatePicker; field($model, 'password_repeat')->passwordInput(['maxlength' => true]) ?>
- +
field($model, 'sex')->dropDownList(Customer::sexes()) ?> diff --git a/frontend/views/customer/_form_update.php b/frontend/views/customer/_form_update.php index 0823749..cebebf1 100644 --- a/frontend/views/customer/_form_update.php +++ b/frontend/views/customer/_form_update.php @@ -22,13 +22,13 @@ use yii\base\Widget;
field($model, 'cardNumber')->widget(CardNumberTypeahead::className(),[]) ?> - +
customerCardNumber ?>
- field($model, 'partnerCardNumber')->textInput() ?> + field($model, 'partnerCardNumber')->textInput() ?>
@@ -55,19 +55,6 @@ use yii\base\Widget; 'format' => 'yyyy.mm.dd' ] ]) ?> - 'CustomerUpdate[birthdate]', - 'value' => Yii::$app->formatter->asDate($model->birthdate), - 'pluginOptions' => [ - 'autoclose'=>true, - 'format' => 'yyyy.mm.dd' - ] - ] - ); - */ - ?>
diff --git a/frontend/views/customer/create.php b/frontend/views/customer/create.php index 360d9dc..0588016 100644 --- a/frontend/views/customer/create.php +++ b/frontend/views/customer/create.php @@ -8,19 +8,13 @@ use frontend\components\ReceptionCardNumberWidget; /* @var $this yii\web\View */ /* @var $model common\models\Customer */ - - $this->title = Yii::t('common/customer', 'Create Customer'); $this->params['breadcrumbs'][] = ['label' => Yii::t('common/customer', 'Customers'), 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; - $customer = $model; $card = $customer->card; - - - ?>
diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index 993db33..fd2f627 100644 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -35,14 +35,14 @@ AppAsset::register($this); echo AlertBlock::widget([ 'useSessionFlash' => true, 'type' => AlertBlock::TYPE_GROWL, - 'delay' => '3000' + 'delay' => '1' ]); $menuStruct = new FrontendMenuStructure(); $items = $menuStruct->run(); NavBar::begin([ - 'brandLabel' => 'My Company', + 'brandLabel' => 'Web Recepció', 'brandUrl' => Yii::$app->homeUrl, 'options' => [ 'class' => 'navbar-inverse navbar-fixed-top', diff --git a/frontend/views/ticket/_form.php b/frontend/views/ticket/_form.php index 8997e12..83892b2 100644 --- a/frontend/views/ticket/_form.php +++ b/frontend/views/ticket/_form.php @@ -31,11 +31,13 @@ use kartik\widgets\DatePicker; + + field($model, 'id_ticket_type')->dropDownList($ticketTypeOptions) ?> field($model, 'id_account')->dropDownList($accountOptions) ?> - field($model, 'id_discount')->dropDownList($discountOptions) ?> + field($model, 'id_discount')->dropDownList($discountOptions) ?> field($model, 'start')->widget(DatePicker::classname(), [ 'pluginOptions' => [ @@ -59,7 +61,8 @@ use kartik\widgets\DatePicker; field($model, 'comment')->textarea(['maxlength' => true]) ?>
- isNewRecord ? Yii::t('common/ticket', 'Create') : Yii::t('common/ticket', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> + ' $(\'#ticketcreate-cart\').val(\'\');','class' => 'btn btn-success' ]) ?> + ' $(\'#ticketcreate-cart\').val(\'add\');', 'class' => 'btn btn-success' ]) ?>
diff --git a/frontend/views/ticket/create.php b/frontend/views/ticket/create.php index 56d435d..5739af6 100644 --- a/frontend/views/ticket/create.php +++ b/frontend/views/ticket/create.php @@ -5,25 +5,27 @@ use frontend\components\ReceptionMenuWidget; use frontend\components\ReceptionCardNumberWidget; use frontend\assets\TicketSellAsset; use common\models\TicketType; +use yii\helpers\Url; /* @var $this yii\web\View */ /* @var $model common\models\Ticket */ /* @var $receptionForm frotned\models\ReceptionForm */ +$card = $receptionForm->card; +$customer = $receptionForm->customer; + TicketSellAsset::register($this); $this->title = Yii::t('common/ticket', 'Create Ticket'); -$this->params['breadcrumbs'][] = ['label' => Yii::t('common/ticket', 'Tickets'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => Yii::t('common/ticket', 'Tickets'), 'url' => ['index' , 'number' => $card->number ]]; $this->params['breadcrumbs'][] = $this->title; -$card = $receptionForm->card; -$customer = $receptionForm->customer; $options = []; // $options['lookup_product_url'] = Url::toRoute(['product/lookup']); -// $options['clear_list_url'] = Url::toRoute(['product/clear-list']); +$options['clear_cart_url'] = Url::toRoute(['product/clear-list']); $options['types'] = TicketType::modelsToArray($ticketTypes); $options['transfer_list'] = $userTransfers; @@ -55,8 +57,9 @@ $this->registerJs ( 'new TicketSell( '. json_encode($options).');' ); ]) ?>
-

+

render( "//common/_transfer_list" ) ?> + 'btn_paid', 'class' => 'btn btn-primary' ]) ?>
diff --git a/frontend/web/js/ticket.sell.js b/frontend/web/js/ticket.sell.js index 0bc6cfa..2c342b7 100644 --- a/frontend/web/js/ticket.sell.js +++ b/frontend/web/js/ticket.sell.js @@ -33,8 +33,10 @@ function TicketSell(o){ max_usage_count: null, id_account: null, price: null, - clear_list_url: '', - transfer_list: [] + clear_cart_url: '', + cart_paid_message: 'Tételek fizetve', + transfer_list: [], + }; init(); @@ -44,6 +46,7 @@ function TicketSell(o){ addBehaviourTypeChangedListener(); useDefaults(); createUserSoldItemsTable(); + addBehaviourBtnCartPaid(); } function useDefaults(){ @@ -59,10 +62,30 @@ function TicketSell(o){ }); } - function refreshSoldUseritems(){ + function refreshCart(){ $('.transfer-list-container').transferList('option','transfers' , app.defaults.sold_items ); } + function addBehaviourBtnCartPaid( ){ + $('#btn_paid').on('click',function(){ + + $.ajax({ + url: app.defaults.clear_cart_url, + type: 'post', + data: {}, + success: function (response) { + if ( response.code == 'success'){ + app.defaults.sold_items= response.transfers; + refreshCart(); + $.notify(app.defaults.cart_paid_message, { 'type' : 'success' }); + } + } + } + ); + }); + } + + function addBehaviourTypeChangedListener(){ $(app.defaults.selector_type).change(change); }