Share Weight Pay Calculator
This calculates the pay by share for IGAIR crew members
by Stephen Katulka
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.min.js"></script>
<script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/ui-lightness/jquery-ui.css">
<script src="https://code.jquery.com/ui/1.11.3/jquery-ui.min.js"></script>
<h1>IGAIR Mission Pay Calculator</h1>
<form id="payform">
<h3>Revenue</h3>
<label for="revenue">Total Mission Revenue</label> <input type="text" name="revenue" class="number totalRevenue" value="500000"/>
<hr/>
<h3>Expenses</h3>
<label for="expenses">Total Mission Expenses</label> <input type="text" name="expenses" class="number totalExpenses" value="130000"/>
<hr/>
<h3>Crew Compensation</h3>
<table class="crew">
<thead>
<tr>
<td>Divisible Profit</td>
<td class="number totalProfit">0</td>
<td colspan="5"></td>
</tr>
<tr>
<th>Shares</th>
<th>Pay Amount</th>
<th>Name</th>
<th>Rank</th>
<th>Cert Level</th>
<th>Bonuses</th>
<th></th>
</tr>
</thead>
<tbody id="crewRows" class="crewEntries">
</tbody>
<tfoot>
<tr class="subtotal">
<td><input type="text" value="3" size="2" class="shares totalShares" disabled="disabled"/></td>
<td class="number perShareAmount">0</td>
<td colspan="4">Per Share</td>
<td>
<a href="#" class="addMember ui-button ui-button-text-only"><span class="ui-icon ui-icon-plusthick"></span></a>
</td>
</tr>
<tr class="crewEntry"><td><input type="text" name="shares" size="2" class="shares rowTotal" value="2" disabled="disabled"/></td><td class="number payAmount">0</td><td colspan="5">Ship Owner</td></tr>
<tr class="igairProfit"><td><input type="text" id="igair_shares" name="shares" class="shares" size="2" value="1" disabled="disabled"/></td><td class="number igairAmount">0</td><td colspan="5">IGAIR...
CSS
.template {
display:none;
}
table.crew {
width:100%;
}
.rightJustify {
text-align:right;
}
input.shares, .number {
text-align:right;
padding-right:5px;
}
.number::after {
content:' UEC';
}
tr.subtotal {
background-color:#ddd;
}
tbody.crewEntries tr.crewEntry.even {
background:#fff;
}
td.extras span.oneline {
display:block;
}
.ui-button.removeRow {
border:0px;
border-radius:5px;
padding:2px;
background:#B31F24;
}
.ui-button.addMember {
border:0px;
border-radius:5px;
padding:2px;
background:#3CA734;
}
.igairProfit {
background:#eee;
}
JavaScript
var crewTemplateSource = $("#crew_template").html();
var crewTemplate = Handlebars.compile(crewTemplateSource);
var calculate = function(){
var calcShares = 0, igairShares = 0, revenue = 0, expenses = 0, profit = 0, perShare = 0, igairAmount = 0;
revenue = parseInt($(".totalRevenue").val());
expenses = parseInt($(".totalExpenses").val());
profit = revenue - expenses;
igairAmount = profit;
$(".totalProfit").html(profit.toLocaleString());
$(".rowTotal").each(function(){
var s = parseInt($(this).val());
calcShares += s;
});
igairShares = Math.ceil(calcShares / 10);
//alert("Shares found: " + calcShares + ", calculated " + igairShares + " shares for IGAIR");
$("#igair_shares").val(igairShares);
calcShares += igairShares;
$(".totalShares").val(calcShares);
perShare = Math.floor(profit / calcShares);
$(".perShareAmount").html(perShare.toLocaleString());
$(".crewEntry").each(function(){
var payAmount = 0, shares = 0;
shares = parseInt($(this).find(".shares").val());
payAmount = perShare * shares;
igairAmount -= payAmount;
$(this).find(".payAmount").html(payAmount.toLocaleString());
});
$(".igairAmount").html(igairAmount.toLocaleString());
};
$(".addMember").click(function(){
var crewNumber = $("#crewRows tbody tr").size()
var crewRow = crewTemplate();
$("#crewRows").append(crewTemplate());
calculate();
$("tbody.crewEntries tr.crewEntry").removeClass("even");
$("tbody.crewEntries tr.crewEntry:even").addClass("even");
});
var calculateRow = function(){
var shares = 0;
var row = $(this).closest("tr.crewEntry");
$(row).find("select.shareAmount option:selected, input:checkbox:checked.shareAmount, input:radio[name=missionCommander]:checked").each(function(){
var s = parseInt($(this).val());
shares += s;
});
$(row).find(".rowTotal").val(shares);
calculate();
}
$(document).on("change", "select.shareAmount", calculateRow);
$(document).on("click",...