<?php include("parent/callMe.php"); ?>
<?php  include("sessioncheck.php"); ?>
<?php

 $branch=$_SESSION['branch'];
    
     $session1;
      if($_REQUEST['session']!=NULL){

       $session1=$_REQUEST['session'];
     }else {
       $session1=$_SESSION['current_session'];
     }

    if($_REQUEST['student']!=NULL){

       $m->where("status", '0');
       $m->where("branch_id", $_SESSION['branch']);
       $m->where("student_id", $_REQUEST['student']);
       $WorkAssignListVal = $m->get("edu_student_details");

      }
     // print_r($WorkAssignListVal)

      $m->where("student_id", $WorkAssignListVal[0]['student_id']);
      /*$m->where("class_id", $WorkAssignListVal[0]['class_id']);*/
      $m->where("session_id", $_SESSION['current_session']);
      $m->where("branch_id", $_SESSION['branch']);
      $details2 = $m->get("eduportal_student_fee_structure");
 
      

  // settings month details

    $default;
    
    if($_GET["month"]!=NULL ){
      $default= $_GET["month"];
    }
    else{
      $default= date("m");
    }
  
      $m->where("Month_Id", $default);
      $month_name=$m->get("eduportal_month_config");

       $date;
    
    if($_GET["date"]!=NULL ){
      $date= $_GET["date"];
    }
    else{
      $date= date("Y-m-d");
    }
 
     ?>

<!DOCTYPE html>
<html lang="en">
  <head>
    
    <title>Create Voucher | EduPortal</title>
    <?php include('RootMe/css_links.php');?>

<style>

.thStyle{background-color:gray;color:white;}

tr th {padding:1.5%;border:1px solid white;}
tr td {padding:1%;}

@media only screen and (max-width: 768px) {

/* For mobile phones: */
.popup_style{margin-top:20%;}

}
</style>   
  </head>
  
<script type="text/javascript">

  function disableDebit(count) {

   
  var debitField;
  debitField=document.getElementById("debit"+count).value.length;


  if( debitField > 0 ) { 
    document.getElementById("debit1"+count).disabled = true; 
  }
}


function disableCredit(count) {

   
  var creditField;
  creditField=document.getElementById("credit"+count).value.length;


  if( creditField > 0 ) { 
    document.getElementById("credit1"+count).disabled = true; 
  }
}






function getAccountName(id){
//alert(id);
  var monthid=document.getElementById("monthid").value
  var yearid=document.getElementById("yearid").value
  var branchid=document.getElementById("branchid").value
  var codeIncreament=document.getElementById("codeIncreament").value

  if(id=="1"){
    document.getElementById("VCno").value = 'BPV-'+codeIncreament;
    document.getElementById("add").style.display="block";
  }
  if(id=="2"){
    document.getElementById("VCno").value = 'CPV-'+codeIncreament;
    document.getElementById("add").style.display="block";
  }
   if(id=="3"){  
    document.getElementById("VCno").value = 'BRV-'+codeIncreament;
    document.getElementById("add").style.display="block";
  }
   if(id=="4"){   
    document.getElementById("VCno").value = 'CRV-'+codeIncreament;
    document.getElementById("add").style.display="block";
  }
   if(id=="5"){  
    document.getElementById("VCno").value = 'JV-'+codeIncreament;
    document.getElementById("add").style.display="block";
  }

  //alert("786");
            if (window.XMLHttpRequest) {

              // code for IE7+, Firefox, Chrome, Opera, Safari

              xmlhttp=new XMLHttpRequest();

            } else { // code for IE6, IE5

              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

            }

            xmlhttp.onreadystatechange=function() {

              if (xmlhttp.readyState==4 && xmlhttp.status==200) {

                document.getElementById("accountDebit").innerHTML=xmlhttp.responseText;

                // alert(xmlhttp.responseText);
                 getCreditAccountName(id);
              }

            }

            xmlhttp.open("GET","get_debit_account_name.php?voucherType="+id,true);

            xmlhttp.send();




          }



    function getCreditAccountName(id){

  //alert(id);

            if (window.XMLHttpRequest) {

              // code for IE7+, Firefox, Chrome, Opera, Safari

              xmlhttp=new XMLHttpRequest();

            } else { // code for IE6, IE5

              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

            }

            xmlhttp.onreadystatechange=function() {

              if (xmlhttp.readyState==4 && xmlhttp.status==200) {

                document.getElementById("accountCredit").innerHTML=xmlhttp.responseText;
                // alert(xmlhttp.responseText);

              }

            }

            xmlhttp.open("GET","get_credit_account_name.php?voucherType="+id,true);

            xmlhttp.send();




          }



      function getDebitbalance(amount){

            var debit=document.getElementsByName("debit[]");            

            var total_bill=0;


            for (var i = 0; i < debit.length; i++) { 

            //alert(pr);
            total_bill = parseFloat(total_bill)+parseFloat(debit[i].value);         


            }

            document.getElementById("totalDebit").value = parseFloat(total_bill);
          
CheckDebitCreditEqual();
      }



  function getCreditbalance(amount){

            var credit=document.getElementsByName("credit[]");

            var total_bill=0;


            for (var i = 0; i < credit.length; i++) { 

            //alert(pr);
            total_bill = parseFloat(total_bill)+parseFloat(credit[i].value);         


            }

            document.getElementById("totalCredit").value = parseFloat(total_bill);
            CheckDebitCreditEqual();
      }


function CheckDebitCreditEqual(){

  var Tdebit=document.getElementById("totalDebit").value;
  var Tcredit=document.getElementById("totalCredit").value;

  if (Tdebit == Tcredit) {
  document.getElementById("error").innerHTML = "";
  document.getElementById("btnID").disabled = false;
  //alert("true");
  } else {
  //alert("false");
  document.getElementById("error").innerHTML = "The Debit and Credit Amounts are not equal.";
  document.getElementById("btnID").disabled = true;
  }

}

function getNewRow(){

 // alert("786");

  var voucherType=document.getElementById("voucher_type").value
  var order=document.getElementById("increament").value
  var incre=1;
  var orderIncreament=Number(order)+Number(incre);
  document.getElementById("increament").value=orderIncreament;

//alert(voucherType);
            if (window.XMLHttpRequest) {

              // code for IE7+, Firefox, Chrome, Opera, Safari

              xmlhttp=new XMLHttpRequest();

            } else { // code for IE6, IE5

              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

            }

            xmlhttp.onreadystatechange=function() {

              if (xmlhttp.readyState==4 && xmlhttp.status==200) {

                //document.getElementById("pro_row").innerHTML=xmlhttp.responseText;
                  $("table tbody").append(xmlhttp.responseText)
                // alert(xmlhttp.responseText);

              }

            }

            xmlhttp.open("GET","get_journal_entry_row.php?voucherType="+voucherType+"&vocherIncr="+orderIncreament,true);

            xmlhttp.send();




          }

</script>


 <!-- jQuery -->
    <script src="js/ajax_functions.js"></script>  
  <body class="nav-md">
    <div class="container body">
      <div class="main_container">
        <div class="col-md-3 left_col">
     
            <?php include('RootMe/sidebar.php');?>

              <?php include('RootMe/header.php');?>
     
       <!-- page content -->
          <div class="right_col" role="main">

            <a href="<?php echo $_SESSION['dashboard'];?>">Dashboard </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp; 
                Finance &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp; 
                Create Voucher
          <br><br>

          <div class="row" style="background-color: white;">
           
  <section class="add_sub_agent" id="table_sub_agent">
  <div class="container">

 <div class="" style="margin-top:10px;">
   
      

                                    <!-- page content -->
        
  <div class="">
    <input type="hidden" name="increament" value="1" id="increament" >
      <h3 style="margin-left: 15px;">Create Voucher
        <input style="display: none;float:right;margin-right: 35px;" class="btn btn-success" id="add" name="pronam" onclick="getNewRow()" type="button" value="Add Row" /> 
      </h3>
            <div class="row">
          
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
            
                  <div class="x_content">
          
     
                    <?php
$branchID=$_SESSION['branch'];
$sql1 = "SELECT * FROM  eduportal_accounts_voucher_details WHERE branch_id='$branchID' ORDER BY voucher_id  DESC LIMIT 1 "; 

$last_code = $m->query($sql1);

$codePlus=(explode("-",$last_code[0]['voucher_code']));

$codeIncreament;
if ($last_code>0) {
  
  $codeIncreament=$codePlus[1]+1;
} else {

  $codeIncreament=1;
}  


 ?>

<input type="hidden" id="monthid" value="<?php echo date('m');?>" >
<input type="hidden" id="yearid" value="<?php echo date('y');?>" >
<input type="hidden" id="branchid" value="<?php echo $_SESSION['branch'];?>" >
<input type="hidden" id="codeIncreament" value="<?php echo $codeIncreament;?>" >

<form class="form-style-7" action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post" enctype="multipart/form-data">

  <?php

   if(!isset($_GET['id123'])){?> 
  
       <input type="hidden" name="action" value="Create_Voucher" />
      
 <?php } else { ?>

        <input type="hidden" name="action" value="Update_RevenueBill" />
        <input type="hidden" name="id"  value="<?php echo $_GET['id'];?>">

<?php } ?>
   




        <div class="row">

               
             <div class="col-md-2 col-xs-6" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Date</label>
                  <input type="date" data-date-format="DD-MM-YYYY" value="<?php echo date("Y-m-d"); ?>" class="form-control" name="voucherDate">
                </div>
              </div>

              <div class="col-md-2 col-xs-6" style="padding: 8px;">

                <div class="form-group" >
                  <label class="required">Voucher Type</label>
                <select name="voucher_type" id="voucher_type" required class="form-control"  onChange="getAccountName(this.value)">                
                  <option>Select Voucher Type</option>
                  <?php
       
                 $voucherTypes = $m->get("eduportal_voucher_type");
                 foreach ($voucherTypes as $voucherType) { ?>

                <option <?php if ($_REQUEST['category']==$voucherType['id']) { echo 'selected'; } ?> value="<?php echo $voucherType['id']; ?>"><?php echo $voucherType['voucher_name']; ?></option>

                    <?php } ?>
                </select>
                
                </div>


                </div>

                <div class="col-md-2 col-xs-6" style="padding: 8px;">

                <div class="form-group" >
                
                <label for=""> Voucher Number </label>
          
                <input type="text" id="VCno" value="" class="form-control" name="voucher_number">

                </div>

                </div> 

            
             

              <div class="col-md-6 col-xs-12" style="padding: 8px;">

                <div class="form-group" >
                
                <label for=""> Voucher Narration </label>
          
                <input type="text" id="voucher_narration" value="" placeholder="Type here voucher narration...!" class="form-control" name="voucher_narration">

                </div>

                </div> 

               

      </div>  <!-- ending row-->     

        <div class="row">
                 
    <table id="mytable" class="table table-striped table-bordered"style="background-color: white;" >
                      <thead>
                        
                      </thead>
                       <tbody>
     
          <tr>
          <th></th>
          <th>Debit Account</th>
          <th>Debit Amount</th>
          <th>Credit Account</th>
          <th>Credit Amount</th>
          <th>Account Narration</th>
          </tr>
            <tr>
            <td>
              <input type="hidden" name="incOrder[]" value="1">
            </td>
            
            <td >   
            
            <select name="Debitaccount_name[]" id="accountDebit" class="form-control" style="">

            <option>Select Debit Account</option>

       
            </select>

        </td>

        <td>  
               <input type="text" name="debit[]" onkeyup="getDebitbalance(this.value)" autocomplete="off" value=""  id="debit" placeholder="Debit Amount" class="form-control"/>

                </td>

        <td>


        <select name="Creditaccount_name[]" id="accountCredit" class="form-control" style="">

        <option value="">Select Credit Account</option>

       
        </select>                
              
            </td>
            

            


              <td>

                <input type="text" name="credit[]" onkeyup="getCreditbalance(this.value)"  autocomplete="off"  id="credit" value=""  maxlength="100" placeholder="Credit Amount" class="form-control"/>
            </td>


            <td>  

             <input type="text" min="0" name="Debitnarration[]"  autocomplete="off" id="AccountNarration" placeholder="Narration" value="" class="form-control" />

           </td>

             <!-- <td>

             <input type="text" min="0" name="Creditnarration[]"  autocomplete="off" id="tutionfee<?php echo $j; ?>" placeholder="Narration" class="form-control" /> 

           

             </td> -->
            
            
          </tr>

   </tbody>
   </table>
<div class="col-md-12">

<div class="col-md-3 col-xs-6" style="float: left;text-align: left; font-size:16px;font-weight:bold;">
<div class="form-group" >
<label for=""> Total Debit Amount </label>
<input type="text" readonly id="totalDebit" value="" class="form-control" name="">
</div>
</div>


<div class="col-md-6" id="error" style="float: left;text-align: left; font-size:12px;color:red;"></div>

<div class="col-md-3 col-xs-6" style="float: Right;text-align: right; font-size:16px;font-weight:bold;">
<div class="form-group" >
<label for=""> Total Credit Amount </label>
<input type="text" readonly id="totalCredit" value="" class="form-control" name="">
</div>
</div>


</div>  

          <input  type="submit" style="font-size:18px; float: right;" id="btnID" value="Submit" class="btn btn-success">
    </div>   <!--  ending 12 column-->


    </form>
              
          </div>
                </div>
              </div>
            </div>
          </div>
       
  

        <!-- /page content -->



  </div>
  <div class="clearfix"></div>
</section>           


          
        
          

       

           
          </div>
        </div>

            </div>
          </div>
        </div>
        <!-- /page content -->
      
  <?php include('RootMe/js_linksscript.php');?>

    
    <script type="text/javascript">
        $(document).ready(function(){
            $(".add-row").click(function(){
                
                var pro;

                $.ajax({url: "get_credit_account_name.php", success: function(result1)
                {

                $.ajax({url: "get_debit_account_name.php", success: function(result)
                {
                    
                    //alert(result);
                    
                var markup = "<tr><td>"+result+"<br>"+result1+"</td><td><input class='form-control' name='debit[]' placeholder='Debit'  type='text' /><br><input class='form-control' name='credit[]' placeholder='Credit'  type='text' /></td><td><input class='form-control' placeholder='Narration' name='narration[]'  type='text' /><br><input class='form-control' placeholder='Narration' name='narration[]'  type='text' /></td></tr>";
                $("#mytable tbody").append(markup);
              
              
                  }}) }});


              
              
            });
            
            // Find and remove selected table rows
            $(".delete-row").click(function(){
                $("table tbody").find('input[name="record"]').each(function(){
                  if($(this).is(":checked")){
                        $(this).parents("tr").remove();
                    }
                });
            });
        });    
    </script>
  </body>
</html>
