Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $server = '127.0.0.1';
- $user='root';
- $pass="";
- $db='s';
- $conn=mysqli_connect($server,$user,$pass);
- $db=mysqli_select_db($conn, $db);
- // $enddate = '2016-04-03';
- // $nextmonday = date('Y-m-d', strtotime('next monday', strtotime($enddate)));
- // $ddate = $nextmonday;
- // $date = new DateTime($ddate);
- // $week = $date->format("W");
- // $year = $date->format("Y");
- // echo "Weeknummer: $week"."<br>";
- // echo "Weekyear: $year"."<br>";
- function getStartAndEndDate($week, $year)
- {
- $time = strtotime("1 January $year", time());
- $day = date('w', $time);
- $time += ((7*$week)+1-$day)*24*3600;
- $return[0] = date('Y-n-j', $time);
- $time += 6*24*3600;
- $return[1] = date('Y-m-j', $time);
- return $return[1];
- }
- if($db==1)
- {
- // Get Monsantoo employees
- $result=mysqli_query($conn,"SELECT emp_number, user_name from ohrm_user as A
- join tbl_costcenters as B on A.cost_center_id = b.id
- where A.cost_center_id IN(2,10,11,12) And status='1'");
- ?>
- <table border=1>
- <tr>
- <td>S.NO</td>
- <td>Name</td>
- <td>Week Start</td>
- <td>Week End</td>
- <td>Row Count</td>
- </tr>
- <?php
- while($row=mysqli_fetch_array($result))
- { ?>
- <tr>
- <td><?php echo $emp_no=$row[0]; ?></td>
- <td><?php echo $row[1]; ?></td>
- <?php
- // Get end_date of particular employee
- $enddate_q=mysqli_query($conn,"select end_date from ohrm_timesheet
- where employee_id='$emp_no'" );
- $endrow=mysqli_fetch_array($enddate_q);
- $enddate= $endrow[0];
- $enddate = $enddate;
- $nextmonday = date('Y-m-d', strtotime('next monday', strtotime($enddate)));
- $ddate = $nextmonday;
- $date = new DateTime($ddate);
- $week = $date->format("W");
- $year = $date->format("Y");
- $sunday = getStartAndEndDate($week,$year);
- ?>
- <td><?php echo $nextmonday; ?></td>
- <td><?php echo $sunday; ?></td>
- <?php
- //Give the current start date and end date to emp
- $res=mysqli_query($conn,"select timesheet_id,employee_id,start_date,end_date from ohrm_timesheet
- where employee_id='$emp_no' AND start_date = '$nextmonday' AND end_date='$sunday'" );
- $num_row1=mysqli_num_rows($res);//count how many rows are there with give start and end date.
- if($num_row1==0)//employess are not submitted enter to if case
- {
- //get the last timesheet_id from table.
- $timeid=mysqli_query($conn,"SELECT timesheet_id FROM ohrm_timesheet ORDER BY timesheet_id DESC limit 1 ");
- $timerow=mysqli_fetch_array($timeid);
- $timesheet_id= $timerow[0];
- $timesheet_id = ($timesheet_id)+(1);//add 1 to current timesheet_id
- $state="NOT SUBMITTED";
- //Insert those emplyees into table
- $in_query="insert into ohrm_timesheet (timesheet_id,state,start_date,end_date,employee_id)
- values('$timesheet_id','$state','$nextmonday','$sunday','$emp_no')";
- //$mysql_query = mysqli_query($conn,$in_query);
- //update the timesheet_id
- $up1="update hs_hr_unique_id set last_id='$timesheet_id' where table_name='ohrm_timesheet'";
- //$mysql_query = mysqli_query($conn,$up1);
- //who are inserted into timesheet those are insert also timesheet_item by from date to date
- $from=$nextmonday;
- $to= date('Y-m-d', strtotime('-2 day', strtotime($sunday)));
- for($datee = $from; $datee <= $to; $datee = date('Y-m-d', strtotime($datee. ' + 1 days')))
- {
- $item_timesheet_id=mysqli_query($conn,"SELECT timesheet_item_id FROM ohrm_timesheet_item ORDER BY timesheet_item_id DESC limit 1 ");
- $item_timesheet_row = mysqli_fetch_array($item_timesheet_id);
- $timesheet_item_id= $item_timesheet_row[0];
- $item_id = ($timesheet_item_id)+(1);
- $sql="insert into ohrm_timesheet_item (timesheet_item_id,timesheet_id,date,duration,comment,project_id,employee_id,activity_id,ticket_id)
- values('$item_id','$timesheet_id','$datee','32400','NULL','63','$emp_no','271','0')";
- //$mysql_query = mysqli_query($conn,$sql);
- $up2="update hs_hr_unique_id set last_id='$timesheet_item_id' where table_name='ohrm_timesheet_item'";
- //$mysql_query = mysqli_query($conn,$up2);
- }
- } ?>
- <td><?php// echo $num_row1; ?></td>
- <td><?php echo $timesheet_id; ?></td>
- </tr>
- <?php } ?>
- </table>
- <?php }
- else
- {
- echo "sorry";
- }
- ?>
Add Comment
Please, Sign In to add comment