$xml = simplexml_load_string($soap_response);if($mode === 'exportQrCode')
    {
        $search_text = trim($_POST['search_text']);
        $trade_type = $_POST['trade_type'];
        $code = trim($_POST['code']);
        $curator = (int)$_POST['curator'];
        $is_active = $_POST['is_active'];
        $where_array = [];
        if (!empty($curator)) {
            $where = " JOIN SS_B2POS.trade_acc_rel AS tr_acc ON v_tr.idtrade = tr_acc.idtrade".$where." AND (tr_acc.idaccount = ? OR tr_acc.idaccount_second = ?)";
            $where_array[] = $curator;
            $where_array[] = $curator;
        }
        if ($trade_type !== "") {
            $where .= "AND idtrade_type=?";
            $where_array[] = $trade_type;
        }
        if (strlen($search_text) > 0) {
            $where .= "AND (city LIKE ? OR street LIKE ? OR v_tr.idtrade=? OR brand LIKE ? OR full_name LIKE ? OR contact_name LIKE ? OR contact_phone LIKE ? OR contact_email LIKE ? OR inet_domain LIKE ? )";
            $where_array[] = "%" . $search_text . "%";
            $where_array[] = "%" . $search_text . "%";
            $where_array[] = $search_text;
            $where_array[] = "%" . $search_text . "%";
            $where_array[] = "%" . $search_text . "%";
            $where_array[] = "%" . $search_text . "%";
            $where_array[] = "%" . $search_text . "%";
            $where_array[] = "%" . $search_text . "%";
            $where_array[] = "%" . $search_text . "%";
        }
        if (strlen($code) > 0) {
            $trades_array = [];
            $sth = $dbh->prepare("SELECT idtrade FROM SS_B2POS.bank_trades WHERE bank_trade = ? GROUP BY idtrade ");
            $sth->execute([$code]);
            while ($trades_in = $sth->fetch()) {
                $trades_array[] = $trades_in['idtrade'];
            }
            if (count($trades_array) == 0) {
                $where .= " AND 2=1";
            } else {
                $trades_in_where = str_repeat("?,", count($trades_array) - 1) . "?";
                $where .= " AND (idtrade IN (" . $trades_in_where . "))";
                $where_array = array_merge($where_array, $trades_array);
            }
        }
        if ($is_active != '') {
            $where .= 'AND v_tr.md_is_activ = ?';
            $where_array[] = $is_active;
        }
        $in_sql = 'SELECT v_tr.idtrade FROM SS_B2POS.v_trade_all v_tr '.$where;
        $sth = $dbh->prepare("SELECT trade_qr_code_file,full_name,city,street,house FROM SS_B2POS.trade_cards trc WHERE trade_qr_code_file IS NOT NULL AND idtrade IN ( ".$in_sql." )");
        $sth->execute($where_array);
        try{
            $nowDate = date('d.m.Y H:i:s');
            $titleZipFile = 'qrCodesTrades_'.$nowDate.'.zip';
            $zipFile = $pathMedia. '/disk/QRCodes/trade_codes/exportQrCodes/'.$titleZipFile;
            $zip = new ZipArchive;
            if($zip->open($zipFile, ZipArchive::CREATE) !== true){
                throw new Exception("Error!");
            }
            while ($code = $sth->fetch()){
                $qrFile = $pathMedia.'/disk/QRCodes/trade_codes/'.substr($code['trade_qr_code_file'], 0, 2).'/'.substr($code['trade_qr_code_file'], 2, 2).'/'.$code['trade_qr_code_file'];
                if(file_exists($qrFile)){
                    $zip->addFile($qrFile, $code['full_name'].','.$code['city'].','.$code['street'].','.$code['house'].'.png');
                }
            }
            $zip->close();
            if(file_exists($zipFile))
            {
                header('Content-Description: File Transfer');
                header('Content-Type: application/octet-stream');
                header('Content-Disposition: attachment; filename="' . basename($zipFile).'"');
                header('Content-Transfer-Encoding: binary');
                header('Expires: 0');
                header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                header('Pragma: public');
                header('Content-Length: ' . filesize($zipFile));
                ob_clean();
                flush();
                readfile($zipFile);
            }
        }catch (Exception $e){
            echo $e->getMessage();
        }
    }$zip = new ZipArchive;
            if($zip->open($zipFile, ZipArchive::CREATE) !== true){
                throw new Exception("Error!");
            }
            while ($code = $sth->fetch()){
                $qrFile = $path_web_st.'/disk/QRCodes/trade_codes/'.substr($code['trade_qr_code_file'], 0, 2).'/'.substr($code['trade_qr_code_file'], 2, 2).'/'.$code['trade_qr_code_file'];
                //die(print_r(file_exists('https://st.ghk.dev.b2pos.ru/disk/QRCodes/trade_codes/b7/cd/b7cdfadcc37f57274201f34ad3534eb7-575bfa75043c3d00872bc5e282014303421101.png')));
                    $zip->addFile('https://st.ghk.dev.b2pos.ru/disk/QRCodes/trade_codes/b7/cd/b7cdfadcc37f57274201f34ad3534eb7-575bfa75043c3d00872bc5e282014303421101.png', $code['full_name'].','.$code['city'].','.$code['street'].','.$code['house'].'.png');
            }
            $zip->close();