<?php
ob_start();
session_start();
require_once("../conn/conn.php");
//include('../utility/chksession.php');
date_default_timezone_set("Asia/Bangkok");


$id_posub=$_POST['id_posub'];
$part_status=$_POST['part_status'];
$id_dep = $_SESSION['id_dep'];

echo $part_status;?></br><?
echo $id_dep;?></br><?
echo $id_posub;?></br><?

//exit;

if($part_status=='รอดำเนินการงานเชื่อม'){
    
    $strSQL = "SELECT * FROM pd_ver
			where id_posub='$id_posub'
			and id_dep='D03'";
	$objQuery = mysqli_query($con,$strSQL); 
	$objResult = mysqli_fetch_array($objQuery);
	
	$addround= $objResult['job_round']+1;
  
    $sql1 = "UPDATE pd_ver SET job_round = '$addround'  WHERE id_posub='$id_posub'
			and id_dep='D03'";
	$query1 = mysqli_query($con,$sql1);
	
    $sql = "UPDATE pd_posub SET part_status = '$part_status'  WHERE id_posub = '$id_posub'";
	$query = mysqli_query($con,$sql);
	
        if($query){
            ?>
                <script language="JavaScript" type="text/javascript">
                    <!--
                    alert("บันทึกข้อมูลเรียบร้อย");
                    location.href='../user/data_qc.php';
                    //-->
                </script>
            <?php
        }else{
            
            echo "Error: " . $sql . "<br>" . mysqli_error($con);

        }
        mysqli_close($con);
}elseif($part_status=='รอดำเนินการงานเครื่องกล'){
    
    $strSQL = "SELECT * FROM pd_ver
			where id_posub='$id_posub'
			and id_dep='D02'";
	$objQuery = mysqli_query($con,$strSQL); 
	$objResult = mysqli_fetch_array($objQuery);
	
	$addround= $objResult['job_round']+1;
  
    $sql1 = "UPDATE pd_ver SET job_round = '$addround'  WHERE id_posub='$id_posub'
			and id_dep='D02'";
	$query1 = mysqli_query($con,$sql1);
	
    $sql = "UPDATE pd_posub SET part_status = '$part_status'  WHERE id_posub = '$id_posub'";
	$query = mysqli_query($con,$sql);
	
        if($query){
            ?>
                <script language="JavaScript" type="text/javascript">
                    <!--
                    alert("บันทึกข้อมูลเรียบร้อย");
                    location.href='../user/data_qc.php';
                    //-->
                </script>
            <?php
        }else{
            
            echo "Error: " . $sql . "<br>" . mysqli_error($con);

        }
        mysqli_close($con); 
}else{
    
    
     $sql = "UPDATE pd_posub SET part_status = '$part_status'  WHERE id_posub = '$id_posub'";
	$query = mysqli_query($con,$sql);
	
        if($query){
            ?>
                <script language="JavaScript" type="text/javascript">
                    <!--
                    alert("บันทึกข้อมูลเรียบร้อย");
                    location.href='../user/data_qc.php';
                    //-->
                </script>
            <?php
        }else{
            
            echo "Error: " . $sql . "<br>" . mysqli_error($con);

        }
        mysqli_close($con);
}





/*
if($part_status=='รอดำเนินการQC'){
    
    $sql = "UPDATE pd_posub SET part_status = '$part_status'  WHERE id_posub = '$id_posub'";
	$query = mysqli_query($con,$sql);
	
        if($query){
            ?>
                <script language="JavaScript" type="text/javascript">
                    <!--
                    alert("บันทึกข้อมูลเรียบร้อย");
                    location.href='../user/user_job.php';
                    //-->
                </script>
            <?php
        }else{
            
            echo "Error: " . $sql . "<br>" . mysqli_error($con);

        }
        mysqli_close($con);
    
    
}else if($part_status=='รอดำเนินการwhes'){
    
    $sql = "UPDATE pd_posub SET part_status = '$part_status'  WHERE id_posub = '$id_posub'";
	$query = mysqli_query($con,$sql);
	
        if($query){
            ?>
                <script language="JavaScript" type="text/javascript">
                    <!--
                    alert("บันทึกข้อมูลเรียบร้อย");
                    location.href='../user/user_job.php';
                    //-->
                </script>
            <?php
        }else{
            
            echo "Error: " . $sql . "<br>" . mysqli_error($con);

        }
        mysqli_close($con);
    
}else if($part_status=='รอดำเนินการ-SUP'){
    
    $sql = "UPDATE pd_posub SET part_status = '$part_status'  WHERE id_posub = '$id_posub'";
	$query = mysqli_query($con,$sql);
	
        if($query){
            ?>
                <script language="JavaScript" type="text/javascript">
                    <!--
                    alert("บันทึกข้อมูลเรียบร้อย");
                    location.href='../user/user_job.php';
                    //-->
                </script>
            <?php
        }else{
            
            echo "Error: " . $sql . "<br>" . mysqli_error($con);

        }
        mysqli_close($con);
    
    
}else if($part_status=='รอดำเนินการงานเชื่อม'){
    //กรณีผลิต
    
    
    echo "เชื่อม";
    
    //
  	$strSQL = "SELECT * FROM pd_ver
			where id_posub='$id_posub'
			and id_dep='D03'";
	$objQuery = mysqli_query($con,$strSQL); 
	$objResult = mysqli_fetch_array($objQuery);
	
	$addround= $objResult['job_round']+1;
  
    $sql1 = "UPDATE pd_ver SET job_round = '$addround'  WHERE id_posub='$id_posub'
			and id_dep='D03'";
	$query1 = mysqli_query($con,$sql1);
	
    $sql = "UPDATE pd_posub SET part_status = '$part_status'  WHERE id_posub = '$id_posub'";
	$query = mysqli_query($con,$sql);
	
        if($query){
            ?>
                <script language="JavaScript" type="text/javascript">
                    <!--
                    alert("บันทึกข้อมูลเรียบร้อย");
                    location.href='../user/user_job.php';
                    //-->
                </script>
            <?php
        }else{
            
            echo "Error: " . $sql . "<br>" . mysqli_error($con);

        }
        mysqli_close($con);
        //
    
}else{
        //กรณีผลิต
  	$strSQL = "SELECT * FROM pd_ver
			where id_posub='$id_posub'
			and id_dep='D04'";
	$objQuery = mysqli_query($con,$strSQL); 
	$objResult = mysqli_fetch_array($objQuery);
	
	$addround= $objResult['job_round']+1;
  
    $sql1 = "UPDATE pd_ver SET job_round = '$addround'  WHERE id_posub='$id_posub'
			and id_dep='D04'";
	$query1 = mysqli_query($con,$sql1);
	
    $sql = "UPDATE pd_posub SET part_status = '$part_status'  WHERE id_posub = '$id_posub'";
	$query = mysqli_query($con,$sql);
	
        if($query){
            ?>
                <script language="JavaScript" type="text/javascript">
                    <!--
                    alert("บันทึกข้อมูลเรียบร้อย");
                    location.href='../user/user_job.php';
                    //-->
                </script>
            <?php
        }else{
            
            echo "Error: " . $sql . "<br>" . mysqli_error($con);

        }
        mysqli_close($con);
    
    
}

  
*/

   



?>