<?php require_once '../../layout/main.php'; ?>
<?php require_once '../../DB/trims_inhouse/select.php'; ?>
<?php require_once '../../DB/trims_inhouse/search.php'; ?>
<?php require_once '../../DB/size/select.php'; ?>
<?php require_once '../../DB/line/select.php'; ?>
<?php require_once '../../DB/po/select.php'; ?>
<?php require_once '../../DB/style/select.php'; ?>

<?php
      $ob = new select_trims_inhouse();
      $result = $ob->select_all();

      $selectSize = new select_size();
      $size_list =  $selectSize->select_all();

      $selectLine = new select_line();
      $line_list =  $selectLine->select_all();

      $selectPO = new select_po();
      $po_list =  $selectPO->select_all();

      $selectStyle = new select_style();
      $style_list =  $selectStyle->select_all();

      if (isset($_POST['search'])) {
        //echo "$_POST['type_select']";
        // echo '<pre>';
        // print_r($_POST['type_select']);
        // echo  '</pre>';
          $search= new search_trims_inhouse();
          $result = $search->search($_POST);
      }
?>

<div class="content-inner">

    <div class="w3-animate-right" style="margin-right:10px;margin-left:10px;">

            <div class="w3-card-4 table-striped w3-hoverable w3-small" style="padding:25px;">


              <div style="margin-right: 10px;margin-top: 10px;" id ="search">

                <form method="POST" action="">

                          <div class="row">

                            <div class="form-group col-md-4">
                                <label class="btn btn-info">Style Name</label>
                                <div class="input-group margin" style="margin-top: 0px">
                                               <select class="form-control col-md-12" name="style_select" id="style_select">
                                                  <option value="">Select Name</option>

                                                  <?php
                                                    while ($row = mysqli_fetch_assoc($style_list))
                                                        {
                                                  ?>
                                                  <option value="<?php echo $row['id']; ?>"><?php echo $row['style_name']; ?></option>
                                                  <?php
                                                        }
                                                  ?>
                                                </select>
                                </div>
                          </div>

                     <div class="form-group col-md-4">
                         <label class="btn btn-info">PO Number</label>
                         <div class="input-group margin" style="margin-top: 0px">
                                          <select class="form-control col-md-12" name="po_select" id="po_select">
                                           <option value="">Select PO</option>

                                           <?php
                                             while ($row = mysqli_fetch_assoc($po_list))
                                                 {
                                           ?>
                                           <option value="<?php echo $row['id']; ?>"><?php echo $row['po_num']; ?></option>
                                           <?php
                                                 }
                                           ?>
                                         </select>
                        </div>
                        </div>

                     <div class="form-group col-md-4">
                         <label class="btn btn-info">Line</label>
                         <div class="input-group margin" style="margin-top: 0px">
                                           <select class="form-control col-md-12" name="line_select" id="line_select">
                                           <option value="">Select Line</option>

                                           <?php
                                             while ($row = mysqli_fetch_assoc($line_list))
                                                 {
                                           ?>
                                           <option value="<?php echo $row['id']; ?>"><?php echo $row['name']; ?></option>
                                           <?php
                                                 }
                                           ?>
                            </select>
                          </div>
                         </div>
                      </div>

                  <div class="row">

                     <div class="form-group col-md-4">
                         <label class="btn btn-info">PCD</label>
                         <input style="margin-top: 2px;" class="form-control" type="date" id="pcd" name="pcd" autocomplete="off">
                     </div>

                     <div class="form-group col-md-4">
                         <label class="btn btn-info">TOD</label>
                         <input style="margin-top: 2px;" class="form-control" type="date" id="tod" name="tod" autocomplete="off">
                     </div>
                    <div class="form-group col-md-4">
                        <label class="btn btn-info">Type</label>
                        <div style="margin-top: 0px">
                           <select class="form-control" name="type_select" id="type_select">
                             <option value="">Select Type</option>
                              <option value="0">Recieve</option>
                              <option value="1">Inhouse</option>
                           </select>
                         </div>
                     </div>
                  </div>


                 </div>

                 <div class="text-center" style="padding-top: 10px;">
                 <button id="search" name="search" type="submit" class="btn btn-danger center-block">SEARCH</button>
                 </div>

                </form>
              </div>



          <div class="table-responsive table-striped w3-hoverable w3-small" style="padding:25px;">
              <table id="export-table" class="table table-striped w3-hoverable display nowrap w3-table-all w3-small" style="width:100%" style="overflow-x:auto;">
                  <thead>
                      <tr  class="btn-gradient-02">
                                    <th style="color:white;">ID</th>
                                    <th style="color:white;">Style name</th>
                                    <th style="color:white;">PO</th>
                                    <th style="color:white;">Total Requirement</th>
                                    <th style="color:white;">Total Received</th>
                                    <th style="color:white;">Total issue</th>
                                    <th style="color:white;">Total Balance</th>
                                    <!-- <th style="color:white;">Style Name</th>
                                    <th style="color:white;">PO Number</th>
                                    <th style="color:white;">PCD</th>
                                    <th style="color:white;">TOD</th>
                                    <th style="color:white;">Supplier</th>
                                    <th style="color:white;">Item Color</th> -->
                                    <!-- <th style="color:white;">Size</th>
                                    <th style="color:white;">Shade</th>
                                    <th style="color:white;">Ref No.</th>
                                    <th style="color:white;">Unit Type</th>
                                    <th style="color:white;">Actual Quantity</th> -->
                                    <!-- <th style="color:white;">Required Quantity</th> -->
                                    <!-- <th style="color:white;">Total Issue Quantity</th>
                                    <th style="color:white;">Balance Quantity</th>
                                    <th style="color:white;">Remarks</th> -->
                                    <th style="color:white;">Actions</th>
                                  </tr>
                              </thead>
                              <tbody>
                                <?php
                                   $i = 1;
                                   while ($info = mysqli_fetch_assoc($result)) {
                                   ?>
                                  <tr>
                                      <td style="color:black;" class="text-center"><?php echo $info['id']; ?> </td>
                                      <td style="color:black;" class="text-center">
                                        <?php
                                        $trinhouseListById = $ob->select_all_trinhouse_name($info['id']);

                                        while ($trinhouseName = mysqli_fetch_assoc($trinhouseListById)) {
                                             echo $trinhouseName['styleName']." ";
                                             break;
                                           }
                                        ?>
                                      </td>
                                      <td style="color:black;" class="text-center">
                                        <?php
                                        $trinhouseListById = $ob->select_all_trinhouse_name($info['id']);

                                        while ($trinhouseName = mysqli_fetch_assoc($trinhouseListById)) {
                                             echo $trinhouseName['poNumber']." ";
                                             break;
                                           }
                                        ?>
                                      </td>
                                      <td style="color:black;" class="text-center"><?php echo $info['total_requirement']; ?> </td>
                                      <td style="color:black;" class="text-center"><?php echo $info['total_received']; ?> </td>
                                      <td style="color:black;" class="text-center"><?php echo $info['total_issue']; ?> </td>
                                      <td style="color:black;" class="text-center"><?php echo $info['total_balance']; ?> </td>
                                      <!-- <td style="color:black;" class="text-center"><?php //echo $info['styleName']; ?> </td>
                                      <td style="color:black;" class="text-center"><?php //echo $info['poNumber']; ?> </td>
                                      <td style="color:black;" class="text-center"><?php //echo $info['pcd']; ?> </td>
                                      <td style="color:black;" class="text-center"><?php //echo $info['tod']; ?> </td>
                                      <td style="color:black;" class="text-center"><?php //echo $info['supplierName']; ?> </td>
                                      <td style="color:black;" class="text-center"><?php //echo $info['colorName']; ?> </td> -->
                                      <!-- <td style="color:black;" class="text-center"><?php //echo $info['sizeNumber']; ?> </td>
                                      <td style="color:black;" class="text-center"><?php //echo $info['shadeName']; ?> </td>
                                      <td style="color:black;" class="text-center"><?php //echo $info['ref_no']; ?> </td>
                                      <td style="color:black;" class="text-center"><?php //echo $info['unit_type']; ?> </td>
                                      <td style="color:black;" class="text-center"><?php //echo $info['actual_quantity']; ?> </td> -->
                                      <!-- <td style="color:black;" class="text-center"><?php //echo $info['required_quantity']; ?> </td> -->
                                      <!-- <td style="color:black;" class="text-center"><?php //echo $info['total_issue_quantity']; ?> </td>
                                      <td style="color:black;" class="text-center"><?php //echo $info['balance_quantity']; ?> </td>
                                      <td style="color:black;" class="text-center"><?php //echo $info['remarks']; ?> </td> -->
                                      <td class="td-actions" class="text-center">
                                          <a href="./pages/trinhouse/details.php?id=<?php echo $info['id'];?>"><button class="btn badge-text badge-text-small info">Details</button></a>
                                          <a href="./pages/trinhouse/update.php?id=<?php echo $info['id'];?>"><button class="btn badge-text badge-text-small info">Update</button></a>
                                              <a href="./pages/trinhouse/copy.php?id=<?php echo $info['id'];?>"><button class="btn badge-text badge-text-small info">Copy</button></a>
                                          <a href="./pages/trinhouse/delete.php?id=<?php echo $info['id'];?>"><button class="btn badge-text badge-text-small danger">Delete</button></a>
                                      </td>
                                  </tr>
                                 <?php $i++;} ?>
                              </tbody>
                          </table>
                       </div>
                    </div>
                  </div>
              </div>
