<?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';

$username=$_SESSION["username"];
$current_file_name = basename($_SERVER['PHP_SELF']);
$sql = "SELECT * FROM adduser where feedisc2 = '$current_file_name' and uname = '$username'";
$result=$conn->query($sql);
$row = $result->fetch_assoc();
$status=$row['feedisc3'] ;

if ($status =="")
{
echo "You are not Authorized This Page <a href='maindashboard.php'>Back </a> ";
}
else
{
include 'dbc.php';
$userid=$_SESSION["userid"];
$username=$_SESSION["username"];
			$bname=$_REQUEST["bname"];
$city=$_REQUEST["city"];
$sql66 = "SELECT * FROM invoice where cname='$bname' ORDER BY v_no DESC LIMIT 1";
$result66=$conn->query($sql66);
		$row66 = $result66->fetch_assoc();
$largestNumber=$row66['v_no'] ;
$largestNumber = $largestNumber +1;
$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;
	$sql5="SELECT * FROM chartofaccounts where acc_type='Cash' or acc_type='Bank' and user_id='$userid'";
$result5 = $conn->query($sql5);
$sql1 = "select * from customer where bname='$bname' and user_id='$userid'";
$result1=$conn->query($sql1);
while($ppp = $result1->fetch_assoc())
{
 
  $id=$ppp["id"]; 
 $qtyret=0;
  $netqty =0;
$tcost = 0; 
$qtysale=0;
$qtypur=0;
$qtysalest=0;
$qtydr=0;
$qtycr=0;
  $sql2 = "select * from invoice where cname='$bname' and user_id='$userid'";
$result2=$conn->query($sql2);
while($ppp1 = $result2->fetch_assoc())
{
  $qtysale= $qtysale + $ppp1["gamount"];   
 } 
  $sql2st = "select * from invoice_st where cname='$bname' and user_id='$userid'";
$result2st=$conn->query($sql2st);
while($ppp1st = $result2st->fetch_assoc())
{
  $qtysalest= $qtysalest + $ppp1st["gamount"];   
 } 
$sql3 = "select * from cashrec where ven_name='$bname' and user_id='$userid'";
$result3=$conn->query($sql3);
while($ppp3 = $result3->fetch_assoc())
{
  $qtypur= $qtypur + $ppp3["netamount"];   
 } 
 
 $sqlret = "select * from invoice_return where cname='$bname' and user_id='$userid'";
$resultret=$conn->query($sqlret);
while($pppret = $resultret->fetch_assoc())
{
  $qtyret= $qtyret + $pppret["netamount"];   
 } 
 
 $sqldr = "select * from cdebitnote where ven_name='$bname' and user_id='$userid'";
$resultdr=$conn->query($sqldr);
while($pppdr = $resultdr->fetch_assoc())
{
  $qtydr= $qtydr + $pppdr["netamount"];   
 } 
 
 $sqlcr = "select * from ccreditnote where ven_name='$bname' and user_id='$userid'";
$resultcr=$conn->query($sqlcr);
while($pppcr = $resultcr->fetch_assoc())
{
  $qtycr= $qtycr + $pppcr["netamount"];   
 } 
$netqty = ($qtysale + $qtysalest + $qtydr) - ($qtypur + $qtyret + $qtycr);
}
?>
<!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>Genrate Invoice</strong><small> Form</small></div>
                            <div class="card-body card-block">
							<form action="Genrate_Invoice_Save.php" method="post" enctype="multipart/form-data" class="form-group">
							
							<div class="col-4">
                                <div class="form-group"><label for="feedisc1" class=" form-control-label"> Month</label><input type="text" id="month_name" name="month_name" placeholder="Attendance Month" class="form-control" value="<? echo $my ?>" ></div>
								</div>
							
								<div class="col-4">
                                <div class="form-group"><label for="feedisc1" class=" form-control-label"> Date</label><input type="date" id="date" name="date" placeholder="Date" class="form-control" value="<? echo $today ?>"></div>
								</div>
																
								
								<div class="col-4">
                                <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-4">
                                <div class="form-group"><label for="feedisc1" class=" form-control-label">Customer Invo No</label><input type="text" id="v_no" name="v_no" placeholder="Customer Invo No" class="form-control" value="<? echo $largestNumber ?>"></div>
								</div>
												
								<div class="col-4">
                                <div class="form-group"><label for="feedisc1" class=" form-control-label">Customer Name</label><input type="text" id="bname" name="bname" placeholder="Customer Name" class="form-control" value="<? echo $bname ?>" readonly></div>
								</div>
								
								<div class="col-4">
                                <div class="form-group"><label for="feedisc1" class=" form-control-label">City</label><input type="text" id="city" name="city" placeholder="City" class="form-control" value="<? echo $city ?>" readonly></div>
								</div>
								<div class="col-4">
                                <div class="form-group"><label for="feedisc1" class=" form-control-label">Balance</label><input type="text" id="bal" name="bal" placeholder="Balance" class="form-control" value="<? echo $netqty ?>" readonly></div>
								</div>
								<div class="row form-group">
                                                                    <div class="col col-md-3"><label for="select" class=" form-control-label">G/L Account</label></div>
                                                                    <div class="col-12 col-md-4">
                                                                        <select name="acc_name_dr" id="acc_name_dr" class="form-control">
                                                                            <?php
  while($user_data5=$result5->fetch_assoc())
  {
  ?>
              <option value="<? echo $user_data5['acc_name']; ?>"><? echo $user_data5["acc_name"]; ?></option>
              <?php
  }
  ?>
                                                                        </select>
                                                                    </div>
                                                                </div>
									
								
								
								
								
								
									
										
				
													
                                                    </div>
													<div class="card-footer">
                                                        <button type="submit" class="btn btn-primary btn-sm">
                                                            <i class="fa fa-dot-circle-o"></i> Genrate Invoice
                                                        </button>
                                                       
                                                    </div>
													
													</form>
                                                </div>
                                            </div>

            


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

    <!-- Right Panel -->

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

</body>

</html>
<?php
}
}
?>