Skip to content

Commit

Permalink
Merge pull request #4 from Besermenji/vb/kif
Browse files Browse the repository at this point in the history
Report generator refactored, and kif report support added
  • Loading branch information
Besermenji authored Jun 29, 2016
2 parents 8ff1970 + 1fa1236 commit e2bd7e5
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 234 deletions.
51 changes: 9 additions & 42 deletions report_generator.rb
Original file line number Diff line number Diff line change
@@ -1,59 +1,26 @@
require 'sinatra'
require 'letter_opener' unless ENV['RACK_ENV'] == 'production'
require 'pry' unless ENV['RACK_ENV'] == 'production'
require 'pony'
require 'json'


class ReportGenerator < Sinatra::Base

before do
unless request.body.read == ""
request.body.rewind
@request_payload ||= JSON.parse request.body.read
end
end

get '/' do
"Hello World! Im just a poor app, nobody loves me."
end

get '/report_sent' do
"Report sent!"
end

get '/something_went_wrong' do
"Oh noes!
You don't like the smell?
Maybe I don't like the smell that some cars produce?
I sure as hell don't like it when
people fart near me or if someone has
bad body odor. You get a sore throat,
maybe I get a headache
from prolonged exposure to
those smells. Should we make
everything that doesn't smell good illegal?"
end

post '/send_report' do
if @request_payload && @request_payload["email"]
generate_pdf
Pony.mail(:to => @request_payload["email"],
post '/kif/?' do
@kif_info = JSON.parse(params["data"])
generate_pdf
Pony.mail(:to => @kif_info["email"],
:from => '[email protected]',
:subject => 'hi',
:body => "Hello there. It is #{DateTime.now}. This is just a test.",
:attachments => {"report.pdf" => File.read(@file)})
redirect '/report_sent'
else
redirect '/something_went_wrong'
end
end
:body => "Hello there. It is #{DateTime.now}. Enjoy your KIF report.",
:attachments => {"KIF_report_#{DateTime.now}.pdf" => File.read(@file)})

get '/pdf' do
generate_pdf
status 200
end

def generate_pdf
kit = PDFKit.new(erb :'reports/report-template.html')
kit = PDFKit.new(erb :'reports/kif-report-template.html')
kit.stylesheets << 'views/reports/css/bootstrap-theme.min.css'
kit.stylesheets << 'views/reports/css/bootstrap.min.css'
kit.stylesheets << 'views/reports/css/style.css'
Expand Down
113 changes: 113 additions & 0 deletions views/reports/kif-report-template.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>Report</title>

<meta name="description" content="Source code generated using layoutit.com">
<meta name="author" content="LayoutIt!">

<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">

</head>
<body>

<div class="container-fluid">
<div class="row">
<div class="col-md-offset-1 col-md-4">
<address>
<strong>Report date:</strong> <%= Date.today %>
<br>
<strong>Report requester:</strong> <%= @kif_info["email"] %>
<br>
<strong>Requester company:</strong> <%= @kif_info["info"][0]["financial_year"]["company"]["name"] %>
</address>
</div>
</div>
<div class="row">
<div class="col-md-2">
</div>
<div class="col-md-8">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>
Number
</th>
<th>
Payment Amount
</th>
<th>
Remaining Amount
</th>
<th>
Issuance Date
</th>
<th>
Circulation Date
</th>
<th>
Payment Deadline
</th>
<th>
Business Partner
</th>
<th>
Financial Year
</th>
</tr>
</thead>
<tbody>
<% @kif_info["info"].each do |kif| %>
<tr>
<td>
<%= kif["number"] %>
</td>
<td>
<%= kif["payment_amount"] %>
</td>
<td>
<%= kif["remaining_amount"] %>
</td>
<td>
<%= kif["issuance_date"] %>
</td>
<td>
<%= kif["circulation_date"] %>
</td>
<td>
<%= kif["payment_deadline"] %>
</td>
<td>
<%= kif["business_partner"]["name"] %>
</td>
<td>
<%= kif["financial_year"]["year"] %>
</td>
</tr>
<% end %>

</tbody>
</table>
</div>
<div class="col-md-2">
</div>
</div>
<div class="row">
<div class="col-md-7">&nbsp;</div>
<div class="col-md-4">
<p>
_________________________________
</p>
<p>
On date: <%= Date.today %>
</p>
</div>
</div>
</div>
</body>
</html>
192 changes: 0 additions & 192 deletions views/reports/report-template.html.erb

This file was deleted.

0 comments on commit e2bd7e5

Please sign in to comment.