Bug 12395: Save order line's creator
authorJulian Maurice <julian.maurice@biblibre.com>
Mon, 9 Jun 2014 14:15:17 +0000 (16:15 +0200)
committerNick Clemens <nick@bywatersolutions.com>
Fri, 6 Jul 2018 14:01:47 +0000 (14:01 +0000)
New MySQL column: aqorders.createdby

Creator's name is displayed on order's receive pages (acqui/orderreceive.pl
and acqui/parcel.pl)

On acqui/orderreceive.pl it replace the name of basket's creator
On acqui/parcel.pl, to avoid adding more data in the table of pending
orders, it is shown in a popup like MARC and Card views

Test plan:
1/ Run updatedatabase.pl
2/ Create a new order and go to the receipt page (acqui/parcel.pl)
3/ Click on "Order" link in column "More" (previously "View record")
4/ A javascript popup should appear with your name in it. Close the
popup.
5/ Click on "Receive" link
6/ Your name should appear in front of "Created by" label, to the right
of the page.

Patch updated with use of atomic update.

Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Koha/Acquisition/Order.pm
acqui/orderreceive.pl
acqui/showorder.pl [new file with mode: 0755]
installer/data/mysql/atomicupdate/Bug-12395-add-column-aqorders.created_by.sql [new file with mode: 0644]
installer/data/mysql/kohastructure.sql
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/showorder.tt [new file with mode: 0644]

index 79fb056..b195ed2 100644 (file)
@@ -69,6 +69,13 @@ sub store {
           unless $self->$key;
     }
 
+    if (not defined $self->{created_by}) {
+        my $userenv = C4::Context->userenv;
+        if ($userenv) {
+            $self->created_by($userenv->{number});
+        }
+    }
+
     $self->quantityreceived(0) unless $self->quantityreceived;
     $self->entrydate(dt_from_string) unless $self->entrydate;
 
index c88a533..4dbb5f0 100755 (executable)
@@ -183,14 +183,7 @@ if( defined $order->{tax_rate_on_receiving} ) {
 
 my $suggestion = GetSuggestionInfoFromBiblionumber($order->{biblionumber});
 
-my $authorisedby = $order->{authorisedby};
-my $authorised_patron = Koha::Patrons->find( $authorisedby );
-if ( $authorised_patron ) { # This should not happen unless there was a migration issue (or very old install?)
-    $template->param(
-        memberfirstname  => $authorised_patron->firstname || "",
-        membersurname    => $authorised_patron->surname || "",
-    );
-}
+my $creator = Koha::Patrons->find( $order->{created_by} );
 
 my $budget = GetBudget( $order->{budget_id} );
 
@@ -223,6 +216,7 @@ $template->param(
     ecost                 => $ecost,
     unitprice             => $unitprice,
     tax_rate              => $tax_rate,
+    creator               => $creator,
     invoiceid             => $invoice->{invoiceid},
     invoice               => $invoice->{invoicenumber},
     datereceived          => $datereceived,
diff --git a/acqui/showorder.pl b/acqui/showorder.pl
new file mode 100755 (executable)
index 0000000..d3ea597
--- /dev/null
@@ -0,0 +1,45 @@
+#!/usr/bin/perl
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 3 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+use Modern::Perl;
+use CGI;
+
+use C4::Auth;
+use C4::Output;
+
+use Koha::Acquisition::Orders;
+use Koha::Patrons;
+
+my $cgi = new CGI;
+my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
+    template_name   => "acqui/showorder.tt",
+    query           => $cgi,
+    type            => "intranet",
+    authnotrequired => 0,
+    flagsrequired   => { acquisition => '*' },
+});
+
+my $ordernumber = $cgi->param('ordernumber');
+my $order = Koha::Acquisition::Orders->find($ordernumber);
+my $creator = Koha::Patrons->find($order->created_by);
+
+$template->param(
+    order => $order,
+    creator => $creator,
+);
+
+output_html_with_http_headers $cgi, $cookie, $template->output;
diff --git a/installer/data/mysql/atomicupdate/Bug-12395-add-column-aqorders.created_by.sql b/installer/data/mysql/atomicupdate/Bug-12395-add-column-aqorders.created_by.sql
new file mode 100644 (file)
index 0000000..4d2a0fb
--- /dev/null
@@ -0,0 +1,2 @@
+ALTER TABLE aqorders ADD COLUMN created_by int(11) NULL DEFAULT NULL AFTER quantityreceived;
+UPDATE aqorders, aqbasket SET aqorders.created_by = aqbasket.authorisedby  WHERE aqorders.basketno = aqbasket.basketno;
index f7970c0..c6f7f01 100644 (file)
@@ -3159,6 +3159,7 @@ CREATE TABLE `aqorders` ( -- information related to the basket line items
   `unitprice_tax_excluded` decimal(28,6) default NULL, -- the unit price excluding tax (on receiving)
   `unitprice_tax_included` decimal(28,6) default NULL, -- the unit price including tax (on receiving)
   `quantityreceived` smallint(6) NOT NULL default 0, -- the quantity that have been received so far
+  `created_by` int(11) NULL DEFAULT NULL, -- the borrowernumber of order line's creator
   `datecancellationprinted` date default NULL, -- the date the line item was deleted
   `cancellationreason` MEDIUMTEXT default NULL, -- reason of cancellation
   `order_internalnote` LONGTEXT, -- notes related to this order line, made for staff
index 1abf288..1719a08 100644 (file)
             [% END %]
        </select></li>
        <li><label>&nbsp;</label><span>(Current: [% budget_period_description %] - [% bookfund %])</span></li>
-       <li><label for="creator">Created by: </label><span> [% IF ( memberfirstname and membersurname ) %][% IF ( memberfirstname ) %][% memberfirstname %][% END %] [% membersurname %][% ELSE %]No name[% END %]</span></li>
+       <li>
+        <label for="creator">Created by: </label>
+        <span>
+          [% IF (creator && creator.firstname && creator.surname) %]
+            [% IF creator.firstname %]
+              [% creator.firstname %]
+            [% END %]
+            [% creator.surname %]
+          [% ELSE %]
+            No name
+          [% END %]
+        </span>
+       </li>
        <li><label for="quantity_to_receive">Quantity to receive: </label><span class="label">
            [% IF ( edit and not subscriptionid) %]
                <input type="text" id="quantity_to_receive" name="quantity" value="[% quantity %]" />
index 96c2f51..f6bbf9e 100644 (file)
             <th>Basket group</th>
             <th>Order line</th>
             <th>Summary</th>
-            <th>View record</th>
+            <th>More</th>
             <th>Quantity</th>
             <th>Unit cost</th>
             <th>Order cost</th>
                     [<a href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber=[% loop_order.ordernumber %]&amp;referrer=/cgi-bin/koha/acqui/parcel.pl%3Finvoiceid=[% invoiceid %]&type=vendor">Add vendor note</a>]
                 [% END %]
                 </td>
-                <td><a href="/cgi-bin/koha/catalogue/showmarc.pl?id=[% loop_order.biblionumber %]" class="previewData">MARC</a> | <a href="/cgi-bin/koha/catalogue/showmarc.pl?viewas=card&amp;id=[% loop_order.biblionumber %]" class="previewData">Card</a></td>
+                <td>
+                  <a href="/cgi-bin/koha/acqui/showorder.pl?ordernumber=[% loop_order.ordernumber %]" class="previewData">Order</a><br>
+                  <a href="/cgi-bin/koha/catalogue/showmarc.pl?id=[% loop_order.biblionumber %]" class="previewData">MARC</a><br>
+                  <a href="/cgi-bin/koha/catalogue/showmarc.pl?viewas=card&amp;id=[% loop_order.biblionumber %]" class="previewData">Card</a>
+                </td>
                 <td>[% loop_order.quantity %]</td>
                 <td>[% loop_order.ecost | $Price %]</td>
                 <td>[% loop_order.total | $Price %]</td>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/showorder.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/showorder.tt
new file mode 100644 (file)
index 0000000..b872b20
--- /dev/null
@@ -0,0 +1,38 @@
+[% INCLUDE 'doc-head-open.inc' %]
+<style>
+  td {
+    padding: 0 1em;
+  }
+  td:first-child {
+    font-weight: bold;
+    text-align: right;
+  }
+</style>
+</head>
+<body>
+  [% IF order %]
+    <table>
+      <tbody>
+        <tr>
+          <td>Creation date</td>
+          <td>[% order.entrydate %]</td>
+        </tr>
+        <tr>
+          <td>Creator</td>
+          <td>[% creator.firstname %] [% creator.surname %]</td>
+        </tr>
+        <tr>
+          <td>Claims count</td>
+          <td>[% order.claims_count %]</td>
+        </tr>
+        <tr>
+          <td>Last claim date</td>
+          <td>[% order.claimed_date %]</td>
+        </tr>
+      </tbody>
+    </table>
+  [% ELSE %]
+    No order found.
+  [% END %]
+</body>
+</html>