MT 1496 : Close basket
authorMatthias Meusburger <matthias.meusburger@biblibre.com>
Mon, 24 Aug 2009 13:36:51 +0000 (15:36 +0200)
committerHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Wed, 30 Sep 2009 09:30:30 +0000 (11:30 +0200)
acqui/basket.pl
acqui/basketgroup.pl
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tmpl

index 1a9e851..c573035 100755 (executable)
@@ -133,33 +133,24 @@ if ( $op eq 'delete_confirm' ) {
         count               =>     $count,
       );
 } elsif ($op eq 'attachbasket' && $template->{'param_map'}->{'CAN_user_acquisition_group_manage'} == 1) {
-    my $basketgroups = GetBasketgroups($basket->{booksellerid});
-    for (my $i=0; $i < scalar(@$basketgroups); $i++) {
-        if (@$basketgroups[$i]->{closed}) {
-            splice(@$basketgroups, $i, 1);
-            $i--;
-        } elsif ($basket->{basketgroupid} == @$basketgroups[$i]->{id}){
-            @$basketgroups[$i]->{default} = 1;
-        }
-    }
-    $template->param(
-        basketgroups    => $basketgroups,
-        booksellerid    => $booksellerid,
-        basketno        => $basket->{'basketno'},
-        basketname      => $basket->{'basketname'},
-        name            => $bookseller->{'name'},
-        selectbasketg    => "1"
-    );
+      print $query->redirect('/cgi-bin/koha/acqui/basketgroup.pl?basketno=' . $basket->{'basketno'} . '&op=attachbasket&booksellerid=' . $booksellerid);
     # check if we have to "close" a basket before building page
 } elsif ($op eq 'close') {
-    my $basket = $query->param('basketno');
-    $basket =~ /^\d+$/ and CloseBasket($basket);
-    if ($template->{'param_map'}->{'CAN_user_acquisition_group_manage'} == 1){
-        print $query->redirect('/cgi-bin/koha/acqui/basket.pl?basketno='.$basket.'&op=attachbasket');
-        exit;
+    my $confirm = $query->param('confirm');
+    if ($confirm) {
+       my $basketno = $query->param('basketno');
+       my $booksellerid = $query->param('booksellerid');
+       $basketno =~ /^\d+$/ and CloseBasket($basketno);
+       print $query->redirect('/cgi-bin/koha/acqui/basketgroup.pl?basketno='.$basketno.'&op=attachbasket&booksellerid=' . $booksellerid);
+       exit;
+
     } else {
-        print $query->redirect('/cgi-bin/koha/acqui/booksellers.pl?supplierid='.$booksellerid);
-        exit;
+       $template->param(confirm_close => "1",
+                       booksellerid    => $booksellerid,
+                       basketno        => $basket->{'basketno'},
+                       basketname      => $basket->{'basketname'},
+                       basketgroupname => $basket->{'basketname'});
+               
     }
 } elsif ($query->param('op') eq 'reopen') {
     my $basket;
@@ -188,10 +179,7 @@ if ( $op eq 'delete_confirm' ) {
     if ($basket->{closedate} && haspermission({ flagsrequired   => { acquisition => 'group_manage'} })) {
         $basketgroups = GetBasketgroups($basket->{booksellerid});
         for (my $i=0; $i < scalar(@$basketgroups); $i++) {
-            if (@$basketgroups[$i]->{closed}) {
-                splice(@$basketgroups, $i, 1);
-                $i--;
-            } elsif ($basket->{basketgroupid} == @$basketgroups[$i]->{id}){
+            if ($basket->{basketgroupid} == @$basketgroups[$i]->{id}){
                 @$basketgroups[$i]->{default} = 1;
             }
         }
index 12db2cf..86dfae9 100755 (executable)
@@ -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/GetOrders GetBasketsByBasketgroup GetBasketsByBookseller ModBasketgroup NewBasketgroup DelBasketgroup GetBasketgroups ModBasket GetBasketgroup GetBasket/;
 use C4::Bookseller qw/GetBookSellerFromId/;
 
 my $input=new CGI;
@@ -311,37 +311,43 @@ if (! $op ) {
     print $pdf;
     exit;
 } elsif ( $op eq 'attachbasket') {
-    # TODO: create basketgroup and attach basket to it?
+    # Getting parameters
     my $basketgroup = {};
-    $basketgroup->{'name'} = $input->param('basketgroupname');
+    my $basketno = $input->param('basketno');
+    my $basket = GetBasket($basketno);
+    $basketgroup->{'name'} = $input->param('basketgroupname') || $basket->{'basketname'};
     $basketgroup->{'booksellerid'} = $input->param('booksellerid');
     my $basketgroupid;
-    my $basketno = $input->param('basketno');
     warn "basketgroupname", $basketgroup->{'name'};
+
+    # If we got a basketgroupname, we create a basketgroup
     if ($basketgroup->{'name'}) {
         $basketgroupid = NewBasketgroup($basketgroup);
     } else {
+       # Else, we use the basketgroupid in parameter
         $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 = {};
+
+    $basketgroup= {};
+    $basketgroup->{'closed'} = 1;
+    $basketgroup->{'id'} = $basketgroupid;
+    ModBasketgroup($basketgroup);
+    $basket = {};
     $basket->{'basketno'} = $basketno;
     $basket->{'basketgroupid'} = $basketgroupid;
     ModBasket($basket);
-    $basketgroup = GetBasketgroup($basketgroupid);
+
+   
+      $basketgroup = GetBasketgroup($basketgroupid);
     my $baskets = GetBasketsByBasketgroup($basketgroupid);
     my $bookseller = &GetBookSellerFromId($booksellerid);
-    my @basketgroups;
-    push(@basketgroups, $basketgroup);
-    $template->param(displayclosedbgs => 1,
-                     booksellerid => $booksellerid);
-    displaybasketgroups(\@basketgroups, $bookseller, $baskets);
+
+    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');
+    }
 }
 #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;
index a5c05db..d07f2ad 100644 (file)
@@ -55,6 +55,7 @@
    <div id="bd">
        <div id="yui-main">
        <div class="yui-b">
+        <!-- TMPL_UNLESS name="confirm_close" -->
         <!-- TMPL_UNLESS name="selectbasketg" -->
             <!-- TMPL_UNLESS name="closedate" -->
                 <div id="toolbar">
                         <li><button onclick="confirm_close()" class="yui-button-disabled" id="closebutton" type="push" disabled="true" title="You can not close this basket" >Can not close basket</a></li>
                         <li><a href="/cgi-bin/koha/acqui/uncertainprice.pl?booksellerid=<!-- TMPL_VAR name="booksellerid" -->&owner=1" class="button" id="uncertpricesbutton">Uncertain prices</a></li>
                     <!-- TMPL_ELSE -->
-                        <!-- TMPL_IF name="CAN_user_acquisition_group_manage" -->
-                            <li><a href="<!-- TMPL_VAR name="script_name" -->?op=close&basketno=<!-- TMPL_VAR name="basketno" -->" class="button" id="closebutton">Close this basket</a></li>
-                        <!-- TMPL_ELSE -->
-                            <li><a href="javascript:confirm_close();" class="button" id="closebutton">Close this basket</a></li>
-                        <!-- /TMPL_IF -->
+                        <li><a href="<!-- TMPL_VAR name="script_name" -->?op=close&basketno=<!-- TMPL_VAR name="basketno" -->&booksellerid=<!-- TMPL_VAR name="booksellerid" -->" class="button" id="closebutton">Close this basket</a></li>
                     <!-- /TMPL_IF -->
                     </ul>
                 </div>
                 </div>
                 <!-- /TMPL_UNLESS -->
             <!-- /TMPL_UNLESS -->
+            <!-- /TMPL_UNLESS -->
             
     <!-- TMPL_IF NAME="NO_BOOKSELLER" -->
     <h2>Supplier Not Found</h2>
         <!-- /TMPL_UNLESS -->
         <!-- /TMPL_UNLESS -->
 <!-- /TMPL_IF -->
-<!-- /TMPL_IF -->
-    <!-- TMPL_ELSE --> <!-- if we want just to select a basketgroup for a closed basket -->
-        <form action="/cgi-bin/koha/acqui/basketgroup.pl">
-        <fieldset>
-            <legend>Assign basket <!-- TMPL_VAR name="basketname" --> to basketgroup</legend>
-                <p><label for="basketgroupid" >basketgroup:</label>
-                    <select id="basketgroupid" name="basketgroupid">
-                        <!-- TMPL_LOOP name="basketgroups" -->
-                        <option value="<!-- TMPL_VAR name="id" -->"><!-- TMPL_VAR name="name" --></option>
-                        <!-- /TMPL_LOOP -->
-                    </select>
-                </p>
-                <p>
-                    <label for="basketgroupname">Or type in the name of a new basketgroup:</label>
-                    <input type="text" id="basketgroupname" name="basketgroupname"/>
-                </p>
-                <p>
-                    <label for='closebasketgroup'>Close basketgroup after attaching it:</label>
-                    <input type="checkbox" id="closebasketgroup" name="closebasketgroup"/>
-                </p>
-                <input type="hidden" id="basketno" value="<!-- TMPL_VAR name="basketno" -->" name="basketno" />
-                <input type="hidden" value="attachbasket" name="op" />
-                <input type="hidden" name="booksellerid" value="<!-- TMPL_VAR name="booksellerid" -->" />
-                <input type="submit" value="Change basketgroup" />
-        </fieldset>
-        </form>
+<!-- /TMPL_IF -->    <!-- TMPL_ELSE --> <!-- if we want just to select a basketgroup for a closed basket -->
     <!-- /TMPL_UNLESS -->
+<!-- TMPL_IF name="confirm_close" -->
+           <div id="closebasket_needsconfirmation" class="dialog alert">
+
+           <form action="/cgi-bin/koha/acqui/basket.pl" class="confirm">
+           <fieldset>
+               <legend>Closing basket <!-- TMPL_VAR name="basketname" --></legend>
+                   <p>Are you sure you want to close this basket ?</p>
+                   <p>
+                       <label for="createorder">Create order ?</label>
+                       <input type="checkbox" id="createorder" name="createorder"/>
+                   </p>
+                   <input type="hidden" id="basketno" value="<!-- TMPL_VAR name="basketno" -->" name="basketno" />
+                   <input type="hidden" value="close" name="op" />
+                   <input type="hidden" name="booksellerid" value="<!-- TMPL_VAR name="booksellerid" -->" />
+                   <input type="hidden" name="confirm" value="1" />
+                   <input type="hidden" name="basketgroupname" value="<!-- TMPL_VAR name="basketgroupname" -->" />
+                   <input type="submit" class="approve" value="Yes, Close (Y)" accesskey="y" />
+                   <input type="submit" class="deny" value="No, Don't Close (N)" accesskey="n" onclick="javascript:window.location='/cgi-bin/koha/acqui/basket.pl?basketno=<!-- TMPL_VAR name="basketno" -->';return false;" />
+           </fieldset>
+           </form>
+           </div>
+       <!-- /TMPL_IF -->
+  
+
+
 </div>
 </div>
 <div class="yui-b">