@@ -, +, @@ --- C4/ImportBatch.pm | 25 ++++++--- acqui/addorderiso2709.pl | 58 +++++++++++++++++--- installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/updatedatabase.pl | 7 +++ .../en/includes/acquisitions-add-to-basket.inc | 1 + .../prog/en/modules/acqui/addorderiso2709.tt | 24 +++++++-- .../prog/en/modules/tools/stage-marc-import.tt | 4 ++ misc/stage_file.pl | 5 ++- tools/stage-marc-import.pl | 3 +- 9 files changed, 108 insertions(+), 20 deletions(-) --- a/C4/ImportBatch.pm +++ a/C4/ImportBatch.pm @@ -205,7 +205,8 @@ sub AddImportBatch { my (@fields, @vals); foreach (qw( matcher_id template_id branchcode overlay_action nomatch_action item_action - import_status batch_type file_name comments record_type )) { + import_status batch_type file_name comments + record_type is_order )) { if (exists $params->{$_}) { push @fields, $_; push @vals, $params->{$_}; @@ -318,7 +319,7 @@ sub ModAuthInBatch { ($batch_id, $num_records, $num_items, @invalid_records) = BatchStageMarcRecords($record_type, $encoding, $marc_records, $file_name, $comments, $branch_code, $parse_items, - $leave_as_staging, + $leave_as_staging, is_order, $progress_interval, $progress_callback); =cut @@ -332,6 +333,7 @@ sub BatchStageMarcRecords { my $branch_code = shift; my $parse_items = shift; my $leave_as_staging = shift; + my $is_order = shift; # optional callback to monitor status # of job @@ -351,6 +353,7 @@ sub BatchStageMarcRecords { file_name => $file_name, comments => $comments, record_type => $record_type, + is_order => $is_order, } ); if ($parse_items) { SetImportBatchItemAction($batch_id, 'always_add'); @@ -915,21 +918,29 @@ sub GetStagedWebserviceBatches { =head2 GetImportBatchRangeDesc - my $results = GetImportBatchRangeDesc($offset, $results_per_group); + my $results = GetImportBatchRangeDesc($offset, $results_per_group, $is_order); Returns a reference to an array of hash references corresponding to import_batches rows (sorted in descending order by import_batch_id) start at the given offset. +Pass in $is_order = 1 to get only batches marked as order records + =cut sub GetImportBatchRangeDesc { - my ($offset, $results_per_group) = @_; + my ($offset, $results_per_group,$is_order) = @_; + + my $is_order_limit = $is_order ? "AND is_order = 1" : q{}; my $dbh = C4::Context->dbh; - my $query = "SELECT * FROM import_batches - WHERE batch_type IN ('batch', 'webservice') - ORDER BY import_batch_id DESC"; + my $query = " + SELECT * FROM import_batches + WHERE batch_type IN ('batch', 'webservice') + $is_order_limit + ORDER BY import_batch_id DESC + "; + my @params; if ($results_per_group){ $query .= " LIMIT ?"; --- a/acqui/addorderiso2709.pl +++ a/acqui/addorderiso2709.pl @@ -58,12 +58,14 @@ my ($template, $loggedinuser, $cookie, $userflags) = get_template_and_user({ my $cgiparams = $input->Vars; my $op = $cgiparams->{'op'} || ''; my $booksellerid = $input->param('booksellerid'); +my $is_order = $input->param('is_order'); my $bookseller = GetBookSellerFromId($booksellerid); my $data; $template->param(scriptname => "/cgi-bin/koha/acqui/addorderiso2709.pl", booksellerid => $booksellerid, booksellername => $bookseller->{name}, + is_order => $is_order, ); if ($cgiparams->{'import_batch_id'} && $op eq ""){ @@ -81,7 +83,7 @@ if (! $cgiparams->{'basketno'}){ if ($op eq ""){ $template->param("basketno" => $cgiparams->{'basketno'}); #display batches - import_batches_list($template); + import_batches_list( $template, $is_order ); # # 2nd step = display the content of the choosen file # @@ -122,7 +124,8 @@ if ($op eq ""){ "basketno" => $cgiparams->{'basketno'}, loop_currencies => \@loop_currency, ); - import_biblios_list($template, $cgiparams->{'import_batch_id'}); + my $cells = import_biblios_list($template, $cgiparams->{'import_batch_id'}); + warn Data::Dumper::Dumper( $cells ); if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) { # prepare empty item form my $cell = PrepareItemrecordDisplay( '', '', '', 'ACQ' ); @@ -268,6 +271,35 @@ if ($op eq ""){ my @serials = $input->param('serial'); my @ind_tag = $input->param('ind_tag'); my @indicator = $input->param('indicator'); + + if ($is_order) { + my ( $notforloan_field, $notforloan_subfield ) = + GetMarcFromKohaField('items.notforloan'); + push( @tags, $notforloan_field ); + push( @subfields, $notforloan_subfield ); + push( @field_values, '-1' ); + + my ( $homebranch_field, $homebranch_subfield ) = + GetMarcFromKohaField('items.homebranch'); + push( @tags, $homebranch_field ); + push( @subfields, $homebranch_subfield ); + push( @field_values, C4::Context->userenv->{'branch'} ); + + my ( $holdingbranch_field, $holdingbranch_subfield ) = + GetMarcFromKohaField('items.holdingbranch'); + push( @tags, $holdingbranch_field ); + push( @subfields, $holdingbranch_subfield ); + push( @field_values, C4::Context->userenv->{'branch'} ); + + my $infos = get_infos_syspref($marcrecord, ['itype']); + my ( $itype_field, $itype_subfield ) = + GetMarcFromKohaField('items.itype'); + push( @tags, $itype_field ); + push( @subfields, $itype_subfield ); + push( @field_values, $infos->{itype} ); + warn "ITYPE: " . $infos->{itype}; + } + my $item; push @{ $item->{tags} }, $tags[0]; push @{ $item->{subfields} }, $subfields[0]; @@ -347,8 +379,8 @@ output_html_with_http_headers $input, $cookie, $template->output; sub import_batches_list { - my ($template) = @_; - my $batches = GetImportBatchRangeDesc(); + my ($template, $is_order) = @_; + my $batches = GetImportBatchRangeDesc(undef,undef,$is_order); my @list = (); foreach my $batch (@$batches) { @@ -446,6 +478,8 @@ sub import_biblios_list { item_action => $item_action ); batch_info($template, $batch); + + return \@list; } sub batch_info { @@ -489,8 +523,7 @@ sub add_matcher_list { $template->param(available_matchers => \@matchers); } -sub get_infos_syspref { - my ($record, $field_list) = @_; +sub GetMarcFieldsToOrderAsYAML { my $syspref = C4::Context->preference('MarcFieldsToOrder'); $syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt my $yaml = eval { @@ -498,8 +531,18 @@ sub get_infos_syspref { }; if ( $@ ) { warn "Unable to parse MarcFieldsToOrder syspref : $@"; - return (); + return; + } else { + return $yaml; } +} + +sub get_infos_syspref { + my ($record, $field_list) = @_; + + my $yaml = GetMarcFieldsToOrderAsYAML; + return unless $yaml; + my $r; for my $field_name ( @$field_list ) { my @fields = split /\|/, $yaml->{$field_name}; @@ -514,3 +557,4 @@ sub get_infos_syspref { } return $r; } + --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -974,6 +974,7 @@ CREATE TABLE `import_batches` ( -- information about batches of marc records tha `record_type` enum('biblio', 'auth', 'holdings') NOT NULL default 'biblio', -- type of record in the batch `file_name` varchar(100), -- the name of the file uploaded `comments` mediumtext, -- any comments added when the file was uploaded + `is_order` tinyint(1) NOT NULL DEFAULT '0', -- defines if this is an Order Record for processing PRIMARY KEY (`import_batch_id`), KEY `branchcode` (`branchcode`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -7162,6 +7162,13 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion ($DBversion); } +$DBversion = "3.13.00.XXX"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("ALTER TABLE import_batches ADD is_order BOOLEAN NOT NULL DEFAULT '0' AFTER comments"); + print "Upgrade to $DBversion done (Bug 10877 - Add 'Order Record' processing)\n"; + SetVersion ($DBversion); + +} =head1 FUNCTIONS =head2 TableExists($table) --- a/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-add-to-basket.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-add-to-basket.inc @@ -17,6 +17,7 @@
  • From a new (empty) record
  • From an external source
  • From a staged file
  • +
  • From a staged order file
  • [% ELSE %]
    --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt @@ -114,12 +114,17 @@ return disableUnchecked($(this)); }); + + [% IF is_order %] + $("#checkAll").click(); + + $("#all_budget_id").hide(); + $('label[for="all_budget_id"]').hide(); + [% END %] }); function disableUnchecked(form){ $("div.biblio.unselected").each(function(){ - $(this).find('select').attr('disabled', 'disabled'); - $(this).find('input').attr('disabled', 'disabled'); }); return 1; } @@ -153,6 +158,12 @@ [% END %] + [% IF is_order %] +

    + Cancel +

    + [% END %] + [% FOREACH biblio IN biblio_list %]
    @@ -222,7 +233,7 @@

    Import All

    Import all the lines in the basket with the following parameters:

    - [% IF ( items ) %] + [% IF ( items && !is_order ) %]
    Item [% IF ( NoACQframework ) %] @@ -257,6 +268,7 @@ + [% UNLESS is_order %]
  • [% IF ( close ) %] Fund: @@ -288,10 +300,12 @@
  • [% END %] + [% END %]
  • + [% UNLESS is_order %]
  • The 2 following fields are available for your own usage. They can be useful for statistical purposes
    @@ -327,9 +341,11 @@ [% END %]
  • + [% END %]
    + Cancel
    @@ -357,7 +373,7 @@ [% batch_lis.import_status %] [% batch_lis.staged_date | $KohaDates %] [% batch_lis.staged_hour %] [% batch_lis.num_biblios %] - Add orders + Add orders [% END %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt @@ -112,6 +112,10 @@ function CheckForm(f) { +
  • + + +
  • --- a/misc/stage_file.pl +++ a/misc/stage_file.pl @@ -45,6 +45,7 @@ my $input_file = ""; my $batch_comment = ""; my $want_help = 0; my $no_replace ; +my $is_order = 0; my $result = GetOptions( 'encoding:s' => \$encoding, @@ -54,6 +55,7 @@ my $result = GetOptions( 'no-replace' => \$no_replace, 'comment:s' => \$batch_comment, 'authorities' => \$authorities, + 'is-order' => \$is_order, 'h|help' => \$want_help ); @@ -99,7 +101,7 @@ sub process_batch { print "... staging MARC records -- please wait\n"; my ($batch_id, $num_valid_records, $num_items, @import_errors) = - BatchStageMarcRecords($record_type, $encoding, $marc_records, $input_file, $batch_comment, '', $add_items, 0, + BatchStageMarcRecords($record_type, $encoding, $marc_records, $input_file, $batch_comment, '', $add_items, 0, $is_order, 100, \&print_progress_and_commit); print "... finished staging MARC records\n"; @@ -192,6 +194,7 @@ Parameters: the record batch; if the comment has spaces in it, surround the comment with quotation marks. + --is-order this file is a bibliographic order file --help or -h show this message. _USAGE_ } --- a/tools/stage-marc-import.pl +++ a/tools/stage-marc-import.pl @@ -56,6 +56,7 @@ my $parse_items = $input->param('parse_items'); my $item_action = $input->param('item_action'); my $comments = $input->param('comments'); my $record_type = $input->param('record_type'); +my $is_order = $input->param('is_order') eq 'on'; my $encoding = $input->param('encoding'); my ($template, $loggedinuser, $cookie) = get_template_and_user({template_name => "tools/stage-marc-import.tmpl", @@ -131,7 +132,7 @@ if ($completedJobID) { } # FIXME branch code - my ($batch_id, $num_valid, $num_items, @import_errors) = BatchStageMarcRecords($record_type, $encoding, $marcrecord, $filename, $comments, '', $parse_items, 0, 50, staging_progress_callback($job, $dbh)); + my ($batch_id, $num_valid, $num_items, @import_errors) = BatchStageMarcRecords($record_type, $encoding, $marcrecord, $filename, $comments, '', $parse_items, 0, $is_order, 50, staging_progress_callback($job, $dbh)); $dbh->commit(); --