From 263961312c1ff7605ed1e28df40191ab01a75af9 Mon Sep 17 00:00:00 2001 From: Nahuel ANGELINETTI Date: Mon, 21 Sep 2009 13:35:35 +0200 Subject: [PATCH] (bug #3622) rewrite a lot of basketgrouping This patch remade a lot of basketgrouping --- C4/Acquisition.pm | 64 ++- acqui/basketgroup.pl | 233 ++++++---- installer/data/mysql/updatedatabase.pl | 4 +- koha-tmpl/intranet-tmpl/prog/en/js/acq.js | 8 + .../prog/en/modules/acqui/basketgroup.tmpl | 408 ++++++++++-------- 5 files changed, 444 insertions(+), 273 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index e446e2ae2b..797f0b647b 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -37,7 +37,7 @@ BEGIN { require Exporter; @ISA = qw(Exporter); @EXPORT = qw( - &GetBasket &NewBasket &CloseBasket &DelBasket &ModBasket + &GetBasket &NewBasket &CloseBasket &CloseBasketgroup &ReOpenBasketgroup &DelBasket &ModBasket &ModBasketHeader &GetBasketsByBookseller &GetBasketsByBasketgroup &ModBasketgroup &NewBasketgroup &DelBasketgroup &GetBasketgroup &GetBasketgroups @@ -218,6 +218,57 @@ sub CloseBasket { #------------------------------------------------------------# +=head3 CloseBasketgroup + +=over 4 + +&CloseBasketgroup($basketgroupno); + +close a basketgroup + +=back + +=cut + +sub CloseBasketgroup { + my ($basketgroupno) = @_; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare(" + UPDATE aqbasketgroups + SET closed=1 + WHERE id=? + "); + $sth->execute($basketgroupno); +} + +#------------------------------------------------------------# + +=head3 ReOpenBaskergroup($basketgroupno) + +=over 4 + +&ReOpenBaskergroup($basketgroupno); + +reopen a basketgroup + +=back + +=cut + +sub ReOpenBasketgroup { + my ($basketgroupno) = @_; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare(" + UPDATE aqbasketgroups + SET closed=0 + WHERE id=? + "); + $sth->execute($basketgroupno); +} + +#------------------------------------------------------------# + + =head3 DelBasket =over 4 @@ -509,12 +560,15 @@ sub ModBasketgroup { push(@params, $basketgroupinfo->{'id'}); my $sth = $dbh->prepare($query); $sth->execute(@params); + + $sth = $dbh->prepare('UPDATE aqbasket SET basketgroupid = NULL WHERE basketgroupid = ?'); + $sth->execute($basketgroupinfo->{'id'}); + if($basketgroupinfo->{'basketlist'} && @{$basketgroupinfo->{'basketlist'}}){ + $sth = $dbh->prepare("UPDATE aqbasket SET basketgroupid=? WHERE basketno=?"); foreach my $basketno (@{$basketgroupinfo->{'basketlist'}}) { - my $query2 = "UPDATE aqbasket SET basketgroupid=? WHERE basketno=?"; - my $sth2 = $dbh->prepare($query2); - $sth2->execute($basketgroupinfo->{'id'}, $basketno); - $sth2->finish; + $sth->execute($basketgroupinfo->{'id'}, $basketno); + $sth->finish; } } $sth->finish; diff --git a/acqui/basketgroup.pl b/acqui/basketgroup.pl index 86dfae9e4c..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 GetBasket/; +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,106 +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') { + # Getting parameters my $basketgroup = {}; - my $basketno = $input->param('basketno'); - my $basket = GetBasket($basketno); - $basketgroup->{'name'} = $input->param('basketgroupname') || $basket->{'basketname'}; - $basketgroup->{'booksellerid'} = $input->param('booksellerid'); - my $basketgroupid; - warn "basketgroupname", $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 ($basketgroup->{'name'}) { + 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 { - # Else, we use the basketgroupid in parameter - $basketgroupid = $input->param('basketgroupid'); } - - $basketgroup= {}; - $basketgroup->{'closed'} = 1; - $basketgroup->{'id'} = $basketgroupid; - ModBasketgroup($basketgroup); - - $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 $baskets = &GetBasketsByBookseller($booksellerid); - if ($input->param('createorder')) { - print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?op=printbgroup&bgroupid=' . $basketgroupid); - } else { - print $input->redirect('/cgi-bin/koha/acqui/booksellers.pl'); - } + 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; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index fedfa7033f..e2f4583a51 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -2781,8 +2781,8 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { CONSTRAINT `aqbasketgroups_ibfk_1` FOREIGN KEY (`booksellerid`) REFERENCES `aqbooksellers` (`id`) ON UPDATE CASCADE ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); $dbh->do("ALTER TABLE aqbasket ADD COLUMN `basketgroupid` int(11)"); - $dbh->do("ALTER TABLE aqbasket ADD FOREIGN KEY (`basketgroupid`) REFERENCES `aqbasketgroups` (`id`) ON UPDATE CASCADE"); - $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('pdfformat','pdfformat/example.pl','Controls what script is used for printing (basketgroups)','','free')"); + $dbh->do("ALTER TABLE aqbasket ADD FOREIGN KEY (`basketgroupid`) REFERENCES `aqbasketgroups` (`id`) ON UPDATE CASCADE ON DELETE SET NULL"); + $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('pdfformat','pdfformat::example','Controls what script is used for printing (basketgroups)','','free')"); print "Upgrade to $DBversion done (adding basketgroups)\n"; SetVersion ($DBversion); } diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/acq.js b/koha-tmpl/intranet-tmpl/prog/en/js/acq.js index 12cf936020..61d841ee4e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/js/acq.js +++ b/koha-tmpl/intranet-tmpl/prog/en/js/acq.js @@ -473,6 +473,14 @@ function closebasketgroup(bgid) { div.appendChild(unclosegroup); } +function closeandprint(bg){ + if(document.location = '/cgi-bin/koha/acqui/basketgroup.pl?op=closeandprint&basketgroupid=' + bg ){ + setTimeout("window.location.reload();",3000); + }else{ + alert('Error downloading the file'); + } +} + //function that lets the user unclose a basketgroup as long as he hasn't submitted the changes to the page. function unclosegroup(bgid){ var div = document.getElementById('basketgroup-'+bgid+'-closed').parentNode; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tmpl index 6e376d6c22..69f16eec4f 100755 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tmpl @@ -2,21 +2,15 @@ Koha › Basket grouping for Vendor <!-- TMPL_VAR name="booksellername" --> - - - - +/fonts/fonts-min.css" /> + + + + + - - + + + + @@ -98,164 +123,203 @@ fieldset.various li {
-
-
- -
- + " name="newbasketgroup" id="newbasketgroup">New Basket Group +
+

Basket grouping for Vendor ">

+
+ +
+
+
- // YUI Toolbar Functions +
" method="post" name="basketgroups" id="basketgroups"> +
+
+

Ungrouped Baskets

+ +
+
+
- function yuiToolbar() { - new YAHOO.widget.Button("newrecord"); - var booksellermenu = [ - { text: _("Bookseller"), url: "/cgi-bin/koha/acqui/supplier.pl?booksellerid=" }, - { text: _("Edit bookseller"), url: "/cgi-bin/koha/acqui/booksellers.pl?booksellerid="}, - ] - var ordersbutton = [ - { text: _("Manage orders"), url: "/cgi-bin/koha/acqui/booksellers.pl?supplier=" }, - { text: _("Edit uncertain prices"), url: "/cgi-bin/koha/acqui/uncertainprice.pl?booksellerid=&owner=1" }, - ] +
+ +
+
+
+

+ +
+

Grouping

+
    + +
  • " > + "> + + + + No name, basketnumber: + + ,
    + Total: + " /> +
  • + - new YAHOO.widget.Button({ - type: "menu", - label: _("Bookseller"), - name: "booksellerbutton", - menu: booksellermenu, - container: "toolbar" - }); - - new YAHOO.widget.Button({ - type: "menu", - label: _("Orders"), - name: "ordersbutton", - menu: ordersbutton, - container: "toolbar" - }); - } - //]]> - -
- -
-
-

Basket grouping for Vendor ">

-
-
-
-
    -
  • - - - - Ok - -
  • -
  • - - - - Ok - -
  • -
  • - - -
  • -
-
- " method="post" name="basketgroups" id="basketgroups"> -
-
-

Ungrouped Baskets

- -
+ +
+
Close
+ " /> + + " /> + + + + + +
+
+
+ +
+
+ +
+ +
+ +
+
+
+ +
+ - - - - - -
-
-
-
- + -- 2.39.5