Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
intranet-invoices
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
project-open
intranet-invoices
Commits
34a904dd
Commit
34a904dd
authored
Apr 03, 2023
by
Frank Bergmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added PL/SQL procedures to determine predecessors/successors
parent
9ebe703d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
89 additions
and
0 deletions
+89
-0
intranet-invoices-preds-succs.sql
sql/postgresql/intranet-invoices-preds-succs.sql
+89
-0
No files found.
sql/postgresql/intranet-invoices-preds-succs.sql
0 → 100644
View file @
34a904dd
-- Returns a formatted string with links to successor objects
create
or
replace
function
im_invoice_predecessor_links
(
integer
)
returns
varchar
as
$
body
$
declare
p_invoice_id
alias
for
$
1
;
row
RECORD
;
v_result
varchar
;
begin
v_result
:
=
''
;
FOR
row
IN
select
distinct
c_pred
.
cost_id
as
pred_id
,
c_pred
.
cost_name
as
pred_name
from
im_invoice_items
ii
,
im_costs
c_pred
where
ii
.
invoice_id
=
p_invoice_id
and
c_pred
.
cost_id
=
item_source_invoice_id
LOOP
IF
v_result
!=
''
THEN
v_result
=
v_result
||
', '
;
END
IF
;
v_result
=
v_result
||
'<a href=/intranet-invoices/view?invoice_id='
||
row
.
pred_id
||
'>'
||
row
.
pred_name
||
'</a>'
;
END
LOOP
;
return
v_result
;
end
;
$
body
$
language
'plpgsql'
;
create
or
replace
function
im_invoice_successor_links
(
integer
)
returns
varchar
as
$
body
$
declare
p_invoice_id
alias
for
$
1
;
row
RECORD
;
v_result
varchar
;
begin
v_result
:
=
''
;
FOR
row
IN
select
distinct
c_succ
.
cost_id
as
succ_id
,
c_succ
.
cost_name
as
succ_name
from
im_invoice_items
ii
,
im_costs
c_succ
where
ii
.
invoice_id
=
c_succ
.
cost_id
and
ii
.
item_source_invoice_id
=
p_invoice_id
LOOP
IF
v_result
!=
''
THEN
v_result
=
v_result
||
', '
;
END
IF
;
v_result
=
v_result
||
'<a href=/intranet-invoices/view?invoice_id='
||
row
.
succ_id
||
'>'
||
row
.
succ_name
||
'</a>'
;
END
LOOP
;
return
v_result
;
end
;
$
body
$
language
'plpgsql'
;
create
or
replace
function
im_invoice_successor_sum
(
integer
)
returns
numeric
as
$
body
$
declare
p_invoice_id
alias
for
$
1
;
row
RECORD
;
v_result
numeric
;
begin
v_result
:
=
0
.
0
;
FOR
row
IN
select
distinct
c_succ
.
cost_id
as
succ_id
,
c_succ
.
cost_name
as
succ_name
,
c_succ
.
amount
from
im_invoice_items
ii
,
im_costs
c_succ
where
ii
.
invoice_id
=
c_succ
.
cost_id
and
ii
.
item_source_invoice_id
=
p_invoice_id
LOOP
v_result
=
v_result
+
row
.
amount
;
END
LOOP
;
return
v_result
;
end
;
$
body
$
language
'plpgsql'
;
select
im_invoice_predecessor_links
(
447724
);
select
im_invoice_successor_links
(
406832
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment