X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=acqui%2Fbasketgroup.pl;h=9baa172566d9994d98cf66108fb59c091b72756a;hb=38b3a375b47bbb4a12eb4ebe749ba0088c9f6e97;hp=12db2cf79ffb9d5fee2bda343a4642b83543c9f7;hpb=e62ffd49b05ad0e214e361150269b2a83794b0c4;p=koha_fer diff --git a/acqui/basketgroup.pl b/acqui/basketgroup.pl index 12db2cf79f..9baa172566 100755 --- a/acqui/basketgroup.pl +++ b/acqui/basketgroup.pl @@ -51,7 +51,7 @@ use C4::Output; use CGI; use C4::Bookseller qw/GetBookSellerFromId/; -use C4::Acquisition qw/GetOrders GetBasketsByBasketgroup GetBasketsByBookseller ModBasketgroup NewBasketgroup DelBasketgroup GetBasketgroups ModBasket GetBasketgroup/; +use C4::Acquisition qw/CloseBasketgroup ReOpenBasketgroup GetOrders GetBasketsByBasketgroup GetBasketsByBookseller ModBasketgroup NewBasketgroup DelBasketgroup GetBasketgroups ModBasket GetBasketgroup GetBasket/; use C4::Bookseller qw/GetBookSellerFromId/; my $input=new CGI; @@ -169,17 +169,87 @@ sub displaybasketgroups { if( ! @$baskets[$i]->{'closedate'} ) { splice(@$baskets, $i, 1); --$i; + }else{ + @$baskets[$i]->{total} = BasketTotal(@$baskets[$i]->{basketno}, $bookseller); } } $template->param(baskets => $baskets); $template->param( booksellername => $bookseller ->{'name'}); } +sub printbasketgrouppdf{ + my ($basketgroupid) = @_; + + my $pdfformat = C4::Context->preference("pdfformat"); + eval "use $pdfformat" ; + warn @_; + eval "use C4::Branch"; + + my $basketgroup = GetBasketgroup($basketgroupid); + my $bookseller = GetBookSellerFromId($basketgroup->{'booksellerid'}); + my $baskets = GetBasketsByBasketgroup($basketgroupid); + + my %orders; + for my $basket (@$baskets) { + my @ba_orders; + my @ords = &GetOrders($basket->{basketno}); + for my $ord (@ords) { + # ba_order is filled with : + # 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); + } + } + } + %orders->{$basket->{basketno}}=\@ba_orders; + } + print $input->header( -type => 'application/pdf', -attachment => 'basketgroup.pdf' ); + my $branch = GetBranchInfo(GetBranch($input, GetBranches())); + $branch = @$branch[0]; + my $pdf = printpdf($basketgroup, $bookseller, $baskets, $branch, \%orders, $bookseller->{gstrate} || C4::Context->preference("gist")) || die "pdf generation failed"; + print $pdf; + exit; +} my $op = $input->param('op'); my $booksellerid = $input->param('booksellerid'); +$template->param(booksellerid => $booksellerid); -if (! $op ) { +if ( $op eq "add" ) { if(! $booksellerid){ $template->param( ungroupedlist => 1); my @booksellers = GetBookSeller(''); @@ -197,8 +267,18 @@ if (! $op ) { } } } else { + my $basketgroupid = $input->param('basketgroupid'); + if($basketgroupid){ + my $selecteds = GetBasketsByBasketgroup($basketgroupid); + foreach (@{$selecteds}){ + $_->{total} = BasketTotal($_->{basketno}, $_); + } + $template->param(basketgroupid => $basketgroupid, + selectedbaskets => $selecteds); + } $template->param( booksellerid => $booksellerid ); } + $template->param(grouping => 1); my $basketgroups = &GetBasketgroups($booksellerid); my $bookseller = &GetBookSellerFromId($booksellerid); my $baskets = &GetBasketsByBookseller($booksellerid); @@ -248,100 +328,71 @@ if (! $op ) { $baskets = &GetBasketsByBookseller($booksellerid); displaybasketgroups($basketgroups, $bookseller, $baskets); -} elsif ( $op eq 'printbgroup') { - my $pdfformat = C4::Context->preference("pdfformat"); - eval "use $pdfformat" ; - eval "use C4::Branch"; - my $basketgroupid = $input->param('bgroupid'); - my $basketgroup = GetBasketgroup($basketgroupid); - my $bookseller = GetBookSellerFromId($basketgroup->{'booksellerid'}); - my $baskets = GetBasketsByBasketgroup($basketgroupid); - my %orders; - for my $basket (@$baskets) { - my @ba_orders; - my @ords = &GetOrders($basket->{basketno}); - for my $ord (@ords) { - # ba_order is filled with : - # 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); - } - } - } - %orders->{$basket->{basketno}}=\@ba_orders; - } - print $input->header( -type => 'application/pdf', -attachment => 'basketgroup.pdf' ); - my $branch = GetBranchInfo(GetBranch($input, GetBranches())); - $branch = @$branch[0]; - my $pdf = printpdf($basketgroup, $bookseller, $baskets, $branch, \%orders, $bookseller->{gstrate} || C4::Context->preference("gist")) || die "pdf generation failed"; - print $pdf; - exit; +} elsif ( $op eq 'closeandprint') { + my $basketgroupid = $input->param('basketgroupid'); + + CloseBasketgroup($basketgroupid); + + printbasketgrouppdf($basketgroupid); +}elsif ($op eq 'print'){ + my $basketgroupid = $input->param('basketgroupid'); + + printbasketgrouppdf($basketgroupid); +}elsif( $op eq "delete"){ + my $basketgroupid = $input->param('basketgroupid'); + warn $basketgroupid; + DelBasketgroup($basketgroupid); + warn "---------------"; + print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid); + +}elsif ( $op eq 'reopen'){ + my $basketgroupid = $input->param('basketgroupid'); + my $booksellerid = $input->param('booksellerid'); + + ReOpenBasketgroup($basketgroupid); + + print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid . '#closed'); + } elsif ( $op eq 'attachbasket') { - # TODO: create basketgroup and attach basket to it? + + # Getting parameters my $basketgroup = {}; - $basketgroup->{'name'} = $input->param('basketgroupname'); - $basketgroup->{'booksellerid'} = $input->param('booksellerid'); - my $basketgroupid; - my $basketno = $input->param('basketno'); - warn "basketgroupname", $basketgroup->{'name'}; - if ($basketgroup->{'name'}) { + + my @baskets = $input->param('basket'); + my $basketgroupid = $input->param('basketgroupid'); + my $basketgroupname = $input->param('basketgroupname'); + my $booksellerid = $input->param('booksellerid'); + 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, + closed => $close, + }; + ModBasketgroup($basketgroup); + if($close){ + + } + }else{ + $basketgroup = { + name => $basketgroupname, + booksellerid => $booksellerid, + basketlist => \@baskets, + closed => $close, + }; $basketgroupid = NewBasketgroup($basketgroup); - } else { - $basketgroupid = $input->param('basketgroupid'); } - if ($input->param('closebasketgroup')){ - #we override $basketgroup on purpose here - my $basketgroup= {}; - $basketgroup->{'closed'} = 1; - $basketgroup->{'id'} = $basketgroupid; - ModBasketgroup($basketgroup) - } - my $basket = {}; - $basket->{'basketno'} = $basketno; - $basket->{'basketgroupid'} = $basketgroupid; - ModBasket($basket); - $basketgroup = GetBasketgroup($basketgroupid); - my $baskets = GetBasketsByBasketgroup($basketgroupid); + + print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid); + +}else{ + my $basketgroups = &GetBasketgroups($booksellerid); my $bookseller = &GetBookSellerFromId($booksellerid); - my @basketgroups; - push(@basketgroups, $basketgroup); - $template->param(displayclosedbgs => 1, - booksellerid => $booksellerid); - displaybasketgroups(\@basketgroups, $bookseller, $baskets); + my $baskets = &GetBasketsByBookseller($booksellerid); + + displaybasketgroups($basketgroups, $bookseller, $baskets); } #prolly won't use all these, maybe just use print, the rest can be done inside validate output_html_with_http_headers $input, $cookie, $template->output;