<?php
session_start();
if($_SESSION["username"]=="")
{
 	echo "You are not Logged in Please <a href='index.html'>Sign in </a> First ";
}
else
{
include 'dbc.php';

$id=$_REQUEST["id"];
$address=$_REQUEST["address"];
$subtypename=$_REQUEST["subtypename"];
$userid=$_SESSION["userid"];
$today=date("Y-m-d");
$month = date("m",strtotime($today));
		$year = date("Y",strtotime($today));
		 $month_name = date("F", mktime(0, 0, 0, $month, 10));
		
		
		 $my=$month_name . " " . $year;
		 $sql3="Select * from addarea where user_id='$userid'";
$result1 = $conn->query($sql3);
		 $sql4="Select * from customer where user_id='$userid'";
$result4 = $conn->query($sql4);
 $sql5 = "SELECT * FROM invoice_st where id = '$id' and  user_id='$userid'";
$result5=$conn->query($sql5);
$row5 = $result5->fetch_assoc();
$cname=$row5['cname'] ;
?>
<!doctype html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang=""> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8" lang=""> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9" lang=""> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js" lang="en">
<!--<![endif]-->

<head>
   <?php include("includes/header.php") ?>
</head>

<body>


    <!-- Left Panel -->

   <!-- /#left-panel -->

    <!-- Left Panel -->

    <!-- Right Panel -->

    <div id="right-panel" class="right-panel">

        <!-- Header-->
        <header id="header" class="header">

             <?php include("includes/sale_menu.php") ?>

        </header><!-- /header -->
        <!-- Header-->

        <div class="breadcrumbs">
            <div class="col-sm-6">
                <div class="page-header float-left">
                    <div class="page-title">
                        <h1><? echo "" . $_SESSION["userid"]; ?></h1>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="page-header float-right">
                    <div class="page-title">
                        <ol class="breadcrumb text-right">
                            <li class="active"><? echo "" . $_SESSION["username"]; ?></li>
                        </ol>
                    </div>
                </div>
            </div>
        </div>

        <div class="content mt-3">

           


          <div class="col-lg-12">
                        <div class="card">
                            <div class="card-header"><strong>Sale Tax Invoice </strong><small> Form</small></div>
                            <div class="card-body card-block">
							
							 <?php
include 'dbc.php';

$subtypename=$_REQUEST["subtypename"];
$userid=$_SESSION["userid"];

 $sqlcus1 = "select * from addst";
   $result3=$conn->query($sqlcus1);
$ppp1 = $result3->fetch_assoc();
	 $st=$ppp1["cname"];
	 
$sqlrec = "SELECT * FROM items where user_id='$userid' ORDER BY id";
$resultrec=$conn->query($sqlrec);
  
?>
                                <table id="bootstrap-data-table-export" class="table table-striped table-bordered">
                                    <thead>
									<?php
echo "<tr>";

echo "<th bgcolor=yellow> No </th>";

echo "<th bgcolor=yellow> Item Type  </th>";
echo "<th bgcolor=yellow> Barcode </th>";
echo "<th bgcolor=yellow> Item Name  </th>";
echo "<th bgcolor=yellow> Sale Rate </th>";
echo "<th bgcolor=yellow> GST % </th>";
echo "<th bgcolor=yellow> Bal </th>";
echo "<th bgcolor=yellow> Qty </th>";


echo "</tr>";
?>
                                    </thead>
									
                                    <tbody>
									<?php
echo "<form name='form_update' method='post' action='Sale_Invoice_Save_st.php'>\n";
while($students = $resultrec->fetch_assoc()) {
$pname=$students["item_name"];
 $bal=$students["bal"]; 
 $netqty =0;

$tsaleqty=0;
$tsaleqtyst=0;
$tpureqty=0;
$tsaleqtywh=0;
$tadjustqty=0;
$tsaleqtyret=0;
 $sql1 = "SELECT * FROM invoice_details where item_name='$pname' and user_id='$userid'";
$result1=$conn->query($sql1);
while($row1 = $result1->fetch_assoc())
 
  {
 $tsaleqty=$tsaleqty + $row1['qty'];
 

  }
  
  $sql1st = "SELECT * FROM invoice_details_st where item_name='$pname' and user_id='$userid'";
$result1st=$conn->query($sql1st);
while($row1st = $result1st->fetch_assoc())
 
  {
 $tsaleqtyst=$tsaleqtyst + $row1st['qty'];
 

  }
   
  $sql1ret = "SELECT * FROM qoute_details where item_name='$pname' and user_id='$userid'";
$result1ret=$conn->query($sql1ret);
while($row1ret = $result1ret->fetch_assoc())
 
  {
 $tsaleqtyret=$tsaleqtyret + $row1ret['qty'];
 

  }
$sql2 = "SELECT * FROM purchase_details where item_name='$pname' and user_id='$userid'";
$result2=$conn->query($sql2);
while($row2 = $result2->fetch_assoc())
 
  {
 $tpureqty=$tpureqty + $row2['qty'];
 

  }
 $sql23 = "SELECT * FROM purchase_details_return where item_name='$pname' and user_id='$userid'";
$result23=$conn->query($sql23);
while($row23 = $result23->fetch_assoc())
 
  {
 $tadjustqty=$tadjustqty + $row23['qty'];
  }
$netqty = ($tpureqty + $tsaleqtyret + $bal) - ($tsaleqty + $tsaleqtyst + $tadjustqty + $tsaleqtywh) ;
	echo '<tr>';
	
	echo "<td><h4>{$students['id']}<input type='hidden' name='id[$i]' value='{$students['id']}' size=5/></h1></td>";
	echo "<td><h4>{$students['type_name']}<input type='hidden' name='type_name[$i]' value='{$students['type_name']}' /></h4></td>";
		echo "<td><h4>{$students['item_no']}<input type='hidden' name='item_no[$i]' value='{$students['item_no']}' /></h4></td>";

	echo "<td><h4>{$students['item_name']}<input type='hidden' name='item_name[$i]' value='{$students['item_name']}' /></h4></td>";

	
	echo "<td><h4><input type='text' name='retail_price[$i]' value='{$students['retail_price']}' size=5/></h3></td>";
	echo "<td><h4><input type='text' name='st[$i]' value='{$st}' size=5/></h3></td>";
	echo "<td><h4>{$netqty}<input type='hidden' name='netqty[$i]' value='{$netqty}' /></h4></td>";

echo "<td><h4><input type='text' name='sale_qty[$i]' size=5/></h3></td>";
	
	
	 
	echo '</tr>';
	++$i;
}
?>
												
																
											<div class="col-3">
                                <div class="form-group"><label for="feedisc1" class=" form-control-label">Invoice No</label><input type="text" id="id" name="invid" placeholder="ID" class="form-control" value="<? echo $id ?>"></div>
								</div>
									<div class="col-3">
                                <div class="form-group"><label for="feedisc1" class=" form-control-label">Invoice Discount</label><input type="text" id="discount" name="discount" placeholder="Discount %" class="form-control" value="0"></div>
								</div>
												
									
	
								
								
								
								
								
								
		
                                                    </div>
													<div class="card-footer">
                                                       <?php
echo '<tr>';
echo "<td><input type='submit' value='Save' /></td>";

echo '</tr>';
echo "</form>";
echo '</table>';
?>
                                                       
                                                    </div>
													
													
                                                </div>
                                            </div>

            


        </div> <!-- .content -->
    </div><!-- /#right-panel -->

    <!-- Right Panel -->

   <?php include("includes/footermenu.php") ?>

</body>

</html>
<?php
}

?>