refactor: enhance structure handling in Fix classes and add new methods for data retrieval

1 parent 7eb60584
......@@ -87,7 +87,7 @@ def get_value(obj, struct):
class SetFixLength(FixLength):
def __init__(self, raw, struct):
super(SetFixLength, self).__init__(struct)
raw = re.sub("\D", "", raw)
raw = re.sub(r"\D", "", raw)
self.set_raw(raw)
for name, typ, size in struct:
setattr(self, name, self[name])
......@@ -106,42 +106,59 @@ class BaseFixLength(SetFixLength):
class FixDati2(BaseFixLength):
def get_structure(self):
return DATI2
def kd_dati2(self):
return self["kd_propinsi"]+'.'+self['kd_dati2']
class FixKecamatan(BaseFixLength):
class FixKecamatan(FixDati2):
def get_structure(self):
return KECAMATAN
def kd_kecamatan(self):
return super().kd_dati2+'.'+self['kd_kecamatan']
class FixKelurahan(BaseFixLength):
class FixKelurahan(FixKecamatan):
def get_structure(self):
return KELURAHAN
def kd_kelurahan(self):
return super().kd_kecamatan+'.'+self['kd_kelurahan']
class FixBlok(BaseFixLength):
class FixBlok(FixKelurahan):
def get_structure(self):
return BLOK
def kd_blok(self):
return super().kd_kelurahan+'.'+self['kd_blok']
class FixKantor(BaseFixLength):
def get_structure(self):
return KANTOR
def kd_kantor(self):
return self['kd_kanwil']+'.'+self['kd_kantor']
class FixBank(BaseFixLength):
class FixBank(FixKantor):
def get_structure(self):
return BANK
def kd_bank(self):
return self['kd_kanwil']+'.'+self['kd_kantor']+'.'+self['kd_tp']
class FixBankSismiop(BaseFixLength):
class FixBankSismiop(FixKantor):
def get_structure(self):
return BANK_SISMIOP
def kd_bank(self):
return self['kd_kanwil_bank']+'.'+self['kd_kppbb_bank']+'.'+self['kd_bank_tunggal']+'.'+self['kd_bank_persepsi']+'.'+self['kd_tp']
class FixNop(BaseFixLength):
class FixNop(FixBlok):
def get_structure(self):
return NOP
def nop(self):
return ".".join([self.kd_blok(), self["no_urut"], self["kd_jns_op"]])
def get_formatted(self):
s = ''
for name, size, typ in self.struct:
......@@ -156,9 +173,29 @@ class FixNop(BaseFixLength):
return s[:-1]
class FixSppt(BaseFixLength):
class FixSppt(FixNop):
def get_structure(self):
return SPPT
def sppt(self):
return self.nop() + "." + self['thn_pajak_sppt']
BUMI = list(NOP)
BUMI.append(('no_bumi', 2, 'N'))
class FixBumi(BaseFixLength):
def get_structure(self):
return BUMI
BNG = list(NOP)
BNG.append(('no_bng', 2, 'N'))
class FixBng(BaseFixLength):
def get_structure(self):
return BNG
class FixSiklus(BaseFixLength):
......@@ -214,6 +251,9 @@ class FixBerkas(BaseFixLength):
def get_nopel_det(self):
return get_value(self, NOPELDET)
def get_tahun_pajak(self):
return self['thn_pajak_sppt']
class FixFormulir(BaseFixLength):
......@@ -279,38 +319,39 @@ def nop_formatted(row):
row.kd_kelurahan, row.kd_blok, row.no_urut, row.kd_jns_op)
def nop_to_id(row):
if type(row) in (StringType, UnicodeType):
row = FixNop(row)
return "%s%s%s%s%s%s%s" % (row.kd_propinsi, row.kd_dati2, row.kd_kecamatan,
row.kd_kelurahan, row.kd_blok, row.no_urut,
row.kd_jns_op)
def query_nop(table):
return func.concat(table.kd_propinsi,
func.concat(
'.',
func.concat(
table.kd_dati2,
func.concat(
'-',
func.concat(
table.kd_kecamatan,
func.concat(
'.',
func.concat(
table.kd_kelurahan,
func.concat(
'-',
func.concat(
table.kd_blok,
func.concat(
'.',
func.concat(
table.no_urut,
func.concat(
'-',
table.kd_jns_op))))))))))))
# def nop_to_id(row):
# if type(row) in (StringType, UnicodeType):
# row = FixNop(row)
# return "%s%s%s%s%s%s%s" % (row.kd_propinsi, row.kd_dati2, row.kd_kecamatan,
# row.kd_kelurahan, row.kd_blok, row.no_urut,
# row.kd_jns_op)
# def query_nop(table):
# return func.concat(table.kd_propinsi,
# func.concat(
# '.',
# func.concat(
# table.kd_dati2,
# func.concat(
# '-',
# func.concat(
# table.kd_kecamatan,
# func.concat(
# '.',
# func.concat(
# table.kd_kelurahan,
# func.concat(
# '-',
# func.concat(
# table.kd_blok,
# func.concat(
# '.',
# func.concat(
# table.no_urut,
# func.concat(
# '-',
# table.kd_jns_op))))))))))))
# JEnis REstitusi Kompensasi
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!