available_invoice.py
1.83 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
import sys
import locale
from time import time
from configparser import ConfigParser
from sqlalchemy import create_engine
from opensipkd.base.models import DBSession
from opensipkd.bphtb.cilegon.models import (
Spt,
DetailSpt,
Pembayaran,
)
import opensipkd.bphtb.cilegon.services
opensipkd.bphtb.cilegon.services.DBSession = DBSession
locale.setlocale(locale.LC_ALL, 'id_ID.utf8')
registry = dict()
Inquiry = opensipkd.bphtb.cilegon.services.Inquiry
def thousand(n):
return locale.format('%.0f', n, True)
class AvailableInvoice:
def __init__(self, count=10):
self.count = count
def run(self):
q_pay = DBSession.query(Pembayaran).\
filter(Pembayaran.t_statusbayarspt == None).\
order_by(Pembayaran.t_idpembayaranspt.desc())
offset = -1
self.no = 0
awal = time()
while True:
offset += 1
pay = q_pay.offset(offset).limit(1).first()
if not pay:
break
self.row_handler(pay)
if time() - awal > 10:
break
if self.no == self.count:
break
def row_handler(self, pay):
inq = Inquiry(pay.t_kodebayarbanksppt, registry['persen_denda'])
if not inq.total:
return
self.no += 1
nominal = thousand(inq.total)
msg = '#{} {} {} {} {} Rp {}'.format(
self.no, inq.invoice_id, inq.get_tahun(), inq.get_nop(),
inq.get_nama(), nominal)
print(msg)
def main(argv=sys.argv):
conf_file = argv[1]
conf = ConfigParser()
conf.read(conf_file)
db_url = conf.get('main', 'db_url')
engine = create_engine(db_url)
DBSession.configure(bind=engine)
registry['persen_denda'] = conf.getfloat('main', 'persen_denda')
a = AvailableInvoice()
a.run()