Finish version/v.0.0.65

This commit is contained in:
Roland Schneider 2016-04-18 22:18:56 +02:00
commit 11e0ad8e41
9 changed files with 278 additions and 3 deletions

View File

@ -1,3 +1,5 @@
-0.0.65
- change trigger to detect move in and move out
-0.0.64 -0.0.64
- admin add unstorno ticket - admin add unstorno ticket
- admin transfer search by customer name - admin transfer search by customer name

View File

@ -4,7 +4,7 @@ return [
'supportEmail' => 'rocho02@gmail.com', 'supportEmail' => 'rocho02@gmail.com',
'infoEmail' => 'info@rocho-net.hu', 'infoEmail' => 'info@rocho-net.hu',
'user.passwordResetTokenExpire' => 3600, 'user.passwordResetTokenExpire' => 3600,
'version' => 'v0.0.64', 'version' => 'v0.0.65',
'company' => 'movar',//gyor 'company' => 'movar',//gyor
'company_name' => "Freimann Kft.", 'company_name' => "Freimann Kft.",
'product_visiblity' => 'account',// on reception which products to display. account or global 'product_visiblity' => 'account',// on reception which products to display. account or global

View File

@ -4,6 +4,8 @@ namespace common\models;
use Yii; use Yii;
use common\components\Helper; use common\components\Helper;
use yii\behaviors\TimestampBehavior;
use yii\helpers\ArrayHelper;
/** /**
* This is the model class for table "door_log". * This is the model class for table "door_log".
@ -30,6 +32,17 @@ class DoorLog extends \yii\db\ActiveRecord
{ {
return 'door_log'; return 'door_log';
} }
public function behaviors()
{
return ArrayHelper::merge( [
[
'class' => TimestampBehavior::className(),
'value' => function(){ return date('Y-m-d H:i:s' ); },
'updatedAtAttribute' => false,
]
], parent::behaviors());
}
/** /**
* @inheritdoc * @inheritdoc

View File

@ -40,6 +40,7 @@ class Log extends BaseFitnessActiveRecord
public static $TYPE_DEFAULT_ACCOUNT= 60; public static $TYPE_DEFAULT_ACCOUNT= 60;
public static $TYPE_CREATE_CUSTOMER= 70; public static $TYPE_CREATE_CUSTOMER= 70;
public static $TYPE_PROCUREMENT_UPDATE = 80; public static $TYPE_PROCUREMENT_UPDATE = 80;
public static $TYPE_TICKET_COUNT_MOVE_OUT = 90;
/** /**
* @inheritdoc * @inheritdoc
*/ */

View File

@ -42,7 +42,7 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
where ticket.start <= CURDATE() where ticket.start <= CURDATE()
and ticket.end >= curdate() and ticket.end >= curdate()
and ticket.status = 10 and ticket.status = 10
and ticket.usage_count < ticket.max_usage_count and ticket.count_move_out < ticket.max_usage_count
group by id_card group by id_card
order by id_card desc order by id_card desc
) as t ) as t
@ -57,7 +57,7 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
where ticket.start <= CURDATE() where ticket.start <= CURDATE()
and ticket.end >= curdate() and ticket.end >= curdate()
and ticket.status = 10 and ticket.status = 10
and ticket.usage_count < ticket.max_usage_count and ticket.count_move_out < ticket.max_usage_count
and ticket.id_card = :id and ticket.id_card = :id
group by id_card group by id_card
order by id_card desc order by id_card desc

View File

@ -0,0 +1,56 @@
<?php
namespace console\controllers;
use Yii;
use common\models;
use yii\console\Controller;
use common\models\Ticket;
use common\models\DoorLog;
class DoorlogController extends Controller{
public function actionIn()
{
$log = new DoorLog();
$log->id_card = 9719;
$log->id_customer = 5559;
$log->id_ticket_current = 10430;
$log->direction = 7;
$log->id_key = null;
$log->type = 0;
$log->source_app = DoorLog::$SOURCE_APP_FITNESS_ADMIN;
$log->id_account = null;
$log->card_flag = 0;
$log->flag_out= 0;
$log->save(false);
}
public function actionOut()
{
$log = new DoorLog();
$log->id_card = 9719;
$log->id_customer = 5559;
$log->id_ticket_current = 10430;
$log->direction = 5;
$log->id_key = null;
$log->type = 0;
$log->source_app = DoorLog::$SOURCE_APP_FITNESS_ADMIN;
$log->id_account = null;
$log->card_flag = 0;
$log->flag_out= 0;
$log->save(false);
}
}

View File

@ -0,0 +1,30 @@
<?php
use yii\db\Schema;
use yii\db\Migration;
class m160418_172543_add_move_aout extends Migration
{
public function up()
{
$this->addColumn("ticket", "count_move_out", "int default 0");
}
public function down()
{
echo "m160418_172543_add_move_aout cannot be reverted.\n";
return false;
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}

View File

@ -0,0 +1,30 @@
<?php
use yii\db\Schema;
use yii\db\Migration;
class m160418_180010_update_ticket_field_count_move_out extends Migration
{
public function up()
{
$this->execute(" update ticket set count_move_out = GREATEST(usage_count,0) ");
}
public function down()
{
echo "m160418_180010_update_ticket_field_count_move_out cannot be reverted.\n";
return false;
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}

View File

@ -0,0 +1,143 @@
<?php
use yii\db\Schema;
use yii\db\Migration;
class m160418_200934_add__trigger_move_in__and__move_out extends Migration
{
public function up()
{
$this->execute("
DROP TRIGGER IF EXISTS trigger_inc_ticket_usage_count;
DELIMITER $$
CREATE TRIGGER trigger_inc_ticket_usage_count
AFTER INSERT ON `door_log` FOR EACH ROW
begin
/*DECLARE p_usage_count Integer;*/
DECLARE p_count_all Integer;
DECLARE p_count_all_2 Integer;
DECLARE p_from DATETIME;
DECLARE p_usage_count Integer;
DECLARE p_max_usage_count Integer;
delete from devlog;
/** van vendég*/
IF NEW.id_customer is not null
/*van kártya*/
and NEW.id_card is not null
/**van bérlet*/
and NEW.id_ticket_current is not null
/**bemozgás volt*/
then
if NEW.direction = 7 then
insert into devlog ( msg) values('direction = in');
select count(*) into @p_count_all from door_log where created_at >= CURDATE() and id_ticket_current = New.id_ticket_current and direction = 7;
insert into devlog ( msg) values( concat( 'count all' ,@p_count_all ) );
IF @p_count_all = 1
THEN
select usage_count, max_usage_count into @p_usage_count ,@p_max_usage_count from ticket where id_ticket = NEW.id_ticket_current;
update ticket set usage_count = usage_count +1 where id_ticket = NEW.id_ticket_current;
insert into log (type,message, app, id_ticket, id_door_log,created_at, updated_at)
values(
30, concat('Bérlet használat (elotte: ',@p_usage_count, ' > utana: ' , @p_usage_count +1 , ' max: ', @p_max_usage_count, ')' ), ' trigger_inc_ticket',New.id_ticket_current, New.id_door_log,now(),now());
else
/**
Innentől kezdve biztos, hogy nem ez az első belépés az aktuális napon.
Ki kell számolnunk hányadik 3 órás intervallumban vagyunk az első belépéstől számítva.
Pl. ha 06:00 kor volt az első belépés, akkor 07: 30 még nem von le újabb használatot,
de a 09:00 már igen
*/
select min(created_at) + INTERVAL (3 * FLOOR( ( ( HOUR(TIMEDIFF(min(created_at) , now() )) /3 ) ) ) ) hour as last_date
into @p_from
from door_log
where created_at > CURDATE() and id_customer is not null;
/**
*/
-- select count(*) into @p_count_all_2 from door_log where created_at >= p_from and id_ticket_current ;
select count(*) into @p_count_all_2 from door_log where created_at >= @p_from and id_ticket_current = New.id_ticket_current and direction = 7;
-- insert into devlog ( msg) values(CONCAT( 'ticket count since last period begin: ', @p_count_all_2) );
/**
Ha az első belépéstől számítot aktuális 3 órás intervallumban ez az elős belépés, akkor növeljük a használatot
*/
IF @p_count_all_2 = 1
THEN
-- insert into devlog ( msg) values( 'need to increase usage count multiple intervals ' );
select usage_count, max_usage_count into @p_usage_count ,@p_max_usage_count from ticket where id_ticket = NEW.id_ticket_current;
update ticket set usage_count = usage_count +1 where id_ticket = New.id_ticket_current;
insert into log (type,message, app, id_ticket, id_door_log,created_at, updated_at)
values(
40, concat('Bérlet használat/egy nap tobbszori (elotte: ',@p_usage_count, ' > utana: ' , @p_usage_count +1 , ' max: ', @p_max_usage_count, ')' ), ' trigger_inc_ticket',New.id_ticket_current, New.id_door_log,now(),now());
END IF; -- end @p_count_all_2 = 1
END IF;
End IF; -- end type == 7 ( move in )
IF NEW.direction = 5 -- type move out
then
insert into devlog ( msg) values('bérlet kilépés...');
update ticket set count_move_out = count_move_out +1 where id_ticket = NEW.id_ticket_current;
END IF; -- end type move out
/**
Van e érvényes bérlet státusz frissítése a bérletkártyán
update card.flag and card.id_ticket_current
*/
-- insert into devlog ( msg) values( 'updateing card state' );
UPDATE card as c1
left JOIN ( select ticket.id_card as id_card , max(ticket.id_ticket) as id_ticket
from ticket
where ticket.start <= CURDATE()
and ticket.end >= curdate()
and ticket.status = 10
and ticket.count_move_out < ticket.max_usage_count
and ticket.id_card = New.id_card
group by id_card
order by id_card desc ) as t
on t.id_card = c1.id_card
SET c1.flag = case when t.id_card is null then ( c1.flag | 1 << 0 ) else ( c1.flag & ~(1 << 0) ) end
, c1.id_ticket_current = case when t.id_ticket is null then null else t.id_ticket end
WHERE c1.type <> 50 and c1.id_card = New.id_card;
END IF;
END;
$$
DELIMITER ;
");
}
public function down()
{
echo "m160418_200934_add__trigger_move_in__and__move_out cannot be reverted.\n";
return false;
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}