<?php include "../../root.class.php";
$html = new html();
$db = new db_safeguard();

$batch_id = $_GET['batch_id'];
$pv = $_GET['pv'];
$ffa = $_GET['ffa'];
$variety_id = $_GET['variety_id'];
$weight = $_GET['weight'];
$moisture = $_GET['moisture'];
$sound_not_sound = $_GET['sound_not_sound'];
$shell = strtoupper($_GET['shell']);
$date = $_GET['date'];
$bins = $_GET['bins'];

if ($sound_not_sound == "YES") {
    if ($shell == "YES") {

        // echo "INSERT INTO 'batch' (`batch_id`, `pv`, `ffa`, `variety_id`, `weight`, `moisture`, `date`,`drying_bin_id`,`shell`,`silo_id`) VALUES ($batch_id, $pv, $ffa, $variety_id, $weight, $moisture, $date, '0', $shell, '0')";

        $res = $db->insert("INSERT INTO batch (`batch_id`, `pv`, `ffa`, `variety_id`, `weight`, `moisture`, `date`,`drying_bin_id`,`shell`,`silo_id`) VALUES ($batch_id, $pv, $ffa, $variety_id, $weight, $moisture, '$date', '0', '$shell', '0')");

        $db->Update('batches', ['status'], ['DEHUSKING'], "record_id = $batch_id");

    } else {

        // echo "INSERT INTO 'batch' (`batch_id`, `pv`, `ffa`, `variety_id`, `weight`, `moisture`, `date` ,'drying_bin_id',`shell`) VALUES ('$batch_id','$pv','$ffa','$variety_id','$weight','$moisture','$date','$bins','$shell')";

        $res = $db->insert("INSERT INTO batch (`batch_id`, `pv`, `ffa`, `variety_id`, `weight`, `moisture`, `date` ,'drying_bin_id',`shell`) VALUES ($batch_id,$pv,$ffa,$variety_id,$weight,$moisture,'$date',$bins,'$shell')");

        // echo "INSERT INTO `bins`(`batch_id`, `variety_id`, `weight`, `date`, `drying_bin_id`) VALUES ('$batch_id', '$variety_id', '$weight', '$date', '$bins')";

        $db->insert("INSERT INTO bins (`batch_id`, `variety_id`, `weight`, `date`, `drying_bin_id`) VALUES ($batch_id, $variety_id, $weight, '$date', $bins)");

        // echo "Update('drying_bins', ['variety_id'], [$variety_id], 'record_id = $variety_id')";

        $db->Update('drying_bins', ['variety_id'], [$variety_id], "record_id = $variety_id");

        $db->Update('batches', ['status'], ['DRYING BINS'], "record_id = $batch_id");
    }
} else {
    $db->Update('batches', ['status', 'sound_not_sound'], ['NOT SOUND', 'NO'], "record_id = $batch_id");
}

if ($res) {
    echo 1;
} else {
    echo 0;
}