|
Lines 18-23
package Koha::Acquisition::Order;
Link Here
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Carp qw( croak ); |
20 |
use Carp qw( croak ); |
|
|
21 |
use Try::Tiny; |
| 22 |
|
| 23 |
use C4::Biblio qw(DelBiblio); |
| 21 |
|
24 |
|
| 22 |
use Koha::Acquisition::Baskets; |
25 |
use Koha::Acquisition::Baskets; |
| 23 |
use Koha::Acquisition::Funds; |
26 |
use Koha::Acquisition::Funds; |
|
Lines 25-30
use Koha::Acquisition::Invoices;
Link Here
|
| 25 |
use Koha::Acquisition::Order::Claims; |
28 |
use Koha::Acquisition::Order::Claims; |
| 26 |
use Koha::Database; |
29 |
use Koha::Database; |
| 27 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
30 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
|
|
31 |
use Koha::Exceptions::Object; |
| 28 |
use Koha::Biblios; |
32 |
use Koha::Biblios; |
| 29 |
use Koha::Holds; |
33 |
use Koha::Holds; |
| 30 |
use Koha::Items; |
34 |
use Koha::Items; |
|
Lines 97-102
sub store {
Link Here
|
| 97 |
return $self; |
101 |
return $self; |
| 98 |
} |
102 |
} |
| 99 |
|
103 |
|
|
|
104 |
=head3 cancel |
| 105 |
|
| 106 |
$order->cancel( |
| 107 |
{ [ reason => $reason, |
| 108 |
delete_biblio => $delete_biblio ] |
| 109 |
} |
| 110 |
); |
| 111 |
|
| 112 |
This method marks an order as cancelled, optionally using the I<reason> parameter. |
| 113 |
As the order is cancelled, the (eventual) items linked to it are removed. |
| 114 |
If I<delete_biblio> is passed, it will try to remove the linked biblio. |
| 115 |
|
| 116 |
If either the items or biblio removal fails, an error message is added to the object |
| 117 |
so the caller can take appropriate actions. |
| 118 |
|
| 119 |
=cut |
| 120 |
|
| 121 |
sub cancel { |
| 122 |
my ($self, $params) = @_; |
| 123 |
|
| 124 |
my $delete_biblio = $params->{delete_biblio}; |
| 125 |
my $reason = $params->{reason}; |
| 126 |
|
| 127 |
try { |
| 128 |
# Delete the related items |
| 129 |
$self->items->safe_delete; |
| 130 |
|
| 131 |
my $biblio = $self->biblio; |
| 132 |
if ( $biblio and $delete_biblio ) { |
| 133 |
|
| 134 |
if ( $biblio->active_orders->count == 0 |
| 135 |
and $biblio->subscriptions->count == 0 |
| 136 |
and $biblio->items->count == 0 ) |
| 137 |
{ |
| 138 |
|
| 139 |
my $error = DelBiblio( $biblio->id ); |
| 140 |
$self->add_message({ message => 'error_delbiblio', error => $error }) |
| 141 |
if $error; |
| 142 |
} |
| 143 |
else { |
| 144 |
|
| 145 |
$self->add_message({ message => 'error_delbiblio' }); |
| 146 |
} |
| 147 |
} |
| 148 |
} |
| 149 |
catch { |
| 150 |
if ( ref($_) eq 'Koha::Exceptions::Object::CannotBeDeleted' ) { |
| 151 |
my $object = $_->object; |
| 152 |
if ( ref($object) eq 'Koha::Item' ) { |
| 153 |
$self->add_message({ message => 'error_delitem' }); |
| 154 |
} |
| 155 |
} |
| 156 |
}; |
| 157 |
|
| 158 |
# Update order status |
| 159 |
$self->set( |
| 160 |
{ |
| 161 |
cancellationreason => $reason, |
| 162 |
datecancellationprinted => \'NOW()', |
| 163 |
orderstatus => 'cancelled', |
| 164 |
} |
| 165 |
)->store; |
| 166 |
|
| 167 |
return $self; |
| 168 |
} |
| 169 |
|
| 100 |
=head3 add_item |
170 |
=head3 add_item |
| 101 |
|
171 |
|
| 102 |
$order->add_item( $itemnumber ); |
172 |
$order->add_item( $itemnumber ); |
| 103 |
- |
|
|