-
Notifications
You must be signed in to change notification settings - Fork 1
/
Contrats.html
195 lines (178 loc) · 7.49 KB
/
Contrats.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
---
layout: default
---
<div class="home">
<header class="post-header">
<h1 class="post-title">Contrats</h1>
</header>
<ul class="pure-u-1" id="contractUl">Loading...</ul>
<fieldset style="display: none" id="contractDetailsFieldset">
<legend>Details</legend>
<p class="pure-u-1"><span id="contractTypeSpan"></span> du <span id="contractFromSpan"></span> au <span id="contractToSpan"></span></p>
<fieldset style="margin-bottom:1em;">
<legend>Salaire</legend>
<div class="pure-u-1">
<p class="pure-u-1-3">Brut : <span id="salaryGrossSpan"></span></p>
<p class="pure-u-1-3">Net : <span id="salarySpan"></span></p>
<p class="pure-u-7-24" style="text-align:right">Super Brut : <span id="salarySGrossSpan"></span></p>
</div>
<div class="pure-u-1">
<p class="pure-u-1-2">Mutuelle et prévoyance : <span id="insuranceSpan"></span></p>
<p class="pure-u-11-24" style="text-align:right">Charge de fonctionnement : <span id="taxSpan"></span></p>
</div>
<div class="pure-u-1">
<p class="pure-u-2-3">Durée : <span id="timeSpan"></span></p>
<p class="pure-u-7-24" style="text-align:right">Total : <span class="amount" id="totalSpan"></span></p>
</div>
</fieldset>
<p class="pure-u-2-5" style="font-style:italic;">Demandé par <span id="contractClaimantSpan"></span></p>
<ul class="pure-u-7-12" style="list-style-type: none; margin-left:0px" id="contractSignaturesUl"></ul>
</fieldset>
</div>
<script>
function monthDiff(d1, d2) {
var months;
months = (d2.getFullYear() - d1.getFullYear()) * 12;
months -= d1.getMonth() + 1;
months += d2.getMonth();
return (months <= 0 ? 0 : months) + 2;
}
const avatars = new Avatars(Avatars.sprites.identicon);
window.onload = () => {
getContent('Contrats')
.then(contract => {
const contractUl = document.getElementById('contractUl');
contractUl.textContent = '';
contract.forEach(c => {
if(c.name.endsWith('.json')) {
const cLi = document.createElement('li');
const cA = document.createElement('a');
cA.href = `#${c.name}`;
cA.textContent = c.name;
cLi.appendChild(cA);
contractUl.appendChild(cLi);
}
})
if(location.hash.substr(1) !== '') {
return loadContract();
}
})
};
function b64DecodeUnicode(str) {
return decodeURIComponent(Array.prototype.map.call(atob(str), function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)
}).join(''))
}
function loadContract() {
const contractName = location.hash.substr(1);
let signatures = {};
let members;
let contractSha;
let contract = {};
getContent(`Contrats/${contractName}`)
.then(c => {
contractSha = c.sha;
contract = JSON.parse(b64DecodeUnicode(c.content));
const contractDetailsFieldset = document.getElementById('contractDetailsFieldset');
contractDetailsFieldset.style.display = 'block';
const contractClaimantSpan = document.getElementById('contractClaimantSpan');
contractClaimantSpan.textContent = contract.claimant;
const contractTypeSpan = document.getElementById('contractTypeSpan');
contractTypeSpan.textContent = contract.type;
const contractFromSpan = document.getElementById('contractFromSpan');
const fromDate = new Date(contract.from);
contractFromSpan.textContent = fromDate.toLocaleDateString('fr');
let time;
if(typeof(contract.to) !== 'undefined') {
const contractToSpan = document.getElementById('contractToSpan');
const toDate = new Date(contract.to);
contractToSpan.textContent = toDate.toLocaleDateString('fr');
time = monthDiff(fromDate, toDate);
const timeSpan = document.getElementById('timeSpan');
timeSpan.textContent = `${time} mois`;
} else {
time = 1;
}
const salaryGrossSpan = document.getElementById('salaryGrossSpan');
const salaryGross = contract.salary/100;
salaryGrossSpan.textContent = salaryGross.toLocaleString('fr', currency);
const salarySpan = document.getElementById('salarySpan');
const salary = contract.salary * (1 - 0.22) / 100;
salarySpan.textContent = salary.toLocaleString('fr', currency);
const salarySGrossSpan = document.getElementById('salarySGrossSpan');
const salarySGross = contract.salary * (1 + 0.43) / 100;
salarySGrossSpan.textContent = salarySGross.toLocaleString('fr', currency);
const insuranceSpan = document.getElementById('insuranceSpan');
insurance = 50;
insuranceSpan.textContent = insurance.toLocaleString('fr', currency);
const taxSpan = document.getElementById('taxSpan');
tax = 14;
taxSpan.textContent = tax.toLocaleString('fr', currency);
const totalSpan = document.getElementById('totalSpan');
const margin = 10/100;
const precarite = 10/100;
const total = salarySGross * time * (1 + precarite) * (1 + margin)
totalSpan.textContent = total.toLocaleString('fr', currency);
return getContent(`Contrats/${contractName}.sig`)
})
.then(sigFile => {
if(typeof(sigFile.content) !== 'undefined') {
signatures = JSON.parse(b64DecodeUnicode(sigFile.content));
}
return getMembers()
})
.then(rMembers => {
members = rMembers;
const keyPromises = [];
members.forEach(member => {
keyPromises.push(getKeys(member.login))
})
return Promise.all(keyPromises);
})
.then(keys => {
const signaturePromises = [];
members.forEach((member, i) => {
if(member.login in signatures) {
signaturePromises.push(verify(contractSha, keys[i], signatures[member.login]));
} else {
signaturePromises.push(Promise.resolve(false));
}
})
return Promise.all(signaturePromises);
})
.then(verifications => {
const contractSignaturesUl = document.getElementById('contractSignaturesUl');
contractSignaturesUl.style['border'] = '1px solid black';
members.forEach((member, i) => {
const loginLi = document.createElement('li')
loginLi.className = 'pure-u-1';
loginLi.style['padding'] = '0.5em';
loginLi.style['line-height'] = '60px';
loginLi.style['font-weight'] = '600';
if(verifications[i]) {
const signImg = document.createElement('img');
signImg.width = 50;
const svg = avatars.create(signatures[member.login]);
const svgUri = `data:image/svg+xml;base64,${btoa(svg)}`;
signImg.src = svgUri;
const signP = document.createElement('span');
signP.className = 'pure-u-4-5';
signP.textContent = `Valid signature by ${member.login}`;
loginLi.style.color = '#77ce44';
loginLi.appendChild(signP);
loginLi.appendChild(signImg);
} else {
if(member.login in signatures) {
loginLi.textContent = `Invalid signature by ${member.login}`;
loginLi.style.color = '#f95e5e';
}
else {
loginLi.textContent = `Not signed by ${member.login}`;
}
}
contractSignaturesUl.appendChild(loginLi);
})
})
}
window.onhashchange = loadContract;
</script>