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

(-)a/acqui/basket.pl (-38 / +31 lines)
Lines 74-80 the supplier this script have to display the basket. Link Here
74
74
75
=cut
75
=cut
76
76
77
our $query        = new CGI;
77
our $query        = CGI->new;
78
our $basketno     = $query->param('basketno');
78
our $basketno     = $query->param('basketno');
79
our $ean          = $query->param('ean');
79
our $ean          = $query->param('ean');
80
our $booksellerid = $query->param('booksellerid');
80
our $booksellerid = $query->param('booksellerid');
Lines 128-172 if ( $op eq 'delete_confirm' ) { Link Here
128
    output_and_exit( $query, $cookie, $template, 'insufficient_permission' )
128
    output_and_exit( $query, $cookie, $template, 'insufficient_permission' )
129
      unless $logged_in_patron->has_permission( { acquisition => 'delete_baskets' } );
129
      unless $logged_in_patron->has_permission( { acquisition => 'delete_baskets' } );
130
130
131
    my $basketno = $query->param('basketno');
131
    my $basketno   = $query->param('basketno');
132
    my $delbiblio = $query->param('delbiblio');
132
    my $delbiblio  = $query->param('delbiblio');
133
    my @orders = GetOrders($basketno);
133
    my $basket_obj = Koha::Acquisition::Baskets->find($basketno);
134
#Delete all orders included in that basket, and all items received.
134
135
    foreach my $myorder (@orders){
135
    my $orders = $basket_obj->orders;
136
        DelOrder($myorder->{biblionumber},$myorder->{ordernumber});
136
137
    }
137
    my @cannotdelbiblios;
138
# if $delbiblio = 1, delete the records if possible
138
139
    if ((defined $delbiblio)and ($delbiblio ==1)){
139
    while ( my $order = $orders->next ) {
140
        my @cannotdelbiblios ;
140
        # cancel the order
141
        foreach my $myorder (@orders){
141
        $order->cancel({ delete_biblio => $delbiblio });
142
            my $biblionumber = $myorder->{'biblionumber'};
142
        my @messages = @{ $order->messages };
143
            my $biblio = Koha::Biblios->find( $biblionumber );
143
144
            my $countbiblio = $biblio->active_orders->count;
144
        if ( scalar @messages > 0 ) {
145
            my $ordernumber = $myorder->{'ordernumber'};
145
146
            my $cnt_subscriptions = $biblio->subscriptions->count;
146
            my $biblio = $order->biblio;
147
            my $itemcount = $biblio->items->count;
147
148
            my $error;
148
            push @cannotdelbiblios, {
149
            if ($countbiblio == 0 && $itemcount == 0 && not $cnt_subscriptions ) {
149
                biblionumber  => $biblio->id,
150
                $error = DelBiblio($myorder->{biblionumber}) }
150
                title         => $biblio->title // '',
151
            else {
151
                author        => $biblio->author // '',
152
                push @cannotdelbiblios, {biblionumber=> ($myorder->{biblionumber}),
152
                countbiblio   => $biblio->active_orders->count,
153
                                         title=> $myorder->{'title'},
153
                itemcount     => $biblio->items->count,
154
                                         author=> $myorder->{'author'},
154
                subscriptions => $biblio->subscriptions->count,
155
                                         countbiblio=> $countbiblio,
155
            };
156
                                         itemcount=>$itemcount,
157
                                         subscriptions => $cnt_subscriptions};
158
            }
159
            if ($error) {
160
                push @cannotdelbiblios, {biblionumber=> ($myorder->{biblionumber}),
161
                                         title=> $myorder->{'title'},
162
                                         author=> $myorder->{'author'},
163
                                         othererror=> $error};
164
            }
165
        }
156
        }
166
        $template->param( cannotdelbiblios => \@cannotdelbiblios );
167
    }
157
    }
168
 # delete the basket
158
169
    DelBasket($basketno,);
159
    $template->param( cannotdelbiblios => \@cannotdelbiblios );
160
161
    # delete the basket
162
    $basket_obj->delete;
170
    $template->param(
163
    $template->param(
171
        delete_confirmed => 1,
164
        delete_confirmed => 1,
172
        booksellername => $bookseller->name,
165
        booksellername => $bookseller->name,
(-)a/acqui/cancelorder.pl (-9 / +12 lines)
Lines 37-43 use C4::Output; Link Here
37
use C4::Acquisition;
37
use C4::Acquisition;
38
use Koha::Acquisition::Baskets;
38
use Koha::Acquisition::Baskets;
39
39
40
my $input = new CGI;
40
my $input = CGI->new;
41
my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
41
my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
42
    template_name   => 'acqui/cancelorder.tt',
42
    template_name   => 'acqui/cancelorder.tt',
43
    query           => $input,
43
    query           => $input,
Lines 52-66 my $biblionumber = $input->param('biblionumber'); Link Here
52
my $basketno = $input->param('basketno');
52
my $basketno = $input->param('basketno');
53
my $basket = Koha::Acquisition::Baskets->find({ basketno => $basketno }, { prefetch => 'booksellerid' });
53
my $basket = Koha::Acquisition::Baskets->find({ basketno => $basketno }, { prefetch => 'booksellerid' });
54
my $referrer = $input->param('referrer') || $input->referer;
54
my $referrer = $input->param('referrer') || $input->referer;
55
my $del_biblio = $input->param('del_biblio') ? 1 : 0;
55
my $delete_biblio = $input->param('del_biblio') ? 1 : 0;
56
56
57
if($action and $action eq "confirmcancel") {
57
if( $action and $action eq "confirmcancel" ) {
58
    my $reason = $input->param('reason');
58
    my $reason = $input->param('reason');
59
    my $error = DelOrder($biblionumber, $ordernumber, $del_biblio, $reason);
59
    my $order  = Koha::Acquisition::Orders->find($ordernumber);
60
    $order->cancel({ reason => $reason, delete_biblio => $delete_biblio });
61
    my @messages = @{ $order->messages };
60
62
61
    if($error) {
63
    if ( scalar @messages > 0 ) {
62
        $template->param(error_delitem => 1) if $error->{'delitem'};
64
        $template->param( error_delitem => 1 )
63
        $template->param(error_delbiblio => 1) if $error->{'delbiblio'};
65
            if $messages[0]->message eq 'error_delitem';
66
        $template->param( error_delbiblio => 1 )
67
            if $messages[0]->message eq 'error_delbiblio';
64
    } else {
68
    } else {
65
        $template->param(success_cancelorder => 1);
69
        $template->param(success_cancelorder => 1);
66
    }
70
    }
Lines 72-78 $template->param( Link Here
72
    biblionumber => $biblionumber,
76
    biblionumber => $biblionumber,
73
    basket => $basket,
77
    basket => $basket,
74
    referrer => $referrer,
78
    referrer => $referrer,
75
    del_biblio => $del_biblio,
79
    del_biblio => $delete_biblio,
76
);
80
);
77
81
78
output_html_with_http_headers $input, $cookie, $template->output;
82
output_html_with_http_headers $input, $cookie, $template->output;
79
- 

Return to bug 26577