#1: Log Card Read In Botond

This commit is contained in:
2018-02-07 08:23:26 +01:00
parent acb5b040c5
commit cf08823d3f
13 changed files with 149 additions and 54 deletions

View File

@@ -10,7 +10,7 @@ return [
'id' => 'app-frontend',
'name' =>'Fitness recepció',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log','assetsAutoCompress'],
'bootstrap' => ['log'],
'controllerNamespace' => 'frontend\controllers',
'components' => [
'assetsAutoCompress' =>

View File

@@ -6,6 +6,7 @@ use frontend\models\TowelForm;
use Yii;
use common\models\Customer;
use frontend\models\ReceptionForm;
use yii\base\InvalidConfigException;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
@@ -54,8 +55,12 @@ class CustomerController extends Controller
$model->number = $number;
$model->readCard();
// $model->mkDoorLog();
if ( $model->defaultAccount && $model->defaultAccount->isLogCardReadInReceptionOn()) {
$model->mkDoorLog();
}
if ( $model->isFreeCard() ){
return $this->redirect([ 'create', 'number' => $model->card->number ]);
}else if ( $model->isCardWithKey()){
@@ -91,7 +96,9 @@ class CustomerController extends Controller
/**
* Creates a new Customer model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @param null $number the card number literal
* @return mixed
* @throws \yii\web\HttpException
*/
public function actionCreate($number = null)
{
@@ -129,18 +136,21 @@ class CustomerController extends Controller
}
}
/**
* Updates an existing Customer model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param null $number
* @return mixed
* @throws NotFoundHttpException
* @internal param int $id
*/
/**
* Updates an existing Customer model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param null $number
* @return mixed
* @throws NotFoundHttpException
* @internal param int $id
* @throws \yii\web\HttpException
*/
public function actionUpdate($number = null)
{
$card = null;
$model = null;
/** @var \backend\models\CustomerUpdate $model */
$model = null;
$receptionForm = new ReceptionForm();
$receptionForm->number = $number;
@@ -158,10 +168,15 @@ class CustomerController extends Controller
if ( $model == null) {
throw new NotFoundHttpException('The requested page does not exist.');
}
$model->birthdate= isset($model->birthdate ) ? Yii::$app->formatter->asDate($model->birthdate) :'';
try {
$model->birthdate = isset($model->birthdate) ? Yii::$app->formatter->asDate($model->birthdate) : '';
} catch (InvalidConfigException $e) {
\Yii::error("Failed to format date: " . $e->getMessage());
$model->birthdate = '';
}
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$this->saveBinaryImage($model);
@@ -185,15 +200,20 @@ class CustomerController extends Controller
]);
}
}
protected function saveBinaryImage($model){
/**
* Save images as binary data.
* @param $model \common\models\Customer
* @throws \yii\web\HttpException
*/
protected function saveBinaryImage($model) {
if ( !empty($model->photo_data)){
$encoded_data = $model->photo_data;
$binary_data = base64_decode( $encoded_data );
// save to server (beware of permissions)
$path = \common\components\Image::saveBinary($binary_data,'profile');
$image = new Image();
$image->path = $path;
$image->save();

View File

@@ -2,10 +2,8 @@
namespace frontend\models;
use Yii;
use yii\base\Model;
use common\models\Card;
use common\models\Customer;
use common\models\Ticket;
use common\models\Account;
use common\models\CardSearch;
@@ -21,6 +19,8 @@ use common\models\DoorLog;
* ContactForm is the model behind the contact form.
*
* @property \common\models\Card $card
* @property \common\models\Account $defaultAccount
* @property \common\models\AccountState $lastCassaState
*/
class ReceptionForm extends Model
{
@@ -74,10 +74,6 @@ class ReceptionForm extends Model
$this->card = $query->one();
if ( $this->card == null ){
}
if ( $this->card != null ){
$this->customer = $this->card->customer;
$this->readValidTickets();
@@ -85,6 +81,7 @@ class ReceptionForm extends Model
}
public function readCard(){
$this->number = Helper::fixAsciiChars( $this->number );
@@ -121,9 +118,12 @@ class ReceptionForm extends Model
$this->cardSearchModel = new CardSearch();
}
public function mkDoorLog(){
if ( !isset($this->card)){
return;
}