improve employee card validity calculation

This commit is contained in:
Roland Schneider 2019-06-03 18:10:32 +02:00
parent 6d93718aae
commit 6e66ab204d

View File

@ -56,13 +56,16 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
order by id_card desc
) as t
on t.id_card = c1.id_card
SET c1.validity = case when t.id_card is null then ( c1.validity | 1 << 0 ) else ( c1.validity & ~(1 << 0) ) end
, 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";
-- first bit is 0 , when there is a valid ticket or the card is 'employee' => 0000 0000
-- first bit is 1, when card is not employee and there is no valid card => 0000 0001
SET c1.validity = case when c1.type = 50 then ( c1.validity & ~(1 << 0) ) when t.id_card is null then ( c1.validity | 1 << 0 ) else ( c1.validity & ~(1 << 0) ) end
-- first bit is 0 when there is a ticket or 'employee' card 0000 0000
-- first bit is 1 when there is no ticket and card type is not 'employee'
, c1.flag = case when c1.type = 50 then ( c1.flag & ~(1 << 0) ) 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";
public static $SQL_UPDATE_CARD = "UPDATE card as c1
left JOIN ( select ticket.id_card as id_card , max(ticket.id_ticket) as id_ticket
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()
@ -73,10 +76,10 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
order by id_card desc
) as t
on t.id_card = c1.id_card
SET c1.validity = case when t.id_card is null then ( c1.validity | 1 << 0 ) else ( c1.validity & ~(1 << 0) ) end
,c1.flag = case when t.id_card is null then ( c1.flag | 1 << 0 ) else ( c1.flag & ~(1 << 0) ) end
SET c1.validity = case when c1.type = 50 then ( c1.validity & ~(1 << 0) ) when t.id_card is null then ( c1.validity | 1 << 0 ) else ( c1.validity & ~(1 << 0) ) end
,c1.flag = case when c1.type = 50 then ( c1.flag & ~(1 << 0) ) 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 = :id";
WHERE c1.id_card = :id";