EasuUI pagination,searching and sorting

/*** FOR SEARCHING *****/

$store_id = intval(REQUEST(“store_id”));
$employee_id = intval(REQUEST(“employee_id”));
$shift_number = intval(REQUEST(“shift_number”));

$searchargument_start =”Where 1=1 “;

if($store_id>0)
{
$searchargument []=”store_id=’$store_id'”;
}

if($employee_id>0)
{
$searchargument []=”employee_id=’$store_id'”;
}
if($shift_number>0)
{
$searchargument []=”ref_shift_id=’$shift_number'”;
}

$where_search=implode(” and “, $searchargument);

if(strlen($where_search)>3)
{
$searchargument_start.= “and “.$where_search;
}
/**** END SEARCHING *****/
$page = isset($_POST[‘page’]) ? intval($_POST[‘page’]) : 1;
$rows = isset($_POST[‘rows’]) ? intval($_POST[‘rows’]) : 1000;
$offset = ($page-1)*$rows;
$result = array();
$rs = R::getAll(“select * from table_report_apps $searchargument_start group by store_id,ref_shift_id order by id desc limit $offset,$rows”);
$result[“total”] = count($rs);
$table_stand_amount =0;
$table_stand_amount =0;

foreach($rs as $v)
{
/**GET EMPLOYEE NAME**/

$get_employee= R:: getRow(“select name from employee_names where id =$v[employee_id]”);
$v[“employee_name”] = $get_employee[“name”];

$get_store_name= R:: getRow(“select name from store_names where id=$v[store_id]”);
$v[“store_name”] = $get_store_name[“name”];
$rs_standout = R::getRow(“select *,sum(amount) as amount from table_report_apps where table_type=’standout’ and store_id=$v[store_id] and ref_shift_id= $v[ref_shift_id] order by id desc limit $offset,$rows”);
$standout_amount= isset($rs_standout[“amount”])?$rs_standout[“amount”]:0;

$v[“standout_amount”]=$standout_amount;

$standout_total_amount +=$standout_amount;

$rs_table = R::getRow(“select *,sum(amount) as amount from table_report_apps where table_type=’table’ and store_id=$v[store_id] and ref_shift_id= $v[ref_shift_id] order by id desc limit $offset,$rows”);
$table_amount= isset($rs_table[“amount”])?$rs_table[“amount”]:0;

$v[“table_amount”]=$table_amount;
$new[] =$v;

$table_total_amount +=$table_amount;
}
$result[“rows”] = $new;
$result[“footer”][] = array(“table_amount”=>$table_total_amount,”standout_amount”=>$standout_total_amount);

echo json_encode($result);
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s