<?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'];
	
	
	$acmremark=str_replace ("'","\'",$_POST['acmremark']);
	$acmremark=str_replace ('"','\"',$acmremark);
	
	
	
	
	$countrymid=$_POST['countrymid'];
	$umid1=$_POST['umid'];
	
	
	$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);
	
	$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,acmremark) VALUES('$umid1','$collegemid','$countrymid','$commissionstrucher','$commissionstruchervalue','$ctaxname','$ctaxpercent','$cmgstincexc','$cmcurrency','Institute','$acstartdate','$acenddate','Inactive','$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: agentdetail.php?id=$umid1");
			
	
?>