<?php
   include('session.php');
   include('header1.php');

// start role specific 
$user_role = $_SESSION['role'];
$companyID = $_SESSION['companyselect'];

$sqlCheckForOpenPayroll = "SELECT * FROM periods WHERE companyid = $companyID AND status = '1'";

$resultOpenPayrolls = mysqli_query($db,$sqlCheckForOpenPayroll);

$countOpenPayrolls = mysqli_num_rows($resultOpenPayrolls);

?>

<main role="main" class="col-md-9 ml-sm-auto col-lg-10 px-4">
  <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
    <h1 class="h2">Add Period</h1>
    <div class="btn-toolbar mb-2 mb-md-0">
      
    </div>
  </div>

<?php if($countOpenPayrolls == 0) : ?>

    <form method = "POST" action="addPayroll1.php">
      <input type = "hidden" name = "companyselectid" value = "<?php echo $companyID; ?>">
    <p>Month Name*
      <input type="text" name="payroll_name" placeholder = "Format: December 2020" required class="form-control"> 
    </p>

    <p>Start Date*
      <input type="date" name="payroll_startdate" required class="form-control"> 
    </p>

    <p>End Date*
      <input type="date" name="payroll_enddate" required class="form-control"> 
    </p>

    <p>No of Working Days*
      <input type="numeric" name="payroll_workingdays" required class="form-control"> 
    </p>

    <input type="submit">
  </form>

  <?php else: ?>

    <div class="alert alert-danger" role="alert">
      ERROR<br>CANNOT OPEN NEW PAYROLL PERIOD. PLEASE CLOSE OPEN PERIODS AND TRY AGAIN
    </div>
    <a href = "payrolls.php">Back to Payroll Listing</a>


<?php endif ?>



  <br>
  <br>

        </main>
      </div>
    </div>

<?php
   include('footer1.php');
?>