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

$id_po=$_POST['id_po'];
$id_item=$_POST['id_item'];
$part_qty=$_POST['part_qty'];
$part_unit=$_POST['part_unit'];
$id_dep=$_POST['id_dep'];

//echo $id_po;

    if($id_dep=='D02'){
        
        $part_status='รอดำเนินการงานเครื่องกล';
        
        
             $strSQL1 = "SELECT * FROM pd_item
            where id_item='$id_item'";
            $objQuery1 = mysqli_query($con,$strSQL1); 
            $objResult1 = mysqli_fetch_array($objQuery1);
            
            $name_item= $objResult1['name_item'];
            //echo $name_item;
            //exit;
          
            $sql = "INSERT INTO `pd_posub` (`id_po`, `id_item`, `name_item`,`part_qty`,`part_unit`,`id_dep`,`part_status`) 
            VALUES ('$id_po', '$id_item','$name_item', '$part_qty', '$part_unit', '$id_dep','$part_status')";
        	$query = mysqli_query($con,$sql);
                 if($query){
                    ?>
                        <script language="JavaScript" type="text/javascript">
                            <!--
                            alert("บันทึกข้อมูลเรียบร้อย");
                            location.href='../admin/data_posub.php?id_po=<?=$id_po;?>';
                            //-->
                        </script>
                    <?php
                }else{
                    
                    echo "Error: " . $sql . "<br>" . mysqli_error($con);
        
                }   
            
       

        
    }else if($id_dep=='D03'){
        
         $part_status='รอดำเนินการงานเชื่อม';
        
        
        
        
          $strSQL1 = "SELECT * FROM pd_item
        where id_item='$id_item'";
        $objQuery1 = mysqli_query($con,$strSQL1); 
        $objResult1 = mysqli_fetch_array($objQuery1);
        
        $name_item= $objResult1['name_item'];
        //echo $name_item;
        //exit;
      
        $sql = "INSERT INTO `pd_posub` (`id_po`, `id_item`, `name_item`,`part_qty`,`part_unit`,`id_dep`,`part_status`) 
        VALUES ('$id_po', '$id_item','$name_item', '$part_qty', '$part_unit', '$id_dep','$part_status')";
    	$query = mysqli_query($con,$sql);
             if($query){
                ?>
                    <script language="JavaScript" type="text/javascript">
                        <!--
                        alert("บันทึกข้อมูลเรียบร้อย");
                        location.href='../admin/data_posub.php?id_po=<?=$id_po;?>';
                        //-->
                    </script>
                <?php
            }else{
                
                echo "Error: " . $sql . "<br>" . mysqli_error($con);
    
            }
       
       
        
    }else{
        
   
    }
    
        mysqli_close($con);




?>