INSERT IGNORE INTO bm.events (title, image, start_date, end_date, text, payableWithCulturecard, reservation_id)  
SELECT name as title, thumb, startDate as start_date, endDate as end_date, "", 0, 3
  FROM old.bruckm_ticketevent WHERE reservationType = 'seat' AND startDate != 0000-00-00 AND endDate != 0000-00-00;
  
UPDATE IGNORE bm.events SET 
    title=convert(cast(convert(title using  latin1) as binary) using utf8);
  
  
  INSERT IGNORE INTO bm.seats(date, event_id)
SELECT start_date, id
  FROM bm.events WHERE start_date > CURDATE() and reservation_id = 3;

UPDATE IGNORE bm.events SET 
    price_cat_a=10, price_cat_b = 15, price_cat_c = 20
    where price_cat_a is null;

  INSERT IGNORE INTO bm.event_concessions(event_id, concession_id)
SELECT id, 1
  FROM bm.events WHERE start_date > CURDATE() and reservation_id = 3;



-- start empore

 INSERT IGNORE INTO bm.single_seats (seat_id, booked, category, y,x) 
	SELECT  (
		select (
			select  (
				select (
					select (
						select id from bm.seats where event_id = test4.id limit 1
					)from bm.events as test4 where image like test3.thumb limit 1
				)  from old.bruckm_ticketevent as test3 where id = test2.eventId limit 1
			)  from old.bruckm_ticketdate as test2 where id = test1.dateId  limit 1
		)  from old.bruckm_ticket as test1 where dateId = myOuterTicket.dateId limit 1
    ),1,'a', seat+19, row+17 
    FROM old.bruckm_ticket as myOuterTicket
    where floor = "Empore" and row = 6;
    
    
    
    
    
 INSERT IGNORE INTO bm.single_seats (seat_id, booked, category, y,x) SELECT (
		select (
			select  (
				select (
					select (
						select id from bm.seats where event_id = test4.id limit 1
					)from bm.events as test4 where image like test3.thumb limit 1
				)  from old.bruckm_ticketevent as test3 where id = test2.eventId limit 1
			)  from old.bruckm_ticketdate as test2 where id = test1.dateId  limit 1
		)  from old.bruckm_ticket as test1 where dateId = myOuterTicket.dateId limit 1
    ),1,'a', IF(seat+13>17,seat+13+2, seat+13), row+17 FROM old.bruckm_ticket as myOuterTicket where floor = "Empore" and row = 5;
 
 
 INSERT IGNORE INTO bm.single_seats (seat_id, booked, category, y,x) SELECT (
		select (
			select  (
				select (
					select (
						select id from bm.seats where event_id = test4.id limit 1
					)from bm.events as test4 where image like test3.thumb limit 1
				)  from old.bruckm_ticketevent as test3 where id = test2.eventId limit 1
			)  from old.bruckm_ticketdate as test2 where id = test1.dateId  limit 1
		)  from old.bruckm_ticket as test1 where dateId = myOuterTicket.dateId limit 1
    ),1,'a', IF(seat+9>17,seat+9+2, seat+9) , row+17 FROM old.bruckm_ticket  as myOuterTicket where floor = "Empore" and row = 4;
 
 
 
 INSERT IGNORE INTO bm.single_seats (seat_id, booked, category, y,x) SELECT (
		select (
			select  (
				select (
					select (
						select id from bm.seats where event_id = test4.id limit 1
					)from bm.events as test4 where image like test3.thumb limit 1
				)  from old.bruckm_ticketevent as test3 where id = test2.eventId limit 1
			)  from old.bruckm_ticketdate as test2 where id = test1.dateId  limit 1
		)  from old.bruckm_ticket as test1 where dateId = myOuterTicket.dateId limit 1
    ),1,'a', IF(seat+5>17,seat+5+2, seat+5) , row+17 FROM old.bruckm_ticket  as myOuterTicket where  floor = "Empore" and row = 3;
 
 INSERT IGNORE INTO bm.single_seats (seat_id, booked, category, y,x) SELECT (
		select (
			select  (
				select (
					select (
						select id from bm.seats where event_id = test4.id limit 1
					)from bm.events as test4 where image like test3.thumb limit 1
				)  from old.bruckm_ticketevent as test3 where id = test2.eventId limit 1
			)  from old.bruckm_ticketdate as test2 where id = test1.dateId  limit 1
		)  from old.bruckm_ticket as test1 where dateId = myOuterTicket.dateId limit 1
    ),1,'a', IF(seat+2>17,seat+2+2, seat+2) , row+17 FROM old.bruckm_ticket as myOuterTicket where floor = "Empore" and row = 2;
 
 
 
 INSERT IGNORE INTO bm.single_seats (seat_id, booked, category, y,x) SELECT (
		select (
			select  (
				select (
					select (
						select id from bm.seats where event_id = test4.id limit 1
					)from bm.events as test4 where image like test3.thumb limit 1
				)  from old.bruckm_ticketevent as test3 where id = test2.eventId limit 1
			)  from old.bruckm_ticketdate as test2 where id = test1.dateId  limit 1
		)  from old.bruckm_ticket as test1 where dateId = myOuterTicket.dateId limit 1
    ),1,'a', IF(seat+3>17,seat+3+2, seat+3), row+17 FROM old.bruckm_ticket as myOuterTicket where floor = "Empore" and row = 1;
  

-- end empore


-- start first block (1-6)

  
  INSERT IGNORE INTO bm.single_seats (seat_id, booked, category, y,x) 
	SELECT  (
		select (
			select  (
				select (
					select (
						select id from bm.seats where event_id = test4.id limit 1
					)from bm.events as test4 where image like test3.thumb limit 1
				)  from old.bruckm_ticketevent as test3 where id = test2.eventId limit 1
			)  from old.bruckm_ticketdate as test2 where id = test1.dateId limit 1
		)  from old.bruckm_ticket as test1 where dateId = myOuterTicket.dateId limit 1
    ),1,'a', IF(seat>12,seat+1, seat), row 
    FROM old.bruckm_ticket as myOuterTicket
    where floor = "Erdgeschoss" and row <= 6;
-- end first block


-- start second block 
 INSERT IGNORE INTO bm.single_seats (seat_id, booked, category, y,x) 
	SELECT  (
		select (
			select  (
				select (
					select (
						select id from bm.seats where event_id = test4.id limit 1
					)from bm.events as test4 where image like test3.thumb limit 1
				)  from old.bruckm_ticketevent as test3 where id = test2.eventId limit 1
			)  from old.bruckm_ticketdate as test2 where id = test1.dateId  limit 1
		)  from old.bruckm_ticket as test1 where dateId = myOuterTicket.dateId limit 1
    ),1,'a', IF(seat>12,seat+1, seat), row+1 
    FROM old.bruckm_ticket as myOuterTicket
    where floor = "Erdgeschoss" and row >= 7 and row <= 8;
    
INSERT  IGNORE INTO bm.single_seats (seat_id, booked, category, y,x) 
	SELECT  (
		select (
			select  (
				select (
					select (
						select id from bm.seats where event_id = test4.id limit 1
					)from bm.events as test4 where image like test3.thumb limit 1
				)  from old.bruckm_ticketevent as test3 where id = test2.eventId limit 1
			)  from old.bruckm_ticketdate as test2 where id = test1.dateId  limit 1
		)  from old.bruckm_ticket as test1 where dateId = myOuterTicket.dateId limit 1
    ),1,'a', IF(seat+1>12,seat+1+1, seat+1), row+1 
    FROM old.bruckm_ticket as myOuterTicket
    where floor = "Erdgeschoss" and row = 9;
    
INSERT IGNORE INTO bm.single_seats (seat_id, booked, category, y,x) 
	SELECT  (
		select (
			select  (
				select (
					select (
						select id from bm.seats where event_id = test4.id limit 1
					)from bm.events as test4 where image like test3.thumb limit 1
				)  from old.bruckm_ticketevent as test3 where id = test2.eventId limit 1
			)  from old.bruckm_ticketdate as test2 where id = test1.dateId  limit 1
		)  from old.bruckm_ticket as test1 where dateId = myOuterTicket.dateId limit 1
    ),1,'a', IF(seat+2>12,seat+2+1, seat+2), row+1 
    FROM old.bruckm_ticket as myOuterTicket
    where floor = "Erdgeschoss" and row = 10;    
    
INSERT IGNORE INTO bm.single_seats (seat_id, booked, category, y,x) 
	SELECT  (
		select (
			select  (
				select (
					select (
						select id from bm.seats where event_id = test4.id limit 1
					)from bm.events as test4 where image like test3.thumb limit 1
				)  from old.bruckm_ticketevent as test3 where id = test2.eventId limit 1
			)  from old.bruckm_ticketdate as test2 where id = test1.dateId  limit 1
		)  from old.bruckm_ticket as test1 where dateId = myOuterTicket.dateId limit 1
    ),1,'a', IF(seat+5>12,seat+5+1, seat+5), row+1 
    FROM old.bruckm_ticket as myOuterTicket
    where floor = "Erdgeschoss" and row = 11;       
    
INSERT IGNORE INTO bm.single_seats (seat_id, booked, category, y,x) 
	SELECT  (
		select (
			select  (
				select (
					select (
						select id from bm.seats where event_id = test4.id limit 1
					)from bm.events as test4 where image like test3.thumb limit 1
				)  from old.bruckm_ticketevent as test3 where id = test2.eventId limit 1
			)  from old.bruckm_ticketdate as test2 where id = test1.dateId  limit 1
		)  from old.bruckm_ticket as test1 where dateId = myOuterTicket.dateId limit 1
    ),1,'a', IF(seat+8>12,seat+8+1, seat+8), row+1 
    FROM old.bruckm_ticket as myOuterTicket
    where floor = "Erdgeschoss" and row = 12;    
    
    
INSERT IGNORE INTO bm.single_seats (seat_id, booked, category, y,x) 
	SELECT  (
		select (
			select  (
				select (
					select (
						select id from bm.seats where event_id = test4.id limit 1
					)from bm.events as test4 where image like test3.thumb limit 1
				)  from old.bruckm_ticketevent as test3 where id = test2.eventId limit 1
			)  from old.bruckm_ticketdate as test2 where id = test1.dateId  limit 1
		)  from old.bruckm_ticket as test1 where dateId = myOuterTicket.dateId limit 1
    ),1,'a', IF(seat+12>12,seat+12+1, seat+12), row+1 
    FROM old.bruckm_ticket as myOuterTicket
    where floor = "Erdgeschoss" and row = 13;      
-- end second block

