function main_iteration($data)
{
    $match_by = $_SESSION['match'];
    $dup_status = '';
    $item = $data[0];
    $item_name = $data[1];
    $item_upc = $data[2];
    $mfg_name = $data[3];
    $item_namedb = htmlspecialchars($data[1], ENT_QUOTES);
    $mfg_namedb = htmlspecialchars($data[3], ENT_QUOTES);
    $pos_item_number = $data[4];
    $price = $data[5];
    @($stock = $data[6]);
    $no_match = "NO MATCH";
    $grade = 0;
    $import_status = 'N';
    $dup_field = '';
    $check = "<input type='checkbox' class='check' name='upload'>";
    // get mfg code here
    $mfg_code = get_mfg_code($mfg_name);
    if ($match_by == 'both') {
        match_pos_mfg($data, $mfg_code);
    } elseif ($mfg_code != 'NO MATCH' && $pos_item_number != '' && $match_by == 'sku') {
        match_pos_mfg($data, $mfg_code);
    } elseif ($data[2] != '0' && $match_by == 'upc' && ($data[2] != '' && $match_by == 'upc')) {
        // check by UPC, ISBN and EAN
        match_pos_upc($data, $item_upc, $mfg_code);
    } else {
        /* if both UPC and MFG ITEM NUMBER are empty in imported csv */
        if ($data[0] != '' && $data[0] != '0') {
            // condition check empty row in csv
            $mfg_show = get_mfg_name($mfg_code);
            $insert_values = array($item, $item_namedb, $item_upc, $mfg_namedb, $pos_item_number, $price, $stock, $mfg_show, $no_match, $grade, $dup_status, $import_status, $dup_field);
            insert_results_indb($insert_values, $import_status);
        }
    }
}
function match_pos_upc($data, $item_upc, $mfg_code)
{
    global $dbs, $pdo;
    $csvupc = check_csvupc_matchby_both($item_upc);
    $stn_sku = stn_sku($mfg_code, $data[0], $data[4]);
    $item_upc = $data[2];
    $item_namedb = htmlspecialchars($data[1], ENT_QUOTES);
    $mfg_namedb = htmlspecialchars($data[3], ENT_QUOTES);
    $no_match = "NO MATCH";
    $dup_field = '';
    $dup_status = '';
    $grade = 0;
    $import = 'N';
    if ($csvupc != 'no') {
        $prod_code = $csvupc;
        $csvupc = strtoupper(substr($prod_code, 8));
        $query = "SELECT\r\n\t\t\t\t\tproduct_sku, stn_sku, product_name,\r\n\t\t\t\t\tproduct_upc, product_isbn, product_ean, mfg_id\r\n\t\t\t\t\tFROM stn_products \r\n\t\t\t\t\tWHERE {$prod_code}=:item_upc\r\n\t\t\t\t ";
        $query_both = $dbs->prepare($query);
        $query_both->bindParam(":item_upc", $item_upc, PDO::PARAM_STR);
        $query_both->execute();
        $count = $query_both->rowCount();
        if ($count > 1) {
            $elements = $query_both->fetchALL(PDO::FETCH_ASSOC);
            get_matchup_results_both($data, $elements, $stn_sku, $csvupc);
        } else {
            $elements = $query_both->fetch(PDO::FETCH_ASSOC);
            get_matchup_result_both($data, $elements, $stn_sku, $csvupc);
        }
    } elseif ($csvupc == 'no' && $item_upc[0] == '0') {
        $item_upc = ltrim($item_upc, '0');
        $csvupc = check_trimmedcsvupc_matchby_both($item_upc);
        if ($csvupc != 'no') {
            $prod_code = $csvupc;
            $csvupc = strtoupper(substr($prod_code, 8));
            $item_upc = "%{$item_upc}";
            $query = "SELECT \r\n\t\t\t\t\t\tproduct_sku, stn_sku, product_name, product_upc,\r\n\t\t\t\t\t\tproduct_isbn, product_ean, mfg_id\r\n\t\t\t\t\t\tFROM stn_products\r\n\t\t\t\t\t\tWHERE {$prod_code} LIKE :item_upc\r\n\t\t\t\t\t ";
            $query_both = $dbs->prepare($query);
            $query_both->bindParam(":item_upc", $item_upc, PDO::PARAM_STR);
            $query_both->execute();
            $count = $query_both->rowCount();
            if ($count > 1) {
                $elements = $query_both->fetchALL(PDO::FETCH_ASSOC);
                get_matchup_results_both($data, $elements, $stn_sku, $csvupc);
            } else {
                $elements = $query_both->fetch(PDO::FETCH_ASSOC);
                get_matchup_result_both($data, $elements, $stn_sku, $csvupc);
            }
        } else {
            $mfg_show = get_mfg_name($mfg_code);
            $insert_values = array($data[0], $item_namedb, $data[2], $mfg_namedb, $data[4], $data[5], $data[6], $mfg_show, $no_match, $grade, $dup_status, $import, $dup_field);
            insert_results_indb($insert_values, $import);
        }
    } else {
        $mfg_show = get_mfg_name($mfg_code);
        $insert_values = array($data[0], $item_namedb, $data[2], $mfg_namedb, $data[4], $data[5], $data[6], $mfg_show, $no_match, $grade, $dup_status, $import, $dup_field);
        insert_results_indb($insert_values, $import);
    }
}