From 9fb349ee649be05a95db4a0a84f18385976ccfcc Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Mon, 25 Jan 2016 23:09:43 +0100 Subject: [PATCH] add change card, add customer tab --- backend/views/customer/update.php | 4 +- changelog.txt | 3 ++ common/config/params.php | 2 +- common/models/Card.php | 15 +++++- common/models/CardSearch.php | 25 +++++++++- frontend/components/CustomerTabWidget.php | 26 +++++++++++ frontend/controllers/CustomerController.php | 7 ++- frontend/models/CustomerCreate.php | 2 + frontend/models/CustomerUpdate.php | 50 +++++++++++++++++++- frontend/views/common/_customer_tab.php | 51 +++++++++++++++++++++ frontend/views/contract/index.php | 5 +- frontend/views/contract/view.php | 6 +-- frontend/views/customer/_camera.php | 4 +- frontend/views/customer/_form_update.php | 3 +- frontend/views/customer/update.php | 24 ++++------ frontend/views/key/index.php | 7 +-- frontend/views/ticket/index.php | 6 ++- frontend/views/ticket/update.php | 7 +-- frontend/web/js/customer.js | 32 +++++++++++++ 19 files changed, 241 insertions(+), 38 deletions(-) create mode 100644 frontend/components/CustomerTabWidget.php create mode 100644 frontend/views/common/_customer_tab.php diff --git a/backend/views/customer/update.php b/backend/views/customer/update.php index b0e396a..ff3a1cf 100644 --- a/backend/views/customer/update.php +++ b/backend/views/customer/update.php @@ -5,9 +5,7 @@ use yii\helpers\Html; /* @var $this yii\web\View */ /* @var $model common\models\Customer */ -$this->title = Yii::t('common/customer', 'Update {modelClass}: ', [ - 'modelClass' => 'Customer', -]) . ' ' . $model->name; +$this->title = Yii::t('common/customer', 'Módosítás: ' ) . ' ' . $model->name; $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'][] = Yii::t('common/customer', 'Update'); diff --git a/changelog.txt b/changelog.txt index d22144b..f324f44 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,6 @@ +-0.0.28 + - Add change customer card to reception customer update + - Add customer tab to reception -0.0.27 - Add contract (szerződés ) - Add door_log ( mozgások ) diff --git a/common/config/params.php b/common/config/params.php index 5de3f85..aa10ba9 100644 --- a/common/config/params.php +++ b/common/config/params.php @@ -4,7 +4,7 @@ return [ 'supportEmail' => 'rocho02@gmail.com', 'infoEmail' => 'info@rocho-net.hu', 'user.passwordResetTokenExpire' => 3600, - 'version' => 'v0.0.27', + 'version' => 'v0.0.28', 'company' => 'movar',//gyor 'company_name' => "Freimann Kft.", 'product_visiblity' => 'account',// on reception which products to display. account or global diff --git a/common/models/Card.php b/common/models/Card.php index acf7a55..b94c873 100644 --- a/common/models/Card.php +++ b/common/models/Card.php @@ -116,9 +116,12 @@ class Card extends \common\models\BaseFitnessActiveRecord public static function readCard($number,$free = null){ $card = null; $query = Card::find() - ->leftJoin(Customer::tableName(), 'card.id_card = customer.id_customer_card ' ) - ->andWhere(['number'=>$number ]); + ->leftJoin(Customer::tableName(), 'card.id_card = customer.id_customer_card ' ); +// ->andWhere(['number'=>$number ]); + Card::addCardNumberCondition($query, $number); + + if ( isset($free) ){ if ( $free == true){ $query->andWhere('customer.id_customer is null'); @@ -149,4 +152,12 @@ class Card extends \common\models\BaseFitnessActiveRecord return $name; } + public static function addCardNumberCondition($query,$number, $field_number = "card.number",$field_rfid_key = "card.rfid_key"){ + $query->andWhere(['or', + ['and',[ 'in',$field_number , [$number]],"trim(coalesce(card.number, '')) <>'' " ], + ['and', ['in',$field_rfid_key ,[ $number ] ],"trim(coalesce(card.rfid_key, '')) <>'' "], + + ]); + } + } diff --git a/common/models/CardSearch.php b/common/models/CardSearch.php index 1b5c4e7..f08b026 100644 --- a/common/models/CardSearch.php +++ b/common/models/CardSearch.php @@ -62,11 +62,34 @@ class CardSearch extends Card $query->innerJoin('customer','card.id_card = customer.id_customer_card'); $query->leftJoin("card_key_assignment", 'card.id_card = card_key_assignment.id_card'); $query->leftJoin("key", 'key.id_key = card_key_assignment.id_key'); - $query->orderBy(['customer.name' => SORT_ASC]); +// $query->orderBy(['customer.name' => SORT_ASC]); $dataProvider = new ActiveDataProvider([ 'query' => $query, + 'sort' =>[ + 'attributes' => [ + 'card_number' => [ + 'asc' => ['card.number' => SORT_ASC ], + 'desc' => ['card.number' => SORT_DESC], + ], + 'customer_name' => [ + 'asc' => ['customer.name' => SORT_ASC ], + 'desc' => ['customer.name' => SORT_DESC], + ], + 'customer_phone' => [ + 'asc' => ['customer.phone' => SORT_ASC ], + 'desc' => ['customer.phone' => SORT_DESC], + ], + 'customer_email' => [ + 'asc' => ['customer.email' => SORT_ASC ], + 'desc' => ['customer.email' => SORT_DESC], + ], + ], + 'defaultOrder' =>[ + 'customer_name' => SORT_ASC, + ] + ] ]); diff --git a/frontend/components/CustomerTabWidget.php b/frontend/components/CustomerTabWidget.php new file mode 100644 index 0000000..39fa17f --- /dev/null +++ b/frontend/components/CustomerTabWidget.php @@ -0,0 +1,26 @@ +render($this->viewFile,[ 'card' => $this->card ,'title' => $this->title ]); + } + + +} \ No newline at end of file diff --git a/frontend/controllers/CustomerController.php b/frontend/controllers/CustomerController.php index 61458a0..36f35a1 100644 --- a/frontend/controllers/CustomerController.php +++ b/frontend/controllers/CustomerController.php @@ -168,7 +168,12 @@ class CustomerController extends Controller \Yii::$app->session->setFlash( 'success','Vendég módosításai elmentve' ); - return $this->redirect(['update', 'number' => $card->number]); + $cardNumber = $card->number; + if ( isset( $model->replacementCard ) ){ + $cardNumber = $model->replacementCard->number; + } + + return $this->redirect(['update', 'number' => $cardNumber ]); } else { diff --git a/frontend/models/CustomerCreate.php b/frontend/models/CustomerCreate.php index 14e5556..dbedb6c 100644 --- a/frontend/models/CustomerCreate.php +++ b/frontend/models/CustomerCreate.php @@ -5,6 +5,7 @@ namespace frontend\models; use Yii; use common\models\Customer; use common\models\Card; +use common\components\Helper; /** * This is the model class for table "customer". @@ -57,6 +58,7 @@ class CustomerCreate extends \common\models\Customer return [ [['cardNumber'], 'required' ], [['cardNumber'], 'string', 'max' => 10], + [['cardNumber'], 'filter', 'filter' => function($value){return Helper::fixAsciiChars($value);}], [['cardNumber'], 'validateCustomerCard' ], [['partnerCardNumber'], 'string', 'max' => 10], diff --git a/frontend/models/CustomerUpdate.php b/frontend/models/CustomerUpdate.php index 3157d83..db4f31b 100644 --- a/frontend/models/CustomerUpdate.php +++ b/frontend/models/CustomerUpdate.php @@ -4,6 +4,9 @@ namespace frontend\models; use Yii; use common\models\Customer; +use common\models\Card; +use common\components\Helper; +use common\models\Ticket; /** * This is the model class for table "customer". @@ -40,6 +43,12 @@ class CustomerUpdate extends \common\models\Customer public $password_plain; public $password_repeat; + public $replacementCardNumber; + public $replacementCard; + public $originalCard; + + + /** * @inheritdoc */ @@ -59,7 +68,9 @@ class CustomerUpdate extends \common\models\Customer // [['cardNumber'], 'validateCustomerCard' ], [['partnerCardNumber'], 'string', 'max' => 10], - [['partnerCardNumber'], 'validatePartnerCard' ], +// [['partnerCardNumber'], 'validatePartnerCard' ], + [['replacementCardNumber'], 'filter', 'filter' => function($value){return Helper::fixAsciiChars($value);}], + [['replacementCardNumber'], 'validateReplacementCard' ], [['name'], 'required' ], [['name'], 'string', 'max' => 128], @@ -115,6 +126,43 @@ class CustomerUpdate extends \common\models\Customer public function validatePartnerCard($a,$p){ // Customer::find()->andWhere( [$this->cardNumber ) } + public function validateReplacementCard($a,$p){ + $query = Card::find(); + Card::addCardNumberCondition($query, $this->replacementCardNumber); + $rcard = $query->one(); + + if ( !isset($rcard) ){ + \Yii::info("csere kártya nem található"); + $this->addError($a,"Csere kártya nem található"); + return; + } + \Yii::info("csere kártya megtalálva"); + $customer = $rcard->customer; + + if ( isset($customer) ){ + \Yii::info("A csere kártyát már valaki használja!"); + $this->addError($a ,"A csere kártya már használatban van"); + return; + } + \Yii::info("A csere kártyát megfelel!"); + $this->replacementCard = $rcard; + + } + + public function beforeSave($insert){ + parent::beforeSave($insert); + if ( isset($this->replacementCard ) ){ + $this->originalCard = $this->card; + $this->id_customer_card = $this->replacementCard->id_card; + } + return true; + } + + public function afterSave($insert, $changedAttributes){ + if ( isset($this->replacementCard)){ + Ticket::updateAll( ['id_card' => $this->replacementCard->id_card ], ['id_card' => $this->originalCard->id_card] ); + } + } } diff --git a/frontend/views/common/_customer_tab.php b/frontend/views/common/_customer_tab.php new file mode 100644 index 0000000..8521b8e --- /dev/null +++ b/frontend/views/common/_customer_tab.php @@ -0,0 +1,51 @@ + + +controller->id .'/'. \Yii::$app->controller->action->id; + + + + + + + +$items = [ + [ 'Recepció', ['customer/reception', 'number' => $card->number ]], + [ 'Termék eladás', ['product/sale', 'number' => $card->number ]], + [ 'Adatlap', ['customer/update', 'number' => $card->number ]], + [ 'Befizetések', ['ticket/index', 'number' => $card->number] ], + [ 'Kulcsok', ['key/index', 'id_card' => $card->id_card] ], + [ 'Szerződések', ['contract/index', 'id_card' => $card->id_card ]], +]; + + + + + +?> + + + + + + + +

+

Vendég: customer->name ?>

+

Kártyaszám: number ?>

+ \ No newline at end of file diff --git a/frontend/views/contract/index.php b/frontend/views/contract/index.php index 04c3609..9062efc 100644 --- a/frontend/views/contract/index.php +++ b/frontend/views/contract/index.php @@ -3,6 +3,7 @@ use yii\helpers\Html; use yii\grid\GridView; use yii\helpers\Url; +use frontend\components\CustomerTabWidget; /* @var $this yii\web\View */ /* @var $searchModel frontend\models\ContractSearch */ @@ -11,9 +12,11 @@ use yii\helpers\Url; $this->title = $searchModel->customer->name . " szerződései"; $this->params['breadcrumbs'][] = $this->title; ?> + + $searchModel->card])?> +
-

title) ?>

render('_search', ['model' => $searchModel]); ?> diff --git a/frontend/views/contract/view.php b/frontend/views/contract/view.php index 1002213..142f759 100644 --- a/frontend/views/contract/view.php +++ b/frontend/views/contract/view.php @@ -3,6 +3,7 @@ use yii\helpers\Html; use yii\widgets\DetailView; use common\models\TicketInstallmentRequest; +use frontend\components\CustomerTabWidget; /* @var $this yii\web\View */ /* @var $model common\models\Contract */ @@ -11,11 +12,10 @@ $this->title = "Szerződés részletek" ; $this->params['breadcrumbs'][] = ['label' => Yii::t('common/contract', 'Szerződések'), 'url' => ['index', 'id_card' => $card->id_card]]; $this->params['breadcrumbs'][] = $this->title; ?> + $model->customer->card,'title' => 'Szerződés részletek'])?> +
-

title) ?>

- - $model, 'attributes' => [ diff --git a/frontend/views/customer/_camera.php b/frontend/views/customer/_camera.php index 08ab227..116249a 100644 --- a/frontend/views/customer/_camera.php +++ b/frontend/views/customer/_camera.php @@ -18,7 +18,7 @@ $this->registerJs ( 'new Customer( '. json_encode($options).');' ); } -
+
@@ -26,4 +26,4 @@ $this->registerJs ( 'new Customer( '. json_encode($options).');' );
-Fénykép \ No newline at end of file +Fénykép \ No newline at end of file diff --git a/frontend/views/customer/_form_update.php b/frontend/views/customer/_form_update.php index c3544a7..063cab5 100644 --- a/frontend/views/customer/_form_update.php +++ b/frontend/views/customer/_form_update.php @@ -19,6 +19,7 @@ use yii\base\Widget; field($model, 'photo_data')->hiddenInput()->label(false) ?> +
field($model, 'cardNumber')->widget(CardNumberTypeahead::className(),[]) ?> @@ -28,7 +29,7 @@ use yii\base\Widget;
- field($model, 'partnerCardNumber')->textInput() ?> + field($model, 'replacementCardNumber')->textInput()->label("Csere új kártyára") ?>
diff --git a/frontend/views/customer/update.php b/frontend/views/customer/update.php index a39db12..26fa06b 100644 --- a/frontend/views/customer/update.php +++ b/frontend/views/customer/update.php @@ -1,45 +1,41 @@ title = Yii::t('common/customer', 'Update customer:' ) . ' ' . $model->name; -$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'][] = Yii::t('common/customer', 'Update'); - $customer = $model; $card = $customer->card; +$this->title = Yii::t('common/customer', 'Update customer:' ) . ' ' . $model->name; +$this->params['breadcrumbs'][] = ['label' => "Recepció", 'url' => ['customer/reception' ,'number' => $card->number]]; +$this->params['breadcrumbs'][] = Yii::t('common/customer', 'Update'); + + ?>
+ $receptionForm, 'route' => ['customer/reception'] ] )?> - $receptionForm, 'route' => ['customer/reception'] ] )?> - + $card])?> render('_camera',['model' => $model]); ?> -

title) ?>

- +
image1 ){ echo Html::img( Url::base( ) . Image::thumb( $model->image1->path,160,120 )); } ?> +
render('_form_update', [ 'model' => $model, ]) ?> diff --git a/frontend/views/key/index.php b/frontend/views/key/index.php index 1ab216a..7c9a900 100644 --- a/frontend/views/key/index.php +++ b/frontend/views/key/index.php @@ -3,6 +3,7 @@ use yii\helpers\Html; use yii\grid\GridView; use yii\helpers\Url; +use frontend\components\CustomerTabWidget; /* @var $this yii\web\View */ /* @var $searchModel frontend\models\KeySearch */ @@ -11,13 +12,13 @@ use yii\helpers\Url; $this->title = Yii::t('frontend/key', 'Vendéghez rendelt kulcsok'); $this->params['breadcrumbs'][] = $this->title; ?> + + $searchModel->card])?> +
-

title) ?>

render('_search', ['model' => $searchModel]); ?> -

Vendég: card->customer->name ;?>

-

Kártyaszám: card->number ;?>

$dataProvider, 'columns' => [ diff --git a/frontend/views/ticket/index.php b/frontend/views/ticket/index.php index 4b45e2f..f5b39cc 100644 --- a/frontend/views/ticket/index.php +++ b/frontend/views/ticket/index.php @@ -7,6 +7,7 @@ use frontend\components\ReceptionCardNumberWidget; use frontend\components\ReceptionWidget; use yii\base\Widget; use common\models\Ticket; +use frontend\components\CustomerTabWidget; /* @var $this yii\web\View */ /* @var $searchModel frontend\models\TicketSearch */ @@ -22,10 +23,11 @@ $this->params['breadcrumbs'][] = $this->title;
- $receptionForm, 'route' => ['customer/reception'] ] )?> + $receptionForm, 'route' => ['customer/reception'] ] )?> -

title) ?>

+ $receptionForm->card])?> + render('_search', ['model' => $searchModel]); ?>

diff --git a/frontend/views/ticket/update.php b/frontend/views/ticket/update.php index 422c44d..ffdf55a 100644 --- a/frontend/views/ticket/update.php +++ b/frontend/views/ticket/update.php @@ -1,18 +1,19 @@ title = "Bérlet módosítása:" . ' ' . $model->id_ticket; -$this->params['breadcrumbs'][] = ['label' => Yii::t('common/ticket', 'Tickets'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = ['label' => $model->id_ticket, 'url' => ['view', 'id' => $model->id_ticket]]; +$this->params['breadcrumbs'][] = ['label' =>'Befizetések', 'url' => ['index', 'number' =>$model->card->number]]; $this->params['breadcrumbs'][] = Yii::t('common/ticket', 'Update'); ?> + $model->card,'title' => 'Bérlet módosítása'])?> +

id_ticket ?>

-

title) ?>

render('_form_update', [ 'model' => $model, diff --git a/frontend/web/js/customer.js b/frontend/web/js/customer.js index bcb170e..81009b9 100644 --- a/frontend/web/js/customer.js +++ b/frontend/web/js/customer.js @@ -27,6 +27,38 @@ function Customer(o){ $("#snap").click(snap); + preventSubmit( '#customerupdate-replacementcardnumber' ); + preventSubmit( '#customercreate-cardnumber' ); + } + + function preventSubmit($selector){ + $($selector).keydown(function(e) { + if(e.keyCode == 13) { // enter key was pressed + e.preventDefault(); +// e.stopImmediatePropagation(); +// e.stopPropagation(); + // run own code + return false; // prevent execution of rest of the script + event propagation / event bubbling + prevent default behaviour + } + }); + $($selector).keyup(function(e) { + if(e.keyCode == 13) { // enter key was pressed + e.preventDefault(); +// e.stopImmediatePropagation(); +// e.stopPropagation(); + // run own code + return false; // prevent execution of rest of the script + event propagation / event bubbling + prevent default behaviour + } + }); + $($selector).keypress(function(e) { + if(e.keyCode == 13) { // enter key was pressed + e.preventDefault(); +// e.stopImmediatePropagation(); +// e.stopPropagation(); + // run own code + return false; // prevent execution of rest of the script + event propagation / event bubbling + prevent default behaviour + } + }); } function snap(){