<?php require_once('../auth/auth.php'); ?>
<?php
if(isset($_GET['ptid'])){
   $ptid= $_GET['ptid'];
   $areaquery= mysqli_query($conn,"SELECT sp_type,tax_group,tax_margin FROM pro_tax WHERE ptid='$ptid' LIMIT 1 ") or die (mysqli_error($conn));
  $rowarea= mysqli_fetch_assoc($areaquery);
   $tax_group=$rowarea['tax_group'];
   $tax_margin=$rowarea['tax_margin'];
}
?>
<section class="content">
  <div class="container-fluid">
    <div class="row">
     <div class="col-md-6">
       <div class="card card-primary card-outline direct-chat direct-chat-primary shadow-none" style="border-left:1px solid #969c9d;border-right:1px solid #969c9d;border-bottom:1px solid #969c9d;">
         <div class="card-header" style="padding: 5px 8px;"><h3 class="card-title">New Tax Add</h3> <div class="card-tools"> <button type="button" class="btn btn-tool" data-card-widget="remove"> <i class="fas fa-times"></i>  </button> </div>
       </div>
       <form id="tax_form" action="#" method="post" autocomplete="off">
        <input type="hidden" name="newtax" required="true">
        <?php if(isset($_GET['ptid'])){  ?>
        <input type="hidden" name="newtax" id="newtax" value="<?php echo @$ptid ;?>"/>
        <?php }else{?>
        <input type="hidden" name="newtax" id="newtax" value="0"/>
        <?php } ?>

        <div class="card-body">
         <div class="col-md-12">
           <div class="row">

                <div class="col-md-12">
              <div class="form-group">
                <label>Sales/Purchase Group<b class="text-danger"> *</b></label>
                <select name="sp_type" id="sp_type" class="form-control select2" style="width: 100%;" required="true">
                  <option value="<?php echo @$rowarea['sp_type']; ?>" selected> <?php echo @$rowarea['sp_type']; ?></option>
                    <option value="sales">sales</option>
                    <option value="purchase">purchase</option>
                </select> 
              </div>
            </div>
            <div class="col-md-6">
              <div class="form-group">
                <label>Tax Group Name<b class="text-danger"> *</b></label>
                <input type="text" name="tax_group"  value="<?php echo @$tax_group ?>" class="form-control form-control-sm inputselect" placeholder="Group Name" style="text-align:center;" required="true">
              </div>
            </div>

            <div class="col-md-6">
              <div class="form-group">
                <label>Tax Margin%<b class="text-danger"> *</b></label>
                <input type="number" name="tax_margin"  value="<?php echo @$tax_margin ?>" class="form-control form-control-sm inputselect" placeholder="Margin%" style="text-align:center;" required="true">
              </div>
            </div>
          </div>
        </div>
      </div>
      <center>
       <div class="card-footer" style="padding: 8px 5px;">
        <button type="submit" id="save" class="btn btn-success btn-xs"><?php if (@$_GET['ptid']) {echo 'update ';}else{echo 'Save Info';}?></button>
        <button type="reset" class="btn btn-secondary btn-xs">Reset</button>
      </div>
    </center>
  </form>
  <div class="card-body p-1">
    <tr>
      <th rowspan="3"  class="text-center" >
        <input type="text" id="search" class="form-control form-control-sm search"  placeholder="searching" required="true" style="border-radius: ;border:1px solid primary;width:100%; text-align:center; padding:; ">
      </th>

    </tr>
    <table id="trbl_table" class=" ttable" cellpadding="0" cellspacing="0">
      <thead>
        <tr class="sticky-top">
          <th class="text-center" style="width:5%;">S/l</th>
          <th style="width:25%;">Company  Name</th>
          <th class="text-center" style="width:25%;">Type </th>
          <th class="text-center" style="width:25%;">Tax Group Name </th>
          <th class="text-center" style="width:25%;">Tax%</th>
          <th class="text-center" style="width:20%;">Opening Date</th>
        </tr>
      </thead>
      <tbody id="colview" class="searchtable">
        <?php
        $pro_tax_query= mysqli_query($conn,"SELECT * FROM pro_tax WHERE  coid='$coid' AND $bid='$bid' AND brid='$brid'  ") or die (mysqli_error($conn));
        $i=0;
        while ($rowar= mysqli_fetch_array ($pro_tax_query) ){
         $companyid  =$rowar['coid'];
         $co_name=mysqli_fetch_assoc(mysqli_query($conn,"SELECT co_name FROM company WHERE coid='$companyid'  LIMIT 1 "))['co_name'];  
         ?>
          <tr class="btn-outline-dark tr-hover delete_op<?php echo $rowar['ptid'];?>"  onclick="pagecall('../company_setup/tax_index.php?ptid='+'<?php echo $rowar['ptid'];?>','#settingview')">
          <td  style="font-size: 11.5px;text-align: center;"><?php echo ++$i ?></td>
          <td  style="font-size: 11.5px"><?php echo $co_name;?> </td>
          <td  style="font-size: 11.5px"><?php echo $rowar['sp_type'];?> </td>



          <td   style="font-size: 11.5px"><?php echo $rowar['tax_group'] ;?>  </td>
          <td  style="font-size: 11.5px"><?php echo $rowar['tax_margin'];?></td>
          <td  style="font-size: 11.5px"> <?php echo $rowar['date'];?></td>
        </tr>
      <?php } ?>
    </tbody>
  </table>
</div>
</div>
</div>




<div class="col-md-6">
 <div class="card card-primary card-outline direct-chat direct-chat-primary shadow-none" style="border-left:1px solid #969c9d;border-right:1px solid #969c9d;border-bottom:1px solid #969c9d;">
   <div class="card-header" style="padding: 5px 8px;"><h3 class="card-title">New Feature  Add</h3> <div class="card-tools"> <button type="button" class="btn btn-tool" data-card-widget="remove"> <i class="fas fa-times"></i>  </button> </div>
 </div>


 <center>Please Wait for new Feature</center>

</div>
</div>


</div>
</div>
</section>

<script>
 $(document).ready(function() {
     $("#sp_type").select2();

   $('#tax_form').on('submit', function(e){
     $('#save').prop('disabled', true);
     $('#save').html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> '+'Loading...');
     e.preventDefault();  
     $.post("../company_setup/tax_index_db.php",$(this).serialize(),function(data){
      $('#tax_form')[0].reset();
      $('#save').prop('disabled', false);
      $('#save').html('Company Save');
      $.post('../company_setup/tax_index.php?running='+1,{},function(res){
       $('#settingview').html(res);
       toastr.success(Showing, '<?php echo "Data Load Succefully " ?>');
     }); 
    });
   });

    $('.search').on('keyup',function(){
      var searchTerm = $(this).val().toLowerCase();
      $('.searchtable tr').each(function(){
        var lineStr = $(this).text().toLowerCase();
        if(lineStr.indexOf(searchTerm) === -1){
          $(this).hide();
        }else{
          $(this).show();
        }
      });
    });

    $('th').each(function (col) {
      $(this).hover(
        function () {
          $(this).addClass('focus');
        },
        function () {
          $(this).removeClass('focus');
        }
        );
      $(this).click(function () {
        if ($(this).is('.asc')) {
          $(this).removeClass('asc');
          $(this).addClass('desc selected');
          sortOrder = -1;
        } else {
          $(this).addClass('asc selected');
          $(this).removeClass('desc');
          sortOrder = 1;
        }
        $(this).siblings().removeClass('asc selected');
        $(this).siblings().removeClass('desc selected');
        var arrData = $('table').find('tbody >tr:has(td)').get();
        arrData.sort(function (a, b) {
          var val1 = $(a).children('td').eq(col).text().toUpperCase();
          var val2 = $(b).children('td').eq(col).text().toUpperCase();
          if ($.isNumeric(val1) && $.isNumeric(val2))
            return sortOrder == 1 ? val1 - val2 : val2 - val1;
          else
            return (val1 < val2) ? -sortOrder : (val1 > val2) ? sortOrder : 0;
        });
        $.each(arrData, function (index, row) {
          $('tbody').append(row);
        });
      });
    });
  });
</script>

