<?php
session_start();
include ('../config/conn.php');
include ('../config/function.php');
//proses tambah
if(isset($_POST['tambah'])){
    $barang_id = $_POST['barang_id'];
    $jumlah = $_POST['jumlah'];
    $satuan = $_POST['satuan_id'];
    $tanggal = $_POST['tanggal'];
    $tanggal_po = $_POST['tanggal_po'];
    $no_po = $_POST['no_po'];
    $project_name = $_POST['project_name'];
    $keterangan = $_POST['keterangan'];
    
    $insert = mysqli_query($con,"INSERT INTO barang_masuk (barang_id, jumlah, satuan_id, tanggal, tanggal_po, no_po, project_name, keterangan) VALUES ('$barang_id','$jumlah','$satuan','$tanggal','$tanggal_po','$no_po','$project_name','$keterangan')") or die (mysqli_error($con));
    $update = mysqli_query($con,"UPDATE barang SET satuan_id='$satuan' WHERE idbarang='$barang_id'") or die (mysqli_error($con));
    if($insert && $update){
        $success = 'Berhasil menambahkan data barang masuk';
    }else{
        $error = 'Gagal menambahkan data barang masuk';
    }
    $_SESSION['success'] = $success;
    $_SESSION['error'] = $error;
    header('Location:../dashboard.php?barang_masuk');
}
if(decrypt($_GET['act'])=='delete' && isset($_GET['id'])!=""){
    // echo $_GET['act'];die;
    $id = decrypt($_GET['id']);
    $delete = mysqli_query($con, "DELETE FROM barang_masuk WHERE idbarang_masuk ='$id'")or die(mysqli_error($con));
    if ($delete) {
        $success = "Data barang masuk berhasil dihapus";
    }else{
        $error = "Data barang masuk gagal dihapus";
    }
    $_SESSION['success'] = $success;
    $_SESSION['error'] = $error;
    header('Location:../dashboard.php?barang_masuk');
}
?>