Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getAlert()
- {
- var fromduration = 0;
- var toduration = 0;
- var hours = 0;
- // get the shift start time and date
- var startdateandtime = $('#starttime').val();
- var startdateandtime = startdateandtime.split("-");
- var startdate = startdateandtime[0];
- var fromdatemonthyear = startdate.split(" ");
- var fromdate = fromdatemonthyear[0];
- var frommonth = fromdatemonthyear[1];
- var fromyear = fromdatemonthyear[2];
- //get the shift end time and date
- var enddateandtime = $('#endtime').val();
- var enddateandtime = enddateandtime.split("-");
- var enddate = enddateandtime[0];
- var todatemonthyear = enddate.split(" ");
- var todate = todatemonthyear[0];
- var tomonth = todatemonthyear[1];
- var toyear = todatemonthyear[2];
- var ward = $("#ward option:selected").text();
- var namenic = $("#name option:selected").text();
- var splitNameNic = namenic.split("-");
- var name = splitNameNic[0];
- var nic = splitNameNic[1];
- var start = new Date(startdateandtime);
- var end = new Date(enddateandtime);
- if(startdateandtime.length == 0||enddateandtime.length == 0 || ward.length == 0|| namenic.length == 0){
- alert("Please Enter all the values");
- }
- else{
- if (end.getFullYear() === start.getFullYear()) {
- if (end.getMonth() === start.getMonth()) {
- if (end.getDate() === start.getDate()) {
- if (end.getHours() === start.getHours()) {
- alert("hours and dates are equal check the date");
- } else if (end.getHours() > start.getHours()) {
- //no of hours will be calculated
- //get start hours
- var starttime = start.getHours();
- //get end hours
- var endtime = end.getHours();
- //no of hours willbe calculated
- var numberofhoursstart = start.getHours();
- var numberofhoursend = end.getHours();
- var totalhours = numberofhoursend - numberofhoursstart;
- //assigning to variables
- fromduration = numberofhoursstart;
- toduration = numberofhoursend;
- hours = totalhours;
- CalcalatedTotalOTHours =totalhours;
- // alert("Total Hours "+totalhours);
- //send data to controller using addovertimetocontroller method
- addOvertimeToController(name,nic,ward,fromduration,toduration,starttime,endtime,fromdate,frommonth,fromyear,todate,tomonth,toyear,hours);
- } else if (end.getHours() < start.getHours()) {
- alert("wrong input start hours are greater than end hours");
- }
- } else if (end.getDate() > start.getDate()) {
- if(end.getDate() === (start.getDate()+1)){
- //get start hours
- var starttime = start.getHours();
- //get end hours
- var endtime = end.getHours();
- //no of hours willbe calculated
- var numberofhoursstart = 24 - start.getHours();
- var numberofhoursend = end.getHours() - 0;
- var totalhours = numberofhoursstart + numberofhoursend;
- //assigning to variables
- fromduration = numberofhoursstart;
- toduration = numberofhoursend;
- hours = totalhours;
- CalcalatedTotalOTHours =totalhours;
- // alert("Calculated OT Hours "+totalhours);
- //send data to controller using addovertimetocontroller method
- addOvertimeToController(name,nic,ward,fromduration,toduration,starttime,endtime,fromdate,frommonth,fromyear,todate,tomonth,toyear,hours);
- }
- else{
- alert("you cannot enter more than 2 days of overtime");
- }
- }else if (end.getDate() < start.getDate()){
- alert("end date is smaller than start date of the same month of the same year");
- }
- } else if (end.getMonth() > start.getMonth()) {
- alert("end month greater than start month");
- if((end.getDate() === 1)&&(start.getDate() === 31)){
- //get start hours
- var starttime = start.getHours();
- //get end hours
- var endtime = end.getHours();
- //no of hours willbe calculated
- var numberofhoursstart = 24 - start.getHours();
- var numberofhoursend = end.getHours() - 0;
- var totalhours = numberofhoursstart + numberofhoursend;
- //assigning to variables
- fromduration = numberofhoursstart;
- toduration = numberofhoursend;
- hours = totalhours;
- alert(totalhours+"End Month greater than StartMonth");
- //send data to controller using addovertimetocontroller method
- addOvertimeToController(name,nic,ward,fromduration,toduration,starttime,endtime,fromdate,frommonth,fromyear,todate,tomonth,toyear,hours);
- }
- else if((end.getDate() === 1)&&(start.getDate() === 30)){
- //get start hours
- var starttime = start.getHours();
- //get end hours
- var endtime = end.getHours();
- //no of hours willbe calculated
- var numberofhoursstart = 24 - start.getHours();
- var numberofhoursend = end.getHours() - 0;
- var totalhours = numberofhoursstart + numberofhoursend;
- //assigning to variables
- fromduration = numberofhoursstart;
- toduration = numberofhoursend;
- hours = totalhours;
- alert(totalhours+"End Month greater than StartMonth");
- //send data to controller using addovertimetocontroller method
- addOvertimeToController(name,nic,ward,fromduration,toduration,starttime,endtime,fromdate,frommonth,fromyear,todate,tomonth,toyear,hours);
- }
- else if((end.getDate() === 1)&&(start.getDate() === 29)){
- //get start hours
- var starttime = start.getHours();
- //get end hours
- var endtime = end.getHours();
- //no of hours willbe calculated
- var numberofhoursstart = 24 - start.getHours();
- var numberofhoursend = end.getHours() - 0;
- var totalhours = numberofhoursstart + numberofhoursend;
- //assigning to variables
- fromduration = numberofhoursstart;
- toduration = numberofhoursend;
- hours = totalhours;
- alert(totalhours+"End Month greater than StartMonth");
- //send data to controller using addovertimetocontroller method
- addOvertimeToController(name,nic,ward,fromduration,toduration,starttime,endtime,fromdate,frommonth,fromyear,todate,tomonth,toyear,hours);
- }
- else if((end.getDate() === 1)&&(start.getDate() === 28)){
- //get start hours
- var starttime = start.getHours();
- //get end hours
- var endtime = end.getHours();
- //no of hours willbe calculated
- var numberofhoursstart = 24 - start.getHours();
- var numberofhoursend = end.getHours() - 0;
- var totalhours = numberofhoursstart + numberofhoursend;
- //assigning to variables
- fromduration = numberofhoursstart;
- toduration = numberofhoursend;
- hours = totalhours;
- CalcalatedTotalOTHours =totalhours;
- alert(totalhours+"End Month greater than StartMonth");
- //send data to controller using addovertimetocontroller method
- addOvertimeToController(name,nic,ward,fromduration,toduration,starttime,endtime,fromdate,frommonth,fromyear,todate,tomonth,toyear,hours);
- }
- else{
- alert("you cannot have more than 24 hours");
- }
- } else if (end.getMonth() < start.getMonth()) {
- alert("start month greater than end month");
- }
- } else if (end.getFullYear() > start.getFullYear()) {
- if((end.getMonth() === 0)&& (start.getMonth() === 11)){
- if(end.getDate() === 1 && start.getDate() === 31){
- alert("end year greater than start year");
- // no of hours will be calculated
- //get start hours
- var starttime = start.getHours();
- //get end hours
- var endtime = end.getHours();
- //no of hours willbe calculated
- var numberofhoursstart = 24 - start.getHours();
- var numberofhoursend = end.getHours() - 0;
- var totalhours = numberofhoursstart + numberofhoursend;
- //assigning to variables
- fromduration = numberofhoursstart;
- toduration = numberofhoursend;
- hours = totalhours;
- CalcalatedTotalOTHours =totalhours;
- alert(totalhours+"End Month greater than StartMonth");
- //send data to controller using addovertimetocontroller method
- addOvertimeToController(name,nic,ward,fromduration,toduration,starttime,endtime,fromdate,frommonth,fromyear,todate,tomonth,toyear,hours);
- }else{
- alert("you cannot have more than 24 hours check the two dates");
- }
- }else{
- alert("you cannot have more than one month differnece");
- }
- } else if (end.getFullYear() < start.getFullYear()) {
- alert("wrong Date input Please check the year");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement