feat: update shipping zone when re-issuing invoice

This commit is contained in:
Vlad Stan 2023-07-04 18:13:17 +03:00
parent b5aed1224a
commit 02d9fcfbfd
5 changed files with 100 additions and 30 deletions

View file

@ -121,13 +121,6 @@
</div>
<div class="col-3 col-sm-1"></div>
</div>
<div class="row items-center no-wrap q-mb-md">
<div class="col-3 q-pr-lg">Address:</div>
<div class="col-6 col-sm-8 q-pr-lg">
<q-input filled dense readonly disabled v-model.trim="props.row.address" type="text"></q-input>
</div>
<div class="col-3 col-sm-1"></div>
</div>
<div class="row items-center no-wrap q-mb-md">
<div class="col-3 q-pr-lg">Customer Public Key:</div>
@ -137,6 +130,14 @@
<div class="col-3 col-sm-1"></div>
</div>
<div v-if="props.row.address" class="row items-center no-wrap q-mb-md">
<div class="col-3 q-pr-lg">Address:</div>
<div class="col-6 col-sm-8 q-pr-lg">
<q-input filled dense readonly disabled v-model.trim="props.row.address" type="text"></q-input>
</div>
<div class="col-3 col-sm-1"></div>
</div>
<div v-if="props.row.contact.phone" class="row items-center no-wrap q-mb-md">
<div class="col-3 q-pr-lg">Phone:</div>
<div class="col-6 col-sm-8 q-pr-lg">
@ -151,20 +152,29 @@
</div>
<div class="col-3 col-sm-1"></div>
</div>
<div class="row items-center no-wrap q-mb-md">
<div class="col-3 q-pr-lg">Shipping Zone:</div>
<div class="col-6 col-sm-8 q-pr-lg">
<q-select :options="getStallZones(props.row.stall_id)" filled dense emit-value
v-model.trim="props.row.shipping_id" label="Shipping Zones"></q-select>
</div>
<div class="col-3 col-sm-1"></div>
</div>
<div class="row items-center no-wrap q-mb-md">
<div class="col-3 q-pr-lg">Invoice ID:</div>
<div class="col-6 col-sm-8 q-pr-lg">
<q-input filled dense readonly disabled v-model.trim="props.row.invoice_id" type="text"></q-input>
</div>
<div class="col-3">
</div>
</div>
<div class="row items-center no-wrap q-mb-md">
<div class="col-3 q-pr-lg"></div>
<div class="col-9">
<q-btn @click="reissueOrderInvoice(props.row.id)" unelevated color="primary" type="submit" class="float-left" label="Reissue Invoice"></q-btn>
<q-btn @click="reissueOrderInvoice(props.row)" unelevated color="primary" type="submit"
class="float-left" label="Reissue Invoice"></q-btn>
</div>
</div>
</q-td>

View file

@ -17,6 +17,7 @@ async function orderList(path) {
data: function () {
return {
orders: [],
stalls: [],
selectedOrder: null,
shippingMessage: '',
showShipDialog: false,
@ -48,6 +49,7 @@ async function orderList(path) {
id: 'false'
}
],
zoneOptions: [],
ordersTable: {
columns: [
{
@ -205,22 +207,26 @@ async function orderList(path) {
this.search.restoring = false
}
},
reissueOrderInvoice: async function (orderId) {
reissueOrderInvoice: async function (order) {
try {
const { data } = await LNbits.api.request(
'PUT',
`/nostrmarket/api/v1/order/${orderId}/reissue`,
this.adminkey
`/nostrmarket/api/v1/order/reissue`,
this.adminkey,
{
id: order.id,
shipping_id: order.shipping_id
}
)
this.$q.notify({
type: 'positive',
message: 'Order invoice reissued!'
})
data.expanded = order.expanded
const i = this.orders.map(o => o.id).indexOf(orderId)
console.log('### order', i)
const i = this.orders.map(o => o.id).indexOf(order.id)
if (i !== -1) {
this.orders[i] = { ...this.orders[i], ...data}
this.orders[i] = { ...this.orders[i], ...data }
}
} catch (error) {
LNbits.utils.notifyApiError(error)
@ -265,6 +271,44 @@ async function orderList(path) {
order.isNew = false
this.orders = [order]
},
getZones: async function () {
try {
const { data } = await LNbits.api.request(
'GET',
'/nostrmarket/api/v1/zone',
this.inkey
)
return data.map(z => ({
id: z.id,
value: z.id,
label: z.name
? `${z.name} (${z.countries.join(', ')})`
: z.countries.join(', ')
}))
} catch (error) {
LNbits.utils.notifyApiError(error)
}
return []
},
getStalls: async function (pending = false) {
try {
const { data } = await LNbits.api.request(
'GET',
`/nostrmarket/api/v1/stall?pending=${pending}`,
this.inkey
)
return data.map(s => ({ ...s, expanded: false }))
} catch (error) {
LNbits.utils.notifyApiError(error)
}
return []
},
getStallZones: function (stallId) {
const stall = this.stalls.find(s => s.id === stallId)
if (!stall) return []
return this.zoneOptions.filter(z => stall.shipping_zones.find(s => s.id === z.id))
},
showShipOrderDialog: function (order) {
this.selectedOrder = order
this.shippingMessage = order.shipped
@ -312,6 +356,8 @@ async function orderList(path) {
await this.getOrders()
}
await this.getCustomers()
this.zoneOptions = await this.getZones()
this.stalls = await this.getStalls()
}
})
}