Bug 21467: Allow several receipts for a given subscription
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 1 Oct 2018 22:41:17 +0000 (19:41 -0300)
committerNick Clemens <nick@bywatersolutions.com>
Tue, 13 Nov 2018 19:31:09 +0000 (19:31 +0000)
When a new order is created from a subscription the quantity is set to 1
and cannot be modified.
The idea was to order 1 subscription.
This behavior leads to a limitation: it is not possible to mark a
receipt as partially received. However it is how it works in real life,
the vendors send invoices throughout the year. The number of items can
also be changed.

The idea is be to rethink the "quantity" value for an order created
from a subscription and use it to track the number of invoices already
paid.

FIXME: This approach will not cohabit with standing orders.
This patch is a first draft to get feedback on the idea.

FIXME: What about cancelled orders?

Test plan:
- Create a new order from a subscription
- Enter the number of items you think you will receive for this
subscription (for instance 1 per month: 12)
- Close the basket
- Receive 3 items (a trimester) and create a specific invoice for this
receipt. Note that the price are per unit.
If you want to receive items with different prices you should make
split the receipt
- Receive more items. This time you will notice that the previous order
will be displayed on the "order receive" under a new block "Receipt
history for this subscription"
- Note that the "Quantity to receive" has been decrease by the number of
items you previously received
- Also you can notice that this "Quantity to receive" can be modified.
Indeed it can happen that the number of items to receive changed during
the year
- Go to the detail of the subscription and notice that the orders have
been grouped by "parent ordernumber"
- Continue to receive items until all have been received

Sponsored-by: BULAC - http://www.bulac.fr/

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

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

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

acqui/finishreceive.pl
acqui/orderreceive.pl
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt

index ca50496..79b6326 100755 (executable)
@@ -61,7 +61,8 @@ my $new_ordernumber  = $ordernumber;
 
 $unitprice = Koha::Number::Price->new( $unitprice )->unformat();
 $replacementprice = Koha::Number::Price->new( $replacementprice )->unformat();
-my $basket = Koha::Acquisition::Orders->find( $ordernumber )->basket;
+my $order_obj = Koha::Acquisition::Orders->find( $ordernumber );
+my $basket = $order_obj->basket;
 
 #need old receivedate if we update the order, parcel.pl only shows the right parcel this way FIXME
 if ($quantityrec > $origquantityrec ) {
@@ -100,6 +101,10 @@ if ($quantityrec > $origquantityrec ) {
 
     # save the quantity received.
     if ( $quantityrec > 0 ) {
+        if ( $order_obj->subscriptionid ) {
+            # Quantity can only be modified if linked to a subscription
+            $order->{quantity} = $quantity; # quantityrec will be deduced from this value in ModReceiveOrder
+        }
         ( $datereceived, $new_ordernumber ) = ModReceiveOrder(
             {
                 biblionumber     => $biblionumber,
index 1db00d3..ebf29f7 100755 (executable)
@@ -197,6 +197,18 @@ my @gst_values = map {
     option => $_ + 0.0
 }, split( '\|', C4::Context->preference("gist") );
 
+if ( $order->{subscriptionid} ) {
+    # Order from a subscription, we will display an history of what has been received
+    my $orders = Koha::Acquisition::Orders->search(
+        {
+            subscriptionid     => $order->{subscriptionid},
+            parent_ordernumber => $order->{ordernumber},
+            ordernumber        => { '!=' => $order->{ordernumber} }
+        }
+    );
+    $template->param( orders => $orders );
+}
+
 $template->param(
     AcqCreateItem         => $AcqCreateItem,
     count                 => 1,
index 1ae2f3b..ab07b1a 100644 (file)
                     <input type="hidden" name="quantity" value="[% quantity | html %]" />[% quantity | html %]
                 [% ELSE %]
                     <label class="required" for="quantity">Quantity: </label>
-                    [% IF (AcqCreateItemOrdering) %]
-                        [% IF subscriptionid || basket.is_standing %]
+                    [% IF subscriptionid %]
+                        <input type="text" size="20" id="quantity" name="quantity" value="1" onchange="updateCosts();" />
+                    [% ELSIF AcqCreateItemOrdering %]
+                        [% IF basket.is_standing %]
                             <input type="text" readonly="readonly" size="20" id="quantity" name="quantity" value="1" />
                         [% ELSE %]
                             <input type="text" readonly="readonly" size="20" id="quantity" name="quantity" value="0" />
                         [% END %]
                     [% ELSE %]
-                        [% IF subscriptionid || basket.is_standing %]
+                        [% IF basket.is_standing %]
                             <input type="text" readonly="readonly" size="20" id="quantity" name="quantity" value="1" />
                         [% ELSE %]
                             <input type="text" size="20" id="quantity" name="quantity" value="[% quantityrec | html %]" onchange="updateCosts();" />
             });
 
             //We apply the fonction only for modify option
-            [% IF ( quantityrec ) %]
+            [% IF ( quantityrec and not subscriptionid ) %]
                 [% IF ( acqcreate ) %]
                     $('#quantity').blur(function(){
                         // if user decreases the quantity
index 9c7e702..abe2d16 100644 (file)
         </fieldset>
     [% END %]
 
-    [% IF (AcqCreateItemReceiving) %]
+    [% IF subscriptionid and orders.count %]
+        <fieldset class="rows">
+            <legend>Receipt history for this subscription</legend>
+            <table id="orders">
+                <thead>
+                    <tr>
+                        <th>Invoice</th>
+                        <th>Order number</th>
+                        <th class="title-string">Creation date</th>
+                        <th class="title-string">Receive date</th>
+                        <th>Quantity received</th>
+                        <th class="title-string">Status</th>
+                        <th title="Actual cost tax exc. / Actual cost tax inc.">Spent</th>
+                        <th>Internal note</th>
+                    </tr>
+                </thead>
+                <tbody>
+                [% FOR order IN orders %]
+                    <tr>
+                        <td>
+                        [% IF order.invoice %]
+                            [% IF CAN_user_acquisition %]
+                                <a href="/cgi-bin/koha/acqui/invoice.pl?invoiceid=[% order.invoiceid | html %]" title="Invoice detail page">
+                                   [% order.invoice.invoicenumber | html %]</a>
+                            [% ELSE %]
+                                [% order.invoice.invoicenumber | html %]
+                            [% END %]
+                        [% END %]
+                        </td>
+                        <td>[% order.ordernumber | html %]</td>
+                        <td><span title="[% order.basket.creationdate | uri %]">[% order.basket.creationdate | $KohaDates%]</span></td>
+                        <td>[% IF order.datereceived %]<span title="[% order.datereceived | uri %]">[% order.datereceived | $KohaDates %]</span>[% END %]</td>
+                        <td>[% order.quantityreceived | html %]</td>
+                        <td>
+                          [% SWITCH order.orderstatus %]
+                          [%# FIXME We should only see/display Complete here, right? %]
+                            [% CASE 'new' %]<span title="status_1">New</span>
+                            [% CASE 'ordered' %]<span title="status_2">Ordered</span>
+                            [% CASE 'partial' %]<span title="status_3">Partial</span>
+                            [% CASE 'complete' %]<span title="status_4">Complete</span>
+                            [% CASE 'cancelled' %]<span title="status_5">Cancelled</span>
+                          [% END %]
+                        </td>
+                        <td>
+                            [% IF order.datereceived %][%# FIXME Should only be true, right? %]
+                                [%# FIXME What if unitprice has not been filled? %]
+                                [% order.unitprice_tax_excluded | $Price | html %] / [% order.unitprice_tax_included | $Price | html %]
+                            [% END %]
+                        </td>
+                        <td>[% order.order_internalnote | html %]</td>
+                    </tr>
+                [% END %]
+                </tbody>
+            </table>
+        </fieldset>
+    [% ELSIF (AcqCreateItemReceiving) %]
         <div id="items_list" style="display:none">
             <p><b>Items list</b></p>
             <div style="width:100%;overflow:auto;">
         </span>
        </li>
        <li><label for="quantity_to_receive">Quantity to receive: </label><span class="label">
-           [% IF ( edit and not subscriptionid) %]
+           [% IF edit or subscriptionid %]
                <input type="text" id="quantity_to_receive" name="quantity" value="[% quantity | html %]" />
            [% ELSE%]
                <input type="text" readonly="readonly" id="quantity_to_receive" name="quantity" value="[% quantity | html %]" />
            [% END %]
            </span></li>
         <li><label for="quantity">Quantity received: </label>
-          [% IF (AcqCreateItemReceiving) %]
-            [% IF ( subscriptionid ) %]
-              <input readonly="readonly" type="text" size="20" name="quantityrec" id="quantity" value="1" />
-            [% ELSE %]
+          [% IF subscriptionid %]
+              <input type="text" size="20" name="quantityrec" id="quantity" value="[% quantity | html %]" />
+              <input id="origquantityrec" readonly="readonly" type="hidden" name="origquantityrec" value="[% quantityreceived | html %]" />
+          [% ELSIF AcqCreateItemReceiving %]
               <input readonly="readonly" type="text" size="20" name="quantityrec" id="quantity" value="0" />
-            [% END %]
           [% ELSE %]
             [% IF ( quantityreceived ) %]
                 [% IF ( edit ) %]
                     <input id="origquantityrec" readonly="readonly" type="hidden" name="origquantityrec" value="[% quantityreceived | html %]" />
                 [% END %]
             [% ELSE %]
-                [% IF ( subscriptionid ) %]
-                    <input type="text" readonly="readonly" id="quantity" size="20" name="quantityrec" value="1" />
-                [% ELSE %]
-                    <input type="text" id="quantity" size="20" name="quantityrec" value="1" />
-                [% END %]
+                <input type="text" id="quantity" size="20" name="quantityrec" value="1" />
                 <input id="origquantityrec" readonly="readonly" type="hidden" name="origquantityrec" value="0" />
             [% END %]
             <div id="qtyrecerror" style="display:none">
                 <p class="error">Warning, you have entered more items than expected.
                 Items will not be created.</p>
             </div>
-          [% END %][%# IF (AcqCreateItemReceiving) %]
+          [% END %][%# IF (subscriptionid) ELSIF (AcqCreateItemReceiving) %]
                </li>
 
         [% IF ( gst_values ) %]
         <li><label for="rrp">Retail price: </label>[% rrp | $Price %] <span class="hint">(adjusted for [% cur_active | html %], [% IF (listincgst == 1) %]tax inclusive[% ELSE %]tax exclusive[% END %])</span></li>
         <li>
             <label for="replacementprice">Replacement price:</label>
-            <input type="text" size="20" name="replacementprice" id="replacementprice" value="[% replacementprice | $Price %]" />
+            <input type="text" size="20" name="replacementprice" id="replacementprice" value="[% replacementprice | $Price | html %]" />
         </li>
         <li><label for="ecost">Budgeted cost: </label>[% ecost | $Price %] <span class="hint">[% IF (listincgst == 1) %](tax inclusive)[% ELSE %](tax exclusive)[% END %]</span></li>
         <li>