Bug 5336: Order search (search and UI enhancements)

You can now search orders by

- order status
- fund

The patch series also adds a new field, aqorders.orderstatus, which can
contain following values:

  new
  ordered
  partial (for partially received orders)
  complete
  cancelled

To test: Search and check if results are consistent in histsearch.pl
Signed-off-by: Cedric Vita <cedric.vita@dracenie.com>

Signed-off-by: Pierre Angot <tredok.pierre@gmail.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Comments on last patch.
Note: status are no longer numeric, but strings now.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 5336: (follow-up) don't display deleted orders in late orders search result

Test plan:
Check that deleted orders are not listed in the late orders search
results.

Signed-off-by: Cedric Vita <cedric.vita@dracenie.com>

Signed-off-by: Pierre Angot <tredok.pierre@gmail.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 5336: (follow-up) merge parent ordernumber and ordernumber columns in display

Signed-off-by: Cedric Vita <cedric.vita@dracenie.com>
Signed-off-by: Pierre Angot <tredok.pierre@gmail.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 5336: (follow-up) add unit tests for 3 acq routines

Unit tests In C4::Acquisition for:
- CloseBasket
- ReopenBasket
- GetBiblioCountByBasketno

Signed-off-by: Cedric Vita <cedric.vita@dracenie.com>
Signed-off-by: Pierre Angot <tredok.pierre@gmail.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 5336: (follow-up) miscellaneous changes

- fix capitalization
- fix update database message

Signed-off-by: Pierre Angot <tredok.pierre@gmail.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 5336: (follow-up) use understandable codes rather than magic numbers for orderstatus

This patch uses understandable codes instead of magical numbers for the
aqorders.orderstatus field.

+ execute sql queries in unit tests into a transaction.

Signed-off-by: Pierre Angot <tredok.pierre@gmail.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 5336: (follow-up) fix case where partial status was not correctly set

An order (o1) is considered as partially received if (at least) another
order (o2) has the o1.ordernumber == o2.parent_ordernumber and the
quantity received is < to the quantity (to receive) and o1.ordernumber
!= o1.parent_ordernumber.

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 5336: (follow-up) multiple QA fixes

- add a message if the search returns no result
- keep selected values if the search returns no result (for fund and
  order status)
- remove plurals in order status
- move the order status column in the search results table

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Passes all tests and QA script.
New tests also pass:
    t/db_dependent/Acquisition/close_reopen_basket.t

1) Database update - I end up with too many partials. My test cases:

 - New orders, basket still open
   OK Expected: new, Result: partial
 - Ordered orders, basket and basketgroup closed
   OK Expected: ordered, Result: partial
 - Partially received orders
   OK Expected: partial/complete, Result: partial/complete
 - Received orders
   OK: Expected: complete, Result: complete
 - Cancelled orders
   * cancelled from open basket before order
   OK: Expected: cancelled, Result: cancelled
   * cancelled from closed basket before receive
   OK: Expected: cancelled, Result: cancelled

All aqorders where updated with the correct status.

I have saved my 'pre-updatedatabase' and can repeat the test anytime you have a follow up.

2) Testing search functionality

  a) Order search - result list
  Order search shows a new column, I think it would be a bit better if the
  status there was singular instead of plural - new order, partially received
  order etc. - maybe we could even leave out the 'order'? (minor)

  The column seems a bit lost in the middle, not sure where it would make more
  sense (just saying)

  b) Order search - advanced search form
  The advanced search form now shows a new filter: Order status

  All new status can be searched.
  - an "empty" search will find all but cancelled orders
  - searching for cancelled orders works correctly and shows results
  Search works correctly, no regressions found.

  If no result is found a message is shown.
  All search input is kept, so you can modify your search terms easily.

3) Testing setting of status after applying the patch

   a) Create a new order with 2 items - status is new. OK
   b) Close the basket - status is ordered. OK
   c) Receive both items - status is completed. OK
   d) Undo receipt - status is ordered. OK
   e) Receive only 1 item - order is split up into 2 orders:
       - status is partial OK
       - status is completed OK
   f) Undo receipt of received item - order is combined into 1 again
       - status is ordered OK!
   g) Receive only 1 item again - status ordered/partial.
   h) Delete order.
       - status is completed
       - status is cancelled
      OK!

   i) Undo receipt of 1 item again.
      Refresh page.

This results in the following behaviour, that has been reported as
bug 10984. After refreshing the page follow message is shown:
  Cannot cancel receipt. Possible reasons :
    - The order line you trying to cancel was created from a partial
    receipt of another order line which is already received.
    Try to cancel this one first and retry.
    - The order line you trying to cancel was created from a partial
    receipt of another order line which has been deleted.
    Cancellation is not possible.
  BUT: The receipt is undone, but you are left with a
    line with 2 items, a cancellation date and the status ordered.
    Because of the cancellation date the order is not visible in pending orders.

The status is correct - so I feel this should not stop this patch.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 5336: DBRev 3.13.00.032

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 5336: (follow-up) update DBIC schema class for aqorders

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 5336: (follow-up) remove unused new parameter to NewOrder() that slipped in

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 5336: (follow-up) improve setting 'partial' order status during upgrade

This patch modifies the logic to set the partial status for an
order to verify that:

- at least one item has been received already
- the order belongs to a closed basket

Signed-off-by: Galen Charlton <gmc@esilibrary.com>