#!/usr/bin/perl

#use utf8;
use strict;
use CGI;
use POSIX qw(
    ceil
);

use Opals::Context;
use Date::Calc qw(Day_of_Week Week_Number Day_of_Year);

use Opals::User qw(
    user_getInformation
);
use Opals::MarcXml qw(
    mxml_delete
);
use Opals::Date qw(
    date_parse
    date_today
    date_text
    date_f005
);
use Opals::Template qw(
    tmpl_read
    tmpl_write
    tmpl_rangedPageList
);
use Opals::Locale qw(
    loc_getMsgFile
    loc_write
);
use JSON;

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

my $cgi = CGI->new;
my $input = $cgi->Vars();
my $type= $input->{'type'};
$type="circTrans"  if($type eq "");
my ($permission, $cookie, $template) = tmpl_read(
        {
            dbh             => $dbh,
            cgi             => $cgi,
            tmplFile        => 'report/circTrans.tmpl',
            reqPermission   => 'rpt_notice|rpt_catRec',
        }
);

$template->param(hlpUrl     => Opals::Constant->getHlpUrl('itemdel') );
   
    my $dateToday = date_f005();
    $dateToday =~ s/([\d]{4})([\d]{2})([\d]{2})[\d]+\.(0|1)/$1-$2-$3/;
     $template->param(todayStr => $dateToday,type=>$type);




my $msgValMap ={};
my $msgMap            =loc_getMsgFile('report/reports.msg',$msgValMap);
my $rptTitleMsgMap={
    circ=>"circTransRptTxt",
    hold=>"holdTransRptTxt",
    itemRecord=>"itemRecordRptTxt"
};
my $reportTitle=$msgMap->{$rptTitleMsgMap->{$type}};

my $itemTypeList=[];
my $sth = $dbh->prepare("select id type from opl_itemType where itemCategory=1");
$sth->execute();
while( my $itemType=$sth->fetchrow_hashref){
    push @$itemTypeList,$itemType;
}
$template->param(reportTitle=>$reportTitle,itemTypeList=>to_json($itemTypeList));
loc_write($template,$msgMap);

tmpl_write($dbh, $cgi, $cookie, $template);
#$dbh->disconnect();

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

