<?php require_once('../auth/auth.php'); ?>
<?php 
  $sltype = $_GET['sltype'];
?>
<section class="content">
 <div class="container-fluid">
  <div class="row">
   <div class="col-md-3"></div>
   <div class="col-md-5">
      <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 if ($sltype=='ERSL') { echo language(166);} else if($sltype=='INSL'){ echo language(376); } ?> </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="cs_form" action="#" method="post" autocomplete="off">
            <div class="card-body">
               <div class="col-md-12">
                  <div class="row">
                    <div class="col-md-3 pr-0">
                      <!--<button class="btn btn-success btn-xs mt-3 text-nowrap"><i class="fa fa-user-plus"></i> <?php echo language(168);?></button>-->
                    </div>
                     <div class="col-md-6">
                      <div class="form-group">
                         <label><?php echo language(167);?></label>
                         <dt id="s_show" style="float: right;"></dt>
                         <input type="hidden" name="c_acid">
                         <input type="hidden" name="sltype" value="<?php echo $sltype;?>">
                         <select id="c_acid" onchange="balance(this.value,'#s_show')" class="form-control select2" style="width: 100%;" 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-deb') AND ac_type IS NULL") 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-4"></div>
  </div>
 </div>
</section>
<script>
  $("select").select2();
  
  $('#c_acid').select2({
    "language": {
       "noResults": function(){
           return "No Results <a href='#' onclick='new_customer()' class='float-right text-success' style='font-weight:600;'> <i class='fa fa-plus'> </i> New Add </a>";
       }
   },
    escapeMarkup: function (markup) {
        return markup;
    },
  });
  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(){
     $('#cs_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();  
     $.get("../sales/sales_index.php",$(this).serialize(),function(data){
      $('#cs_form')[0].reset();
      $('#save').prop('disabled', false);
      $('#save').html('Save');
      $('#salmview').html(data);
       toastr.success(Showing, '<?php echo "Data Load Succefully" ?>'); 
    });
   });
  });  
</script>
<script>
 function new_customer(){    
   $("#modal-lg").modal({backdrop: "static"});
    pagecall('../accounts/add_new_accounts.php?type='+'<?php echo $sltype ?>','#mdview');   
   } 
</script>