Bug 7180: Order from staged file improvements

This patch adds:
- 1 syspref MarcFieldsToOrder
- 1 Ajax script acqui/ajax-getauthvaluedropbox.pl
- 1 routine C4::Budgets::GetBudgetByCode

Before this patch you were not able to order 1 or all the records from
your staged file. You were allowed to specify some information ("Import
All" and "Accounting details" areas) for the order.

With this patch, the previous behaviour still exists.
But now you can *select* which records you want to ordered.
For these ones you can specify independently quantity,
price, budget, sort1 and sort2.

The cherry on the cake is that you can pre-fill these fields  with
values from the MARC record.

Test plan:
1. Fill the new syspref MarcFieldsToOrder with something like:
==BEGIN==
price: 947$c
quantity: 969$h
budget_code: 922$a
rrp: 010$d
discount: 969$d
sort1: 923$a
sort2: 924$a

==END==
The empty line at the end is mandatory!
The budget (corresponding to your budget_code) can be filled with
authorized value categories (statistic 1 and 2).
The sort1 and sort2 values can be filled with the an authorized value
(of the category previously selected)

2. Choose randomly one or more biblio(s) and fill fields with what is
   relevant.

3. Export the biblio and import it (with the "Stage MARC records for
   import" tool).

4. Go on a basket and add an order from a staged file. Select your
   staged file.

5. Well. Now you can see your biblio (or biblios if your had exported
   more than one). For each one, fields should be pre-filled with the
   biblio values. The budget should be selected on the budget
   corresponding to the budget_code (in the field 922$a) and the
   "planning values" too (with fields 923$a and 924$a).
   You can modify these values (or not) and choose a default value for
   budget and planning values (in the "Accounting details" area).

6. Save and check the prices values. Modify the order and check that
   budget and sort* are good

Prices are calculated following some parameters:
if there is no price => listprice = 0
else =>
  - the gstrate value for your order is the gstrate value of the bookseller
  - discount = if filled : the discount value / 100
               else: the discount value of the bookseller
  - if the bookseller includes tax( List item price includes tax: Yes )
        if a discount exists:
            ecost = price
            rrp   = ecost / ( 1 - discount )
        else: # a discount does not exist
            ecost = price * ( 1 - discount )
            rrp   = price
    else # the bookseller does not include tax
        if a discount exists:
            ecost = price / ( 1 + gstrate )
            rrp   = ecost / ( 1 - discount )
        else: # a discount does not exist
            rrp   = price / ( 1 + gstrate )
            ecost = rrp * ( 1 - discount )
  - in all cases:
        listprice = rrp / currency rate
        unitprice = ecost
        total = ecost * quantity

7. Retry with different parameters

8. Check the 'Import all' action still works

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 7180: (follow-up) fix getAuthValueDropbox should display the selected value

If the no AV match the name/category or if no category is defined, the
input field should contain the value.

Signed-off-by: Pierre Angot <tredok.pierre@gmail.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 7180: Add UT for C4::Budgets::GetBudgetByCode

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 7180: QA followup

Ergonomic improvements:
- Remove the green color the selected record.
- Use fieldset.rows (and legend).
- Use the required css class for quantity inputs.
- Replace "budget" with "fund".
- fix the "undefined" string
- Add a "show MARC" link
- replace "no_match" with a text.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 7180: (follow-up) ensure that the default quantity is 1

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 7180: (follow-up) fix minor issues

- Fixed some labels from Budget to Fund
- Added the system preference to sysprefs.sql
- Fixed some untranslatable Javascript strings

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 7180: (follow-up) change syspref description

- the blank line is now useless
- add an example for the syspref value

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 7180: make neworderempty code use getAuthValueDropbox.

The js function fetchSortDropbox has been deleted in previous patch.
The new function is getAuthValueDropbox.

Test plan:
- link authorized values to some funds
- open an existing order and verify value are correctly filled in the
  sort1 and sort2 values
- create a new order and verify behavior is the same as before

Note: This patch generates 2 ajax queries (max) if the budget is linked
to 2 av categories for sort1 and sort2. This could be improved using a
template plugin for values display on load.

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 7180: (follow-up) update license version

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 7180: QA followup

- fix unit tests (use a transaction).
- add 3 tabs on the page in order to be more understandable.
- fix a warn in logs

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 7180: (follow-up) correct minor language issues

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 7180: (follow-up) restore the "Add order" link

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 7180: (follow-up) remove useless rrp variable

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 7180: (followup) fix case where discount was divided by 100 twice.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 7180: (follow-up) remove disused script fetch_sort_dropbox.pl

Test plan:
  git grep fetch_sort_dropbox
should return no result.

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 7180: (follow-up) fix various issues

* fix calculation of discount
* add CSS for unselected rows
* fix Javascript error
* correct capitalization
* use “Statistic” instead of “Planning value”
* improve description of system preference

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 7180: (follow-up) fix various issues

1/ showmarc.pl takes the importid for staged files.
2/ small note to indicate that the vendor's discount will be used if no
discount is filled.

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 7180: (follow-up) reset statistic values on reloading the page

On the "Default accounting details", if a dropdown list was created for
a statistic value, on reloading the page it still exist. It should not
given the fund value is reset.

The CGIsort variable is useless and can be remove: the dropdown list
is generated using the ajax call.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 7180: (follow-up) use "MARC record" instead of "marcrecord"

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

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