use C4::Acquisition qw( NewBasket CloseBasket ModOrder);
use C4::Suggestions qw( ModSuggestion );
use C4::Items qw(AddItem);
-use C4::Biblio qw( AddBiblio TransformKohaToMarc GetMarcBiblio );
+use C4::Biblio qw( AddBiblio TransformKohaToMarc GetMarcBiblio GetFrameworkCode GetMarcFromKohaField );
use Koha::Edifact::Order;
use Koha::Edifact;
use Log::Log4perl;
my $ean_obj =
$schema->resultset('EdifactEan')->search($ean_search_keys)->single;
+ # If no branch specific each can be found, look for a default ean
+ unless ($ean_obj) {
+ $ean_obj = $schema->resultset('EdifactEan')->search(
+ {
+ ean => $ean,
+ branchcode => undef,
+ }
+ )->single;
+ }
+
my $dbh = C4::Context->dbh;
my $arr_ref = $dbh->selectcol_arrayref(
'select id from edifact_messages where basketno = ? and message_type = \'QUOTE\'',
}
push @{ $branch_map{$b} }, $item;
}
+
+ # Handling for 'AcqItemSetSubfieldsWhenReceived'
+ my @affects;
+ my $biblionumber;
+ my $itemfield;
+ if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) {
+ @affects = split q{\|},
+ C4::Context->preference("AcqItemSetSubfieldsWhenReceived");
+ if (@affects) {
+ my $order = Koha::Acquisition::Orders->find($ordernumber);
+ $biblionumber = $order->biblionumber;
+ my $frameworkcode = GetFrameworkCode($biblionumber);
+ ($itemfield) = GetMarcFromKohaField( 'items.itemnumber',
+ $frameworkcode );
+ }
+ }
+
my $gir_occurrence = 0;
while ( $gir_occurrence < $quantity ) {
my $branch = $inv_line->girfield( 'branch', $gir_occurrence );
}
}
+ # Handling for 'AcqItemSetSubfieldsWhenReceived'
+ if (@affects) {
+ my $item_marc = C4::Items::GetMarcItem( $biblionumber, $item->itemnumber );
+ for my $affect (@affects) {
+ my ( $sf, $v ) = split q{=}, $affect, 2;
+ foreach ( $item_marc->field($itemfield) ) {
+ $_->update( $sf => $v );
+ }
+ }
+ C4::Items::ModItemFromMarc( $item_marc, $biblionumber, $item->itemnumber );
+ }
+
$item->update;
}
else {
for my $b (@added_baskets) {
create_edi_order(
{
-
+ ean => $messages->[0]->buyer_ean,
basketno => $b,
}
);
my $schema = Koha::Database->new()->schema();
my $logger = Log::Log4perl->get_logger();
+ # $basketno is the return from AddBasket in the calling routine
+ # So this call should not fail unless that has
my $basket = Koha::Acquisition::Baskets->find( $basketno );
unless ( $basket ) {
$logger->error('Skipping order creation no valid basketno');
quantityreceived => 0,
order_vendornote => q{},
order_internalnote => $order_note,
- rrp => $item->price,
+ replacementprice => $item->price,
+ rrp_tax_included => $item->price,
+ rrp_tax_excluded => $item->price,
ecost => _discounted_price( $quote->vendor->discount, $item->price ),
uncertainprice => 0,
sort1 => q{},
itemnumber => $itemnumber,
}
);
+
+ my $lrp =
+ $item->girfield( 'library_rotation_plan', $occurrence );
+ if ($lrp) {
+ my $rota =
+ Koha::StockRotationRotas->find( { title => $lrp },
+ { key => 'stockrotationrotas_title' } );
+ if ($rota) {
+ $rota->add_item($itemnumber);
+ $logger->trace("Item added to rota $rota->id");
+ }
+ else {
+ $logger->error(
+ "No rota found matching $lrp in orderline");
+ }
+ }
}
++$occurrence;
);
}
- if ( $basket->effective_create_item eq 'ordering' ) {
+ # Do not use the basket level value as it is always NULL
+ # See calling subs call to AddBasket
+ if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) {
my $new_item = {
notforloan => -1,
cn_sort => q{},
itemnumber => $itemnumber,
}
);
+
+ my $lrp =
+ $item->girfield( 'library_rotation_plan', $occurrence );
+ if ($lrp) {
+ my $rota =
+ Koha::StockRotationRotas->find( { title => $lrp },
+ { key => 'stockrotationrotas_title' } );
+ if ($rota) {
+ $rota->add_item($itemnumber);
+ $logger->trace("Item added to rota $rota->id");
+ }
+ else {
+ $logger->error(
+ "No rota found matching $lrp in orderline");
+ }
+ }
}
++$occurrence;
$isbn =~ s/\-//xmsg;
if ( $isbn =~ m/(\d{13})/xms ) {
my $b_isbn = Business::ISBN->new($1);
- if ( $b_isbn && $b_isbn->is_valid ) {
+ if ( $b_isbn && $b_isbn->is_valid && $b_isbn->as_isbn10 ) {
$search_isbn = $b_isbn->as_isbn10->as_string( [] );
}