Add method to retrieve daily PBB data and update related calls

1 parent e0efc019
...@@ -155,6 +155,49 @@ class Views(BaseView): ...@@ -155,6 +155,49 @@ class Views(BaseView):
"monthtrAccTrx": [("JAN", 100), ("FEB", 200), ("MAR", 300), ("APR", 200), ("MAY", 100), ("JUN", 100), ("JUL", 700)], "monthtrAccTrx": [("JAN", 100), ("FEB", 200), ("MAR", 300), ("APR", 200), ("MAY", 100), ("JUN", 100), ("JUL", 700)],
} }
def get_daily_data_pbb(self, table, field, today, filters, typ=None):
# todo ada kemungkinan menyebabkan error ke transaksi yang lain
if type(filters) is not list:
filters = [filters]
if PCDBSession.registry().in_transaction():
PCDBSession.rollback()
columns = [field.label("step")]
qry = table.qry_sum(columns) \
.group_by(field)\
.order_by(field)
qry = qry.filter(*filters)
if typ != None:
if typ == "pajak":
qry = qry.filter(table.jenis_pajak.notin_(PAD_TYP['pbb']))
else:
qry = qry.filter(table.jenis_pajak.in_(PAD_TYP[typ]))
daily = []
dailyTrx = []
dailyAcc = []
dailyAccTrx = []
amt = trx = acc = accTrx = 0
for r in qry:
mapped = r._mapping
step = mapped.get("step", "")
pokok = mapped.get("bayar", 0)
denda = mapped.get("denda", 0)
bayar = pokok + denda
tx = mapped.get("trx", 0)
daily.append((step, pokok))
dailyTrx.append((step, tx))
acc += pokok
accTrx += tx
dailyAcc.append((step, acc))
dailyAccTrx.append((step, accTrx))
if step == today:
amt = pokok
trx = tx
return amt, trx, daily, dailyTrx, dailyAcc, dailyAccTrx
def get_daily_data(self, table, field, today, filters, typ=None): def get_daily_data(self, table, field, today, filters, typ=None):
# todo ada kemungkinan menyebabkan error ke transaksi yang lain # todo ada kemungkinan menyebabkan error ke transaksi yang lain
if type(filters) is not list: if type(filters) is not list:
...@@ -227,7 +270,7 @@ class Views(BaseView): ...@@ -227,7 +270,7 @@ class Views(BaseView):
today-timedelta(days=6), today) today-timedelta(days=6), today)
amt, trx, daily, dailyTrx, dailyAcc, dailyAccTrx = \ amt, trx, daily, dailyTrx, dailyAcc, dailyAccTrx = \
self.get_daily_data(PembayaranSppt, field, self.get_daily_data_pbb(PembayaranSppt, field,
today.strftime("%Y-%m-%d"), filter_exp) today.strftime("%Y-%m-%d"), filter_exp)
# Total Setahun # Total Setahun
...@@ -235,14 +278,14 @@ class Views(BaseView): ...@@ -235,14 +278,14 @@ class Views(BaseView):
filter_exp = PembayaranSppt.tgl_pembayaran_sppt.between( filter_exp = PembayaranSppt.tgl_pembayaran_sppt.between(
datetime.strptime(f"{today.year}-01-01", "%Y-%m-%d"), today) datetime.strptime(f"{today.year}-01-01", "%Y-%m-%d"), today)
ytd, ytdTrx, yearly, yearlyTrx, yearlyAcc, yearlyAccTrx = \ ytd, ytdTrx, yearly, yearlyTrx, yearlyAcc, yearlyAccTrx = \
self.get_daily_data(PembayaranSppt, field, self.get_daily_data_pbb(PembayaranSppt, field,
str(today.year), filter_exp) str(today.year), filter_exp)
# Piutang # Piutang
filter_exp = [PembayaranSppt.tgl_pembayaran_sppt.between( filter_exp = [PembayaranSppt.tgl_pembayaran_sppt.between(
datetime.strptime(f"{today.year}-01-01", "%Y-%m-%d"), today), datetime.strptime(f"{today.year}-01-01", "%Y-%m-%d"), today),
PembayaranSppt.thn_pajak_sppt < today.year] PembayaranSppt.thn_pajak_sppt < today.year]
piutang, piutangTrx, yearly, yearlyTrx, yearlyAcc, yearlyAccTrx = \ piutang, piutangTrx, yearly, yearlyTrx, yearlyAcc, yearlyAccTrx = \
self.get_daily_data(PembayaranSppt, field, self.get_daily_data_pbb(PembayaranSppt, field,
str(today.year), filter_exp) str(today.year), filter_exp)
# Bulanan # Bulanan
...@@ -255,7 +298,7 @@ class Views(BaseView): ...@@ -255,7 +298,7 @@ class Views(BaseView):
filter_exp = PembayaranSppt.tgl_pembayaran_sppt.between( filter_exp = PembayaranSppt.tgl_pembayaran_sppt.between(
today-timedelta(weeks=6), today) today-timedelta(weeks=6), today)
week, weekTrx, weekly, weeklyTrx, weeklyAcc, weeklyAccTrx = \ week, weekTrx, weekly, weeklyTrx, weeklyAcc, weeklyAccTrx = \
self.get_daily_data(PembayaranSppt, field, None, filter_exp) self.get_daily_data_pbb(PembayaranSppt, field, None, filter_exp)
try: try:
ytd_target = self.get_targets("pbb") ytd_target = self.get_targets("pbb")
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!