<?php 
require('../config/dbcon.php');
if(isset($_POST['search'])){
    $search = $_POST['search'];
	$query = "SELECT * FROM supplier_mst WHERE acc_type ='SCR' and Lower(supplier_name) LIKE Lower('%".$search."%') or Lower(supplier_code) LIKE Lower('%".$search."%') or Lower(supplier_place) LIKE Lower('%".$search."%') order by supplier_name limit 10";
    $result = mysqli_query($connect,$query);	
	$curr_month = date('m');
	if($curr_month >= 4 && $curr_month <= 12){
		$year = date('y') . '-' . date('y', strtotime("+1 year"));
	} else{
		$year = date("y",strtotime("-1 year")) . '-' . date("y");
	}	
    while($row = mysqli_fetch_array($result) ){
		$tax_code = $row['tax_code']; 
		if ($tax_code == "GST-B2B")
		{
			$query = "SELECT srno FROM control_mst WHERE description='GRN'";
			$rs = mysqli_query($connect, $query) or die("Cannot execute query: $query\n");
			while ($row1 = mysqli_fetch_assoc($rs)) {
				$srno = '';
				//$srno = 'B2B- '.$row1['srno'].'  '.'('.$year.')';
				$grn_number = $row1['srno']; 
			}
		}
		if ($tax_code == "I-GST")
		{
			$query = "SELECT srno FROM control_mst WHERE description='GRN'";
			$rs = mysqli_query($connect, $query) or die("Cannot execute query: $query\n");
			while ($row1 = mysqli_fetch_assoc($rs)) {
				$srno = '';
				//$srno = 'IGST- '.$row1['srno'].'  '.'('.$year.')';
				$grn_number = $row1['srno']; 
			}
		}
		if ($tax_code == "GST-B2C")
		{
			$query = "SELECT srno FROM control_mst WHERE description='GRN'";
			$rs = mysqli_query($connect, $query) or die("Cannot execute query: $query\n");
			while ($row1 = mysqli_fetch_assoc($rs)) {
				$srno = '';
				//$srno = 'B2C- '.$row1['srno'].'  '.'('.$year.')';
				$grn_number = $row1['srno']; 
			}
		}
        $response[] = array("label"=>$row['supplier_name'],"value"=>$row['supplier_code'],"supplier_place"=>$row['supplier_place'],"tax_code"=>$row['tax_code'],"supplier_gstno"=>$row['supplier_gstno'],"transporter_name"=>$row['transporter_name'],"srno"=>$srno,"opening"=>$row['opening'],"debit"=>$row['debit'],"credit"=>$row['credit'],"clbalance"=>$row['clbalance'],"supplier_address_one"=>$row['supplier_address_one'],"supplier_address_two"=>$row['supplier_address_two'],"supplier_address_three"=>$row['supplier_address_three'],"supplier_pin_code"=>$row['supplier_pin_code'],"supplier_phone"=>$row['supplier_phone'],"supplier_mobile"=>$row['supplier_mobile'],"supplier_st_code"=>$row['supplier_st_code'],"supplier_pan_no"=>$row['supplier_pan_no'],"supplier_email"=>$row['supplier_email'],"supplier_aadhar_no"=>$row['supplier_aadhar_no'],"supplier_st_name"=>$row['supplier_st_name'],"due_days"=>$row['due_days'],"grn_number"=>$grn_number);
    }
    echo json_encode($response);
}
exit;
?>