Lines 1-263
Link Here
|
1 |
<template> |
|
|
2 |
<div id="vendor_baskets"> |
3 |
<div v-if="parseInt(basketCount) > 0" class="page-section"> |
4 |
<KohaTable |
5 |
ref="table" |
6 |
v-bind="tableOptions" |
7 |
@addToBasket="addToBasket" |
8 |
@closeBasket="closeBasket" |
9 |
@uncertainPrices="uncertainPrices" |
10 |
></KohaTable> |
11 |
</div> |
12 |
<div v-else class="alert alert-info"> |
13 |
{{ $__("There are no baskets defined") }} |
14 |
</div> |
15 |
</div> |
16 |
</template> |
17 |
|
18 |
<script> |
19 |
import { inject, ref } from "vue" |
20 |
import { storeToRefs } from "pinia" |
21 |
import KohaTable from "../KohaTable.vue" |
22 |
|
23 |
export default { |
24 |
setup() { |
25 |
const patronToHTML = $patron_to_html |
26 |
const formatDate = $date |
27 |
|
28 |
const vendorStore = inject("vendorStore") |
29 |
const { vendors } = storeToRefs(vendorStore) |
30 |
|
31 |
const { setConfirmationDialog, setMessage } = inject("mainStore") |
32 |
|
33 |
const table = ref() |
34 |
|
35 |
return { |
36 |
vendors, |
37 |
table, |
38 |
setConfirmationDialog, |
39 |
setMessage, |
40 |
escape_str, |
41 |
patronToHTML, |
42 |
formatDate, |
43 |
} |
44 |
}, |
45 |
data() { |
46 |
return { |
47 |
fp_config: flatpickr_defaults, |
48 |
initialized: false, |
49 |
tableOptions: { |
50 |
columns: this.getTableColumns(), |
51 |
options: { embed: "orders,creator,basket_group" }, |
52 |
url: () => this.tableURL(), |
53 |
add_filters: true, |
54 |
actions: { |
55 |
"-1": [ |
56 |
{ |
57 |
addToBasket: { |
58 |
text: this.$__("Add to basket"), |
59 |
icon: "fa fa-plus", |
60 |
}, |
61 |
}, |
62 |
{ |
63 |
closeBasket: { |
64 |
text: this.$__("Close basket"), |
65 |
icon: "fa fa-close", |
66 |
should_display: row => |
67 |
row.orders.length > 0 && !row.standing, |
68 |
}, |
69 |
}, |
70 |
{ |
71 |
uncertainPrices: { |
72 |
text: this.$__("Uncertain prices"), |
73 |
icon: "fa fa-question", |
74 |
should_display: row => |
75 |
row.orders.filter(o => o.uncertain_price) |
76 |
.length > 0, |
77 |
}, |
78 |
}, |
79 |
], |
80 |
}, |
81 |
}, |
82 |
} |
83 |
}, |
84 |
methods: { |
85 |
addToBasket({ basket_id }, dt, event) { |
86 |
event.preventDefault() |
87 |
location.href = |
88 |
"/cgi-bin/koha/acqui/basket.pl?basketno=" + basket_id |
89 |
}, |
90 |
closeBasket({ basket_id }, dt, event) { |
91 |
event.preventDefault() |
92 |
location.href = |
93 |
"/cgi-bin/koha/acqui/basket.pl?basketno=" + basket_id |
94 |
}, |
95 |
uncertainPrices({ basket_id }, dt, event) { |
96 |
event.preventDefault() |
97 |
location.href = |
98 |
"/cgi-bin/koha/acqui/uncertainprice.pl?booksellerid=" + |
99 |
basket_id + |
100 |
"&owner=1" |
101 |
}, |
102 |
tableURL() { |
103 |
let url = |
104 |
"/api/v1/acquisitions/baskets?q=" + |
105 |
JSON.stringify({ "me.vendor_id": this.vendorId }) |
106 |
return url |
107 |
}, |
108 |
getTableColumns() { |
109 |
const escape_str = this.escape_str |
110 |
const patronToHTML = this.patronToHTML |
111 |
const formatDate = this.formatDate |
112 |
|
113 |
return [ |
114 |
{ |
115 |
title: __("Name"), |
116 |
data: "me.name:me.basket_id", |
117 |
searchable: true, |
118 |
orderable: true, |
119 |
render(data, type, row, meta) { |
120 |
const name = row.name ? row.name : __("Unnamed basket") |
121 |
return ( |
122 |
'<a href="/cgi-bin/koha/acqui/basket.pl?basketno=' + |
123 |
row.basket_id + |
124 |
'" class="show">' + |
125 |
escape_str(`${name} (#${row.basket_id})`) + |
126 |
"</a>" |
127 |
) |
128 |
}, |
129 |
}, |
130 |
{ |
131 |
title: __("Item count"), |
132 |
data: "name", |
133 |
searchable: false, |
134 |
orderable: true, |
135 |
|
136 |
render(data, type, row, meta) { |
137 |
let count = row.orders.length |
138 |
const cancelledOrders = row.orders.filter( |
139 |
o => o.status == "cancelled" |
140 |
).length |
141 |
if (cancelledOrders) { |
142 |
count += |
143 |
" (" + cancelledOrders + __(" cancelled") + ")" |
144 |
} |
145 |
return count |
146 |
}, |
147 |
}, |
148 |
{ |
149 |
title: __("Bibliographic record count"), |
150 |
data: "name", |
151 |
searchable: false, |
152 |
orderable: true, |
153 |
render(data, type, row, meta) { |
154 |
const recordCount = row.orders.reduce( |
155 |
(acc, order) => { |
156 |
if ( |
157 |
!acc.cancelledBibs.includes( |
158 |
order.biblio_id |
159 |
) && |
160 |
order.status == "cancelled" |
161 |
) { |
162 |
acc.cancelledBibs.push(order.biblio_id) |
163 |
} |
164 |
if (acc.bibNumbers.includes(order.biblio_id)) { |
165 |
return acc |
166 |
} |
167 |
acc.bibNumbers.push(order.biblio_id) |
168 |
return acc |
169 |
}, |
170 |
{ |
171 |
bibNumbers: [], |
172 |
cancelledBibs: [], |
173 |
} |
174 |
) |
175 |
let count = recordCount.bibNumbers.length |
176 |
if (recordCount.cancelledBibs.length) { |
177 |
count += |
178 |
" (" + |
179 |
recordCount.cancelledBibs.length + |
180 |
__(" cancelled") + |
181 |
")" |
182 |
} |
183 |
return count |
184 |
}, |
185 |
}, |
186 |
{ |
187 |
title: __("Items expected"), |
188 |
data: "name", |
189 |
searchable: false, |
190 |
orderable: true, |
191 |
render(data, type, row, meta) { |
192 |
return row.orders.filter( |
193 |
o => !o.date_received && !o.cancellation_date |
194 |
).length |
195 |
}, |
196 |
}, |
197 |
{ |
198 |
title: __("Created by"), |
199 |
data: "creator_id", |
200 |
searchable: false, |
201 |
orderable: true, |
202 |
render(data, type, row, meta) { |
203 |
return patronToHTML(row.creator) |
204 |
}, |
205 |
}, |
206 |
{ |
207 |
title: __("Date"), |
208 |
data: "creation_date", |
209 |
searchable: false, |
210 |
orderable: true, |
211 |
render(data, type, row, meta) { |
212 |
return formatDate(row.creation_date) |
213 |
}, |
214 |
}, |
215 |
{ |
216 |
title: __("Basket group"), |
217 |
data: "basket_group_id", |
218 |
searchable: false, |
219 |
orderable: true, |
220 |
render(data, type, row, meta) { |
221 |
return row.basket_group ? row.basket_group.name : "" |
222 |
}, |
223 |
}, |
224 |
{ |
225 |
title: __("Internal note"), |
226 |
data: "note", |
227 |
searchable: false, |
228 |
orderable: true, |
229 |
}, |
230 |
{ |
231 |
title: __("Closed"), |
232 |
data: "close_date", |
233 |
searchable: false, |
234 |
orderable: true, |
235 |
render(data, type, row, meta) { |
236 |
return formatDate(row.close_date) |
237 |
}, |
238 |
}, |
239 |
] |
240 |
}, |
241 |
}, |
242 |
components: { KohaTable }, |
243 |
props: { |
244 |
basketCount: { |
245 |
type: String, |
246 |
default: "0", |
247 |
}, |
248 |
vendorId: { |
249 |
type: Number, |
250 |
}, |
251 |
}, |
252 |
name: "VendorBaskets", |
253 |
emits: ["select-vendor", "close"], |
254 |
} |
255 |
</script> |
256 |
|
257 |
<style scoped> |
258 |
.filters > label[for="by_mine_filter"], |
259 |
.filters > input[type="checkbox"], |
260 |
.filters > input[type="button"] { |
261 |
margin-left: 1rem; |
262 |
} |
263 |
</style> |