def deleteSample(self, barcode, ag_login_id):
        """ Removes by either releasing barcode back for relogging or withdraw

        Parameters
        ----------
        barcode : str
            Barcode to delete
        ag_login_id : UUID4
            Login ID for the barcode

        Notes
        -----
        Strictly speaking the ag_login_id isn't needed but it makes it really
        hard to hack the function when you would need to know someone else's
        login id (a GUID) to delete something maliciously.

        If the barcode has never been scanned, assume a mis-log and wipe it so
        barcode can be logged again. If barcode has been scanned, that means we
        have recieved it and must withdraw it to delete it from the system.
        """
        with TRN:
            # Figure out if we've received the barcode or not
            sql = "SELECT scan_date FROM barcode WHERE barcode = %s"
            TRN.add(sql, [barcode])
            received = TRN.execute_fetchlast()

            if not received:
                # Not recieved, so we release the barcode back to be relogged
                set_text = """site_sampled = NULL,
                             sample_time = NULL, sample_date = NULL,
                             environment_sampled = NULL, notes = NULL"""
                sql = "UPDATE barcode SET status = NULL WHERE barcode = %s"
                TRN.add(sql, [barcode])
            else:
                # barcode already recieved, so we withdraw the barcode
                set_text = "withdrawn = 'Y'"

            sql = """UPDATE ag_kit_barcodes
                     SET {}
                     WHERE barcode IN (
                     SELECT  akb.barcode
                        FROM ag_kit_barcodes akb
                        INNER JOIN ag_kit ak USING (ag_kit_id)
                        WHERE ak.ag_login_id = %s
                        AND akb.barcode = %s)""".format(set_text)
            TRN.add(sql, [ag_login_id, barcode])

            sql = """DELETE FROM ag.source_barcodes_surveys
                     WHERE barcode = %s"""
            TRN.add(sql, [barcode])