bphtb.py
4.2 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
import sys
from sqlalchemy import (
Column,
Integer,
DateTime,
String,
Date,
ForeignKey,
)
import transaction
from opensipkd.waktu import dmyhms
from opensipkd.bphtb.models.default import (
Payment,
Invoice,
Perolehan,
Customer,
)
from opensipkd.bphtb.services.base import get_db_session
from iso8583_web.models.meta import Base as BaseConf
from opensipkd.iso8583.bjb.bphtb import Doc
from ..models import (
Base,
Bphtb,
)
from .common import (
get_iso,
get_keys,
App as BaseApp,
init_db as base_init_db,
)
class IsoPayment(Base):
__tablename__ = 'bphtb_payment'
__table_args__ = dict(schema='bphtb')
id = Column(Integer, ForeignKey(Payment.id), primary_key=True)
tgl = Column(DateTime(timezone=True), nullable=False)
iso_request = Column(String(1024), nullable=False)
transmission = Column(DateTime(timezone=True), nullable=False)
settlement = Column(Date, nullable=False)
stan = Column(Integer, nullable=False)
invoice_id = Column(Integer, ForeignKey(Invoice.id), nullable=False)
invoice_no = Column(String(32), nullable=False)
ntb = Column(String(32), nullable=False)
ntp = Column(String(32), nullable=False, unique=True)
bank_id = Column(Integer)
channel_id = Column(Integer)
bank_ip = Column(String(15), nullable=False)
class IsoReversal(Base):
__tablename__ = 'bphtb_reversal'
__table_args__ = dict(schema='public')
id = Column(Integer, ForeignKey(IsoPayment.id), primary_key=True)
tgl = Column(DateTime(timezone=True), nullable=False)
iso_request = Column(String(1024), nullable=False)
class App(BaseApp):
iso_class = Doc
report_orm = Bphtb
iso_reversal_orm = IsoReversal
def __init__(self, argv):
super().__init__(argv)
if not self.pid:
return
self.base_q_inv = self.prod_session.query(
Invoice, Customer, Perolehan).filter(
Invoice.ppat_id == Customer.id,
Invoice.perolehan_id == Perolehan.id)
def get_db_session(self): # Override
return get_db_session()
def run_payment(self): # Override
last = self.get_last_id('bphtb payment last id')
q_iso = self.prod_session.query(IsoPayment, Payment).filter(
IsoPayment.id == Payment.id,
IsoPayment.id > last.as_int())
for row_iso, row_pay in q_iso.order_by(IsoPayment.id):
if row_iso.iso_request[0] == '{':
last.nilai = str(row_iso.id)
with transaction.manager:
self.rpt_session.add(last)
continue
iso = get_iso(row_iso.iso_request, Doc, self.option.debug)
if self.get_report(iso):
continue
tgl_bayar = row_iso.tgl.date()
q_inv = self.base_q_inv.filter(Invoice.id == row_pay.sspd_id)
inv, ppat, perolehan = q_inv.first()
d = get_keys(iso)
s_tgl = dmyhms(row_iso.tgl)
self.log.info(
f'Tgl bayar {s_tgl}, Nomor bayar {d["nomor_bayar"]}, '
f'STAN {d["stan"]}, NTB {d["ntb"]}, Channel {d["channel"]}')
rpt = Bphtb(
stan=d['stan'], ntb=d['ntb'], tgl=tgl_bayar,
jam=row_iso.tgl.time(),
invoice_id=iso.get_invoice_id().strip(),
nop=row_pay.nop, wp_nama=row_pay.wp_nama,
wp_alamat=row_pay.wp_alamat, op_alamat=inv.op_alamat,
npop=row_pay.npop, bumi_luas=row_pay.bumi_luas,
bng_luas=row_pay.bng_luas, nilai_bphtb=row_pay.bayar,
jenis_perolehan=perolehan.nama, ppat=ppat.nama,
channel_id=iso.get_channel().strip(),
channel_nama=d['channel'])
last.nilai = str(row_iso.id)
with transaction.manager:
self.rpt_session.add(rpt)
self.rpt_session.add(last)
def run_reversal(self): # Override
super().run_reversal('bphtb reversal last date')
def main(argv=sys.argv[1:]):
app = App(argv)
if app.pid:
app.run()
def init_db(argv=sys.argv[1:]):
base_init_db(Base.metadata, BaseConf.metadata, argv)