Files
CRM/MonitoringVpBCTotal.php
BACHIR SOULDI 2794e62571 first commit
2025-09-28 08:49:37 +01:00

249 lines
7.1 KiB
PHP

<?php
$dbvp = true;
require_once 'MonitoringVMHeader.php';
require_once 'MonitoringDBRequest.php';
$userId = $current_user->get('id');
if(isTopDG($roleid)){$roleid="H10";}
if(isset($_POST['year']))
$year = $_POST['year'];
$result = getResultatBCTotal($year,$roleid ,$userId);
echo getMonitoringMainBarVP(1).
'<div class="main-container main-container-Accounts">
<div id="scrollbar" style="margin:15px 15px 15px 15px; border:1px solid #ecf0f1; overflow-y: scroll; overflow-x: scroll; height:462.709px ;border:1px solid #bdc3c7;">'.
getTopTextSelect('Total des bons de commande crée en', $year).
'<hr>
<div class="form-row">
<div class="form-group col-md-4">
<label for="inputCity">Nom & Prénom</label>
<input class="form-control mb-4 w-20" type="text" name="nomprenom" placeholder="Rechercher" onKeyUp="fullNameChange(this)">
</div>'.getRegionSelectSubmit($roleid,false).getRolesSelectVP().'
</div>';
echo '<table id="tabcenter" class="table table-bordered table-striped" >
<tr class="center borderline">
<th id="role" >Post</th>
<th id="region">Region</th>
<th id="fullname" > Nom & Prenom</th>
<th> janvier</th>
<th> février</th>
<th> mars</th>
<th>avril</th>
<th> mai</th>
<th>juin</th>
<th>juillet</th>
<th>août</th>
<th>septembre</th>
<th>octobre</th>
<th>novembre</th>
<th>décembre</th>
<th>Total</th>
</tr>
</table>
</div></div>';
$viewer->view('CustomDashboardFooter.tpl');
?>
<script>
function convertArray(data)
{
var a=[];
var c=[];
if(data.length > 0) {
for(var i = 0; i < data.length; i++) {
var row = data[i];
if(row['month'] !== null && row['bc'] !== null){
if(a.indexOf(row[0]) == -1){
var b=[0,0,0,0,0,0,0,0,0,0,0,0,0,'',''];
a.push(row[0]);
b[0]=row[0];
b[row['month']]=parseFloat(row['bc']);
setJobRegion(b, row['role']);
c[a.length-1]=b;
} else{
b[row['month']]=parseFloat(row['bc']);
setJobRegion(b, row['role']);
c[a.length-1]=b;
}
}else{
var b=[0,0,0,0,0,0,0,0,0,0,0,0,0,'',''];
a.push(row[0]);
b[0]=row[0];
setJobRegion(b, row['role']);
c[a.length-1]=b;
}
}
}
return c
}
function fullNameChange(e) {
document.getElementById("role").value = "All";
document.getElementById("region").value = "All";
var res = result.filter(a => a.fullname.toUpperCase().includes(e.value.toUpperCase()) );
loadTable(convertArray(res));
}
function loadTable(data)
{
$('#tabcenter tr').slice(1).remove();
if(data.length > 0) {
for(var i = 0; i < data.length; i++) {
var row = data[i];
var click = "";
var cellTotal = parseInt(row[1]+row[2]+row[3]+row[4]+row[5]+row[6]+row[7]+row[8]+row[9]+row[10]+row[11]+row[12]);
$('#tabcenter').append(
"<tr class='center borderline'"+click+">"
+"<td>"+row[13]+"</td>"
+"<td>"+row[14]+"</td>"
+"<td >"+row[0]+"</td>"
+"<td>"+myFormatNumber(row[1])+"</td>"
+"<td>"+myFormatNumber(row[2])+"</td>"
+"<td>"+myFormatNumber(row[3])+"</td>"
+"<td>"+myFormatNumber(row[4])+"</td>"
+"<td>"+myFormatNumber(row[5])+"</td>"
+"<td>"+myFormatNumber(row[6])+"</td>"
+"<td>"+myFormatNumber(row[7])+"</td>"
+"<td>"+myFormatNumber(row[8])+"</td>"
+"<td>"+myFormatNumber(row[9])+"</td>"
+"<td>"+myFormatNumber(row[10])+"</td>"
+"<td>"+myFormatNumber(row[11])+"</td>"
+"<td>"+myFormatNumber(row[12])+"</td>"
+"<td style=' background:#7f8fa6; color: #ffffff; font-weight: bold;'>"+myFormatNumber(cellTotal)+"</td>"
+"</tr>"
);
}
var totals = [];
var allTotals = 0;
for (var i = 1; i < 13; i++) {
var sum = 0;
for(var j = 0; j < data.length; j++) {
var row = data[j];
sum += row[i];
}
totals.push(parseInt(sum));
allTotals += sum;
}
allTotals = parseInt(allTotals);
$('#tabcenter').append(
"<tr class='center borderline'"+click+">"
+"<td>TOTAL</td>"
+"<td></td>"
+"<td ></td>"
+"<td>"+myFormatNumber(totals[0])+"</td>"
+"<td>"+myFormatNumber(totals[1])+"</td>"
+"<td>"+myFormatNumber(totals[2])+"</td>"
+"<td>"+myFormatNumber(totals[3])+"</td>"
+"<td>"+myFormatNumber(totals[4])+"</td>"
+"<td>"+myFormatNumber(totals[5])+"</td>"
+"<td>"+myFormatNumber(totals[6])+"</td>"
+"<td>"+myFormatNumber(totals[7])+"</td>"
+"<td>"+myFormatNumber(totals[8])+"</td>"
+"<td>"+myFormatNumber(totals[9])+"</td>"
+"<td>"+myFormatNumber(totals[10])+"</td>"
+"<td>"+myFormatNumber(totals[11])+"</td>"
+"<td style=' background:#7f8fa6; color: #ffffff; font-weight: bold;'>"+myFormatNumber(allTotals)+"</td>"
+"</tr>"
);
}
}
var result = <?php echo json_encode($result); ?>;
function loadByFullName() {
// Converting objects to arrays using Array.prototype.slice.call
var fullnames = Array.prototype.slice.call(result).sort(function(a, b){
if(a.fullname < b.fullname) { return -1; }
if(a.fullname > b.fullname) { return 1; }
return 0;
});
loadTable(convertArray(fullnames));
}
roleChange("DELEGUE COMMERCIAL");
//filtre region
function regionChange(e) {
document.getElementById("role").value = "All";
var arrayFiltre;
arrayFiltre=convertArray(result);
var filteredValue = arrayFiltre.filter(function (item) {
return (item[14] === e);
});
if(e== "All"){filteredValue=arrayFiltre;}
loadTable(filteredValue);
}
//filtre Role
function roleChange(e) {
if(document.getElementById("region").options.length > 1)
document.getElementById("region").value = "All";
var arrayFiltre;
arrayFiltre=convertArray(result);
var filteredValue = arrayFiltre.filter(function (item) {
return (item[13] === e);
});
if(e== "All"){filteredValue=arrayFiltre;}
loadTable(filteredValue);
}
</script>
</body>
</html>