X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=acqui%2Fbasketgroup.pl;h=6b7e5bf192a7b5cfa6761dc750bfc9fe5904bf60;hb=1b4b78a136c769075f6ce796cbd763de7feb95c6;hp=08356f85b05e02ee67dd6ba5f26d30360910678c;hpb=8ae5719d1681ffb5bf3dc803de5b80a39b6f3a68;p=koha_fer
diff --git a/acqui/basketgroup.pl b/acqui/basketgroup.pl
index 08356f85b0..6b7e5bf192 100755
--- a/acqui/basketgroup.pl
+++ b/acqui/basketgroup.pl
@@ -45,6 +45,7 @@ The bookseller who we want to display the baskets (and basketgroups) of.
use strict;
use warnings;
+use Carp;
use C4::Input;
use C4::Auth;
@@ -52,14 +53,14 @@ use C4::Output;
use CGI;
use C4::Bookseller qw/GetBookSellerFromId/;
-use C4::Acquisition qw/CloseBasketgroup ReOpenBasketgroup GetOrders GetBasketsByBasketgroup GetBasketsByBookseller ModBasketgroup NewBasketgroup DelBasketgroup GetBasketgroups ModBasket GetBasketgroup GetBasket/;
+use C4::Acquisition qw/CloseBasketgroup ReOpenBasketgroup GetOrders GetBasketsByBasketgroup GetBasketsByBookseller ModBasketgroup NewBasketgroup DelBasketgroup GetBasketgroups ModBasket GetBasketgroup GetBasket GetBasketGroupAsCSV/;
use C4::Bookseller qw/GetBookSellerFromId/;
use C4::Branch qw/GetBranches/;
use C4::Members qw/GetMember/;
-my $input=new CGI;
+our $input=new CGI;
-my ($template, $loggedinuser, $cookie)
+our ($template, $loggedinuser, $cookie)
= get_template_and_user({template_name => "acqui/basketgroup.tmpl",
query => $input,
type => "intranet",
@@ -184,9 +185,21 @@ sub printbasketgrouppdf{
my ($basketgroupid) = @_;
my $pdfformat = C4::Context->preference("OrderPdfFormat");
- eval "use $pdfformat";
- # FIXME consider what would happen if $pdfformat does not
- # contain the name of a valid Perl module.
+ if ($pdfformat eq 'pdfformat::layout3pages' || $pdfformat eq 'pdfformat::layout2pages'){
+ eval {
+ eval "require $pdfformat";
+ import $pdfformat;
+ };
+ if ($@){
+ }
+ }
+ else {
+ print $input->header;
+ print $input->start_html; # FIXME Should do a nicer page
+ print "
Invalid PDF Format set
";
+ print "Please go to the systempreferences and set a valid pdfformat";
+ exit;
+ }
my $basketgroup = GetBasketgroup($basketgroupid);
my $bookseller = GetBookSellerFromId($basketgroup->{'booksellerid'});
@@ -202,8 +215,20 @@ sub printbasketgrouppdf{
#isbn, itemtype, author, title, publishercode, quantity, listprice ecost discount gstrate
my @ba_order;
if ( $ord->{biblionumber} && $ord->{quantity}> 0 ) {
- eval "use C4::Biblio";
- eval "use C4::Koha";
+ eval {
+ require C4::Biblio;
+ import C4::Biblio;
+ };
+ if ($@){
+ croak $@;
+ }
+ eval {
+ require C4::Koha;
+ import C4::Koha;
+ };
+ if ($@){
+ croak $@;
+ }
my $bib = GetBiblioData($ord->{biblionumber});
my $itemtypes = GetItemTypes();
if($ord->{isbn}){
@@ -211,8 +236,8 @@ sub printbasketgrouppdf{
} else {
push(@ba_order, undef);
}
- if ($ord->{itemtype}){
- push(@ba_order, $itemtypes->{$bib->{itemtype}}->{description}) if $bib->{itemtype};
+ if ($ord->{itemtype} and $bib->{itemtype}){
+ push(@ba_order, $itemtypes->{$bib->{itemtype}}->{description});
} else {
push(@ba_order, undef);
}
@@ -226,10 +251,13 @@ sub printbasketgrouppdf{
push(@ba_orders, \@ba_order);
# Editor Number
my $en;
- if (C4::Context->preference("marcflavour") eq 'UNIMARC') {
- $en = MARC::Record::new_from_xml($ord->{marcxml},'UTF-8')->subfield('345',"b");
- } elsif (C4::Context->preference("marcflavour") eq 'MARC21') {
- $en = MARC::Record::new_from_xml($ord->{marcxml},'UTF-8')->subfield('037',"a");
+ my $marcrecord=eval{MARC::Record::new_from_xml( $ord->{marcxml},'UTF-8' )};
+ if ($marcrecord){
+ if ( C4::Context->preference("marcflavour") eq 'UNIMARC' ) {
+ $en = $marcrecord->subfield( '345', "b" );
+ } elsif ( C4::Context->preference("marcflavour") eq 'MARC21' ) {
+ $en = $marcrecord->subfield( '037', "a" );
+ }
}
if($en){
push(@ba_order, $en);
@@ -246,9 +274,10 @@ sub printbasketgrouppdf{
);
my $pdf = printpdf($basketgroup, $bookseller, $baskets, \%orders, $bookseller->{gstrate} // C4::Context->preference("gist")) || die "pdf generation failed";
print $pdf;
+
}
-my $op = $input->param('op');
+my $op = $input->param('op') || 'display';
my $booksellerid = $input->param('booksellerid');
$template->param(booksellerid => $booksellerid);
@@ -299,30 +328,11 @@ if ( $op eq "add" ) {
my $borrower = GetMember( ( 'borrowernumber' => $loggedinuser ) );
$billingplace = $billingplace || $borrower->{'branchcode'};
$deliveryplace = $deliveryplace || $borrower->{'branchcode'};
-
- my $branches = GetBranches;
-
- # Build the combobox to select the billing place
- my @billingplaceloop;
- for (sort keys %$branches) {
- push @billingplaceloop, {
- value => $_,
- selected => $_ eq $billingplace,
- branchname => $branches->{$_}->{branchname},
- };
- }
- $template->param( billingplaceloop => \@billingplaceloop );
-
- # Build the combobox to select the delivery place
- my @deliveryplaceloop;
- for (sort keys %$branches) {
- push @deliveryplaceloop, {
- value => $_,
- selected => $_ eq $deliveryplace,
- branchname => $branches->{$_}->{branchname},
- };
- }
- $template->param( deliveryplaceloop => \@deliveryplaceloop );
+
+ my $branches = C4::Branch::GetBranchesLoop( $billingplace );
+ $template->param( billingplaceloop => $branches );
+ $branches = C4::Branch::GetBranchesLoop( $deliveryplace );
+ $template->param( deliveryplaceloop => $branches );
$template->param( booksellerid => $booksellerid );
}
@@ -388,6 +398,14 @@ if ( $op eq "add" ) {
printbasketgrouppdf($basketgroupid);
exit;
+}elsif ( $op eq "export" ) {
+ my $basketgroupid = $input->param('basketgroupid');
+ print $input->header(
+ -type => 'text/csv',
+ -attachment => 'basketgroup' . $basketgroupid . '.csv',
+ );
+ print GetBasketGroupAsCSV( $basketgroupid, $input );
+ exit;
}elsif( $op eq "delete"){
my $basketgroupid = $input->param('basketgroupid');
DelBasketgroup($basketgroupid);