Created
February 23, 2017 02:28
-
-
Save bfrigon/0d3cf05437ad89e34803243f881fb734 to your computer and use it in GitHub Desktop.
YAAM MySQL Database setup (trigger for cdr insert)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELIMITER $$ | |
DROP TRIGGER IF EXISTS asterisk.cdr_update_cost$$ | |
CREATE DEFINER=`root`@`localhost` TRIGGER `asterisk`.`cdr_update_cost` BEFORE INSERT ON `cdr` FOR EACH ROW | |
BEGIN | |
declare _min INTEGER; | |
declare _cost FLOAT; | |
declare _inc INTEGER; | |
DECLARE EXIT HANDLER FOR NOT FOUND BEGIN | |
SET NEW.cost=0; | |
END; | |
SELECT | |
cost, min, increment | |
INTO _cost , _min , _inc FROM | |
cdr_routes | |
WHERE | |
name = NEW.route_name; | |
SET _inc = GREATEST(_inc,1); | |
IF (NEW.billsec > 0) THEN | |
SET NEW.billsec = GREATEST(_min, ceil(NEW.billsec / _inc) * _inc); | |
END IF; | |
SET NEW.cost = (NEW.billsec/60) * _cost; | |
END$$ | |
DELIMITER ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment