$value) { // Iterate over each search condition foreach ($search as $k => $v) { // If the array element does not meet the search condition then continue to the next element if (!isset($value[$k]) || $value[$k] != $v) { continue 2; } } // Add the array element's key to the result array $result[] = $key; } // Return the result array return $result; } $json = file_get_contents('php://input'); $data = json_decode($json); $sql = "SELECT a.ID, a.NAME, a.PERIOD, a.CURRENCY_CODE, a.PRODUCT_ATTR_VALUE, a.CATEGORY_ID, a.DESCRIPTION ITEM_DESCRIPTION, a.SKU_SIZE, NVL(a.SIZE_NM,'-') SIZE_NM, NVL(a.BRAND,'-') BRAND, a.PRODUCT_UOM_CODE, a.CUSTOMER_ID, a.CUSTOMER_NAME, a.VOLUME, a.NEW_PRICE, a.BILL_TO, a.SHIP_TO, NVL(a.COMMENTS,'-') COMMENTS, CASE a.APPROVAL_FLAG WHEN 'A' THEN 'Approved' WHEN 'R' THEN 'Rejected' WHEN 'P' THEN 'In Progress' ELSE null END Status, b.employee_name as CREATED_BY, to_char(to_date(a.period,'MON-RR')-1,'MON-RR') prev_period FROM apps.YTY_G_PRC_MODIFIER_LIST_TL a, production.employee_master b WHERE a.created_by = b.emp_id AND a.id = :price_id"; $sqlarr = oci_parse($dbcon , $sql); oci_bind_by_name($sqlarr, ':price_id', $data->price_id); $r = oci_execute($sqlarr); if (!$r) { $e = oci_error($sqlarr); $resMsg = json_encode($e['message']); } oci_fetch_all($sqlarr, $rows_main, null, null, OCI_FETCHSTATEMENT_BY_ROW); //Number $rows_main[0]["VOLUME"] = (float)$rows_main[0]["VOLUME"]; $rows_main[0]["NEW_PRICE"] = (float)$rows_main[0]["NEW_PRICE"]; $sql = "SELECT to_char(new_price) prev_price, (to_number(:p_price) - new_price) diff_price, CASE WHEN (to_number(:p_price) - new_price) > 0 THEN '+' || rtrim(to_char((to_number(:p_price) - new_price), 'FM90.99'), '.') || '' WHEN (to_number(:p_price) - new_price) < 0 THEN '' || rtrim(to_char((to_number(:p_price) - new_price), 'FM90.99'), '.') || '' END html_diff_price, product_attr_value, NVL(size_nm,'-') size_nm, NVL(brand,'-') brand, currency_code, period FROM apps.YTY_G_PRC_MODIFIER_LIST_TL WHERE currency_code = :p_currency AND customer_id = :p_custid AND product_attr_value = :p_sku AND NVL(approval_flag, 'N') = 'A' UNION SELECT '-',null,null,'-','-','-',null,'-' FROM DUAL WHERE NOT EXISTS ( SELECT to_char(new_price) prev_price, (to_number(:p_price) - new_price) diff_price, CASE WHEN (to_number(:p_price) - new_price) > 0 THEN '+' || rtrim(to_char((to_number(:p_price) - new_price), 'FM90.99'), '.') || '' WHEN (to_number(:p_price) - new_price) < 0 THEN '' || rtrim(to_char((to_number(:p_price) - new_price), 'FM90.99'), '.') || '' END html_diff_price, product_attr_value, NVL(size_nm,'-') size_nm, NVL(brand,'-') brand, currency_code, period FROM apps.YTY_G_PRC_MODIFIER_LIST_TL WHERE currency_code = :p_currency AND customer_id = :p_custid AND product_attr_value = :p_sku AND NVL(approval_flag, 'N') = 'A')"; $sqlarr = oci_parse($dbcon , $sql); oci_bind_by_name($sqlarr, ':p_currency', $rows_main[0]["CURRENCY_CODE"]); oci_bind_by_name($sqlarr, ':p_custid', $rows_main[0]["CUSTOMER_ID"]); oci_bind_by_name($sqlarr, ':p_sku', $rows_main[0]["PRODUCT_ATTR_VALUE"]); oci_bind_by_name($sqlarr, ':p_price', $rows_main[0]["NEW_PRICE"]); $r = oci_execute($sqlarr); if (!$r) { $e = oci_error($sqlarr); $resMsg = json_encode($e['message']); } oci_fetch_all($sqlarr, $rows_hist, null, null, OCI_FETCHSTATEMENT_BY_ROW); if (count($rows_hist) > 0) { $rows_prev = $rows_hist; //Filter Exactly foreach($rows_prev as $sub) { if($sub["SIZE_NM"] == $rows_main[0]["SIZE_NM"] && $sub["BRAND"] == $rows_main[0]["BRAND"]) { $exact_prev[] = $sub; } } if (count($exact_prev) == 0) { //Filter with matching size only foreach($rows_prev as $sub) { if($sub["SIZE_NM"] == $rows_main[0]["SIZE_NM"] || $sub["SIZE_NM"] == "-") { $size_prev[] = $sub; } } if (count($size_prev) > 0) { $rows_prev = $size_prev; } //From the result filter again by brand if (count($rows_prev) > 1) { foreach($rows_prev as $sub) { if($sub["BRAND"] == $rows_main[0]["BRAND"] || $sub["BRAND"] == "-") { $brand_prev[] = $sub; } } if (count($brand_prev) > 0) { $rows_prev = $brand_prev; } } } else { $rows_prev = $exact_prev; } } if (count($rows_hist) > 5) { for ($i = 5; $i "-", "CURRENCY_CODE" => null, "DIFF_PRICE" => null, "HTML_DIFF_PRICE" => "-", "SIZE_NM" => "-", "PERIOD" => "-", "PREV_PRICE" => null, "PRODUCT_ATTR_VALUE" => "-" ); } } $keyindx = (multi_array_search($rows_hist, array('PRODUCT_ATTR_VALUE' => $rows_prev[0]["PRODUCT_ATTR_VALUE"], 'SIZE_NM' => $rows_prev[0]["SIZE_NM"], 'BRAND' => $rows_prev[0]["BRAND"]))); $result[] = [ "message" => $resMsg, "data" => $rows_main, "prev" => $rows_prev, "hist" => $rows_hist, "keyidx" => $keyindx ]; print json_encode($result); ?>