<?php require_once('../auth/auth.php');require_once('../auth/function.php'); ?>
<section class="content">
   <div class="container-fluid">
      <div class="row">
         <div class="col-md-2"></div>
         <div class="col-md-8">
            <div class="card card-success 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"> <?php echo language(49); ?></h3>
                  <div class="card-tools">
                     <span class="mark1" onclick="copy(this);" title="Copy Invoice"><?php echo $invoice = invoice("OPINS");?></span>
                     <button type="button" class="btn btn-tool" data-card-widget="remove">
                     <i class="fas fa-times"></i>
                     </button>
                  </div>
               </div>
               <div class="card-body">
               <form id="installment_form" class="mt-2" action="#" method="post" autocomplete="off">
                     <div class="col-md-12">
                        <div class="row mt-2">
                            <input type="hidden" name="ins_invoice" id="ins_invoice" value="<?php echo $invoice; ?>">


                            
		                    <div class="col-md-4">
		                      <div class="form-group">
		                         <label><?php echo language(167);?></label>
		                         <dt id="s_show" style="float: right;"></dt>
		                         <input type="hidden" name="c_acid">
		                         <select id="c_acid" onchange="balance(this.value,'#s_show')" class="form-control select2" style="width: 100%;" required="true">
		                          	<option value=""></option>

		                        <?php 
		                            $accat= mysqli_query($conn,"SELECT acid,ac_name,ac_alise,ac_number,balance 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["ac_alise"].')</option>';
		                            }?>   
		                         </select>
		                      </div>
		                     </div>

                             <div class="col-md-3">
                              <div class="form-group">
                                 <center><label><?php echo language(236);?></label></center>
                                 <input type="number" value="0" name="ins_due_amount" class="form-control form-control-sm inputselect" placeholder="xxx" style="text-align:center;" required="true">
                              </div>
                           </div>



                           <div class="col-md-3">
                              <div class="form-group">
                                 <center><label><?php echo language(348);?></label></center>
                                 <input type="number" value="2" name="ins_qty" min="2" class="form-control form-control-sm inputselect" placeholder="xxx" style="text-align:center;" required="true">
                              </div>
                           </div>


                           <div class="col-md-2">
                              <div class="form-group">
                                 <center><label><?php echo language(358);?></label></center>
                                 <input type="text" name="first_ins_date" class="form-control form-control-sm" onmouseover="stdate(this)" style="text-align:center;" readonly="true" required="true" value="<?php echo $date;?>">
                              </div>
                           </div>

                           <div class="col-md-2">
                              <div class="form-group">
                                 <center> <label><?php echo language(349); ?></label> </center>
                                 <select  name="ins_type" class="form-control select2" style="width: 100%;" required="true">
                                 	<option value=""></option>
                                    <option value="Daily">   <?php echo language(350);?></option>
                                    <option value="Weekly">  <?php echo language(351);?></option>
                                    <option value="Monthly"> <?php echo language(352);?></option>
                                 </select>
                              </div>
                           </div>



                          <div class="col-md-4">
                              <div class="form-group">
                                 <center><label><?php echo language(353);?></label></center>
                                 <input type="text" name="service_name" class="form-control form-control-sm" value="N/A"  style="text-align:center;"  required="true" value="<?php echo $date;?>">
                              </div>
                           </div>
                     



                           <div class="col-md-3">
                              <div class="form-group">
                                 <center><label><?php echo language(354);?></label></center>
                                 <input type="text" name="reference_name" class="form-control form-control-sm" value="N/A"  style="text-align:center;"  required="true" value="<?php echo $date;?>">
                              </div>
                           </div>

                            <div class="col-md-3">
                              <div class="form-group">
                                 <center><label><?php echo language(355);?></label></center>
                                 <input type="number" name="reference_number" class="form-control form-control-sm" value="01"  style="text-align:center;"  required="true" value="<?php echo $date;?>">
                              </div>
                           </div>

                            <div class="col-md-3">
                              <div class="form-group">
                                 <center><label><?php echo language(356); ?></label></center>
                                 <input type="text" name="reference_address" class="form-control form-control-sm" value="N/A"  style="text-align:center;"  required="true" value="<?php echo $date;?>">
                              </div>
                           </div> 

                           <div class="col-md-3">
                              <div class="form-group">
                                 <center><label><?php echo language(131);?></label></center>
                                 <input type="text" name="ac_op_date" class="form-control form-control-sm" onmouseover="lcdate(this)" style="text-align:center;" readonly="true" required="true" value="<?php echo $date;?>">
                              </div>
                           </div>


                           <div class="col-md-3 ">
                               <div class="form-group mt-3">
                                 <div class="custom-control custom-checkbox">
                                   <input name="email" class="custom-control-input" type="checkbox" id="customCheckbox1" value="yes">
                                   <label for="customCheckbox1" class="custom-control-label float-right"><?php echo language(155);?></label>
                                 </div>
                               </div>
                             </div>

                             <div class="col-md-3 ">
                               <div class="form-group mt-3">
                                 <div class="custom-control custom-checkbox">
                                   <input name="sms" class="custom-control-input" type="checkbox" id="customCheckboxsmscash" value="yes">
                                   <label for="customCheckboxsmscash" class="custom-control-label float-right"><?php echo language(132);?></label>
                                 </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 echo language(23);?></button>
          <button type="reset" class="btn btn-secondary btn-xs"><?php echo language(24);?></button>
        </div>
      </center>
                  </form>
          
               </div>
            </div>
         </div>
         <div class="col-md-2"></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() {
      var ins_invoice = $("#ins_invoice").val();
     $('#installment_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("../voucher/ins_op_voucher_db.php",$(this).serialize(),function(data){
          $('#installment_form')[0].reset();
          $('#save').prop('disabled', false);
            toastr.success(Showing, yourdata);
        $("#modal-lg").modal({backdrop: "static"});
          pagecall('../print_setup/op_ins_preview.php?ins_invoice=<?php echo $invoice?>','#mdview',0);
               $('#save').html('save');

     });
    });
   
   });  
</script>