add reception changes
This commit is contained in:
86
frontend/controllers/CardController.php
Normal file
86
frontend/controllers/CardController.php
Normal 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 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -12,6 +12,7 @@ use yii\filters\VerbFilter;
|
||||
use yii\base\Object;
|
||||
use common\models\Card;
|
||||
use frontend\models\CustomerUpdate;
|
||||
use frontend\models\CustomerCreate;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @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()) {
|
||||
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 {
|
||||
return $this->render('create', [
|
||||
'model' => $model,
|
||||
@@ -104,7 +114,7 @@ class CustomerController extends Controller
|
||||
if ( $number != null ){
|
||||
$card = Card::readCard($number);
|
||||
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()) {
|
||||
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 {
|
||||
|
||||
|
||||
|
||||
return $this->render('update', [
|
||||
'model' => $model,
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user