<?php include ("header1.php");
 $querylogin = "select * from  mst_users where user_name = '". $_SESSION["LOGIN_NAME"]."' AND password = '".$_SESSION["EMPLOYEE_PASSWORD"]."'";
$resultlogin = mysqli_query($conn,$querylogin);
while($row=mysqli_fetch_array($resultlogin))
{
$user_name = $row['user_name'];
$user_id = $row['user_id'];
$first_name = $row['first_name'];
 $login_type_admin=$row['login_type'];
}
 date_default_timezone_set('Asia/Calcutta');
$today = date("Y-m-d");
$time = date("h:i A"); 
$currentyear = date("Y");
$currentmonth = date("m");

if($currentmonth>03) { 
$cuyear = date("Y");
$cuyear1 = date("y")+1;
} 
else { 
$cuyear = date("Y")-1;
$cuyear1 =  date("y");
} 
$f_year = "$cuyear"."-"."$cuyear1";

?>

  <div class="content-page">
    <div class="content">
      <div class="container">
        <div class="row">
          <div class="col-sm-12">
            <div class="page-header-title">
			<button type="button" class="btn btn-dark  waves-effect waves-light" onclick="location.href='customer_po.php'">BACK</button>
			
              <div class="clearfix"></div>
            </div>
          </div>
        </div>
     
        
        <div class="row">
          <div class="col-md-12">
            <div class="panel panel-primary">
              <div class="panel-heading"><?php 
$qry97 = "select * from mst_customer where customer_id='".$_REQUEST['customer_id']."'";
$re97 = mysqli_query($conn,$qry97);
while($row=mysqli_fetch_array($re97))
{
$customer_name = $row['customer_name'];
}

?>

                <h3 class="panel-title"> VIEW ALL Inward : <?php echo $customer_name?> </h3>
              </div>
              <div class="panel-body">
<?php 			  
		$queryaaprgroup = "SELECT * FROM  delivery_challan_more_product_02 where entry_date between '".$_REQUEST['datepicker']."' and '".$_REQUEST['datepicker1']."' and invoice_no='' and  receipt_no!='' group by category_id   ";
$result1group = mysqli_query($conn,$queryaaprgroup);
$num_rows2 = mysqli_num_rows($result1hsn);
while($row=mysqli_fetch_array($result1group))
{

$category_id = $row['category_id'];

$sumoftotal='';
$sumqty='';
?>
                <table  class="table table-striped table-bordered">
                  <thead>
                    <tr>
                    
									 <th>Sr No</th>
									 <th>#</th>
									<th>BMST Challan Date</th>
									<th>BMST Challan No.</th>
									<th>DINESH Challan No.</th>
									<th>COMPONANT</th>
									<th>P.O.No.</th>
									<th>QTY</th>
									<th>RATE OF P.O.</th>
									<th>TOTAL AMOUNT </th>
					</tr>
                  </thead>
                  <tbody>         <form name="chkForm" id="chkForm" action="insert_inovice_step1.php"  method="post">
				  
				  <input type="hidden" name="datepicker" value="<?php echo $_REQUEST['datepicker']?>" />
				  
				  <input type="hidden" name="datepicker1" value="<?php echo $_REQUEST['datepicker1']?>" />
				  <input type="hidden" name="customer_id" value="<?php echo  $_REQUEST['customer_id']?>"

				  <? $k=1;
				  
			$queryaapr = "SELECT * FROM  delivery_challan_more_product_02 where entry_date between '".$_REQUEST['datepicker']."' and '".$_REQUEST['datepicker1']."' and receipt_no!='' and invoice_no='' and category_id='$category_id' ";
				
				
				
				$result1hsn = mysqli_query($conn,$queryaapr);
$num_rows2 = mysqli_num_rows($result1hsn);
while($row=mysqli_fetch_array($result1hsn))
{
$material_name = $row['material_name'];
$inward_challan_no = $row['inward_challan_no'];
$cust_more_row_id = $row['cust_more_row_id'];
$row_id = $row['row_id'];
$receipt_no=$row['receipt_no'];

$delivery_challan_no = $row['delivery_challan_no'];
$componant = $row['componant'];
$cust_po = $row['cust_po'];
$qty = $row['qty'];
$rate_of_po = $row['rate_of_po'];
$total = $row['total'];
$delivery_challan_more_product_id=$row['delivery_challan_more_product_id'];
$sumoftotal+=$total;
$sumqty+=$qty;

?>  <tr>
                    	
                        <td><?php echo $k;?>
						</td>                                <td><input type="checkbox" name="check_list[]" value="<?php echo $delivery_challan_more_product_id ?>"   checked="checked"  /></td>

						<td><?php $qry9705 = "select * from cust_inward_more_row_02 where row_id='$row_id' and cust_more_row_id='$cust_more_row_id'";
$re9702 = mysqli_query($conn,$qry9705);
while($row=mysqli_fetch_array($re9702))
{
$challan_date = $row['challan_date'];

}
 echo $challan_date; ?></td>
					    <td><?php echo $receipt_no; ?></td>
						<td><?php echo $delivery_challan_no; ?></td>
						<td><?php echo $componant; ?></td>
						<td><?php echo $cust_po; ?></td>
						<td><?php echo $qty; ?></td>
						<td><?php echo $rate_of_po; ?></td>
						<td><?php echo $total; ?></td>
						</tr>

                     <?php $k++; }?>
					 <tr>
<td colspan="7"><div align="right">Total</div></td>
<td><?php echo $sumqty?></td>
<td>&nbsp;</td>
<td><?php echo $sumoftotal?></td>
</tr>
</table>
<?php 
}
	$queryls = "select * from invoice_series where auto_no!='' and year='$f_year'  ORDER BY auto_id";
//echo $queryls;
$resultls = mysqli_query($conn,$queryls);    
 while($row=mysqli_fetch_array($resultls))
                                                    {
                                                    $auto_no = $row['auto_no'];
													 $company_name = $row['company_name'];
                                                    }
    
                                                     
$auto_no_new=$auto_no+1;
$cont_seriesa= sprintf("%04d", $auto_no_new);
$invoice_no1="$cont_seriesa"."-"."$f_year";
?>    
                                                    <div class="col-sm-3 col-xs-12"><div class="form-group">
                                                        <label>Invoice  No</label>
														
														<input type="text" name="invoice_no" value="<?php echo $invoice_no1;?>" class="form-control" />
</div></div>    

                                                    <div class="col-sm-3 col-xs-12"><div class="form-group">
                                                        <label>Date</label>
														
														<input type="date" name="invoice_date" value="<?php echo $invoice_date; ?>" class="form-control" required />
</div></div>   <div class="col-sm-3 col-xs-12"><div class="form-group">
                                                        <label> <br /> <br /></label>
			 											<input name="Submit"  type="submit" value="Save Invoice"  onclick="validate()" class="btn btn-sm btn-primary"/>
														</div></div>
              </div>
            </div>
          </div>
        </div>
        
      </div>
    </div>
	<?php include 'footer1.php';?>