<?php
ini_set('display_errors', 0);
//error_reporting(E_ALL);
//ini_set('display_errors', 1);

session_start();
ob_start();

require_once('configuration/server_connect.php');
require_once('configuration/all_function.php');

$item_id = $_REQUEST['item_id'];
$tr_date = $_REQUEST['tr_date'];
$total_unit_morning = $_REQUEST['total_unit_morning'];
$total_unit_afternoon = $_REQUEST['total_unit_afternoon'];

$flag = $_REQUEST['flag'];

$remarks=" ";
$unit_name='KG';
$tr_no=0;		
		

$sql_del = 'delete from calf_drinks_milk where tr_date="'.$tr_date.'" and  item_id="'.$item_id.'" ';
mysqli_query($conn,$sql_del);
	


$entry_by=$_SESSION['user']['id'];
$entry_at=date('Y-m-d H:i:s');

//$up_sql = 'update milk_record  set total_unit="'.$total_unit.'", 
// edit_by="'.$entry_by.'", edit_at="'.$entry_at.'"  where id='.$order_no;
//mysqli_query($conn,$up_sql);



if($total_unit_morning>0) {
$morning_sql = 'INSERT INTO  calf_drinks_milk (tr_no, tr_date, item_id, unit_name, total_unit, entry_by, entry_at, remarks, milk_schedule, edit_by, edit_at) VALUES

("'.$tr_no.'", "'.$tr_date.'", "'.$item_id.'", "'.$unit_name.'", "'.$total_unit_morning.'", "'.$entry_by.'", "'.$entry_at.'", "'.$remarks.'", "1","0","0000-00-00 00:00:00")';
	
mysqli_query($conn,$morning_sql);
}

if($total_unit_afternoon>0) {
$afternoon_sql = 'INSERT INTO  calf_drinks_milk (tr_no, tr_date, item_id, unit_name, total_unit, entry_by, entry_at, remarks, milk_schedule, edit_by, edit_at) VALUES

("'.$tr_no.'", "'.$tr_date.'", "'.$item_id.'", "'.$unit_name.'", "'.$total_unit_afternoon.'", "'.$entry_by.'", "'.$entry_at.'", "'.$remarks.'", "2","0","0000-00-00 00:00:00")';
	
mysqli_query($conn,$afternoon_sql);
}




echo 'Success!';
?>