#!/usr/bin/perl

#use utf8;
use strict;
use CGI;
use Digest::SHA qw(
    sha1_base64
    sha1_hex
);

use Opals::Context;
use Opals::Template qw(
    tmpl_read
    tmpl_write
    tmpl_preference
);

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

my $cgi      = CGI->new;
my $input    = $cgi->Vars();
my $lidList       = $input->{"lidList"};


my ($status,$errorCode,$errorMsg)    ;
my ($permission, $cookie, $template) = tmpl_read(
    {
        dbh             => $dbh,
        cgi             => $cgi,
        tmplFile        => '/txtbk/ajax/circ/fineInfo.tmpl',
        reqPermission   => 'tb_circ_loan|tb_circ_return',
    }
);
if ($permission && ($permission->{'tb_circ_loan'}|| $permission->{'tb_circ_return'})) {
    my @fineList =fine_getFineList($dbh,$lidList);
    foreach my $fine(@fineList){
        my $fa=$fine->{'fineInfo'};
        foreach my $f(@$fa){
            my $type =$f->{'type'};
            $fine->{"$type" . "_odlId"}=$f->{'odl_id'};
            if($type eq 'overdue'){
                $fine->{"daysOverdue"}=$f->{'daysOverdue'};
            }
        }
    }
    $template->param(fineList => \@fineList);
}
 
tmpl_write($dbh, $cgi, $cookie, $template);
#------------------------------------------------------------------------------
