srikanthp

index of monsto

Apr 21st, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.88 KB | None | 0 0
  1.  
  2. <?php
  3. $server = '127.0.0.1';
  4. $user='root';
  5. $pass="";
  6. $db='s';
  7.  
  8. $conn=mysqli_connect($server,$user,$pass);
  9. $db=mysqli_select_db($conn, $db);
  10.  
  11. // $enddate = '2016-04-03';
  12. // $nextmonday = date('Y-m-d', strtotime('next monday', strtotime($enddate)));
  13. // $ddate = $nextmonday;
  14. // $date = new DateTime($ddate);
  15. // $week = $date->format("W");
  16. // $year = $date->format("Y");
  17. // echo "Weeknummer: $week"."<br>";
  18. // echo "Weekyear: $year"."<br>";
  19.  
  20. function getStartAndEndDate($week, $year)
  21. {
  22.  
  23. $time = strtotime("1 January $year", time());
  24. $day = date('w', $time);
  25. $time += ((7*$week)+1-$day)*24*3600;
  26. $return[0] = date('Y-n-j', $time);
  27. $time += 6*24*3600;
  28. $return[1] = date('Y-m-j', $time);
  29. return $return[1];
  30. }
  31.  
  32. if($db==1)
  33. {
  34. // Get Monsantoo employees
  35. $result=mysqli_query($conn,"SELECT emp_number, user_name from ohrm_user as A
  36. join tbl_costcenters as B on A.cost_center_id = b.id
  37. where A.cost_center_id IN(2,10,11,12) And status='1'");
  38. ?>
  39. <table border=1>
  40. <tr>
  41. <td>S.NO</td>
  42. <td>Name</td>
  43. <td>Week Start</td>
  44. <td>Week End</td>
  45. <td>Row Count</td>
  46. </tr>
  47. <?php
  48. while($row=mysqli_fetch_array($result))
  49. { ?>
  50. <tr>
  51. <td><?php echo $emp_no=$row[0]; ?></td>
  52. <td><?php echo $row[1]; ?></td>
  53.  
  54. <?php
  55. // Get end_date of particular employee
  56. $enddate_q=mysqli_query($conn,"select end_date from ohrm_timesheet
  57. where employee_id='$emp_no'" );
  58. $endrow=mysqli_fetch_array($enddate_q);
  59. $enddate= $endrow[0];
  60.  
  61. $enddate = $enddate;
  62. $nextmonday = date('Y-m-d', strtotime('next monday', strtotime($enddate)));
  63. $ddate = $nextmonday;
  64. $date = new DateTime($ddate);
  65. $week = $date->format("W");
  66. $year = $date->format("Y");
  67. $sunday = getStartAndEndDate($week,$year);
  68.  
  69.  
  70. ?>
  71. <td><?php echo $nextmonday; ?></td>
  72. <td><?php echo $sunday; ?></td>
  73. <?php
  74. //Give the current start date and end date to emp
  75. $res=mysqli_query($conn,"select timesheet_id,employee_id,start_date,end_date from ohrm_timesheet
  76. where employee_id='$emp_no' AND start_date = '$nextmonday' AND end_date='$sunday'" );
  77. $num_row1=mysqli_num_rows($res);//count how many rows are there with give start and end date.
  78.  
  79. if($num_row1==0)//employess are not submitted enter to if case
  80. {
  81. //get the last timesheet_id from table.
  82. $timeid=mysqli_query($conn,"SELECT timesheet_id FROM ohrm_timesheet ORDER BY timesheet_id DESC limit 1 ");
  83. $timerow=mysqli_fetch_array($timeid);
  84. $timesheet_id= $timerow[0];
  85. $timesheet_id = ($timesheet_id)+(1);//add 1 to current timesheet_id
  86. $state="NOT SUBMITTED";
  87. //Insert those emplyees into table
  88. $in_query="insert into ohrm_timesheet (timesheet_id,state,start_date,end_date,employee_id)
  89. values('$timesheet_id','$state','$nextmonday','$sunday','$emp_no')";
  90. //$mysql_query = mysqli_query($conn,$in_query);
  91.  
  92. //update the timesheet_id
  93. $up1="update hs_hr_unique_id set last_id='$timesheet_id' where table_name='ohrm_timesheet'";
  94. //$mysql_query = mysqli_query($conn,$up1);
  95.  
  96. //who are inserted into timesheet those are insert also timesheet_item by from date to date
  97. $from=$nextmonday;
  98. $to= date('Y-m-d', strtotime('-2 day', strtotime($sunday)));
  99.  
  100. for($datee = $from; $datee <= $to; $datee = date('Y-m-d', strtotime($datee. ' + 1 days')))
  101. {
  102. $item_timesheet_id=mysqli_query($conn,"SELECT timesheet_item_id FROM ohrm_timesheet_item ORDER BY timesheet_item_id DESC limit 1 ");
  103.  
  104. $item_timesheet_row = mysqli_fetch_array($item_timesheet_id);
  105.  
  106. $timesheet_item_id= $item_timesheet_row[0];
  107.  
  108. $item_id = ($timesheet_item_id)+(1);
  109.  
  110. $sql="insert into ohrm_timesheet_item (timesheet_item_id,timesheet_id,date,duration,comment,project_id,employee_id,activity_id,ticket_id)
  111.  
  112. values('$item_id','$timesheet_id','$datee','32400','NULL','63','$emp_no','271','0')";
  113.  
  114. //$mysql_query = mysqli_query($conn,$sql);
  115.  
  116. $up2="update hs_hr_unique_id set last_id='$timesheet_item_id' where table_name='ohrm_timesheet_item'";
  117. //$mysql_query = mysqli_query($conn,$up2);
  118. }
  119. } ?>
  120. <td><?php// echo $num_row1; ?></td>
  121. <td><?php echo $timesheet_id; ?></td>
  122. </tr>
  123. <?php } ?>
  124. </table>
  125. <?php }
  126. else
  127. {
  128. echo "sorry";
  129. }
  130. ?>
Add Comment
Please, Sign In to add comment