| 487 | |
| 488 | === dla wersji >= 5.0 === |
| 489 | |
| 490 | {{{ |
| 491 | #!sql |
| 492 | WITH RECURSIVE user_all_replacements (who___, bywhom, path) |
| 493 | AS ( |
| 494 | SELECT r.who___, |
| 495 | r.bywhom, |
| 496 | array [r.who___]::INT [] AS path |
| 497 | FROM replacements r |
| 498 | WHERE r.bywhom IN (29) |
| 499 | AND (now() BETWEEN r.from__ AND r.to____) |
| 500 | AND NOT r.suspen |
| 501 | |
| 502 | UNION ALL |
| 503 | |
| 504 | SELECT r.who___, |
| 505 | r.bywhom, |
| 506 | uar.path || r.who___ AS path |
| 507 | FROM replacements r, |
| 508 | user_all_replacements uar |
| 509 | WHERE NOT (r.who___ = ANY (path)) |
| 510 | AND r.bywhom = uar.who___ |
| 511 | AND (now() BETWEEN r.from__ AND r.to____) |
| 512 | AND NOT r.suspen |
| 513 | ), |
| 514 | all_orunids as ( |
| 515 | SELECT array_agg(who___)||29 as val |
| 516 | FROM ( |
| 517 | SELECT DISTINCT r.who___ FROM user_all_replacements r |
| 518 | ) foo |
| 519 | ) |
| 520 | SELECT keyval, |
| 521 | dscrpt, |
| 522 | clsnam, |
| 523 | ptstnm, |
| 524 | dctpid, |
| 525 | prtpnm, |
| 526 | end___, |
| 527 | ptstid, |
| 528 | aa.prior_ |
| 529 | FROM procedures_def |
| 530 | RIGHT JOIN ( |
| 531 | SELECT (doc_id) AS keyval, |
| 532 | p2.prtpid, |
| 533 | substr(d.dscrpt, 0, 100) AS dscrpt, |
| 534 | 'DOCUMENT' AS clsnam, |
| 535 | end___, |
| 536 | s.ptstnm, |
| 537 | d.dctpid, |
| 538 | ptstid, |
| 539 | orgarr, |
| 540 | s.actdat, |
| 541 | d.prior_ |
| 542 | FROM procedures pd |
| 543 | LEFT JOIN stages s USING (PROCID) |
| 544 | LEFT JOIN procedures p2 ON (p2.PROCID = pd.rootpr) |
| 545 | LEFT JOIN bpm_loops_def bld USING (ptstid) |
| 546 | RIGHT JOIN documents d ON (d.PROCID = p2.PROCID) |
| 547 | WHERE ( |
| 548 | bld.multii IS NOT TRUE |
| 549 | OR s.prn_id IS NOT NULL |
| 550 | ) |
| 551 | AND ( |
| 552 | ((SELECT val FROM all_orunids) && s.orgarr) |
| 553 | OR ( |
| 554 | s.orgarr IS NULL |
| 555 | AND ARRAY[d.target] <@ (SELECT val FROM all_orunids) |
| 556 | ) |
| 557 | ) |
| 558 | AND NOT d.is_del |
| 559 | AND gostof IS NULL |
| 560 | AND sop_id IS NOT NULL |
| 561 | AND s.is_act |
| 562 | AND NOT p2.comple |
| 563 | AND ptsttp NOT IN ('SUBPROCESS', 'START', 'END') |
| 564 | |
| 565 | UNION |
| 566 | |
| 567 | SELECT (prc_id) AS keyval, |
| 568 | p2.prtpid, |
| 569 | substr(p.dscrpt, 0, 100) AS dscrpt, |
| 570 | 'PROCESS' AS clsnam, |
| 571 | end___, |
| 572 | s.ptstnm, |
| 573 | 0 AS dctpid, |
| 574 | ptstid, |
| 575 | orgarr, |
| 576 | s.actdat, |
| 577 | NULL AS prior_ |
| 578 | FROM procedures pd |
| 579 | LEFT JOIN stages s USING (PROCID) |
| 580 | LEFT JOIN procedures p2 ON (p2.PROCID = pd.rootpr) |
| 581 | LEFT JOIN bpm_loops_def bld USING (ptstid) |
| 582 | RIGHT JOIN processes p ON (p.PROCID = p2.PROCID) |
| 583 | WHERE ( |
| 584 | bld.multii IS NOT TRUE |
| 585 | OR s.prn_id IS NOT NULL |
| 586 | ) |
| 587 | AND p.is_fix IS FALSE |
| 588 | AND p.is_del IS FALSE |
| 589 | AND ((SELECT val FROM all_orunids) && s.orgarr) |
| 590 | AND sop_id IS NOT NULL |
| 591 | AND s.is_act IS TRUE |
| 592 | AND p2.comple IS NOT TRUE |
| 593 | AND ptsttp NOT IN ('SUBPROCESS', 'START', 'END') |
| 594 | |
| 595 | UNION |
| 596 | |
| 597 | SELECT (rcp_id) AS keyval, |
| 598 | p2.prtpid, |
| 599 | substr(p.dscrpt, 0, 100) AS dscrpt, |
| 600 | 'RCP' AS clsnam, |
| 601 | end___, |
| 602 | s.ptstnm, |
| 603 | 0 AS dctpid, |
| 604 | ptstid, |
| 605 | orgarr, |
| 606 | s.actdat, |
| 607 | NULL AS prior_ |
| 608 | FROM procedures pd |
| 609 | LEFT JOIN stages s USING (PROCID) |
| 610 | LEFT JOIN procedures p2 ON (p2.PROCID = pd.rootpr) |
| 611 | LEFT JOIN bpm_loops_def bld USING (ptstid) |
| 612 | RIGHT JOIN rcp_cards p ON (p.PROCID = p2.PROCID) |
| 613 | WHERE ( |
| 614 | bld.multii IS NOT TRUE |
| 615 | OR s.prn_id IS NOT NULL |
| 616 | ) |
| 617 | AND p.is_fix IS FALSE |
| 618 | AND p.is_del IS FALSE |
| 619 | AND ( |
| 620 | ((SELECT val FROM all_orunids) && s.orgarr) |
| 621 | OR ( |
| 622 | s.orgarr IS NULL |
| 623 | AND p.emp_id = 14 |
| 624 | ) |
| 625 | ) |
| 626 | AND sop_id IS NOT NULL |
| 627 | AND s.is_act IS TRUE |
| 628 | AND p2.comple IS NOT TRUE |
| 629 | AND ptsttp NOT IN ('SUBPROCESS', 'START', 'END') |
| 630 | ) AS aa USING (prtpid) |
| 631 | ORDER BY prtpid, |
| 632 | ptstid, |
| 633 | ( |
| 634 | end___ IS NOT NULL |
| 635 | AND orgarr IS NOT NULL |
| 636 | ) DESC, |
| 637 | end___ IS NOT NULL DESC, |
| 638 | end___ ASC, |
| 639 | actdat ASC, |
| 640 | orgarr IS NOT NULL DESC, |
| 641 | dscrpt ASC |
| 642 | }}} |
| 643 | |