X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=acqui%2Fbasketgroup.pl;h=6fe4db2a1fb460c1d71418c3286e7bb47fb8146b;hb=08382876306cfda839637c5f72a107b304458a8e;hp=2a35f3a26474761abe088e184b0421218f2ffcba;hpb=2c470899b3f0191b9597d713e895b9240fe1d137;p=koha.git diff --git a/acqui/basketgroup.pl b/acqui/basketgroup.pl index 2a35f3a264..6fe4db2a1f 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,15 @@ 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::Budgets qw/ConvertCurrency/; +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", @@ -155,16 +157,19 @@ sub displaybasketgroups { if (scalar @$basketgroups != 0) { foreach my $basketgroup (@$basketgroups){ my $i = 0; + my $basketsqty = 0; while($i < scalar(@$baskets)){ my $basket = @$baskets[$i]; if($basket->{'basketgroupid'} && $basket->{'basketgroupid'} == $basketgroup->{'id'}){ $basket->{total} = BasketTotal($basket->{basketno}, $bookseller); push(@{$basketgroup->{'baskets'}}, $basket); splice(@$baskets, $i, 1); + ++$basketsqty; --$i; } ++$i; } + $basketgroup -> {'basketsqty'} = $basketsqty; } $template->param(basketgroups => $basketgroups); } @@ -184,9 +189,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' || $pdfformat eq 'pdfformat::layout3pagesfr'){ + 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'}); @@ -197,48 +214,75 @@ sub printbasketgrouppdf{ my @ba_orders; my @ords = &GetOrders($basket->{basketno}); for my $ord (@ords) { - # ba_order is filled with : + + next unless ( $ord->{biblionumber} or $ord->{quantity}> 0 ); + eval { + require C4::Biblio; + import C4::Biblio; + }; + if ($@){ + croak $@; + } + eval { + require C4::Koha; + import C4::Koha; + }; + if ($@){ + croak $@; + } + + $ord->{rrp} = ConvertCurrency( $ord->{'currency'}, $ord->{rrp} ); + if ( $bookseller->{'listincgst'} ) { + $ord->{rrpgsti} = sprintf( "%.2f", $ord->{rrp} ); + $ord->{gstgsti} = sprintf( "%.2f", $ord->{gstrate} * 100 ); + $ord->{rrpgste} = sprintf( "%.2f", $ord->{rrp} / ( 1 + ( $ord->{gstgsti} / 100 ) ) ); + $ord->{gstgste} = sprintf( "%.2f", $ord->{gstgsti} / ( 1 + ( $ord->{gstgsti} / 100 ) ) ); + $ord->{ecostgsti} = sprintf( "%.2f", $ord->{ecost} ); + $ord->{ecostgste} = sprintf( "%.2f", $ord->{ecost} / ( 1 + ( $ord->{gstgsti} / 100 ) ) ); + $ord->{gstvalue} = sprintf( "%.2f", ( $ord->{ecostgsti} - $ord->{ecostgste} ) * $ord->{quantity}); + $ord->{totalgste} = sprintf( "%.2f", $ord->{quantity} * $ord->{ecostgste} ); + $ord->{totalgsti} = sprintf( "%.2f", $ord->{quantity} * $ord->{ecostgsti} ); + } else { + $ord->{rrpgsti} = sprintf( "%.2f", $ord->{rrp} * ( 1 + ( $ord->{gstrate} ) ) ); + $ord->{rrpgste} = sprintf( "%.2f", $ord->{rrp} ); + $ord->{gstgsti} = sprintf( "%.2f", $ord->{gstrate} * 100 ); + $ord->{gstgste} = sprintf( "%.2f", $ord->{gstrate} * 100 ); + $ord->{ecostgsti} = sprintf( "%.2f", $ord->{ecost} * ( 1 + ( $ord->{gstrate} ) ) ); + $ord->{ecostgste} = sprintf( "%.2f", $ord->{ecost} ); + $ord->{gstvalue} = sprintf( "%.2f", ( $ord->{ecostgsti} - $ord->{ecostgste} ) * $ord->{quantity}); + $ord->{totalgste} = sprintf( "%.2f", $ord->{quantity} * $ord->{ecostgste} ); + $ord->{totalgsti} = sprintf( "%.2f", $ord->{quantity} * $ord->{ecostgsti} ); + } + my $bib = GetBiblioData($ord->{biblionumber}); + my $itemtypes = GetItemTypes(); + + #FIXME DELETE ME # 0 1 2 3 4 5 6 7 8 9 #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"; - my $bib = GetBiblioData($ord->{biblionumber}); - my $itemtypes = GetItemTypes(); - if($ord->{isbn}){ - push(@ba_order, $ord->{isbn}); - } else { - push(@ba_order, undef); - } - if ($ord->{itemtype}){ - push(@ba_order, $itemtypes->{$bib->{itemtype}}->{description}) if $bib->{itemtype}; - } else { - push(@ba_order, undef); - } -# } else { -# push(@ba_order, undef, undef); - for my $key (qw/author title publishercode quantity listprice ecost/) { - push(@ba_order, $ord->{$key}); #Order lines - } - push(@ba_order, $bookseller->{discount}); - push(@ba_order, $bookseller->{gstrate}*100 // C4::Context->preference("gist") // 0); - 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"); - } - if($en){ - push(@ba_order, $en); - } else { - push(@ba_order, undef); + + # Editor Number + my $en; + 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" ); } } + + my $ba_order = { + isbn => ($ord->{isbn} ? $ord->{isbn} : undef), + itemtype => ( $ord->{itemtype} and $bib->{itemtype} ? $itemtypes->{$bib->{itemtype}}->{description} : undef ), + en => ( $en ? $en : undef ), + }; + for my $key ( qw/ gstrate author title itemtype publishercode discount quantity rrpgsti rrpgste gstgsti gstgste ecostgsti ecostgste gstvalue totalgste totalgsti / ) { + $ba_order->{$key} = $ord->{$key}; + } + + push(@ba_orders, $ba_order); } - $orders{$basket->{basketno}}=\@ba_orders; + $orders{$basket->{basketno}} = \@ba_orders; } print $input->header( -type => 'application/pdf', @@ -246,9 +290,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); @@ -273,6 +318,7 @@ if ( $op eq "add" ) { my $basketgroupid = $input->param('basketgroupid'); my $billingplace; my $deliveryplace; + my $freedeliveryplace; if ( $basketgroupid ) { # Get the selected baskets in the basketgroup to display them my $selecteds = GetBasketsByBasketgroup($basketgroupid); @@ -287,43 +333,22 @@ if ( $op eq "add" ) { $template->param( name => $basketgroup->{name}, deliverycomment => $basketgroup->{deliverycomment}, + freedeliveryplace => $basketgroup->{freedeliveryplace}, ); $billingplace = $basketgroup->{billingplace}; $deliveryplace = $basketgroup->{deliveryplace}; + $freedeliveryplace = $basketgroup->{freedeliveryplace}; } # determine default billing and delivery places depending on librarian homebranch and existing basketgroup data 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) { - my $selected = 1 if $_ eq $billingplace; - my %row = ( - value => $_, - selected => $selected, - branchname => $branches->{$_}->{branchname}, - ); - push @billingplaceloop, \%row; - } - $template->param( billingplaceloop => \@billingplaceloop ); - - # Build the combobox to select the delivery place - my @deliveryplaceloop; - for (sort keys %$branches) { - my $selected = 1 if $_ eq $deliveryplace; - my %row = ( - value => $_, - selected => $selected, - branchname => $branches->{$_}->{branchname}, - ); - push @deliveryplaceloop, \%row; - } - $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 ); } @@ -389,6 +414,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); @@ -405,25 +438,27 @@ if ( $op eq "add" ) { } elsif ( $op eq 'attachbasket') { # Getting parameters - my $basketgroup = {}; - my @baskets = $input->param('basket'); - my $basketgroupid = $input->param('basketgroupid'); - my $basketgroupname = $input->param('basketgroupname'); - my $booksellerid = $input->param('booksellerid'); - my $billingplace = $input->param('billingplace'); - my $deliveryplace = $input->param('deliveryplace'); - my $deliverycomment = $input->param('deliverycomment'); - my $close = $input->param('close') ? 1 : 0; + my $basketgroup = {}; + my @baskets = $input->param('basket'); + my $basketgroupid = $input->param('basketgroupid'); + my $basketgroupname = $input->param('basketgroupname'); + my $booksellerid = $input->param('booksellerid'); + my $billingplace = $input->param('billingplace'); + my $deliveryplace = $input->param('deliveryplace'); + my $freedeliveryplace = $input->param('freedeliveryplace'); + my $deliverycomment = $input->param('deliverycomment'); + my $close = $input->param('close') ? 1 : 0; # If we got a basketgroupname, we create a basketgroup if ($basketgroupid) { $basketgroup = { - name => $basketgroupname, - id => $basketgroupid, - basketlist => \@baskets, - billingplace => $billingplace, - deliveryplace => $deliveryplace, - deliverycomment => $deliverycomment, - closed => $close, + name => $basketgroupname, + id => $basketgroupid, + basketlist => \@baskets, + billingplace => $billingplace, + deliveryplace => $deliveryplace, + freedeliveryplace => $freedeliveryplace, + deliverycomment => $deliverycomment, + closed => $close, }; ModBasketgroup($basketgroup); if($close){ @@ -431,12 +466,14 @@ if ( $op eq "add" ) { } }else{ $basketgroup = { - name => $basketgroupname, - booksellerid => $booksellerid, - basketlist => \@baskets, - deliveryplace => $deliveryplace, - deliverycomment => $deliverycomment, - closed => $close, + name => $basketgroupname, + booksellerid => $booksellerid, + basketlist => \@baskets, + billingplace => $billingplace, + deliveryplace => $deliveryplace, + freedeliveryplace => $freedeliveryplace, + deliverycomment => $deliverycomment, + closed => $close, }; $basketgroupid = NewBasketgroup($basketgroup); }