<?php 
 ####### UPDATE START STATUS#######
 if(isset($_POST['projstrt_id'])){
    try{
        $projstrt_id = $_POST['projstrt_id'];
        $sql = $db->query("UPDATE `tbl_projects` SET `prces` = '2' WHERE `projid` = '$projstrt_id'");
        $msg = "Updated Successfully";
        
    }catch(PDOException $e){
        echo $e->getMessage();
    }
}

####### UPDATE #######
 if(isset($_POST['projgeninv_id'])){
    try{
        $projgeninv_id = $_POST['projgeninv_id'];
        $sql = $db->query("UPDATE `tbl_projects` SET `prces` = '3' WHERE `projid` = '$projgeninv_id'");
        $msg = "Updated Successfully";
        
    }catch(PDOException $e){
        echo $e->getMessage();
    }
}
?>

<div class="card mb-g border shadow-0">
    <div class="card-header bg-white p-0 header">
        <div class="p-3 d-flex flex-row">
            <div class="d-block ml-2">
                <span class="h6 font-weight-bold text-uppercase d-block m-0">
                    <?php echo $title;?> 
                </span>
                <div class="clearfix"></div>  
            </div>
        </div>
    </div>

    <div class="card-body">
     <br>
                 
        <table id="dt-basic-example" class="table table-hover table-striped w-100"  style="font-size: 11px;">
            <thead class="header">
                <tr>
                    <th style="font-weight: bold;"></th>
                    <th style="font-weight: bold;">CODE</th>
                    <th style="font-weight: bold;">PROJECT</th>
                    <th style="font-weight: bold;">AGREEMENT/WORK ORDER N<sup>o</sup></th>
                    <th style="font-weight: bold;">SIGNED DATE</th>
                    <th style="font-weight: bold;">STARTED DATE</th>
                    <th style="font-weight: bold;">DURATION</th>
                    <th style="font-weight: bold;"></th>
                </tr>
            </thead>
            
            <tbody>
                <?php 
                    $n=0;
                    $sth = $db->prepare('SELECT *FROM tbl_projects p
                    INNER JOIN tbl_clients c ON c.ct_id=p.clnt
                    WHERE prjsts=1
                    ORDER BY projid DESC');
                    $sth->execute();
                    while($getp = $sth->fetch()){
                    $projid = $getp['projid'];
                    $wrkp = $getp['wps'];
                    $process = $getp['prces'];
                    $n++;

                    $prjsts=$getp['prjsts'];
                    $prcsQue = $db->prepare('SELECT *FROM tbl_process WHERE prcs_id="'.$process.'"');
                    $prcsQue->execute();
                    $getPrcs=$prcsQue->fetch();
                    if($process == 1){
                        $icon='<i class="fa fa-exclamation-circle" aria-hidden="true"></i>';
                        $btn='btn-primary';
                    }elseif($process == 2){
                        $icon='<i class="fa fa-check" aria-hidden="true"></i>';
                        $btn='btn-success';
                    }else{
                        $icon='<i class="fa fa-folder-open" aria-hidden="true"></i>';
                        $btn='btn-default';
                    }
                ?>
                
                    <tr class="b-tr">
                        <td><i class="fa fa-share" aria-hidden="true"></i></td>
                        <td><?php echo $getp['codeproj'];?></td>
                        <td><?php echo $getp['projname'];?></td>
                        <td><?php echo $getp['aggreno'];?></td>
                        <td><?php echo date('d/m/Y', strtotime($getp['signdate']));?></td>
                        <td><?php echo date('d/m/Y', strtotime($getp['startDue']));?></td>

                        <td><i style="color: #596d43"><?php echo $getp['durat']." Month(s)";?></i></td>
                        
                        <td>
                            <?php 
                             if($process == 1){
                            ?>
                            <div class="fs-sm text-muted ml-auto hide-on-hover-parent order-4 position-on-mobile-absolute
                                pos-top pos-right mt-2 mr-3 mr-sm-4 mt-lg-0 mr-lg-0">
                                <a href="javascript:void(0)"  data-toggle="modal" data-target="#strt<?php echo $projid;?>"  class="btn <?php echo $btn;?> btn-xs" style="font-weight: bold;">
                                <?php echo  $icon." ".$getPrcs['prcsname'];?>
                            </a>
                            </div>
                            <?php }elseif($process == 2){?>
                                <div class="fs-sm text-muted ml-auto hide-on-hover-parent order-4 position-on-mobile-absolute
                                pos-top pos-right mt-2 mr-3 mr-sm-4 mt-lg-0 mr-lg-0">
                                <a href="javascript:void(0)"  data-toggle="modal" data-target="#genInv<?php echo $projid;?>"  class="btn <?php echo $btn;?> btn-xs" style="font-weight: bold;">
                                <?php echo  $icon." ".$getPrcs['prcsname'];?>
                            </a>
                            </div>
                            <?php }else{?>
                                <div class="fs-sm text-muted ml-auto hide-on-hover-parent order-4 position-on-mobile-absolute
                                pos-top pos-right mt-2 mr-3 mr-sm-4 mt-lg-0 mr-lg-0">
                                <label class="btn <?php echo $btn;?> btn-xs" style="font-weight: bold;"><?php echo  $icon." ".$getPrcs['prcsname'];?></label>
                            <?php }?>
                        </td>
                    </tr>
                <?php
                include 'strt.php';
                include 'geninv.php';
                }
                ?>
            </tfoot>
        </table>

    </div>
</div>