chart_detail.py
4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import sys
import re
import logging
import os
import qrcode
import base64
from email.utils import parseaddr
from sqlalchemy import not_, func, or_, desc
from datetime import datetime
from time import gmtime, strftime, strptime
from pyramid.view import (
view_config,
)
from pyramid.httpexceptions import (
HTTPFound,
)
import colander
from deform import (
Form,
widget,
ValidationFailure,
)
from ..tools import (
_DTnumberformat,
multi_dict_values,
odt_export,
terbilang,
thousand,
dmy,
BULANS,
get_settings
)
from ..models import DBSession
from ..models.isipkd import(
Pegawai, ObjekPajak, SubjekPajak, ARInvoice,
Unit, UserUnit,Wilayah, Pajak, Rekening,
ARSts, ARStsItem, ARSspd, ARTbp
)
from datatables import (
ColumnDT, DataTables)
from ..security import group_finder,group_in
from daftar import (STATUS, deferred_status,
daftar_subjekpajak, deferred_subjekpajak,
daftar_objekpajak, deferred_objekpajak,
daftar_wilayah, deferred_wilayah,
daftar_unit, deferred_unit,
daftar_pajak, deferred_pajak,
auto_op_nm, auto_unit_nm, auto_wp_nm, auto_wp_nm3
)
SESS_ADD_FAILED = 'Gagal tambah Tagihan'
SESS_EDIT_FAILED = 'Gagal edit Tagihan'
log = logging.getLogger(__name__)
@view_config(route_name='chart-det', renderer='templates/chart_det.pt')
def view_detail(request):
params = request.params
url_dict = request.matchdict
kd = ''
unit = ''
if 'kode' in params and params['kode']:
rekening = Rekening.query().filter(func.trim(Rekening.kode)==params['kode'].strip()).first()
level = rekening.level_id
kd = rekening.kode.strip()
unit = rekening.nama.strip()
rek = Rekening.query().filter(Rekening.level_id==(level+1), Rekening.kode.ilike(params['kode']+'%')).order_by(Rekening.kode).all()
else:
rek = Rekening.query().filter(Rekening.level_id==2).order_by(Rekening.kode).all()
reks = []
for r in rek:
reks.append(dict(
kode=r.kode.strip(),
nama=r.nama.strip(),
target=[0,0,0,0,0,0,0,0,0,0,0,0],
realisasi=[0,0,0,0,0,0,0,0,0,0,0,0],
persen=[0,0,0,0,0,0,0,0,0,0,0,0]
))
payments = DBSession.query(
ARSspd.tgl_bayar.label('tanggal'),
ARSspd.bayar.label('jumlah'),
ARInvoice.rek_kode.label('rek_kode'),
Unit.kode.label('kode'),
Unit.nama.label('nama'),
).join(ARInvoice, ARInvoice.id == ARSspd.arinvoice_id).\
join(Unit, func.trim(Unit.kode) == func.trim(ARInvoice.unit_kode)).\
filter(ARSspd.tahun_id==params['year']).order_by(ARInvoice.unit_kode)\
.all()
for p in payments:
for re in reks:
if p.rek_kode.strip().startswith(re['kode']):
## chart realisasi
for x in range(12):
if p.tanggal.month == x+1:
re['realisasi'][x] += int(p.jumlah)
invoices = DBSession.query(
ARInvoice.tgl_tetap.label('tanggal'),
ARInvoice.jumlah.label('jumlah'),
ARInvoice.rek_kode.label('rek_kode'),
Unit.kode.label('kode'),
Unit.nama.label('nama'),
).join(Unit, func.trim(Unit.kode) == func.trim(ARInvoice.unit_kode)).\
filter(ARInvoice.tahun_id==params['year']).order_by(ARInvoice.unit_kode)\
.all()
for i in invoices:
for re in reks:
if i.rek_kode.strip().startswith(re['kode']):
## chart target
for x in range(12):
if i.tanggal.month == x+1:
re['target'][x] += int(p.jumlah)
##Hitung persen
for re in reks:
for x in range(12):
re['persen'][x] = re['target'][x]>0 and str(round((float(re['realisasi'][x])/float(re['target'][x]))*100,2)) or '0'
##hanya yang isi saja yang diambil
#re_ = []
#for re in reks:
# if sum(re['target'])>0 and sum(re['realisasi'])>0:
# re_.append(re)
#
#if len(re_)==0:
# raise HTTPFound(location=request.route_url('home'))
#data = re_
#count_unit = len(re_) > 3 and 3 or 4
if len(reks)==0:
raise HTTPFound(location=request.route_url('home'))
data = reks
count_unit = len(reks) > 3 and 3 or 4
return dict(data=data, count_unit=count_unit, kd=kd, unit=unit)