improve employee card validity calculation
This commit is contained in:
parent
6d93718aae
commit
6e66ab204d
@ -56,13 +56,16 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
|||||||
order by id_card desc
|
order by id_card desc
|
||||||
) as t
|
) as t
|
||||||
on t.id_card = c1.id_card
|
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
|
-- first bit is 0 , when there is a valid ticket or the card is 'employee' => 0000 0000
|
||||||
, c1.flag = case when t.id_card is null then ( c1.flag | 1 << 0 ) else ( c1.flag & ~(1 << 0) ) end
|
-- first bit is 1, when card is not employee and there is no valid card => 0000 0001
|
||||||
, c1.id_ticket_current = case when t.id_ticket is null then null else t.id_ticket 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
|
||||||
WHERE c1.type <> 50";
|
-- 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
|
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
|
from ticket
|
||||||
where ticket.start <= CURDATE()
|
where ticket.start <= CURDATE()
|
||||||
and ticket.end >= curdate()
|
and ticket.end >= curdate()
|
||||||
@ -73,10 +76,10 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
|||||||
order by id_card desc
|
order by id_card desc
|
||||||
) as t
|
) as t
|
||||||
on t.id_card = c1.id_card
|
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
|
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 t.id_card is null then ( c1.flag | 1 << 0 ) else ( c1.flag & ~(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
|
, 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";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user