-my $sth2 = $dbh->prepare("
- SELECT issuingrules.*,
- itemtypes.description AS humanitemtype,
- categories.description AS humancategorycode,
- COALESCE( localization.translation, itemtypes.description ) AS translated_description
- FROM issuingrules
- LEFT JOIN itemtypes
- ON (itemtypes.itemtype = issuingrules.itemtype)
- LEFT JOIN categories
- ON (categories.categorycode = issuingrules.categorycode)
- LEFT JOIN localization ON issuingrules.itemtype = localization.code
- AND localization.entity = 'itemtypes'
- AND localization.lang = ?
- WHERE issuingrules.branchcode = ?
-");
-$sth2->execute($language, $branch);
-
-while (my $row = $sth2->fetchrow_hashref) {
- $row->{'current_branch'} ||= $row->{'branchcode'};
- $row->{humanitemtype} ||= $row->{itemtype};
- $row->{default_translated_description} = 1 if $row->{humanitemtype} eq '*';
- $row->{'humancategorycode'} ||= $row->{'categorycode'};
- $row->{'default_humancategorycode'} = 1 if $row->{'humancategorycode'} eq '*';
- $row->{'fine'} = sprintf('%.2f', $row->{'fine'});
- if ($row->{'hardduedate'} && $row->{'hardduedate'} ne '0000-00-00') {
- my $harddue_dt = eval { dt_from_string( $row->{'hardduedate'} ) };
- $row->{'hardduedate'} = eval { output_pref( { dt => $harddue_dt, dateonly => 1 } ) } if ( $harddue_dt );
- $row->{'hardduedatebefore'} = 1 if ($row->{'hardduedatecompare'} == -1);
- $row->{'hardduedateexact'} = 1 if ($row->{'hardduedatecompare'} == 0);
- $row->{'hardduedateafter'} = 1 if ($row->{'hardduedatecompare'} == 1);
- } else {
- $row->{'hardduedate'} = 0;
- }
- if ($row->{no_auto_renewal_after_hard_limit}) {
- my $dt = eval { dt_from_string( $row->{no_auto_renewal_after_hard_limit} ) };
- $row->{no_auto_renewal_after_hard_limit} = eval { output_pref( { dt => $dt, dateonly => 1 } ) } if $dt;
- }
-
- push @row_loop, $row;
-}
-
-my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
-
-my $sth_branch_cat;
-if ($branch eq "*") {
- $sth_branch_cat = $dbh->prepare("
- SELECT default_borrower_circ_rules.*, categories.description AS humancategorycode
- FROM default_borrower_circ_rules
- JOIN categories USING (categorycode)
-
- ");
- $sth_branch_cat->execute();
-} else {
- $sth_branch_cat = $dbh->prepare("
- SELECT branch_borrower_circ_rules.*, categories.description AS humancategorycode
- FROM branch_borrower_circ_rules
- JOIN categories USING (categorycode)
- WHERE branch_borrower_circ_rules.branchcode = ?
- ");
- $sth_branch_cat->execute($branch);
-}
-
-my @branch_cat_rules = ();
-while (my $row = $sth_branch_cat->fetchrow_hashref) {
- push @branch_cat_rules, $row;
-}
-my @sorted_branch_cat_rules = sort { $a->{'humancategorycode'} cmp $b->{'humancategorycode'} } @branch_cat_rules;
-
-# note undef maxissueqty so that template can deal with them
-foreach my $entry (@sorted_branch_cat_rules, @sorted_row_loop) {
- $entry->{unlimited_maxissueqty} = 1 unless defined($entry->{maxissueqty});
- $entry->{unlimited_maxonsiteissueqty} = 1 unless defined($entry->{maxonsiteissueqty});
- $entry->{unlimited_max_holds} = 1 unless defined($entry->{max_holds});
-}