Advertisement
Guest User

Untitled

a guest
Sep 15th, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getAlert()
  2. {
  3.    
  4.     var fromduration = 0;
  5.     var toduration = 0;
  6.     var hours = 0;
  7.    
  8.     // get the shift start time and date  
  9.     var startdateandtime = $('#starttime').val();
  10.     var startdateandtime = startdateandtime.split("-");
  11.     var startdate  = startdateandtime[0];
  12.     var fromdatemonthyear = startdate.split(" ");
  13.     var fromdate = fromdatemonthyear[0];
  14.     var frommonth = fromdatemonthyear[1];
  15.     var fromyear = fromdatemonthyear[2];
  16.    
  17.    
  18.     //get the shift end time and date
  19.     var enddateandtime = $('#endtime').val();
  20.     var enddateandtime = enddateandtime.split("-");
  21.     var enddate = enddateandtime[0];
  22.     var todatemonthyear = enddate.split(" ");
  23.     var todate = todatemonthyear[0];
  24.     var tomonth = todatemonthyear[1];
  25.     var toyear = todatemonthyear[2];
  26.    
  27.    
  28.    
  29.    
  30.     var ward = $("#ward option:selected").text();
  31.     var namenic = $("#name option:selected").text();
  32.     var splitNameNic = namenic.split("-");
  33.     var name = splitNameNic[0];
  34.     var nic = splitNameNic[1];
  35.  
  36.     var start = new Date(startdateandtime);
  37.  
  38.     var end = new Date(enddateandtime);
  39.    
  40.     if(startdateandtime.length == 0||enddateandtime.length == 0 || ward.length == 0|| namenic.length == 0){
  41.            
  42.             alert("Please Enter all the values");
  43.     }
  44.     else{
  45.     if (end.getFullYear() === start.getFullYear()) {
  46.         if (end.getMonth() === start.getMonth()) {
  47.             if (end.getDate() === start.getDate()) {
  48.                
  49.                         if (end.getHours() === start.getHours()) {
  50.                                 alert("hours and dates are equal check the date");
  51.                        
  52.                          } else if (end.getHours() > start.getHours()) {
  53.                                
  54.                                 //no of hours will be calculated
  55.                                 //get start hours
  56.                                 var starttime = start.getHours();
  57.                            
  58.                                 //get end hours
  59.                                 var endtime = end.getHours();
  60.                            
  61.                                 //no of hours willbe calculated
  62.                                 var numberofhoursstart = start.getHours();
  63.                                 var numberofhoursend = end.getHours();
  64.                                 var totalhours = numberofhoursend - numberofhoursstart;
  65.                            
  66.                                 //assigning to variables
  67.                                 fromduration = numberofhoursstart;
  68.                                 toduration = numberofhoursend;
  69.                                 hours = totalhours;
  70.                                 CalcalatedTotalOTHours =totalhours;
  71.                                // alert("Total Hours "+totalhours);
  72.                            
  73.                                 //send data to controller using addovertimetocontroller method
  74.                                 addOvertimeToController(name,nic,ward,fromduration,toduration,starttime,endtime,fromdate,frommonth,fromyear,todate,tomonth,toyear,hours);
  75.                                
  76.                          } else if (end.getHours() < start.getHours()) {
  77.                    
  78.                                 alert("wrong input start hours are greater than end hours");
  79.                          
  80.                          }
  81.                          
  82.             } else if (end.getDate() > start.getDate()) {
  83.              
  84.                         if(end.getDate() === (start.getDate()+1)){
  85.                            
  86.                             //get start hours
  87.                             var starttime = start.getHours();
  88.                             //get end hours
  89.                             var endtime = end.getHours();
  90.                             //no of hours willbe calculated
  91.                             var numberofhoursstart = 24 - start.getHours();
  92.                             var numberofhoursend = end.getHours() - 0;
  93.                             var totalhours = numberofhoursstart + numberofhoursend;
  94.                             //assigning to variables
  95.                             fromduration = numberofhoursstart;
  96.                             toduration = numberofhoursend;
  97.                             hours = totalhours;
  98.                             CalcalatedTotalOTHours =totalhours;
  99.                          //   alert("Calculated OT Hours "+totalhours);
  100.                             //send data to controller using addovertimetocontroller method
  101.                             addOvertimeToController(name,nic,ward,fromduration,toduration,starttime,endtime,fromdate,frommonth,fromyear,todate,tomonth,toyear,hours);
  102.                            
  103.                         }
  104.                         else{
  105.                             alert("you cannot enter more than 2 days of overtime");
  106.                         }
  107.            
  108.             }else if (end.getDate() < start.getDate()){
  109.                            
  110.                             alert("end date is smaller than start date of the same month of the same year");
  111.             }
  112.            
  113.         } else if (end.getMonth() > start.getMonth()) {
  114.            
  115.                         alert("end month greater than start month");
  116.                         if((end.getDate() === 1)&&(start.getDate() === 31)){
  117.                            
  118.                             //get start hours
  119.                             var starttime = start.getHours();
  120.                             //get end hours
  121.                             var endtime = end.getHours();
  122.                             //no of hours willbe calculated
  123.                             var numberofhoursstart = 24 - start.getHours();
  124.                             var numberofhoursend = end.getHours() - 0;
  125.                             var totalhours = numberofhoursstart + numberofhoursend;
  126.                             //assigning to variables
  127.                             fromduration = numberofhoursstart;
  128.                             toduration = numberofhoursend;
  129.                             hours = totalhours;
  130.                             alert(totalhours+"End Month greater than StartMonth");
  131.                             //send data to controller using addovertimetocontroller method
  132.                             addOvertimeToController(name,nic,ward,fromduration,toduration,starttime,endtime,fromdate,frommonth,fromyear,todate,tomonth,toyear,hours);
  133.                        
  134.                         }
  135.                         else if((end.getDate() === 1)&&(start.getDate() === 30)){
  136.                            
  137.                             //get start hours
  138.                             var starttime = start.getHours();
  139.                             //get end hours
  140.                             var endtime = end.getHours();
  141.                             //no of hours willbe calculated
  142.                             var numberofhoursstart = 24 - start.getHours();
  143.                             var numberofhoursend = end.getHours() - 0;
  144.                             var totalhours = numberofhoursstart + numberofhoursend;
  145.                             //assigning to variables
  146.                             fromduration = numberofhoursstart;
  147.                             toduration = numberofhoursend;
  148.                             hours = totalhours;
  149.                             alert(totalhours+"End Month greater than StartMonth");
  150.                             //send data to controller using addovertimetocontroller method
  151.                             addOvertimeToController(name,nic,ward,fromduration,toduration,starttime,endtime,fromdate,frommonth,fromyear,todate,tomonth,toyear,hours);
  152.                        
  153.                         }
  154.                         else if((end.getDate() === 1)&&(start.getDate() === 29)){
  155.                            
  156.                             //get start hours
  157.                             var starttime = start.getHours();
  158.                             //get end hours
  159.                             var endtime = end.getHours();
  160.                             //no of hours willbe calculated
  161.                             var numberofhoursstart = 24 - start.getHours();
  162.                             var numberofhoursend = end.getHours() - 0;
  163.                             var totalhours = numberofhoursstart + numberofhoursend;
  164.                             //assigning to variables
  165.                             fromduration = numberofhoursstart;
  166.                             toduration = numberofhoursend;
  167.                             hours = totalhours;
  168.                             alert(totalhours+"End Month greater than StartMonth");
  169.                             //send data to controller using addovertimetocontroller method
  170.                             addOvertimeToController(name,nic,ward,fromduration,toduration,starttime,endtime,fromdate,frommonth,fromyear,todate,tomonth,toyear,hours);
  171.                        
  172.                         }
  173.                         else if((end.getDate() === 1)&&(start.getDate() === 28)){
  174.                            
  175.                             //get start hours
  176.                             var starttime = start.getHours();
  177.                             //get end hours
  178.                             var endtime = end.getHours();
  179.                             //no of hours willbe calculated
  180.                             var numberofhoursstart = 24 - start.getHours();
  181.                             var numberofhoursend = end.getHours() - 0;
  182.                             var totalhours = numberofhoursstart + numberofhoursend;
  183.                             //assigning to variables
  184.                             fromduration = numberofhoursstart;
  185.                             toduration = numberofhoursend;
  186.                             hours = totalhours;
  187.                             CalcalatedTotalOTHours =totalhours;
  188.                             alert(totalhours+"End Month greater than StartMonth");
  189.                             //send data to controller using addovertimetocontroller method
  190.                             addOvertimeToController(name,nic,ward,fromduration,toduration,starttime,endtime,fromdate,frommonth,fromyear,todate,tomonth,toyear,hours);
  191.                        
  192.                        
  193.                         }
  194.                         else{
  195.                             alert("you cannot have more than 24 hours");
  196.                         }
  197.      } else if (end.getMonth() < start.getMonth()) {
  198.            
  199.                             alert("start month greater than end month");
  200.         }
  201.     } else if (end.getFullYear() > start.getFullYear()) {
  202.                        
  203.                         if((end.getMonth() === 0)&& (start.getMonth() === 11)){
  204.                        
  205.                             if(end.getDate() === 1 && start.getDate() === 31){
  206.                             alert("end year greater than start year");
  207.                            
  208.                             // no of hours will be calculated
  209.                             //get start hours
  210.                             var starttime = start.getHours();
  211.                             //get end hours
  212.                             var endtime = end.getHours();
  213.                             //no of hours willbe calculated
  214.                             var numberofhoursstart = 24 - start.getHours();
  215.                             var numberofhoursend = end.getHours() - 0;
  216.                             var totalhours = numberofhoursstart + numberofhoursend;
  217.                             //assigning to variables
  218.                             fromduration = numberofhoursstart;
  219.                             toduration = numberofhoursend;
  220.                             hours = totalhours;
  221.                             CalcalatedTotalOTHours =totalhours;
  222.                             alert(totalhours+"End Month greater than StartMonth");
  223.                             //send data to controller using addovertimetocontroller method
  224.                             addOvertimeToController(name,nic,ward,fromduration,toduration,starttime,endtime,fromdate,frommonth,fromyear,todate,tomonth,toyear,hours);
  225.                        
  226.                             }else{
  227.                                 alert("you cannot have more than 24 hours check the two dates");
  228.                             }
  229.                            
  230.                         }else{
  231.                             alert("you cannot have more than one month differnece");
  232.                         }
  233.  
  234.  
  235.     } else if (end.getFullYear() < start.getFullYear()) {
  236.        
  237.                         alert("wrong Date input Please check the year");
  238.     }
  239.    
  240.     }      
  241. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement