[PATCH 27/78] neworderempty, changes

Paul Poulain paul.poulain at biblibre.com
Tue Apr 28 22:22:46 CEST 2009


* deal with import from staged file
* deal with z3950 import
* deal with granular permissions
* deal with uncertain price
* deal with create item if SysPref set to create items on ordering
---
 acqui/fetch_sort_dropbox.pl                        |   64 ++++
 acqui/neworderempty.pl                             |  319 ++++++++++++++++----
 .../prog/en/modules/acqui/neworderempty.tmpl       |  238 +++++++++------
 3 files changed, 467 insertions(+), 154 deletions(-)
 create mode 100755 acqui/fetch_sort_dropbox.pl

diff --git a/acqui/fetch_sort_dropbox.pl b/acqui/fetch_sort_dropbox.pl
new file mode 100755
index 0000000..e052db8
--- /dev/null
+++ b/acqui/fetch_sort_dropbox.pl
@@ -0,0 +1,64 @@
+#!/usr/bin/perl
+
+# Copyright 2008-2009 BibLibre SARL
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA  02111-1307 USA
+
+use strict;
+use CGI;
+use C4::Context;
+use C4::Output;
+use C4::Auth;
+use C4::Budgets;
+
+=head1
+
+fetch_sort_dropbox : 
+
+=cut
+
+my $input = new CGI;
+
+my $budget_id = $input->param('budget_id');
+my $sort_id   = $input->param('sort');
+
+my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
+    {   template_name   => "acqui/ajax.tmpl", # FIXME: REMOVE TMPL DEP?
+        query           => $input,
+        type            => "intranet",
+        authnotrequired => 0,
+        flagsrequired => {editcatalogue => 1},
+        debug => 0,
+    }
+);
+
+my $sort_dropbox;
+my $budget = GetBudget($budget_id);
+
+if ( $sort_id == 1 ) {
+    $sort_dropbox = GetAuthvalueDropbox( 'sort1', $budget->{'sort1_authcat'}, '' );
+} elsif ( $sort_id == 2 ) {
+    $sort_dropbox = GetAuthvalueDropbox( 'sort2', $budget->{'sort2_authcat'}, '' );
+}
+
+#strip off select tags ;/
+$sort_dropbox =~ s/^\<select.*?\"\>//;
+$sort_dropbox =~ s/\<\/select\>$//;
+chomp $sort_dropbox;
+
+$template->param( return => $sort_dropbox );
+output_html_with_http_headers $input, $cookie, $template->output;
+1;
diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl
index df23586..e6e66d0 100755
--- a/acqui/neworderempty.pl
+++ b/acqui/neworderempty.pl
@@ -56,19 +56,26 @@ the basket number for this new order.
 =item suggestionid
 if this order comes from a suggestion.
 
+=item breedingid
+the item's id in the breeding reservoir
+
 =item close
 
 =back
 
 =cut
 
+use warnings;
 use strict;
 use CGI;
 use C4::Context;
 use C4::Input;
 
 use C4::Auth;
-use C4::Bookfund;
+use C4::Budgets;
+use C4::Input;
+#use C4::Bookfund;
+
 use C4::Bookseller;		# GetBookSellerFromId
 use C4::Acquisition;
 use C4::Suggestions;	# GetSuggestion
@@ -78,9 +85,14 @@ use C4::Input;
 use C4::Koha;
 use C4::Branch;			# GetBranches
 use C4::Members;
+use C4::Search qw/FindDuplicate BiblioAddAuthorities/;
+
+#needed for z3950 import:
+use C4::ImportBatch qw/GetImportRecordMarc/;
 
 my $input        = new CGI;
 my $booksellerid = $input->param('booksellerid');	# FIXME: else ERROR!
+my $budget_id    = $input->param('budget_id');	# FIXME: else ERROR!
 my $title        = $input->param('title');
 my $author       = $input->param('author');
 my $copyright    = $input->param('copyright');
@@ -92,8 +104,59 @@ my $purchaseorder= $input->param('purchaseordernumber');
 my $suggestionid = $input->param('suggestionid');
 # my $donation     = $input->param('donation');
 my $close        = $input->param('close');
+my $uncertainprice = $input->param('uncertainprice');
 my $data;
-my $new;
+my $new = 'no';
+
+my $budget_name;
+
+my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
+    {
+        template_name   => "acqui/neworderempty.tmpl",
+        query           => $input,
+        type            => "intranet",
+        authnotrequired => 0,
+        flagsrequired   => { acquisition => 'order_manage' },
+        debug           => 1,
+    }
+);
+
+#simple parameters reading (all in one :-)
+my $params = $input->Vars;
+if ( $ordnum eq '' and defined $params->{'breedingid'}){
+#we want to import from the breeding reservoir (from a z3950 search)
+    my ($marcrecord, $encoding) = MARCfindbreeding($params->{'breedingid'});
+    die("Could not find the selected record in the reservoir, bailing") unless $marcrecord;
+
+    my $duplicatetitle;
+#look for duplicates
+    if (! (($biblionumber,$duplicatetitle) = FindDuplicate($marcrecord))){
+        my $itemtypes = GetItemTypes();
+        my $marcflavour = C4::Context->preference("marcflavour");
+#         warn("$marcflavour----itemtype"."-------------marcflavour".$marcflavour."---------subfield".$marcrecord->subfield('200', 'b'));
+#use the itemtype field of the UNIMARC standard.
+        if ( $marcflavour eq 'UNIMARC' ) {
+            my $itemtype = $marcrecord->subfield('200', 'b');
+#Check wether the itemtype is known
+            warn(grep { $itemtypes->{$_}->{itemtype} =~ /$itemtype/ } keys %$itemtypes);
+            if (scalar(grep { $itemtypes->{$_}->{itemtype} =~ /$itemtype/ } keys %$itemtypes) == 0) {
+                my @itemtypes = sort {lc($itemtypes->{$a}->{'description'}) cmp lc($itemtypes->{$b}->{'description'})} keys %$itemtypes;
+                $itemtype = $itemtypes[0];
+#                warn(YAML->Dump(@itemtypes));
+                $marcrecord->field('200')->update('b' => $itemtype);
+            }
+        }
+        if (C4::Context->preference("BiblioAddsAuthorities")){
+              my ($countlinked,$countcreated)=BiblioAddAuthorities($marcrecord, $params->{'frameworkcode'});
+        }
+        my $bibitemnum;
+        $params->{'frameworkcode'} or $params->{'frameworkcode'} = "";
+        ( $biblionumber, $bibitemnum ) = AddBiblio( $marcrecord, $params->{'frameworkcode'} );
+    }
+}
+
+
+my $cur = GetCurrency();
 
 if ( $ordnum eq '' ) {    # create order
     $new = 'yes';
@@ -112,27 +175,20 @@ if ( $ordnum eq '' ) {    # create order
 else {    #modify order
     $data   = GetOrder($ordnum);
     $biblionumber = $data->{'biblionumber'};
+    $budget_id = $data->{'budget_id'};
+
     #get basketno and supplierno. too!
     my $data2 = GetBasket( $data->{'basketno'} );
     $basketno     = $data2->{'basketno'};
     $booksellerid = $data2->{'booksellerid'};
 }
 
-my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
-    {
-        template_name   => "acqui/neworderempty.tmpl",
-        query           => $input,
-        type            => "intranet",
-        authnotrequired => 0,
-        flagsrequired   => { acquisition => 1 },
-        debug           => 1,
-    }
-);
-
 # get currencies (for change rates calcs if needed)
 my @rates = GetCurrencies();
 my $count = scalar @rates;
 
+# ## @rates
+
 my @loop_currency = ();
 for ( my $i = 0 ; $i < $count ; $i++ ) {
     my %line;
@@ -141,6 +197,9 @@ for ( my $i = 0 ; $i < $count ; $i++ ) {
     push @loop_currency, \%line;
 }
 
+    # ##  @loop_currency
+
+
 # build itemtype list
 my $itemtypes = GetItemTypes;
 
@@ -149,70 +208,71 @@ foreach my $thisitemtype (sort keys %$itemtypes) {
     push @itemtypesloop, { itemtype => $itemtypes->{$thisitemtype}->{'itemtype'} , desc =>  $itemtypes->{$thisitemtype}->{'description'} } ;
 }
 
-# build branches list
-my $onlymine=C4::Context->preference('IndependantBranches') && 
-             C4::Context->userenv && 
-             C4::Context->userenv->{flags}!=1 && 
-             C4::Context->userenv->{branch};
-my $branches = GetBranches($onlymine);
-my @branchloop;
-foreach my $thisbranch ( sort keys %$branches ) {
-     my %row = (
-        value      => $thisbranch,
-        branchname => $branches->{$thisbranch}->{'branchname'},
-    );
-	$row{'selected'} = 1 if( $thisbranch eq $data->{branchcode}) ;
-    push @branchloop, \%row;
-}
-$template->param( branchloop => \@branchloop , itypeloop => \@itemtypesloop );
+$template->param( itypeloop => \@itemtypesloop );
 
-# build bookfund list
 my $borrower= GetMember($loggedinuser);
 my ( $flags, $homebranch )= ($borrower->{'flags'},$borrower->{'branchcode'});
 
-my @select_bookfund;
-my %select_bookfunds;
-
-my @bookfund = GetBookFunds($homebranch);
-my $count2 = scalar @bookfund;
-
-for ( my $i = 0 ; $i < $count2 ; $i++ ) {
-    push @select_bookfund, $bookfund[$i]->{'bookfundid'};
-    $select_bookfunds{ $bookfund[$i]->{'bookfundid'} } =
-      $bookfund[$i]->{'bookfundname'};
+my $budget =  GetBudget($budget_id);
+# build budget list
+my %labels;
+my @values;
+my $budgets = GetBudgetHierarchy('1','',$borrower->{'borrowernumber'});
+foreach my $r (@$budgets) {
+    $labels{"$r->{budget_id}"} = $r->{budget_name};
+    next if  sprintf ("%00d",  $r->{budget_amount})  ==   0;
+    push @values, $r->{budget_id};
 }
-my $CGIbookfund = CGI::scrolling_list(
-    -name     => 'bookfund',
-	-id       => 'bookfund',
-    -values   => \@select_bookfund,
-    -default  => ($data->{'bookfundid'} ? $data->{'bookfundid'} : $select_bookfund[0]),
-    -labels   => \%select_bookfunds,
-	#-size     => 1,
-    -multiple => 0
+# if no budget_id is passed then its an add
+my $budget_dropbox = CGI::scrolling_list(
+    -name    => 'budget_id',
+    -id      => 'budget_id',
+    -values  => \@values,
+    -size    => 1,
+    -labels  => \%labels,
+    -onChange   => "fetchSortDropbox(this.form)",
 );
 
-my $bookfundname;
-my $bookfundid;
 if ($close) {
-    $bookfundid   = $data->{'bookfundid'};
-    $bookfundname = $select_bookfunds{$bookfundid};
+    $budget_id      =  $data->{'budget_id'};
+    $budget_name    =   $budget->{'budget_name'};      
+
+}
+
+
+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'} );
+    }
+} else {
+    $CGIsort1 = GetAuthvalueDropbox( 'sort1', 'Asort1', '' );
 }
 
-#Build sort lists
-my $CGIsort1 = buildCGIsort( "Asort1", "sort1", $data->{'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 = buildCGIsort( "Asort2", "sort2", $data->{'sort2'} );
+my $CGIsort2;
+if ($budget) {
+    if ( defined $budget->{'sort2_authcat'} ) {
+        $CGIsort2 = GetAuthvalueDropbox( 'sort2', $budget->{'sort2_authcat'}, $data->{'sort2'} );
+    }
+} else {
+    $CGIsort2 = GetAuthvalueDropbox( 'sort2', 'Asort2', '' );
+}
 if ($CGIsort2) {
     $template->param( CGIsort2 => $CGIsort2 );
 } else {
     $template->param( sort2 => $data->{'sort2'} );
 }
 
+
+
 #do a biblioitems lookup on bib
 my @bibitems = GetBiblioItemByBiblioNumber($biblionumber);
 my $bibitemscount = scalar @bibitems;
@@ -233,14 +293,24 @@ if ( $bibitemscount > 0 ) {
     $template->param( bibitemexists => "1" );
 }
 
+if (C4::Context->preference('AcqCreateItem') eq 'ordering' && !$ordnum) {
+    # prepare empty item form
+    my $cell = PrepareItemrecordDisplay();
+    my @itemloop;
+    push @itemloop,$cell;
+    
+    $template->param(items => \@itemloop);
+}
+
 # fill template
 $template->param(
     close        => $close,
-    bookfundid   => $bookfundid,
-    bookfundname => $bookfundname
+    budget_id    => $budget_id,
+    budget_name  => $budget_name
   )
   if ($close);
 
+    # ## @loop_currency,
 $template->param(
     existing         => $biblionumber,
     ordnum           => $ordnum,
@@ -248,38 +318,157 @@ $template->param(
     booksellerid     => $booksellerid,
     suggestionid     => $suggestionid,
     biblionumber     => $biblionumber,
+    uncertainprice   => $data->{'uncertainprice'},
     authorisedbyname => $borrower->{'firstname'} . " " . $borrower->{'surname'},
 	biblioitemnumber => $data->{'biblioitemnumber'},
     itemtype         => $data->{'itemtype'},
     itemtype_desc    => $itemtypes->{$data->{'itemtype'}}->{description},
+    discount_2dp     => sprintf( "%.2f",  $bookseller->{'discount'}) ,   # for display
     discount         => $bookseller->{'discount'},
     listincgst       => $bookseller->{'listincgst'},
-    listprice        => $bookseller->{'listprice'},
-    gstreg           => $bookseller->{'gstreg'},
-    invoiceinc       => $bookseller->{'invoiceincgst'},
+    invoiceincgst    => $bookseller->{'invoiceincgst'},
     invoicedisc      => $bookseller->{'invoicedisc'},
     nocalc           => $bookseller->{'nocalc'},
     name             => $bookseller->{'name'},
-    currency         => $bookseller->{'listprice'},
-    gstrate          => C4::Context->preference("gist") || 0,
+    cur_active_sym   => $cur->{symbol},
+    cur_active       => $cur->{currency},
+    currency         => $bookseller->{'listprice'}, # eg: 'EUR'
     loop_currencies  => \@loop_currency,
     orderexists      => ( $new eq 'yes' ) ? 0 : 1,
     title            => $data->{'title'},
     author           => $data->{'author'},
     copyrightdate    => $data->{'copyrightdate'},
-    CGIbookfund      => $CGIbookfund,
+    budget_dropbox   => $budget_dropbox,
     isbn             => $data->{'isbn'},
     seriestitle      => $data->{'seriestitle'},
     quantity         => $data->{'quantity'},
-    listprice        => $data->{'listprice'},
+    quantityrec      => $data->{'quantity'},
+
+
     rrp              => $data->{'rrp'},
-    total            => $data->{ecost}*$data->{quantity},
+    list_price       => sprintf("%.2f", $data->{'listprice'}), # watch the '-'
+    total            => sprintf("%.2f", $data->{ecost}*$data->{quantity} ),
     invoice          => $data->{'booksellerinvoicenumber'},
     ecost            => $data->{'ecost'},
     purchaseordernumber => $data->{'purchaseordernumber'},
     notes            => $data->{'notes'},
     publishercode    => $data->{'publishercode'},
+
+
+# CHECKME: gst-stuff needs verifing, mason.
+    gstrate          => $bookseller->{gstrate} || C4::Context->preference("gist"),
+    gstreg           => $bookseller->{'gstreg'},
+
 #     donation         => $donation
 );
 
 output_html_with_http_headers $input, $cookie, $template->output;
+
+
+=item MARCfindbreeding
+
+    $record = MARCfindbreeding($breedingid);
+
+Look up the import record repository for the record with
+record with id $breedingid.  If found, returns the decoded
+MARC::Record; otherwise, -1 is returned (FIXME).
+Returns as second parameter the character encoding.
+
+=cut
+
+sub MARCfindbreeding {
+    my ( $id ) = @_;
+    my ($marc, $encoding) = GetImportRecordMarc($id);
+    # remove the - in isbn, koha store isbn without any -
+    if ($marc) {
+        my $record = MARC::Record->new_from_usmarc($marc);
+        my ($isbnfield,$isbnsubfield) = GetMarcFromKohaField('biblioitems.isbn','');
+        if ( $record->field($isbnfield) ) {
+            foreach my $field ( $record->field($isbnfield) ) {
+                foreach my $subfield ( $field->subfield($isbnsubfield) ) {
+                    my $newisbn = $field->subfield($isbnsubfield);
+                    $newisbn =~ s/-//g;
+                    $field->update( $isbnsubfield => $newisbn );
+                }
+            }
+        }
+        # fix the unimarc 100 coded field (with unicode information)
+        if (C4::Context->preference('marcflavour') eq 'UNIMARC' && $record->subfield(100,'a')) {
+            my $f100a=$record->subfield(100,'a');
+            my $f100 = $record->field(100);
+            my $f100temp = $f100->as_string;
+            $record->delete_field($f100);
+            if ( length($f100temp) > 28 ) {
+                substr( $f100temp, 26, 2, "50" );
+                $f100->update( 'a' => $f100temp );
+                my $f100 = MARC::Field->new( '100', '', '', 'a' => $f100temp );
+                $record->insert_fields_ordered($f100);
+            }
+        }
+		
+        if ( !defined(ref($record)) ) {
+            return -1;
+        }
+        else {
+            # normalize author : probably UNIMARC specific...
+            if (    C4::Context->preference("z3950NormalizeAuthor")
+                and C4::Context->preference("z3950AuthorAuthFields") )
+            {
+                my ( $tag, $subfield ) = GetMarcFromKohaField("biblio.author");
+
+ #                 my $summary = C4::Context->preference("z3950authortemplate");
+                my $auth_fields =
+                  C4::Context->preference("z3950AuthorAuthFields");
+                my @auth_fields = split /,/, $auth_fields;
+                my $field;
+
+                if ( $record->field($tag) ) {
+                    foreach my $tmpfield ( $record->field($tag)->subfields ) {
+
+       #                        foreach my $subfieldcode ($tmpfield->subfields){
+                        my $subfieldcode  = shift @$tmpfield;
+                        my $subfieldvalue = shift @$tmpfield;
+                        if ($field) {
+                            $field->add_subfields(
+                                "$subfieldcode" => $subfieldvalue )
+                              if ( $subfieldcode ne $subfield );
+                        }
+                        else {
+                            $field =
+                              MARC::Field->new( $tag, "", "",
+                                $subfieldcode => $subfieldvalue )
+                              if ( $subfieldcode ne $subfield );
+                        }
+                    }
+                }
+                $record->delete_field( $record->field($tag) );
+                foreach my $fieldtag (@auth_fields) {
+                    next unless ( $record->field($fieldtag) );
+                    my $lastname  = $record->field($fieldtag)->subfield('a');
+                    my $firstname = $record->field($fieldtag)->subfield('b');
+                    my $title     = $record->field($fieldtag)->subfield('c');
+                    my $number    = $record->field($fieldtag)->subfield('d');
+                    if ($title) {
+
+#                         $field->add_subfields("$subfield"=>"[ ".ucfirst($title).ucfirst($firstname)." ".$number." ]");
+                        $field->add_subfields(
+                                "$subfield" => ucfirst($title) . " "
+                              . ucfirst($firstname) . " "
+                              . $number );
+                    }
+                    else {
+
+#                       $field->add_subfields("$subfield"=>"[ ".ucfirst($firstname).", ".ucfirst($lastname)." ]");
+                        $field->add_subfields(
+                            "$subfield" => ucfirst($firstname) . ", "
+                              . ucfirst($lastname) );
+                    }
+                }
+                $record->insert_fields_ordered($field);
+            }
+            return $record, $encoding;
+        }
+    }
+    return -1;
+}
+
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tmpl
index 34e2cb8..2daf10b 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tmpl
@@ -1,87 +1,72 @@
 <!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
 <title>Koha &rsaquo; Acquisitions &rsaquo; Shopping Basket <!-- TMPL_VAR NAME="basketno" --> &rsaquo; <!-- TMPL_IF name="ordnum" -->Modify order details (line #<!-- TMPL_VAR NAME="ordnum" -->)<!-- TMPL_ELSE -->New order<!-- /TMPL_IF --></title>
 <!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+
+<script type="text/javascript" src="<!-- TMPL_VAR NAME='themelang' -->/js/acq.js"></script>
+<script type="text/javascript" src="<!-- TMPL_VAR NAME='themelang' -->/js/additem.js"></script>
 <script type="text/javascript">
 //<![CDATA[
-function update(f){
-//collect values
-quantity=f.quantity.value;
-if (quantity ==0) {
-    alert("Quantity must be >0");
-}
- discount=f.discount.value;
- currency=f.currency.value;
-listprice=f.list_price.value;
-  listinc=parseInt(f.listinc.value);
- applygst=parseInt(f.applygst.value);
-//  rrp=f.rrp.value
-//  ecost=f.ecost.value  //budgetted cost
-//  GST=f.GST.value
-//  total=f.total.value
-//make useful constants out of the above
-exchangerate=f.elements[currency].value;      //get exchange rate.  same as "discount" above?
-gst_on=(!listinc && applygst);
-//do real stuff
-rrp=listprice*exchangerate;
-ecost=rrp*(100-discount)/100;
-GST=0;
-if (gst_on){
-<!-- TMPL_IF NAME="gstrate"-->
-    rrp=rrp*(1+<!-- TMPL_VAR NAME="gstrate" -->);
-    GST=ecost*(<!-- TMPL_VAR NAME="gstrate" -->);
-<!-- TMPL_ELSE --> ; // TMPL_VAR NAME=gstrate not set.  leave rrp and GST alone.
-<!-- /TMPL_IF -->
-}
+ actTotal = "";
 
-total=(ecost+GST)*quantity;
+function Check(ff) {
+    var ok=0;
+    var _alertString="Form not submitted because of the following problem(s)\n";
 
-  f.rrp.value=rrp;
-f.ecost.value=ecost;
-f.total.value=total;
-<!-- TMPL_IF NAME="GST" -->  // FIXME: TMPL_VAR NAME="GST" never populated
-  f.GST.value=GST;
-<!-- /TMPL_IF -->
-return true;
-}
+    _alertString +="-------------------------------------------------------------------\n\n";
 
-function messenger(X,Y,etc){	// FIXME: unused?
-    win=window.open("","mess","height="+X+",width="+Y+",screenX=150,screenY=0");
-    win.focus();
-    win.document.close();
-    win.document.write("<body>");
-    win.document.write(etc);
-    win.document.write("<form><input type=\"button\" onclick=\"self.close()\" value=\"Close\" \/><\/form>");
-    win.document.write("<\/body><\/html>");
-}
+    if ( isNull(ff.title,1)  &&  isNull(ff.entertitle,1)   ){
+        ok=1;
+                    _alertString += "\n- " + _("Title cannot be empty");
+    }
 
-function check(f) {
-quantity=f.quantity.value
-title=f.title.value
-if (title == "") {
-    alert("Title can't be empty");
-    return false;
-}
-if (quantity ==0) {
-    alert("Quantity must be >0");
+    if (!(isNum(ff.quantity,0))){
+        ok=1;
+                    _alertString += "\n- " + _("Quanity must be greater than '0'");
+    }
+
+    if (!(isNum(ff.list_price,0))){
+        ok=1;
+                    _alertString += "\n- " + _("Vendor price must be a number");
+    }
+
+    if (!(isNum(ff.total,0))){
+        ok=1;
+                    _alertString += "\n- " + _("Total must be a number");
+    }
+
+   	if (totalExceedsBudget(ff.budget_id.value, ff.total.value  )  ) {
+    	ok=1;
+     	_alertString += "\n- " + "Order total (" + ff.total.value + ") exceeds budget available ("+actTotal+")";
+    }
+
+   if (ok) {
+        alert(_alertString);
     return false;
+    }
+
+   ff.submit();
+
 }
-    document.frusin.submit();
-}
+
+
 //]]>
 </script>
 </head>
 <body>
+
+<div  name="<!-- TMPL_VAR NAME="ordnum" -->" >
+
 <!-- TMPL_INCLUDE NAME="header.inc" -->
 <!-- TMPL_INCLUDE NAME="acquisitions-search.inc" -->
 
 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a> &rsaquo; <a href="/cgi-bin/koha/acqui/basket.pl?basketno=<!-- TMPL_VAR NAME="basketno" -->">Shopping Basket <!-- TMPL_VAR NAME="basketno" --></a> &rsaquo; <!-- TMPL_IF name="ordnum" -->Modify order details (line #<!-- TMPL_VAR NAME="ordnum" -->)<!-- TMPL_ELSE -->New order<!-- /TMPL_IF --></div>
 
 <div id="doc3" class="yui-t2">
-   
+
    <div id="bd">
 	<div id="yui-main">
 	<div class="yui-b">
-	
+
 <h1>
     <!-- TMPL_IF name="ordnum" -->
         Modify order details (line #<!-- TMPL_VAR NAME="ordnum" -->)
@@ -92,6 +77,7 @@ if (quantity ==0) {
 </h1>
 
 <!-- TMPL_IF name="basketno" -->
+<fieldset class="rows">
 <div id="basket-details">Basket Details
   <ul>  <li>Basket number: <!-- TMPL_VAR NAME="basketno" --></li>
     <li>Managed by: <!-- TMPL_VAR NAME="authorisedbyname" --></li>
@@ -100,9 +86,13 @@ if (quantity ==0) {
     <li>Invoice number: <!-- TMPL_VAR NAME="booksellerinvoicenumber" --></li>
     <!-- TMPL_IF name="closedate" --><li>Closed on: <!-- TMPL_VAR name="closedate" --></li><!-- /TMPL_IF --></ul>
 </div>
+</fieldset>
 <!-- /TMPL_IF -->
 
-<form action="/cgi-bin/koha/acqui/addorder.pl" method="post" name="frusin">
+<form action="/cgi-bin/koha/acqui/addorder.pl" method="post" name="Aform">
+
+
+
 <fieldset class="rows">
         <legend>Catalog details</legend>
         <!-- TMPL_UNLESS name="existing" -->
@@ -118,6 +108,11 @@ if (quantity ==0) {
         <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" -->" />
         <!-- TMPL_LOOP NAME="loop_currencies" -->
             <input type="hidden" name="<!-- TMPL_VAR NAME="currency" -->" value="<!-- TMPL_VAR NAME="rate" -->" />
@@ -125,12 +120,14 @@ if (quantity ==0) {
         <ol><li>
             <!-- TMPL_IF name="biblionumber" -->
 			<span class="label">Title</span>
-                <input type="hidden" size="20" name="title" value="<!-- TMPL_VAR NAME="title" -->" /> <span class="title"><!-- TMPL_VAR NAME="title" escape="html" --></span>
+                <input type="hidden" size="20" name="title" value="<!-- TMPL_VAR NAME="title" ESCAPE="HTML" -->" /> <span class="title"><!-- TMPL_VAR NAME="title" --></span>
             <!-- TMPL_ELSE -->
             <label for="entertitle" class="required">Title: </label>
-                <input type="text" id="entertitle" size="20" name="title" value="<!-- TMPL_VAR NAME="title" -->" />
+                <input type="text" id="entertitle" size="20" name="title" value="<!-- TMPL_VAR NAME="title" ESCAPE="HTML" -->" />
             <!-- /TMPL_IF -->
         </li>
+
+
         <li>
             <!-- TMPL_IF name="biblionumber" -->
 			<span class="label">Author: </span>
@@ -189,19 +186,47 @@ if (quantity ==0) {
                 <input type="text" size="20" name="series" id="series" value="<!-- TMPL_VAR NAME="seriestitle" -->" />
             <!-- /TMPL_IF -->
         </li>
-        <li>
-            <label for="branch">Library: </label>
-            <select name="branch" id="branch">
-            <!-- TMPL_LOOP name="branchloop" -->
-                <!-- TMPL_IF NAME="selected" --><option value="<!-- TMPL_VAR NAME="value" -->" selected="selected"><!-- TMPL_VAR NAME="branchname" --></option>
-				<!-- TMPL_ELSE -->
-				<option value="<!-- TMPL_VAR NAME="value" -->"><!-- TMPL_VAR NAME="branchname" --></option>
-				<!-- /TMPL_IF -->
-            <!-- /TMPL_LOOP -->
-            </select>
-        </li>
 		</ol>
     </fieldset>
+    <!-- TMPL_IF name="items" -->
+    <fieldset class="rows">
+        <legend>Item</legend>
+
+        <!-- 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>
+
+        <input type="hidden" name="moditem" value="" />
+        <input type="hidden" name="tag" value="<!-- TMPL_VAR NAME="itemtagfield" -->" />
+        <input type="hidden" name="subfield" value="<!-- TMPL_VAR NAME="itemtagsubfield" -->" />
+        <input type="hidden" name="serial" value="<!-- TMPL_VAR NAME="serialid" -->" />
+        <input type="hidden" name="bibnum" value="<!-- TMPL_VAR NAME="biblionumber" -->" />
+        <input type="hidden" name="itemid" value="1" />
+        <input type="hidden" name="field_value" value="<!-- TMPL_VAR NAME="itemnumber" -->" />
+        <!--/TMPL_LOOP--> <!-- /items -->
+    </fieldset>
+    <!-- /TMPL_IF --> <!-- items -->
 	<fieldset class="rows">
         <legend>Accounting Details</legend>
 		<ol>
@@ -211,34 +236,53 @@ if (quantity ==0) {
                     <input type="hidden" size="20" id="quantity" name="quantity" value="<!-- TMPL_VAR NAME="quantity" -->" /><!-- TMPL_VAR NAME="quantity" -->
                 <!-- TMPL_ELSE -->
                 <label class="required" for="quantity">Quantity: </label>
-                    <input type="text" size="20" id="quantity" name="quantity" value="<!-- TMPL_VAR NAME="quantity" -->" onchange="update(this.form);" />
+                    <!-- TMPL_IF name="items" -->
+                        <input type="text" READONLY size="20" id="quantityrec" name="quantity" value="1" onchange="calcNeworderTotal(this.form);" />
+                    <!-- TMPL_ELSE -->
+                        <input type="text" size="20" id="quantityrec" name="quantity" value="<!-- TMPL_VAR name="quantityrec" -->" onchange="calcNeworderTotal(this.form);" />
+                    <!-- /TMPL_IF -->
                 <!--/TMPL_IF-->
+                <!-- origquantityrec only here for javascript compatibility (additem.js needs it, useless here, usefull when receiveing an order -->
+                <input id="origquantityrec" READONLY type="hidden" name="origquantityrec" value="1" />
             </li>
+
+
             <li>
                 <!-- TMPL_IF name="close" -->
-			<span class="label">Fund: </span>
-                    <input type="hidden" size="20" name="bookfund" id="bookfund" value="<!-- TMPL_VAR NAME="bookfundid" -->" /><!-- TMPL_VAR NAME="bookfundname" -->
+			<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="bookfund">Fund: </label>
-                    <!-- TMPL_VAR NAME="CGIbookfund" -->
+                <label for="budget_id">Budget: </label>
+                    <!-- TMPL_VAR NAME="budget_dropbox" -->
                 <!--/TMPL_IF-->
             </li>
+
             <li>
                 <!-- TMPL_IF name="close" -->
 			<span class="label">Vendor price: </span>
-                    <input type="hidden" size="20" name="list_price" id="list_price" value="<!-- TMPL_VAR NAME="listprice" -->" /><!-- TMPL_VAR NAME="listprice" -->
+                    <input type="hidden" size="20" name="list_price" id="list_price" value="<!-- TMPL_VAR NAME="list_price" -->" /><!-- TMPL_VAR NAME="list_price" -->
                 <!-- TMPL_ELSE -->
                 <label for="list_price">Vendor price: </label>
-                    <input type="text" size="20" name="list_price" id="list_price" value="<!-- TMPL_VAR NAME="listprice" -->" onchange="update(this.form)" />
+                    <input type="text" size="20" name="list_price" id="list_price" value="<!-- TMPL_VAR NAME="list_price" -->" onchange="calcNeworderTotal(this.form)" /> (entered as <!-- TMPL_VAR NAME="currency" -->)
+
                 <!--/TMPL_IF-->
             </li>
+            <!-- TMPL_UNLESS NAME="close" -->
             <li>
+                    <label for="uncertainprice">Uncertain price: </label>
+                    <!--TMPL_IF NAME="uncertainprice" -->
+                    <input type="checkbox" name="uncertainprice" value="1" checked />
+                    <!-- TMPL_ELSE -->
+                    <input type="checkbox" name="uncertainprice" value="1" />
+                   <!--/TMPL_IF-->
+            </li>
+            <!-- /TMPL_UNLESS -->
                 <!-- TMPL_IF name="close" -->
 			<span class="label">Replacement cost: </span>
                     <input type="hidden" size="20" name="rrp" id="rrp" value="<!-- TMPL_VAR NAME="rrp" -->" /><!-- TMPL_VAR NAME="rrp" -->
                 <!-- TMPL_ELSE -->
-                <label for="rrp">Replacement cost : </label>
-                    <input type="text" size="20" name="rrp" id="rrp" value="<!-- TMPL_VAR NAME="rrp" -->" />
+                <label for="rrp">Replacement cost: </label>
+                    <input type="text" size="20" name="rrp" id="rrp" value="<!-- TMPL_VAR NAME="rrp" -->" /> (adjusted for <!-- TMPL_VAR NAME="cur_active" -->)
                 <!--/TMPL_IF-->
             </li>
             <li>
@@ -249,6 +293,8 @@ if (quantity ==0) {
                 <label for="ecost">Budgeted cost: </label>
                     <input type="text" size="20" name="ecost" id="ecost" value="<!-- TMPL_VAR NAME="ecost" -->" />
                 <!--/TMPL_IF-->
+                <!-- TMPL_IF name="discount_2dp" -->  (adjusted for <!-- TMPL_VAR name="discount_2dp" -->% discount)  <!--/TMPL_IF-->
+
             </li>
             <!-- TMPL_IF NAME="GST"-->
             <li>
@@ -261,13 +307,14 @@ if (quantity ==0) {
 				<!--/TMPL_IF-->
             </li>
             <!-- /TMPL_IF -->
+
             <li>
                 <!-- TMPL_IF name="close" -->
 			<label for="total">Total: </label>
 				<input type="text" id="total" size="20" name="total" value="<!-- TMPL_VAR name="total" -->" readonly="readonly" />
 				<!-- TMPL_ELSE -->
                 <label for="total">Total: </label>
-                <input type="text" id="total" size="20" name="total" value="<!-- TMPL_VAR name="total" -->" />
+                <input type="text" id="total" size="20" name="total" value="<!-- TMPL_VAR name="total" -->" /> (budgeted cost * quantity)
 				<!--/TMPL_IF-->
             </li>
             <li>
@@ -281,7 +328,7 @@ if (quantity ==0) {
             </li>
             <li>
                 <label for="purchaseordernumber">Purchase order: </label>
-                <input type="text" id="purchaseordernumber" size="20" name="purchaseordernumber"  value="<!-- TMPL_VAR name="purchaseordernumber" -->" /> 
+                <input type="text" id="purchaseordernumber" size="20" name="purchaseordernumber"  value="<!-- TMPL_VAR name="purchaseordernumber" -->" />
             </li>
             <li>
                 <label for="invoice">Invoice number: </label>
@@ -291,25 +338,37 @@ if (quantity ==0) {
                 <label for="notes">Notes: </label>
                 <textarea id="notes" cols="30" rows="3" name="notes"><!-- TMPL_VAR 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 -->
-                <label for="sort1">Sort field 1: </label>
+
                     <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 -->
-                <label for="sort2">Sort field 2: </label>
                     <input type="text" id="sort2" size="20" name="sort2" value="<!-- TMPL_VAR NAME="sort2" -->" />
                 <!--/TMPL_IF -->
-            </li></ol>
+            </li>
+
+
+
+</ol>
     </fieldset>
     <fieldset class="action">
-        <input type="button" value="Save" onclick="check(this.form)" /> <!-- 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 -->
+        <input type="button" value="Save" onclick="Check(this.form)" /> <!-- 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>
@@ -318,4 +377,5 @@ if (quantity ==0) {
 <!-- TMPL_INCLUDE NAME="acquisitions-menu.inc" -->
 </div>
 </div>
+</div>
 <!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->
-- 
1.6.0.4


--------------040707080604020206060201
Content-Type: text/x-patch;
 name="0067-check-errors-not-new_acq-related.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="0067-check-errors-not-new_acq-related.patch"



More information about the Koha-patches mailing list