<script type="text/javascript" language="javascript">
function getReference(){
var status=$("#status").val();
$.ajax({
		type: "POST",
		url: "modules/accounts/receivedAction.php",
		data: "statusID="+ status,
		success: function(data)
		{
		      //alert(data);
			  var updatedata='Sl-01/'+ data +'/18-19';
			  $("#reference").val(updatedata);
		
		}
	});
	
}
</script>
<div id="contentwrapper">
  <div class="main_content">
    <nav>
      <div id="jCrumbs" class="breadCrumb module">
        <ul>
          <li> <a href="#"><i class="icon-home"></i></a> </li>
          <li> <a href="#">VAT CHALLAN</a> </li>
        </ul>
      </div>
    </nav>
    <div class="row-fluid">
      <div class="span12">
        <?php

		          	if(isset($_POST['submit']))
						{
						$order=$_POST['order'];
						$invoice=$_POST['invoice'];
						$reference=$_POST['reference'];
						$mydate=$_POST['mydate'];
						$status=$_POST['status'];						
	
						$query = "SELECT id FROM ".$prefix2."order_vat_challan WHERE invoiceid='$invoice'";
					    $result_not_done=mysqli_query($linkid,$query) or die(mysqli_error());
						$getrows=mysqli_num_rows($result_not_done);
						
						if($getrows=="")
						{
						$query = "INSERT INTO ".$prefix2."order_vat_challan values (null,'$reference','$order','$invoice','$mydate','$status',CURDATE(),'$uid')";
					    $result_done=mysqli_query($linkid,$query) or die(mysqli_error());
						}
						else
						{
						echo '<div class="alert alert-danger"> <a data-dismiss="alert" class="close">x</a> <strong>Challan</strong> can not be duplicated.</div>';
						}
	

						if($result_done){
						?>
        <div class="alert alert-success"> <a data-dismiss="alert" class="close">x</a> <strong>Challan</strong> is saved.</div>
       <script type="text/javascript" language="javascript">
							  setTimeout(function () {
								 window.location.href= 'vat-challan.php?id=<?php echo $invoice;?>'; // the redirect goes here

								},2000);

	   </script>
        <?php 

						 }

						}
					 //unlink($filename1);

						 unset($_POST);

						 $_POST['submit']='';

						 $_POST='';
					?>
        <h3 class="heading">NEW VAT CHALLAN</h3>
        <form class="form_validation_reg" id="form_validation_reg" action=""  method="post" enctype="multipart/form-data">
          <input type="hidden" name="order" id="order" class="span12" value="<?php echo $getData['order_'];?>" />
          <input type="hidden" name="invoice" id="invoice" class="span12" value="<?php echo $getData['reference'];?>" />
          <div class="formSep">
            <div class="row-fluid">
              <table class="table table-condensed table-striped" data-provides="rowlink">
                <tr>
                  <th> Order No</th>
                  <th> Reference</th>
                  <th> Trans Date </th>
                  <th> Customer </th>
                  <th> Phone </th>
                  <th> Amount(BDT)</th>
                </tr>
                <tr style="background-color:#F2F2F2; padding:5px;">
                  <td><?php echo $getData['order_'];?></strong></td>
                  <td><?php echo $getData['reference'];?></td>
                  <td><?php echo $getData['tran_date'];?></td>
                  <td><?php echo $getData['name'];?></td>
                  <td><?php echo $getData['debtor_ref'];?></td>
                  <td><?php echo $getData['ov_amount'];?></td>
                </tr>
              </table>
            </div>
          </div>
          <div class="formSep">
            <div class="row-fluid">
              <div class="span2">
                <label>Date</label>
                <input type="text" name="mydate" id="mydate" class="span12" value="<?php echo date('Y-m-d');?>" />
              </div>
            <div class="span2">
                <label>Action </label>
                <SELECT class="input_text" name="status" id="status" onchange="getReference()">
                  <OPTION SELECTED VALUE="">Select</OPTION>
				  <OPTION VALUE="1">VAT</OPTION>
                </SELECT>
              </div>
              <div class="span2">
                <label>Reference </label>
                <input type="text" name="reference" id="reference" class="span12"/>
              </div>
			  
			  <div class="span8">
                <label>&nbsp; </label>
              </div>
            </div>
          </div>
          <div class="form-actions">
            <input class="btn btn-inverse" name="submit" type="submit" value="Submit" />
            <button class="btn">Cancel</button>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>
