add kulcsok, add tartós beszedés, add ticket type with intallments

This commit is contained in:
2016-01-20 14:48:34 +01:00
parent d1638a19de
commit d7cc84e78f
111 changed files with 4077 additions and 12 deletions

View File

@@ -88,6 +88,9 @@ class CustomerCreate extends \common\models\Customer
[['phone', 'tax_number', 'country'], 'string', 'max' => 20],
[['bank_account'], 'string', 'max' => 24],
[['bank_name'], 'string', 'max' => 100],
[['phone'], 'required', 'when' => function($model) {
return !isset( $model->email ) || empty( $model->email ) ;
} ,

View File

@@ -89,6 +89,9 @@ class CustomerUpdate extends \common\models\Customer
[['phone', 'tax_number', 'country'], 'string', 'max' => 20],
[['bank_account'], 'string', 'max' => 24],
[['bank_name'], 'string', 'max' => 100],
[['phone'], 'required', 'when' => function($model) {
return !isset( $model->email ) || empty( $model->email ) ;
} ,

View File

@@ -0,0 +1,76 @@
<?php
namespace frontend\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Key;
use yii\db\Query;
/**
* KeySearch represents the model behind the search form about `common\models\Key`.
*/
class KeySearch extends Key
{
public $card;
/**
* @inheritdoc
*/
public function rules()
{
return [
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = new Query();
$query->select([ 'user.username as user_username', 'card.id_card as card_id_card', 'key.id_key as key_id_key', 'card.number as card_number' , 'key.number as key_number','card_key_assignment.created_at as assign_created_at'] );
$query->from('card');
$query->innerJoin('card_key_assignment','card.id_card = card_key_assignment.id_card' );
$query->innerJoin('key','key.id_key = card_key_assignment.id_key' );
$query->innerJoin('user','user.id = card_key_assignment.id_user' );
$query->andWhere(['card_key_assignment.id_card' => $this->card->id_card]);
$query->orderBy( ['card_key_assignment.created_at' => SORT_ASC] );
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere([
'type' => $this->type,
]);
$query->andFilterWhere(['like', 'number', $this->number])
->andFilterWhere(['like', 'rfid_key', $this->rfid_key]);
return $dataProvider;
}
}

View File

@@ -0,0 +1,75 @@
<?php
namespace frontend\models;
use Yii;
use yii\base\Model;
use common\models\CardKeyAssignment;
use common\models\Key;
use yii\helpers\ArrayHelper;
/**
* ContactForm is the model behind the contact form.
*/
class KeyToggleForm extends Model
{
public $key;
public $card;
public $customer;
public $keyModel;
/**
* @inheritdoc
*/
public function rules()
{
return [
[['key'], 'safe' ]
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
];
}
public function toggleKey(){
$this->keyModel = Key::find()->andWhere(['rfid_key' => $this->key])->one();
if ( isset($this->keyModel) ){
$assignments = CardKeyAssignment::find()->andWhere(['id_key' => $this->keyModel->id_key])->all();
if ( count($assignments) > 0){
$this->unassign();
}else{
$this->assign();
}
}else{
\Yii::$app->session->setFlash ( 'danger', 'Kulcs nem található!' );
}
}
public function assign(){
if ( isset($this->card) && isset($this->customer) ){
$assignment = new CardKeyAssignment();
$assignment->id_card = $this->card->id_card;
$assignment->id_key = $this->keyModel->id_key;
$assignment->id_user = \Yii::$app->user->id;
$assignment->save(false);
\Yii::$app->session->setFlash ( 'success', 'Kulcs kiadva!' );
}else{
\Yii::$app->session->setFlash ( 'danger', 'Nincs vendég kiválasztva vagy érvénytelen kártya!' );
}
}
public function unassign(){
CardKeyAssignment::deleteAll(['id_key' => $this->keyModel->id_key]);
\Yii::$app->session->setFlash ( 'success', 'Kulcs visszaadva!' );
}
}

View File

@@ -10,6 +10,8 @@ use common\models\Ticket;
use common\models\Account;
use common\models\CardSearch;
use common\models\AccountState;
use common\models\Key;
use common\models\CardKeyAssignment;
/**
* ContactForm is the model behind the contact form.
@@ -23,7 +25,7 @@ class ReceptionForm extends Model
public $defaultAccount;
public $cardSearchModel;
public $lastCassaState;
public $keys;
/**
* @inheritdoc
*/
@@ -53,6 +55,7 @@ class ReceptionForm extends Model
if ( $this->card != null ){
$this->customer = $this->card->customer;
$this->readValidTickets();
$this->readAssignedKeys();
}
$defaultAccount = Account::readDefault();
@@ -65,6 +68,14 @@ class ReceptionForm extends Model
}
public function readAssignedKeys(){
$query = Key::find();
$query->join( 'INNER JOIN', CardKeyAssignment::tableName() , Key::tableName().".id_key = " . CardKeyAssignment::tableName() . ".id_key");
$query->andWhere([ "card_key_assignment.id_card" => $this->card->id_card ]);
$this->keys = $query->all();
}
public function readLastCassaState(){
$a = Account::readDefault();
if ( isset($a)){
@@ -136,4 +147,23 @@ class ReceptionForm extends Model
}
public function getCardNumber(){
if ( isset($this->card)){
return $this->card->number;
}
return null;
}
public function getKeysText(){
$keyNumbers = [];
$result = "-";
if ( isset($this->keys)){
foreach ($this->keys as $k ){
$keyNumbers[] = $k->number;
}
$result = implode(", ",$keyNumbers);
}
return $result;
}
}

View File

@@ -9,6 +9,7 @@ use common\models\Transfer;
use common\models\UserSoldItem;
use common\models\ShoppingCart;
use yii\base\Object;
use common\models\TicketInstallmentRequest;
/**
* @property $cart string name of cart, into we put the ticket
@@ -111,9 +112,21 @@ class TicketCreate extends Ticket{
$this->addTransfer();
$this->appendToUserCart();
$this->appendToCustomerCart();
$this->addTicketInstallmentRequests($insert);
}
public function addTicketInstallmentRequests($insert){
if ($insert){
$ticketType = TicketType::findOne($this->id_ticket_type);
if ( isset($ticketType) && $ticketType->isInstallment() ){
$requests = TicketInstallmentRequest::createInstallments($this, $ticketType, $this->customer);
foreach ($requests as $request){
$request->save(false);
}
}
}
}
protected function addTransfer(){
$transfer = Transfer::createTicketTransfer($this->_account, $this->_discount, null, 1, $this);