#!/usr/bin/perl -w

use lib "/www/opals/module";
use Opals::Context("/etc/opals/conf/_SITECODE_");
use Opals::MarcXml qw(
    mxml_del_rec_holding
);

use strict;
my $dbh = Opals::Context->dbh();;
END {
    if ($dbh) {
        $dbh->disconnect();
    }
}

$| = 1;
# Codes start...

my $rid_bc = getAllTmpBarcode($dbh);
mxml_del_rec_holding($dbh, $rid_bc, 0);

# Codes end.

exit 0;
################################################################################

sub getAllTmpBarcode {
    my ($dbh) = @_;
    my $sql = <<_SQL_;
select rid, barcode
from   opl_item
where  barcode regexp '^TMP_'       
_SQL_

    my $sth = $dbh->prepare($sql);
    $sth->execute();

    my $h;
    while (my $rec = $sth->fetchrow_hashref) {
        $h->{$rec->{'rid'}}->{$rec->{'barcode'}} = 1;
    }
    $sth->finish;

    return $h;
}
############################################################
