views/licence-view.ejs
<%- include('_header'); -%>
<div class="columns is-variable is-4-mobile is-4-tablet is-block-print" id="is-site-layout">
<%- include("_sideMenu-licences"); -%>
<div class="column is-block-print">
<nav class="breadcrumb">
<ul>
<li><a href="<%= urlPrefix %>/dashboard">Home</a></li>
<li><a href="<%= urlPrefix %>/licences">
<span class="icon is-small"><i class="fas fa-certificate" aria-hidden="true"></i></span>
<span>Lottery Licences</span>
</a></li>
<li class="is-active">
<a href="#" aria-current="page">
<% if (configFunctions.getProperty("licences.externalLicenceNumber.isPreferredID")) { %>
Licence <%= licence.externalLicenceNumber %>
<% } else { %>
Licence #<%= licence.licenceID %>
<% } %>
</a>
</li>
</ul>
</nav>
<div class="level">
<div class="level-left">
<h1 class="title is-1">
<% if (configFunctions.getProperty("licences.externalLicenceNumber.isPreferredID")) { %>
Licence <%= licence.externalLicenceNumber %>
<% } else { %>
Licence #<%= licence.licenceID %>
<% } %>
</h1>
</div>
<% if (licence.issueDate) { %>
<div class="level-right is-hidden-print">
<div class="field is-grouped justify-flex-end">
<div class="control">
<a class="button is-link" href="<%= urlPrefix %>/licences/<%= licence.licenceID %>/print" download>
<span class="icon is-small">
<i class="fas fa-print" aria-hidden="true"></i>
</span>
<span>Print Licence</span>
</a>
</div>
</div>
</div>
<% } %>
</div>
<% if (licence.canUpdate) { %>
<div class="fixed-container is-fixed-bottom-right mx-4 my-4 is-hidden-print">
<a class="button is-circle is-primary has-tooltip-left" data-tooltip="Edit this Licence" href="<%= urlPrefix %>/licences/<%= licence.licenceID %>/edit">
<i class="fas fa-pencil-alt" aria-hidden="true"></i>
<span class="sr-only">Edit this Licence</span>
</a>
</div>
<% } else if (user.userProperties.isAdmin) { %>
<div class="fixed-container is-fixed-bottom-right mx-4 my-4 is-hidden-print">
<a class="button is-circle is-warning has-tooltip-left" data-tooltip="Unlock this Licence" href="<%= urlPrefix %>/licences/<%= licence.licenceID %>/poke">
<i class="fas fa-unlock" aria-hidden="true"></i>
<span class="sr-only">Unlock this Licence</span>
</a>
</div>
<% } %>
<% if (licence.licenceAmendments.length > 0) { %>
<%- include('_licence-view_edit-amendments'); -%>
<% } %>
<div class="columns">
<div class="column">
<p>
<strong>Licence ID</strong><br />
<%= licence.licenceID %>
</p>
</div>
<div class="column">
<p>
<strong><%= configFunctions.getProperty("licences.externalLicenceNumber.fieldLabel") %></strong><br />
<%= licence.externalLicenceNumber %>
</p>
</div>
<div class="column">
<p>
<strong>Application Date</strong><br />
<%= licence.applicationDateString %>
</p>
</div>
</div>
<div class="columns">
<div class="column">
<p>
<strong>Organization</strong><br />
<a <%- (organization.isEligibleForLicences ? "" : " class=\"has-text-danger\"") %> href="<%= urlPrefix %>/organizations/<%= organization.organizationID %>">
<%= organization.organizationName %>
</a>
</p>
</div>
</div>
<div class="columns">
<div class="column is-6">
<p>
<strong>Municipality</strong><br />
<%= licence.municipality %>
</p>
</div>
<div class="column is-6">
<p>
<strong>Location</strong><br />
<% if (licence.locationID) { %>
<a href="<%= urlPrefix %>/locations/<%=licence.locationID %>"><%= licence.locationDisplayName %></a>
<% } else { %>
<span class="has-text-grey">(No Location)</span>
<% } %>
</p>
</div>
</div>
<div class="columns">
<div class="column is-3">
<p>
<strong>Start Date</strong><br />
<%= licence.startDateString %>
</p>
</div>
<div class="column is-3">
<p>
<strong>End Date</strong><br />
<%= licence.endDateString %>
</p>
</div>
<div class="column is-3">
<p>
<strong>Start Time</strong><br />
<%= licence.startTimeString %>
</p>
</div>
<div class="column is-3">
<p>
<strong>End Time</strong><br />
<%= licence.endTimeString %>
</p>
</div>
</div>
<div class="columns">
<div class="column is-6">
<p>
<strong>Licence Details</strong><br />
<span class="has-newline-chars"><%= licence.licenceDetails %></span>
</p>
</div>
<div class="column is-6">
<p>
<strong>Terms and Conditions</strong><br />
<span class="has-newline-chars"><%= licence.termsConditions %></span>
</p>
</div>
</div>
<div class="columns">
<div class="column is-6">
<p>
<strong>Licence Type</strong><br />
<%
const licenceType = configFunctions.getLicenceType(licence.licenceTypeKey);
%>
<%= (licenceType ? licenceType.licenceType : licence.licenceTypeKey) %>
</p>
</div>
<div class="column is-6">
<p>
<strong>Total Prize Value</strong><br />
<%= htmlFns.formatDollarsAsHTML(licence.totalPrizeValue || 0) %>
</p>
</div>
</div>
<div class="columns">
<div class="column">
<div class="panel">
<div class="panel-heading">
<div class="level">
<div class="level-left">
<h2 class="has-text-weight-bold">Event Dates</h2>
</div>
<div class="level-right has-text-weight-normal has-text-right is-hidden-print">
<a class="button is-small" href="<%= urlPrefix %>/reports/events-byLicence?licenceID=<%= licence.licenceID %>" download>
<span class="icon is-small">
<i class="fas fa-file-download" aria-hidden="true"></i>
</span>
<span>Export Events</span>
</a>
</div>
</div>
</div>
<% if (licence.events.length === 0) { %>
<div class="panel-block">
<div class="message is-warning">
<div class="message-body">
There are no events associated with this licence.
</div>
</div>
</div>
<% } else { %>
<% for (let eventIndex = 0; eventIndex < licence.events.length; eventIndex += 1) { %>
<a class="panel-block" href="<%= urlPrefix %>/events/<%= licence.licenceID %>/<%=licence.events[eventIndex].eventDate %>">
<span class="panel-icon">
<i class="fas fa-calendar" aria-hidden="true"></i>
</span>
<%= licence.events[eventIndex].eventDateString %>
</a>
<% } %>
<% } %>
</div>
</div>
<div class="column">
<%
if (licence.licenceFields.length > 0) {
const licenceFields = licenceType.licenceFields || [];
%>
<div class="panel">
<h2 class="panel-heading">
Additional <%= (licenceType ? licenceType.licenceType : licence.licenceTypeKey) %> Fields
</h2>
<%
let fieldKeys = "";
for (let fieldIndex = 0; fieldIndex < licenceFields.length; fieldIndex += 1) {
const licenceField = licenceFields[fieldIndex];
const inputName = licenceType.licenceTypeKey + "-" + licenceField.fieldKey;
let fieldValue = "";
for (let savedFieldIndex = 0; savedFieldIndex < licence.licenceFields.length; savedFieldIndex += 1) {
if (licence.licenceFields[savedFieldIndex].fieldKey === inputName) {
licence.licenceFields[savedFieldIndex].isDisplayed = true;
fieldValue = licence.licenceFields[savedFieldIndex].fieldValue;
break;
}
}
if (fieldValue === "") {
continue;
}
%>
<div class="panel-block">
<p>
<strong><%= licenceField.fieldLabel || licenceField.fieldKey %></strong><br />
<%= fieldValue %>
</p>
</div>
<%
}
for (let savedFieldIndex = 0; savedFieldIndex < licence.licenceFields.length; savedFieldIndex += 1) {
const savedField = licence.licenceFields[savedFieldIndex];
if (!savedField.isDisplayed) {
%>
<div class="panel-block">
<p>
<strong><%= savedField.fieldKey %></strong><br />
<%= savedField.fieldValue %>
</p>
</div>
<%
}
}
%>
</div>
<%
} else {
%>
<div class="message is-info">
<p class="message-body">
There are no additional fields recorded for this licence.
</p>
</div>
<%
}
%>
</div>
</div>
<% if (licence.licenceTicketTypes.length) { %>
<div class="panel" id="is-ticket-types-panel">
<div class="panel-heading">
<div class="level">
<div class="level-left">
<h2 class="has-text-weight-bold">Ticket Types</h2>
</div>
<div class="level-right has-text-weight-normal has-text-right is-hidden-print">
<a class="button is-small" href="<%= urlPrefix %>/reports/ticketTypes-byLicence?licenceID=<%= licence.licenceID %>" download>
<span class="icon"><i class="fas fa-file-download" aria-hidden="true"></i></span>
<span>Export Ticket Types</span>
</a>
</div>
</div>
</div>
<div class="panel-tabs">
<a class="is-active" href="#ticketTypesTabPanel--summary" aria-controls="ticketTypesTabPanel--summary">Summary</a>
<a href="#ticketTypesTabPanel--log" aria-controls="ticketTypesTabPanel--log">Log</a>
</div>
<table class="table is-fullwidth is-hidden" id="ticketTypesTabPanel--log">
<thead>
<tr>
<th>Amend Date</th>
<th>Type</th>
<th class="has-text-right">Units</th>
<th class="has-text-right">Value</th>
<th class="has-text-right">Prizes</th>
<th class="has-text-right">Licence Fee</th>
<th>Manufacturer</th>
<th>Distributor</th>
</tr>
</thead>
<tbody>
<%
const ticketTypeTotals = new Map();
const ticketTypeGrandTotals = {
totalUnits: 0,
totalValue: 0,
totalPrizes: 0,
totalLicenceFee: 0
};
for (const licenceTicketType of licence.licenceTicketTypes) {
%>
<%
const ticketTypeDef = (licenceType && licenceType.ticketTypes
? licenceType.ticketTypes.find(ele => ele.ticketType === licenceTicketType.ticketType)
: null);
const rowUnits = licenceTicketType.unitCount;
let totalUnits = rowUnits;
const rowTicketValue = (ticketTypeDef ? (ticketTypeDef.ticketPrice * ticketTypeDef.ticketCount) : 0);
const rowValue = rowTicketValue * rowUnits;
let totalValue = rowValue;
const prizesPerDeal = (ticketTypeDef ? ticketTypeDef.prizesPerDeal : 0);
const rowPrizes = prizesPerDeal * rowUnits;
let totalPrizes = rowPrizes;
const rowLicenceFee = licenceTicketType.licenceFee;
let totalLicenceFee = rowLicenceFee;
// ticket type sums
if (ticketTypeTotals.has(licenceTicketType.ticketType)) {
totalUnits += ticketTypeTotals.get(licenceTicketType.ticketType).totalUnits;
totalValue += ticketTypeTotals.get(licenceTicketType.ticketType).totalValue;
totalPrizes += ticketTypeTotals.get(licenceTicketType.ticketType).totalPrizes;
totalLicenceFee += ticketTypeTotals.get(licenceTicketType.ticketType).totalLicenceFee;
}
ticketTypeTotals.set(licenceTicketType.ticketType, {
totalUnits,
totalValue,
totalPrizes,
totalLicenceFee
});
ticketTypeGrandTotals.totalUnits += rowUnits;
ticketTypeGrandTotals.totalValue += rowValue;
ticketTypeGrandTotals.totalPrizes += rowPrizes;
ticketTypeGrandTotals.totalLicenceFee += rowLicenceFee;
%>
<tr>
<td><%= licenceTicketType.amendmentDateString %></td>
<td><%= licenceTicketType.ticketType %></td>
<td class="has-text-right">
<%= rowUnits %>
</td>
<td class="has-text-right">
<span data-tooltip="$<%= rowTicketValue %> value per deal"><%- htmlFns.formatDollarsAsHTML(rowValue) %></span>
</td>
<td class="has-text-right">
<span data-tooltip="<%= htmlFns.formatDollarsAsHTML(prizesPerDeal) %> prizes per deal"><%- htmlFns.formatDollarsAsHTML(rowPrizes) %></span>
</td>
<td class="has-text-right">
<%- htmlFns.formatDollarsAsHTML(rowLicenceFee) %>
</td>
<td>
<span>
<% if (licenceTicketType.manufacturerLocationID === null) { %>
<span class="has-text-grey">(Not Set)</span>
<% } else { %>
<%= licenceTicketType.manufacturerLocationDisplayName %>
<% } %>
</span>
</td>
<td>
<span>
<% if (licenceTicketType.distributorLocationID === null) { %>
<span class="has-text-grey">(Not Set)</span>
<% } else { %>
<%= licenceTicketType.distributorLocationDisplayName %>
<% } %>
</span>
</td>
</tr>
<%
}
%>
</tbody>
<tfoot>
<tr>
<td></td>
<td></td>
<th class="has-text-right">
<%= ticketTypeGrandTotals.totalUnits %>
</th>
<th class="has-text-right">
<%- htmlFns.formatDollarsAsHTML(ticketTypeGrandTotals.totalValue) %>
</th>
<th class="has-text-right">
<%- htmlFns.formatDollarsAsHTML(ticketTypeGrandTotals.totalPrizes) %>
</th>
<th class="has-text-right">
<%- htmlFns.formatDollarsAsHTML(ticketTypeGrandTotals.totalLicenceFee) %>
</th>
<td></td>
<td></td>
</tr>
</tfoot>
</table>
<table class="table is-fullwidth" id="ticketTypesTabPanel--summary">
<thead>
<tr>
<th>Type</th>
<th class="has-text-right">Total Units</th>
<th class="has-text-right">Total Value</th>
<th class="has-text-right">Total Prizes</th>
<th class="has-text-right">Total Licence Fee</th>
</tr>
</thead>
<tbody>
<%
const usedTicketTypes = [];
for (const usedTicketType of ticketTypeTotals.keys()) {
usedTicketTypes.push(usedTicketType);
}
usedTicketTypes.sort();
for (const usedTicketType of usedTicketTypes) {
%>
<%
const rowTotals = ticketTypeTotals.get(usedTicketType);
%>
<tr>
<td><%= usedTicketType %></td>
<td class="has-text-right">
<%= rowTotals.totalUnits %>
</td>
<td class="has-text-right">
<%= htmlFns.formatDollarsAsHTML(rowTotals.totalValue) %>
</td>
<td class="has-text-right">
<%= htmlFns.formatDollarsAsHTML(rowTotals.totalPrizes) %>
</td>
<td class="has-text-right">
<%= htmlFns.formatDollarsAsHTML(rowTotals.totalLicenceFee) %>
</td>
</tr>
<%
}
%>
</tbody>
<tfoot>
<tr>
<td></td>
<th class="has-text-right">
<%= ticketTypeGrandTotals.totalUnits %>
</th>
<th class="has-text-right">
<%- htmlFns.formatDollarsAsHTML(ticketTypeGrandTotals.totalValue) %>
</th>
<th class="has-text-right">
<%- htmlFns.formatDollarsAsHTML(ticketTypeGrandTotals.totalPrizes) %>
</th>
<th class="has-text-right">
<%- htmlFns.formatDollarsAsHTML(ticketTypeGrandTotals.totalLicenceFee) %>
</th>
</tr>
</tfoot>
</table>
</div>
<% } %>
<div class="panel">
<div class="panel-heading">
<div class="level">
<div class="level-left">
<h2 class="has-text-weight-bold">Transactions</h2>
</div>
<div class="level-right has-text-weight-normal has-text-right is-hidden-print">
<a class="button is-small" href="<%= urlPrefix %>/reports/transactions-byLicence?licenceID=<%= licence.licenceID %>" download>
<span class="icon"><i class="fas fa-file-download" aria-hidden="true"></i></span>
<span>Export Transactions</span>
</a>
</div>
</div>
</div>
<% if (licence.licenceTransactions.length === 0) { %>
<div class="panel-block is-block">
<div class="message is-warning">
<p class="message-body">
No transactions have been recorded for this licence.
</p>
</div>
</div>
<% } else { %>
<table class="table is-fullwidth">
<thead>
<tr>
<th>Date</th>
<th class="has-text-right">Amount</th>
<th><%= configFunctions.getProperty("licences.externalReceiptNumber.fieldLabel") %></th>
<th>Note</th>
</tr>
</thead>
<tbody>
<%
let transactionTotal = 0;
for (let index = 0; index < licence.licenceTransactions.length; index += 1) {
const transactionObj = licence.licenceTransactions[index];
transactionTotal += transactionObj.transactionAmount;
%>
<tr>
<td><%= transactionObj.transactionDateString %></td>
<td class="has-text-right">
$<%= transactionObj.transactionAmount.toFixed(2) %>
</td>
<td><%= transactionObj.externalReceiptNumber %></td>
<td class="has-newline-chars"><%= transactionObj.transactionNote %></td>
</tr>
<%
}
%>
</tbody>
<tfoot>
<tr>
<td></td>
<td class="has-text-right has-text-weight-bold">
$ <span id="licence--transactionTotal"><%= transactionTotal.toFixed(2) %></span>
<% if (licence.licenceFee !== transactionTotal) { %>
<br />
<span class="is-size-7 has-text-danger">
$<%= (licence.licenceFee - transactionTotal).toFixed(2) %> discrepancy
</span>
<% } %>
</td>
<td></td>
<td></td>
</tr>
</tfoot>
</table>
<% } %>
</div>
</div>
</div>
<%- include('_footerA'); -%>
<script src="<%= urlPrefix %>/javascripts/licence-viewEdit.min.js"></script>
<%- include('_footerB'); -%>