private function deductionForDeletion($connection, $tableName, $documentType, $documentId, $shopId)
    {
        $sql = sprintf(
            "SELECT `id` FROM {$tableName}
            WHERE
                `type` != 'D'
                AND `document_type` = :documentType
                AND `document_id` = :documentId
                AND `status` = :status
                AND `id` < :id"
        );

        $statement = $connection->prepare($sql);
        $statement->execute(
            [
                'documentType' => $documentType,
                'documentId' => $documentId,
                'status' => self::STATUS_NEW,
                'id' => $connection->lastInsertId(),
            ]
        );

        $entries = $statement->fetchAll();

        foreach ($entries as $entry) {
            $this->removeRecord($entry['id'], [$shopId]);
        }
    }