Merging Katipo changes
[koha.git] / acqui / newbiblio.pl
index 08e8fe8..2b19a83 100755 (executable)
@@ -29,8 +29,11 @@ use C4::Database;
 use C4::Auth;
 use C4::Acquisition;
 use C4::Suggestions;
+use C4::Biblio;
 use C4::Search;
 use C4::Output;
+use C4::Input;
+use C4::Koha;
 use C4::Interface::CGI::Output;
 use HTML::Template;
 
@@ -44,6 +47,7 @@ my $ordnum=$input->param('ordnum');
 my $biblio=$input->param('biblio');
 my $basketno=$input->param('basketno');
 my $suggestionid = $input->param('suggestionid');
+my $close= $input->param('close');
 my $data;
 my $new;
 my $dbh = C4::Context->dbh;
@@ -109,26 +113,26 @@ my $CGIitemtype=CGI::scrolling_list( -name     => 'format',
 $sth->finish;
 
 # build branches list
-my @branches;
-my @select_branch;
-my %select_branches;
-my ($count2,@branches)=branches();
-for (my $i=0;$i<$count2;$i++){
-       push @select_branch, $branches[$i]->{'branchcode'};#
-       $select_branches{$branches[$i]->{'branchcode'}} = $branches[$i]->{'branchname'};
+my $branches = getbranches;
+my @branchloop;
+foreach my $thisbranch (sort keys %$branches) {
+       my %row =(value => $thisbranch,
+                               branchname => $branches->{$thisbranch}->{'branchname'},
+                       );
+       push @branchloop, \%row;
 }
-my $CGIbranch=CGI::scrolling_list( -name     => 'branch',
-                       -values   => \@select_branch,
-                       -default  => $data->{'branchcode'},
-                       -labels   => \%select_branches,
-                       -size     => 1,
-                       -multiple => 0 );
+$template->param(branchloop =>\@branchloop);
 
 # build bookfund list
+my $sthtemp = $dbh->prepare("Select flags, branchcode from borrowers where borrowernumber = ?");
+$sthtemp->execute($loggedinuser);
+my ($flags, $homebranch)=$sthtemp->fetchrow;
+
+my $count2;
 my @bookfund;
 my @select_bookfund;
 my %select_bookfunds;
-($count2,@bookfund)=bookfunds();
+($count2,@bookfund)=bookfunds($homebranch);
 for (my $i=0;$i<$count2;$i++){
        push @select_bookfund, $bookfund[$i]->{'bookfundid'};
        $select_bookfunds{$bookfund[$i]->{'bookfundid'}} = $bookfund[$i]->{'bookfundname'}
@@ -139,23 +143,32 @@ my $CGIbookfund=CGI::scrolling_list( -name     => 'bookfund',
                        -labels   => \%select_bookfunds,
                        -size     => 1,
                        -multiple => 0 );
+my $bookfundname;
+my $bookfundid;
+if ($close){
+       $bookfundid=$data->{'bookfundid'};
+       $bookfundname= $select_bookfunds{$bookfundid};
+}
 
-my $CGIsort1 = buildCGIsort("Bsort1","sort1",$data->{'sort1'});
+#Build sort lists
+my $CGIsort1 = buildCGIsort("Asort1","sort1",$data->{'sort1'});
 if ($CGIsort1) {
        $template->param(CGIsort1 => $CGIsort1);
 } else {
        $template->param( sort1 => $data->{'sort1'});
 }
 
-my $CGIsort2 = buildCGIsort("Bsort2","sort2",$data->{'sort2'});
+my $CGIsort2 = buildCGIsort("Asort2","sort2",$data->{'sort2'});
 if ($CGIsort2) {
        $template->param(CGIsort2 =>$CGIsort2);
 } else {
        $template->param( sort2 => $data->{'sort2'});
 }
-                       
-                       
+
 # fill template
+$template->param( close=> $close, bookfundid=>$bookfundid, bookfundname=>$bookfundname) if ($close);
+
+
 $template->param( existing => $biblio,
                                                title => $title,
                                                ordnum => $ordnum,
@@ -169,6 +182,9 @@ $template->param( existing => $biblio,
                                                listincgst => $booksellers[0]->{'listincgst'},
                                                listprice => $booksellers[0]->{'listprice'},
                                                gstreg => $booksellers[0]->{'gstreg'},
+                                               invoiceinc => $booksellers[0]->{'invoiceincgst'},
+                                               invoicedisc => $booksellers[0]->{'invoicedisc'},
+                                               nocalc => $booksellers[0]->{'nocalc'},
                                                name => $booksellers[0]->{'name'},
                                                currency => $booksellers[0]->{'listprice'},
                                                gstrate => C4::Context->preference("gist") ,
@@ -178,7 +194,6 @@ $template->param( existing => $biblio,
                                                author => $data->{'author'},
                                                copyrightdate => $data->{'copyrightdate'},
                                                CGIitemtype => $CGIitemtype,
-                                               CGIbranch => $CGIbranch,
                                                CGIbookfund => $CGIbookfund,
                                                isbn => $data->{'isbn'},
                                                seriestitle => $data->{'seriestitle'},