<?php
session_start();
include('../config/conn.php');
include('../config/function.php');
if (isset($_POST['tambah'])) {
    $id = $_POST['id'];
    $stok = $_POST['stok'];
    $barang = $_POST['barang'];

    $select_barang = mysqli_query($con, "Select * From barang where idbarang = '$barang'")->fetch_all();
    $stok_barang = $select_barang[0][5];
    $count = ($stok + $stok_barang);

    $update_barang = mysqli_query($con, "UPDATE barang set stok='$count' where idbarang= '$barang' ");
    $update_peminjaman = mysqli_query($con, "UPDATE peminjaman set status=1 where id_peminjaman = '$id'");
    if ($update_barang && $update_peminjaman) {
        $success = 'Berhasil Mengembalikan barang';
    } else {
        $error = "Gagal mengembalikan barang";
    }
    $_SESSION['success'] = $success;
    $_SESSION['error'] = $error;
    header('Location:../dashboard.php?peminjaman');
}
