<?php
 
 
require_once ("connectioni.php");



$sqlt = "select * from  s_trn where DEPARTMENT='01' " ; 
 
 $rssalma = mysqli_query($GLOBALS['dbinv'], $sqlt); 
 while ($rssalma = mysqli_fetch_array($rssalma)) { 
  echo $rssalma['STK_NO'];
    // 	$sql1="select * from s_submas where STO_CODE= '".$rssalma['DEPARTMENT']."' and STK_NO= '".$rssalma['STK_NO']."'";  echo $sql1;
    //     $result1 = mysqli_query($GLOBALS['dbinv'], $sql1);
    //     if ($row1 = mysqli_fetch_array($result1)) { 
		    
		     $sql21="update s_submas set QTYINHAND=QTYINHAND+" . $rssalma['QTY'] . " where STK_NO='" . $rssalma['STK_NO'] . "' and  STO_CODE= '".$rssalma['DEPARTMENT']."'  "; 
             $result21 = mysqli_query($GLOBALS['dbinv'], $sql21);
                    
             $sql = "update s_mas set QTYINHAND = QTYINHAND+'" . $rssalma['QTY'] . "' where STK_NO= '" . $rssalma['STK_NO'] . "'"; 
             $resultp = mysqli_query($GLOBALS['dbinv'], $sql);
             
             echo "Up".$rssalma['STK_NO'].'<br>';
		 
// 		} else {
		     
// 		    $sql4 = "select * from s_mas where STK_NO='" . $rssalma['STK_NO'] . "' ";
//         	$result4 = mysqli_query($GLOBALS['dbinv'], $sql4);
//             $row4 = mysqli_fetch_array($result4);
                     
    	
// 			$sql2="Insert into s_submas (STO_CODE, STK_NO, DESCRIPt,QTYINHAND) values
// 			('".$rssalma['DEPARTMENT']."', '".$rssalma['STK_NO']."', '".$row4["DESCRIPT"]."','".$rssalma['QTY']."')";
// 			$result2 = mysqli_query($GLOBALS['dbinv'], $sql2);
			
// 			$sql = "update s_mas set QTYINHAND = QTYINHAND+'" . $rssalma['QTY'] . "' where STK_NO= '" . $rssalma['STK_NO'] . "'"; 
//             $resultp = mysqli_query($GLOBALS['dbinv'], $sql);
            
//             echo "Up &Insert".$rssalma['STK_NO'].'<br>';
// 		}
}

	
	
	
// 
// $sqlt = "select * from  viewsubmas where STO_CODE='03' " ; 
// $result1 = $db->RunQuery($sqlt);
// echo $sqlt."</br>";
// while ($rssalma = mysql_fetch_array($result1)) { 
//     $ref="STKUP".date("Y-m-d");
//     if($rssalma['QTYINHAND']>0){
//         $sql="Insert into s_trn (REFNO, SDATE, LEDINDI,QTY,STK_NO, DEPARTMENT)values 
//     	('".$ref."', '".date("Y-m-d")."', 'INV', '".$rssalma['QTYINHAND']."', '".$rssalma['STK_NO']."','03') ";  
//     	$result =$db->RunQuery($sql);	
    	
//     	$sql4 = "select sum(QTYINHAND) as QTYINHAND from s_submas where STK_NO='" . $rssalma['STK_NO'] . "' and   STO_CODE !='03'";
//     	$result4 =$db->RunQuery($sql4);
//     	$row4 = mysql_fetch_array($result4);
    	
//         $tot=$row4['QTYINHAND'];
//         $sql21="update s_mas set QTYINHAND=" . $tot . " where STK_NO='" . $rssalma['STK_NO'] . "'"; 
//         $result21 =$db->RunQuery($sql21);
     
    	
//     // 	 $sql = "update s_mas set QTYINHAND = QTYINHAND-'" . $rssalma['QTYINHAND'] . "' where STK_NO= '" . $rssalma['STK_NO'] . "'"; 
//     //      $resultp =$db->RunQuery($sql);
         
//          $sql = "update s_submas set QTYINHAND = QTYINHAND-'" . $rssalma['QTYINHAND'] . "' where STK_NO= '" . $rssalma['STK_NO'] . "' and STO_CODE='03'";
//          $resultp =$db->RunQuery($sql);
         
//          echo "up";
         
//     }else{
//       $sql="Insert into s_trn (REFNO, SDATE, LEDINDI,QTY,STK_NO, DEPARTMENT)values 
//     	('".$ref."', '".date("Y-m-d")."', 'GRN', '".$rssalma['QTYINHAND']."'*-1, '".$rssalma['STK_NO']."','03') ";  
//     	$result =$db->RunQuery($sql);
    	
//     	$sql4 = "select sum(QTYINHAND) as QTYINHAND from s_submas where STK_NO='" . $rssalma['STK_NO'] . "' and   STO_CODE !='03'";
//     	$result4 =$db->RunQuery($sql4);
//     	$row4 = mysql_fetch_array($result4);
    	
//         $tot=$row4['QTYINHAND'];
//         $sql21="update s_mas set QTYINHAND=" . $tot . " where STK_NO='" . $rssalma['STK_NO'] . "'"; 
//         $result21 =$db->RunQuery($sql21);
        
        
    	
//     // 	 $sql = "update s_mas set QTYINHAND = QTYINHAND+'" . $rssalma['QTYINHAND'] . "'*-1 where STK_NO= '" . $rssalma['STK_NO'] . "'"; 
//     //      $resultp =$db->RunQuery($sql);
         
//          $sql = "update s_submas set QTYINHAND = QTYINHAND+'" . $rssalma['QTYINHAND'] . "'*-1 where STK_NO= '" . $rssalma['STK_NO'] . "' and STO_CODE='03'";
//          $resultp =$db->RunQuery($sql);
         
         
//          echo "up";
//     }
    
			
   
// }
// 	$sql="Select * from s_mas ";
// 	$result =$db->RunQuery($sql);
// 	while($row = mysql_fetch_array($result)){
//  	  $M_STOCODE='04';
//  	  $stkNo=$row["STK_NO"];
// 		$sql1="select * from s_submas where sto_code= '".trim($M_STOCODE)."' and stk_no= '".trim($stkNo)."'"; 
// 		$result1 =$db->RunQuery($sql1);
// 		if($row1 = mysql_fetch_array($result1)){
		 
// 		} else {
// 			$sql2="Insert into s_submas (STO_CODE, STK_NO, DESCRIPt,QTYINHAND) values ('".trim($M_STOCODE)."', '".trim($stkNo)."', '".$row["DESCRIPT"]."','0')";
// 			$result2 =$db->RunQuery($sql2);echo $stkNo.'<br>';
// 		}
	
// 	}
 
?>