<?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'];
 $cattle_type = $_REQUEST['cattle_type'];
 $no_of_cattle = $_REQUEST['no_of_cattle'];
 $total_feed_qty = $_REQUEST['total_feed_qty'];
 $tr_date = $_REQUEST['tr_date'];
 $unit_price = $_REQUEST['unit_price'];

 $percent = $_REQUEST['percent'];
 $total_unit_cal = $_REQUEST['total_unit_cal'];
 $total_unit = $_REQUEST['total_unit'];
 $flag = $_REQUEST['flag'];


 $unit_name="KG";
		
 $tr_no=0;
 
 $total_amt=$total_unit*$unit_price;

$sql_del = 'delete from cattle_feed_issue where tr_date="'.$tr_date.'" and  item_id="'.$item_id.'" and  cattle_type="'.$cattle_type.'" ';
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>0) {
$feed_sql = 'INSERT INTO  cattle_feed_issue (tr_no, tr_date, cattle_type, no_of_cattle, total_feed_qty, item_id, unit_name, unit_price, percent, total_unit_cal, total_unit, total_amt, entry_by, entry_at, edit_by, edit_at) VALUES

("'.$tr_no.'", "'.$tr_date.'", "'.$cattle_type.'",  "'.$no_of_cattle.'", "'.$total_feed_qty.'",  "'.$item_id.'", "'.$unit_name.'", "'.$unit_price.'", "'.$percent.'", "'.$total_unit_cal.'", "'.$total_unit.'", "'.$total_amt.'", "'.$entry_by.'", "'.$entry_at.'", "0", "0000-00-00")';
	
mysqli_query($conn,$feed_sql);
}




echo 'Success!';
?>