<?php require_once('../auth/auth.php'); ?>
<section class="content">
   <div class="container-fluid">
<div class="row">
   <div class="col-md-3"></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: 3px 8px;">
            <h3 class="card-title"><?php echo language(58);?> </h3>
            <div class="card-tools m-0">
               <button type="button" class="btn btn-tool" data-card-widget="remove">
               <i class="fas fa-times"></i>
               </button>
            </div>
         </div>
         <form id="ret_sp_form" class="mt-2" action="#" method="post" autocomplete="off">
            <div class="card-body">
               <div class="col-md-12">
                  <div class="row">
                    <div class="col-md-3 pr-0">
                    </div>
                     <div class="col-md-6">
                      <div class="form-group">
                         <label><?php echo language(136);?></label>
                         <dt id="s_show" style="float: right;"></dt>
                         <input type="hidden" name="s_acid">
                         <select id="s_acid" onchange="balance(this.value,'#s_show')" class="form-control select2" required="true">
                          <option></option>
                        <?php 
                            $accat= mysqli_query($conn,"SELECT acid,ac_name,ac_alise,ac_number,balance,outlet_id FROM accounts LEFT JOIN ac_sub_g_category ON(accounts.gcatid=ac_sub_g_category.ac_g_catid) WHERE accounts.coid='$coid' AND bid='$bid' AND brid='$brid' AND active=1 AND g_type IN('su-cre')") or die(mysqli_error($conn));
                              while($acat= mysqli_fetch_assoc($accat)){
                              echo '<option value='.$acat["acid"].','.$acat["balance"].'>'.$acat["ac_name"]."-".$acat["ac_number"].' '.'('.$acat["outlet_id"].')</option>';
                            }?>   
                         </select>
                      </div>
                     </div>
                    <div class="col-md-3 pl-0">
                      <button type="submit" id="save" class="btn btn-success btn-xs mt-3"><i class="fa fa-search"></i> <?php echo language(68);?></button>
                    </div>                     
                  </div>
               </div>
            </div>
         </form>
      </div>
   </div>
   <div class="col-md-3"></div>
</div>

</div>
</section>
<script>
  $("select").select2();   
  function balance (value,sid){
      var vvvv = value.split(",");
      $(sid).next().val(Number(vvvv[0]));
      var bl  = Number(vvvv[1]);
      if (bl >=0) {
        $(sid).css("color","green");
        $(sid).text(bden.format(bl) + ' Dr');
      } else {
        $(sid).css("color","red");
        $(sid).text(bden.format(-bl) + ' Cr');
      }
  }

   $(document).ready(function(){
     $('#ret_sp_form').on('submit', function(e){
      e.preventDefault();
     $('#save').prop('disabled', true);
     $('#save').html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> '+'Loading...');
     e.preventDefault();  
     $.post("../purchase_retrun/pur_retrun_index.php",$(this).serialize(),function(data){
      $('#ret_sp_form')[0].reset();
      $('#save').prop('disabled', false);
      $('#save').html('Save');
      $('#purmview').html(data);
       toastr.success(Showing, '<?php echo "Data Load Succefully" ?>'); 
    });
   });
  });  
</script>