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 b267627e
authored
Aug 22, 2017
by
aa.gusti
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
anggaran
1 parent
545f22da
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
94 additions
and
67 deletions
eis_models.py
import-sipkd.py
eis_models.py
View file @
b267627
...
@@ -24,7 +24,7 @@ from sqlalchemy.orm import (
...
@@ -24,7 +24,7 @@ from sqlalchemy.orm import (
from
conf
import
eis_url
from
conf
import
eis_url
EisBase
=
declarative_base
()
EisBase
=
declarative_base
()
EisDBSession
=
scoped_session
(
sessionmaker
())
EisDBSession
=
scoped_session
(
sessionmaker
())
engine
=
create_engine
(
eis_url
)
engine
=
create_engine
(
eis_url
,
echo
=
False
)
EisDBSession
.
configure
(
bind
=
engine
)
EisDBSession
.
configure
(
bind
=
engine
)
EisBase
.
metadata
.
bind
=
engine
EisBase
.
metadata
.
bind
=
engine
...
@@ -105,11 +105,10 @@ class ArPayment(NamaModel, EisBase):
...
@@ -105,11 +105,10 @@ class ArPayment(NamaModel, EisBase):
tanggal
=
Column
(
DateTime
(
timezone
=
False
))
tanggal
=
Column
(
DateTime
(
timezone
=
False
))
departemen_kd
=
Column
(
String
(
16
))
departemen_kd
=
Column
(
String
(
16
))
departemen_nm
=
Column
(
String
(
255
))
departemen_nm
=
Column
(
String
(
255
))
rekening_kd
=
Column
(
String
(
16
))
rekening_nm
=
Column
(
String
(
255
))
jumlah
=
Column
(
BigInteger
)
jumlah
=
Column
(
BigInteger
)
level_id
=
Column
(
Integer
)
level_id
=
Column
(
Integer
)
__table_args__
=
(
UniqueConstraint
(
'kode'
),
tahun
=
Column
(
String
(
4
))
__table_args__
=
(
UniqueConstraint
(
'tanggal'
,
'departemen_kd'
,
'kode'
),
TABLE_ARGS
)
TABLE_ARGS
)
class
ApPayment
(
NamaModel
,
EisBase
):
class
ApPayment
(
NamaModel
,
EisBase
):
...
@@ -118,11 +117,10 @@ class ApPayment(NamaModel, EisBase):
...
@@ -118,11 +117,10 @@ class ApPayment(NamaModel, EisBase):
tanggal
=
Column
(
DateTime
(
timezone
=
False
))
tanggal
=
Column
(
DateTime
(
timezone
=
False
))
departemen_kd
=
Column
(
String
(
16
))
departemen_kd
=
Column
(
String
(
16
))
departemen_nm
=
Column
(
String
(
255
))
departemen_nm
=
Column
(
String
(
255
))
rekening_kd
=
Column
(
String
(
16
))
rekening_nm
=
Column
(
String
(
255
))
jumlah
=
Column
(
BigInteger
)
jumlah
=
Column
(
BigInteger
)
level_id
=
Column
(
Integer
)
level_id
=
Column
(
Integer
)
__table_args__
=
(
UniqueConstraint
(
'kode'
),
tahun
=
Column
(
String
(
4
))
__table_args__
=
(
UniqueConstraint
(
'tanggal'
,
'departemen_kd'
,
'kode'
),
TABLE_ARGS
)
TABLE_ARGS
)
class
ByPayment
(
NamaModel
,
EisBase
):
class
ByPayment
(
NamaModel
,
EisBase
):
...
@@ -131,11 +129,10 @@ class ByPayment(NamaModel, EisBase):
...
@@ -131,11 +129,10 @@ class ByPayment(NamaModel, EisBase):
tanggal
=
Column
(
DateTime
(
timezone
=
False
))
tanggal
=
Column
(
DateTime
(
timezone
=
False
))
departemen_kd
=
Column
(
String
(
16
))
departemen_kd
=
Column
(
String
(
16
))
departemen_nm
=
Column
(
String
(
255
))
departemen_nm
=
Column
(
String
(
255
))
rekening_kd
=
Column
(
String
(
16
))
rekening_nm
=
Column
(
String
(
255
))
jumlah
=
Column
(
BigInteger
)
jumlah
=
Column
(
BigInteger
)
level_id
=
Column
(
Integer
)
level_id
=
Column
(
Integer
)
__table_args__
=
(
UniqueConstraint
(
'kode'
),
tahun
=
Column
(
String
(
4
))
__table_args__
=
(
UniqueConstraint
(
'tanggal'
,
'departemen_kd'
,
'kode'
),
TABLE_ARGS
)
TABLE_ARGS
)
class
Rekening
(
NamaModel
,
EisBase
):
class
Rekening
(
NamaModel
,
EisBase
):
__tablename__
=
'sipkd_rekening'
__tablename__
=
'sipkd_rekening'
...
...
import-sipkd.py
View file @
b267627
from
sipkd_models
import
Anggaran
,
Realisasi
,
Base
,
DBSession
from
sipkd_models
import
Realisasi
,
Base
,
DBSession
from
eis_models
import
(
Anggaran
as
EisAnggaran
,
ApPayment
as
EisApPayment
,
from
eis_models
import
(
ApPayment
as
EisApPayment
,
ArPayment
as
EisArPayment
,
ByPayment
as
EisByPayment
,
ByPayment
as
EisByPayment
,
Rekening
as
EisRekening
,
EisBase
,
EisDBSession
)
EisBase
,
EisDBSession
)
from
conf
import
sipkd_url
from
conf
import
sipkd_url
from
sqlalchemy
import
create_engine
from
sqlalchemy
import
create_engine
,
literal_column
,
func
from
datetime
import
datetime
from
datetime
import
datetime
from
datetime
import
date
from
datetime
import
date
try
:
from
urllib
import
quote_plus
,
quote
except
:
from
urllib.parse
import
quote_plus
,
quote
engine
=
create_engine
(
sipkd_url
)
engine
=
create_engine
(
sipkd_url
)
DBSession
.
configure
(
bind
=
engine
)
DBSession
.
configure
(
bind
=
engine
)
Base
.
metadata
.
bind
=
engine
Base
.
metadata
.
bind
=
engine
...
@@ -14,78 +21,99 @@ now = datetime.now()
...
@@ -14,78 +21,99 @@ now = datetime.now()
tanggal
=
now
.
date
()
tanggal
=
now
.
date
()
tahun
=
now
.
strftime
(
'
%
Y'
)
tahun
=
now
.
strftime
(
'
%
Y'
)
def
import_anggaran
():
def
calculate
(
tabel
,
all
=
False
):
query
=
DBSession
.
query
(
Anggaran
)
.
filter_by
(
tahun
=
tahun
)
query
=
EisDBSession
.
query
(
tabel
)
.
filter_by
(
tahun
=
str
(
tahun
))
.
\
order_by
(
tabel
.
departemen_kd
,
tabel
.
tanggal
,
tabel
.
kode
.
desc
())
if
not
all
:
query
=
query
.
filter_by
(
tanggal
=
tanggal
)
old_level
=
0
levels
=
{}
jumlahs
=
{}
key
=
""
for
row
in
query
.
all
():
for
row
in
query
.
all
():
anggaran
=
EisDBSession
.
query
(
EisAnggaran
)
.
\
if
row
.
level_id
>
old_level
:
filter_by
(
tahun
=
row
.
tahun
,
print
(
'Lebih'
,
jumlahs
,
key
)
kode
=
row
.
kd_rekening
,
old_level
=
row
.
level_id
departemen_kd
=
row
.
kd_opd
,
key
=
'a'
+
str
(
row
.
level_id
)
)
.
first
()
if
not
anggaran
:
#JIKA level sama dengan sebelumnya jumlahkan
anggaran
=
EisAnggaran
()
if
row
.
level_id
==
old_level
:
anggaran
.
tahun
=
row
.
tahun
print
(
'Sama'
)
anggaran
.
kode
=
row
.
kd_rekening
if
not
key
in
jumlahs
:
anggaran
.
departemen_kd
=
row
.
kd_opd
jumlahs
[
key
]
=
row
.
jumlah
anggaran
.
level_id
=
row
.
kd_rekening
.
count
(
'.'
)
else
:
anggaran
.
nama
=
row
.
nm_rekening
jumlahs
[
key
]
+=
row
.
jumlah
anggaran
.
departemen_nm
=
row
.
nm_opd
anggaran
.
murni
=
row
.
ang_murni
#JIKA level < sebelumnya update current row
anggaran
.
perubahan
=
row
.
ang_perubahan
if
row
.
level_id
<
old_level
:
EisDBSession
.
add
(
anggaran
)
print
(
'Kurang'
,
jumlahs
,
key
)
print
(
'kode: '
,
row
.
kode
,
'level: '
,
row
.
level_id
,
'old: '
,
old_level
,
'key: '
,
key
,
'jml: '
,
row
.
jumlah
,
'jmls: '
,
jumlahs
)
row
.
jumlah
=
jumlahs
[
key
]
EisDBSession
.
add
(
row
)
EisDBSession
.
flush
()
EisDBSession
.
flush
()
jumlahs
[
key
]
=
0
#key sebelumnya diset jadi 0
key
=
'a'
+
str
(
row
.
level_id
)
if
not
key
in
jumlahs
:
jumlahs
[
key
]
=
row
.
jumlah
else
:
jumlahs
[
key
]
+=
row
.
jumlah
old_level
=
row
.
level_id
print
(
'kode: '
,
row
.
kode
,
'level: '
,
row
.
level_id
,
'old: '
,
old_level
,
'key: '
,
key
,
'jml: '
,
row
.
jumlah
,
'jmls: '
,
jumlahs
)
EisDBSession
.
commit
()
EisDBSession
.
commit
()
def
import_ar
(
all
=
False
):
def
validate_parent
(
tabel
,
departemen_kd
,
departemen_nm
,
rekening
,
tanggal
):
query
=
DBSession
.
query
(
Realisasi
)
kode
=
rekening
.
split
(
'.'
)
if
not
all
:
rekening
=
"
\'
"
+
rekening
+
"
\'
"
query
=
query
.
filter_by
(
tanggal
=
tanggal
)
rows
=
EisDBSession
.
query
(
EisRekening
)
.
\
filter
(
literal_column
(
rekening
)
.
like
(
for
row
in
query
.
filter
(
Realisasi
.
kd_rekening
.
like
(
'4
%
'
))
.
all
():
func
.
concat
(
EisRekening
.
kode
,
'
%
'
)))
.
all
()
eis
=
EisDBSession
.
query
(
ArPayment
)
.
\
for
row
in
rows
:
filter_by
(
tahun
=
row
.
tahun
,
if
not
row
.
kode
:
rekening_kd
=
row
.
kd_rekening
,
continue
departemen_kd
=
row
.
kd_opd
,
induk
=
EisDBSession
.
query
(
tabel
)
.
\
tanggal
=
tanggal
,
filter_by
(
tahun
=
str
(
row
.
tahun
),
kode
=
row
.
kode
,
departemen_kd
=
departemen_kd
,
)
.
first
()
)
.
first
()
if
not
eis
:
if
not
induk
:
eis
=
EisArPayment
()
induk
=
tabel
()
eis
.
tahun
=
row
.
tahun
induk
.
tahun
=
str
(
tahun
)
eis
.
kode
=
row
.
kd_rekening
induk
.
kode
=
row
.
kode
eis
.
departemen_kd
=
row
.
kd_opd
induk
.
departemen_kd
=
departemen_kd
eis
.
tanggal
=
tanggal
induk
.
tanggal
=
tanggal
eis
.
level_id
=
row
.
kd_rekening
.
count
(
'.'
)
induk
.
departemen_nm
=
departemen_nm
eis
.
nama
=
row
.
nm_rekening
induk
.
level_id
=
row
.
kode
.
count
(
'.'
)
eis
.
departemen_nm
=
row
.
nm_opd
induk
.
nama
=
row
.
nama
eis
.
jumlah
=
row
.
realisai
EisDBSession
.
add
(
induk
)
EisDBSession
.
add
(
anggaran
)
EisDBSession
.
flush
()
EisDBSession
.
flush
()
EisDBSession
.
commit
()
def
import_ap
(
all
=
False
):
def
import_ap
(
all
=
False
):
query
=
DBSession
.
query
(
Realisasi
)
query
=
DBSession
.
query
(
Realisasi
)
if
not
all
:
if
not
all
:
query
=
query
.
filter_by
(
tanggal
=
tanggal
)
query
=
query
.
filter_by
(
tanggal
=
tanggal
)
query
=
query
.
filter
(
Realisasi
.
kd_rekening
.
like
(
'5.
%
'
))
for
row
in
query
.
filter
(
Realisasi
.
kd_rekening
.
like
(
'5
%
'
))
.
all
():
for
row
in
query
.
all
():
eis
=
EisDBSession
.
query
(
Ar
Payment
)
.
\
eis
=
EisDBSession
.
query
(
EisAp
Payment
)
.
\
filter_by
(
tahun
=
row
.
tahun
,
filter_by
(
tahun
=
row
.
tahun
,
rekening_kd
=
row
.
kd_rekening
,
kode
=
row
.
kd_rekening
,
departemen_kd
=
row
.
kd_opd
,
departemen_kd
=
row
.
kd_opd
,
tanggal
=
tanggal
,
tanggal
=
row
.
tanggal
,
)
.
first
()
)
.
first
()
if
not
eis
:
if
not
eis
:
eis
=
EisApPayment
()
eis
=
EisApPayment
()
eis
.
tahun
=
row
.
tahun
eis
.
tahun
=
row
.
tahun
eis
.
kode
=
row
.
kd_rekening
eis
.
kode
=
row
.
kd_rekening
eis
.
departemen_kd
=
row
.
kd_opd
eis
.
departemen_kd
=
row
.
kd_opd
eis
.
tanggal
=
tanggal
eis
.
tanggal
=
row
.
tanggal
eis
.
level_id
=
row
.
kd_rekening
.
count
(
'.'
)
eis
.
level_id
=
row
.
kd_rekening
.
count
(
'.'
)
eis
.
nama
=
row
.
nm_rekening
eis
.
nama
=
row
.
nm_rekening
eis
.
departemen_nm
=
row
.
nm_opd
eis
.
departemen_nm
=
row
.
nm_opd
eis
.
jumlah
=
row
.
realisai
eis
.
jumlah
=
row
.
realisa
s
i
EisDBSession
.
add
(
eis
)
EisDBSession
.
add
(
eis
)
EisDBSession
.
flush
()
EisDBSession
.
flush
()
validate_parent
(
EisApPayment
,
eis
.
departemen_kd
,
eis
.
departemen_nm
,
eis
.
kode
,
eis
.
tanggal
)
EisDBSession
.
commit
()
EisDBSession
.
commit
()
def
import_by
(
all
=
False
):
def
import_by
(
all
=
False
):
...
@@ -93,8 +121,8 @@ def import_by(all=False):
...
@@ -93,8 +121,8 @@ def import_by(all=False):
if
not
all
:
if
not
all
:
query
=
query
.
filter_by
(
tanggal
=
tanggal
)
query
=
query
.
filter_by
(
tanggal
=
tanggal
)
for
row
in
query
.
filter
(
Realisasi
.
kd_rekening
.
like
(
'6
%
'
))
.
all
():
for
row
in
query
.
filter
(
Realisasi
.
kd_rekening
.
like
(
'6
.
%
'
))
.
all
():
eis
=
EisDBSession
.
query
(
Ar
Payment
)
.
\
eis
=
EisDBSession
.
query
(
EisBy
Payment
)
.
\
filter_by
(
tahun
=
row
.
tahun
,
filter_by
(
tahun
=
row
.
tahun
,
rekening_kd
=
row
.
kd_rekening
,
rekening_kd
=
row
.
kd_rekening
,
departemen_kd
=
row
.
kd_opd
,
departemen_kd
=
row
.
kd_opd
,
...
@@ -112,9 +140,11 @@ def import_by(all=False):
...
@@ -112,9 +140,11 @@ def import_by(all=False):
eis
.
jumlah
=
row
.
realisai
eis
.
jumlah
=
row
.
realisai
EisDBSession
.
add
(
eis
)
EisDBSession
.
add
(
eis
)
EisDBSession
.
flush
()
EisDBSession
.
flush
()
validate_parent
(
EisByPayment
,
eis
.
departemen_kd
,
eis
.
departemen_nm
,
eis
.
kode
)
EisDBSession
.
commit
()
EisDBSession
.
commit
()
EisDBSession
.
commit
()
import_anggaran
()
import_ap
()
import_ar
()
\ No newline at end of file
\ No newline at end of file
import_ap
(
True
)
import_by
(
True
)
calculate
(
EisApPayment
,
True
)
calculate
(
EisByPayment
,
True
)
\ No newline at end of file
\ No newline at end of file
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