payment.py
8.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
from datetime import timedelta, datetime
import sys
from opensipkd.base.models import (
Base, CommonModel, DefaultModel, NamaModel, KodeModel,
TABLE_ARGS
)
from sqlalchemy import (Column, Integer, DateTime, String, Text, ForeignKey, Float,
Boolean, BigInteger, SmallInteger, desc, asc, Date, Time,
UniqueConstraint, func)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import engine_from_config
from opensipkd.tools import get_settings
from sqlalchemy.orm import (
scoped_session,
sessionmaker,
)
from pyramid.paster import (
get_appsettings,
setup_logging,
)
from ..tools import create_now
PCDBSession = scoped_session(sessionmaker())
PCBase = declarative_base()
class PaymentPBB(PCBase, DefaultModel):
__tablename__ = 'pbb_report'
__table_args__ = {'schema': 'public'}
id = Column(BigInteger, primary_key=True)
stan = Column(String(6), nullable=False)
ntb = Column(String(32), nullable=False)
kd_propinsi = Column(String(2))
kd_dati2 = Column(String(2))
kd_kecamatan = Column(String(3))
kd_kelurahan = Column(String(3))
kd_blok = Column(String(3))
no_urut = Column(String(4))
kd_jns_op = Column(String(1))
thn_pajak_sppt = Column(String(4))
pembayaran_sppt_ke = Column(SmallInteger)
nm_wp_sppt = Column(String(30))
tgl_pembayaran_sppt = Column(DateTime)
tgl_rekam_byr_sppt = Column(DateTime)
tgl_inquiry = Column(DateTime)
pbb_yg_harus_dibayar_sppt = Column(Integer)
denda_sppt = Column(Integer)
jml_sppt_yg_dibayar = Column(Integer)
channel_kode = Column(String(6))
channel_nama = Column(String(256))
user_id = Column(String(128))
iso_request = Column(String(2048))
discount = Column(BigInteger)
bank_id = Column(String(4))
tgl_batal = Column(DateTime(timezone=True))
__table_args__ = (
UniqueConstraint('stan', 'ntb'),
)
@classmethod
def qry_sum(cls, columns=[]):
qry = PCDBSession.query(
func.sum(cls.jml_sppt_yg_dibayar).label('bayar'),
func.sum(cls.denda_sppt).label('denda'),
func.count(cls.id).label('trx')).select_from(cls)
for col in columns:
qry=qry.add_columns(col)
return qry
@classmethod
def sum_data(cls):
return PCDBSession.query(
func.to_char(cls.tgl_pembayaran_sppt,
'yyyy-mm-dd').label('tanggal'),
func.sum(cls.jml_sppt_yg_dibayar).label('bayar'),
func.sum(cls.denda_sppt).label('denda'))\
.group_by(func.to_char(cls.tgl_pembayaran_sppt, 'yyyy-mm-dd'))
@classmethod
def sum_daily(cls, length=0):
now = datetime.now()
tod = now.date
tom = tod + timedelta(days=1)
if length:
tod = tod-timedelta(days=length)
return cls.sum_data().filter(cls.tgl_pembayaran_sppt.between(tod, tom))
# baru dari db BPHTB
class PaymentBPHTB(PCBase, CommonModel):
__tablename__ = 'bphtb_report'
__table_args__ = {'schema': 'public'}
id = Column(Integer, primary_key=True)
stan = Column(String(6), nullable=False)
ntb = Column(String(32), nullable=False)
tgl = Column(Date, nullable=False)
jam = Column(Time, nullable=False)
invoice_id = Column(String(24), nullable=False)
nop = Column(String(24), nullable=False)
wp_nama = Column(String(50), nullable=False)
wp_alamat = Column(String(100), nullable=False)
op_alamat = Column(String(100), nullable=False)
npop = Column(BigInteger)
bumi_luas = Column(BigInteger)
bng_luas = Column(BigInteger)
nilai_bphtb = Column(BigInteger)
channel_id = Column(String(6))
channel_nama = Column(String(256), nullable=False)
# user_id = Column(String(128), nullable=False)
jenis_perolehan = Column(String(123), nullable=False)
ppat = Column(String(256), nullable=False)
tgl_batal = Column(DateTime(timezone=True))
__table_args__ = (
UniqueConstraint('stan', 'ntb'),
)
@classmethod
def sum_data(cls):
return PCDBSession.query(func.sum(cls.nilai_bphtb).label('bayar'),
func.sum('0').label('denda'))
@classmethod
def sum_today(cls):
now = datetime.now()
tom = timedelta(now.date, days=1)
qry = cls.sum_data().filter(cls.tgl.between(now.date, tom))
return qry.first()
# baru PAD
class PaymentPAD(PCBase, CommonModel):
__tablename__ = 'pad_report'
__table_args__ = {'schema': 'public'}
id = Column(Integer, primary_key=True)
stan = Column(String(6), nullable=False)
ntb = Column(String(32), nullable=False)
# pad.pad_sspd.create_date
tgl = Column(Date, nullable=False)
# pad.pad_sspd.sspdjam
jam = Column(Time, nullable=False)
# pad.pad_sspd.id
sspd_id = Column(Integer, nullable=False)
# Bit 61
nomor_bayar = Column(String(16), nullable=False)
# Pad.Usahanm
jenis_pajak = Column(String(32), nullable=False)
# pad.pad_spt.masadari
masa_pajak = Column(Date, nullable=False)
# pad.pad_customer
npwpd = Column(String(17), nullable=False)
# pad.pad_customer.customernm
nama_wp = Column(String(150), nullable=False)
# pad.pad_sspd.jml_bayar - pad.pad_sspd.denda
pokok = Column(Float, nullable=False)
# pad.pad_sspd.denda
denda = Column(Float, nullable=False)
# pad.pad_sspd.bunga
bunga = Column(Float, nullable=False)
# pad.pad_sspd.jml_bayar
jml_bayar = Column(Float, nullable=False)
# Bit 18
channel_id = Column(String(4), nullable=False)
# Bit 41 / 42 / 43
channel_name = Column(String(32), nullable=False)
# Dari pad_reversal
tgl_batal = Column(DateTime(timezone=True))
# pad.kecamatan.kecamatannm
kecamatan_nm = Column(String(50), nullable=False)
__table_args__ = (
UniqueConstraint('stan', 'ntb'),
)
@classmethod
def sum_data(cls):
return PCDBSession.query(func.sum(cls.jml_bayar).label('bayar'),
func.sum(cls.denda+cls.bunga).label('denda'))
@classmethod
def sum_today(cls):
now = datetime.now()
tom = timedelta(now.date, days=1)
qry = cls.sum_data().filter(cls.tgl.between(now.date, tom))
return qry.first()
# baru PAD
class PaymentWEBR(PCBase, CommonModel):
__tablename__ = 'webr_report'
__table_args__ = {'schema': 'public'}
id = Column(Integer, primary_key=True)
stan = Column(String(6), nullable=False)
ntb = Column(String(32), nullable=False)
tgl = Column(Date, nullable=False)
jam = Column(Time, nullable=False)
payment_id = Column(Integer, nullable=False)
nomor_bayar = Column(String(16), nullable=False)
nama_wp = Column(String(150), nullable=False)
# webr.payment.jml_bayar - webr.payment.denda
pokok = Column(Float, nullable=False)
# webr.payment.denda
denda = Column(Float, nullable=False)
# webr.payment.jml_bayar
jml_bayar = Column(Float, nullable=False)
# Bit 18
channel_id = Column(String(4), nullable=False)
# Bit 41 / 42 / 43
channel_name = Column(String(32), nullable=False)
# Dari pad_reversal
tgl_batal = Column(DateTime(timezone=True))
# webr.payment.status
status = Column(String(2), nullable=False)
__table_args__ = (
UniqueConstraint('stan', 'ntb'),
)
@classmethod
def sum_data(cls):
return PCDBSession.query(func.sum(cls.jml_bayar).label('bayar'),
func.sum(cls.denda).label('denda'))
@classmethod
def sum_today(cls):
now = datetime.now()
tom = timedelta(now.date, days=1)
qry = cls.sum_data().filter(cls.tgl.between(now.date, tom))
return qry.first()
def get_connection(settings):
url = 'pcpd.url' in settings and settings['pcpd.url'] and 'pcpd.' or 'sqlalchemy.'
engine = engine_from_config(settings, url)
PCDBSession.configure(bind=engine)
PCBase.metadata.bind = engine
return engine
def includeme(config):
settings = get_settings()
get_connection(settings)
def init_db(argv=sys.argv):
config_uri = argv[1]
setup_logging(config_uri)
settings = get_appsettings(config_uri)
engine = get_connection(settings)
PCBase.metadata.bind = engine
PCBase.metadata.create_all(bind=engine)