Skip to content

Commit

Permalink
List Absent pupils in date range (to PDF), #6
Browse files Browse the repository at this point in the history
  • Loading branch information
Arcath committed Oct 17, 2014
1 parent becd496 commit b155e9f
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/client/views/attendance-summary.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

{Class, Pupil, Session} = require '../../database'

AttendanceRangeView = require './select/attendance-range'

module.exports =
class AttendanceSummary extends View
@content: ->
@div =>
@h1 'Attendance Summary'
@button class: 'image-button primary', click: 'printSummary', =>
@span "Print Summary"
@i class: 'icon-file-pdf bg-cobalt'
for session in Session.all()
pupils = Session.pupilsInSession(session.idSessions, new Date)
@h2 session.name
Expand All @@ -20,3 +25,6 @@ module.exports =
@ul =>
for pupil in Session.absentPupilsInSession(session.idSessions, new Date)
@li pupil.firstName + ' ' + pupil.lastName + ' (' + Class.find('idClass', pupil.classId).name + ')'

printSummary: (event, element) ->
$('#mainBody').append(new AttendanceRangeView)
17 changes: 17 additions & 0 deletions lib/client/views/pdfs/attendance-range.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{View} = require 'space-pen'

{Class, Config, Session} = require '../../../database'

module.exports =
class AttendanceRangePDF extends View
@content: (dates) ->
klass = 0
@div class: 'pdf', =>
@h1 Config.setting('name')
@h2 'Absent Pupils in Range'
for date in dates
for session in Session.all()
@h3 session.name + ' ' + Session.displayDate(date)
@ul =>
for pupil in Session.absentPupilsInSession(session.idSessions, new Date(Date.parse(date)))
@li pupil.firstName + ' ' + pupil.lastName + ' (' + Class.find('idClass', pupil.classId).name + ')'
49 changes: 49 additions & 0 deletions lib/client/views/select/attendance-range.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{View} = require 'space-pen'

{Register} = require '../../../database'

AttendanceRangePDF = require '../pdfs/attendance-range'

wkhtmltopdf = require '../../../bindings/wkhtmltopdf'

module.exports =
class AttendanceRangeView extends View
@content: ->
@div class: 'metro window-overlay', id: 'modalContainer', =>
@div class: 'window flat shadow', =>
@div class: 'caption', =>
@button class: 'btn-close', click: 'closeWindow'
@div class: 'title', 'Select Range'
@div class: 'content', =>
@form =>
@label 'From'
@div class: 'input-control text', =>
@input type: 'date', id: 'fromDate'
@label 'To'
@div class: 'input-control text', =>
@input type: 'date', id: 'toDate'
@div class: 'form-actions', =>
@button class: 'primary', click: 'print', 'Print'
@button click: 'closeWindow', 'Cancel'

closeWindow: (event, element) ->
$('#modalContainer').remove()
return false

print: (event, element) ->
registers = Register.inRange($('#fromDate').val(), $('#toDate').val())
dates = []
for register in registers
if dates.indexOf(register.date) == -1
dates.push register.date

$('#mainBody').append(new AttendanceRangePDF(dates))

path = "C:\\pdf\\attendance.pdf"

wkhtmltopdf.render($('.pdf').html(), path)

$('.pdf').remove()

@closeWindow(event, element)
return false
3 changes: 3 additions & 0 deletions lib/database/models/register.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ module.exports =
return @manualSelectQuery('classId = ' + classId + ' AND sessionId = ' + sessionId + ' AND date = "' + date + '"')[0]
else
return results[0]

@inRange: (from, to) ->
@manualSelectQuery('date >= "' + from + '" AND date <= "' + to + '"')

0 comments on commit b155e9f

Please sign in to comment.