X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=acqui%2Fbasketgroup.pl;h=cdb392d7218ee7ddbe719e21d7798a1a86903555;hb=ef5d4f3c62957100dae0948a44bd27a2159892b4;hp=c9db3b379a9af0436837047cb860096e16496fe1;hpb=fc250be5385f9bac3e0c92034102e43e7073ce15;p=koha_fer diff --git a/acqui/basketgroup.pl b/acqui/basketgroup.pl index c9db3b379a..cdb392d721 100755 --- a/acqui/basketgroup.pl +++ b/acqui/basketgroup.pl @@ -70,69 +70,6 @@ our ($template, $loggedinuser, $cookie) debug => 1, }); -sub parseinputbaskets { - my $booksellerid = shift; - my $baskets = &GetBasketsByBookseller($booksellerid); - for(my $i=0; $i < scalar @$baskets; ++$i) { - if( @$baskets[$i] && ! @$baskets[$i]->{'closedate'} ) { - splice(@$baskets, $i, 1); - --$i; - } - } - foreach my $basket (@$baskets){ -#perl DBI uses value "undef" for the mysql "NULL" value, so i need to check everywhere where $basket->{'basketgroupid'} is used for undef ☹ - $basket->{'basketgroupid'} = $input->param($basket->{'basketno'}.'-group') || undef; - } - return $baskets; -} - - - -sub parseinputbasketgroups { - my $booksellerid = shift; - my $baskets = shift; - my $basketgroups = &GetBasketgroups($booksellerid); - my $newbasketgroups; - foreach my $basket (@$baskets){ - my $basketgroup; - my $i = 0; - my $exists; - if(! $basket->{'basketgroupid'} || $basket->{'basketgroupid'} == 0){ - $exists = "true"; - } else { - foreach my $basketgroup (@$basketgroups){ - if($basket->{'basketgroupid'} == $basketgroup->{'id'}){ - $exists = "true"; - push(@{$basketgroup->{'basketlist'}}, $basket->{'basketno'}); - last; - } - } - } - if (! $exists){ -#if the basketgroup doesn't exist yet - $basketgroup = $newbasketgroups->{$basket->{'basketgroupid'}} || undef; - $basketgroup->{'booksellerid'} = $booksellerid; - } else { - while($i < scalar @$basketgroups && @$basketgroups[$i]->{'id'} != $basket->{'basketgroupid'}){ - ++$i; - } - $basketgroup = @$basketgroups[$i]; - } - $basketgroup->{'id'}=$basket->{'basketgroupid'}; - $basketgroup->{'name'}=$input->param('basketgroup-'.$basketgroup->{'id'}.'-name') || ""; - $basketgroup->{'closed'}= $input->param('basketgroup-'.$basketgroup->{'id'}.'-closed'); - push(@{$basketgroup->{'basketlist'}}, $basket->{'basketno'}); - if (! $exists){ - $newbasketgroups->{$basket->{'basketgroupid'}} = $basketgroup; - } else { - if($basketgroup->{'id'}){ - @$basketgroups[$i] = $basketgroup; - } - } - } - return($basketgroups, $newbasketgroups); -} - sub BasketTotal { my $basketno = shift; my $bookseller = shift; @@ -145,7 +82,7 @@ sub BasketTotal { $total = $total * ( $gst / 100 +1); } } - $total .= $bookseller->{invoiceprice}; + $total .= " " . ($bookseller->{invoiceprice} // 0); return $total; } @@ -189,7 +126,8 @@ sub printbasketgrouppdf{ my ($basketgroupid) = @_; my $pdfformat = C4::Context->preference("OrderPdfFormat"); - if ($pdfformat eq 'pdfformat::layout3pages' || $pdfformat eq 'pdfformat::layout2pages' || $pdfformat eq 'pdfformat::layout3pagesfr'){ + if ($pdfformat eq 'pdfformat::layout3pages' || $pdfformat eq 'pdfformat::layout2pages' || $pdfformat eq 'pdfformat::layout3pagesfr' + || $pdfformat eq 'pdfformat::layout2pagesde'){ eval { eval "require $pdfformat"; import $pdfformat; @@ -262,12 +200,15 @@ sub printbasketgrouppdf{ # Editor Number my $en; + my $edition; 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" ); + $edition = $marcrecord->subfield( '205', 'a' ); } elsif ( C4::Context->preference("marcflavour") eq 'MARC21' ) { $en = $marcrecord->subfield( '037', "a" ); + $edition = $marcrecord->subfield( '250', 'a' ); } } @@ -275,8 +216,9 @@ sub printbasketgrouppdf{ isbn => ($ord->{isbn} ? $ord->{isbn} : undef), itemtype => ( $ord->{itemtype} and $bib->{itemtype} ? $itemtypes->{$bib->{itemtype}}->{description} : undef ), en => ( $en ? $en : undef ), + edition => ( $edition ? $edition : undef ), }; - for my $key ( qw/ gstrate author title itemtype publishercode discount quantity rrpgsti rrpgste gstgsti gstgste ecostgsti ecostgste gstvalue totalgste totalgsti / ) { + for my $key ( qw/ gstrate author title itemtype publishercode copyrightdate publicationyear discount quantity rrpgsti rrpgste gstgsti gstgste ecostgsti ecostgste gstvalue totalgste totalgsti order_vendornote / ) { $ba_order->{$key} = $ord->{$key}; } @@ -297,7 +239,6 @@ my $op = $input->param('op') || 'display'; # possible values of $op : # - add : adds a new basketgroup, or edit an open basketgroup, or display a closed basketgroup # - mod_basket : modify an individual basket of the basketgroup -# - validate : FIXME dead code # - closeandprint : close and print an closed basketgroup in pdf. called by clicking on "Close and print" button in closed basketgroups list # - print : print a closed basketgroup. called by clicking on "Print" button in closed basketgroups list # - export : export in CSV a closed basketgroup. called by clicking on "Export" button in closed basketgroups list @@ -314,68 +255,48 @@ if ( $op eq "add" ) { # else, edit (if it is open) or display (if it is close) the basketgroup basketgroupid # the template will know if basketgroup must be displayed or edited, depending on the value of closed key # - if(! $booksellerid){ -# Unknown bookseller -# FIXME : ungroupedlist does not seem to be used in this file nor in template - $template->param( ungroupedlist => 1); - my @booksellers = GetBookSeller(''); - for (my $i=0; $i < scalar @booksellers; $i++) { - my $baskets = &GetBasketsByBookseller($booksellers[$i]->{id}); - for (my $j=0; $j < scalar @$baskets; $j++) { - if(! @$baskets[$i]->{closedate} || @$baskets[$i]->{basketgroupid}) { - splice(@$baskets, $j, 1); - $j--; - } - } - if (scalar @$baskets == 0){ - splice(@booksellers, $i, 1); - $i--; - } + my $bookseller = &GetBookSellerFromId($booksellerid); + 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); + foreach my $basket(@{$selecteds}){ + $basket->{total} = BasketTotal($basket->{basketno}, $bookseller); } + $template->param(basketgroupid => $basketgroupid, + selectedbaskets => $selecteds); + + # Get general informations about the basket group to prefill the form + my $basketgroup = GetBasketgroup($basketgroupid); + $template->param( + name => $basketgroup->{name}, + deliverycomment => $basketgroup->{deliverycomment}, + freedeliveryplace => $basketgroup->{freedeliveryplace}, + ); + $billingplace = $basketgroup->{billingplace}; + $deliveryplace = $basketgroup->{deliveryplace}; + $freedeliveryplace = $basketgroup->{freedeliveryplace}; + $template->param( closedbg => ($basketgroup ->{'closed'}) ? 1 : 0); } else { -# Known bookseller - 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); - foreach (@{$selecteds}){ - $_->{total} = BasketTotal($_->{basketno}, $_); - } - $template->param(basketgroupid => $basketgroupid, - selectedbaskets => $selecteds); - - # Get general informations about the basket group to prefill the form - my $basketgroup = GetBasketgroup($basketgroupid); - $template->param( - name => $basketgroup->{name}, - deliverycomment => $basketgroup->{deliverycomment}, - freedeliveryplace => $basketgroup->{freedeliveryplace}, - ); - $billingplace = $basketgroup->{billingplace}; - $deliveryplace = $basketgroup->{deliveryplace}; - $freedeliveryplace = $basketgroup->{freedeliveryplace}; - $template->param( closedbg => ($basketgroup ->{'closed'}) ? 1 : 0); - } else { - $template->param( closedbg => 0); - } - # 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 = C4::Branch::GetBranchesLoop( $billingplace ); - $template->param( billingplaceloop => $branches ); - $branches = C4::Branch::GetBranchesLoop( $deliveryplace ); - $template->param( deliveryplaceloop => $branches ); - $template->param( booksellerid => $booksellerid ); + $template->param( closedbg => 0); } + # 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 = C4::Branch::GetBranchesLoop( $billingplace ); + $template->param( billingplaceloop => $branches ); + $branches = C4::Branch::GetBranchesLoop( $deliveryplace ); + $template->param( deliveryplaceloop => $branches ); + $template->param( booksellerid => $booksellerid ); + # the template will display a unique basketgroup $template->param(grouping => 1); my $basketgroups = &GetBasketgroups($booksellerid); - my $bookseller = &GetBookSellerFromId($booksellerid); my $baskets = &GetBasketsByBookseller($booksellerid); displaybasketgroups($basketgroups, $bookseller, $baskets); } elsif ($op eq 'mod_basket') { @@ -387,47 +308,6 @@ if ( $op eq "add" ) { ModBasket( { basketno => $basketno, basketgroupid => $basketgroupid } ); print $input->redirect("basket.pl?basketno=" . $basketno); -} elsif ($op eq 'validate') { -# -# FIXME dead code -# - if(! $booksellerid){ - $template->param( booksellererror => 1); - } else { - $template->param( booksellerid => $booksellerid ); - } - my $baskets = parseinputbaskets($booksellerid); - my ($basketgroups, $newbasketgroups) = parseinputbasketgroups($booksellerid, $baskets); - foreach my $nbgid (keys %$newbasketgroups){ -#javascript just picks an ID that's higher than anything else, the ID might not be correct..change it and change all the basket's basketgroupid as well - my $bgid = NewBasketgroup($newbasketgroups->{$nbgid}); - ${$newbasketgroups->{$nbgid}}->{'id'} = $bgid; - ${$newbasketgroups->{$nbgid}}->{'oldid'} = $nbgid; - } - foreach my $basket (@$baskets){ -#if the basket was added to a new basketgroup, first change the groupid to the groupid of the basket in mysql, because it contains the id from javascript otherwise. - if ( $basket->{'basketgroupid'} && $newbasketgroups->{$basket->{'basketgroupid'}} ){ - $basket->{'basketgroupid'} = ${$newbasketgroups->{$basket->{'basketgroupid'}}}->{'id'}; - } - ModBasket($basket); - } - foreach my $basketgroup (@$basketgroups){ - if(! $basketgroup->{'id'}){ - foreach my $basket (@{$basketgroup->{'baskets'}}){ - if($input->param('basket'.$basket->{'basketno'}.'changed')){ - ModBasket($basket); - } - } - } elsif ($input->param('basketgroup-'.$basketgroup->{'id'}.'-changed')){ - ModBasketgroup($basketgroup); - } - } - $basketgroups = &GetBasketgroups($booksellerid); - my $bookseller = &GetBookSellerFromId($booksellerid); - $baskets = &GetBasketsByBookseller($booksellerid); - # keep ungroupedbaskets - - displaybasketgroups($basketgroups, $bookseller, $baskets); } elsif ( $op eq 'closeandprint') { # # close an open basketgroup and generates a pdf