Merge remote-tracking branch 'origin/new/bug_8597'
authorPaul Poulain <paul.poulain@biblibre.com>
Wed, 19 Sep 2012 09:43:04 +0000 (11:43 +0200)
committerPaul Poulain <paul.poulain@biblibre.com>
Wed, 19 Sep 2012 09:43:04 +0000 (11:43 +0200)
54 files changed:
C4/Acquisition.pm
C4/Biblio.pm
C4/Budgets.pm
C4/Circulation.pm
C4/Reports/Guided.pm
C4/SIP/ILS/Transaction/Checkout.pm
C4/Search.pm
C4/Serials.pm
acqui/addorderiso2709.pl
acqui/finishreceive.pl
acqui/invoice.pl [new file with mode: 0755]
acqui/invoices.pl [new file with mode: 0755]
acqui/orderreceive.pl
acqui/parcel.pl
acqui/parcels.pl
acqui/spent.pl
admin/authorised_values.pl
catalogue/moredetail.pl
installer/data/mysql/kohastructure.sql
installer/data/mysql/sysprefs.sql
installer/data/mysql/updatedatabase.pl
koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-menu.inc
koha-tmpl/intranet-tmpl/prog/en/includes/biblio-view-menu.inc
koha-tmpl/intranet-tmpl/prog/en/includes/search_indexes.inc
koha-tmpl/intranet-tmpl/prog/en/includes/serials-search.inc
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt [new file with mode: 0644]
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt [new file with mode: 0644]
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcels.tt
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/spent.tt
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt
koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt
koha-tmpl/intranet-tmpl/prog/en/modules/reports/dictionary.tt
koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt
koha-tmpl/intranet-tmpl/prog/en/modules/serials/serial-issues.tt
koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-home.tt
koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt [new file with mode: 0644]
koha-tmpl/opac-tmpl/prog/en/css/opac.css
koha-tmpl/opac-tmpl/prog/en/modules/opac-advsearch.tt
koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt
koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACDetail.xsl
koha-tmpl/opac-tmpl/prog/en/xslt/NORMARCslim2OPACDetail.xsl
kohaversion.pl
misc/cronjobs/runreport.pl
opac/svc/report
reports/dictionary.pl
reports/guided_reports.pl
serials/serials-home.pl
serials/serials-search.pl [new file with mode: 0755]
svc/report
t/db_dependent/Search.t

index 21e7640..03a55cc 100644 (file)
@@ -64,6 +64,14 @@ BEGIN {
         &GetParcels &GetParcel
         &GetContracts &GetContract
 
+        &GetInvoices
+        &GetInvoice
+        &GetInvoiceDetails
+        &AddInvoice
+        &ModInvoice
+        &CloseInvoice
+        &ReopenInvoice
+
         &GetItemnumbersFromOrder
 
         &AddClaim
@@ -1245,15 +1253,14 @@ sub GetCancelledOrders {
 =head3 ModReceiveOrder
 
   &ModReceiveOrder($biblionumber, $ordernumber, $quantityreceived, $user,
-    $unitprice, $booksellerinvoicenumber, $biblioitemnumber,
-    $freight, $bookfund, $rrp);
+    $unitprice, $invoiceid, $biblioitemnumber,
+    $bookfund, $rrp, \@received_itemnumbers);
 
 Updates an order, to reflect the fact that it was received, at least
 in part. All arguments not mentioned below update the fields with the
 same name in the aqorders table of the Koha database.
 
-If a partial order is received, splits the order into two.  The received
-portion must have a booksellerinvoicenumber.
+If a partial order is received, splits the order into two.
 
 Updates the order with bibilionumber C<$biblionumber> and ordernumber
 C<$ordernumber>.
@@ -1264,7 +1271,7 @@ C<$ordernumber>.
 sub ModReceiveOrder {
     my (
         $biblionumber,    $ordernumber,  $quantrec, $user, $cost,
-        $invoiceno, $freight, $rrp, $budget_id, $datereceived, $received_items
+        $invoiceid, $rrp, $budget_id, $datereceived, $received_items
     )
     = @_;
 
@@ -1305,9 +1312,8 @@ sub ModReceiveOrder {
         $order->{'quantity'} = $quantrec;
         $order->{'quantityreceived'} = $quantrec;
         $order->{'datereceived'} = $datereceived;
-        $order->{'booksellerinvoicenumber'} = $invoiceno;
+        $order->{'invoiceid'} = $invoiceid;
         $order->{'unitprice'} = $cost;
-        $order->{'freight'} = $freight;
         $order->{'rrp'} = $rrp;
         $order->{'orderstatus'} = 3;    # totally received
         $new_ordernumber = NewOrder($order);
@@ -1319,10 +1325,10 @@ sub ModReceiveOrder {
         }
     } else {
         $sth=$dbh->prepare("update aqorders
-                            set quantityreceived=?,datereceived=?,booksellerinvoicenumber=?,
-                                unitprice=?,freight=?,rrp=?
+                            set quantityreceived=?,datereceived=?,invoiceid=?,
+                                unitprice=?,rrp=?
                             where biblionumber=? and ordernumber=?");
-        $sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$biblionumber,$ordernumber);
+        $sth->execute($quantrec,$datereceived,$invoiceid,$cost,$rrp,$biblionumber,$ordernumber);
         $sth->finish;
     }
     return ($datereceived, $new_ordernumber);
@@ -1370,7 +1376,7 @@ sub CancelReceipt {
             UPDATE aqorders
             SET quantityreceived = ?,
                 datereceived = ?,
-                booksellerinvoicenumber = ?
+                invoiceid = ?
             WHERE ordernumber = ?
         };
         $sth = $dbh->prepare($query);
@@ -1597,9 +1603,10 @@ sub GetParcel {
         LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno
         LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
         LEFT JOIN biblio ON aqorders.biblionumber=biblio.biblionumber
+        LEFT JOIN aqinvoices ON aqorders.invoiceid = aqinvoices.invoiceid
         WHERE
             aqbasket.booksellerid = ?
-            AND aqorders.booksellerinvoicenumber LIKE ?
+            AND aqinvoices.invoicenumber LIKE ?
             AND aqorders.datereceived = ? ";
 
     my @query_params = ( $supplierid, $code, $datereceived );
@@ -1672,18 +1679,19 @@ sub GetParcels {
     my $dbh    = C4::Context->dbh;
     my @query_params = ();
     my $strsth ="
-        SELECT  aqorders.booksellerinvoicenumber,
+        SELECT  aqinvoices.invoicenumber,
                 datereceived,purchaseordernumber,
                 count(DISTINCT biblionumber) AS biblio,
                 sum(quantity) AS itemsexpected,
                 sum(quantityreceived) AS itemsreceived
         FROM   aqorders LEFT JOIN aqbasket ON aqbasket.basketno = aqorders.basketno
+        LEFT JOIN aqinvoices ON aqorders.invoiceid = aqinvoices.invoiceid
         WHERE aqbasket.booksellerid = ? and datereceived IS NOT NULL
     ";
     push @query_params, $bookseller;
 
     if ( defined $code ) {
-        $strsth .= ' and aqorders.booksellerinvoicenumber like ? ';
+        $strsth .= ' and aqinvoices.invoicenumber like ? ';
         # add a % to the end of the code to allow stemming.
         push @query_params, "$code%";
     }
@@ -1698,7 +1706,7 @@ sub GetParcels {
         push @query_params, $dateto;
     }
 
-    $strsth .= "group by aqorders.booksellerinvoicenumber,datereceived ";
+    $strsth .= "group by aqinvoices.invoicenumber,datereceived ";
 
     # can't use a placeholder to place this column name.
     # but, we could probably be checking to make sure it is a column that will be fetched.
@@ -1915,7 +1923,7 @@ sub GetHistory {
             aqorders.quantityreceived,
             aqorders.ecost,
             aqorders.ordernumber,
-            aqorders.booksellerinvoicenumber as invoicenumber,
+            aqinvoices.invoicenumber,
             aqbooksellers.id as id,
             aqorders.biblionumber
         FROM aqorders
@@ -1923,7 +1931,8 @@ sub GetHistory {
         LEFT JOIN aqbasketgroups ON aqbasket.basketgroupid=aqbasketgroups.id
         LEFT JOIN aqbooksellers ON aqbasket.booksellerid=aqbooksellers.id
        LEFT JOIN biblioitems ON biblioitems.biblionumber=aqorders.biblionumber
-        LEFT JOIN biblio ON biblio.biblionumber=aqorders.biblionumber";
+        LEFT JOIN biblio ON biblio.biblionumber=aqorders.biblionumber
+    LEFT JOIN aqinvoices ON aqorders.invoiceid = aqinvoices.invoiceid";
 
     $query .= " LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber"
     if ( C4::Context->preference("IndependantBranches") );
@@ -1977,8 +1986,8 @@ sub GetHistory {
     }
 
     if ($booksellerinvoicenumber) {
-        $query .= " AND (aqorders.booksellerinvoicenumber LIKE ? OR aqbasket.booksellerinvoicenumber LIKE ?)";
-        push @query_params, "%$booksellerinvoicenumber%", "%$booksellerinvoicenumber%";
+        $query .= " AND aqinvoices.invoicenumber LIKE ? ";
+        push @query_params, "%$booksellerinvoicenumber%";
     }
 
     if ($basketgroupname) {
@@ -2124,7 +2133,345 @@ sub AddClaim {
         ";
     my $sth = $dbh->prepare($query);
     $sth->execute($ordernumber);
+}
+
+=head3 GetInvoices
+
+    my @invoices = GetInvoices(
+        invoicenumber => $invoicenumber,
+        suppliername => $suppliername,
+        shipmentdatefrom => $shipmentdatefrom, # ISO format
+        shipmentdateto => $shipmentdateto, # ISO format
+        billingdatefrom => $billingdatefrom, # ISO format
+        billingdateto => $billingdateto, # ISO format
+        isbneanissn => $isbn_or_ean_or_issn,
+        title => $title,
+        author => $author,
+        publisher => $publisher,
+        publicationyear => $publicationyear,
+        branchcode => $branchcode,
+        order_by => $order_by
+    );
+
+Return a list of invoices that match all given criteria.
+
+$order_by is "column_name (asc|desc)", where column_name is any of
+'invoicenumber', 'booksellerid', 'shipmentdate', 'billingdate', 'closedate',
+'shipmentcost', 'shipmentcost_budgetid'.
+
+asc is the default if omitted
+
+=cut
+
+sub GetInvoices {
+    my %args = @_;
+
+    my @columns = qw(invoicenumber booksellerid shipmentdate billingdate
+        closedate shipmentcost shipmentcost_budgetid);
+
+    my $dbh = C4::Context->dbh;
+    my $query = qq{
+        SELECT aqinvoices.*, aqbooksellers.name AS suppliername,
+          COUNT(
+            DISTINCT IF(
+              aqorders.datereceived IS NOT NULL,
+              aqorders.biblionumber,
+              NULL
+            )
+          ) AS receivedbiblios,
+          SUM(aqorders.quantityreceived) AS receiveditems
+        FROM aqinvoices
+          LEFT JOIN aqbooksellers ON aqbooksellers.id = aqinvoices.booksellerid
+          LEFT JOIN aqorders ON aqorders.invoiceid = aqinvoices.invoiceid
+          LEFT JOIN biblio ON aqorders.biblionumber = biblio.biblionumber
+          LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber
+          LEFT JOIN subscription ON biblio.biblionumber = subscription.biblionumber
+    };
+
+    my @bind_args;
+    my @bind_strs;
+    if($args{supplierid}) {
+        push @bind_strs, " aqinvoices.booksellerid = ? ";
+        push @bind_args, $args{supplierid};
+    }
+    if($args{invoicenumber}) {
+        push @bind_strs, " aqinvoices.invoicenumber LIKE ? ";
+        push @bind_args, "%$args{invoicenumber}%";
+    }
+    if($args{suppliername}) {
+        push @bind_strs, " aqbooksellers.name LIKE ? ";
+        push @bind_args, "%$args{suppliername}%";
+    }
+    if($args{shipmentdatefrom}) {
+        push @bind_strs, " aqinvoices.shipementdate >= ? ";
+        push @bind_args, $args{shipementdatefrom};
+    }
+    if($args{shipmentdateto}) {
+        push @bind_strs, " aqinvoices.shipementdate <= ? ";
+        push @bind_args, $args{shipementdateto};
+    }
+    if($args{billingdatefrom}) {
+        push @bind_strs, " aqinvoices.billingdate >= ? ";
+        push @bind_args, $args{billingdatefrom};
+    }
+    if($args{billingdateto}) {
+        push @bind_strs, " aqinvoices.billingdate <= ? ";
+        push @bind_args, $args{billingdateto};
+    }
+    if($args{isbneanissn}) {
+        push @bind_strs, " (biblioitems.isbn LIKE ? OR biblioitems.ean LIKE ? OR biblioitems.issn LIKE ? ) ";
+        push @bind_args, $args{isbneanissn}, $args{isbneanissn}, $args{isbneanissn};
+    }
+    if($args{title}) {
+        push @bind_strs, " biblio.title LIKE ? ";
+        push @bind_args, $args{title};
+    }
+    if($args{author}) {
+        push @bind_strs, " biblio.author LIKE ? ";
+        push @bind_args, $args{author};
+    }
+    if($args{publisher}) {
+        push @bind_strs, " biblioitems.publishercode LIKE ? ";
+        push @bind_args, $args{publisher};
+    }
+    if($args{publicationyear}) {
+        push @bind_strs, " biblioitems.publicationyear = ? ";
+        push @bind_args, $args{publicationyear};
+    }
+    if($args{branchcode}) {
+        push @bind_strs, " aqorders.branchcode = ? ";
+        push @bind_args, $args{branchcode};
+    }
+
+    $query .= " WHERE " . join(" AND ", @bind_strs) if @bind_strs;
+    $query .= " GROUP BY aqinvoices.invoiceid ";
+
+    if($args{order_by}) {
+        my ($column, $direction) = split / /, $args{order_by};
+        if(grep /^$column$/, @columns) {
+            $direction ||= 'ASC';
+            $query .= " ORDER BY $column $direction";
+        }
+    }
 
+    my $sth = $dbh->prepare($query);
+    $sth->execute(@bind_args);
+
+    my $results = $sth->fetchall_arrayref({});
+    return @$results;
+}
+
+=head3 GetInvoice
+
+    my $invoice = GetInvoice($invoiceid);
+
+Get informations about invoice with given $invoiceid
+
+Return a hash filled with aqinvoices.* fields
+
+=cut
+
+sub GetInvoice {
+    my ($invoiceid) = @_;
+    my $invoice;
+
+    return unless $invoiceid;
+
+    my $dbh = C4::Context->dbh;
+    my $query = qq{
+        SELECT *
+        FROM aqinvoices
+        WHERE invoiceid = ?
+    };
+    my $sth = $dbh->prepare($query);
+    $sth->execute($invoiceid);
+
+    $invoice = $sth->fetchrow_hashref;
+    return $invoice;
+}
+
+=head3 GetInvoiceDetails
+
+    my $invoice = GetInvoiceDetails($invoiceid)
+
+Return informations about an invoice + the list of related order lines
+
+Orders informations are in $invoice->{orders} (array ref)
+
+=cut
+
+sub GetInvoiceDetails {
+    my ($invoiceid) = @_;
+    my $invoice;
+
+    return unless $invoiceid;
+
+    my $dbh = C4::Context->dbh;
+    my $query = qq{
+        SELECT aqinvoices.*, aqbooksellers.name AS suppliername
+        FROM aqinvoices
+          LEFT JOIN aqbooksellers ON aqinvoices.booksellerid = aqbooksellers.id
+        WHERE invoiceid = ?
+    };
+    my $sth = $dbh->prepare($query);
+    $sth->execute($invoiceid);
+
+    $invoice = $sth->fetchrow_hashref;
+
+    $query = qq{
+        SELECT aqorders.*, biblio.*
+        FROM aqorders
+          LEFT JOIN biblio ON aqorders.biblionumber = biblio.biblionumber
+        WHERE invoiceid = ?
+    };
+    $sth = $dbh->prepare($query);
+    $sth->execute($invoiceid);
+    $invoice->{orders} = $sth->fetchall_arrayref({});
+    $invoice->{orders} ||= []; # force an empty arrayref if fetchall_arrayref fails
+
+    return $invoice;
+}
+
+=head3 AddInvoice
+
+    my $invoiceid = AddInvoice(
+        invoicenumber => $invoicenumber,
+        booksellerid => $booksellerid,
+        shipmentdate => $shipmentdate,
+        billingdate => $billingdate,
+        closedate => $closedate,
+        shipmentcost => $shipmentcost,
+        shipmentcost_budgetid => $shipmentcost_budgetid
+    );
+
+Create a new invoice and return its id or undef if it fails.
+
+=cut
+
+sub AddInvoice {
+    my %invoice = @_;
+
+    return unless(%invoice and $invoice{invoicenumber});
+
+    my @columns = qw(invoicenumber booksellerid shipmentdate billingdate
+        closedate shipmentcost shipmentcost_budgetid);
+
+    my @set_strs;
+    my @set_args;
+    foreach my $key (keys %invoice) {
+        if(0 < grep(/^$key$/, @columns)) {
+            push @set_strs, "$key = ?";
+            push @set_args, ($invoice{$key} || undef);
+        }
+    }
+
+    my $rv;
+    if(@set_args > 0) {
+        my $dbh = C4::Context->dbh;
+        my $query = "INSERT INTO aqinvoices SET ";
+        $query .= join (",", @set_strs);
+        my $sth = $dbh->prepare($query);
+        $rv = $sth->execute(@set_args);
+        if($rv) {
+            $rv = $dbh->last_insert_id(undef, undef, 'aqinvoices', undef);
+        }
+    }
+    return $rv;
+}
+
+=head3 ModInvoice
+
+    ModInvoice(
+        invoiceid => $invoiceid,    # Mandatory
+        invoicenumber => $invoicenumber,
+        booksellerid => $booksellerid,
+        shipmentdate => $shipmentdate,
+        billingdate => $billingdate,
+        closedate => $closedate,
+        shipmentcost => $shipmentcost,
+        shipmentcost_budgetid => $shipmentcost_budgetid
+    );
+
+Modify an invoice, invoiceid is mandatory.
+
+Return undef if it fails.
+
+=cut
+
+sub ModInvoice {
+    my %invoice = @_;
+
+    return unless(%invoice and $invoice{invoiceid});
+
+    my @columns = qw(invoicenumber booksellerid shipmentdate billingdate
+        closedate shipmentcost shipmentcost_budgetid);
+
+    my @set_strs;
+    my @set_args;
+    foreach my $key (keys %invoice) {
+        if(0 < grep(/^$key$/, @columns)) {
+            push @set_strs, "$key = ?";
+            push @set_args, ($invoice{$key} || undef);
+        }
+    }
+
+    my $dbh = C4::Context->dbh;
+    my $query = "UPDATE aqinvoices SET ";
+    $query .= join(",", @set_strs);
+    $query .= " WHERE invoiceid = ?";
+
+    my $sth = $dbh->prepare($query);
+    $sth->execute(@set_args, $invoice{invoiceid});
+}
+
+=head3 CloseInvoice
+
+    CloseInvoice($invoiceid);
+
+Close an invoice.
+
+Equivalent to ModInvoice(invoiceid => $invoiceid, closedate => undef);
+
+=cut
+
+sub CloseInvoice {
+    my ($invoiceid) = @_;
+
+    return unless $invoiceid;
+
+    my $dbh = C4::Context->dbh;
+    my $query = qq{
+        UPDATE aqinvoices
+        SET closedate = CAST(NOW() AS DATE)
+        WHERE invoiceid = ?
+    };
+    my $sth = $dbh->prepare($query);
+    $sth->execute($invoiceid);
+}
+
+=head3 ReopenInvoice
+
+    ReopenInvoice($invoiceid);
+
+Reopen an invoice
+
+Equivalent to ModInvoice(invoiceid => $invoiceid, closedate => C4::Dates->new()->output('iso'))
+
+=cut
+
+sub ReopenInvoice {
+    my ($invoiceid) = @_;
+
+    return unless $invoiceid;
+
+    my $dbh = C4::Context->dbh;
+    my $query = qq{
+        UPDATE aqinvoices
+        SET closedate = NULL
+        WHERE invoiceid = ?
+    };
+    my $sth = $dbh->prepare($query);
+    $sth->execute($invoiceid);
 }
 
 1;
index 533fcb6..ab4cc36 100644 (file)
@@ -1704,10 +1704,12 @@ sub GetMarcSubjects {
 
         # if there is an authority link, build the links with an= subfield9
         my $subfield9 = $field->subfield('9');
+        my $authoritylink;
         if ($subfield9) {
             my $linkvalue = $subfield9;
             $linkvalue =~ s/(\(|\))//g;
             @link_loop = ( { limit => 'an', 'link' => $linkvalue } );
+            $authoritylink = $linkvalue
         }
 
         # other subfields
@@ -1743,7 +1745,10 @@ sub GetMarcSubjects {
             }
         }
 
-        push @marcsubjects, { MARCSUBJECT_SUBFIELDS_LOOP => \@subfields_loop };
+        push @marcsubjects, {
+            MARCSUBJECT_SUBFIELDS_LOOP => \@subfields_loop,
+            authoritylink => $authoritylink,
+        };
 
     }
     return \@marcsubjects;
@@ -1829,7 +1834,10 @@ sub GetMarcAuthors {
                 };
             }
         }
-        push @marcauthors, { MARCAUTHOR_SUBFIELDS_LOOP => \@subfields_loop };
+        push @marcauthors, {
+            MARCAUTHOR_SUBFIELDS_LOOP => \@subfields_loop,
+            authoritylink => $subfield9,
+        };
     }
     return \@marcauthors;
 }
index e9732ac..d07dc75 100644 (file)
@@ -314,9 +314,19 @@ sub GetBudgetSpent {
             quantityreceived > 0 AND
             datecancellationprinted IS NULL
     |);
-
        $sth->execute($budget_id);
        my $sum =  $sth->fetchrow_array;
+
+    $sth = $dbh->prepare(qq|
+        SELECT SUM(shipmentcost) AS sum
+        FROM aqinvoices
+        WHERE shipmentcost_budgetid = ?
+          AND closedate IS NOT NULL
+    |);
+    $sth->execute($budget_id);
+    my ($shipmentcost_sum) = $sth->fetchrow_array;
+    $sum += $shipmentcost_sum;
+
        return $sum;
 }
 
@@ -330,9 +340,19 @@ sub GetBudgetOrdered {
             quantityreceived = 0 AND
             datecancellationprinted IS NULL
     |);
-
        $sth->execute($budget_id);
        my $sum =  $sth->fetchrow_array;
+
+    $sth = $dbh->prepare(qq|
+        SELECT SUM(shipmentcost) AS sum
+        FROM aqinvoices
+        WHERE shipmentcost_budgetid = ?
+          AND closedate IS NULL
+    |);
+    $sth->execute($budget_id);
+    my ($shipmentcost_sum) = $sth->fetchrow_array;
+    $sum += $shipmentcost_sum;
+
        return $sum;
 }
 
index 499fd51..8f60d80 100644 (file)
@@ -1005,6 +1005,22 @@ sub CanBookBeIssued {
             }
         }
     }
+
+## check for high holds decreasing loan period
+    my $decrease_loan = C4::Context->preference('decreaseLoanHighHolds');
+    if ( $decrease_loan && $decrease_loan == 1 ) {
+        my ( $reserved, $num, $duration, $returndate ) =
+          checkHighHolds( $item, $borrower );
+
+        if ( $num >= C4::Context->preference('decreaseLoanHighHoldsValue') ) {
+            $needsconfirmation{HIGHHOLDS} = {
+                num_holds  => $num,
+                duration   => $duration,
+                returndate => output_pref($returndate),
+            };
+        }
+    }
+
     return ( \%issuingimpossible, \%needsconfirmation, \%alerts );
 }
 
@@ -1030,6 +1046,8 @@ Returns:
 
 =item C<$message> is the branchcode where the item SHOULD be returned, if the return is not allowed
 
+=back
+
 =cut
 
 sub CanBookBeReturned {
@@ -1055,6 +1073,50 @@ sub CanBookBeReturned {
   return ($allowed, $message);
 }
 
+=head2 CheckHighHolds
+
+    used when syspref decreaseLoanHighHolds is active. Returns 1 or 0 to define whether the minimum value held in
+    decreaseLoanHighHoldsValue is exceeded, the total number of outstanding holds, the number of days the loan
+    has been decreased to (held in syspref decreaseLoanHighHoldsValue), and the new due date
+
+=cut
+
+sub checkHighHolds {
+    my ( $item, $borrower ) = @_;
+    my $biblio = GetBiblioFromItemNumber( $item->{itemnumber} );
+    my $branch = _GetCircControlBranch( $item, $borrower );
+    my $dbh    = C4::Context->dbh;
+    my $sth    = $dbh->prepare(
+'select count(borrowernumber) as num_holds from reserves where biblionumber=?'
+    );
+    $sth->execute( $item->{'biblionumber'} );
+    my ($holds) = $sth->fetchrow_array;
+    if ($holds) {
+        my $issuedate = DateTime->now( time_zone => C4::Context->tz() );
+
+        my $calendar = Koha::Calendar->new( branchcode => $branch );
+
+        my $itype =
+          ( C4::Context->preference('item-level_itypes') )
+          ? $biblio->{'itype'}
+          : $biblio->{'itemtype'};
+        my $orig_due =
+          C4::Circulation::CalcDateDue( $issuedate, $itype, $branch,
+            $borrower );
+
+        my $reduced_datedue =
+          $calendar->addDate( $issuedate,
+            C4::Context->preference('decreaseLoanHighHoldsDuration') );
+
+        if ( DateTime->compare( $reduced_datedue, $orig_due ) == -1 ) {
+            return ( 1, $holds,
+                C4::Context->preference('decreaseLoanHighHoldsDuration'),
+                $reduced_datedue );
+        }
+    }
+    return ( 0, 0, 0, undef );
+}
+
 =head2 AddIssue
 
   &AddIssue($borrower, $barcode, [$datedue], [$cancelreserve], [$issuedate])
index e5c28f3..377a55a 100644 (file)
@@ -26,7 +26,8 @@ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 use C4::Context;
 use C4::Dates qw/format_date format_date_in_iso/;
 use C4::Templates qw/themelanguage/;
-use C4::Dates;
+use C4::Koha;
+use C4::Output;
 use XML::Simple;
 use XML::Dumper;
 use C4::Debug;
@@ -34,75 +35,82 @@ use C4::Debug;
 # use Data::Dumper;
 
 BEGIN {
-       # set the version for version checking
+    # set the version for version checking
     $VERSION = 3.07.00.049;
-       require Exporter;
-       @ISA = qw(Exporter);
-       @EXPORT = qw(
-               get_report_types get_report_areas get_columns build_query get_criteria
-           save_report get_saved_reports execute_query get_saved_report create_compound run_compound
-               get_column_type get_distinct_values save_dictionary get_from_dictionary
-               delete_definition delete_report format_results get_sql
-        nb_rows update_sql
-       );
+    require Exporter;
+    @ISA    = qw(Exporter);
+    @EXPORT = qw(
+      get_report_types get_report_areas get_report_groups get_columns build_query get_criteria
+      save_report get_saved_reports execute_query get_saved_report create_compound run_compound
+      get_column_type get_distinct_values save_dictionary get_from_dictionary
+      delete_definition delete_report format_results get_sql
+      nb_rows update_sql build_authorised_value_list
+    );
 }
 
-our %table_areas;
-$table_areas{'1'} =
-  [ 'borrowers', 'statistics','items', 'biblioitems' ];    # circulation
-$table_areas{'2'} = [ 'items', 'biblioitems', 'biblio' ];   # catalogue
-$table_areas{'3'} = [ 'borrowers' ];        # patrons
-$table_areas{'4'} = ['aqorders', 'biblio', 'items'];        # acquisitions
-$table_areas{'5'} = [ 'borrowers', 'accountlines' ];        # accounts
-our %keys;
-$keys{'1'} = [
-    'statistics.borrowernumber=borrowers.borrowernumber',
-    'items.itemnumber = statistics.itemnumber',
-    'biblioitems.biblioitemnumber = items.biblioitemnumber'
-];
-$keys{'2'} = [
-    'items.biblioitemnumber=biblioitems.biblioitemnumber',
-    'biblioitems.biblionumber=biblio.biblionumber'
-];
-$keys{'3'} = [ ];
-$keys{'4'} = [
-       'aqorders.biblionumber=biblio.biblionumber',
-       'biblio.biblionumber=items.biblionumber'
-];
-$keys{'5'} = ['borrowers.borrowernumber=accountlines.borrowernumber'];
+=item get_report_areas()
 
-# have to do someting here to know if its dropdown, free text, date etc
+This will return a list of all the available report areas
 
-our %criteria;
-# reports on circulation
-$criteria{'1'} = [
-    'statistics.type',   'borrowers.categorycode',
-    'statistics.branch',
-    'biblioitems.publicationyear|date',
-    'items.dateaccessioned|date'
-];
-# reports on catalogue
-$criteria{'2'} =
-  [ 'items.itemnumber|textrange',   'items.biblionumber|textrange',   'items.barcode|textrange', 
-    'biblio.frameworkcode',         'items.holdingbranch',            'items.homebranch', 
-  'biblio.datecreated|daterange',   'biblio.timestamp|daterange',     'items.onloan|daterange', 
-  'items.ccode',                    'items.itemcallnumber|textrange', 'items.itype', 
-  'items.itemlost',                 'items.location' ];
-# reports on borrowers
-$criteria{'3'} = ['borrowers.branchcode', 'borrowers.categorycode'];
-# reports on acquisition
-$criteria{'4'} = ['aqorders.datereceived|date'];
-
-# reports on accounting
-$criteria{'5'} = ['borrowers.branchcode', 'borrowers.categorycode'];
+=cut
+
+my @REPORT_AREA = (
+    [CIRC => "Circulation"],
+    [CAT  => "Catalogue"],
+    [PAT  => "Patrons"],
+    [ACQ  => "Acquisition"],
+    [ACC  => "Accounts"],
+);
+my $AREA_NAME_SQL_SNIPPET
+  = "CASE report_area " .
+    join (" ", map "WHEN '$_->[0]' THEN '$_->[1]'", @REPORT_AREA) .
+    " END AS areaname";
+sub get_report_areas {
+    return \@REPORT_AREA
+}
+
+my %table_areas = (
+    CIRC => [ 'borrowers', 'statistics', 'items', 'biblioitems' ],
+    CAT  => [ 'items', 'biblioitems', 'biblio' ],
+    PAT  => ['borrowers'],
+    ACQ  => [ 'aqorders', 'biblio', 'items' ],
+    ACC  => [ 'borrowers', 'accountlines' ],
+);
+my %keys = (
+    CIRC => [ 'statistics.borrowernumber=borrowers.borrowernumber',
+              'items.itemnumber = statistics.itemnumber',
+              'biblioitems.biblioitemnumber = items.biblioitemnumber' ],
+    CAT  => [ 'items.biblioitemnumber=biblioitems.biblioitemnumber',
+              'biblioitems.biblionumber=biblio.biblionumber' ],
+    PAT  => [],
+    ACQ  => [ 'aqorders.biblionumber=biblio.biblionumber',
+              'biblio.biblionumber=items.biblionumber' ],
+    ACC  => ['borrowers.borrowernumber=accountlines.borrowernumber'],
+);
+
+# have to do someting here to know if its dropdown, free text, date etc
+my %criteria = (
+    CIRC => [ 'statistics.type', 'borrowers.categorycode', 'statistics.branch',
+              'biblioitems.publicationyear|date', 'items.dateaccessioned|date' ],
+    CAT  => [ 'items.itemnumber|textrange', 'items.biblionumber|textrange',
+              'items.barcode|textrange', 'biblio.frameworkcode',
+              'items.holdingbranch', 'items.homebranch',
+              'biblio.datecreated|daterange', 'biblio.timestamp|daterange',
+              'items.onloan|daterange', 'items.ccode',
+              'items.itemcallnumber|textrange', 'items.itype', 'items.itemlost',
+              'items.location' ],
+    PAT  => [ 'borrowers.branchcode', 'borrowers.categorycode' ],
+    ACQ  => ['aqorders.datereceived|date'],
+    ACC  => [ 'borrowers.branchcode', 'borrowers.categorycode' ],
+);
 
 # Adds itemtypes to criteria, according to the syspref
-if (C4::Context->preference('item-level_itypes')) {
-    unshift @{ $criteria{'1'} }, 'items.itype';
-    unshift @{ $criteria{'2'} }, 'items.itype';
+if ( C4::Context->preference('item-level_itypes') ) {
+    unshift @{ $criteria{'CIRC'} }, 'items.itype';
+    unshift @{ $criteria{'CAT'} }, 'items.itype';
 } else {
-    unshift @{ $criteria{'1'} }, 'biblioitems.itemtype';
-    unshift @{ $criteria{'2'} }, 'biblioitems.itemtype';
+    unshift @{ $criteria{'CIRC'} }, 'biblioitems.itemtype';
+    unshift @{ $criteria{'CAT'} }, 'biblioitems.itemtype';
 }
 
 =head1 NAME
@@ -145,26 +153,33 @@ sub get_report_types {
 
 }
 
-=item get_report_areas()
+=item get_report_groups()
 
-This will return a list of all the available report areas
+This will return a list of all the available report areas with groups
 
 =cut
 
-sub get_report_areas {
+sub get_report_groups {
     my $dbh = C4::Context->dbh();
 
-    # FIXME these should be in the database
-    my @reports = ( 'Circulation', 'Catalog', 'Patrons', 'Acquisitions', 'Accounts');
-    my @reports2;
-    for ( my $i = 0 ; $i < 5 ; $i++ ) {
-        my %hashrep;
-        $hashrep{id}   = $i + 1;
-        $hashrep{name} = $reports[$i];
-        push @reports2, \%hashrep;
+    my $groups = GetAuthorisedValues('REPORT_GROUP');
+    my $subgroups = GetAuthorisedValues('REPORT_SUBGROUP');
+
+    my %groups_with_subgroups = map { $_->{authorised_value} => {
+                        name => $_->{lib},
+                        groups => {}
+                    } } @$groups;
+    foreach (@$subgroups) {
+        my $sg = $_->{authorised_value};
+        my $g = $_->{lib_opac}
+          or warn( qq{REPORT_SUBGROUP "$sg" without REPORT_GROUP (lib_opac)} ),
+             next;
+        my $g_sg = $groups_with_subgroups{$g}
+          or warn( qq{REPORT_SUBGROUP "$sg" with invalid REPORT_GROUP "$g"} ),
+             next;
+        $g_sg->{subgroups}{$sg} = $_->{lib};
     }
-    return ( \@reports2 );
-
+    return \%groups_with_subgroups
 }
 
 =item get_all_tables()
@@ -196,8 +211,10 @@ This will return a list of all columns for a report area
 sub get_columns {
 
     # this calls the internal fucntion _get_columns
-    my ($area,$cgi) = @_;
-    my $tables = $table_areas{$area};
+    my ( $area, $cgi ) = @_;
+    my $tables = $table_areas{$area}
+      or die qq{Unsuported report area "$area"};
+
     my @allcolumns;
     my $first = 1;
     foreach my $table (@$tables) {
@@ -383,7 +400,7 @@ sub nb_rows($) {
 
 =item execute_query
 
-  ($results, $total, $error) = execute_query($sql, $offset, $limit)
+  ($results, $error) = execute_query($sql, $offset, $limit)
 
 
 When passed C<$sql>, this function returns an array ref containing a result set
@@ -505,37 +522,47 @@ Returns id of the newly created report
 =cut
 
 sub save_report {
-    my ( $borrowernumber, $sql, $name, $type, $notes, $cache_expiry, $public ) = @_;
-    $cache_expiry ||= 300;
+    my ($fields) = @_;
+    my $borrowernumber = $fields->{borrowernumber};
+    my $sql = $fields->{sql};
+    my $name = $fields->{name};
+    my $type = $fields->{type};
+    my $notes = $fields->{notes};
+    my $area = $fields->{area};
+    my $group = $fields->{group};
+    my $subgroup = $fields->{subgroup};
+    my $cache_expiry = $fields->{cache_expiry} || 300;
+    my $public = $fields->{public};
+
     my $dbh = C4::Context->dbh();
-    $sql =~ s/(\s*\;\s*)$//; # removes trailing whitespace and /;/
-    my $query =
-"INSERT INTO saved_sql (borrowernumber,date_created,last_modified,savedsql,report_name,type,notes,cache_expiry, public)  VALUES (?,now(),now(),?,?,?,?,?,?)";
-    $dbh->do( $query, undef, $borrowernumber, $sql, $name, $type, $notes, $cache_expiry, $public );
+    $sql =~ s/(\s*\;\s*)$//;    # removes trailing whitespace and /;/
+    my $query = "INSERT INTO saved_sql (borrowernumber,date_created,last_modified,savedsql,report_name,report_area,report_group,report_subgroup,type,notes,cache_expiry,public)  VALUES (?,now(),now(),?,?,?,?,?,?,?,?,?)";
+    $dbh->do($query, undef, $borrowernumber, $sql, $name, $area, $group, $subgroup, $type, $notes, $cache_expiry, $public);
+
     my $id = $dbh->selectrow_array("SELECT max(id) FROM saved_sql WHERE borrowernumber=? AND report_name=?", undef,
                                    $borrowernumber, $name);
     return $id;
 }
 
 sub update_sql {
-    my $id = shift || croak "No Id given";
-    my $sql = shift;
-    my $reportname = shift;
-    my $notes = shift;
-    my $cache_expiry = shift;
-    my $public = shift;
-
-    # not entirely a magic number, Cache::Memcached::Set assumed any expiry >= (60*60*24*30) is an absolute unix timestamp (rather than relative seconds)
+    my $id         = shift || croak "No Id given";
+    my $fields     = shift;
+    my $sql = $fields->{sql};
+    my $name = $fields->{name};
+    my $notes = $fields->{notes};
+    my $group = $fields->{group};
+    my $subgroup = $fields->{subgroup};
+    my $cache_expiry = $fields->{cache_expiry};
+    my $public = $fields->{public};
+
     if( $cache_expiry >= 2592000 ){
       die "Please specify a cache expiry less than 30 days\n";
     }
 
-    my $dbh = C4::Context->dbh();
-    $sql =~ s/(\s*\;\s*)$//; # removes trailing whitespace and /;/
-    my $query = "UPDATE saved_sql SET savedsql = ?, last_modified = now(), report_name = ?, notes = ?, cache_expiry = ?, public = ? WHERE id = ? ";
-    my $sth = $dbh->prepare($query);
-    $sth->execute( $sql, $reportname, $notes, $cache_expiry, $public, $id );
-    $sth->finish();
+    my $dbh        = C4::Context->dbh();
+    $sql =~ s/(\s*\;\s*)$//;    # removes trailing whitespace and /;/
+    my $query = "UPDATE saved_sql SET savedsql = ?, last_modified = now(), report_name = ?, report_group = ?, report_subgroup = ?, notes = ?, cache_expiry = ?, public = ? WHERE id = ? ";
+    $dbh->do($query, undef, $sql, $name, $group, $subgroup, $notes, $cache_expiry, $public, $id );
 }
 
 sub store_results {
@@ -582,30 +609,34 @@ sub format_results {
 }      
 
 sub delete_report {
-       my ( $id ) = @_;
-       my $dbh = C4::Context->dbh();
-       my $query = "DELETE FROM saved_sql WHERE id = ?";
-       my $sth = $dbh->prepare($query);
-       $sth->execute($id);
+    my ($id)  = @_;
+    my $dbh   = C4::Context->dbh();
+    my $query = "DELETE FROM saved_sql WHERE id = ?";
+    my $sth   = $dbh->prepare($query);
+    $sth->execute($id);
 }      
 
-# $filter is either { date => $d, author => $a, keyword => $kw }
-# or $keyword. Optional.
+
+my $SAVED_REPORTS_BASE_QRY = <<EOQ;
+SELECT s.*, r.report, r.date_run, $AREA_NAME_SQL_SNIPPET, av_g.lib AS groupname, av_sg.lib AS subgroupname,
+b.firstname AS borrowerfirstname, b.surname AS borrowersurname
+FROM saved_sql s
+LEFT JOIN saved_reports r ON r.report_id = s.id
+LEFT OUTER JOIN authorised_values av_g ON (av_g.category = 'REPORT_GROUP' AND av_g.authorised_value = s.report_group)
+LEFT OUTER JOIN authorised_values av_sg ON (av_sg.category = 'REPORT_SUBGROUP' AND av_sg.lib_opac = s.report_group AND av_sg.authorised_value = s.report_subgroup)
+LEFT OUTER JOIN borrowers b USING (borrowernumber)
+EOQ
 my $DATE_FORMAT = "%d/%m/%Y";
 sub get_saved_reports {
+# $filter is either { date => $d, author => $a, keyword => $kw, }
+# or $keyword. Optional.
     my ($filter) = @_;
     $filter = { keyword => $filter } if $filter && !ref( $filter );
+    my ($group, $subgroup) = @_;
 
     my $dbh   = C4::Context->dbh();
+    my $query = $SAVED_REPORTS_BASE_QRY;
     my (@cond,@args);
-    my $query = "SELECT saved_sql.id, report_id, report,
-                        date_run, date_created, last_modified, savedsql, last_run,
-                        report_name, type, notes,
-                        borrowernumber, surname as borrowersurname, firstname as borrowerfirstname,
-                        cache_expiry, public
-                 FROM saved_sql 
-                 LEFT JOIN saved_reports ON saved_reports.report_id = saved_sql.id
-                 LEFT OUTER JOIN borrowers USING (borrowernumber)";
     if ($filter) {
         if (my $date = $filter->{date}) {
             $date = format_date_in_iso($date);
@@ -629,6 +660,14 @@ sub get_saved_reports {
                          savedsql LIKE ?";
             push @args, $keyword, $keyword, $keyword, $keyword;
         }
+        if ($filter->{group}) {
+            push @cond, "report_group = ?";
+            push @args, $filter->{group};
+        }
+        if ($filter->{subgroup}) {
+            push @cond, "report_subgroup = ?";
+            push @args, $filter->{subgroup};
+        }
     }
     $query .= " WHERE ".join( " AND ", map "($_)", @cond ) if @cond;
     $query .= " ORDER by date_created";
@@ -642,7 +681,6 @@ sub get_saved_reports {
 sub get_saved_report {
     my $dbh   = C4::Context->dbh();
     my $query;
-    my $sth;
     my $report_arg;
     if ($#_ == 0 && ref $_[0] ne 'HASH') {
         ($report_arg) = @_;
@@ -661,10 +699,7 @@ sub get_saved_report {
     } else {
         return;
     }
-    $sth   = $dbh->prepare($query);
-    $sth->execute($report_arg);
-    my $data = $sth->fetchrow_hashref();
-    return ( $data->{'savedsql'}, $data->{'type'}, $data->{'report_name'}, $data->{'notes'}, $data->{'cache_expiry'}, $data->{'public'}, $data->{'id'} );
+    return $dbh->selectrow_hashref($query, undef, $report_arg);
 }
 
 =item create_compound($masterID,$subreportID)
@@ -674,22 +709,27 @@ This will take 2 reports and create a compound report using both of them
 =cut
 
 sub create_compound {
-       my ($masterID,$subreportID) = @_;
-       my $dbh = C4::Context->dbh();
-       # get the reports
-       my ($mastersql,$mastertype) = get_saved_report($masterID);
-       my ($subsql,$subtype) = get_saved_report($subreportID);
-       
-       # now we have to do some checking to see how these two will fit together
-       # or if they will
-       my ($mastertables,$subtables);
-       if ($mastersql =~ / from (.*) where /i){ 
-               $mastertables = $1;
-       }
-       if ($subsql =~ / from (.*) where /i){
-               $subtables = $1;
-       }
-       return ($mastertables,$subtables);
+    my ( $masterID, $subreportID ) = @_;
+    my $dbh = C4::Context->dbh();
+
+    # get the reports
+    my $master = get_saved_report($masterID);
+    my $mastersql = $master->{savedsql};
+    my $mastertype = $master->{type};
+    my $sub = get_saved_report($subreportID);
+    my $subsql = $master->{savedsql};
+    my $subtype = $master->{type};
+
+    # now we have to do some checking to see how these two will fit together
+    # or if they will
+    my ( $mastertables, $subtables );
+    if ( $mastersql =~ / from (.*) where /i ) {
+        $mastertables = $1;
+    }
+    if ( $subsql =~ / from (.*) where /i ) {
+        $subtables = $1;
+    }
+    return ( $mastertables, $subtables );
 }
 
 =item get_column_type($column)
@@ -739,43 +779,41 @@ sub get_distinct_values {
 }      
 
 sub save_dictionary {
-       my ($name,$description,$sql,$area) = @_;
-       my $dbh = C4::Context->dbh();
-       my $query = "INSERT INTO reports_dictionary (name,description,saved_sql,area,date_created,date_modified)
+    my ( $name, $description, $sql, $area ) = @_;
+    my $dbh   = C4::Context->dbh();
+    my $query = "INSERT INTO reports_dictionary (name,description,saved_sql,report_area,date_created,date_modified)
   VALUES (?,?,?,?,now(),now())";
     my $sth = $dbh->prepare($query);
     $sth->execute($name,$description,$sql,$area) || return 0;
     return 1;
 }
 
+my $DICTIONARY_BASE_QRY = <<EOQ;
+SELECT d.*, $AREA_NAME_SQL_SNIPPET
+FROM reports_dictionary d
+EOQ
 sub get_from_dictionary {
-       my ($area,$id) = @_;
-       my $dbh = C4::Context->dbh();
-       my $query = "SELECT * FROM reports_dictionary";
-       if ($area){
-               $query.= " WHERE area = ?";
-       }
-       elsif ($id){
-               $query.= " WHERE id = ?"
-       }
-       my $sth = $dbh->prepare($query);
-       if ($id){
-               $sth->execute($id);
-       }
-       elsif ($area) {
-               $sth->execute($area);
-       }
-       else {
-               $sth->execute();
-       }
-       my @loop;
-       my @reports = ( 'Circulation', 'Catalog', 'Patrons', 'Acquisitions', 'Accounts');
-       while (my $data = $sth->fetchrow_hashref()){
-               $data->{'areaname'}=$reports[$data->{'area'}-1];
-               push @loop,$data;
-               
-       }
-       return (\@loop);
+    my ( $area, $id ) = @_;
+    my $dbh   = C4::Context->dbh();
+    my $query = $DICTIONARY_BASE_QRY;
+    if ($area) {
+        $query .= " WHERE report_area = ?";
+    } elsif ($id) {
+        $query .= " WHERE id = ?";
+    }
+    my $sth = $dbh->prepare($query);
+    if ($id) {
+        $sth->execute($id);
+    } elsif ($area) {
+        $sth->execute($area);
+    } else {
+        $sth->execute();
+    }
+    my @loop;
+    while ( my $data = $sth->fetchrow_hashref() ) {
+        push @loop, $data;
+    }
+    return ( \@loop );
 }
 
 sub delete_definition {
@@ -815,6 +853,72 @@ sub _get_column_defs {
        close COLUMNS;
        return \%columns;
 }
+
+=item build_authorised_value_list($authorised_value)
+
+Returns an arrayref - hashref pair. The hashref consists of
+various code => name lists depending on the $authorised_value.
+The arrayref is the hashref keys, in appropriate order
+
+=cut
+
+sub build_authorised_value_list {
+    my ( $authorised_value ) = @_;
+
+    my $dbh = C4::Context->dbh;
+    my @authorised_values;
+    my %authorised_lib;
+
+    # builds list, depending on authorised value...
+    if ( $authorised_value eq "branches" ) {
+        my $branches = GetBranchesLoop();
+        foreach my $thisbranch (@$branches) {
+            push @authorised_values, $thisbranch->{value};
+            $authorised_lib{ $thisbranch->{value} } = $thisbranch->{branchname};
+        }
+    } elsif ( $authorised_value eq "itemtypes" ) {
+        my $sth = $dbh->prepare("SELECT itemtype,description FROM itemtypes ORDER BY description");
+        $sth->execute;
+        while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
+            push @authorised_values, $itemtype;
+            $authorised_lib{$itemtype} = $description;
+        }
+    } elsif ( $authorised_value eq "cn_source" ) {
+        my $class_sources  = GetClassSources();
+        my $default_source = C4::Context->preference("DefaultClassificationSource");
+        foreach my $class_source ( sort keys %$class_sources ) {
+            next
+              unless $class_sources->{$class_source}->{'used'}
+                  or ( $class_source eq $default_source );
+            push @authorised_values, $class_source;
+            $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
+        }
+    } elsif ( $authorised_value eq "categorycode" ) {
+        my $sth = $dbh->prepare("SELECT categorycode, description FROM categories ORDER BY description");
+        $sth->execute;
+        while ( my ( $categorycode, $description ) = $sth->fetchrow_array ) {
+            push @authorised_values, $categorycode;
+            $authorised_lib{$categorycode} = $description;
+        }
+
+        #---- "true" authorised value
+    } else {
+        my $authorised_values_sth = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib");
+
+        $authorised_values_sth->execute($authorised_value);
+
+        while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
+            push @authorised_values, $value;
+            $authorised_lib{$value} = $lib;
+
+            # For item location, we show the code and the libelle
+            $authorised_lib{$value} = $lib;
+        }
+    }
+
+    return (\@authorised_values, \%authorised_lib);
+}
+
 1;
 __END__
 
index 38951fc..da7a1b0 100644 (file)
@@ -54,6 +54,7 @@ sub do_checkout {
        my $shelf          = $self->{item}->hold_shelf;
        my $barcode        = $self->{item}->id;
        my $patron_barcode = $self->{patron}->id;
+        my $overridden_duedate; # usually passed as undef to AddIssue
        $debug and warn "do_checkout: patron (" . $patron_barcode . ")";
        my $borrower = $self->{patron}->getmemberdetails_object();
        $debug and warn "do_checkout borrower: . " . Dumper $borrower;
@@ -72,7 +73,7 @@ sub do_checkout {
             $noerror = 0;
         }
     } else {
-        foreach my $confirmation (keys %$needsconfirmation) {
+        foreach my $confirmation (keys %{$needsconfirmation}) {
             if ($confirmation eq 'RENEW_ISSUE'){
                 $self->screen_msg("Item already checked out to you: renewing item.");
             } elsif ($confirmation eq 'RESERVED' or $confirmation eq 'RESERVE_WAITING') {
@@ -87,6 +88,9 @@ sub do_checkout {
                 $self->screen_msg("Item already checked out to another patron.  Please return item for check-in.");
                 $noerror = 0;
             } elsif ($confirmation eq 'DEBT') {     # don't do anything, it's the minor debt, and alarms fire elsewhere
+            } elsif ($confirmation eq 'HIGHHOLDS') {
+                $overridden_duedate = $needsconfirmation->{$confirmation}->{returndate};
+                $self->screen_msg('Loan period reduced for high-demand item');
             } else {
                 $self->screen_msg($needsconfirmation->{$confirmation});
                 $noerror = 0;
@@ -118,10 +122,10 @@ sub do_checkout {
         # TODO: adjust representation in $self->item
     }
        # can issue
-       $debug and warn "do_checkout: calling AddIssue(\$borrower,$barcode, undef, 0)\n"
+       $debug and warn "do_checkout: calling AddIssue(\$borrower,$barcode, $overridden_duedate, 0)\n"
                # . "w/ \$borrower: " . Dumper($borrower)
                . "w/ C4::Context->userenv: " . Dumper(C4::Context->userenv);
-       my $due_dt  = AddIssue($borrower, $barcode, undef, 0);
+       my $due_dt  = AddIssue($borrower, $barcode, $overridden_duedate, 0);
     if ($due_dt) {
         $self->{due} = $due_dt->clone();
     } else {
index b36c5f8..2b78f75 100644 (file)
@@ -34,6 +34,8 @@ use C4::Charset;
 use YAML;
 use URI::Escape;
 use Business::ISBN;
+use MARC::Record;
+use MARC::Field;
 
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG);
 
@@ -1029,6 +1031,104 @@ sub getIndexes{
     return \@indexes;
 }
 
+=head2 _handle_exploding_index
+
+    my $query = _handle_exploding_index($index, $term)
+
+Callback routine to generate the search for "exploding" indexes (i.e.
+those indexes which are turned into multiple or-connected searches based
+on authority data).
+
+=cut
+
+sub _handle_exploding_index {
+    my ( $index, $term ) = @_;
+
+    return unless ($index =~ m/(su-br|su-na|su-rl)/ && $term);
+
+    my $marcflavour = C4::Context->preference('marcflavour');
+
+    my $codesubfield = $marcflavour eq 'UNIMARC' ? '5' : 'w';
+    my $wantedcodes = '';
+    my @subqueries = ( "(su=\"$term\")");
+    my ($error, $results, $total_hits) = SimpleSearch( "Heading,wrdl=$term", undef, undef, [ "authorityserver" ] );
+    foreach my $auth (@$results) {
+        my $record = MARC::Record->new_from_usmarc($auth);
+        my @references = $record->field('5..');
+        if (@references) {
+            if ($index eq 'su-br') {
+                $wantedcodes = 'g';
+            } elsif ($index eq 'su-na') {
+                $wantedcodes = 'h';
+            } elsif ($index eq 'su-rl') {
+                $wantedcodes = '';
+            }
+            foreach my $reference (@references) {
+                my $codes = $reference->subfield($codesubfield);
+                push @subqueries, '(su="' . $reference->as_string('abcdefghijlmnopqrstuvxyz') . '")' if (($codes && $codes eq $wantedcodes) || !$wantedcodes);
+            }
+        }
+    }
+    return join(' or ', @subqueries);
+}
+
+=head2 parseQuery
+
+    ( $operators, $operands, $indexes, $limits,
+      $sort_by, $scan, $lang ) =
+            buildQuery ( $operators, $operands, $indexes, $limits, $sort_by, $scan, $lang);
+
+Shim function to ease the transition from buildQuery to a new QueryParser.
+This function is called at the beginning of buildQuery, and modifies
+buildQuery's input. If it can handle the input, it returns a query that
+buildQuery will not try to parse.
+=cut
+
+sub parseQuery {
+    my ( $operators, $operands, $indexes, $limits, $sort_by, $scan, $lang) = @_;
+
+    my @operators = $operators ? @$operators : ();
+    my @indexes   = $indexes   ? @$indexes   : ();
+    my @operands  = $operands  ? @$operands  : ();
+    my @limits    = $limits    ? @$limits    : ();
+    my @sort_by   = $sort_by   ? @$sort_by   : ();
+
+    my $query = $operands[0];
+    my $index;
+    my $term;
+
+# TODO: once we are using QueryParser, all this special case code for
+#       exploded search indexes will be replaced by a callback to
+#       _handle_exploding_index
+    if ( $query =~ m/^(.*)\b(su-br|su-na|su-rl)[:=](\w.*)$/ ) {
+        $query = $1;
+        $index = $2;
+        $term  = $3;
+    } else {
+        $query = '';
+        for ( my $i = 0 ; $i <= @operands ; $i++ ) {
+            if ($operands[$i] && $indexes[$i] =~ m/(su-br|su-na|su-rl)/) {
+                $index = $indexes[$i];
+                $term = $operands[$i];
+            } elsif ($operands[$i]) {
+                $query .= $operators[$i] eq 'or' ? ' or ' : ' and ' if ($query);
+                $query .= "($indexes[$i]:$operands[$i])";
+            }
+        }
+    }
+
+    if ($index) {
+        my $queryPart = _handle_exploding_index($index, $term);
+        if ($queryPart) {
+            $query .= "($queryPart)";
+        }
+        $operators = ();
+        $operands[0] = "ccl=$query";
+    }
+
+    return ( $operators, \@operands, $indexes, $limits, $sort_by, $scan, $lang);
+}
+
 =head2 buildQuery
 
 ( $error, $query,
@@ -1050,6 +1150,8 @@ sub buildQuery {
 
     warn "---------\nEnter buildQuery\n---------" if $DEBUG;
 
+    ( $operators, $operands, $indexes, $limits, $sort_by, $scan, $lang) = parseQuery($operators, $operands, $indexes, $limits, $sort_by, $scan, $lang);
+
     # dereference
     my @operators = $operators ? @$operators : ();
     my @indexes   = $indexes   ? @$indexes   : ();
index e31d5df..eb620cc 100644 (file)
@@ -36,6 +36,7 @@ BEGIN {
     @EXPORT = qw(
       &NewSubscription    &ModSubscription    &DelSubscription    &GetSubscriptions
       &GetSubscription    &CountSubscriptionFromBiblionumber      &GetSubscriptionsFromBiblionumber
+      &SearchSubscriptions
       &GetFullSubscriptionsFromBiblionumber   &GetFullSubscription &ModSubscriptionHistory
       &HasSubscriptionStrictlyExpired &HasSubscriptionExpired &GetExpirationDate &abouttoexpire
 
@@ -631,6 +632,74 @@ sub GetSubscriptions {
     return @results;
 }
 
+=head2 SearchSubscriptions
+
+@results = SearchSubscriptions($args);
+$args is a hashref. Its keys can be contained: title, issn, ean, publisher, bookseller and branchcode
+
+this function gets all subscriptions which have title like $title, ISSN like $issn, EAN like $ean, publisher like $publisher, bookseller like $bookseller AND branchcode eq $branch.
+
+return:
+a table of hashref. Each hash containt the subscription.
+
+=cut
+
+sub SearchSubscriptions {
+    my ( $args ) = @_;
+
+    my $query = qq{
+        SELECT subscription.*, subscriptionhistory.*, biblio.*, biblioitems.issn
+        FROM subscription
+            LEFT JOIN subscriptionhistory USING(subscriptionid)
+            LEFT JOIN biblio ON biblio.biblionumber = subscription.biblionumber
+            LEFT JOIN biblioitems ON biblioitems.biblionumber = subscription.biblionumber
+            LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id
+    };
+    my @where_strs;
+    my @where_args;
+    if( $args->{biblionumber} ) {
+        push @where_strs, "biblio.biblionumber = ?";
+        push @where_args, $args->{biblionumber};
+    }
+    if( $args->{title} ){
+        push @where_strs, "biblio.title LIKE ?";
+        push @where_args, "%$args->{title}%";
+    }
+    if( $args->{issn} ){
+        push @where_strs, "biblioitems.issn LIKE ?";
+        push @where_args, "%$args->{issn}%";
+    }
+    if( $args->{ean} ){
+        push @where_strs, "biblioitems.ean LIKE ?";
+        push @where_args, "%$args->{ean}%";
+    }
+    if( $args->{publisher} ){
+        push @where_strs, "biblioitems.publishercode LIKE ?";
+        push @where_args, "%$args->{publisher}%";
+    }
+    if( $args->{bookseller} ){
+        push @where_strs, "aqbooksellers.name LIKE ?";
+        push @where_args, "%$args->{bookseller}%";
+    }
+    if( $args->{branch} ){
+        push @where_strs, "subscription.branchcode = ?";
+        push @where_args, "$args->{branch}";
+    }
+
+    if(@where_strs){
+        $query .= " WHERE " . join(" AND ", @where_strs);
+    }
+
+    my $dbh = C4::Context->dbh;
+    my $sth = $dbh->prepare($query);
+    $sth->execute(@where_args);
+    my $results = $sth->fetchall_arrayref( {} );
+    $sth->finish;
+
+    return @$results;
+}
+
+
 =head2 GetSerials
 
 ($totalissues,@serials) = GetSerials($subscriptionid);
index b1b4910..22001f1 100755 (executable)
@@ -191,13 +191,11 @@ if ($op eq ""){
         # 3rd add order
         my $patron = C4::Members->GetMember( borrowernumber => $loggedinuser );
         my $branch = C4::Branch->GetBranchDetail( $patron->{branchcode} );
-        my ($invoice);
         # get quantity in the MARC record (1 if none)
         my $quantity = GetMarcQuantity($marcrecord, C4::Context->preference('marcflavour')) || 1;
         my %orderinfo = (
             "biblionumber", $biblionumber, "basketno", $cgiparams->{'basketno'},
             "quantity", $quantity, "branchcode", $branch, 
-            "booksellerinvoicenumber", $invoice, 
             "budget_id", $budget_id, "uncertainprice", 1,
             "sort1", $cgiparams->{'sort1'},"sort2", $cgiparams->{'sort2'},
             "notes", $cgiparams->{'notes'}, "budget_id", $cgiparams->{'budget_id'},
index bfd8010..bb4818d 100755 (executable)
@@ -45,14 +45,14 @@ my $origquantityrec=$input->param('origquantityrec');
 my $quantityrec=$input->param('quantityrec');
 my $quantity=$input->param('quantity');
 my $unitprice=$input->param('cost');
-my $invoiceno=$input->param('invoice');
-my $datereceived=$input->param('datereceived');
+my $invoiceid = $input->param('invoiceid');
+my $invoice = GetInvoice($invoiceid);
+my $invoiceno = $invoice->{invoicenumber};
+my $datereceived= $invoice->{shipmentdate};
 my $replacement=$input->param('rrp');
 my $gst=$input->param('gst');
-my $freight=$input->param('freight');
 my $booksellerid = $input->param('booksellerid');
 my $cnt=0;
-my $error_url_str;
 my $ecost = $input->param('ecost');
 my $note = $input->param("note");
 
@@ -68,8 +68,7 @@ if ($quantityrec > $origquantityrec ) {
     if ( $quantityrec > 0 ) {
         ($datereceived, $new_ordernumber) = ModReceiveOrder(
             $biblionumber, $ordernumber, $quantityrec, $user, $unitprice,
-            $invoiceno, $freight, $replacement, undef, $datereceived,
-            \@received_items);
+            $invoiceid, $replacement, undef, $datereceived, \@received_items);
     }
 
     # now, add items if applicable
@@ -112,7 +111,7 @@ if ($quantityrec > $origquantityrec ) {
 
 update_item( $_ ) foreach GetItemnumbersFromOrder( $ordernumber );
 
-print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoice=$invoiceno&booksellerid=$booksellerid&freight=$freight&gst=$gst&datereceived=$datereceived$error_url_str");
+print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoiceid=$invoiceid");
 
 ################################ End of script ################################
 
diff --git a/acqui/invoice.pl b/acqui/invoice.pl
new file mode 100755 (executable)
index 0000000..1dc97ee
--- /dev/null
@@ -0,0 +1,227 @@
+#!/usr/bin/perl
+
+# Copyright 2011 BibLibre SARL
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+=head1 NAME
+
+invoice.pl
+
+=head1 DESCRIPTION
+
+Invoice details
+
+=cut
+
+use strict;
+use warnings;
+
+use CGI;
+use C4::Auth;
+use C4::Output;
+use C4::Acquisition;
+use C4::Bookseller qw/GetBookSellerFromId/;
+use C4::Budgets;
+
+my $input = new CGI;
+my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
+    {
+        template_name   => 'acqui/invoice.tmpl',
+        query           => $input,
+        type            => 'intranet',
+        authnotrequired => 0,
+        flagsrequired   => { 'acquisition' => '*' },
+        debug           => 1,
+    }
+);
+
+my $invoiceid = $input->param('invoiceid');
+my $op        = $input->param('op');
+
+if ( $op && $op eq 'close' ) {
+    CloseInvoice($invoiceid);
+    my $referer = $input->param('referer');
+    if ($referer) {
+        print $input->redirect($referer);
+        exit 0;
+    }
+}
+elsif ( $op && $op eq 'reopen' ) {
+    ReopenInvoice($invoiceid);
+    my $referer = $input->param('referer');
+    if ($referer) {
+        print $input->redirect($referer);
+        exit 0;
+    }
+}
+elsif ( $op && $op eq 'mod' ) {
+    my $shipmentdate       = $input->param('shipmentdate');
+    my $billingdate        = $input->param('billingdate');
+    my $shipmentcost       = $input->param('shipmentcost');
+    my $shipment_budget_id = $input->param('shipment_budget_id');
+    ModInvoice(
+        invoiceid             => $invoiceid,
+        shipmentdate          => C4::Dates->new($shipmentdate)->output("iso"),
+        billingdate           => C4::Dates->new($billingdate)->output("iso"),
+        shipmentcost          => $shipmentcost,
+        shipmentcost_budgetid => $shipment_budget_id
+    );
+    $template->param( modified => 1 );
+}
+
+my $details     = GetInvoiceDetails($invoiceid);
+my $bookseller  = GetBookSellerFromId( $details->{booksellerid} );
+my @orders_loop = ();
+my $orders      = $details->{'orders'};
+my $qty_total;
+my @books_loop;
+my @book_foot_loop;
+my %foot;
+my $total_quantity = 0;
+my $total_rrp      = 0;
+my $total_est      = 0;
+
+foreach my $order (@$orders) {
+    my $line = get_infos( $order, $bookseller );
+
+    $total_quantity += $$line{quantity};
+    $total_rrp      += $order->{quantity} * $order->{rrp};
+    $total_est      += $order->{quantity} * $order->{'ecost'};
+
+    my %row = ( %$order, %$line );
+    push @orders_loop, \%row;
+}
+
+my $gist = $bookseller->{gstrate} // C4::Context->preference("gist") // 0;
+my $discount =
+  $bookseller->{'discount'} ? ( $bookseller->{discount} / 100 ) : 0;
+my $total_est_gste;
+my $total_est_gsti;
+my $total_rrp_gsti;    # RRP Total, GST included
+my $total_rrp_gste;    # RRP Total, GST excluded
+my $gist_est;
+my $gist_rrp;
+if ($gist) {
+
+    # if we have GST
+    if ( $bookseller->{'listincgst'} ) {
+
+        # if prices already includes GST
+
+        # we know $total_rrp_gsti
+        $total_rrp_gsti = $total_rrp;
+
+        # and can reverse compute other values
+        $total_rrp_gste = $total_rrp_gsti / ( $gist + 1 );
+
+        $gist_rrp       = $total_rrp_gsti - $total_rrp_gste;
+        $total_est_gste = $total_rrp_gste - ( $total_rrp_gste * $discount );
+        $total_est_gsti = $total_est;
+    }
+    else {
+        # if prices does not include GST
+
+        # then we use the common way to compute other values
+        $total_rrp_gste = $total_rrp;
+        $gist_rrp       = $total_rrp_gste * $gist;
+        $total_rrp_gsti = $total_rrp_gste + $gist_rrp;
+        $total_est_gste = $total_est;
+        $total_est_gsti = $total_rrp_gsti - ( $total_rrp_gsti * $discount );
+    }
+    $gist_est = $gist_rrp - ( $gist_rrp * $discount );
+}
+else {
+    $total_rrp_gste = $total_rrp_gsti = $total_rrp;
+    $total_est_gste = $total_est_gsti = $total_est;
+    $gist_rrp       = $gist_est       = 0;
+}
+my $total_gsti_shipment = $total_est_gsti + $details->{shipmentcost};
+
+my $format = "%.2f";
+$template->param(
+    total_rrp_gste      => sprintf( $format, $total_rrp_gste ),
+    total_rrp_gsti      => sprintf( $format, $total_rrp_gsti ),
+    total_est_gste      => sprintf( $format, $total_est_gste ),
+    total_est_gsti      => sprintf( $format, $total_est_gsti ),
+    gist_rrp            => sprintf( $format, $gist_rrp ),
+    gist_est            => sprintf( $format, $gist_est ),
+    total_gsti_shipment => sprintf( $format, $total_gsti_shipment ),
+    gist                => sprintf( $format, $gist * 100 ),
+);
+
+my $budgets = GetBudgets();
+my @budgets_loop;
+my $shipmentcost_budgetid = $details->{shipmentcost_budgetid};
+foreach my $budget (@$budgets) {
+    next unless CanUserUseBudget( $loggedinuser, $budget, $flags );
+    my %line = %{$budget};
+    if (    $shipmentcost_budgetid
+        and $budget->{budget_id} == $shipmentcost_budgetid )
+    {
+        $line{selected} = 1;
+    }
+    push @budgets_loop, \%line;
+}
+
+$template->param(
+    invoiceid        => $details->{'invoiceid'},
+    invoicenumber    => $details->{'invoicenumber'},
+    suppliername     => $details->{'suppliername'},
+    supplierid       => $details->{'booksellerid'},
+    datereceived     => $details->{'datereceived'},
+    shipmentdate     => $details->{'shipmentdate'},
+    billingdate      => $details->{'billingdate'},
+    invoiceclosedate => $details->{'closedate'},
+    shipmentcost     => sprintf( $format, $details->{'shipmentcost'} || 0 ),
+    orders_loop      => \@orders_loop,
+    total_quantity   => $total_quantity,
+    invoiceincgst    => $bookseller->{invoiceincgst},
+    currency         => $bookseller->{listprice},
+    DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
+    budgets_loop             => \@budgets_loop,
+);
+
+sub get_infos {
+    my $order      = shift;
+    my $bookseller = shift;
+    my $qty        = $order->{'quantity'} || 0;
+    if ( !defined $order->{quantityreceived} ) {
+        $order->{quantityreceived} = 0;
+    }
+    my $budget = GetBudget( $order->{'budget_id'} );
+
+    my %line = %{$order};
+    $line{order_received} = ( $qty == $order->{'quantityreceived'} );
+    $line{budget_name}    = $budget->{budget_name};
+    $line{total}          = $qty * $order->{ecost};
+
+    if ( $line{uncertainprice} ) {
+        $line{rrp} .= ' (Uncertain)';
+    }
+    if ( $line{'title'} ) {
+        my $volume      = $order->{'volume'};
+        my $seriestitle = $order->{'seriestitle'};
+        $line{'title'} .= " / $seriestitle" if $seriestitle;
+        $line{'title'} .= " / $volume"      if $volume;
+    }
+    else {
+        $line{'title'} = "Deleted bibliographic notice, can't find title.";
+    }
+
+    return \%line;
+}
+
+output_html_with_http_headers $input, $cookie, $template->output;
diff --git a/acqui/invoices.pl b/acqui/invoices.pl
new file mode 100755 (executable)
index 0000000..4b45e31
--- /dev/null
@@ -0,0 +1,157 @@
+#!/usr/bin/perl
+
+# Copyright 2011 BibLibre SARL
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+=head1 NAME
+
+invoices.pl
+
+=head1 DESCRIPTION
+
+Search for invoices
+
+=cut
+
+use strict;
+use warnings;
+
+use CGI;
+use C4::Auth;
+use C4::Output;
+
+use C4::Acquisition;
+use C4::Bookseller qw/GetBookSeller/;
+use C4::Branch;
+
+my $input = new CGI;
+my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
+    {
+        template_name   => 'acqui/invoices.tmpl',
+        query           => $input,
+        type            => 'intranet',
+        authnotrequired => 0,
+        flagsrequired   => { 'acquisition' => '*' },
+        debug           => 1,
+    }
+);
+
+my $invoicenumber    = $input->param('invoicenumber');
+my $supplier         = $input->param('supplier');
+my $shipmentdatefrom = $input->param('shipmentdatefrom');
+my $shipmentdateto   = $input->param('shipmentdateto');
+my $billingdatefrom  = $input->param('billingdatefrom');
+my $billingdateto    = $input->param('billingdateto');
+my $isbneanissn      = $input->param('isbneanissn');
+my $title            = $input->param('title');
+my $author           = $input->param('author');
+my $publisher        = $input->param('publisher');
+my $publicationyear  = $input->param('publicationyear');
+my $branch           = $input->param('branch');
+my $op               = $input->param('op');
+
+my @results_loop = ();
+if ( $op and $op eq "do_search" ) {
+    my $shipmentdatefrom_iso = C4::Dates->new($shipmentdatefrom)->output("iso");
+    my $shipmentdateto_iso   = C4::Dates->new($shipmentdateto)->output("iso");
+    my $billingdatefrom_iso  = C4::Dates->new($billingdatefrom)->output("iso");
+    my $billingdateto_iso    = C4::Dates->new($billingdateto)->output("iso");
+    my @invoices             = GetInvoices(
+        invoicenumber    => $invoicenumber,
+        suppliername     => $supplier,
+        shipmentdatefrom => $shipmentdatefrom_iso,
+        shipmentdateto   => $shipmentdateto_iso,
+        billingdatefrom  => $billingdatefrom_iso,
+        billingdateto    => $billingdateto_iso,
+        isbneanissn      => $isbneanissn,
+        title            => $title,
+        author           => $author,
+        publisher        => $publisher,
+        publicationyear  => $publicationyear,
+        branchcode       => $branch
+    );
+    foreach (@invoices) {
+        my %row = (
+            invoiceid       => $_->{invoiceid},
+            billingdate     => $_->{billingdate},
+            invoicenumber   => $_->{invoicenumber},
+            suppliername    => $_->{suppliername},
+            receivedbiblios => $_->{receivedbiblios},
+            receiveditems   => $_->{receiveditems},
+            subscriptionid  => $_->{subscriptionid},
+            closedate       => $_->{closedate},
+        );
+        push @results_loop, \%row;
+    }
+}
+
+# Build suppliers list
+my @suppliers      = GetBookSeller(undef);
+my @suppliers_loop = ();
+my $suppliername;
+foreach (@suppliers) {
+    my $selected = 0;
+    if ( $supplier && $supplier == $_->{'id'} ) {
+        $selected     = 1;
+        $suppliername = $_->{'name'};
+    }
+    my %row = (
+        suppliername => $_->{'name'},
+        supplierid   => $_->{'id'},
+        selected     => $selected,
+    );
+    push @suppliers_loop, \%row;
+}
+
+# Build branches list
+my $branches      = GetBranches();
+my @branches_loop = ();
+my $branchname;
+foreach ( sort keys %$branches ) {
+    my $selected = 0;
+    if ( $branch && $branch eq $_ ) {
+        $selected   = 1;
+        $branchname = $branches->{$_}->{'branchname'};
+    }
+    my %row = (
+        branchcode => $_,
+        branchname => $branches->{$_}->{'branchname'},
+        selected   => $selected,
+    );
+    push @branches_loop, \%row;
+}
+
+$template->param(
+    do_search => ( $op and $op eq "do_search" ) ? 1 : 0,
+    results_loop             => \@results_loop,
+    invoicenumber            => $invoicenumber,
+    supplier                 => $supplier,
+    suppliername             => $suppliername,
+    billingdatefrom          => $billingdatefrom,
+    billingdateto            => $billingdateto,
+    isbneanissn              => $isbneanissn,
+    title                    => $title,
+    author                   => $author,
+    publisher                => $publisher,
+    publicationyear          => $publicationyear,
+    branch                   => $branch,
+    branchname               => $branchname,
+    suppliers_loop           => \@suppliers_loop,
+    branches_loop            => \@branches_loop,
+    DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
+);
+
+output_html_with_http_headers $input, $cookie, $template->output;
index 85168d5..a0b933b 100755 (executable)
@@ -40,9 +40,9 @@ to know on what supplier this script has to display receive order.
 
 =item receive
 
-=item invoice
+=item invoiceid
 
-the number of this invoice.
+the id of this invoice.
 
 =item freight
 
@@ -82,19 +82,18 @@ use C4::Suggestions;
 my $input      = new CGI;
 
 my $dbh          = C4::Context->dbh;
-my $booksellerid = $input->param('booksellerid');
+my $invoiceid    = $input->param('invoiceid');
+my $invoice      = GetInvoice($invoiceid);
+my $booksellerid   = $invoice->{booksellerid};
+my $freight      = $invoice->{shipmentcost};
+my $datereceived = $invoice->{shipmentdate};
 my $ordernumber  = $input->param('ordernumber');
 my $search       = $input->param('receive');
-my $invoice      = $input->param('invoice');
-my $freight      = $input->param('freight');
-my $datereceived = $input->param('datereceived');
-
 
 $datereceived = $datereceived ? C4::Dates->new($datereceived, 'iso') : C4::Dates->new();
 
 my $bookseller = GetBookSellerFromId($booksellerid);
-my $input_gst = ($input->param('gst') eq '' ? undef : $input->param('gst'));
-my $gst= $input_gst // $bookseller->{gstrate} // C4::Context->preference("gist") // 0;
+my $gst = $bookseller->{gstrate} // C4::Context->preference("gist") // 0;
 my $results = SearchOrder($ordernumber,$search);
 
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
@@ -195,7 +194,8 @@ if ( $count == 1 ) {
         unitprice             => sprintf( "%.2f",$order->{'unitprice'}),
         memberfirstname       => $member->{firstname} || "",
         membersurname         => $member->{surname} || "",
-        invoice               => $invoice,
+        invoiceid             => $invoice->{invoiceid},
+        invoice               => $invoice->{invoicenumber},
         datereceived          => $datereceived->output(),
         datereceived_iso      => $datereceived->output('iso'),
         notes                 => $order->{notes},
@@ -209,7 +209,7 @@ else {
     for ( my $i = 0 ; $i < $count ; $i++ ) {
         my %line = %{ @$results[$i] };
 
-        $line{invoice}      = $invoice;
+        $line{invoice}      = $invoice->{invoicenumber};
         $line{datereceived} = $datereceived->output();
         $line{freight}      = $freight;
         $line{gst}          = $gst;
@@ -221,7 +221,8 @@ else {
 
     $template->param(
         loop         => \@loop,
-        booksellerid   => $booksellerid,
+        booksellerid => $booksellerid,
+        invoiceid    => $invoice->{invoiceid},
     );
 }
 my $op = $input->param('op');
index 1c1736d..7f50f0b 100755 (executable)
@@ -42,8 +42,6 @@ To know the supplier this script has to show orders.
 
 is the bookseller invoice number.
 
-=item freight
-
 
 =item gst
 
@@ -57,7 +55,8 @@ To filter the results list on this given date.
 =cut
 
 use strict;
-#use warnings; FIXME - Bug 2505
+use warnings;
+
 use C4::Auth;
 use C4::Acquisition;
 use C4::Budgets;
@@ -71,36 +70,20 @@ use C4::Suggestions;
 use JSON;
 
 my $input=new CGI;
-my $booksellerid=$input->param('booksellerid');
-my $bookseller=GetBookSellerFromId($booksellerid);
-
-my $invoice=$input->param('invoice') || '';
-my $freight=$input->param('freight');
-my $input_gst = ($input->param('gst') eq '' ? undef : $input->param('gst'));
-my $gst= $input_gst // $bookseller->{gstrate} // C4::Context->preference("gist") // 0;
-my $op = $input->param('op') // '';
-my $datereceived = ( $op eq ('new' or 'search' ) )
-    ? C4::Dates->new($input->param('datereceived'))
-    :  C4::Dates->new($input->param('datereceived'), 'iso');
-$datereceived = C4::Dates->new() unless $datereceived;
-my $code            = $input->param('code');
-my @rcv_err         = $input->param('error');
-my @rcv_err_barcode = $input->param('error_bc');
-my $startfrom=$input->param('startfrom');
-my $resultsperpage = $input->param('resultsperpage');
-$resultsperpage = 20 unless ($resultsperpage);
-$startfrom=0 unless ($startfrom);
 
 my ($template, $loggedinuser, $cookie)
     = get_template_and_user({template_name => "acqui/parcel.tmpl",
                  query => $input,
-                                type => "intranet",
+                 type => "intranet",
                  authnotrequired => 0,
                  flagsrequired => {acquisition => 'order_receive'},
                  debug => 1,
 });
 
-if($op eq 'cancelreceipt') {
+my $invoiceid = $input->param('invoiceid');
+my $op = $input->param('op') // '';
+
+if ($op eq 'cancelreceipt') {
     my $ordernumber = $input->param('ordernumber');
     my $parent_ordernumber = CancelReceipt($ordernumber);
     unless($parent_ordernumber) {
@@ -108,6 +91,21 @@ if($op eq 'cancelreceipt') {
     }
 }
 
+my $invoice = GetInvoiceDetails($invoiceid);
+my $booksellerid = $invoice->{booksellerid};
+my $bookseller = GetBookSellerFromId($booksellerid);
+my $gst = $bookseller->{gstrate} // C4::Context->preference("gist") // 0;
+my $datereceived = C4::Dates->new();
+my $code            = $input->param('code');
+my @rcv_err         = $input->param('error');
+my @rcv_err_barcode = $input->param('error_bc');
+my $startfrom=$input->param('startfrom');
+my $resultsperpage = $input->param('resultsperpage');
+$resultsperpage = 20 unless ($resultsperpage);
+$startfrom=0 unless ($startfrom);
+
+
+
 # If receiving error, report the error (coming from finishrecieve.pl(sic)).
 if( scalar(@rcv_err) ) {
        my $cnt=0;
@@ -122,10 +120,9 @@ if( scalar(@rcv_err) ) {
 }
 
 my $cfstr         = "%.2f";                                                           # currency format string -- could get this from currency table.
-my @parcelitems   = GetParcel($booksellerid, $invoice, $datereceived->output('iso'));
+my @parcelitems   = @{ $invoice->{orders} };
 my $countlines    = scalar @parcelitems;
 my $totalprice    = 0;
-my $totalfreight  = 0;
 my $totalquantity = 0;
 my $total;
 my $tototal;
@@ -133,15 +130,14 @@ my @loop_received = ();
 
 for (my $i = 0 ; $i < $countlines ; $i++) {
 
-    #$total=($parcelitems[$i]->{'unitprice'} + $parcelitems[$i]->{'freight'}) * $parcelitems[$i]->{'quantityreceived'};   #weird, are the freight fees counted by book? (pierre)
-    $total = ($parcelitems[$i]->{'unitprice'}) * $parcelitems[$i]->{'quantityreceived'};    #weird, are the freight fees counted by book? (pierre)
+    $total = ($parcelitems[$i]->{'unitprice'}) * $parcelitems[$i]->{'quantityreceived'};
     $parcelitems[$i]->{'unitprice'} += 0;
     my %line;
     %line          = %{ $parcelitems[$i] };
-    $line{invoice} = $invoice;
+    $line{invoice} = $invoice->{invoicenumber};
     $line{gst}     = $gst;
     $line{total} = sprintf($cfstr, $total);
-    $line{booksellerid} = $booksellerid;
+    $line{booksellerid} = $invoice->{booksellerid};
     $totalprice += $parcelitems[$i]->{'unitprice'};
     $line{unitprice} = sprintf($cfstr, $parcelitems[$i]->{'unitprice'});
 
@@ -159,156 +155,149 @@ for (my $i = 0 ; $i < $countlines ; $i++) {
     }
 
     push @loop_received, \%line;
-    #double FIXME - totalfreight is redefined later.
-
-# FIXME - each order in a  parcel holds the freight for the whole parcel. This means if you receive a parcel with items from multiple budgets, you'll see the freight charge in each budget..
-    if ($i > 0 && $totalfreight != $parcelitems[$i]->{'freight'}) {
-        warn "FREIGHT CHARGE MISMATCH!!";
-    }
-    $totalfreight = $parcelitems[$i]->{'freight'};
     $totalquantity += $parcelitems[$i]->{'quantityreceived'};
     $tototal       += $total;
 }
 
-# We get the pending orders either all or filtered
-my $pendingorders;
-if($input->param('op') eq "search"){
-    my $search   = $input->param('summaryfilter') || '';
-    my $ean      = $input->param('eanfilter') || '';
-    my $basketno = $input->param('basketfilter') || '';
-    my $orderno  = $input->param('orderfilter') || '';
-    my $grouped;
-    my $owner;
-    $pendingorders = GetPendingOrders($booksellerid,$grouped,$owner,$basketno,$orderno,$search,$ean);
-}else{
-    $pendingorders = GetPendingOrders($booksellerid);
-}
-my $countpendings = scalar @$pendingorders;
-
-# pending orders totals
-my ($totalPunitprice, $totalPquantity, $totalPecost, $totalPqtyrcvd);
-my $ordergrandtotal;
-my @loop_orders = ();
-for (my $i = 0 ; $i < $countpendings ; $i++) {
-    my %line;
-    %line = %{$pendingorders->[$i]};
-   
-    $line{quantity}+=0;
-    $line{quantityreceived}+=0;
-    $line{unitprice}+=0;
-    $totalPunitprice += $line{unitprice};
-    $totalPquantity +=$line{quantity};
-    $totalPqtyrcvd +=$line{quantityreceived};
-    $totalPecost += $line{ecost};
-    $line{ecost} = sprintf("%.2f",$line{ecost});
-    $line{ordertotal} = sprintf("%.2f",$line{ecost}*$line{quantity});
-    $line{unitprice} = sprintf("%.2f",$line{unitprice});
-    $line{invoice} = $invoice;
-    $line{gst} = $gst;
-    $line{total} = $total;
-    $line{booksellerid} = $booksellerid;
-    $ordergrandtotal += $line{ecost} * $line{quantity};
-    
-    my $biblionumber = $line{'biblionumber'};
-    my $countbiblio = CountBiblioInOrders($biblionumber);
-    my $ordernumber = $line{'ordernumber'};
-    my @subscriptions = GetSubscriptionsId ($biblionumber);
-    my $itemcount = GetItemsCount($biblionumber);
-    my $holds  = GetHolds ($biblionumber);
-    my @items = GetItemnumbersFromOrder( $ordernumber );
-    my $itemholds;
-    foreach my $item (@items){
-        my $nb = GetItemHolds($biblionumber, $item);
-        if ($nb){
-            $itemholds += $nb;
+if(!defined $invoice->{closedate}) {
+    my $pendingorders;
+    if($input->param('op') eq "search"){
+        my $search   = $input->param('summaryfilter') || '';
+        my $ean      = $input->param('eanfilter') || '';
+        my $basketno = $input->param('basketfilter') || '';
+        my $orderno  = $input->param('orderfilter') || '';
+        my $grouped;
+        my $owner;
+        $pendingorders = GetPendingOrders($booksellerid,$grouped,$owner,$basketno,$orderno,$search,$ean);
+    }else{
+        $pendingorders = GetPendingOrders($booksellerid);
+    }
+    my $countpendings = scalar @$pendingorders;
+
+    # pending orders totals
+    my ($totalPunitprice, $totalPquantity, $totalPecost, $totalPqtyrcvd);
+    my $ordergrandtotal;
+    my @loop_orders = ();
+    for (my $i = 0 ; $i < $countpendings ; $i++) {
+        my %line;
+        %line = %{$pendingorders->[$i]};
+
+        $line{quantity}+=0;
+        $line{quantityreceived}+=0;
+        $line{unitprice}+=0;
+        $totalPunitprice += $line{unitprice};
+        $totalPquantity +=$line{quantity};
+        $totalPqtyrcvd +=$line{quantityreceived};
+        $totalPecost += $line{ecost};
+        $line{ecost} = sprintf("%.2f",$line{ecost});
+        $line{ordertotal} = sprintf("%.2f",$line{ecost}*$line{quantity});
+        $line{unitprice} = sprintf("%.2f",$line{unitprice});
+        $line{invoice} = $invoice;
+        $line{gst} = $gst;
+        $line{total} = $total;
+        $line{booksellerid} = $booksellerid;
+        $ordergrandtotal += $line{ecost} * $line{quantity};
+
+        my $biblionumber = $line{'biblionumber'};
+        my $countbiblio = CountBiblioInOrders($biblionumber);
+        my $ordernumber = $line{'ordernumber'};
+        my @subscriptions = GetSubscriptionsId ($biblionumber);
+        my $itemcount = GetItemsCount($biblionumber);
+        my $holds  = GetHolds ($biblionumber);
+        my @items = GetItemnumbersFromOrder( $ordernumber );
+        my $itemholds;
+        foreach my $item (@items){
+            my $nb = GetItemHolds($biblionumber, $item);
+            if ($nb){
+                $itemholds += $nb;
+            }
         }
+
+        my $suggestion   = GetSuggestionInfoFromBiblionumber($line{biblionumber});
+        $line{suggestionid}         = $suggestion->{suggestionid};
+        $line{surnamesuggestedby}   = $suggestion->{surnamesuggestedby};
+        $line{firstnamesuggestedby} = $suggestion->{firstnamesuggestedby};
+
+        # if the biblio is not in other orders and if there is no items elsewhere and no subscriptions and no holds we can then show the link "Delete order and Biblio" see bug 5680
+        $line{can_del_bib}          = 1 if $countbiblio <= 1 && $itemcount == scalar @items && !(@subscriptions) && !($holds);
+        $line{items}                = ($itemcount) - (scalar @items);
+        $line{left_item}            = 1 if $line{items} >= 1;
+        $line{left_biblio}          = 1 if $countbiblio > 1;
+        $line{biblios}              = $countbiblio - 1;
+        $line{left_subscription}    = 1 if scalar @subscriptions >= 1;
+        $line{subscriptions}        = scalar @subscriptions;
+        $line{left_holds}           = ($holds >= 1) ? 1 : 0;
+        $line{left_holds_on_order}  = 1 if $line{left_holds}==1 && ($line{items} == 0 || $itemholds );
+        $line{holds}                = $holds;
+        $line{holds_on_order}       = $itemholds?$itemholds:$holds if $line{left_holds_on_order};
+
+
+        push @loop_orders, \%line if ($i >= $startfrom and $i < $startfrom + $resultsperpage);
     }
 
-    my $suggestion   = GetSuggestionInfoFromBiblionumber($line{biblionumber});
-    $line{suggestionid}         = $suggestion->{suggestionid};
-    $line{surnamesuggestedby}   = $suggestion->{surnamesuggestedby};
-    $line{firstnamesuggestedby} = $suggestion->{firstnamesuggestedby};
+    my $count = $countpendings;
 
-    # if the biblio is not in other orders and if there is no items elsewhere and no subscriptions and no holds we can then show the link "Delete order and Biblio" see bug 5680
-    $line{can_del_bib}          = 1 if $countbiblio <= 1 && $itemcount == scalar @items && !(@subscriptions) && !($holds);
-    $line{items}                = ($itemcount) - (scalar @items);
-    $line{left_item}            = 1 if $line{items} >= 1;
-    $line{left_biblio}          = 1 if $countbiblio > 1;
-    $line{biblios}              = $countbiblio - 1;
-    $line{left_subscription}    = 1 if scalar @subscriptions >= 1;
-    $line{subscriptions}        = scalar @subscriptions;
-    $line{left_holds}           = 1 if $holds >= 1;
-    $line{left_holds_on_order}  = 1 if $line{left_holds} == 1 && ($line{items} == 0 || $itemholds );
-    $line{holds}                = $holds;
-    $line{holds_on_order}       = $itemholds?$itemholds:$holds if $line{left_holds_on_order};
-    
-    
-    push @loop_orders, \%line if ($i >= $startfrom and $i < $startfrom + $resultsperpage);
-}
-$freight = $totalfreight unless $freight;
-my $count = $countpendings;
-
-if ($count>$resultsperpage){
-    my $displaynext=0;
-    my $displayprev=$startfrom;
-    if(($count - ($startfrom+$resultsperpage)) > 0 ) {
-        $displaynext = 1;
-    }
+    if ($count>$resultsperpage){
+        my $displaynext=0;
+        my $displayprev=$startfrom;
+        if(($count - ($startfrom+$resultsperpage)) > 0 ) {
+            $displaynext = 1;
+        }
 
-    my @numbers = ();
-    for (my $i=1; $i<$count/$resultsperpage+1; $i++) {
-            my $highlight=0;
-            ($startfrom/$resultsperpage==($i-1)) && ($highlight=1);
-            push @numbers, { number => $i,
-                highlight => $highlight ,
-                startfrom => ($i-1)*$resultsperpage};
-    }
+        my @numbers = ();
+        for (my $i=1; $i<$count/$resultsperpage+1; $i++) {
+                my $highlight=0;
+                ($startfrom/$resultsperpage==($i-1)) && ($highlight=1);
+                push @numbers, { number => $i,
+                    highlight => $highlight ,
+                    startfrom => ($i-1)*$resultsperpage};
+        }
 
-    my $from = $startfrom*$resultsperpage+1;
-    my $to;
-    if($count < (($startfrom+1)*$resultsperpage)){
-        $to = $count;
-    } else {
-        $to = (($startfrom+1)*$resultsperpage);
+        my $from = $startfrom*$resultsperpage+1;
+        my $to;
+        if($count < (($startfrom+1)*$resultsperpage)){
+            $to = $count;
+        } else {
+            $to = (($startfrom+1)*$resultsperpage);
+        }
+        $template->param(numbers=>\@numbers,
+                         displaynext=>$displaynext,
+                         displayprev=>$displayprev,
+                         nextstartfrom=>(($startfrom+$resultsperpage<$count)?$startfrom+$resultsperpage:$count),
+                         prevstartfrom=>(($startfrom-$resultsperpage>0)?$startfrom-$resultsperpage:0)
+                        );
     }
-    $template->param(numbers=>\@numbers,
-                     displaynext=>$displaynext,
-                     displayprev=>$displayprev,
-                     nextstartfrom=>(($startfrom+$resultsperpage<$count)?$startfrom+$resultsperpage:$count),
-                     prevstartfrom=>(($startfrom-$resultsperpage>0)?$startfrom-$resultsperpage:0)
-                    );
+
+    $template->param(
+        countpending => $countpendings,
+        loop_orders  => \@loop_orders,
+        ordergrandtotal => sprintf($cfstr, $ordergrandtotal),
+        totalPunitprice => sprintf("%.2f", $totalPunitprice),
+        totalPquantity  => $totalPquantity,
+        totalPqtyrcvd   => $totalPqtyrcvd,
+        totalPecost     => sprintf("%.2f", $totalPecost),
+    );
 }
 
-#$totalfreight=$freight;
-$tototal = $tototal + $freight;
 
 $template->param(
-    invoice               => $invoice,
+    invoiceid             => $invoice->{invoiceid},
+    invoice               => $invoice->{invoicenumber},
+    invoiceclosedate      => $invoice->{closedate},
     datereceived          => $datereceived->output('iso'),
     invoicedatereceived   => $datereceived->output('iso'),
     formatteddatereceived => $datereceived->output(),
     name                  => $bookseller->{'name'},
-    booksellerid            => $booksellerid,
+    booksellerid          => $bookseller->{id},
     gst                   => $gst,
-    freight               => $freight,
-    invoice               => $invoice,
     countreceived         => $countlines,
     loop_received         => \@loop_received,
-    countpending          => $countpendings,
-    loop_orders           => \@loop_orders,
     totalprice            => sprintf($cfstr, $totalprice),
-    totalfreight          => $totalfreight,
     totalquantity         => $totalquantity,
     tototal               => sprintf($cfstr, $tototal),
-    ordergrandtotal       => sprintf($cfstr, $ordergrandtotal),
     gst                   => $gst,
     grandtot              => sprintf($cfstr, $tototal + $gst),
-    totalPunitprice       => sprintf("%.2f", $totalPunitprice),
-    totalPquantity        => $totalPquantity,
-    totalPqtyrcvd         => $totalPqtyrcvd,
-    totalPecost           => sprintf("%.2f", $totalPecost),
     resultsperpage        => $resultsperpage,
     (uc(C4::Context->preference("marcflavour"))) => 1
 );
 output_html_with_http_headers $input, $cookie, $template->output;
index fdb46d5..4f2849d 100755 (executable)
@@ -44,9 +44,9 @@ To know the supplier this script has to show orders.
 sort list of order by 'orderby'.
 Orderby can be equals to
     * datereceived desc (default value)
-    * aqorders.booksellerinvoicenumber
+    * invoicenumber
     * datereceived
-    * aqorders.booksellerinvoicenumber desc
+    * invoicenumber desc
 
 =item filter
 
@@ -75,6 +75,7 @@ use C4::Output;
 use C4::Dates qw/format_date/;
 use C4::Acquisition;
 use C4::Bookseller qw/ GetBookSellerFromId /;
+use C4::Budgets;
 
 my $input          = CGI->new;
 my $booksellerid     = $input->param('booksellerid');
@@ -84,9 +85,10 @@ my $code           = $input->param('filter');
 my $datefrom       = $input->param('datefrom');
 my $dateto         = $input->param('dateto');
 my $resultsperpage = $input->param('resultsperpage');
+my $op             = $input->param('op');
 $resultsperpage ||= 20;
 
-our ( $template, $loggedinuser, $cookie ) = get_template_and_user(
+our ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
     {   template_name   => 'acqui/parcels.tmpl',
         query           => $input,
         type            => 'intranet',
@@ -96,8 +98,38 @@ our ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     }
 );
 
+if($op and $op eq 'new') {
+    my $invoicenumber = $input->param('invoice');
+    my $shipmentdate = $input->param('shipmentdate');
+    my $shipmentcost = $input->param('shipmentcost');
+    my $shipmentcost_budgetid = $input->param('shipmentcost_budgetid');
+    if($shipmentdate) {
+        $shipmentdate = C4::Dates->new($shipmentdate)->output('iso');
+    }
+    my $invoiceid = AddInvoice(
+        invoicenumber => $invoicenumber,
+        booksellerid => $booksellerid,
+        shipmentdate => $shipmentdate,
+        shipmentcost => $shipmentcost,
+        shipmentcost_budgetid => $shipmentcost_budgetid,
+    );
+    if(defined $invoiceid) {
+        # Successful 'Add'
+        print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoiceid=$invoiceid");
+        exit 0;
+    } else {
+        $template->param(error_failed_to_create_invoice => 1);
+    }
+}
+
 my $bookseller = GetBookSellerFromId($booksellerid);
-my @parcels = GetParcels( $booksellerid, $order, $code, $datefrom, $dateto );
+my @parcels = GetInvoices(
+    supplierid => $booksellerid,
+    invoicenumber => $code,
+    shipmentdatefrom => $datefrom,
+    shipmentdateto => $dateto,
+    order_by => $order
+);
 my $count_parcels = @parcels;
 
 # multi page display gestion
@@ -114,19 +146,28 @@ for my $i ( $startfrom .. $last_row) {
 
     push @{$loopres},
       { number           => $i + 1,
-        code             => $p->{booksellerinvoicenumber},
-        nullcode         => $p->{booksellerinvoicenumber} eq 'NULL',
-        emptycode        => $p->{booksellerinvoicenumber} eq q{},
-        raw_datereceived => $p->{datereceived},
-        datereceived     => format_date( $p->{datereceived} ),
-        bibcount         => $p->{biblio},
-        reccount         => $p->{itemsreceived},
-        itemcount        => $p->{itemsexpected},
+        invoiceid        => $p->{invoiceid},
+        code             => $p->{invoicenumber},
+        nullcode         => $p->{invoicenumber} eq 'NULL',
+        emptycode        => $p->{invoicenumber} eq q{},
+        raw_datereceived => $p->{shipmentdate},
+        datereceived     => format_date( $p->{shipmentdate} ),
+        bibcount         => $p->{receivedbiblios} || 0,
+        reccount         => $p->{receiveditems} || 0,
+        itemcount        => $p->{itemsexpected} || 0,
       };
 }
 if ($count_parcels) {
     $template->param( searchresults => $loopres, count => $count_parcels );
 }
+
+my $budgets = GetBudgets();
+my @budgets_loop;
+foreach my $budget (@$budgets) {
+    next unless CanUserUseBudget($loggedinuser, $budget, $flags);
+    push @budgets_loop, $budget;
+}
+
 $template->param(
     orderby                  => $order,
     filter                   => $code,
@@ -135,9 +176,10 @@ $template->param(
     resultsperpage           => $resultsperpage,
     name                     => $bookseller->{'name'},
     DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
-    datereceived_today       => C4::Dates->new()->output(),
+    shipmentdate_today       => C4::Dates->new()->output(),
     booksellerid             => $booksellerid,
     GST                      => C4::Context->preference('gist'),
+    budgets                  => \@budgets_loop,
 );
 
 output_html_with_http_headers $input, $cookie, $template->output;
index 0dcba98..2d555f9 100755 (executable)
@@ -60,10 +60,10 @@ SELECT
     aqbasket.booksellerid,
     itype,
     title,
-    aqorders.booksellerinvoicenumber,
+    aqorders.invoiceid,
+    aqinvoices.invoicenumber,
     quantityreceived,
     unitprice,
-    freight,
     datereceived,
     aqorders.biblionumber
 FROM (aqorders, aqbasket)
@@ -73,6 +73,8 @@ LEFT JOIN biblio ON
     biblio.biblionumber=aqorders.biblionumber
 LEFT JOIN aqorders_items ON
     aqorders.ordernumber=aqorders_items.ordernumber
+LEFT JOIN aqinvoices ON
+    aqorders.invoiceid = aqinvoices.invoiceid
 WHERE
     aqorders.basketno=aqbasket.basketno AND
     budget_id=? AND
@@ -85,27 +87,48 @@ $sth->execute($bookfund);
 if ( $sth->err ) {
     die "An error occurred fetching records: " . $sth->errstr;
 }
-my $total = 0;
+my $subtotal = 0;
 my $toggle;
 my @spent;
 while ( my $data = $sth->fetchrow_hashref ) {
     my $recv = $data->{'quantityreceived'};
     if ( $recv > 0 ) {
-        my $subtotal = $recv * ( $data->{'unitprice'} + $data->{'freight'} );
-        $data->{'subtotal'}  = sprintf( "%.2f", $subtotal );
-        $data->{'freight'}   = sprintf( "%.2f", $data->{'freight'} );
+        my $rowtotal = $recv * $data->{'unitprice'};
+        $data->{'rowtotal'}  = sprintf( "%.2f", $rowtotal );
         $data->{'unitprice'} = sprintf( "%.2f", $data->{'unitprice'} );
-        $total += $subtotal;
+        $subtotal += $rowtotal;
         push @spent, $data;
     }
 
 }
-$total = sprintf( "%.2f", $total );
 
-$template->{VARS}->{'fund'}  = $bookfund;
-$template->{VARS}->{'spent'} = \@spent;
-$template->{VARS}->{'total'} = $total;
-$template->{VARS}->{'fund_code'} = $fund_code;
+my $total = $subtotal;
+$query = qq{
+    SELECT invoicenumber, shipmentcost
+    FROM aqinvoices
+    WHERE shipmentcost_budgetid = ?
+};
+$sth = $dbh->prepare($query);
+$sth->execute($bookfund);
+my @shipmentcosts;
+while (my $data = $sth->fetchrow_hashref) {
+    push @shipmentcosts, {
+        shipmentcost => sprintf("%.2f", $data->{shipmentcost}),
+        invoicenumber => $data->{invoicenumber}
+    };
+    $total += $data->{shipmentcost};
+}
 $sth->finish;
 
+$total = sprintf( "%.2f", $total );
+
+$template->param(
+    fund => $bookfund,
+    spent => \@spent,
+    subtotal => $subtotal,
+    shipmentcosts => \@shipmentcosts,
+    total => $total,
+    fund_code => $fund_code
+);
+
 output_html_with_http_headers $input, $cookie, $template->output;
index 949e488..17917ce 100755 (executable)
@@ -188,17 +188,18 @@ output_html_with_http_headers $input, $cookie, $template->output;
 exit 0;
 
 sub default_form {
-       # build categories list
-       my $sth = $dbh->prepare("select distinct category from authorised_values");
-       $sth->execute;
-       my @category_list;
-       my %categories;     # a hash, to check that some hardcoded categories exist.
-       while ( my ($category) = $sth->fetchrow_array) {
-               push(@category_list,$category);
-               $categories{$category} = 1;
-       }
-       # push koha system categories
-    foreach (qw(Asort1 Asort2 Bsort1 Bsort2 SUGGEST DAMAGED LOST)) {
+    # build categories list
+    my $sth = $dbh->prepare("select distinct category from authorised_values");
+    $sth->execute;
+    my @category_list;
+    my %categories;    # a hash, to check that some hardcoded categories exist.
+    while ( my ($category) = $sth->fetchrow_array ) {
+        push( @category_list, $category );
+        $categories{$category} = 1;
+    }
+
+    # push koha system categories
+    foreach (qw(Asort1 Asort2 Bsort1 Bsort2 SUGGEST DAMAGED LOST REPORT_GROUP REPORT_SUBGROUP)) {
         push @category_list, $_ unless $categories{$_};
     }
 
index 3eee676..66d731b 100755 (executable)
@@ -152,17 +152,19 @@ foreach my $item (@items){
     }
 
     my $order  = GetOrderFromItemnumber( $item->{'itemnumber'} );
-    my $basket = GetBasket( $order->{'basketno'} );
-    $item->{'booksellerid'}            = $basket->{'booksellerid'};
     $item->{'ordernumber'}             = $order->{'ordernumber'};
     $item->{'basketno'}                = $order->{'basketno'};
-    $item->{'booksellerinvoicenumber'} = $order->{'booksellerinvoicenumber'};
     $item->{'orderdate'}               = $order->{'entrydate'};
     if ($item->{'basketno'}){
            my $basket = GetBasket($item->{'basketno'});
            my $bookseller = GetBookSellerFromId($basket->{'booksellerid'});
            $item->{'vendor'} = $bookseller->{'name'};
     }
+    $item->{'invoiceid'}               = $order->{'invoiceid'};
+    if($item->{invoiceid}) {
+        my $invoice = GetInvoice($item->{invoiceid});
+        $item->{invoicenumber} = $invoice->{invoicenumber} if $invoice;
+    }
     $item->{'datereceived'}            = $order->{'datereceived'};
 
     if ($item->{notforloantext} or $item->{itemlost} or $item->{damaged} or $item->{wthdrawn}) {
index 68cdfec..a514d99 100644 (file)
@@ -97,7 +97,7 @@ CREATE TABLE `auth_types` (
 DROP TABLE IF EXISTS `authorised_values`;
 CREATE TABLE `authorised_values` ( -- stores values for authorized values categories and values
   `id` int(11) NOT NULL auto_increment, -- unique key, used to identify the authorized value
-  `category` varchar(10) NOT NULL default '', -- key used to identify the authorized value category
+  `category` varchar(16) NOT NULL default '', -- key used to identify the authorized value category
   `authorised_value` varchar(80) NOT NULL default '', -- code use to identify the authorized value
   `lib` varchar(200) default NULL, -- authorized value description as printed in the staff client
   `lib_opac` varchar(200) default NULL, -- authorized value description as printed in the OPAC
@@ -1626,8 +1626,9 @@ CREATE TABLE reports_dictionary ( -- definitions (or snippets of SQL) stored for
    `date_created` datetime default NULL, -- date and time this definition was created
    `date_modified` datetime default NULL, -- date and time this definition was last modified
    `saved_sql` text, -- SQL snippet for us in reports
-   `area` int(11) default NULL, -- Koha module this definition is for (1 = Circulation, 2 = Catalog, 3 = Patrons, 4 = Acquistions, 5 = Accounts)
-   PRIMARY KEY  (`id`)
+   report_area varchar(6) DEFAULT NULL, -- Koha module this definition is for Circulation, Catalog, Patrons, Acquistions, Accounts)
+   PRIMARY KEY  (id),
+   KEY dictionary_area_idx (report_area)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 --
@@ -1725,7 +1726,11 @@ CREATE TABLE saved_sql ( -- saved sql reports
    `notes` text, -- the notes or description given to this report
    `cache_expiry` int NOT NULL default 300,
    `public` boolean NOT NULL default FALSE,
+    report_area varchar(6) default NULL,
+    report_group varchar(80) default NULL,
+    report_subgroup varchar(80) default NULL,
    PRIMARY KEY  (`id`),
+   KEY sql_area_group_idx (report_group, report_subgroup),
    KEY boridx (`borrowernumber`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
@@ -2748,7 +2753,7 @@ CREATE TABLE `aqorders` ( -- information related to the basket line items
   `listprice` decimal(28,6) default NULL, -- the vendor price for this line item
   `totalamount` decimal(28,6) default NULL, -- not used? always NULL
   `datereceived` date default NULL, -- the date this order was received
-  `booksellerinvoicenumber` mediumtext, -- the invoice number this line item was received on
+  invoiceid int(11) default NULL, -- id of invoice
   `freight` decimal(28,6) default NULL, -- shipping costs (not used)
   `unitprice` decimal(28,6) default NULL, -- the actual cost entered when receiving this line item
   `quantityreceived` smallint(6) NOT NULL default 0, -- the quantity that have been received so far
@@ -2781,7 +2786,8 @@ CREATE TABLE `aqorders` ( -- information related to the basket line items
   KEY `biblionumber` (`biblionumber`),
   KEY `budget_id` (`budget_id`),
   CONSTRAINT `aqorders_ibfk_1` FOREIGN KEY (`basketno`) REFERENCES `aqbasket` (`basketno`) ON DELETE CASCADE ON UPDATE CASCADE,
-  CONSTRAINT `aqorders_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE
+  CONSTRAINT `aqorders_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE,
+  CONSTRAINT aqorders_ibfk_3 FOREIGN KEY (invoiceid) REFERENCES aqinvoices (invoiceid) ON DELETE SET NULL ON UPDATE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 
@@ -2798,6 +2804,27 @@ CREATE TABLE `aqorders_items` ( -- information on items entered in the acquisiti
   KEY `ordernumber` (`ordernumber`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
+
+--
+-- Table structure for table aqinvoices
+--
+
+DROP TABLE IF EXISTS aqinvoices;
+CREATE TABLE aqinvoices (
+  invoiceid int(11) NOT NULL AUTO_INCREMENT,    -- ID of the invoice, primary key
+  invoicenumber mediumtext NOT NULL,    -- Name of invoice
+  booksellerid int(11) NOT NULL,    -- foreign key to aqbooksellers
+  shipmentdate date default NULL,   -- date of shipment
+  billingdate date default NULL,    -- date of billing
+  closedate date default NULL,  -- invoice close date, NULL means the invoice is open
+  shipmentcost decimal(28,6) default NULL,  -- shipment cost
+  shipmentcost_budgetid int(11) default NULL,   -- foreign key to aqbudgets, link the shipment cost to a budget
+  PRIMARY KEY (invoiceid),
+  CONSTRAINT aqinvoices_fk_aqbooksellerid FOREIGN KEY (booksellerid) REFERENCES aqbooksellers (id) ON DELETE CASCADE ON UPDATE CASCADE,
+  CONSTRAINT aqinvoices_fk_shipmentcost_budgetid FOREIGN KEY (shipmentcost_budgetid) REFERENCES aqbudgets (budget_id) ON DELETE SET NULL ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+
 --
 -- Table structure for table `fieldmapping`
 --
index 4b4bf77..7b33ce6 100644 (file)
@@ -358,6 +358,9 @@ INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES (
 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OpacStarRatings','all',NULL,'disable|all|details','Choice');
 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacBrowseResults','1','Disable/enable browsing and paging search results from the OPAC detail page.',NULL,'YesNo');
 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('SvcMaxReportRows','10','Maximum number of rows to return via the report web service.',NULL,'Integer');
+INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('decreaseLoanHighHolds', NULL, '', 'Decreases the loan period for items with number of holds above the threshold specified in decreaseLoanHighHoldsValue', 'YesNo');
+INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('decreaseLoanHighHoldsValue', NULL, '', 'Specifies a threshold for the minimum number of holds needed to trigger a reduction in loan duration (used with decreaseLoanHighHolds)', 'Integer');
+INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('decreaseLoanHighHoldsDuration', NULL, '', 'Specifies a number of days that a loan is reduced to when used in conjunction with decreaseLoanHighHolds', 'Integer');
 INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('ReservesControlBranch','PatronLibrary','ItemHomeLibrary|PatronLibrary','Branch checked for members reservations rights','Choice');
 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('IssueLostItem', 'alert', 'alert|confirm|nothing', 'Defines what should be done when an attempt is made to issue an item that has been marked as lost.', 'Choice');
 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('SuspendHoldsIntranet', '1', NULL , 'Allow holds to be suspended from the intranet.', 'YesNo');
index 158f25b..8f0efc8 100755 (executable)
@@ -5827,6 +5827,98 @@ if(C4::Context->preference("Version") < TransformToNum($DBversion) ) {
     SetVersion($DBversion);
 }
 
+
+
+$DBversion = "3.09.00.050";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE authorised_values MODIFY category varchar(16) NOT NULL DEFAULT '';");
+    $dbh->do("INSERT INTO authorised_values (category, authorised_value, lib) VALUES
+              ('REPORT_GROUP', 'CIRC', 'Circulation'),
+              ('REPORT_GROUP', 'CAT', 'Catalog'),
+              ('REPORT_GROUP', 'PAT', 'Patrons'),
+              ('REPORT_GROUP', 'ACQ', 'Acquisitions'),
+              ('REPORT_GROUP', 'ACC', 'Accounts');");
+
+    $dbh->do("ALTER TABLE reports_dictionary ADD report_area varchar(6) DEFAULT NULL;");
+    $dbh->do("UPDATE reports_dictionary SET report_area = CASE area
+                  WHEN 1 THEN 'CIRC'
+                  WHEN 2 THEN 'CAT'
+                  WHEN 3 THEN 'PAT'
+                  WHEN 4 THEN 'ACQ'
+                  WHEN 5 THEN 'ACC'
+                  END;");
+    $dbh->do("ALTER TABLE reports_dictionary DROP area;");
+    $dbh->do("ALTER TABLE reports_dictionary ADD KEY dictionary_area_idx (report_area);");
+
+    $dbh->do("ALTER TABLE saved_sql ADD report_area varchar(6) DEFAULT NULL;");
+    $dbh->do("ALTER TABLE saved_sql ADD report_group varchar(80) DEFAULT NULL;");
+    $dbh->do("ALTER TABLE saved_sql ADD report_subgroup varchar(80) DEFAULT NULL;");
+    $dbh->do("ALTER TABLE saved_sql ADD KEY sql_area_group_idx (report_group, report_subgroup);");
+
+    print "Upgrade to $DBversion done saved_sql new fields report_group and report_area; authorised_values.category 16 char \n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.09.00.051";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("
+        CREATE TABLE aqinvoices (
+          invoiceid int(11) NOT NULL AUTO_INCREMENT,
+          invoicenumber mediumtext NOT NULL,
+          booksellerid int(11) NOT NULL,
+          shipmentdate date default NULL,
+          billingdate date default NULL,
+          closedate date default NULL,
+          shipmentcost decimal(28,6) default NULL,
+          shipmentcost_budgetid int(11) default NULL,
+          PRIMARY KEY (invoiceid),
+          CONSTRAINT aqinvoices_fk_aqbooksellerid FOREIGN KEY (booksellerid) REFERENCES aqbooksellers (id) ON DELETE CASCADE ON UPDATE CASCADE,
+          CONSTRAINT aqinvoices_fk_shipmentcost_budgetid FOREIGN KEY (shipmentcost_budgetid) REFERENCES aqbudgets (budget_id) ON DELETE SET NULL ON UPDATE CASCADE
+        ) ENGINE=InnoDB DEFAULT CHARSET=utf8
+    ");
+
+    # Fill this new table with existing invoices
+    my $sth = $dbh->prepare("
+        SELECT aqorders.booksellerinvoicenumber AS invoicenumber, aqbasket.booksellerid, aqorders.datereceived
+        FROM aqorders
+          LEFT JOIN aqbasket ON aqorders.basketno = aqbasket.basketno
+        WHERE aqorders.booksellerinvoicenumber IS NOT NULL
+          AND aqorders.booksellerinvoicenumber != ''
+        GROUP BY aqorders.booksellerinvoicenumber
+    ");
+    $sth->execute;
+    my $results = $sth->fetchall_arrayref({});
+    $sth = $dbh->prepare("
+        INSERT INTO aqinvoices (invoicenumber, booksellerid, shipmentdate) VALUES (?,?,?)
+    ");
+    foreach(@$results) {
+        $sth->execute($_->{invoicenumber}, $_->{booksellerid}, $_->{datereceived});
+    }
+
+    # Add the column in aqorders, fill it with correct value
+    # and then drop booksellerinvoicenumber column
+    $dbh->do("
+        ALTER TABLE aqorders
+        ADD COLUMN invoiceid int(11) default NULL AFTER booksellerinvoicenumber,
+        ADD CONSTRAINT aqorders_ibfk_3 FOREIGN KEY (invoiceid) REFERENCES aqinvoices (invoiceid) ON DELETE SET NULL ON UPDATE CASCADE
+    ");
+
+    $dbh->do("
+        UPDATE aqorders, aqinvoices
+        SET aqorders.invoiceid = aqinvoices.invoiceid
+        WHERE aqorders.booksellerinvoicenumber = aqinvoices.invoicenumber
+    ");
+
+    $dbh->do("
+        ALTER TABLE aqorders
+        DROP COLUMN booksellerinvoicenumber
+    ");
+
+    print "Upgrade to $DBversion done (Add aqinvoices table) \n";
+    SetVersion ($DBversion);
+}
+
+
 =head1 FUNCTIONS
 
 =head2 TableExists($table)
index ac1a7a4..439118d 100644 (file)
@@ -1,6 +1,7 @@
 <ul>
        <li><a href="/cgi-bin/koha/acqui/lateorders.pl">Late orders</a></li>
        [% IF ( suggestion ) %]<li><a href="/cgi-bin/koha/suggestion/suggestion.pl">Suggestions</a></li>[% ELSE %][% END %]
+    <li><a href="/cgi-bin/koha/acqui/invoices.pl">Invoices</a></li>
     [% IF ( CAN_user_acquisition_budget_manage ) %]
     <li><a href="/cgi-bin/koha/admin/aqbudgetperiods.pl">Budgets</a></li>
     <li><a href="/cgi-bin/koha/admin/aqbudgets.pl">Funds</a></li>
index 903cf3a..b2edbe6 100644 (file)
@@ -25,7 +25,7 @@
     [% END %]
     [% IF ( EasyAnalyticalRecords ) %][% IF ( analyze ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% IF ( object ) %][% object %]&amp;analyze=1[% ELSE %][% biblionumber %]&amp;analyze=1[% END %]">Analytics</a></li>[% END %]
 
-    [% IF ( subscriptionsnumber ) %]<li><a href="/cgi-bin/koha/serials/serials-home.pl?searched=1&amp;biblionumber=[% biblionumber %]">Subscription(s)</a></li>[% END %]
+    [% IF ( subscriptionsnumber ) %]<li><a href="/cgi-bin/koha/serials/serials-search.pl?searched=1&amp;biblionumber=[% biblionumber %]">Subscription(s)</a></li>[% END %]
 </ul>
 <ul>
 [% IF ( issuehistoryview ) %]<li class="active">[% ELSE %]<li>[% END %]
index 2413216..09e748b 100644 (file)
     <option value="se">&nbsp;&nbsp;&nbsp;&nbsp; Series title</option>
     <option value="su">Subject</option>
     <option value="su,phr">&nbsp;&nbsp;&nbsp;&nbsp; Subject as phrase</option>
+    [% IF ( expanded_options ) %]
+        <option value="su-br">&nbsp;&nbsp;&nbsp;&nbsp; Subject and broader terms</option>
+        <option value="su-na">&nbsp;&nbsp;&nbsp;&nbsp; Subject and narrower terms</option>
+        <option value="su-rl">&nbsp;&nbsp;&nbsp;&nbsp; Subject and related terms</option>
+    [% END %]
     <option value="bc">Barcode</option>
     <option value="location">Shelving location</option>
     <option value="sn">Standard number</option>
index dfb908f..beb309c 100644 (file)
@@ -1,35 +1,37 @@
 <div class="gradient">
-<h1 id="logo"><a href="/cgi-bin/koha/mainpage.pl">[% LibraryName %]</a></h1><!-- Begin Serials Resident Search Box -->
-<div id="header_search">
-       <div id="subscription_search" class="residentsearch">
+  <h1 id="logo"><a href="/cgi-bin/koha/mainpage.pl">[% LibraryName %]</a></h1><!-- Begin Serials Resident Search Box -->
+  <div id="header_search">
+    <div id="subscription_search" class="residentsearch">
     <p class="tip">Search subscriptions:</p>
- <form action="/cgi-bin/koha/serials/serials-home.pl" method="get">
- [% IF ( routing ) %]<input type="hidden" name="routing" value="[% routing %]" />[% END %]
- <input type="hidden" name="searched" value="1" />
- <label for="ISSN_filter">ISSN:</label> <input type="text" size="10" maxlength="11" name="ISSN_filter" id="ISSN_filter" value="[% ISSN_filter %]" />
+    <form action="/cgi-bin/koha/serials/serials-search.pl" method="get">
+      [% IF ( routing ) %]
+        <input type="hidden" name="routing" value="[% routing %]" />
+      [% END %]
+      <input type="hidden" name="searched" value="1" />
+      <label for="ISSN_filter">ISSN:</label> <input type="text" size="10" maxlength="11" name="ISSN_filter" id="ISSN_filter" value="[% ISSN_filter %]" />
 
- [% IF (UNIMARC) %]
- <label for="EAN_filter">EAN:</label> <input type="text" size="20" maxlength="40" name="EAN_filter" id="EAN_filter" value="[% EAN_filter %]" />
- [% END %]
- <label for="title_filter">Title:</label> <input type="text" size="20" maxlength="40" name="title_filter" id="title_filter" value="[% title_filter %]" />
<input type="submit" value="Search" class="submit" />
- </form>
-       </div>
     [% IF (UNIMARC) %]
       <label for="EAN_filter">EAN:</label> <input type="text" size="20" maxlength="40" name="EAN_filter" id="EAN_filter" value="[% EAN_filter %]" />
     [% END %]
     <label for="title_filter">Title:</label> <input type="text" size="20" maxlength="40" name="title_filter" id="title_filter" value="[% title_filter %]" />
     <input value="Submit" class="submit" type="submit" /> <a href="/cgi-bin/koha/serials/serials-search.pl">Advanced search</a>
   </form>
+    </div>
     [% INCLUDE 'patron-search-box.inc' %]
-       [% IF ( CAN_user_catalogue ) %]
-    <div id="catalog_search" class="residentsearch">
-       <p class="tip">Enter search keywords:</p>
-               <form action="/cgi-bin/koha/catalogue/search.pl"  method="get" id="cat-search-block">
-                        <input type="text" name="q" id="search-form" size="40" value="" title="Enter the terms you wish to search for." class="form-text" />
-                               <input type="submit" value="Submit"  class="submit" />
-               </form>
-       </div>
-       [% END %]
-                       <ul>
-            <li><a href="#subscription_search">Search subscriptions</a></li>
-            [% IF ( CAN_user_circulate ) %]<li><a href="#circ_search">Check out</a></li>[% END %]
-            [% IF ( CAN_user_catalogue ) %]<li><a href="#catalog_search">Search the catalog</a></li>[% END %]
-                       </ul>   
-</div><!-- /header_search -->
+    [% IF ( CAN_user_catalogue ) %]
+      <div id="catalog_search" class="residentsearch">
+        <p class="tip">Enter search keywords:</p>
+        <form action="/cgi-bin/koha/catalogue/search.pl"  method="get" id="cat-search-block">
+          <input type="text" name="q" id="search-form" size="40" value="" title="Enter the terms you wish to search for." class="form-text" />
+          <input type="submit" value="Submit"  class="submit" />
+        </form>
+      </div>
+    [% END %]
+    <ul>
+      <li><a href="#subscription_search">Search subscriptions</a></li>
+      [% IF ( CAN_user_circulate ) %]<li><a href="#circ_search">Check out</a></li>[% END %]
+      [% IF ( CAN_user_catalogue ) %]<li><a href="#catalog_search">Search the catalog</a></li>[% END %]
+    </ul>
+  </div><!-- /header_search -->
 </div><!-- /gradient -->
 <!-- End Serials Resident Search Box -->
index ef720e0..5659c1d 100644 (file)
                         <br />[% suggestions_loo.author %] <br /> [% suggestions_loo.isbn %]</td>
                                        <td><a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% suggestions_loo.id %]">[% suggestions_loo.name %]</a></td>
                                        <td>[% suggestions_loo.creationdate | $KohaDates %]</td>
-                                       <td>[% suggestions_loo.datereceived | $KohaDates %]</td>
+                    <td>
+                        [% IF suggestions_loo.datereceived %]
+                            [% suggestions_loo.datereceived | $KohaDates %]
+                        [% END %]
+                    </td>
                                        <td>[% suggestions_loo.quantity %]</td>
                                        <td>[% suggestions_loo.ecost %]</td>
                                </tr>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt
new file mode 100644 (file)
index 0000000..c03a4d7
--- /dev/null
@@ -0,0 +1,173 @@
+[% USE KohaDates %]
+
+[% INCLUDE 'doc-head-open.inc' %]
+<title>Koha &rsaquo; Acquisitions &rsaquo; Invoice</title>
+<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
+[% INCLUDE 'doc-head-close.inc' %]
+[% INCLUDE 'calendar.inc' %]
+<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.dataTables.min.js"></script>
+[% INCLUDE 'datatables-strings.inc' %]
+<script type="text/javascript" src="[% themelang %]/js/datatables.js"></script>
+<script type="text/javascript">
+//<![CDATA[
+    $(document).ready(function() {
+        $("#orderst").dataTable($.extend(true, {}, dataTablesDefaults, {
+            bInfo: false,
+            bPaginate: false,
+            bFilter: false,
+            sDom: "t"
+        }));
+    });
+//]]>
+</script>
+</head>
+
+<body>
+[% INCLUDE 'header.inc' %]
+[% INCLUDE 'acquisitions-search.inc' %]
+
+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a> &rsaquo; <a href="/cgi-bin/koha/acqui/invoices.pl">Invoices</a> &rsaquo; <a href="/cgi-bin/koha/acqui/invoice.pl?invoiceid=[% invoiceid %]">[% invoicenumber %]</a></div>
+
+<div id="doc3" class="yui-t2">
+
+<div id="bd">
+  <div id="yui-main">
+    <div class="yui-b">
+      [% IF ( modified ) %]
+        <div class="dialog">
+          <p>Invoice has been modified</p>
+        </div>
+      [% END %]
+      <h1>Invoice: [% invoicenumber %]</h1>
+
+      <p>Supplier: [% suppliername %]</p>
+      <form action="" method="post">
+        <label for="shipmentdate">Shipment date:</label>
+        <input type="text" size="10" id="shipmentdate" name="shipmentdate" value="[% shipmentdate | $KohaDates %]" readonly="readonly" class="datepicker" />
+        <p></p>
+        <label for="billingdate">Billing date:</label>
+        <input type="text" size="10" id="billingdate" name="billingdate" value="[% billingdate | $KohaDates %]" readonly="readonly" class="datepicker" />
+        <p></p>
+        <label for="shipmentcost">Shipment cost:</label>
+        <input type="text" size="10" id="shipmentcost" name="shipmentcost" value="[% shipmentcost %]" />
+        <label for="shipment_budget_id">Budget:</label>
+        <select id="shipment_budget_id" name="shipment_budget_id">
+            <option value="">No budget</option>
+          [% FOREACH budget IN budgets_loop %]
+            [% IF ( budget.selected ) %]
+              <option selected="selected" value="[% budget.budget_id %]">
+            [% ELSE %]
+              <option value="[% budget.budget_id %]">
+            [% END %]
+              [% budget.budget_name %]
+            </option>
+          [% END %]
+        </select>
+        <input type="hidden" name="op" value="mod" />
+        <input type="hidden" name="invoiceid" value="[% invoiceid %]" />
+        <fieldset class="action">
+            <input type="submit" value="Save">
+        </fieldset>
+      </form>
+      <p>Status:
+        [% IF ( invoiceclosedate ) %]
+          Closed on [% invoiceclosedate | $KohaDates %].
+          <a href="/cgi-bin/koha/acqui/invoice.pl?op=reopen&invoiceid=[% invoiceid %]">
+            Reopen
+          </a>
+        [% ELSE %]
+          Open.
+          <a href="/cgi-bin/koha/acqui/invoice.pl?op=close&invoiceid=[% invoiceid %]">
+            Close
+          </a>
+        [% END %]
+      </p>
+      <p>
+          <a href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid %]">Go to receipt page</a>
+      </p>
+      <h2>Invoice details</h2>
+      [% IF orders_loop.size %]
+          <table id="orderst">
+            <thead>
+              <tr>
+                <th>Summary</th>
+                <th>Publisher</th>
+                <th>Branch</th>
+                <th>RRP</th>
+                <th>Est.</th>
+                <th>Qty.</th>
+                <th>Total</th>
+                <th>Fund</th>
+              </tr>
+            </thead>
+            <tbody>
+              [% FOREACH order IN orders_loop %]
+                <tr>
+                  <td><p><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% order.biblionumber %]">[% order.title %]</a>
+                    [% IF ( order.author ) %]
+                      <br /><em>by</em> [% order.author %]
+                    [% END %]
+                  </p></td>
+                  <td>
+                    [% IF ( order.publishercode ) %]
+                      <p>[% order.publishercode %]
+                        [% IF ( order.publicationyear ) %]
+                          - [% order.publicationyear %]
+                        [% END %]
+                      </p>
+                    [% END %]
+                  </td>
+                  <td><p>[% order.branchcode %]</p></td>
+                  <td>[% order.rrp %]</td>
+                  <td>[% order.ecost %]</td>
+                  <td class="number">[% order.quantity %]</td>
+                  <td>[% order.total %]</td>
+                  <td>[% order.budget_name %]</td>
+                </tr>
+              [% END %]
+            </tbody>
+            <tfoot>
+                <tr>
+                    <th colspan="3">Total Tax Exc.</th>
+                    <th>[% total_rrp_gste %]</th>
+                    <th>&nbsp;</th>
+                    <th>[% total_quantity %]</th>
+                    <th>[% total_est_gste %]</th>
+                    <th>&nbsp;</th>
+                </tr>
+                <tr>
+                    <th colspan='3'>Tax ([% gist %]%)</th>
+                    <th>[% gist_rrp %]</th>
+                    <th>&nbsp;</th>
+                    <th>&nbsp;</th>
+                    <th>[% gist_est %]</th>
+                    <th>&nbsp;</th>
+                </tr>
+                <tr>
+                    <th colspan='3'>Total Tax Inc. ([% currency %])</th>
+                    <th>[% total_rrp_gsti %]</th>
+                    <th>&nbsp;</th>
+                    <th>[% total_quantity %]</th>
+                    <th>[% total_est_gsti %]</th>
+                    <th>&nbsp;</th>
+                </tr>
+                <tr>
+                    <th colspan="3">Total + Shipment cost ([% currency %])</th>
+                    <th>&nbsp;</th>
+                    <th>&nbsp;</th>
+                    <th>[% total_quantity %]</th>
+                    <th>[% total_gsti_shipment %]</th>
+                    <th>&nbsp;</th>
+                </tr>
+            </tfoot>
+          </table>
+        [% ELSE %]
+            <p>No orders yet</p>
+        [% END %]
+    </div>
+  </div>
+  <div class="yui-b">
+    [% INCLUDE 'acquisitions-menu.inc' %]
+  </div>
+</div>
+[% INCLUDE 'intranet-bottom.inc' %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt
new file mode 100644 (file)
index 0000000..c324882
--- /dev/null
@@ -0,0 +1,232 @@
+[% USE KohaDates %]
+
+[% INCLUDE 'doc-head-open.inc' %]
+<title>Koha &rsaquo; Acquisitions &rsaquo; Invoices</title>
+<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
+[% INCLUDE 'doc-head-close.inc' %]
+<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.dataTables.min.js"></script>
+[% INCLUDE 'datatables-strings.inc' %]
+<script type="text/javascript" src="[% themelang %]/js/datatables.js"></script>
+[% INCLUDE 'calendar.inc' %]
+<script type="text/javascript">
+//<![CDATA[
+$(document).ready(function() {
+    $("#resultst").dataTable($.extend(true, {}, dataTablesDefaults, {
+        bInfo: false,
+        bPaginate: false,
+        bFilter: false,
+        sDom: "t",
+        aoColumnDefs: [
+            { "bSortable": false, "aTargets": [6] }
+        ]
+    }));
+});
+//]]>
+</script>
+</head>
+
+<body>
+[% INCLUDE 'header.inc' %]
+[% INCLUDE 'acquisitions-search.inc' %]
+
+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a> &rsaquo; Invoices</div>
+
+<div id="doc3" class="yui-t2">
+
+<div id="bd">
+  <div id="yui-main">
+    <div class="yui-b">
+      <h1>Invoices</h1>
+      [% IF ( do_search ) %]
+        [% IF ( results_loop ) %]
+          <table id="resultst">
+            <thead>
+              <tr>
+                <th>Invoice no.</th>
+                <th>Vendor</th>
+                <th>Billing date</th>
+                <th>Received biblios</th>
+                <th>Received items</th>
+                <th>Status</th>
+                <th>&nbsp;</th>
+              </tr>
+            </thead>
+            <tbody>
+              [% FOREACH result IN results_loop %]
+                <tr>
+                  <td>[% result.invoicenumber %]</td>
+                  <td>[% result.suppliername %]</td>
+                  <td>
+                    [% IF (result.billingdate) %]
+                      [% result.billingdate | $KohaDates %]
+                    [% END %]
+                  </td>
+                  <td>[% result.receivedbiblios %]</td>
+                  <td>[% result.receiveditems %]</td>
+                  <td>
+                    [% IF ( result.closedate ) %]
+                      Closed on [% result.closedate | $KohaDates %]
+                    [% ELSE %]
+                      Open
+                    [% END %]
+                  </td>
+                  <td>
+                    <a href="/cgi-bin/koha/acqui/invoice.pl?invoiceid=[% result.invoiceid %]">Details</a> /
+                    [% IF ( result.closedate ) %]
+                      <a href="invoice.pl?op=reopen&invoiceid=[% result.invoiceid %]&referer=/cgi-bin/koha/acqui/invoices.pl%3Fop=do_search%26invoicenumber=[% invoicenumber %]%26supplier=[% supplier %]%26billingdatefrom=[% billingdatefrom %]%26billingdateto=[% billingdateto %]%26isbneanissn=[% isbneanissn %]%26title=[% title %]%26author=[% author %]%26publisher=[% publisher %]%26publicationyear=[% publicationyear %]%26branch=[% branch %]">Reopen</a>
+                    [% ELSE %]
+                      <a href="invoice.pl?op=close&invoiceid=[% result.invoiceid %]&referer=/cgi-bin/koha/acqui/invoices.pl%3Fop=do_search%26invoicenumber=[% invoicenumber %]%26supplier=[% supplier %]%26billingdatefrom=[% billingdatefrom %]%26billingdateto=[% billingdateto %]%26isbneanissn=[% isbneanissn %]%26title=[% title %]%26author=[% author %]%26publisher=[% publisher %]%26publicationyear=[% publicationyear %]%26branch=[% branch %]">Close</a>
+                    [% END %]
+                  </td>
+                </tr>
+              [% END %]
+            </tbody>
+          </table>
+        [% ELSE %]
+          <p>Sorry, but there is no results for your search.</p>
+          <p>Search was:
+            <ul>
+              [% IF ( invoicenumber ) %]
+                <li>Invoice no.: [% invoicenumber %]</li>
+              [% END %]
+              [% IF ( supplier ) %]
+                <li>Vendor: [% suppliername %]</li>
+              [% END %]
+              [% IF ( billingdatefrom ) %]
+                <li>Billing date:
+                [% IF ( billingdateto ) %]
+                  From [% billingdatefrom %]
+                  To [% billingdateto %]
+                [% ELSE %]
+                  All since [% billingdatefrom %]
+                [% END %]
+                </li>
+              [% ELSE %]
+                [% IF ( billingdateto ) %]
+                  <li>Billing date:
+                    All until [% billingdateto %]
+                  </li>
+                [% END %]
+              [% END %]
+              [% IF ( isbneanissn ) %]
+                <li>ISBN/EAN/ISSN: [% isbneanissn %]</li>
+              [% END %]
+              [% IF ( title ) %]
+                <li>Title: [% title %]</li>
+              [% END %]
+              [% IF ( author ) %]
+                <li>Author: [% author %]</li>
+              [% END %]
+              [% IF ( publisher ) %]
+                <li>Publisher: [% publisher %]</li>
+              [% END %]
+              [% IF ( publicationyear ) %]
+                <li>Publication year: [% publicationyear %]</li>
+              [% END %]
+              [% IF ( branch ) %]
+                <li>Branch: [% branchname %]</li>
+              [% END %]
+            </ul>
+          </p>
+        [% END %]<!-- results_loop -->
+      [% ELSE %]
+        <p>Please fill in the form to the left to make a search.</p>
+      [% END %]<!-- do_search -->
+    </div>
+  </div>
+  <div class="yui-b">
+    <form action="" method="get">
+      <fieldset class="brief">
+        <h3>Search filters</h3>
+        <ol>
+          <li>
+            <label for="invoicenumber">Invoice no:</label>
+            <input type="text" id="invoicenumber" name="invoicenumber" value="[% invoicenumber %]" />
+          </li>
+          <li>
+            <label for="supplier">Supplier:</label>
+            <select id="supplier" name="supplier">
+              <option value="">All</option>
+              [% FOREACH supplier IN suppliers_loop %]
+                [% IF ( supplier.selected ) %]
+                  <option selected="selected" value="[% supplier.supplierid %]">[% supplier.suppliername %]</option>
+                [% ELSE %]
+                  <option value="[% supplier.supplierid %]">[% supplier.suppliername %]</option>
+                [% END %]
+              [% END %]
+            </select>
+          </li>
+          <li>
+            <fieldset class="brief">
+              <legend>Shipment date</legend>
+              <ol>
+                <li>
+                  <label for="shipmentdatefrom">From:</label>
+                  <input type="text" id="shipmentdatefrom" name="shipmentdatefrom" size="10" value="[% shipmentdatefrom %]" class="datepicker" />
+                </li>
+                <li>
+                  <label for="shipmentdateto">To:</label>
+                  <input type="text" id="shipmentdateto" name="shipmentdateto" size="10" value="[% shipmentdateto %]" class="datepicker" />
+                </li>
+              </ol>
+            </fieldset>
+          </li>
+          <li>
+            <fieldset class="brief">
+              <legend>Billing date</legend>
+              <ol>
+                <li>
+                  <label for="billingdatefrom">From:</label>
+                  <input type="text" id="billingdatefrom" name="billingdatefrom" size="10" value="[% billingdatefrom %]" class="datepicker" />
+                </li>
+                <li>
+                  <label for="billingdateto">To:</label>
+                  <input type="text" id="billingdateto" name="billingdateto" size="10" value="[% billingdateto %]" class="datepicker" />
+                </li>
+              </ol>
+            </fieldset>
+          </li>
+          <li>
+            <label for="isbneanissn">ISBN / EAN / ISSN:</label>
+            <input type="text" id="isbneanissn" name="isbneanissn" value="[% isbneanissn %]" />
+          </li>
+          <li>
+            <label for="title">Title:</label>
+            <input type="text" id="title" name="title" value="[% title %]" />
+          </li>
+          <li>
+            <label for="author">Author:</label>
+            <input type="text" id="author" name="author" value="[% author %]" />
+          </li>
+          <li>
+            <label for="publisher">Publisher:</label>
+            <input type="text" id="publisher" name="publisher" value="[% publisher %]" />
+          </li>
+          <li>
+            <label for="publicationyear">Publication year:</label>
+            <input type="text" id="publicationyear" name="publicationyear" value="[% publicationyear %]" />
+          </li>
+          <li>
+            <label for="branch">Branch:</label>
+            <select id="branch" name="branch">
+              <option value="">All</option>
+              [% FOREACH branch IN branches_loop %]
+                [% IF ( branch.selected ) %]
+                  <option selected="selected" value="[% branch.branchcode %]">[% branch.branchname %]</option>
+                [% ELSE %]
+                  <option value="[% branch.branchcode %]">[% branch.branchname %]</option>
+                [% END %]
+              [% END %]
+            </select>
+          </li>
+        </ol>
+        <fieldset class="action">
+          <input type="submit" value="Search" />
+        </fieldset>
+      </fieldset>
+      <input type="hidden" name="op" id="op" value="do_search" />
+    </form>
+    [% INCLUDE 'acquisitions-menu.inc' %]
+  </div>
+</div>
+[% INCLUDE 'intranet-bottom.inc' %]
index 1e19f8b..612b5bc 100644 (file)
         [% END %]
     [% END %]
     <input type="hidden" name="biblionumber" value="[% biblionumber %]" />
+    <input type="hidden" name="invoiceid" value="[% invoiceid %]" />
     <input type="hidden" name="ordernumber" value="[% ordernumber %]" />
     <input type="hidden" name="biblioitemnumber" value="[% biblioitemnumber %]" />
     <input type="hidden" name="booksellerid" value="[% booksellerid %]" />
     <input type="hidden" name="datereceived" value="[% datereceived_iso %]" />
-    <input type="hidden" name="freight" value="[% freight %]" />
     <input type="hidden" name="gst" value="[% gst %]" />
        </div>
        <div class="yui-u">
             <input type="text" size="20" name="cost" id="cost" value="[% ecost %]" />
         [% END %]</li></ol>
         <label for="note">Notes: </label><textarea name="note" width="40" rows="8" >[% notes %]</textarea>
-        <input type="hidden" name="invoice" value="[% invoice %]" />
     </fieldset>
 
 </div>
 </div><div class="yui-g"><fieldset class="action">
         <input type="submit"  value="Save" />
-        <a class="cancel" href="/cgi-bin/koha/acqui/parcel.pl?booksellerid=[% supplierid %]&amp;invoice=[% invoice %]&amp;gst=[% gst %]&amp;freight=[% freight %]">Cancel</a>
+        <a class="cancel" href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid %]">Cancel</a>
 </fieldset></div>    </form>
 [% ELSE %]
 <div id="acqui_acquire_orderlist">
         <tr>
             <td>[% loo.basketno %]</td>
             <td>[% loo.isbn %]</td>
-         <td><a href="orderreceive.pl?datereceived=[% loo.datereceived %]&amp;receive=[% loo.ordernumber %]&amp;biblio=[% loo.biblionumber %]&amp;invoice=[% loo.invoice %]&amp;freight=[% loo.freight %]&amp;gst=[% loo.gst %]&amp;id=[% loo.id %]">[% loo.title |html %]</a></td>
+         <td><a href="orderreceive.pl?ordernumber=[% loo.ordernumber %]&amp;invoiceid=[% invoiceid %]">[% loo.title |html %]</a></td>
             <td>[% loo.author %]</td>
             <td>[% loo.quantity %]</td>
             <td>[% loo.quantityreceived %]</td>
index d8ff600..554f0af 100644 (file)
@@ -45,6 +45,7 @@
                 null,
                 null,
                 null,
+                null
             ],
             "sPaginationType": "four_button"
         } ) );
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'acquisitions-search.inc' %]
 
-<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a> &rsaquo;  [% IF ( datereceived ) %]
-            Receipt summary for <i>[% name %]</i> [% IF ( invoice ) %]<i>[ [% invoice %] ]</i>[% END %] on <i>[% formatteddatereceived %]</i>
-        [% ELSE %]
-            Receive orders from [% name %]
-        [% END %]</div>
+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a> &rsaquo;
+    [% IF ( datereceived ) %]
+        Receipt summary for <i>[% name %]</i>
+        [% IF ( invoice ) %]
+            <i>[ [% invoice %] ]</i>
+        [% END %]
+        on <i>[% formatteddatereceived %]</i>
+    [% ELSE %]
+        Receive orders from [% name %]
+    [% END %]
+</div>
 
 <div id="doc3" class="yui-t2">
 
 
 <div id="acqui_receive_summary">
 <p><strong>Invoice number:</strong> [% invoice %] <strong>Received by:</strong> [% loggedinusername %] <strong>On:</strong> [% formatteddatereceived %]</p>
-       <!-- TODO: Add date picker, change rcv date. -->
+<p><a href="/cgi-bin/koha/acqui/invoice.pl?invoiceid=[% invoiceid %]">Go to invoice details</a></p>
 </div>
+[% UNLESS (invoiceclosedate) %]
 <div id="acqui_receive_search">
     <h3>Pending orders</h3>
 
                 <td>[% loop_order.ecost %]</td>
                 <td>[% loop_order.ordertotal %]</td>
                                <td>
-                              <a href="orderreceive.pl?ordernumber=[% loop_order.ordernumber %]&amp;datereceived=[% invoicedatereceived %]&amp;invoice=[% invoice %]&amp;gst=[% loop_order.gst %]&amp;freight=[% loop_order.freight %]&amp;booksellerid=[% loop_order.booksellerid %]">Receive</a>
+                              <a href="orderreceive.pl?ordernumber=[% loop_order.ordernumber %]&amp;invoiceid=[% invoiceid %]">Receive</a>
                                    
                                </td>
                                <td>
-                                   [% IF ( loop_order.left_holds_on_order ) %]
-                    <span class="button" title="Can't delete order, ([% loop_order.holds_on_order %]) holds are linked with this order cancel holds first">Can't delete order</span><br>
-                    [% ELSE %]
-                    <a href="javascript:confirm_delete_item([% loop_order.ordernumber %],[% loop_order.basketno %],[% loop_order.biblionumber %])" class="button">Delete order</a><br>
-                    [% END %]
-                    [% IF ( loop_order.can_del_bib ) %]
-                    <a href="javascript:confirm_delete_biblio([% loop_order.ordernumber %],[% loop_order.basketno %],[% loop_order.biblionumber %])" class="button">Delete order and catalog record</a><br>
-                    [% ELSE %]
-                    <span class="button" title="Can't delete catalog record, see constraints below">Can't delete order and catalog record</span><br>
-                    [% END %]
-                    [% IF ( loop_order.left_item ) %]
-                    <b title="Can't delete catalog record, because of [% loop_order.items %] existing item(s)" >[% loop_order.items %] item(s) left</b><br>
-                    [% END %]
-                    [% IF ( loop_order.left_biblio ) %]
-                    <b title="Can't delete catalog record, delete other orders linked to it first">[% loop_order.biblios %] order(s) left</b><br>
-                    [% END %]
-                    [% IF ( loop_order.left_subscription ) %]
-                    <b title="Can't delete catalog record, delete subscriptions first">[% loop_order.subscriptions %] subscription(s) left</b><br>
-                    [% END %]
-                    [% IF ( loop_order.left_holds ) %]
-                    <b title="Can't delete catalog record or order, cancel holds first">[% loop_order.holds %] hold(s) left</b>
-                    [% END %]
-                               </td>
-            </tr>
+                        [% IF ( loop_order.left_holds_on_order ) %]
+                        <span class="button" title="Can't delete order, ([% loop_order.holds_on_order %]) holds are linked with this order cancel holds first">Can't delete order</span><br>
+                        [% ELSE %]
+                        <a href="javascript:confirm_delete_item([% loop_order.ordernumber %],[% loop_order.biblionumber %])" class="button">Delete order</a><br>
+                        [% END %]
+                        [% IF ( loop_order.can_del_bib ) %]
+                        <a href="javascript:confirm_delete_biblio([% loop_order.ordernumber %],[% loop_order.biblionumber %])" class="button">Delete order and catalog record</a><br>
+                        [% ELSE %]
+                        <span class="button" title="Can't delete catalog record, see constraints below">Can't delete order and catalog record</span><br>
+                        [% END %]
+                        [% IF ( loop_order.left_item ) %]
+                        <b title="Can't delete catalog record, because of [% loop_order.items %] existing item(s)" >[% loop_order.items %] item(s) left</b><br>
+                        [% END %]
+                        [% IF ( loop_order.left_biblio ) %]
+                        <b title="Can't delete catalog record, delete other orders linked to it first">[% loop_order.biblios %] order(s) left</b><br>
+                        [% END %]
+                        [% IF ( loop_order.left_subscription ) %]
+                        <b title="Can't delete catalog record, delete subscriptions first">[% loop_order.subscriptions %] subscription(s) left</b><br>
+                        [% END %]
+                        [% IF ( loop_order.left_holds ) %]
+                        <b title="Can't delete catalog record or order, cancel holds first">[% loop_order.holds %] hold(s) left</b>
+                        [% END %]
+                    </td>
+                </tr>
+            [% END %]
+        </tbody>
+         </table>[% ELSE %]There are no pending orders.[% END %]
+       <div id="resultnumber">
+        <!-- Row of numbers corresponding to search result pages -->
+        [% IF ( displayprev ) %]
+            <a href="parcel.pl?invoiceid=[% invoiceid %]&amp;startfrom=[% prevstartfrom %][% IF ( resultsperpage ) %]&amp;resultsperpage=[% resultsperpage %][% END %]#resultnumber">&lt;&lt; Previous</a>
         [% END %]
-    </tbody>
-     </table>[% ELSE %]There are no pending orders.[% END %]
-   <div id="resultnumber">
-       <!-- Row of numbers corresponding to search result pages -->
-       [% IF ( displayprev ) %]
-               <a href="parcel.pl?type=intra&amp;booksellerid=[% booksellerid %]&amp;startfrom=[% prevstartfrom %][% IF ( datereceived ) %]&amp;datereceived=[% datereceived %][% END %][% IF ( invoice ) %]&amp;invoice=[% invoice %][% END %][% IF ( resultsperpage ) %]&amp;resultsperpage=[% resultsperpage %][% END %]#resultnumber">&lt;&lt; Previous</a>
-       [% END %]
-       [% FOREACH number IN numbers %]
-               [% IF ( number.highlight ) %]
-               <span class="current">[% number.number %]</span>
-               [% ELSE %]
-               <a href="parcel.pl?type=intra&amp;booksellerid=[% booksellerid %]&amp;startfrom=[% number.startfrom %][% IF ( datereceived ) %]&amp;datereceived=[% datereceived %][% END %][% IF ( invoice ) %]&amp;invoice=[% invoice %][% END %][% IF ( resultsperpage ) %]&amp;resultsperpage=[% resultsperpage %][% END %]#resultnumber">[% number.number %]</a>
-               [% END %]
-       [% END %]
-       [% IF ( displaynext ) %]
-               <a href="parcel.pl?type=intra&amp;booksellerid=[% booksellerid %]&amp;startfrom=[% nextstartfrom %][% IF ( datereceived ) %]&amp;datereceived=[% datereceived %][% END %][% IF ( invoice ) %]&amp;invoice=[% invoice %][% END %][% IF ( resultsperpage ) %]&amp;resultsperpage=[% resultsperpage %][% END %]#resultnumber">Next &gt;&gt;</a>
-       [% END %]
-       </div>
-</div>
+        [% FOREACH number IN numbers %]
+            [% IF ( number.highlight ) %]
+            <span class="current">[% number.number %]</span>
+            [% ELSE %]
+            <a href="parcel.pl?invoiceid=[% invoiceid %]&amp;startfrom=[% number.startfrom %][% IF ( resultsperpage ) %]&amp;resultsperpage=[% resultsperpage %][% END %]#resultnumber">[% number.number %]</a>
+            [% END %]
+        [% END %]
+        [% IF ( displaynext ) %]
+            <a href="parcel.pl?invoiceid=[% invoiceid %]&amp;startfrom=[% nextstartfrom %][% IF ( resultsperpage ) %]&amp;resultsperpage=[% resultsperpage %][% END %]#resultnumber">Next &gt;&gt;</a>
+        [% END %]
+        </div>
+    </div>
+[% ELSE %]
+    <p>
+        Invoice is close, so you can't receive orders.
+        <a href="/cgi-bin/koha/acqui/invoice.pl?op=reopen&invoiceid=[% invoiceid %]&referer=/cgi-bin/koha/acqui/parcel.pl%3Finvoiceid=[% invoiceid %]">Reopen it</a>.
+    </p>
+[% END %]
+
 <div id="acqui_receive_receivelist">
     <h3>Already received</h3>
 
                             Can't cancel receipt
                         </span>
                     [% ELSE %]
-                        <a href="/cgi-bin/koha/acqui/parcel.pl?invoice=[% loop_receive.invoice %]&booksellerid=[% booksellerid %]&datereceived=[% datereceived %]&op=cancelreceipt&ordernumber=[% loop_receive.ordernumber %]">Cancel receipt</a>
+                        <a href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid %]&op=cancelreceipt&ordernumber=[% loop_receive.ordernumber %]">Cancel receipt</a>
                     [% END %]
                 </td>
             </tr>
index 5374c8c..616139c 100644 (file)
    <div id="bd">
        <div id="yui-main">
        <div class="yui-b">
-       
+
+[% IF ( error_failed_to_create_invoice ) %]
+    <div id="error" class="dialog error">
+        <p>An error has occured. Invoice cannot be created.</p>
+    </div>
+[% END %]
 <h1>Receive shipment from vendor <a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% booksellerid %]">[% name %]</a></h1>
 
 [% IF ( count ) %]
                 [% searchresult.number %]
             </td>
             <td>
-                <a href="/cgi-bin/koha/acqui/parcel.pl?type=intra&amp;booksellerid=[% booksellerid |url %]&amp;datereceived=[% searchresult.raw_datereceived |url %][% IF ( searchresult.code ) %]&amp;invoice=[% searchresult.code |url %][% END %]">
-                    [% searchresult.datereceived %]</a>
+                [% searchresult.datereceived %]
             </td>
             <td>
-                [% IF ( searchresult.code ) %][% searchresult.code %][% ELSE %]<acronym title="not available">n/a</acronym>[% END %]
+                [% IF ( searchresult.code ) %]
+                    <a href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% searchresult.invoiceid %]">[% searchresult.code %]</a>
+                [% ELSE %]
+                    <acronym title="not available">n/a</acronym>
+                [% END %]
             </td>
             <td>
                 [% searchresult.reccount %]
 [% END %]
 
     <div id="parcels_new_parcel">
-        <form method="get" action="parcel.pl">
+        <form method="get" action="parcels.pl">
     <fieldset class="rows">
     <legend>Receive a new shipment</legend>
        <ol> <li>
             <label for="freight">Shipping:</label>
             <input type="text" size="20" id="freight" name="freight" />
         </li> -->
-         <li><label for="datereceived">Shipment date: </label>
-            <input type="text" id="datereceived" name="datereceived"  maxlength="10" size="10"  value="[% datereceived_today %]" class="datepicker" />
-                               <div class="hint">[% INCLUDE 'date-format.inc' %]</div> </li>
+         <li>
+            <label for="shipmentdate">Shipment date: </label>
+            <input type="text" id="shipmentdate" name="shipmentdate" maxlength="10" size="10" value="[% shipmentdate_today %]" class="datepicker" />
+            <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
+        </li>
+        <li>
+            <label for="shipmentcost">Shipment cost: </label>
+            <input type="text" id="shipmentcost" name="shipmentcost" size="10" />
+        </li>
+        <li>
+            <label for="shipmentcost_budgetid">Budget: </label>
+            <select id="shipmentcost_budgetid" name="shipmentcost_budgetid">
+                <option value="">No budget</option>
+                [% FOREACH budget IN budgets %]
+                    <option value="[% budget.budget_id %]">[% budget.budget_name %]</option>
+                [% END %]
+            </select>
+        </li>
                </ol>
     </fieldset>
             <fieldset class="action"><input type="submit" class="button" value="Next" /> <a class="cancel" href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% booksellerid %]">Cancel</a></fieldset>
             <li><label for="datefrom">From:</label><input type="text" size="9" id="datefrom" name="datefrom" value="[% datefrom %]" /><br /> 
                 <label for="dateto">To:</label><input type="text" size="9" id="dateto" name="dateto" value="[% dateto %]" /></li>
             <li><label for="orderby">Sort by :</label><select name="orderby" id="orderby">
-                <option value="aqorders.booksellerinvoicenumber">Invoice number</option>
-                <option value="datereceived"> Date received</option>
-                <option value="datereceived desc"> Date received reverse</option>
-                <option value="aqorders.booksellerinvoicenumber desc"> Invoice number reverse</option>
+                <option value="invoicenumber">Invoice number</option>
+                <option value="shipmentdate">Shipment date</option>
+                <option value="shipmentdate desc">Shipment date reverse</option>
+                <option value="invoicenumber desc">Invoice number reverse</option>
                 </select><br />
                 <label for="resultsperpage">Results per page :</label><select name="resultsperpage" id="resultsperpage">
                 <option value="20">20</option>
index d78a244..1d6255d 100644 (file)
@@ -42,7 +42,6 @@
        <th> Itemtype </th>
        <th> Received </th>
     <th> Unit price </th>
-    <th> Freight per item </th>
     <th> Date ordered </th>
     <th> Date received </th>
        <th> Subtotal </th>
            [% order.title %]
        </td>
        <td class="cell">
-            <a href="/cgi-bin/koha/acqui/orderreceive.pl?ordernumber=[% order.ordernumber %]&amp;biblio=[% order.biblionumber %]&amp;invoice=[% order.booksellerinvoicenumber %]&amp;booksellerid=[% order.booksellerid %]&amp;catview=yes">[% order.ordernumber %]</a>
+            <a href="/cgi-bin/koha/acqui/orderreceive.pl?ordernumber=[% order.ordernumber %]&amp;biblio=[% order.biblionumber %]&amp;invoiceid=[% order.invoiceid %]">[% order.ordernumber %]</a>
        </td>
        <td class="cell">
            <a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% order.booksellerid %]">[% order.booksellerid %]</a>
        </td>
        <td class="cell">
-           <a href="/cgi-bin/koha/acqui/parcel.pl?invoice=[% order.booksellerinvoicenumber %]&amp;booksellerid=[% order.booksellerid %]&amp;datereceived=[% order.datereceived %]">[% order.booksellerinvoicenumber %]</a>
+           <a href="/cgi-bin/koha/acqui/invoice.pl?invoiceid=[% order.invoiceid %]">[% order.invoicenumber %]</a>
        </td>
        <td class="cell">
            [% order.itype %]
@@ -77,9 +76,6 @@
        <td class="cell" align="right">
            [% order.unitprice %]
        </td>
-       <td class="cell" align="right">
-           [% order.freight %]
-       </td>
        <td class="cell" align="right">
            [% order.entrydate | $KohaDates %]
        </td>
            [% order.datereceived | $KohaDates %]
        </td>
        <td class="cell" align="right">
-           [% order.subtotal %]
+           [% order.rowtotal %]
        </td>
     </tr>
 [% END %]
     <tfoot>
-        <tr valign="top">
-        <td> Total </td>
-        <td> </td>
-        <td> </td>
-        <td> </td>
-        <td> </td>
-        <td> </td>
-        <td> </td>
-        <td> </td>
-       <td> </td>
-       <td> </td>
-        <td align="right">
-               [% total %]
-       </td>
+        [% IF shipmentcosts.size %]
+            <tr valign="top">
+                <td colspan="9"> Sub total </td>
+                <td align="right"> [% subtotal %] </td>
+            </tr>
+            [% FOREACH shipmentcost IN shipmentcosts %]
+                <tr>
+                    <td></td>
+                    <td colspan="8">Shipment cost for invoice [% shipmentcost.invoicenumber %]</td>
+                    <td class="total">[% shipmentcost.shipmentcost %]</td>
+                </tr>
+            [% END %]
+        [% END %]
+        <tr>
+            <td colspan="9">TOTAL</td>
+            <td class="total">[% total %]</td>
         </tr>
     </tfoot>
-
 </table>
 
 </div>
index 9ff3056..531b878 100644 (file)
@@ -407,6 +407,22 @@ Circulation:
                   yes: Allow
                   no: "Don't allow"
             - holds to be suspended from the OPAC.
+        -
+            - pref: decreaseLoanHighHolds
+              choices:
+                  yes: Enable
+                  no:  "Don't enable"
+            - the reduction of loan period for items with number of holds above the threshold specified in decreaseLoanHighHoldsValue
+        -
+            - A loan should be reduced by
+            - pref: decreaseLoanHighHoldsDuration
+              class: integer
+            - days, when decreaseLoanHighHoldsValue threshold is reached (if decreaseLoanHighHolds is enabled)
+        -
+            - A loan should be reduced by decreaseLoanHighHoldsDuration when
+            - pref: decreaseLoanHighHoldsValue
+              class: integer
+            - holds have been places (if decreaseLoanHighHolds is enables)
     Fines Policy:
         -
             - Calculate fines based on days overdue
index 71f8fe4..5234e28 100644 (file)
 
             [% IF ITEM_DAT.dateaccessioned %]
                 <li><span class="label">Accession date:</span>
-                    [% IF ( CAN_user_acquisition_order_receive && ITEM_DAT.booksellerinvoicenumber ) %]
-                        <a href="/cgi-bin/koha/acqui/parcel.pl?booksellerid=[% ITEM_DAT.booksellerid %]&amp;invoice=[% ITEM_DAT.booksellerinvoicenumber %]&amp;datereceived=[% ITEM_DAT.datereceived %]">[% ITEM_DAT.dateaccessioned | $KohaDates %]</a>
+                    [% IF ( CAN_user_acquisition_order_receive && ITEM_DAT.invoiceid ) %]
+                        <a href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% ITEM_DAT.invoiceid %]">[% ITEM_DAT.dateaccessioned | $KohaDates %]</a>
                     [% ELSE %]
                         [% ITEM_DAT.dateaccessioned | $KohaDates %]
                     [% END %]
                 </li>
             [% END %]
-            [% IF ( ITEM_DAT.booksellerinvoicenumber ) %]
+            [% IF ( ITEM_DAT.invoicenumber ) %]
                 <li><span class="label">Invoice number:</span>
-                    [% ITEM_DAT.booksellerinvoicenumber %]
+                    [% ITEM_DAT.invoicenumber %]
                 </li>
             [% END %]
 
index 5f8fb99..db17ced 100644 (file)
@@ -364,8 +364,19 @@ function validate1(date) {
 [% IF ( ITEM_LOST ) %]
     <li>This item has been lost with a status of "[% ITEM_LOST %]". Check out anyway?</li>
 [% END %]
+
+[% IF  HIGHHOLDS %]
+       <li>High demand item. Loan period shortened to [% HIGHHOLDS.duration %] days (due [% HIGHHOLDS.returndate %]). Check out anyway?</li>
+[% END %]
 </ul>
 
+[% IF HIGHHOLDS %]
+       <script language="JavaScript" type="text/javascript">
+       $(document).ready(function() {
+               $("input[name=duedatespec]:hidden").val('[% HIGHHOLDS.returndate %]');
+       });
+       </script>
+[% END %]
 <form method="post" action="/cgi-bin/koha/circ/circulation.pl" autocomplete="off">
 
 [% IF ( RESERVED ) %]
index 102a6ee..2e15834 100644 (file)
@@ -33,7 +33,7 @@
                <form action="/cgi-bin/koha/reports/dictionary.pl" method="post">
         <input type="hidden" name="phase" value="View Dictionary" />
                [% IF ( areas ) %]
-                       Filter by area <select name="areas">
+                       Filter by area <select name="area">
                        <option value="">All</option>
                        [% FOREACH area IN areas %]
                            [% IF ( area.selected ) %]
 <ol><li><input type="hidden" name="phase" value="New Term step 3" />
 <input type="hidden" name="definition_name" value="[% definition_name %]" />
 <input type="hidden" name="definition_description" value="[% definition_description %]" />
-<label for="areas">Select table </label><select name="areas" id="areas">
+<label for="area">Select table </label><select name="area" id="area">
 [% FOREACH area IN areas %]     
 <option value="[% area.id %]">[% area.name %]</option>                  
 [% END %]                
index 21d8235..aa6a627 100644 (file)
 
 <script type="text/javascript">
 //<![CDATA[
+var group_subgroups = {};
+var no_subgroup_label = _( "(None)" );
+function load_group_subgroups () {
+    var group = $("#group").val();
+    var sg = $("#subgroup");
+    var has_subgroups = false;
+    $(sg).empty().append('<option value="">' + no_subgroup_label + '</option>');
+    if (group) {
+        $.each( group_subgroups[group], function(index, value) {
+                has_subgroups = true;
+            $('<option value="' + value[0] + '">' + value[1] + '</option>').appendTo(sg);
+        } );
+    }
+    if (has_subgroups) {
+        $(sg).show();
+    } else {
+        $(sg).hide();
+    }
+}
 $(document).ready(function(){
 [% IF ( showsql ) %]
     $("#sql").focus(function() {
@@ -138,6 +157,9 @@ canned reports and writing custom SQL reports.</p>
   <th>ID</th>
   <th>Report name</th>
   <th>Type</th>
+  <th>Area</th>
+  <th>Group</th>
+  <th>Subgroup</th>
   <th>Notes</th>
   <th>Author</th>
   <th>Creation date</th>
@@ -155,6 +177,9 @@ canned reports and writing custom SQL reports.</p>
 <td>[% savedreport.id %]</td>
 <td>[% savedreport.report_name %]</td>
 <td>[% savedreport.type %]</td>
+<td>[% savedreport.areaname %]</td>
+<td>[% savedreport.groupname %]</td>
+<td>[% savedreport.subgroupname %]</td>
 <td>[% savedreport.notes %]</td>
 <td>[% savedreport.borrowersurname %][% IF ( savedreport.borrowerfirstname ) %], [% savedreport.borrowerfirstname %][% END %] ([% savedreport.borrowernumber %])</td>
 <td>[% savedreport.date_created %]</td>
@@ -219,7 +244,7 @@ canned reports and writing custom SQL reports.</p>
 <form action="/cgi-bin/koha/reports/guided_reports.pl">
 <fieldset class="rows">
 <legend>Step 1 of 6: Choose a module to report on,[% IF (usecache) %] Set cache expiry, [% END %] and Choose report visibility </legend>
-<ol><li><label for="areas">Choose: </label><select name="areas" id="areas">
+<ol><li><label for="area">Choose: </label><select name="area" id="area">
 [% FOREACH area IN areas %]
 <option value="[% area.id %]">[% area.name %]</option>
 [% END %]
@@ -485,12 +510,38 @@ canned reports and writing custom SQL reports.</p>
 <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
 <input type="hidden" name="sql" value="[% sql |html %]" />
 <input type="hidden" name="type" value="[% type %]" />
+<input type="hidden" name="area" value="[% area %]" />
 <input type="hidden" name="public" value="[% public %]" />
 <input type="hidden" name="cache_expiry" value="[% cache_expiry %]" />
 <fieldset class="rows">
 <legend>Save your custom report</legend>
 <ol>
     <li><label for="reportname">Report name: </label><input type="text" id="reportname" name="reportname" /></li>
+    [% IF groups_with_subgroups %]
+    <li><label for="group">Report group: </label><select name="group" id="group" onChange="load_group_subgroups();">
+        [% FOR g IN groups_with_subgroups %]
+            [% IF g.selected %]
+    <option value="[% g.id %]" selected>[% g.name %]</option>
+            [% ELSE %]
+    <option value="[% g.id %]">[% g.name %]</option>
+            [% END %]
+    <script type="text/javascript">
+        var g_sg = new Array();
+            [% FOR sg IN g.subgroups %]
+        g_sg.push(["[% sg.id %]", "[% sg.name %]"]);
+                [% IF sg.selected %]
+        $(document).ready(function() {
+            $("#subgroup").val("[% sg.id %]");
+        });
+                [% END %]
+            [% END %]
+        group_subgroups["[% g.id %]"] = g_sg;
+    </script>
+        [% END %]
+    </select></li>
+    <li><label for="subgroup">Report subgroup: </label><select name="subgroup" id="subgroup">
+    </select></li>
+    [% END %]
     <li><label for="notes">Notes:</label> <textarea name="notes" id="notes"></textarea></li>
 </ol></fieldset>
 <fieldset class="action"><input type="hidden" name="phase" value="Save Report" />
@@ -553,6 +604,11 @@ canned reports and writing custom SQL reports.</p>
 [% END %]
 
 [% IF ( create ) %]
+<script type="text/javascript">
+$(document).ready(function() {
+    load_group_subgroups();
+});
+</script>
 <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
 <fieldset class="rows">
 <legend>Create report from SQL</legend>
@@ -561,6 +617,31 @@ canned reports and writing custom SQL reports.</p>
         [% IF ( reportname ) %]<input type="text" id="reportname" name="reportname" value="[% reportname %]" />
         [% ELSE %]<input type="text" id="reportname" name="reportname" />[% END %] 
     </li>
+    [% IF groups_with_subgroups %]
+    <li><label for="group">Report group: </label><select name="group" id="group" onChange="load_group_subgroups();">
+        [% FOR g IN groups_with_subgroups %]
+            [% IF g.selected %]
+    <option value="[% g.id %]" selected>[% g.name %]</option>
+            [% ELSE %]
+    <option value="[% g.id %]">[% g.name %]</option>
+            [% END %]
+    <script type="text/javascript">
+        var g_sg = new Array();
+            [% FOR sg IN g.subgroups %]
+        g_sg.push(["[% sg.id %]", "[% sg.name %]"]);
+                [% IF sg.selected %]
+        $(document).ready(function() {
+            $("#subgroup").val("[% sg.id %]");
+        });
+                [% END %]
+            [% END %]
+        group_subgroups["[% g.id %]"] = g_sg;
+    </script>
+        [% END %]
+    </select></li>
+    <li><label for="subgroup">Report subgroup: </label><select name="subgroup" id="subgroup">
+    </select></li>
+    [% END %]
 [% IF (public) %]
   <li><label for="public">Report is public:</label><select id="public" name="public"> <option value="0">No (default)</option> <option value="1" selected="selected">Yes</public> </select></li>
 [% ELSE %]
@@ -645,6 +726,11 @@ Sub report:<select name="subreport">
 [% END %]
 
 [% IF ( editsql ) %]
+<script type="text/javascript">
+$(document).ready(function() {
+    load_group_subgroups();
+});
+</script>
 <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post">
 <input type="hidden" name="phase" value="Update SQL" />
 <input type="hidden" name="id" value="[% id %]"/>
@@ -652,6 +738,31 @@ Sub report:<select name="subreport">
 <legend>Edit SQL report</legend>
 <ol>
 <li><label for="reportname">Report name:</label><input type="text" id="reportname" name="reportname" value="[% reportname %]" size="50" /></li>
+    [% IF groups_with_subgroups %]
+    <li><label for="group">Report group: </label><select name="group" id="group" onChange="load_group_subgroups();">
+        [% FOR g IN groups_with_subgroups %]
+            [% IF g.selected %]
+    <option value="[% g.id %]" selected>[% g.name %]</option>
+            [% ELSE %]
+    <option value="[% g.id %]">[% g.name %]</option>
+            [% END %]
+    <script type="text/javascript">
+        var g_sg = new Array();
+            [% FOR sg IN g.subgroups %]
+        g_sg.push(["[% sg.id %]", "[% sg.name %]"]);
+                [% IF sg.selected %]
+        $(document).ready(function() {
+            $("#subgroup").val("[% sg.id %]");
+        });
+                [% END %]
+            [% END %]
+        group_subgroups["[% g.id %]"] = g_sg;
+    </script>
+        [% END %]
+    </select></li>
+    <li><label for="subgroup">Report subgroup: </label><select name="subgroup" id="subgroup">
+    </select></li>
+    [% END %]
 [% IF (public) %]
   <li><label for="public">Report is public:</label><select id="public" name="public"> <option value="0">No (default)</option> <option value="1" selected="selected">Yes</public> </select></li>
 [% ELSE %]
@@ -719,12 +830,43 @@ Sub report:<select name="subreport">
 
 [% IF ( saved1 ) %]
 <div id="saved-reports-filter">
+<script type="text/javascript">
+$(document).ready(function() {
+    no_subgroup_label = _( "-- All --" );
+    load_group_subgroups();
+});
+</script>
 <form action="/cgi-bin/koha/reports/guided_reports.pl" method="get">
   <input type="hidden" name="phase" value="Use saved" />
   <input type="hidden" name="filter_set" value="1" />
   <fieldset class="brief">
   <h3>Filter</h3>
   <ol>
+    <li><label for="group">Choose Group and Subgroup: </label>
+    <select name="group" id="group" onChange="load_group_subgroups();">
+        <option value="">-- All --</option>
+    [% FOR g IN groups_with_subgroups %]
+        [% IF g.selected %]
+        <option value="[% g.id %]" selected>[% g.name %]</option>
+        [% ELSE %]
+        <option value="[% g.id %]">[% g.name %]</option>
+        [% END %]
+        <script type="text/javascript">
+            var g_sg = new Array();
+        [% FOR sg IN g.subgroups %]
+            g_sg.push(["[% sg.id %]", "[% sg.name %]"]);
+            [% IF sg.selected %]
+            $(document).ready(function() {
+                $("#subgroup").val("[% sg.id %]");
+            });
+            [% END %]
+        [% END %]
+            group_subgroups["[% g.id %]"] = g_sg;
+        </script>
+    [% END %]
+    </select>
+    <select name="subgroup" id="subgroup"></select>
+    </li>
     <li><label for="filter_date">Date:</label> <input type="text" id="filter_date" name="filter_date" size="10" value="[% filter_date %]" class="datepicker" />
     <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
 
index a22b97b..7bc9feb 100644 (file)
@@ -16,7 +16,7 @@
 
 <h1>Subscription information for <i>[% bibliotitle %]</i></h1>
 <div id="action">
-    <a href="/cgi-bin/koha/serials/serials-home.pl?biblionumber=[% biblionumber %]">Subscriptions</a>
+    <a href="/cgi-bin/koha/serials/serials-search.pl?biblionumber=[% biblionumber %]">Subscriptions</a>
     <a href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=[% biblionumber %]">Back to biblio</a>
     <a href="/cgi-bin/koha/serials/serial-issues.pl?biblionumber=[% biblionumber %]&amp;selectview=full">Complete view</a>
 </div>
index a0cd35e..eaafc94 100644 (file)
 [% INCLUDE 'doc-head-open.inc' %]
 [% USE KohaDates %]
 <title>Koha &rsaquo; Serials [% biblionumber %]</title>
-<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
 [% INCLUDE 'doc-head-close.inc' %]
-<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.dataTables.min.js"></script>
-[% INCLUDE 'datatables-strings.inc' %]
-<script type="text/javascript" src="[% themelang %]/js/datatables.js"></script>
-<script type="text/javascript">
-//<![CDATA[
- $(document).ready(function() {
-    var srlt = $("#srlt").dataTable($.extend(true, {}, dataTablesDefaults, {
-        "aoColumnDefs": [
-            { "aTargets": [ -1, -2, -3 ], "bSortable": false, "bSearchable": false },
-        ],
-        "sPaginationType": "four_button"
-    } ) );
-
-    srlt.fnAddFilters("filter", 750);
- });
- //]]>
-</script>
 </head>
 <body id="ser_serials-home" class="ser">
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'serials-search.inc' %]
 
-<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; [% IF ( done_searched ) %]<a href="/cgi-bin/koha/serials/serials-home.pl">Serials</a> &rsaquo; Search results[% ELSE %]Serials [% END %] </div>
+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; Serials </div>
 
 <div id="doc3" class="yui-t2">
-   
-   <div id="bd">
-       <div id="yui-main">
-       <div class="yui-b">
-       [% INCLUDE 'serials-toolbar.inc' %]
-       
-[% IF ( information ) %]
-Serials updated :
-<table>
-  <tr>
-    <th>
-      Serialseq
-    </th>
-    <th>
-      Status
-    </th>
-    <th>
-      Published date
-    </th>
-    <th>
-      Planned date
-    </th>
-    <th>
-      Notes
-    </th>
-  </tr>  
-[% FOREACH informatio IN information %]
-  <tr>
-    <td>
-      [% informatio.serialseq %]
-    </td>
-    <td>
-      [% informatio.status %]
-    </td>
-    <td>
-      [% informatio.publisheddate %]
-    </td>
-    <td>
-      [% informatio.planneddate %]
-    </td>
-    <td>
-      [% informatio.notes %]
-    </td>
-  </tr>  
-[% END %]
-</table>
-[% END %]
-        [% IF ( done_searched ) %]
-<h2>Serials subscriptions</h2>
-
-    <table id="srlt">
-       <thead>
-        <tr>
-            <th>ISSN</th>
-            <th>Title</th>
-            <th> Notes </th>
-            <th>Library</th>
-            <th>Call number</th>
-            <th>Expiration date</th>
-            [% IF ( routing && CAN_user_serials_routing ) %]
-              <th>Routing list</th>
-            [% END %]        
-            <th>&nbsp;</th>
-            <th>&nbsp;</th>
-        </tr>
-       </thead>
-    <tfoot>
-        <tr>
-            <td><input type="text" class="filter" data-column_num="0" placeholder="Search ISSN" /></td>
-            <td><input type="text" class="filter" data-column_num="1" placeholder="Search title" /></td>
-            <td><input type="text" class="filter" data-column_num="2" placeholder="Search notes" /></td>
-            <td><input type="text" class="filter" data-column_num="3" placeholder="Search library" /></td>
-            <td><input type="text" class="filter" data-column_num="4" placeholder="Search callnumber" /></td>
-            <td><input type="text" class="filter" data-column_num="5" placeholder="Search expiration date" /></td>
-            [% IF ( routing && CAN_user_serials_routing ) %]<td></td>[% END %]
-            <td></td>
-            <td></td>
-        </tr>
-    </tfoot>
-       <tbody> 
-        [% FOREACH subscription IN subscriptions %]
-            <tr>
-                <td>
-                [% IF ( subscription.issn ) %][% subscription.issn %]
-                [% END %]
-                </td>
-                <td><a href="/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=[% subscription.subscriptionid %]" class="button" title="subscription detail">[% subscription.title |html %]</a>
-                </td>
-                <td>[% IF ( subscription.notes ) %][% subscription.notes %][% END %]
-                [% IF ( subscription.internalnotes ) %]([% subscription.internalnotes %])[% END %]
-                </td>
-                <td>
-                  [% IF ( subscription.branchname ) %][% subscription.branchname %][% END %]
-                </td>
-                <td>
-                  [% IF ( subscription.callnumber ) %][% subscription.callnumber %][% END %]
-                </td>
-                <td>
-                  [% IF ( subscription.enddate ) %][% subscription.enddate | $KohaDates %][% END %]
-                </td>
-                [% IF ( routing && CAN_user_serials_routing ) %]
-                <td>
-                    [% IF ( subscription.cannotedit ) %]
-                        &nbsp;
-                    [% ELSE %]
-                        [% IF ( subscription.routingedit ) %]
-                            <a href="/cgi-bin/koha/serials/routing.pl?subscriptionid=[% subscription.subscriptionid %]">Edit</a>
-                            ([% subscription.routingedit %])
-                        [% ELSE %]
-                            <a href="/cgi-bin/koha/serials/routing.pl?subscriptionid=[% subscription.subscriptionid %]&amp;op=new">New</a>
-                        [% END %]
-                    [% END %]
-                </td>
-                [% END %]
-                <td><a href="/cgi-bin/koha/serials/serials-collection.pl?subscriptionid=[% subscription.subscriptionid %]">Issue history</a>
-                </td>
-                <td>
-                [% IF ( subscription.cannotedit ) %]
-                  &nbsp;        
-                [% ELSE %]
-                  [% IF ( CAN_user_serials_receive_serials ) %]<a href="/cgi-bin/koha/serials/serials-edit.pl?subscriptionid=[% subscription.subscriptionid %]&amp;serstatus=1,3,7">Serial receive</a>[% END %]
-                [% END %]
-                </td>
-            </tr>
-        [% END %]
-       </tbody>
-    </table>
-    
-        [% END %]
-
-</div>
-</div>
-
-<div class="yui-b">
-[% INCLUDE 'serials-menu.inc' %]
-</div>
+<div id="bd">
+  <div id="yui-main">
+    <div class="yui-b">
+      [% INCLUDE 'serials-toolbar.inc' %]
+    </div>
+  </div>
+  <div class="yui-b">
+    [% INCLUDE 'serials-menu.inc' %]
+  </div>
 </div>
 [% INCLUDE 'intranet-bottom.inc' %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt
new file mode 100644 (file)
index 0000000..b5e7f54
--- /dev/null
@@ -0,0 +1,185 @@
+[% INCLUDE 'doc-head-open.inc' %]
+[% USE KohaDates %]
+<title>Koha &rsaquo; Serials [% biblionumber %]</title>
+<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
+[% INCLUDE 'doc-head-close.inc' %]
+<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.dataTables.min.js"></script>
+[% INCLUDE 'datatables-strings.inc' %]
+<script type="text/javascript" src="[% themelang %]/js/datatables.js"></script>
+<script type="text/javascript">
+//<![CDATA[
+ $(document).ready(function() {
+    var srlt = $("#srlt").dataTable($.extend(true, {}, dataTablesDefaults, {
+        "aoColumnDefs": [
+            { "aTargets": [ -1, -2, -3 ], "bSortable": false, "bSearchable": false },
+        ],
+        "sPaginationType": "four_button"
+    } ) );
+
+    srlt.fnAddFilters("filter", 750);
+ });
+ //]]>
+</script>
+</head>
+<body id="ser_serials-home" class="ser">
+[% INCLUDE 'header.inc' %]
+[% INCLUDE 'serials-search.inc' %]
+
+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; [% IF ( done_searched ) %]<a href="/cgi-bin/koha/serials/serials-home.pl">Serials</a> &rsaquo; Search results[% ELSE %]Serials [% END %] </div>
+
+<div id="doc3" class="yui-t2">
+  <div id="bd">
+    <div id="yui-main">
+      <div class="yui-b">
+      [% INCLUDE 'serials-toolbar.inc' %]
+
+      <h2>Serials subscriptions</h2>
+
+      <div id="advsearch">
+        <form action="/cgi-bin/koha/serials/serials-search.pl" method="get">
+          <fieldset class="rows">
+          <legend onclick="$('#advsearch_form').slideToggle(400);">
+              <a id="unfold_advsearch" style="cursor:pointer">Search subscriptions</a>
+          </legend>
+            [% IF ( done_searched ) %]
+              <div id="advsearch_form" style="display:none">
+            [% ELSE %]
+              <div>
+            [% END %]
+              <ol>
+                <li>
+                  <label for="issn">ISSN:</label>
+                  <input type="text" id="issn" name="ISSN_filter" value="[% ISSN_filter %]" />
+                </li>
+                <li>
+                  <label for="title">Title:</label>
+                  <input type="text" id="title" name="title_filter" value="[% title_filter %]" />
+                </li>
+                [% IF ( marcflavour == "UNIMARC" ) %]
+                <li>
+                  <label for="ean">EAN:</label>
+                  <input type="text" id="ean" name="EAN_filter" value="[% EAN_filter %]" />
+                </li>
+                [% END %]
+                <li>
+                  <label for="publisher">Publisher:</label>
+                  <input type="text" id="publisher" name="publisher_filter" value="[% publisher_filter %]" />
+                </li>
+                <li>
+                  <label for="bookseller">Bookseller:</label>
+                  <input type="text" id="bookseller" name="bookseller_filter" value="[% bookseller_filter %]" />
+                </li>
+                <li>
+                  <label for="branch">Branch:</label>
+                  <select id="branch" name="branch_filter">
+                    <option value="">All</option>
+                    [% FOREACH branch IN branches_loop %]
+                      [% IF ( branch.selected ) %]
+                        <option selected="selected" value="[% branch.branchcode %]">[% branch.branchname %]</option>
+                      [% ELSE %]
+                        <option value="[% branch.branchcode %]">[% branch.branchname %]</option>
+                      [% END %]
+                    [% END %]
+                  </select>
+                </li>
+              </ol>
+              <input type="hidden" name="searched" value="1" />
+              <fieldset class="action">
+                <input type="submit" value="Search" />
+              </fieldset>
+            </div>
+          </fieldset>
+        </form>
+      </div>
+
+      [% IF ( done_searched ) %]
+        [% IF ( subscriptions ) %]
+          <table id="srlt">
+            <thead>
+              <tr>
+                  <th>ISSN</th>
+                  <th>Title</th>
+                  <th> Notes </th>
+                  <th>Library</th>
+                  <th>Call number</th>
+                  <th>Expiration date</th>
+                  [% IF ( routing && CAN_user_serials_routing ) %]
+                    <th>Routing list</th>
+                  [% END %]
+                  <th>&nbsp;</th>
+                  <th>&nbsp;</th>
+              </tr>
+            </thead>
+            <tfoot>
+              <tr>
+                <td><input type="text" class="filter" data-column_num="0" placeholder="Search ISSN" /></td>
+                <td><input type="text" class="filter" data-column_num="1" placeholder="Search title" /></td>
+                <td><input type="text" class="filter" data-column_num="2" placeholder="Search notes" /></td>
+                <td><input type="text" class="filter" data-column_num="3" placeholder="Search library" /></td>
+                <td><input type="text" class="filter" data-column_num="4" placeholder="Search callnumber" /></td>
+                <td><input type="text" class="filter" data-column_num="5" placeholder="Search expiration date" /></td>
+                [% IF ( routing && CAN_user_serials_routing ) %]<td></td>[% END %]
+                <td></td>
+                <td></td>
+              </tr>
+            </tfoot>
+            <tbody>
+              [% FOREACH subscription IN subscriptions %]
+                <tr>
+                  <td>
+                  [% IF ( subscription.issn ) %][% subscription.issn %]
+                  [% END %]
+                  </td>
+                  <td><a href="/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=[% subscription.subscriptionid %]" class="button" title="subscription detail">[% subscription.title |html %]</a>
+                  </td>
+                  <td>[% IF ( subscription.notes ) %][% subscription.notes %][% END %]
+                  [% IF ( subscription.internalnotes ) %]([% subscription.internalnotes %])[% END %]
+                  </td>
+                  <td>
+                    [% IF ( subscription.branchname ) %][% subscription.branchname %][% END %]
+                  </td>
+                  <td>
+                    [% IF ( subscription.callnumber ) %][% subscription.callnumber %][% END %]
+                  </td>
+                  <td>
+                    [% IF ( subscription.enddate ) %][% subscription.enddate | $KohaDates %][% END %]
+                  </td>
+                  [% IF ( routing && CAN_user_serials_routing ) %]
+                  <td>
+                    [% IF ( subscription.cannotedit ) %]
+                      &nbsp;
+                    [% ELSE %]
+                      [% IF ( subscription.routingedit ) %]
+                        <a href="/cgi-bin/koha/serials/routing.pl?subscriptionid=[% subscription.subscriptionid %]">Edit</a>
+                        ([% subscription.routingedit %])
+                      [% ELSE %]
+                        <a href="/cgi-bin/koha/serials/routing.pl?subscriptionid=[% subscription.subscriptionid %]&amp;op=new">New</a>
+                      [% END %]
+                    [% END %]
+                  </td>
+                  [% END %]
+                  <td><a href="/cgi-bin/koha/serials/serials-collection.pl?subscriptionid=[% subscription.subscriptionid %]">Issue history</a>
+                  </td>
+                  <td>
+                  [% IF ( subscription.cannotedit ) %]
+                    &nbsp;
+                  [% ELSE %]
+                    [% IF ( CAN_user_serials_receive_serials ) %]<a href="/cgi-bin/koha/serials/serials-edit.pl?subscriptionid=[% subscription.subscriptionid %]&amp;serstatus=1,3,7">Serial receive</a>[% END %]
+                  [% END %]
+                  </td>
+                </tr>
+              [% END %]
+            </tbody>
+          </table>
+        [% ELSE %]
+          There is no subscription for your search.
+        [% END %]
+      [% END %]
+    </div>
+  </div>
+
+  <div class="yui-b">
+    [% INCLUDE 'serials-menu.inc' %]
+  </div>
+</div>
+[% INCLUDE 'intranet-bottom.inc' %]
index 2c756e8..e13c2e2 100644 (file)
@@ -2706,6 +2706,10 @@ ul.ui-tabs-nav li {
     display: inline-block;
 }
 
+.authlink {
+    padding-left: 0.25em;
+}
+
 /* jQuery UI Datepicker */
 .ui-datepicker table {width: 100%; font-size: .9em; border : 0; border-collapse: collapse; margin:0 0 .4em; }
 .ui-datepicker th { background : transparent none; padding: .7em .3em; text-align: center; font-weight: bold; border: 0;  }
index 6ed2b86..cca5d0d 100644 (file)
         <select name="idx">
             <option value="kw">Keyword</option>
             <option value="su,wrdl">Subject</option>
-[% IF ( search_boxes_loo.expanded_options ) %]
+[% IF ( expanded_options ) %]
             <option value="su,phr">&nbsp;&nbsp;&nbsp;&nbsp; Subject phrase</option>
+            <option value="su-br">&nbsp;&nbsp;&nbsp;&nbsp; Subject and broader terms</option>
+            <option value="su-na">&nbsp;&nbsp;&nbsp;&nbsp; Subject and narrower terms</option>
+            <option value="su-rl">&nbsp;&nbsp;&nbsp;&nbsp; Subject and related terms</option>
 [% END %]
             <option value="ti">Title</option>
 [% IF ( expanded_options ) %]
index a77e468..f740488 100644 (file)
@@ -360,11 +360,17 @@ YAHOO.util.Event.onContentReady("furtherm", function () {
 
     [% IF ( MARCAUTHORS ) %]
     <span class="results_summary"><span class="label">Additional authors:</span>
-                [% FOREACH MARCAUTHOR IN MARCAUTHORS %]
-                [% FOREACH MARCAUTHOR_SUBFIELDS_LOO IN MARCAUTHOR.MARCAUTHOR_SUBFIELDS_LOOP %][% MARCAUTHOR_SUBFIELDS_LOO.separator %]<a title="‡[% MARCAUTHOR_SUBFIELDS_LOO.code %] [% MARCAUTHOR_SUBFIELDS_LOO.value %]" href="/cgi-bin/koha/opac-search.pl?q=[% FOREACH link_loo IN MARCAUTHOR_SUBFIELDS_LOO.link_loop %][% link_loo.operator |url %][% link_loo.limit |url %]:[% link_loo.link |url %][% END %]">[% MARCAUTHOR_SUBFIELDS_LOO.value %]</a>[% END %] 
-        [% UNLESS ( loop.last ) %]|
-[% END %]
-                [% END %]
+        [% FOREACH MARCAUTHOR IN MARCAUTHORS %]
+            [% FOREACH MARCAUTHOR_SUBFIELDS_LOO IN MARCAUTHOR.MARCAUTHOR_SUBFIELDS_LOOP %]
+                [% MARCAUTHOR_SUBFIELDS_LOO.separator %]
+                <a title="‡[% MARCAUTHOR_SUBFIELDS_LOO.code %] [% MARCAUTHOR_SUBFIELDS_LOO.value %]"
+                    href="/cgi-bin/koha/opac-search.pl?q=[% FOREACH link_loo IN MARCAUTHOR_SUBFIELDS_LOO.link_loop %][% link_loo.operator |url %][% link_loo.limit |url %]:[% link_loo.link |url %][% END %]">[% MARCAUTHOR_SUBFIELDS_LOO.value %]</a>
+            [% END %]
+            [% IF (MARCAUTHOR.authoritylink) %]
+                <a class='authlink' href="/cgi-bin/koha/opac-authoritiesdetail.pl?authid=[% MARCAUTHOR.authoritylink %]"><img style="vertical-align:middle" height="15" width="15" src="/opac-tmpl/prog/images/filefind.png"></a>
+            [% END %]
+            [% UNLESS ( loop.last ) %]|[% END %]
+        [% END %]
     </span>
     [% END %]
 
@@ -418,12 +424,20 @@ YAHOO.util.Event.onContentReady("furtherm", function () {
     [% END %]
 
     [% IF ( MARCSUBJCTS ) %]
-            <span class="results_summary"><span class="label">Subject(s):</span> 
-                [% FOREACH MARCSUBJCT IN MARCSUBJCTS %]
-                    [% FOREACH MARCSUBJECT_SUBFIELDS_LOO IN MARCSUBJCT.MARCSUBJECT_SUBFIELDS_LOOP %]
-                        [% MARCSUBJECT_SUBFIELDS_LOO.separator %]<a title="$[% MARCSUBJECT_SUBFIELDS_LOO.code %] [% MARCSUBJECT_SUBFIELDS_LOO.value %]" href="/cgi-bin/koha/opac-search.pl?q=[% FOREACH link_loo IN MARCSUBJECT_SUBFIELDS_LOO.link_loop %][% link_loo.operator |url %][% link_loo.limit |url %]:[% link_loo.link |url %][% END %]">[% MARCSUBJECT_SUBFIELDS_LOO.value %]</a>[% END %]
-        [% IF ( loop.last ) %][% ELSE %]|[% END %]
-                [% END %]</span>
+        <span class="results_summary">
+            <span class="label">Subject(s):</span>
+            [% FOREACH MARCSUBJCT IN MARCSUBJCTS %]
+                [% subjectsloop = loop %]
+                [% FOREACH SUBFIELD IN MARCSUBJCT.MARCSUBJECT_SUBFIELDS_LOOP %]
+                    [% SUBFIELD.separator %]
+                    <a title="$[% SUBFIELD.code %] [% SUBFIELD.value %]" href="/cgi-bin/koha/opac-search.pl?q=[% FOREACH link_loo IN SUBFIELD.link_loop %][% link_loo.operator |url %][% link_loo.limit |url %]:[% link_loo.link |url %][% END %]" onclick="showSubjects(this, [% subjectsloop.count %], [% loop.count %]); return false;">[% SUBFIELD.value %]</a>
+                [% END %]
+                [% IF (MARCSUBJCT.authoritylink) %]
+                    <a class="authlink" href="/cgi-bin/koha/opac-authoritiesdetail.pl?authid=[% MARCSUBJCT.authoritylink %]"><img style="vertical-align:middle" height="15" width="15" src="/opac-tmpl/prog/images/filefind.png" /></a>
+                [% END %]
+                [% UNLESS ( loop.last ) %] | [% END %]
+            [% END %]
+        </span>
     [% ELSE %]
     [% IF ( subjects ) %]<span class="results_summary"><span class="label">Subject(s):</span> [% FOREACH subject IN subjects %]<a href="/cgi-bin/koha/opac-search.pl?q=su:[% subject.subject |url %]">[% subject.subject %]</a> | [% END %]</span>[% END %]
     [% END %]
index 8d54517..4fcd12f 100644 (file)
                 </xsl:with-param>
             </xsl:call-template>
             </a>
+            <xsl:if test="marc:subfield[@code=9]">
+                <a class='authlink'>
+                    <xsl:attribute name="href">/cgi-bin/koha/opac-authoritiesdetail.pl?authid=<xsl:value-of select="marc:subfield[@code=9]"/></xsl:attribute>
+                    <img style="vertical-align:middle" height="15" width="15" src="/opac-tmpl/prog/images/filefind.png"/>
+                </a>
+            </xsl:if>
             <xsl:choose>
             <xsl:when test="position()=last()"></xsl:when>
             <xsl:otherwise> | </xsl:otherwise>
                     <xsl:text>]</xsl:text>
                 </xsl:if>
             </a>
+            <xsl:if test="marc:subfield[@code=9]">
+                <a class='authlink'>
+                    <xsl:attribute name="href">/cgi-bin/koha/opac-authoritiesdetail.pl?authid=<xsl:value-of select="marc:subfield[@code=9]"/></xsl:attribute>
+                    <img style="vertical-align:middle" height="15" width="15" src="/opac-tmpl/prog/images/filefind.png"/>
+                </a>
+            </xsl:if>
         </xsl:for-each>
         <xsl:text>.</xsl:text>
     </xsl:template>
index 0460880..0d951f7 100644 (file)
             </xsl:otherwise>
         </xsl:choose>
         <xsl:call-template name="nameABCDQ"/></a>
+        <xsl:if test="marc:subfield[@code=9]">
+            <a class='authlink'>
+                <xsl:attribute name="href">/cgi-bin/koha/opac-authoritiesdetail.pl?authid=<xsl:value-of select="marc:subfield[@code=9]"/></xsl:attribute>
+                <img style="vertical-align:middle" height="15" width="15" src="/opac-tmpl/prog/images/filefind.png"/>
+            </a>
+        </xsl:if>
         <xsl:choose>
         <xsl:when test="position()=last()"><xsl:text>.</xsl:text></xsl:when><xsl:otherwise><xsl:text>; </xsl:text></xsl:otherwise></xsl:choose>
         </xsl:for-each>
             </xsl:otherwise>
         </xsl:choose>
         <xsl:call-template name="nameABCDN"/></a>
+        <xsl:if test="marc:subfield[@code=9]">
+            <a class='authlink'>
+                <xsl:attribute name="href">/cgi-bin/koha/opac-authoritiesdetail.pl?authid=<xsl:value-of select="marc:subfield[@code=9]"/></xsl:attribute>
+                <img style="vertical-align:middle" height="15" width="15" src="/opac-tmpl/prog/images/filefind.png"/>
+            </a>
+        </xsl:if>
         <xsl:choose><xsl:when test="position()=last()"><xsl:text>.</xsl:text></xsl:when><xsl:otherwise><xsl:text>; </xsl:text></xsl:otherwise></xsl:choose>
         </xsl:for-each>
 
             </xsl:otherwise>
         </xsl:choose>
         <xsl:call-template name="nameACDEQ"/></a>
+        <xsl:if test="marc:subfield[@code=9]">
+            <a class='authlink'>
+                <xsl:attribute name="href">/cgi-bin/koha/opac-authoritiesdetail.pl?authid=<xsl:value-of select="marc:subfield[@code=9]"/></xsl:attribute>
+                <img style="vertical-align:middle" height="15" width="15" src="/opac-tmpl/prog/images/filefind.png"/>
+            </a>
+        </xsl:if>
         <xsl:choose><xsl:when test="position()=last()"><xsl:text>.</xsl:text></xsl:when><xsl:otherwise><xsl:text>; </xsl:text></xsl:otherwise></xsl:choose>
 
         </xsl:for-each>
                 </xsl:with-param>
             </xsl:call-template>
             </a>
+            <xsl:if test="marc:subfield[@code=9]">
+                <a class='authlink'>
+                    <xsl:attribute name="href">/cgi-bin/koha/opac-authoritiesdetail.pl?authid=<xsl:value-of select="marc:subfield[@code=9]"/></xsl:attribute>
+                    <img style="vertical-align:middle" height="15" width="15" src="/opac-tmpl/prog/images/filefind.png"/>
+                </a>
+            </xsl:if>
             <xsl:choose>
             <xsl:when test="position()=last()"></xsl:when>
             <xsl:otherwise> | </xsl:otherwise>
index fdccd3d..c796607 100644 (file)
@@ -16,7 +16,7 @@ the kohaversion is divided in 4 parts :
 use strict;
 
 sub kohaversion {
-    our $VERSION = '3.09.00.049';
+    our $VERSION = '3.09.00.051';
     # version needs to be set this way
     # so that it can be picked up by Makefile.PL
     # during install
index 6a8cce7..690f216 100755 (executable)
@@ -186,14 +186,26 @@ unless (scalar(@ARGV)) {
 ($verbose) and print scalar(@ARGV), " argument(s) after options: " . join(" ", @ARGV) . "\n";
 
 
-foreach my $report (@ARGV) {
-    my ($sql, $type) = get_saved_report($report);
-    unless ($sql) {
-        carp "ERROR: No saved report $report found";
+foreach my $report_id (@ARGV) {
+    my $report = get_saved_report($report_id);
+    unless ($report) {
+        warn "ERROR: No saved report $report_id found";
         next;
     }
+    my $sql         => $report->{savedsql};
+    my $report_name => $report->{report_name};
+    my $type        => $report->{type};
+
     $verbose and print "SQL: $sql\n\n";
-    # my $results = execute_query($sql, undef, 0, 99999, $format, $report); 
+    if (defined($report_name) and $report_name ne "")
+    {
+        $subject = $report_name ;
+    }
+    else
+    {
+        $subject = 'Koha Saved Report';
+    }
+    # my $results = execute_query($sql, undef, 0, 99999, $format, $report_id);
     my ($sth) = execute_query($sql);
     # execute_query(sql, , 0, 20, , )
     my $count = scalar($sth->rows);
index 86b7a00..38cbd42 100755 (executable)
@@ -31,38 +31,34 @@ my $query  = CGI->new();
 my $report_id = $query->param('id');
 my $report_name = $query->param('name');
 
-my $cache;
-my $sql;
-my $type;
-my $notes;
-my $cache_expiry;
-my $public;
+my $report_rec = get_saved_report( $report_name ? { 'name' => $report_name } : { 'id' => $report_id } );
+die "Sorry this report is not public\n" unless $report_rec->{public};
 
-( $sql, $type, $report_name, $notes, $cache_expiry, $public, $report_id ) =
-  get_saved_report($report_name ? { 'name' => $report_name } : { 'id' => $report_id } );
-die "Sorry this report is not public\n" unless $public;
 
-if (Koha::Cache->is_cache_active) {
-    $cache = Koha::Cache->new(
-    );
-    my $page = $cache->get_from_cache("opac:report:$report_id");
-    if ($page) {
-        print $query->header;
-        print $page;
-        exit;
-    }
+my $cache_active = Koha::Cache->is_cache_active;
+my ($cache_key, $cache, $json_text);
+if ($cache_active) {
+    $cache_key = "opac:report:".($report_name ? "name:$report_name" : "id:$report_id");
+    $cache = Koha::Cache->new();
+    $json_text = $cache->get_from_cache($cache_key);
 }
 
-print $query->header;
-if ($sql) {
+unless ($json_text) {
     my $offset = 0;
     my $limit  = C4::Context->preference("SvcMaxReportRows") || 10;
-    my ( $sth, $errors ) = execute_query( $sql, $offset, $limit );
-    my $lines     = $sth->fetchall_arrayref;
-    my $json_text = to_json($lines);
-    print $json_text;
+    my ( $sth, $errors ) = execute_query( $report_rec->{savedsql}, $offset, $limit );
+    if ($sth) {
+        my $lines     = $sth->fetchall_arrayref;
+        $json_text = to_json($lines);
 
-    if (Koha::Cache->is_cache_active) {
-        $cache->set_in_cache( "opac:report:$report_id", $json_text, $cache_expiry );
+        if ($cache_active) {
+            $cache->set_in_cache( $cache_key, $json_text, $report_rec->{cache_expiry} );
+        }
+    }
+    else {
+        $json_text = to_json($errors);
     }
 }
+
+print $query->header;
+print $json_text;
index 4f94d69..aae96c9 100755 (executable)
@@ -37,11 +37,12 @@ my $input = new CGI;
 my $referer = $input->referer();
 
 my $phase = $input->param('phase') || 'View Dictionary';
-my $area = $input->param('areas') || '';
-my $no_html = 0; # this will be set if we dont want to print out an html::template
-my     ( $template, $borrowernumber, $cookie ) = get_template_and_user(
-    {
-        template_name   => "reports/dictionary.tmpl",
+my $definition_name        = $input->param('definition_name');
+my $definition_description = $input->param('definition_description');
+my $area  = $input->param('area') || '';
+my $no_html = 0;    # this will be set if we dont want to print out an html::template
+my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
+    {   template_name   => "reports/dictionary.tmpl",
         query           => $input,
         type            => "intranet",
         authnotrequired => 0,
@@ -51,78 +52,71 @@ my  ( $template, $borrowernumber, $cookie ) = get_template_and_user(
        );
 
 if ($phase eq 'View Dictionary'){
-       # view the dictionary we use to set up abstract variables such as all borrowers over fifty who live in a certain town
-       my $areas = get_report_areas();
-    foreach (@{ $areas }) {
-        $_->{selected} = 1 if $_->{id} eq $area; # mark active area
-    }
-       my $definitions = get_from_dictionary($area);
-       $template->param( 'areas' => $areas ,
-               'start_dictionary' => 1,
-               'definitions' => $definitions,
-       );
-}
-elsif ($phase eq 'Add New Definition'){
-       # display form allowing them to add a new definition
-       $template->param( 'new_dictionary' => 1,
-               );
+    # view the dictionary we use to set up abstract variables such as all borrowers over fifty who live in a certain town
+    my $definitions = get_from_dictionary($area);
+    $template->param(
+        'areas'=> areas(),
+        'start_dictionary' => 1,
+        'definitions'      => $definitions,
+    );
+} elsif ( $phase eq 'Add New Definition' ) {
+
+    # display form allowing them to add a new definition
+    $template->param( 'new_dictionary' => 1, );
 }
 
-elsif ($phase eq 'New Term step 2'){
-       # Choosing the area
-       my $areas = C4::Reports::Guided::get_report_areas();
-       my $definition_name=$input->param('definition_name');
-       my $definition_description=$input->param('definition_description');             
-       $template->param( 'step_2' => 1,
-               'areas' => $areas,
-               'definition_name' => $definition_name,
-               'definition_description' => $definition_description,
-       );
+elsif ( $phase eq 'New Term step 2' ) {
+
+    # Choosing the area
+    $template->param(
+        'step_2'                 => 1,
+        'areas'                  => areas(),
+        'definition_name'        => $definition_name,
+        'definition_description' => $definition_description,
+    );
 }
 
-elsif ($phase eq 'New Term step 3'){
-       # Choosing the columns
-       my $area = $input->param('areas');
-       my $columns = get_columns($area,$input);
-       my $definition_name=$input->param('definition_name');
-       my $definition_description=$input->param('definition_description');             
-       $template->param( 'step_3' => 1,
-               'area' => $area,
-               'columns' => $columns,
-               'definition_name' => $definition_name,
-               'definition_description' => $definition_description,
-       );
+elsif ( $phase eq 'New Term step 3' ) {
+
+    # Choosing the columns
+    my $columns                = get_columns( $area, $input );
+    $template->param(
+        'step_3'                 => 1,
+        'area'                   => $area,
+        'columns'                => $columns,
+        'definition_name'        => $definition_name,
+        'definition_description' => $definition_description,
+    );
 }
 
-elsif ($phase eq 'New Term step 4'){
-       # Choosing the values
-       my $area=$input->param('area');
-       my $definition_name=$input->param('definition_name');
-       my $definition_description=$input->param('definition_description');             
-    my @columns = $input->param('columns');
-       my $columnstring = join (',',@columns);
-       my @column_loop;
-       foreach my $column (@columns){
-               my %tmp_hash;
-               $tmp_hash{'name'}=$column;
-               my $type =get_column_type($column);
-               if ($type eq 'distinct'){
-                       my $values = get_distinct_values($column);
-                       $tmp_hash{'values'} = $values;
-                       $tmp_hash{'distinct'} = 1;
-                         
-               }
-               if ($type eq 'DATE' || $type eq 'DATETIME'){
-                       $tmp_hash{'date'}=1;
-               }
-               if ($type eq 'TEXT' || $type eq 'MEDIUMTEXT'){
-                       $tmp_hash{'text'}=1;
-               }
-#              else {
-#                      warn $type;#
-#                      }
-               push @column_loop,\%tmp_hash;
-               }
+elsif ( $phase eq 'New Term step 4' ) {
+
+    # Choosing the values
+    my @columns                = $input->param('columns');
+    my $columnstring           = join( ',', @columns );
+    my @column_loop;
+    foreach my $column (@columns) {
+        my %tmp_hash;
+        $tmp_hash{'name'} = $column;
+        my $type = get_column_type($column);
+        if ( $type eq 'distinct' ) {
+            my $values = get_distinct_values($column);
+            $tmp_hash{'values'}   = $values;
+            $tmp_hash{'distinct'} = 1;
+
+        }
+        if ( $type eq 'DATE' || $type eq 'DATETIME' ) {
+            $tmp_hash{'date'} = 1;
+        }
+        if ( $type eq 'TEXT' ) {
+            $tmp_hash{'text'} = 1;
+        }
+
+        #              else {
+        #                      warn $type;#
+        #                      }
+        push @column_loop, \%tmp_hash;
+    }
 
        $template->param( 'step_4' => 1,
                'area' => $area,
@@ -134,83 +128,78 @@ elsif ($phase eq 'New Term step 4'){
        );
 }
 
-elsif ($phase eq 'New Term step 5'){
-       # Confirmation screen
-       my $areas = C4::Reports::Guided::get_report_areas();
-       my $area = $input->param('area');
-    my $areaname = $areas->[$area - 1]->{'name'};
-       my $columnstring = $input->param('columnstring');
-       my $definition_name=$input->param('definition_name');
-       my $definition_description=$input->param('definition_description');     
-       my @criteria = $input->param('criteria_column'); 
-       my $query_criteria;
-       my @criteria_loop;
-       foreach my $crit (@criteria) {
-               my $value = $input->param( $crit . "_value" );
-               if ($value) {
-                    my %tmp_hash;
-                    $tmp_hash{'name'}=$crit;
-                    $tmp_hash{'value'} = $value;
-                    push @criteria_loop,\%tmp_hash;
-                    if ($value =~ C4::Dates->regexp(C4::Context->preference('dateformat'))) {    
-                        my $date = C4::Dates->new($value);
-                        $value = $date->output("iso");
-                    }
-                    $query_criteria .= " AND $crit='$value'";
-               }
-               $value = $input->param( $crit . "_start_value" );
-               if ($value) {
-                    my %tmp_hash;
-                    $tmp_hash{'name'}="$crit Start";
-                    $tmp_hash{'value'} = $value;
-                    push @criteria_loop,\%tmp_hash;
-                    if ($value =~ C4::Dates->regexp(C4::Context->preference('dateformat'))) {    
-                        my $date = C4::Dates->new($value);
-                        $value = $date->output("iso");
-                    }
-                    $query_criteria .= " AND $crit >= '$value'";
-               }
-               $value = $input->param( $crit . "_end_value" );
-               if ($value) {
-                    my %tmp_hash;
-                    $tmp_hash{'name'}="$crit End";
-                    $tmp_hash{'value'} = $value;
-                    push @criteria_loop,\%tmp_hash;
-                    if ($value =~ C4::Dates->regexp(C4::Context->preference('dateformat'))) {    
-                        my $date = C4::Dates->new($value);
-                        $value = $date->output("iso");
-                    }
-                    $query_criteria .= " AND $crit <= '$value'";
-               }                 
-       }
-       $template->param( 'step_5' => 1,
-               'area' => $area,
-               'areaname' => $areaname,
-               'definition_name' => $definition_name,
-               'definition_description' => $definition_description,
-               'query' => $query_criteria,
-               'columnstring' => $columnstring,
-               'criteria_loop' => \@criteria_loop,
-       );
+elsif ( $phase eq 'New Term step 5' ) {
+    # Confirmation screen
+    my $columnstring           = $input->param('columnstring');
+    my @criteria               = $input->param('criteria_column');
+    my $query_criteria;
+    my @criteria_loop;
+
+    foreach my $crit (@criteria) {
+        my $value = $input->param( $crit . "_value" );
+        if ($value) {
+            my %tmp_hash;
+            $tmp_hash{'name'}  = $crit;
+            $tmp_hash{'value'} = $value;
+            push @criteria_loop, \%tmp_hash;
+            if ( $value =~ C4::Dates->regexp( C4::Context->preference('dateformat') ) ) {
+                my $date = C4::Dates->new($value);
+                $value = $date->output("iso");
+            }
+            $query_criteria .= " AND $crit='$value'";
+        }
+        $value = $input->param( $crit . "_start_value" );
+        if ($value) {
+            my %tmp_hash;
+            $tmp_hash{'name'}  = "$crit Start";
+            $tmp_hash{'value'} = $value;
+            push @criteria_loop, \%tmp_hash;
+            if ( $value =~ C4::Dates->regexp( C4::Context->preference('dateformat') ) ) {
+                my $date = C4::Dates->new($value);
+                $value = $date->output("iso");
+            }
+            $query_criteria .= " AND $crit >= '$value'";
+        }
+        $value = $input->param( $crit . "_end_value" );
+        if ($value) {
+            my %tmp_hash;
+            $tmp_hash{'name'}  = "$crit End";
+            $tmp_hash{'value'} = $value;
+            push @criteria_loop, \%tmp_hash;
+            if ( $value =~ C4::Dates->regexp( C4::Context->preference('dateformat') ) ) {
+                my $date = C4::Dates->new($value);
+                $value = $date->output("iso");
+            }
+            $query_criteria .= " AND $crit <= '$value'";
+        }
+    }
+    my %report_areas = map @$_, get_report_areas();
+    $template->param(
+        'step_5'                 => 1,
+        'area'                   => $area,
+        'areaname'               => $report_areas{$area},
+        'definition_name'        => $definition_name,
+        'definition_description' => $definition_description,
+        'query'                  => $query_criteria,
+        'columnstring'           => $columnstring,
+        'criteria_loop'          => \@criteria_loop,
+    );
 }
 
-elsif ($phase eq 'New Term step 6'){
-       # Saving
-       my $area = $input->param('area');
-       my $definition_name=$input->param('definition_name');
-       my $definition_description=$input->param('definition_description');             
-       my $sql=$input->param('sql');
-       save_dictionary($definition_name,$definition_description,$sql,$area);
-       $no_html=1;
-       print $input->redirect("/cgi-bin/koha/reports/dictionary.pl?phase=View%20Dictionary");  
-
+elsif ( $phase eq 'New Term step 6' ) {
+    # Saving
+    my $area                   = $input->param('area');
+    my $sql                    = $input->param('sql');
+    save_dictionary( $definition_name, $definition_description, $sql, $area );
+    $no_html = 1;
+    print $input->redirect("/cgi-bin/koha/reports/dictionary.pl?phase=View%20Dictionary");
+
+} elsif ( $phase eq 'Delete Definition' ) {
+    $no_html = 1;
+    my $id = $input->param('id');
+    delete_definition($id);
+    print $input->redirect("/cgi-bin/koha/reports/dictionary.pl?phase=View%20Dictionary");
 }
-elsif ($phase eq 'Delete Definition'){
-       $no_html=1;
-       my $id = $input->param('id');
-       delete_definition($id);
-       print $input->redirect("/cgi-bin/koha/reports/dictionary.pl?phase=View%20Dictionary");
-       }
 
 $template->param( 'referer' => $referer );
 
@@ -218,3 +207,16 @@ $template->param( 'referer' => $referer );
 if (!$no_html){
        output_html_with_http_headers $input, $cookie, $template->output;
 }
+
+sub areas {
+    my $areas = get_report_areas();
+    my @a;
+    foreach (@$areas) {
+        push @a, {
+            id => $_->[0],
+            name => $_->[1],
+            selected => ($_->[0] eq $area),
+        };
+    }
+    return \@a;
+}
index 8a2aada..00f52ef 100755 (executable)
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 use strict;
-#use warnings; FIXME - Bug 2505
+use warnings;
+
 use CGI;
 use Text::CSV;
 use URI::Escape;
 use C4::Reports::Guided;
 use C4::Auth qw/:DEFAULT get_session/;
 use C4::Output;
-use C4::Dates;
+use C4::Dates qw/format_date/;
 use C4::Debug;
 use C4::Branch; # XXX subfield_is_koha_internal_p
 
@@ -68,7 +69,7 @@ my $session = $cookie ? get_session($cookie->value) : undef;
 my $filter;
 if ( $input->param("filter_set") ) {
     $filter = {};
-    $filter->{$_} = $input->param("filter_$_") foreach qw/date author keyword/;
+    $filter->{$_} = $input->param("filter_$_") foreach qw/date author keyword group subgroup/;
     $session->param('report_filter', $filter) if $session;
     $template->param( 'filter_set' => 1 );
 }
@@ -85,21 +86,27 @@ if ( !$phase ) {
 elsif ( $phase eq 'Build new' ) {
     # build a new report
     $template->param( 'build1' => 1 );
-    $template->param( 'areas' => get_report_areas(), 'usecache' => $usecache, 'cache_expiry' => 300, 'public' => '0' );
-}
-elsif ( $phase eq 'Use saved' ) {
+    my $areas = get_report_areas();
+    $template->param(
+        'areas' => [map { id => $_->[0], name => $_->[1] }, @$areas],
+        'usecache' => $usecache,
+        'cache_expiry' => 300,
+        'public' => '0',
+    );
+} elsif ( $phase eq 'Use saved' ) {
+
     # use a saved report
     # get list of reports and display them
+    my $group = $input->param('group');
+    my $subgroup = $input->param('subgroup');
+    $filter->{group} = $group;
+    $filter->{subgroup} = $subgroup;
     $template->param(
         'saved1' => 1,
         'savedreports' => get_saved_reports($filter),
         'usecache' => $usecache,
+        'groups_with_subgroups'=> groups_with_subgroups($group, $subgroup),
     );
-    if ($filter) {
-        while ( my ($k, $v) = each %$filter ) {
-            $template->param( "filter_$k" => $v ) if $v;
-        }
-    }
 }
 
 elsif ( $phase eq 'Delete Saved') {
@@ -113,30 +120,33 @@ elsif ( $phase eq 'Delete Saved') {
 
 elsif ( $phase eq 'Show SQL'){
        
-       my $id = $input->param('reports');
-    my ($sql,$type,$reportname,$notes) = get_saved_report($id);
-       $template->param(
+    my $id = $input->param('reports');
+    my $report = get_saved_report($id);
+    $template->param(
         'id'      => $id,
-        'reportname' => $reportname,
-        'notes'      => $notes,
-               'sql'     => $sql,
-               'showsql' => 1,
+        'reportname' => $report->{report_name},
+        'notes'      => $report->{notes},
+       'sql'     => $report->{savedsql},
+       'showsql' => 1,
     );
 }
 
 elsif ( $phase eq 'Edit SQL'){
        
     my $id = $input->param('reports');
-    my ($sql,$type,$reportname,$notes, $cache_expiry, $public) = get_saved_report($id);
+    my $report = get_saved_report($id);
+    my $group = $report->{report_group};
+    my $subgroup  = $report->{report_subgroup};
     $template->param(
-           'sql'        => $sql,
-           'reportname' => $reportname,
-        'notes'      => $notes,
+        'sql'        => $report->{savedsql},
+        'reportname' => $report->{report_name},
+        'groups_with_subgroups' => groups_with_subgroups($group, $subgroup),
+        'notes'      => $report->{notes},
         'id'         => $id,
-        'cache_expiry' => $cache_expiry,
-        'public' => $public,
+        'cache_expiry' => $report->{cache_expiry},
+        'public' => $report->{public},
         'usecache' => $usecache,
-           'editsql'    => 1,
+        'editsql'    => 1,
     );
 }
 
@@ -144,6 +154,8 @@ elsif ( $phase eq 'Update SQL'){
     my $id         = $input->param('id');
     my $sql        = $input->param('sql');
     my $reportname = $input->param('reportname');
+    my $group      = $input->param('group');
+    my $subgroup   = $input->param('subgroup');
     my $notes      = $input->param('notes');
     my $cache_expiry = $input->param('cache_expiry');
     my $cache_expiry_units = $input->param('cache_expiry_units');
@@ -177,16 +189,22 @@ elsif ( $phase eq 'Update SQL'){
             'errors'    => \@errors,
             'sql'       => $sql,
         );
-    }
-    else {
-        update_sql( $id, $sql, $reportname, $notes, $cache_expiry, $public );
+    } else {
+        update_sql( $id, {
+                sql => $sql,
+                name => $reportname,
+                group => $group,
+                subgroup => $subgroup,
+                notes => $notes,
+                cache_expiry => $cache_expiry,
+                public => $public,
+        } );
         $template->param(
             'save_successful'       => 1,
             'reportname'            => $reportname,
             'id'                    => $id,
         );
     }
-    
 }
 
 elsif ($phase eq 'retrieve results') {
@@ -228,7 +246,7 @@ elsif ( $phase eq 'Report on this Area' ) {
       # they have choosen a new report and the area to report on
       $template->param(
           'build2' => 1,
-          'area'   => $input->param('areas'),
+          'area'   => $input->param('area'),
           'types'  => get_report_types(),
           'cache_expiry' => $cache_expiry,
           'public' => $input->param('public'),
@@ -275,42 +293,42 @@ elsif ( $phase eq 'Choose these criteria' ) {
     my $area     = $input->param('area');
     my $type     = $input->param('type');
     my $column   = $input->param('column');
-       my @definitions = $input->param('definition');
-       my $definition = join (',',@definitions);
+    my @definitions = $input->param('definition');
+    my $definition = join (',',@definitions);
     my @criteria = $input->param('criteria_column');
-       my $query_criteria;
+    my $query_criteria;
     foreach my $crit (@criteria) {
         my $value = $input->param( $crit . "_value" );
-       
-       # If value is not defined, then it may be range values
-       if (!defined $value) {
-
-           my $fromvalue = $input->param( "from_" . $crit . "_value" );
-           my $tovalue   = $input->param( "to_"   . $crit . "_value" );
-           
-           # If the range values are dates
-           if ($fromvalue =~ C4::Dates->regexp('syspref') && $tovalue =~ C4::Dates->regexp('syspref')) { 
-               $fromvalue = C4::Dates->new($fromvalue)->output("iso");
-               $tovalue = C4::Dates->new($tovalue)->output("iso");
-           }
-
-           if ($fromvalue && $tovalue) {
-               $query_criteria .= " AND $crit >= '$fromvalue' AND $crit <= '$tovalue'";
-           }
-
-       } else {
-
-           # If value is a date
-           if ($value =~ C4::Dates->regexp('syspref')) { 
-               $value = C4::Dates->new($value)->output("iso");
-           }
-        # don't escape runtime parameters, they'll be at runtime
-        if ($value =~ /<<.*>>/) {
-            $query_criteria .= " AND $crit=$value";
+
+        # If value is not defined, then it may be range values
+        if (!defined $value) {
+
+            my $fromvalue = $input->param( "from_" . $crit . "_value" );
+            my $tovalue   = $input->param( "to_"   . $crit . "_value" );
+
+            # If the range values are dates
+            if ($fromvalue =~ C4::Dates->regexp('syspref') && $tovalue =~ C4::Dates->regexp('syspref')) {
+                $fromvalue = C4::Dates->new($fromvalue)->output("iso");
+                $tovalue = C4::Dates->new($tovalue)->output("iso");
+            }
+
+            if ($fromvalue && $tovalue) {
+                $query_criteria .= " AND $crit >= '$fromvalue' AND $crit <= '$tovalue'";
+            }
+
         } else {
-            $query_criteria .= " AND $crit='$value'";
+
+            # If value is a date
+            if ($value =~ C4::Dates->regexp('syspref')) {
+                $value = C4::Dates->new($value)->output("iso");
+            }
+            # don't escape runtime parameters, they'll be at runtime
+            if ($value =~ /<<.*>>/) {
+                $query_criteria .= " AND $crit=$value";
+            } else {
+                $query_criteria .= " AND $crit='$value'";
+            }
         }
-       }
     }
     $template->param(
         'build5'         => 1,
@@ -412,6 +430,7 @@ elsif ( $phase eq 'Build report' ) {
       build_query( \@columns, $query_criteria, $query_orderby, $area, $totals, $definition );
     $template->param(
         'showreport' => 1,
+        'area'       => $area,
         'sql'        => $sql,
         'type'       => $type,
         'cache_expiry' => $input->param('cache_expiry'),
@@ -420,23 +439,29 @@ elsif ( $phase eq 'Build report' ) {
 }
 
 elsif ( $phase eq 'Save' ) {
-       # Save the report that has just been built
+    # Save the report that has just been built
+    my $area           = $input->param('area');
     my $sql  = $input->param('sql');
     my $type = $input->param('type');
     $template->param(
         'save' => 1,
+        'area'  => $area,
         'sql'  => $sql,
         'type' => $type,
         'cache_expiry' => $input->param('cache_expiry'),
         'public' => $input->param('public'),
+        'groups_with_subgroups' => groups_with_subgroups($area), # in case we have a report group that matches area
     );
 }
 
 elsif ( $phase eq 'Save Report' ) {
-    # save the sql pasted in by a user 
-    my $sql  = $input->param('sql');
-    my $name = $input->param('reportname');
-    my $type = $input->param('types');
+    # save the sql pasted in by a user
+    my $area  = $input->param('area');
+    my $group = $input->param('group');
+    my $subgroup = $input->param('subgroup');
+    my $sql   = $input->param('sql');
+    my $name  = $input->param('reportname');
+    my $type  = $input->param('types');
     my $notes = $input->param('notes');
     my $cache_expiry = $input->param('cache_expiry');
     my $cache_expiry_units = $input->param('cache_expiry_units');
@@ -454,7 +479,7 @@ elsif ( $phase eq 'Save Report' ) {
       }
     }
     # check $cache_expiry isnt too large, Memcached::set requires it to be less than 30 days or it will be treated as if it were an absolute time stamp
-    if( $cache_expiry >= 2592000 ){
+    if( $cache_expiry && $cache_expiry >= 2592000 ){
       push @errors, {cache_expiry => $cache_expiry};
     }
     ## FIXME this is AFTER entering a name to save the report under
@@ -462,7 +487,7 @@ elsif ( $phase eq 'Save Report' ) {
         push @errors, {sqlerr => $1};
     }
     elsif ($sql !~ /^(SELECT)/i) {
-        push @errors, {queryerr => 1};
+        push @errors, {queryerr => "No SELECT"};
     }
     if (@errors) {
         $template->param(
@@ -476,161 +501,174 @@ elsif ( $phase eq 'Save Report' ) {
         );
     }
     else {
-        my $id = save_report( $borrowernumber, $sql, $name, $type, $notes, $cache_expiry, $public );
-        $template->param(
-            'save_successful'       => 1,
-            'reportname'            => $name,
-            'id'                    => $id,
-        );
+        save_report( {
+                borrowernumber => $borrowernumber,
+                sql            => $sql,
+                name           => $name,
+                area           => $area,
+                group          => $group,
+                subgroup       => $subgroup,
+                type           => $type,
+                notes          => $notes,
+                cache_expiry   => $cache_expiry,
+                public         => $public,
+            } );
+        $template->param( 'save_successful' => 1, );
     }
 }
 
 elsif ($phase eq 'Run this report'){
     # execute a saved report
-    my $limit  = 20;    # page size. # TODO: move to DB or syspref?
-    my $offset = 0;
-    my $report = $input->param('reports');
+    my $limit      = 20; # page size. # TODO: move to DB or syspref?
+    my $offset     = 0;
+    my $report_id  = $input->param('reports');
     my @sql_params = $input->param('sql_params');
     # offset algorithm
     if ($input->param('page')) {
         $offset = ($input->param('page') - 1) * $limit;
     }
-    my ($sql,$type,$name,$notes) = get_saved_report($report);
-    unless ($sql) {
-        push @errors, {no_sql_for_id=>$report};   
-    } 
-    my @rows = ();
-    # if we have at least 1 parameter, and it's not filled, then don't execute but ask for parameters
-    if ($sql =~ /<</ && !@sql_params) {
-        # split on ??. Each odd (2,4,6,...) entry should be a parameter to fill
-        my @split = split /<<|>>/,$sql;
-        my @tmpl_parameters;
-        for(my $i=0;$i<($#split/2);$i++) {
-            my ($text,$authorised_value) = split /\|/,$split[$i*2+1];
-            my $input;
-            my $labelid;
-            if ($authorised_value eq "date") {
-               $input = 'date';
-            }
-            elsif ($authorised_value) {
-                my $dbh=C4::Context->dbh;
-                my @authorised_values;
-                my %authorised_lib;
-                # builds list, depending on authorised value...
-                if ( $authorised_value eq "branches" ) {
-                    my $branches = GetBranchesLoop();
-                    foreach my $thisbranch (@$branches) {
-                        push @authorised_values, $thisbranch->{value};
-                        $authorised_lib{$thisbranch->{value}} = $thisbranch->{branchname};
-                    }
+
+    my ( $sql, $type, $name, $notes );
+    if (my $report = get_saved_report($report_id)) {
+        $sql   = $report->{savedsql};
+        $name  = $report->{report_name};
+        $notes = $report->{notes};
+
+        my @rows = ();
+        # if we have at least 1 parameter, and it's not filled, then don't execute but ask for parameters
+        if ($sql =~ /<</ && !@sql_params) {
+            # split on ??. Each odd (2,4,6,...) entry should be a parameter to fill
+            my @split = split /<<|>>/,$sql;
+            my @tmpl_parameters;
+            for(my $i=0;$i<($#split/2);$i++) {
+                my ($text,$authorised_value) = split /\|/,$split[$i*2+1];
+                my $input;
+                my $labelid;
+                if ($authorised_value eq "date") {
+                   $input = 'date';
                 }
-                elsif ( $authorised_value eq "itemtypes" ) {
-                    my $sth = $dbh->prepare("SELECT itemtype,description FROM itemtypes ORDER BY description");
-                    $sth->execute;
-                    while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
-                        push @authorised_values, $itemtype;
-                        $authorised_lib{$itemtype} = $description;
+                elsif ($authorised_value) {
+                    my $dbh=C4::Context->dbh;
+                    my @authorised_values;
+                    my %authorised_lib;
+                    # builds list, depending on authorised value...
+                    if ( $authorised_value eq "branches" ) {
+                        my $branches = GetBranchesLoop();
+                        foreach my $thisbranch (@$branches) {
+                            push @authorised_values, $thisbranch->{value};
+                            $authorised_lib{$thisbranch->{value}} = $thisbranch->{branchname};
+                        }
                     }
-                }
-                elsif ( $authorised_value eq "cn_source" ) {
-                    my $class_sources = GetClassSources();
-                    my $default_source = C4::Context->preference("DefaultClassificationSource");
-                    foreach my $class_source (sort keys %$class_sources) {
-                        next unless $class_sources->{$class_source}->{'used'} or
-                                    ($class_source eq $default_source);
-                        push @authorised_values, $class_source;
-                        $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
+                    elsif ( $authorised_value eq "itemtypes" ) {
+                        my $sth = $dbh->prepare("SELECT itemtype,description FROM itemtypes ORDER BY description");
+                        $sth->execute;
+                        while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
+                            push @authorised_values, $itemtype;
+                            $authorised_lib{$itemtype} = $description;
+                        }
                     }
-                }
-                elsif ( $authorised_value eq "categorycode" ) {
-                    my $sth = $dbh->prepare("SELECT categorycode, description FROM categories ORDER BY description");
-                    $sth->execute;
-                    while ( my ( $categorycode, $description ) = $sth->fetchrow_array ) {
-                        push @authorised_values, $categorycode;
-                        $authorised_lib{$categorycode} = $description;
+                    elsif ( $authorised_value eq "cn_source" ) {
+                        my $class_sources = GetClassSources();
+                        my $default_source = C4::Context->preference("DefaultClassificationSource");
+                        foreach my $class_source (sort keys %$class_sources) {
+                            next unless $class_sources->{$class_source}->{'used'} or
+                                        ($class_source eq $default_source);
+                            push @authorised_values, $class_source;
+                            $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
+                        }
                     }
+                    elsif ( $authorised_value eq "categorycode" ) {
+                        my $sth = $dbh->prepare("SELECT categorycode, description FROM categories ORDER BY description");
+                        $sth->execute;
+                        while ( my ( $categorycode, $description ) = $sth->fetchrow_array ) {
+                            push @authorised_values, $categorycode;
+                            $authorised_lib{$categorycode} = $description;
+                        }
+
+                        #---- "true" authorised value
+                    }
+                    else {
+                        my $authorised_values_sth = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib");
 
-                    #---- "true" authorised value
-                }
-                else {
-                    my $authorised_values_sth = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib");
-
-                    $authorised_values_sth->execute( $authorised_value);
+                        $authorised_values_sth->execute( $authorised_value);
 
-                    while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
-                        push @authorised_values, $value;
-                        $authorised_lib{$value} = $lib;
-                        # For item location, we show the code and the libelle
-                        $authorised_lib{$value} = $lib;
+                        while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
+                            push @authorised_values, $value;
+                            $authorised_lib{$value} = $lib;
+                            # For item location, we show the code and the libelle
+                            $authorised_lib{$value} = $lib;
+                        }
                     }
-                }
-                $labelid = $text;
-                $labelid =~ s/\W//g;
-                $input =CGI::scrolling_list(      # FIXME: factor out scrolling_list
-                    -name     => "sql_params",
-                    -id       => "sql_params_".$labelid,
-                    -values   => \@authorised_values,
+                    $labelid = $text;
+                    $labelid =~ s/\W//g;
+                    $input =CGI::scrolling_list(      # FIXME: factor out scrolling_list
+                        -name     => "sql_params",
+                        -id       => "sql_params_".$labelid,
+                        -values   => \@authorised_values,
 #                     -default  => $value,
-                    -labels   => \%authorised_lib,
-                    -override => 1,
-                    -size     => 1,
-                    -multiple => 0,
-                    -tabindex => 1,
-                );
-
-            } else {
-                $input = "text";
+                        -labels   => \%authorised_lib,
+                        -override => 1,
+                        -size     => 1,
+                        -multiple => 0,
+                        -tabindex => 1,
+                    );
+                } else {
+                    $input = "text";
+                }
+                push @tmpl_parameters, {'entry' => $text, 'input' => $input, 'labelid' => $labelid };
             }
-            push @tmpl_parameters, {'entry' => $text, 'input' => $input, 'labelid' => $labelid };
-        }
-        $template->param('sql'         => $sql,
-                        'name'         => $name,
-                        'sql_params'   => \@tmpl_parameters,
-                        'enter_params' => 1,
-                        'reports'      => $report,
-                        );
-    } else {
-        # OK, we have parameters, or there are none, we run the report
-        # if there were parameters, replace before running
-        # split on ??. Each odd (2,4,6,...) entry should be a parameter to fill
-        my @split = split /<<|>>/,$sql;
-        my @tmpl_parameters;
-        for(my $i=0;$i<$#split/2;$i++) {
-            my $quoted = C4::Context->dbh->quote($sql_params[$i]);
-            # if there are special regexp chars, we must \ them
-            $split[$i*2+1] =~ s/(\||\?|\.|\*|\(|\)|\%)/\\$1/g;
-            $sql =~ s/<<$split[$i*2+1]>>/$quoted/;
-        }
-        my ($sth, $errors) = execute_query($sql, $offset, $limit);
-        my $total = nb_rows($sql) || 0;
-        unless ($sth) {
-            die "execute_query failed to return sth for report $report: $sql";
+            $template->param('sql'         => $sql,
+                            'name'         => $name,
+                            'sql_params'   => \@tmpl_parameters,
+                            'enter_params' => 1,
+                            'reports'      => $report_id,
+                            );
         } else {
-            my $headref = $sth->{NAME} || [];
-            my @headers = map { +{ cell => $_ } } @$headref;
-            $template->param(header_row => \@headers);
-            while (my $row = $sth->fetchrow_arrayref()) {
-                my @cells = map { +{ cell => $_ } } @$row;
-                push @rows, { cells => \@cells };
+            # OK, we have parameters, or there are none, we run the report
+            # if there were parameters, replace before running
+            # split on ??. Each odd (2,4,6,...) entry should be a parameter to fill
+            my @split = split /<<|>>/,$sql;
+            my @tmpl_parameters;
+            for(my $i=0;$i<$#split/2;$i++) {
+                my $quoted = C4::Context->dbh->quote($sql_params[$i]);
+                # if there are special regexp chars, we must \ them
+                $split[$i*2+1] =~ s/(\||\?|\.|\*|\(|\)|\%)/\\$1/g;
+                $sql =~ s/<<$split[$i*2+1]>>/$quoted/;
+            }
+            my ($sth, $errors) = execute_query($sql, $offset, $limit);
+            my $total = nb_rows($sql) || 0;
+            unless ($sth) {
+                die "execute_query failed to return sth for report $report_id: $sql";
+            } else {
+                my $headref = $sth->{NAME} || [];
+                my @headers = map { +{ cell => $_ } } @$headref;
+                $template->param(header_row => \@headers);
+                while (my $row = $sth->fetchrow_arrayref()) {
+                    my @cells = map { +{ cell => $_ } } @$row;
+                    push @rows, { cells => \@cells };
+                }
             }
-        }
 
-        my $totpages = int($total/$limit) + (($total % $limit) > 0 ? 1 : 0);
-        my $url = "/cgi-bin/koha/reports/guided_reports.pl?reports=$report&amp;phase=Run%20this%20report";
-        if (@sql_params) {
-            $url = join('&amp;sql_params=', $url, map { URI::Escape::uri_escape($_) } @sql_params);
+            my $totpages = int($total/$limit) + (($total % $limit) > 0 ? 1 : 0);
+            my $url = "/cgi-bin/koha/reports/guided_reports.pl?reports=$report_id&amp;phase=Run%20this%20report";
+            if (@sql_params) {
+                $url = join('&amp;sql_params=', $url, map { URI::Escape::uri_escape($_) } @sql_params);
+            }
+            $template->param(
+                'results' => \@rows,
+                'sql'     => $sql,
+                'id'      => $report_id,
+                'execute' => 1,
+                'name'    => $name,
+                'notes'   => $notes,
+                'errors'  => $errors,
+                'pagination_bar'  => pagination_bar($url, $totpages, $input->param('page')),
+                'unlimited_total' => $total,
+            );
         }
-        $template->param(
-            'results' => \@rows,
-            'sql'     => $sql,
-            'id'      => $report,
-            'execute' => 1,
-            'name'    => $name,
-            'notes'   => $notes,
-            'errors'  => $errors,
-            'pagination_bar'  => pagination_bar($url, $totpages, $input->param('page')),
-            'unlimited_total' => $total,
-        );
+    }
+    else {
+        push @errors, { no_sql_for_id => $report_id };
     }
 }
 
@@ -680,16 +718,26 @@ elsif ($phase eq 'Export'){
     );
 }
 
-elsif ($phase eq 'Create report from SQL') {
-       # allow the user to paste in sql
-    if ($input->param('sql')) {
+elsif ( $phase eq 'Create report from SQL' ) {
+
+    my ($group, $subgroup);
+    # allow the user to paste in sql
+    if ( $input->param('sql') ) {
+        $group = $input->param('report_group');
+        $subgroup  = $input->param('report_subgroup');
         $template->param(
             'sql'           => $input->param('sql'),
             'reportname'    => $input->param('reportname'),
             'notes'         => $input->param('notes'),
         );
     }
-        $template->param('create' => 1, 'public' => '0', 'cache_expiry' => 300, 'usecache' => $usecache);
+    $template->param(
+        'create' => 1,
+        'groups_with_subgroups' => groups_with_subgroups($group, $subgroup),
+        'public' => '0',
+        'cache_expiry' => 300,
+        'usecache' => $usecache,
+    );
 }
 
 elsif ($phase eq 'Create Compound Report'){
@@ -728,3 +776,29 @@ $template->param(   'referer' => $input->referer(),
                 );
 
 output_html_with_http_headers $input, $cookie, $template->output;
+
+sub groups_with_subgroups {
+    my ($group, $subgroup) = @_;
+
+    my $groups_with_subgroups = get_report_groups();
+    my @g_sg;
+    while (my ($g_id, $v) = each %$groups_with_subgroups) {
+        my @subgroups;
+        if (my $sg = $v->{subgroups}) {
+            while (my ($sg_id, $n) = each %$sg) {
+                push @subgroups, {
+                    id => $sg_id,
+                    name => $n,
+                    selected => ($group && $g_id eq $group && $subgroup && $sg_id eq $subgroup ),
+                };
+            }
+        }
+        push @g_sg, {
+            id => $g_id,
+            name => $v->{name},
+            selected => ($group && $g_id eq $group),
+            subgroups => \@subgroups,
+        };
+    }
+    return \@g_sg;
+}
index 21b76e0..9ec0336 100755 (executable)
@@ -26,42 +26,18 @@ serials-home.pl
 
 this script is the main page for serials/
 
-=head1 PARAMETERS
-
-=over 4
-
-=item title
-
-=item ISSN
-
-=item biblionumber
-
-=back
-
 =cut
 
-use strict;
-use warnings;
+use Modern::Perl;
 use CGI;
 use C4::Auth;
-use C4::Serials;
-use C4::Output;
-use C4::Context;
 use C4::Branch;
+use C4::Context;
+use C4::Output;
+use C4::Serials;
 
-my $query        = new CGI;
-my $title        = $query->param('title_filter');
-my $ISSN         = $query->param('ISSN_filter');
-my $EAN          = $query->param('EAN_filter');
-my $routing      = $query->param('routing') || C4::Context->preference("RoutingSerials");
-my $searched     = $query->param('searched');
-my $biblionumber = $query->param('biblionumber');
-
-my @serialseqs = $query->param('serialseq');
-my @planneddates = $query->param('planneddate');
-my @publisheddates = $query->param('publisheddate');
-my @status = $query->param('status');
-my @notes = $query->param('notes');
+my $query   = new CGI;
+my $routing = $query->param('routing') || C4::Context->preference("RoutingSerials");
 
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     {
@@ -74,42 +50,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     }
 );
 
-if (@serialseqs){
-  my @information;
-  my $index;
-  foreach my $seq (@serialseqs){
-    if ($seq){
-      ### FIXME  This limitation that a serial must be given a title may not be very efficient for some library who do not update serials titles.
-      push @information,
-        { serialseq=>$seq,
-          publisheddate=>$publisheddates[$index],
-          planneddate=>$planneddates[$index],
-          notes=>$notes[$index],
-          status=>$status[$index]
-        }
-    }
-    $index++;
-  }
-  $template->param('information'=>\@information);
-}
-my @subscriptions;
-if ($searched) {
-    @subscriptions = GetSubscriptions( $title, $ISSN, $EAN, $biblionumber );
-}
-
-# to toggle between create or edit routing list options
-if ($routing) {
-    for my $subscription ( @subscriptions) {
-        $subscription->{routingedit} = check_routing( $subscription->{subscriptionid} );
-        $subscription->{branchname} = GetBranchName ( $subscription->{branchcode} );
-    }
-}
-
 $template->param(
-    subscriptions => \@subscriptions,
-    title_filter  => $title,
-    ISSN_filter   => $ISSN,
-    done_searched => $searched,
     routing       => $routing,
     (uc(C4::Context->preference("marcflavour"))) => 1
 );
diff --git a/serials/serials-search.pl b/serials/serials-search.pl
new file mode 100755 (executable)
index 0000000..ac5d0d3
--- /dev/null
@@ -0,0 +1,110 @@
+#!/usr/bin/perl
+
+# Copyright 2012 Koha Team
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+
+=head1 NAME
+
+serials-search.pl
+
+=head1 DESCRIPTION
+
+this script is the search page for serials
+
+=cut
+
+use Modern::Perl;
+use CGI;
+use C4::Auth;
+use C4::Branch;
+use C4::Context;
+use C4::Output;
+use C4::Serials;
+
+my $query         = new CGI;
+my $title         = $query->param('title_filter') || '';
+my $ISSN          = $query->param('ISSN_filter') || '';
+my $EAN           = $query->param('EAN_filter') || '';
+my $publisher     = $query->param('publisher_filter') || '';
+my $bookseller    = $query->param('bookseller_filter') || '';
+my $biblionumber  = $query->param('biblionumber') || '';
+my $branch        = $query->param('branch_filter') || '';
+my $routing       = $query->param('routing') || C4::Context->preference("RoutingSerials");
+my $searched      = $query->param('searched') || 0;
+
+my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
+    {
+        template_name   => "serials/serials-search.tmpl",
+        query           => $query,
+        type            => "intranet",
+        authnotrequired => 0,
+        flagsrequired   => { serials => '*' },
+        debug           => 1,
+    }
+);
+
+my @subscriptions;
+if ($searched){
+    @subscriptions = SearchSubscriptions(
+        {
+            biblionumber => $biblionumber,
+            title        => $title,
+            issn         => $ISSN,
+            ean          => $EAN,
+            publisher    => $publisher,
+            bookseller   => $bookseller,
+            branch       => $branch,
+        }
+    );
+}
+
+# to toggle between create or edit routing list options
+if ($routing) {
+    for my $subscription ( @subscriptions) {
+        $subscription->{routingedit} = check_routing( $subscription->{subscriptionid} );
+        $subscription->{branchname} = GetBranchName ( $subscription->{branchcode} );
+    }
+}
+
+my $branches = GetBranches();
+my @branches_loop;
+foreach (sort keys %$branches){
+    my $selected = 0;
+    $selected = 1 if( $branch eq $_ );
+    push @branches_loop, {
+        branchcode  => $_,
+        branchname  => $branches->{$_}->{'branchname'},
+        selected    => $selected,
+    };
+}
+
+$template->param(
+    subscriptions => \@subscriptions,
+    title_filter  => $title,
+    ISSN_filter   => $ISSN,
+    EAN_filter    => $EAN,
+    publisher_filter => $publisher,
+    bookseller_filter  => $bookseller,
+    branch_filter => $branch,
+    branches_loop => \@branches_loop,
+    done_searched => $searched,
+    routing       => $routing,
+    marcflavour   => (uc(C4::Context->preference("marcflavour")))
+);
+
+output_html_with_http_headers $query, $cookie, $template->output;
index b0507bd..654ef15 100755 (executable)
@@ -33,13 +33,6 @@ my $query  = CGI->new();
 my $report_id = $query->param('id');
 my $report_name = $query->param('name');
 
-my $cache;
-my $sql;
-my $type;
-my $notes;
-my $cache_expiry;
-my $public;
-
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     {
         template_name   => "intranet-main.tmpl",
@@ -50,39 +43,31 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     }
 );
 
-if (Koha::Cache->is_cache_active) {
-    if ($report_name) { # When retrieving by name, we have to hit the
-                        # database to get the ID before we can check
-                        # the cache. Yuck.
-        ( $sql, $type, $report_name, $notes, $cache_expiry, $public, $report_id ) =
-            get_saved_report( { 'name' => $report_name } );
-    }
-
+my $cache_active = Koha::Cache->is_cache_active;
+my ($cache_key, $cache, $json_text);
+if ($cache_active) {
+    $cache_key = "intranet:report:".($report_name ? "name:$report_name" : "id:$report_id");
     $cache = Koha::Cache->new();
-    my $page = $cache->get_from_cache("intranet:report:$report_id");
-    if ($page) {
-        print $query->header;
-        print $page;
-        exit;
-    }
+    $json_text = $cache->get_from_cache($cache_key);
 }
 
-print $query->header;
-
-# $public isnt used for intranet
-unless ($sql) {
-    ( $sql, $type, $report_name, $notes, $cache_expiry, $public, $report_id ) =
-        get_saved_report($report_name ? { 'name' => $report_name } : { 'id' => $report_id } );
-}
-if ($sql) {
+unless ($json_text) {
+    my $report_rec = get_saved_report($report_name ? { 'name' => $report_name } : { 'id' => $report_id });
     my $offset = 0;
     my $limit  = C4::Context->preference("SvcMaxReportRows") || 10;
-    my ( $sth, $errors ) = execute_query( $sql, $offset, $limit );
-    my $lines     = $sth->fetchall_arrayref;
-    my $json_text = to_json($lines);
-    print $json_text;
+    my ( $sth, $errors ) = execute_query( $report_rec->{savedsql}, $offset, $limit );
+    if ($sth) {
+        my $lines     = $sth->fetchall_arrayref;
+        $json_text = to_json($lines);
 
-    if (Koha::Cache->is_cache_active) {
-        $cache->set_in_cache( "intranet:report:$report_id", $json_text, $cache_expiry );
+        if ($cache_active) {
+            $cache->set_in_cache( $cache_key, $json_text, $report_rec->{cache_expiry} );
+        }
+    }
+    else {
+        $json_text = to_json($errors);
     }
 }
+
+print $query->header;
+print $json_text;
index 3a517a8..6d3d7a3 100644 (file)
@@ -12,7 +12,7 @@ use YAML;
 use C4::Debug;
 require C4::Context;
 
-use Test::More tests => 57;
+use Test::More tests => 78;
 use Test::MockModule;
 use MARC::Record;
 use File::Spec;
@@ -515,4 +515,82 @@ END {
     }
 }
 
+# Testing exploding indexes
+my $term;
+my $searchmodule = new Test::MockModule('C4::Search');
+$searchmodule->mock('SimpleSearch', sub {
+    my $query = shift;
+
+    is($query, "Heading,wrdl=$term", "Searching for expected term '$term' for exploding") or return '', [], 0;
+
+    my $record = MARC::Record->new;
+    if ($query =~ m/Arizona/) {
+        $record->add_fields(
+            [ '001', '1234' ],
+            [ '151', ' ', ' ', a => 'Arizona' ],
+            [ '551', ' ', ' ', a => 'United States', w => 'g' ],
+            [ '551', ' ', ' ', a => 'Maricopa County', w => 'h' ],
+            [ '551', ' ', ' ', a => 'Navajo County', w => 'h' ],
+            [ '551', ' ', ' ', a => 'Pima County', w => 'h' ],
+            [ '551', ' ', ' ', a => 'New Mexico' ],
+            );
+    }
+    return '', [ $record->as_usmarc() ], 1;
+});
+
+$term = 'Arizona';
+( $error, $query, $simple_query, $query_cgi,
+$query_desc, $limit, $limit_cgi, $limit_desc,
+$stopwords_removed, $query_type ) = buildQuery([], [ $term ], [ 'su-br' ], [  ], [], 0, 'en');
+matchesExplodedTerms("Advanced search for broader subjects", $query, 'Arizona', 'United States');
+
+( $error, $query, $simple_query, $query_cgi,
+$query_desc, $limit, $limit_cgi, $limit_desc,
+$stopwords_removed, $query_type ) = buildQuery([], [ $term ], [ 'su-na' ], [  ], [], 0, 'en');
+matchesExplodedTerms("Advanced search for narrower subjects", $query, 'Arizona', 'Maricopa County', 'Navajo County', 'Pima County');
+
+( $error, $query, $simple_query, $query_cgi,
+$query_desc, $limit, $limit_cgi, $limit_desc,
+$stopwords_removed, $query_type ) = buildQuery([], [ $term ], [ 'su-rl' ], [  ], [], 0, 'en');
+matchesExplodedTerms("Advanced search for related subjects", $query, 'Arizona', 'United States', 'Maricopa County', 'Navajo County', 'Pima County');
+
+( $error, $query, $simple_query, $query_cgi,
+$query_desc, $limit, $limit_cgi, $limit_desc,
+$stopwords_removed, $query_type ) = buildQuery([], [ "$term", 'history' ], [ 'su-rl', 'kw' ], [  ], [], 0, 'en');
+matchesExplodedTerms("Advanced search for related subjects and keyword 'history' searches related subjects", $query, 'Arizona', 'United States', 'Maricopa County', 'Navajo County', 'Pima County');
+like($query, qr/history/, "Advanced search for related subjects and keyword 'history' searches for 'history'");
+
+( $error, $query, $simple_query, $query_cgi,
+$query_desc, $limit, $limit_cgi, $limit_desc,
+$stopwords_removed, $query_type ) = buildQuery([], [ 'history', "$term" ], [ 'kw', 'su-rl' ], [  ], [], 0, 'en');
+matchesExplodedTerms("Order of terms doesn't matter for advanced search", $query, 'Arizona', 'United States', 'Maricopa County', 'Navajo County', 'Pima County');
+like($query, qr/history/, "Order of terms doesn't matter for advanced search");
+
+( $error, $query, $simple_query, $query_cgi,
+$query_desc, $limit, $limit_cgi, $limit_desc,
+$stopwords_removed, $query_type ) = buildQuery([], [ "su-br:$term" ], [  ], [  ], [], 0, 'en');
+matchesExplodedTerms("Simple search for broader subjects", $query, 'Arizona', 'United States');
+
+( $error, $query, $simple_query, $query_cgi,
+$query_desc, $limit, $limit_cgi, $limit_desc,
+$stopwords_removed, $query_type ) = buildQuery([], [ "su-na:$term" ], [  ], [  ], [], 0, 'en');
+matchesExplodedTerms("Simple search for narrower subjects", $query, 'Arizona', 'Maricopa County', 'Navajo County', 'Pima County');
+
+( $error, $query, $simple_query, $query_cgi,
+$query_desc, $limit, $limit_cgi, $limit_desc,
+$stopwords_removed, $query_type ) = buildQuery([], [ "su-rl:$term" ], [  ], [  ], [], 0, 'en');
+matchesExplodedTerms("Simple search for related subjects", $query, 'Arizona', 'United States', 'Maricopa County', 'Navajo County', 'Pima County');
+
+( $error, $query, $simple_query, $query_cgi,
+$query_desc, $limit, $limit_cgi, $limit_desc,
+$stopwords_removed, $query_type ) = buildQuery([], [ "history and su-rl:$term" ], [  ], [  ], [], 0, 'en');
+matchesExplodedTerms("Simple search for related subjects and keyword 'history' searches related subjects", $query, 'Arizona', 'United States', 'Maricopa County', 'Navajo County', 'Pima County');
+like($query, qr/history/, "Simple search for related subjects and keyword 'history' searches for 'history'");
+
+sub matchesExplodedTerms {
+    my ($message, $query, @terms) = @_;
+    my $match = "(( or )?\\((" . join ('|', map { "su=\"$_\"" } @terms) . ")\\)){" . scalar(@terms) . "}";
+    like($query, qr/$match/, $message);
+}
+
 1;