fix dashboard using needed angeltypes from room config too for frab shifts
This commit is contained in:
parent
952dc6921a
commit
35be25a786
|
@ -32,13 +32,25 @@ function Shifts_by_angeltype($angeltype) {
|
|||
function Shifts_free($start, $end)
|
||||
{
|
||||
$shifts = Db::select("
|
||||
SELECT *
|
||||
FROM `Shifts`
|
||||
WHERE (`end` > ? AND `start` < ?)
|
||||
AND (SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`)
|
||||
> (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0)
|
||||
ORDER BY `start`
|
||||
SELECT * FROM (
|
||||
SELECT *
|
||||
FROM `Shifts`
|
||||
WHERE (`end` > ? AND `start` < ?)
|
||||
AND (SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`)
|
||||
> (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0)
|
||||
|
||||
UNION
|
||||
|
||||
SELECT *
|
||||
FROM `Shifts`
|
||||
WHERE (`end` > ? AND `start` < ?)
|
||||
AND (SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`room_id`=`Shifts`.`RID`)
|
||||
> (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0)
|
||||
) as `tmp`
|
||||
ORDER BY `tmp`.`start`
|
||||
", [
|
||||
$start,
|
||||
$end,
|
||||
$start,
|
||||
$end
|
||||
]);
|
||||
|
|
|
@ -27,12 +27,25 @@ function stats_currently_working()
|
|||
function stats_hours_to_work()
|
||||
{
|
||||
$result = Db::selectOne("
|
||||
SELECT ROUND(SUM(
|
||||
(SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`)
|
||||
* (`Shifts`.`end` - `Shifts`.`start`)/3600
|
||||
)) as `count`
|
||||
FROM `Shifts`
|
||||
WHERE `end` >= ?", [
|
||||
SELECT ROUND(SUM(`count`)) as `count` FROM (
|
||||
SELECT
|
||||
(SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`)
|
||||
* (`Shifts`.`end` - `Shifts`.`start`)/3600 as `count`
|
||||
FROM `Shifts`
|
||||
WHERE `end` >= ?
|
||||
AND `Shifts`.`PSID` IS NULL
|
||||
|
||||
UNION
|
||||
|
||||
SELECT
|
||||
(SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`room_id`=`Shifts`.`RID`)
|
||||
* (`Shifts`.`end` - `Shifts`.`start`)/3600 as `count`
|
||||
FROM `Shifts`
|
||||
WHERE `end` >= ?
|
||||
AND NOT `Shifts`.`PSID` IS NULL
|
||||
) as `tmp`
|
||||
", [
|
||||
time(),
|
||||
time()
|
||||
]);
|
||||
if (empty($result['count'])) {
|
||||
|
@ -49,12 +62,27 @@ function stats_angels_needed_three_hours()
|
|||
$now = time();
|
||||
$in3hours = $now + 3 * 60 * 60;
|
||||
$result = Db::selectOne("
|
||||
SELECT SUM(
|
||||
(SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`)
|
||||
- (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0)
|
||||
) as `count`
|
||||
FROM `Shifts`
|
||||
WHERE `end` > ? AND `start` < ?", [
|
||||
SELECT SUM(`count`) as `count` FROM (
|
||||
SELECT
|
||||
(SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`)
|
||||
- (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0)
|
||||
as `count`
|
||||
FROM `Shifts`
|
||||
WHERE `end` > ? AND `start` < ?
|
||||
AND `Shifts`.`PSID` IS NULL
|
||||
|
||||
UNION
|
||||
|
||||
SELECT
|
||||
(SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`room_id`=`Shifts`.`RID`)
|
||||
- (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0)
|
||||
as `count`
|
||||
FROM `Shifts`
|
||||
WHERE `end` > ? AND `start` < ?
|
||||
AND NOT `Shifts`.`PSID` IS NULL
|
||||
) as `tmp`", [
|
||||
$now,
|
||||
$in3hours,
|
||||
$now,
|
||||
$in3hours
|
||||
]);
|
||||
|
@ -72,12 +100,27 @@ function stats_angels_needed_for_nightshifts()
|
|||
$night_start = parse_date('Y-m-d H:i', date('Y-m-d', time() + 12 * 60 * 60) . ' 02:00');
|
||||
$night_end = $night_start + 6 * 60 * 60;
|
||||
$result = Db::selectOne("
|
||||
SELECT SUM(
|
||||
(SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`)
|
||||
- (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0)
|
||||
) as `count`
|
||||
FROM `Shifts`
|
||||
WHERE `end` > ? AND `start` < ?", [
|
||||
SELECT SUM(`count`) as `count` FROM (
|
||||
SELECT
|
||||
(SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`)
|
||||
- (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0)
|
||||
as `count`
|
||||
FROM `Shifts`
|
||||
WHERE `end` > ? AND `start` < ?
|
||||
AND `Shifts`.`PSID` IS NULL
|
||||
|
||||
UNION
|
||||
|
||||
SELECT
|
||||
(SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`room_id`=`Shifts`.`RID`)
|
||||
- (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0)
|
||||
as `count`
|
||||
FROM `Shifts`
|
||||
WHERE `end` > ? AND `start` < ?
|
||||
AND NOT `Shifts`.`PSID` IS NULL
|
||||
) as `tmp`", [
|
||||
$night_start,
|
||||
$night_end,
|
||||
$night_start,
|
||||
$night_end
|
||||
]);
|
||||
|
|
Loading…
Reference in New Issue