Revision 3eab069a
Von Bernd Bleßmann vor mehr als 2 Jahren hinzugefügt
SL/FU.pm | ||
---|---|---|
35 | 35 |
if (!$params{id}) { |
36 | 36 |
($params{id}) = selectrow_query($form, $dbh, qq|SELECT nextval('follow_up_id')|); |
37 | 37 |
|
38 |
$query = qq|INSERT INTO follow_ups (created_by, done, note_id, follow_up_date, id)
|
|
39 |
VALUES ((SELECT id FROM employee WHERE login = ?), ?, ?, ?, ?)|;
|
|
38 |
$query = qq|INSERT INTO follow_ups (created_by, note_id, follow_up_date, id) |
|
39 |
VALUES ((SELECT id FROM employee WHERE login = ?), ?, ?, ?)|; |
|
40 | 40 |
|
41 | 41 |
push @values, $::myconfig{login}; |
42 | 42 |
|
43 | 43 |
} else { |
44 |
$query = qq|UPDATE follow_ups SET done = ?, note_id = ?, follow_up_date = ? WHERE id = ?|;
|
|
44 |
$query = qq|UPDATE follow_ups SET note_id = ?, follow_up_date = ? WHERE id = ?|; |
|
45 | 45 |
} |
46 | 46 |
|
47 | 47 |
$params{note_id} = Notes->save('id' => $params{note_id}, |
... | ... | |
51 | 51 |
'body' => $params{body}, |
52 | 52 |
'dbh' => $dbh,); |
53 | 53 |
|
54 |
$params{done} = 1 if (!defined $params{done});
|
|
54 |
do_query($form, $dbh, $query, @values, conv_i($params{note_id}), $params{follow_up_date}, conv_i($params{id}));
|
|
55 | 55 |
|
56 |
do_query($form, $dbh, $query, @values, $params{done} ? 't' : 'f', conv_i($params{note_id}), $params{follow_up_date}, conv_i($params{id})); |
|
56 |
$params{done} = 1 if (!defined $params{done}); |
|
57 |
if ($params{done}) { |
|
58 |
do_query($form, $dbh, qq|INSERT INTO follow_up_done (follow_up_id, employee_id) VALUES (?, (SELECT id FROM employee WHERE login = ?))|, |
|
59 |
conv_i($params{id}), $::myconfig{login}); |
|
60 |
} else { |
|
61 |
do_query($form, $dbh, qq|DELETE FROM follow_up_done WHERE follow_up_id = ?|, conv_i($params{id})); |
|
62 |
} |
|
57 | 63 |
|
58 | 64 |
do_query($form, $dbh, qq|DELETE FROM follow_up_links WHERE follow_up_id = ?|, conv_i($params{id})); |
59 | 65 |
|
... | ... | |
89 | 95 |
my $myconfig = \%main::myconfig; |
90 | 96 |
my $form = $main::form; |
91 | 97 |
|
92 |
SL::DB->client->with_transaction(sub { |
|
93 |
do_query($form, SL::DB->client->dbh, qq|UPDATE follow_ups SET done = TRUE WHERE id = ?|, conv_i($params{id})); |
|
94 |
1; |
|
95 |
}) or do { die SL::DB->client->error }; |
|
98 |
my ($done) = selectrow_query($::form, SL::DB->client->dbh, qq|SELECT id FROM follow_up_done WHERE follow_up_id = ?|, conv_i($params{id})); |
|
99 |
if (!$done) { |
|
100 |
SL::DB->client->with_transaction(sub { |
|
101 |
do_query($form, SL::DB->client->dbh, qq|INSERT INTO follow_up_done (follow_up_id, employee_id) VALUES (?, (SELECT id FROM employee WHERE login = ?))|, |
|
102 |
conv_i($params{id}), $myconfig->{login}); |
|
103 |
1; |
|
104 |
}) or do { die SL::DB->client->error }; |
|
105 |
} |
|
96 | 106 |
|
97 | 107 |
$main::lxdebug->leave_sub(); |
98 | 108 |
} |
... | ... | |
137 | 147 |
my ($query, @values); |
138 | 148 |
|
139 | 149 |
my ($employee_id) = selectrow_query($form, $dbh, qq|SELECT id FROM employee WHERE login = ?|, $::myconfig{login}); |
140 |
$query = qq|SELECT fu.*, n.subject, n.body, n.created_by |
|
150 |
$query = qq|SELECT fu.*, n.subject, n.body, n.created_by, |
|
151 |
follow_up_done.follow_up_id AS done, |
|
152 |
date_trunc('second', follow_up_done.done_at) AS done_at, |
|
153 |
COALESCE(done_by.name, done_by.login) AS done_by_employee_name |
|
141 | 154 |
FROM follow_ups fu |
142 | 155 |
LEFT JOIN notes n ON (fu.note_id = n.id) |
143 | 156 |
LEFT JOIN follow_up_created_for_employees ON (follow_up_created_for_employees.follow_up_id = fu.id) |
157 |
LEFT JOIN follow_up_done ON (follow_up_done.follow_up_id = fu.id) |
|
158 |
LEFT JOIN employee done_by ON (follow_up_done.employee_id = done_by.id) |
|
144 | 159 |
WHERE (fu.id = ?) |
145 | 160 |
AND ( (fu.created_by = ?) OR (follow_up_created_for_employees.employee_id = ?) |
146 | 161 |
OR (fu.created_by IN (SELECT DISTINCT what FROM follow_up_access WHERE who = ?)))|; |
... | ... | |
219 | 234 |
|
220 | 235 |
if ($params{done} ne $params{not_done}) { |
221 | 236 |
my $not = $params{not_done} ? 'NOT' : ''; |
222 |
$where .= qq| AND $not COALESCE(fu.done, FALSE)|;
|
|
237 |
$where .= qq| AND $not EXISTS (SELECT id FROM follow_up_done WHERE follow_up_id = fu.id)|;
|
|
223 | 238 |
} |
224 | 239 |
|
225 | 240 |
if ($params{not_id}) { |
... | ... | |
286 | 301 |
$query = qq|SELECT DISTINCT fu.*, n.subject, n.body, n.created_by, |
287 | 302 |
fu.follow_up_date <= current_date AS due, |
288 | 303 |
fu.itime::DATE AS created_on, |
289 |
COALESCE(eby.name, eby.login) AS created_by_name |
|
304 |
COALESCE(eby.name, eby.login) AS created_by_name, |
|
305 |
follow_up_done.follow_up_id AS done |
|
290 | 306 |
FROM follow_ups fu |
291 | 307 |
LEFT JOIN notes n ON (fu.note_id = n.id) |
292 | 308 |
LEFT JOIN employee eby ON (n.created_by = eby.id) |
293 | 309 |
LEFT JOIN follow_up_created_for_employees ON (follow_up_created_for_employees.follow_up_id = fu.id) |
310 |
LEFT JOIN follow_up_done ON (follow_up_done.follow_up_id = fu.id) |
|
294 | 311 |
WHERE ((fu.created_by = ?) OR (follow_up_created_for_employees.employee_id = ?) |
295 | 312 |
$where_user) |
296 | 313 |
$where |
Auch abrufbar als: Unified diff
Wiedervorlagen: Mehr Infos über Abschluss speichern und in den Masken zeigen