Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Sprint15 #3

Merged
merged 10 commits into from
Jul 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ FROM weboaks/node-karma-protractor-chrome

ENV PATH /usr/local/bin:$PATH

RUN apt-get update && \
RUN apt-get update && apt-get install -y apt-utils && \
apt-get install -y --no-install-recommends libffi-dev \
build-essential checkinstall libreadline-gplv2-dev \
libncursesw5-dev libssl-dev libsqlite3-dev tk-dev \
libgdbm-dev libc6-dev libbz2-dev xvfb xauth \
locales gcc libc6 libgcc1 libstdc++6 pdftk apt-utils \
locales gcc libc6 libgcc1 libstdc++6 pdftk \
tk-dev uuid-dev wget ca-certificates gnupg dirmngr

RUN rm -rf /var/lib/apt/lists/* \
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ version: '3'
services:
validate:
build: .
environment:
- AWS_ACCESS_KEY_ID=${ACCESS_KEY}
- AWS_SECRET_ACCESS_KEY=${SECRET_KEY}
- AWS_DEFAULT_REGION=us-east-1
volumes:
- ./:/opt/imagegenerator
ports:
Expand Down
2 changes: 1 addition & 1 deletion lib/wkhtmltopdf.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh
/usr/bin/xvfb-run -a --server-args="-screen 0, 1024x768x24" /usr/bin/wkhtmltopdf -q $*
/usr/bin/xvfb-run -a --server-args="-screen 0, 1024x768x24" /usr/bin/wkhtmltopdf -q --no-pdf-compression --encoding 'UTF-8' $*
149 changes: 100 additions & 49 deletions routes/src/form3x.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ def directory_files(directory):
return files_list


def merge(dict1, dict2):
res = {**dict1, **dict2}
return res


def print_pdftk(stamp_print):
# check if json_file is in the request

Expand Down Expand Up @@ -51,62 +56,104 @@ def print_pdftk(stamp_print):
f3x_col_a = f3x_summary_temp['colA']
f3x_col_b = f3x_summary_temp['colB']
for key in f3x_col_a:
f3x_summary['colA_' + key] = f3x_col_a[key]
f3x_summary['colA_' + key] = '{0:.2f}'.format(f3x_col_a[key])
for key in f3x_col_b:
f3x_summary['colB_' + key] = f3x_col_b[key]
f3x_summary['colB_' + key] = '{0:.2f}'.format(f3x_col_b[key])


coverageStartDateArray = f3x_data['coverageStartDate'].split("/")
f3x_data['coverageStartDateMonth'] = coverageStartDateArray[0]
f3x_data['coverageStartDateDay'] = coverageStartDateArray[1]
f3x_data['coverageStartDateYear'] = coverageStartDateArray[2]

coverageEndDateArray = f3x_data['coverageEndDate'].split("/")
f3x_data['coverageEndDateMonth'] = coverageEndDateArray[0]
f3x_data['coverageEndDateDay'] = coverageEndDateArray[1]
f3x_data['coverageEndDateYear'] = coverageEndDateArray[2]

if len(f3x_data['dateSigned']) > 0:
dateSignedArray = f3x_data['dateSigned'].split("/")
f3x_data['dateSignedMonth'] = dateSignedArray[0]
f3x_data['dateSignedDay'] = dateSignedArray[1]
f3x_data['dateSignedYear'] = dateSignedArray[2]

treasurer_full_name = []
treasurer_full_name.append(f3x_data['treasurerLastName'])
treasurer_full_name.append(f3x_data['treasurerFirstName'])
treasurer_full_name.append(f3x_data['treasurerMiddleName'])
treasurer_full_name.append(f3x_data['treasurerPrefix'])
treasurer_full_name.append(f3x_data['treasurerSuffix'])
f3x_data['treasurerFullName'] = ",".join(map(str, treasurer_full_name))
f3x_data['treasurerName'] = f3x_data['treasurerLastName'] + "," + f3x_data['treasurerFirstName']
f3x_data['efStamp'] = '[Electronically Filed]'

f3x_data_summary_array = [f3x_data, f3x_summary]
f3x_data_summary = {i: j for x in f3x_data_summary_array for i, j in x.items()}

has_sa_schedules = False
if 'schedules' in f3x_data:
schedules = f3x_data['schedules']
if 'SA' in schedules:
schedule_total = 0.00
# os.remove(md5_directory + 'SA/all_pages.pdf')
# create SA folder under MD5 directory
os.makedirs(md5_directory + 'SA', exist_ok=True)
sa_infile = current_app.config['FORM_TEMPLATES_LOCATION'].format('SA')
sa_schedules = schedules['SA']
# print(len(sa_schedules))
sa_array = []
sa_json = {}
no_of_pages = 0
no_of_transactions_in_last_page = 0
# print(int(len(sa_schedules) / 3))
if int(len(sa_schedules) % 3) == 0:
no_of_pages = int(len(sa_schedules) / 3)
no_of_transactions_in_last_page = 3
else:
no_of_pages = int(len(sa_schedules) / 3) + 1
no_of_transactions_in_last_page = int(len(sa_schedules) % 3)

total_no_of_pages += no_of_pages
if no_of_pages > 1:
for sa_page_no in range(no_of_pages):
page_subtotal = 0.00
sa_schedule_page_dict = {}
sa_schedule_page_dict['pageNo'] = 5 + sa_page_no + 1
sa_schedule_page_dict['totalPages'] = total_no_of_pages
page_start_index = sa_page_no * 3
if sa_page_no == (no_of_pages - 1):
# page_end_index = page_start_index + no_of_transactions_in_last_page - 1
sa_schedule_dict = build_per_page_schedule_dict(no_of_transactions_in_last_page,
page_start_index, sa_schedule_page_dict,
sa_schedules)
else:
# no_of_transactions_in_last_page = 3
sa_schedule_dict = build_per_page_schedule_dict(3, page_start_index, sa_schedule_page_dict,
sa_schedules)

page_subtotal = float(sa_schedule_page_dict['pageSubtotal'])
schedule_total += page_subtotal
if no_of_pages == (sa_page_no+1):
sa_schedule_page_dict['scheduleTotal'] = '{0:.2f}'.format(schedule_total)
sa_schedule_page_dict['committeeName'] = f3x_data['committeeName']
sa_schedule_page_dict['lineNumber'] = sa_schedule_dict['lineNumber']
sa_outfile = md5_directory + '/SA/' + 'page_'+str(sa_page_no)+'.pdf'
pypdftk.fill_form(sa_infile, sa_schedule_page_dict, sa_outfile)
pypdftk.concat(directory_files(md5_directory + 'SA/'), md5_directory + 'SA/all_pages.pdf')
no_of_schedules = len(sa_schedules)
if no_of_schedules > 0:
has_sa_schedules = True
schedule_total = 0.00
# os.remove(md5_directory + 'SA/all_pages.pdf')
# create SA folder under MD5 directory
os.makedirs(md5_directory + 'SA', exist_ok=True)
sa_infile = current_app.config['FORM_TEMPLATES_LOCATION'].format('SA')


for sa_count in range(no_of_schedules):
if 'child' in sa_schedules[sa_count]:
sa_child_schedules = sa_schedules[sa_count]['child']
sa_child_schedules_count = len(sa_child_schedules)
no_of_schedules += sa_child_schedules_count
for sa_child_count in range(sa_child_schedules_count):
# sa_schedules[sa_count].append(sa_schedules[sa_count]['child'][sa_child_count])
sa_schedules.append(sa_schedules[sa_count]['child'][sa_child_count])
del sa_schedules[sa_count]['child']
# print(len(sa_schedules))
sa_array = []
sa_json = {}
no_of_pages = 0
no_of_transactions_in_last_page = 0
# print(int(len(sa_schedules) / 3))
if int(len(sa_schedules) % 3) == 0:
no_of_pages = int(len(sa_schedules) / 3)
no_of_transactions_in_last_page = 3
else:
no_of_pages = int(len(sa_schedules) / 3) + 1
no_of_transactions_in_last_page = int(len(sa_schedules) % 3)

total_no_of_pages += no_of_pages
if no_of_pages > 0:
for sa_page_no in range(no_of_pages):
page_subtotal = 0.00
sa_schedule_page_dict = {}
sa_schedule_page_dict['pageNo'] = 5 + sa_page_no + 1
sa_schedule_page_dict['totalPages'] = total_no_of_pages
page_start_index = sa_page_no * 3
if sa_page_no == (no_of_pages - 1):
# page_end_index = page_start_index + no_of_transactions_in_last_page - 1
sa_schedule_dict = build_per_page_schedule_dict(no_of_transactions_in_last_page,
page_start_index, sa_schedule_page_dict,
sa_schedules)
else:
# no_of_transactions_in_last_page = 3
sa_schedule_dict = build_per_page_schedule_dict(3, page_start_index, sa_schedule_page_dict,
sa_schedules)

page_subtotal = float(sa_schedule_page_dict['pageSubtotal'])
schedule_total += page_subtotal
if no_of_pages == (sa_page_no+1):
sa_schedule_page_dict['scheduleTotal'] = '{0:.2f}'.format(schedule_total)
sa_schedule_page_dict['committeeName'] = f3x_data['committeeName']
sa_schedule_page_dict['lineNumber'] = sa_schedule_dict['lineNumber']
sa_outfile = md5_directory + '/SA/' + 'page_'+str(sa_page_no)+'.pdf'
pypdftk.fill_form(sa_infile, sa_schedule_page_dict, sa_outfile)
pypdftk.concat(directory_files(md5_directory + 'SA/'), md5_directory + 'SA/all_pages.pdf')



Expand All @@ -115,8 +162,12 @@ def print_pdftk(stamp_print):
shutil.copy(outfile, md5_directory + 'F3X.pdf')
os.remove(md5_directory + json_file_md5 +'_temp.pdf')
# pypdftk.concat(directory_files(md5_directory + 'SA/'), md5_directory + 'SA/all_pages.pdf')
pypdftk.concat([md5_directory + 'F3X.pdf', md5_directory + 'SA/all_pages.pdf'], md5_directory + 'all_pages.pdf')
os.remove(md5_directory + 'SA/all_pages.pdf')
# checking for any sa transactions
if has_sa_schedules:
pypdftk.concat([md5_directory + 'F3X.pdf', md5_directory + 'SA/all_pages.pdf'], md5_directory + 'all_pages.pdf')
os.remove(md5_directory + 'SA/all_pages.pdf')
else:
shutil.move(md5_directory + 'F3X.pdf', md5_directory + 'all_pages.pdf')

# push output file to AWS
s3 = boto3.client('s3')
Expand Down
15 changes: 11 additions & 4 deletions routes/src/form99.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,14 +477,21 @@ def print_f99_pdftk_html(stamp_print):
output_file.write(str(soup).replace("&lt;", "<").replace("&gt;", ">"))

# F99 PDF page padding options
# options = {
# 'margin-top': '0.36in',
# 'margin-right': '0.25in',
# 'margin-bottom': '0.39in',
# 'margin-left': '0.25in'
# }
options = {
'margin-top': '0.36in',
'margin-right': '0.25in',
'margin-bottom': '0.39in',
'margin-left': '0.25in'
'margin-top': '0.40in',
'margin-right': '0.20in',
'margin-bottom': '0.40in',
'margin-left': '0.20in'
}
# HTML(outfile).write_pdf(md5_directory + json_file_md5 + '.pdf', stylesheets=[CSS(current_app.config['FORMS_LOCATION'].format('F99.css'))])
pdfkit.from_file(outfile, md5_directory + json_file_md5 + '.pdf', options=options)
# pdfkit.from_file(outfile, md5_directory + json_file_md5 + '.pdf')

total_no_of_pages = pypdftk.get_num_pages(md5_directory + json_file_md5 + '.pdf')
page_number_file = current_app.config['FORM_TEMPLATES_LOCATION'].format('Page_Number')
Expand Down
Binary file modified templates/forms/F3X.pdf
Binary file not shown.
44 changes: 32 additions & 12 deletions templates/forms/F99/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@
left: 50%;
transform: translate(-50%, -50%);
}
/*table tr {page-break-inside: avoid}
@media print {
* {
page-break-inside: avoid;
page-break-after: avoid;
page-break-before: avoid;
}
}*/

}

</style>
<link href="form-text.css" rel="stylesheet" type="text/css">
Expand Down Expand Up @@ -206,20 +200,46 @@
<td colspan="4" height="26">&nbsp;</td>
</tr>
<tr>
<td height="22" colspan="4"><strong>MESSAGE &#x25BC;</strong></td>
<td height="22" colspan="4"><!-- strong>MESSAGE &#x25BC;</strong --></td>
</tr>
<tr>
<td height="21" colspan="4">&nbsp;</td>
</tr>
<tr>
<td colspan="4">
<div style="height:auto;">
<label style="min-height:50px; border: 2px solid #ced4da; width: 1248; display:block; padding-left: 20px; padding-right: 20px;font-size:22px;" id="text"></label>
</div>
<!-- div style="height: outo;">
<label style="
min-height:50px;
border: 3px solid #ced4da;
width: 1412px;
display: block;
padding-left: 20px;
padding-right: 20px;
font-size: 22px;
overflow-x: visible;
line-height: 1.25em;
" id="text"></label>
</div -->
</td>
</tr>
</tbody>
</table>
<div style="height: outo;">
<strong>MESSAGE &#x25BC;</strong>
<label style="
min-height:50px;
border: 3px solid #ced4da;
width: 1412px;
display: block;
padding-left: 20px;
padding-right: 20px;
font-size: 22px;
overflow-x: visible;
line-height: 1.25em;
" id="text"></label>
</div>


</body>
</html>

Binary file modified templates/forms/SA.pdf
Binary file not shown.