
<?php 
    $sql2 = $conn->prepare("SELECT *FROM tbl_sub_supp s
    INNER JOIN tbl_categ_su c ON c.ctg_id=s.ctg_su
    INNER JOIN tbl_s_s ss ON ss.ss_id=s.su_type WHERE subsup_id='".$_REQUEST['ssid']."'
    ORDER BY c.ctg_name ASC");
    $sql2->execute();
    while($fetch2 = $sql2->fetch()){
?>
<form id="" action="gate?b=supsub" method="POST" enctype="multipart/form-data" autocomplete="off">
  <br><br> 
    <div class="row">
    <div class="col-md-1"></div>
    <div class="col-md-10" style="background-image: url(../img/placeholders/inner-texture-bg.png); border-radius: 8px;">
      <div style='border-radius: 8px;border: 2px solid #7E9350;width:100%;margin-top:1%;margin-bottom:1%;'>
        <br/>
        <center>
           <b style="font-family: century gothic;font-size: 23px;"><i class="fa fa-user"></i> New Supplier/Subcontractor.</b>
        </center>
        <br/>      
        
        <div class="form-group row">              
            <label class="col-form-label col-2 col-lg-2 form-label text-lg-right">Type<span class="required" style="color:red">*</span></label>
            <div class="col-3 col-lg-3">     
            <input type="hidden" name="supsubid" value="<?php echo $fetch2['subsup_id'];?>">             
               <select class="show-tick ms select2" name="tpid" id="tpid" style="width: 100%" data-placeholder="~select type~"  onchange="getsctg(this.value)" required>
                <option></option>
                    <?php
                    $stmt2 = $db->query('SELECT *FROM tbl_s_s');
                    try
                    {
                        while ($rrr2 = $stmt2->fetch(PDO::FETCH_ASSOC)) {
                            if($fetch2['su_type']==$rrr2['ss_id']){
                        ?>
                           <option value="<?php echo $fetch2['su_type']; ?>" selected><?php echo $rrr2['namesu']; ?></option>
                        <?php }else{ ?>
                            <option value="<?php echo $rrr2['ss_id']; ?>"><?php echo $rrr2['namesu']; ?></option>
                        <?php
                        }
                        }
                    }
                        catch (PDOException $ex) {
                        //Something went wrong rollback!
                        echo $ex->getMessage();
                    }
                    ?>	
                </select>
            </div>

            <label class="col-form-label col-2 col-lg-2 form-label text-lg-right">Company Name</label>
            <div class="col-3 col-lg-3">
                 <textarea type="text" name="cpny" rows="2" class="form-control" placeholder="name here..." required><?php echo $fetch2['cpny_name'];?></textarea>
            </div>
        </div>

            
        <div class="form-group row">              
            <label class="col-form-label col-2 col-lg-2 form-label text-lg-right">Rank<?php echo $fetch2['ss_rank'];?><span class="required" style="color:red">*</span></label>
            <div class="col-3 col-lg-3">                  
                <select class="show-tick ms select2" name="rank_name" style="width: 100%" data-placeholder="~select rank~" required>
                    <option></option>
			        <?php
			            $selectrank= $conn->prepare("SELECT * FROM tbl_rank");
                        $selectrank->execute();
                        while($row_1rank = $selectrank->fetch()) { 
                        if($fetch2['ss_rank']==$row_1rank['rank_id']){    
                        ?>
                        <option value="<?php echo $fetch2['ss_rank'];?>" selected><?php echo $row_1rank['rank_name']; ?></option>
                        <?php
                        }else{
                        ?>
                            <option value="<?php echo $row_1rank['rank_id']; ?>"><?php echo $row_1rank['rank_name']; ?></option>
                        <?php
                        }
                    }
			        ?>
                </select>
            </div>

            <label class="col-form-label col-2 col-lg-2 form-label text-lg-right">Owner/MD<span class="required" style="color:red">*</span></label>
            <div class="col-3 col-lg-3">                  
               <textarea type="text" name="owner" rows="2" class="form-control" placeholder="write owner..." required><?php echo $fetch2['own_name'];?></textarea>
            </div>
        </div>

        <div class="form-group row">    
            <label class="col-form-label col-2 col-lg-2 form-label text-lg-right">S/S Category><span class="required" style="color:red">*</span></label>
            <div class="col-3 col-lg-3">                  
                <select class="show-tick ms select2" name="ssctg" id="ssctg" style="width: 100%" data-placeholder="~choose one~" required>
                    <option></option>
                    <?php
			            $qque= $conn->prepare("SELECT * FROM tbl_categ_su WHERE ss_type='".$fetch2['su_type']."' ");
                        $qque->execute();
                        while($rr22 = $qque->fetch()) { 
                          if($fetch2['ctg_su']==$rr22['ctg_id']){   
                        ?>                        
                        <option value="<?php echo $rr22['ctg_id'];?>" selected><?php echo $rr22['ctg_name']; ?></option>

                        <?php }else{?>
                            <option value = <?php echo $rr22['ctg_id'];?>><?php echo $rr22['ctg_name']; ?></option>
                        <?php
                        }
                     }
			        ?>			        
                </select>
            </div>

            <label class="col-form-label col-2 col-lg-2 form-label text-lg-right">Contact<span class="required" style="color:red">*</span></label>
            <div class="col-3 col-lg-3">                  
                <input type="number" class="form-control" id="supp_phone" name="supp_phone" 
                oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');" value="<?php echo $fetch2['tel_cont'];?>" placeholder="07..." required>
            </div>
        </div>

        <div class="form-group row">    
            <label class="col-form-label col-2 col-lg-2 form-label text-lg-right">TIN N<sup>o</sup></label>
            <div class="col-3 col-lg-3">                  
                <input type="number" class="form-control" id="" name="tino" value="<?php echo $fetch2['tin'];?>" placeholder="Tin...">
            </div>
        </div>

        <hr>
        <center>
            <a href="gate?b=supsub" class="btn btn-default btn-sm" style="border-radius: 4px;font-weight: bold;">Go back</a>
            <button type="submit" class="btn btn-primary btn-sm" name="btnupdate" style="border-radius: 4px;font-weight: bold;">Save Changes</button>
        </center>
        <br>
    </div> <!--border -->
    </div>
  </div>
</form>

<?php }?>
