From 519c27364334a1b62dd9acd4a36fbd40b7492475 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 24 Jul 2014 13:43:05 +0200 Subject: [PATCH] Bug 12648: Link patrons to an order This patch is the main patch. This feature adds the ability to link patrons to an order. On that way, they will be notified when the order is completely received. Test plan: 1/ Execute the updatedb entry and verify you have a new notification template in your table (tools/letter.pl). code: ACQ_NOTIF_ON_RECEIV, module: acquisition 2/ You can edit it if you want 3/ Create a basket and create an order with 1 or more items 4/ Link 1+ patrons to this order 5/ Close the basket and receive the order 6/ When you have received all items for this order, all patrons attached will be notified. Check the message_queue table to check if the letters have correctly been added to the queue. Signed-off-by: Paola Rossi Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- C4/Acquisition.pm | 107 ++++++++++++++++++ acqui/addorder.pl | 8 +- acqui/basket.pl | 6 +- acqui/neworderempty.pl | 9 ++ .../prog/en/modules/acqui/neworderempty.tt | 57 ++++++++++ tools/letter.pl | 3 + 6 files changed, 185 insertions(+), 5 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 89691e8160..273f8c07ce 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -82,6 +82,10 @@ BEGIN { &AddClaim &GetBiblioCountByBasketno + + &GetOrderUsers + &ModOrderUsers + &NotifyOrderUsers ); } @@ -1474,6 +1478,10 @@ q{SELECT * FROM aqorders WHERE biblionumber=? AND aqorders.ordernumber=?}, $biblionumber, $ordernumber ); + + # All items have been received, sent a notification to users + NotifyOrderUsers( $ordernumber ); + } return ($datereceived, $new_ordernumber); } @@ -2892,6 +2900,105 @@ sub populate_order_with_prices { return $order; } +=head3 GetOrderUsers + + $order_users_ids = &GetOrderUsers($ordernumber); + +Returns a list of all borrowernumbers that are in order users list + +=cut + +sub GetOrderUsers { + my ($ordernumber) = @_; + + return unless $ordernumber; + + my $query = q| + SELECT borrowernumber + FROM aqorderusers + WHERE ordernumber = ? + |; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare($query); + $sth->execute($ordernumber); + my $results = $sth->fetchall_arrayref( {} ); + + my @borrowernumbers; + foreach (@$results) { + push @borrowernumbers, $_->{'borrowernumber'}; + } + + return @borrowernumbers; +} + +=head3 ModOrderUsers + + my @order_users_ids = (1, 2, 3); + &ModOrderUsers($ordernumber, @basketusers_ids); + +Delete all users from order users list, and add users in C<@order_users_ids> +to this users list. + +=cut + +sub ModOrderUsers { + my ( $ordernumber, @order_users_ids ) = @_; + + return unless $ordernumber; + + my $dbh = C4::Context->dbh; + my $query = q| + DELETE FROM aqorderusers + WHERE ordernumber = ? + |; + my $sth = $dbh->prepare($query); + $sth->execute($ordernumber); + + $query = q| + INSERT INTO aqorderusers (ordernumber, borrowernumber) + VALUES (?, ?) + |; + $sth = $dbh->prepare($query); + foreach my $order_user_id (@order_users_ids) { + $sth->execute( $ordernumber, $order_user_id ); + } +} + +sub NotifyOrderUsers { + my ($ordernumber) = @_; + + my @borrowernumbers = GetOrderUsers($ordernumber); + return unless @borrowernumbers; + + my $order = GetOrder( $ordernumber ); + for my $borrowernumber (@borrowernumbers) { + my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ); + my $branch = C4::Branch::GetBranchDetail( $borrower->{branchcode} ); + my $biblio = C4::Biblio::GetBiblio( $order->{biblionumber} ); + my $letter = C4::Letters::GetPreparedLetter( + module => 'acquisition', + letter_code => 'ACQ_NOTIF_ON_RECEIV', + branchcode => $branch->{branchcode}, + tables => { + 'branches' => $branch, + 'borrowers' => $borrower, + 'biblio' => $biblio, + 'aqorders' => $order, + }, + ); + if ( $letter ) { + C4::Letters::EnqueueLetter( + { + letter => $letter, + borrowernumber => $borrowernumber, + LibraryName => C4::Context->preference("LibraryName"), + message_transport_type => 'email', + } + ) or warn "can't enqueue letter $letter"; + } + } +} + 1; __END__ diff --git a/acqui/addorder.pl b/acqui/addorder.pl index d95ba7b12b..f00f4bc139 100755 --- a/acqui/addorder.pl +++ b/acqui/addorder.pl @@ -263,8 +263,12 @@ if ( $orderinfo->{quantity} ne '0' ) { # if we already have $ordernumber, then it's an ordermodif my $order = Koha::Acquisition::Order->new($orderinfo); - if ($$orderinfo{ordernumber}) { - ModOrder( $orderinfo); + if ( $orderinfo->{ordernumber} ) { + ModOrder($orderinfo); + my $order_users_ids = $input->param('users_ids'); + my @order_users = split( /:/, $order_users_ids ); + + ModOrderUsers( $orderinfo->{ordernumber}, @order_users ); } else { # else, it's a new line $order->insert; diff --git a/acqui/basket.pl b/acqui/basket.pl index 5379c3741a..3dd917c708 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -237,7 +237,7 @@ if ( $op eq 'delete_confirm' ) { ReopenBasket($query->param('basketno')); print $query->redirect('/cgi-bin/koha/acqui/basket.pl?basketno='.$basket->{'basketno'}) } elsif ( $op eq 'mod_users' ) { - my $basketusers_ids = $query->param('basketusers_ids'); + my $basketusers_ids = $query->param('users_ids'); my @basketusers = split( /:/, $basketusers_ids ); ModBasketUsers($basketno, @basketusers); print $query->redirect("/cgi-bin/koha/acqui/basket.pl?basketno=$basketno"); @@ -408,8 +408,8 @@ if ( $op eq 'delete_confirm' ) { creationdate => $basket->{creationdate}, authorisedby => $basket->{authorisedby}, authorisedbyname => $basket->{authorisedbyname}, - basketusers_ids => join(':', @basketusers_ids), - basketusers => \@basketusers, + users_ids => join(':', @basketusers_ids), + users => \@basketusers, closedate => $basket->{closedate}, estimateddeliverydate=> $estimateddeliverydate, deliveryplace => C4::Branch::GetBranchName( $basket->{deliveryplace} ), diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl index 93c07c6b68..2966e8e77b 100755 --- a/acqui/neworderempty.pl +++ b/acqui/neworderempty.pl @@ -174,6 +174,7 @@ if ( $ordernumber eq '' and defined $params->{'breedingid'}){ +my ( @order_user_ids, @order_users ); if ( $ordernumber eq '' ) { # create order $new = 'yes'; @@ -196,6 +197,12 @@ else { #modify order $basket = GetBasket( $data->{'basketno'} ); $basketno = $basket->{'basketno'}; + + @order_user_ids = GetOrderUsers($ordernumber); + foreach my $order_user_id (@order_user_ids) { + my $order_user = GetMember(borrowernumber => $order_user_id); + push @order_users, $order_user if $order_user; + } } my $suggestion; @@ -400,6 +407,8 @@ $template->param( import_batch_id => $import_batch_id, subscriptionid => $subscriptionid, acqcreate => C4::Context->preference("AcqCreateItem") eq "ordering" ? 1 : "", + users_ids => join(':', @order_user_ids), + users => \@order_users, (uc(C4::Context->preference("marcflavour"))) => 1 ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt index faa76fd6d2..9a2fe24493 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt @@ -160,6 +160,40 @@ $(document).ready(function() }); $("#budget_id").change(); }); + + function UserSearchPopup(f) { + window.open( + "/cgi-bin/koha/acqui/add_user_search.pl", + 'UserSearchPopup', + 'width=740,height=450,toolbar=no,' + ); + } + + function add_user(borrowernumber, borrowername) { + var ids = $("#users_ids").val(); + if(ids.length > 0) { + ids = ids.split(':'); + } else { + ids = new Array; + } + if (ids.indexOf(borrowernumber) < 0) { + ids.push(borrowernumber); + $("#users_ids").val(ids.join(':')); + var li = '
  • '+borrowername + + ' [' + + _("Delete user") + ']
  • '; + $("#users_names").append(li); + return 0; + } + return -1; + } + + function del_user(borrowernumber) { + $("#user_"+borrowernumber).remove(); + var ids = $("#users_ids").val().split(':'); + ids.splice(ids.indexOf(borrowernumber.toString()), 1); + $("#users_ids").val(ids.join(':')); + } //]]> @@ -227,6 +261,29 @@ $(document).ready(function()
    +
    + Patrons +
      +
    1. + To notify on reveiving: +
      +
        + [% FOREACH user IN users %] +
      • + [% user.firstname %] [% user.surname %] + [Delete user] +
      • + [% END %] +
      + + + + +
      +
    2. +
    +
    +
    Catalog details diff --git a/tools/letter.pl b/tools/letter.pl index b806e9b6f7..06f7ae5f66 100755 --- a/tools/letter.pl +++ b/tools/letter.pl @@ -196,6 +196,9 @@ sub add_form { if ($module eq 'reserves') { push @{$field_selection}, add_fields('borrowers', 'reserves', 'biblio', 'items'); } + elsif ( $module eq 'acquisition' ) { + push @{$field_selection}, add_fields('aqbooksellers', 'aqorders', 'biblio', 'items'); + } elsif ($module eq 'claimacquisition') { push @{$field_selection}, add_fields('aqbooksellers', 'aqorders', 'biblio', 'biblioitems'); } -- 2.39.2