<?php
 echo @$_GET['msg'];
  session_start();
  if(isset($_SESSION['userId'])){ 

include 'template/header.php';

?>
 <link rel="stylesheet" href="css/jquery-ui.css">
  <!-- <link rel="stylesheet" href="/resources/demos/style.css"> -->
  <script src="js/jquery-1.12.4.js"></script>
  <script src="js/jquery-ui.js"></script>
    <link rel="stylesheet" href="css/bootsrap_my.css" />


  <link rel="stylesheet" href="css/jquery-ui.css">
        <link rel="stylesheet" href="bootstrap.min.css" />
    <script src="js/jquery-1.12.4.js"></script>
     <script src="js/jquery-ui.js"></script>
<div class="ch-container">
    <div class="row">
        
<!-- SIDEBAR HERE-->
<?php

include 'template/sidebar.php';

?>
    

        <div id="content" class="col-lg-10 col-sm-10">
            <!-- content starts -->
      <div>
    <ul class="breadcrumb">
        <li>
            <a href="#">Home</a>
        </li>
        <li>
            <a href="#">Voucher Transfer</a>
        </li>
    </ul>
</div>



  <style>
/* Chrome, Safari, Edge, Opera */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Firefox */
input[type=number] {
  -moz-appearance: textfield;
}
</style>




  <style>
    .popup-container {
      display: none;
      position: fixed;
      top: 20%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 300px;
      padding: 20px;
      background-color: #f0f0f0;
      border: 1px solid #ccc;
      border-radius: 5px;
    }
    
    .popup-container label {
      display: block;
      margin-bottom: 10px;
    }
    
    .popup-container input[type="text"] {
      width: 100%;
      padding: 5px;
      margin-bottom: 15px;
    }
    
    .popup-container button {
      width: 100%;
      padding: 10px;
      background-color: #4caf50;
      color: #fff;
      border: none;
      border-radius: 5px;
      cursor: pointer;
}

        /* Hide the Actions column on mobile screens */
    @media (max-width: 768px) {
   
   
     .hide-on-mobile {
      display: none;
    }
    }


  </style>


<div class="row">
    <div class="box col-md-12">
        <div class="box-inner">

          
         <?php
                    require 'connection.php';

                 $qryvno = "SELECT max(vno) as vno FROM jvvoucher";
             $runvno = mysqli_query($connect, $qryvno) or die(mysqli_error($connect));
            $rowvno = mysqli_fetch_array($runvno);
?>
            <div class="box-header well">
                <h2><i class="glyphicon glyphicon-info-sign"></i> V.No </h2>
                <h2 id="vno" style="margin-left: 10px"><?php echo $rowvno['vno']+1; ?></h2>

    <!--   <p>Date: <input type="text" id="datepicker" data-role="calendarpicker" data-input-format="%d-%m-%y"></p> -->


                <div class="box-icon">
                    <a href="#" class="btn btn-setting btn-round btn-default"><i
                            class="glyphicon glyphicon-cog"></i></a>
                    <a href="#" class="btn btn-minimize btn-round btn-default"><i
                            class="glyphicon glyphicon-chevron-up"></i></a>
                    <a href="#" class="btn btn-close btn-round btn-default"><i
                            class="glyphicon glyphicon-remove"></i></a>
                </div>
            </div>
            <div class="box-content row">

                <!-- Account -->
              
                <div class="col-lg-4 col-md-12" >

                 <select id="selaccid2" class="form-control selectpicker"data-live-search="true">
                 <?php
                    require 'connection.php';

              $qry = "SELECT * FROM accreg  where activityacc=0";
             $run = mysqli_query($connect, $qry) or die(mysqli_error($connect));
    while($row = mysqli_fetch_array($run)){
?>
        <option id="dd" value="<?php echo $row['accid']; ?>"><?php echo $row['accname']; ?></option>
        <?php } ?>
            </select>
                </div>
      <div class="col-lg-7 col-md-12"> 
        <div class="col-lg-9">
                  <select id="custid" class="form-control selectpicker"data-live-search="true">
                 <?php
                    require 'connection.php';

              $qry = "SELECT * FROM accreg  where activityacc=0";
             $run = mysqli_query($connect, $qry) or die(mysqli_error($connect));
    while($row = mysqli_fetch_array($run)){
?>
        <option id="dd" value="<?php echo $row['accid']; ?>"><?php echo $row['accname']; ?></option>
        <?php } ?>
            </select>
            </div>
      </div>
                <!-- dated -->
            <div class="col-lg-1 col-md-12" style="margin-bottom: px;">
               <input style=" border: none; border-bottom: 1px solid black; float: right; font-size: 2rem" type="date"  data-date-format="DD MMMM YYYY" id="dated">
                </div>
<!-- *********************************** -->
     <div class="col-lg-6 col-md-12" style="margin-bottom: 10px">
</div>
     <div class="col-lg-6 col-md-12" style="margin-bottom: 10px; margin-top: 10px;" >
                        <div style=" float: right;" class="col-lg-4 col-md-12" >
                    
                 <i  style="font-size: 30px;  color: darkred;" onclick="openPopup()" class="glyphicon glyphicon-search custsrch"></i>
  
            </div>    
              
            
                </div>
      <div class="col-lg-12 col-md-12">
      
   <div class="col-lg-6 col-md-12">
        <input autocomplete="off" style="margin-left: -10px; " type="text" name="refno" id="refno" class="form-control" placeholder="Description">


        <span id="error_qty" class="text-danger"></span>
      </div>
       

 <div class="col-lg-2 col-md-12">

        <input autocomplete="off"  style="margin-left: -10px; " type="number" name="rate" id="rate" class="form-control" placeholder="Amount">
        <span id="error_rate" class="text-danger"></span>
      </div>
       

      </div>

      <div class="form-group" align="center">
        <input type="hidden" name="row_id" id="hidden_row_id" />
        <!-- <button type="button" name="save" id="save" class="btn btn-info">Save</button> -->
        <!-- <button type="button" name="post" id="post" class="btn btn-info">POST</button> -->
      </div>

    <div id="action_alert" title="Action">
    </div>
      <form method="post" id="user_form">
        <div class="col-lg-12">
          <label class="glyphicon glyphicon-shopping-cart" style="color: maroon; font-size: 30px; margin-top: 3px; margin-left: 15px;"></label>
          <label class="" style="color: maroon; font-size: 20px;">Add to Cart</label>
          <!-- <table class="table table-striped table-bordered" id="user_data"> -->
                  <table class="table" id="user_data">

            <tr>
                   <th hidden>ID</th>
                   <th hidden>ID2</th>
                   <th hidden>Date</th>
                    <th>V.No.</th>
                    <th>Description</th>
                    <th>Amount</th>
                    <th>Details</th>
                    <th>Remove</th>
                  </tr>
             
           
          </table>

        </div>
        <div align="center">
                 <input style="margin-bottom: 20px;" type="submit" name="insert" id="insert" class="btn btn-info" value="Insert into Database" />

 <img style=" display: none; height: 30px; width: 30px; margin-bottom: 20px;" id="load" src="ajaxresult.gif">



        </div>
      </form>
        <div class="col-lg-5 col-md-5">
    </div>
    <div class="col-lg-6 col-md-6">
      <button  id="btndlt" class="btn btn-default">View Detail</button>
      
    </div>
    </div>
  
 <i id="refresh" style="color: red; float: right;" class="glyphicon glyphicon-refresh btn btn-lg"></i>




<!-- ************************************** -->
            </div>
<!-- ***************************************************************** -->

<div class="row">
    <div class="box col-md-12">
        <div class="box-inner">

            <div class="box-header well">
                <h2></i>Detail Section</h2>
                <div class="box-icon">
                   
                    <a href="index.php" class="btn btn-minimize btn-round btn-default"><i
                            class="glyphicon glyphicon-chevron-up"></i></a>
                    <a href="#" class="btn btn-close btn-round btn-default"><i
                            class="glyphicon glyphicon-remove"></i></a>
                </div>
            </div>
            <div class="box-content row">
              <div class="col-lg-12" id="itemdetail" style="margin-bottom: 20px;">
                
        <!--          <table class="table" id="table">
                    <tr>
                    <th>Sr. No.</th>
                    <th>Product Name</th>
                    <th>Rate</th>
                    <th>Qty</th>
                    <th>Amount</th>
                  </tr>
                                     <tbody id="itemdetail">
                                     </tbody>
                                   </table> -->
                             <!--       <div class="col-lg-9 col-md-12">
                           <input disabled style="float: right; width: 100px;" type="text" id="tamt" name="">
                           </div> -->

                           
                </div>
                      <div class="col-lg-6 col-md-12">
  
                           </div>

      <div class="col-lg-6 col-md-12">


                           </div>
  <div class="col-lg-1 col-md-12">
    </div>
            </div>
        </div>
    </div>
</div>

<!-- ********************************************************************** -->


        </div>


    </div>


   <div id="popup" class="popup-container">
    <label for="voucher-number">Voucher Number:</label>
    <input style="margin-bottom: 10px; width: 100%" id="voucher-number" type="number">
    <button id="delinv" style="margin-bottom: 20px;" >View Detail</button>

    <button onclick="closePopup()">Close</button>
  </div>

<!-- *****************************modal start*************************** -->

<div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">
    
      <!-- Modal content-->
      <div class="modal-content">
        <div style="background-color: darkblue" class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h5 style="color: white" class="modal-title">JV Edit / Update</h5>
          <label hidden id="accidlbl"></label>
          
        </div>
        <div class="modal-body">
            <input value="<?php echo $dated; ?>" style=" border: none; border-bottom: 1px solid black; float: right; font-size: 2rem" type="date"  data-date-format="DD MMMM YYYY" id="dated2">
            <br>
            <label>Credit Side</label>
            <br>
              <select id="craccid" class="form-control selectpicker"data-live-search="true">
                 <?php
                    require 'connection.php';

              $qry = "SELECT * FROM accreg where activityacc=0";
             $run = mysqli_query($connect, $qry) or die(mysqli_error($connect));
    while($row = mysqli_fetch_array($run)){
?>
        <option  value="<?php echo $row['accid']; ?>"><?php echo $row['accname']; ?></option>
        <?php } ?>
            </select>
          
            <br>
            <div id="mdlcntntdtl">
                




            </div>

<br>
          <label>Debit Side</label>
            <br>
              <select id="draccid" class="form-control selectpicker"data-live-search="true">
                 <?php
                    require 'connection.php';

              $qry = "SELECT * FROM accreg where activityacc=0";
             $run = mysqli_query($connect, $qry) or die(mysqli_error($connect));
    while($row = mysqli_fetch_array($run)){
?>
        <option  value="<?php echo $row['accid']; ?>"><?php echo $row['accname']; ?></option>
        <?php } ?>
            </select>
        </div>
        <div class="modal-footer">
            <i class="pull-left" style=" color: red; font-size: 26px; font-weight: bold;" id="itmnamelbl"></i>

          <button  id="btndlt2"  class="btn btn-sm btn-primary pull-left" style="background-color: red">Delete Voucher</button>

          <button id="btnupdt"  class="btn btn-sm btn-warning" style="background-color: red">Update JV</button>

          <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
</div>
<!-- **** -->

<!-- ******************************modal end********************** -->




<!-- ********************************************************************** -->


    <!-- content ends -->
    </div><!--/#content.col-md-0-->
</div><!--/fluid-row-->

   

    <hr>



<?php
include 'template/footer.php';
?>



<script>  
$(document).ready(function(){ 
  
  var count = 0;
})


  $( function() {
    $( "#datepicker" ).datepicker();
  } );
  </script>

<script type="text/javascript">
 var today = new Date();

document.getElementById("dated").value = today.getFullYear() + '-' + ('0' + (today.getMonth() + 1)).slice(-2) + '-' + ('0' + today.getDate()).slice(-2);

document.getElementById("dated2").value = today.getFullYear() + '-' + ('0' + (today.getMonth() + 1)).slice(-2) + '-' + ('0' + today.getDate()).slice(-2);
  </script>



<script type="text/javascript">
  
  $('#btndlt').click(function(){
    var dated= $('#dated').val();
    event.preventDefault();
 
       var win = window.open('jvdetail.php?dated='+dated+'', '_blank');

  })
</script>




<script> 

  function openNewPage() {
    var pv = $("#voucher-number").val();
    var url = "prcartdtl.php?pv=" + pv;
    window.open(url, "_blank");
    var popup = document.getElementById("popup");
      popup.style.display = "none";
  }
    function openPopup() {
      var popup = document.getElementById("popup");
      popup.style.display = "block";
    }

    function closePopup() {
      var popup = document.getElementById("popup");
      popup.style.display = "none";
    }
  </script>


  <script type="text/javascript">
  $('#delinv').click(function(){

var vno = $("#voucher-number").val();
        var popup = document.getElementById("popup");
      popup.style.display = "none";
      event.preventDefault();
      $.ajax({
        url: 'jvvnodtl.php',
        method: 'POST',
        data: { vno: vno },
        success: function(data){
        $("#mdlcntntdtl").html(data);
        grpids=$("#spidss").val();
     $('#craccid').val(grpids).change();
        grpids=$("#custidss").val();
     $('#draccid').val(grpids).change();
        grpids=$("#spdated").val();

        $("#dated2").val(grpids)
        $("#accidlbl").html(vno)
        $('#myModal').modal('show');
  
     
        }
      });

  
  });
</script>

     <script type="text/javascript">
    $("#btnupdt").click(function(){
      var jvno = $('#accidlbl').html();
      var dated = $('#dated2').val();
      var craccid = $('#craccid').val();
      var draccid = $('#draccid').val();
      var amtbox = $('#amtbox').val();
      var descbox = $('#descbox').val();

      event.preventDefault();
 
            $.ajax({
        url: 'jvupdt.php',
        method: 'POST',
       data: {jvno: jvno, dated: dated, craccid: craccid, draccid: draccid, amtbox: amtbox, descbox: descbox},
        success: function(data){
            // $('#prate').val(data);
            alert(data);
            location.reload();


        }
      })

    });

</script>
     <script type="text/javascript">
    $("#btndlt2").click(function(){
      var jvnodlt = $('#accidlbl').html();
        event.preventDefault();
 
            $.ajax({
        url: 'jvupdt.php',
        method: 'POST',
       data: {jvnodlt: jvnodlt},
        success: function(data){
            // $('#prate').val(data);
            alert(data);
            location.reload();


        }
      })

    });

</script>



<script>  
$(document).ready(function(){ 
  
  var count = 0;

  $('#user_dialog').dialog({
    autoOpen:false,
    width:400
  });

  $('#add').click(function(){
    $('#user_dialog').dialog('option', 'title', 'Add Data');
    $('#first_name').val('');
    $('#last_name').val('');
    $('#ids').val('');
    $('#error_first_name').text('');
    $('#error_last_name').text('');
    $('#ids').text('');
    $('#first_name').css('border-color', '');
    $('#last_name').css('border-color', '');
    $('#last_name1').css('border-color', '');
    $('#save').text('Save');
    $('#user_dialog').dialog('open');
  });


  $('#rate').keydown(function(e){
if(e.keyCode==13 && $("#rate").val()!=="")
{
   var custid = $('#custid').val();
    var accid =  $('#selaccid2').val();
    var vno =  $('#vno').text();
    var vno2= parseInt(vno)+1;
    var dated =  $('#dated').val();
    var refno =  $('#refno').val();
    var rate =  $('#rate').val();
    count = count + 1;
    var srno =  count;

        output = '<tr id="row_'+count+'">';
        output += '<td hidden>'+accid+' <input type="hidden" name="hidden_accid[]" id="accid'+count+'" class="accid" value="'+accid+'" /></td>';

        output += '<td hidden>'+custid+' <input type="hidden" name="hidden_custid[]" id="custid'+count+'" class="custid" value="'+custid+'" /></td>';
        output += '<td hidden>'+dated+' <input type="hidden" name="hidden_dated[]" id="dated'+count+'" value="'+dated+'" /></td>';

   output += '<td>'+vno+' <input type="hidden" name="hidden_vno[]" id="vno'+count+'" class="vno" value="'+vno+'" /></td>';

        output += '<td>'+refno+' <input type="hidden" name="hidden_refno[]" id="refno'+count+'" value="'+refno+'" /></td>';

    output += '<td>'+rate+' <input type="hidden" name="hidden_rate[]" id="rate'+count+'" value="'+rate+'" /></td>';

        output += '<td><button type="button" name="view_details" class="btn btn-warning btn-xs view_details" id="'+count+'">View</button></td>';

        output += '<td><button type="button" name="remove_details" class="btn btn-danger btn-xs remove_details" id="'+count+'">Remove</button></td>';
        output += '</tr>';
        $('#user_data').append(output);
        // $('#user_dialog').dialog('close');
        $("#refno").val("");
        $("#qty").val("");
        var i=1;

$('#vid').append(new Option('Foo', 'foo', true, true));

        $("#vno").text(vno2);

if($('#fixrate'). prop("checked")!== true){
        $("#rate").val("");
  }

        $("#amt").val("");
        $("#refno").focus();
}
});



  $('#save').click(function(){
    var error_first_name = '';
    var error_last_name = '';
    var first_name = '';
    var last_name = '';
    if($('#first_name').val() == '')
    {
      error_first_name = 'First Name is required';
      $('#error_first_name').text(error_first_name);
      $('#first_name').css('border-color', '#cc0000');
      first_name = '';
    }
    else
    {
      error_first_name = '';
      $('#error_first_name').text(error_first_name);
      $('#first_name').css('border-color', '');
      first_name = $('#first_name').val();
    } 
    if($('#last_name').val() == '')
    {
      error_last_name = 'Last Name is required';
      $('#error_last_name').text(error_last_name);
      $('#last_name').css('border-color', '#cc0000');
      last_name = '';
    }
    else
    {
      error_last_name = '';
      $('#error_last_name').text(error_last_name);
      $('#last_name').css('border-color', '');
      last_name = $('#last_name').val();
    }

      if($('#last_name1').val() == '')
    {
      error_last_name1 = 'Last Name1 is required';
      $('#error_last_name1').text(error_last_name1);
      $('#last_name1').css('border-color', '#cc0000');
      last_name1 = '';
    }
    else
    {
      error_last_name1 = '';
      $('#error_last_name1').text(error_last_name1);
      $('#last_name1').css('border-color', '');
      last_name1 = $('#last_name1').val();
    }

    if(error_first_name != '' || error_last_name != '' || error_last_name1 != '')
    {
      return false;
    }
    else
    {
      if($('#save').text() == 'Save')
      {
        count = count + 1;
        output = '<tr id="row_'+count+'">';
        output += '<td>'+first_name+' <input type="hidden" name="hidden_first_name[]" id="first_name'+count+'" class="first_name" value="'+first_name+'" /></td>';
        
        output += '<td>'+last_name+' <input type="hidden" name="hidden_last_name[]" id="last_name'+count+'" value="'+last_name+'" /></td>';

      output += '<td>'+last_name1+' <input type="hidden" name="hidden_last_name1[]" id="last_name1'+count+'" value="'+last_name1+'" /></td>';

        output += '<td><button type="button" name="view_details" class="btn btn-warning btn-xs view_details" id="'+count+'">View</button></td>';

        output += '<td><button type="button" name="remove_details" class="btn btn-danger btn-xs remove_details" id="'+count+'">Remove</button></td>';
        output += '</tr>';
        $('#user_data').append(output);

      }
      else
      {
        var row_id = $('#hidden_row_id').val();
        output = '<td>'+first_name+' <input type="hidden" name="hidden_first_name[]" id="first_name'+row_id+'" class="first_name" value="'+first_name+'" /></td>';
      
          output += '<td>'+last_name1+' <input type="hidden" name="hidden_last_name[]" id="last_name'+row_id+'" value="'+last_name+'" /></td>';

        output += '<td>'+last_name1+' <input type="hidden" name="hidden_last_name1[]" id="last_name1'+row_id+'" value="'+last_name1+'" /></td>';
          
            output += '<td>'+last_name+' <input type="hidden" name="hidden_last_name[]" id="last_name'+row_id+'" value="'+last_name+'" /></td>';

        output += '<td><button type="button" name="view_details" class="btn btn-warning btn-xs view_details" id="'+row_id+'">View</button></td>';
        output += '<td><button type="button" name="remove_details" class="btn btn-danger btn-xs remove_details" id="'+row_id+'">Remove</button></td>';
        $('#row_'+row_id+'').html(output);
      }
      $("#first_name").focus();
       $('#user_dialog').dialog('close');
    }
  });


  $(document).on('click', '.view_details', function(){
    var row_id = $(this).attr("id");
    var srno = $('#srno'+row_id+'').val();
    var accid = $('#accid'+row_id+'').val();
    var itemid = $('#itemid'+row_id+'').val();
    var rate = $('#rate'+row_id+'').val();
    var qty = $('#qty'+row_id+'').val();
    $('#srno').val(srno);
    $('#accid').val(accid);
    $('#itemid').val(itemid);
    $('#rate').val(rate);
    $('#qty').val(qty);
    $('#save').text('Edit');
    $('#hidden_row_id').val(row_id);
    $('#user_dialog').dialog('option', 'title', 'Edit Data');
    $('#user_dialog').dialog('open');
  });

  $(document).on('click', '.remove_details', function(){
    var row_id = $(this).attr("id");
    if(confirm("Are you sure you want to remove this row data?"))
    {
      $('#row_'+row_id+'').remove();
    }
    else
    {
      return false;
    }
  });

  $('#action_alert').dialog({
    autoOpen:false
  });

  $('#user_form').on('submit', function(event){
    event.preventDefault();
     var save= confirm("Do you realy want to save this invoice?");
    if(save){
      $("#load").show();
    var count_data = 0;
    $('.vno').each(function(){
      count_data = count_data + 1;
    });
    if(count_data > 0)
    {
      if($('#dontmsg'). prop("checked")== true){
      var form_data = $(this).serialize();
      $.ajax({
        url:"addbrl2.php",
        method:"POST",
        data:form_data,
        success:function(data)
        {
           $('#user_data').find("tr:gt(0)").remove();
        
          alert(data);
      $("#load").hide();
      $("#refno").focus();

           // location.reload(true);
        }
      })

        }
        else{

              var form_data = $(this).serialize();
      $.ajax({
        url:"addjv.php",
        method:"POST",
        data:form_data,
        success:function(data)
        {
           $('#user_data').find("tr:gt(0)").remove();
        
          alert(data);
      $("#load").hide();

           // location.reload(true);
        }
      })

        }

    }
    else
    {
      $('#action_alert').html('<p>Please Add atleast one data</p>');
      $('#action_alert').dialog('open');
    }
  }
  });
  
});  
</script>


</body>
</html>
<?php 
}
?>