<?php
include "../../root.class.php";
$db = new db_safeguard();
$index = 1;
$fail = 0;
while ($fail == 0) {

    if (isset($_POST["stock_id_$index"])) {

        $db->query("stock_take_stock", "UPDATE stock_take_stock SET amount_counted = {$_POST["stock_amount_$index"]} WHERE item_id = {$_POST["stock_id_$index"]} AND stock_take_id = {$_GET['stock_take_id']}");


    } else {
        $fail = 1;
    }
    $index++;
}


$index_non_stock = 1;
$fail_non_stock = 0;
while ($fail_non_stock == 0) {

    if (isset($_POST["non_stock_id_$index_non_stock"])) {

        $db->query("stock_take_non_stock", "UPDATE stock_take_non_stock SET in_stock = {$_POST["non_stock_in_stock_$index_non_stock"]} WHERE non_stock_id = {$_POST["non_stock_id_$index_non_stock"]} AND stock_take_id = {$_GET['stock_take_id']}");

    } else {
        $fail_non_stock = 1;
    }
    $index_non_stock++;
}

$date = date("Y-m-d H:i", strtotime("+ 2 Hours"));
if ($_GET['save'] == 0) {
    $db->query("stock_takes", "UPDATE stock_takes SET date_done = '$date', user_id_done = {$_SESSION['user_id']}, disision = 'IN-REVIEW' WHERE record_id = {$_GET['stock_take_id']}");
}


echo "1";