<?php
ini_set('display_errors', 0);
//error_reporting(E_ALL);
//ini_set('display_errors', 1);

session_start();
ob_start();

require_once('configuration/server_connect.php');
require_once('configuration/all_function.php');

$active_id=$_REQUEST['active_id'];
$menu_id=$_REQUEST['menu_id'];

// Common Information

$page_title="Draft Voucher";
$page="25_voucher.php?active_id=".$active_id."&menu_id=".$menu_id."";
$table='journal_master';	
$unique='jv_no';

// End Common Information

?>

<!DOCTYPE html>
<html lang="en"><style type="text/css">
<!--
.style1 {font-size: 12px}
-->
</style>

 <?php require_once('inc_files/inc_head.php'); ?>
 
 <?php
  do_calander('#fdate');
  do_calander('#tdate');
  ?>
 
 

<body>

  <!-- ======= Header ======= -->
  <?php 
  require_once('inc_files/inc_header.php');
  ?><!-- End Header -->

  <!-- ======= Sidebar ======= -->
  <?php  require_once('inc_files/inc_menu.php'); ?><!-- End Sidebar-->

  <main id="main" class="main">

    <div class="pagetitle">
      <h1><?php echo $page_title?></h1>
      <nav>
        <ol class="breadcrumb">
          <li class="breadcrumb-item"><a href="home.php">Home</a></li>
          <li class="breadcrumb-item">General Voucher</li>
          <li class="breadcrumb-item active"><?php echo $page_title?></li>
        </ol>
      </nav>
    </div><!-- End Page Title -->

    <section class="section">
      <div class="row">
        <div class="col-lg-12"> 

          <div class="card">
            <div class="card-body">
			<br>
            <form class="row g-3" action="" method="post" name="codz" id="codz">
   		       
			
	<table width="80%" border="0" align="center">
      
      
        <tr height="50">
          <td align="right">Voucher Type:&nbsp;&nbsp;</td>
          <td width="13%">
		  <select id="jv_type" name="jv_type"  class="form-select"    >
		  <option></option>
			
			<?php foreign_relation($conn,'journal_type','id','journal_type',$_POST['jv_type'],'1 order by id');?>
        	</select>		  </td>
          <td width="16%" align="right">From Fate:&nbsp;&nbsp;</td>
          <td width="18%">
		  <input type="text" name="fdate" id="fdate" class="form-control" style="width:150px;" value="<?php echo $_POST['fdate'];?>" /></td>
          <td width="16%" rowspan="6" align="center" ><strong>
            &nbsp;&nbsp;&nbsp;
            <button type="submit" name="run_data" id="run_data" class="btn btn-success rounded-pill btn-sm">&nbsp;<i class="bi bi-filter me-1"></i> Run Report&nbsp;&nbsp;</button>
          </strong></td>
        </tr>
        <tr height="50">
        <td width="14%" align="right">Voucher No:&nbsp;&nbsp;</td>
        <td>
		<select id="jv_no" name="jv_no"  class="form-select"    >
		  <option></option>
			
			<?php foreign_relation($conn,'journal_master','jv_no','view_jv_no',$_POST['jv_no'],'status="MANUAL" order by jv_type, jv_no');?>
        	</select>			</td>
        <td align="right">To Date:&nbsp;&nbsp;</td>
        <td>
		 <input type="text" name="tdate" id="tdate" class="form-control" style="width:150px;" value="<?php echo $_POST['tdate'];?>" />		</td>
        </tr>
    </table>
               
  </form>
  <br>
	
              <!-- Table with stripped rows -->
              <table width="100%" class="table table-sm" style="font-size:12px;">
                <thead>
                  <tr style="text-transform:uppercase; color:#012970; background:#f6f9ff;  border-top: 1px solid #CCCCCC;">
                    <th width="8%" scope="col"><span class="card-title" style="font-size:12px; text-transform:uppercase;"> JV No </span></th>
                    <th width="18%" scope="col"><span class="card-title" style="font-size:12px; text-transform:uppercase;">JV Date </span></th>
                    <th width="15%" scope="col"><span class="card-title" style="font-size:12px; text-transform:uppercase;">JV Type </span></th>
                    <th width="13%" scope="col"><span class="style1">Entry by </span></th>
                    <th width="12%" scope="col"><span class="card-title" style="font-size:12px; text-transform:uppercase;">DR Amt </span></th>
                    <th width="12%" scope="col"><span class="card-title" style="font-size:12px; text-transform:uppercase;">CR Amt </span></th>
                    <th width="10%" scope="col"><span class="card-title" style="font-size:12px; text-transform:uppercase;">Action</span></th>
                  </tr>
                </thead>
                <tbody>
					<?php
					
					
 
if($_POST['fdate']!=''&&$_POST['tdate']!='') $date_con .= ' and jv_date between "'.$_POST['fdate'].'" and "'.$_POST['tdate'].'"';

if($_POST['jv_type']!=''){
$jv_type_con=" and jv_type='".$_POST['jv_type']."' ";
}


if($_POST['jv_no']!=''){
$jv_no_con=" and jv_no='".$_POST['jv_no']."' ";
}

if($_POST['customer_type']!=''){
$customer_type_con=" and customer_type='".$_POST['customer_type']."' ";
}



	
		 $sql = "select id, journal_type from journal_type where 1 group by id";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $journal_type[$info->id]=$info->journal_type;
		}	
		
		 $sql = "select user_id, fname from user_management where 1 group by user_id";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $fname[$info->user_id]=$info->fname;
		}	
		
		
		 $sql = "select jv_no, sum(dr_amt) as dr_amt, sum(cr_amt) as cr_amt from secondary_journal where ledger_id>0 group by jv_no";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $dr_amt[$info->jv_no]=$info->dr_amt;
		 $cr_amt[$info->jv_no]=$info->cr_amt;
		}				
					
		
		
			
					  $sql = 'select * from '.$table.' where status="MANUAL" '.$date_con.$jv_type_con.$jv_no_con.' ';
						$query = mysqli_query($conn,$sql);
						while ($data = mysqli_fetch_object($query)) {

					?>
	<?php //if(isset($_POST['run_data'])){}?>		
      <tr>
      <td><?php echo $data->view_jv_no;?></td>
      <td><?php echo date('d-M-y',strtotime($data->jv_date));?></td>
      <td><?php echo $journal_type[$data->jv_type];?></td>
	  <td><?php echo $fname[$data->entry_by];?></td>
      <td><input class="form-control" name="dr_amt_<?php echo $data->jv_no?>" id="dr_amt_<?php echo $data->jv_no?>" type="text"  
	  value="<?php echo $dr_amt[$data->jv_no];?>" style="width:90%; height:30px;" readonly="" /></td>
      <td><input class="form-control" name="cr_amt_<?php echo  $data->jv_no?>" id="cr_amt_<?php echo $data->jv_no?>" type="text" 
	   value="<?php echo $cr_amt[$data->jv_no];?>" style="width:90%; height:30px;" readonly=""/></td>
      <td>
	 

              <?php if($data->jv_type==1){?>
			 <a href="21_voucher.php?active_id=301&menu_id=3&request_no=<?php echo $data->jv_no;?>" ><input class="form-control" type="button" name="Button" value="Voucher View"   style="width:80%; height:30px;background-color:#66CC66;   font-weight:700; font-size:12px;"/></a>
			  <?php } elseif ($data->jv_type==2){ ?>
			  <a href="22_voucher.php?active_id=302&menu_id=3&request_no=<?php echo $data->jv_no;?>" ><input class="form-control" type="button" name="Button" value="Voucher View"   style="width:80%; height:30px;background-color:#66CC66;   font-weight:700; font-size:12px;"/></a>
			  <?php }elseif ($data->jv_type==3 && $data->special_note==""){?>
			   <a href="23_voucher.php?active_id=303&menu_id=3&request_no=<?php echo $data->jv_no;?>" ><input class="form-control" type="button" name="Button" value="Voucher View"   style="width:80%; height:30px;background-color:#66CC66;   font-weight:700; font-size:12px;"/></a>
			     <?php }elseif ($data->jv_type==3 && $data->special_note=="IOU Settlement"){?>
			    <a href="29_voucher_iou_settlement.php?active_id=303&menu_id=3&request_no=<?php echo $data->jv_no;?>" ><input class="form-control" type="button" name="Button" value="Voucher View"   style="width:80%; height:30px;background-color:#66CC66;   font-weight:700; font-size:12px;"/></a>
			   <?php }elseif ($data->jv_type==4){?>
			   <a href="24_voucher.php?active_id=304&menu_id=3&request_no=<?php echo $data->jv_no;?>" ><input class="form-control" type="button" name="Button" value="Voucher View"   style="width:80%; height:30px;background-color:#66CC66;   font-weight:700; font-size:12px;"/></a>
			  <?php }elseif ($data->jv_type==5){?> 
			  <a href="43_customer_so.php?active_id=503&menu_id=5&request_no=<?php echo $data->jv_no;?>" ><input class="form-control" type="button" name="Button" value="Voucher View"   style="width:80%; height:30px;background-color:#66CC66;   font-weight:700; font-size:12px;"/></a>
			  <?php }elseif ($data->jv_type==6){?>
			  <a href="53_supplier_po.php?active_id=603&menu_id=6&request_no=<?php echo $data->jv_no;?>" ><input class="form-control" type="button" name="Button" value="Voucher View"   style="width:80%; height:30px;background-color:#66CC66;   font-weight:700; font-size:12px;"/></a>
			  <?php }?>
            </td>
      </tr>
				  <?php }?>
                </tbody>
              </table>
              <!-- End Table with stripped rows -->

            </div>
          </div>

        </div>

        
      </div>
    </section>

  </main><!-- End #main -->

  <!-- ======= Footer ======= -->
  <?php require_once('inc_files/inc_footer.php'); ?>
 <!-- ======= Footer ======= -->
 <?php 
 selected_two("#jv_no");
 ?>
</body>

</html>