public function GetMaxNumberOfShopReviewMailsToSend($iSendForShippingDateNewerThan)
    {
        if ($this->bDebug) {
            echo '<br><br>';
        }

        $query = "SELECT *
                  FROM `shop_order`
                 WHERE `shop_order`.`pkg_shop_rating_service_order_completely_shipped` > '0000-00-00 00:00:00'
                   AND `shop_order`.`shop_id` = '".MySqlLegacySupport::getInstance()->real_escape_string($this->sShopID)."'
                   AND `shop_order`.`cms_language_id` = '".MySqlLegacySupport::getInstance()->real_escape_string($this->sLanguageID)."'
                   AND `shop_order`.`pkg_shop_rating_service_order_completely_shipped` <= '".MySqlLegacySupport::getInstance()->real_escape_string(date('Y-m-d H:i:s', $iSendForShippingDateNewerThan))."'
                   AND `shop_order`.`pkg_shop_rating_service_rating_processed_on` = '0000-00-00 00:00:00'
                   AND `shop_order`.`pkg_shop_rating_service_mail_processed` = '0'
                   AND `shop_order`.`adr_billing_country_id` = '".MySqlLegacySupport::getInstance()->real_escape_string($this->sUserCountryID)."'
               ";
        if ($this->SendCustomersMailOnlyOnce()) {
            $query .= 'GROUP BY `shop_order`.`customer_number`';
        }

        if ($this->bDebug) {
            echo __LINE__.': '.$query."\n<br />\n";
        }

        $rRow = MySqlLegacySupport::getInstance()->query($query);
        $iNumberOfCompletedOrders = MySqlLegacySupport::getInstance()->num_rows($rRow);

        $query = ' SELECT * FROM `pkg_shop_rating_service_history` ';
        if ($this->SendCustomersMailOnlyOnce()) {
            $query .= 'GROUP BY `pkg_shop_rating_service_history`.`data_extranet_user_id`';
        }

        if ($this->bDebug) {
            echo __LINE__.': '.$query."\n<br />\n";
        }

        $rRow = MySqlLegacySupport::getInstance()->query($query);
        $iNumberOfReviewMailsSend = MySqlLegacySupport::getInstance()->num_rows($rRow);
        $iPercentageToBeSend = $this->Shopreviewmail_PercentOfCustomers; //$this->GetConfigValue('shopreviewmail_percent_of_customers');;
        $iPercentageMailSend = 100;

        if (0 == $iNumberOfCompletedOrders && 0 == $iNumberOfReviewMailsSend) {
            $iPercentageMailSend = 100;
        } elseif ($iNumberOfCompletedOrders > 0) {
            $iPercentageMailSend = ($iNumberOfReviewMailsSend / $iNumberOfCompletedOrders) * 100;
        } else {
            $iPercentageMailSend = 0;
        }

        if ($this->bDebug) {
            echo '<br />';
        }
        if ($this->bDebug) {
            echo __LINE__.'iPercentageToBeSend: '.$iPercentageToBeSend."\n<br />\n";
        }
        if ($this->bDebug) {
            echo __LINE__.'iNumberOfCompletedOrders: '.$iNumberOfCompletedOrders."\n<br />\n";
        }

        $iNumberOfReviewMailsToBeSend = ceil(($iPercentageToBeSend / 100) * $iNumberOfCompletedOrders);

        if ($this->bDebug) {
            echo __LINE__.'iNumberOfReviewMailsToBeSend: '.$iNumberOfReviewMailsToBeSend."\n<br />\n";
        }
        if ($this->bDebug) {
            echo __LINE__.'iNumberOfReviewMailsSend: '.$iNumberOfReviewMailsSend."\n<br />\n";
        }
        echo '<br><br>';

        // NOTE: the total possible mails covers all orders that have been send out
        // (so it includes orders which had their expected order date passed - Frau sommer 25.11.08)
        return $iNumberOfReviewMailsToBeSend;
    }