Commit 8bb345d5 by Owo Sugiana

Invoice ID Tangsel bisa 12 atau 16 digit

1 parent ccfc7a09
0.4.2 2022-2-26
---------------
0.4.3 2022-03-12
----------------
- Kota Tangerang Selatan kini bisa menerima Invoice ID 12 digit maupun 16
digit.
- Inquiry bisa opsi --debug
0.4.2 2022-02-26
----------------
- Tambah Kota Sukabumi
0.4.1 2021-12-31
......
......@@ -5,6 +5,7 @@ import transaction
from opensipkd.string.money import thousand
from opensipkd.waktu import date_from_str
from .common import init
from .logger import log_config
help_tgl_bayar = 'format dd-mm-yyyy'
......@@ -42,6 +43,7 @@ def get_option(argv):
pars.add_argument('--tgl-bayar', help=help_tgl_bayar)
pars.add_argument('--payment', action='store_true')
pars.add_argument('--reversal', action='store_true')
pars.add_argument('--debug', action='store_true')
return pars.parse_args(argv)
......@@ -107,6 +109,7 @@ def error(s):
def main(argv=sys.argv):
option = get_option(argv[1:])
log_config(option.debug and 'DEBUG' or 'INFO')
conf, services = init(option)
invoice_id = option.invoice_id
tgl_bayar = option.tgl_bayar and date_from_str(option.tgl_bayar)
......
import sys
import logging.config
log_format = '%(asctime)s %(levelname)s %(name)s %(message)s'
formatter = logging.Formatter(log_format)
console_handler = logging.StreamHandler(sys.stdout)
console_handler.setFormatter(formatter)
def log_config(level='INFO'):
d = dict(
version=1,
formatters={'simple': {'format': log_format}},
handlers={
'console': {
'class': 'logging.StreamHandler',
'stream': 'ext://sys.stdout',
'formatter': 'simple'}},
loggers={'': {
'level': level,
'handlers': ['console']}})
logging.config.dictConfig(d)
......@@ -41,10 +41,10 @@ class Common:
def __init__(self, invoice_id):
self.invoice_id = invoice_id
self.invoice = None
if len(invoice_id) != self.invoice_id_length:
if not self.validate_invoice_id():
return
self.invoice_struct = FixLength(self.invoice_id_structure)
self.invoice_struct.set_raw(invoice_id)
self.invoice_struct.set_raw(self.invoice_id)
self.tahun = self.invoice_struct['Tahun']
self.tahun = int(self.tahun)
self.kode = self.invoice_struct['Kode'].lstrip('0')
......@@ -52,6 +52,9 @@ class Common:
q = self.query_invoice()
self.invoice = q.first()
def validate_invoice_id(self):
return len(self.invoice_id) == self.invoice_id_length
def query_invoice(self):
db_session = get_db_session()
return db_session.query(self.invoice_model).filter_by(
......@@ -72,7 +75,7 @@ class Common:
db_session.add(self.invoice)
def is_available(self):
return self.invoice.status_pembayaran == 0
return self.invoice.status_pembayaran in (0, 1)
def status_pembayaran(self):
return self.invoice.status_pembayaran
......@@ -83,6 +86,9 @@ class Inquiry(Common):
super().__init__(invoice_id)
if not self.invoice:
return
if not self.is_available():
self.invoice = None
return
self.persen_denda = conf.get('persen_denda')
if tgl_bayar:
self.tgl_bayar = tgl_bayar
......@@ -246,7 +252,7 @@ class Inquiry(Common):
# Override
def do_payment(self, ntb, bank_id=110, cabang=None, users=None, seq=None):
Common.do_payment(self)
super().do_payment()
cust = self.get_notaris()
pay_seq = self.get_pay_seq()
inv = self.invoice
......@@ -288,10 +294,9 @@ class Reversal(Common):
def __init__(self, invoice_id):
super().__init__(invoice_id)
self.payment = None
if not self.invoice:
if not self.invoice or not self.is_available():
return
if not self.is_available():
self.payment = self.get_last_payment()
self.payment = self.get_last_payment()
def get_last_payment(self):
db_session = get_db_session()
......@@ -300,7 +305,7 @@ class Reversal(Common):
return q.first()
def do_reversal(self): # Override
Common.do_reversal(self)
super().do_reversal()
self.payment.bayar = self.payment.denda = 0
db_session = get_db_session()
db_session.add(self.payment)
......
import logging
from opensipkd.string import FixLength
from opensipkd.string.money import thousand
from ..default import (
Common as BaseCommon,
Inquiry as BaseInquiry,
Reversal as BaseReversal,
AvailableInvoice as BaseAvailableInvoice,
)
from .structure import (
KODE_PROPINSI,
KODE_KABUPATEN,
JENIS_PAJAK,
INVOICE_ID_PREFIX,
INVOICE_ID,
INVOICE_ID_LENGTH,
)
class Common(BaseCommon):
def validate_invoice_id(self): # Override
if super().validate_invoice_id():
return True
log = logging.getLogger(__name__)
length = len(self.invoice_id)
if length != INVOICE_ID_LENGTH:
log.debug(f'Invoice ID {self.invoice_id} bukan '
f'{INVOICE_ID_LENGTH} digit')
return
if self.invoice_id.find(INVOICE_ID_PREFIX) != 0:
log.debug(f'Invoice ID {self.invoice_id} tidak berawalan '
f'{INVOICE_ID_PREFIX}')
return
log.debug(f'Invoice ID {self.invoice_id}')
inv_id = FixLength(INVOICE_ID)
inv_id.set_raw(self.invoice_id)
self.invoice_id = '20' + inv_id['Tahun'] + inv_id['Kode'] + \
inv_id['SSPD No']
log.debug(f'Invoice ID {self.invoice_id}')
return True
class Inquiry(BaseInquiry, Common):
pass
class Reversal(BaseReversal, Common):
pass
class AvailableInvoice(BaseAvailableInvoice):
def get_message(self, row):
invoice_id_struct = FixLength(self.invoice_id_structure)
invoice_id_struct['Tahun'] = row.tahun
invoice_id_struct['Kode'] = row.kode.zfill(2)
invoice_id_struct['SSPD No'] = row.no_sspd
invoice_id = invoice_id_struct.get_raw()
inq = self.inquiry_cls(invoice_id, self.conf)
if inq.total < 1:
return
invoice_id_v2_struct = FixLength(INVOICE_ID)
invoice_id_v2_struct['Propinsi'] = KODE_PROPINSI
invoice_id_v2_struct['Kabupaten'] = KODE_KABUPATEN
invoice_id_v2_struct['Jenis Pajak'] = JENIS_PAJAK
invoice_id_v2_struct['Tahun'] = row.tahun - 2000
invoice_id_v2_struct['Kode'] = row.kode.zfill(2)
invoice_id_v2_struct['SSPD No'] = row.no_sspd
invoice_id_v2 = invoice_id_v2_struct.get_raw()
total = thousand(inq.total).rjust(13)
msg = f'{invoice_id} / {invoice_id_v2} Rp {total}'
if row.tgl_jatuh_tempo:
jatuh_tempo = row.tgl_jatuh_tempo.strftime('%d-%m-%Y')
return f'{msg} jatuh tempo {jatuh_tempo}'
return msg
KODE_PROPINSI = '36'
KODE_KABUPATEN = '76'
JENIS_PAJAK = '01'
INVOICE_ID_PREFIX = KODE_PROPINSI + KODE_KABUPATEN + JENIS_PAJAK
INVOICE_ID = [
['Propinsi', 2, 'N'],
['Kabupaten', 2, 'N'],
['Jenis Pajak', 2, 'N'],
['Tahun', 2, 'N'],
['Kode', 2, 'N'],
['SSPD No', 6, 'N'],
]
INVOICE_ID_LENGTH = 0
for nama, size, tipe in INVOICE_ID:
INVOICE_ID_LENGTH += size
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!