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

(-)a/acqui/lateorders.pl (-77 / +10 lines)
Lines 22-58 lateorders.pl Link Here
22
22
23
=head1 DESCRIPTION
23
=head1 DESCRIPTION
24
24
25
this script shows late orders for a specific supplier, branch and delay
25
This script shows late orders
26
given on input arg.
27
28
=head1 CGI PARAMETERS
29
30
=over 4
31
32
=item booksellerid
33
To know on which supplier this script have to display late order.
34
35
=item delay
36
To know the time boundary. Default value is 30 days.
37
38
=item branch
39
To know on which branch this script have to display late order.
40
41
=back
42
26
43
=cut
27
=cut
44
28
45
use Modern::Perl;
29
use Modern::Perl;
46
use CGI        qw ( -utf8 );
30
use CGI         qw ( -utf8 );
47
use C4::Auth   qw( get_template_and_user );
31
use C4::Auth    qw( get_template_and_user );
48
use C4::Output qw( output_html_with_http_headers );
32
use C4::Output  qw( output_html_with_http_headers );
49
use C4::Context;
33
use C4::Letters qw( SendAlerts GetLetters );
50
use C4::Letters     qw( SendAlerts GetLetters );
51
use Koha::DateUtils qw( dt_from_string );
52
use Koha::Acquisition::Orders;
34
use Koha::Acquisition::Orders;
53
use Koha::CsvProfiles;
35
use Koha::CsvProfiles;
54
36
55
my $input = CGI->new;
37
my $input = CGI->new;
38
56
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
39
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
57
    {
40
    {
58
        template_name => "acqui/lateorders.tt",
41
        template_name => "acqui/lateorders.tt",
Lines 62-87 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
62
    }
45
    }
63
);
46
);
64
47
65
my $booksellerid = $input->param('booksellerid');
48
my $op = $input->param('op');
66
my $delay        = $input->param('delay') // 0;
67
68
# Get the "date from" param if !defined is today
69
my $estimateddeliverydatefrom = $input->param('estimateddeliverydatefrom');
70
my $estimateddeliverydateto   = $input->param('estimateddeliverydateto');
71
72
# Get the "date to" param. If it is not defined and $delay is not defined too, it is the today's date.
73
$estimateddeliverydateto ||=
74
    ( not defined $delay and not defined $estimateddeliverydatefrom )
75
    ? dt_from_string()
76
    : undef;
77
78
my $branch = $input->param('branch');
79
my $op     = $input->param('op');
80
81
my @errors = ();
82
if ( $delay and not $delay =~ /^\d{1,3}$/ ) {
83
    push @errors, { delay_digits => 1, bad_delay => $delay };
84
}
85
49
86
if ( $op and $op eq "cud-send_alert" ) {
50
if ( $op and $op eq "cud-send_alert" ) {
87
    my @ordernums = $input->multi_param("ordernumber");
51
    my @ordernums = $input->multi_param("ordernumber");
Lines 104-145 if ( $op and $op eq "cud-send_alert" ) { Link Here
104
    }
68
    }
105
}
69
}
106
70
107
my @lateorders = Koha::Acquisition::Orders->filter_by_lates(
108
    {
109
        delay => $delay,
110
        (
111
            $estimateddeliverydatefrom
112
            ? ( estimated_from => dt_from_string( $estimateddeliverydatefrom, 'iso' ) )
113
            : ()
114
        ),
115
        (
116
            $estimateddeliverydateto
117
            ? ( estimated_to => dt_from_string( $estimateddeliverydateto, 'iso' ) )
118
            : ()
119
        )
120
    },
121
)->as_list;
122
123
my $booksellers = Koha::Acquisition::Booksellers->search(
124
    {
125
        id => { -in => [ map { $_->basket->booksellerid } @lateorders ] },
126
    }
127
);
128
129
@lateorders = grep { $_->basket->booksellerid eq $booksellerid } @lateorders if $booksellerid;
130
131
my $letters = GetLetters( { module => "claimacquisition" } );
71
my $letters = GetLetters( { module => "claimacquisition" } );
132
72
133
$template->param( ERROR_LOOP => \@errors ) if (@errors);
134
$template->param(
73
$template->param(
135
    lateorders                => \@lateorders,
74
    letters      => $letters,
136
    booksellers               => $booksellers,
75
    csv_profiles => Koha::CsvProfiles->search( { type => 'sql', used_for => 'late_orders' } ),
137
    bookseller_filter         => ( $booksellerid ? $booksellers->find($booksellerid) : undef ),
138
    delay                     => $delay,
139
    letters                   => $letters,
140
    estimateddeliverydatefrom => $estimateddeliverydatefrom,
141
    estimateddeliverydateto   => $estimateddeliverydateto,
142
    intranetcolorstylesheet   => C4::Context->preference("intranetcolorstylesheet"),
143
    csv_profiles              => Koha::CsvProfiles->search( { type => 'sql', used_for => 'late_orders' } ),
144
);
76
);
77
145
output_html_with_http_headers $input, $cookie, $template->output;
78
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt (-255 / +377 lines)
Lines 5-10 Link Here
5
[% USE Branches %]
5
[% USE Branches %]
6
[% USE TablesSettings %]
6
[% USE TablesSettings %]
7
[% USE Price %]
7
[% USE Price %]
8
[% USE To %]
8
[% SET footerjs = 1 %]
9
[% SET footerjs = 1 %]
9
[% PROCESS 'i18n.inc' %]
10
[% PROCESS 'i18n.inc' %]
10
[% INCLUDE 'doc-head-open.inc' %]
11
[% INCLUDE 'doc-head-open.inc' %]
Lines 53-273 Link Here
53
                    [% IF info_claim %]
54
                    [% IF info_claim %]
54
                        <div class="alert alert-info">Email has been sent.</div>
55
                        <div class="alert alert-info">Email has been sent.</div>
55
                    [% END %]
56
                    [% END %]
56
                    [% IF lateorders.size %]
57
                    <form action="lateorders.pl" name="claim" method="post">
57
                        <form action="lateorders.pl" name="claim" method="post">
58
                        [% INCLUDE 'csrf-token.inc' %]
58
                            [% INCLUDE 'csrf-token.inc' %]
59
                        <input type="hidden" name="op" value="cud-send_alert" />
59
                            <input type="hidden" name="op" value="cud-send_alert" />
60
                        [% IF ( letters ) %]
60
                            <input type="hidden" name="delay" value="[% delay | html %]" />
61
                            <p
61
                            <input type="hidden" name="booksellerid" value="[% bookseller_filter.id | html %]" />
62
                                ><label for="letter_code">Claim using notice: </label
62
                            [% IF ( letters ) %]
63
                                ><select name="letter_code" id="letter_code">
63
                                <p
64
                                    [% FOREACH letter IN letters %]
64
                                    ><label for="letter_code">Claim using notice: </label
65
                                        <option value="[% letter.code | html %]">[% letter.name | html %]</option>
65
                                    ><select name="letter_code" id="letter_code">
66
                                        [% FOREACH letter IN letters %]
67
                                            <option value="[% letter.code | html %]">[% letter.name | html %]</option>
68
                                        [% END %]
69
                                    </select>
70
                                </p>
71
                            [% END %]
72
                            [% SET total = 0 %]
73
                            [% SET total_quantity = 0 %]
74
                            [% IF bookseller_filter %]
75
                                <p
76
                                    ><a id="CheckAll" href="#"><i class="fa fa-check"></i> Check all</a> <a id="CheckNone" href="#"><i class="fa fa-times"></i> Uncheck all</a></p
77
                                >
78
                            [% END %]
79
                            <table id="late_orders">
80
                                <thead>
81
                                    <tr>
82
                                        <th class="no-sort"></th>
83
                                        <th>Order line</th>
84
                                        <th>Order date</th>
85
                                        <th>Estimated delivery date</th>
86
                                        <th>Vendor</th>
87
                                        <th class="anti-the">Information</th>
88
                                        <th>Quantity</th>
89
                                        <th>Total cost</th>
90
                                        <th>Basket</th>
91
                                        <th>Basket date</th>
92
                                        <th>Basket group</th>
93
                                        <th>Library</th>
94
                                        <th>Budget</th>
95
                                        <th>Fund</th>
96
                                        <th>Claims count</th>
97
                                        <th>Claimed date</th>
98
                                        <th>Internal note</th>
99
                                        <th>Vendor note</th>
100
                                        <th>ISBN</th>
101
                                    </tr>
102
                                </thead>
103
                                <tbody>
104
                                    [% FOREACH lateorder IN lateorders %]
105
                                        <tr>
106
                                            <td>
107
                                                <input type="checkbox" value="[% lateorder.ordernumber | html %]" data-booksellerid="[% lateorder.basket.booksellerid | html %]" name="ordernumber" />
108
                                            </td>
109
                                            <td> [% lateorder.ordernumber | $raw %] </td>
110
                                            <td data-order="[% lateorder.basket.closedate | html %]"> [% lateorder.basket.closedate | $KohaDates %] ([% lateorder.basket.late_since_days | html %] days) </td>
111
                                            [% IF lateorder.get_column('estimated_delivery_date') %]
112
                                                [% SET estimated_delivery_date = lateorder.get_column('estimated_delivery_date') %]
113
                                            [% ELSIF lateorder.get_column('calculated_estimated_delivery_date') %]
114
                                                [% SET estimated_delivery_date = lateorder.get_column('calculated_estimated_delivery_date') %]
115
                                            [% END %]
116
                                            <td data-order="[% estimated_delivery_date | html %]">
117
                                                <p class="delivery_date">
118
                                                    <span>[% estimated_delivery_date | $KohaDates %]</span>
119
                                                    [% IF CAN_user_acquisition_order_manage %]
120
                                                        <a
121
                                                            class="edit_delivery_date no-export"
122
                                                            data-ordernumber="[% lateorder.ordernumber | html %]"
123
                                                            data-delivery_date="[% estimated_delivery_date | html %]"
124
                                                            id="delivery_date_[% lateorder.ordernumber | html %]"
125
                                                            href="/cgi-bin/koha/acqui/moddeliverydate.pl?ordernumber=[% lateorder.ordernumber | html %]"
126
                                                            title="Edit delivery date"
127
                                                        >
128
                                                            <i class="fa-solid fa-pencil" aria-hidden="true"></i> Edit
129
                                                        </a>
130
                                                    [% END %]
131
                                                </p>
132
                                            </td>
133
                                            <td> [% lateorder.basket.bookseller.name | html %] ([% lateorder.basket.bookseller.id | html %]) </td>
134
                                            <td>
135
                                                <span class="title">[% INCLUDE 'biblio-title.inc' biblio=lateorder.biblio link=1 %]</span>
136
                                                [% IF ( lateorder.biblio.author ) %]<br /><em>Author:</em> [% lateorder.biblio.author | html %][% END %]
137
                                                [% IF ( lateorder.biblio.biblioitem.publishercode ) %]
138
                                                    <br /><em>Published by:</em> [% lateorder.biblio.biblioitem.publishercode | html %]
139
                                                    [% IF ( lateorder.biblio.biblioitem.publicationyear ) %]
140
                                                        <em> in </em>[% lateorder.biblio.biblioitem.publicationyear | html %]
141
                                                    [% END %]
142
                                                [% END %]
143
                                            </td>
144
                                            <td>
145
                                                [% lateorder.quantity | html %]
146
                                                [% SET total_quantity = total_quantity + lateorder.quantity %]
147
                                            </td>
148
                                            <td>
149
                                                [% SET subtotal = (lateorder.quantity - lateorder.quantityreceived) * lateorder.rrp %]
150
                                                [% SET total = total + subtotal %]
151
                                                [% lateorder.rrp | html %]x[% lateorder.quantity - lateorder.quantityreceived | html %]
152
                                                = [% subtotal | $Price %]
153
                                            </td>
154
                                            <td>
155
                                                [% IF ( CAN_user_acquisition_order_manage ) %]
156
                                                    <a href="basket.pl?basketno=[% lateorder.basketno | uri %]" title="basket">[% lateorder.basket.basketname | html %] ([% lateorder.basketno | html %])</a>
157
                                                [% ELSE %]
158
                                                    [% lateorder.basket.basketname | html %]
159
                                                    ([% lateorder.basketno | html %])
160
                                                [% END %]
161
                                            </td>
162
                                            <td data-order="[% lateorder.basket.creationdate | html %]">[% lateorder.basket.creationdate | $KohaDates %]</td>
163
                                            <td>
164
                                                [% IF ( lateorder.basket.basketgroupid ) %]
165
                                                    [% IF ( CAN_user_acquisition_group_manage ) %]
166
                                                        <a href="basketgroup.pl?op=add&booksellerid=[% lateorder.basket.booksellerid | uri %]&basketgroupid=[% lateorder.basket.basketgroupid | uri %]" title="basketgroup"
167
                                                            >[% lateorder.basket.basket_group.name | html %] ([% lateorder.basket.basketgroupid | html %])</a
168
                                                        >
169
                                                    [% ELSE %]
170
                                                        [% lateorder.basket.basket_group.name | html %]
171
                                                        ([% lateorder.basket.basketgroupid | html %])
172
                                                    [% END %]
173
                                                [% END %]
174
                                            </td>
175
                                            <td>[% Branches.GetName( lateorder.basket.authorizer.branchcode ) | html %] </td>
176
                                            <td>[% lateorder.fund.budget.budget_period_description | html %]</td>
177
                                            <td>[% lateorder.fund.budget_name | html %]</td>
178
                                            <td>[% lateorder.claims.count | html %]</td>
179
                                            <td data-order="[% lateorder.claims.last.claimed_on | html %]">
180
                                                [% FOR claim IN lateorder.claims %]
181
                                                    [% claim.claimed_on | $KohaDates %]
182
                                                    [% UNLESS loop.last %]<br />[% END %]
183
                                                [% END %]
184
                                            </td>
185
                                            <td>
186
                                                [% IF lateorder.order_internalnote %]
187
                                                    <p class="ordernote">
188
                                                        <span id="internal-note-[% lateorder.ordernumber | html %]">[% lateorder.order_internalnote | html %]</span>
189
                                                        <a
190
                                                            class="edit_note no-export"
191
                                                            data-ordernumber="[% lateorder.ordernumber | html %]"
192
                                                            data-note_type="internal"
193
                                                            href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber=[% lateorder.ordernumber | html %]&type=internal"
194
                                                            title="Edit internal note"
195
                                                        >
196
                                                            <i class="fa-solid fa-pencil" aria-hidden="true"></i> Edit internal note
197
                                                        </a>
198
                                                    </p>
199
                                                [% ELSE %]
200
                                                    <a
201
                                                        class="edit_note no-export"
202
                                                        data-ordernumber="[% lateorder.ordernumber | html %]"
203
                                                        data-note_type="internal"
204
                                                        href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber=[% lateorder.ordernumber | html %]&type=internal"
205
                                                        title="Add internal note"
206
                                                    >
207
                                                        <i class="fa fa-plus"></i> Add internal note
208
                                                    </a>
209
                                                [% END %]
210
                                            </td>
211
                                            <td>
212
                                                [% IF lateorder.order_vendornote %]
213
                                                    <p class="ordernote">
214
                                                        <span id="vendor-note-[% lateorder.ordernumber | html %]">[% lateorder.order_vendornote | html %]</span>
215
                                                        <a
216
                                                            class="edit_note no-export"
217
                                                            data-ordernumber="[% lateorder.ordernumber | html %]"
218
                                                            data-note_type="vendor"
219
                                                            href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber=[% lateorder.ordernumber | html %]&type=vendor"
220
                                                            title="Edit vendor note"
221
                                                        >
222
                                                            <i class="fa-solid fa-pencil" aria-hidden="true"></i> Edit vendor note
223
                                                        </a>
224
                                                    </p>
225
                                                [% ELSE %]
226
                                                    <a
227
                                                        class="edit_note no-export"
228
                                                        data-ordernumber="[% lateorder.ordernumber | html %]"
229
                                                        data-note_type="vendor"
230
                                                        href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber=[% lateorder.ordernumber | html %]&type=vendor"
231
                                                        title="Add vendor note"
232
                                                    >
233
                                                        <i class="fa fa-plus"></i> Add vendor note
234
                                                    </a>
235
                                                [% END %]
236
                                            </td>
237
                                            <td>[% lateorder.biblio.biblioitem.isbn | $raw %]</td>
238
                                        </tr>
239
                                    [% END %]
66
                                    [% END %]
240
                                </tbody>
67
                                </select>
241
                                <tfoot>
68
                            </p>
242
                                    <tr>
69
                        [% END %]
243
                                        <th colspan="6">Total</th>
70
                        <p>
244
                                        <th>[% total_quantity | html %]</th>
71
                            <a id="CheckAll" href="#"><i class="fa fa-check"></i> Check all</a>
245
                                        <th>[% total | $Price %]</th>
72
                            <a id="CheckNone" href="#"><i class="fa fa-times"></i> Uncheck all</a>
246
                                        <th colspan="10">&nbsp;</th>
73
                        </p>
247
                                    </tr>
74
                        <table id="late_orders">
248
                                </tfoot>
75
                            <thead>
249
                            </table>
76
                                <tr>
250
77
                                    <th class="no-sort"></th>
251
                            <fieldset class="action">
78
                                    <th>Order line</th>
252
                                <div class="btn-group">
79
                                    <th>Order date</th>
253
                                    <a id="exportbutton" class="btn btn-default" href="/cgi-bin/koha/acqui/lateorders-export.pl"><i class="fa fa-download"></i> Export as CSV</a>
80
                                    <th>Estimated delivery date</th>
254
                                    <a class="btn btn-default dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false"></a>
81
                                    <th>Vendor</th>
255
                                    <ul class="dropdown-menu" id="export-csv-menu">
82
                                    <th class="anti-the">Information</th>
256
                                        <li><a class="dropdown-item dropdown-menu-end" href="#">Default</a></li>
83
                                    <th>Quantity</th>
257
                                        [% IF csv_profiles.count %]
84
                                    <th>Total cost</th>
258
                                            [% FOR csv IN csv_profiles %]
85
                                    <th>Basket</th>
259
                                                <li><a class="dropdown-item" href="#" data-value="[% csv.export_format_id | html %]">[% csv.profile | html %]</a></li>
86
                                    <th>Basket date</th>
260
                                            [% END %]
87
                                    <th>Basket group</th>
88
                                    <th>Library</th>
89
                                    <th>Budget</th>
90
                                    <th>Fund</th>
91
                                    <th>Claims count</th>
92
                                    <th>Claimed date</th>
93
                                    <th>Internal note</th>
94
                                    <th>Vendor note</th>
95
                                    <th>ISBN</th>
96
                                </tr>
97
                            </thead>
98
                        </table>
99
100
                        <fieldset class="action">
101
                            <div class="btn-group">
102
                                <a id="exportbutton" class="btn btn-default" href="/cgi-bin/koha/acqui/lateorders-export.pl"><i class="fa fa-download"></i> Export as CSV</a>
103
                                <a class="btn btn-default dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false"></a>
104
                                <ul class="dropdown-menu" id="export-csv-menu">
105
                                    <li><a class="dropdown-item dropdown-menu-end" href="#">Default</a></li>
106
                                    [% IF csv_profiles.count %]
107
                                        [% FOR csv IN csv_profiles %]
108
                                            <li><a class="dropdown-item" href="#" data-value="[% csv.export_format_id | html %]">[% csv.profile | html %]</a></li>
261
                                        [% END %]
109
                                        [% END %]
262
                                    </ul>
110
                                    [% END %]
263
                                </div>
111
                                </ul>
264
112
                            </div>
265
                                <input type="submit" class="btn btn-default" value="Claim order" />
113
266
                            </fieldset>
114
                            <input type="submit" class="btn btn-default" value="Claim order" />
267
                        </form>
115
                        </fieldset>
268
                    [% ELSE %]
116
                    </form>
269
                        <p>There are no late orders.</p>
270
                    [% END %]
271
                </div>
117
                </div>
272
                <!-- /#acqui_lateorders -->
118
                <!-- /#acqui_lateorders -->
273
            </main>
119
            </main>
Lines 276-317 Link Here
276
122
277
        <div class="col-md-2 order-sm-2 order-md-1">
123
        <div class="col-md-2 order-sm-2 order-md-1">
278
            <aside>
124
            <aside>
279
                <form action="lateorders.pl" method="get">
125
                <form method="get" id="late_orders_filter_form">
280
                    <fieldset class="brief">
126
                    <fieldset class="brief">
281
                        <h4>Filter results:</h4>
127
                        <h3>Filters:</h3>
282
                        [% FOREACH ERROR_LOO IN ERROR_LOOP %]
283
                            [% IF ( ERROR_LOO.delay_digits ) %]<p class="error">The number of days ([% ERROR_LOO.bad_delay | html %]) must be a number between 0 and 999.</p>[% END %]
284
                        [% END %]
285
                        <ol>
128
                        <ol>
286
                            <li><label for="delay">Order date:</label><input size="3" maxlength="3" id="delay" type="text" name="delay" value="[% delay | html %]" /> days ago</li>
129
                            <li>
287
                            <li
130
                                <label for="late_delay">Order date:</label>
288
                                ><label for="from">Estimated delivery date from: </label>
131
                                <input size="3" maxlength="3" id="late_delay" type="text" name="late_delay" value="0" /> days ago
289
                                <input type="text" size="10" id="from" name="estimateddeliverydatefrom" value="[% estimateddeliverydatefrom | html %]" class="flatpickr" data-date_to="to" />
290
                                <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
291
                            </li>
132
                            </li>
292
                            <li
133
                            <li>
293
                                ><label for="to">To: </label>
134
                                <label for="estimated_deliverydate_from">Estimated delivery date from:</label>
294
                                <input type="text" size="10" id="to" name="estimateddeliverydateto" value="[% estimateddeliverydateto | html %]" class="flatpickr" />
135
                                <input type="text" name="estimated_deliverydate_from" id="estimated_deliverydate_from" class="flatpickr" data-date_to="estimated_deliverydate_from" />
295
                                <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
136
                            </li>
137
                            <li>
138
                                <label for="estimated_deliverydate_to">To:</label>
139
                                <input type="text" name="estimated_deliverydate_to" id="estimated_deliverydate_to" class="flatpickr" data-date_to="estimated_deliverydate_to" />
296
                            </li>
140
                            </li>
297
298
                            <li
141
                            <li
299
                                ><label for="booksellerid">Vendor:</label>
142
                                ><label for="vendor_filter">Vendor:</label>
300
                                <select id="booksellerid" tabindex="" name="booksellerid">
143
                                <select id="vendor_filter" tabindex="" name="vendor_filter">
301
                                    <option value=""></option>
144
                                    <option value="">All vendors</option>
302
                                    [% FOREACH bookseller IN booksellers %]
303
                                        [% IF bookseller.id == bookseller_filter.id %]
304
                                            <option value="[% bookseller.id | html %]" selected="selected">[% bookseller.name | html %]</option>
305
                                        [% ELSE %]
306
                                            <option value="[% bookseller.id | html %]">[% bookseller.name | html %]</option>
307
                                        [% END %]
308
                                    [% END %]
309
                                </select>
145
                                </select>
310
                            </li></ol
146
                            </li>
311
                        >
147
                        </ol>
148
                    </fieldset>
149
                    <fieldset class="action">
150
                        <input type="submit" class="btn btn-primary" value="Filter" />
151
                        <input type="button" value="Clear" class="clear_search" />
312
                    </fieldset>
152
                    </fieldset>
313
                    <fieldset class="action"><input type="submit" class="btn btn-primary" value="Filter" /></fieldset>
314
                </form>
153
                </form>
154
                <!-- /#late_orders_filter_form, -->
315
                [% INCLUDE 'acquisitions-menu.inc' %]
155
                [% INCLUDE 'acquisitions-menu.inc' %]
316
            </aside>
156
            </aside>
317
        </div>
157
        </div>
Lines 388-405 Link Here
388
228
389
        $(document).ready(function() {
229
        $(document).ready(function() {
390
230
391
            var table_settings = [% TablesSettings.GetTableSettings( 'acqui', 'lateorders', 'late_orders', 'json' ) | $raw %];
392
            late_orderst = $("#late_orders").kohaTable({
393
                "sorting": [[ 1, "asc" ]],
394
                "pagingType": "full",
395
                "autoWidth": false,
396
                "drawCallback": function() {
397
                    if ( typeof late_orderst != 'undefined' ) {
398
                        check_uncheck();
399
                        $('input:checkbox[name=ordernumber]').bind('click', check_uncheck);
400
                    };
401
                }
402
            }, table_settings );
403
            $('input:checkbox[name=ordernumber]').bind('click', check_uncheck);
231
            $('input:checkbox[name=ordernumber]').bind('click', check_uncheck);
404
            $('#CheckAll').click(function(e){
232
            $('#CheckAll').click(function(e){
405
                e.preventDefault();
233
                e.preventDefault();
Lines 410-416 Link Here
410
                $("#late_orders input:checkbox").prop("checked", false);
238
                $("#late_orders input:checkbox").prop("checked", false);
411
            });
239
            });
412
240
413
            // Generates a dynamic link for exporting the selection's data as CSV
241
            const buildQuery = () => {
242
                const late_delay = parseInt($("#late_delay").val());
243
                const estimated_deliverydate_from = $("#estimated_deliverydate_from").val();
244
                const estimated_deliverydate_to = $("#estimated_deliverydate_to").val();
245
246
                const queryParams = [
247
                    ["only_late", "1"],
248
                    ...(Number.isNaN(late_delay) ? [] : [["late_delay", late_delay]]),
249
                    ...(estimated_deliverydate_from ? [["estimated_deliverydate_from", estimated_deliverydate_from]] : []),
250
                    ...(estimated_deliverydate_to ? [["estimated_deliverydate_to", estimated_deliverydate_to]] : []),
251
                ];
252
253
                return '/api/v1/acquisitions/orders?' + queryParams
254
                    .map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
255
                    .join("&");
256
            }
257
258
            let additional_filters = {
259
                "basket.vendor_id": () => {
260
                    let vendor_id = $("#vendor_filter").val();
261
                    if (!vendor_id) return "";
262
                    return { "=": vendor_id };
263
                }
264
            };
265
266
            var table_settings = [% TablesSettings.GetTableSettings( 'acqui', 'lateorders', 'late_orders', 'json' ) | $raw %];
267
            var late_orderst = $("#late_orders").kohaTable({
268
                order: [[ 1, "asc" ]],
269
                paging: true,
270
                embed: [
271
                    "basket.authorizer+strings",
272
                    "basket.basket_group",
273
                    "basket.late_since_days",
274
                    "basket.vendor",
275
                    "biblio",
276
                    "claims+count",
277
                    "fund.budget"
278
                ],
279
                ajax: {
280
                    url: buildQuery(),
281
                 },
282
                columns: [
283
                    {
284
                        data: "order_id", // checkbox
285
                        orderable: false,
286
                        searchable: false,
287
                        render: function(data, type, row, meta) {
288
                            return '<input type="checkbox" value="%s" data-booksellerid="%s" name="ordernumber" />'.format(escape_str(data),escape_str(row.basket.vendor_id));
289
                        }
290
                    },
291
                    {
292
                        data: "order_id",
293
                        orderable: true,
294
                        searchable: true
295
                    },
296
                    {
297
                        data: "basket.close_date",
298
                        type: "date",
299
                        orderable: true,
300
                        render: function(data, type, row, meta) {
301
                            return '%s (%s)'.format($date(data),_("%s days").format(escape_str(row.basket.late_since_days)));
302
                        }
303
                    },
304
                    {
305
                        data: "estimated_delivery_date",
306
                        type: "date",
307
                        orderable: true,
308
                        render: function(data, type, row, meta) {
309
                            return '<p class="delivery_date"><span>%s</span>'.format($date(data))
310
                                [% IF CAN_user_acquisition_order_manage %]
311
                                   + '<a class="edit_delivery_date no-export" data-ordernumber="%s" '.format(escape_str(row.order_id))
312
                                   + 'data-delivery_date="%s" id="delivery_date_%s" '.format(escape_str(data),escape_str(row.order_id))
313
                                   + 'href="/cgi-bin/koha/acqui/moddeliverydate.pl?ordernumber=%s" title="%s">'.format(encodeURIComponent(row.order_id),_("Edit delivery date"))
314
                                   + '<i class="fa-solid fa-pencil" aria-hidden="true"></i> %s</a>'.format(_("Edit"))
315
                                [% END %]
316
                                   + '</p>';
317
                        }
318
                    },
319
                    {
320
                        data: 'basket.vendor.name',
321
                        orderable: false,
322
                        searchable: true,
323
                        render: function(data, type, row, meta) {
324
                            return '%s (%s)'.format(escape_str(data), escape_str(row.basket.vendor_id));
325
                        }
326
                    },
327
                    {
328
                        [% SET summary_fields = "biblio.title:biblio.author:biblio.isbn:biblio.publisher:me.internal_note:me.vendor_note" %]
329
                        [% IF Koha.Preference('marcflavour')=='UNIMARC' %][% SET summary_fields = summary_fields _ ":biblio.ean" %][% END %]
330
                        "data": "[% summary_fields | html %]",
331
                        "render": function(data, type, row, meta) {
332
                            var result = '';
333
                            if ( row && row.biblio_id != null ) {
334
                                result = '<p><span class="title"><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=%s">%s</a></span>'.format(encodeURIComponent(row.biblio_id),escape_str(row.biblio.title));
335
                                if ( row.biblio.author != null )
336
                                    result += '<br /><em>%s:</em> %s'.format(_("Author"),escape_str(row.biblio.author));
337
                                if ( row.biblio.publisher != null ) {
338
                                    result += '<br /><em>%s:</em> %s'.format(_("Published by"),escape_str(row.biblio.publisher));
339
                                    if ( row.biblio.publication_year != null ) {
340
                                        result += '<em> %s </em> %s'.format(__px("Published in <date>","in"),escape_str(row.biblio.publication_year));
341
                                    }
342
                                }
343
                                result += '</p>';
344
                            }
345
346
                            return result;
347
                        },
348
                        "orderable": true,
349
                    },
350
                    {
351
                        data: 'quantity',
352
                        orderable: true,
353
                        searchable: true
354
                    },
355
                    {
356
                        data: "", // total cost, calculated
357
                        orderable: false,
358
                        searchable: false,
359
                        render: function(data, type, row, meta) {
360
                            let reminder_qty = (row.quantity - row.quantity_received);
361
                            let subtotal = reminder_qty * row.replacement_price;
362
                            return '%s x %s = %s'.format( escape_price(row.replacement_price), reminder_qty, escape_price(subtotal) );
363
                        }
364
                    },
365
                    {
366
                        data: 'basket.name',
367
                        orderable: true,
368
                        searchable: true,
369
                        render: function(data, type, row, meta) {
370
                            var basket_name = '%s (%s)'.format(escape_str(data),escape_str(row.basket_id));
371
                        [% IF ( CAN_user_acquisition_order_manage ) %]
372
                            return '<a href="basket.pl?basketno="%s" title="%s">%s</a>'.format(encodeURIComponent(row.basket_id),escape_str(data),basket_name);
373
                        [% ELSE %]
374
                            return basket_name;
375
                        [% END %]
376
                        }
377
                    },
378
                    {
379
                        data: 'basket.creation_date',
380
                        orderable: true,
381
                        render: function(data, type, row, meta) {
382
                            return $date(data);
383
                        }
384
                    },
385
                    {
386
                        data: 'basket.basket_group_id',
387
                        orderable: true,
388
                        searchable: true,
389
                        render: function(data, type, row, meta) {
390
                            if ( data != null ) {
391
                            [%- IF CAN_user_acquisition_group_manage -%]
392
                                return '<a href="basketgroup.pl?op=add&booksellerid=%s&basketgroupid=%s" title="basketgroup">%s (%s)</a>'
393
                                    .format(encodeURIComponent(row.vendor_id),encodeURIComponent(data),row.basket.basket_group.name, data);
394
                            [%- ELSE -%]
395
                                return '%s (%s)'.format(row.basket.basket_group.name, data);
396
                            [%- END -%]
397
                            } else { return ''; }
398
                        }
399
                    },
400
                    {
401
                        data: 'basket.authorizer.library_id',
402
                        orderable: false,
403
                        searchable: false,
404
                        render: function(data, type, row, meta) {
405
                            return escape_str(row.basket.authorizer._strings.library_id.str);
406
                        }
407
                    },
408
                    {
409
                        data: 'fund.budget.budget_period_description',
410
                        orderable: true,
411
                        searchable: true
412
                    },
413
                    {
414
                        data: 'fund.name',
415
                        orderable: true,
416
                        searchable: true
417
                    },
418
                    {
419
                        data: 'claims_count',
420
                        orderable: true,
421
                        searchable: false
422
                    },
423
                    {
424
                        data: 'claims',
425
                        orderable: false,
426
                        searchable: false,
427
                        render: function(data, type, row, meta) {
428
                            return data != undefined ? data.map(item => $date(item.date_claimed)).join('<br/>') : '';
429
                        }
430
                    },
431
                    {
432
                        data: "", // internal_note
433
                        orderable: false,
434
                        searchable: false,
435
                        render: function(data, type, row, meta) {
436
                            if ( row.internal_note != null && row.internal_note != '' ) {
437
                                return '<p class="ordernote">'
438
                                        + '<span id="internal-note-%s">%s</span>'.format(row.order_id,escape_str(row.internal_note))
439
                                        + '<a class="edit_note no-export" data-ordernumber="%s" '.format(row.order_id)
440
                                        + 'data-note_type="internal" href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber=%s&type=internal" '.format(encodeURIComponent(row.order_id))
441
                                        + 'title="Edit internal note"><i class="fa-solid fa-pencil" aria-hidden="true"></i> Edit internal note</a></p>'.format(_("Edit internal note"),_("Edit internal note"));
442
                            }
443
                            else {
444
                                return '<a class="edit_note no-export" data-ordernumber="%s" '.format(row.order_id)
445
                                       + 'data-note_type="internal" href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber=%s&type=internal" '.format(encodeURIComponent(row.order_id))
446
                                       + 'title="%s"><i class="fa fa-plus"></i> %s</a>'.format(_("Add internal note"),_("Add internal note"));
447
                            }
448
449
                        }
450
                    },
451
                    {
452
                        data: "", // vendor_note
453
                        orderable: false,
454
                        searchable: false,
455
                        render: function(data, type, row, meta) {
456
                            if ( row.vendor_note != null && row.vendor_note != '' ) {
457
                                return '<p class="ordernote"><span id="vendor-note-%s">%s</span>'.format(row.order_id,escape_str(row.vendor_note))
458
                                       + '<a class="edit_note no-export" data-ordernumber="%s" data-note_type="vendor" '.format(row.order_id)
459
                                       + 'href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber=%s&type=vendor" '.format(encodeURIComponent(row.order_id))
460
                                       + 'title="%s"><i class="fa-solid fa-pencil" aria-hidden="true"></i> Edit vendor note</a></p>'.format(_("Edit vendor note"),_("Edit vendor note"));
461
                            }
462
                            else {
463
                                return '<a class="edit_note no-export" data-ordernumber="%s" data-note_type="vendor" '.format(row.order_id)
464
                                       + 'href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber=%s&type=vendor" '.format(row.order_id)
465
                                       + 'title="%s"><i class="fa fa-plus"></i> %s</a>'.format(_("Add vendor note"),_("Add vendor note"));
466
                            }
467
                        }
468
                    },
469
                    {
470
                        data: 'biblio.isbn',
471
                        orderable: true,
472
                        searchable: true
473
                    }
474
                ]
475
            },
476
            table_settings,
477
            false, // add_column_filters
478
            additional_filters, // default_filters
479
            undefined, // filters_options
480
            undefined, //external_filter_nodes
481
            );
482
483
            const redrawTable = () => {
484
                late_orderst.api().ajax.url(buildQuery()).load();
485
            };
486
487
            const clearFilters = () => {
488
                $("#late_delay").val("0");
489
                $("#estimated_deliverydate_from")[0]._flatpickr?.clear();
490
                $("#estimated_deliverydate_to")[0]._flatpickr?.clear();
491
                $("#vendor_filter").val("").trigger('change');
492
493
                redrawTable();
494
            };
495
496
            $("#late_orders_filter_form").on("submit", (e) => {
497
                e.preventDefault();
498
                redrawTable();
499
            });
500
501
            // Clear all filters
502
            $(".clear_search").click(clearFilters);
503
504
                      // Generates a dynamic link for exporting the selection's data as CSV
414
            $("#exportbutton, #export-csv-menu a").click(function() {
505
            $("#exportbutton, #export-csv-menu a").click(function() {
415
                var all_nodes = late_orderst.DataTable().rows().nodes();
506
                var all_nodes = late_orderst.DataTable().rows().nodes();
416
                var selected = $(all_nodes).find("input[name='ordernumber']:checked");
507
                var selected = $(all_nodes).find("input[name='ordernumber']:checked");
Lines 474-479 Link Here
474
                $("#estimated_delivery_date").html( "" );
565
                $("#estimated_delivery_date").html( "" );
475
                $("#date_ordernumber").val("");
566
                $("#date_ordernumber").val("");
476
            });
567
            });
568
569
            function populateVendorsFilter() {
570
                $.ajax({
571
                    type: "GET",
572
                    url: "/api/v1/acquisitions/vendors",
573
                    success: function (vendors) {
574
                        vendors
575
                            .sort((a, b) =>
576
                                a.name.localeCompare(b.name)
577
                            )
578
                            .forEach(function (vendor) {
579
                                if (
580
                                    $(
581
                                        "#vendor_filter option[value=" +
582
                                            vendor.id +
583
                                            "]"
584
                                    ).length == 0
585
                                ) {
586
                                    $("#vendor_filter").append(
587
                                        '<option value="' +
588
                                            vendor.id +
589
                                            '">' +
590
                                            vendor.name +
591
                                            "</option>"
592
                                    );
593
                                }
594
                            });
595
                    },
596
                });
597
            }
598
599
            populateVendorsFilter();
477
        });
600
        });
478
    </script>
601
    </script>
479
[% END %]
602
[% END %]
480
- 

Return to bug 32266