add editable account on reception/customer-cart, add towel handling
This commit is contained in:
parent
8585286150
commit
90c598f8c6
@ -19,7 +19,7 @@ class LogSearch extends Log
|
||||
public $end;
|
||||
public $timestampStart;
|
||||
public $timestampEnd;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
|
||||
@ -48,7 +48,7 @@ class TransferSearch extends Transfer
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id_account', 'id_user', 'type', 'status', 'payment_method'], 'integer'],
|
||||
[['id_account', 'id_user', 'type', 'status', 'payment_method','paid_by'], 'integer'],
|
||||
[['customer_name','output','transfer_name', 'card_number' ], 'safe'],
|
||||
// [[ 'searchObjectName' ], 'string'],
|
||||
// [[ 'start', ], 'date' , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
|
||||
@ -189,7 +189,12 @@ class TransferSearch extends Transfer
|
||||
$query->andFilterWhere([
|
||||
'or',
|
||||
['transfer.id_user' => $this->id_user],
|
||||
['transfer.paid_by' => $this->id_user],
|
||||
]);
|
||||
}
|
||||
if (isset($this->paid_by)) {
|
||||
$query->andFilterWhere([
|
||||
'or',
|
||||
['transfer.paid_by' => $this->paid_by],
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ $items = [
|
||||
[ 'Befizetések', ['ticket/index-customer', 'id' => $customer->id_customer ]],
|
||||
[ 'Kulcsok', ['key/index-customer','id' => $customer->id_customer ]],
|
||||
[ 'Szerződések', ['contract/index-customer', 'id' => $customer->id_customer ]],
|
||||
// [ 'Kosár', ['transfer/customer-cart', 'id_card' => $card->id_card ]],
|
||||
// [ 'Kosár', ['transfer/customer-cart', 'id_card' => $card->id_card ]],
|
||||
];
|
||||
|
||||
|
||||
|
||||
@ -69,7 +69,9 @@ use kartik\widgets\DateTimePicker;
|
||||
<?= $form->field($model, 'card_number')->label("Kártya szám") ?>
|
||||
</div>
|
||||
<div class='col-md-3'>
|
||||
</div>
|
||||
<?= $form->field($model, 'paid_by')->dropDownList( ['' => Yii::t('common/transfer', 'All')] +ArrayHelper::map($users,'id' , 'username') )
|
||||
->label("Fizette")?>
|
||||
</div>
|
||||
<div class='col-md-3'>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -30,10 +30,11 @@ class TransferPayout extends \yii\base\Object{
|
||||
|
||||
/**Ha a fizetési módot meg szeretnél változtatni*/
|
||||
public $overridePaymentMethod = null;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**Ha a fizetési Kasszát meg szeretné változtatni.
|
||||
* Fizetési kasszát csak bankártyásra lehet változtatni*/
|
||||
public $overrideIdAccount = null;
|
||||
|
||||
|
||||
public function payout(){
|
||||
|
||||
@ -85,15 +86,21 @@ class TransferPayout extends \yii\base\Object{
|
||||
$transfer->paid_by = $this->idUser;
|
||||
$transfer->status = Transfer::STATUS_PAID;
|
||||
$transfer->paid_at = date('Y-m-d H:i:s' );
|
||||
|
||||
$account = $transfer->account;
|
||||
|
||||
if ( isset($account )){
|
||||
/**Ha a tranzakció eredet kasszája látható típusu, akkor változtathatjuk az atuális kasszára. Különben nem*/
|
||||
if ($account->type == Account::TYPE_ALL){
|
||||
$transfer->id_account = Account::readDefault();
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset($this->overrideIdAccount) && !empty($this->overrideIdAccount)){
|
||||
$transfer->id_account = $this->overrideIdAccount;
|
||||
}else{
|
||||
$account = $transfer->account;
|
||||
|
||||
if ( isset($account )){
|
||||
/**Ha a tranzakció eredeti kasszája látható típusú, akkor változtathatjuk az atuális kasszára. Különben nem*/
|
||||
if ($account->type == Account::TYPE_ALL){
|
||||
$transfer->id_account = Account::readDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
\Yii::info("fizetési mód: " . $this->overridePaymentMethod);
|
||||
|
||||
|
||||
@ -16,6 +16,7 @@ use common\components\Helper;
|
||||
* @property string $created_at
|
||||
* @property string $updated_at
|
||||
* @property int flag_out
|
||||
* @property \common\models\Customer $customer relation
|
||||
*/
|
||||
class Card extends \common\models\BaseFitnessActiveRecord
|
||||
{
|
||||
|
||||
@ -16,6 +16,7 @@ class CardSearch extends Card
|
||||
{
|
||||
|
||||
public $customerName;
|
||||
public $towel;
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@ -23,7 +24,8 @@ class CardSearch extends Card
|
||||
{
|
||||
return [
|
||||
['customerName','string','max' =>200],
|
||||
['number','string','max' =>200]
|
||||
['number','string','max' =>200],
|
||||
['towel','integer']
|
||||
];
|
||||
}
|
||||
|
||||
@ -40,7 +42,8 @@ class CardSearch extends Card
|
||||
return ArrayHelper::merge(parent::attributeLabels(),
|
||||
[
|
||||
'card_number' => 'Kártya szám',
|
||||
'customerName' => 'Vendég'
|
||||
'customerName' => 'Vendég',
|
||||
'towel' => 'Törölköző'
|
||||
]
|
||||
);
|
||||
|
||||
@ -57,7 +60,7 @@ class CardSearch extends Card
|
||||
{
|
||||
|
||||
$query = new Query();
|
||||
$query->select(['card.id_card as card_id_card', 'card.number as card_number' , 'customer.name as customer_name', 'customer.email as customer_email','customer.phone as customer_phone']);
|
||||
$query->select(['card.id_card as card_id_card', 'card.number as card_number' , 'customer.name as customer_name', 'customer.email as customer_email','customer.phone as customer_phone','customer.towel_count as towel_count']);
|
||||
$query->from('card');
|
||||
$query->innerJoin('customer','card.id_card = customer.id_customer_card');
|
||||
$query->leftJoin("card_key_assignment", 'card.id_card = card_key_assignment.id_card');
|
||||
@ -85,6 +88,10 @@ class CardSearch extends Card
|
||||
'asc' => ['customer.email' => SORT_ASC ],
|
||||
'desc' => ['customer.email' => SORT_DESC],
|
||||
],
|
||||
'towel_count' => [
|
||||
'asc' => ['customer.towel_count' => SORT_ASC ],
|
||||
'desc' => ['customer.towel_count' => SORT_DESC],
|
||||
],
|
||||
],
|
||||
'defaultOrder' =>[
|
||||
'customer_name' => SORT_ASC,
|
||||
@ -115,6 +122,10 @@ class CardSearch extends Card
|
||||
]);
|
||||
}
|
||||
|
||||
if ( isset($this->towel) && !empty($this->towel)){
|
||||
$query->andWhere(['>','customer.towel_count',0]);
|
||||
}
|
||||
|
||||
$query->andFilterWhere(['like', 'customer.name', $this->customerName]);
|
||||
|
||||
return $dataProvider;
|
||||
|
||||
@ -29,6 +29,7 @@ use Yii;
|
||||
* @property string $updated_at
|
||||
* @property \common\models\Card card
|
||||
* @property integer status
|
||||
* @property integer towel_count
|
||||
* @property \common\models\User user
|
||||
* @property mixed bank_account
|
||||
*/
|
||||
@ -47,6 +48,7 @@ class Customer extends BaseFitnessActiveRecord
|
||||
|
||||
public $photo_data;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
|
||||
@ -51,6 +51,8 @@ class Log extends BaseFitnessActiveRecord
|
||||
public static $TYPE_NEWSLETTER_SEND_END = 160;
|
||||
public static $TYPE_KEY_ASSIGN = 170;
|
||||
public static $TYPE_KEY_UNASSIGN = 180;
|
||||
public static $TYPE_TOWEL_IN = 190;
|
||||
public static $TYPE_TOWEL_OUT = 200;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
|
||||
@ -99,8 +99,11 @@ class DetstaConsoleController extends Controller
|
||||
|
||||
$content = $detsta->toString();
|
||||
|
||||
file_put_contents('c:\tmp\detsta.txt', $content);
|
||||
$fn = 'c:\tmp\detsta.txt';
|
||||
|
||||
file_put_contents($fn , $content);
|
||||
echo "File saved: " . $fn;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Schema;
|
||||
use yii\db\Migration;
|
||||
|
||||
class m161017_054129_alter__table__customer__add__column_towel_count extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$this->addColumn("customer", "towel_count", "int default 0");
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
echo "m161017_054129_alter__table__customer__add__column_towel_count cannot be reverted.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
// Use safeUp/safeDown to run migration code within a transaction
|
||||
public function safeUp()
|
||||
{
|
||||
}
|
||||
|
||||
public function safeDown()
|
||||
{
|
||||
}
|
||||
*/
|
||||
}
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace frontend\controllers;
|
||||
|
||||
use frontend\models\TowelForm;
|
||||
use Yii;
|
||||
use common\models\Customer;
|
||||
use frontend\models\ReceptionForm;
|
||||
@ -35,7 +36,7 @@ class CustomerController extends Controller
|
||||
],
|
||||
'access' => [
|
||||
'class' => \yii\filters\AccessControl::className(),
|
||||
'only' => ['create', 'update','reception','contract'],
|
||||
'only' => ['create', 'update','reception','contract','towel'],
|
||||
'rules' => [
|
||||
// allow authenticated users
|
||||
[
|
||||
@ -91,8 +92,9 @@ class CustomerController extends Controller
|
||||
*/
|
||||
/**
|
||||
* Displays a single Customer model.
|
||||
* @param integer $id
|
||||
* @param null $number
|
||||
* @return mixed
|
||||
* @internal param int $id
|
||||
*/
|
||||
/*
|
||||
public function actionView($id)
|
||||
@ -102,6 +104,26 @@ class CustomerController extends Controller
|
||||
]);
|
||||
}
|
||||
*/
|
||||
|
||||
public function actionTowel($number = null)
|
||||
{
|
||||
$model = new TowelForm();
|
||||
if ($model->load(Yii::$app->request->post()) ) {
|
||||
if ( $model->save() ){
|
||||
if ( $model->direction == 'in'){
|
||||
\Yii::$app->session->setFlash ( 'success', 'Törölköző(k) visszaadva!' );
|
||||
}else{
|
||||
\Yii::$app->session->setFlash ( 'success', 'Törölköző(k) kiadva!' );
|
||||
}
|
||||
}else{
|
||||
\Yii::$app->session->setFlash ( 'danger', 'Sikertelen törölköző művelet' );
|
||||
}
|
||||
}
|
||||
return $this->redirect(['customer/reception', 'number' => $number ]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Customer model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
@ -216,8 +238,8 @@ class CustomerController extends Controller
|
||||
$model->save(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// s
|
||||
|
||||
84
frontend/controllers/LogController.php
Normal file
84
frontend/controllers/LogController.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\controllers;
|
||||
|
||||
use Yii;
|
||||
use common\models\Log;
|
||||
use frontend\models\LogSearch;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
use common\models\Card;
|
||||
use common\models\TicketInstallmentRequest;
|
||||
use common\models\Ticket;
|
||||
use common\models\Transfer;
|
||||
use common\models\Account;
|
||||
use common\components\Helper;
|
||||
use common\models\Sale;
|
||||
use common\models\Product;
|
||||
use common\models\ShoppingCart;
|
||||
use common\models\Customer;
|
||||
use frontend\models\LogForm;
|
||||
|
||||
/**
|
||||
* LogController implements the CRUD actions for Log model.
|
||||
*/
|
||||
class LogController extends Controller {
|
||||
public function behaviors() {
|
||||
return [
|
||||
'access' => [
|
||||
'class' => \yii\filters\AccessControl::className(),
|
||||
'only' => ['towel'],
|
||||
'rules' => [
|
||||
// allow authenticated users
|
||||
[
|
||||
'allow' => true,
|
||||
'roles' => ['@'],
|
||||
],
|
||||
// everything else is denied
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all Log models.
|
||||
* @param $id_card
|
||||
* @return mixed
|
||||
* @throws \Yii\web\NotFoundHttpException
|
||||
*/
|
||||
public function actionTowel($id_card) {
|
||||
$card = Card::findOne ( $id_card );
|
||||
|
||||
if (! isset ( $card ))
|
||||
throw new NotFoundHttpException ( 'A bérlet nem található' );
|
||||
|
||||
$searchModel = new LogSearch ();
|
||||
$searchModel->card = $card;
|
||||
$searchModel->customer = $card->customer;
|
||||
$dataProvider = $searchModel->search ( Yii::$app->request->queryParams );
|
||||
|
||||
return $this->render ( 'index', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider
|
||||
] );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Finds the Log model based on its primary key value.
|
||||
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||
*
|
||||
* @param integer $id
|
||||
* @return Log the loaded model
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
protected function findModel($id) {
|
||||
if (($model = Log::findOne ( $id )) !== null) {
|
||||
return $model;
|
||||
} else {
|
||||
throw new NotFoundHttpException ( 'The requested page does not exist.' );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -401,6 +401,11 @@ class TransferController extends Controller
|
||||
return $this->redirect(['account/select']);
|
||||
}
|
||||
|
||||
$hiddenAccounts = Account::find()
|
||||
->andWhere(['type' => Account::TYPE_VALUE_HIDDEN])
|
||||
->andWhere(['status' => Account::STATUS_ACTIVE])->all();
|
||||
|
||||
|
||||
$customer = null;
|
||||
$card = Card::findOne($id_card);
|
||||
if ($card != null )
|
||||
@ -413,6 +418,7 @@ class TransferController extends Controller
|
||||
|
||||
$model = new CustomerCartForm();
|
||||
$model->customer = $customer;
|
||||
$model->hiddenAccounts = $hiddenAccounts;
|
||||
if ($model->load(Yii::$app->request->post()) && $model->payout()) {
|
||||
return $this->redirect(['customer-cart','id_card' => $model->customer->card->id_card]);
|
||||
}
|
||||
|
||||
@ -20,7 +20,8 @@ class CustomerCartForm extends Model
|
||||
public $money = 0;
|
||||
public $selected = [];
|
||||
public $customer;
|
||||
|
||||
public $hiddenAccounts;
|
||||
public $id_account;
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@ -28,7 +29,7 @@ class CustomerCartForm extends Model
|
||||
{
|
||||
return [
|
||||
['selected', 'each', 'rule' => ['integer']],
|
||||
[['money' ,'payment_method'],'integer'],
|
||||
[['money' ,'payment_method' ,'id_account' ],'integer'],
|
||||
[['payment_method'],'validatePaymentMethod'],
|
||||
];
|
||||
}
|
||||
@ -44,15 +45,45 @@ class CustomerCartForm extends Model
|
||||
|
||||
public function validatePaymentMethod( $attribute, $params ){
|
||||
if ( !empty($this->payment_method)){
|
||||
// echo $this->payment_method;
|
||||
$arr = Transfer::paymentMethods();
|
||||
if ( !array_key_exists($this->payment_method, $arr) ){
|
||||
$this->addError($attribute, "Érvénytelen fizetési mód");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function validateIdAccount( $attribute, $params ){
|
||||
if ( !empty($this->id_account)){
|
||||
$account = $this->loadAvailableOverrideAccounts($this->id_account);
|
||||
if ( !isset($account) ){
|
||||
$this->addError($attribute, "Érvénytelen kassza");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function loadAvailableOverrideAccounts($id_account = null){
|
||||
$accounts = null;
|
||||
$query = Account::find();
|
||||
|
||||
$query->innerJoinWith('userAccountAssignments');
|
||||
$query->andWhere(['user_account_assignment.id_user' => Yii::$app->user->id]);
|
||||
$query->andWhere(['status' => Account::STATUS_ACTIVE])->all();
|
||||
|
||||
if ( isset($id_account)){
|
||||
$query->andWhere(['account.id_account' => $id_account]);
|
||||
}
|
||||
|
||||
|
||||
$query->orderBy( ['name' => SORT_ASC]);
|
||||
|
||||
|
||||
$accounts = $query->all();
|
||||
return $accounts;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function payout(){
|
||||
$valid = $this->validate();
|
||||
|
||||
@ -71,6 +102,7 @@ class CustomerCartForm extends Model
|
||||
'idAccount' => Account::readDefault (),
|
||||
'cartType' => 'customer',
|
||||
'overridePaymentMethod' => $this->payment_method,
|
||||
'overrideIdAccount' => $this->id_account,
|
||||
'idCustomer' => $this->customer->id_customer
|
||||
] );
|
||||
|
||||
@ -82,10 +114,10 @@ class CustomerCartForm extends Model
|
||||
|
||||
} catch ( Exception $e ) {
|
||||
$transaction->rollback ();
|
||||
Yii::error ( "faled to save :" . $e->getMessage () );
|
||||
Yii::error ( "failed to save :" . $e->getMessage () );
|
||||
} catch ( \Exception $e ) {
|
||||
$transaction->rollback ();
|
||||
Yii::error ( "faled to save :" . $e->getMessage () );
|
||||
Yii::error ( "failed to save :" . $e->getMessage () );
|
||||
}
|
||||
return false;
|
||||
|
||||
@ -100,7 +132,13 @@ class CustomerCartForm extends Model
|
||||
$item->payment_method = $this->payment_method;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function changeAccount($item){
|
||||
if ( !empty($this->id_account)){
|
||||
$item->id_account = $this->id_account;
|
||||
}
|
||||
}
|
||||
|
||||
public function run(){
|
||||
$this->readTransfers();
|
||||
}
|
||||
|
||||
130
frontend/models/LogSearch.php
Normal file
130
frontend/models/LogSearch.php
Normal file
@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use common\models\Log;
|
||||
use yii\db\Expression;
|
||||
use yii\db\Query;
|
||||
use common\components\Helper;
|
||||
|
||||
/**
|
||||
* LogSearch represents the model behind the search form about `common\models\Log`.
|
||||
*/
|
||||
class LogSearch extends Log
|
||||
{
|
||||
|
||||
public $start;
|
||||
public $end;
|
||||
public $timestampStart;
|
||||
public $timestampEnd;
|
||||
|
||||
public $card;
|
||||
public $customer;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[[ 'start', ], 'date', 'format' =>Yii::$app->formatter->datetimeFormat , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd HH:mm' ,'timeZone' => 'UTC' ],
|
||||
[[ 'end' , ], 'date' ,'format' =>Yii::$app->formatter->datetimeFormat , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd HH:mm' ,'timeZone' => 'UTC' ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @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([
|
||||
'log.id_log as log_id_log',
|
||||
'log.created_at as log_created_at',
|
||||
'log.message as log_message',
|
||||
'user.username as user_username',
|
||||
'customer.name as customer_name',
|
||||
new Expression("case when log.type = " .Log::$TYPE_TOWEL_IN ." then 'Visszaad' ".
|
||||
" when log.type = ". Log::$TYPE_TOWEL_OUT . " then 'Bérel' ".
|
||||
" else '-' end as log_type")
|
||||
|
||||
]);
|
||||
$query->from("log");
|
||||
$query->leftJoin("user"," user.id = log.id_user");
|
||||
$query->leftJoin("customer"," customer.id_customer = log.id_customer");
|
||||
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
'sort' =>[
|
||||
'defaultOrder' => [ 'log_created_at' => SORT_DESC],
|
||||
'attributes' => Helper::mkYiiSortItems([
|
||||
['log_id_log'],
|
||||
['log_created_at'],
|
||||
['log_message'],
|
||||
['log_app'],
|
||||
['log_app'],
|
||||
['user_username'],
|
||||
['customer_name'],
|
||||
['log_type'],
|
||||
|
||||
])
|
||||
|
||||
]
|
||||
]);
|
||||
|
||||
$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(['>=', 'log.created_at', $this->timestampStart]);
|
||||
$query->andFilterWhere(['<', 'log.created_at', $this->timestampEnd]);
|
||||
|
||||
$query->andFilterWhere([
|
||||
'id_log' => $this->id_log,
|
||||
'type' => $this->type,
|
||||
'id_user' => $this->id_user,
|
||||
'id_transfer' => $this->id_transfer,
|
||||
'id_money_movement' => $this->id_money_movement,
|
||||
'id_ticket' => $this->id_ticket,
|
||||
'id_sale' => $this->id_sale,
|
||||
'id_customer' => $this->id_customer,
|
||||
'id_account' => $this->id_account,
|
||||
'id_account_state' => $this->id_account_state,
|
||||
'id_key' => $this->id_key,
|
||||
'id_product' => $this->id_product,
|
||||
'id_door_log' => $this->id_door_log,
|
||||
'created_at' => $this->created_at,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere(['like', 'message', $this->message])
|
||||
->andFilterWhere(['like', 'url', $this->url])
|
||||
->andFilterWhere(['like', 'app', $this->app]);
|
||||
|
||||
|
||||
$query->andWhere(['in', 'log.type',[Log::$TYPE_TOWEL_IN,Log::$TYPE_TOWEL_OUT]]);
|
||||
$query->andWhere([ '=', 'customer.id_customer' , $this->customer->id_customer]);
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
}
|
||||
116
frontend/models/TowelForm.php
Normal file
116
frontend/models/TowelForm.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\models;
|
||||
|
||||
use common\models\DoorLog;
|
||||
use common\models\Log;
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use common\models\CardKeyAssignment;
|
||||
use common\models\Key;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use common\components\Helper;
|
||||
use common\models\Card;
|
||||
|
||||
/**
|
||||
* ContactForm is the model behind the contact form.
|
||||
*
|
||||
* @property \common\models\Card $card
|
||||
* @property \common\models\Key $key
|
||||
*
|
||||
*/
|
||||
class TowelForm extends Model
|
||||
{
|
||||
|
||||
public $count;
|
||||
public $number;
|
||||
public $direction;
|
||||
|
||||
public $card;
|
||||
public $customer;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['count'], 'integer', 'min' => 1, 'max' => 10 ],
|
||||
[['number','direction'], 'safe' ],
|
||||
[['count', 'number'], 'required'],
|
||||
[['number'],'validateCard' ],
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
];
|
||||
}
|
||||
|
||||
public function validateCard($a,$params){
|
||||
|
||||
$this->number = Helper::fixAsciiChars( $this->number );
|
||||
|
||||
$query = Card::find();
|
||||
$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->andWhere(['or',
|
||||
['and',[ 'in','card.number' , [$this->number]],"trim(coalesce(card.number, '')) <>'' " ],
|
||||
['and', ['in','card.rfid_key' ,[ $this->number] ],"trim(coalesce(card.rfid_key, '')) <>'' "],
|
||||
['and',[ 'in','key.number' , [$this->number]],"trim(coalesce(key.number, '')) <>'' " ],
|
||||
['and', ['in','key.rfid_key' ,[ $this->number] ],"trim(coalesce(key.rfid_key, '')) <>'' "]
|
||||
|
||||
]);
|
||||
|
||||
$this->card = $query->one();
|
||||
|
||||
if ( $this->card != null ){
|
||||
$this->customer = $this->card->customer;
|
||||
}
|
||||
|
||||
if ( !isset($this->customer)){
|
||||
$this->addError($a,"A megadott vendég nem található");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function updateTowelCount(){
|
||||
$count = $this->count;
|
||||
if ( isset($this->direction) && $this->direction == 'in'){
|
||||
$count = $this->customer->towel_count - $count;
|
||||
$log_type = Log::$TYPE_TOWEL_IN;
|
||||
}else{
|
||||
$count = $this->customer->towel_count + $count;
|
||||
$log_type = Log::$TYPE_TOWEL_OUT;
|
||||
}
|
||||
|
||||
$count = max(0, $count );
|
||||
|
||||
$this->customer->towel_count = $count;
|
||||
$result = $this->customer->save(false);
|
||||
if ( $result ){
|
||||
Log::log([
|
||||
'type' => $log_type,
|
||||
'message' => '' .$this->customer->towel_count,
|
||||
'id_customer' => $this->customer->id_customer
|
||||
]);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function save(){
|
||||
if ( $this->validate()){
|
||||
return $this->updateTowelCount();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@ -27,6 +27,9 @@ use yii\widgets\ActiveForm;
|
||||
<div class="col-md-4">
|
||||
<?php echo $form->field($model, 'number')->label("Kártya/kulcs szám") ?>
|
||||
</div>
|
||||
<div class='col-md-3'>
|
||||
<?= $form->field($model, 'towel')->dropDownList( ['' => "Mind" , '1' => "Bérel Törölközőt"] ) ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
|
||||
@ -38,6 +38,10 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
'attribute' => 'customer_email',
|
||||
'label' => 'E-mail',
|
||||
],
|
||||
[
|
||||
'attribute' => 'towel_count',
|
||||
'label' => 'Törölköző (db)',
|
||||
],
|
||||
// [
|
||||
// 'attribute' => 'customer.name',
|
||||
// 'value' => 'customer.name',
|
||||
@ -45,7 +49,7 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
|
||||
|
||||
['class' => 'yii\grid\ActionColumn',
|
||||
'template' => '{ticket} {product} {ticket_history} {keys} {contract}',
|
||||
'template' => '{ticket} {product} {ticket_history} {keys} {contract} {towel}',
|
||||
'buttons' => [
|
||||
'ticket' => function ($url, $model, $key) {
|
||||
return Html::a('Új bérlet', $url, ['class'=> 'btn btn-xs btn-success' ]) ;
|
||||
@ -61,6 +65,9 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
},
|
||||
'contract' => function ($url, $model, $key) {
|
||||
return Html::a('Szerződések', $url, ['class'=> 'btn btn-xs btn-success' ]) ;
|
||||
},
|
||||
'towel' => function ($url, $model, $key) {
|
||||
return Html::a('Törölközők', $url, ['class'=> 'btn btn-xs btn-success' ]) ;
|
||||
},
|
||||
],
|
||||
'urlCreator' => function ($action, $model, $key, $index){
|
||||
@ -75,6 +82,9 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
$url = Url::to(['key/index','id_card' => $model['card_id_card']]);
|
||||
}else if ( 'contract' == $action ){
|
||||
$url = Url::to(['contract/index','id_card' => $model['card_id_card']]);
|
||||
}else if ( 'towel' == $action ){
|
||||
$start = Yii::$app->formatter->asDatetime(strtotime('today UTC'));
|
||||
$url = Url::to(['log/towel','id_card' => $model['card_id_card'] ,'LogSearch[start]' =>$start ]);
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ use yii\helpers\Url;
|
||||
|
||||
$route = \Yii::$app->controller->id .'/'. \Yii::$app->controller->action->id;
|
||||
|
||||
|
||||
$todayDateTime = Yii::$app->formatter->asDatetime(strtotime('today UTC'));
|
||||
|
||||
|
||||
|
||||
@ -22,6 +22,7 @@ $items = [
|
||||
[ 'Szerződések', ['contract/index', 'id_card' => $card->id_card ]],
|
||||
[ 'Kosár', ['transfer/customer-cart', 'id_card' => $card->id_card ]],
|
||||
[ 'Kártya', ['card/info', 'id_card' => $card->id_card ]],
|
||||
[ 'Törölköző Bérlés', ['log/towel', 'id_card' => $card->id_card , 'LogSearch[start]' => $todayDateTime ]],
|
||||
];
|
||||
|
||||
|
||||
|
||||
@ -36,6 +36,10 @@ if ( $model->isCardWithCustomer() ){
|
||||
'label' => 'Telefon',
|
||||
'value' => $model->customer->phone
|
||||
],
|
||||
[
|
||||
'label' => 'Kiadott törölközők',
|
||||
'value' => $model->customer->towel_count
|
||||
],
|
||||
[
|
||||
'label' => 'Kulcsok',
|
||||
'value' =>
|
||||
|
||||
@ -81,5 +81,28 @@ $card = $model->card;
|
||||
</div>
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
<?php if ( isset($model->customer) ) { ?>
|
||||
<?php $form = ActiveForm::begin([
|
||||
'action' => ['customer/towel', 'number' => $model->getCardNumber()],
|
||||
'method' => 'post',
|
||||
]); ?>
|
||||
<div class="row" style="margin-top: 6px; margin-bottom: 6px;">
|
||||
<div class='col-md-12'>
|
||||
<?php echo Html::hiddenInput('TowelForm[number]', $model->getCardNumber())?>
|
||||
<?php echo Html::textInput('TowelForm[count]','',['class'=>"form-control", 'placeholder' =>'Törölköző darab' ,'type' => 'number']) ?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class='col-md-6'>
|
||||
<?= Html::submitButton(Yii::t('frontend/collection', 'Bérel'), [ 'name' => 'TowelForm[direction]', 'value' => 'out', 'class' => 'btn btn-primary btn-block']) ?>
|
||||
</div>
|
||||
<div class='col-md-6'>
|
||||
<?= Html::submitButton(Yii::t('frontend/collection', 'Vissza ad'), ['name' => 'TowelForm[direction]', 'value' => 'in', 'class' => 'btn btn-primary btn-block']) ?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<?php ActiveForm::end(); ?>
|
||||
<?php }?>
|
||||
|
||||
|
||||
|
||||
@ -136,4 +136,23 @@ if ( isset( $model->unpaidTickets ) ) {
|
||||
}
|
||||
|
||||
|
||||
if ( isset($model->customer)){
|
||||
|
||||
if ( $model->customer->towel_count > 0 ){
|
||||
$towelText = "Kiadott törölközők (db):" . $model->customer->towel_count;
|
||||
$towelClass = "alert alert-danger";
|
||||
}else{
|
||||
$towelText = "Nincs kiadott törölköző";
|
||||
$towelClass = "alert alert-success";
|
||||
}
|
||||
|
||||
|
||||
echo Html::beginTag("div",['class'=> $towelClass, "role"=>"alert"]);
|
||||
echo Html::beginTag("strong",[ ]);
|
||||
echo $towelText;
|
||||
echo Html::endTag("strong");
|
||||
echo Html::endTag("div");
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
50
frontend/views/log/_search.php
Normal file
50
frontend/views/log/_search.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
use kartik\widgets\DateTimePicker;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\models\LogSearch */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<div class="log-search">
|
||||
|
||||
<?php $form = ActiveForm::begin([
|
||||
'action' => ['towel', 'id_card' => $model->card->id_card ],
|
||||
'method' => 'get',
|
||||
]); ?>
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
|
||||
<?= $form->field($model, 'start')->widget(DateTimePicker::classname(), [
|
||||
'pluginOptions' => [
|
||||
'autoclose'=>true,
|
||||
'format' => 'yyyy.mm.dd hh:ii'
|
||||
]
|
||||
]) ?>
|
||||
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<?= $form->field($model, 'end') ->widget(DateTimePicker::classname(), [
|
||||
'pluginOptions' => [
|
||||
'autoclose'=>true,
|
||||
'format' => 'yyyy.mm.dd hh:ii'
|
||||
]
|
||||
]) ?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton(Yii::t('common/log', 'Keresés'), ['class' => 'btn btn-primary']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
||||
38
frontend/views/log/index.php
Normal file
38
frontend/views/log/index.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $searchModel frontend\models\LogSearch */
|
||||
/* @var $dataProvider yii\data\ActiveDataProvider */
|
||||
|
||||
$this->title = Yii::t('common/log', 'Törölköző bérlés történet');
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<?php echo \frontend\components\CustomerTabWidget::widget(['card' => $searchModel->card])?>
|
||||
<div class="log-index">
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
<?php echo $this->render('_search', ['model' => $searchModel]); ?>
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $dataProvider,
|
||||
'columns' => [
|
||||
[
|
||||
'attribute' => "log_created_at",
|
||||
'label' => "Dátum idő",
|
||||
],
|
||||
[
|
||||
'attribute' => "log_type",
|
||||
'label' => "Esemény",
|
||||
],
|
||||
[
|
||||
'attribute' => "log_message",
|
||||
'label' => "Db",
|
||||
],
|
||||
[
|
||||
'attribute' => "user_username",
|
||||
'label' => "Felhasználó",
|
||||
],
|
||||
],
|
||||
]); ?>
|
||||
</div>
|
||||
@ -32,7 +32,13 @@ $this->registerJs ( 'new TransferCustomerCart( '. json_encode($options).');' );
|
||||
|
||||
<div class="transfer-form">
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
<?php echo $form->field($model, 'payment_method')->dropDownList( ['' => 'Aktuális'] + Transfer::paymentMethods())->label("Fizetése mód") ?>
|
||||
<?php echo $form->field($model, 'payment_method')->dropDownList( ['' => 'Aktuális fizetési mód'] + Transfer::paymentMethods())->label("Fizetése mód") ?>
|
||||
<?php echo $form->field($model, 'id_account')
|
||||
->dropDownList( ['' => 'Aktuális kassza'] + array_reduce( $model->hiddenAccounts, function( $result, $item ){
|
||||
$result[$item->id_account] = $item->name;
|
||||
return $result;
|
||||
} ,array()) )
|
||||
->label("Kassza") ?>
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<span style="font-weight: bold;">Összesen:</span>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user