Commit 5c3ace01 by Owo Sugiana

Tambah tangsel

1 parent 28277c09
*egg-info
build build
dist
*egg-info
test-*.ini test-*.ini
0.2 2020-07-15
--------------
- File konfigurasi wajib ada baris module
- Modul default adalah struktur Kabupaten Tangerang
- Tambah modul tangsel
0.1 2020-05-06 0.1 2020-05-06
-------------- --------------
- Kali pertama - Kali pertama
[main] [main]
module = default
db_url = postgresql://user:pass@localhost/db db_url = postgresql://user:pass@localhost/db
persen_denda = 2 persen_denda = 2
#rekening_notes = #rekening_notes =
...@@ -195,9 +195,6 @@ class Customer(Base): ...@@ -195,9 +195,6 @@ class Customer(Base):
kd_diskopengunjung = Column(Integer) kd_diskopengunjung = Column(Integer)
kd_diskotarif = Column(Float) kd_diskotarif = Column(Float)
kd_waletvolume = Column(Integer) kd_waletvolume = Column(Integer)
#formno_old = Column(Integer)
#ket = Column(String(50))
#npwpd_ori = Column(String(20))
__table_args__ = ( __table_args__ = (
UniqueConstraint('rp', 'pb', 'formno', 'kecamatan_id', 'kelurahan_id'), UniqueConstraint('rp', 'pb', 'formno', 'kecamatan_id', 'kelurahan_id'),
dict(schema='pad')) dict(schema='pad'))
...@@ -255,7 +252,8 @@ class Invoice(Base): ...@@ -255,7 +252,8 @@ class Invoice(Base):
tahun = Column(Integer, nullable=False) tahun = Column(Integer, nullable=False)
sptno = Column(Integer, nullable=False) sptno = Column(Integer, nullable=False)
customer_id = Column(Integer, ForeignKey(Customer.id), nullable=False) customer_id = Column(Integer, ForeignKey(Customer.id), nullable=False)
customer_usaha_id = Column(Integer, ForeignKey(CustomerUsaha.id), nullable=False) customer_usaha_id = Column(
Integer, ForeignKey(CustomerUsaha.id), nullable=False)
rekening_id = Column(Integer, ForeignKey(Rekening.id)) rekening_id = Column(Integer, ForeignKey(Rekening.id))
pajak_id = Column(Integer, ForeignKey(Pajak.id), nullable=False) pajak_id = Column(Integer, ForeignKey(Pajak.id), nullable=False)
type_id = Column(Integer, ForeignKey(SptType.id)) type_id = Column(Integer, ForeignKey(SptType.id))
...@@ -330,9 +328,6 @@ class Invoice(Base): ...@@ -330,9 +328,6 @@ class Invoice(Base):
r_alamat = Column(String(255)) r_alamat = Column(String(255))
m_tonase = Column(Float) m_tonase = Column(Float)
m_njop = Column(Float) m_njop = Column(Float)
#r_njop_lain = Column(Float)
#r_kecamatan_id = Column(Integer)
#printed_kd = Column(Integer)
__table_args__ = ( __table_args__ = (
UniqueConstraint('tahun', 'sptno'), UniqueConstraint('tahun', 'sptno'),
UniqueConstraint('tahun', 'sptno', 'customer_usaha_id', 'masadari'), UniqueConstraint('tahun', 'sptno', 'customer_usaha_id', 'masadari'),
...@@ -362,11 +357,6 @@ class Payment(Base): ...@@ -362,11 +357,6 @@ class Payment(Base):
denda = Column(Integer) denda = Column(Integer)
jml_bayar = Column(Integer) jml_bayar = Column(Integer)
is_valid = Column(Integer) is_valid = Column(Integer)
#cancel_jml_bayar = Column(Integer)
#cancel_bunga = Column(Integer)
#cancel_denda = Column(Integer)
#cancel_date = Column(DateTime)
#cancel_uid = Column(Integer)
__table_args__ = ( __table_args__ = (
UniqueConstraint('tahun', 'sspdno'), UniqueConstraint('tahun', 'sspdno'),
dict(schema='pad')) dict(schema='pad'))
......
...@@ -26,12 +26,14 @@ def main(argv=sys.argv): ...@@ -26,12 +26,14 @@ def main(argv=sys.argv):
option = get_option(argv[1:]) option = get_option(argv[1:])
conf = ConfigParser() conf = ConfigParser()
conf.read(option.conf) conf.read(option.conf)
module = __import__('opensipkd.pad.services') module_name = conf.get('main', 'module')
AvailableInvoice = module.pad.services.AvailableInvoice module = __import__('opensipkd.pad.services.' + module_name)
services = getattr(module.pad.services, module_name)
AvailableInvoice = services.AvailableInvoice
db_url = conf.get('main', 'db_url') db_url = conf.get('main', 'db_url')
persen_denda = conf.getfloat('main', 'persen_denda') persen_denda = conf.getfloat('main', 'persen_denda')
engine = create_engine(db_url) engine = create_engine(db_url)
session_factory = sessionmaker(bind=engine) session_factory = sessionmaker(bind=engine)
module.pad.services.DBSession = session_factory() module.pad.services.base.DBSession = session_factory()
a = AvailableInvoice(persen_denda, option) a = AvailableInvoice(persen_denda, option)
a.show() a.show()
...@@ -9,6 +9,10 @@ from zope.sqlalchemy import register ...@@ -9,6 +9,10 @@ from zope.sqlalchemy import register
from opensipkd.string.money import thousand from opensipkd.string.money import thousand
ERR_PAYMENT_NOT_FOUND = 'Pembayaran tidak ditemukan, '\
'tidak ada yang perlu dibatalkan.'
def show_val(label, value): def show_val(label, value):
print('{}: {}'.format(label, value or '')) print('{}: {}'.format(label, value or ''))
...@@ -43,7 +47,7 @@ def show(inq): ...@@ -43,7 +47,7 @@ def show(inq):
show_rp('Total Bayar', inq.total_bayar) show_rp('Total Bayar', inq.total_bayar)
show_rp('Total Tagihan', inq.total) show_rp('Total Tagihan', inq.total)
show_val('Is Available', inq.is_available()) show_val('Is Available', inq.is_available())
def show_pkey_values(row): def show_pkey_values(row):
print('Primary key tabel {}:'.format(row.__table__.name)) print('Primary key tabel {}:'.format(row.__table__.name))
...@@ -65,22 +69,23 @@ def error(s): ...@@ -65,22 +69,23 @@ def error(s):
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_file = option.conf
invoice_id = option.invoice_id invoice_id = option.invoice_id
conf = ConfigParser() conf = ConfigParser()
conf.read(conf_file) conf.read(conf_file)
module_name = conf.get('main', 'module')
db_url = conf.get('main', 'db_url') db_url = conf.get('main', 'db_url')
rekening_notes = read_list_conf(conf, 'rekening_notes') rekening_notes = read_list_conf(conf, 'rekening_notes')
engine = create_engine(db_url) engine = create_engine(db_url)
module = __import__('opensipkd.pad.services') module = __import__('opensipkd.pad.services.' + module_name)
services = getattr(module.pad.services, module_name)
session_factory = sessionmaker(bind=engine) session_factory = sessionmaker(bind=engine)
module.pad.services.DBSession = session_factory() module.pad.services.base.DBSession = session_factory()
register(module.pad.services.DBSession) register(module.pad.services.base.DBSession)
inq = module.pad.services.Inquiry( inq = services.Inquiry(
invoice_id, rekening_notes, conf.getfloat('main', 'persen_denda')) invoice_id, rekening_notes, conf.getfloat('main', 'persen_denda'))
if not inq.invoice: if not inq.invoice:
print('Invoice ID {} tidak ada.'.format(invoice_id)) error('Invoice ID {} tidak ada.'.format(invoice_id))
return
show(inq) show(inq)
if option.payment: if option.payment:
if not inq.total: if not inq.total:
...@@ -91,12 +96,12 @@ def main(argv=sys.argv): ...@@ -91,12 +96,12 @@ def main(argv=sys.argv):
show_pkey_values(pay) show_pkey_values(pay)
print('Berhasil dibayar') print('Berhasil dibayar')
if option.reversal: if option.reversal:
rev = module.pad.services.Reversal(invoice_id) rev = services.Reversal(invoice_id)
if rev.is_available(): if rev.is_available():
error('Memang belum dibayar') error('Memang belum dibayar')
pay = rev.payment pay = rev.payment
if not pay: if not pay:
error('Pembayaran tidak ditemukan, tidak ada yang perlu dibatalkan.') error(ERR_PAYMENT_NOT_FOUND)
with transaction.manager: with transaction.manager:
rev.do_reversal() rev.do_reversal()
show_pkey_values(pay) show_pkey_values(pay)
......
DBSession = None # Diisi saat init
def get_db_session():
return DBSession
...@@ -12,7 +12,7 @@ from opensipkd.hitung import ( ...@@ -12,7 +12,7 @@ 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 .models import ( from opensipkd.pad.models.default import (
Kecamatan, Kecamatan,
Kelurahan, Kelurahan,
Customer, Customer,
...@@ -21,14 +21,9 @@ from .models import ( ...@@ -21,14 +21,9 @@ from .models import (
Payment, Payment,
Pajak, Pajak,
Rekening, Rekening,
Usaha,
) )
from ..base import get_db_session
DBSession = None # Override, please
def get_db_session():
return DBSession
INVOICE_ID = [ INVOICE_ID = [
...@@ -45,38 +40,79 @@ class BaseInquiry: ...@@ -45,38 +40,79 @@ class BaseInquiry:
if not self.invoice_id['SptNo']: if not self.invoice_id['SptNo']:
return return
self.rekening_notes = rekening_notes self.rekening_notes = rekening_notes
Invoice = self.get_invoice_model()
DBSession = get_db_session()
q = DBSession.query(Invoice).filter_by( q = DBSession.query(Invoice).filter_by(
tahun=self.invoice_id['Tahun'], sptno=self.invoice_id['SptNo']) tahun=self.invoice_id['Tahun'], sptno=self.invoice_id['SptNo'])
self.invoice = q.first() self.invoice = q.first()
def get_kecamatan_model(self):
return Kecamatan
def get_kelurahan_model(self):
return Kelurahan
def get_customer_model(self):
return Customer
def get_usaha_model(self):
return Usaha
def get_customer_usaha_model(self):
return CustomerUsaha
def get_rekening_model(self):
return Rekening
def get_pajak_model(self):
return Pajak
def get_invoice_model(self):
return Invoice
def get_payment_model(self):
return Payment
def is_available(self): def is_available(self):
return self.invoice.status_pembayaran == 0 return self.invoice.status_pembayaran == 0
def get_objek_pajak(self): def get_objek_pajak(self):
CustomerUsaha = self.get_customer_usaha_model()
DBSession = get_db_session()
q = DBSession.query(CustomerUsaha).filter_by( q = DBSession.query(CustomerUsaha).filter_by(
id=self.invoice.customer_usaha_id) id=self.invoice.customer_usaha_id)
return q.first() return q.first()
def get_wajib_pajak(self): def get_wajib_pajak(self):
Customer = self.get_customer_model()
DBSession = get_db_session()
q = DBSession.query(Customer).filter_by( q = DBSession.query(Customer).filter_by(
id=self.objek_pajak.customer_id) id=self.objek_pajak.customer_id)
return q.first() return q.first()
def get_kelurahan(self): def get_kelurahan(self):
Kelurahan = self.get_kelurahan_model()
DBSession = get_db_session()
q = DBSession.query(Kelurahan).filter_by( q = DBSession.query(Kelurahan).filter_by(
id=self.objek_pajak.kelurahan_id) id=self.objek_pajak.kelurahan_id)
return q.first() return q.first()
def get_kecamatan(self): def get_kecamatan(self):
Kecamatan = self.get_kecamatan_model()
DBSession = get_db_session()
q = DBSession.query(Kecamatan).filter_by( q = DBSession.query(Kecamatan).filter_by(
id=self.objek_pajak.kecamatan_id) id=self.objek_pajak.kecamatan_id)
return q.first() return q.first()
def get_pajak(self): def get_pajak(self):
Pajak = self.get_pajak_model()
DBSession = get_db_session()
q = DBSession.query(Pajak).filter_by(id=self.invoice.pajak_id) q = DBSession.query(Pajak).filter_by(id=self.invoice.pajak_id)
return q.first() return q.first()
def get_rekening(self): def get_rekening(self):
Rekening = self.get_rekening_model()
DBSession = get_db_session()
q = DBSession.query(Rekening).filter_by(id=self.pajak.rekening_id) q = DBSession.query(Rekening).filter_by(id=self.pajak.rekening_id)
return q.first() return q.first()
...@@ -153,7 +189,7 @@ class Inquiry(BaseInquiry): ...@@ -153,7 +189,7 @@ class Inquiry(BaseInquiry):
def __init__( def __init__(
self, invoice_id, rekening_notes=[], persen_denda=2, self, invoice_id, rekening_notes=[], persen_denda=2,
tgl_bayar=None): tgl_bayar=None):
BaseInquiry.__init__(self, invoice_id, rekening_notes) super().__init__(invoice_id, rekening_notes)
if not self.invoice: if not self.invoice:
return return
self.tgl_bayar = tgl_bayar or datetime.now() self.tgl_bayar = tgl_bayar or datetime.now()
...@@ -162,6 +198,8 @@ class Inquiry(BaseInquiry): ...@@ -162,6 +198,8 @@ class Inquiry(BaseInquiry):
self.hitung() self.hitung()
def get_payment_amount(self): def get_payment_amount(self):
Payment = self.get_payment_model()
DBSession = get_db_session()
q = DBSession.query(func.sum(Payment.jml_bayar).label('jml')) q = DBSession.query(func.sum(Payment.jml_bayar).label('jml'))
q = q.filter_by(spt_id=self.invoice.id) q = q.filter_by(spt_id=self.invoice.id)
pay = q.first() pay = q.first()
...@@ -188,6 +226,8 @@ class Inquiry(BaseInquiry): ...@@ -188,6 +226,8 @@ class Inquiry(BaseInquiry):
self.total += self.denda self.total += self.denda
def get_pay_seq(self): def get_pay_seq(self):
Payment = self.get_payment_model()
DBSession = get_db_session()
q = DBSession.query(Payment).filter_by(tahun=self.invoice.tahun) q = DBSession.query(Payment).filter_by(tahun=self.invoice.tahun)
q = q.order_by(Payment.sspdno.desc()) q = q.order_by(Payment.sspdno.desc())
pay = q.first() pay = q.first()
...@@ -196,6 +236,7 @@ class Inquiry(BaseInquiry): ...@@ -196,6 +236,7 @@ class Inquiry(BaseInquiry):
return 1 return 1
def do_payment(self, ntb): def do_payment(self, ntb):
Payment = self.get_payment_model()
sspdno = self.get_pay_seq() sspdno = self.get_pay_seq()
pay = Payment() pay = Payment()
pay.tahun = self.invoice.tahun pay.tahun = self.invoice.tahun
...@@ -207,6 +248,7 @@ class Inquiry(BaseInquiry): ...@@ -207,6 +248,7 @@ class Inquiry(BaseInquiry):
pay.sspdtgl = self.tgl_bayar pay.sspdtgl = self.tgl_bayar
pay.printed = pay.enabled = 1 pay.printed = pay.enabled = 1
self.invoice.status_pembayaran = 1 self.invoice.status_pembayaran = 1
DBSession = get_db_session()
DBSession.add(pay) DBSession.add(pay)
DBSession.add(self.invoice) DBSession.add(self.invoice)
DBSession.flush() DBSession.flush()
...@@ -216,12 +258,11 @@ class Inquiry(BaseInquiry): ...@@ -216,12 +258,11 @@ class Inquiry(BaseInquiry):
class Reversal(BaseInquiry): class Reversal(BaseInquiry):
def __init__(self, invoice_id): def __init__(self, invoice_id):
BaseInquiry.__init__(self, invoice_id) BaseInquiry.__init__(self, invoice_id)
if not self.invoice: if self.invoice:
return self.payment = self.get_payment()
self.set_profile()
self.payment = self.get_payment()
def do_reversal(self): def do_reversal(self):
DBSession = get_db_session()
if self.payment: if self.payment:
self.payment.jml_bayar = self.payment.denda = \ self.payment.jml_bayar = self.payment.denda = \
self.payment.bunga = 0 self.payment.bunga = 0
...@@ -232,6 +273,8 @@ class Reversal(BaseInquiry): ...@@ -232,6 +273,8 @@ class Reversal(BaseInquiry):
DBSession.flush() DBSession.flush()
def get_payment(self): def get_payment(self):
Payment = self.get_payment_model()
DBSession = get_db_session()
q = DBSession.query(Payment).filter_by(spt_id=self.invoice.id) q = DBSession.query(Payment).filter_by(spt_id=self.invoice.id)
q = q.order_by(Payment.id.desc()) q = q.order_by(Payment.id.desc())
return q.first() return q.first()
...@@ -265,25 +308,52 @@ class AvailableInvoice: ...@@ -265,25 +308,52 @@ class AvailableInvoice:
if count == self.option.count: if count == self.option.count:
break break
def get_invoice_model(self):
return Invoice
def get_pajak_model(self):
return Pajak
def get_rekening_model(self):
return Rekening
def get_usaha_model(self):
return Usaha
def get_customer_usaha_model(self):
return CustomerUsaha
def get_inquiry_class(self):
return Inquiry
def get_query(self): def get_query(self):
Invoice = self.get_invoice_model()
Pajak = self.get_pajak_model()
Rekening = self.get_rekening_model()
Usaha = self.get_usaha_model()
CustomerUsaha = self.get_customer_usaha_model()
DBSession = get_db_session()
q = DBSession.query( q = DBSession.query(
Invoice.sptno, Invoice.tahun, Rekening.rekeningkd, Invoice.sptno, Invoice.tahun, Rekening.rekeningkd,
Rekening.rekeningnm) Rekening.rekeningnm)
q = q.filter( q = q.filter(
Invoice.pajak_id==Pajak.id, Pajak.rekening_id==Rekening.id, Invoice.pajak_id == Pajak.id, Pajak.rekening_id == Rekening.id,
Invoice.status_pembayaran==0) Invoice.customer_usaha_id == CustomerUsaha.id,
CustomerUsaha.usaha_id == Usaha.id,
Invoice.status_pembayaran == 0)
if self.option.jenis: if self.option.jenis:
pola = '%{}%'.format(self.option.jenis) pola = '%{}%'.format(self.option.jenis)
q = q.filter(Rekening.rekeningnm.ilike(pola)) q = q.filter(Usaha.usahanm.ilike(pola))
return q return q
def get_message(self, row): def get_message(self, row):
invoice_id = FixLength(INVOICE_ID) invoice_id = FixLength(INVOICE_ID)
invoice_id['Tahun'] = row.tahun invoice_id['Tahun'] = row.tahun
invoice_id['SptNo'] = row.sptno invoice_id['SptNo'] = row.sptno
Inquiry = self.get_inquiry_class()
inq = Inquiry(invoice_id.get_raw(), persen_denda=self.persen_denda) inq = Inquiry(invoice_id.get_raw(), persen_denda=self.persen_denda)
if not inq.total: if not inq.total:
return return
return '{} {}, {}, Rp {}'.format( return '{} {} {} Rp {}'.format(
invoice_id.get_raw(), row.rekeningkd, row.rekeningnm, invoice_id.get_raw(), row.rekeningkd, row.rekeningnm,
thousand(inq.total)) thousand(inq.total))
from opensipkd.pad.services.default import (
Inquiry as BaseInquiry,
Reversal as BaseReversal,
AvailableInvoice as BaseAvailableInvoice,
)
from opensipkd.pad.models.tangsel import (
Kecamatan,
Kelurahan,
Customer,
CustomerUsaha,
Invoice,
Payment,
Pajak,
Rekening,
Usaha,
)
class Inquiry(BaseInquiry):
def get_kecamatan_model(self): # Override
return Kecamatan
def get_kelurahan_model(self): # Override
return Kelurahan
def get_customer_model(self): # Override
return Customer
def get_usaha_model(self): # Override
return Usaha
def get_customer_usaha_model(self): # Override
return CustomerUsaha
def get_rekening_model(self): # Override
return Rekening
def get_pajak_model(self): # Override
return Pajak
def get_invoice_model(self): # Override
return Invoice
def get_payment_model(self): # Override
return Payment
class Reversal(BaseReversal):
def get_invoice_model(self): # Override
return Invoice
def get_payment_model(self): # Override
return Payment
class AvailableInvoice(BaseAvailableInvoice):
def get_invoice_model(self): # Override
return Invoice
def get_pajak_model(self): # Override
return Pajak
def get_rekening_model(self): # Override
return Rekening
def get_usaha_model(self): # Override
return Usaha
def get_customer_usaha_model(self): # Override
return CustomerUsaha
def get_inquiry_class(self): # Override
return Inquiry
...@@ -10,11 +10,19 @@ with open('CHANGES.txt') as f: ...@@ -10,11 +10,19 @@ with open('CHANGES.txt') as f:
line = CHANGES.splitlines()[0] line = CHANGES.splitlines()[0]
version = line.split()[0] version = line.split()[0]
req_opensipkd_hitung = 'opensipkd-hitung @ '\
'git+https://git.opensipkd.com/sugiana/opensipkd-hitung',
requires = [ requires = [
'sqlalchemy', 'sqlalchemy',
'opensipkd-hitung @ git+https://git.opensipkd.com/sugiana/opensipkd-hitung', req_opensipkd_hitung,
] ]
script_available_inv = 'pad_available_invoice = '\
'opensipkd.pad.scripts.available_invoice:main'
script_inq = 'pad_inquiry = opensipkd.pad.scripts.inquiry:main'
setuptools.setup( setuptools.setup(
name='opensipkd-pad-models', name='opensipkd-pad-models',
version=version, version=version,
...@@ -32,8 +40,8 @@ setuptools.setup( ...@@ -32,8 +40,8 @@ setuptools.setup(
], ],
entry_points={ entry_points={
'console_scripts': [ 'console_scripts': [
'pad_available_invoice = opensipkd.pad.scripts.available_invoice:main', script_available_inv,
'pad_inquiry = opensipkd.pad.scripts.inquiry:main', script_inq,
] ]
}, },
) )
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!