From 622b7d9c7f322d384ec42866f49de18ffb04c839 Mon Sep 17 00:00:00 2001 From: Mathieu Saby <mathieu.saby@univ-rennes2.fr> Date: Thu, 7 Nov 2013 20:16:40 +0100 Subject: [PATCH ] Bug 9807 : Make possible to view a basketgroup without reopening it Content-Type: text/plain; charset="utf-8" Patch rewritten to eliminate reindenting This patch make possible to view an individual closed basketgroup without reopening it. - It adds a new "View" button on closed basketgroup list - It creates a view for closed basketgroups, with 3 buttons (reopen, print, export) - It adds a "delete" button on standard "edit" view (for open basketgroup) To test : 1/ regression test : - create some empty basketgroups - create some basketgroups by closing baskets - in the list of basketgroups closed and opened, check you can use the buttons that existed before the patch (close and print, delete, export, print, reopen) - click on "Edit" to edit a opened basketgroup : check everything is like before : -- change the billing and delivery places, -- add a note, -- put some new baskets in the bg, -- remove baskets from it -- save it without checking "close" box => it must be save but kept open -- edit it again, and make other some changes (define a free delivery place for example) -- save it with checking "close" => it must be saved but closed 2/ new feature test - click on "view" button on top right column of some closed basketgroup - check all the displayed informations are correct (places, free place, note, list of baskets) - check you can not change anything - click on "print" button => check a pdf is created - click on "export" button => check a csv is created - click on "reopen" button => you must stay on the same basketgroup, but it is now open and you can make some changes - go back to the basketgroup list of the vendor. Check the reopened bg is in "open" tab - click on "edit" - click on new "delete" button => the bg must be deleted, and you are redirected to the bg list of the vendor. Signed-off-by: cedric.vita@dracenie.com <cedric.vita@dracenie.com> --- acqui/basketgroup.pl | 92 ++++++++++++++------ .../prog/en/modules/acqui/basketgroup.tt | 92 +++++++++++++++++--- 2 files changed, 143 insertions(+), 41 deletions(-) diff --git a/acqui/basketgroup.pl b/acqui/basketgroup.pl index 6fe4db2..e431276 100755 --- a/acqui/basketgroup.pl +++ b/acqui/basketgroup.pl @@ -29,7 +29,7 @@ basketgroup.pl =head1 DESCRIPTION This script lets the user group (closed) baskets into basket groups for easier order management. Note that the grouped baskets have to be from the same bookseller and - have to be closed. + have to be closed to be printed or exported. =head1 CGI PARAMETERS @@ -294,11 +294,29 @@ sub printbasketgrouppdf{ } 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 +# - delete : delete an open basketgroup. called by clicking on "Delete" button in open basketgroups list +# - reopen : reopen a closed basketgroup. called by clicking on "Reopen" button in closed basketgroup list +# - attachbasket : save a modified basketgroup, or creates a new basketgroup when a basket is closed. called from basket page +# - display : display the list of all basketgroups for a vendor my $booksellerid = $input->param('booksellerid'); $template->param(booksellerid => $booksellerid); if ( $op eq "add" ) { +# +# if no param('basketgroupid') is not defined, adds a new basketgroup +# 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++) { @@ -315,6 +333,7 @@ if ( $op eq "add" ) { } } } else { +# Known bookseller my $basketgroupid = $input->param('basketgroupid'); my $billingplace; my $deliveryplace; @@ -338,8 +357,10 @@ if ( $op eq "add" ) { $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'}; @@ -349,23 +370,27 @@ if ( $op eq "add" ) { $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') { -#we want to modify an individual basket's group +# +# edit an individual basket contained in this basketgroup +# my $basketno=$input->param('basketno'); my $basketgroupid=$input->param('basketgroupid'); 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 { @@ -374,7 +399,7 @@ if ( $op eq "add" ) { 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..chenge it and change all the basket's basketgroupid as well +#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; @@ -400,21 +425,28 @@ if ( $op eq "add" ) { $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 +# my $basketgroupid = $input->param('basketgroupid'); - CloseBasketgroup($basketgroupid); - printbasketgrouppdf($basketgroupid); exit; }elsif ($op eq 'print'){ +# +# print a closed basketgroup +# my $basketgroupid = $input->param('basketgroupid'); - printbasketgrouppdf($basketgroupid); exit; }elsif ( $op eq "export" ) { +# +# export a closed basketgroup in csv +# my $basketgroupid = $input->param('basketgroupid'); print $input->header( -type => 'text/csv', @@ -423,20 +455,25 @@ if ( $op eq "add" ) { print GetBasketGroupAsCSV( $basketgroupid, $input ); exit; }elsif( $op eq "delete"){ +# +# delete an closed basketgroup +# my $basketgroupid = $input->param('basketgroupid'); DelBasketgroup($basketgroupid); - print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid); - + print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid.'&listclosed=1'); }elsif ( $op eq 'reopen'){ +# +# reopen a closed basketgroup +# my $basketgroupid = $input->param('basketgroupid'); my $booksellerid = $input->param('booksellerid'); - ReOpenBasketgroup($basketgroupid); - - print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid . '#closed'); - + my $redirectpath = ((defined $input->param('mode'))&& ($input->param('mode') eq 'singlebg')) ?'/cgi-bin/koha/acqui/basketgroup.pl?op=add&basketgroupid='.$basketgroupid.'&booksellerid='.$booksellerid : '/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' .$booksellerid.'&listclosed=1'; + print $input->redirect($redirectpath); } elsif ( $op eq 'attachbasket') { - +# +# save a modified basketgroup, or creates a new basketgroup when a basket is closed. called from basket page +# # Getting parameters my $basketgroup = {}; my @baskets = $input->param('basket'); @@ -447,9 +484,9 @@ if ( $op eq "add" ) { 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 + my $closedbg = $input->param('closedbg') ? 1 : 0; if ($basketgroupid) { + # If we have a basketgroupid we edit the basketgroup $basketgroup = { name => $basketgroupname, id => $basketgroupid, @@ -458,13 +495,14 @@ if ( $op eq "add" ) { deliveryplace => $deliveryplace, freedeliveryplace => $freedeliveryplace, deliverycomment => $deliverycomment, - closed => $close, + closed => $closedbg, }; ModBasketgroup($basketgroup); - if($close){ - + if($closedbg){ +# FIXME } }else{ + # we create a new basketgroup (whith a closed basket) $basketgroup = { name => $basketgroupname, booksellerid => $booksellerid, @@ -473,22 +511,22 @@ if ( $op eq "add" ) { deliveryplace => $deliveryplace, freedeliveryplace => $freedeliveryplace, deliverycomment => $deliverycomment, - closed => $close, + closed => $closedbg, }; $basketgroupid = NewBasketgroup($basketgroup); } - - my $url = '/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid; - $url .= "&closed=1" if ($input->param("closed")); - print $input->redirect($url); + my $redirectpath = ((defined $input->param('mode')) && ($input->param('mode') eq 'singlebg')) ?'/cgi-bin/koha/acqui/basketgroup.pl?op=add&basketgroupid='.$basketgroupid.'&booksellerid='.$booksellerid : '/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid; + $redirectpath .= "&listclosed=1" if $closedbg ; + print $input->redirect($redirectpath ); }else{ +# no param : display the list of all basketgroups for a given vendor my $basketgroups = &GetBasketgroups($booksellerid); my $bookseller = &GetBookSellerFromId($booksellerid); my $baskets = &GetBasketsByBookseller($booksellerid); displaybasketgroups($basketgroups, $bookseller, $baskets); } -$template->param(closed => $input->param("closed")); +$template->param(listclosed => ((defined $input->param('listclosed')) && ($input->param('listclosed') eq '1'))? 1:0 ); #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/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tt index c7c9a1b..133fe9d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tt @@ -140,10 +140,25 @@ function submitForm(form) { <div class="yui-b"> [% IF ( grouping ) %] + [% IF (closedbg) %] + <div id="toolbar" class="btn-toolbar"> + <div class="btn-group"><a href="[% script_name %]?op=reopen&basketgroupid=[% basketgroupid %]&booksellerid=[% booksellerid %]&mode=singlebg" class="btn btn-small" id="reopenbutton"><i class="icon-download"></i> Reopen this basket group</a></div> + <div class="btn-group"><a href="[% script_name %]?op=export&basketgroupid=[% basketgroupid %]&booksellerid=[% booksellerid %]" class="btn btn-small" id="exportbutton"><i class="icon-download"></i> Export this basket group as CSV</a></div> + <div class="btn-group"><a href="[% script_name %]?op=print&basketgroupid=[% basketgroupid %]&booksellerid=[% booksellerid %]" class="btn btn-small" id="printbutton"><i class="icon-download"></i> Print this basket group in PDF</a></div> + </div> + [% ELSE %] + <div class="btn-group"><a href="[% script_name %]?op=delete&basketgroupid=[% basketgroupid %]&booksellerid=[% booksellerid %]" class="btn btn-small" id="delbutton"><i class="icon-remove"></i> Delete basket group</a></div> + [% END %] + [% IF (name && closedgb) %] + <h1>Basket group [% name %] ([% basketgroupid %]) for <a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% booksellerid %]">[% booksellername |html %]</a></h1> + [% ELSIF (name) %] + <h1>Edit basket group [% name %] ([% basketgroupid %]) for <a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% booksellerid %]">[% booksellername |html %]</a></h1> + [% ELSE %] <h1>Add basket group for <a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% booksellerid %]">[% booksellername |html %]</a></h1> + [% END %] <div id="basketgroupcolumns" class="yui-g"> + [% UNLESS (closedbg) %] <div class="yui-u"> - <form action="[% scriptname %]" method="post" name="basketgroups" id="basketgroups"> <div id="groups"> <fieldset class="brief"> @@ -170,39 +185,82 @@ function submitForm(form) { </fieldset> </div> </form> - </div> - + [% END %] <div class="yui-u first"> <form action="" method="post" id="groupingform" onsubmit="return submitForm(this)"> <fieldset id="various" class="brief"> <ol> + [% UNLESS (closedbg) %] <li><label for="basketgroupname">Basket group name:</label> <input type="text" name="basketgroupname" id="basketgroupname" value="[% name %]" class="focus" /></li> - <li><label for="billingplace">Billing place:</label> + [% ELSE %] + <input type="hidden" name="basketgroupname" id="basketgroupname" value="[% name %]" /> + [% END %] + <li> + [% UNLESS (closedbg) %] + <label for="billingplace">Billing place:</label> <select name="billingplace" id="billingplace" style="width:13em;"> <option value="">--</option> [% FOREACH billingplaceloo IN billingplaceloop %] [% IF ( billingplaceloo.selected ) %]<option value="[% billingplaceloo.value %]" selected="selected">[% billingplaceloo.branchname %]</option> [% ELSE %]<option value="[% billingplaceloo.value %]">[% billingplaceloo.branchname %]</option>[% END%] [% END %] - </select></li> - <li><label for="deliveryplace">Delivery place:</label> + </select> + [% ELSE %] + <span class="label">Billing place:</span> + [% FOREACH billingplaceloo IN billingplaceloop %] + [% IF ( billingplaceloo.selected ) %] + <input name="billingplace" id="billingplace" type ="hidden" value="[% billingplaceloo.value %]" />[% billingplaceloo.branchname %] + [% END %] + [% END %] + [% END %] + </li> + [% UNLESS (closedbg) %] + <li> + <label for="deliveryplace">Delivery place:</label> <select name="deliveryplace" id="deliveryplace" style="width:13em;"> <option value="">--</option> [% FOREACH deliveryplaceloo IN deliveryplaceloop %] [% IF ( deliveryplaceloo.selected ) %]<option value="[% deliveryplaceloo.value %]" selected="selected">[% deliveryplaceloo.branchname %]</option> [% ELSE %]<option value="[% deliveryplaceloo.value %]">[% deliveryplaceloo.branchname %]</option>[% END %] [% END %] - </select></li> + <select> + </li> <li><p>or</p></li> <li><label for="freedeliveryplace">Delivery place:</label> <textarea cols="26" rows="3" name="freedeliveryplace" id="freedeliveryplace">[% freedeliveryplace %]</textarea></li> - <li><label for="deliverycomment">Delivery comment:</label> - <textarea cols="26" rows="3" name="deliverycomment" id="deliverycomment">[% deliverycomment %]</textarea> + [% ELSE %] + <li> + <span class="label">Delivery place:</span> + [% IF (freedeliveryplace) %] + <input name="freedeliveryplace" id="freedeliveryplace" type ="hidden" value="[% freedeliveryplace %]" />[% freedeliveryplace %] + <input name="deliveryplace" id="deliveryplace" type ="hidden" value="" /> + [% ELSE %] + [% FOREACH deliveryplaceloo IN deliveryplaceloop %] + [% IF ( deliveryplaceloo.selected ) %] + <input name="deliveryplace" id="deliveryplace" type ="hidden" value="[% deliveryplaceloo.value %]" />[% deliveryplaceloo.branchname %] + [% END %] + [% END %] + <input name="freedeliveryplace" id="freedeliveryplace" type ="hidden" value="" /> + [% END %] + </li> + [% END %] + <li> + [% UNLESS (closedbg) %] + <label for="deliverycomment">Delivery comment:</label> + <textarea cols="26" rows="3" name="deliverycomment" id="deliverycomment">[% deliverycomment %]</textarea> + [% ELSE %] + <span class="label">Delivery comment:</span>[% deliverycomment %] + <input name="deliverycomment" id="deliverycomment" type="hidden" value = "[% deliverycomment %]" /> + [% END %] </li> <li><span class="label">Baskets in this group:</span> + [% UNLESS (closedbg) %] <ul class="draglist" id="bg"> + [% ELSE %] + <ul> + [% END %] [% FOREACH selectedbasket IN selectedbaskets %] <li class="grouped" id="b-[% selectedbasket.basketno %]" > <a href="basket.pl?basketno=[% selectedbasket.basketno %]"> @@ -218,10 +276,14 @@ function submitForm(form) { [% END %] </ul> </li> - <li><label><input type="checkbox" id="close" name="close" /> Close basket group</label></li> + [% UNLESS (closedbg) %] + <li><label><input type="checkbox" id="closedbg" name="closedbg" />Close basket group</label></li> + [% ELSE %] + <input type="hidden" id="closedbg" name="closedbg" value ="1"/> + [% END %] </ol> </fieldset> - + [% UNLESS (closedbg) %] <fieldset class="action"><input type="hidden" name="booksellerid" value="[% booksellerid %]" /> [% IF ( basketgroupid ) %] <input type="hidden" name="basketgroupid" value="[% basketgroupid %]" /> @@ -229,6 +291,7 @@ function submitForm(form) { <input type="hidden" name="op" value="attachbasket" /> <input type="submit" value="Save" /> <a href="/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=[% booksellerid %]" class="cancel">Cancel</a> </fieldset> + [% END %] </form> </div> </div> @@ -241,9 +304,9 @@ function submitForm(form) { <div id="basket_groups" class="toptabs"> <ul class="ui-tabs-nav"> - [% UNLESS ( closed ) %]<li class="ui-tabs-selected"><a href="#opened">Open</a></li> + [% UNLESS ( listclosed) %]<li class="ui-tabs-selected"><a href="#opened">Open</a></li> [% ELSE%]<li><a href="#opened">Open</a></li>[% END %] - [% IF ( closed ) %]<li class="ui-tabs-selected"><a href="#closed">Closed</a></li> + [% IF ( listclosed) %]<li class="ui-tabs-selected"><a href="#closed">Closed</a></li> [% ELSE %]<li><a href="#closed">Closed</a></li>[% END %] </ul> <div id="opened"> @@ -273,7 +336,7 @@ function submitForm(form) { <td>[% IF (basketgroup.freedeliveryplace) %]Free delivery place[% ELSE %][% basketgroup.deliveryplace | $KohaBranchName %][% END %]</td> <td>[% basketgroup.basketsqty %]</td> <td> - <input type="button" onclick="closeandprint([% basketgroup.id %])" value="Close and print" /> + <input type="button" onclick="closeandprint('[% basketgroup.id %]');" value="Close and print" /> <form action="/cgi-bin/koha/acqui/basketgroup.pl" method="get"><input type="hidden" name="op" value="add" /><input type="hidden" name="booksellerid" value="[% basketgroup.booksellerid %]" /><input type="hidden" name="basketgroupid" value="[% basketgroup.id %]" /><input type="submit" value="Edit" /></form> <form action="/cgi-bin/koha/acqui/basketgroup.pl" method="get"><input type="hidden" name="op" value="delete" /><input type="hidden" name="booksellerid" value="[% basketgroup.booksellerid %]" /><input type="hidden" name="basketgroupid" value="[% basketgroup.id %]" /><input type="submit" value="Delete" /></form> </td> @@ -311,6 +374,7 @@ function submitForm(form) { <td>[% IF (basketgroup.freedeliveryplace) %]Free delivery place[% ELSE %][% basketgroup.deliveryplace | $KohaBranchName %][% END %]</td> <td>[% basketgroup.basketsqty %]</td> <td> + <form action="/cgi-bin/koha/acqui/basketgroup.pl" method="get"><input type="hidden" name="op" value="add" /><input type="hidden" name="booksellerid" value="[% basketgroup.booksellerid %]" /><input type="hidden" name="basketgroupid" value="[% basketgroup.id %]" /><input type="submit" value="View" /></form> <form action="/cgi-bin/koha/acqui/basketgroup.pl" method="get"><input type="hidden" name="op" value="reopen" /><input type="hidden" name="booksellerid" value="[% basketgroup.booksellerid %]" /><input type="hidden" name="basketgroupid" value="[% basketgroup.id %]" /><input type="submit" value="Reopen" /></form> <form action="/cgi-bin/koha/acqui/basketgroup.pl" method="get"><input type="hidden" name="op" value="print" /><input type="hidden" name="basketgroupid" value="[% basketgroup.id %]" /><input type="submit" value="Print" /></form> <form action="/cgi-bin/koha/acqui/basketgroup.pl" method="get"><input type="hidden" name="op" value="export" /><input type="hidden" name="basketgroupid" value="[% basketgroup.id %]" /><input type="submit" value="Export as CSV" /></form> -- 1.7.9.5