View | Details | Raw Unified | Return to bug 23971
Collapse All | Expand All

(-)a/C4/Acquisition.pm (-2 / +94 lines)
Lines 19-24 package C4::Acquisition; Link Here
19
19
20
20
21
use Modern::Perl;
21
use Modern::Perl;
22
use JSON qw(to_json);
22
use Carp;
23
use Carp;
23
use C4::Context;
24
use C4::Context;
24
use C4::Debug;
25
use C4::Debug;
Lines 26-31 use C4::Suggestions; Link Here
26
use C4::Biblio;
27
use C4::Biblio;
27
use C4::Contract;
28
use C4::Contract;
28
use C4::Debug;
29
use C4::Debug;
30
use C4::Log qw(logaction);
29
use C4::Templates qw(gettemplate);
31
use C4::Templates qw(gettemplate);
30
use Koha::DateUtils qw( dt_from_string output_pref );
32
use Koha::DateUtils qw( dt_from_string output_pref );
31
use Koha::Acquisition::Baskets;
33
use Koha::Acquisition::Baskets;
Lines 203-208 sub NewBasket { Link Here
203
    $basketbooksellernote ||= q{};
205
    $basketbooksellernote ||= q{};
204
    ModBasketHeader( $basket, $basketname, $basketnote, $basketbooksellernote,
206
    ModBasketHeader( $basket, $basketname, $basketnote, $basketbooksellernote,
205
        $basketcontractnumber, $booksellerid, $deliveryplace, $billingplace, $is_standing, $create_items );
207
        $basketcontractnumber, $booksellerid, $deliveryplace, $billingplace, $is_standing, $create_items );
208
209
    # Log the basket creation
210
    # We need the creation timestamp, so need to get the newly created basket
211
    my $new_basket = GetBasket($basket);
212
    my $bookseller = Koha::Acquisition::Booksellers->find(
213
        $new_basket->{booksellerid}
214
    );
215
    my $patron = Koha::Patrons->find( $authorisedby );
216
    my $infos = {
217
        basketno     => $basket,
218
        basketname   => $new_basket->{basketname},
219
        creationdate => $new_basket->{creationdate},
220
        vendorname   => $bookseller->name,
221
        created_by   => $patron->firstname . ' ' . $patron->surname
222
    };
223
    logaction('ACQUISITIONS', 'ADD', $basket, to_json($infos));
224
206
    return $basket;
225
    return $basket;
207
}
226
}
208
227
Lines 217-223 close a basket (becomes unmodifiable, except for receives) Link Here
217
=cut
236
=cut
218
237
219
sub CloseBasket {
238
sub CloseBasket {
220
    my ($basketno) = @_;
239
    my ($basketno, $user, $edi_approval) = @_;
221
    my $dbh        = C4::Context->dbh;
240
    my $dbh        = C4::Context->dbh;
222
    $dbh->do('UPDATE aqbasket SET closedate=now() WHERE basketno=?', {}, $basketno );
241
    $dbh->do('UPDATE aqbasket SET closedate=now() WHERE basketno=?', {}, $basketno );
223
242
Lines 225-230 sub CloseBasket { Link Here
225
q{UPDATE aqorders SET orderstatus = 'ordered' WHERE basketno = ? AND orderstatus NOT IN ( 'complete', 'cancelled')},
244
q{UPDATE aqorders SET orderstatus = 'ordered' WHERE basketno = ? AND orderstatus NOT IN ( 'complete', 'cancelled')},
226
        {}, $basketno
245
        {}, $basketno
227
    );
246
    );
247
248
    # Log the closure
249
    my $basket = GetBasket($basketno);
250
    my $bookseller = Koha::Acquisition::Booksellers->find(
251
        $basket->{booksellerid}
252
    );
253
    my ($day, $mon, $year) = (localtime->mday, localtime->mon, localtime->year);
254
    $mon = sprintf '%02d', $mon + 1;
255
    $day = sprintf '%02d', $day;
256
    $year += 1900;
257
    my $action = $edi_approval ? 'APPROVE_BASKET' : 'CLOSE_BASKET';
258
    my $infos = {
259
        basketno   => $basketno,
260
        basketname => $basket->{basketname},
261
        closeddate => "$year-$mon-$day",
262
        vendorname => $bookseller->name,
263
    };
264
    if ($user) {
265
        my $patron = Koha::Patrons->find( $user );
266
        $infos->{closed_by} = $patron->firstname . ' ' . $patron->surname
267
    }
268
    logaction(
269
        'ACQUISITIONS',
270
        $action,
271
        $basketno,
272
        to_json($infos)
273
    );
274
228
    return;
275
    return;
229
}
276
}
230
277
Lines 548-553 sub ModBasket { Link Here
548
    my $sth = $dbh->prepare($query);
595
    my $sth = $dbh->prepare($query);
549
    $sth->execute(@params);
596
    $sth->execute(@params);
550
597
598
    # Log the basket update
599
    my $edited_basket = GetBasket($basketinfo->{'basketno'});
600
    my $bookseller = Koha::Acquisition::Booksellers->find(
601
        $edited_basket->{booksellerid}
602
    );
603
    my ($day, $mon, $year) = (localtime->mday, localtime->mon, localtime->year);
604
    $mon = sprintf '%02d', $mon + 1;
605
    $day = sprintf '%02d', $day;
606
    $year += 1900;
607
    my $infos = {
608
        basketno   => $basketinfo->{'basketno'},
609
        basketname => $edited_basket->{basketname},
610
        updatedate => "$year-$mon-$day",
611
        vendorname => $bookseller->name,
612
    };
613
    if ($basketinfo->{borrowernumber}) {
614
        my $patron = Koha::Patrons->find( $basketinfo->{borrowernumber} );
615
        $infos->{edited_by} = $patron->firstname . ' ' . $patron->surname;
616
    }
617
    logaction(
618
        'ACQUISITIONS',
619
        'MODIFY',
620
        $basketinfo->{'basketno'},
621
        to_json($infos)
622
    );
623
551
    return;
624
    return;
552
}
625
}
553
626
Lines 587-593 case the AcqCreateItem syspref takes precedence). Link Here
587
=cut
660
=cut
588
661
589
sub ModBasketHeader {
662
sub ModBasketHeader {
590
    my ($basketno, $basketname, $note, $booksellernote, $contractnumber, $booksellerid, $deliveryplace, $billingplace, $is_standing, $create_items) = @_;
663
    my ($basketno, $basketname, $note, $booksellernote, $contractnumber, $booksellerid, $deliveryplace, $billingplace, $is_standing, $create_items, $borrowernumber) = @_;
591
664
592
    $is_standing ||= 0;
665
    $is_standing ||= 0;
593
    my $query = qq{
666
    my $query = qq{
Lines 605-610 sub ModBasketHeader { Link Here
605
        my $sth2 = $dbh->prepare($query2);
678
        my $sth2 = $dbh->prepare($query2);
606
        $sth2->execute($contractnumber,$basketno);
679
        $sth2->execute($contractnumber,$basketno);
607
    }
680
    }
681
682
    # Log the basket update
683
    my $bookseller = Koha::Acquisition::Booksellers->find($booksellerid);
684
    my ($day, $mon, $year) = (localtime->mday, localtime->mon, localtime->year);
685
    $mon = sprintf '%02d', $mon + 1;
686
    $day = sprintf '%02d', $day;
687
    $year += 1900;
688
    my $infos = {
689
        basketno   => $basketno,
690
        basketname => $basketname,
691
        updatedate => "$year-$mon-$day",
692
        vendorname => $bookseller->name,
693
    };
694
    if ($borrowernumber) {
695
        my $patron = Koha::Patrons->find( $borrowernumber );
696
        $infos->{edited_by} = $patron->firstname . ' ' . $patron->surname;
697
    }
698
    logaction('ACQUISITIONS', 'MODIFY', $basketno, to_json($infos));
699
608
    return;
700
    return;
609
}
701
}
610
702
(-)a/Koha/EDI.pm (-1 / +3 lines)
Lines 574-580 sub process_quote { Link Here
574
                    basketno => $b,
574
                    basketno => $b,
575
                }
575
                }
576
            );
576
            );
577
            CloseBasket($b);
577
            # Close the basket, passing a flag indicating that this action
578
            # originated from an approval
579
            CloseBasket($b, undef, 1);
578
        }
580
        }
579
    }
581
    }
580
582
(-)a/acqui/basket.pl (-6 / +9 lines)
Lines 195-201 if ( $op eq 'delete_confirm' ) { Link Here
195
    if ($confirm) {
195
    if ($confirm) {
196
        my $basketno = $query->param('basketno');
196
        my $basketno = $query->param('basketno');
197
        my $booksellerid = $query->param('booksellerid');
197
        my $booksellerid = $query->param('booksellerid');
198
        $basketno =~ /^\d+$/ and CloseBasket($basketno);
198
        $basketno =~ /^\d+$/ and CloseBasket($basketno, $loggedinuser);
199
        # if requested, create basket group, close it and attach the basket
199
        # if requested, create basket group, close it and attach the basket
200
        if ($query->param('createbasketgroup')) {
200
        if ($query->param('createbasketgroup')) {
201
            my $branchcode;
201
            my $branchcode;
Lines 210-216 if ( $op eq 'delete_confirm' ) { Link Here
210
                            closed => 1,
210
                            closed => 1,
211
                            });
211
                            });
212
            ModBasket( { basketno => $basketno,
212
            ModBasket( { basketno => $basketno,
213
                         basketgroupid => $basketgroupid } );
213
                         basketgroupid => $basketgroupid,
214
                         borrowernumber => $loggedinuser } );
214
            print $query->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid='.$booksellerid.'&closed=1');
215
            print $query->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid='.$booksellerid.'&closed=1');
215
        } else {
216
        } else {
216
            print $query->redirect('/cgi-bin/koha/acqui/booksellers.pl?booksellerid=' . $booksellerid);
217
            print $query->redirect('/cgi-bin/koha/acqui/booksellers.pl?booksellerid=' . $booksellerid);
Lines 243-249 elsif ( $op eq 'ediorder' ) { Link Here
243
    $branch = undef if(defined $branch and $branch eq '');
244
    $branch = undef if(defined $branch and $branch eq '');
244
    ModBasket({
245
    ModBasket({
245
        basketno => $basket->{basketno},
246
        basketno => $basket->{basketno},
246
        branch   => $branch
247
        branch   => $branch,
248
        borrowernumber => $loggedinuser
247
    });
249
    });
248
    print $query->redirect("/cgi-bin/koha/acqui/basket.pl?basketno=$basketno");
250
    print $query->redirect("/cgi-bin/koha/acqui/basket.pl?basketno=$basketno");
249
    exit;
251
    exit;
Lines 536-542 sub edi_close_and_order { Link Here
536
            if ( create_edi_order($edi_params) ) {
538
            if ( create_edi_order($edi_params) ) {
537
                #$template->param( edifile => 1 );
539
                #$template->param( edifile => 1 );
538
            }
540
            }
539
        CloseBasket($basketno);
541
        CloseBasket($basketno, $loggedinuser);
540
542
541
        # if requested, create basket group, close it and attach the basket
543
        # if requested, create basket group, close it and attach the basket
542
        if ( $query->param('createbasketgroup') ) {
544
        if ( $query->param('createbasketgroup') ) {
Lines 558-565 sub edi_close_and_order { Link Here
558
            );
560
            );
559
            ModBasket(
561
            ModBasket(
560
                {
562
                {
561
                    basketno      => $basketno,
563
                    basketno       => $basketno,
562
                    basketgroupid => $basketgroupid
564
                    basketgroupid  => $basketgroupid,
565
                    borrowernumber => $loggedinuser
563
                }
566
                }
564
            );
567
            );
565
            print $query->redirect(
568
            print $query->redirect(
(-)a/acqui/basketgroup.pl (-1 / +2 lines)
Lines 308-314 if ( $op eq "add" ) { Link Here
308
  my $basketno=$input->param('basketno');
308
  my $basketno=$input->param('basketno');
309
  my $basketgroupid=$input->param('basketgroupid');
309
  my $basketgroupid=$input->param('basketgroupid');
310
  ModBasket( { basketno => $basketno,
310
  ModBasket( { basketno => $basketno,
311
                         basketgroupid => $basketgroupid } );
311
                         basketgroupid => $basketgroupid,
312
                         borrowernumber => $loggedinuser } );
312
  print $input->redirect("basket.pl?basketno=" . $basketno);
313
  print $input->redirect("basket.pl?basketno=" . $basketno);
313
} elsif ( $op eq 'closeandprint') {
314
} elsif ( $op eq 'closeandprint') {
314
#
315
#
(-)a/acqui/basketheader.pl (-1 / +2 lines)
Lines 154-160 if ( $op eq 'add_form' ) { Link Here
154
            scalar $input->param('deliveryplace'),
154
            scalar $input->param('deliveryplace'),
155
            scalar $input->param('billingplace'),
155
            scalar $input->param('billingplace'),
156
            scalar $input->param('is_standing') ? 1 : undef,
156
            scalar $input->param('is_standing') ? 1 : undef,
157
            scalar $input->param('create_items')
157
            scalar $input->param('create_items'),
158
            $loggedinuser
158
        );
159
        );
159
    } else { #New basket
160
    } else { #New basket
160
        $basketno = NewBasket(
161
        $basketno = NewBasket(
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt (-2 / +3 lines)
Lines 57-62 Link Here
57
[%        CASE 'ADDCIRCMESSAGE' %]Add circulation message
57
[%        CASE 'ADDCIRCMESSAGE' %]Add circulation message
58
[%        CASE 'DELCIRCMESSAGE' %]Delete circulation message
58
[%        CASE 'DELCIRCMESSAGE' %]Delete circulation message
59
[%        CASE 'STATUS_CHANGE'  %]Change ILL request status
59
[%        CASE 'STATUS_CHANGE'  %]Change ILL request status
60
[%        CASE 'CLOSE_BASKET' %]Close an acquisitions basket
61
[%        CASE 'APPROVE_BASKET' %]Approve an acquisitions basket
60
[%        CASE 'Run'    %]Run
62
[%        CASE 'Run'    %]Run
61
[%        CASE %][% action | html %]
63
[%        CASE %][% action | html %]
62
[%    END %]
64
[%    END %]
Lines 124-130 Link Here
124
                                        <option value="">All</option>
126
                                        <option value="">All</option>
125
                                    [% END %]
127
                                    [% END %]
126
128
127
                                    [% FOREACH actx IN [ 'ADD' 'DELETE' 'MODIFY' 'ISSUE' 'RETURN' 'RENEW' 'CREATE' 'CANCEL' 'SUSPEND' 'RESUME' 'ADDCIRCMESSAGE' 'DELCIRCMESSAGE' 'STATUS_CHANGE' 'CHANGE PASS' 'Run' ] %]
129
                                    [% FOREACH actx IN [ 'ADD' 'DELETE' 'MODIFY' 'ISSUE' 'RETURN' 'RENEW' 'CREATE' 'CANCEL' 'SUSPEND' 'RESUME' 'ADDCIRCMESSAGE' 'DELCIRCMESSAGE' 'STATUS_CHANGE' 'CHANGE PASS' 'Run', 'CLOSE_BASKET', 'APPROVE_BASKET' ] %]
128
                                        [% IF actions.grep(actx).size %]
130
                                        [% IF actions.grep(actx).size %]
129
                                            <option value="[% actx | html %]" selected="selected">[% PROCESS translate_log_action action=actx %]</option>
131
                                            <option value="[% actx | html %]" selected="selected">[% PROCESS translate_log_action action=actx %]</option>
130
                                        [% ELSE %]
132
                                        [% ELSE %]
131
- 

Return to bug 23971