X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=acqui%2Fbasketgroup.pl;h=d29df7485db077cff0bb8bcdd3a8d6d52e321231;hb=refs%2Fheads%2Fkoha_ffzg;hp=e1a16fdae0465c52df1affc07d0b32a576d735a2;hpb=bd3b1c1a33e4bb14bbcd10a0fcf871b39362430d;p=koha.git diff --git a/acqui/basketgroup.pl b/acqui/basketgroup.pl index e1a16fdae0..d29df7485d 100755 --- a/acqui/basketgroup.pl +++ b/acqui/basketgroup.pl @@ -43,15 +43,15 @@ The bookseller who we want to display the baskets (and basketgroups) of. =cut -use strict; -use warnings; +use Modern::Perl; use Carp; use C4::Auth; use C4::Output; use CGI qw ( -utf8 ); +use File::Spec; -use C4::Acquisition qw/CloseBasketgroup ReOpenBasketgroup GetOrders GetBasketsByBasketgroup GetBasketsByBookseller ModBasketgroup NewBasketgroup DelBasketgroup GetBasketgroups ModBasket GetBasketgroup GetBasket GetBasketGroupAsCSV/; +use C4::Acquisition qw/CloseBasketgroup ReOpenBasketgroup GetOrders GetBasketsByBasketgroup GetBasketsByBookseller ModBasketgroup NewBasketgroup DelBasketgroup GetBasketgroups ModBasket GetBasketgroup GetBasket GetBasketGroupAsCSV get_rounded_price/; use Koha::EDI qw/create_edi_order get_edifact_ean/; use Koha::Biblioitems; @@ -78,12 +78,11 @@ sub BasketTotal { for my $order (@orders){ # FIXME The following is wrong if ( $bookseller->listincgst ) { - $total = $total + ( $order->{ecost_tax_included} * $order->{quantity} ); + $total = $total + ( get_rounded_price($order->{ecost_tax_included}) * $order->{quantity} ); } else { - $total = $total + ( $order->{ecost_tax_excluded} * $order->{quantity} ); + $total = $total + ( get_rounded_price($order->{ecost_tax_excluded}) * $order->{quantity} ); } } - $total .= " " . ($bookseller->invoiceprice // 0); return $total; } @@ -125,29 +124,27 @@ sub displaybasketgroups { sub printbasketgrouppdf{ my ($basketgroupid) = @_; - + my $pdfformat = C4::Context->preference("OrderPdfFormat"); - if ($pdfformat eq 'pdfformat::layout3pages' || $pdfformat eq 'pdfformat::layout2pages' || $pdfformat eq 'pdfformat::layout3pagesfr' - || $pdfformat eq 'pdfformat::layout2pagesde'){ - eval { - eval "require $pdfformat"; - import $pdfformat; - }; - if ($@){ - } + my @valid_pdfformats = qw(pdfformat::layout3pages pdfformat::layout2pages pdfformat::layout3pagesfr pdfformat::layout2pagesde pdfformat::ffzg); + if (grep {$_ eq $pdfformat} @valid_pdfformats) { + $pdfformat = "Koha::$pdfformat"; + my $pdfformat_filepath = File::Spec->catfile(split /::/, $pdfformat) . '.pm'; + require $pdfformat_filepath; + import $pdfformat qw(printpdf); } 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; + 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 = Koha::Acquisition::Booksellers->find( $basketgroup->{booksellerid} ); my $baskets = GetBasketsByBasketgroup($basketgroupid); - + my %orders; for my $basket (@$baskets) { my @ba_orders; @@ -172,8 +169,8 @@ sub printbasketgrouppdf{ $ord->{tax_value} = $ord->{tax_value_on_ordering}; $ord->{tax_rate} = $ord->{tax_rate_on_ordering}; - $ord->{total_tax_included} = $ord->{ecost_tax_included} * $ord->{quantity}; - $ord->{total_tax_excluded} = $ord->{ecost_tax_excluded} * $ord->{quantity}; + $ord->{total_tax_included} = get_rounded_price($ord->{ecost_tax_included}) * $ord->{quantity}; + $ord->{total_tax_excluded} = get_rounded_price($ord->{ecost_tax_excluded}) * $ord->{quantity}; my $biblioitem = Koha::Biblioitems->search({ biblionumber => $ord->{biblionumber} })->next; @@ -184,7 +181,7 @@ sub printbasketgrouppdf{ # Editor Number my $en; my $edition; - my $ord->{marcxml} = C4::Biblio::GetXmlBiblio( $ord->{biblionumber} ); + $ord->{marcxml} = C4::Biblio::GetXmlBiblio( $ord->{biblionumber} ); my $marcrecord=eval{MARC::Record::new_from_xml( $ord->{marcxml},'UTF-8' )}; if ($marcrecord){ if ( C4::Context->preference("marcflavour") eq 'UNIMARC' ) { @@ -196,7 +193,11 @@ sub printbasketgrouppdf{ } } - $ord->{itemtype} = ( $ord->{itemtype} and $biblioitem->itemtype ) ? Koha::ItemTypes->find( $biblioitem->itemtype )->description : undef; + my $itemtype = ( $ord->{itemtype} and $biblioitem->itemtype ) + ? Koha::ItemTypes->find( $biblioitem->itemtype ) + : undef; + $ord->{itemtype} = $itemtype ? $itemtype->description : undef; + $ord->{en} = $en ? $en : undef; $ord->{edition} = $edition ? $edition : undef; @@ -218,8 +219,15 @@ sub generate_edifact_orders { my $baskets = GetBasketsByBasketgroup($basketgroupid); my $ean = get_edifact_ean(); - for my $basket ( @{$baskets} ) { - create_edi_order( { ean => $ean, basketno => $basket->{basketno}, } ); + if($ean) { + for my $basket ( @{$baskets} ) { + create_edi_order( { ean => $ean, basketno => $basket->{basketno}, } ); + } + } else { + my $booksellerid = $input->param('booksellerid') || 0; + print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . + $booksellerid . + '&message=No%20EDIFACT%20Setup'); } return; } @@ -238,6 +246,12 @@ my $op = $input->param('op') || 'display'; # - display : display the list of all basketgroups for a vendor my $booksellerid = $input->param('booksellerid'); $template->param(booksellerid => $booksellerid); +my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); + +my $schema = Koha::Database->new()->schema(); +my $rs = $schema->resultset('VendorEdiAccount')->search( + { vendor_id => $booksellerid, } ); +$template->param( ediaccount => ($rs->count > 0)); if ( $op eq "add" ) { # @@ -389,8 +403,17 @@ if ( $op eq "add" ) { } elsif ( $op eq 'ediprint') { my $basketgroupid = $input->param('basketgroupid'); - generate_edifact_orders( $basketgroupid ); - exit; + if ($template->param( 'ediaccount' )) { + generate_edifact_orders( $basketgroupid ); + exit; + } else { + $template->param('NoEDIMessage' => 1); + my $basketgroups = &GetBasketgroups($booksellerid); + my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); + my $baskets = &GetBasketsByBookseller($booksellerid); + + displaybasketgroups($basketgroups, $bookseller, $baskets); + } }else{ # no param : display the list of all basketgroups for a given vendor my $basketgroups = &GetBasketgroups($booksellerid);