Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Owo Sugiana
/
opensipkd-webr-models
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 db3ca99f
authored
Dec 20, 2022
by
iwan
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
webr jabar
1 parent
7fe4f9dc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
256 additions
and
5 deletions
opensipkd/webr/models/jabar.py
opensipkd/webr/services/jabar.py
opensipkd/webr/models/jabar.py
View file @
db3ca99
...
@@ -5,6 +5,8 @@ from sqlalchemy import (
...
@@ -5,6 +5,8 @@ from sqlalchemy import (
Float
,
Float
,
Date
,
Date
,
DateTime
,
DateTime
,
ForeignKey
,
UniqueConstraint
,
)
)
from
sqlalchemy.ext.declarative
import
declarative_base
from
sqlalchemy.ext.declarative
import
declarative_base
...
@@ -48,6 +50,18 @@ class User(Base):
...
@@ -48,6 +50,18 @@ class User(Base):
api_key
=
Column
(
String
(
256
))
api_key
=
Column
(
String
(
256
))
class
Pajak
(
Base
):
__tablename__
=
'pajaks'
id
=
Column
(
Integer
,
primary_key
=
True
)
kode
=
Column
(
String
(
64
))
nama
=
Column
(
String
(
128
))
tahun
=
Column
(
Integer
)
tarif
=
Column
(
Float
)
rekening_id
=
Column
(
Integer
)
denda_rekening_id
=
Column
(
Integer
)
status
=
Column
(
Integer
)
class
Subjek
(
Base
):
class
Subjek
(
Base
):
__tablename__
=
'subjekpajaks'
__tablename__
=
'subjekpajaks'
id
=
Column
(
Integer
,
primary_key
=
True
)
id
=
Column
(
Integer
,
primary_key
=
True
)
...
@@ -80,7 +94,7 @@ class Objek(Base):
...
@@ -80,7 +94,7 @@ class Objek(Base):
unit_id
=
Column
(
Integer
,
ForeignKey
(
Unit
.
id
))
unit_id
=
Column
(
Integer
,
ForeignKey
(
Unit
.
id
))
pajak_id
=
Column
(
Integer
,
ForeignKey
(
Pajak
.
id
))
pajak_id
=
Column
(
Integer
,
ForeignKey
(
Pajak
.
id
))
subjekpajak_id
=
Column
(
Integer
,
ForeignKey
(
Subjek
.
id
))
subjekpajak_id
=
Column
(
Integer
,
ForeignKey
(
Subjek
.
id
))
__table_args__
=
UniqueConstraint
(
'subjekpajak_id'
,
'kode'
)
#
__table_args__ = UniqueConstraint('subjekpajak_id', 'kode')
class
Rekening
(
Base
):
class
Rekening
(
Base
):
...
...
opensipkd/webr/services/jabar.py
View file @
db3ca99
from
.default
import
AvailableInvoice
from
time
import
time
from
datetime
import
(
date
,
datetime
,
)
from
sqlalchemy.sql
import
func
from
opensipkd.hitung
import
(
hitung_denda
,
round_up
,
)
from
opensipkd.string.money
import
thousand
from
opensipkd.string.transaction_id
import
TransactionID
from
..models.jabar
import
(
from
..models.jabar
import
(
Invoice
,
Invoice
,
Payment
,
Payment
,
)
)
from
.base
import
get_db_session
def
date_from_str
(
s
):
d
,
m
,
y
=
[
int
(
x
)
for
x
in
s
.
split
(
'-'
)]
return
date
(
y
,
m
,
d
)
# Nomor Transaksi Pemda
class
NTP
(
TransactionID
):
payment_model
=
Payment
def
is_found
(
self
,
tid
):
DBSession
=
get_db_session
()
q
=
DBSession
.
query
(
self
.
payment_model
)
.
filter_by
(
ntp
=
tid
)
return
q
.
first
()
class
Inquiry
:
invoice_model
=
Invoice
payment_model
=
Payment
ntp_cls
=
NTP
def
__init__
(
self
,
invoice_id
,
persen_denda
=
2
,
tgl_bayar
=
None
):
self
.
invoice_id
=
invoice_id
self
.
persen_denda
=
persen_denda
self
.
tgl_bayar
=
tgl_bayar
or
date
.
today
()
DBSession
=
get_db_session
()
q
=
DBSession
.
query
(
self
.
invoice_model
)
.
filter_by
(
kode
=
invoice_id
)
self
.
invoice
=
q
.
first
()
if
not
self
.
invoice
:
return
if
not
self
.
is_available
():
self
.
invoice
=
None
return
self
.
hitung
()
def
get_payment
(
self
):
DBSession
=
get_db_session
()
q
=
DBSession
.
query
(
self
.
payment_model
)
.
filter_by
(
arinvoice_id
=
self
.
invoice
.
id
)
q
=
q
.
filter
(
self
.
payment_model
.
bayar
>
0
)
q
=
q
.
order_by
(
self
.
payment_model
.
pembayaran_ke
.
desc
())
return
q
.
first
()
def
get_total_payment
(
self
):
DBSession
=
get_db_session
()
q
=
DBSession
.
query
(
func
.
sum
(
self
.
payment_model
.
bayar
)
.
label
(
'jml'
))
q
=
q
.
filter_by
(
arinvoice_id
=
self
.
invoice
.
id
)
pay
=
q
.
first
()
return
pay
and
int
(
pay
.
jml
or
0
)
def
hitung
(
self
):
bunga
=
self
.
invoice
.
bunga
or
0
bunga
=
round_up
(
bunga
)
self
.
tagihan
=
self
.
invoice
.
jumlah
-
bunga
self
.
tagihan
=
round_up
(
self
.
tagihan
)
bln
,
denda_waktu
=
hitung_denda
(
self
.
tagihan
,
self
.
invoice
.
jatuh_tempo
,
self
.
persen_denda
,
self
.
tgl_bayar
)
self
.
denda
=
denda_waktu
+
bunga
self
.
denda
=
round_up
(
self
.
denda
)
self
.
total
=
self
.
tagihan
+
self
.
denda
self
.
total_bayar
=
self
.
get_total_payment
()
if
self
.
total_bayar
>
0
:
self
.
total
-=
self
.
total_bayar
if
self
.
total
<
0
:
self
.
total
=
0
def
is_available
(
self
):
return
self
.
invoice
.
status_bayar
in
(
0
,
1
)
def
get_nama
(
self
):
return
self
.
invoice
.
wp_nama
.
upper
()
def
get_alamat_1
(
self
):
if
self
.
invoice
.
op_alamat_1
:
return
self
.
invoice
.
op_alamat_1
.
upper
()
def
get_alamat_2
(
self
):
if
self
.
invoice
.
op_alamat_2
:
return
self
.
invoice
.
op_alamat_2
.
upper
()
def
get_kode_rekening
(
self
):
return
self
.
invoice
.
rek_kode
def
get_nama_rekening
(
self
):
return
self
.
invoice
.
rek_nama
.
upper
()
def
get_kode_departemen
(
self
):
return
self
.
invoice
.
unit_kode
def
get_nama_departemen
(
self
):
return
self
.
invoice
.
unit_nama
.
upper
()
def
get_jatuh_tempo
(
self
):
return
self
.
invoice
.
jatuh_tempo
def
get_pembayaran_ke
(
self
):
DBSession
=
get_db_session
()
q
=
DBSession
.
query
(
self
.
payment_model
)
.
filter_by
(
arinvoice_id
=
self
.
invoice
.
id
)
q
=
q
.
order_by
(
self
.
payment_model
.
pembayaran_ke
.
desc
())
row
=
q
.
first
()
if
row
:
return
row
.
pembayaran_ke
+
1
return
1
def
do_payment
(
self
,
ntb
,
bank_id
=
None
,
channel_id
=
None
):
DBSession
=
get_db_session
()
ntp_generator
=
self
.
ntp_cls
()
ntp
=
ntp_generator
.
create
()
pembayaran_ke
=
self
.
get_pembayaran_ke
()
created
=
datetime
.
now
()
pay
=
self
.
payment_model
(
ntp
=
ntp
,
posted
=
0
,
create_date
=
created
,
update_date
=
created
,
tgl_bayar
=
self
.
tgl_bayar
,
tahun_id
=
self
.
invoice
.
tahun_id
,
unit_id
=
self
.
invoice
.
unit_id
,
arinvoice_id
=
self
.
invoice
.
id
,
pembayaran_ke
=
pembayaran_ke
,
bayar
=
self
.
total
,
bunga
=
self
.
denda
,
ntb
=
ntb
,
bank_id
=
bank_id
,
channel_id
=
channel_id
)
DBSession
.
add
(
pay
)
self
.
invoice
.
status
=
1
DBSession
.
add
(
self
.
invoice
)
DBSession
.
flush
()
return
pay
class
Reversal
(
Inquiry
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
()
.
__init__
(
*
args
,
**
kwargs
)
if
self
.
invoice
:
self
.
payment
=
self
.
get_payment
()
def
do_reversal
(
self
):
DBSession
=
get_db_session
()
self
.
invoice
.
status_bayar
=
0
DBSession
.
add
(
self
.
invoice
)
if
self
.
payment
:
self
.
payment
.
bayar
=
0
DBSession
.
add
(
self
.
payment
)
DBSession
.
flush
()
class
AvailableInvoice
:
invoice_model
=
Invoice
def
__init__
(
self
,
persen_denda
=
2
,
option
=
None
):
self
.
option
=
option
self
.
persen_denda
=
persen_denda
def
show
(
self
):
offset
=
-
1
count
=
0
max_count_length
=
len
(
str
(
self
.
option
.
count
))
q
=
self
.
get_query
()
awal
=
time
()
while
True
:
if
time
()
-
awal
>
10
:
break
offset
+=
1
row
=
q
.
offset
(
offset
)
.
first
()
if
not
row
:
break
msg
=
self
.
get_message
(
row
)
if
not
msg
:
continue
count
+=
1
no
=
str
(
count
)
.
zfill
(
max_count_length
)
msg
=
f
'#{no}/{self.option.count} {msg}'
print
(
msg
)
if
count
==
self
.
option
.
count
:
break
def
get_query
(
self
):
DBSession
=
get_db_session
()
q
=
DBSession
.
query
(
self
.
invoice_model
)
.
filter_by
(
status_bayar
=
0
)
q
=
self
.
get_filter_tahun
(
q
)
q
=
self
.
get_filter_nominal
(
q
)
q
=
self
.
get_filter_jatuh_tempo
(
q
)
return
q
def
get_filter_tahun
(
self
,
q
):
if
self
.
option
.
tahun
:
q
=
q
.
filter_by
(
tahun
=
self
.
option
.
tahun
)
return
q
def
get_filter_nominal
(
self
,
q
):
if
self
.
option
.
nominal_min
:
q
=
q
.
filter
(
self
.
invoice_model
.
jumlah
-
self
.
invoice_model
.
bunga
>=
self
.
option
.
nominal_min
)
if
self
.
option
.
nominal_max
:
q
=
q
.
filter
(
self
.
invoice_model
.
jumlah
-
self
.
invoice_model
.
bunga
<=
self
.
option
.
nominal_max
)
return
q
def
get_filter_jatuh_tempo
(
self
,
q
):
if
self
.
option
.
jatuh_tempo_min
:
tgl
=
date_from_str
(
self
.
option
.
jatuh_tempo_min
)
q
=
q
.
filter
(
self
.
invoice_model
.
jatuh_tempo
>=
tgl
)
if
self
.
option
.
jatuh_tempo_max
:
tgl
=
date_from_str
(
self
.
option
.
jatuh_tempo_max
)
q
=
q
.
filter
(
self
.
invoice_model
.
jatuh_tempo
<=
tgl
)
return
q
class
AvailableInvoice
(
BaseAvailableInvoice
):
def
get_message
(
self
,
row
):
invoice_model
=
Invoice
# Override
inq
=
Inquiry
(
row
.
kode
,
persen_denda
=
self
.
persen_denda
)
payment_model
=
Payment
# Override
if
not
inq
.
total
:
return
total
=
thousand
(
inq
.
total
)
tagihan
=
thousand
(
inq
.
tagihan
)
denda
=
thousand
(
inq
.
denda
)
s
=
f
'{row.kode} Tagihan Rp {tagihan} + Denda Rp {denda} = Rp {total}'
jatuh_tempo
=
inq
.
invoice
.
jatuh_tempo
if
jatuh_tempo
:
jatuh_tempo
=
jatuh_tempo
.
strftime
(
'
%
d-
%
m-
%
Y'
)
s
=
f
'{s} jatuh tempo {jatuh_tempo}'
return
s
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