//start job schedule
function nth(d) { if (d > 3 && d < 21) return 'th'; switch (d % 10) { case 1: return "st"; case 2: return "nd"; case 3: return "rd"; default: return "th"; } }
function dateToYMD(date) { var strArray=['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; var d = date.getDate(); var m = strArray[date.getMonth()]; var y = date.getFullYear(); return '' + (d <= 9 ? '0' + d : d) + '-' + m + '-' + y; }
Date.prototype.addDays = function(days) { var date = new Date(this.valueOf()); date.setDate(date.getDate() + days); return date; }
function pad(str) { return (" "+str).slice(-2) }
//var cnt = 0;
var dataSet = [];
function printNextPeriod(startDate, endDate, periodInDays,cnt) {
var numWorkDays = 0;
var currentDate = new Date(startDate);
var premises = "Innovation Building in DMC";
var Time = "Day";
var typeoftreatment = "Residual-spray / Dust / bait & Traps"
while (numWorkDays < periodInDays && currentDate <= endDate) {
currentDate = currentDate.addDays(1);
// Skips friday
if (currentDate.getDay() !== 5) {
numWorkDays++;
}
if (numWorkDays == periodInDays) {
numWorkDays = 0;
cnt++;
let date = dateToYMD(currentDate);
let pos = holidays.indexOf(date);
if (pos != -1) {
console.log("replace",date,"with",instead[pos])
date = instead[pos];
}
let treatment = pad(cnt) + nth(cnt) + (cnt == 1 ? " Basic" : " Control") + " Treatment"
dataSet.push([premises, typeoftreatment, treatment, date, Time])
}
}
}
var holidays = [];//assign holidays days here
var instead = [];
holidays.forEach((hol,i) => {
let d = new Date(hol);
let date = d.getDate() + 1
d.setDate(date); // next day (could be Weekend);
while (d.getDay() === 5) {
date++;
d.setDate(date); // is any day not friday ok?
}
instead.push(dateToYMD(d))
holidays[i] = dateToYMD(new Date(hol))
})
$('.jobshepest').on('shown.bs.modal', function (e) {
$('.examplejobshecdule').DataTable({
destroy: true,
data: dataSet,
columns: [
{ title: "Premises" },
{ title: "Type of treatment" },
{ title: "Frequency" },
{ title: "Date" },
{title: "Time"}],
order: [[2, "asc"]],
columnDefs: [
{ width: "23%", targets: 3 }
]
});
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link href="https://use.fontawesome.com/releases/v5.0.6/css/all.css" rel="stylesheet">
<link href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css" rel="stylesheet">
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<link rel="stylesheet" type="text/css" href="<?php echo base_url('/assets/demo/sam.css');?>" media="all"/>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/timepicker/1.3.5/jquery.timepicker.min.css">
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script src="http://code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/timepicker/1.3.5/jquery.timepicker.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.14.0/jquery.validate.min.js"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.6/umd/popper.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<!--<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>-->
<script src="<?php echo base_url('assets/demo/sam.js');?>"></script>
<div class="modal fade jobshepest" id="viewactipestmodal" role="document">
<div class="modal-dialog modal-lg" style="overflow-y: initial !important">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalschedulepest">schedule report pest</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<!-- <form id="newModalFormviewschedpest" name="viewschedulepest" role="form" autocomplete="off">
<fieldset disabled="disabled">
<div class="period" style="float:left; padding: 5px; text-align:right; font-family: monospace;" id="first">Date<hr/>
</div>
<div class="period" style="float:left; padding: 5px; text-align:right; font-family: monospace;" id="second">Frequency<hr/></div>
</fieldset>
</form>-->
<table id="examplejobshecdule" class="table table-striped table-bordered examplejobshecdule" style="width:100%">
<tfoot>
<tr>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</div>
<button onclick="printNextPeriod(new Date('2019-01-01'), new Date('2020-01-01'),26,0);" class="btn btn-success btn-sm actpest" data-target="#viewactipestmodal" data-keyboard="false" data-backdrop="static" data-toggle="modal">1st button</button>
<button onclick="printNextPeriod(new Date('2019-01-01'), new Date('2019-12-31'),15,0);" class="btn btn-success btn-sm actpest" data-target="#viewactipestmodal" data-keyboard="false" data-backdrop="static" data-toggle="modal">2nd button</button>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js"></script>
when i click the first button, popup modal will open and results will show (calling through calling a function) - 12 entries is there after closing the modal and try to click the 2nd button,
when second button clicks, another dates are passing in the argument- 20 entries is there. But the problem is 12+20=32 entries are showing up..ITs wrong..How to fix it??I need to show 12 entries for the 1st button clicks and 20 entries for the second button clicks everytime
i tried redraw, fndestry and all ..its not working.
can anyone plz help me to do this?