diff --git a/common/models/User.php b/common/models/User.php index e29d28c..5a29c27 100644 --- a/common/models/User.php +++ b/common/models/User.php @@ -20,6 +20,7 @@ use common\components\RoleDefinition; * @property integer $status * @property integer $created_at * @property integer $updated_at + * @property integer $key_listener_enabled * @property string $password write-only password */ class User extends ActiveRecord implements IdentityInterface diff --git a/console/migrations/m230626_205132_alter_table_user_add_column_key_listener_enabled.php b/console/migrations/m230626_205132_alter_table_user_add_column_key_listener_enabled.php new file mode 100644 index 0000000..e04ef90 --- /dev/null +++ b/console/migrations/m230626_205132_alter_table_user_add_column_key_listener_enabled.php @@ -0,0 +1,46 @@ +addColumn( + "user", + "key_listener_enabled", + $this->integer()->null()->defaultValue(1) + ); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + echo "m230626_205132_alter_table_user_add_column_key_listener_enabled cannot be reverted.\n"; + + return false; + } + + /* + // Use up()/down() to run migration code without a transaction. + public function up() + { + + } + + public function down() + { + echo "m230626_205132_alter_table_user_add_column_key_listener_enabled cannot be reverted.\n"; + + return false; + } + */ +} diff --git a/frontend/components/ReceptionWidget.php b/frontend/components/ReceptionWidget.php index f83e227..b93bdc5 100644 --- a/frontend/components/ReceptionWidget.php +++ b/frontend/components/ReceptionWidget.php @@ -1,27 +1,36 @@ user = User::findOne(\Yii::$app->user->id); + } - - + + public function run(){ - echo $this->render($this->viewFile,[ 'model' => $this->form ]); + + echo $this->render($this->viewFile,[ 'model' => $this->form, + "user_key_listener_enabled" => $this->user->key_listener_enabled ]); } - - + + } \ No newline at end of file diff --git a/frontend/controllers/CustomerController.php b/frontend/controllers/CustomerController.php index ad774c2..8709a0b 100644 --- a/frontend/controllers/CustomerController.php +++ b/frontend/controllers/CustomerController.php @@ -3,6 +3,7 @@ namespace frontend\controllers; use backend\models\CustomerActivateForm; +use common\models\User; use frontend\models\SingleCustomerActivateForm; use common\components\Helper; use frontend\components\HtmlHelper; @@ -83,6 +84,10 @@ class CustomerController extends Controller $model->mkDoorLog(); } + if ( \Yii::$app->request->isPost){ + User::updateAll(['key_listener_enabled' =>1 ],['id' => \Yii::$app->user->id]); +// return $this->redirect([ 'customer/reception']); + } if ( $model->isFreeCard() ){ return $this->redirect([ 'create', 'number' => $model->card->number ]); diff --git a/frontend/controllers/TicketController.php b/frontend/controllers/TicketController.php index 2adec5d..c848bc5 100644 --- a/frontend/controllers/TicketController.php +++ b/frontend/controllers/TicketController.php @@ -66,12 +66,12 @@ class TicketController extends FrontendController public function actionIndex($number = null) { $receptionForm = $this->mkReceptionForm($number); - - + + if ( !isset($receptionForm->card ) ){ throw new NotFoundHttpException( Yii::t('frontend/ticket', 'The requested card does not exist.')); } - + $searchModel = new TicketSearch(); $dataProvider = $searchModel->search( $receptionForm->card, Yii::$app->request->queryParams); @@ -91,47 +91,52 @@ class TicketController extends FrontendController */ public function actionCreate($number = null) { - + $receptionForm =$this->mkReceptionForm($number); - + if ( !isset($receptionForm->card ) ){ throw new NotFoundHttpException( Yii::t('frontend/ticket', 'The requested card does not exist.')); } - + if ( isset($_POST['payout_customer_cart']) && $this->payoutCustomerCart($receptionForm) ){ return $this->redirect(['customer/reception' ]); }else if ( isset($_POST['payout_user_cart']) && $this->payoutUserCart($receptionForm)){ return $this->redirect(['customer/reception' ]); } - - + + $model = new TicketCreate(); $discounts = Discount::readTicketDiscounts(); - + $ticketTypes = TicketType::read(null, null); - + $accounts = Account::read(); - + $user = User::findOne( [ 'id' => Yii::$app->user->id ] ); - + + $user->key_listener_enabled = 0; + $user->save(); + $model->customer = $receptionForm->customer; $model->id_user = \Yii::$app->user->id; - - + + $model->usage_count = 0; - $model->id_card = $receptionForm->card->id_card; + $model->id_card = $receptionForm->card->id_card; $model->id_account = Account::readDefault(); - + 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(['product/sale', 'number' => $receptionForm->card->number]); - } - + } + $model->userCart = Transfer::modelsToArray( Transfer::readUserSoldTransfers($user) ); $model->customerCart = Transfer::modelsToArray( Transfer::readCustomerCart( $receptionForm->customer ) ); - + + + return $this->render('create', [ 'model' => $model, 'discounts' => $discounts, @@ -150,17 +155,17 @@ class TicketController extends FrontendController /** @var \frontend\models\TicketUpdate $model */ $model = TicketUpdate::findOne($id); - + if ( !isset($model)){ throw new NotFoundHttpException('The requested page does not exist.'); } - + if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index', 'number' => $model->card->number]); } - + return $this->render('update',['model' => $model]); - + } /** @@ -191,7 +196,7 @@ class TicketController extends FrontendController $transfer->storno(); $transaction->commit(); \Yii::$app->session->setFlash( 'success','Bérlet törölve' ); - + // $transaction->commit(); // if ( $transfer->delete() ){ // \Yii::$app->session->setFlash( 'success','Bérlet törölve' ); @@ -199,16 +204,16 @@ class TicketController extends FrontendController // }else{ // throw new \Exception("Failed to save"); // } - + } catch(Exception $e) { $transaction->rollback(); \Yii::$app->session->setFlash( 'danger','Bérlet törlése nem sikerült' ); } - - + + return $this->redirect(Yii::$app->request->referrer); } - + /** * Finds the Ticket model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. @@ -224,5 +229,5 @@ class TicketController extends FrontendController throw new NotFoundHttpException('The requested page does not exist.'); } } - + } diff --git a/frontend/models/TicketCreate.php b/frontend/models/TicketCreate.php index 0251bc1..fc505a8 100644 --- a/frontend/models/TicketCreate.php +++ b/frontend/models/TicketCreate.php @@ -28,17 +28,17 @@ class TicketCreate extends Ticket{ public $_discount; public $_transfer; public $_ticketType; - - + + public $customer; public $userCart; public $customerCart; - - + + public $cart; - + public $payment_method; - + public function rules() { return [ @@ -75,7 +75,7 @@ class TicketCreate extends Ticket{ [[ 'max_usage_count'], 'required'], [[ 'max_usage_count'], 'integer'], ///////////////////// - //price + //price ///////////////////// [[ 'price_brutto'], 'required'], [[ 'price_brutto'], 'integer'], @@ -87,11 +87,11 @@ class TicketCreate extends Ticket{ //cart ///////////////////// [['cart'], 'string', 'max' => 10] - + ]; } - - + + public function validateTicketType($attribute){ $type = TicketType::findOne($this->id_ticket_type); $this->_ticketType = $type; @@ -114,40 +114,40 @@ class TicketCreate extends Ticket{ $query->andWhere( [ '>', 'expired_at' , Helper::getDateTimeString() ]); $query->andWhere( [ 'not in', 'flag', [Contract::$FLAG_DELETED ] ]); $contracts = $query->all(); - + if ( count($contracts) > 0 ){ $this->addError($attribute,"A vendégnek már van érvényes vagy felbontott szerződése!"); } - + } } } - + public function validateAccount($attribute){ $this->_account = Account::findOne($this->id_account); if ( !isset($this->_account )) { $this->addError($attribute,\Yii::t('frontend/ticket' , 'Invalid transfer' )); } } - + public function validateDiscount($attribute){ $this->_discount = Discount::findOne($this->id_discount); if ( !isset($this->_discount)) { $this->addError($attribute,\Yii::t('frontend/ticket' , 'Invalid discount' )); } } - + public function beforeSave($insert){ $result = parent::beforeSave($insert); if ( $result ){ if ($insert){ - + if ( $this->isAppendToCustomerCart() || $this->isAppendToUserCart()){ $this->status = Ticket::STATUS_INACTIVE; }else{ $this->status = Ticket::STATUS_ACTIVE; } - + $ticketType = TicketType::findOne($this->id_ticket_type); if ( isset($ticketType) && $ticketType->isInstallment() ){ $this->part = 0; @@ -157,12 +157,17 @@ class TicketCreate extends Ticket{ $this->part_count = 0; } - if ( isset($ticketType )){ - $this->original_price = $ticketType->price_brutto; + if (isset($ticketType)) { + $this->original_price = $ticketType->price_brutto; $start = DateUtil::parseDate($this->start); - $original_end = Helper::getTicketExpirationDate($start,$ticketType); - $this->original_end = DateUtil::formatDateUtc($original_end); - $this->max_reservation_count = $ticketType->max_reservation_count; + $original_end = Helper::getTicketExpirationDate($start, $ticketType); + $this->original_end = DateUtil::formatDateUtc($original_end); + $this->max_reservation_count = $ticketType->max_reservation_count; + + if (!Helper::isTicketCreatePriceEditable()) { + $this->price_brutto = $ticketType->price_brutto; + } + } } } @@ -180,18 +185,18 @@ class TicketCreate extends Ticket{ $this->appendToCustomerCart(); $this->addContract($insert); $this->updateCardFlag(); - + } - + protected function updateCardFlag(){ Card::updateCardFlagTicket($this->id_card); } - + public function addContract($insert){ if ($insert){ $ticketType = TicketType::findOne($this->id_ticket_type); if ( isset($ticketType) && $ticketType->isInstallment() ){ - + $contract = new Contract(); $contract->id_customer = $this->customer->id_customer; $contract->id_user = \Yii::$app->user->id; @@ -204,7 +209,7 @@ class TicketCreate extends Ticket{ $contract->id_ticket_type = $this->id_ticket_type; $contract->id_discount = $this->id_discount; $contract->save(); - + $requests = TicketInstallmentRequest::createInstallments($this, $ticketType, $this->customer,$contract); foreach ($requests as $request){ $request->save(false); @@ -219,24 +224,27 @@ class TicketCreate extends Ticket{ protected function addTransfer(){ //$transfer = Transfer::createTicketTransfer($this->_account, $this->_discount, null, 1, $this); - + $transfer = new Transfer(); - + $transfer->type = Transfer::TYPE_TICKET; $transfer->direction = Transfer::DIRECTION_IN; - + $transfer->id_object = $this->id_ticket; - + $transfer->item_price = $this->_ticketType->price_brutto; $transfer->count = 1; - + if (isset ( $this->_discount )) { $transfer->id_discount = $this->_discount->id_discount; } - - - $transfer->money = $this->price_brutto; - + + if ( Helper::isTicketCreatePriceEditable() ){ + $transfer->money = $this->price_brutto; + } else { + $transfer->money = $transfer->item_price; + } + $transfer->id_account = $this->_account->id_account; if ( !Transfer::canMarkPaidByReception( $this->payment_method ) ){ @@ -252,7 +260,7 @@ class TicketCreate extends Ticket{ } $transfer->status = $status; $transfer->payment_method = $this->payment_method; - + if ( isset($this->comment)){ $transfer->comment = $this->comment; } @@ -264,7 +272,7 @@ class TicketCreate extends Ticket{ } $this->_transfer = $transfer; } - + public function isAppendToUserCart(){ $result = false; if ( isset( $this->cart ) && $this->cart == 'user' ){ @@ -272,7 +280,7 @@ class TicketCreate extends Ticket{ } return $result; } - + public function isAppendToCustomerCart(){ $result = false; if ( isset( $this->cart ) && $this->cart == 'customer' ){ @@ -310,11 +318,11 @@ class TicketCreate extends Ticket{ \Yii::error("Nem sikerült menteni a bérletet! Vendég kosár hozzárendelés sikertelen!"); throw new \Exception("Nem sikerült menteni a bérletet! Vendég kosár hozzárendelés sikertelen!"); } - + } } } - - - + + + } \ No newline at end of file diff --git a/frontend/views/common/_reception.php b/frontend/views/common/_reception.php index db8c510..ff6fde9 100644 --- a/frontend/views/common/_reception.php +++ b/frontend/views/common/_reception.php @@ -1,4 +1,4 @@ - -isCassaClose() ){ @@ -22,10 +23,13 @@ use yii\helpers\Html; $cassaMessage = "Nincs kassza kiválasztva"; } ?> +