-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Besermenji/vb/kif
Report generator refactored, and kif report support added
- Loading branch information
Showing
3 changed files
with
122 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"> </div> | ||
<div class="col-md-4"> | ||
<p> | ||
_________________________________ | ||
</p> | ||
<p> | ||
On date: <%= Date.today %> | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
This file was deleted.
Oops, something went wrong.