Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Taufik Yulianto
/
esipkd
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 309da8a5
authored
Sep 17, 2020
by
taufikyu
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
update laporan skrd
1 parent
279f4936
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
157 additions
and
0 deletions
esipkd/reports/skrd.odt
esipkd/tools.py
esipkd/views/arinvoice_b.py
esipkd/views/templates/arinvoice/list_b.pt
esipkd/reports/skrd.odt
0 → 100644
View file @
309da8a
No preview for this file type
esipkd/tools.py
View file @
309da8a
...
...
@@ -10,6 +10,7 @@ import pytz
import
io
import
random
import
sys
import
subprocess
from
string
import
ascii_uppercase
,
ascii_lowercase
,
digits
from
email.utils
import
parseaddr
...
...
@@ -570,3 +571,113 @@ def csv_response(request, value, filename):
fcsv
.
writerows
(
value
.
get
(
'rows'
,
[]))
response
.
write
(
fout
.
getvalue
())
return
response
def
odt_export
(
request
,
filename
,
file_type
):
results
=
odt_export_
(
filename
,
file_type
)
if
'error'
in
results
:
return
results
out_filename
=
results
[
'filename'
]
if
not
os
.
path
.
isfile
(
out_filename
):
return
dict
(
error
=
True
,
msg
=
'Error
%
s tidak ditemukan '
%
out_filename
)
with
open
(
out_filename
,
'rb'
)
as
f
:
return
file_response
(
request
,
f
,
out_filename
,
file_type
)
def
odt_export_
(
filename
,
file_type
,
password
=
None
):
settings
=
get_settings
()
import
getpass
username
=
getpass
.
getuser
()
odt_file
=
'.'
.
join
([
filename
,
'odt'
])
out_dir
=
os
.
path
.
dirname
(
filename
)
if
'unoconv_py'
in
settings
and
settings
[
'unoconv_py'
]:
unoconv_py
=
settings
[
'unoconv_py'
]
if
'unoconv_bin'
in
settings
and
settings
[
'unoconv_bin'
]:
unoconv_bin
=
settings
[
'unoconv_bin'
]
else
:
unoconv_bin
=
''
params
=
[
unoconv_py
,
unoconv_bin
,
'-f'
,
file_type
]
if
password
:
params
.
extend
([
'-e'
,
'EncryptFile=True'
,
'-e'
,
'DocumentOpenPassword='
+
password
])
params
.
append
(
odt_file
)
print
(
"DEBUG EXPORT>>"
,
' '
.
join
(
params
))
subprocess
.
call
(
params
)
# convert using bin
else
:
if
'unoconv_bin'
in
settings
and
settings
[
'unoconv_bin'
]:
unoconv_bin
=
settings
[
'unoconv_bin'
]
params
=
[
unoconv_bin
,
'-env:UserInstallation=file:///tmp/'
+
username
,
'--headless'
,
'--convert-to'
,
'pdf'
]
params
.
extend
([
'--outdir'
,
out_dir
,
file_type
,
odt_file
])
print
(
"DEBUG EXPORT>>"
,
' '
.
join
(
params
))
subprocess
.
call
(
params
)
out_file
=
'.'
.
join
([
filename
,
file_type
])
if
not
os
.
path
.
isfile
(
odt_file
):
return
dict
(
error
=
dict
(
code
=-
1
,
message
=
'File
%
s tidak ditemukan '
%
odt_file
))
else
:
if
not
os
.
path
.
isfile
(
out_file
):
return
dict
(
error
=
dict
(
code
=-
1
,
message
=
'File
%
s tidak ditemukan '
%
out_file
))
print
(
"DEBUG DELETE>>"
,
odt_file
)
os
.
remove
(
odt_file
)
print
(
"DEBUG OUT FILE>>"
,
out_file
)
return
dict
(
filename
=
out_file
)
def
file_response
(
request
,
f
=
None
,
filename
=
None
,
filetype
=
None
):
"""
:param request:
:param f: object file
:param filename:
:param filetype: type of file
:return: object response
"""
import
ntpath
if
not
f
:
f
=
open
(
filename
,
'rb'
)
fname
=
ntpath
.
basename
(
filename
)
else
:
fname
=
filename
if
not
filetype
:
t
=
fname
.
split
(
'.'
)
filetype
=
''
.
join
(
t
[
-
1
:])
response
=
request
.
response
response
.
content_type
=
"application/"
+
filetype
response
.
content_disposition
=
'filename='
+
fname
response
.
write
(
f
.
read
())
return
response
def
terbilang
(
bil
):
angka
=
[
""
,
"Satu"
,
"Dua"
,
"Tiga"
,
"Empat"
,
"Lima"
,
"Enam"
,
"Tujuh"
,
"Delapan"
,
"Sembilan"
,
"Sepuluh"
,
"Sebelas"
]
hasil
=
" "
n
=
int
(
bil
)
if
n
>=
0
and
n
<=
11
:
hasil
=
hasil
+
angka
[
n
]
elif
n
<
20
:
hasil
=
terbilang
(
n
%
10
)
+
" Belas"
elif
n
<
100
:
hasil
=
terbilang
(
n
/
10
)
+
" Puluh"
+
terbilang
(
n
%
10
)
elif
n
<
200
:
hasil
=
" Seratus"
+
terbilang
(
n
-
100
)
elif
n
<
1000
:
hasil
=
terbilang
(
n
/
100
)
+
" Ratus"
+
terbilang
(
n
%
100
)
elif
n
<
2000
:
hasil
=
" Seribu"
+
terbilang
(
n
-
1000
)
elif
n
<
1000000
:
hasil
=
terbilang
(
n
/
1000
)
+
" Ribu"
+
terbilang
(
n
%
1000
)
elif
n
<
1000000000
:
hasil
=
terbilang
(
n
/
1000000
)
+
" Juta"
+
terbilang
(
n
%
1000000
)
else
:
hasil
=
terbilang
(
n
/
1000000000
)
+
" Miliar"
+
terbilang
(
n
%
1000000000
)
return
hasil
\ No newline at end of file
esipkd/views/arinvoice_b.py
View file @
309da8a
import
sys
import
re
import
logging
import
os
from
email.utils
import
parseaddr
from
sqlalchemy
import
not_
,
func
,
or_
,
desc
from
datetime
import
datetime
...
...
@@ -20,6 +21,10 @@ from deform import (
from
..tools
import
(
_DTnumberformat
,
multi_dict_values
,
odt_export
,
terbilang
,
thousand
,
dmy
)
from
..models
import
DBSession
from
..models.isipkd
import
(
...
...
@@ -785,3 +790,34 @@ def view_pdf(request):
rows
.
append
(
s
)
pdf
,
filename
=
open_rml_pdf
(
'arinvoiceb_cetak.rml'
,
rows2
=
rows
)
return
pdf_response
(
request
,
pdf
,
filename
)
if
url_dict
[
'pdf'
]
==
'skrd'
:
if
not
'id'
in
params
or
not
params
[
'id'
]:
request
.
session
.
flash
(
'ID tidak ditemukan'
,
'error'
)
raise
route_list
()
from
py3o.template
import
Template
class
Item
(
object
):
pass
_here
=
os
.
path
.
dirname
(
__file__
)
# get current folder -> views
path
=
os
.
path
.
dirname
(
_here
)
# mundur 1 level
path
=
os
.
path
.
join
(
path
,
'reports/'
)
file
=
'/tmp/skrd'
template
=
Template
(
path
+
'skrd.odt'
,
file
+
'.odt'
)
row
=
DBSession
.
query
(
ARInvoice
)
.
filter_by
(
id
=
params
[
'id'
])
.
first
()
item
=
Item
()
item
.
opd
=
row
.
unit_nama
item
.
nama
=
row
.
wp_nama
item
.
alamat
=
row
.
wp_alamat_2
and
(
'{} {}'
.
format
(
row
.
wp_alamat_1
,
row
.
wp_alamat_2
))
or
row
.
wp_alamat_1
item
.
rek_nama
=
row
.
rek_nama
item
.
tahunskrd
=
row
.
tahun_id
item
.
tahun
=
datetime
.
now
()
.
year
item
.
jumlah
=
thousand
(
row
.
jumlah
)
item
.
jatuh_tempo
=
dmy
(
row
.
jatuh_tempo
)
item
.
terbilang
=
terbilang
(
row
.
jumlah
)
data
=
{}
data
[
'item'
]
=
item
template
.
render
(
data
)
return
odt_export
(
request
,
file
,
'pdf'
)
esipkd/views/templates/arinvoice/list_b.pt
View file @
309da8a
...
...
@@ -169,6 +169,7 @@
' <button id="btn_edit" class="btn btn btn-primary pull-left" type="button">Edit</button>'
,
' <button id="btn_delete" class="btn btn btn-danger pull-left" type="button">Hapus</button>'
,
' <button id="btn_print" class="btn btn btn-primary pull-left" type="button">Cetak</button>'
,
' <button id="btn_skrd" class="btn btn btn-success pull-left" type="button">SKRD</button>'
,
' <button id="btn_print1" class="btn btn btn-info pull-left" type="button">Kwitansi</button>'
,
' <button id="btn_posting" class="btn btn btn-success pull-left" type="button">Posting</button>'
,
' <button id="btn_close" class="btn btn btn-warning" type="button">Tutup</button>'
,
...
...
@@ -253,6 +254,15 @@
alert
(
'Silahkan pilih data yang akan dicetak kwitansinya.'
);
}
});
$
(
'#btn_skrd'
).
click
(
function
()
{
if
(
mID
)
{
url
=
oFormUrl
+
'skrd/pdf?id='
+
mID
;
window
.
open
(
url
);
}
else
{
alert
(
'Silahkan pilih data yang akan dicetak skrdnya.'
);
}
});
$
(
'#btn_csv'
).
click
(
function
()
{
url
=
oFormUrl
+
'reg/csv?awal='
+
$
(
'#awal'
).
val
()
+
"&akhir="
+
$
(
'#akhir'
).
val
();
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment