-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
191 lines (163 loc) · 7.86 KB
/
index.php
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
<!DOCTYPE html>
<html>
<head>
<title>EDI DNT</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<style>
.card {
margin: 0 auto;
margin-top: 30px;
max-width: 400px;
}
.centered-image {
display: block;
margin: 0 auto;
text-align: center;
}
</style>
</head>
<body>
<div class="container">
<div class="centered-image mt-5">
<img src="./files/icon-cafat.png" alt="Logo Cafat" width="200px">
</div>
<div class="card">
<div class="card-body">
<h2 class="card-title">Génération XML</h2>
<form action="traitement.php" method="POST" onsubmit="return generateXML()">
<div class="form-group">
<label for="periode">Période:</label>
<select class="form-control" id="periode" name="periode" onchange="showDateFields()">
<option value="">Choisir une période</option>
<option value="mensuel">Mensuel</option>
<option value="trimestriel">Trimestriel</option>
<option value="annuel">Annuel</option>
</select>
</div>
<div id="dateFields" style="display: none;">
<!-- The date fields will be dynamically added here -->
</div>
<button type="submit" class="btn btn-primary">Générer</button>
</form>
</div>
</div>
</div>
<script>
function showDateFields() {
var periode = document.getElementById("periode").value;
var dateFields = document.getElementById("dateFields");
// Reset the date fields with each period change
dateFields.innerHTML = "";
if (periode === "mensuel") {
// Create the mensuelly date form (mensuel and annuel)
var mensuelInput = document.createElement("input");
mensuelInput.setAttribute("type", "number");
mensuelInput.setAttribute("class", "form-control mb-3");
mensuelInput.setAttribute("placeholder", "Mois");
mensuelInput.setAttribute("name", "mensuel");
mensuelInput.setAttribute("required", "required");
mensuelInput.setAttribute("min", "1");
mensuelInput.setAttribute("max", "12");
var annuelInput = document.createElement("input");
annuelInput.setAttribute("type", "number");
annuelInput.setAttribute("class", "form-control mb-3");
annuelInput.setAttribute("placeholder", "Année");
annuelInput.setAttribute("name", "annuel");
annuelInput.setAttribute("required", "required");
annuelInput.setAttribute("min", "1900");
annuelInput.setAttribute("max", "2100");
dateFields.appendChild(mensuelInput);
dateFields.appendChild(annuelInput);
} else if (periode === "trimestriel") {
// Create the quarterly selection form
var trimestrielSelect = document.createElement("select");
trimestrielSelect.setAttribute("class", "form-control mb-3");
trimestrielSelect.setAttribute("name", "trimestriel");
trimestrielSelect.setAttribute("required", "required");
var trimestriels = ["Trimestre 1", "Trimestre 2", "Trimestre 3", "Trimestre 4"];
var trimestrielValues = ["01", "02", "03", "04"];
for (var i = 0; i < trimestriels.length; i++) {
var option = document.createElement("option");
option.value = trimestrielValues[i];
option.text = trimestriels[i];
trimestrielSelect.appendChild(option);
}
var annuelInput = document.createElement("input");
annuelInput.setAttribute("type", "number");
annuelInput.setAttribute("class", "form-control mb-3");
annuelInput.setAttribute("placeholder", "Année");
annuelInput.setAttribute("name", "annuel");
annuelInput.setAttribute("required", "required");
annuelInput.setAttribute("min", "1900");
annuelInput.setAttribute("max", "2100");
dateFields.appendChild(trimestrielSelect);
dateFields.appendChild(annuelInput);
} else if (periode === "annuel") {
// Create the date picker for a annuel
var annuelInput = document.createElement("input");
annuelInput.setAttribute("type", "number");
annuelInput.setAttribute("class", "form-control mb-3");
annuelInput.setAttribute("placeholder", "Année");
annuelInput.setAttribute("name", "annuel");
annuelInput.setAttribute("required", "required");
annuelInput.setAttribute("min", "1900");
annuelInput.setAttribute("max", "2100");
dateFields.appendChild(annuelInput);
}
// Display the date fields
dateFields.style.display = "block";
}
function generateXML() {
var periode = document.getElementById("periode").value;
if (periode === "mensuel") {
var mensuel = document.getElementsByName("mensuel")[0].value;
var annuel = document.getElementsByName("annuel")[0].value;
// Validate the mensuel and annuel values (add additional conditions if necessary)
if (mensuel < 1 || mensuel > 12) {
alert("Mois invalide");
return false;
}
if (annuel < 1900 || annuel > 2100) {
alert("Année invalide");
return false;
}
} else if (periode === "trimestriel") {
var trimestriel = document.getElementsByName("trimestriel")[0].value;
var annuel = document.getElementsByName("annuel")[0].value;
// Validate the values of the quarter and the annuel (add additional conditions if necessary)
// Here, we validate only if the annuel is a 4-digit number
if (!annuel.match(/^\d{4}$/)) {
alert("Année invalide");
return false;
}
}
// Generate the XML file name
var fileName = generateFileName(periode, annuel, mensuel, trimestriel);
// Submit the form with the XML file name
document.getElementById("xmlFileName").value = fileName;
return true;
}
function generateFileName(periode, annuel, mensuel, trimestriel) {
var prefix = "DN-";
var periodeType = "";
var periodeNumber = "";
if (periode === "mensuel") {
periodeType = "M";
periodeNumber = ("0" + mensuel).slice(-2);
} else if (periode === "trimestriel") {
periodeType = "T";
periodeNumber = trimestriel.split("-")[0];
} else if (periode === "annuel") {
periodeType = "A";
periodeNumber = "01";
}
var compteEmployeur = "1234567";
var suffixeCompteEmployeur = "890";
var numeroUnique = "001";
var extension = ".xml";
var fileName = prefix + annuel + periodeType + periodeNumber + "-" + compteEmployeur + suffixeCompteEmployeur + "-" + numeroUnique + extension;
return fileName;
}
</script>
</body>
</html>