Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BEGIN
- DECLARE _payment VARCHAR(5) DEFAULT '';
- DECLARE _column_id INT DEFAULT 0;
- DECLARE _time INT DEFAULT 0;
- DECLARE _group_id INT DEFAULT 0;
- DECLARE _zone_id INT DEFAULT 0;
- DECLARE _notify_sms INT DEFAULT 0;
- DECLARE _is_important INT DEFAULT 0;
- DECLARE _with_driver INT DEFAULT 0;
- DECLARE _loaders_count INT DEFAULT 0;
- DECLARE _car_type INT DEFAULT 0;
- DECLARE _client_id INT DEFAULT 0;
- DECLARE _consider_curator INT DEFAULT 0;
- DECLARE _is_coordinator BOOLEAN DEFAULT FALSE;
- DECLARE _exist_user_coordinator BOOLEAN DEFAULT FALSE;
- DECLARE _result INT DEFAULT 0;
- SELECT
- o.`payment`,
- o.`column_id`,
- o.`zone_id`,
- o.`notify_sms`,
- c.`is_important`,
- IF(o.`driver_id` > 0, 1, 0),
- o.`cargo_count`,
- o.`vehicle_type_id`,
- o.`client_id`
- INTO
- _payment,
- _column_id,
- _zone_id,
- _notify_sms,
- _is_important,
- _with_driver,
- _loaders_count,
- _car_type,
- _client_id
- FROM
- `orders` as o
- JOIN
- `clients` as c ON c.`id` = o.`client_id`
- WHERE
- o.`id` = order_id
- LIMIT 1;
- SELECT
- u.`group_id`,
- u.`is_coordinator`
- INTO
- _group_id,
- _is_coordinator
- FROM
- `users` as u
- WHERE
- u.`id` = user_id
- LIMIT 1;
- SELECT
- IF(time_type = 1,o.`time_visibility`,o.`time_assignment`),
- o.consider_curator
- INTO
- _time,
- _consider_curator
- FROM
- `orders_scopes` as o
- WHERE
- (o.`payment_types` LIKE CONCAT('%| ',_payment,' |%') OR o.`payment_types` LIKE '%-1%') AND
- (o.`column_ids` LIKE CONCAT('%| ',_column_id,' |%') OR o.`column_ids` LIKE '%-1%') AND
- (o.`group_ids` LIKE CONCAT('%| ',_group_id,' |%') OR o.`group_ids` LIKE '%-1%') AND
- (o.`zone_ids` LIKE CONCAT('%| ',_zone_id,' |%') OR o.`zone_ids` LIKE '%-1%') AND
- (o.`notify_sms` LIKE CONCAT('%| ',_notify_sms,' |%') OR o.`notify_sms` LIKE '%-1%') AND
- (o.`important_client` LIKE CONCAT('%| ',_is_important,' |%') OR o.`important_client` LIKE '%-1%') AND
- (o.`with_driver` LIKE CONCAT('%| ',_with_driver,' |%') OR o.`with_driver` LIKE '%-1%') AND
- (o.`loaders_count` LIKE CONCAT('%| ',_loaders_count,' |%') OR o.`loaders_count` LIKE '%-1%') AND
- (o.`car_types` LIKE CONCAT('%| ',_car_type,' |%') OR o.`car_types` LIKE '%-1%')
- ORDER BY
- o.`id` DESC
- LIMIT 1;
- IF (_consider_curator = TRUE) THEN
- IF (_is_coordinator = TRUE) THEN
- SELECT EXISTS(
- SELECT 1 FROM client_user_coordinator
- WHERE `client_user_coordinator`.`client_id` = _client_id AND `client_user_coordinator`.`user_id` = user_id
- LIMIT 1
- )
- INTO
- _exist_user_coordinator;
- IF (_exist_user_coordinator = TRUE) THEN
- SET _result = _time;
- END IF;
- END IF;
- ELSE
- SET _result = _time;
- END IF;
- RETURN _result;
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement