#!/usr/bin/perl 

use lib "/www/opals/module";
use Opals::Context("/etc/opals/conf/ztest");


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

$| = 1;
# Codes start...


my $totalTBItem = findAllTextBookfromLib($dbh, "Textbook");
print "Total Textbook Item: \t" ,  $totalTBItem, "\n";







# Codes end.

sub findAllTextBookfromLib {

    my ($dbh,$typeId) = @_;
    my $sth = $dbh->prepare(<<_STH_);
select count(*) from opl_item I inner join opl_marcRecord R using (rid) where
I.typeId regexp '?' && barcode not regexp '_' && R.deleted = '0';
_STH_
    $sth->execute($typeId);
    my $count = $sth->fetchrow_array;
    if (! $count){
        return 0;
    }
    return $count;
}




exit 0;

################################################################################
