<?php if (!isset($_SESSION)) {
@session_start();
}
?>
<?php include('../Connections/conndb.php');
$strSQL = "SELECT * FROM employee WHERE Eusername = '".$_SESSION['Eusername']."' AND Edepart = '".$_SESSION['Edepart']."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
$employee = $objResult['Eid'];
/* Database connection start */
$servername = "localhost";
$username = "root";
$password = "4321";
$dbname = "salecentral";
$conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());
mysqli_set_charset($conn,"utf8");
/* Database connection end */
// storing request (ie, get/post) global array to a variable
$requestData= $_REQUEST;
$columns = array(
// datatable column index => database column name
0 =>'checkPO',
1 =>'Sadate',
2 =>'Sacode',
3 =>'name_partner',
4 => 'contactby'
);
// getting total number records without any search
$sql = "SELECT checkPO,Sadate, Sacode, name_partner, contactby, nickname";
$sql.=" FROM sale,employee,partner,contact where sale.id_contact=contact.id_contact AND sale.Eid=employee.Eid AND sale.id_partner=partner.id_partner";
$sql.=" UNION ALL SELECT checkPO,Sadate, Sacode, name_partner, contactby, nickname";
$sql.=" FROM cc_edit_sale,employee,partner,contact where cc_edit_sale.id_contact=contact.id_contact AND cc_edit_sale.Eid=employee.Eid AND cc_edit_sale.id_partner=partner.id_partner";
$query=mysqli_query($conn, $sql) or die("preCC-grid-data.php: get error");
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData; // when there is no search parameter then total number rows = total number filtered rows.
$sql = "SELECT checkPO,Sadate, Sacode, name_partner, contactby, nickname";
$sql.=" FROM sale,employee,partner,contact where sale.id_contact=contact.id_contact AND sale.Eid=employee.Eid AND sale.id_partner=partner.id_partner";
$sql.=" UNION ALL SELECT checkPO,Sadate, Sacode, name_partner, contactby, nickname";
$sql.=" FROM cc_edit_sale,employee,partner,contact where cc_edit_sale.id_contact=contact.id_contact AND cc_edit_sale.Eid=employee.Eid AND cc_edit_sale.id_partner=partner.id_partner AND 1=1";
if( !empty($requestData['search']['value']) ) { // if there is a search parameter, $requestData['search']['value'] contains search parameter
$sql.=" AND ( checkPO LIKE '%".$requestData['search']['value']."%' ";
$sql.=" OR Sadate LIKE '%".$requestData['search']['value']."%' ";
$sql.=" OR Sacode LIKE '%".$requestData['search']['value']."%' ";
$sql.=" OR name_partner LIKE '%".$requestData['search']['value']."%' ";
$sql.=" OR contactby LIKE '%".$requestData['search']['value']."%' )";
}
$query=mysqli_query($conn, $sql) or die("preCC-grid-data.php: get error");
$totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result.
$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length']." ";
/* $requestData['order'][0]['column'] contains colmun index, $requestData['order'][0]['dir'] contains order such as asc/desc */
$query=mysqli_query($conn, $sql) or die("preCC-grid-data.php: get error");
$data = array();
while( $row=mysqli_fetch_array($query) ) { // preparing an array
//$idPO= $row["idPO"];
$nestedData=array();
if ($_SESSION['Eusername']== "cw03" || ($_SESSION['Eusername']== "cc62") || ($_SESSION['Eusername']== "cc44") ||$_SESSION['Edepart']== "reader")
{
if( strpos( $row["Sacode"], "Rev" )) {
if ($row['checkPO']=='1') {
$nestedData[] = "<a href='checkPO_CC_edit.php?idx=$row[Sacode]'><img src='../images/icon_correct.gif'/></a>";
}
else {
$nestedData[] = "<a href='checkPO_CC_edit.php?idx=$row[Sacode]'><img src='../images/icon_wrong.gif'/></a>";
}
}
else {
if ($row['checkPO']=='1') {
$nestedData[] = "<a href='checkPO_CC.php?idx=$row[Sacode]'><img src='../images/icon_correct.gif'/></a>";
}
else {
$nestedData[] = "<a href='checkPO_CC.php?idx=$row[Sacode]'><img src='../images/icon_wrong.gif'/></a>";
}
}
}
else {
if ($row['checkPO']=='1'){ $nestedData[] = "<img src='../images/icon_correct.gif'/>";} else { $nestedData[] = "<img src='../images/icon_wrong.gif'/>";}
}
/*if($row['checkPO']=='1') { $nestedData[] = "<a href='checkPO_CC_edit.php?idx=$row[Sacode]'><img src='../images/icon_correct.gif'/></a>";}
if($row['checkPO']=='0') { $nestedData[] = "<img src='../images/icon_wrong.gif'/>";} */
list($Year,$month,$day) = explode("-",$row['Sadate']);
$nestedData[] = (int)$day."/".(int)$month."/".($Year);
$nestedData[] = $row["Sacode"];
$nestedData[] = $row["name_partner"];
$nestedData[] = $row["contactby"]."(".$row["nickname"].")";
$nestedData[] = "<a href='editQuotationCC-before.php?idx=$row[Sacode]' target='_self'><img src='../images/edit.png' width='30' title='แก้ไข' border='0' ></a><a class='example1' href='viewCC.php?idx=$row[Sacode]'><img src='../images/search.png' width='30' title='ดูใบเสนอราคา' border='0' ></a><a href='printCC.php?idx=$row[Sacode]'><img src='../images/print.png' width='30' title='พิมพ์ใบเสนอราคา' border='0' onClick='return Conf(this)' ></a>";
$data[] = $nestedData;
}
$json_data = array(
"draw" => intval( $requestData['draw'] ), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw.
"recordsTotal" => intval( $totalData ), // total number of records
"recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
"data" => $data // total data array
);
echo json_encode($json_data); // send data as json format
?>