<?php
require "../commonincludefiles.php";
error_reporting(1);


if ($_SESSION["cCompany_id"] != "" && isset($_SESSION["cCompany_id"])) {
	$phone1 = Escape($_POST["phone1"]);
	$cust_id = Escape($_REQUEST["customer_id"]);

	$result = " SELECT *,DATE_FORMAT(date1,'%d-%m-%Y') as date_f FROM `lms_cust` INNER JOIN lms_customer INNER JOIN lms_usermaster WHERE lms_cust.status != 'Completed' and lms_cust.customer_id = lms_customer.customer_id and lms_cust.company_id = '" . $_SESSION['cCompany_id'] . "' and lms_cust.user_id = lms_usermaster.user_id order by status   desc , date1 desc ";
	//echo $result;

	if ($phone1 != "") {
		$result = $result . " AND `mobno` LIKE '%" . $phone1 . "%' OR `phoneNo` LIKE '%" . $phone1 . "%' ";//  OR `customer_orgname` LIKE '%".$phone1."%'  ";
	}

	$q = dbQuery($result);
	$total = dbRows($q);
	$i = 0;
	$distictData = array("count" => $total, "rows1" => array());
	if (($total) > 0) {
		$temparray = array();

		while ($row = dbArray($q)) {
			$product_name1 = 0;
			$temparray["cust_id"] = $row["cust_id"];
			$temparray["customer_id"] = $row["customer_id"];
			$temparray["customer_orgname"] = $row["customer_orgname"];
			$temparray["date1"] = $row["date1"];
			$temparray["status"] = $row["status"];
			$temparray["user_id"] = $row["user_id"];
			$temparray["user_name"] = $row["user_name"];
			$temparray["assign_user_id"] = $row["assign_user_id"];
			$asign_qry = "SELECT `user_name` as asign_user_name FROM `lms_usermaster` WHERE `user_id` = '" . $temparray["assign_user_id"] . "'";
			$asign_res = dbQuery($asign_qry);
			$result_asign = dbArray($asign_res);
			$temparray["asign_user_name"] = $result_asign["asign_user_name"];

			$distictData["rows1"][$i] = $temparray;
			$i++;
		}
		print_r($product_name);
	}
	echo json_encode($distictData);
}
?>