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

(-)a/Koha/REST/V1/Biblios.pm (-8 / +16 lines)
Lines 271-287 sub get_items { Link Here
271
271
272
        if ($group_by_status) {
272
        if ($group_by_status) {
273
            $c->req->params->remove('_order_by');
273
            $c->req->params->remove('_order_by');
274
            my @item_ids;
275
            for my $status (
276
                qw( available checked_out local_use in_transit lost withdrawn damaged not_for_loan on_hold recalled in_bundle restricted )
277
                )
278
            {
279
                push @item_ids, $items_rs->search( { _status => $status } )->get_column('itemnumber');
280
            }
281
            $items_rs = $items_rs->search(
274
            $items_rs = $items_rs->search(
282
                {},
275
                {},
283
                {
276
                {
284
                    order_by => [ \[ sprintf( "field(me.itemnumber, %s)", join( ', ', map { qq{'$_'} } @item_ids ) ) ] ]
277
                   order_by => [    
278
                        \[ "CASE 
279
                                WHEN (withdrawn != 0) THEN '10_Withdrawn'
280
                                WHEN (itemlost != 0) THEN '09_Lost'
281
                                WHEN (damaged != 0) THEN '08_Damaged'
282
                                WHEN (notforloan = 3) THEN '07_In bundle'
283
                                WHEN (notforloan != 0) THEN '06_Not for loan'
284
                                WHEN EXISTS (SELECT 1 FROM issues WHERE itemnumber = me.itemnumber AND onsite_checkout = 1) THEN '05_Local use'
285
                                WHEN (onloan IS NOT NULL) THEN '04_Checked out'
286
                                WHEN (SELECT COUNT(*) FROM branchtransfers WHERE itemnumber = me.itemnumber AND datearrived IS NULL) > 0 THEN '03_In transit'
287
                                WHEN (SELECT COUNT(*) FROM reserves WHERE itemnumber = me.itemnumber AND (found IS NULL OR found = 'W')) > 0 THEN '02_On hold'
288
                                ELSE '01_Available'
289
                            END ASC" ],
290
                        { -asc => 'me.itemlost' },
291
                        { -asc => 'me.notforloan' },
292
                    ]
285
                }
293
                }
286
            );
294
            );
287
        }
295
        }
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc (-9 / +100 lines)
Lines 301-319 Link Here
301
            holdings: false,
301
            holdings: false,
302
            otherholdings: false,
302
            otherholdings: false,
303
        };
303
        };
304
        $(".GroupByStatus").on("click",function(e){
304
305
        function get_display_status(row, forSort = false) {
306
            let status = "";
307
            let priority = "";
308
309
            if (!row._status) row._status = [];
310
311
            if (row.withdrawn != 0) {
312
                status = _("Withdrawn");
313
                priority = "10";
314
            } else if (row.lost_status != 0) {
315
                let lost_text = av_lost.get(row.lost_status.toString()) || _("Lost");
316
                status = lost_text;
317
                if (forSort) {
318
                    if (lost_text.toLowerCase().includes("paid")) priority = "09c";
319
                    else if (lost_text.toLowerCase().includes("overdue")) priority = "09b";
320
                    else priority = "09a";
321
                } else {
322
                    priority = "09";
323
                }
324
            }
325
             else if (row.damaged_status != 0) {
326
                status = _("Damaged");
327
                priority = "08";
328
            }
329
            else if (row.not_for_loan_status == 3) {
330
                status = _("In bundle");
331
                priority = "07";
332
            } else if (row.not_for_loan_status != 0) {
333
                status = _("Not for loan");
334
                priority = "06";
335
            }
336
            else if (row._status.includes('local_use')) {
337
                status = _("Local use");
338
                priority = "05";
339
            } 
340
            else if (row._status.includes('checked_out')) {
341
                status = _("Checked out");
342
                priority = "04";
343
            } 
344
            else if (row._status.includes('in_transit')) {
345
                status = _("In transit");
346
                priority = "03";
347
            }
348
             else if (row._status.includes('on_hold') || row._status.includes('waiting')) {
349
                status = _("On hold");
350
                priority = "02";
351
            } 
352
            else if (row._status.includes('available') || (row.lost_status == 0 && row.withdrawn == 0)) {
353
                status = _("Available");
354
                priority = "01";
355
            } 
356
            else {
357
                status = _("Undefined");
358
                priority = "99";
359
            }
360
361
            status = status.trim();
362
363
            if (forSort) {
364
                if (priority.startsWith("09")) {
365
                    return "09_" + _("Lost");
366
                }
367
                return priority + "_" + status;
368
            }
369
370
            return status;
371
        }
372
373
        $(".GroupByStatus").on("click", function(e) {
305
            e.preventDefault();
374
            e.preventDefault();
306
            let tab_id = $(this).data("tab");
375
            let tab_id = $(this).data("tab");
307
            let was_grouped = group_by_status_values[tab_id];
376
            group_by_status_values[tab_id] = !group_by_status_values[tab_id];
308
            group_by_status_values[tab_id] = !was_grouped;
377
            let is_grouping = group_by_status_values[tab_id];
378
379
            var dt_options = { 
380
                "destroy": true,
381
            };
309
382
310
            build_items_table(tab_id, true, { destroy: true }, build_items_table_drawncallback );
383
            if (is_grouping) {
384
                dt_options["rowGroup"] = {
385
                    "dataSrc": function(row) {
386
                        return get_display_status(row, true);
387
                    },
388
                    "startRender": function (rows, group) {
389
                        let displayTitle = group.indexOf('_') !== -1 ? group.split('_')[1] : group;
390
391
                        let groupColor = "#007bff"; 
392
393
                        if (group.startsWith("01")) {
394
                            groupColor = "#28a745";
395
                        } else if (group.startsWith("08") || group.startsWith("09") || group.startsWith("10")) {
396
                            groupColor = "#dc3545";
397
                        }
398
399
                        return $('<tr class="group-header"><td colspan="30" style="background-color:#f8f9fa; font-weight:bold; border-left:5px solid ' + groupColor + '; padding:10px;">' 
400
                                + displayTitle + ' (' + rows.count() + ')</td></tr>');
401
                    }
402
                };
311
403
312
            if ( was_grouped ) {
404
                $(this).html('<i class="fa fa-object-ungroup"></i> ' + _("Ungroup by status") + '</button>');
313
                $(this).html('<i class="fa fa-object-group"></i> ' + _("Group by status") + '</button>');
314
            } else {
405
            } else {
315
                $(this).html('<i class="fa fa-object-ungroup"></i> '+ _("Ungroup by status") + '</button>');
406
                $(this).html('<i class="fa fa-object-group"></i> '+ _("Group by status") + '</button>');
316
            }
407
            }
408
            build_items_table(tab_id, true, dt_options, build_items_table_drawncallback, { group_by_status: is_grouping ? 1 : 0 });
317
        });
409
        });
318
410
319
        function build_items_table (tab_id, add_filters, dt_options, drawcallback) {
411
        function build_items_table (tab_id, add_filters, dt_options, drawcallback) {
Lines 570-576 Link Here
570
                            }
662
                            }
571
663
572
                            if ( status == 'lost' ) {
664
                            if ( status == 'lost' ) {
573
                                let lost_lib = av_lost.get(row.lost_status.toString()) || _("Unavailable (lost or missing");
665
                                let lost_lib = av_lost.get(row.lost_status.toString()) || _("Unavailable (lost or missing)");
574
                                nodes += '<span class="lost">%s</span>'.format(escape_str(lost_lib));
666
                                nodes += '<span class="lost">%s</span>'.format(escape_str(lost_lib));
575
667
576
                                const hasReturnClaims = row.return_claims && row.return_claims.filter(rc => !rc.resolution).length > 0 ? true : false
668
                                const hasReturnClaims = row.return_claims && row.return_claims.filter(rc => !rc.resolution).length > 0 ? true : false
577
- 

Return to bug 38122