Commit 60ffe639 by Owo Sugiana

Tambah tasik_kabupaten

1 parent b6663386
0.2.1 2020-05-18
----------------
- Tidak perlu lagi tabel bphtb_config karena opsi Invoice ID 16 digit juga
tidak ada.
- Tambah tasik_kabupaten
0.2 2020-05-09 0.2 2020-05-09
-------------- --------------
- Konfigurasi kini memuat nama modul - Konfigurasi kini memuat nama modul
......
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from zope.sqlalchemy import register
from ..tangerang_kabupaten import set_conf
import opensipkd.bphtb.cilegon.services
def init(conf):
set_conf(conf, 'persen_denda', 2.0)
engine = create_engine(conf['db_url'])
session_factory = sessionmaker(bind=engine)
DBSession = session_factory()
register(DBSession)
opensipkd.bphtb.cilegon.services.DBSession = DBSession
...@@ -173,6 +173,9 @@ class Inquiry: ...@@ -173,6 +173,9 @@ class Inquiry:
row = q.first() row = q.first()
return row.jml or 0 return row.jml or 0
def is_available(self):
return not self.payment.t_statusbayarspt
def do_payment(self, ntb): def do_payment(self, ntb):
self.payment.t_tanggalpembayaran = self.tgl_bayar self.payment.t_tanggalpembayaran = self.tgl_bayar
self.payment.t_nilaipembayaranspt = self.total self.payment.t_nilaipembayaranspt = self.total
......
...@@ -2,8 +2,6 @@ import sys ...@@ -2,8 +2,6 @@ import sys
from configparser import ConfigParser from configparser import ConfigParser
from argparse import ArgumentParser from argparse import ArgumentParser
from optparse import OptionParser from optparse import OptionParser
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
def get_option(argv): def get_option(argv):
...@@ -26,12 +24,9 @@ def main(argv=sys.argv): ...@@ -26,12 +24,9 @@ def main(argv=sys.argv):
module_name = conf.get('main', 'module') module_name = conf.get('main', 'module')
module = __import__('opensipkd.bphtb.' + module_name + '.services') module = __import__('opensipkd.bphtb.' + module_name + '.services')
area_module = getattr(module.bphtb, module_name) area_module = getattr(module.bphtb, module_name)
cf = dict(conf['main'])
area_module.init(cf)
services_module = getattr(area_module, 'services') services_module = getattr(area_module, 'services')
AvailableInvoice = services_module.AvailableInvoice AvailableInvoice = services_module.AvailableInvoice
db_url = conf.get('main', 'db_url') a = AvailableInvoice(cf['persen_denda'], option)
persen_denda = conf.getfloat('main', 'persen_denda')
engine = create_engine(db_url)
session_factory = sessionmaker(bind=engine)
services_module.DBSession = session_factory()
a = AvailableInvoice(persen_denda, option)
a.show() a.show()
...@@ -5,7 +5,6 @@ from optparse import OptionParser ...@@ -5,7 +5,6 @@ from optparse import OptionParser
from sqlalchemy import create_engine from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker from sqlalchemy.orm import sessionmaker
import transaction import transaction
from zope.sqlalchemy import register
from opensipkd.string.money import thousand from opensipkd.string.money import thousand
...@@ -74,11 +73,10 @@ def main(argv=sys.argv): ...@@ -74,11 +73,10 @@ def main(argv=sys.argv):
module_name = conf.get('main', 'module') module_name = conf.get('main', 'module')
module = __import__('opensipkd.bphtb.' + module_name + '.services') module = __import__('opensipkd.bphtb.' + module_name + '.services')
area_module = getattr(module.bphtb, module_name) area_module = getattr(module.bphtb, module_name)
cf = dict(conf['main'])
area_module.init(cf)
services_module = getattr(area_module, 'services') services_module = getattr(area_module, 'services')
AvailableInvoice = services_module.AvailableInvoice AvailableInvoice = services_module.AvailableInvoice
session_factory = sessionmaker(bind=engine)
services_module.DBSession = session_factory()
register(services_module.DBSession)
inq = services_module.Inquiry( inq = services_module.Inquiry(
invoice_id, conf.getfloat('main', 'persen_denda')) invoice_id, conf.getfloat('main', 'persen_denda'))
if not inq.invoice: if not inq.invoice:
......
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from zope.sqlalchemy import register
import opensipkd.bphtb.tangerang_kabupaten.services
def set_conf(conf, name, default=None):
func = type(default)
if name in conf:
conf[name] = func(conf.get(name))
else:
conf[name] = 2
def init(conf):
set_conf(conf, 'persen_denda', 2.0)
engine = create_engine(conf['db_url'])
session_factory = sessionmaker(bind=engine)
DBSession = session_factory()
register(DBSession)
opensipkd.bphtb.tangerang_kabupaten.services.DBSession = DBSession
...@@ -280,7 +280,6 @@ class Payment(Base): ...@@ -280,7 +280,6 @@ class Payment(Base):
kd_kantor = Column(String(2)) kd_kantor = Column(String(2))
kd_bank_tunggal = Column(String(2)) kd_bank_tunggal = Column(String(2))
kd_bank_persepsi = Column(String(2)) kd_bank_persepsi = Column(String(2))
wp_propinsi = Column(String(100))
pembayaran_ke = Column(Integer, nullable=False) pembayaran_ke = Column(Integer, nullable=False)
__table_args__ = ( __table_args__ = (
UniqueConstraint('tanggal', 'jam', 'seq', 'transno'), UniqueConstraint('tanggal', 'jam', 'seq', 'transno'),
...@@ -309,10 +308,3 @@ class IsoReversal(Base): ...@@ -309,10 +308,3 @@ class IsoReversal(Base):
id = Column(Integer, ForeignKey(IsoPayment.id), primary_key=True) id = Column(Integer, ForeignKey(IsoPayment.id), primary_key=True)
tgl = Column(DateTime(timezone=True), nullable=False, default=datetime.now) tgl = Column(DateTime(timezone=True), nullable=False, default=datetime.now)
iso_request = Column(String(1024), nullable=False) iso_request = Column(String(1024), nullable=False)
class Config(Base):
__tablename__ = 'bphtb_config'
id = Column(Integer, primary_key=True)
nama = Column(String(32), nullable=False, unique=True)
nilai = Column(String(10), nullable=False)
...@@ -14,12 +14,10 @@ from ..structure import NOP ...@@ -14,12 +14,10 @@ from ..structure import NOP
from .structure import ( from .structure import (
INVOICE_ID, INVOICE_ID,
INVOICE_ID_LENGTH, INVOICE_ID_LENGTH,
INVOICE_ID_V2,
) )
from .models import ( from .models import (
Invoice, Invoice,
Payment, Payment,
Config,
Customer, Customer,
Kecamatan, Kecamatan,
Kelurahan, Kelurahan,
...@@ -29,29 +27,23 @@ from .models import ( ...@@ -29,29 +27,23 @@ from .models import (
DBSession = None # override, please DBSession = None # override, please
def get_db_session():
return DBSession
class Common: class Common:
def __init__(self, invoice_id): def __init__(self, invoice_id):
self.invoice_id = invoice_id self.invoice_id = invoice_id
is_v1 = len(invoice_id) == INVOICE_ID_LENGTH
if is_v1:
self.invoice_struct = FixLength(INVOICE_ID) self.invoice_struct = FixLength(INVOICE_ID)
else:
self.invoice_struct = FixLength(INVOICE_ID_V2)
self.invoice_struct.set_raw(invoice_id) self.invoice_struct.set_raw(invoice_id)
self.tahun = self.invoice_struct['Tahun'] self.tahun = self.invoice_struct['Tahun']
if not is_v1:
self.tahun = '20' + self.tahun
self.tahun = int(self.tahun) self.tahun = int(self.tahun)
q = self.query_invoice() q = self.query_invoice()
self.invoice = q.first() self.invoice = q.first()
def get_db_session(self):
return DBSession
def query_invoice(self): def query_invoice(self):
kode = int(self.invoice_struct['Kode']) kode = int(self.invoice_struct['Kode'])
kode = str(kode) kode = str(kode)
DBSession = self.get_db_session()
return DBSession.query(Invoice).filter_by( return DBSession.query(Invoice).filter_by(
tahun=self.tahun, kode=kode, no_sspd=self.invoice_struct['SSPD No']) tahun=self.tahun, kode=kode, no_sspd=self.invoice_struct['SSPD No'])
...@@ -60,10 +52,12 @@ class Common: ...@@ -60,10 +52,12 @@ class Common:
def do_payment(self): def do_payment(self):
self.invoice.status_pembayaran = 1 self.invoice.status_pembayaran = 1
DBSession = self.get_db_session()
DBSession.add(self.invoice) DBSession.add(self.invoice)
def do_reversal(self): def do_reversal(self):
self.invoice.status_pembayaran = 0 self.invoice.status_pembayaran = 0
DBSession = self.get_db_session()
DBSession.add(self.invoice) DBSession.add(self.invoice)
def is_available(self): def is_available(self):
...@@ -128,10 +122,12 @@ class Inquiry(Common): ...@@ -128,10 +122,12 @@ class Inquiry(Common):
return self.invoice and self.nop_struct.get_raw() or '' return self.invoice and self.nop_struct.get_raw() or ''
def get_profile(self): def get_profile(self):
DBSession = self.get_db_session()
q = DBSession.query(DetailSpt).filter_by(t_idspt=self.invoice.t_idspt) q = DBSession.query(DetailSpt).filter_by(t_idspt=self.invoice.t_idspt)
return q.first() return q.first()
def get_kecamatan(self): def get_kecamatan(self):
DBSession = self.get_db_session()
q = DBSession.query(Kecamatan).filter_by( q = DBSession.query(Kecamatan).filter_by(
kd_propinsi=self.invoice.kd_propinsi, kd_propinsi=self.invoice.kd_propinsi,
kd_dati2=self.invoice.kd_dati2, kd_dati2=self.invoice.kd_dati2,
...@@ -139,6 +135,7 @@ class Inquiry(Common): ...@@ -139,6 +135,7 @@ class Inquiry(Common):
return q.first() return q.first()
def get_kelurahan(self): def get_kelurahan(self):
DBSession = self.get_db_session()
q = DBSession.query(Kelurahan).filter_by( q = DBSession.query(Kelurahan).filter_by(
kd_propinsi=self.invoice.kd_propinsi, kd_propinsi=self.invoice.kd_propinsi,
kd_dati2=self.invoice.kd_dati2, kd_dati2=self.invoice.kd_dati2,
...@@ -147,6 +144,7 @@ class Inquiry(Common): ...@@ -147,6 +144,7 @@ class Inquiry(Common):
return q.first() return q.first()
def get_notaris(self): def get_notaris(self):
DBSession = self.get_db_session()
q = DBSession.query(Customer).filter_by(id=self.invoice.ppat_id) q = DBSession.query(Customer).filter_by(id=self.invoice.ppat_id)
return q.first() return q.first()
...@@ -216,12 +214,14 @@ class Inquiry(Common): ...@@ -216,12 +214,14 @@ class Inquiry(Common):
return self.invoice.tgl_jatuh_tempo.date() return self.invoice.tgl_jatuh_tempo.date()
def get_payment_amount(self): def get_payment_amount(self):
DBSession = self.get_db_session()
q = DBSession.query(func.sum(Payment.bayar).label('total_bayar')).\ q = DBSession.query(func.sum(Payment.bayar).label('total_bayar')).\
filter_by(sspd_id=self.invoice.id) filter_by(sspd_id=self.invoice.id)
row = q.first() row = q.first()
return row.total_bayar or 0 return row.total_bayar or 0
def get_pay_seq(self): def get_pay_seq(self):
DBSession = self.get_db_session()
q = DBSession.query(Payment).filter_by(sspd_id=self.invoice.id) q = DBSession.query(Payment).filter_by(sspd_id=self.invoice.id)
pay = q.first() pay = q.first()
return pay and pay.pembayaran_ke + 1 or 1 return pay and pay.pembayaran_ke + 1 or 1
...@@ -234,8 +234,7 @@ class Inquiry(Common): ...@@ -234,8 +234,7 @@ class Inquiry(Common):
inv = self.invoice inv = self.invoice
tgl_catat = datetime.now() tgl_catat = datetime.now()
if not bit037: if not bit037:
s = tgl_catat.strftime('%Y%m%d%H%M%S') bit037 = tgl_catat.strftime('%m%d%H%M%S')
bit037 = s[2:]
if bit107: if bit107:
cabang = bit107[:4] cabang = bit107[:4]
users = bit107[4:] users = bit107[4:]
...@@ -261,6 +260,7 @@ class Inquiry(Common): ...@@ -261,6 +260,7 @@ class Inquiry(Common):
bng_njop=inv.bng_njop, npop=inv.npop, bayar=self.total, bng_njop=inv.bng_njop, npop=inv.npop, bayar=self.total,
denda=self.denda, bphtbjeniskd=inv.perolehan_id, denda=self.denda, bphtbjeniskd=inv.perolehan_id,
no_tagihan=self.invoice_id, pembayaran_ke=pay_seq) no_tagihan=self.invoice_id, pembayaran_ke=pay_seq)
DBSession = self.get_db_session()
DBSession.add(pay) DBSession.add(pay)
DBSession.flush() DBSession.flush()
return pay return pay
...@@ -276,6 +276,7 @@ class Reversal(Common): ...@@ -276,6 +276,7 @@ class Reversal(Common):
self.payment = self.invoice and self.get_last_payment() self.payment = self.invoice and self.get_last_payment()
def get_last_payment(self): def get_last_payment(self):
DBSession = self.get_db_session()
q = DBSession.query(Payment).filter_by(sspd_id=self.invoice.id).\ q = DBSession.query(Payment).filter_by(sspd_id=self.invoice.id).\
order_by(Payment.id.desc()) order_by(Payment.id.desc())
return q.first() return q.first()
...@@ -283,15 +284,20 @@ class Reversal(Common): ...@@ -283,15 +284,20 @@ class Reversal(Common):
def do_reversal(self): # Override def do_reversal(self): # Override
Common.do_reversal(self) Common.do_reversal(self)
self.payment.bayar = self.payment.denda = 0 self.payment.bayar = self.payment.denda = 0
DBSession = self.get_db_session()
DBSession.add(self.payment) DBSession.add(self.payment)
DBSession.flush() DBSession.flush()
class AvailableInvoice(BaseAvailableInvoice): class AvailableInvoice(BaseAvailableInvoice):
def get_db_session(self):
return DBSession
def get_inquiry_class(self):
return Inquiry
def get_query(self): def get_query(self):
q = DBSession.query(Config).filter_by(nama='prefix kode bayar') DBSession = self.get_db_session()
conf = q.first()
self.prefix = conf.nilai
q = DBSession.query(Invoice).filter_by(status_pembayaran=0) q = DBSession.query(Invoice).filter_by(status_pembayaran=0)
if self.option.tahun: if self.option.tahun:
q = q.filter_by(tahun=self.option.tahun) q = q.filter_by(tahun=self.option.tahun)
...@@ -306,23 +312,16 @@ class AvailableInvoice(BaseAvailableInvoice): ...@@ -306,23 +312,16 @@ class AvailableInvoice(BaseAvailableInvoice):
def get_message(self, row): def get_message(self, row):
invoice_id_struct = FixLength(INVOICE_ID) invoice_id_struct = FixLength(INVOICE_ID)
invoice_id_struct_v2 = FixLength(INVOICE_ID_V2)
invoice_id_struct_v2.set_raw(self.prefix)
invoice_id_struct['Tahun'] = row.tahun invoice_id_struct['Tahun'] = row.tahun
invoice_id_struct_v2['Tahun'] = str(row.tahun)[2:4] invoice_id_struct['Kode'] = row.kode.zfill(2)
invoice_id_struct['Kode'] = invoice_id_struct_v2['Kode'] = \ invoice_id_struct['SSPD No'] = row.no_sspd
row.kode.zfill(2)
invoice_id_struct['SSPD No'] = invoice_id_struct_v2['SSPD No'] = \
row.no_sspd
invoice_id = invoice_id_struct.get_raw() invoice_id = invoice_id_struct.get_raw()
invoice_id_v2 = invoice_id_struct_v2.get_raw() cls = self.get_inquiry_class()
inq = Inquiry(invoice_id, self.persen_denda) inq = cls(invoice_id, self.persen_denda)
inq = Inquiry(invoice_id_v2, self.persen_denda) # make sure
if inq.total < 1: if inq.total < 1:
return return
total = thousand(inq.total).rjust(11) total = thousand(inq.total).rjust(11)
msg = '{id} {id_v2} Rp {total}'.format( msg = '{id} Rp {total}'.format(id=invoice_id, total=total)
id=invoice_id, total=total, id_v2=invoice_id_v2)
if row.tgl_jatuh_tempo: if row.tgl_jatuh_tempo:
return '{} jatuh tempo {}'.format( return '{} jatuh tempo {}'.format(
msg, row.tgl_jatuh_tempo.strftime('%d-%m-%Y')) msg, row.tgl_jatuh_tempo.strftime('%d-%m-%Y'))
......
...@@ -7,16 +7,3 @@ INVOICE_ID = [ ...@@ -7,16 +7,3 @@ INVOICE_ID = [
INVOICE_ID_LENGTH = 0 INVOICE_ID_LENGTH = 0
for nama, size, tipe in INVOICE_ID: for nama, size, tipe in INVOICE_ID:
INVOICE_ID_LENGTH += size INVOICE_ID_LENGTH += size
INVOICE_ID_V2 = [
['Provinsi', 2, 'N'],
['Kabupaten', 2, 'N'],
['Jenis Pajak', 2, 'N'],
['Tahun', 2, 'N'],
['Kode', 2, 'N'],
['SSPD No', 6, 'N'],
]
INVOICE_ID_LENGTH_V2 = 0
for nama, size, tipe in INVOICE_ID_V2:
INVOICE_ID_LENGTH_V2 += size
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from zope.sqlalchemy import register
from ..tangerang_kabupaten import set_conf
import opensipkd.bphtb.tasik_kabupaten.services
def init(conf):
set_conf(conf, 'persen_denda', 2.0)
engine = create_engine(conf['db_url'])
session_factory = sessionmaker(bind=engine)
DBSession = session_factory()
register(DBSession)
opensipkd.bphtb.tasik_kabupaten.services.DBSession = DBSession
from datetime import datetime
from sqlalchemy import (
Column,
String,
Integer,
ForeignKey,
ForeignKeyConstraint,
)
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Provinsi(Base):
__tablename__ = 'ref_propinsi'
kd_propinsi = Column(String(2), primary_key=True)
nm_propinsi = Column(String(30), nullable=False)
class Kabupaten(Base):
__tablename__ = 'ref_dati2'
kd_propinsi = Column(
String(2), ForeignKey(Provinsi.kd_propinsi), primary_key=True)
kd_dati2 = Column(String(2), primary_key=True)
nm_dati2 = Column(String(30), nullable=False)
class Kecamatan(Base):
__tablename__ = 'ref_kecamatan'
kd_propinsi = Column(String(2), primary_key=True)
kd_dati2 = Column(String(2), primary_key=True)
kd_kecamatan = Column(String(3), primary_key=True)
nm_kecamatan = Column(String(30), nullable=False)
__table_args__ = (
ForeignKeyConstraint([
kd_propinsi, kd_dati2],
[Kabupaten.kd_propinsi, Kabupaten.kd_dati2]),)
class Kelurahan(Base):
__tablename__ = 'ref_kelurahan'
kd_propinsi = Column(String(2), primary_key=True)
kd_dati2 = Column(String(2), primary_key=True)
kd_kecamatan = Column(String(3), primary_key=True)
kd_kelurahan = Column(String(3), primary_key=True)
kd_sektor = Column(String(2), nullable=False)
nm_kelurahan = Column(String(30), nullable=False)
no_kelurahan = Column(Integer)
kd_pos_kelurahan = Column(String(5))
__table_args__ = (
ForeignKeyConstraint(
[kd_propinsi, kd_dati2, kd_kecamatan],
[Kecamatan.kd_propinsi, Kecamatan.kd_dati2,
Kecamatan.kd_kecamatan]),)
from ..tangerang_kabupaten.services import (
Inquiry as BaseInquiry,
Reversal as BaseReversal,
AvailableInvoice as BaseAvailableInvoice,
)
from .models import (
Kecamatan,
Kelurahan,
)
DBSession = None # override, please
class Inquiry(BaseInquiry):
def get_db_session(self):
return DBSession
def get_kecamatan(self):
q = DBSession.query(Kecamatan).filter_by(
kd_propinsi=self.invoice.kd_propinsi,
kd_dati2=self.invoice.kd_dati2,
kd_kecamatan=self.invoice.kd_kecamatan)
return q.first()
def get_kelurahan(self):
q = DBSession.query(Kelurahan).filter_by(
kd_propinsi=self.invoice.kd_propinsi,
kd_dati2=self.invoice.kd_dati2,
kd_kecamatan=self.invoice.kd_kecamatan,
kd_kelurahan=self.invoice.kd_kelurahan)
return q.first()
class Reversal(BaseReversal):
def get_db_session(self):
return DBSession
class AvailableInvoice(BaseAvailableInvoice):
def get_db_session(self):
return DBSession
def get_inquiry_class(self):
return Inquiry
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!