<?php
 	session_start(); 

	if(!isset($_SESSION['tulsilogin']))
	{
		header('Location: index.php');
		return;
	}


date_default_timezone_set("Asia/Kolkata");
$mdate1= date('Y-m-d H:i:s');
$mdate= date('d-m-Y');
$_SESSION['_token']=bin2hex(openssl_random_pseudo_bytes(16));
	
	$umid = $_SESSION['umid'];
	include("connect.php");

	
	//$cmname=$_POST['cmname'];
	
	
	
	
	
	$countrymid=$_POST['countrymid'];
	$umid1=$_POST['umid'];
	
	$acincentivetype=str_replace ("'","\'",$_POST['acincentivetype']);
	$acincentivetype=str_replace ('"','\"',$acincentivetype);
	
	$actargettype=str_replace ("'","\'",$_POST['actargettype']);
	$actargettype=str_replace ('"','\"',$actargettype);
	
	
	$actargetvalue=str_replace ("'","\'",$_POST['actargetvalue']);
	$actargetvalue=str_replace ('"','\"',$actargetvalue);
	
	
	$commissionstrucher=str_replace ("'","\'",$_POST['commissionstrucher']);
	$commissionstrucher=str_replace ('"','\"',$commissionstrucher);
	
	$cmcurrency=str_replace ("'","\'",$_POST['cmcurrency']);
	$cmcurrency=str_replace ('"','\"',$cmcurrency);
	
	
	$cmgstincexc=str_replace ("'","\'",$_POST['cmgstincexc']);
	$cmgstincexc=str_replace ('"','\"',$cmgstincexc);
	
	$ctaxpercent=str_replace ("'","\'",$_POST['ctaxpercent']);
	$ctaxpercent=str_replace ('"','\"',$ctaxpercent);
	
	$acmremark=str_replace ("'","\'",$_POST['acmremark']);
	$acmremark=str_replace ('"','\"',$acmremark);
	
	$commissionstruchervalue=str_replace ("'","\'",$_POST['commissionstruchervalue']);
	$commissionstruchervalue=str_replace ('"','\"',$commissionstruchervalue);
	$ctaxname=str_replace ("'","\'",$_POST['ctaxname']);
	$ctaxname=str_replace ('"','\"',$ctaxname);
	$delete_checkbox_array1=$_POST['collegemid'];
	$acstartdate = date("Y-m-d",strtotime($_POST['acstartdate']));
	$acenddate = date("Y-m-d",strtotime($_POST['acenddate']));
	
	foreach ($delete_checkbox_array1 as $one_by_one_sid1) 
			{
				$collegemid=$one_by_one_sid1;
	
		 $eve1 = "INSERT INTO res_agentcomission_master (umid,collegemid,countrymid,commissionstrucher,commissionstruchervalue,ctaxname,ctaxpercent,cmgstincexc,cmcurrency,actype,acstartdate,acenddate,acstatus,acincentivetype,actargettype,actargetvalue,acmremark) VALUES('$umid1','$collegemid','$countrymid','$commissionstrucher','$commissionstruchervalue','$ctaxname','$ctaxpercent','$cmgstincexc','$cmcurrency','Institute','$acstartdate','$acenddate','Inactive','$acincentivetype','$actargettype','$actargetvalue','$acmremark')";
		
		
		if ($conn->query($eve1) === TRUE)
		{
			$last_id = $conn->insert_id;
			 if($commissionstrucher == 'Slab')
		  {
		  $delete_checkbox_array = $_POST['slabmid'];
		$n=0;
			foreach ($delete_checkbox_array as $one_by_one_sid) 
			{
				$slabmid=$one_by_one_sid;
					
				$svalue=$_POST['svalue'][$n];
				$n = $n + 1;
			
				
				if($slabmid==0)
				{
				}
				else
				{	
					$eve2="insert into res_agentcomissionslab_detail (acsdid,slabmid,svalue) values($last_id,'$slabmid','$svalue')";
					$re2 = mysqli_query($conn, $eve2);
				}	
				
			}
		  }
			
			$_SESSION['msg'] = "Record has been added successfully";
		}
		else
		{
			$_SESSION['msg1'] = "Error";
		}
			}

	header("Location: userdetail.php?id=$umid1");
			
	
?>