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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt (-1 / +113 lines)
Lines 10-15 Link Here
10
[% PROCESS 'member-display-address-style.inc' %]
10
[% PROCESS 'member-display-address-style.inc' %]
11
[% PROCESS 'member-display-alt-address-style.inc' %]
11
[% PROCESS 'member-display-alt-address-style.inc' %]
12
[% PROCESS 'i18n.inc' %]
12
[% PROCESS 'i18n.inc' %]
13
[% PROCESS 'patron-search.inc' %]
13
[% SET footerjs = 1 %]
14
[% SET footerjs = 1 %]
14
[% INCLUDE 'doc-head-open.inc' %]
15
[% INCLUDE 'doc-head-open.inc' %]
15
<title
16
<title
Lines 283-288 Link Here
283
                            </li>
284
                            </li>
284
                        [% END %]
285
                        [% END %]
285
286
287
                        [% IF Koha.Preference('EnablePatronAccountLinking') %]
288
                            <li id="patron-linked-accounts">
289
                                <span class="label">Linked accounts:</span>
290
                                [% IF linked_accounts.size > 0 %]
291
                                    <ul>
292
                                        [% IF linked_accounts_debt && linked_accounts_debt > 0 %]
293
                                            <li class="linked-accounts-fines">
294
                                                <span class="circ-hlt">Combined charges:</span>
295
                                                Linked accounts collectively owe [% linked_accounts_debt | $Price %].
296
                                            </li>
297
                                        [% END %]
298
                                        [% FOREACH linked IN linked_accounts %]
299
                                            <li class="linked-account-item" data-borrowernumber="[% linked.borrowernumber | html %]">
300
                                                [% IF logged_in_user.can_see_patron_infos( linked ) %]
301
                                                    <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% linked.borrowernumber | uri %]">[% linked.firstname | html %] [% linked.surname | html %]</a>
302
                                                [% ELSE %]
303
                                                    [% linked.firstname | html %]
304
                                                    [% linked.surname | html %]
305
                                                [% END %]
306
                                                ([% linked.cardnumber | html %]) [% IF linked.branchcode %]- [% Branches.GetName( linked.branchcode ) | html %][% END %]
307
                                            </li>
308
                                        [% END %]
309
                                    </ul>
310
                                    [% IF CAN_user_borrowers_edit_borrowers %]
311
                                        <p style="margin-top: 5px;">
312
                                            <a href="#patron_search_modal_linked" class="btn btn-default" data-bs-toggle="modal"><i class="fa fa-plus"></i> Add linked account</a>
313
                                            <a href="#" id="leave-linked-accounts" class="btn btn-default" title="Remove this patron from their linked group"><i class="fa fa-trash-can"></i> Leave linked group</a>
314
                                        </p>
315
                                    [% END %]
316
                                [% ELSE %]
317
                                    <span class="none">None</span>
318
                                    [% IF CAN_user_borrowers_edit_borrowers %]
319
                                        <p style="margin-top: 5px;">
320
                                            <a href="#patron_search_modal_linked" class="btn btn-default" data-bs-toggle="modal"><i class="fa fa-plus"></i> Add linked account</a>
321
                                        </p>
322
                                    [% END %]
323
                                [% END %]
324
                            </li>
325
                        [% END %]
326
286
                        [% IF ( patron.primary_contact_method ) %]
327
                        [% IF ( patron.primary_contact_method ) %]
287
                            <li>
328
                            <li>
288
                                <span class="label">Main contact method: </span>
329
                                <span class="label">Main contact method: </span>
Lines 915-923 Link Here
915
                placeholder: _("Select or type a reason"),
956
                placeholder: _("Select or type a reason"),
916
                context: 'modal',
957
                context: 'modal',
917
            });
958
            });
959
960
            [% IF Koha.Preference('EnablePatronAccountLinking') && CAN_user_borrowers_edit_borrowers %]
961
            // Linked accounts management - leave entire linked group
962
            $("#leave-linked-accounts").on("click", function(e) {
963
                e.preventDefault();
964
                var patron_borrowernumber = [% patron.borrowernumber | html %];
965
966
                if (confirm(_("Are you sure you want to remove this patron from all linked accounts?"))) {
967
                    // Get the link_id for the current patron
968
                    $.ajax({
969
                        url: "/api/v1/patrons/" + patron_borrowernumber + "/account_links",
970
                        type: "GET",
971
                        headers: { "Accept": "application/json" },
972
                        success: function(links) {
973
                            // Find the CURRENT patron's link record
974
                            var link = links.find(function(l) { return l.patron_id == patron_borrowernumber; });
975
                            if (link) {
976
                                // Delete the current patron's link (removes them from the group)
977
                                $.ajax({
978
                                    url: "/api/v1/patrons/" + patron_borrowernumber + "/account_links/" + link.account_link_id,
979
                                    type: "DELETE",
980
                                    success: function() {
981
                                        // Reload page to show updated state
982
                                        location.reload();
983
                                    },
984
                                    error: function(xhr) {
985
                                        alert(_("Error leaving linked group: ") + xhr.responseJSON.error);
986
                                    }
987
                                });
988
                            }
989
                        },
990
                        error: function(xhr) {
991
                            alert(_("Error fetching linked accounts: ") + xhr.responseJSON.error);
992
                        }
993
                    });
994
                }
995
            });
996
            [% END %]
918
        });
997
        });
998
999
        [% IF Koha.Preference('EnablePatronAccountLinking') && CAN_user_borrowers_edit_borrowers %]
1000
        function link_patron(borrowernumber, borrower) {
1001
            var patron_borrowernumber = [% patron.borrowernumber | html %];
1002
1003
            if (borrowernumber == patron_borrowernumber) {
1004
                alert(_("Cannot link a patron to themselves."));
1005
                return;
1006
            }
1007
1008
            $.ajax({
1009
                url: "/api/v1/patrons/" + patron_borrowernumber + "/account_links",
1010
                type: "POST",
1011
                contentType: "application/json",
1012
                data: JSON.stringify({ linked_patron_id: borrowernumber }),
1013
                success: function(response) {
1014
                    // Reload the page to show the new linked account
1015
                    location.reload();
1016
                },
1017
                error: function(xhr) {
1018
                    var error_msg = xhr.responseJSON ? xhr.responseJSON.error : _("Unknown error");
1019
                    alert(_("Error linking account: ") + error_msg);
1020
                }
1021
            });
1022
1023
            $("#patron_search_modal_linked").modal("hide");
1024
        }
1025
        [% END %]
919
    </script>
1026
    </script>
920
    [% Asset.js("js/checkouts.js") | $raw %]
1027
    [% Asset.js("js/checkouts.js") | $raw %]
1028
1029
    [% IF Koha.Preference('EnablePatronAccountLinking') && CAN_user_borrowers_edit_borrowers %]
1030
        [% SET columns = ['cardnumber', 'name', 'category', 'branch', 'action'] %]
1031
        [% PROCESS patron_search_modal columns => columns, modal_title => t("Link patron account"), patron_search_modal_id => 'patron_search_modal_linked', table_id => 'patron_search_modal_linked_table' %]
1032
        [% PROCESS patron_search_js columns => columns, actions => ["select"], preview_on_name_click => 1, table_id => 'patron_search_modal_linked_table', callback => 'link_patron' %]
1033
    [% END %]
921
[% END %]
1034
[% END %]
922
1035
923
[% INCLUDE 'intranet-bottom.inc' %]
1036
[% INCLUDE 'intranet-bottom.inc' %]
924
- 

Return to bug 39658