Commit 14d4255c by Owo Sugiana

Penyesuaian untuk Kabupaten Cirebon

1 parent 2c1eaf82
Showing 38 changed files with 974 additions and 561 deletions
0.3 2020-11-15
--------------
- Penyesuaian untuk Kabupaten Cirebon
0.2.2 2020-07-15 0.2.2 2020-07-15
---------------- ----------------
- Tambah tangsel - Tambah tangsel
......
[main] [main]
module = tangerang_kabupaten # Kota Cilegon
# module = cilegon
# Kabupaten Tasikmalaya
# module = tasik_kabupaten
# Kabupaten Tangerang, Kota Tangerang Selatan, Kabupaten Cirebon
module = default
db_url = postgresql://username:password@localhost/database db_url = postgresql://username:password@localhost/database
persen_denda = 2 persen_denda = 2
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
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 is 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()
import sys
import locale
import transaction
from datetime import datetime
from configparser import ConfigParser
from optparse import OptionParser
from sqlalchemy import (
create_engine,
func,
)
from opensipkd.hitung import hitung_denda
from opensipkd.base.models import DBSession
from opensipkd.bphtb.cilegon.models import (
Spt,
DetailSpt,
Pembayaran,
)
import opensipkd.bphtb.cilegon.services
from opensipkd.bphtb.cilegon.services import (
Inquiry,
Reversal,
)
opensipkd.bphtb.cilegon.services.DBSession = DBSession
locale.setlocale(locale.LC_ALL, 'id_ID.utf8')
def thousand(n):
return locale.format('%.0f', n, True)
def show_val(label, value):
print('{}: {}'.format(label, value))
def show_rp(label, value):
show_val(label, 'Rp {}'.format(thousand(value)))
def get_option(argv):
pars = OptionParser()
pars.add_option('-i', '--invoice-id')
pars.add_option('', '--payment', action='store_true')
pars.add_option('', '--reversal', action='store_true')
return pars.parse_args(argv)
def show(inq):
show_val('Invoice ID', inq.invoice_id)
show_val('Luas Tanah', inq.get_luas_tanah())
show_val('Luas Bangunan', inq.get_luas_bangunan())
show_rp('NPOP', inq.get_npop())
show_val('Jenis Perolehan Hak', inq.get_jenis_perolehan_hak())
show_val('Alamat Objek Pajak', inq.get_alamat_op())
show_val('Kelurahan Objek Pajak', inq.get_kelurahan_op())
show_val('Kecamatan Objek Pajak', inq.get_kecamatan_op())
show_val('Kota Objek Pajak', inq.get_kota_op())
show_val('NOP', inq.get_nop())
show_rp('Tagihan', inq.tagihan)
show_rp('Denda', inq.denda)
show_rp('Total Bayar', inq.total_bayar)
show_rp('Total Tagihan', inq.total)
show_val('Nama Notaris', inq.get_nama_notaris())
show_val('Nama Wajib Pajak', inq.get_nama())
show_val('NPWP', inq.get_npwp())
show_val('Alamat Wajib Pajak', inq.get_alamat_wp())
show_val('Kelurahan Wajib Pajak', inq.get_kelurahan_wp())
show_val('Kecamatan Wajib Pajak', inq.get_kecamatan_wp())
show_val('RT Wajib Pajak', inq.get_rt_wp())
show_val('RW Wajib Pajak', inq.get_rw_wp())
show_val('Kode Pos Wajib Pajak', inq.get_kode_pos_wp())
show_val('Tahun Pajak', inq.get_tahun())
def main(argv=sys.argv):
option, remain = get_option(argv[1:])
conf_file = remain[0]
invoice_id = option.invoice_id
conf = ConfigParser()
conf.read(conf_file)
db_url = conf.get('main', 'db_url')
engine = create_engine(db_url)
DBSession.configure(bind=engine)
with transaction.manager:
inq = Inquiry(invoice_id, conf.getfloat('main', 'persen_denda'))
if not inq.invoice:
print('Invoice ID {} tidak ada.'.format(invoice_id))
return
show(inq)
if option.payment:
if not inq.total:
print('Tidak ada tagihan, tidak ada yang perlu dibayar.')
return
ntb = datetime.now().strftime('%y%m%d%H%M%S')
pay = inq.do_payment(ntb)
print(
'Berhasil dibayar dengan ID pembayaran {}'.format(
pay.t_idpembayaranspt))
if option.reversal:
rev = Reversal(invoice_id)
pay = rev.payment
if not pay:
print(
'Pembayaran tidak ditemukan, '
'tidak ada yang perlu dibatalkan.')
return
rev.do_reversal()
print(
'ID Pembayaran {} berhasil dibatalkan'.format(
pay.t_idpembayaranspt))
from sqlalchemy.ext.declarative import declarative_base
from .provinsi import ProvinsiMixin
from .kabupaten import KabupatenMixin
from .kecamatan import KecamatanMixin
from .kelurahan import KelurahanMixin
from .customer import CustomerMixin
from .perolehan import PerolehanMixin
from .invoice import InvoiceMixin
from .payment import PaymentMixin
from .iso_payment import IsoPaymentMixin
from .iso_reversal import IsoReversalMixin
Base = declarative_base()
class Provinsi(ProvinsiMixin, Base):
pass
class Kabupaten(KabupatenMixin, Base):
pass
class Kecamatan(KecamatanMixin, Base):
pass
class Kelurahan(KelurahanMixin, Base):
pass
class Customer(CustomerMixin, Base):
pass
class Perolehan(PerolehanMixin, Base):
pass
class Invoice(InvoiceMixin, Base):
pass
class Payment(PaymentMixin, Base):
pass
class IsoPayment(IsoPaymentMixin, Base):
__table_args__ = dict(schema='bphtb')
class IsoReversal(IsoReversalMixin, Base):
__table_args__ = dict(schema='bphtb')
from sqlalchemy import (
Column,
Integer,
String,
Date,
DateTime,
)
from sqlalchemy.ext.declarative import declared_attr
class CustomerMixin:
@declared_attr
def __tablename__(self):
return 'bphtb_ppat'
@declared_attr
def id(self):
return Column(Integer, primary_key=True)
@declared_attr
def kode(self):
return Column(String(6), unique=True)
@declared_attr
def nama(self):
return Column(String(50))
@declared_attr
def alamat(self):
return Column(String(50))
@declared_attr
def kelurahan(self):
return Column(String(50))
@declared_attr
def kecamatan(self):
return Column(String(50))
@declared_attr
def kota(self):
return Column(String(50))
@declared_attr
def wilayah_kerja(self):
return Column(String(50))
@declared_attr
def kd_wilayah(self):
return Column(String(4))
@declared_attr
def no_telp(self):
return Column(String(20))
@declared_attr
def no_fax(self):
return Column(String(20))
@declared_attr
def no_sk(self):
return Column(String(30), unique=True)
@declared_attr
def tgl_sk(self):
return Column(Date)
@declared_attr
def create_uid(self):
return Column(String(20))
@declared_attr
def update_uid(self):
return Column(String(20))
@declared_attr
def created(self):
return Column(DateTime)
@declared_attr
def updated(self):
return Column(DateTime)
@declared_attr
def npwp(self):
return Column(String(20))
@declared_attr
def pejabat_id(self):
return Column(Integer)
# @declared_attr
# def status(self):
# return Column(Integer)
@declared_attr
def __table_args__(self):
return dict(schema='bphtb')
# Kabupaten Tangerang
from sqlalchemy.ext.declarative import declarative_base
from .provinsi import ProvinsiMixin
from .kabupaten import KabupatenMixin
from .kecamatan import KecamatanMixin
from .kelurahan import KelurahanMixin
from .customer import CustomerMixin
from .perolehan import PerolehanMixin
from .invoice import InvoiceMixin
from .payment import PaymentMixin
from .iso_payment import IsoPaymentMixin
from .iso_reversal import IsoReversalMixin
Base = declarative_base()
class Provinsi(ProvinsiMixin, Base):
pass
class Kabupaten(KabupatenMixin, Base):
pass
class Kecamatan(KecamatanMixin, Base):
pass
class Kelurahan(KelurahanMixin, Base):
pass
class Customer(CustomerMixin, Base):
pass
class Perolehan(PerolehanMixin, Base):
pass
class Invoice(InvoiceMixin, Base):
pass
class Payment(PaymentMixin, Base):
pass
class IsoPayment(IsoPaymentMixin, Base):
pass
class IsoReversal(IsoReversalMixin, Base):
pass
from datetime import datetime
from sqlalchemy import (
Column,
Integer,
DateTime,
String,
Date,
ForeignKey,
)
from sqlalchemy.ext.declarative import declared_attr
class IsoPaymentMixin:
@declared_attr
def __tablename__(self):
return 'bphtb_payment'
@declared_attr
def id(self):
return Column(
Integer, ForeignKey('bphtb.bphtb_bank.id'), primary_key=True)
@declared_attr
def tgl(self):
return Column(
DateTime(timezone=True), nullable=False, default=datetime.now)
@declared_attr
def iso_request(self):
return Column(String(1024), nullable=False)
@declared_attr
def transmission(self):
return Column(DateTime(timezone=True), nullable=False)
@declared_attr
def settlement(self):
return Column(Date, nullable=False)
@declared_attr
def stan(self):
return Column(Integer, nullable=False)
@declared_attr
def invoice_id(self):
return Column(
Integer, ForeignKey('bphtb.bphtb_sspd.id'), nullable=False)
@declared_attr
def invoice_no(self):
return Column(String(32), nullable=False)
@declared_attr
def ntb(self):
return Column(String(32), nullable=False)
@declared_attr
def ntp(self):
return Column(String(32), nullable=False, unique=True)
@declared_attr
def bank_id(self):
return Column(Integer)
@declared_attr
def channel_id(self):
return Column(Integer)
@declared_attr
def bank_ip(self):
return Column(String(15), nullable=False)
from datetime import datetime
from sqlalchemy import (
Column,
Integer,
DateTime,
String,
ForeignKey,
)
from sqlalchemy.ext.declarative import declared_attr
class IsoReversalMixin:
@declared_attr
def __tablename__(self):
return 'bphtb_reversal'
@declared_attr
def id(self):
return Column(
Integer, ForeignKey('bphtb.bphtb_payment.id'), primary_key=True)
@declared_attr
def tgl(self):
return Column(DateTime(
timezone=True), nullable=False, default=datetime.now)
@declared_attr
def iso_request(self):
return Column(String(1024), nullable=False)
from sqlalchemy import (
Column,
String,
ForeignKeyConstraint,
)
from sqlalchemy.ext.declarative import declared_attr
class KabupatenMixin:
@declared_attr
def __tablename__(self):
return 'ref_dati2'
@declared_attr
def kd_propinsi(self):
return Column(String(2), primary_key=True)
@declared_attr
def kd_dati2(self):
return Column(String(2), primary_key=True)
@declared_attr
def nm_dati2(self):
return Column(String(30), nullable=False)
@declared_attr
def __table_args__(self):
return (
ForeignKeyConstraint(
['kd_propinsi'], ['pbb.ref_propinsi.kd_propinsi']),
dict(schema='pbb'))
from sqlalchemy import (
Column,
String,
)
from sqlalchemy.ext.declarative import declared_attr
class KecamatanMixin:
@declared_attr
def __tablename__(self):
return 'ref_kecamatan'
@declared_attr
def kd_propinsi(self):
return Column(String(2), primary_key=True)
@declared_attr
def kd_dati2(self):
return Column(String(2), primary_key=True)
@declared_attr
def kd_kecamatan(self):
return Column(String(3), primary_key=True)
@declared_attr
def nm_kecamatan(self):
return Column(String(30), nullable=False)
@declared_attr
def __table_args__(self):
return dict(schema='pbb')
from sqlalchemy import (
Column,
String,
Integer,
)
from sqlalchemy.ext.declarative import declared_attr
class KelurahanMixin:
@declared_attr
def __tablename__(self):
return 'ref_kelurahan'
@declared_attr
def kd_propinsi(self):
return Column(String(2), primary_key=True)
@declared_attr
def kd_dati2(self):
return Column(String(2), primary_key=True)
@declared_attr
def kd_kecamatan(self):
return Column(String(3), primary_key=True)
@declared_attr
def kd_kelurahan(self):
return Column(String(3), primary_key=True)
@declared_attr
def kd_sektor(self):
return Column(String(2), nullable=False)
@declared_attr
def nm_kelurahan(self):
return Column(String(30), nullable=False)
@declared_attr
def no_kelurahan(self):
return Column(Integer)
@declared_attr
def kd_pos_kelurahan(self):
return Column(String(5))
@declared_attr
def __table_args__(self):
return dict(schema='pbb')
from sqlalchemy import (
Column,
Integer,
Date,
Time,
String,
UniqueConstraint,
)
from sqlalchemy.ext.declarative import declared_attr
class PaymentMixin:
@declared_attr
def __tablename__(self):
return 'bphtb_bank'
@declared_attr
def id(self):
return Column(Integer, primary_key=True)
@declared_attr
def tanggal(self):
return Column(Date, nullable=False)
@declared_attr
def jam(self):
return Column(Time, nullable=False)
@declared_attr
def seq(self):
return Column(Integer, nullable=False)
@declared_attr
def transno(self):
return Column(String(20), nullable=False)
@declared_attr
def cabang(self):
return Column(String(5))
@declared_attr
def users(self):
return Column(String(5))
@declared_attr
def bankid(self):
return Column(Integer, nullable=False)
@declared_attr
def txs(self):
return Column(String(5), nullable=False)
@declared_attr
def sspd_id(self):
return Column(Integer)
@declared_attr
def nop(self):
return Column(String(50), nullable=False)
@declared_attr
def tahun(self):
return Column(Integer)
@declared_attr
def kd_propinsi(self):
return Column(String(2))
@declared_attr
def kd_dati2(self):
return Column(String(2))
@declared_attr
def kd_kecamatan(self):
return Column(String(3))
@declared_attr
def kd_kelurahan(self):
return Column(String(3))
@declared_attr
def kd_blok(self):
return Column(String(3))
@declared_attr
def no_urut(self):
return Column(String(4))
@declared_attr
def kd_jns_op(self):
return Column(String(1))
@declared_attr
def thn_pajak_sppt(self):
return Column(String(4))
@declared_attr
def wp_nama(self):
return Column(String(50), nullable=False)
@declared_attr
def wp_alamat(self):
return Column(String(100))
@declared_attr
def wp_blok_kav(self):
return Column(String(100))
@declared_attr
def wp_rt(self):
return Column(String(3))
@declared_attr
def wp_rw(self):
return Column(String(3))
@declared_attr
def wp_kelurahan(self):
return Column(String(30))
@declared_attr
def wp_kecamatan(self):
return Column(String(30))
@declared_attr
def wp_kota(self):
return Column(String(30))
@declared_attr
def wp_provinsi(self):
return Column(String(50))
@declared_attr
def wp_kdpos(self):
return Column(String(5))
@declared_attr
def wp_identitas(self):
return Column(String(50))
@declared_attr
def wp_identitaskd(self):
return Column(String(50))
@declared_attr
def wp_npwp(self):
return Column(String(50))
@declared_attr
def notaris(self):
return Column(String(50))
@declared_attr
def bumi_luas(self):
return Column(Integer)
@declared_attr
def bumi_njop(self):
return Column(Integer)
@declared_attr
def bng_luas(self):
return Column(Integer)
@declared_attr
def bng_njop(self):
return Column(Integer)
@declared_attr
def npop(self):
return Column(Integer)
@declared_attr
def bayar(self):
return Column(Integer)
@declared_attr
def denda(self):
return Column(Integer)
@declared_attr
def bphtbjeniskd(self):
return Column(Integer)
@declared_attr
def is_validated(self):
return Column(Integer)
@declared_attr
def no_tagihan(self):
return Column(String(50))
@declared_attr
def catatan(self):
return Column(String(255))
@declared_attr
def kd_kanwil(self):
return Column(String(2))
@declared_attr
def kd_kantor(self):
return Column(String(2))
@declared_attr
def kd_bank_tunggal(self):
return Column(String(2))
@declared_attr
def kd_bank_persepsi(self):
return Column(String(2))
# @declared_attr
# def wp_propinsi(self):
# return Column(String(100))
@declared_attr
def pembayaran_ke(self):
return Column(Integer, nullable=False)
# @declared_attr
# def sts_id(self):
# return Column(Integer, nullable=False)
# @declared_attr
# def posted(self):
# return Column(Integer, nullable=False)
@declared_attr
def __table_args__(self):
return (
UniqueConstraint('tanggal', 'jam', 'seq', 'transno'),
dict(schema='bphtb'))
from sqlalchemy import (
Column,
Integer,
String,
)
from sqlalchemy.ext.declarative import declared_attr
class PerolehanMixin:
@declared_attr
def __tablename__(self):
return 'bphtb_perolehan'
@declared_attr
def id(self):
return Column(Integer, primary_key=True)
@declared_attr
def nama(self):
return Column(String(100), nullable=False)
@declared_attr
def npoptkp(self):
return Column(Integer, nullable=False)
@declared_attr
def pengurang(self):
return Column(Integer)
@declared_attr
def singkatan(self):
return Column(String(20))
@declared_attr
def __table_args__(self):
return dict(schema='bphtb')
from sqlalchemy import (
Column,
String,
)
from sqlalchemy.ext.declarative import declared_attr
class ProvinsiMixin:
@declared_attr
def __tablename__(self):
return 'ref_propinsi'
@declared_attr
def kd_propinsi(self):
return Column(String(2), primary_key=True)
@declared_attr
def nm_propinsi(self):
return Column(String(30))
@declared_attr
def __table_args__(self):
return dict(schema='pbb')
from sqlalchemy.ext.declarative import declarative_base
from .provinsi import ProvinsiMixin
from .kabupaten import KabupatenMixin
from .kecamatan import KecamatanMixin
from .kelurahan import KelurahanMixin
from .customer import CustomerMixin
from .perolehan import PerolehanMixin
from .invoice import InvoiceMixin
from .payment import PaymentMixin
from .iso_payment import IsoPaymentMixin
from .iso_reversal import IsoReversalMixin
Base = declarative_base()
class Provinsi(ProvinsiMixin, Base):
pass
class Kabupaten(KabupatenMixin, Base):
pass
class Kecamatan(KecamatanMixin, Base):
pass
class Kelurahan(KelurahanMixin, Base):
pass
class Customer(CustomerMixin, Base):
pass
class Perolehan(PerolehanMixin, Base):
pass
class Invoice(InvoiceMixin, Base):
pass
class Payment(PaymentMixin, Base):
pass
class IsoPayment(IsoPaymentMixin, Base):
__table_args__ = dict(schema='bphtb')
class IsoReversal(IsoReversalMixin, Base):
pass
from sqlalchemy import ForeignKeyConstraint
from sqlalchemy.ext.declarative import declarative_base
from .provinsi import ProvinsiMixin
from .kabupaten import KabupatenMixin
from .kecamatan import KecamatanMixin
from .kelurahan import KelurahanMixin
from .customer import CustomerMixin
from .perolehan import PerolehanMixin
from .invoice import InvoiceMixin
from .payment import PaymentMixin
from .iso_payment import IsoPaymentMixin
from .iso_reversal import IsoReversalMixin
Base = declarative_base()
class Provinsi(ProvinsiMixin, Base):
__table_args__ = dict(schema='bphtb')
class Kabupaten(KabupatenMixin, Base):
__table_args__ = dict(schema='bphtb')
class Kecamatan(KecamatanMixin, Base):
__table_args__ = (
ForeignKeyConstraint(
['kd_propinsi', 'kd_dati2'],
[Kabupaten.kd_propinsi, Kabupaten.kd_dati2]),
dict(schema='bphtb'))
class Kelurahan(KelurahanMixin, Base):
__table_args__ = (
ForeignKeyConstraint(
['kd_propinsi', 'kd_dati2', 'kd_kecamatan'],
[Kecamatan.kd_propinsi, Kecamatan.kd_dati2,
Kecamatan.kd_kecamatan]),
dict(schema='bphtb'))
class Customer(CustomerMixin, Base):
pass
class Perolehan(PerolehanMixin, Base):
pass
class Invoice(InvoiceMixin, Base):
pass
class Payment(PaymentMixin, Base):
pass
class IsoPayment(IsoPaymentMixin, Base):
pass
class IsoReversal(IsoReversalMixin, Base):
pass
import sys import sys
from configparser import ConfigParser
from argparse import ArgumentParser from argparse import ArgumentParser
from .common import init
def get_option(argv): def get_option(argv):
...@@ -18,14 +18,7 @@ def get_option(argv): ...@@ -18,14 +18,7 @@ def get_option(argv):
def main(argv=sys.argv): def main(argv=sys.argv):
option = get_option(argv[1:]) option = get_option(argv[1:])
conf = ConfigParser() conf, services = init(option)
conf.read(option.conf) persen_denda = conf.getfloat('main', 'persen_denda')
module_name = conf.get('main', 'module') a = services.AvailableInvoice(persen_denda, option)
module = __import__('opensipkd.bphtb.' + module_name + '.services')
area_module = getattr(module.bphtb, module_name)
cf = dict(conf['main'])
area_module.init(cf)
services_module = getattr(area_module, 'services')
AvailableInvoice = services_module.AvailableInvoice
a = AvailableInvoice(cf['persen_denda'], option)
a.show() a.show()
from configparser import ConfigParser
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from zope.sqlalchemy import register
def init(option):
conf = ConfigParser()
conf.read(option.conf)
module_name = conf.get('main', 'module')
module = __import__('opensipkd.bphtb.services.' + module_name)
db_url = conf.get('main', 'db_url')
engine = create_engine(db_url)
session_factory = sessionmaker(bind=engine)
dbs = module.bphtb.services.base.DBSession = session_factory()
register(dbs)
services = getattr(module.bphtb.services, module_name)
return conf, services
import sys import sys
from datetime import datetime from datetime import datetime
from configparser import ConfigParser
from argparse import ArgumentParser from argparse import ArgumentParser
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
import transaction import transaction
from opensipkd.string.money import thousand from opensipkd.string.money import thousand
from .common import init
def show_val(label, value): def show_val(label, value):
...@@ -63,43 +61,35 @@ def show_pkey_values(row): ...@@ -63,43 +61,35 @@ def show_pkey_values(row):
show_val(' '+c.name, val) show_val(' '+c.name, val)
def error(s):
print(s)
sys.exit()
def main(argv=sys.argv): def main(argv=sys.argv):
option = get_option(argv[1:]) option = get_option(argv[1:])
conf_file = option.conf conf, services = init(option)
persen_denda = conf.getfloat('main', 'persen_denda')
invoice_id = option.invoice_id invoice_id = option.invoice_id
conf = ConfigParser() inq = services.Inquiry(
conf.read(conf_file)
db_url = conf.get('main', 'db_url')
engine = create_engine(db_url)
module_name = conf.get('main', 'module')
module = __import__('opensipkd.bphtb.' + module_name + '.services')
area_module = getattr(module.bphtb, module_name)
cf = dict(conf['main'])
area_module.init(cf)
services_module = getattr(area_module, 'services')
AvailableInvoice = services_module.AvailableInvoice
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:
print('Invoice ID {} tidak ada.'.format(invoice_id)) error(f'Invoice ID {invoice_id} tidak ada.')
return
show(inq) show(inq)
if option.payment: if option.payment:
if not inq.total: if not inq.total:
print('Tidak ada tagihan, tidak ada yang perlu dibayar.') error('Tidak ada tagihan, tidak ada yang perlu dibayar.')
return
ntb = datetime.now().strftime('%y%m%d%H%M%S') ntb = datetime.now().strftime('%y%m%d%H%M%S')
with transaction.manager: with transaction.manager:
pay = inq.do_payment(ntb) pay = inq.do_payment(ntb)
show_pkey_values(pay) show_pkey_values(pay)
print('Berhasil dibayar') print('Berhasil dibayar')
if option.reversal: if option.reversal:
rev = services_module.Reversal(invoice_id) rev = services.Reversal(invoice_id)
pay = rev.payment pay = rev.payment
if not pay: if not pay:
print( error(
'Pembayaran tidak ditemukan, tidak ada yang perlu dibatalkan.') 'Pembayaran tidak ditemukan, tidak ada yang perlu dibatalkan.')
return
with transaction.manager: with transaction.manager:
rev.do_reversal() rev.do_reversal()
show_pkey_values(pay) show_pkey_values(pay)
......
from time import time from time import time
DBSession = None # Diisi saat init
def get_db_session():
return DBSession
class AvailableInvoice: class AvailableInvoice:
def __init__(self, persen_denda=2, option=None): def __init__(self, persen_denda=2, option=None):
self.option = option self.option = option
......
...@@ -8,8 +8,9 @@ from opensipkd.hitung import ( ...@@ -8,8 +8,9 @@ from opensipkd.hitung import (
round_up, round_up,
) )
from opensipkd.string.money import thousand from opensipkd.string.money import thousand
from ..services import AvailableInvoice as BaseAvailableInvoice from .base import get_db_session
from .models import ( from .default import AvailableInvoice as BaseAvailableInvoice
from ..models.cilegon import (
Spt, Spt,
DetailSpt, DetailSpt,
Pembayaran, Pembayaran,
...@@ -19,13 +20,6 @@ from .models import ( ...@@ -19,13 +20,6 @@ from .models import (
) )
DBSession = None # override, please
def get_db_session():
return DBSession
class Inquiry: class Inquiry:
def __init__(self, invoice_id, persen_denda=2, tgl_bayar=None): def __init__(self, invoice_id, persen_denda=2, tgl_bayar=None):
self.invoice_id = invoice_id self.invoice_id = invoice_id
...@@ -34,18 +28,19 @@ class Inquiry: ...@@ -34,18 +28,19 @@ class Inquiry:
self.tgl_bayar = tgl_bayar self.tgl_bayar = tgl_bayar
else: else:
self.tgl_bayar = date.today() self.tgl_bayar = date.today()
q = DBSession.query(Pembayaran).filter_by( db_session = get_db_session()
q = db_session.query(Pembayaran).filter_by(
t_kodebayarbanksppt=invoice_id).order_by( t_kodebayarbanksppt=invoice_id).order_by(
Pembayaran.t_idpembayaranspt) Pembayaran.t_idpembayaranspt)
self.payment = q.first() self.payment = q.first()
if not self.payment: if not self.payment:
self.invoice = None self.invoice = None
return return
q = DBSession.query(Spt).filter_by(t_idspt=self.payment.t_idspt) q = db_session.query(Spt).filter_by(t_idspt=self.payment.t_idspt)
self.invoice = q.first() self.invoice = q.first()
if not self.invoice: if not self.invoice:
return return
q = DBSession.query(Pemeriksaan).filter_by( q = db_session.query(Pemeriksaan).filter_by(
p_idpembayaranspt=self.payment.t_idpembayaranspt) p_idpembayaranspt=self.payment.t_idpembayaranspt)
self.pemeriksaan = q.first() self.pemeriksaan = q.first()
self.profile = self.get_profile() self.profile = self.get_profile()
...@@ -78,17 +73,19 @@ class Inquiry: ...@@ -78,17 +73,19 @@ class Inquiry:
self.discount = 0 self.discount = 0
def get_profile(self): def get_profile(self):
q = DBSession.query(DetailSpt).filter_by(t_idspt=self.invoice.t_idspt) db_session = get_db_session()
q = db_session.query(DetailSpt).filter_by(t_idspt=self.invoice.t_idspt)
return q.first() return q.first()
def get_notaris(self): def get_notaris(self):
q = DBSession.query(User).filter_by( db_session = get_db_session()
q = db_session.query(User).filter_by(
s_iduser=self.invoice.t_idnotarisspt) s_iduser=self.invoice.t_idnotarisspt)
user = q.first() user = q.first()
if not user: if not user:
return return
notaris_id = int(user.s_idpejabat_idnotaris) notaris_id = int(user.s_idpejabat_idnotaris)
q = DBSession.query(Notaris).filter_by(s_idnotaris=notaris_id) q = db_session.query(Notaris).filter_by(s_idnotaris=notaris_id)
return q.first() return q.first()
def get_nop(self): def get_nop(self):
...@@ -167,7 +164,8 @@ class Inquiry: ...@@ -167,7 +164,8 @@ class Inquiry:
return self.invoice.t_periodespt return self.invoice.t_periodespt
def get_payment_amount(self): def get_payment_amount(self):
q = DBSession.query( db_session = get_db_session()
q = db_session.query(
func.sum(Pembayaran.t_nilaipembayaranspt).label('jml')) func.sum(Pembayaran.t_nilaipembayaranspt).label('jml'))
q = q.filter_by(t_idspt=self.invoice.t_idspt, t_statusbayarspt=True) q = q.filter_by(t_idspt=self.invoice.t_idspt, t_statusbayarspt=True)
row = q.first() row = q.first()
...@@ -180,7 +178,8 @@ class Inquiry: ...@@ -180,7 +178,8 @@ class Inquiry:
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
self.payment.t_statusbayarspt = True self.payment.t_statusbayarspt = True
DBSession.add(self.payment) db_session = get_db_session()
db_session.add(self.payment)
return self.payment return self.payment
...@@ -190,7 +189,8 @@ class Reversal: ...@@ -190,7 +189,8 @@ class Reversal:
self.payment = self.get_last_payment() self.payment = self.get_last_payment()
def get_last_payment(self): def get_last_payment(self):
q = DBSession.query(Pembayaran).filter_by( db_session = get_db_session()
q = db_session.query(Pembayaran).filter_by(
t_kodebayarbanksppt=self.invoice_id).order_by( t_kodebayarbanksppt=self.invoice_id).order_by(
Pembayaran.t_idpembayaranspt) Pembayaran.t_idpembayaranspt)
pay = q.first() pay = q.first()
...@@ -201,17 +201,16 @@ class Reversal: ...@@ -201,17 +201,16 @@ class Reversal:
self.payment.t_tanggalpembayaran = None self.payment.t_tanggalpembayaran = None
self.payment.t_nilaipembayaranspt = 0 self.payment.t_nilaipembayaranspt = 0
self.payment.t_statusbayarspt = False self.payment.t_statusbayarspt = False
DBSession.add(self.payment) db_session = get_db_session()
db_session.add(self.payment)
class AvailableInvoice(BaseAvailableInvoice): class AvailableInvoice(BaseAvailableInvoice):
def get_query(self): def get_query(self):
q = DBSession.query( db_session = get_db_session()
Pembayaran.t_kodebayarbanksppt, Spt.t_tgljatuhtempospt).\ q = db_session.query(
filter( Pembayaran.t_kodebayarbanksppt, Spt.t_tgljatuhtempospt).filter(
Pembayaran.t_idspt == Spt.t_idspt, Pembayaran.t_idspt == Spt.t_idspt, Spt.t_totalspt > 0)
or_(Pembayaran.t_statusbayarspt is None,
Pembayaran.t_statusbayarspt is False))
if self.option.tahun: if self.option.tahun:
q = q.filter(Spt.t_periodespt == self.option.tahun) q = q.filter(Spt.t_periodespt == self.option.tahun)
if self.option.belum_jatuh_tempo or self.option.lewat_jatuh_tempo: if self.option.belum_jatuh_tempo or self.option.lewat_jatuh_tempo:
...@@ -221,8 +220,7 @@ class AvailableInvoice(BaseAvailableInvoice): ...@@ -221,8 +220,7 @@ class AvailableInvoice(BaseAvailableInvoice):
q = q.filter(Spt.t_tgljatuhtempospt >= kini) q = q.filter(Spt.t_tgljatuhtempospt >= kini)
else: else:
q = q.filter(Spt.t_tgljatuhtempospt < kini) q = q.filter(Spt.t_tgljatuhtempospt < kini)
print('jatuh tempo') return q.order_by(Spt.t_periodespt.desc(), Spt.t_totalspt, Spt.t_idspt)
return q.order_by(Pembayaran.t_idpembayaranspt.desc())
def get_message(self, row): def get_message(self, row):
inq = Inquiry(row.t_kodebayarbanksppt, self.persen_denda) inq = Inquiry(row.t_kodebayarbanksppt, self.persen_denda)
......
# Kabupaten Tangerang, Kabupaten Cirebon
from datetime import ( from datetime import (
date, date,
datetime, datetime,
...@@ -9,29 +10,31 @@ from opensipkd.hitung import ( ...@@ -9,29 +10,31 @@ from opensipkd.hitung import (
) )
from opensipkd.string import FixLength from opensipkd.string import FixLength
from opensipkd.string.money import thousand from opensipkd.string.money import thousand
from ..services import AvailableInvoice as BaseAvailableInvoice from opensipkd.bphtb.structure import NOP
from ..structure import NOP from opensipkd.bphtb.models.default import (
from .structure import (
INVOICE_ID,
INVOICE_ID_LENGTH,
)
from .models import (
Invoice, Invoice,
Payment, Payment,
Customer, Customer,
Kecamatan, Kecamatan,
Kelurahan, Kelurahan,
) )
from ..base import (
AvailableInvoice as BaseAvailableInvoice,
DBSession = None # override, please get_db_session,
)
from .structure import (
def get_db_session(): INVOICE_ID,
return DBSession INVOICE_ID_LENGTH,
)
class Common: class Common:
kecamatan_model = Kecamatan
kelurahan_model = Kelurahan
invoice_model = Invoice
payment_model = Payment
customer_model = Customer
def __init__(self, invoice_id): def __init__(self, invoice_id):
self.invoice_id = invoice_id self.invoice_id = invoice_id
self.invoice_struct = FixLength(INVOICE_ID) self.invoice_struct = FixLength(INVOICE_ID)
...@@ -44,30 +47,11 @@ class Common: ...@@ -44,30 +47,11 @@ class Common:
else: else:
self.invoice = None self.invoice = None
def get_kelurahan_model(self):
return Kelurahan
def get_kecamatan_model(self):
return Kecamatan
def get_invoice_model(self):
return Invoice
def get_payment_model(self):
return Payment
def get_customer_model(self):
return Customer
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() db_session = get_db_session()
Invoice = self.get_invoice_model() return db_session.query(self.invoice_model).filter_by(
return DBSession.query(Invoice).filter_by(
tahun=self.tahun, kode=kode, tahun=self.tahun, kode=kode,
no_sspd=self.invoice_struct['SSPD No']) no_sspd=self.invoice_struct['SSPD No'])
...@@ -76,13 +60,13 @@ class Common: ...@@ -76,13 +60,13 @@ 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() db_session = get_db_session()
DBSession.add(self.invoice) db_session.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() db_session = get_db_session()
DBSession.add(self.invoice) db_session.add(self.invoice)
def is_available(self): def is_available(self):
return self.invoice.status_pembayaran == 0 return self.invoice.status_pembayaran == 0
...@@ -93,7 +77,7 @@ class Common: ...@@ -93,7 +77,7 @@ class Common:
class Inquiry(Common): class Inquiry(Common):
def __init__(self, invoice_id, persen_denda=2, tgl_bayar=None): def __init__(self, invoice_id, persen_denda=2, tgl_bayar=None):
Common.__init__(self, invoice_id) super().__init__(invoice_id)
if not self.invoice: if not self.invoice:
return return
self.persen_denda = persen_denda self.persen_denda = persen_denda
...@@ -146,23 +130,21 @@ class Inquiry(Common): ...@@ -146,23 +130,21 @@ 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() db_session = get_db_session()
q = DBSession.query(DetailSpt).filter_by(t_idspt=self.invoice.t_idspt) q = db_session.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() db_session = get_db_session()
Kecamatan = self.get_kecamatan_model() q = db_session.query(self.kecamatan_model).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,
kd_kecamatan=self.invoice.kd_kecamatan) kd_kecamatan=self.invoice.kd_kecamatan)
return q.first() return q.first()
def get_kelurahan(self): def get_kelurahan(self):
DBSession = self.get_db_session() db_session = get_db_session()
Kelurahan = self.get_kelurahan_model() q = db_session.query(self.kelurahan_model).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,
kd_kecamatan=self.invoice.kd_kecamatan, kd_kecamatan=self.invoice.kd_kecamatan,
...@@ -170,9 +152,9 @@ class Inquiry(Common): ...@@ -170,9 +152,9 @@ class Inquiry(Common):
return q.first() return q.first()
def get_notaris(self): def get_notaris(self):
DBSession = self.get_db_session() db_session = get_db_session()
Customer = self.get_customer_model() q = db_session.query(self.customer_model).filter_by(
q = DBSession.query(Customer).filter_by(id=self.invoice.ppat_id) id=self.invoice.ppat_id)
return q.first() return q.first()
def get_luas_tanah(self): def get_luas_tanah(self):
...@@ -241,16 +223,16 @@ class Inquiry(Common): ...@@ -241,16 +223,16 @@ 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() db_session = get_db_session()
q = DBSession.query( q = db_session.query(
func.sum(Payment.bayar). func.sum(Payment.bayar).
label('total_bayar')).filter_by(sspd_id=self.invoice.id) label('total_bayar')).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() db_session = get_db_session()
q = DBSession.query(Payment).filter_by(sspd_id=self.invoice.id) q = db_session.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
...@@ -288,15 +270,15 @@ class Inquiry(Common): ...@@ -288,15 +270,15 @@ 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() db_session = get_db_session()
DBSession.add(pay) db_session.add(pay)
DBSession.flush() db_session.flush()
return pay return pay
class Reversal(Common): class Reversal(Common):
def __init__(self, invoice_id): def __init__(self, invoice_id):
Common.__init__(self, invoice_id) super().__init__(invoice_id)
self.payment = None self.payment = None
if not self.invoice: if not self.invoice:
return return
...@@ -304,43 +286,36 @@ class Reversal(Common): ...@@ -304,43 +286,36 @@ 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() db_session = get_db_session()
q = DBSession.query(Payment).filter_by( q = db_session.query(Payment).filter_by(
sspd_id=self.invoice.id).order_by(Payment.id.desc()) sspd_id=self.invoice.id).order_by(Payment.id.desc())
return q.first() return q.first()
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() db_session = get_db_session()
DBSession.add(self.payment) db_session.add(self.payment)
DBSession.flush() db_session.flush()
class AvailableInvoice(BaseAvailableInvoice): class AvailableInvoice(BaseAvailableInvoice):
def get_db_session(self): invoice_model = Invoice
return DBSession inquiry_cls = Inquiry
def get_inquiry_class(self):
return Inquiry
def get_invoice_model(self):
return Invoice
def get_query(self): def get_query(self):
DBSession = self.get_db_session() db_session = get_db_session()
Invoice = self.get_invoice_model() q = db_session.query(self.invoice_model).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)
if self.option.belum_jatuh_tempo or self.option.lewat_jatuh_tempo: if self.option.belum_jatuh_tempo or self.option.lewat_jatuh_tempo:
q = q.filter(Invoice.tgl_jatuh_tempo is not None) q = q.filter(self.invoice_model.tgl_jatuh_tempo is not None)
kini = date.today() kini = date.today()
if self.option.belum_jatuh_tempo: if self.option.belum_jatuh_tempo:
q = q.filter(Invoice.tgl_jatuh_tempo >= kini) q = q.filter(self.invoice_model.tgl_jatuh_tempo >= kini)
else: else:
q = q.filter(Invoice.tgl_jatuh_tempo < kini) q = q.filter(self.invoice_model.tgl_jatuh_tempo < kini)
return q.order_by(Invoice.id.desc()) return q.order_by(self.invoice_model.id.desc())
def get_message(self, row): def get_message(self, row):
invoice_id_struct = FixLength(INVOICE_ID) invoice_id_struct = FixLength(INVOICE_ID)
...@@ -348,8 +323,7 @@ class AvailableInvoice(BaseAvailableInvoice): ...@@ -348,8 +323,7 @@ class AvailableInvoice(BaseAvailableInvoice):
invoice_id_struct['Kode'] = row.kode.zfill(2) invoice_id_struct['Kode'] = row.kode.zfill(2)
invoice_id_struct['SSPD No'] = row.no_sspd invoice_id_struct['SSPD No'] = row.no_sspd
invoice_id = invoice_id_struct.get_raw() invoice_id = invoice_id_struct.get_raw()
cls = self.get_inquiry_class() inq = self.inquiry_cls(invoice_id, self.persen_denda)
inq = cls(invoice_id, self.persen_denda)
if inq.total < 1: if inq.total < 1:
return return
total = thousand(inq.total).rjust(11) total = thousand(inq.total).rjust(11)
......
from ..models.tasik_kabupaten import (
Kecamatan,
Kelurahan,
)
from .default import (
Inquiry as BaseInquiry,
Reversal,
AvailableInvoice,
)
class Inquiry(BaseInquiry):
kecamatan_model = Kecamatan
kelurahan_model = Kelurahan
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
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from zope.sqlalchemy import register
import opensipkd.bphtb.tangsel.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.tangsel.services.DBSession = DBSession
from ..tangerang_kabupaten.services import (
Inquiry as BaseInquiry,
Reversal as BaseReversal,
AvailableInvoice as BaseAvailableInvoice,
)
from .models import (
Kecamatan,
Kelurahan,
Customer,
Invoice,
Payment,
)
DBSession = None # override, please
def get_db_session():
return DBSession
class Inquiry(BaseInquiry):
def get_kelurahan_model(self): # Override
return Kelurahan
def get_kecamatan_model(self): # Override
return Kecamatan
def get_invoice_model(self): # Override
return Invoice
def get_payment_model(self): # Override
return Payment
def get_customer_model(self): # Override
return Customer
def get_db_session(self): # Override
return DBSession
class Reversal(BaseReversal):
def get_db_session(self): # Override
return DBSession
def get_invoice_model(self): # Override
return Invoice
def get_payment_model(self): # Override
return Payment
class AvailableInvoice(BaseAvailableInvoice):
def get_db_session(self): # Override
return DBSession
def get_inquiry_class(self): # Override
return Inquiry
def get_invoice_model(self): # Override
return Invoice
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)
__table_args__ = dict(schema='bphtb')
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)
__table_args__ = dict(schema='bphtb')
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]),
dict(schema='bphtb'))
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]),
dict(schema='bphtb'))
from ..tangerang_kabupaten.services import (
Inquiry as BaseInquiry,
Reversal as BaseReversal,
AvailableInvoice as BaseAvailableInvoice,
)
from .models import (
Kecamatan,
Kelurahan,
)
DBSession = None # override, please
def get_db_session():
return DBSession
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!