Skip to content

Commit

Permalink
Kif and kuf working
Browse files Browse the repository at this point in the history
  • Loading branch information
Besermenji committed Jun 29, 2016
1 parent e2bd7e5 commit 465aaaf
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 4 deletions.
18 changes: 15 additions & 3 deletions report_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ReportGenerator < Sinatra::Base

post '/kif/?' do
@kif_info = JSON.parse(params["data"])
generate_pdf
generate_pdf('reports/kif-report-template.html')
Pony.mail(:to => @kif_info["email"],
:from => '[email protected]',
:subject => 'hi',
Expand All @@ -19,8 +19,20 @@ class ReportGenerator < Sinatra::Base
status 200
end

def generate_pdf
kit = PDFKit.new(erb :'reports/kif-report-template.html')
post '/kuf/?' do
@kuf_info = JSON.parse(params["data"])
generate_pdf('reports/kuf-report-template.html')
Pony.mail(:to => @kuf_info["email"],
:from => '[email protected]',
:subject => 'hi',
:body => "Hello there. It is #{DateTime.now}. Enjoy your KUF report.",
:attachments => {"KUF_report_#{DateTime.now}.pdf" => File.read(@file)})

status 200
end

def generate_pdf(pdf_path)
kit = PDFKit.new(erb pdf_path.to_sym)
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
2 changes: 1 addition & 1 deletion views/reports/kif-report-template.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<br>
<strong>Report requester:</strong> <%= @kif_info["email"] %>
<br>
<strong>Requester company:</strong> <%= @kif_info["info"][0]["financial_year"]["company"]["name"] %>
<strong>Requester company:</strong> <%= @kif_info["company"]["name"] %>
</address>
</div>
</div>
Expand Down
113 changes: 113 additions & 0 deletions views/reports/kuf-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> <%= @kuf_info["email"] %>
<br>
<strong>Requester company:</strong> <%= @kuf_info["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>
<% @kuf_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>

0 comments on commit 465aaaf

Please sign in to comment.