<?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');

 $order_no = $_REQUEST['id'];
 $tr_no = $_REQUEST['tr_no'];
 $batch_date = $_REQUEST['batch_date'];
 $recipe_type = $_REQUEST['recipe_type'];
 $no_of_batch = $_REQUEST['no_of_batch'];
 
 $item_id = $_REQUEST['item_id'];
 $unit_name = $_REQUEST['unit_name'];
 $unit_price = $_REQUEST['unit_price'];
 $batch_qty = $_REQUEST['batch_qty'];
 $total_unit_cal = $_REQUEST['total_unit_cal'];
 $total_unit = $_REQUEST['total_unit'];
 $flag = $_REQUEST['flag'];

 
 
 $total_amt=$total_unit*$unit_price;

if($flag>0){
$sql_del = 'delete from batch_production_issue where order_no="'.$order_no.'" and  tr_no="'.$tr_no.'"';
mysqli_query($conn,$sql_del);
}	


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




if($total_unit>0) {
 $issue_sql = 'INSERT INTO  batch_production_issue (tr_no, tr_date, recipe_type, no_of_batch, order_no, item_id, unit_name, unit_price, batch_qty, total_unit_cal, total_unit, total_amt, entry_by, entry_at) VALUES

("'.$tr_no.'", "'.$batch_date.'", "'.$recipe_type.'",  "'.$no_of_batch.'", "'.$order_no.'",  "'.$item_id.'", "'.$unit_name.'", "'.$unit_price.'", "'.$batch_qty.'", "'.$total_unit_cal.'", "'.$total_unit.'", "'.$total_amt.'", "'.$entry_by.'", "'.$entry_at.'")';
	
mysqli_query($conn,$issue_sql);
}




echo 'Success!';
?>