<?php session_start(); 

						
if ($_SESSION["dev"]!=""){
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="imagetoolbar" content="no" />
<title>Administration Panel</title>
<link media="screen" rel="stylesheet" type="text/css" href="css/admin.css"  />
<!--[if lte IE 6]><link media="screen" rel="stylesheet" type="text/css" href="css/admin-ie.css" /><![endif]-->
<script src="js/user.js"></script> 
</head>

<body>
	<!--[if !IE]>start wrapper<![endif]-->
	<div id="wrapper">
		<!--[if !IE]>start head<![endif]-->
		<div id="head">
			
			<!--[if !IE]>start logo and user details<![endif]-->
			<!--<div id="logo_user_details">-->
				<!--<h1 id="logo"><img src="images/tyres.png" alt="img" width="218" height="165" />	 </h1>-->
                
                 <!--<div class="tyrename">-->
                <?php
				/*	if ($_SESSION['company']=="BEN"){
						echo "Benedictsons (Pvt) Ltd.";
					} else if ($_SESSION['company']=="THT"){
						echo "Tyre House Trading (Pvt) Ltd.";
					}*/
				// 	echo $_SESSION['company'];	
				?> 
				<!--</div>-->
              
							<!--[if !IE]>start user details<![endif]--><!--[if !IE]>end user details<![endif]-->
				
				
				
			<!--</div>-->
			
			<!--[if !IE]>end logo end user details<![endif]-->
			
			
			
			<!--[if !IE]>start menus_wrapper<![endif]-->
			<?php
				include('menu_index.php');
			?>
			<!--[if !IE]>end menus_wrapper<![endif]-->
			
			
			
		</div>
		<!--[if !IE]>end head<![endif]-->
		
		<!--[if !IE]>start content<![endif]-->
		<div id="content">
                    <img src="./css/layout/login/logo2.png"></img>
                    
                     <div class="box">
        <table>
            <tr>
                <th>
			<?php
            	include('connectioni.php');
	
		$sqltmp="select * from invpara";
		$resulttmp=mysqli_query($GLOBALS['dbinv'],$sqltmp);
		$rowtmp = mysqli_fetch_array($resulttmp);
			
//		  echo "<label>";
//			if ($rowtmp["form_loc"]=="1"){
//				echo "<input type=\"radio\" name=\"radio\" id=\"rd_lock\" value=\"rd_lock\" checked=\"checked\" onclick=\"set_check();\"/> Lock</br></br>";
//				echo "<input type=\"radio\" name=\"radio\" id=\"rd_unlock\" value=\"rd_unlock\"  onclick=\"set_check();\"/> Un Lock</br>";
//			} else {
//				echo "<input type=\"radio\" name=\"radio\" id=\"rd_lock\" value=\"rd_lock\" onclick=\"set_check();\"/> Lock</br></br>";
//				echo "<input type=\"radio\" name=\"radio\" id=\"rd_unlock\" value=\"rd_unlock\"  checked=\"checked\" onclick=\"set_check();\"/> Un Lock</br>";
//			}
                if ($_SESSION["UserName"] == "malabe"){
			if ($rowtmp["block_c"]=="1"){
				echo "<input type=\"radio\" name=\"radio\" id=\"rd_lock\" value=\"rd_lock\" checked=\"checked\" onclick=\"set_check('1');\"/> Lock</br></br>";
				echo "<input type=\"radio\" name=\"radio\" id=\"rd_unlock\" value=\"rd_unlock\"  onclick=\"set_check('0');\"/> Un Lock</br>";
			} else {
				echo "<input type=\"radio\" name=\"radio\" id=\"rd_lock\" value=\"rd_lock\" onclick=\"set_check('1');\"/> Lock</br></br>";
				echo "<input type=\"radio\" name=\"radio\" id=\"rd_unlock\" value=\"rd_unlock\"  checked=\"checked\" onclick=\"set_check('0');\"/> Un Lock</br>";
			}	
				
                }			
                          ?>
            
		
		 <tr>
                <th>
                     <?php
                                    
                                   
                                   echo "<table class='CSSTableGenerator' style=\"overflow-y:scroll; color:red; height:100px;overflow:scroll;\">";
                                        echo "<tr><th colspan=4' style='color:blue'>Problem Items</th></tr>";

                                        echo "<tr><th width ='50' style='color:blue'>STK NO</th>";
                                        echo "<th width ='200' style='color:blue'>Qty IN Hand</th>";
                                        echo "<th width ='80' style='color:blue'>True QTY</th>";
                                        echo "<th width ='80' style='color:blue'>Department</th></tr>";
                                        
                                        //       $sql_20="Select * from s_mas ";
                                        //         $result_20 = mysqli_query($GLOBALS['dbinv'], $sql_20); 
                                        // while ($row_20 = mysqli_fetch_array($result_20)) {
                                            
                                                            
                                        //     // foreach ($conn->query($sql_20) as $row_20) {  
                                        //         $M_STOCODE='01';
                                        //         $stkNo=$row_20["STK_NO"];
                                        //         $sql_21="select * from s_submas where sto_code= '".trim($M_STOCODE)."' and stk_no= '".trim($stkNo)."'";  
                                                            
                                        //         $result_21=mysqli_query($GLOBALS['dbinv'],$sql_21);
                                        //     if ($row_21= mysqli_fetch_array($result_21)){
                                            
                                        //         // meka wardi check krnn
                                        //         } else {
                                        //             $sql2="Insert into s_submas (STO_CODE, STK_NO, DESCRIPt,QTYINHAND) values ('".trim($M_STOCODE)."', '".trim($stkNo)."', '".$row_20["DESCRIPT"]."', '0')";
                                        //           $resul2=mysqli_query($GLOBALS['dbinv'],$sql2);
                                        //             echo $stkNo.'<br>';
                                            
                                        //         }
                                            
                                        //     }
     
                                        $sql11 = "update s_trn set tru_qty = qty where (ledindi = 'ARN' or ledindi ='GRN' or ledindi = 'GINR' or ledindi ='IIN' or ledindi = 'TRN'  or ledindi = 'GINRNR')    ";
                                        $result_1 = mysqli_query($GLOBALS['dbinv'], $sql11);
                                        $row_1 = mysqli_fetch_array($result_1);
                                                  
                                        $sql12 = "update s_trn set tru_qty = qty * -1 where (ledindi = 'ISO' or ledindi = 'ARR' or ledindi ='INV' or ledindi = 'GINI' or ledindi ='IOU' or ledindi = 'GININ' or ledindi = 'GINRN')   ";
                                        $result_2 = mysqli_query($GLOBALS['dbinv'], $sql12);
                                        $row_2 = mysqli_fetch_array($result_2);
                                                  
                                        $sql13 = "select stk_no,QTYINHAND,sum(tru_qty),department  from view_trn_submas   group by stk_no,department  having qtyinhand <> sum(tru_qty)  ";
                                        $result_3 = mysqli_query($GLOBALS['dbinv'], $sql13); 
                                        while ($row_3 = mysqli_fetch_array($result_3)) {
                            //                 $sql110 = "update s_submas set QTYINHAND = '".$row_3['sum(tru_qty)']."' where  STK_NO='" . $row_3['STK_NO'] . "' and STO_CODE='" . $row_3['DEPARTMENT'] . "'   ";  
                            // $resul2=mysqli_query($GLOBALS['dbinv'],$sql110);
                                            

                                            echo "<tr><td>" . $row_3['STK_NO'] . "</td>";
                                            echo "<td>" . $row_3['QTYINHAND'] . "</td>";
                                            echo "<td>" . $row_3['sum(tru_qty)'] . "</td>";
                                            echo "<td>" . $row_3['DEPARTMENT'] . "</td></tr>";
                                        }
                                        
//                                         echo "<tr><th width ='50' style='color:blue' >STK NO</th>";
//                                         echo "<th width ='200' style='color:blue'>Qty IN Hand</th>";
//                                         echo "<th width ='80' style='color:blue'>True QTY</th>"; 
     
// //                                        $sql14 = "update s_trn set tru_qty = qty where (ledindi = 'ARN' or ledindi ='GRN' or ledindi = 'GINR' or ledindi ='IIN'  or ledindi='TRN');";
// //                                        $result_4 = mysqli_query($GLOBALS['dbinv'], $sql14);
// //                                        $row_4 = mysqli_fetch_array($result_4);
// //                                                  
// //                                        $sql15 = "update s_trn set tru_qty = qty * -1 where (ledindi = 'ISO' or ledindi = 'ARR' or ledindi ='INV' or ledindi = 'GINI' or ledindi ='IOU');";
// //                                        $result_5 = mysqli_query($GLOBALS['dbinv'], $sql15);
// //                                        $row_5 = mysqli_fetch_array($result_5);
                                                  
//                                         $sql16 = "select stk_no,QTYINHAND,sum(tru_qty)  from view_trn_smas    group by stk_no  having qtyinhand <> sum(tru_qty)";;
//                                         $result_6 = mysqli_query($GLOBALS['dbinv'], $sql16); 
//                                         while ($row_6 = mysqli_fetch_array($result_6)) {
                                            
//                                             //  $sql111 = "update s_mas set QTYINHAND = '".$row_6['sum(tru_qty)']."' where  STK_NO='" . $row_6['STK_NO'] . "'    ";  
//                                             // $result_111 = mysqli_query($GLOBALS['dbinv'], $sql111);
//                                             // $row_111 = mysqli_fetch_array($result_111);

//                                             echo "<tr><td>" . $row_6['STK_NO'] . "</td>";
//                                             echo "<td>" . $row_6['QTYINHAND'] . "</td>";
//                                             echo "<td>" . $row_6['sum(tru_qty)'] . "</td></tr>";
//                                         }
                                        
//                                         echo "<tr><th colspan=4' style='color:blue'>Minus Items</th></tr>";

//                                         echo "<tr><th width ='50' style='color:blue'>Item No</th>";
//                                         echo "<th width ='200' style='color:blue'>Qty IN Hand</th>"; 
//                                         echo "<th width ='80' style='color:blue'>Department</th></tr>";
                                        
//                                         $sql17 = "select *  from s_mas  where QTYINHAND <0   ";
//                                         $result_7 = mysqli_query($GLOBALS['dbinv'], $sql17);
//                                         while ($row_7 = mysqli_fetch_array($result_7)) {

//                                             echo "<tr><td>" . $row_7['STK_NO'] . "</td>";
//                                             echo "<td>" . $row_7['QTYINHAND'] . "</td></tr>";
//                                         }
                                        
//                                          $sql18 = "select *  from s_submas  where QTYINHAND <0   ";
//                                         $result_8 = mysqli_query($GLOBALS['dbinv'], $sql18);
//                                         while ($row_8 = mysqli_fetch_array($result_8)) {

//                                             echo "<tr><td>" . $row_8['STK_NO'] . "</td>";
//                                             echo "<td>" . $row_8['QTYINHAND'] . "</td>";
//                                             echo "<td>" . $row_8['STO_CODE'] . "</td></tr>";
//                                         }
                                        
//                                         echo "<tr><th colspan=4' style='color:blue'>Department Total Problem</th></tr>";

//                                         echo "<tr><th width ='50' style='color:blue'>Item No</th></tr>";
                                        
//                                          $sql19 = "select *  from s_mas  ";
//                                         $result_9 = mysqli_query($GLOBALS['dbinv'], $sql19);
//                                         while ($row_9 = mysqli_fetch_array($result_9)) {
                                            
//                                             $sql10 = "select sum(QTYINHAND) as QTYINHAND  from s_submas where STK_NO = '" . $row_9["STK_NO"] . "' group by STK_NO "; 
//                                             $result_10 = mysqli_query($GLOBALS['dbinv'], $sql10);
//                                             $row_10 = mysqli_fetch_array($result_10);
                                            
//                                             if($row_9['QTYINHAND']!=$row_10['QTYINHAND']){
//                                                 echo "<tr><td>" . $row_9['STK_NO'] . "</td></tr>";
//                                             }

                                            
//                                         }
                                   
                                   echo "</table>";
                                    ?>


                </th>
            </tr>
            
            
        </table>
    </div>
	  </div>
	  <!--[if !IE]>end content<![endif]-->
		
	</div>
	<!--[if !IE]>end wrapper<![endif]-->
	
	<!--[if !IE]>start footer<![endif]-->
	<div id="footer">
	</div>
	<!--[if !IE]>end footer<![endif]-->
	
</body>
</html>
<?php
} else {
	echo "Invalied User !!!"; 
}
?>