View | Details | Raw Unified | Return to bug 15184
Collapse All | Expand All

(-)a/Koha/Acquisition/Order.pm (-1 / +61 lines)
Lines 22-30 use Carp qw( croak ); Link Here
22
use Koha::Acquisition::Baskets;
22
use Koha::Acquisition::Baskets;
23
use Koha::Acquisition::Funds;
23
use Koha::Acquisition::Funds;
24
use Koha::Acquisition::Invoices;
24
use Koha::Acquisition::Invoices;
25
use Koha::Subscriptions;
26
use Koha::Database;
25
use Koha::Database;
27
use Koha::DateUtils qw( dt_from_string output_pref );
26
use Koha::DateUtils qw( dt_from_string output_pref );
27
use Koha::Items;
28
use Koha::Subscriptions;
28
29
29
use base qw(Koha::Object);
30
use base qw(Koha::Object);
30
31
Lines 167-172 sub subscription { Link Here
167
    return Koha::Subscription->_new_from_dbic( $subscription_rs );
168
    return Koha::Subscription->_new_from_dbic( $subscription_rs );
168
}
169
}
169
170
171
sub items {
172
    my ( $self )  = @_;
173
    # aqorders_items is not a join table
174
    # There is no FK on items (may have been deleted)
175
    my $items_rs = $self->_result->aqorders_items;
176
    my @itemnumbers = $items_rs->get_column( 'itemnumber' )->all;
177
    return Koha::Items->search({ itemnumber => \@itemnumbers });
178
}
179
180
sub duplicate_to {
181
    my ( $self, $basket, $default_values ) = @_;
182
    my $new_order;
183
    $default_values //= {};
184
    Koha::Database->schema->txn_do(
185
        sub {
186
            my $order_info = $self->unblessed;
187
            undef $order_info->{ordernumber};
188
            for my $field (
189
                qw(
190
                ordernumber
191
                received_on
192
                datereceived
193
                datecancellationprinted
194
                cancellationreason
195
                purchaseordernumber
196
                claims_count
197
                claimed_date
198
                parent_ordernumber
199
                )
200
              )
201
            {
202
                undef $order_info->{$field};
203
            }
204
            $order_info->{placed_on}        = dt_from_string;
205
            $order_info->{entrydate}        = dt_from_string;
206
            $order_info->{orderstatus}      = 'new';
207
            $order_info->{quantityreceived} = 0;
208
            while ( my ( $field, $value ) = each %$default_values ) {
209
                $order_info->{$field} = $value;
210
            }
211
212
            # FIXME $order_info->{created_by} = logged_in_user?
213
            $order_info->{basketno} = $basket->basketno;
214
215
            $new_order = Koha::Acquisition::Order->new($order_info)->store;
216
            my $items = $self->items;
217
            while ( my ($item) = $items->next ) {
218
                my $item_info = $item->unblessed;
219
                undef $item_info->{itemnumber};
220
                undef $item_info->{barcode};
221
                my $new_item = Koha::Item->new($item_info)->store;
222
                $new_order->add_item( $new_item->itemnumber );
223
            }
224
        }
225
    );
226
    return $new_order;
227
}
228
229
170
=head2 Internal methods
230
=head2 Internal methods
171
231
172
=head3 _type
232
=head3 _type
(-)a/acqui/duplicate_orders.pl (+177 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2018 Koha Development Team
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use CGI qw ( -utf8 );
23
24
use C4::Auth;
25
use C4::Output;
26
use C4::Acquisition qw(GetHistory);
27
use C4::Budgets qw(GetBudgetPeriods GetBudgetHierarchy CanUserUseBudget);
28
use Koha::Acquisition::Baskets;
29
use Koha::Acquisition::Currencies;
30
use Koha::Acquisition::Orders;
31
use Koha::DateUtils qw(dt_from_string output_pref);
32
33
my $input    = new CGI;
34
my $basketno = $input->param('basketno');
35
my $op       = $input->param('op') || 'search';    # search, select, batch_edit
36
37
my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user(
38
    {
39
        template_name   => "acqui/duplicate_orders.tt",
40
        query           => $input,
41
        type            => "intranet",
42
        authnotrequired => 0,
43
        flagsrequired   => { acquisition => 'order_manage' },
44
    }
45
);
46
47
my $basket = Koha::Acquisition::Baskets->find($basketno);
48
49
output_and_exit( $input, $cookie, $template, 'unknown_basket' )
50
  unless $basket;
51
52
my $vendor = $basket->bookseller;
53
my $patron = Koha::Patrons->find($loggedinuser)->unblessed;
54
55
my $filters = {
56
    basket                  => scalar $input->param('basket'),
57
    title                   => scalar $input->param('title'),
58
    author                  => scalar $input->param('author'),
59
    isbn                    => scalar $input->param('isbn'),
60
    name                    => scalar $input->param('name'),
61
    ean                     => scalar $input->param('ean'),
62
    basketgroupname         => scalar $input->param('basketgroupname'),
63
    booksellerinvoicenumber => scalar $input->param('booksellerinvoicenumber'),
64
    budget                  => scalar $input->param('budget'),
65
    orderstatus             => scalar $input->param('orderstatus'),
66
    ordernumber             => scalar $input->param('ordernumber'),
67
    search_children_too     => scalar $input->param('search_children_too'),
68
    created_by              => scalar $input->multi_param('created_by'),
69
};
70
my $from_placed_on =
71
  eval { dt_from_string( scalar $input->param('from') ) } || dt_from_string;
72
my $to_placed_on =
73
  eval { dt_from_string( scalar $input->param('to') )   } || dt_from_string;
74
75
unless ( $input->param('from') ) {
76
    # Fill the form with year-1
77
    $from_placed_on->subtract( years => 1 );
78
}
79
$filters->{from_placed_on} =
80
  output_pref( { dt => $from_placed_on, dateformat => 'iso', dateonly => 1 } ),
81
  $filters->{to_placed_on} =
82
  output_pref( { dt => $to_placed_on, dateformat => 'iso', dateonly => 1 } ),
83
84
  my ( @result_order_loop, @selected_order_loop );
85
my @ordernumbers = split ',', scalar $input->param('ordernumbers') || '';
86
if ( $op eq 'select' ) {
87
    @result_order_loop = map {
88
        my $order = $_;
89
        ( grep { /^$order->{ordernumber}$/ } @ordernumbers ) ? () : $order
90
    } @{ C4::Acquisition::GetHistory(%$filters) };
91
92
    @selected_order_loop =
93
      scalar @ordernumbers
94
      ? @{ C4::Acquisition::GetHistory( ordernumbers => \@ordernumbers ) }
95
      : ();
96
}
97
elsif ( $op eq 'batch_edit' ) {
98
    @ordernumbers = $input->multi_param('ordernumber');
99
100
    # build budget list
101
    my $budget_loop       = [];
102
    my $budgets_hierarchy = GetBudgetHierarchy;
103
    foreach my $r ( @{$budgets_hierarchy} ) {
104
        next
105
          unless ( C4::Budgets::CanUserUseBudget( $patron, $r, $userflags ) );
106
        if ( !defined $r->{budget_amount} || $r->{budget_amount} == 0 ) {
107
            next;
108
        }
109
        push @{$budget_loop},
110
          {
111
            b_id            => $r->{budget_id},
112
            b_txt           => $r->{budget_name},
113
            b_code          => $r->{budget_code},
114
            b_sort1_authcat => $r->{'sort1_authcat'},
115
            b_sort2_authcat => $r->{'sort2_authcat'},
116
            b_active        => $r->{budget_period_active},
117
          };
118
    }
119
    @{$budget_loop} =
120
      sort { uc( $a->{b_txt} ) cmp uc( $b->{b_txt} ) } @{$budget_loop};
121
122
    my @currencies = Koha::Acquisition::Currencies->search;
123
    $template->param(
124
        currencies  => \@currencies,
125
        budget_loop => $budget_loop,
126
    );
127
}
128
elsif ( $op eq 'do_duplicate' ) {
129
    my @fields_to_copy = $input->multi_param('copy_existing_value');
130
131
    my $default_values;
132
    for my $field (
133
        qw(currency budget_id order_internalnote order_vendornote sort1 sort2 ))
134
    {
135
        next if grep { /^$field$/ } @fields_to_copy;
136
        $default_values->{$field} = $input->param("all_$field");
137
    }
138
139
    @ordernumbers = $input->multi_param('ordernumber');
140
    my @new_ordernumbers;
141
    for my $ordernumber (@ordernumbers) {
142
        my $original_order = Koha::Acquisition::Orders->find($ordernumber);
143
        next unless $original_order;
144
        my $new_order =
145
          $original_order->duplicate_to( $basket, $default_values );
146
        push @new_ordernumbers, $new_order->ordernumber;
147
    }
148
149
    my $new_orders =
150
      C4::Acquisition::GetHistory( ordernumbers => \@new_ordernumbers );
151
    $template->param( new_orders => $new_orders );
152
    $op = 'duplication_done';
153
}
154
155
my $budgetperiods = C4::Budgets::GetBudgetPeriods;
156
my $bp_loop       = $budgetperiods;
157
for my $bp ( @{$budgetperiods} ) {
158
    my $hierarchy = C4::Budgets::GetBudgetHierarchy( $$bp{budget_period_id} );
159
    for my $budget ( @{$hierarchy} ) {
160
        $$budget{budget_display_name} =
161
          sprintf( "%s", ">" x $$budget{depth} . $$budget{budget_name} );
162
    }
163
    $$bp{hierarchy} = $hierarchy;
164
}
165
166
$template->param(
167
    basket              => $basket,
168
    vendor              => $vendor,
169
    filters             => $filters,
170
    result_order_loop   => \@result_order_loop,
171
    selected_order_loop => \@selected_order_loop,
172
    bp_loop             => $bp_loop,
173
    ordernumbers        => \@ordernumbers,
174
    op                  => $op,
175
);
176
177
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-add-to-basket.inc (+1 lines)
Lines 15-20 Link Here
15
        <li><a href="/cgi-bin/koha/acqui/newordersuggestion.pl?booksellerid=[% booksellerid %]&amp;basketno=[% basketno %]">From a suggestion</a></li>
15
        <li><a href="/cgi-bin/koha/acqui/newordersuggestion.pl?booksellerid=[% booksellerid %]&amp;basketno=[% basketno %]">From a suggestion</a></li>
16
        <li><a href="/cgi-bin/koha/acqui/newordersubscription.pl?booksellerid=[% booksellerid %]&amp;basketno=[% basketno %]">From a subscription</a></li>
16
        <li><a href="/cgi-bin/koha/acqui/newordersubscription.pl?booksellerid=[% booksellerid %]&amp;basketno=[% basketno %]">From a subscription</a></li>
17
        <li><a href="/cgi-bin/koha/acqui/neworderempty.pl?booksellerid=[% booksellerid %]&amp;basketno=[% basketno %]">From a new (empty) record</a></li>
17
        <li><a href="/cgi-bin/koha/acqui/neworderempty.pl?booksellerid=[% booksellerid %]&amp;basketno=[% basketno %]">From a new (empty) record</a></li>
18
        <li><a href="/cgi-bin/koha/acqui/duplicate_orders.pl?basketno=[% basketno %]">From existing orders (copy)</a></li>
18
        <li><a href="/cgi-bin/koha/acqui/z3950_search.pl?booksellerid=[% booksellerid %]&amp;basketno=[% basketno %]">From an external source</a></li>
19
        <li><a href="/cgi-bin/koha/acqui/z3950_search.pl?booksellerid=[% booksellerid %]&amp;basketno=[% basketno %]">From an external source</a></li>
19
        <li><a href="/cgi-bin/koha/acqui/addorderiso2709.pl?booksellerid=[% booksellerid %]&amp;basketno=[% basketno %]"> From a staged file</a></li>
20
        <li><a href="/cgi-bin/koha/acqui/addorderiso2709.pl?booksellerid=[% booksellerid %]&amp;basketno=[% basketno %]"> From a staged file</a></li>
20
        [% IF ( CAN_user_circulate ) %]<li><a href="/cgi-bin/koha/circ/reserveratios.pl?booksellerid=[% booksellerid %]&amp;basketno=[% basketno %]">From titles with highest hold ratios</a></li>[% END %]
21
        [% IF ( CAN_user_circulate ) %]<li><a href="/cgi-bin/koha/circ/reserveratios.pl?booksellerid=[% booksellerid %]&amp;basketno=[% basketno %]">From titles with highest hold ratios</a></li>[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/blocking_errors.inc (+2 lines)
Lines 7-12 Link Here
7
        <div class="dialog message">This bibliographic record does not exist.</div>
7
        <div class="dialog message">This bibliographic record does not exist.</div>
8
    [% CASE 'unknown_item' %]
8
    [% CASE 'unknown_item' %]
9
        <div class="dialog message">This item does not exist.</div>
9
        <div class="dialog message">This item does not exist.</div>
10
    [% CASE 'unknown_basket' %]
11
        <div class="dialog message">This basket does not exist.</div>
10
    [% CASE %][% blocking_error %]
12
    [% CASE %][% blocking_error %]
11
    [% END %]
13
    [% END %]
12
14
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/filter-orders.inc (+1 lines)
Lines 1-4 Link Here
1
[% USE Koha %]
1
[% USE Koha %]
2
[% USE KohaDates %]
2
<ol>
3
<ol>
3
    <li><label for="title">Title: </label> <input type="text" name="title" id="title" value="[% filters.title %]" /></li>
4
    <li><label for="title">Title: </label> <input type="text" name="title" id="title" value="[% filters.title %]" /></li>
4
    <li><label for="author">Author: </label> <input type="text" name="author" id="author" value="[% filters.author %]" /></li>
5
    <li><label for="author">Author: </label> <input type="text" name="author" id="author" value="[% filters.author %]" /></li>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/duplicate_orders.tt (-1 / +428 lines)
Line 0 Link Here
0
- 
1
[% USE Asset %]
2
[% USE Koha %]
3
[% USE KohaDates %]
4
[% SET footerjs = 1 %]
5
[% INCLUDE 'doc-head-open.inc' %]
6
<title>Koha &rsaquo; Acquisitions &rsaquo;
7
[% UNLESS blocking_error %]
8
Basket [% basket.basketno %] &rsaquo; Duplicate existing orders
9
[% END %]
10
</title>
11
[% INCLUDE 'doc-head-close.inc' %]
12
[% Asset.css("css/datatables.css") %]
13
<style type="text/css">
14
    .picked_to_duplicate > td { background-color: #bcdb89 !important; }
15
</style>
16
</head>
17
18
<body id="acq_duplicate_orders" class="acq">
19
20
[% INCLUDE 'header.inc' %]
21
[% INCLUDE 'acquisitions-search.inc' %]
22
23
<div id="breadcrumbs">
24
    <a href="/cgi-bin/koha/mainpage.pl">Home</a>
25
    &rsaquo; <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a>
26
    [% UNLESS blocking_error %]
27
    &rsaquo; <a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% vendor.id %]">[% vendor.name %]</a>
28
    &rsaquo; <a href="/cgi-bin/koha/acqui/basket.pl?basketno=[% basket.basketno %]">Basket [% basket.basketno %]</a>
29
    &rsaquo; Duplicate existing orders
30
    [% END %]
31
</div>
32
33
<div class="main container-fluid">
34
    <div class="row">
35
        <div class="col-sm-10 col-sm-push-2">
36
            <main>
37
38
[% INCLUDE 'blocking_errors.inc' %]
39
40
<h2>Duplicate existing orders</h2>
41
42
[% IF op == 'search' || op == 'select' %]
43
<form action="/cgi-bin/koha/acqui/duplicate_orders.pl" method="post">
44
    <fieldset class="rows">
45
        <legend>
46
            [% IF op == 'search' %]
47
                <span>Search orders</span>
48
            [% ELSE %]
49
                <span>Refine search</span>
50
            [% END %]
51
            <span class="toggle_orders_filters" id="show_orders_filters"><a href="#">[+]</a></span>
52
            <span class="toggle_orders_filters" id="hide_orders_filters"><a href="#">[-]</a></span>
53
        </legend>
54
        <div id="orders_filters">
55
            [% INCLUDE 'filter-orders.inc' %]
56
            <input type="hidden" name="op" value="select" />
57
            <input type="hidden" name="basketno" value="[% basket.basketno %]" />
58
59
            <input type="hidden" name="ordernumbers" value="[% ordernumbers.join(',') %]" />
60
            <fieldset class="action"><input type="submit" value="Search" /></fieldset>
61
        </div>
62
    </fieldset>
63
</form>
64
[% END %]
65
66
[% BLOCK display_order_line %]
67
    [% IF selected %]
68
    <tr class="picked_to_duplicate" data-ordernumber="[% order.ordernumber %]">
69
    [% ELSE %]
70
    <tr data-ordernumber="[% order.ordernumber %]">
71
    [% END %]
72
        <td>
73
            [% IF selected %]
74
                <input type="checkbox" name="ordernumber" value="[% order.ordernumber %]" checked="checked" />
75
            [% ELSE %]
76
                <input type="checkbox" name="ordernumber" value="[% order.ordernumber %]" />
77
            [% END %]
78
            [% order.ordernumber %]
79
            [% IF order.ordernumber != order.parent_ordernumber %]([% order.parent_ordernumber %])[% END %]
80
        </td>
81
        <td>
82
            [% SWITCH order.orderstatus %]
83
                [% CASE 'new' %]New
84
                [% CASE 'ordered' %]Ordered
85
                [% CASE 'partial' %]Partially received
86
                [% CASE 'complete' %]Received
87
                [% CASE 'cancelled' %]Cancelled
88
            [% END %]
89
        </td>
90
        <td>[% order.basketname %] (<a href="basket.pl?basketno=[% order.basketno %]">[% order.basketno %]</a>)</td>
91
        <td>[% order.authorisedbyname %]</td>
92
        <td>
93
            [% IF ( order.basketgroupid ) %]
94
                [% order.groupname %] (<a href="basketgroup.pl?op=add&booksellerid=[% order.id %]&basketgroupid=[% order.basketgroupid %]">[% order.basketgroupid %]</a>)
95
            [% ELSE %]
96
                &nbsp;
97
            [% END %]
98
        </td>
99
        <td>[% IF ( order.invoicenumber ) %]
100
                <a href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% order.invoiceid %]">[% order.invoicenumber %]</a>
101
            [% ELSE %]
102
                &nbsp;
103
            [% END %]
104
        </td>
105
        <td>
106
            <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% order.biblionumber %]">[% order.title |html %]</a>
107
            <br />[% order.author %] <br /> [% order.isbn %]
108
        </td>
109
        <td><a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% order.id %]">[% order.name %]</a></td>
110
        <td><span title="[% order.creationdate %]">[% order.creationdate | $KohaDates %]</span></td>
111
        <td>
112
            [% IF order.datereceived %]
113
                <span title="[% order.datereceived %]">[% order.datereceived | $KohaDates %]</span>
114
            [% ELSE %]
115
                <span title="0000-00-00"></span>
116
            [% END %]
117
        </td>
118
        <td>[% order.quantityreceived %]</td>
119
        <td>[% order.quantity %]</td>
120
        <td>[% order.ecost %]</td>
121
        <td>[% order.budget_name %]</td>
122
    </tr>
123
[% END %]
124
125
126
[% IF op == 'select' && ( result_order_loop || selected_order_loop ) %]
127
    <div id="xxx">
128
        <form method="post" action="/cgi-bin/koha/acqui/duplicate_orders.pl">
129
        <table id="table_orders">
130
            <caption>
131
                <span class="actions"><a href="#" id="select_all"><i class="fa fa-check"></i> Select all</a>
132
                | <a href="#" id="clear_all"><i class="fa fa-remove"></i> Clear all</a></span>
133
            </caption>
134
135
            <thead>
136
                    <tr>
137
                    <th>Order line (parent)</th>
138
                    <th>Status</th>
139
                    <th>Basket</th>
140
                    <th>Basket creator</th>
141
                    <th>Basket group</th>
142
                    <th>Invoice number</th>
143
                    <th class="anti-the">Summary</th>
144
                    <th>Vendor</th>
145
                    <th class="title-string">Placed on</th>
146
                    <th class="title-string">Received on</th>
147
                    <th>Quantity received</th>
148
                    <th>Pending order</th>
149
                    <th>Unit cost</th>
150
                    <th>Fund</th>
151
                </tr>
152
            </thead>
153
            <tfoot>
154
            [% FOREACH order IN selected_order_loop %]
155
                [% INCLUDE display_order_line selected => 1 %]
156
            [% END %]
157
            </tfoot>
158
            <tbody>
159
            [% FOREACH order IN result_order_loop %]
160
                [% INCLUDE display_order_line %]
161
            [% END %]
162
            </tbody>
163
        </table>
164
        <fieldset class="action">
165
            <input type="hidden" name="op" value="batch_edit" />
166
            <input type="hidden" name="basketno" value="[% basket.basketno %]" />
167
            <button type="submit" class="btn btn-default go_to_batch_edit">Next <i class="fa fa-fw fa-arrow-right"></i></button>
168
        </fieldset>
169
        </form>
170
    </div>
171
172
[% ELSIF op == "batch_edit" %]
173
174
<form method="post" action="/cgi-bin/koha/acqui/duplicate_orders.pl" id="batch_edit_form">
175
    <div id="accounting_details">
176
      <p>Duplicate all the orders with the following accounting details:</p>
177
      <fieldset class="rows" style="float:none;">
178
          <legend>Accounting details</legend>
179
          <ol>
180
              <li>
181
                  <!-- origquantityrec only here for javascript compatibility (additem.js needs it, useless here, useful when receiveing an order -->
182
                  <input id="origquantityrec" readonly="readonly" type="hidden" name="origquantityrec" value="1" />
183
              </li>
184
              <li>
185
                      <li>
186
                          <label for="all_currency">Currency:</label>
187
                          <input type="checkbox" name="copy_existing_value" value="currency" title="Copy existing value" />
188
                          <select name="all_currency" id="all_currency">
189
                          [% FOREACH currency IN currencies %]
190
                              [% IF currency.currency == vendor.listprice %]
191
                                  <option value="[% currency.currency %]" selected="selected">[% currency.currency %]</option>
192
                              [% ELSIF not currency.archived %]
193
                                  <option value="[% currency.currency %]">[% currency.currency %]</option>
194
                              [% END %]
195
                          [% END %]
196
                          </select>
197
                          <span class="hint" id="hint_currency">The original currency value will be copied</span>
198
                      </li>
199
                      <li>
200
                          <label for="all_budget_id">Fund: </label>
201
                          <input type="checkbox" name="copy_existing_value" value="budget_id" title="Copy existing value" />
202
                          <select id="all_budget_id" size="1" name="all_budget_id">
203
                            <option value="">Select a fund</option>
204
                          [% FOREACH budget_loo IN budget_loop %]
205
                              [% IF ( budget_loo.b_active ) %]<option value="[% budget_loo.b_id %]" data-sort1-authcat="[% budget_loo.b_sort1_authcat %]" data-sort2-authcat="[% budget_loo.b_sort2_authcat %]">[% budget_loo.b_txt %]</option>
206
                              [% ELSE %]<option value="[% budget_loo.b_id %]" class="b_inactive" data-sort1-authcat="[% budget_loo.b_sort1_authcat %]" data-sort2-authcat="[% budget_loo.b_sort2_authcat %]">[% budget_loo.b_txt %] (inactive)</option>
207
                              [% END %]
208
                          [% END %]
209
                          </select>
210
                          <label for="all_showallbudgets" style="float:none;width:auto;">&nbsp;Show inactive:</label>
211
                          <input type="checkbox" id="all_showallbudgets" />
212
                          <span class="hint" id="hint_budget_id">The original fund will be used</span>
213
                      </li>
214
              </li>
215
              <li>
216
                  <label for="all_order_internalnote">Internal note: </label>
217
                  <input type="checkbox" name="copy_existing_value" value="order_internalnote" title="Copy existing value" />
218
                  <textarea id="all_order_internalnote" cols="30" rows="3" name="all_order_internalnote"></textarea>
219
                  <span class="hint" id="hint_order_internalnote">The original internal note will be used</span>
220
              </li>
221
              <li>
222
                  <label for="all_order_vendornote">Vendor note: </label>
223
                  <input type="checkbox" name="copy_existing_value" value="order_vendornote" title="Copy existing value" />
224
                  <textarea id="all_order_vendornote" cols="30" rows="3" name="all_order_vendornote"></textarea>
225
                  <span class="hint" id="hint_order_vendornote">The original vendor note will be used</span>
226
              </li>
227
              <li>
228
                  <div class="hint">The 2 following fields are available for your own usage. They can be useful for statistical purposes</div>
229
                  <label for="all_sort1">Statistic 1: </label>
230
                  <input type="checkbox" name="copy_existing_value" value="sort1" title="Copy existing value" />
231
                  <input type="text" id="all_sort1" size="20" name="all_sort1" value="" />
232
                  <span class="hint" id="hint_sort1">The original statistic 1 will be used</span>
233
234
              </li>
235
              <li>
236
                  <label for="all_sort2">Statistic 2: </label>
237
                  <input type="checkbox" name="copy_existing_value" value="sort2" title="Copy existing value" />
238
                  <input type="text" id="all_sort2" size="20" name="all_sort2" value="" />
239
                  <span class="hint" id="hint_sort2">The original statistic 2 will be used</span>
240
              </li>
241
          </ol>
242
      </fieldset>
243
    </div>
244
245
    <fieldset class="action">
246
        [% FOREACH ordernumber IN ordernumbers %]
247
            <input type="hidden" name="ordernumber" value="[% ordernumber %]" />
248
        [% END %]
249
        <input type="hidden" name="op" value="do_duplicate" />
250
        <input type="hidden" name="basketno" value="[% basket.basketno %]" />
251
        <button type="submit" class="btn btn-default">Duplicate orders</button>
252
        <a class="cancel" href="/cgi-bin/koha/acqui/duplicate_orders.pl?basketno=[% basket.basketno %]">Cancel</a>
253
    </fieldset>
254
</form>
255
256
[% ELSIF op == 'duplication_done' %]
257
    [% IF new_orders %]
258
        <table id="table_neworders">
259
            <thead>
260
                <tr>
261
                    <th>Order line</th>
262
                    <th>Status</th>
263
                    <th>Basket</th>
264
                    <th>Basket creator</th>
265
                    <th>Basket group</th>
266
                    <th>Invoice number</th>
267
                    <th class="anti-the">Summary</th>
268
                    <th>Vendor</th>
269
                    <th class="title-string">Placed on</th>
270
                    <th class="title-string">Received on</th>
271
                    <th>Quantity received</th>
272
                    <th>Pending order</th>
273
                    <th>Unit cost</th>
274
                    <th>Fund</th>
275
                </tr>
276
            </thead>
277
            <tbody>
278
            [% FOREACH order IN new_orders %]
279
                [% INCLUDE display_order_line %]
280
            [% END %]
281
            </tbody>
282
        </table>
283
        <a class="btn btn-default" href="/cgi-bin/koha/acqui/basket.pl?basketno=[% basket.basketno %]"><i class="fa fa-fw fa-arrow-left"></i> Return to the basket</a
284
    [% ELSE %]
285
        <span>No order has been duplicated. Maybe something wrong happened?</span>
286
    [% END %]
287
[% END %]
288
289
</main>
290
</div> <!-- /.col-sm-10.col-sm-push-2 -->
291
292
<div class="col-sm-2 col-sm-pull-10">
293
    <aside>
294
        [% INCLUDE 'acquisitions-menu.inc' %]
295
    </aside>
296
</div> <!-- /.col-sm-2.col-sm-pull-10 -->
297
</div>
298
299
[% MACRO jsinclude BLOCK %]
300
    [% Asset.js("js/acquisitions-menu.js") %]
301
    [% INCLUDE 'calendar.inc' %]
302
    [% INCLUDE 'datatables.inc' %]
303
    [% INCLUDE 'columns_settings.inc' %]
304
    [% Asset.js("js/autocomplete/patrons.js") %]
305
    [% Asset.js("js/acq.js") %]
306
    [% Asset.js("js/funds_sorts.js") %]
307
    [% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") %]
308
    <script>
309
        function update_ordernumber_list(){
310
            var ordernumbers = [];
311
            $("input[name='ordernumber']").filter(":checked").each(function(){
312
                ordernumbers.push($(this).val());
313
            });
314
            $("input[name='ordernumbers']").val(ordernumbers.join(','));
315
        }
316
317
        var MSG_REMOVE_PATRON = _("Remove");
318
        var MSG_NO_ITEM_SELECTED = _("Nothing is selected.");
319
        var MSG_NO_FUND_SELECTED = _("No fund selected.");
320
        $(document).ready(function() {
321
            $('.hint').hide();
322
            var columns_settings;// = [% ColumnsSettings.GetColumns( 'acqui', 'histsearch', 'histsearcht', 'json' ) %];
323
            KohaTable("table_orders", {
324
                "aoColumnDefs": [
325
                    { "sType": "anti-the", "aTargets" : [ "anti-the" ] },
326
                    { "sType": "title-string", "aTargets" : [ "title-string" ] }
327
                ],
328
                "bPaginate": false
329
            }, columns_settings );
330
331
            [% IF op == 'search' OR op == 'select' %]
332
                patron_autocomplete({
333
                    patron_container: $("#basket_creators"),
334
                    input_autocomplete: $("#find_patron"),
335
                    patron_input_name: 'created_by',
336
                    field_to_retrieve: 'borrowernumber'
337
                });
338
            [% END %]
339
340
            $("#show_orders_filters, #hide_orders_filters").on('click', function(e) {
341
                e.preventDefault();
342
                $('#orders_filters').toggle();
343
                $('.toggle_orders_filters').toggle();
344
            });
345
            [% IF op == 'search' OR op == 'select' AND NOT result_order_loop %]
346
                $("#show_orders_filters").hide();
347
                $("#orders_filters").show();
348
            [% ELSE %]
349
                $("#hide_orders_filters").hide();
350
                $("#orders_filters").hide();
351
            [% END %]
352
353
            $("input[name='ordernumber']").on("change", function(){
354
                if ( $(this).is(':checked') ) {
355
                    $(this).parents("tr").addClass("picked_to_duplicate");
356
                } else {
357
                    $(this).parents("tr").removeClass("picked_to_duplicate");
358
                }
359
            }).on("click", function(e){
360
                update_ordernumber_list();
361
            });
362
363
            $("#select_all").on("click",function(e){
364
                e.preventDefault();
365
                selectAll();
366
                update_ordernumber_list();
367
            });
368
369
            $("#clear_all").on("click",function(e){
370
                e.preventDefault();
371
                clearAll();
372
                update_ordernumber_list();
373
            });
374
            function selectAll () {
375
                $("#table_orders").checkCheckboxes();
376
                $("#table_orders").find("input[type='checkbox'][name='ordernumber']").each(function(){
377
                    $(this).change();
378
                } );
379
                return false;
380
            }
381
            function clearAll () {
382
                $("#table_orders").unCheckCheckboxes();
383
                $("#table_orders").find("input[type='checkbox'][name='ordernumber']").each(function(){
384
                    $(this).change();
385
                } );
386
                return false;
387
            }
388
389
            $(".go_to_batch_edit").on("click",function(e){
390
                if ($("input[name='ordernumber']").filter(":checked").length == 0){
391
                    alert(MSG_NO_ITEM_SELECTED);
392
                    e.preventDefault();
393
                }
394
            });
395
396
            $("#batch_edit_form").on("submit", function(e){
397
                var budget_value_will_be_reused = $("input[name='copy_existing_value'][value='budget_id']").is(':checked');
398
                if ( ! budget_value_will_be_reused ) {
399
                    if ($("#all_budget_id").find("option:selected").attr("value") == "" ) {
400
                        alert(MSG_NO_FUND_SELECTED);
401
                        e.preventDefault();
402
                    }
403
                }
404
            });
405
            $("input[name='copy_existing_value']").click(function(){
406
                render_disabled(this);
407
            });
408
409
            $("input[name='copy_existing_value']").each(function(){
410
                render_disabled(this);
411
            });
412
        });
413
        function render_disabled (elt) {
414
            var field = $(elt).val();
415
            var hint_node = $("#hint_" + field);
416
            var input_element = $(elt).parent().find("[name='all_"+field+"']");
417
            if ($(elt).is(":checked")) {
418
                $(input_element).prop('disabled', true);
419
                $(hint_node).show();
420
            } else {
421
                $(input_element).prop('disabled', false);
422
                $(hint_node).hide();
423
            }
424
        }
425
    </script>
426
[% END %]
427
428
[% INCLUDE 'intranet-bottom.inc' %]

Return to bug 15184