<?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(48);?></h3>
        			<div class="card-tools">
                <span class="mark1" onclick="copy(this);" title="Copy Invoice"><?php echo $invoice = invoice("OP");?></span>
        				<button type="button" class="btn btn-tool" data-card-widget="remove">
        					<i class="fas fa-times"></i>
        				</button>
        			</div>
        		</div>

	            <form id="op_form" action="#" method="post" autocomplete="off">
                <input type="hidden" name="op_invoice" value="<?php echo $invoice;?>">
                     <div class="card-body">
                        <div class="col-md-12">
                          <div class="row">
                           <div class="col-md-5">
                              <div class="form-group">
                                 <label><?php echo language(221);?></label>
                                 <dt id="show" style="float: right;"></dt>
                                 <input type="hidden" name="acid">
                                 <select id="acid" onchange="balance(this.value,'#show')" class="form-control select2" style="width: 100%;" required="true">  
                                 </select>
                              </div>
                           </div>

                           <div class="col-md-4">
                              <div class="form-group">
                                 <center><label><?php echo language(163);?></label></center>
                                  <input type="number" name="amount" onblur="blcal(this.value)" 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">
                                 <label><?php echo language(130);?></label>
                                 <select name="ttype" class="form-control select2" style="width: 100%;" required="true">
                                  <option selected="selected" value="+"><?php echo language(217);?> (+)</option>
                                  <option value="-"><?php echo language(218);?> (-)</option>
                                </select>
                              </div>
                            </div>

                        <div class="col-md-12"><hr style="margin-top:-5px;margin-bottom: 7px;"></div>
              						<div class="col-md-12">
              						   <div class="form-group">
              						      <label><?php echo language(128);?></label>
              						      <textarea name="details" class="form-control form-control-sm inputselect" rows="2" placeholder="Enter ...">Opening balance</textarea>
              						   </div>
              						</div>

                         <div class="col-md-3">
                          <div class="form-group">
          						      <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"><?php echo language(155);?></label>
          						      </div>
          						   </div>
                        </div>
            						<div class="col-md-3">
            						   <div class="form-group">
            						      <div class="custom-control custom-checkbox">
            						         <input name="sms" class="custom-control-input" type="checkbox" id="customCheckbox2" value="yes">
            						         <label for="customCheckbox2" class="custom-control-label"><?php echo language(132);?></label>
            						      </div>
            						   </div>
            						</div>

            					 <div class="col-md-3">
            						<div class="form-group"><span style="float: right;margin: 2px -35px;"><?php echo language(131);?></span>
            						    <input type="text" name="tdate" class="form-control form-control-sm" style="text-align:center;" readonly="true" required="true" value="<?php echo $co_f_year_start;?>">
            						</div>
                       </div>
                       <div class="col-md-3"></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 class="col-md-2"></div>
</div>
</div>
</section>

<script>
  $(document).ready(function(){
      $("select").select2();
      $("#acid").select2({
          ajax: {
              url: "../voucher/s_acc.php",
              type: "post",
              dataType: 'json',
              delay: 250,
              data: function (params) {
                  return {
                      search: params.term,
                      g_type: "'mcash','bank','du-adv','su-deb','stl','su-cre'"
                  };
              },
              processResults: function (response) {
                  return {
                      results: response
                  };
              },
              cache: true
          }
      });
  });

  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');
      }
  }

balance ($("#acid").val(),"#show");

  function blcal (value){
    if (!isNaN(value)) {   
     var v = $("#acid").val().split(","); 
     var sbl  = Number(v[1]) + Number(value);
     if (sbl>=0) {
        $("#show").css("color","green");
        $("#show").text(bden.format(sbl) + ' Dr');
     } else {
        $("#show").css("color","red");
        $("#show").text(bden.format(-sbl) + ' Cr');
     }
    }
  }
</script>

<script>
$(document).ready(function() {
$('#op_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/op_voucher_db.php",$(this).serialize(),function(data){
     $('#op_form')[0].reset();
     $('#save').prop('disabled', false);
     $('#save').html('Vouchar Save');
     
             pagecall('../voucher/op_voucher_index.php','#mview');

  
         toastr.success(Successfully, yourdata);

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