SELECT
    `reservations`.`ID`,
    `tickets`.`ID` AS `TicketID`,
    `tickets`.`PostDate`
FROM
    `reservations`
    INNER JOIN `additionaloffers` ON `reservations`.`ProgramID` = `additionaloffers`.`ProgramID`
    INNER JOIN `events` ON `additionaloffers`.`EventID` = `events`.`ID`
    INNER JOIN `tickets` ON `tickets`.`OrderID` = `reservations`.`ID`
WHERE
    `reservations`.`ProgramID` = 1353 AND
    `reservations`.`Status` & 16 AND
    `reservations`.`Status` & 128 AND
    `reservations`.`Progress` = 5


UPDATE `reservations` SET `Status` = `Status` - 128 WHERE `ID` = 1076408 LIMIT 1



-- INFO: iztriwa biletite
-- total: 8476
-- for delete: 32
DELETE FROM `tickets` WHERE `ID` IN (
    SELECT
        `tickets`.`ID` AS `TicketID`
    FROM
        `reservations`
        INNER JOIN `additionaloffers` ON `reservations`.`ProgramID` = `additionaloffers`.`ProgramID`
        INNER JOIN `events` ON `additionaloffers`.`EventID` = `events`.`ID`
        INNER JOIN `tickets` ON `tickets`.`OrderID` = `reservations`.`ID`
    WHERE
        `reservations`.`ProgramID` = 1353 AND
        `reservations`.`Status` & 16 AND
        `reservations`.`Status` & 128 AND
        `reservations`.`Progress` = 5
);

-- INFO: resetwa izprashtaneto i statusite na rezervaciqta
UPDATE `reservations` SET `Status` = `Status` - 128 WHERE `ID` IN (
    SELECT
        `reservations`.`ID`
    FROM
        `reservations`
        INNER JOIN `additionaloffers` ON `reservations`.`ProgramID` = `additionaloffers`.`ProgramID`
        INNER JOIN `events` ON `additionaloffers`.`EventID` = `events`.`ID`
    WHERE
        `reservations`.`ProgramID` = 1353 AND
        `reservations`.`Status` & 16 AND
        `reservations`.`Status` & 128 AND
        `reservations`.`Progress` = 5
);