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])?> +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 ?>