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

(-)a/acqui/vendors.pl (-5 / +6 lines)
Lines 39-49 my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user( Link Here
39
my @gst_values = map { option => $_ + 0.0 }, split( '\|', C4::Context->preference("TaxRates") );
39
my @gst_values = map { option => $_ + 0.0 }, split( '\|', C4::Context->preference("TaxRates") );
40
40
41
$template->param(
41
$template->param(
42
    currencies  => Koha::Acquisition::Currencies->search->unblessed,
42
    currencies       => Koha::Acquisition::Currencies->search->unblessed,
43
    gst_values  => \@gst_values,
43
    gst_values       => \@gst_values,
44
    edifact     => C4::Context->preference('EDIFACT'),
44
    edifact          => C4::Context->preference('EDIFACT'),
45
    marc_orders => C4::Context->preference('MarcOrderingAutomation'),
45
    marc_orders      => C4::Context->preference('MarcOrderingAutomation'),
46
    erm_module  => C4::Context->preference('ERMModule')
46
    erm_module       => C4::Context->preference('ERMModule'),
47
    logged_in_branch => { branchcode => C4::Context::mybranch },
47
);
48
);
48
49
49
output_html_with_http_headers $query, $cookie, $template->output;
50
output_html_with_http_headers $query, $cookie, $template->output;
(-)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/paths/acquisitions_vendors.yaml (+1 lines)
Lines 158-163 Link Here
158
            - contracts
158
            - contracts
159
            - extended_attributes
159
            - extended_attributes
160
            - +strings
160
            - +strings
161
            - lib_group_limits
161
        collectionFormat: csv
162
        collectionFormat: csv
162
    produces:
163
    produces:
163
      - application/json
164
      - application/json
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/vendors.tt (+2 lines)
Lines 36-41 Link Here
36
            const edifact = [% To.json(edifact) | $raw %];
36
            const edifact = [% To.json(edifact) | $raw %];
37
            const marcOrderAutomation = [% To.json(marc_orders) | $raw %];
37
            const marcOrderAutomation = [% To.json(marc_orders) | $raw %];
38
            const ermModule = [% To.json(erm_module) | $raw %];
38
            const ermModule = [% To.json(erm_module) | $raw %];
39
            const loggedInUser = [% To.json(logged_in_user.unblessed) | $raw %];
40
            const loggedInBranch = [% To.json(logged_in_branch) | $raw %];
39
        </script>
41
        </script>
40
        [% Asset.js("js/vue/dist/acquisitions.js") | $raw %]
42
        [% Asset.js("js/vue/dist/acquisitions.js") | $raw %]
41
        [% INCLUDE 'select2.inc' %]
43
        [% INCLUDE 'select2.inc' %]
(-)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 12-18 export class AcquisitionAPIClient { Link Here
12
                    endpoint: "vendors/" + id,
12
                    endpoint: "vendors/" + id,
13
                    headers: {
13
                    headers: {
14
                        "x-koha-embed":
14
                        "x-koha-embed":
15
                            "aliases,subscriptions+count,interfaces,contacts,contracts,baskets,extended_attributes,+strings",
15
                            "aliases,subscriptions+count,interfaces,contacts,contracts,baskets,extended_attributes,+strings,lib_group_limits",
16
                    },
16
                    },
17
                }),
17
                }),
18
            getAll: (query, params) =>
18
            getAll: (query, params) =>
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/Main.vue (-15 / +37 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 63-81 export default { Link Here
63
        this.loadAuthorisedValues(this.authorisedValues, this.vendorStore).then(
75
        this.loadAuthorisedValues(this.authorisedValues, this.vendorStore).then(
64
            () => {
76
            () => {
65
                this.loadUserPermissions().then(() => {
77
                this.loadUserPermissions().then(() => {
66
                    this.config.settings.edifact = edifact;
78
                    const libraryClient = APIClient.libraries;
67
                    this.config.settings.ermModule = ermModule;
79
                    libraryClient.libraryGroups.getAll().then(
68
                    this.config.settings.marcOrderAutomation =
80
                        libraryGroups => {
69
                        marcOrderAutomation;
81
                            this.setLibraryGroups(libraryGroups);
70
                    this.vendorStore.currencies = currencies;
82
                            this.config.settings.edifact = edifact;
71
                    this.vendorStore.gstValues = gstValues.map(gv => {
83
                            this.config.settings.ermModule = ermModule;
72
                        return {
84
                            this.config.settings.marcOrderAutomation =
73
                            label: `${Number(gv.option * 100).format_price()}%`,
85
                                marcOrderAutomation;
74
                            value: gv.option,
86
                            this.vendorStore.currencies = currencies;
75
                        };
87
                            this.user.loggedInUser = loggedInUser;
76
                    });
88
                            this.user.loggedInUser.loggedInBranch =
77
                    this.loaded();
89
                                loggedInBranch.branchcode;
78
                    this.initialized = true;
90
                            this.vendorStore.gstValues = gstValues.map(gv => {
91
                                return {
92
                                    label: `${Number(gv.option * 100).format_price()}%`,
93
                                    value: gv.option,
94
                                };
95
                            });
96
                            this.loaded();
97
                            this.initialized = true;
98
                        },
99
                        error => {}
100
                    );
79
                });
101
                });
80
            }
102
            }
81
        );
103
        );
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorDetails.vue (-1 / +43 lines)
Lines 59-64 Link Here
59
                    {{ get_lib_from_av("av_lang", vendor.language) }}
59
                    {{ get_lib_from_av("av_lang", vendor.language) }}
60
                </span>
60
                </span>
61
            </li>
61
            </li>
62
            <li v-if="vendor.lib_group_limits.length">
63
                <label>{{ $__("Library group visibility") }}:</label>
64
                <table id="lib_group_visibility_table">
65
                    <thead>
66
                        <tr>
67
                            <th>{{ $__("ID") }}</th>
68
                            <th>{{ $__("Title") }}</th>
69
                        </tr>
70
                    </thead>
71
                    <tbody>
72
                        <tr
73
                            v-for="(libGroup, key) in vendor.lib_group_limits"
74
                            v-bind:key="key"
75
                        >
76
                            <td>{{ libGroup.id }}</td>
77
                            <td>{{ libGroup.title }}</td>
78
                        </tr>
79
                    </tbody>
80
                </table>
81
            </li>
82
            <li v-else>
83
                <label>{{ $__("Library group visibility") }}:</label>
84
                <span>{{ $__("All library groups") }}</span>
85
            </li>
62
            <li v-if="vendor.aliases.length">
86
            <li v-if="vendor.aliases.length">
63
                <label>{{ $__("Aliases") }}:</label>
87
                <label>{{ $__("Aliases") }}:</label>
64
                <ul style="margin-left: 8rem">
88
                <ul style="margin-left: 8rem">
Lines 151-156 Link Here
151
                    :options="authorisedValues.av_lang"
175
                    :options="authorisedValues.av_lang"
152
                />
176
                />
153
            </li>
177
            </li>
178
            <li v-if="getVisibleGroups.length">
179
                <label for="lib_group_visibility"
180
                    >{{ $__("Library group visibility") }}:</label
181
                >
182
                <v-select
183
                    id="lib_group_visibility"
184
                    v-model="vendor.lib_group_visibility"
185
                    label="title"
186
                    :reduce="av => av.id"
187
                    :options="getVisibleGroups"
188
                    multiple
189
                />
190
            </li>
154
            <li>
191
            <li>
155
                <label for="vendor_aliases">{{ $__("Aliases") }}:</label>
192
                <label for="vendor_aliases">{{ $__("Aliases") }}:</label>
156
                <input id="vendor_aliases" v-model="newAlias" />
193
                <input id="vendor_aliases" v-model="newAlias" />
Lines 181-186 Link Here
181
<script>
218
<script>
182
import { inject } from "vue";
219
import { inject } from "vue";
183
import ToolbarButton from "../ToolbarButton.vue";
220
import ToolbarButton from "../ToolbarButton.vue";
221
import { storeToRefs } from "pinia";
184
222
185
export default {
223
export default {
186
    props: {
224
    props: {
Lines 189-198 export default { Link Here
189
    },
227
    },
190
    setup() {
228
    setup() {
191
        const vendorStore = inject("vendorStore");
229
        const vendorStore = inject("vendorStore");
192
        const { get_lib_from_av, authorisedValues } = vendorStore;
230
        const { get_lib_from_av, authorisedValues, formatLibraryGroupIds } =
231
            vendorStore;
232
        const { getVisibleGroups } = storeToRefs(vendorStore);
193
        return {
233
        return {
194
            get_lib_from_av,
234
            get_lib_from_av,
195
            authorisedValues,
235
            authorisedValues,
236
            getVisibleGroups,
237
            formatLibraryGroupIds,
196
        };
238
        };
197
    },
239
    },
198
    data() {
240
    data() {
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorFormAdd.vue (+16 lines)
Lines 39-46 import VendorInterfaces from "./VendorInterfaces.vue"; Link Here
39
import Toolbar from "../Toolbar.vue";
39
import Toolbar from "../Toolbar.vue";
40
import ToolbarButton from "../ToolbarButton.vue";
40
import ToolbarButton from "../ToolbarButton.vue";
41
import AdditionalFieldsEntry from "../AdditionalFieldsEntry.vue";
41
import AdditionalFieldsEntry from "../AdditionalFieldsEntry.vue";
42
import { inject } from "vue";
42
43
43
export default {
44
export default {
45
    setup() {
46
        const vendorStore = inject("vendorStore");
47
        const { formatLibraryGroupIds } = vendorStore;
48
49
        return {
50
            formatLibraryGroupIds,
51
        };
52
    },
44
    data() {
53
    data() {
45
        return {
54
        return {
46
            vendor: {
55
            vendor: {
Lines 69-74 export default { Link Here
69
                external_id: "",
78
                external_id: "",
70
                payment_method: [],
79
                payment_method: [],
71
                language: "",
80
                language: "",
81
                lib_group_visibility: [],
72
                aliases: [],
82
                aliases: [],
73
                contacts: [],
83
                contacts: [],
74
                interfaces: [],
84
                interfaces: [],
Lines 101-106 export default { Link Here
101
                    this.vendor.payment_method = vendor.payment_method
111
                    this.vendor.payment_method = vendor.payment_method
102
                        ? vendor.payment_method.split("|")
112
                        ? vendor.payment_method.split("|")
103
                        : [];
113
                        : [];
114
                    this.vendor.lib_group_visibility =
115
                        this.formatLibraryGroupIds(vendor.lib_group_visibility);
104
                    this.initialized = true;
116
                    this.initialized = true;
105
                },
117
                },
106
                error => {}
118
                error => {}
Lines 126-131 export default { Link Here
126
            delete vendor.physical;
138
            delete vendor.physical;
127
            delete vendor.subscriptions_count;
139
            delete vendor.subscriptions_count;
128
            delete vendor._strings;
140
            delete vendor._strings;
141
            delete vendor.lib_group_limits;
129
142
130
            vendor.contacts = this.checkContactOrInterface(
143
            vendor.contacts = this.checkContactOrInterface(
131
                vendor.contacts.map(
144
                vendor.contacts.map(
Lines 146-151 export default { Link Here
146
                vendor.payment_method = null;
159
                vendor.payment_method = null;
147
            }
160
            }
148
161
162
            const visibility = vendor.lib_group_visibility.join("|");
163
            vendor.lib_group_visibility = visibility;
164
149
            const client = APIClient.acquisition;
165
            const client = APIClient.acquisition;
150
            if (vendorId) {
166
            if (vendorId) {
151
                client.vendors.update(vendor, vendorId).then(
167
                client.vendors.update(vendor, vendorId).then(
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/vendors.js (-1 / +138 lines)
Lines 10-15 export const useVendorStore = defineStore("vendors", { Link Here
10
        vendors: [],
10
        vendors: [],
11
        currencies: [],
11
        currencies: [],
12
        gstValues: [],
12
        gstValues: [],
13
        libraryGroups: null,
14
        visibleGroups: null,
15
        user: {
16
            loggedInUser: null,
17
            userflags: null,
18
        },
13
        config: {
19
        config: {
14
            settings: {
20
            settings: {
15
                edifact: false,
21
                edifact: false,
Lines 30-34 export const useVendorStore = defineStore("vendors", { Link Here
30
        map_av_dt_filter(arr_name) {
36
        map_av_dt_filter(arr_name) {
31
            return map_av_dt_filter_handler(arr_name, this);
37
            return map_av_dt_filter_handler(arr_name, this);
32
        },
38
        },
39
        determineBranch(code) {
40
            if (code) {
41
                return code;
42
            }
43
            const {
44
                loggedInUser: { loggedInBranch, branchcode },
45
            } = this.user;
46
            return loggedInBranch ? loggedInBranch : branchcode;
47
        },
48
        _matchSubGroups(group, filteredGroups, branch, groupsToCheck) {
49
            let matched = false;
50
            if (group.libraries.find(lib => lib.branchcode === branch)) {
51
                if (
52
                    groupsToCheck &&
53
                    groupsToCheck.length &&
54
                    groupsToCheck.includes(group.id)
55
                ) {
56
                    filteredGroups[group.id] = group;
57
                    matched = true;
58
                }
59
                if (!groupsToCheck || groupsToCheck.length === 0) {
60
                    filteredGroups[group.id] = group;
61
                    matched = true;
62
                }
63
            }
64
            if (group.subGroups && group.subGroups.length) {
65
                group.subGroups.forEach(grp => {
66
                    const result = this._matchSubGroups(
67
                        grp,
68
                        filteredGroups,
69
                        branch,
70
                        groupsToCheck
71
                    );
72
                    matched = matched ? matched : result;
73
                });
74
            }
75
            return matched;
76
        },
77
        filterLibGroupsByUsersBranchcode(branchcode, groupsToCheck) {
78
            const branch = this.determineBranch(branchcode);
79
            const filteredGroups = {};
80
            if (!this.libraryGroups) {
81
                return [];
82
            }
83
            this.libraryGroups.forEach(group => {
84
                const matched = this._matchSubGroups(
85
                    group,
86
                    filteredGroups,
87
                    branch,
88
                    groupsToCheck
89
                );
90
                // If a sub group has been matched but the parent level group did not, then we should add the parent level group as well
91
                // This happens when a parent group doesn't have any branchcodes assigned to it, only sub groups
92
                if (
93
                    matched &&
94
                    !Object.keys(filteredGroups).find(id => id === group.id)
95
                ) {
96
                    filteredGroups[group.id] = group;
97
                }
98
            });
99
            return Object.keys(filteredGroups)
100
                .map(key => {
101
                    return filteredGroups[key];
102
                })
103
                .sort((a, b) => a.id - b.id);
104
        },
105
        formatLibraryGroupIds(ids) {
106
            if (!ids) {
107
                return [];
108
            }
109
            const groups = ids.includes("|") ? ids.split("|") : [ids];
110
            const groupIds = groups.map(group => {
111
                return parseInt(group);
112
            });
113
            return groupIds;
114
        },
115
        setLibraryGroups(groups) {
116
            if (!groups?.length) {
117
                return;
118
            }
119
            const topLevelGroups = groups.filter(
120
                group => !group.parent_id && group.ft_acquisitions
121
            );
122
            if (!topLevelGroups?.length) {
123
                return;
124
            }
125
            this.libraryGroups = topLevelGroups.map(group => {
126
                return this._mapLibraryGroup(group, groups);
127
            });
128
        },
129
        _mapLibraryGroup(group, groups) {
130
            const groupInfo = {
131
                id: group.id,
132
                title: group.title,
133
                libraries: [],
134
                subGroups: [],
135
            };
136
            const libsOrSubGroups = groups.filter(
137
                grp => grp.parent_id == group.id
138
            );
139
            libsOrSubGroups.forEach(libOrSubGroup => {
140
                if (libOrSubGroup.branchcode) {
141
                    groupInfo.libraries.push(libOrSubGroup);
142
                } else {
143
                    const subGroupInfo = this._mapLibraryGroup(
144
                        libOrSubGroup,
145
                        groups,
146
                        true
147
                    );
148
                    groupInfo.subGroups.push(subGroupInfo);
149
                }
150
            });
151
            groupInfo.subGroups.forEach(subGroup => {
152
                subGroup.libraries.forEach(lib => {
153
                    if (
154
                        !groupInfo.libraries.find(
155
                            g => g.branchcode === lib.branchcode
156
                        )
157
                    ) {
158
                        groupInfo.libraries.push(lib);
159
                    }
160
                });
161
            });
162
            return groupInfo;
163
        },
164
    },
165
    getters: {
166
        getVisibleGroups() {
167
            return this.visibleGroups?.length
168
                ? this.visibleGroups
169
                : this.filterLibGroupsByUsersBranchcode();
170
        },
33
    },
171
    },
34
});
172
});
35
- 

Return to bug 38290