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 <paola.rossi@cineca.it> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
This commit is contained in:
parent
bb1beb4f5d
commit
519c273643
|
|
@ -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__
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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} ),
|
||||
|
|
|
|||
|
|
@ -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
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -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 = '<li id="user_'+borrowernumber+'">'+borrowername
|
||||
+ ' [<a style="cursor:pointer" onclick="del_user('+borrowernumber+');">'
|
||||
+ _("Delete user") + '</a>]</li>';
|
||||
$("#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(':'));
|
||||
}
|
||||
//]]>
|
||||
</script>
|
||||
</head>
|
||||
|
|
@ -227,6 +261,29 @@ $(document).ready(function()
|
|||
|
||||
<form action="/cgi-bin/koha/acqui/addorder.pl" method="post" id="Aform" onsubmit="return Check(this);">
|
||||
|
||||
<fieldset class="rows">
|
||||
<legend>Patrons</legend>
|
||||
<ol>
|
||||
<li>
|
||||
<span class="label">To notify on reveiving:</span>
|
||||
<div style="float:left">
|
||||
<ul id="users_names" style="padding-left:0">
|
||||
[% FOREACH user IN users %]
|
||||
<li id="user_[% user.borrowernumber %]">
|
||||
[% user.firstname %] [% user.surname %]
|
||||
[<a onclick="del_user([% user.borrowernumber %]);" style="cursor:pointer">Delete user</a>]
|
||||
</li>
|
||||
[% END %]
|
||||
</ul>
|
||||
<input type="hidden" id="basketno" name="basketno" value="[% basketno %]" />
|
||||
<input type="hidden" id="users_ids" name="users_ids" value="[% users_ids %]" />
|
||||
<input type="hidden" id="op" name="op" value="mod_users" />
|
||||
<input type="button" id="add_user" onclick="UserSearchPopup();" value="Add user" />
|
||||
</div>
|
||||
</li>
|
||||
</ol>
|
||||
</fieldset>
|
||||
|
||||
<fieldset class="rows">
|
||||
<legend>
|
||||
Catalog details
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue