[Koha-patches] [PATCH] Bug 5961 : New Feature to add multiple orders from a staged file
Chris Cormack
chrisc at catalyst.net.nz
Mon Mar 28 03:28:43 CEST 2011
From: Christophe Croullebois <christophe.croullebois at biblibre.com>
(MT #4007) Filling a basket from the reservoir
creating a form order to import all records from a staged file
---
C4/Biblio.pm | 28 +++++
C4/Output.pm | 2 +
acqui/addorderiso2709.pl | 99 +++++++++++++++-
acqui/neworderempty.pl | 1 +
.../prog/en/modules/acqui/addorderiso2709.tmpl | 123 +++++++++++++++++++-
5 files changed, 245 insertions(+), 8 deletions(-)
diff --git a/C4/Biblio.pm b/C4/Biblio.pm
index 1b378df..97d9fb0 100644
--- a/C4/Biblio.pm
+++ b/C4/Biblio.pm
@@ -3479,6 +3479,34 @@ sub get_biblio_authorised_values {
return $authorised_values;
}
+=head3 GetMarcPrice
+
+return the prices in accordance with the Marc format.
+=cut
+
+sub GetMarcPrice {
+ my ( $record, $marcflavour ) = @_;
+ my @listtags;
+ my $subfield;
+
+ if ( $marcflavour eq "MARC21" ) {
+ @listtags = ('345', '010');
+ $subfield="c";
+ } elsif ( $marcflavour eq "UNIMARC" ) { # assume unimarc if not marc21
+ @listtags = ('345', '010');
+ $subfield="d";
+ } else {
+ return;
+ }
+
+ for my $field ( $record->field(@listtags) ) {
+ for my $subfield_value ($field->subfields($subfield)){
+ #check value
+ return $subfield_value if ($subfield_value);
+ }
+ }
+}
+
1;
__END__
diff --git a/C4/Output.pm b/C4/Output.pm
index 9f5ed5e..1e123c7 100644
--- a/C4/Output.pm
+++ b/C4/Output.pm
@@ -33,6 +33,8 @@ use C4::Languages qw(getTranslatedLanguages get_bidi regex_lang_subtags language
use C4::Dates qw(format_date);
use C4::Budgets qw(GetCurrency);
+
+
use HTML::Template::Pro;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
diff --git a/acqui/addorderiso2709.pl b/acqui/addorderiso2709.pl
index 29f8143..82b0e75 100755
--- a/acqui/addorderiso2709.pl
+++ b/acqui/addorderiso2709.pl
@@ -25,6 +25,8 @@
use strict;
use warnings;
use CGI;
+use Number::Format qw(:all);
+
use C4::Context;
use C4::Auth;
use C4::Input;
@@ -36,10 +38,23 @@ use C4::Acquisition qw/NewOrder/;
use C4::Biblio;
use C4::Items;
use C4::Koha qw/GetItemTypes/;
-use C4::Budgets qw/GetBudgets/;
use C4::Acquisition qw/NewOrderItem GetBasket/;
+use C4::Budgets qw/GetBudgets GetBudgetHierarchy/;
use C4::Bookseller qw/GetBookSellerFromId/;
+
+use C4::Dates;
+use C4::Suggestions; # GetSuggestion
+use C4::Branch; # GetBranches
+use C4::Members;
+#needed for z3950 import:
+use C4::ImportBatch qw/GetImportRecordMarc SetImportRecordStatus/;
+use C4::Acquisition;
+use C4::Koha;
+use C4::Budgets;
+use C4::Acquisition;
+use C4::Bookseller;
+
my $input = new CGI;
my ($template, $loggedinuser, $cookie) = get_template_and_user({
template_name => "acqui/addorderiso2709.tmpl",
@@ -52,6 +67,8 @@ my ($template, $loggedinuser, $cookie) = get_template_and_user({
my $cgiparams = $input->Vars;
my $op = $cgiparams->{'op'};
my $booksellerid = $input->param('booksellerid');
+my $close = $input->param('close');
+my $data;
my $bookseller = GetBookSellerFromId($booksellerid);
$template->param(scriptname => "/cgi-bin/koha/acqui/addorderiso2709.pl",
@@ -80,6 +97,7 @@ if ($op eq ""){
import_biblios_list($template, $cgiparams->{'import_batch_id'});
} elsif ($op eq 'import_records'){
+ my $num=FormatNumber();
#import selected lines
$template->param('basketno' => $cgiparams->{'basketno'});
# Budget_id is mandatory for adding an order, we just add a default, the user needs to modify this aftewards
@@ -119,6 +137,11 @@ if ($op eq ""){
}
}
+ $price= GetMarcPrice($marcrecord);
+ if ($price){
+ $price = $num->unformat_number($price);
+ }
+
( $biblionumber, $bibitemnum ) = AddBiblio( $marcrecord, $cgiparams->{'frameworkcode'} || '' );
} else {
warn("Duplicate item found: ", $biblionumber, "; Duplicate: ", $duplicatetitle);
@@ -171,6 +194,7 @@ if ($op eq ""){
}
$orderinfo{'rrp'} = $orderinfo{'listprice'};
}
+
# remove uncertainprice flag if we have found a price in the MARC record
$orderinfo{uncertainprice} = 0 if $orderinfo{listprice};
my $basketno;
@@ -237,6 +261,66 @@ if ($op eq ""){
print $input->redirect("/cgi-bin/koha/acqui/basket.pl?basketno=".$cgiparams->{'basketno'});
exit;
}
+
+my $budgets = GetBudgets();
+my $budget_id = @$budgets[0]->{'budget_id'};
+# build bookfund list
+my $borrower = GetMember( 'borrowernumber' => $loggedinuser );
+my ( $flags, $homebranch ) = ( $borrower->{'flags'}, $borrower->{'branchcode'} );
+my $budget = GetBudget($budget_id);
+
+# build budget list
+my $budget_loop = [];
+my $budgets = GetBudgetHierarchy( q{}, $borrower->{branchcode}, $borrower->{borrowernumber} );
+foreach my $r ( @{$budgets} ) {
+ if ( !defined $r->{budget_amount} || $r->{budget_amount} == 0 ) {
+ next;
+ }
+ push @{$budget_loop},
+ { b_id => $r->{budget_id},
+ b_txt => $r->{budget_name},
+ b_sel => ( $r->{budget_id} == $budget_id ) ? 1 : 0,
+ };
+}
+#warn Data::Dumper::Dumper($budget_loop);
+$template->param( budget_loop => $budget_loop,);
+
+my $CGIsort1;
+if ($budget) { # its a mod ..
+ if ( defined $budget->{'sort1_authcat'} ) { # with custom Asort* planning values
+ $CGIsort1 = GetAuthvalueDropbox( 'sort1', $budget->{'sort1_authcat'}, $data->{'sort1'} );
+ }
+} elsif ( scalar(@$budgets) ) {
+ $CGIsort1 = GetAuthvalueDropbox( 'sort1', @$budgets[0]->{'sort1_authcat'}, '' );
+} else {
+ $CGIsort1 = GetAuthvalueDropbox( 'sort1', '', '' );
+}
+
+# if CGIsort is successfully fetched, the use it
+# else - failback to plain input-field
+if ($CGIsort1) {
+ $template->param( CGIsort1 => $CGIsort1 );
+} else {
+ $template->param( sort1 => $data->{'sort1'} );
+}
+
+my $CGIsort2;
+if ($budget) {
+ if ( defined $budget->{'sort2_authcat'} ) {
+ $CGIsort2 = GetAuthvalueDropbox( 'sort2', $budget->{'sort2_authcat'}, $data->{'sort2'} );
+ }
+} elsif ( scalar(@$budgets) ) {
+ $CGIsort2 = GetAuthvalueDropbox( 'sort2', @$budgets[0]->{sort2_authcat}, '' );
+} else {
+ $CGIsort2 = GetAuthvalueDropbox( 'sort2', '', '' );
+}
+
+if ($CGIsort2) {
+ $template->param( CGIsort2 => $CGIsort2 );
+} else {
+ $template->param( sort2 => $data->{'sort2'} );
+}
+
output_html_with_http_headers $input, $cookie, $template->output;
@@ -268,12 +352,13 @@ sub import_biblios_list {
my $batch = GetImportBatch($import_batch_id,'staged');
my $biblios = GetImportBibliosRange($import_batch_id,'','','staged');
my @list = ();
-# # Itemtype is mandatory for adding a biblioitem, we just add a default, the user needs to modify this aftewards
-# my $itemtypehash = GetItemTypes();
-# my @itemtypes;
-# for my $key (sort { $itemtypehash->{$a}->{description} cmp $itemtypehash->{$b}->{description} } keys %$itemtypehash) {
-# push(@itemtypes, $itemtypehash->{$key});
-# }
+
+ # # Itemtype is mandatory for adding a biblioitem, we just add a default, the user needs to modify this aftewards
+ # my $itemtypehash = GetItemTypes();
+ # my @itemtypes;
+ # for my $key (sort { $itemtypehash->{$a}->{description} cmp $itemtypehash->{$b}->{description} } keys %$itemtypehash) {
+ # push(@itemtypes, $itemtypehash->{$key});
+ # }
foreach my $biblio (@$biblios) {
my $citation = $biblio->{'title'};
$citation .= " $biblio->{'author'}" if $biblio->{'author'};
diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl
index 0ba7180..d5f19ec 100755
--- a/acqui/neworderempty.pl
+++ b/acqui/neworderempty.pl
@@ -69,6 +69,7 @@ the item's id in the breeding reservoir
use warnings;
use strict;
use CGI;
+
use C4::Context;
use C4::Input;
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tmpl
index 94637d1..3658ad5 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tmpl
@@ -8,6 +8,7 @@
</title>
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/jquery/plugins/jquery.tablesorter.min.js"></script>
+<script type="text/javascript" src="<!-- TMPL_VAR NAME='themelang' -->/js/acq.js"></script>
<script type="text/JavaScript">
//<![CDATA[
$(document).ready(function() {
@@ -54,6 +55,7 @@
</td>
<td><!-- TMPL_VAR name="overlay_status"--></td>
<td><a href="/cgi-bin/koha/acqui/neworderempty.pl?booksellerid=<!--TMPL_VAR name="booksellerid" -->&basketno=<!-- TMPL_VAR name="basketno" -->&booksellerid=<!-- TMPL_VAR name="booksellerid" -->&breedingid=<!-- TMPL_VAR name="import_record_id" -->&import_batch_id=<!-- TMPL_VAR name="import_batch_id" -->">Add order</a></td>
+ <td><input type="text" name="price" value="<!-- TMPL_VAR NAME="price" -->" /><td />
</tr>
<!-- TMPL_IF name="match_biblionumber" -->
<tr>
@@ -63,7 +65,8 @@
<!-- /TMPL_IF -->
<!-- /TMPL_LOOP -->
</table>
- <input type="button" value="Save" onclick="this.form.submit()" />
+ <input type="button" value="Save" onclick="this.form.submit()" /><input type="button" value="Select all" onclick="javascript:document.location.href='/cgi-bin/koha/acqui/neworderempty.pl?booksellerid=<!--TMPL_VAR name="booksellerid" -->&basketno=<!-- TMPL_VAR name="basketno" -->&booksellerid=<!-- TMPL_VAR name="booksellerid" -->&breedingid=<!-- TMPL_VAR name="import_record_id" -->&import_batch_id=<!-- TMPL_VAR name="import_batch_id" -->'" />
+
</form>
</div>
<!-- TMPL_IF name="pages" -->
@@ -109,5 +112,123 @@
</div>
</div>
</div>
+
+<div class="yui-t2">
+<h2>Import All</h2>
+<form action="/cgi-bin/koha/acqui/addorder.pl" method="post" id="Aform">
+
+<!-- TMPL_UNLESS name="existing" -->
+ <input type="hidden" name="existing" value="no" />
+ <!-- /TMPL_UNLESS -->
+ <input type="hidden" name="ordernumber" value="<!-- TMPL_VAR NAME="ordernumber" -->" />
+ <input type="hidden" name="basketno" value="<!-- TMPL_VAR NAME="basketno" -->" />
+ <input type="hidden" name="booksellerid" value="<!-- TMPL_VAR NAME="booksellerid" -->" />
+ <input type="hidden" name="biblionumber" value="<!-- TMPL_VAR NAME="biblionumber" -->" />
+ <input type="hidden" name="biblioitemnumber" value="<!-- TMPL_VAR NAME="biblioitemnumber" -->" />
+ <input type="hidden" name="discount" value="<!-- TMPL_VAR NAME="discount" -->" />
+ <input type="hidden" name="listinc" value="<!-- TMPL_VAR NAME="listincgst" -->" />
+ <input type="hidden" name="currency" value="<!-- TMPL_VAR NAME="currency" -->" />
+ <input type="hidden" name="applygst" value="<!-- TMPL_VAR NAME="gstreg" -->" />
+ <input type="hidden" name="invoiceincgst" value="<!-- TMPL_VAR NAME="invoiceincgst" -->" />
+ <input type="hidden" name="gstrate" value="<!-- TMPL_VAR NAME="gstrate" -->" />
+ <input type="hidden" name="suggestionid" value="<!-- TMPL_VAR NAME="suggestionid" -->" />
+ <input type="hidden" name="import_batch_id" value="<!-- TMPL_VAR name="import_batch_id" -->" />
+
+ <!-- TMPL_LOOP NAME="loop_currencies" -->
+ <input type="hidden" name="<!-- TMPL_VAR NAME="currency" -->" value="<!-- TMPL_VAR NAME="rate" -->" />
+ <!-- /TMPL_LOOP -->
+
+ <!-- TMPL_IF name="items" -->
+ <fieldset class="rows">
+ <legend>Item</legend>
+ <!-- TMPL_IF name="NoACQframework" -->
+ <div class="dialog message">No ACQ framework, using default. You should create a framework with code ACQ, the items framework would be used</div>
+ <!-- /TMPL_IF -->
+
+ <!-- TMPL_LOOP NAME="items" -->
+ <div id="outeritemblock">
+ <div id="itemblock">
+ <ol><!-- TMPL_LOOP NAME="iteminformation" --><li>
+ <div class="subfield_line" style="<!-- TMPL_VAR NAME='hidden' -->;" id="subfield<!-- TMPL_VAR NAME='serialid' --><!-- TMPL_VAR NAME='countitems' --><!-- TMPL_VAR NAME='subfield' --><!-- TMPL_VAR name="random" -->">
+
+ <label><!-- TMPL_VAR NAME="subfield" --> - <!-- TMPL_IF name="mandatory" --><b><!-- /TMPL_IF --><!-- TMPL_VAR NAME="marc_lib" --><!-- TMPL_IF name="mandatory" --> *</b><!-- /TMPL_IF --></label>
+ <!-- TMPL_VAR NAME="marc_value" -->
+ <input type="hidden" name="itemid" value="1" />
+ <input type="hidden" name="kohafield" value="<!-- TMPL_VAR NAME="kohafield" -->" />
+ <input type="hidden" name="tag" value="<!-- TMPL_VAR NAME="tag" -->" />
+ <input type="hidden" name="subfield" value="<!-- TMPL_VAR NAME="subfield" -->" />
+ <input type="hidden" name="mandatory" value="<!-- TMPL_VAR NAME="mandatory" -->" />
+ <!-- TMPL_IF NAME="ITEM_SUBFIELDS_ARE_NOT_REPEATABLE" -->
+ <span class="buttonPlus" onclick="CloneSubfield('subfield<!-- TMPL_VAR NAME='serialid' --><!-- TMPL_VAR NAME='countitems' --><!-- TMPL_VAR NAME='subfield' --><!-- TMPL_VAR name="random" -->')">+</span>
+ <!-- /TMPL_IF -->
+
+ </div></li>
+ <!-- /TMPL_LOOP-->
+ </ol>
+ <a style="cursor: pointer; color: grey; font-size: 180%;" onclick="cloneItemBlock('itemblock<!-- TMPL_VAR name="itemBlockIndex" -->')">+</a>
+ <a style="display:none; cursor: pointer; color: grey; font-size: 180%;" onclick="deleteItemBlock('itemblock<!-- TMPL_VAR name="itemBlockIndex" -->')">-</a>
+ </div><!-- /iteminformation -->
+ </div>
+
+ <!--/TMPL_LOOP--> <!-- /items -->
+ </fieldset>
+ <!-- /TMPL_IF --> <!-- items -->
+ <fieldset class="rows">
+ <legend>Accounting Details</legend>
+ <ol>
+ <li>
+ <!-- origquantityrec only here for javascript compatibility (additem.js needs it, useless here, usefull when receiveing an order -->
+ <input id="origquantityrec" readonly="readonly" type="hidden" name="origquantityrec" value="1" />
+ </li>
+ <li>
+ <!-- TMPL_IF name="close" -->
+ <span class="label">Budget: </span>
+ <input type="hidden" size="20" name="budget_id" id="budget_id" value="<!-- TMPL_VAR NAME="budget_id" -->" /><!-- TMPL_VAR NAME="Budget_name" -->
+ <!-- TMPL_ELSE -->
+ <label for="budget_id">Budget: </label>
+ <select id="budget_id" onchange="fetchSortDropbox(this.form)" size="1" name="budget_id">
+ <!-- TMPL_LOOP NAME="budget_loop" -->
+ <!-- TMPL_IF NAME="b_sel" -->
+ <option value="<!-- TMPL_VAR NAME='b_id' -->" selected="selected"><!-- TMPL_VAR NAME="b_txt" --></option>
+ <!-- TMPL_ELSE -->
+ <option value="<!-- TMPL_VAR NAME='b_id' -->"><!-- TMPL_VAR NAME="b_txt" --></option>
+ <!-- /TMPL_IF -->
+ <!-- /TMPL_LOOP -->
+ </select>
+ <!--/TMPL_IF-->
+ </li>
+ <li>
+ <label for="notes">Notes: </label>
+ <textarea id="notes" cols="30" rows="3" name="notes"></textarea>
+ </li>
+ <li><div class="hint">The 2 following fields are available for your own usage. They can be useful for statistical purposes</div>
+ <label for="sort1">Planning value1: </label>
+
+ <!-- TMPL_IF Name="CGIsort1" -->
+ <!-- TMPL_VAR Name="CGIsort1" -->
+ <!-- TMPL_ELSE -->
+
+ <input type="text" id="sort1" size="20" name="sort1" value="<!-- TMPL_VAR NAME="sort1" -->" />
+ <!--/TMPL_IF -->
+ </li>
+ <li>
+ <label for="sort2">Planning value2: </label>
+
+ <!-- TMPL_IF Name="CGIsort2" -->
+ <!-- TMPL_VAR Name="CGIsort2" -->
+ <!-- TMPL_ELSE -->
+ <input type="text" id="sort2" size="20" name="sort2" value="<!-- TMPL_VAR NAME="sort2" -->" />
+ <!--/TMPL_IF -->
+ </li>
+ <li>
+
+ </li>
+</ol>
+ </fieldset>
+ <fieldset class="action">
+ <input type="submit" value="Save" /> <!-- TMPL_IF name="suggestionid" --><a class="cancel" href="/cgi-bin/koha/acqui/newordersuggestion.pl?booksellerid=<!-- TMPL_VAR NAME="booksellerid" -->&basketno=<!-- TMPL_VAR NAME="basketno" -->">Cancel</a><!-- TMPL_ELSE --><a class="cancel" href="/cgi-bin/koha/acqui/basket.pl?basketno=<!-- TMPL_VAR NAME="basketno" -->">Cancel</a><!-- /TMPL_IF -->
+ </fieldset>
+</form>
+</div>
</body>
</html>
--
1.7.1
More information about the Koha-patches
mailing list