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

(-)a/C4/Acquisition.pm (-2 / +90 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
        creatorname  => $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, $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
    logaction(
265
        'ACQUISITIONS',
266
        $action,
267
        $basketno,
268
        to_json($infos)
269
    );
270
228
    return;
271
    return;
229
}
272
}
230
273
Lines 548-553 sub ModBasket { Link Here
548
    my $sth = $dbh->prepare($query);
591
    my $sth = $dbh->prepare($query);
549
    $sth->execute(@params);
592
    $sth->execute(@params);
550
593
594
    # Log the basket update
595
    my $edited_basket = GetBasket($basketinfo->{'basketno'});
596
    my $bookseller = Koha::Acquisition::Booksellers->find(
597
        $edited_basket->{booksellerid}
598
    );
599
    my ($day, $mon, $year) = (localtime->mday, localtime->mon, localtime->year);
600
    $mon = sprintf '%02d', $mon + 1;
601
    $day = sprintf '%02d', $day;
602
    $year += 1900;
603
    my $infos = {
604
        basketno   => $basketinfo->{'basketno'},
605
        basketname => $edited_basket->{basketname},
606
        updatedate => "$year-$mon-$day",
607
        vendorname => $bookseller->name,
608
    };
609
    if ($basketinfo->{borrowernumber}) {
610
        my $patron = Koha::Patrons->find( $basketinfo->{borrowernumber} );
611
        $infos->{editorname} = $patron->firstname . ' ' . $patron->surname;
612
    }
613
    logaction(
614
        'ACQUISITIONS',
615
        'MODIFY',
616
        $basketinfo->{'basketno'},
617
        to_json($infos)
618
    );
619
551
    return;
620
    return;
552
}
621
}
553
622
Lines 587-593 case the AcqCreateItem syspref takes precedence). Link Here
587
=cut
656
=cut
588
657
589
sub ModBasketHeader {
658
sub ModBasketHeader {
590
    my ($basketno, $basketname, $note, $booksellernote, $contractnumber, $booksellerid, $deliveryplace, $billingplace, $is_standing, $create_items) = @_;
659
    my ($basketno, $basketname, $note, $booksellernote, $contractnumber, $booksellerid, $deliveryplace, $billingplace, $is_standing, $create_items, $borrowernumber) = @_;
591
660
592
    $is_standing ||= 0;
661
    $is_standing ||= 0;
593
    my $query = qq{
662
    my $query = qq{
Lines 605-610 sub ModBasketHeader { Link Here
605
        my $sth2 = $dbh->prepare($query2);
674
        my $sth2 = $dbh->prepare($query2);
606
        $sth2->execute($contractnumber,$basketno);
675
        $sth2->execute($contractnumber,$basketno);
607
    }
676
    }
677
678
    # Log the basket update
679
    my $bookseller = Koha::Acquisition::Booksellers->find($booksellerid);
680
    my ($day, $mon, $year) = (localtime->mday, localtime->mon, localtime->year);
681
    $mon = sprintf '%02d', $mon + 1;
682
    $day = sprintf '%02d', $day;
683
    $year += 1900;
684
    my $infos = {
685
        basketno   => $basketno,
686
        basketname => $basketname,
687
        updatedate => "$year-$mon-$day",
688
        vendorname => $bookseller->name,
689
    };
690
    if ($borrowernumber) {
691
        my $patron = Koha::Patrons->find( $borrowernumber );
692
        $infos->{editorname} = $patron->firstname . ' ' . $patron->surname;
693
    }
694
    logaction('ACQUISITIONS', 'MODIFY', $basketno, to_json($infos));
695
608
    return;
696
    return;
609
}
697
}
610
698
(-)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, 1);
578
        }
580
        }
579
    }
581
    }
580
582
(-)a/acqui/basket.pl (-4 / +7 lines)
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 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