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

(-)a/Koha/REST/V1/Acquisitions/Vendors.pm (-6 / +8 lines)
Lines 226-237 sub config { Link Here
226
    return $c->render(
226
    return $c->render(
227
        status  => 200,
227
        status  => 200,
228
        openapi => {
228
        openapi => {
229
            permissions => $permissions,
229
            permissions      => $permissions,
230
            currencies  => Koha::Acquisition::Currencies->search->unblessed,
230
            currencies       => Koha::Acquisition::Currencies->search->unblessed,
231
            gst_values  => \@gst_values,
231
            gst_values       => \@gst_values,
232
            edifact     => C4::Context->preference('EDIFACT'),
232
            edifact          => C4::Context->preference('EDIFACT'),
233
            marc_orders => C4::Context->preference('MarcOrderingAutomation'),
233
            marc_orders      => C4::Context->preference('MarcOrderingAutomation'),
234
            erm_module  => C4::Context->preference('ERMModule'),
234
            erm_module       => C4::Context->preference('ERMModule'),
235
            logged_in_user   => $patron,
236
            logged_in_branch => C4::Context::mybranch,
235
        },
237
        },
236
    );
238
    );
237
}
239
}
(-)a/admin/library_groups.pl (+4 lines)
Lines 52-57 if ( $op eq 'cud-add' ) { Link Here
52
    my $ft_search_groups_staff = $cgi->param('ft_search_groups_staff') || 0;
52
    my $ft_search_groups_staff = $cgi->param('ft_search_groups_staff') || 0;
53
    my $ft_local_hold_group    = $cgi->param('ft_local_hold_group')    || 0;
53
    my $ft_local_hold_group    = $cgi->param('ft_local_hold_group')    || 0;
54
    my $ft_local_float_group   = $cgi->param('ft_local_float_group')   || 0;
54
    my $ft_local_float_group   = $cgi->param('ft_local_float_group')   || 0;
55
    my $ft_acquisitions        = $cgi->param('ft_acquisitions')        || 0;
55
56
56
    if ( !$branchcode && Koha::Library::Groups->search( { title => $title } )->count() ) {
57
    if ( !$branchcode && Koha::Library::Groups->search( { title => $title } )->count() ) {
57
        $template->param( error_duplicate_title => $title );
58
        $template->param( error_duplicate_title => $title );
Lines 68-73 if ( $op eq 'cud-add' ) { Link Here
68
                    ft_local_hold_group    => $ft_local_hold_group,
69
                    ft_local_hold_group    => $ft_local_hold_group,
69
                    ft_limit_item_editing  => $ft_limit_item_editing,
70
                    ft_limit_item_editing  => $ft_limit_item_editing,
70
                    ft_local_float_group   => $ft_local_float_group,
71
                    ft_local_float_group   => $ft_local_float_group,
72
                    ft_acquisitions        => $ft_acquisitions,
71
                    branchcode             => $branchcode,
73
                    branchcode             => $branchcode,
72
                }
74
                }
73
            )->store();
75
            )->store();
Lines 88-93 if ( $op eq 'cud-add' ) { Link Here
88
    my $ft_search_groups_staff = $cgi->param('ft_search_groups_staff') || 0;
90
    my $ft_search_groups_staff = $cgi->param('ft_search_groups_staff') || 0;
89
    my $ft_local_hold_group    = $cgi->param('ft_local_hold_group')    || 0;
91
    my $ft_local_hold_group    = $cgi->param('ft_local_hold_group')    || 0;
90
    my $ft_local_float_group   = $cgi->param('ft_local_float_group')   || 0;
92
    my $ft_local_float_group   = $cgi->param('ft_local_float_group')   || 0;
93
    my $ft_acquisitions        = $cgi->param('ft_acquisitions')        || 0;
91
94
92
    if ($id) {
95
    if ($id) {
93
        my $group = Koha::Library::Groups->find($id);
96
        my $group = Koha::Library::Groups->find($id);
Lines 102-107 if ( $op eq 'cud-add' ) { Link Here
102
                ft_search_groups_staff => $ft_search_groups_staff,
105
                ft_search_groups_staff => $ft_search_groups_staff,
103
                ft_local_hold_group    => $ft_local_hold_group,
106
                ft_local_hold_group    => $ft_local_hold_group,
104
                ft_local_float_group   => $ft_local_float_group,
107
                ft_local_float_group   => $ft_local_float_group,
108
                ft_acquisitions        => $ft_acquisitions,
105
            }
109
            }
106
        )->store();
110
        )->store();
107
111
(-)a/api/v1/swagger/definitions/vendor.yaml (+8 lines)
Lines 124-129 properties: Link Here
124
      - string
124
      - string
125
      - "null"
125
      - "null"
126
    description: Language
126
    description: Language
127
  lib_group_visibility:
128
    type:
129
      - string
130
      - "null"
131
    description: Language
132
  lib_group_limits:
133
    type: array
134
    description: Library groups this vendor belongs to
127
  aliases:
135
  aliases:
128
    type: array
136
    type: array
129
    description: List of aliases
137
    description: List of aliases
(-)a/api/v1/swagger/definitions/vendors_config.yaml (+6 lines)
Lines 19-22 properties: Link Here
19
  erm_module:
19
  erm_module:
20
    type: boolean
20
    type: boolean
21
    description: ERMModule system preference value
21
    description: ERMModule system preference value
22
  logged_in_user:
23
    type: object
24
    description: The patron logged in to this session
25
  logged_in_branch:
26
    type: string
27
    description: The branch that the patron has logged in to this session
22
additionalProperties: false
28
additionalProperties: false
(-)a/api/v1/swagger/paths/acquisitions_vendors.yaml (+1 lines)
Lines 159-164 Link Here
159
            - contracts
159
            - contracts
160
            - extended_attributes
160
            - extended_attributes
161
            - +strings
161
            - +strings
162
            - lib_group_limits
162
        collectionFormat: csv
163
        collectionFormat: csv
163
    produces:
164
    produces:
164
      - application/json
165
      - application/json
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt (-2 / +22 lines)
Lines 152-157 Link Here
152
                                    Is local float group
152
                                    Is local float group
153
                                </label>
153
                                </label>
154
                            </p>
154
                            </p>
155
                            <p>
156
                                <label>
157
                                    <input type="checkbox" name="ft_acquisitions" id="add-group-modal-ft_acquisitions" value="1" />
158
                                    Use in the acquisitions module
159
                                </label>
160
                            </p>
155
                        </div>
161
                        </div>
156
                    </div>
162
                    </div>
157
                </div>
163
                </div>
Lines 235-240 Link Here
235
                                    Is local float group
241
                                    Is local float group
236
                                </label>
242
                                </label>
237
                            </p>
243
                            </p>
244
                            <p>
245
                                <label>
246
                                    <input type="checkbox" id="edit-group-modal-ft_acquisitions" name="ft_acquisitions" value="1" />
247
                                    Use in the acquisitions module
248
                                </label>
249
                            </p>
238
                        </div>
250
                        </div>
239
                    </div>
251
                    </div>
240
                </div>
252
                </div>
Lines 331-337 Link Here
331
                var ft_search_groups_staff = $(this).data("groupFt_search_groups_staff");
343
                var ft_search_groups_staff = $(this).data("groupFt_search_groups_staff");
332
                var ft_local_hold_group = $(this).data("groupFt_local_hold_group");
344
                var ft_local_hold_group = $(this).data("groupFt_local_hold_group");
333
                var ft_local_float_group = $(this).data("groupFt_local_float_group");
345
                var ft_local_float_group = $(this).data("groupFt_local_float_group");
334
                edit_group(id, parent_id, title, description, ft_hide_patron_info, ft_search_groups_opac, ft_search_groups_staff, ft_local_hold_group, ft_limit_item_editing, ft_local_float_group);
346
                var ft_acquisitions = $(this).data("groupFt_acquisitions");
347
                edit_group(id, parent_id, title, description, ft_hide_patron_info, ft_search_groups_opac, ft_search_groups_staff, ft_local_hold_group, ft_limit_item_editing, ft_local_float_group, ft_acquisitions);
335
            });
348
            });
336
349
337
            $(".delete-group").on("click", function (e) {
350
            $(".delete-group").on("click", function (e) {
Lines 368-373 Link Here
368
            $("#add-group-modal-ft_search_groups_staff").prop("checked", false);
381
            $("#add-group-modal-ft_search_groups_staff").prop("checked", false);
369
            $("#add-group-modal-ft_local_hold_group").prop("checked", false);
382
            $("#add-group-modal-ft_local_hold_group").prop("checked", false);
370
            $("#add-group-modal-ft_local_float_group").prop("checked", false);
383
            $("#add-group-modal-ft_local_float_group").prop("checked", false);
384
            $("#add-group-modal-ft_acquisitions").prop("checked", false);
371
            if (parent_id) {
385
            if (parent_id) {
372
                $("#root-group-features-add").hide();
386
                $("#root-group-features-add").hide();
373
            } else {
387
            } else {
Lines 376-382 Link Here
376
            $("#add-group-modal").modal("show");
390
            $("#add-group-modal").modal("show");
377
        }
391
        }
378
392
379
        function edit_group(id, parent_id, title, description, ft_hide_patron_info, ft_search_groups_opac, ft_search_groups_staff, ft_local_hold_group, ft_limit_item_editing, ft_local_float_group) {
393
        function edit_group(id, parent_id, title, description, ft_hide_patron_info, ft_search_groups_opac, ft_search_groups_staff, ft_local_hold_group, ft_limit_item_editing, ft_local_float_group, ft_acquisitions) {
380
            $("#edit-group-modal-id").val(id);
394
            $("#edit-group-modal-id").val(id);
381
            $("#edit-group-modal-title").val(title);
395
            $("#edit-group-modal-title").val(title);
382
            $("#edit-group-modal-description").val(description);
396
            $("#edit-group-modal-description").val(description);
Lines 387-392 Link Here
387
                $("#edit-group-modal-ft_search_groups_staff").prop("checked", false);
401
                $("#edit-group-modal-ft_search_groups_staff").prop("checked", false);
388
                $("#edit-group-modal-ft_local_hold_group").prop("checked", false);
402
                $("#edit-group-modal-ft_local_hold_group").prop("checked", false);
389
                $("#edit-group-modal-ft_local_float_group").prop("checked", false);
403
                $("#edit-group-modal-ft_local_float_group").prop("checked", false);
404
                $("#edit-group-modal-ft_acquisitions").prop("checked", false);
390
                $("#root-group-features-edit").hide();
405
                $("#root-group-features-edit").hide();
391
            } else {
406
            } else {
392
                $("#edit-group-modal-ft_hide_patron_info").prop("checked", ft_hide_patron_info ? true : false);
407
                $("#edit-group-modal-ft_hide_patron_info").prop("checked", ft_hide_patron_info ? true : false);
Lines 395-400 Link Here
395
                $("#edit-group-modal-ft_search_groups_staff").prop("checked", ft_search_groups_staff ? true : false);
410
                $("#edit-group-modal-ft_search_groups_staff").prop("checked", ft_search_groups_staff ? true : false);
396
                $("#edit-group-modal-ft_local_hold_group").prop("checked", ft_local_hold_group ? true : false);
411
                $("#edit-group-modal-ft_local_hold_group").prop("checked", ft_local_hold_group ? true : false);
397
                $("#edit-group-modal-ft_local_float_group").prop("checked", ft_local_float_group ? true : false);
412
                $("#edit-group-modal-ft_local_float_group").prop("checked", ft_local_float_group ? true : false);
413
                $("#edit-group-modal-ft_acquisitions").prop("checked", ft_acquisitions ? true : false);
398
                $("#root-group-features-edit").show();
414
                $("#root-group-features-edit").show();
399
            }
415
            }
400
416
Lines 455-460 Link Here
455
                    [% IF group.ft_local_float_group %]
471
                    [% IF group.ft_local_float_group %]
456
                        <li>Is local float group</li>
472
                        <li>Is local float group</li>
457
                    [% END %]
473
                    [% END %]
474
                    [% IF group.ft_acquisitions %]
475
                        <li>Use in the acquisitions module</li>
476
                    [% END %]
458
                </ul>
477
                </ul>
459
            [% END %]
478
            [% END %]
460
        </td>
479
        </td>
Lines 486-491 Link Here
486
                                data-group-ft_local_hold_group="[% group.ft_local_hold_group | html %]"
505
                                data-group-ft_local_hold_group="[% group.ft_local_hold_group | html %]"
487
                                data-group-ft_limit_item_editing="[% group.ft_limit_item_editing | html %]"
506
                                data-group-ft_limit_item_editing="[% group.ft_limit_item_editing | html %]"
488
                                data-group-ft_local_float_group="[% group.ft_local_float_group | html %]"
507
                                data-group-ft_local_float_group="[% group.ft_local_float_group | html %]"
508
                                data-group-ft_acquisitions="[% group.ft_acquisitions | html %]"
489
                            >
509
                            >
490
                                <i class="fa-solid fa-pencil" aria-hidden="true"></i> Edit
510
                                <i class="fa-solid fa-pencil" aria-hidden="true"></i> Edit
491
                            </a>
511
                            </a>
(-)a/koha-tmpl/intranet-tmpl/prog/js/fetch/acquisition-api-client.js (-1 / +1 lines)
Lines 21-27 export class AcquisitionAPIClient { Link Here
21
                    endpoint: "vendors/" + id,
21
                    endpoint: "vendors/" + id,
22
                    headers: {
22
                    headers: {
23
                        "x-koha-embed":
23
                        "x-koha-embed":
24
                            "aliases,subscriptions+count,interfaces,contacts,contracts,baskets+count,invoices+count,extended_attributes,+strings",
24
                            "aliases,subscriptions+count,interfaces,contacts,contracts,baskets+count,invoices+count,extended_attributes,+strings,lib_group_limits",
25
                    },
25
                    },
26
                }),
26
                }),
27
            getAll: (query, params) =>
27
            getAll: (query, params) =>
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/Main.vue (-4 / +26 lines)
Lines 37-44 import { APIClient } from "../../fetch/api-client.js"; Link Here
37
export default {
37
export default {
38
    setup() {
38
    setup() {
39
        const vendorStore = inject("vendorStore");
39
        const vendorStore = inject("vendorStore");
40
        const { config, authorisedValues } = storeToRefs(vendorStore);
40
        const {
41
        const { loadAuthorisedValues } = vendorStore;
41
            config,
42
            authorisedValues,
43
            user,
44
            currencies,
45
            libraryGroups,
46
            gstValues,
47
        } = storeToRefs(vendorStore);
48
        const { loadAuthorisedValues, setLibraryGroups } = vendorStore;
42
49
43
        const mainStore = inject("mainStore");
50
        const mainStore = inject("mainStore");
44
        const { loading, loaded, setError } = mainStore;
51
        const { loading, loaded, setError } = mainStore;
Lines 55-60 export default { Link Here
55
            config,
62
            config,
56
            loadAuthorisedValues,
63
            loadAuthorisedValues,
57
            authorisedValues,
64
            authorisedValues,
65
            user,
66
            currencies,
67
            libraryGroups,
68
            gstValues,
69
            setLibraryGroups,
58
        };
70
        };
59
    },
71
    },
60
    beforeCreate() {
72
    beforeCreate() {
Lines 65-83 export default { Link Here
65
                const client = APIClient.acquisition;
77
                const client = APIClient.acquisition;
66
                client.config.get("vendors").then(config => {
78
                client.config.get("vendors").then(config => {
67
                    this.userPermissions = config.permissions;
79
                    this.userPermissions = config.permissions;
80
                    const libraryClient = APIClient.libraries;
68
                    this.config.settings.edifact = config.edifact;
81
                    this.config.settings.edifact = config.edifact;
69
                    this.config.settings.ermModule = config.erm_module;
82
                    this.config.settings.ermModule = config.erm_module;
70
                    this.config.settings.marcOrderAutomation =
83
                    this.config.settings.marcOrderAutomation =
71
                        config.marcOrderAutomation;
84
                        config.marcOrderAutomation;
72
                    this.vendorStore.currencies = config.currencies;
85
                    this.vendorStore.currencies = config.currencies;
86
                    this.user.loggedInUser = config.logged_in_user;
87
                    this.user.loggedInUser.loggedInBranch =
88
                        config.logged_in_branch;
73
                    this.vendorStore.gstValues = config.gst_values.map(gv => {
89
                    this.vendorStore.gstValues = config.gst_values.map(gv => {
74
                        return {
90
                        return {
75
                            label: `${Number(gv.option * 100).format_price()}%`,
91
                            label: `${Number(gv.option * 100).format_price()}%`,
76
                            value: gv.option,
92
                            value: gv.option,
77
                        };
93
                        };
78
                    });
94
                    });
79
                    this.loaded();
95
                    libraryClient.libraryGroups.getAll().then(
80
                    this.initialized = true;
96
                        libraryGroups => {
97
                            this.setLibraryGroups(libraryGroups);
98
                            this.loaded();
99
                            this.initialized = true;
100
                        },
101
                        error => {}
102
                    );
81
                });
103
                });
82
            }
104
            }
83
        );
105
        );
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorDetails.vue (-1 / +43 lines)
Lines 66-71 Link Here
66
                    {{ get_lib_from_av("av_lang", vendor.language) }}
66
                    {{ get_lib_from_av("av_lang", vendor.language) }}
67
                </span>
67
                </span>
68
            </li>
68
            </li>
69
            <li v-if="vendor.lib_group_limits.length">
70
                <label>{{ $__("Library group visibility") }}:</label>
71
                <table id="lib_group_visibility_table">
72
                    <thead>
73
                        <tr>
74
                            <th>{{ $__("ID") }}</th>
75
                            <th>{{ $__("Title") }}</th>
76
                        </tr>
77
                    </thead>
78
                    <tbody>
79
                        <tr
80
                            v-for="(libGroup, key) in vendor.lib_group_limits"
81
                            v-bind:key="key"
82
                        >
83
                            <td>{{ libGroup.id }}</td>
84
                            <td>{{ libGroup.title }}</td>
85
                        </tr>
86
                    </tbody>
87
                </table>
88
            </li>
89
            <li v-else>
90
                <label>{{ $__("Library group visibility") }}:</label>
91
                <span>{{ $__("All library groups") }}</span>
92
            </li>
69
            <li v-if="vendor.aliases.length">
93
            <li v-if="vendor.aliases.length">
70
                <label>{{ $__("Aliases") }}:</label>
94
                <label>{{ $__("Aliases") }}:</label>
71
                <ul style="margin-left: 8rem">
95
                <ul style="margin-left: 8rem">
Lines 159-164 Link Here
159
                />
183
                />
160
                <input v-else id="language" v-model="vendor.type" />
184
                <input v-else id="language" v-model="vendor.type" />
161
            </li>
185
            </li>
186
            <li v-if="getVisibleGroups.length">
187
                <label for="lib_group_visibility"
188
                    >{{ $__("Library group visibility") }}:</label
189
                >
190
                <v-select
191
                    id="lib_group_visibility"
192
                    v-model="vendor.lib_group_visibility"
193
                    label="title"
194
                    :reduce="av => av.id"
195
                    :options="getVisibleGroups"
196
                    multiple
197
                />
198
            </li>
162
            <li>
199
            <li>
163
                <label for="vendor_aliases">{{ $__("Aliases") }}:</label>
200
                <label for="vendor_aliases">{{ $__("Aliases") }}:</label>
164
                <input
201
                <input
Lines 193-198 Link Here
193
<script>
230
<script>
194
import { inject } from "vue";
231
import { inject } from "vue";
195
import Link from "../Link.vue";
232
import Link from "../Link.vue";
233
import { storeToRefs } from "pinia";
196
234
197
export default {
235
export default {
198
    props: {
236
    props: {
Lines 201-210 export default { Link Here
201
    },
239
    },
202
    setup() {
240
    setup() {
203
        const vendorStore = inject("vendorStore");
241
        const vendorStore = inject("vendorStore");
204
        const { get_lib_from_av, authorisedValues } = vendorStore;
242
        const { get_lib_from_av, authorisedValues, formatLibraryGroupIds } =
243
            vendorStore;
244
        const { getVisibleGroups } = storeToRefs(vendorStore);
205
        return {
245
        return {
206
            get_lib_from_av,
246
            get_lib_from_av,
207
            authorisedValues,
247
            authorisedValues,
248
            getVisibleGroups,
249
            formatLibraryGroupIds,
208
        };
250
        };
209
    },
251
    },
210
    data() {
252
    data() {
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorFormAdd.vue (+17 lines)
Lines 43-50 import VendorContacts from "./VendorContacts.vue"; Link Here
43
import VendorOrderingInformation from "./VendorOrderingInformation.vue";
43
import VendorOrderingInformation from "./VendorOrderingInformation.vue";
44
import VendorInterfaces from "./VendorInterfaces.vue";
44
import VendorInterfaces from "./VendorInterfaces.vue";
45
import AdditionalFieldsEntry from "../AdditionalFieldsEntry.vue";
45
import AdditionalFieldsEntry from "../AdditionalFieldsEntry.vue";
46
import { inject } from "vue";
46
47
47
export default {
48
export default {
49
    setup() {
50
        const vendorStore = inject("vendorStore");
51
        const { formatLibraryGroupIds } = vendorStore;
52
53
        return {
54
            formatLibraryGroupIds,
55
        };
56
    },
48
    data() {
57
    data() {
49
        return {
58
        return {
50
            vendor: {
59
            vendor: {
Lines 72-77 export default { Link Here
72
                fax: "",
81
                fax: "",
73
                external_id: "",
82
                external_id: "",
74
                payment_method: [],
83
                payment_method: [],
84
                language: "",
85
                lib_group_visibility: [],
75
                aliases: [],
86
                aliases: [],
76
                contacts: [],
87
                contacts: [],
77
                interfaces: [],
88
                interfaces: [],
Lines 114-119 export default { Link Here
114
                        this.vendor.discount = this.vendor.discount.toFixed(1);
125
                        this.vendor.discount = this.vendor.discount.toFixed(1);
115
                    }
126
                    }
116
127
128
                    this.vendor.lib_group_visibility =
129
                        this.formatLibraryGroupIds(vendor.lib_group_visibility);
117
                    this.initialized = true;
130
                    this.initialized = true;
118
                },
131
                },
119
                error => {}
132
                error => {}
Lines 144-149 export default { Link Here
144
            delete vendor.contracts;
157
            delete vendor.contracts;
145
            delete vendor.invoices_count;
158
            delete vendor.invoices_count;
146
            delete vendor._strings;
159
            delete vendor._strings;
160
            delete vendor.lib_group_limits;
147
161
148
            if (!this.discountValid)
162
            if (!this.discountValid)
149
                errors.push(this.$__("Invalid discount value"));
163
                errors.push(this.$__("Invalid discount value"));
Lines 173-178 export default { Link Here
173
                vendor.payment_method = null;
187
                vendor.payment_method = null;
174
            }
188
            }
175
189
190
            const visibility = vendor.lib_group_visibility.join("|");
191
            vendor.lib_group_visibility = visibility;
192
176
            const client = APIClient.acquisition;
193
            const client = APIClient.acquisition;
177
            if (vendorId) {
194
            if (vendorId) {
178
                client.vendors.update(vendor, vendorId).then(
195
                client.vendors.update(vendor, vendorId).then(
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/vendors.js (-5 / +145 lines)
Lines 1-5 Link Here
1
import { defineStore } from "pinia";
1
import { defineStore } from "pinia";
2
import { reactive, toRefs } from "vue";
2
import { reactive, toRefs, computed } from "vue";
3
import { withAuthorisedValueActions } from "../composables/authorisedValues";
3
import { withAuthorisedValueActions } from "../composables/authorisedValues";
4
4
5
export const useVendorStore = defineStore("vendors", () => {
5
export const useVendorStore = defineStore("vendors", () => {
Lines 7-12 export const useVendorStore = defineStore("vendors", () => { Link Here
7
        vendors: [],
7
        vendors: [],
8
        currencies: [],
8
        currencies: [],
9
        gstValues: [],
9
        gstValues: [],
10
        libraryGroups: null,
11
        visibleGroups: null,
12
        user: {
13
            loggedInUser: null,
14
            userflags: null,
15
        },
10
        config: {
16
        config: {
11
            settings: {
17
            settings: {
12
                edifact: false,
18
                edifact: false,
Lines 17-29 export const useVendorStore = defineStore("vendors", () => { Link Here
17
            av_vendor_types: "VENDOR_TYPE",
23
            av_vendor_types: "VENDOR_TYPE",
18
            av_vendor_interface_types: "VENDOR_INTERFACE_TYPE",
24
            av_vendor_interface_types: "VENDOR_INTERFACE_TYPE",
19
            av_vendor_payment_methods: "VENDOR_PAYMENT_METHOD",
25
            av_vendor_payment_methods: "VENDOR_PAYMENT_METHOD",
20
            av_lang: "LANG"
26
            av_lang: "LANG",
21
        },
27
        },
22
    });
28
    });
23
    const sharedActions = withAuthorisedValueActions(store);
29
    const actions = {
30
        ...withAuthorisedValueActions(store),
31
        determineBranch(code) {
32
            if (code) {
33
                return code;
34
            }
35
            const {
36
                loggedInUser: { loggedInBranch, branchcode },
37
            } = store.user;
38
            return loggedInBranch ? loggedInBranch : branchcode;
39
        },
40
        _matchSubGroups(group, filteredGroups, branch, groupsToCheck) {
41
            let matched = false;
42
            if (group.libraries.find(lib => lib.branchcode === branch)) {
43
                if (
44
                    groupsToCheck &&
45
                    groupsToCheck.length &&
46
                    groupsToCheck.includes(group.id)
47
                ) {
48
                    filteredGroups[group.id] = group;
49
                    matched = true;
50
                }
51
                if (!groupsToCheck || groupsToCheck.length === 0) {
52
                    filteredGroups[group.id] = group;
53
                    matched = true;
54
                }
55
            }
56
            if (group.subGroups && group.subGroups.length) {
57
                group.subGroups.forEach(grp => {
58
                    const result = this._matchSubGroups(
59
                        grp,
60
                        filteredGroups,
61
                        branch,
62
                        groupsToCheck
63
                    );
64
                    matched = matched ? matched : result;
65
                });
66
            }
67
            return matched;
68
        },
69
        filterLibGroupsByUsersBranchcode(branchcode, groupsToCheck) {
70
            const branch = this.determineBranch(branchcode);
71
            const filteredGroups = {};
72
            if (!store.libraryGroups) {
73
                return [];
74
            }
75
            store.libraryGroups.forEach(group => {
76
                const matched = this._matchSubGroups(
77
                    group,
78
                    filteredGroups,
79
                    branch,
80
                    groupsToCheck
81
                );
82
                // If a sub group has been matched but the parent level group did not, then we should add the parent level group as well
83
                // This happens when a parent group doesn't have any branchcodes assigned to it, only sub groups
84
                if (
85
                    matched &&
86
                    !Object.keys(filteredGroups).find(id => id === group.id)
87
                ) {
88
                    filteredGroups[group.id] = group;
89
                }
90
            });
91
            return Object.keys(filteredGroups)
92
                .map(key => {
93
                    return filteredGroups[key];
94
                })
95
                .sort((a, b) => a.id - b.id);
96
        },
97
        formatLibraryGroupIds(ids) {
98
            if (!ids) {
99
                return [];
100
            }
101
            const groups = ids.includes("|") ? ids.split("|") : [ids];
102
            const groupIds = groups.map(group => {
103
                return parseInt(group);
104
            });
105
            return groupIds;
106
        },
107
        setLibraryGroups(groups) {
108
            if (!groups?.length) {
109
                return;
110
            }
111
            const topLevelGroups = groups.filter(
112
                group => !group.parent_id && group.ft_acquisitions
113
            );
114
            if (!topLevelGroups?.length) {
115
                return;
116
            }
117
            store.libraryGroups = topLevelGroups.map(group => {
118
                return this._mapLibraryGroup(group, groups);
119
            });
120
        },
121
        _mapLibraryGroup(group, groups) {
122
            const groupInfo = {
123
                id: group.id,
124
                title: group.title,
125
                libraries: [],
126
                subGroups: [],
127
            };
128
            const libsOrSubGroups = groups.filter(
129
                grp => grp.parent_id == group.id
130
            );
131
            libsOrSubGroups.forEach(libOrSubGroup => {
132
                if (libOrSubGroup.branchcode) {
133
                    groupInfo.libraries.push(libOrSubGroup);
134
                } else {
135
                    const subGroupInfo = this._mapLibraryGroup(
136
                        libOrSubGroup,
137
                        groups,
138
                        true
139
                    );
140
                    groupInfo.subGroups.push(subGroupInfo);
141
                }
142
            });
143
            groupInfo.subGroups.forEach(subGroup => {
144
                subGroup.libraries.forEach(lib => {
145
                    if (
146
                        !groupInfo.libraries.find(
147
                            g => g.branchcode === lib.branchcode
148
                        )
149
                    ) {
150
                        groupInfo.libraries.push(lib);
151
                    }
152
                });
153
            });
154
            return groupInfo;
155
        },
156
    };
157
    const getters = {
158
        getVisibleGroups: computed(() => {
159
            return store.visibleGroups?.length
160
                ? store.visibleGroups
161
                : actions.filterLibGroupsByUsersBranchcode();
162
        }),
163
    };
24
164
25
    return {
165
    return {
26
        ...toRefs(store),
166
        ...toRefs(store),
27
        ...sharedActions,
167
        ...actions,
168
        ...getters,
28
    };
169
    };
29
});
170
});
30
- 

Return to bug 38290