/************************************
* Obetengo lo qu ehay que pagar dividiendo entre 15 el pado
************************************/
SELECT 
	CASE
		WHEN 12 > (HOUR(DATE_ADD(TIMEDIFF('2021-12-14 05:00:00',so.progress_date), INTERVAL IF(MINUTE(TIMEDIFF('2021-12-14 05:00:00',so.progress_date)) < 30, 0, 1) HOUR)))
		THEN 
			(12 - (HOUR(DATE_ADD(TIMEDIFF('2021-12-14 05:00:00',so.progress_date), INTERVAL IF(MINUTE(TIMEDIFF('2021-12-14 05:00:00',so.progress_date)) < 30, 0, 1) HOUR)))) 
				* 
            (tx.pay_day DIV 15)
		ELSE 0
	END AS total_to_pay,
    so.progress_date
FROM SERVICE_ORDER so
INNER JOIN TAXI tx ON so.taxi_id = tx.id
WHERE so.service_order_type = 'PROGRESS';
/************************************
* Con este query intento sacar la difencial de tiempo entre la fecha actual y la fecha de inicio de PROGRESS
************************************/
SELECT 
 TIMEDIFF('2021-12-14 05:00:00',so.progress_date),
DATEDIFF('2021-12-14',so.progress_date) AS '14',
DATEDIFF('2021-12-17',so.progress_date)  AS '17',
so.progress_date
FROM SERVICE_ORDER so
INNER JOIN TAXI tx ON so.taxi_id = tx.id
WHERE so.service_order_type = 'PROGRESS';