Commit 31ecba36 by Owo Sugiana

Tambah Kabupaten Bekasi

1 parent ff20a421
0.3 2021-02-23
--------------
- Penambahan Kabupaten Bekasi
0.2.6 2020-11-24 0.2.6 2020-11-24
---------------- ----------------
- Inquiry kini memperhatikan field status_pembayaran - Inquiry kini memperhatikan field status_pembayaran
......
[main]
module = bekasi_kab
db_url = postgresql://user:pass@localhost/db
persen_denda = 2
# Berisi nomor rekening dimana Alamat 2 akan berisi pad.pad_spt.notes
# Setiap rekening dipisahkan oleh spasi atau beda baris
rekening_notes =
rekening_tanpa_denda =
4110202
4110205
# 973/1306/Bapenda 20200413
# Discount untuk kondisi Maret 2020 <= field masadari <= Desember 2020
rekening_tanpa_denda_mulai_maret_2020 =
4110101
4110102
4110103
4110104
4110105
4110106
4110107
4110108
4110109
4110112
4110201
4110701
4110301
41103011
41103012
4110302
4110304
4110305
4110307
4110310
4110311
4110312
4110313
4110314
4110315
4110316
4110317
4110318
4110319
41103191
41103192
4110320
# Discount untuk kondisi April 2020 <= field terimatgl <= Desember 2020
rekening_tanpa_denda_mulai_april_2020 =
4110801
4110401
4110402
4110403
4110404
4110405
4110406
4110407
4110408
4110409
4110410
4110411
...@@ -2,4 +2,6 @@ ...@@ -2,4 +2,6 @@
module = default module = default
db_url = postgresql://user:pass@localhost/db db_url = postgresql://user:pass@localhost/db
persen_denda = 2 persen_denda = 2
# Berisi nomor rekening dimana Alamat 2 akan berisi pad.pad_spt.notes
# Setiap rekening dipisahkan oleh spasi atau beda baris
#rekening_notes = #rekening_notes =
import sys import sys
from configparser import ConfigParser
from argparse import ArgumentParser from argparse import ArgumentParser
from sqlalchemy import create_engine from .common import init
from sqlalchemy.orm import sessionmaker
default_count = 10 default_count = 10
help_jenis = 'dari tabel pad_usaha' help_jenis = 'dari field pad_usaha.usahanm'
help_rekening = 'dari field tblrekening.rekeningkd'
help_tipe = 'dari tabel pad_spt_type' help_tipe = 'dari tabel pad_spt_type'
help_tgl = 'dd-mm-yyyy'
help_count = f'default {default_count}' help_count = f'default {default_count}'
...@@ -15,9 +15,10 @@ def get_option(argv): ...@@ -15,9 +15,10 @@ def get_option(argv):
pars = ArgumentParser() pars = ArgumentParser()
pars.add_argument('conf') pars.add_argument('conf')
pars.add_argument('--jenis', help=help_jenis) pars.add_argument('--jenis', help=help_jenis)
pars.add_argument('--rekening', help=help_rekening)
pars.add_argument('--tahun', type=int) pars.add_argument('--tahun', type=int)
pars.add_argument('--jatuh-tempo-min') pars.add_argument('--jatuh-tempo-min', help=help_tgl)
pars.add_argument('--jatuh-tempo-max') pars.add_argument('--jatuh-tempo-max', help=help_tgl)
pars.add_argument('--nominal-min', type=int) pars.add_argument('--nominal-min', type=int)
pars.add_argument('--nominal-max', type=int) pars.add_argument('--nominal-max', type=int)
pars.add_argument('--tgl-kohir-min') pars.add_argument('--tgl-kohir-min')
...@@ -25,6 +26,10 @@ def get_option(argv): ...@@ -25,6 +26,10 @@ def get_option(argv):
pars.add_argument('--tipe', help=help_tipe) pars.add_argument('--tipe', help=help_tipe)
pars.add_argument('--self', action='store_true') pars.add_argument('--self', action='store_true')
pars.add_argument('--no-self', action='store_true') pars.add_argument('--no-self', action='store_true')
pars.add_argument('--masa-min', help=help_tgl)
pars.add_argument('--masa-max', help=help_tgl)
pars.add_argument('--tgl-terima-min', help=help_tgl)
pars.add_argument('--tgl-terima-max', help=help_tgl)
pars.add_argument( pars.add_argument(
'--count', type=int, default=default_count, help=help_count) '--count', type=int, default=default_count, help=help_count)
return pars.parse_args(argv) return pars.parse_args(argv)
...@@ -32,16 +37,7 @@ def get_option(argv): ...@@ -32,16 +37,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)
module_name = conf.get('main', 'module')
module = __import__('opensipkd.pad.services.' + module_name)
services = getattr(module.pad.services, module_name)
AvailableInvoice = services.AvailableInvoice AvailableInvoice = services.AvailableInvoice
db_url = conf.get('main', 'db_url') a = AvailableInvoice(conf, option)
persen_denda = conf.getfloat('main', 'persen_denda')
engine = create_engine(db_url)
session_factory = sessionmaker(bind=engine)
module.pad.services.base.DBSession = session_factory()
a = AvailableInvoice(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)
cf = dict(rekening_notes=[])
for key, val in conf.items('main'):
if key == 'persen_denda':
val = float(val)
elif key.find('rekening_') == 0:
val = val.split()
cf[key] = val
module_name = cf['module']
module = __import__('opensipkd.pad.services.' + module_name)
db_url = cf['db_url']
engine = create_engine(db_url)
session_factory = sessionmaker(bind=engine)
dbs = module.pad.services.base.DBSession = session_factory()
register(dbs)
services = getattr(module.pad.services, module_name)
return cf, 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 zope.sqlalchemy import register
from opensipkd.string.money import thousand from opensipkd.string.money import thousand
from .common import init
ERR_PAYMENT_NOT_FOUND = 'Pembayaran tidak ditemukan, '\ ERR_PAYMENT_NOT_FOUND = 'Pembayaran tidak ditemukan, '\
...@@ -64,7 +61,7 @@ def show(inq): ...@@ -64,7 +61,7 @@ def show(inq):
show_val('Kecamatan Objek Pajak', inq.get_kecamatan_op()) show_val('Kecamatan Objek Pajak', inq.get_kecamatan_op())
show_val('Jatuh Tempo', inq.get_jatuh_tempo()) show_val('Jatuh Tempo', inq.get_jatuh_tempo())
show_rp('Tagihan', inq.tagihan) show_rp('Tagihan', inq.tagihan)
show_rp('Denda', inq.denda_pokok) show_rp('Denda', inq.denda)
show_rp('Discount Denda', inq.discount_denda) show_rp('Discount Denda', inq.discount_denda)
if inq.discount_denda: if inq.discount_denda:
show_val('Note', inq.notes) show_val('Note', inq.notes)
...@@ -86,11 +83,6 @@ def show_pkey_values(row): ...@@ -86,11 +83,6 @@ def show_pkey_values(row):
show_val(' '+c.name, val) show_val(' '+c.name, val)
def read_list_conf(conf, name):
return conf.has_option('main', name) and \
conf.get('main', name).split() or []
def error(s): def error(s):
print(s) print(s)
sys.exit() sys.exit()
...@@ -103,26 +95,13 @@ def date_from_str(s): ...@@ -103,26 +95,13 @@ def date_from_str(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, services = init(option)
invoice_id = option.invoice_id invoice_id = option.invoice_id
if option.tgl_bayar: if option.tgl_bayar:
tgl_bayar = date_from_str(option.tgl_bayar) tgl_bayar = date_from_str(option.tgl_bayar)
else: else:
tgl_bayar = None tgl_bayar = None
conf = ConfigParser() inq = services.Inquiry(invoice_id, conf, tgl_bayar)
conf.read(conf_file)
module_name = conf.get('main', 'module')
db_url = conf.get('main', 'db_url')
rekening_notes = read_list_conf(conf, 'rekening_notes')
engine = create_engine(db_url)
module = __import__('opensipkd.pad.services.' + module_name)
services = getattr(module.pad.services, module_name)
session_factory = sessionmaker(bind=engine)
module.pad.services.base.DBSession = session_factory()
register(module.pad.services.base.DBSession)
inq = services.Inquiry(
invoice_id, rekening_notes, conf.getfloat('main', 'persen_denda'),
tgl_bayar=tgl_bayar)
if not inq.invoice: if not inq.invoice:
error('Invoice ID {} tidak ada.'.format(invoice_id)) error('Invoice ID {} tidak ada.'.format(invoice_id))
show(inq) show(inq)
......
...@@ -3,3 +3,10 @@ DBSession = None # Diisi saat init ...@@ -3,3 +3,10 @@ DBSession = None # Diisi saat init
def get_db_session(): def get_db_session():
return DBSession return DBSession
def satu_kalimat(notes):
if not notes[1:]:
return notes[0]
s = ', '.join(notes[:-1])
return ', dan '.join([s, notes[-1]])
from datetime import date
from .default import (
Inquiry as BaseInquiry,
Reversal,
AvailableInvoice as BaseAvailableInvoice,
)
def dmy(tgl):
return tgl.strftime('%d-%m-%Y')
AWAL_MASA = date(2020, 3, 1)
AKHIR_MASA = date(2020, 12, 31)
AWAL_TERIMA = date(2020, 4, 1)
AKHIR_TGL_BAYAR = date(2021, 3, 31)
NOTE_REK = 'Rekening {rek} tidak dikenai denda'
NOTE_TGL_BAYAR = 'Tanggal bayar {tgl} <= ' + dmy(AKHIR_TGL_BAYAR)
NOTE_AWAL_MASA = 'field masadari {tgl} >= ' + dmy(AWAL_MASA)
NOTE_AKHIR_MASA = 'field masadari {tgl} <= ' + dmy(AKHIR_MASA)
NOTE_TGL_TERIMA = 'field terimatgl {tgl} >= ' + dmy(AWAL_TERIMA)
class Inquiry(BaseInquiry):
def get_discount_denda(self): # Override
self.notes = []
rek = self.rekening.rekeningkd
if rek in self.conf.get('rekening_tanpa_denda', []):
self.notes.append(NOTE_REK.format(rek=rek))
return self.denda
tgl_bayar = self.tgl_bayar.date()
if tgl_bayar > AKHIR_TGL_BAYAR:
return 0
tgl_masa = self.invoice.masadari.date()
if tgl_masa > AKHIR_MASA:
return 0
notes = [
NOTE_TGL_BAYAR.format(tgl=dmy(tgl_bayar)),
NOTE_AKHIR_MASA.format(tgl=dmy(tgl_masa))]
if tgl_masa >= AWAL_MASA and \
rek in self.conf.get(
'rekening_tanpa_denda_mulai_maret_2020', []):
notes.append(NOTE_AWAL_MASA.format(tgl=dmy(tgl_masa)))
notes.append(NOTE_REK.format(rek=rek))
self.notes = notes
return self.denda
tgl_terima = self.invoice.terimatgl.date()
if tgl_terima >= AWAL_TERIMA and \
rek in self.conf.get(
'rekening_tanpa_denda_mulai_april_2020', []):
notes.append(NOTE_TGL_TERIMA.format(tgl=tgl_terima))
notes.append(NOTE_REK.format(rek=rek))
self.notes = notes
return self.denda
return 0
class AvailableInvoice(BaseAvailableInvoice):
def get_inquiry_class(self):
return Inquiry
...@@ -31,7 +31,7 @@ from opensipkd.pad.models.default import ( ...@@ -31,7 +31,7 @@ from opensipkd.pad.models.default import (
Kohir, Kohir,
IsoPayment, IsoPayment,
) )
from ..base import get_db_session from .base import get_db_session
INVOICE_ID = [ INVOICE_ID = [
...@@ -41,14 +41,14 @@ INVOICE_ID = [ ...@@ -41,14 +41,14 @@ INVOICE_ID = [
class BaseInquiry: class BaseInquiry:
def __init__(self, invoice_id, rekening_notes=[]): def __init__(self, invoice_id, conf=dict()):
real_inv_id = self.get_invoice_id(invoice_id) real_inv_id = self.get_invoice_id(invoice_id)
self.invoice_id = FixLength(INVOICE_ID) self.invoice_id = FixLength(INVOICE_ID)
self.invoice_id.set_raw(real_inv_id) self.invoice_id.set_raw(real_inv_id)
self.invoice = None self.invoice = None
if not self.invoice_id['SptNo']: if not self.invoice_id['SptNo']:
return return
self.rekening_notes = rekening_notes self.conf = conf
Invoice = self.get_invoice_model() Invoice = self.get_invoice_model()
DBSession = get_db_session() DBSession = get_db_session()
q = DBSession.query(Invoice).filter_by( q = DBSession.query(Invoice).filter_by(
...@@ -167,18 +167,21 @@ class BaseInquiry: ...@@ -167,18 +167,21 @@ class BaseInquiry:
self.rekening = self.get_rekening() self.rekening = self.get_rekening()
self.kelurahan = self.get_kelurahan() self.kelurahan = self.get_kelurahan()
self.kecamatan = self.get_kecamatan() self.kecamatan = self.get_kecamatan()
if self.rekening.rekeningkd in self.rekening_notes: if self.rekening.rekeningkd in self.conf['rekening_notes']:
alamat = wrap(self.invoice.notes, 40) alamat = wrap(self.invoice.notes, 40)
if alamat[1:]: if alamat[1:]:
self.alamat1 = alamat[0] self.alamat1 = alamat[0]
self.alamat2 = alamat[1] self.alamat2 = alamat[1]
else: else:
self.alamat1 = self.wajib_pajak.alamat self.alamat1 = self.wajib_pajak.alamat.upper()
self.alamat2 = alamat[0] self.alamat2 = alamat[0]
else: else:
alamat = wrap(self.wajib_pajak.alamat, 40) alamat = wrap(self.wajib_pajak.alamat, 40)
self.alamat1 = alamat[0] self.alamat1 = alamat[0]
self.alamat2 = alamat[1:] and ' '.join(alamat[1:]) or '' self.alamat2 = alamat[1:] and ' '.join(alamat[1:]) or ''
self.alamat2 = self.alamat2
self.alamat1 = self.alamat1.upper()
self.alamat2 = self.alamat2.upper()
def get_tahun(self): def get_tahun(self):
return self.invoice.tahun return self.invoice.tahun
...@@ -196,7 +199,7 @@ class BaseInquiry: ...@@ -196,7 +199,7 @@ class BaseInquiry:
return ','.join(lengkap) return ','.join(lengkap)
def get_alamat_wp(self): def get_alamat_wp(self):
return self.wajib_pajak.alamat return self.wajib_pajak.alamat.upper()
def get_kode_pos_wp(self): def get_kode_pos_wp(self):
return self.wajib_pajak.wpkodepos return self.wajib_pajak.wpkodepos
...@@ -208,19 +211,19 @@ class BaseInquiry: ...@@ -208,19 +211,19 @@ class BaseInquiry:
return self.alamat2 return self.alamat2
def get_alamat_op(self): def get_alamat_op(self):
return self.objek_pajak.opalamat return self.objek_pajak.opalamat.strip().upper()
def get_kelurahan_op(self): def get_kelurahan_op(self):
return self.kelurahan.kelurahannm return self.kelurahan.kelurahannm.strip().upper()
def get_kecamatan_op(self): def get_kecamatan_op(self):
return self.kecamatan.kecamatannm return self.kecamatan.kecamatannm.strip().upper()
def get_kode_rekening(self): def get_kode_rekening(self):
return self.rekening.rekeningkd return self.rekening.rekeningkd.upper()
def get_nama_rekening(self): def get_nama_rekening(self):
return self.rekening.rekeningnm return self.rekening.rekeningnm.upper()
def get_masa_1(self, fmt='%d%m%Y'): def get_masa_1(self, fmt='%d%m%Y'):
return self.invoice.masadari.strftime(fmt) return self.invoice.masadari.strftime(fmt)
...@@ -253,16 +256,13 @@ class BaseInquiry: ...@@ -253,16 +256,13 @@ class BaseInquiry:
class Inquiry(BaseInquiry): class Inquiry(BaseInquiry):
def __init__( def __init__(self, invoice_id, conf, tgl_bayar=None):
self, invoice_id, rekening_notes=[], persen_denda=2, super().__init__(invoice_id, conf)
tgl_bayar=None):
super().__init__(invoice_id, rekening_notes)
if not self.invoice: if not self.invoice:
return return
self.notes = '' self.notes = ''
self.tgl_bayar = tgl_bayar or datetime.now() self.tgl_bayar = tgl_bayar or datetime.now()
self.set_profile() self.set_profile()
self.persen_denda = persen_denda
self.hitung() self.hitung()
def get_payment_amount(self): def get_payment_amount(self):
...@@ -282,13 +282,13 @@ class Inquiry(BaseInquiry): ...@@ -282,13 +282,13 @@ class Inquiry(BaseInquiry):
self.denda = self.bunga = round_up(bunga) self.denda = self.bunga = round_up(bunga)
if self.invoice.jatuhtempotgl: if self.invoice.jatuhtempotgl:
self.bln_tunggakan, self.denda_waktu = hitung_denda( self.bln_tunggakan, self.denda_waktu = hitung_denda(
self.tagihan, self.invoice.jatuhtempotgl, self.persen_denda, self.tagihan, self.invoice.jatuhtempotgl,
self.conf['persen_denda'],
self.tgl_bayar.date()) self.tgl_bayar.date())
self.denda_waktu = round_up(self.denda_waktu) self.denda_waktu = round_up(self.denda_waktu)
self.denda += self.denda_waktu self.denda += self.denda_waktu
else: else:
self.bln_tunggakan = None self.bln_tunggakan = None
self.denda_pokok = self.denda
self.discount_denda = self.get_discount_denda() self.discount_denda = self.get_discount_denda()
self.denda -= self.discount_denda self.denda -= self.discount_denda
...@@ -372,9 +372,9 @@ def date_from_str(s): ...@@ -372,9 +372,9 @@ def date_from_str(s):
class AvailableInvoice: class AvailableInvoice:
def __init__(self, persen_denda=2, option=None): def __init__(self, conf, option):
self.conf = conf
self.option = option self.option = option
self.persen_denda = persen_denda
def show(self): def show(self):
offset = -1 offset = -1
...@@ -434,13 +434,21 @@ class AvailableInvoice: ...@@ -434,13 +434,21 @@ class AvailableInvoice:
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.status_pembayaran == 0)
q = self.get_filter_rekening(q)
q = self.get_filter_usaha(q) q = self.get_filter_usaha(q)
q = self.get_filter_nominal(q) q = self.get_filter_nominal(q)
q = self.get_filter_jatuh_tempo(q) q = self.get_filter_jatuh_tempo(q)
q = self.get_filter_masa(q)
q = self.get_filter_tgl_terima(q)
q = self.get_filter_kohir(q) q = self.get_filter_kohir(q)
q = self.get_filter_type(q) q = self.get_filter_type(q)
return q return q
def get_filter_rekening(self, q):
if self.option.rekening:
q = q.filter(Rekening.rekeningkd == self.option.rekening)
return q
def get_filter_usaha(self, q): def get_filter_usaha(self, q):
if not (self.option.jenis or self.option.self or self.option.no_self): if not (self.option.jenis or self.option.self or self.option.no_self):
return q return q
...@@ -481,6 +489,26 @@ class AvailableInvoice: ...@@ -481,6 +489,26 @@ class AvailableInvoice:
q = q.filter(Invoice.jatuhtempotgl <= tgl) q = q.filter(Invoice.jatuhtempotgl <= tgl)
return q return q
def get_filter_masa(self, q):
Invoice = self.get_invoice_model()
if self.option.masa_min:
tgl = date_from_str(self.option.masa_min)
q = q.filter(Invoice.masadari >= tgl)
if self.option.masa_max:
tgl = date_from_str(self.option.masa_max)
q = q.filter(Invoice.masadari <= tgl)
return q
def get_filter_tgl_terima(self, q):
Invoice = self.get_invoice_model()
if self.option.tgl_terima_min:
tgl = date_from_str(self.option.tgl_terima_min)
q = q.filter(Invoice.terimatgl >= tgl)
if self.option.tgl_terima_max:
tgl = date_from_str(self.option.tgl_terima_max)
q = q.filter(Invoice.terimatgl <= tgl)
return q
def get_filter_kohir(self, q): def get_filter_kohir(self, q):
if not (self.option.tgl_kohir_min or self.option.tgl_kohir_max): if not (self.option.tgl_kohir_min or self.option.tgl_kohir_max):
return q return q
...@@ -509,7 +537,7 @@ class AvailableInvoice: ...@@ -509,7 +537,7 @@ class AvailableInvoice:
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() Inquiry = self.get_inquiry_class()
inq = Inquiry(invoice_id.get_raw(), persen_denda=self.persen_denda) inq = Inquiry(invoice_id.get_raw(), self.conf)
if not inq.total: if not inq.total:
return return
total = thousand(inq.total) total = thousand(inq.total)
......
...@@ -3,12 +3,12 @@ from datetime import ( ...@@ -3,12 +3,12 @@ from datetime import (
datetime, datetime,
timedelta, timedelta,
) )
from opensipkd.pad.services.default import ( from .default import (
Inquiry as BaseInquiry, Inquiry as BaseInquiry,
Reversal as BaseReversal, Reversal as BaseReversal,
AvailableInvoice as BaseAvailableInvoice, AvailableInvoice as BaseAvailableInvoice,
) )
from opensipkd.pad.models.tangsel import ( from ..models.tangsel import (
Kecamatan, Kecamatan,
Kelurahan, Kelurahan,
Customer, Customer,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!