From 3f0fbedcd9265303e4d9ca928c2888f7ef5ab2c9 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 11 Sep 2013 13:04:22 -0400 Subject: [PATCH] Bug 10877 - Add "Order Record" processing Order Record Processing will allow a library to stage an "order record" file which is a standard marc file with some additional information in it about how to create items automatically ( quantity, itemtype, etc ). The location of these fields is defined in the system preference MarcFieldsToOrder from bug 7180. The workflow is thus: 1) A librarian uploads an "order record" file, and marks the batch as an order file during the staging process. 2) The librarian selects an acquisitions basket and chooses "from a staged order file" 3) From here, the librarian can view all the records that will be created, along with quantity and other data ( from bug 7180 ). The librarian will *not* see the item fields, as those are automatically created using the minimum data needed ( branches, itype ). 4) The librarian hits "save" and the items are automatically generated on order. Later ( using features not directly tied to this feature ), the librarian will receive a new marc batch file with items attached ( including itemnumbers ). The vendor will have this information because it was sent via EDI ( bug 7736 ). The librarian will then use the marc record staging feature to overlay those bare bones item records with the full data ( via bug 7131 ). --- C4/ImportBatch.pm | 25 +++++++--- acqui/addorderiso2709.pl | 54 +++++++++++++++++-- installer/data/mysql/updatedatabase.pl | 7 +++ .../en/includes/acquisitions-add-to-basket.inc | 1 + .../prog/en/modules/acqui/addorderiso2709.tt | 35 ++++++++++--- misc/stage_file.pl | 2 + tools/stage-marc-import.pl | 1 + 7 files changed, 105 insertions(+), 20 deletions(-) diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm index c045878..0643e38 100644 --- a/C4/ImportBatch.pm +++ b/C4/ImportBatch.pm @@ -206,7 +206,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->{$_}; @@ -319,7 +320,7 @@ sub ModAuthInBatch { ($batch_id, $num_records, $num_items, @invalid_records) = BatchStageMarcRecords($encoding, $marc_records, $file_name, $marc_modification_template, $comments, $branch_code, $parse_items, - $leave_as_staging, + $leave_as_staging, is_order, $progress_interval, $progress_callback); =cut @@ -334,6 +335,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 @@ -353,6 +355,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'); @@ -953,21 +956,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 ?"; diff --git a/acqui/addorderiso2709.pl b/acqui/addorderiso2709.pl index 5933eb6..6d9e411 100755 --- a/acqui/addorderiso2709.pl +++ b/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 # @@ -266,6 +268,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]; @@ -345,8 +376,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) { @@ -440,6 +471,8 @@ sub import_biblios_list { item_action => $item_action ); batch_info($template, $batch); + + return \@list; } sub batch_info { @@ -483,8 +516,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 { @@ -492,8 +524,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 ) { next unless exists $yaml->{$field_name}; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 03a46a7..e0dbc2f 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -7923,6 +7923,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) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-add-to-basket.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-add-to-basket.inc index 46f8400..1c92651 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-add-to-basket.inc +++ b/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 %]
    diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt index c4f9394..f4c6d8d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt @@ -118,7 +118,15 @@ return disableUnchecked($(this)); }); + $('#tabs').tabs(); + + [% IF is_order %] + $("#checkAll").click(); + + $("#all_budget_id").hide(); + $('label[for="all_budget_id"]').hide(); + [% END %] }); function disableUnchecked(form){ @@ -146,7 +154,9 @@
    @@ -163,6 +173,12 @@ [% END %] + [% IF is_order %] +

    + Cancel +

    + [% END %] + [% FOREACH biblio IN biblio_list %]
    @@ -228,11 +244,11 @@
    [% END %]
    + [% IF ( items && !is_order ) %]

    Item information

    Import all the checked items in the basket with the following parameters:

    - [% IF ( items ) %]
    Item [% IF ( NoACQframework ) %] @@ -264,8 +280,8 @@
    [% END %] - [% END %]
    + [% END %]
    Accounting details @@ -274,6 +290,7 @@ + [% UNLESS is_order %]
  • [% IF ( close ) %] Fund: @@ -305,10 +322,12 @@
  • [% END %] + [% END %]
  • + [% UNLESS is_order %]
  • The 2 following fields are available for your own usage. They can be useful for statistical purposes
    @@ -344,14 +363,16 @@ [% END %]
  • + [% END %]
    -
    - Cancel -
    +
    + + Cancel +
    [% ELSE %]
    @@ -375,7 +396,7 @@ [% batch_lis.import_status %] [% batch_lis.staged_date | $KohaDates with_hours => 1 %] [% batch_lis.num_biblios %] - Add orders + Add orders [% END %] diff --git a/misc/stage_file.pl b/misc/stage_file.pl index 2e15466..35dbaf9 100755 --- a/misc/stage_file.pl +++ b/misc/stage_file.pl @@ -56,6 +56,7 @@ my $result = GetOptions( 'no-replace' => \$no_replace, 'comment:s' => \$batch_comment, 'authorities' => \$authorities, + 'is-order' => \$is_order, 'h|help' => \$want_help ); @@ -198,6 +199,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_ } diff --git a/tools/stage-marc-import.pl b/tools/stage-marc-import.pl index 8d6ab1a..84faefe 100755 --- a/tools/stage-marc-import.pl +++ b/tools/stage-marc-import.pl @@ -57,6 +57,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 $marc_modification_template = $input->param('marc_modification_template_id'); -- 1.7.2.5