Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Project
/
import-sipkd-eis
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit a0a1101a
authored
Aug 21, 2017
by
aa.gusti
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
anggaran
1 parent
96916aba
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
107 additions
and
0 deletions
import-sipkd-anggaran.py
import-sipkd-anggaran.py
0 → 100644
View file @
a0a1101
from
sipkd_models
import
Anggaran
,
Realisasi
,
Base
,
DBSession
from
eis_models
import
(
Anggaran
as
EisAnggaran
,
ApPayment
as
EisApPayment
,
ArPayment
as
EisArPayment
,
ByPayment
as
EisByPayment
,
Rekening
as
EisRekening
,
EisBase
,
EisDBSession
)
from
conf
import
sipkd_url
from
sqlalchemy
import
create_engine
,
literal_column
,
func
from
datetime
import
datetime
from
datetime
import
date
try
:
from
urllib
import
quote_plus
,
quote
except
:
from
urllib.parse
import
quote_plus
,
quote
engine
=
create_engine
(
sipkd_url
)
DBSession
.
configure
(
bind
=
engine
)
Base
.
metadata
.
bind
=
engine
Base
.
metadata
.
create_all
(
engine
)
now
=
datetime
.
now
()
tanggal
=
now
.
date
()
tahun
=
now
.
strftime
(
'
%
Y'
)
def
calculate
():
rows
=
EisDBSession
.
query
(
EisAnggaran
)
.
filter_by
(
tahun
=
str
(
tahun
))
.
\
order_by
(
EisAnggaran
.
kode
.
desc
())
old_level
=
0
levels
=
{}
murnis
=
{}
key
=
""
for
row
in
rows
:
if
row
.
level_id
>
old_level
:
old_level
=
row
.
level_id
key
=
'a'
+
str
(
row
.
level_id
)
#print(row.kode, row.level_id, old_level, key, row.murni)
#JIKA level sama dengan sebelumnya jumlahkan
if
row
.
level_id
==
old_level
:
if
not
key
in
murnis
:
murnis
[
key
]
=
row
.
murni
else
:
murnis
[
key
]
+=
row
.
murni
#JIKA level < sebelumnya update current row
if
row
.
level_id
<
old_level
:
row
.
murni
=
murnis
[
key
]
EisDBSession
.
add
(
row
)
EisDBSession
.
flush
()
murnis
[
key
]
=
0
#key sebelumnya diset jadi 0
key
=
'a'
+
str
(
row
.
level_id
)
if
not
key
in
murnis
:
murnis
[
key
]
=
row
.
murni
else
:
murnis
[
key
]
+=
row
.
murni
old_level
=
row
.
level_id
def
validate_parent
(
departemen_kd
,
departemen_nm
,
rekening
):
kode
=
rekening
.
split
(
'.'
)
rekening
=
"
\'
"
+
rekening
+
"
\'
"
rows
=
EisDBSession
.
query
(
EisRekening
)
.
\
filter
(
literal_column
(
rekening
)
.
like
(
func
.
concat
(
EisRekening
.
kode
,
'
%
'
)))
.
all
()
for
row
in
rows
:
if
not
row
.
kode
:
continue
induk
=
EisDBSession
.
query
(
EisAnggaran
)
.
\
filter_by
(
tahun
=
str
(
row
.
tahun
),
kode
=
row
.
kode
,
departemen_kd
=
departemen_kd
,
)
.
first
()
if
not
induk
:
induk
=
EisAnggaran
()
induk
.
tahun
=
tahun
induk
.
kode
=
row
.
kode
induk
.
departemen_kd
=
departemen_kd
induk
.
level_id
=
row
.
kode
.
count
(
'.'
)
induk
.
nama
=
row
.
nama
EisDBSession
.
add
(
induk
)
EisDBSession
.
flush
()
def
import_anggaran
():
query
=
DBSession
.
query
(
Anggaran
)
.
filter_by
(
tahun
=
tahun
)
for
row
in
query
.
all
():
anggaran
=
EisDBSession
.
query
(
EisAnggaran
)
.
\
filter_by
(
tahun
=
row
.
tahun
,
kode
=
row
.
kd_rekening
,
departemen_kd
=
row
.
kd_opd
,
)
.
first
()
if
not
anggaran
:
anggaran
=
EisAnggaran
()
anggaran
.
tahun
=
row
.
tahun
anggaran
.
kode
=
row
.
kd_rekening
anggaran
.
departemen_kd
=
row
.
kd_opd
anggaran
.
level_id
=
row
.
kd_rekening
.
count
(
'.'
)
anggaran
.
nama
=
row
.
nm_rekening
anggaran
.
departemen_nm
=
row
.
nm_opd
anggaran
.
murni
=
row
.
ang_murni
anggaran
.
perubahan
=
row
.
ang_perubahan
EisDBSession
.
add
(
anggaran
)
EisDBSession
.
flush
()
validate_parent
(
row
.
kd_opd
,
row
.
nm_opd
,
row
.
kd_rekening
)
EisDBSession
.
commit
()
import_anggaran
()
calculate
()
EisDBSession
.
commit
()
Write
Preview
Markdown
is supported
Attach a file
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 post a comment