add reception changes

This commit is contained in:
rocho 2015-09-30 15:24:16 +02:00
parent 640d04cb76
commit 7128cd438d
11 changed files with 311 additions and 161 deletions

View File

@ -0,0 +1,86 @@
<?php
namespace frontend\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;
/**
* CardController implements the CRUD actions for Card model.
*/
class CardController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* 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 );
}
}

View File

@ -12,6 +12,7 @@ use yii\filters\VerbFilter;
use yii\base\Object; use yii\base\Object;
use common\models\Card; use common\models\Card;
use frontend\models\CustomerUpdate; use frontend\models\CustomerUpdate;
use frontend\models\CustomerCreate;
/** /**
* CustomerController implements the CRUD actions for Customer model. * CustomerController implements the CRUD actions for Customer model.
@ -78,12 +79,21 @@ class CustomerController extends Controller
* If creation is successful, the browser will be redirected to the 'view' page. * If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed * @return mixed
*/ */
public function actionCreate() public function actionCreate($number = null)
{ {
$model = new Customer(); $model = new CustomerCreate();
$model->country = "Magyarország";
$model->id_user = Yii::$app->user->id;
if ( isset($number)){
$model->cardNumber = $number;
}
if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id_customer]); \Yii::$app->session->setFlash( 'success','Vendég létrehozva!' );
return $this->redirect(['update', 'number' => $model->cardNumber]);
} else { } else {
return $this->render('create', [ return $this->render('create', [
'model' => $model, 'model' => $model,
@ -104,7 +114,7 @@ class CustomerController extends Controller
if ( $number != null ){ if ( $number != null ){
$card = Card::readCard($number); $card = Card::readCard($number);
if ( $card != null ){ if ( $card != null ){
$model = CustomerUpdate::find()->innerJoin(Card::tableName(), "customer.id_customer_card = card.id_card")->one(); $model = CustomerUpdate::find()->innerJoin(Card::tableName(), "customer.id_customer_card = card.id_card")->andWhere( [ 'customer.id_customer_card' => $card->id_card ])->one();
} }
} }
@ -113,9 +123,17 @@ class CustomerController extends Controller
} }
$model->birthdate= isset($model->birthdate ) ? Yii::$app->formatter->asDate($model->birthdate) :'';
if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['update', 'number' => $card->number]);
\Yii::$app->session->setFlash( 'success','Vendég módosításai elmentve' );
return $this->redirect(['update', 'number' => $card->number]);
} else { } else {
return $this->render('update', [ return $this->render('update', [
'model' => $model, 'model' => $model,
]); ]);

View File

@ -68,7 +68,7 @@ class CustomerUpdate extends \common\models\Customer
[['email'], 'email' ], [['email'], 'email' ],
[['email'], 'unique' ], [['email'], 'unique' ],
[['password_plain','password_repeat'], 'string', 'max' => 32], // [['password_plain','password_repeat'], 'string', 'max' => 32],
[['sex'], 'integer'], [['sex'], 'integer'],

View File

@ -2,6 +2,7 @@
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
use yii\helpers\Url;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $card common\models\Card */ /* @var $card common\models\Card */
@ -33,44 +34,47 @@ function mkCustomerBtn($card, $label,$route = null ){
$classes .= ' disabled'; $classes .= ' disabled';
} }
if ( isset($route)){ if ( isset($route)){
$url = [$route, 'number' => $card->number]; $url = [$route, 'number' => ( isset( $card ) ? $card->number : '' )];
} }
return Html::a( $label , $url, ['class' => $classes ] ); return Html::a( $label , $url, ['class' => $classes ] );
} }
function mkBtn($card, $label,$route = null ){
$url = null;
$classes = 'btn btn-primary btn-reception';
if ( isset($route)){
$url = [$route, 'number' => ( isset( $card ) ? $card->number : '' )];
}
return Html::a( $label , $url, ['class' => $classes ] );
}
?> ?>
<div class='row'>
<div class='row'> <div class='col-md-8'>
<div class='col-md-8'> <?php echo mkCustomerBtn( $card, Yii::t( 'frontend/customer' , 'Adatlap') , 'customer/update' ); ?>
<?php echo mkCustomerBtn( $card, Yii::t( 'frontend/customer' , 'Adatlap') , 'customer/update' ); ?> </div>
</div> <div class='col-md-4'>
<div class='col-md-4'> <?php echo Html::a(Html::tag("i","", [ 'class' => 'glyphicon glyphicon-plus' ] ) , Url::toRoute('customer/create') , ['class' => 'btn btn-primary btn-reception'] )?>
<?php echo Html::a(Html::tag("i","", [ 'class' => 'glyphicon glyphicon-plus' ] ) , null, ['class' => 'btn btn-primary btn-reception'] )?> </div>
</div> </div>
</div> <div class='row'>
<div class='row'> <div class='col-md-8'>
<div class='col-md-8'> <?php echo mkCustomerBtn( $card, Yii::t( 'frontend/customer' , 'Befizetések') , 'ticket/index'); ?>
<?php echo mkCustomerBtn( $card, Yii::t( 'frontend/customer' , 'Befizetések') ); ?> </div>
</div> <div class='col-md-4'>
<div class='col-md-4'> <?php echo Html::a(Html::tag("i","", [ 'class' => 'glyphicon glyphicon-plus' ] ) , 'ticket/create' , ['class' => 'btn btn-primary btn-reception'] )?>
<?php echo Html::a(Html::tag("i","", [ 'class' => 'glyphicon glyphicon-plus' ] ) , null, ['class' => 'btn btn-primary btn-reception'] )?> </div>
</div> </div>
</div> <div class='row'>
<div class='row'> <div class='col-md-12'>
<div class='col-md-12'> <?php //echo Html::a(Yii::t( 'frontend/customer', 'Termékeladás') , 'product/index' , ['class' => 'btn btn-primary btn-reception'] )?>
<?php echo Html::a(Yii::t( 'frontend/customer', 'Jelentkezések') , null,['class' => 'btn btn-primary btn-reception'] )?> <?php echo mkBtn($card, Yii::t( 'frontend/customer', 'Termékeladás'), 'product/index')?>
</div> </div>
</div> </div>
<div class='row'>
<div class='col-md-12'>
<?php echo mkCustomerBtn( $card, Yii::t( 'frontend/customer' , 'Egyenleg') ); ?>
</div>
</div>
<div class='row'>
<div class='col-md-12'>
<?php echo Html::a(Yii::t( 'frontend/customer', 'Termékeladás') , null,['class' => 'btn btn-primary btn-reception'] )?>
</div>
</div>

View File

@ -0,0 +1,128 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\models\Customer;
use common\components\CityNameTypeahead;
use common\components\CityZipTypeahead;
use common\components\CardNumberTypeahead;
use kartik\widgets\DatePicker;
/* @var $this yii\web\View */
/* @var $model common\models\Customer */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="customer-form">
<?php $form = ActiveForm::begin(); ?>
<div class='row'>
<div class='col-md-3'>
<?php echo $form->field($model, 'cardNumber')->widget(CardNumberTypeahead::className(),[]) ?>
</div>
<div class='col-md-3'>
<?= $form->field($model, 'partnerCardNumber')->textInput() ?>
</div>
</div>
<div class='row'>
<div class='col-md-6'>
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
</div>
</div>
<div class='row'>
<div class='col-md-6'>
<?= $form->field($model, 'email')->textInput(['maxlength' => true]) ?>
</div>
</div>
<div class='row'>
<div class='col-md-3'>
<?= $form->field($model, 'password_plain')->passwordInput(['maxlength' => true]) ?>
</div>
<div class='col-md-3'>
<?= $form->field($model, 'password_repeat')->passwordInput(['maxlength' => true]) ?>
</div>
</div>
<div class='row'>
<div class='col-md-3'>
<?= $form->field($model, 'sex')->dropDownList(Customer::sexes()) ?>
</div>
<div class='col-md-3'>
<?= $form->field($model, 'birthdate')->widget(DatePicker::classname(), [
'pluginOptions' => [
'autoclose'=>true,
'format' => 'yyyy.mm.dd'
]
]) ?>
</div>
</div>
<div class='row'>
<div class='col-md-3'>
<?= $form->field($model, 'phone')->textInput(['maxlength' => true]) ?>
</div>
<div class='col-md-3'>
<?= $form->field($model, 'date_stundent_card_expire')->widget(DatePicker::classname(), [
'pluginOptions' => [
'autoclose'=>true,
'format' => 'yyyy.mm.dd'
]
]) ?>
</div>
</div>
<div class='row'>
<div class='col-md-6'>
<?= $form->field($model, 'description')->textarea(['maxlength' => true]) ?>
</div>
</div>
<div class='row'>
<div class='col-md-6'>
<?= $form->field($model, 'tax_number')->textInput(['maxlength' => true]) ?>
</div>
</div>
<div class='row'>
<div class='col-md-6'>
<?= $form->field($model, 'country')->textInput(['maxlength' => true]) ?>
</div>
</div>
<div class='row'>
<div class='col-md-2'>
<?= $form->field($model, 'zip')->widget(CityZipTypeahead::className(),[
'pluginEvents' =>[
"typeahead:select" => "function(a,b) {
$('#customercreate-city').typeahead( 'val', b.name );
}",]
])?>
</div>
<div class='col-md-4'>
<?php echo $form->field($model, 'city')->widget(CityNameTypeahead::className(),[
'pluginEvents' =>[
"typeahead:select" => "function(a,b) {
$('#customercreate-zip').typeahead( 'val', b.zip );
}",]
])?>
</div>
</div>
<?= $form->field($model, 'address')->textInput(['maxlength' => true]) ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('common/customer', 'Create') : Yii::t('common/customer', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -1,97 +0,0 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model common\models\Customer */
/* @var $form yii\widgets\ActiveForm */
?>
<style >
.reception-form .btn.btn-reception{
width:100%;
margin-top: 6px;
margin-bottom: 6px;
}
</style>
<?php
$card = $model->card;
$customer = $model->customer;
$customername = "";
if ( $customer != null ){
$customername = $customer->name;
}
function mkCustomerBtn($card, $label,$url = null ){
$classes = 'btn btn-primary btn-reception';
if ( $card == null ){
$classes .= ' disabled';
}
return Html::a( $label , null, ['class' => $classes ] );
}
?>
<div class="reception-form">
<?php $form = ActiveForm::begin([
'enableAjaxValidation' => false,
'method' => 'get'
]); ?>
<div class="row">
<div class='col-md-3'>
<div class='row'>
<div class='col-md-8'>
<?php echo mkCustomerBtn( $card, Yii::t( 'frontend/customer' , 'Adatlap') ); ?>
</div>
<div class='col-md-4'>
<?php echo Html::a(Html::tag("i","", [ 'class' => 'glyphicon glyphicon-plus' ] ) , null, ['class' => 'btn btn-primary btn-reception'] )?>
</div>
</div>
<div class='row'>
<div class='col-md-8'>
<?php echo mkCustomerBtn( $card, Yii::t( 'frontend/customer' , 'Befizetések') ); ?>
</div>
<div class='col-md-4'>
<?php echo Html::a(Html::tag("i","", [ 'class' => 'glyphicon glyphicon-plus' ] ) , null, ['class' => 'btn btn-primary btn-reception'] )?>
</div>
</div>
<div class='row'>
<div class='col-md-12'>
<?php echo Html::a(Yii::t( 'frontend/customer', 'Jelentkezések') , null,['class' => 'btn btn-primary btn-reception'] )?>
</div>
</div>
<div class='row'>
<div class='col-md-12'>
<?php echo mkCustomerBtn( $card, Yii::t( 'frontend/customer' , 'Egyenleg') ); ?>
</div>
</div>
<div class='row'>
<div class='col-md-12'>
<?php echo Html::a(Yii::t( 'frontend/customer', 'Termékeladás') , null,['class' => 'btn btn-primary btn-reception'] )?>
</div>
</div>
</div>
<div class='col-md-2'>
<div class="row" >
<div class='col-md-12'>
<?php echo $form->field($model, 'number')->textInput()?>
</div>
<div class='col-md-12'>
<?php echo $customername; ?>
</div>
</div>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -44,31 +44,19 @@ use yii\base\Widget;
</div> </div>
</div> </div>
<div class='row'>
<div class='col-md-3'>
<?= $form->field($model, 'password_plain')->passwordInput(['maxlength' => true]) ?>
</div>
<div class='col-md-3'>
<?= $form->field($model, 'password_repeat')->passwordInput(['maxlength' => true]) ?>
</div>
</div>
<div class='row'> <div class='row'>
<div class='col-md-3'> <div class='col-md-3'>
<?= $form->field($model, 'sex')->dropDownList(Customer::sexes()) ?> <?= $form->field($model, 'sex')->dropDownList(Customer::sexes()) ?>
</div> </div>
<div class='col-md-3'> <div class='col-md-3'>
<?php /* echo $form->field($model, 'birthdate',[ ] )->widget(DatePicker::classname(), [ <?php echo $form->field($model, 'birthdate',[ ] )->widget(DatePicker::classname(), [
'value' => Yii::$app->formatter->asDate($model->birthdate),
'pluginOptions' => [ 'pluginOptions' => [
'autoclose'=>true, 'autoclose'=>true,
'format' => 'yyyy.mm.dd' 'format' => 'yyyy.mm.dd'
] ]
]) */?> ]) ?>
<?php <?php
echo DatePicker::widget( /*echo DatePicker::widget(
[ [
'name' => 'CustomerUpdate[birthdate]', 'name' => 'CustomerUpdate[birthdate]',
'value' => Yii::$app->formatter->asDate($model->birthdate), 'value' => Yii::$app->formatter->asDate($model->birthdate),
@ -77,7 +65,8 @@ use yii\base\Widget;
'format' => 'yyyy.mm.dd' 'format' => 'yyyy.mm.dd'
] ]
] ]
) );
*/
?> ?>
</div> </div>
</div> </div>

View File

@ -1,20 +1,38 @@
<?php <?php
use yii\helpers\Html; use yii\helpers\Html;
use frontend\components\ReceptionMenuWidget;
use frontend\components\ReceptionCardNumberWidget;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $model common\models\Customer */ /* @var $model common\models\Customer */
$this->title = Yii::t('frontend/customer', 'Create Customer'); $this->title = Yii::t('common/customer', 'Create Customer');
$this->params['breadcrumbs'][] = ['label' => Yii::t('frontend/customer', 'Customers'), 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => Yii::t('common/customer', 'Customers'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title; $this->params['breadcrumbs'][] = $this->title;
$customer = $model;
$card = $customer->card;
?> ?>
<div class="customer-create"> <div class="customer-create">
<div class='row'>
<div class='col-md-3'>
<?php echo ReceptionMenuWidget::widget( [ 'customer' => $customer, 'card' => $card] ) ?>
</div>
<div class='col-md-4'>
<?php echo ReceptionCardNumberWidget::widget( [ 'customer' => $customer, 'card' =>$card, 'route' => ['customer/reception'] ] )?>
</div>
<div class='col-md-4'>
</div>
</div>
<h1><?= Html::encode($this->title) ?></h1> <h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [ <?= $this->render('_form_create', [
'model' => $model, 'model' => $model,
]) ?> ]) ?>

View File

@ -7,9 +7,7 @@ use frontend\components\ReceptionCardNumberWidget;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $model common\models\Customer */ /* @var $model common\models\Customer */
$this->title = Yii::t('common/customer', 'Update {modelClass}: ', [ $this->title = Yii::t('common/customer', 'Update customer:' ) . ' ' . $model->name;
'modelClass' => 'Customer',
]) . ' ' . $model->name;
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/customer', 'Customers'), 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => Yii::t('common/customer', 'Customers'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id_customer]]; $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id_customer]];
$this->params['breadcrumbs'][] = Yii::t('common/customer', 'Update'); $this->params['breadcrumbs'][] = Yii::t('common/customer', 'Update');
@ -20,7 +18,6 @@ $card = $customer->card;
?> ?>
<div class="customer-update"> <div class="customer-update">
<h1><?= Html::encode($this->title) ?></h1>
<div class='row'> <div class='row'>
<div class='col-md-3'> <div class='col-md-3'>
@ -33,6 +30,7 @@ $card = $customer->card;
</div> </div>
</div> </div>
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form_update', [ <?= $this->render('_form_update', [
'model' => $model, 'model' => $model,
]) ?> ]) ?>

View File

@ -11,6 +11,7 @@ use frontend\assets\AppAsset;
use common\widgets\Alert; use common\widgets\Alert;
use common\components\FrotnendMenuStructure; use common\components\FrotnendMenuStructure;
use frontend\components\FrontendMenuStructure; use frontend\components\FrontendMenuStructure;
use kartik\widgets\AlertBlock;
AppAsset::register($this); AppAsset::register($this);
?> ?>
@ -30,6 +31,13 @@ AppAsset::register($this);
<div class="wrap"> <div class="wrap">
<?php <?php
// with growl
echo AlertBlock::widget([
'useSessionFlash' => true,
'type' => AlertBlock::TYPE_GROWL,
'delay' => '3000'
]);
$menuStruct = new FrontendMenuStructure(); $menuStruct = new FrontendMenuStructure();
$items = $menuStruct->run(); $items = $menuStruct->run();

View File

@ -21,9 +21,7 @@ $this->params['breadcrumbs'][] = $this->title;
<?= GridView::widget([ <?= GridView::widget([
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [ 'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id_product', 'id_product',
'id_product_category', 'id_product_category',