Commit 27b9b916 by taufikyu

tambahkan laporan csv

1 parent 596ba0e8
......@@ -9,6 +9,7 @@ import locale
import pytz
import io
import random
import sys
from string import ascii_uppercase,ascii_lowercase,digits
from email.utils import parseaddr
......@@ -553,3 +554,19 @@ def multi_dict_values(md):
d[key] = value
return d
def csv_response(request, value, filename):
response = request.response
response.content_type = 'text/csv'
# response.content_disposition = 'attachment;filename=' + filename
response.content_disposition = 'filename=' + filename
if sys.version_info < (3,):
import StringIO
fout = StringIO.StringIO()
else:
fout = io.StringIO()
fcsv = csv.writer(fout, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
fcsv.writerow(value.get('header', []))
fcsv.writerows(value.get('rows', []))
response.write(fout.getvalue())
return response
......@@ -7,6 +7,8 @@ from pyramid.view import view_config
from pyramid.httpexceptions import (HTTPFound, HTTPForbidden, HTTPNotFound)
from pyramid.security import (remember, forget, authenticated_userid,)
from deform import (Form, ValidationFailure, widget,)
from ..tools import dmy, date_from_str
from sqlalchemy import func
from ..models import (DBSession, User,)
from ..models.isipkd import(
......@@ -41,13 +43,22 @@ from pyramid.view import notfound_view_config
########
@view_config(route_name='home', renderer='templates/home.pt')
def view_home(request):
now = date.today()
if 'date' in request.params and request.params['date']:
request.session['date'] = request.params['date'].strip()
if 'date' in request.session and request.session['date']:
now = date_from_str(request.session['date'])
else:
now = date.today()
request.session['date'] = dmy(now)
if 'unit' in request.params:
request.session['unit'] = request.params['unit'].strip()
dates = dict(
year = now.year,
month = now.month,
week = int(now.strftime('%W')),
day = now,
)
opd_ls = Unit.query().order_by(Unit.kode).all()
data_dashboard = dict(
tabular = dict(
tahun = dict(q=0,n=0),
......@@ -60,6 +71,7 @@ def view_home(request):
n = [0,0,0,0,0,0,0,0,0,0,0,0],
),
opd= [],
sopd10= [],
sopd= [],
)
payments = DBSession.query(
......@@ -68,38 +80,71 @@ def view_home(request):
Unit.kode.label('kode'),
Unit.nama.label('nama'),
).join(ARInvoice, ARInvoice.id == ARSspd.arinvoice_id).\
join(Unit, Unit.kode == ARInvoice.unit_kode).\
filter(ARSspd.tahun_id==dates['year']).order_by(ARInvoice.unit_kode).all()
join(Unit, func.trim(Unit.kode) == func.trim(ARInvoice.unit_kode)).\
filter(ARSspd.tahun_id==dates['year']).order_by(ARInvoice.unit_kode)
payments = payments.all()
for p in payments:
if 'unit' in request.session and request.session['unit']:
if p.kode.strip().startswith(request.session['unit']):
data_dashboard['tabular']['tahun']['q'] += 1
data_dashboard['tabular']['tahun']['n'] += int(p.jumlah)
if p.tanggal.month == dates['month']:
data_dashboard['tabular']['bulan']['q'] += 1
data_dashboard['tabular']['bulan']['n'] += int(p.jumlah)
if int(p.tanggal.strftime('%W')) == dates['week']:
data_dashboard['tabular']['minggu']['q'] += 1
data_dashboard['tabular']['minggu']['n'] += int(p.jumlah)
if p.tanggal.date() == dates['day']:
data_dashboard['tabular']['hari']['q'] += 1
data_dashboard['tabular']['hari']['n'] += int(p.jumlah)
for x in range(12):
if p.tanggal.month == x+1:
data_dashboard['chart']['q'][x] += int(1)
data_dashboard['chart']['n'][x] += int(p.jumlah)
elif not 'unit' in request.session or not request.session['unit']:
data_dashboard['tabular']['tahun']['q'] += 1
data_dashboard['tabular']['tahun']['n'] += int(p.jumlah)
if p.tanggal.month == dates['month']:
data_dashboard['tabular']['bulan']['q'] += 1
data_dashboard['tabular']['bulan']['n'] += int(p.jumlah)
if int(p.tanggal.strftime('%W')) == dates['week']:
data_dashboard['tabular']['minggu']['q'] += 1
data_dashboard['tabular']['minggu']['n'] += int(p.jumlah)
if p.tanggal.date() == dates['day']:
data_dashboard['tabular']['hari']['q'] += 1
data_dashboard['tabular']['hari']['n'] += int(p.jumlah)
for x in range(12):
if p.tanggal.month == x+1:
data_dashboard['chart']['q'][x] += int(1)
data_dashboard['chart']['n'][x] += int(p.jumlah)
tanggal_berjalan = datetime.now()
tahun_berjalan = tanggal_berjalan.year
opd = DBSession.query(
ARSspd.tgl_bayar.label('tanggal'),
ARSspd.bayar.label('jumlah'),
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==tahun_berjalan).order_by(ARInvoice.unit_kode).all()
prev_opd = ''
i = -1
for p in payments:
data_dashboard['tabular']['tahun']['q'] += 1
data_dashboard['tabular']['tahun']['n'] += int(p.jumlah)
if p.tanggal.month == dates['month']:
data_dashboard['tabular']['bulan']['q'] += 1
data_dashboard['tabular']['bulan']['n'] += int(p.jumlah)
if int(p.tanggal.strftime('%W')) == dates['week']:
data_dashboard['tabular']['minggu']['q'] += 1
data_dashboard['tabular']['minggu']['n'] += int(p.jumlah)
if p.tanggal.date() == dates['day']:
data_dashboard['tabular']['hari']['q'] += 1
data_dashboard['tabular']['hari']['n'] += int(p.jumlah)
for x in range(12):
if p.tanggal.month == x+1:
data_dashboard['chart']['q'][x] += int(1)
data_dashboard['chart']['n'][x] += int(p.jumlah)
if prev_opd != p.kode:
for o in opd:
##OPD SESUAI TANGGAL
if prev_opd != o.kode:
i += 1
data_dashboard['opd'].append(dict(kode=p.kode.strip(),unit=p.nama.strip(),jumlah=0))
data_dashboard['opd'][i]['jumlah']+=int(p.jumlah)
prev_opd = p.kode
data_dashboard['opd'].append(dict(kode=o.kode.strip(),unit=o.nama.strip(),jumlah=0))
prev_opd = o.kode
data_dashboard['opd'][i]['jumlah']+=int(o.jumlah)
sort_opd = sorted(data_dashboard['opd'], key = lambda i: (i['jumlah']), reverse=True)
i = 0
i = -1
for sopd in sort_opd:
if i<10:
data_dashboard['sopd'].append(dict(peringkat=i+1, upd=sopd['unit'], nominal=sopd['jumlah']))
i+=1
return dict(project='esipkd', dates=dates, data = data_dashboard)
i += 1
if i < 10:
data_dashboard['sopd10'].append(dict(peringkat=i+1, kode=sopd['kode'], unit=sopd['unit'], nominal=sopd['jumlah']))
data_dashboard['sopd'].append(dict(peringkat=i+1, kode=sopd['kode'], unit=sopd['unit'], nominal=sopd['jumlah']))
return dict(project='esipkd', dates=dates, data = data_dashboard, opds=opd_ls)
#########
......
......@@ -15,7 +15,7 @@ from pyramid.httpexceptions import (
)
import colander
from esipkd.views.base_view import BaseViews
from esipkd.tools import thousand, dmy
from esipkd.tools import thousand, dmy, csv_response
from pyjasper import (JasperGenerator)
from pyjasper import (JasperGeneratorWithSubreport)
......@@ -260,7 +260,90 @@ class ViewLaporan(BaseViews):
akhir = 'akhir' in params and params['akhir'] and str(params['akhir']) or datetime.now().strftime('%Y-%m-%d')
##----------------------- Query laporan -------------------------------------##
if url_dict['act']=='Laporan_1' :
if url_dict['act'] == 'Laporan_98':
query = DBSession.query(
ARTbp.kode,
ARTbp.tahun_id,
ARTbp.unit_id,
ARTbp.unit_kode,
ARTbp.unit_nama,
ARTbp.no_id,
ARTbp.subjek_pajak_id,
ARTbp.wp_kode,
ARTbp.wp_nama,
ARTbp.wp_alamat_1,
ARTbp.wp_alamat_2,
ARTbp.rekening_id,
ARTbp.rek_kode,
ARTbp.rek_nama,
ARTbp.objek_pajak_id,
ARTbp.op_kode,
ARTbp.op_nama,
ARTbp.op_alamat_1,
ARTbp.op_alamat_2,
ARTbp.dasar,
ARTbp.tarif,
ARTbp.pokok,
ARTbp.terutang,
ARTbp.denda,
ARTbp.bunga,
ARTbp.jumlah,
ARTbp.periode_1,
ARTbp.periode_2,
ARTbp.tgl_terima,
ARTbp.jatuh_tempo,
ARTbp.wilayah_id,
ARTbp.status_invoice,
ARTbp.invoice_id,
ARTbp.invoice_kode
).order_by(ARTbp.create_date)
row = query.first()
if not row:
req.session.flash('Data tidak ditemukan.')
raise HTTPFound(location=request.route_url('report'))
header = ['kode','tahun_id','unit_id','unit_kode','unit_nama','no_id','subjek_pajak_id','wp_kode','wp_nama','wp_alamat_1','wp_alamat_2','rekening_id','rek_kode','rek_nama','objek_pajak_id','op_kode','op_nama','op_alamat_1','op_alamat_2','dasar','tarif','pokok','terutang','denda','bunga','jumlah','periode_1','periode_2','tgl_terima','jatuh_tempo','wilayah_id','status_invoice','invoice_id','invoice_kode']
rows = []
for item in query.all():
rows.append(list(item))
filename = 'E-Payment.csv'
value = {
'header': header,
'rows': rows,
}
return csv_response(req, value, filename)
elif url_dict['act'] == 'Laporan_99':
query = DBSession.query(
ARSspd.tahun_id,
ARSspd.unit_id,
ARSspd.arinvoice_id,
ARSspd.pembayaran_ke,
ARSspd.bunga,
ARSspd.bayar,
ARSspd.tgl_bayar,
ARSspd.create_date,
ARSspd.ntb,
ARSspd.ntp,
ARSspd.bank_id,
ARSspd.channel_id,
ARSspd.denda_rekening_id,
ARSspd.unit_kode,
ARSspd.unit_nama,
ARSspd.rekening_id,
ARSspd.rek_kode,
ARSspd.rek_nama
).order_by(ARSspd.tgl_bayar)
row = query.first()
header = ['tahun_id','unit_id','arinvoice_id','pembayaran_ke','bunga','bayar','tgl_bayar','create_date','ntb','ntp','bank_id','channel_id','denda_rekening_id','unit_kode','unit_nama','rekening_id','rek_kode','rek_nama']
rows = []
for item in query.all():
rows.append(list(item))
filename = 'Penerimaan.csv'
value = {
'header': header,
'rows': rows,
}
return csv_response(req, value, filename)
elif url_dict['act']=='Laporan_1' :
query = DBSession.query(ARInvoice.unit_id.label('un_id'),
ARInvoice.unit_kode.label('un_kd'),
ARInvoice.unit_nama.label('un_nm'),
......
......@@ -3,9 +3,15 @@
<style>
h4 {
font-weight:bold;
text-align:center;
text-align:left;
color: #15915b;
}
h5 {
font-weight:bold;
font-size:18px;
text-align:left;
color: #264184;
}
.wraplabel {
border:1px solid #15915b;
border-radius: 5px;
......@@ -70,6 +76,9 @@
bottom: 5px;
right: 10px;
}
.picker {
font-size:13px;
}
</style>
<!-- <div class="well"> -->
<!-- <h1>SISTEM PENDAPATAN TERPADU</h1> -->
......@@ -94,7 +103,22 @@
<!-- <li>PT. Bank Pembangunan Daerah Jawa Barat dan Banten, Tbk (Bank BJB)</li> -->
<!-- </div> -->
<h4>REALISASI PENDAPATAN DAERAH TAHUN ${dates['year']}</h4>
<div class="col-md-6">
<h4>REALISASI PENDAPATAN DAERAH TAHUN ${dates['year']}</h4>
</div>
<div class="col-md-6">
<form method="get">
<div class="col-md-5">
<input id="date" type="text" class="form-control date" name="date" value="${request.session['date']}">
</div>
<div class="col-md-7">
<select id="unit" class="form-control" name="unit">
<option></option>
<option tal:repeat="o opds" value="${o.kode.strip()}">${o.kode.strip()} - ${o.nama}</option>
</select>
</div>
</form>
</div>
<div class="col-md-12">
<div class="col-md-3">
<div class="wraplabel">
......@@ -138,17 +162,17 @@
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">Peringkat</th>
<th scope="col">Upd</th>
<th scope="col">Nominal</th>
<th style="text-align:center;">Peringkat</th>
<th style="text-align:center;">Nama Unit</th>
<th style="text-align:center;">Nominal</th>
</tr>
</thead>
<tbody>
<tal:block tal:repeat="sopd data['sopd']">
<tal:block tal:repeat="s data['sopd10']">
<tr>
<td>${sopd['peringkat']}</td>
<td>${sopd['upd']}</td>
<td>${'{:n}'.format(sopd['nominal'])}</td>
<td style="text-align:center;">${s['peringkat']}</td>
<td style="text-align:left;">${s['unit']}</td>
<td style="text-align:right;">${'{:n}'.format(s['nominal'])}</td>
</tr>
</tal:block>
</tbody>
......@@ -164,6 +188,34 @@
</div>
</tal:block>
</div>
<div class="col-md-12">
<div class="clearfix"></div>
<br>
<div class="col-md-6">
<h5>Ranking Penerimaan OPD Periode ${dates['day'].strftime('%d-%m-%Y')}</h5>
</div>
<div class="clearfix"></div>
<table class="table table-bordered">
<thead>
<tr>
<th style="text-align:center;">Peringkat</th>
<th style="text-align:center;">Kode Unit</th>
<th style="text-align:center;">Nama Unit</th>
<th style="text-align:center;">Nominal</th>
</tr>
</thead>
<tbody>
<tal:block tal:repeat="so data['sopd']">
<tr>
<td style="text-align:center;">${so['peringkat']}</td>
<td style="text-align:left;">${so['kode']}</td>
<td style="text-align:left;">${so['unit']}</td>
<td style="text-align:right;">${'{:n}'.format(so['nominal'])}</td>
</tr>
</tal:block>
</tbody>
</table>
</div>
<script type="text/javascript" src="/static/js/Chart.min.js"></script>
<script type="text/javascript" src="/static/js/jquery-2.1.1.min.js"></script>
<script>
......@@ -276,6 +328,9 @@
display: false,
labelString: 'Value'
},
ticks: {
beginAtZero: true
}
}]
},
elements: {
......@@ -287,7 +342,19 @@
};
var ctx = document.getElementById('chart').getContext('2d');
BAR = new Chart(ctx, config);
});
$('.date').pickadate({
"submitFormat": "dd-mm-yyyy",
"format": "dd-mm-yyyy",});
});
$("#date, #unit").change(function(){
$(this).parents('form').submit();
});
$('.date').attr('readonly', true);
$('.date').css('background-color', 'transparent');
<tal:block tal:condition="'unit' in request.session and request.session['unit']">
$("#unit").val("${request.session['unit']}");
</tal:block>
</script>
</div>
</html>
......@@ -274,6 +274,8 @@
return;
}
window.open('/reports/act/Laporan_12?jenis='+jenis+'&bayar='+bayar+'&awal='+awal+'&akhir='+akhir);
}else if(jenis=='98'){
window.open('/reports/act/Laporan_98');
}
});
......@@ -330,6 +332,9 @@
<div class="radio">
<label><input type="radio" name="jenis" value="12">Laporan Kode Rekening per OPD</label>
</div>
<div class="radio">
<label><input type="radio" name="jenis" value="98">CSV</label>
</div>
</div>
</div>
<!-- Rekening -->
......
......@@ -185,6 +185,8 @@
}else if(jenis=='22'){
window.open('/reports/act/Laporan_22');
}else if(jenis=='99'){
window.open('/reports/act/Laporan_99');
}
});
......@@ -241,6 +243,9 @@
<div class="radio">
<label><input type="radio" name="jenis" value="22">Penerimaan OPD <span class="badge">(Tidak Aktif)</span></label>
</div>
<div class="radio">
<label><input type="radio" name="jenis" value="99">CSV</label>
</div>
</div>
</div>
<!--Mulai S/d-->
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!