<?php require_once('../auth/auth.php');
 $itype='EPUR';?>
<section class="content">
  <div class="container-fluid">
    <div class="row">
      <div class="col-md-12">
        <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: 3px 8px;">
            <h3 class="card-title"><?php echo language(183);?> </h3>
            <div class="card-tools">
              <button type="button" class="btn btn-tool" onclick="ExcelMe('#gledger_table')"  title="Download Excel">
              <i class="far fa-file-excel"></i>
              </button>
              <button type="button" onclick="BfpdfMe('#gledger_table');" class="btn btn-tool" title="Download Pdf"><i class="fas fa-download"></i></button>
              <button type="button" class="btn btn-tool" onclick="printMe('#grpl_show','header')" title="Print Now"><i class="fas fa-print"></i></button>
              <button type="button" class="btn btn-tool" data-card-widget="remove" data-dismiss="modal"><i class="fas fa-times"></i></button>
            </div>
          </div>
          <div class="card-body p-1">
            <div class="col-md-12" style="border:1px solid #969c9d;background: hsla(0,0%,50.2%,.11);border-radius: 5px;">
              <div class="row mt-1 mb-n2">
                <?php if($bid_check>1 || $multi_bid > 1) {?>
                <div class="col-md-2">
                  <div class="form-group">
                    <label>  <?php echo language(231); ?> </label>
                    <select id="bbid" class="form-control select2" style="width: 100%" onchange="lives();">
                      <option selected value="<?php echo $bid;?>">
                        <?php echo $bid_name=mysqli_fetch_assoc(mysqli_query($conn,"SELECT bid_name FROM business WHERE bid='$bid' LIMIT 1 "))['bid_name'];
                        ?>
                      </option>
                      <option value="0"> <?php echo language(222); ?> </option>
                      <?php
                      $prr= mysqli_query($conn,"SELECT bid,bid_name FROM business WHERE coid='$coid'") or die(mysqli_error($conn));
                      while($prw= mysqli_fetch_assoc($prr)){
                      echo '<option value='.$prw["bid"].'>'.$prw["bid_name"].'</option>';
                      }?>
                    </select>
                  </div>
                </div>
                <?php } else { ?>
                <input type="hidden" id="bbid" value="<?php echo $bid;?>">
                <?php } if( $brid_check > 1 ||  $multi_brid > 1) { ?>
                <div class="col-md-2">
                  <div class="form-group" >
                    <label> <?php echo language(232); ?> </label>
                    <select  id="bbrid"  class="form-control select2" style="width: 100%" required="true" onchange="lives();">
                      <option selected value="<?php echo $brid;?>">
                        <?php echo $branch_name=mysqli_fetch_assoc(mysqli_query($conn,"SELECT branch_name FROM branch WHERE bid='$bid'  LIMIT 1 "))['branch_name'];
                        ?>
                      </option>
                      <option value="0"> <?php echo language(222); ?> </option>
                      <?php
                      $prr= mysqli_query($conn,"SELECT brid,branch_name FROM branch WHERE coid='$coid' AND bid='$bid'") or die(mysqli_error($conn));
                      while($prw= mysqli_fetch_assoc($prr)){
                      echo '<option value='.$prw["brid"].'>'.$prw["branch_name"].'</option>';
                      }?>
                    </select>
                  </div>
                </div>
                <?php } else { ?>
                <input type="hidden" id="bbrid" value="<?php echo $brid;?>">
                <?php } ?>

                <div class="col-md-2">
                  <div class="form-group" >
                    <label> Select Group</label>
                    <select id="gcatid"  class="form-control select2" style="width: 100%" required="true" onchange="lives();">
                      <option value="0"> <?php echo language(222); ?> </option>
                      <?php
                      $prr= mysqli_query($conn,"SELECT ac_g_catid,ac_g_cat_name FROM ac_sub_g_category WHERE coid='$coid'") or die(mysqli_error($conn));
                      while($prw= mysqli_fetch_assoc($prr)){
                      echo '<option value='.$prw["ac_g_catid"].'>'.$prw["ac_g_cat_name"].'</option>';
                      }?>
                    </select>
                  </div>
                </div>
                
                <div class="col-md-2">
                  <div class="form-group">
                    <label><?php echo language(257);?></label>
                    <input type="text" id="fdate" class="form-control form-control-sm text-center" onmouseover="lcdate(this)" readonly="true" required="true" value="<?php echo $date;?>">
                  </div>
                </div>
                <div class="col-md-2">
                  <div class="form-group">
                    <label><?php echo language(258);?></label>
                    <input type="text" id="edate" class="form-control form-control-sm text-center" onmouseover="lcdate(this)" readonly="true" required="true" value="<?php echo $date;?>">
                  </div>
                </div>
              </div>
            </div>
            <div id="grpl_show" class="mt-2"></div>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>
<script type="text/javascript">
   $(document).ready(function(){
     $('select').select2();       
     pagecall('../display_report/group_ledger_view.php?bbid=<?php echo $bid;?>'+'&bbrid=<?php echo $brid;?>'+'&gcatid=0'+'&fdate=<?php echo $date;?>'+'&edate=<?php echo $date;?>','#grpl_show',0);
   });
     function lives() {
       let bbid        = $('#bbid').val();
       let bbrid       = $('#bbrid').val();
       let gcatid      = $('#gcatid').val();
       let fdate       = $('#fdate').val();
       let edate       = $('#edate').val();
       $(".preloader").css('display','flex');
       $.get("../display_report/group_ledger_view.php",
         {
           bbid        : bbid,
           bbrid       : bbrid,
           gcatid      : gcatid,
           fdate       : fdate,
           edate       : edate
         },
         function(html) {
           $("#grpl_show").html(html);
           $('.preloader').hide();
         });
     }
      // FOR DATE PICKER //
    var timer = null;
    $('#fdate,#edate').change(function(){
      clearTimeout(timer);
      timer = setTimeout(lives, 100);
    });
</script>