$(document).ready(function() {
//var base_url = "http://127.0.0.1/group/";
//--------------------forms params---------------------------
if( $('.has-datetimepicker').length )
{
$('.has-datetimepicker').datetimepicker({
inline: true,
sideBySide: true,
locale: 'fr',
format: 'YYYY-MM-DD LT',
});
}
if( $('.has-datepicker').length )
{
$('.has-datepicker').datetimepicker({
format: 'YYYY-MM-DD',
locale: 'fr'
});
}
if( $('.has-timepicker').length )
{
$('.has-timepicker').datetimepicker({
format : 'LT',
inline:true,
locale: 'fr'
});
}
function diff_hours(dt2, dt1)
{
var diff =(dt2.getTime() - dt1.getTime()) / 1000;
diff /= (60 * 60);
return Math.abs(Math.round(diff));
}
function inInterval(timeMin,date,timeMax,istime){
var debut=null;
var fin =null;
var time=null;
debut = new Date('1/1/1999 ' + timeMin);
fin = new Date('1/1/1999 ' + timeMax);
if(istime==true){
time= new Date('1/1/1999 ' + date);
}else{
time= new Date('1/1/1999 '+date.toLocaleTimeString());
}
return (debut<= time) && (fin >=time);
}
function isInTimeDemande(date){
console.log("d5aal");
var success=false;
$.post(base_url+"Ecritureplanning/IsInTimeDemande",{"date":date},function(data){
var response = JSON.parse(data);
success = (response.success>0)? true: false;
}).done(function(){
return success;
});
return success;
}
$("select").select2();
//--------------------------usual functions---------------------
function ChartEtat(uri,id,type=""){
$.get(base_url+uri,
function(data){
var pieChartCanvas = $('#'+id).get(0).getContext('2d');
var pieChart = new Chart(pieChartCanvas);
var PieData = JSON.parse(data);
var pieOptions = {
// Boolean - Whether we should show a stroke on each segment
segmentShowStroke : true,
// String - The colour of each segment stroke
segmentStrokeColor : '#fff',
// Number - The width of each segment stroke
segmentStrokeWidth : 1,
// Number - The percentage of the chart that we cut out of the middle
percentageInnerCutout: 50, // This is 0 for Pie charts
// Number - Amount of animation steps
animationSteps : 100,
// String - Animation easing effect
animationEasing : 'easeOutBounce',
// Boolean - Whether we animate the rotation of the Doughnut
animateRotate : true,
// Boolean - Whether we animate scaling the Doughnut from the centre
animateScale : false,
// Boolean - whether to make the chart responsive to window resizing
responsive : true,
// Boolean - whether to maintain the starting aspect ratio or not when responsive, if set to false, will take up entire container
maintainAspectRatio : false,
// String - A legend template
legendTemplate : '<ul class=\'<%=name.toLowerCase()%>-legend\'><% for (var i=0; i<segments.length; i++){%><li><span style=\'background-color:<%=segments[i].fillColor%>\'></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>',
// String - A tooltip template
tooltipTemplate : '<%=value %> '+type+' <%=label%> '
};
// Create pie or douhnut chart
// You can switch between pie and douhnut using the method below.
pieChart.Doughnut(PieData, pieOptions);
});
}
//**********conge forms-----------------------------------------
$('#dataconge').dataTable( {
"searching": true,
"paging": false,
"language":{
"url":base_url+"resources/data/French.json"
}
} );
if($("#exportcongeBtn").length){
$("#exportcongeBtn").click(function(){
window.open(base_url+"Conge/exportlist/"+$("#datedebutmodal").val().replace("/", "-").replace("/", "-")+"/"+$("#datefinmodal").val().replace("/", "-").replace("/", "-")+"/"+$("#typeconge_idmodal").val()+"/"+$("#etatmodal").val()+"/"+$("#usersmodal").val(), '_system', 'toolbar=no,location=yes, status=no, menubar=no');
});
}
if($('#pieChartConge').length){
var uri= "Conge/ChartEtat";
ChartEtat(uri,"pieChartConge","conge");
}
if($('#sendchartconge').length){
$("#sendchartconge").click(function(){
var uri = "Conge/ChartEtat/"+$("#datedebutchart").val().replace("/", "-").replace("/", "-")+"/"+$("#datefinchart").val().replace("/", "-").replace("/", "-");
ChartEtat(uri,"pieChartConge","conge");
});
}
if($('#sendallchartconge').length){
$("#sendallchartconge").click(function(){
var uri = "Conge/ChartEtat/";
ChartEtat(uri,"pieChartConge","conge");
});
}
$("#datedebut").on("dp.change", function (e) {
$('#firstdate').val($('#datedebut').val()+" 08:00");
$('#firstdatemsg').html($('#datedebut').val()+" 08:00");
});
$("#datefin").on("dp.change", function (e) {
$('#lastdate').val($('#datefin').val()+" 18:00");
$('#lastdatemsg').html($('#datefin').val()+" 18:00");
if($("#datedebut").val()==$("#datefin").val()){
$("#demijournefam").attr('disabled','true');
$("#demijournefpm").attr('disabled','true');
if($("#demijournedam").prop('checked')){
$("#lastdate").val($("#datefin").val()+" 12:00");
$("#lastdatemsg").html($("#datefin").val()+" 12:00");
}
if($("#demijournedpm").prop('checked')){
$("#lastdate").val($("#datefin").val()+" 18:00");
$("#lastdatemsg").html($("#datefin").val()+" 18:00");
}
}else{
$("#demijournefam").removeAttr('disabled');
$("#demijournefpm").removeAttr('disabled');
$("#demijournefpm").removeAttr('checked');
}
});
$("#demijournedam").click(function(){
if($(this).prop('checked')){
$("#firstdate").val($("#datedebut").val()+" 08:00");
$("#firstdatemsg").html($("#datedebut").val()+" 08:00");
if($("#datedebut").val()==$("#datefin").val()){
if($("#demijournedam").prop('checked')){
$("#lastdate").val($("#datefin").val()+" 12:00");
$("#lastdatemsg").html($("#datefin").val()+" 12:00");
}
if($("#demijournedpm").prop('checked')){
$("#lastdate").val($("#datefin").val()+" 18:00");
$("#lastdatemsg").html($("#datefin").val()+" 18:00");
}
}
}
});
$("#demijournedpm").click(function(){
if($(this).prop('checked')){
$("#firstdate").val($("#datedebut").val()+" 14:00");
$("#firstdatemsg").html($("#datedebut").val()+" 14:00");
if($("#datedebut").val()==$("#datefin").val()){
if($("#datedebut").val()==$("#datefin").val()){
if($("#demijournedam").prop('checked')){
$("#lastdate").val($("#datefin").val()+" 12:00");
$("#lastdatemsg").html($("#datefin").val()+" 12:00");
}
if($("#demijournedpm").prop('checked')){
$("#lastdate").val($("#datefin").val()+" 18:00");
$("#lastdatemsg").html($("#datefin").val()+" 18:00");
}
}
}
}
});
$("#demijournefam").click(function(){
if($(this).prop('checked')){
$("#lastdate").val($("#datefin").val()+" 12:00");
$("#lastdatemsg").html($("#datefin").val()+" 12:00");
}
});
$("#demijournefpm").click(function(){
if($(this).prop('checked')){
$("#lastdate").val($("#datefin").val()+" 18:00");
$("#lastdatemsg").html($("#datefin").val()+" 18:00");
if($("#datedebut").val()!=$("#datefin").val()){
$("#demijournefpm").removeAttr('checked');
}
}
});
function calculateConge(){
var data = $("#congefrm").serialize();
$.post(base_url+"Conge/CalculateService",data,function(respense){
alert(respense);
});
}
function checkForEmptyConge(){
var iserror=false;
var debut = new Date($("#firstdate").val());
var fin = new Date($("#lastdate").val());
if($("#typeconge_id").val()==0){
if(iserror==false){
iserror=true;
}
$("#typecongeerror").html("<p>Vous devez remplir ce champ</p>");
}else{
$("#typecongeerror").html("");
}
if($("#interim_id").val()==0){
if(iserror==false){
iserror=true;
}
$("#interimerror").html("<p>Vous devez remplir ce champ</p>");
}else{
if($("#interim_id").val() == $("#iduser").val()){
if(iserror==false){
iserror=true;
}
$("#interimerror").html("L'interim ne doit pas étre vous meme!");
}else{
$("#interimerror").html("");
}
}
if($("#description").val()==""){
if(iserror==false){
iserror=true;
}
$("#descriptionerror").html("<p>Vous devez remplir ce champ</p>");
}else{
$("#descriptionerror").html("");
}
if(debut>fin){
if(iserror==false){
iserror=true;
}
$("#debuterror").html("<p>Date debut doit étre inférieur ou égal à la date de fin</p>");
$("#finerror").html("<p>Date fin doit étre supérieur ou égal à la date de debut</p>");
}else{
$("#debuterror").html("");
}
return iserror;
}
if($("#sendconge").length){
$("#sendconge").click(function(){
if(checkForEmptyConge()==false){
$("#congefrm").submit();
}else{
$("#alerttime").show();
checkForEmptyConge();
}
});
}
//---------mission forms-------------------------------------
var tableMission= $('#datamission').dataTable( {
//"autoWidth": true,
"order": [[ 0, 'desc' ]],
"searching": true,
"paging": false,
"scrollX": true,
"language":{
"url":base_url+"resources/data/French.json"
}
} );
if($("#exportmissionBtn").length){
$("#exportmissionBtn").click(function(){
window.open(base_url+"Mission/exportlist/"+$("#datedebutmodal").val().replace("/", "-").replace("/", "-")+"/"+$("#datefinmodal").val().replace("/", "-").replace("/", "-")+"/"+$("#typemission_idmodal").val()+"/"+$("#etatmodal").val()+"/"+$("#usersmodal").val(), '_system', 'toolbar=no,location=yes, status=no, menubar=no');
});
}
if($('#pieChartMission').length){
var uri= "Mission/ChartEtat";
ChartEtat(uri,"pieChartMission","mission");
}
if($('#sendchartmission').length){
$("#sendchartmission").click(function(){
var uri = "Mission/ChartEtat/"+$("#datedebutchart").val().replace("/", "-").replace("/", "-")+"/"+$("#datefinchart").val().replace("/", "-").replace("/", "-");
ChartEtat(uri,"pieChartMission","mission");
});
}
if($('#sendallchartmission').length){
$("#sendallchartmission").click(function(){
var uri = "Mission/ChartEtat/";
ChartEtat(uri,"pieChartMission","mission");
});
}
function checkForEmptyMission(){
var iserror=false;
var debut = new Date($("#datedebut").val());
var debutminutes = debut.getMinutes();
var debuthours = debut.getHours();
var tempdebut = (debuthours+":"+debutminutes);
var fin = new Date($("#datefin").val());
var finminutes = fin.getMinutes();
var finhours = fin.getHours();
var tempfin = (finhours+":"+finminutes);
if($("#interim_id").val()==0){
if(iserror==false){
iserror=true;
}
$("#interimerror").html("<p>Vous devez remplir ce champ</p>");
}else{
if($("#interim_id").val() == $("#iduser").val()){
if(iserror==false){
iserror=true;
}
$("#interimerror").html("L'interim ne doit pas étre vous meme!");
}else{
$("#interimerror").html("");
}
}
if($("#objetmission_id").val()==0){
if(iserror==false){
iserror=true;
}
$("#objetmissionerror").html("<p>Vous devez remplir ce champ</p>");
}else{
$("#objetmissionerror").html("");
}
if($("#typemission_id").val()==0){
if(iserror==false){
iserror=true;
}
$("#typemissionerror").html("<p>Vous devez remplir ce champ</p>");
}else{
$("#typemissionerror").html("");
}
if($("#transport_id").val()==0){
if(iserror==false){
iserror=true;
}
$("#transporterror").html("<p>Vous devez remplir ce champ</p>");
}else{
$("#transporterror").html("");
}
if($("#description").val()==""){
if(iserror==false){
iserror=true;
}
$("#descriptionerror").html("<p>Vous devez remplir ce champ</p>");
}else{
$("#descriptionerror").html("");
}
if($("#destination").val()==""){
if(iserror==false){
iserror=true;
}
$("#destinationerror").html("<p>Vous devez remplir ce champ</p>");
}else{
$("#destinationerror").html("");
}
if(debut>=fin){
if(iserror==false){
iserror=true;
}
$("#debuterror").html("<p>Date debut doit étre inférieur ou égal à la date de fin</p>");
$("#finerror").html("<p>Date fin doit étre supérieur ou égal à la date de debut</p>");
}else{
var intimedebut = inInterval("08:00",debut,"18:00",false);
var intimefin = inInterval("08:00",fin,"18:00",false);
var outtimedebut = inInterval("12:01",debut,"13:59",false);
var outtimefin=inInterval("12:01",fin,"13:59",false);
/*if((intimedebut==false || intimefin==false) || (outtimedebut==true || outtimefin==true)){
if(iserror==false){
iserror=true;
}
$("#debuterror").html("<p>il faut respecter les interval de temps considérant la pause et le temps de travail.</p>");
$("#finerror").html("<p>il faut respecter les interval de temps considérant la pause et le temps de travail.</p>");
}else{
$("#debuterror").html("");
}*/
$("#debuterror").html("");
}
return iserror;
}
if($("#sendmission").length){
$("#sendmission").click(function(){
if(checkForEmptyMission()==false){
$("#missionfrm").submit();
}else{
$("#alerttime").show();
}
});
}
//---------autoriation forms--------------------------------------
$('#dataautorisation').dataTable( {
"searching": true,
"paging": false,
"language":{
"url":base_url+"resources/data/French.json"
}
} );
if( parseFloat($("#soldeconsomme").val())>=parseFloat($("#solde").val()) ){
$("#alertsolde").show();
$("#alertsolde").html(" Vous avez dépassé le solde plafond d'autorisation.<br> il vous reste "+Math.round(parseFloat($("#solde").val())-parseFloat($("#soldeconsomme").val()))+"Heur(s)" );
}
if($("#datedemande").length){
$("#datedemande").on("dp.change", function (e) {
$('#lastdate').val($('#datedemande').val()+" "+$('#heursdebut').val());
$('#firstdate').val($('#datedemande').val()+" "+$('#heursfin').val());
});
$("#heursdebut").on("dp.change", function (e) {
$('#lastdate').val($('#datedemande').val()+" "+$('#heursdebut').val());
$('#firstdate').val($('#datedemande').val()+" "+$('#heursfin').val());
});
$("#heursfin").on("dp.change", function (e) {
$('#lastdate').val($('#datedemande').val()+" "+$('#heursdebut').val());
$('#firstdate').val($('#datedemande').val()+" "+$('#heursfin').val());
});
}
function checkForEmptyAutorisation(){
var iserror=false;
var debut = new Date('1/1/1999 ' + $("#heursdebut").val());
var fin = new Date('1/1/1999 ' + $("#heursfin").val());
var demande = new Date($("#datedemande").val());
var debutminutes = debut.getMinutes();
var debuthours = debut.getHours();
var tempdebut = (debuthours+":"+debutminutes);
var finminutes = fin.getMinutes();
var finhours = fin.getHours();
var tempfin = (finhours+":"+finminutes);
if( parseFloat($("#soldeconsomme").val())>=parseFloat($("#solde").val()) ){
if(iserror==false){
iserror=true;
}
$("#alertsolde").show();
$("#alertsolde").html(" Vous avez dépassé le solde plafond d'autorisation.");
}else{
$("#alertsolde").hide();
}
if($("#transport_id").val()==0){
if(iserror==false){
iserror=true;
}
$("#transporterror").html("<p>Vous devez remplir ce champ</p>");
}else{
$("#transporterror").html("");
}
if($("#datedemande").val()==""){
if(iserror==false){
iserror=true;
}
$("#datedemandeerror").html("<p>Vous devez remplir ce champ</p>");
}else{
var now = new Date();
/*if(demande.getDate()<now.getDate() ){
if(iserror==false){
iserror=true;
}
$("#datedemandeerror").html("<p>Date de demande ne doit pas être inferieur à la date de création</p>");
}else{
$("#datedemandeerror").html("");
}*/
$("#datedemandeerror").html("");
}
if($("#objetautorisation_id").val()==0){
if(iserror==false){
iserror=true;
}
$("#objetautorisationerror").html("<p>Vous devez remplir ce champ</p>");
}else{
$("#objetautorisationerror").html("");
}
if($("#description").val()==""){
if(iserror==false){
iserror=true;
}
$("#descriptionerror").html("<p>Vous devez remplir ce champ</p>");
}else{
$("#descriptionerror").html("");
}
if(fin<=debut){
if(iserror==false){
iserror=true;
}
$("#debuterror").html("<p>Heure debut doit étre inférieur ou égal à la Heure de fin</p>");
$("#finerror").html("<p>Heure fin doit étre supérieur ou égal à la Heure de debut</p>");
}else{
if(diff_hours(fin,debut)>2 ){
if(iserror==false){
iserror=true;
}
$("#finerror").html("<p>Vous êtes autoriser pour 2H d'autorisation seulement</p>");
var intimedebut = inInterval("08:00",debut,"18:00",false);
var intimefin = inInterval("08:00",fin,"18:00",false);
var outtimedebut = inInterval("12:00",debut,"14:00",false);
var outtimefin=inInterval("12:00",fin,"14:00",false);
if((intimedebut==false || intimefin==false) || (outtimedebut==true || outtimefin==true)){
/*if(iserror==false){
iserror=true;
}
$("#debuterror").html("<p>il faut respecter les interval de temps considérant la pause et le temps de travail.</p>");
$("#finerror").html("<p>il faut respecter les interval de temps considérant la pause et le temps de travail.</p>");*/
}
}else{
$("#finerror").html("");
}
}
return iserror;
}
if($("#sendautorisation").length){
$("#sendautorisation").click(function(){
if(checkForEmptyAutorisation()==false){
$("#autorisationfrm").submit();
}else{
$("#alerttime").show();
}
});
}
if($("#exportautorisationBtn").length){
$("#exportautorisationBtn").click(function(){
window.open(base_url+"Autorisation/exportlist/"+$("#datedebutmodal").val().replace("/", "-").replace("/", "-")+"/"+$("#datefinmodal").val().replace("/", "-").replace("/", "-")+"/"+$("#objetautorisation_idmodal").val()+"/"+$("#etatmodal").val()+"/"+$("#usersmodal").val(), '_system', 'toolbar=no,location=yes, status=no, menubar=no');
});
}
if($('#pieChartAutorisation').length){
var uri= "Autorisation/ChartEtat";
ChartEtat(uri,"pieChartAutorisation","autorisation");
}
if($('#sendchartautorisation').length){
$("#sendchartautorisation").click(function(){
var uri = "Autorisation/ChartEtat/"+$("#datedebutchart").val().replace("/", "-").replace("/", "-")+"/"+$("#datefinchart").val().replace("/", "-").replace("/", "-");
ChartEtat(uri,"pieChartAutorisation","autorisation");
});
}
if($('#sendallchartautorisation').length){
$("#sendallchartautorisation").click(function(){
var uri = "Autorisation/ChartEtat/";
ChartEtat(uri,"pieChartAutorisation","autorisation");
});
}
//---------affectation forms--------------------------------------
$('#dataaffectation').dataTable( {
"searching": true,
"paging": false,
"language":{
"url":base_url+"resources/data/French.json"
}
} );
if($("#sendaffectation").length){
$("#sendaffectation").click(function(){
if($("#frmaffectation")[0].checkValidity() ){
$("#frmaffectation").submit();
}else{
$("#alerttime").show();
}
});
}
//---------contrat forms-------------------------------------
$('#datacontrat').dataTable( {
"searching": true,
"paging": false,
"language":{
"url":base_url+"resources/data/French.json"
}
} );
if($("#sendcontrat").length){
$("#sendcontrat").click(function(){
if($("#frmcontrat")[0].checkValidity()){
$("#frmcontrat").submit();
}else{
$("#alerttime").show();
}
});
}
//---------user forms-------------------------------------
if($('#datausers').length){
$('#datausers').dataTable( {
"searching": true,
"paging": false,
"language":{
"url":base_url+"resources/data/French.json"
}
} );
}
if($("#senduser").length){
$("#senduser").click(function(){
if($("#frmuser")[0].checkValidity()){
$("#frmuser").submit();
}else{
$("#alerttime").show();
}
});
}
//---------typemission forms-------------------------------------
if($("#sendtypemission").length){
$("#sendtypemission").click(function(){
if($("#frmtypemission")[0].checkValidity()){
$("#frmtypemission").submit();
}else{
$("#alerttime").show();
}
});
}
//---------notification forms-------------------------------------
if($("#notifyto_id").length){
$.get(base_url+"User/getForList",function(data){
$("#notifyto_id").select2({
data: JSON.parse(data)
});
});
$.get(base_url+"User/getForListCustom",function(data){
$("#usersubmited_id").select2({
data: JSON.parse(data)
});
});
}
//-----------Access Part ---------------------------
if($("#ligneacce").length){
$('#ligneacce').DataTable();
}
if($("#module").length){
$.get(base_url+"Ligneacce/getForListModule",function(data){
$("#module").select2({
data: JSON.parse(data)
});
});
}
if($("#action").length){
$.get(base_url+"Ligneacce/getForListAction",function(data){
$("#action").select2({
data: JSON.parse(data)
});
});
}
if($("#userrole").length){
$.get(base_url+"User/getForList",function(data){
$("#userrole").select2({
data: JSON.parse(data)
});
});
}
if($("#sendaccess").length){
$("#sendaccess").click(function(){
if($("#frmacces")[0].checkValidity()){
$("#frmacces").submit();
}else{
$("#alerttime").show();
}
});
}
if($("#repartition").length){
$("#repartition").click(function(){
$.get(
base_url+"planning/getIntervalDate/"+$("#plan").val(),
function (data){
$("#repartContent").html(data);
}
).done(function(){
if( $('.has-timepicker').length )
{
$('.has-timepicker').datetimepicker({
format : 'LT',
inline:true,
locale: 'fr'
});
}
/*$("#btnRepartition").click(function(){
var rows= parseInt($('#rownumber').val());
for(var i=0;i<rows;i++){
var items= $('#frmRepartition'+i).serializeArray();
console.log(items);
var send={
"jour":items[0].value,
"tempdebut":items[1].value,
"tempfin":items[2].value,
"pausedebut":items[3].value,
"pausefin":items[4].value,
"type":items[7].value,
"planning_id":1,
}
$.post(base_url+"planning/addecriture",send,function(){
});
}
});*/
});
});
}
//-----------------------planning------------------------------
/*$("#plusitem").click(function(){
$("#timeline").append($(".itemline:first-child").clone());
});
/*$("#timeline .itemline>.moinitem").click(function(){
});
$(document).on('click', '.moinitem', function () {
$(this).parent().parent().remove();
});*/
});