<?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';
date_default_timezone_set("Asia/Karachi");
$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;
$userid=$_SESSION["userid"];
include 'dbc.php';

$username=$_SESSION["username"];

    $id= $_REQUEST['id'];
	
	$sql2 = "SELECT * FROM purchase_details where  inv_no='$id' and user_id='$userid'";
$result2=$conn->query($sql2);
 while($row2 = $result2->fetch_assoc())
 
  {
  $tqty= tqty + 1;
  $tfeerec=$tfeerec + $row2['amount'];
  }
  
?>
<!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 -->

    <?php include("includes/menu.php") ?><!-- /#left-panel -->

    <!-- Left Panel -->

    <!-- Right Panel -->

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

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

             <?php include("includes/headermenu.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="animated fadeIn">
                <div class="row">
<div class="col-lg-6">
                        <div class="card">
                            <div class="card-header"><strong>Add Purchase Items</strong><small> Form</small></div>
                            <div class="card-body card-block">
							<form action="Add_Purchase_Item_Save1.php" method="post" enctype="multipart/form-data" class="form-group">
						
								<div class="col-2">
                                <div class="form-group"><label for="feedisc1" class=" form-control-label"> No</label><input type="text" id="inv_no" name="inv_no" placeholder="Invoice No" class="form-control" value="<? echo $id ?>" readonly></div>
								</div>
								<div class="col-3">
                                <div class="form-group"><label for="feedisc1" class=" form-control-label">User </label><input type="text" id="username" name="username" placeholder="User Name" class="form-control" value="<? echo $username ?>" readonly></div>
								</div>
								<div class="col-2">
                                <div class="form-group"><label for="feedisc1" class=" form-control-label"> Qty</label><input type="text" id="qty" name="qty" placeholder="" class="form-control" ></div>
								</div>
			
								<div class="col-4">
                                <div class="form-group"><label for="feedisc1" class=" form-control-label"> Item No</label><input type="text" id="item_no" name="item_no" placeholder="" class="form-control" ></div>
								</div>

                                                    </div>
													<div class="card-footer">
                                                        <button type="submit" class="btn btn-primary btn-sm">
                                                            <i class="fa fa-dot-circle-o"></i> Add Item
                                                        </button>
                                                       
                                                    </div>
													
													</form>
                                                </div>
                                            </div>
											
											
											
											<div class="col-lg-6">
                        <div class="card">
                            <div class="card-header"><strong>Add Purchase Items</strong><small> Form</small></div>
                            <div class="card-body card-block">
							<form action="Add_Purchase_Item_Save.php" method="post" enctype="multipart/form-data" class="form-group">
							
				<div class="col-2">
                                <div class="form-group"><label for="feedisc1" class=" form-control-label"> No</label><input type="text" id="inv_no" name="inv_no" placeholder="Invoice No" class="form-control" value="<? echo $id ?>" readonly></div>
								</div>
								<div class="col-3">
                                <div class="form-group"><label for="feedisc1" class=" form-control-label">User </label><input type="text" id="username" name="username" placeholder="User Name" class="form-control" value="<? echo $username ?>" readonly></div>
								</div>
								<div class="col-2">
                                <div class="form-group"><label for="feedisc1" class=" form-control-label"> Qty</label><input type="text" id="qty" name="qty" placeholder="" class="form-control" autofocus></div>
								</div>
								<div class="col-4">
                                <div class="form-group"><label for="feedisc1" class=" form-control-label"> Barcode No</label><input type="text" id="barcode" name="barcode" placeholder="" class="form-control"></div>
								</div>
                                                    </div>
													<div class="card-footer">
                                                        <button type="submit" class="btn btn-primary btn-sm">
                                                            <i class="fa fa-dot-circle-o"></i> Add Item
                                                        </button>
                                                       
                                                    </div>
													
													</form>
                                                </div>
                                            </div>
											<div class="col-md-18">
                        <div class="card">
                            <div class="card-header">
                                <strong class="card-title"><h2>Total Amount:  <?php echo $tfeerec; ?>:::Total Items:  <?php echo $tqty; ?></h2>Edit Item Qty:-----------------</strong>
                            </div>
                            <div class="card-body">
							<?php

include 'dbc.php';



$sql1 = "SELECT * FROM purchase_details where  inv_no='$id' and user_id='$userid' order by id";
$result1=$conn->query($sql1);
?>
                                <table id="bootstrap-data-table-export" class="table table-striped table-bordered">
                                    <thead>
									<?php
                                       echo "<tr>";
						 echo "<th > ID </th>";			 
echo "<th > Invoice No </th>";
 echo "<th > Item No </th>";
echo "<th > Item Name </th>";
echo "<th > Barcode </th>";
echo "<th >Rate </th>";
echo "<th > Qty </th>";




echo "</tr>";
?>
                                    </thead>
									
                                    <tbody>
									<?php
									$a = 0;
									echo "<form name='form_update' method='post' action='Purchase_Update.php'>\n";

                                       while($students = $result1->fetch_assoc())
 
  {
  echo '<tr>';
	echo "<td>{$students['id']}<input type='hidden' name='id[$i]' value='{$students['id']}' /></td>";
	echo "<td>{$students['inv_no']}<input type='hidden' name='inv_no[$i]' value='{$students['inv_no']}' /></td>";
	echo "<td>{$students['itemcode']}<input type='hidden' name='itemcode[$i]' value='{$students['itemcode']}' /></td>";
	echo "<td>{$students['barcode']}<input type='hidden' name='barcode[$i]' value='{$students['barcode']}' /></td>";
	echo "<td>{$students['item_name']}<input type='hidden' name='item_name[$i]' value='{$students['item_name']}' /></td>";
	
	echo "<td>{$students['srate']}<input type='hidden' name='srate[$i]' value='{$students['srate']}' /></td>";
	echo "<td><input type='text' size='20' name='saleqty[$i]' value='{$students['qty']}' /></td>";
	
	
	echo '</tr>';
	++$a;
}

	
		echo '<tr>';
echo "<td><input type='submit' value='Purchase Save' /></td>";
echo '</tr>';
echo "</form>";
  


  ?>
                                       
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
					
					<div class="col-md-14">
                        <div class="card">
                            <div class="card-header">
                                <strong class="card-title">Del Item </strong>
                            </div>
                            <div class="card-body">
											
										<?php
include 'dbc.php';



$userid=$_SESSION["userid"];


$class_name=$_POST["class_name"];



$sql = "select * from purchase_details where  inv_no='$id' and user_id='$userid' order by id";
$result=$conn->query($sql);
?>
                                <table id="bootstrap-data-table-export" class="table table-striped table-bordered">
                                    <thead>
									<?php
   

   echo "</tr>";
echo "<tr>";
echo "<th bgcolor=yellow> Date </th>";
echo "<th bgcolor=yellow> Invoice No </th>";
echo "<th bgcolor=yellow> Item Code </th>";
echo "<th bgcolor=yellow> Barcode </th>";
echo "<th bgcolor=yellow> Item Name </th>";
echo "<th bgcolor=yellow>Rate </th>";
echo "<th bgcolor=yellow> Qty </th>";
echo "<th bgcolor=yellow> Amount </th>";
echo "<th bgcolor=yellow> User </th>";
echo "</tr>";
?>
                                    </thead>
									
                                    <tbody>
									<?php
while($ppp = $result->fetch_assoc())
{
   $id = $ppp['id'];	
   echo "<tr>";
    echo "<td width=20%>"  .$ppp["date"] . "</td>" ;
	 echo "<td width=20%>"  .$ppp["inv_no"] . "</td>" ;
   echo "<td width=20%>"  .$ppp["item_no"] . "</td>" ;
   
   echo "<td width=20%>"  .$ppp["barcode"] . "</td>" ;
   echo "<td width=15%>"  .$ppp["item_name"] . "</td>" ;
   echo "<td width=15%>"  .$ppp["srate"] . "</td>" ;
    echo "<td width=15%>"  .$ppp["qty"] . "</td>" ;
    echo "<td width=10%>"  .$ppp["amount"] . "</td>" ;
	echo "<td width=10%>"  .$ppp["username"] . "</td>" ;
	 echo"<th> <a href ='Del_Purchase_Item.php?id=$id'>"?><button type="button" class="btn btn-primary">  Del </button><?php "</a>";
   echo "</tr>";
    $cnt=$cnt + 1;
	$tfeerec1=$tfeerec1 + $ppp['amount'];

   }
    echo "<tr>";
 echo "<th width=20% colspan=8>" ."Toatl Items    :     " .$cnt . "</th>";
 echo "</tr>";
  echo "<tr>";
 echo "<th width=20% colspan=8>" ."Toatl Amount    :     " .$tfeerec1 . "</th>";
 echo "</tr>";
   ?>
         
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
   
   
    

            	
											
                    


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

    <!-- Right Panel -->

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

</body>

</html>
<?php
}

?>