UPDATE _ProjectTask INNER JOIN _Case ON _ProjectTask Case _Case ID INN

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
UPDATE
_ProjectTask INNER JOIN _Case ON (
_ProjectTask.Case = _Case.ID
) INNER JOIN _BriefStep ON (
_BriefStep.ID = _ProjectTask.Step
) INNER JOIN _BriefPhase ON (
_BriefPhase.ID = _ProjectTask.Phase
)
SET
_ProjectTask.Status = (
CASE _Case.Status
WHEN (
"NOT_ACTIVE"
) THEN (
"CANCELED_IN_THE_CASE"
)
WHEN (
"PAUSE"
) THEN (
IF (
_ProjectTask.Status = "NEW" OR _ProjectTask.Status = "DELAY" OR _ProjectTask.Status = "NO_ACTIVE",
"FROZEN",
_ProjectTask.Status
)
)
WHEN (
"ACTIVE"
) THEN (
IF (
_BriefPhase.Active
AND
(
SELECT
IF (COUNT(*) = 0, TRUE, SUM(_BriefCondition.Ok) > 0)
FROM
_BriefCondition INNER JOIN _ProjectTaskCondition ON (
_BriefCondition.ID = _ProjectTaskCondition._BriefCondition
)
WHERE
_ProjectTaskCondition._ProjectTask = _ProjectTask.ID
),
IF (DATE(NOW()) <= DATE(DATE_ADD(_BriefStep.Date, INTERVAL _ProjectTask.Deadline DAY)), "NEW", "DELAY"),
"CANCELED_IN_THE_CASE"
)
)
ELSE
_ProjectTask.Status
END
)
WHERE
1