Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
aa.gusti
/
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 094125ab
authored
Jul 12, 2025
by
aa.gustiana@gmail.com
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Refactor connection setup and enhance view initialization with session management
1 parent
61e40e7b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
81 deletions
eispajak/models/payment.py
eispajak/views/pcpd.py
eispajak/models/payment.py
View file @
094125a
...
...
@@ -286,7 +286,7 @@ class Targets(PCBase, DefaultModel):
def
get_connection
(
settings
):
url
=
'pcpd.url'
in
settings
and
settings
[
'pcpd.url'
]
and
'pcpd.'
or
'sqlalchemy.'
engine
=
engine_from_config
(
settings
,
url
,
pool_pre_ping
=
True
)
engine
=
engine_from_config
(
settings
,
url
)
PCDBSession
.
configure
(
bind
=
engine
)
PCBase
.
metadata
.
bind
=
engine
return
engine
...
...
@@ -294,7 +294,6 @@ def get_connection(settings):
def
includeme
(
config
):
settings
=
get_settings
()
get_connection
(
settings
)
...
...
eispajak/views/pcpd.py
View file @
094125a
...
...
@@ -11,6 +11,8 @@ from sqlalchemy.sql.expression import cast
from
..models.payment
import
PaymentPBB
,
PaymentPAD
,
PaymentBPHTB
,
PaymentWEBR
,
Targets
from
opensipkd.pbb.monitoring.models
import
PembayaranSppt
,
Kecamatan
,
Kelurahan
,
Sppt
from
datetime
import
timedelta
from
..models.payment
import
PCDBSession
logger
=
logging
.
getLogger
(
__name__
)
PAD_TYP
=
{
...
...
@@ -120,6 +122,10 @@ jenis_pajak = {
class
Views
(
BaseView
):
def
__init__
(
self
,
request
):
super
()
.
__init__
(
request
)
self
.
db_session
=
PCDBSession
@view_config
(
route_name
=
'eis-pcpd'
,
renderer
=
'templates/pcpd.pt'
,
permission
=
'eis'
)
def
view_app
(
self
):
...
...
@@ -153,14 +159,14 @@ class Views(BaseView):
qry
=
table
.
qry_sum
(
columns
)
\
.
group_by
(
field
)
\
.
order_by
(
field
)
# for i, f in enumerate(filters):
qry
=
qry
.
filter
(
filters
)
if
typ
!=
None
:
if
typ
==
"pajak"
:
qry
=
qry
.
filter
(
table
.
jenis_pajak
.
notin_
(
PAD_TYP
[
'pbb'
]))
else
:
qry
=
qry
.
filter
(
table
.
jenis_pajak
.
in_
(
PAD_TYP
[
typ
]))
daily
=
[]
dailyTrx
=
[]
dailyAcc
=
[]
...
...
@@ -183,66 +189,15 @@ class Views(BaseView):
trx
=
tx
return
amt
,
trx
,
daily
,
dailyTrx
,
dailyAcc
,
dailyAccTrx
# def get_pbb_data(self):
# if log.root.level == logging.DEBUG:
# today = datetime.strptime('2025-06-05', "%Y-%m-%d")
# else:
# today = datetime.now().date()
# field = func.to_char(PaymentPBB.tgl_pembayaran_sppt, 'yyyy-mm-dd')
# filter_exp = PaymentPBB.tgl_pembayaran_sppt.between(
# today-timedelta(6), today)
# amt, trx, daily, dailyTrx, dailyAcc, dailyAccTrx = \
# self.get_daily_data(PaymentPBB, field,
# today.strftime("%Y-%m-%d"), filter_exp)
# filter_exp = PaymentPBB.tgl_pembayaran_sppt.between(
# today-timedelta(days=6), today)
# field = func.to_char(PaymentPBB.tgl_pembayaran_sppt, 'IYYY')
# filter_exp = PaymentPBB.tgl_pembayaran_sppt.between(
# datetime.strptime(f"{today.year}-01-01", "%Y-%m-%d"), today)
# ytd, ytdTrx, yearly, yearlyTrx, yearlyAcc, yearlyAccTrx = \
# self.get_daily_data(PaymentPBB, field,
# str(today.year), filter_exp)
# field = func.to_char(PaymentPBB.tgl_pembayaran_sppt, 'MM')
# month, monthTrx, monthly, monthlyTrx, monthlyAcc, monthlyAccTrx = \
# self.get_daily_data(PaymentPBB, field, None, filter_exp)
# field = func.to_char(PaymentPBB.tgl_pembayaran_sppt, 'WW')
# filter_exp = PaymentPBB.tgl_pembayaran_sppt.between(
# today-timedelta(weeks=6), today)
# week, weekTrx, weekly, weeklyTrx, weeklyAcc, weeklyAccTrx = \
# self.get_daily_data(PaymentPBB, field, None, filter_exp)
# return {"today": amt,
# "trx": trx,
# "daily": daily,
# "dailyTrx": dailyTrx,
# "dailyAcc": dailyAcc,
# "dailyAccTrx": dailyAccTrx,
# "ytd": ytd,
# "trxYtd": ytdTrx,
# "pie": [("I", 100, '#16a75c'), ("II", 200, '#ffb900'),
# ("III", 300, '#133132'), ("IV", 200, '#123456'),
# ("V", 100, '#545355')],
# "weekly": weekly,
# "weeklyTrx": weeklyTrx,
# "weeklyAcc": weeklyAcc,
# "weeklyAccTrx": weeklyAccTrx,
# "monthly": monthly,
# "monthlyTrx": monthlyTrx,
# "monthlyAcc": monthlyAcc,
# "monthlyAccTrx": monthlyAccTrx,
# }
def
get_targets
(
self
,
kode
=
None
):
targets
=
Targets
.
query_from
([
func
.
sum
(
Targets
.
t_anggaran
)
.
label
(
"murni"
),
func
.
sum
(
Targets
.
t_perubahan
)
.
label
(
"perubahan"
),])
.
filter
(
targets
=
Targets
.
query_from
([
func
.
sum
(
Targets
.
t_anggaran
)
.
label
(
"murni"
),
func
.
sum
(
Targets
.
t_perubahan
)
.
label
(
"perubahan"
),])
\
.
filter
(
Targets
.
tahun
==
self
.
ses
[
'tahun'
],
)
if
kode
:
if
kode
==
"pajak"
:
if
kode
==
"pajak"
:
return
0
targets
=
targets
.
filter
(
Targets
.
kode
.
ilike
(
jenis_pajak
[
kode
][
"kode"
]
+
'
%
'
))
...
...
@@ -260,27 +215,27 @@ class Views(BaseView):
else
:
today
=
datetime
.
now
()
.
date
()
#Harian
field
=
func
.
to_char
(
PembayaranSppt
.
tgl_pembayaran_sppt
,
'yyyy-mm-dd'
)
filter_exp
=
PembayaranSppt
.
tgl_pembayaran_sppt
.
between
(
today
-
timedelta
(
6
),
today
)
today
-
timedelta
(
days
=
6
),
today
)
amt
,
trx
,
daily
,
dailyTrx
,
dailyAcc
,
dailyAccTrx
=
\
self
.
get_daily_data
(
PembayaranSppt
,
field
,
today
.
strftime
(
"
%
Y-
%
m-
%
d"
),
filter_exp
)
filter_exp
=
PembayaranSppt
.
tgl_pembayaran_sppt
.
between
(
today
-
timedelta
(
days
=
6
),
today
)
#Total Setahun
field
=
func
.
to_char
(
PembayaranSppt
.
tgl_pembayaran_sppt
,
'IYYY'
)
filter_exp
=
PembayaranSppt
.
tgl_pembayaran_sppt
.
between
(
datetime
.
strptime
(
f
"{today.year}-01-01"
,
"
%
Y-
%
m-
%
d"
),
today
)
ytd
,
ytdTrx
,
yearly
,
yearlyTrx
,
yearlyAcc
,
yearlyAccTrx
=
\
self
.
get_daily_data
(
PembayaranSppt
,
field
,
str
(
today
.
year
),
filter_exp
)
#Bulanan
field
=
func
.
to_char
(
PembayaranSppt
.
tgl_pembayaran_sppt
,
'MM'
)
month
,
monthTrx
,
monthly
,
monthlyTrx
,
monthlyAcc
,
monthlyAccTrx
=
\
self
.
get_daily_data
(
PembayaranSppt
,
field
,
None
,
filter_exp
)
#Mingguan
field
=
func
.
to_char
(
PembayaranSppt
.
tgl_pembayaran_sppt
,
'WW'
)
filter_exp
=
PembayaranSppt
.
tgl_pembayaran_sppt
.
between
(
today
-
timedelta
(
weeks
=
6
),
today
)
...
...
@@ -322,15 +277,16 @@ class Views(BaseView):
today
=
datetime
.
strptime
(
'2025-06-05'
,
"
%
Y-
%
m-
%
d"
)
else
:
today
=
datetime
.
now
()
.
date
()
#Harian
field
=
func
.
to_char
(
PaymentBPHTB
.
tgl
,
'yyyy-mm-dd'
)
filter_exp
=
PaymentBPHTB
.
tgl
.
between
(
today
-
timedelta
(
6
),
today
)
today
-
timedelta
(
days
=
6
),
today
)
amt
,
trx
,
daily
,
dailyTrx
,
dailyAcc
,
dailyAccTrx
=
\
self
.
get_daily_data
(
PaymentBPHTB
,
field
,
today
.
strftime
(
"
%
Y-
%
m-
%
d"
),
filter_exp
)
filter_exp
=
PaymentBPHTB
.
tgl
.
between
(
today
-
timedelta
(
days
=
6
),
today
)
#Total Tahunan
field
=
func
.
to_char
(
PaymentBPHTB
.
tgl
,
'IYYY'
)
filter_exp
=
PaymentBPHTB
.
tgl
.
between
(
datetime
.
strptime
(
f
"{today.year}-01-01"
,
"
%
Y-
%
m-
%
d"
),
today
)
...
...
@@ -338,15 +294,18 @@ class Views(BaseView):
self
.
get_daily_data
(
PaymentBPHTB
,
field
,
str
(
today
.
year
),
filter_exp
)
#Bulanan
field
=
func
.
to_char
(
PaymentBPHTB
.
tgl
,
'MM'
)
month
,
monthTrx
,
monthly
,
monthlyTrx
,
monthlyAcc
,
monthlyAccTrx
=
\
self
.
get_daily_data
(
PaymentBPHTB
,
field
,
None
,
filter_exp
)
#Mingguan
field
=
func
.
to_char
(
PaymentBPHTB
.
tgl
,
'WW'
)
filter_exp
=
PaymentBPHTB
.
tgl
.
between
(
today
-
timedelta
(
weeks
=
6
),
today
)
week
,
weekTrx
,
weekly
,
weeklyTrx
,
weeklyAcc
,
weeklyAccTrx
=
\
self
.
get_daily_data
(
PaymentBPHTB
,
field
,
None
,
filter_exp
)
ytd_target
=
float
(
self
.
get_targets
(
"bphtb"
))
ytd_persen
=
round
(
ytd
/
ytd_target
*
100
,
2
)
if
ytd_target
>
0
else
0
return
{
"today"
:
amt
,
...
...
@@ -379,15 +338,15 @@ class Views(BaseView):
today
=
datetime
.
now
()
.
date
()
filter_ex
=
[]
#Harian
field
=
func
.
to_char
(
PaymentPAD
.
tgl
,
'yyyy-mm-dd'
)
filter_exp
=
PaymentPAD
.
tgl
.
between
(
today
-
timedelta
(
6
),
today
)
filter_exp
=
PaymentPAD
.
tgl
.
between
(
today
-
timedelta
(
days
=
6
),
today
)
amt
,
trx
,
daily
,
dailyTrx
,
dailyAcc
,
dailyAccTrx
=
\
self
.
get_daily_data
(
PaymentPAD
,
field
,
today
.
strftime
(
"
%
Y-
%
m-
%
d"
),
filter_exp
,
typ
)
filter_exp
=
PaymentPAD
.
tgl
.
between
(
today
-
timedelta
(
days
=
6
),
today
)
#Total Tahun Berjalan
field
=
func
.
to_char
(
PaymentPAD
.
tgl
,
'IYYY'
)
filter_exp
=
PaymentPAD
.
tgl
.
between
(
datetime
.
strptime
(
f
"{today.year}-01-01"
,
"
%
Y-
%
m-
%
d"
),
today
)
...
...
@@ -395,15 +354,19 @@ class Views(BaseView):
self
.
get_daily_data
(
PaymentPAD
,
field
,
str
(
today
.
year
),
filter_exp
,
typ
)
#Bulanan
field
=
func
.
to_char
(
PaymentPAD
.
tgl
,
'MM'
)
month
,
monthTrx
,
monthly
,
monthlyTrx
,
monthlyAcc
,
monthlyAccTrx
=
\
self
.
get_daily_data
(
PaymentPAD
,
field
,
None
,
filter_exp
,
typ
)
#Mingguan
field
=
func
.
to_char
(
PaymentPAD
.
tgl
,
'WW'
)
filter_exp
=
PaymentPAD
.
tgl
.
between
(
today
-
timedelta
(
weeks
=
6
),
today
)
week
,
weekTrx
,
weekly
,
weeklyTrx
,
weeklyAcc
,
weeklyAccTrx
=
\
self
.
get_daily_data
(
PaymentPAD
,
field
,
None
,
filter_exp
,
typ
)
#Target
ytd_target
=
float
(
self
.
get_targets
(
typ
))
ytd_persen
=
round
(
ytd
/
ytd_target
*
100
,
2
)
if
ytd_target
>
0
else
0
return
{
"today"
:
amt
,
...
...
@@ -434,19 +397,16 @@ class Views(BaseView):
today
=
datetime
.
strptime
(
'2025-06-05'
,
"
%
Y-
%
m-
%
d"
)
else
:
today
=
datetime
.
now
()
.
date
()
filter_ex
=
[]
# if typ == 'hotel':
# filter_ex = [PaymentPAD.jenis_pajak == "PBJT - JASA PERHOTELAN",]
# Harian
field
=
func
.
to_char
(
PaymentWEBR
.
tgl
,
'yyyy-mm-dd'
)
filter_exp
=
PaymentWEBR
.
tgl
.
between
(
today
-
timedelta
(
6
),
today
)
today
-
timedelta
(
days
=
6
),
today
)
amt
,
trx
,
daily
,
dailyTrx
,
dailyAcc
,
dailyAccTrx
=
\
self
.
get_daily_data
(
PaymentWEBR
,
field
,
today
.
strftime
(
"
%
Y-
%
m-
%
d"
),
filter_exp
)
filter_exp
=
PaymentWEBR
.
tgl
.
between
(
today
-
timedelta
(
days
=
6
),
today
)
#Tahunan
field
=
func
.
to_char
(
PaymentWEBR
.
tgl
,
'IYYY'
)
filter_exp
=
PaymentWEBR
.
tgl
.
between
(
datetime
.
strptime
(
f
"{today.year}-01-01"
,
"
%
Y-
%
m-
%
d"
),
today
)
...
...
@@ -454,10 +414,12 @@ class Views(BaseView):
self
.
get_daily_data
(
PaymentWEBR
,
field
,
str
(
today
.
year
),
filter_exp
)
#Bulanan
field
=
func
.
to_char
(
PaymentWEBR
.
tgl
,
'YYYY-MM'
)
month
,
monthTrx
,
monthly
,
monthlyTrx
,
monthlyAcc
,
monthlyAccTrx
=
\
self
.
get_daily_data
(
PaymentWEBR
,
field
,
None
,
filter_exp
)
#Mingguan
field
=
func
.
to_char
(
PaymentWEBR
.
tgl
,
'YYYY-WW'
)
filter_exp
=
PaymentWEBR
.
tgl
.
between
(
today
-
timedelta
(
weeks
=
6
),
today
)
...
...
@@ -630,20 +592,19 @@ class Views(BaseView):
if
jenis
==
"pbb"
:
realisasi
=
self
.
get_pbb_data
()[
"ytd"
]
elif
jenis
==
"bphtb"
:
elif
jenis
==
"bphtb"
:
realisasi
=
self
.
get_bphtb_data
()[
"ytd"
]
else
:
realisasi
=
self
.
get_pad_data
(
jenis
)[
"ytd"
]
return
{
jenis
:
{
"kode"
:
jenis_pajak
[
jenis
][
"kode"
]
.
ljust
(
8
,
'0'
),
"nama"
:
jenis_pajak
[
jenis
][
"nama"
],
"target"
:
target
,
"realisasi"
:
realisasi
,
"sisa"
:
target
-
realisasi
,
"persen"
:
round
(
realisasi
/
target
*
100
,
2
)
if
target
>
0
else
0
}
"persen"
:
round
(
realisasi
/
target
*
100
,
2
)
if
target
>
0
else
0
}
}
@view_config
(
route_name
=
'eis-pcpd-act'
,
renderer
=
'json'
)
...
...
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