def show(self, option): sample_count = int(option.sample_count) q = DBSession.query(models.Invoice).filter_by( status_pembayaran=0).filter( models.Invoice.bphtb_harus_dibayarkan > 0) offset = -1 count = 0 while True: if count >= sample_count: break offset += 1 row = q.offset(offset).first() if not row: break invoice_id = FixLength(self.get_invoice_id_structure()) invoice_id['Tahun'] = row.tahun invoice_id['Kode'] = row.kode invoice_id['SSPD No'] = row.no_sspd calc = CalculateInvoice( models, DBSession, invoice_id, persen_denda) if calc.total < 1: continue count += 1 invoice_id_raw = invoice_id.get_raw() self.on_print(option, count, invoice_id_raw, calc)
def show(self, option): sample_count = int(option.sample_count) q = DBSession.query(models.Invoice).filter_by(status_pembayaran=0) q = q.order_by(models.Invoice.bphtb_harus_dibayarkan) offset = -1 count = 0 while True: if count >= sample_count: break offset += 1 row = q.offset(offset).first() if not row: break invoice_id = FixLength(self.get_invoice_id_structure()) invoice_id['Tahun'] = row.tahun invoice_id['Kode'] = row.kode invoice_id['SSPD No'] = row.no_sspd calc = CalculateInvoice(models, DBSession, invoice_id, persen_denda) if calc.total < 1: continue count += 1 msg = '#{no}/{count} {id} Rp {total}'.format( no=count, id=invoice_id.get_raw(), total=calc.total, count=sample_count) print(msg)
def show(self, option): sample_count = int(option.sample_count) q = DBSession.query( models.Invoice).filter_by(status_pembayaran=0).filter( models.Invoice.bphtb_harus_dibayarkan > 0) offset = -1 count = 0 while True: if count >= sample_count: break offset += 1 row = q.offset(offset).first() if not row: break invoice_id = FixLength(self.get_invoice_id_structure()) invoice_id['Tahun'] = row.tahun invoice_id['Kode'] = row.kode invoice_id['SSPD No'] = row.no_sspd calc = CalculateInvoice(models, DBSession, invoice_id, persen_denda) if calc.total < 1: continue count += 1 invoice_id_raw = invoice_id.get_raw() self.on_print(option, count, invoice_id_raw, calc)
class Transaction(BaseTransaction): def __init__(self, *args, **kwargs): self.invoice_id = FixLength(INVOICE_ID) self.invoice_profile = FixLength(INVOICE_PROFILE) BaseTransaction.__init__(self, *args, **kwargs) self.invoice_id_raw = None # Override def get_bit_definition(self): return TRANSACTION_BITS # Override def get_inquiry_code(self): return INQUIRY_CODE # Override def get_payment_code(self): return PAYMENT_CODE # Override def set_transaction_response(self): self.setMTI('0210') self.copy([2, 3, 7, 11, 12, 13, 15, 18, 32, 37, 41, 48, 90]) # Override def get_invoice_id(self): if self.invoice_id_raw is not None: return self.invoice_id_raw raw = self.get_value(48) self.invoice_profile.set_raw(raw) self.invoice_id_raw = self.invoice_profile['ID Billing'].strip() self.invoice_id.set_raw(self.invoice_id_raw) return self.invoice_id_raw def set_invoice_id(self, raw): self.invoice_profile['ID Billing'] = raw self.set_invoice_profile() # Override def set_invoice_profile(self): self.setBit(48, self.invoice_profile.get_raw()) # Override def set_ntp(self, ntp): self.invoice_profile['NTPD'] = ntp # Override def get_ntb(self): return self.get_value(90) def set_ntb(self, raw): self.setBit(90, raw) # Override def payment_response(self): self.copy([4])
def show(self, option): sample_count = int(option.sample_count) q = DBSession.query(models.Invoice.tahun, models.Invoice.sptno, models.Rekening.rekeningnm, models.Rekening.rekeningkd) q = q.filter(models.Invoice.pajak_id == models.Pajak.id) q = q.filter(models.Pajak.rekening_id == models.Rekening.id) q = q.filter(models.Invoice.status_pembayaran == 0) if option.jenis: pola = '%{nama}%'.format(nama=option.jenis) q = q.filter(models.Rekening.rekeningnm.ilike(pola)) if option.berdenda: q = q.filter(models.Invoice.jatuhtempotgl < date.today()) elif option.tanpa_denda: q = q.filter(models.Invoice.jatuhtempotgl >= date.today()) q = q.filter(models.Invoice.pajak_terhutang > 0) q = q.order_by(models.Invoice.pajak_terhutang) #q = q.order_by(models.Invoice.tahun.desc(), models.Invoice.sptno.desc()) offset = -1 count = 0 while True: if count >= sample_count: break offset += 1 row = q.offset(offset).first() if not row: break invoice_id = FixLength(INVOICE_ID) invoice_id['Tahun'] = row.tahun invoice_id['SPT No'] = row.sptno invoice_id_raw = invoice_id.get_raw() calc = CalculateInvoice(models, DBSession, invoice_id_raw, persen_denda) if calc.total < 1: continue count += 1 if calc.invoice.jatuhtempotgl: jatuh_tempo = calc.invoice.jatuhtempotgl.strftime('%d-%m-%Y') else: jatuh_tempo = 'tidak ada' msg = '#{no}/{count} {id} {nama_rek} {kode_rek} Rp {tagihan} + '\ 'Rp {denda} = Rp {total}, jatuh tempo {jatuh_tempo}' msg = msg.format(no=count, id=invoice_id_raw, nama_rek=row.rekeningnm, kode_rek=row.rekeningkd, tagihan=calc.tagihan, denda=calc.denda, total=calc.total, count=sample_count, jatuh_tempo=jatuh_tempo) print(msg)
class BaseResponse(object): def __init__(self, parent): self.parent = parent self.invoice_id = FixLength(INVOICE_ID) self.invoice_id.set_raw(parent.from_iso.get_invoice_id()) self.invoice_id_raw = self.invoice_id.get_raw() def is_transaction_owner(self, pay): conf = host[self.parent.conf['name']] return pay.kd_kanwil == conf['kd_kanwil'] and \ pay.kd_kantor == conf['kd_kantor'] and \ pay.kd_tp == conf['kd_tp'] def commit(self): DBSession.commit() self.parent.ack()
class BaseResponse(object): def __init__(self, parent): self.parent = parent self.invoice_id = FixLength(INVOICE_ID) self.invoice_id.set_raw(parent.from_iso.get_invoice_id()) self.invoice_id_raw = self.invoice_id.get_raw() def is_transaction_owner(self, pay): conf = host[self.parent.conf['name']] if pay.kd_kanwil != conf['kd_kanwil']: return if pay.kd_kantor != conf['kd_kantor']: return kd_tp = conf['kd_tp'] if isinstance(kd_tp, dict): if pay.kd_tp in kd_tp.values(): return True elif pay.kd_tp == kd_tp: return True def commit(self): DBSession.commit() self.parent.ack() def nama_kelurahan(self): return self.query.cari_kelurahan(self.invoice_id['Propinsi'], self.invoice_id['Kabupaten'], self.invoice_id['Kecamatan'], self.invoice_id['Kelurahan']) def nama_kecamatan(self): return self.query.cari_kecamatan(self.invoice_id['Propinsi'], self.invoice_id['Kabupaten'], self.invoice_id['Kecamatan']) def nama_propinsi(self): return self.query.cari_propinsi(self.invoice_id['Propinsi'])
def show(self, option): sample_count = int(option.sample_count) q = DBSession.query(models.Invoice.tahun, models.Invoice.sptno, models.Rekening.rekeningnm, models.Rekening.rekeningkd) q = q.filter(models.Invoice.pajak_id == models.Pajak.id) q = q.filter(models.Pajak.rekening_id == models.Rekening.id) q = q.filter(models.Invoice.status_pembayaran == 0) if option.jenis: pola = '%{nama}%'.format(nama=option.jenis) q = q.filter(models.Rekening.rekeningnm.ilike(pola)) if option.berdenda: q = q.filter(models.Invoice.jatuhtempotgl < date.today()) elif option.tanpa_denda: q = q.filter(models.Invoice.jatuhtempotgl >= date.today()) q = q.filter(models.Invoice.pajak_terhutang > 0) q = q.order_by(models.Invoice.pajak_terhutang) offset = -1 count = 0 while True: if count >= sample_count: break offset += 1 row = q.offset(offset).first() if not row: break invoice_id = FixLength(INVOICE_ID) invoice_id['Tahun'] = row.tahun invoice_id['SPT No'] = row.sptno invoice_id_raw = invoice_id.get_raw() calc = CalculateInvoice(models, iso_models, DBSession, invoice_id_raw, persen_denda) if calc.total < 1: continue count += 1 self.on_print(option, count, invoice_id_raw, row, calc)
class InquiryResponse(BaseResponse): def __init__(self, parent): BaseResponse.__init__(self, parent) self.invoice_profile = FixLength(INVOICE_PROFILE) self.invoice_profile.from_dict({ 'Propinsi': self.invoice_id['Propinsi'], 'Kabupaten': self.invoice_id['Kabupaten'], 'Kecamatan': self.invoice_id['Kecamatan'], 'Kelurahan': self.invoice_id['Kelurahan'], 'Blok': self.invoice_id['Blok'], 'Urut': self.invoice_id['Urut'], 'Jenis': self.invoice_id['Jenis'], 'Tahun Pajak': self.invoice_id['Tahun Pajak'], 'Nama Kelurahan': nama_kelurahan(self.invoice_id), 'Nama Kecamatan': nama_kecamatan(self.invoice_id), 'Nama Propinsi': nama_propinsi(self.invoice_id)}) try: int(self.invoice_id_raw) except ValueError: self.calc = None return self.calc = CalculateInvoice(models, DBSession, persen_denda, self.invoice_id['Propinsi'], self.invoice_id['Kabupaten'], self.invoice_id['Kecamatan'], self.invoice_id['Kelurahan'], self.invoice_id['Blok'], self.invoice_id['Urut'], self.invoice_id['Jenis'], self.invoice_id['Tahun Pajak']) def set_invoice_profile(self): inv = self.calc.invoice self.parent.set_amount(self.calc.total) self.invoice_profile.from_dict({ 'Nama': inv.nm_wp_sppt, 'Luas Tanah': int(inv.luas_bumi_sppt), 'Luas Bangunan': int(inv.luas_bng_sppt), 'Lokasi': inv.jln_wp_sppt, 'Jatuh Tempo': inv.tgl_jatuh_tempo_sppt.strftime('%Y%m%d'), 'Tagihan': self.calc.tagihan, 'Denda': self.calc.denda, 'Total Bayar': self.calc.total}) self.set_invoice_profile_to_parent() def set_invoice_profile_to_parent(self): self.parent.set_invoice_profile(self.invoice_profile.get_raw()) def is_valid(self, is_need_invoice_profile=True): if not self.calc: return self.parent.ack_invalid_number() if not self.calc.invoice: is_need_invoice_profile and self.set_invoice_profile_to_parent() return self.parent.ack_not_available() is_need_invoice_profile and self.set_invoice_profile() if self.calc.paid: return self.ack_already_paid() if self.calc.total <= 0: return self.parent.ack_already_paid_2(self.calc.total) return True def ack_already_paid(self): pay = self.calc.invoice2payment() if pay and self.is_transaction_owner(pay): ntp = pay.id else: ntp = '' self.parent.set_ntp(ntp) return self.parent.ack_already_paid() def response(self): if not self.is_valid(): return self.parent.set_amount(0) self.parent.set_amount(self.calc.total) query.create_inquiry(self.calc, self.parent.from_iso, persen_denda) self.commit()
class InquiryResponse(BaseResponse): def __init__(self, parent): BaseResponse.__init__(self, parent) cls = self.get_calc_cls() raw = parent.from_iso.get_invoice_id() self.calc = cls(models, DBSession, raw, persen_denda) module_conf = host[self.parent.conf['name']] self.parent.conf.update(module_conf) self.invoice_profile = FixLength(self.get_invoice_profile_structure()) def get_calc_cls(self): return CalculateInvoice def get_invoice_profile_structure(self): return INVOICE_PROFILE def init_invoice_profile(self): self.invoice_profile.from_dict({ 'kode pajak': 'BPHTB', 'nama pajak': 'BEA PEROLEHAN HAK ATAS TANAH DAN BANGUNAN', }) def set_invoice_profile(self): invoice = self.calc.invoice self.invoice_profile.from_dict({ 'npwpd': invoice.wp_npwp, 'nama': invoice.wp_nama, 'alamat': invoice.wp_alamat, 'tagihan': self.calc.tagihan, 'denda': self.calc.denda, 'jumlah': self.calc.total, 'jenis perolehan': invoice.perolehan_id, 'nilai perolehan': invoice.npop, 'rt wp': invoice.wp_rt, 'rw wp': invoice.wp_rw, 'kelurahan wp': invoice.wp_kelurahan, 'kecamatan wp': invoice.wp_kecamatan, 'kota wp': invoice.wp_kota, 'tahun pajak': invoice.tahun, 'nik': invoice.wp_identitas, 'luas tanah': invoice.bumi_luas, 'luas bangunan': invoice.bng_luas, 'alamat op': invoice.op_alamat, }) self.set_jatuh_tempo() self.set_kode_pos_wp() self.set_kecamatan_op() self.set_kelurahan_op() self.set_notaris() self.set_invoice_profile_to_parent() def is_valid(self, is_need_invoice_profile=True): if not self.calc.invoice: is_need_invoice_profile and self.set_invoice_profile_to_parent() if self.calc.invoice is False: return self.parent.ack_invalid_number() return self.parent.ack_not_available() is_need_invoice_profile and self.set_invoice_profile() if self.calc.paid: return self.ack_already_paid() if self.calc.total <= 0: return self.parent.ack_already_paid_2(self.calc.total) return True def response(self): if not self.is_allowed(): return self.init_invoice_profile() if not self.is_valid(): return self.parent.set_amount(0) self.parent.set_amount(self.calc.total) self.parent.ack() def set_jatuh_tempo(self): if self.calc.invoice.tgl_jatuh_tempo: self.set_invoice_profile_( 'jatuh tempo', self.calc.invoice.tgl_jatuh_tempo.strftime('%d%m%Y')) def set_kode_pos_wp(self): kode_pos = self.calc.invoice.wp_kdpos.strip() self.set_invoice_profile_('kode pos wp', kode_pos) def set_kecamatan_op(self): row = self.calc.get_kecamatan() if row: self.set_invoice_profile_('kecamatan op', row.nm_kecamatan) def set_kelurahan_op(self): row = self.calc.get_kelurahan() if row: self.set_invoice_profile_('kelurahan op', row.nm_kelurahan) def set_notaris(self): row = self.calc.get_customer() if row: self.set_invoice_profile_('notaris', row.nama) def set_invoice_profile_(self, key, value): if value: self.invoice_profile.from_dict({key: value}) def set_invoice_profile_to_parent(self): self.parent.set_invoice_profile(self.invoice_profile.get_raw()) def ack_already_paid(self): iso_pay = self.calc.get_iso_payment() if iso_pay and iso_pay.bank_id == self.parent.get_bank_id(): ntp = iso_pay.ntp else: ntp = '' self.parent.set_ntp(ntp) return self.parent.ack_already_paid()
class InquiryResponse(BaseResponse): def __init__(self, parent): BaseResponse.__init__(self, parent) q_cls = self.get_query_cls() self.query = q_cls(models, DBSession) inv_struct = self.get_invoice_profile_structure() self.invoice_profile = FixLength(inv_struct) nama_kelurahan = self.nama_kelurahan() nama_kecamatan = self.nama_kecamatan() nama_propinsi = self.nama_propinsi() self.invoice_profile.from_dict({ 'Propinsi': self.invoice_id['Propinsi'], 'Kabupaten': self.invoice_id['Kabupaten'], 'Kecamatan': self.invoice_id['Kecamatan'], 'Kelurahan': self.invoice_id['Kelurahan'], 'Blok': self.invoice_id['Blok'], 'Urut': self.invoice_id['Urut'], 'Jenis': self.invoice_id['Jenis'], 'Tahun Pajak': self.invoice_id['Tahun Pajak'], 'Nama Kelurahan': nama_kelurahan, 'Nama Kecamatan': nama_kecamatan, 'Nama Propinsi': nama_propinsi }) self.calc = self.get_calc() def get_query_cls(self): return Inquiry def get_calc_cls(self): return CalculateInvoice def get_invoice_profile_structure(self): return INVOICE_PROFILE def get_calc(self): try: int(self.invoice_id_raw) except ValueError: return cls = self.get_calc_cls() return cls(models, DBSession, persen_denda, self.invoice_id['Propinsi'], self.invoice_id['Kabupaten'], self.invoice_id['Kecamatan'], self.invoice_id['Kelurahan'], self.invoice_id['Blok'], self.invoice_id['Urut'], self.invoice_id['Jenis'], self.invoice_id['Tahun Pajak']) def set_invoice_profile(self): self.parent.set_amount(self.calc.total) nama_jalan = self.nama_jalan() inv = self.calc.invoice self.invoice_profile.from_dict({ 'Nama': inv.nm_wp_sppt, 'Luas Tanah': int(inv.luas_bumi_sppt), 'Luas Bangunan': int(inv.luas_bng_sppt), 'Lokasi': nama_jalan, 'Jatuh Tempo': inv.tgl_jatuh_tempo_sppt.strftime('%Y%m%d'), 'Tagihan': self.calc.tagihan, 'Denda': self.calc.denda, 'Total Bayar': self.calc.total }) def set_invoice_profile_to_parent(self): self.parent.set_invoice_profile(self.invoice_profile.get_raw()) def nama_jalan(self): return self.calc.invoice.jln_wp_sppt def is_valid(self): if not self.calc: return self.parent.ack_invalid_number() if not self.calc.invoice: return self.parent.ack_not_available() self.set_invoice_profile() self.set_invoice_profile_to_parent() if self.calc.paid: return self.parent.ack_already_paid() if self.calc.total <= 0: return self.parent.ack_already_paid_2(self.calc.total) return True def ack_already_paid(self): pay = self.calc.invoice2payment() ntp = '' if pay and self.is_transaction_owner(pay): calc = self.calc q = DBSession.query(models.Payment).filter_by( propinsi=calc.propinsi, kabupaten=calc.kabupaten, kecamatan=calc.kecamatan, kelurahan=calc.kelurahan, blok=calc.blok, urut=calc.urut, jenis=calc.jenis, tahun=calc.tahun).order_by(models.Payment.ke.desc()) iso_pay = q.first() if iso_pay: ntp = iso_pay.id self.parent.set_ntp(ntp) return self.parent.ack_already_paid() def response(self): if not self.is_valid(): return self.parent.set_amount(0) self.parent.set_amount(self.calc.total) self.query.create_inquiry(self.calc, self.parent.from_iso, persen_denda) self.commit()
class Inquiry(BaseResponse): def __init__(self, parent): BaseResponse.__init__(self, parent) self.calc = CalculateInvoice(models, DBSession, self.invoice_id_raw) def init_invoice_profile(self): self.invoice_profile = FixLength(INVOICE_PROFILE) self.invoice_profile.from_dict({ 'kode pajak': 'BPHTB', 'nama pajak': 'BEA PEROLEHAN HAK ATAS TANAH DAN BANGUNAN', }) def set_invoice_profile(self): invoice = self.calc.invoice self.invoice_profile.from_dict({ 'npwpd': invoice.npwp_wp, 'nama' : invoice.nama_wp, 'alamat': invoice.alamat_wp, 'tagihan': self.calc.tagihan, 'jumlah': self.calc.tagihan, 'jenis perolehan' : invoice.kd_bphtb, 'nilai perolehan': invoice.npop_omset, 'rt wp': invoice.rt_wp, 'rw wp': invoice.rw_wp, 'kelurahan wp': invoice.kelurahan_wp, 'kecamatan wp': invoice.kecamatan_wp, 'kota wp': invoice.kota_wp, 'tahun pajak': invoice.tahun, #'nik': invoice.wp_identitas, 'luas tanah': invoice.luas_bumi, 'luas bangunan': invoice.luas_bng, 'alamat op' : invoice.alamat_op, }) self.set_jatuh_tempo() self.set_kode_pos_wp() self.set_kecamatan_op() self.set_kelurahan_op() self.set_notaris() self.set_invoice_profile_to_parent() def is_valid(self, is_need_invoice_profile=True): if not self.calc.invoice: is_need_invoice_profile and self.set_invoice_profile_to_parent() if self.calc.invoice is False: return self.parent.ack_invalid_number() return self.parent.ack_not_available() is_need_invoice_profile and self.set_invoice_profile() if self.calc.paid: return self.ack_already_paid() if self.calc.tagihan <= 0: return self.parent.ack_already_paid_2(self.calc.tagihan) return True def response(self): if not self.is_allowed(): return self.init_invoice_profile() if not self.is_valid(): return self.parent.set_amount(0) self.parent.set_amount(self.calc.tagihan) self.save() def set_jatuh_tempo(self): if self.calc.invoice.jatuh_tempo: self.set_invoice_profile_('jatuh tempo', self.calc.invoice.jatuh_tempo.strftime('%d%m%Y')) def set_kode_pos_wp(self): kode_pos = self.calc.invoice.kodepos_wp.strip() self.set_invoice_profile_('kode pos wp', kode_pos) def set_kecamatan_op(self): if self.calc.invoice.kecamatan_op: self.set_invoice_profile_('kecamatan op', self.calc.invoice.kecamatan_op) def set_kelurahan_op(self): if self.calc.invoice.kelurahan_op: self.set_invoice_profile_('kelurahan op', self.calc.invoice.kelurahan_op) def set_notaris(self): if self.calc.invoice.nm_notaris: self.set_invoice_profile_('notaris', self.calc.invoice.nm_notaris) def set_invoice_profile_(self, key, value): if value: self.invoice_profile.from_dict({key: value}) def set_invoice_profile_to_parent(self): self.parent.set_invoice_profile(self.invoice_profile.get_raw()) def ack_already_paid(self): iso_pay = self.calc.get_iso_payment() ntp = '' if iso_pay: pay = query.get_payment_from_iso(iso_pay) if pay.bank_id == self.parent.conf['id']: ntp = pay.ntp self.parent.set_ntp(ntp) return self.parent.ack_already_paid() def save(self): inq = models.IsoInquiry() inq.tgl = datetime.now() inq.invoice_id = self.calc.invoice.id inq.bank_id = self.parent.conf['id'] inq.channel_id = self.parent.from_iso.get_channel() inq.stan = self.parent.from_iso.get_stan() inq.transmission = self.parent.from_iso.get_transmission() inq.settlement = self.parent.from_iso.get_settlement() DBSession.add(inq) DBSession.flush() self.commit()
class InquiryResponse(BaseResponse): def __init__(self, parent): BaseResponse.__init__(self, parent) self.calc = CalculateInvoice(models, DBSession, self.invoice_id, persen_denda) module_conf = host[self.parent.conf['name']] self.parent.conf.update(module_conf) self.invoice_profile = FixLength(self.get_invoice_profile_structure()) def get_invoice_id_structure(self): return INVOICE_ID def get_invoice_profile_structure(self): return INVOICE_PROFILE def init_invoice_profile(self): self.invoice_profile.from_dict({ 'kode pajak': 'BPHTB', 'nama pajak': 'BEA PEROLEHAN HAK ATAS TANAH DAN BANGUNAN', }) def set_invoice_profile(self): invoice = self.calc.invoice self.invoice_profile.from_dict({ 'npwpd': invoice.wp_npwp, 'nama': invoice.wp_nama, 'alamat': invoice.wp_alamat, 'tagihan': self.calc.tagihan, 'denda': self.calc.denda, 'jumlah': self.calc.total, 'jenis perolehan': invoice.perolehan_id, 'nilai perolehan': invoice.npop, 'rt wp': invoice.wp_rt, 'rw wp': invoice.wp_rw, 'kelurahan wp': invoice.wp_kelurahan, 'kecamatan wp': invoice.wp_kecamatan, 'kota wp': invoice.wp_kota, 'tahun pajak': invoice.tahun, 'nik': invoice.wp_identitas, 'luas tanah': invoice.bumi_luas, 'luas bangunan': invoice.bng_luas, 'alamat op': invoice.op_alamat, }) self.set_jatuh_tempo() self.set_kode_pos_wp() self.set_kecamatan_op() self.set_kelurahan_op() self.set_notaris() self.set_invoice_profile_to_parent() def is_valid(self, is_need_invoice_profile=True): if not self.calc.invoice: is_need_invoice_profile and self.set_invoice_profile_to_parent() if self.calc.invoice is False: return self.parent.ack_invalid_number() return self.parent.ack_not_available() is_need_invoice_profile and self.set_invoice_profile() if self.calc.paid: return self.ack_already_paid() if self.calc.total <= 0: return self.parent.ack_already_paid_2(self.calc.total) return True def response(self): self.init_invoice_profile() if not self.is_valid(): return self.parent.set_amount(0) self.parent.set_amount(self.calc.total) self.parent.ack() def set_jatuh_tempo(self): if self.calc.invoice.tgl_jatuh_tempo: self.set_invoice_profile_( 'jatuh tempo', self.calc.invoice.tgl_jatuh_tempo.strftime('%d%m%Y')) def set_kode_pos_wp(self): kode_pos = self.calc.invoice.wp_kdpos.strip() self.set_invoice_profile_('kode pos wp', kode_pos) def set_kecamatan_op(self): row = self.calc.get_kecamatan() if row: self.set_invoice_profile_('kecamatan op', row.nm_kecamatan) def set_kelurahan_op(self): row = self.calc.get_kelurahan() if row: self.set_invoice_profile_('kelurahan op', row.nm_kelurahan) def set_notaris(self): row = self.calc.get_customer() if row: self.set_invoice_profile_('notaris', row.nama) def set_invoice_profile_(self, key, value): if value: self.invoice_profile.from_dict({key: value}) def set_invoice_profile_to_parent(self): self.parent.set_invoice_profile(self.invoice_profile.get_raw()) def ack_already_paid(self): iso_pay = self.calc.get_iso_payment() if iso_pay and iso_pay.bank_id == self.parent.conf['id']: ntp = iso_pay.ntp else: ntp = '' self.parent.set_ntp(ntp) return self.parent.ack_already_paid()
class InquiryResponse(BaseResponse): def __init__(self, parent): BaseResponse.__init__(self, parent) self.parent = parent cls = self.get_calc_cls() invoice_id_raw = parent.from_iso.get_invoice_id() self.calc = cls(self.models, DBSession, invoice_id_raw, persen_denda) module_conf = host[self.parent.conf['name']] self.parent.conf.update(module_conf) def get_calc_cls(self): return CalculateInvoice def init_invoice_profile(self): self.invoice_profile = FixLength(INVOICE_PROFILE) self.invoice_profile.from_dict({ 'kode pajak': 'PADL', 'nama pajak': 'PENDAPATAN ASLI DAERAH LAINNYA', }) def set_invoice_profile(self): invoice = self.calc.invoice op = self.calc.get_op() kel = self.calc.get_kelurahan(op.kelurahan_id) kec = self.calc.get_kecamatan(kel.kecamatan_id) wp = self.calc.get_wp(op) nama = self.get_nama_wp(op, wp) self.invoice_profile.from_dict({ 'npwpd': wp.npwpd, 'nama': nama, 'alamat': wp.alamat, 'tagihan': self.calc.tagihan, 'denda': self.calc.denda, 'jumlah': self.calc.total, 'alamat op': op.opalamat, 'kelurahan op': kel.kelurahannm, 'kecamatan op': kec.kecamatannm, 'kode pos wp': wp.wpkodepos, }) self.set_jatuh_tempo() self.set_invoice_profile_to_parent() def get_nama_wp(self, op, wp): nama_ = [] if op.opnm: nama_.append(op.opnm) nama = self.calc.invoice.r_nama or wp.customernm if nama: nama_.append(nama) return ','.join(nama_) def is_valid(self, is_need_invoice_profile=True): if not self.calc.invoice: is_need_invoice_profile and self.set_invoice_profile_to_parent() return self.parent.ack_not_available() is_need_invoice_profile and self.set_invoice_profile() if self.calc.paid: return self.ack_already_paid() if self.calc.total <= 0: return self.parent.ack_already_paid_2(self.calc.total) return True def response(self): if not self.is_allowed(): return self.init_invoice_profile() if not self.is_valid(): return self.parent.set_amount(0) self.parent.set_amount(self.calc.total) self.parent.ack() def set_jatuh_tempo(self): if self.calc.invoice.jatuhtempotgl: self.set_invoice_profile_( 'jatuh tempo', self.calc.invoice.jatuhtempotgl.strftime('%d%m%Y')) def set_invoice_profile_(self, key, value): if value: self.invoice_profile.from_dict({key: value}) def set_invoice_profile_to_parent(self): self.parent.set_invoice_profile(self.invoice_profile.get_raw()) def ack_already_paid(self): iso_pay = self.calc.get_iso_payment() if iso_pay and iso_pay.bank_id == self.parent.conf['id']: ntp = iso_pay.ntp else: ntp = '' self.parent.set_ntp(ntp) return self.parent.ack_already_paid()
class Transaction(BaseTransaction): def __init__(self, *args, **kwargs): BaseTransaction.__init__(self, *args, **kwargs) self.invoice_profile = FixLength(INVOICE_PROFILE) # Override def get_bit_definition(self): return TRANSACTION_BITS # Override def set_response(self): if self.from_iso.is_network_request(): Network.set_response(self) if self.from_iso.is_payment_request(): self.set_payment_response() elif self.from_iso.is_transaction_request(): self.set_transaction_response() elif self.from_iso.is_reversal_request(): self.set_reversal_response() def get_payment_codes(self): return PAYMENT_CODES def get_methods(self): return METHODS def get_invoice_id(self): return self.get_value(61).strip() def is_inquiry_request(self): return self.is_transaction_request() and \ self.get_transaction_code() == INQUIRY_CODE and \ 'inquiry_request_handler' def is_inquiry_response(self): return self.is_transaction_response() and \ self.get_transaction_code() == INQUIRY_CODE def is_payment_request(self): return self.is_transaction_request() and \ self.get_transaction_code() == PAYMENT_CODE and \ 'payment_request_handler' def is_payment_response(self): return self.is_transaction_response() and \ self.get_transaction_code() == PAYMENT_CODE def set_transaction_response(self): BaseTransaction.set_transaction_response(self) self.copy([ 2, 3, 7, 11, 12, 13, 15, 18, 22, 32, 33, 35, 37, 41, 43, 49, 61, 62 ]) def set_payment_response(self): self.set_transaction_response() self.copy([4, 48, 62]) self.set_ntp('') def set_invoice_profile(self): raw = self.invoice_profile.get_raw() self.setBit(62, raw.upper()) def get_ntb(self): return self.get_value(48) def set_ntb(self, v): self.setBit(48, v) def set_ntp(self, v): self.setBit(47, v) def set_amount(self, value): self.setBit(4, value) def get_amount(self): return int(self.get_value(4)) def get_channel_id(self): return self.get_value(18) def get_bank_ip(self): return self.conf['ip'] ############ # Reversal # ############ def is_reversal_request(self): return BaseTransaction.is_reversal_request(self) and \ self.get_transaction_code() == PAYMENT_CODE and \ 'reversal_request_handler' ################### # Acknowledgement # ################### def ack_invalid_number(self): msg = ERR_INVALID_NUMBER.format( invoice_id=self.from_iso.get_invoice_id()) self.ack(RC_INVALID_NUMBER, msg) def ack_not_available(self): msg = ERR_NOT_AVAILABLE.format( invoice_id=self.from_iso.get_invoice_id()) self.ack(RC_NOT_AVAILABLE, msg) def ack_already_paid(self): msg = ERR_ALREADY_PAID.format( invoice_id=self.from_iso.get_invoice_id()) self.ack(RC_ALREADY_PAID, msg) def ack_insufficient_fund(self, total_tagihan): msg = ERR_INSUFFICIENT_FUND.format( invoice_id=self.from_iso.get_invoice_id(), bayar=self.from_iso.get_amount(), tagihan=total_tagihan) self.ack(RC_INSUFFICIENT_FUND, msg) def ack_payment_not_found(self): self.ack(RC_NOT_AVAILABLE, ERR_PAYMENT.format(invoice_id=self.get_invoice_id())) def ack_iso_payment_not_found(self): self.ack(RC_NOT_AVAILABLE, ERR_ISO_PAYMENT.format(invoice_id=self.get_invoice_id())) def ack_payment_owner(self): msg = ERR_PAYMENT_OWNER.format(invoice_id=self.get_invoice_id()) self.ack(RC_NOT_AVAILABLE, msg) def ack_invoice_open(self): msg = ERR_INVOICE_OPEN.format(invoice_id=self.get_invoice_id()) self.ack(RC_ALREADY_PAID, msg) def ack_payment_owner(self): msg = ERR_PAYMENT_OWNER.format(invoice_id=self.get_invoice_id()) self.ack(RC_NOT_AVAILABLE, msg) def ack_ntb(self): msg = ERR_NTB.format(ntb=self.get_ntb(), invoice_id=self.get_invoice_id())
class DbTransaction(Transaction): def __init__(self, *args, **kwargs): self.invoice_profile = FixLength(INVOICE_PROFILE) Transaction.__init__(self, *args, **kwargs) # Override def get_bit_definition(self): return TRANSACTION_BITS # Override def get_inquiry_codes(self): return (INQUIRY_CODE, ) # Override def get_payment_codes(self): return (PAYMENT_CODE, ) # Override def get_methods(self): return { INQUIRY_CODE: 'inquiry_request_handler', PAYMENT_CODE: 'payment_request_handler', } # Override def set_transaction_response(self): self.setMTI('0210') # Sesuai kolom yang berisi E (Equal) pada dokumentasi self.copy([2, 3, 7, 11, 12, 13, 15, 18, 37, 41, 48, 90]) raw = self.get_invoice_profile() self.invoice_profile.set_raw(raw) # Override # Ini dipanggil dengan from_iso. def get_invoice_id(self): raw = self.get_invoice_profile() self.invoice_profile.set_raw(raw) bank_invoice_id_raw = self.invoice_profile['ID Billing'].strip() return bank_invoice_id_raw[2:] def inquiry_request_handler(self): self.transaction_request_handler('inquiry') def payment_request_handler(self): self.transaction_request_handler('payment') def jenis_pajak(self): self.invoice_id_raw = self.get_invoice_id() length = len(self.invoice_id_raw) if length == 12: return 'bphtb' elif length == 10: return 'padl' self.ack_invalid_number() def transaction_request_handler(self, name): jenis_pajak = self.jenis_pajak() if not jenis_pajak: return func_name = '{j}_{n}_request_handler'.format(j=jenis_pajak, n=name) func = getattr(self, func_name) func() def get_invoice_profile(self): return self.get_value(48) # Override def set_invoice_profile(self, raw=None): raw = self.invoice_profile.get_raw() self.setBit(48, raw) # Override def set_ntp(self, ntp): self.invoice_profile['NTPD'] = ntp # Override def get_cabang(self): return dict(kode=None, user=None) # Override def get_ntb(self): return self.get_value(90).lstrip('0') # Override def is_reversal_request(self): ok = BaseTransaction.is_reversal_request(self) if not ok: return jenis_pajak = self.jenis_pajak() if jenis_pajak: return '{j}_reversal_request_handler'.format(j=jenis_pajak) def bphtb_inquiry_request_handler(self): try: bphtb.inquiry(self) except: self.ack_unknown() def bphtb_payment_request_handler(self): try: bphtb.payment(self) except: self.ack_unknown() def padl_inquiry_request_handler(self): try: padl.inquiry(self) except: self.ack_unknown() def padl_payment_request_handler(self): try: padl.payment(self) except: self.ack_unknown() # Override def bphtb_reversal_request_handler(self): try: bphtb.reversal(self) except: self.ack_unknown() # Override def padl_reversal_request_handler(self): try: padl.reversal(self) except: self.ack_unknown() def ack_invalid_length(self): msg = ERR_INVALID_LENGTH.format(id=self.invoice_id_raw) self.ack(RC_INVALID_NUMBER, msg) # Override def ack_already_paid(self): msg = ERR_ALREADY_PAID.format( invoice_id=self.from_iso.get_invoice_id()) self.ack(RC_ALREADY_PAID, msg) # Override def ack_not_available(self): msg = ERR_NOT_AVAILABLE.format( invoice_id=self.from_iso.get_invoice_id()) self.ack(RC_NOT_AVAILABLE, msg)
class CalculateInvoice(Invoice): def __init__(self, models, DBSession, invoice_id, persen_denda): Invoice.__init__(self, models, DBSession, invoice_id) if not self.invoice: return self.persen_denda = persen_denda self.nop = FixLength(NOP) self.nop.from_dict({ 'Propinsi': self.invoice.kd_propinsi, 'Kabupaten': self.invoice.kd_dati2, 'Kecamatan': self.invoice.kd_kecamatan, 'Kelurahan': self.invoice.kd_kelurahan, 'Blok': self.invoice.kd_blok, 'Urut': self.invoice.no_urut, 'Jenis': self.invoice.kd_jns_op, }) self.hitung() self.paid = self.is_paid() or self.total < 1 if self.paid: self.payment = self.get_payment() def hitung(self): self.tagihan = round_up(self.invoice.bphtb_harus_dibayarkan) bln, self.denda = hitung_denda(self.tagihan, self.invoice.tgl_jatuh_tempo.date(), self.persen_denda) self.denda = round_up(self.denda) self.total = self.tagihan + self.denda def get_iso_payment(self): if not self.invoice or not self.paid or not self.payment: return return Query.get_iso_payment(self, self.payment) def get_nop(self): return self.invoice and self.nop.get_raw() or '' def get_customer(self): q = self.DBSession.query(self.models.Customer).filter_by( id=self.invoice.ppat_id) return q.first() def get_kecamatan(self): q = self.DBSession.query(self.models.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 = self.DBSession.query(self.models.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() def get_pay_seq(self): q = self.DBSession.query(self.models.Payment).filter_by( sspd_id=self.invoice.id) pay = q.first() if pay: return pay.pembayaran_ke + 1 return 1 def set_paid(self): self.invoice.status_pembayaran = 1 self.DBSession.add(self.invoice)
class InquiryResponse(BaseResponse): def __init__(self, parent): BaseResponse.__init__(self, parent) self.invoice_profile = FixLength(INVOICE_PROFILE) self.invoice_profile.from_dict({ 'Invoice ID': self.invoice_id_raw, 'Alamat Objek Pajak': nama_kelurahan(self.invoice_id), 'Kecamatan': nama_kecamatan(self.invoice_id), }) try: int(self.invoice_id_raw) except ValueError: self.calc = None return self.calc = CalculateInvoice(models, DBSession, persen_denda, self.invoice_id['Propinsi'], self.invoice_id['Kabupaten'], self.invoice_id['Kecamatan'], self.invoice_id['Kelurahan'], self.invoice_id['Blok'], self.invoice_id['Urut'], self.invoice_id['Jenis'], self.invoice_id['Tahun Pajak']) def set_invoice_profile(self): self.parent.set_amount(self.calc.total) self.set_invoice_profile_to_parent() def set_invoice_profile_to_parent(self): if self.calc.invoice: self.invoice_profile.from_dict({ 'Nama Wajib Pajak': self.calc.invoice.nm_wp_sppt, 'Tagihan Pokok': self.calc.tagihan, 'Denda': self.calc.denda, 'Total Tagihan': self.calc.total}) self.parent.set_invoice_profile(self.invoice_profile.get_raw()) def is_valid(self, is_need_invoice_profile=True): if not self.calc: return self.parent.ack_invalid_number() if not self.calc.invoice: is_need_invoice_profile and self.set_invoice_profile_to_parent() return self.parent.ack_not_available() is_need_invoice_profile and self.set_invoice_profile() if self.calc.paid: return self.parent.ack_already_paid() if self.calc.total <= 0: return self.parent.ack_already_paid_2(self.calc.total) return True def ack_already_paid(self): pay = self.calc.invoice2payment() ntp = '' if pay and self.is_transaction_owner(pay): calc = self.calc q = DBSession.query(models.Payment).filter_by( propinsi=calc.propinsi, kabupaten=calc.kabupaten, kecamatan=calc.kecamatan, kelurahan=calc.kelurahan, blok=calc.blok, urut=calc.urut, jenis=calc.jenis, tahun=calc.tahun).order_by( models.Payment.ke.desc()) iso_pay = q.first() if iso_pay: ntp = iso_pay.id self.set_ntp(ntp) return self.parent.ack_already_paid() def set_ntp(self, ntp): self.invoice_profile.from_dict({'NTP': ntp}) def response(self): if not self.is_valid(): return self.parent.set_amount(0) self.parent.set_amount(self.calc.total) query.create_inquiry(self.calc, self.parent.from_iso, persen_denda) self.commit()
class Inquiry(BaseResponse): def __init__(self, parent): BaseResponse.__init__(self, parent) self.calc = CalculateInvoice(models, DBSession, self.invoice_id_raw) def init_invoice_profile(self): self.invoice_profile = FixLength(INVOICE_PROFILE) self.invoice_profile.from_dict({ 'kode pajak': 'BPHTB', 'nama pajak': 'BEA PEROLEHAN HAK ATAS TANAH DAN BANGUNAN', }) def set_invoice_profile(self): invoice = self.calc.invoice self.invoice_profile.from_dict({ 'npwpd': invoice.npwp_wp, 'nama': invoice.nama_wp, 'alamat': invoice.alamat_wp, 'tagihan': self.calc.tagihan, 'jumlah': self.calc.tagihan, 'jenis perolehan': invoice.kd_bphtb, 'nilai perolehan': invoice.npop_omset, 'rt wp': invoice.rt_wp, 'rw wp': invoice.rw_wp, 'kelurahan wp': invoice.kelurahan_wp, 'kecamatan wp': invoice.kecamatan_wp, 'kota wp': invoice.kota_wp, 'tahun pajak': invoice.tahun, #'nik': invoice.wp_identitas, 'luas tanah': invoice.luas_bumi, 'luas bangunan': invoice.luas_bng, 'alamat op': invoice.alamat_op, }) self.set_jatuh_tempo() self.set_kode_pos_wp() self.set_kecamatan_op() self.set_kelurahan_op() self.set_notaris() self.set_invoice_profile_to_parent() def is_valid(self, is_need_invoice_profile=True): if not self.calc.invoice: is_need_invoice_profile and self.set_invoice_profile_to_parent() if self.calc.invoice is False: return self.parent.ack_invalid_number() return self.parent.ack_not_available() is_need_invoice_profile and self.set_invoice_profile() if self.calc.paid: return self.ack_already_paid() if self.calc.tagihan <= 0: return self.parent.ack_already_paid_2(self.calc.tagihan) return True def response(self): if not self.is_allowed(): return self.init_invoice_profile() if not self.is_valid(): return self.parent.set_amount(0) self.parent.set_amount(self.calc.tagihan) self.save() def set_jatuh_tempo(self): if self.calc.invoice.jatuh_tempo: self.set_invoice_profile_( 'jatuh tempo', self.calc.invoice.jatuh_tempo.strftime('%d%m%Y')) def set_kode_pos_wp(self): kode_pos = self.calc.invoice.kodepos_wp.strip() self.set_invoice_profile_('kode pos wp', kode_pos) def set_kecamatan_op(self): if self.calc.invoice.kecamatan_op: self.set_invoice_profile_('kecamatan op', self.calc.invoice.kecamatan_op) def set_kelurahan_op(self): if self.calc.invoice.kelurahan_op: self.set_invoice_profile_('kelurahan op', self.calc.invoice.kelurahan_op) def set_notaris(self): if self.calc.invoice.nm_notaris: self.set_invoice_profile_('notaris', self.calc.invoice.nm_notaris) def set_invoice_profile_(self, key, value): if value: self.invoice_profile.from_dict({key: value}) def set_invoice_profile_to_parent(self): self.parent.set_invoice_profile(self.invoice_profile.get_raw()) def ack_already_paid(self): iso_pay = self.calc.get_iso_payment() ntp = '' if iso_pay: pay = query.get_payment_from_iso(iso_pay) if pay.bank_id == self.parent.conf['id']: ntp = pay.ntp self.parent.set_ntp(ntp) return self.parent.ack_already_paid() def save(self): inq = models.IsoInquiry() inq.tgl = datetime.now() inq.invoice_id = self.calc.invoice.id inq.bank_id = self.parent.conf['id'] inq.channel_id = self.parent.from_iso.get_channel() inq.stan = self.parent.from_iso.get_stan() inq.transmission = self.parent.from_iso.get_transmission() inq.settlement = self.parent.from_iso.get_settlement() DBSession.add(inq) DBSession.flush() self.commit()
class InquiryResponse(BaseResponse): def __init__(self, parent): BaseResponse.__init__(self, parent) self.parent = parent self.calc = CalculateInvoice(models, DBSession, parent.from_iso.get_invoice_id(), persen_denda) module_conf = host[self.parent.conf['name']] self.parent.conf.update(module_conf) def init_invoice_profile(self): self.invoice_profile = FixLength(INVOICE_PROFILE) self.invoice_profile.from_dict({ 'kode pajak': 'PADL', 'nama pajak': 'PENDAPATAN ASLI DAERAH LAINNYA', }) def set_invoice_profile(self): invoice = self.calc.invoice op = self.calc.get_op() kel = self.calc.get_kelurahan(op.kelurahan_id) kec = self.calc.get_kecamatan(kel.kecamatan_id) wp = self.calc.get_wp(op) nama = self.get_nama_wp(op, wp) self.invoice_profile.from_dict({ 'npwpd': wp.npwpd, 'nama': nama, 'alamat': wp.alamat, 'tagihan': self.calc.tagihan, 'denda': self.calc.denda, 'jumlah': self.calc.total, 'alamat op': op.opalamat, 'kelurahan op': kel.kelurahannm, 'kecamatan op': kec.kecamatannm, 'kode pos wp': wp.wpkodepos, }) self.set_jatuh_tempo() self.set_invoice_profile_to_parent() def get_nama_wp(self, op, wp): nama_ = [] if op.opnm: nama_.append(op.opnm) nama = self.calc.invoice.r_nama or wp.customernm if nama: nama_.append(nama) return ','.join(nama_) def is_valid(self, is_need_invoice_profile=True): if not self.calc.invoice: is_need_invoice_profile and self.set_invoice_profile_to_parent() return self.parent.ack_not_available() is_need_invoice_profile and self.set_invoice_profile() if self.calc.paid: return self.ack_already_paid() if self.calc.total <= 0: return self.parent.ack_already_paid_2(self.calc.total) return True def response(self): self.init_invoice_profile() if not self.is_valid(): return self.parent.set_amount(0) self.parent.set_amount(self.calc.total) self.parent.ack() def set_jatuh_tempo(self): if self.calc.invoice.jatuhtempotgl: self.set_invoice_profile_( 'jatuh tempo', self.calc.invoice.jatuhtempotgl.strftime('%d%m%Y')) def set_invoice_profile_(self, key, value): if value: self.invoice_profile.from_dict({key: value}) def set_invoice_profile_to_parent(self): self.parent.set_invoice_profile(self.invoice_profile.get_raw()) def ack_already_paid(self): iso_pay = self.calc.get_iso_payment() if iso_pay and iso_pay.bank_id == self.parent.conf['id']: ntp = iso_pay.ntp else: ntp = '' self.parent.set_ntp(ntp) return self.parent.ack_already_paid()
class InquiryResponse(BaseResponse): def __init__(self, parent): BaseResponse.__init__(self, parent) self.parent = parent self.calc = CalculateInvoice( models, DBSession, parent.from_iso.get_invoice_id(), persen_denda) module_conf = host[self.parent.conf['name']] self.parent.conf.update(module_conf) def init_invoice_profile(self): self.invoice_profile = FixLength(INVOICE_PROFILE) def set_invoice_profile(self): invoice = self.calc.invoice self.invoice_profile.from_dict({ 'Kode': invoice.kode, 'Nama Penyetor': invoice.objek_nama, 'Alamat 1': invoice.objek_alamat_1, 'Alamat 2': invoice.objek_alamat_2, 'Tagihan': self.calc.tagihan, 'Denda': self.calc.denda, 'Total': self.calc.total, 'Kode Rekening': invoice.rekening_kode, 'Nama Rekening': invoice.rekening_nama, 'Kode SKPD': invoice.departemen_kode, 'Nama SKPD': invoice.departemen_nama, 'Additional 1': pesan1, 'Additional 2': pesan2,}) self.set_invoice_profile_to_parent() print_debug('Invoice Profile', self.invoice_profile.to_dict()) def is_valid(self, is_need_invoice_profile=True): if not self.calc.invoice: is_need_invoice_profile and self.set_invoice_profile_to_parent() return self.parent.ack_not_available() is_need_invoice_profile and self.set_invoice_profile() if self.calc.paid: return self.ack_already_paid() if self.calc.total <= 0: return self.parent.ack_already_paid_2(self.calc.total) return True def response(self): self.init_invoice_profile() if not self.is_valid(): return self.parent.set_amount(0) self.parent.set_amount(self.calc.total) self.parent.ack() def set_invoice_profile_(self, key, value): if value: self.invoice_profile.from_dict({key: value}) def set_invoice_profile_to_parent(self): self.parent.set_invoice_profile(self.invoice_profile.get_raw()) def ack_already_paid(self): pay = self.calc.get_payment() if pay and pay.bank_id == self.parent.conf['id']: ntp = pay.kode else: ntp = '' self.parent.set_ntp(ntp) return self.parent.ack_already_paid()
class Transaction(BaseTransaction): def __init__(self, *args, **kwargs): BaseTransaction.__init__(self, *args, **kwargs) self.invoice_profile = FixLength(INVOICE_PROFILE) self.invoice_profile2 = FixLength(INVOICE_PROFILE2) # Override def get_inquiry_code(self): return INQUIRY_CODE # Override def get_payment_code(self): return PAYMENT_CODE # Override def get_bit_definition(self): return TRANSACTION_BITS def set_transaction_response(self): BaseTransaction.set_transaction_response(self) self.copy([49, 58, 59, 60, 62, 63, 102, 107]) self.setBit(47, '') self.setBit(48, '') self.setBit(61, '') def get_nop(self): return self.get_value(61).strip() def set_nop(self, nop): return self.setBit(61, nop) def get_invoice_id(self): return self.get_value(62).strip() def set_invoice_profile(self): raw = self.invoice_profile.get_raw() self.setBit(47, raw) raw = self.invoice_profile2.get_raw() self.setBit(48, raw) def set_ntp(self, ntp): self.setBit(57, ntp) # Nomor Transaksi Bank def set_ntb(self, ntb): self.setBit(58, ntb) def get_ntb(self): return self.get_value(58) def get_bank_ip(self): if 'ip' in self.conf: return self.conf['ip'] def ack_invalid_max_length(self, max_length): msg = ERR_INVALID_MAX_LENGTH.format(invoice_id=self.invoice_id_raw, max_length=max_length) self.ack(RC_INVALID_NUMBER, msg) def ack_invalid_length(self, length): msg = ERR_INVALID_LENGTH.format(invoice_id=self.get_invoice_id(), length=length, orig_length=len(self.invoice_id_raw)) self.ack(RC_INVALID_NUMBER, msg) def ack_invalid_prefix(self, prefix): msg = ERR_INVALID_PREFIX.format(invoice_id=self.get_invoice_id(), prefix=prefix) self.ack(RC_INVALID_NUMBER, msg) def ack_invalid_nop(self, nop): msg = ERR_INVALID_NOP.format(invoice_id=self.get_invoice_id(), nop=nop, invalid_nop=self.from_iso.get_nop()) self.ack(RC_NOT_AVAILABLE, msg)
class Transaction(BaseTransaction): def __init__(self, *args, **kwargs): BaseTransaction.__init__(self, *args, **kwargs) self.invoice_profile = FixLength(INVOICE_PROFILE) self.invoice_profile2 = FixLength(INVOICE_PROFILE2) # Override def get_inquiry_code(self): return INQUIRY_CODE # Override def get_payment_code(self): return PAYMENT_CODE # Override def get_bit_definition(self): return TRANSACTION_BITS def set_transaction_response(self): BaseTransaction.set_transaction_response(self) self.copy([49, 58, 59, 60, 62, 63, 102, 107]) self.setBit(47, '') self.setBit(48, '') self.setBit(61, '') def get_nop(self): return self.get_value(61).strip() def set_nop(self, nop): return self.setBit(61, nop) def get_invoice_id(self): return self.get_value(62).strip() def set_invoice_profile(self): raw = self.invoice_profile.get_raw() self.setBit(47, raw) raw = self.invoice_profile2.get_raw() self.setBit(48, raw) def set_ntp(self, ntp): self.setBit(57, ntp) # Nomor Transaksi Bank def set_ntb(self, ntb): self.setBit(58, ntb) def get_ntb(self): return self.get_value(58) def get_bank_ip(self): if 'ip' in self.conf: return self.conf['ip'] def ack_invalid_max_length(self, max_length): msg = ERR_INVALID_MAX_LENGTH.format( invoice_id=self.invoice_id_raw, max_length=max_length) self.ack(RC_INVALID_NUMBER, msg) def ack_invalid_length(self, length): msg = ERR_INVALID_LENGTH.format( invoice_id=self.get_invoice_id(), length=length, orig_length=len(self.invoice_id_raw)) self.ack(RC_INVALID_NUMBER, msg) def ack_invalid_prefix(self, prefix): msg = ERR_INVALID_PREFIX.format( invoice_id=self.get_invoice_id(), prefix=prefix) self.ack(RC_INVALID_NUMBER, msg) def ack_invalid_nop(self, nop): msg = ERR_INVALID_NOP.format( invoice_id=self.get_invoice_id(), nop=nop, invalid_nop=self.from_iso.get_nop()) self.ack(RC_NOT_AVAILABLE, msg)
class Transaction(BaseTransaction): def __init__(self, *args, **kwargs): BaseTransaction.__init__(self, *args, **kwargs) self.invoice_profile = FixLength(INVOICE_PROFILE) # Override def get_bit_definition(self): return TRANSACTION_BITS # Override def set_response(self): if self.from_iso.is_network_request(): Network.set_response(self) if self.from_iso.is_payment_request(): self.set_payment_response() elif self.from_iso.is_transaction_request(): self.set_transaction_response() elif self.from_iso.is_reversal_request(): self.set_reversal_response() def get_payment_codes(self): return PAYMENT_CODES def get_methods(self): return METHODS def get_invoice_id(self): return self.get_value(61).strip() def is_inquiry_request(self): return self.is_transaction_request() and \ self.get_transaction_code() == INQUIRY_CODE and \ 'inquiry_request_handler' def is_inquiry_response(self): return self.is_transaction_response() and \ self.get_transaction_code() == INQUIRY_CODE def is_payment_request(self): return self.is_transaction_request() and \ self.get_transaction_code() == PAYMENT_CODE and \ 'payment_request_handler' def is_payment_response(self): return self.is_transaction_response() and \ self.get_transaction_code() == PAYMENT_CODE def set_transaction_response(self): BaseTransaction.set_transaction_response(self) self.copy( [2, 3, 7, 11, 12, 13, 15, 18, 22, 32, 33, 35, 37, 41, 43, 49, 61, 62]) def set_payment_response(self): self.set_transaction_response() self.copy([4, 48, 62]) self.set_ntp('') def set_invoice_profile(self): raw = self.invoice_profile.get_raw() self.setBit(62, raw.upper()) def get_ntb(self): return self.get_value(48) def set_ntb(self, v): self.setBit(48, v) def set_ntp(self, v): self.setBit(47, v) def set_amount(self, value): self.setBit(4, value) def get_amount(self): return int(self.get_value(4)) def get_channel_id(self): return self.get_value(18) def get_bank_ip(self): return self.conf['ip'] ############ # Reversal # ############ def is_reversal_request(self): return BaseTransaction.is_reversal_request(self) and \ self.get_transaction_code() == PAYMENT_CODE and \ 'reversal_request_handler' ################### # Acknowledgement # ################### def ack_invalid_number(self): msg = ERR_INVALID_NUMBER.format( invoice_id=self.from_iso.get_invoice_id()) self.ack(RC_INVALID_NUMBER, msg) def ack_not_available(self): msg = ERR_NOT_AVAILABLE.format( invoice_id=self.from_iso.get_invoice_id()) self.ack(RC_NOT_AVAILABLE, msg) def ack_already_paid(self): msg = ERR_ALREADY_PAID.format( invoice_id=self.from_iso.get_invoice_id()) self.ack(RC_ALREADY_PAID, msg) def ack_insufficient_fund(self, total_tagihan): msg = ERR_INSUFFICIENT_FUND.format( invoice_id=self.from_iso.get_invoice_id(), bayar=self.from_iso.get_amount(), tagihan=total_tagihan) self.ack(RC_INSUFFICIENT_FUND, msg) def ack_payment_not_found(self): self.ack(RC_NOT_AVAILABLE, ERR_PAYMENT.format( invoice_id=self.get_invoice_id())) def ack_iso_payment_not_found(self): self.ack(RC_NOT_AVAILABLE, ERR_ISO_PAYMENT.format( invoice_id=self.get_invoice_id())) def ack_payment_owner(self): msg = ERR_PAYMENT_OWNER.format(invoice_id=self.get_invoice_id()) self.ack(RC_NOT_AVAILABLE, msg) def ack_invoice_open(self): msg = ERR_INVOICE_OPEN.format(invoice_id=self.get_invoice_id()) self.ack(RC_ALREADY_PAID, msg) def ack_payment_owner(self): msg = ERR_PAYMENT_OWNER.format(invoice_id=self.get_invoice_id()) self.ack(RC_NOT_AVAILABLE, msg) def ack_ntb(self): msg = ERR_NTB.format( ntb=self.get_ntb(), invoice_id=self.get_invoice_id())
class InquiryResponse(BaseResponse): def __init__(self, parent): BaseResponse.__init__(self, parent) self.parent = parent self.calc = CalculateInvoice(models, DBSession, parent.from_iso.get_invoice_id(), persen_denda) module_conf = host[self.parent.conf['name']] self.parent.conf.update(module_conf) def init_invoice_profile(self): self.invoice_profile = FixLength(INVOICE_PROFILE) def set_invoice_profile(self): invoice = self.calc.invoice self.invoice_profile.from_dict({ 'Kode': invoice.kode, 'Nama Penyetor': invoice.objek_nama, 'Alamat 1': invoice.objek_alamat_1, 'Alamat 2': invoice.objek_alamat_2, 'Tagihan': self.calc.tagihan, 'Denda': self.calc.denda, 'Total': self.calc.total, 'Kode Rekening': invoice.rekening_kode, 'Nama Rekening': invoice.rekening_nama, 'Kode SKPD': invoice.departemen_kode, 'Nama SKPD': invoice.departemen_nama, 'Additional 1': pesan1, 'Additional 2': pesan2, }) self.set_invoice_profile_to_parent() print_debug('Invoice Profile', self.invoice_profile.to_dict()) def is_valid(self, is_need_invoice_profile=True): if not self.calc.invoice: is_need_invoice_profile and self.set_invoice_profile_to_parent() return self.parent.ack_not_available() is_need_invoice_profile and self.set_invoice_profile() if self.calc.paid: return self.ack_already_paid() if self.calc.total <= 0: return self.parent.ack_already_paid_2(self.calc.total) return True def response(self): self.init_invoice_profile() if not self.is_valid(): return self.parent.set_amount(0) self.parent.set_amount(self.calc.total) self.parent.ack() def set_invoice_profile_(self, key, value): if value: self.invoice_profile.from_dict({key: value}) def set_invoice_profile_to_parent(self): self.parent.set_invoice_profile(self.invoice_profile.get_raw()) def ack_already_paid(self): pay = self.calc.get_payment() if pay and pay.bank_id == self.parent.conf['id']: ntp = pay.kode else: ntp = '' self.parent.set_ntp(ntp) return self.parent.ack_already_paid()