0 and id not in (select item_stock_id from cleanup_item_stock) and expiry_date != '0000-00-00' and DATE(expiry_date)<= (CURDATE() + INTERVAL $expiryAlertAdvance DAY ) $searchSql "; error_log("COUNTING QUERY::" . $sql); // echo $sql; $result = mysqli_query($conn, $sql); // echo $result; $row = mysqli_fetch_array($result); $total = $row[0]; if (!isset($rp)) { $rp = 10; } // Setup paging SQL // $rp=1; $pageStart = ($page - 1) * $rp; $limitSql = "limit $pageStart, $rp"; // Return JSON data $data = array(); $data['page'] = $page; $data['total'] = $total; $data['rows'] = array(); $count = 1; $sql_pending_expiry = "select * from item_stock_miscellaneous where issue_to_ohc_id='" . $ohc_loc . "' and stock_qty>0 and id not in (select item_stock_id from cleanup_item_stock) and expiry_date != '0000-00-00' and DATE(expiry_date)<= (CURDATE() + INTERVAL $expiryAlertAdvance DAY )"; error_log("PENDING EXPIRY QUERY::" . $sql_pending_expiry); $sql_export = $sql_pending_expiry; $sql_pending_expiry .= " $searchSql $sortSql $limitSql "; $sql_export .= " $searchSql $sortSql "; $results_pending_expiry = mysqli_query($conn, $sql_pending_expiry); $view_link = ""; $edit_link = ""; $delete_link = ""; $links = ""; while ($row_pending_expiry = mysqli_fetch_assoc($results_pending_expiry)) { $id = $row_pending_expiry['id']; $item_id = $row_pending_expiry['item_id']; $item_desc = getItemWithFormName($row_pending_expiry['item_id']); $item_qty = $row_pending_expiry['stock_qty']; $item_batch = $row_pending_expiry['item_batch_no']; $procurement_qty_query = "select sum(a.issue_qty) from stock_issue_items a left join stock_issue b on a.stock_issue_id=b.stock_issue_id where a.item_id=" . $item_id . " and a.item_batch_no='" . $item_batch . "' and b.ohc_location_id='" . $ohc_loc . "' "; error_log("CONSUMPTION QUERY::" . $procurement_qty_query); $results_qty_query = mysqli_query($conn, $procurement_qty_query); $row_procurement_qty = mysqli_fetch_row($results_qty_query); $procurement_qty = $row_procurement_qty[0]; $item_expiry_date = date_format(date_create($row_pending_expiry['expiry_date']), "M-Y "); if ($access_level == 'W' || $access_level == 'E') { $edit_link = ""; } $space = "   "; $links = $space . $edit_link; $data['rows'][] = array( 'id' => $row1['id'], 'cell' => array( $count++, $item_desc, $procurement_qty, $procurement_qty - $item_qty, $item_qty, $item_batch, $item_expiry_date, $links ) ); } $data['rows'][] = array( 'id' => $row['filterkey'], 'cell' => array('', "", "", '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '') ); echo json_encode($data); ?>