342 | | |
343 | | |
344 | | |
345 | | }}} |
| 342 | }}} |
| 343 | |
| 344 | == Zapytanie dla "moich zadań workflow" == |
| 345 | |
| 346 | {{{ |
| 347 | SELECT keyval, |
| 348 | dscrpt, |
| 349 | clsnam, |
| 350 | ptstnm, |
| 351 | dctpid, |
| 352 | prtpnm, |
| 353 | end___, |
| 354 | ptstid |
| 355 | FROM procedures_def |
| 356 | RIGHT JOIN ( |
| 357 | SELECT (doc_id) AS keyval, |
| 358 | p2.prtpid, |
| 359 | substr(d.dscrpt, 0, 100) AS dscrpt, |
| 360 | 'DOCUMENT' AS clsnam, |
| 361 | end___, |
| 362 | s.ptstnm, |
| 363 | d.dctpid, |
| 364 | ptstid, |
| 365 | orgarr |
| 366 | FROM procedures pd |
| 367 | LEFT JOIN stages s USING(procid) |
| 368 | LEFT JOIN procedures p2 ON (p2.procid = pd.rootpr) |
| 369 | LEFT JOIN bpm_loops_def bld USING(ptstid) |
| 370 | RIGHT JOIN documents d ON (d.procid = p2.procid) |
| 371 | LEFT JOIN ( |
| 372 | SELECT doc_id, text_sum(attrib::text) AS attrib |
| 373 | FROM ( |
| 374 | SELECT * |
| 375 | FROM ( |
| 376 | SELECT doc_id, coalesce(attrib, '-'::text) AS attrib, CASE WHEN grp_id IS NULL THEN -1 ELSE ul.prior_ END AS prior_, CASE WHEN dlu.usr_id IS NULL THEN ul.usr_id ELSE dlu.usr_id END AS usr_id |
| 377 | FROM doc_link_users dlu |
| 378 | LEFT JOIN users_link_group ul USING(grp_id) |
| 379 | WHERE TRUE AND (dlu.usr_id = 2 OR ul.usr_id = 2) |
| 380 | ) AS foo |
| 381 | ORDER BY usr_id, prior_ ASC |
| 382 | ) AS foo2 |
| 383 | GROUP BY doc_id |
| 384 | ) AS dolu USING (doc_id) |
| 385 | WHERE (bld.multii IS NOT TRUE OR s.prn_id IS NOT NULL) |
| 386 | AND s.ptsttp != 'SUBPROCESS' |
| 387 | AND ((dolu.attrib ~ '^r') OR (dolu.attrib IS NULL AND (prionl IS NOT TRUE OR d.adduid = 2))) |
| 388 | AND ((ARRAY[1] && s.orgarr) OR (s.orgarr IS NULL AND d.target = ANY(ARRAY[1]))) AND d.is_del IS NOT TRUE AND gostof IS NULL AND sop_id IS NOT NULL AND s.is_act IS TRUE AND pd.comple IS NOT TRUE AND ptsttp != 'START' |
| 389 | |
| 390 | UNION |
| 391 | SELECT (prc_id) AS keyval, |
| 392 | p2.prtpid, |
| 393 | substr(p.dscrpt, 0, 100) AS dscrpt, |
| 394 | 'PROCESS' AS clsnam, |
| 395 | end___, |
| 396 | s.ptstnm, |
| 397 | 0 AS dctpid, |
| 398 | ptstid, |
| 399 | orgarr |
| 400 | FROM procedures pd |
| 401 | LEFT JOIN stages s USING(procid) |
| 402 | LEFT JOIN procedures p2 ON (p2.procid = pd.rootpr) |
| 403 | LEFT JOIN bpm_loops_def bld USING(ptstid) |
| 404 | RIGHT JOIN processes p ON (p.procid = p2.procid) |
| 405 | WHERE (bld.multii IS NOT TRUE |
| 406 | OR s.prn_id IS NOT NULL) |
| 407 | AND s.ptsttp != 'SUBPROCESS' |
| 408 | AND p.is_fix IS FALSE |
| 409 | AND p.is_del IS FALSE |
| 410 | AND (ARRAY[1] && s.orgarr) |
| 411 | AND sop_id IS NOT NULL |
| 412 | AND s.is_act IS TRUE |
| 413 | AND pd.comple IS NOT TRUE |
| 414 | AND ptsttp != 'START' |
| 415 | UNION |
| 416 | SELECT (rcp_id) AS keyval, |
| 417 | p2.prtpid, |
| 418 | substr(p.dscrpt, 0, 100) AS dscrpt, |
| 419 | 'RCP' AS clsnam, |
| 420 | end___, |
| 421 | s.ptstnm, |
| 422 | 0 AS dctpid, |
| 423 | ptstid, |
| 424 | orgarr |
| 425 | FROM procedures pd |
| 426 | LEFT JOIN stages s USING(procid) |
| 427 | LEFT JOIN procedures p2 ON (p2.procid = pd.rootpr) |
| 428 | LEFT JOIN bpm_loops_def bld USING(ptstid) |
| 429 | RIGHT JOIN rcp_cards p ON (p.procid = p2.procid) |
| 430 | WHERE (bld.multii IS NOT TRUE |
| 431 | OR s.prn_id IS NOT NULL) |
| 432 | AND s.ptsttp != 'SUBPROCESS' |
| 433 | AND p.is_fix IS FALSE |
| 434 | AND p.is_del IS FALSE |
| 435 | AND ((ARRAY[1] && s.orgarr) |
| 436 | OR (s.orgarr IS NULL |
| 437 | AND p.emp_id = 2)) |
| 438 | AND sop_id IS NOT NULL |
| 439 | AND s.is_act IS TRUE |
| 440 | AND pd.comple IS NOT TRUE |
| 441 | AND ptsttp != 'START' |
| 442 | ) AS aa USING(prtpid) |
| 443 | ORDER BY prtpid, ptstid, (end___ IS NOT NULL AND orgarr IS NOT NULL) DESC, end___ IS NOT NULL DESC, end___ ASC, orgarr IS NOT NULL DESC, dscrpt ASC |
| 444 | }}} |
| 445 | |