395 lines
9.9 KiB
Vue
395 lines
9.9 KiB
Vue
<script>
|
|
import Swal from "sweetalert2";
|
|
import { authenticatedRequest } from "@/components/session/authenticatedRequest.vue";
|
|
import { ObjectsGlobal } from "@/components/session/token/SessionUser/Objects/ObjectsGlobal.vue";
|
|
import { SessionUser } from "@/components/session/token/SessionUser.vue";
|
|
import {ref} from "vue";
|
|
import { getDepartmentName } from "@/components/pagination/departmentTabs.vue";
|
|
|
|
/**
|
|
* The OrderBookings object
|
|
*/
|
|
export const OrderBookings = {
|
|
meta: {
|
|
title: "Order Bookinger",
|
|
icon: "fas fa-list",
|
|
description: "Oversigt over order bookinger",
|
|
endpoint: "/order-bookings",
|
|
labels: {
|
|
single: "orderbooking",
|
|
multiple: "orderbookinger",
|
|
fields: {
|
|
names: {
|
|
customer_number: {
|
|
label: "E-conomic kundenummer",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
columns: {
|
|
id: {
|
|
label: "ID",
|
|
type: "number",
|
|
sortable: true,
|
|
creation: {
|
|
required: false
|
|
}
|
|
},
|
|
customer_number: {
|
|
label: "Kundenummer",
|
|
type: "number",
|
|
sortable: true,
|
|
creation: {
|
|
required: true
|
|
},
|
|
},
|
|
department: {
|
|
label: "Afdeling",
|
|
type: "select",
|
|
sortable: true,
|
|
creation: {
|
|
required: true
|
|
},
|
|
options: async () => {
|
|
return SessionUser.objects.department_notification_sms.columns.department.options()
|
|
}
|
|
},
|
|
reg_1: {
|
|
label: "Reg. 1",
|
|
type: "string",
|
|
sortable: true,
|
|
creation: {
|
|
required: true
|
|
},
|
|
},
|
|
reg_2: {
|
|
label: "Reg. 2",
|
|
type: "string",
|
|
sortable: true,
|
|
creation: {
|
|
required: true
|
|
},
|
|
},
|
|
reg_3: {
|
|
label: "Reg. 3",
|
|
type: "string",
|
|
sortable: true,
|
|
creation: {
|
|
required: true
|
|
},
|
|
},
|
|
datetime: {
|
|
label: "Dato",
|
|
type: "datetime",
|
|
sortable: true,
|
|
creation: {
|
|
required: true
|
|
},
|
|
},
|
|
note: {
|
|
label: "Notat",
|
|
type: "string",
|
|
sortable: true,
|
|
creation: {
|
|
required: false
|
|
},
|
|
},
|
|
reference: {
|
|
label: "Reference",
|
|
type: "string",
|
|
sortable: true,
|
|
creation: {
|
|
required: false
|
|
},
|
|
},
|
|
po: {
|
|
label: "PO Nummer",
|
|
type: "string",
|
|
sortable: true,
|
|
creation: {
|
|
required: false
|
|
},
|
|
},
|
|
pickup: {
|
|
label: "Hentning",
|
|
type: "boolean",
|
|
sortable: true,
|
|
creation: {
|
|
required: false
|
|
},
|
|
},
|
|
items: {
|
|
label: "Varer",
|
|
type: "array",
|
|
sortable: false,
|
|
creation: {
|
|
required: false
|
|
},
|
|
},
|
|
order_id: {
|
|
label: "Order",
|
|
type: "select",
|
|
sortable: true,
|
|
creation: {
|
|
required: false
|
|
},
|
|
options: async (options = { filters: {
|
|
//customer_id: 12345679,
|
|
//department_id: 2
|
|
}, pagination: { limit: 10, page: 1 } }) => {
|
|
return SessionUser.objects.orders.get.list(options).then((orders) => {
|
|
return [
|
|
{ id: null, name: "Ingen" },
|
|
...orders.map((order) => {
|
|
return {
|
|
...order,
|
|
name: `#${order.id} - ${getDepartmentName(order.department_id)} - ${order.created_at}`
|
|
};
|
|
})
|
|
];
|
|
});
|
|
}
|
|
},
|
|
/**
|
|
* status: {
|
|
* label: "Status",
|
|
* type: "select",
|
|
* sortable: true,
|
|
* creation: {
|
|
* required: false
|
|
* },
|
|
* options: async () => {
|
|
* return [
|
|
* { id: 'pending', name: "Afventer" },
|
|
* { id: 'cancelled', name: "Annulleret" },
|
|
* { id: 'completed', name: "Færdig" },
|
|
* ];
|
|
* }
|
|
* },
|
|
*/
|
|
created_at: {
|
|
label: "Oprettet",
|
|
type: "string",
|
|
sortable: true,
|
|
creation: {
|
|
required: false
|
|
},
|
|
},
|
|
deleted_at: {
|
|
label: "Slettet",
|
|
type: "string",
|
|
sortable: true,
|
|
creation: {
|
|
required: false
|
|
},
|
|
},
|
|
},
|
|
add: async (customer_number, department, reg_1, reg_2 = null, reg_3 = null, datetime, note = null, reference = null, po = null, pickup = false, items = []) => {
|
|
return ObjectsGlobal.add.object(
|
|
OrderBookings.meta.endpoint,
|
|
{
|
|
customer_number: parseInt(customer_number),
|
|
department: parseInt(department),
|
|
reg_1,
|
|
reg_2,
|
|
reg_3,
|
|
datetime,
|
|
note,
|
|
reference,
|
|
po,
|
|
pickup,
|
|
items,
|
|
},
|
|
{authenticated: SessionUser.functions.hasToken()}
|
|
);
|
|
},
|
|
set: {
|
|
customer_number: async (id, customer_number) => {
|
|
return ObjectsGlobal.set.column(
|
|
OrderBookings.meta.endpoint,
|
|
id,
|
|
"customer_number",
|
|
parseInt(customer_number)
|
|
)
|
|
},
|
|
department: async (id, department) => {
|
|
return ObjectsGlobal.set.column(
|
|
OrderBookings.meta.endpoint,
|
|
id,
|
|
"department",
|
|
parseInt(department)
|
|
)
|
|
},
|
|
reg_1: async (id, reg_1) => {
|
|
return ObjectsGlobal.set.column(
|
|
OrderBookings.meta.endpoint,
|
|
id,
|
|
"reg_1",
|
|
reg_1
|
|
)
|
|
},
|
|
reg_2: async (id, reg_2) => {
|
|
return ObjectsGlobal.set.column(
|
|
OrderBookings.meta.endpoint,
|
|
id,
|
|
"reg_2",
|
|
reg_2
|
|
)
|
|
},
|
|
reg_3: async (id, reg_3) => {
|
|
return ObjectsGlobal.set.column(
|
|
OrderBookings.meta.endpoint,
|
|
id,
|
|
"reg_3",
|
|
reg_3
|
|
)
|
|
},
|
|
datetime: async (id, datetime) => {
|
|
// Input format: 2025-11-05T13:00
|
|
// Output format: 2025-11-05 13:00:00
|
|
return ObjectsGlobal.set.column(
|
|
OrderBookings.meta.endpoint,
|
|
id,
|
|
"datetime",
|
|
datetime.replace("T", " ") + ":00"
|
|
)
|
|
},
|
|
note: async (id, note) => {
|
|
return ObjectsGlobal.set.column(
|
|
OrderBookings.meta.endpoint,
|
|
id,
|
|
"note",
|
|
note
|
|
)
|
|
},
|
|
reference: async (id, reference) => {
|
|
return ObjectsGlobal.set.column(
|
|
OrderBookings.meta.endpoint,
|
|
id,
|
|
"reference",
|
|
reference
|
|
)
|
|
},
|
|
po: async (id, po) => {
|
|
return ObjectsGlobal.set.column(
|
|
OrderBookings.meta.endpoint,
|
|
id,
|
|
"po",
|
|
po
|
|
)
|
|
},
|
|
pickup: async (id, pickup) => {
|
|
return ObjectsGlobal.set.column(
|
|
OrderBookings.meta.endpoint,
|
|
id,
|
|
"pickup",
|
|
pickup === true || pickup === 1 || pickup === "1" || pickup === "true"
|
|
)
|
|
},
|
|
items: async (id, items) => {
|
|
return ObjectsGlobal.set.column(
|
|
OrderBookings.meta.endpoint,
|
|
id,
|
|
"items",
|
|
items
|
|
)
|
|
},
|
|
order_id: async (id, order_id) => {
|
|
return ObjectsGlobal.set.column(
|
|
OrderBookings.meta.endpoint,
|
|
id,
|
|
"order_id",
|
|
order_id ? parseInt(order_id) : null
|
|
)
|
|
},
|
|
},
|
|
get: {
|
|
single: async (identifier) => {
|
|
return ObjectsGlobal.get.object(OrderBookings.meta.endpoint, identifier, {authenticated: SessionUser.functions.hasToken()});
|
|
},
|
|
all: async (queryParams = {}) => {
|
|
return ObjectsGlobal.get.objects(OrderBookings.meta.endpoint, queryParams, {authenticated: SessionUser.functions.hasToken()});
|
|
},
|
|
list: async (optionsObject = {filters: {}, pagination: {page: 1, limit: 100}, search: ''}) => {
|
|
return ObjectsGlobal.get.list(OrderBookings.meta.endpoint, optionsObject);
|
|
},
|
|
},
|
|
delete: {
|
|
single: async (id) => {
|
|
return ObjectsGlobal.delete.object(
|
|
OrderBookings.meta.endpoint,
|
|
id,
|
|
{ authenticated: SessionUser.functions.hasToken() }
|
|
);
|
|
}
|
|
},
|
|
functions: {
|
|
showDeleteConfirmationModal: async (id, onAfterDelete = null) => {
|
|
return ObjectsGlobal.showDeleteConfirmationModal(
|
|
OrderBookings,
|
|
id,
|
|
onAfterDelete
|
|
);
|
|
},
|
|
complete: async (id, safetySeal = null, onAfterComplete = null) => {
|
|
return ObjectsGlobal.performAction(
|
|
OrderBookings.meta.endpoint,
|
|
id,
|
|
"complete",
|
|
{ safety_seal: parseInt(safetySeal) },
|
|
onAfterComplete
|
|
);
|
|
},
|
|
showCompleteConfirmationModal: async (id, onAfterComplete = null) => {
|
|
// Show a confirmation modal with input for safety seal
|
|
Swal.fire({
|
|
title: `Mark order booking #${id} as completed`,
|
|
text: "Are you sure you want to mark this order booking as completed? Please enter the safety seal number to confirm.",
|
|
input: 'text',
|
|
inputLabel: 'Safety Seal Number',
|
|
inputPlaceholder: 'Enter safety seal number',
|
|
showCancelButton: true,
|
|
confirmButtonText: 'Complete',
|
|
preConfirm: (safetySeal) => {
|
|
if (!safetySeal) {
|
|
Swal.showValidationMessage('Safety seal number is required');
|
|
}
|
|
return safetySeal;
|
|
}
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
return OrderBookings.functions.complete(id, result.value, onAfterComplete);
|
|
}
|
|
});
|
|
}
|
|
},
|
|
/**
|
|
* Show the create object form
|
|
* @param onAfterSubmit
|
|
* @returns {Promise<SweetAlertResult<Awaited<any>>>}
|
|
*/
|
|
showCreateObjectForm: (onAfterSubmit = null) => {
|
|
return ObjectsGlobal.showCreateObjectForm(OrderBookings, onAfterSubmit);
|
|
},
|
|
/**
|
|
* Show the edit object field form
|
|
* @param id
|
|
* @param column
|
|
* @param value
|
|
* @param onAfterSubmit
|
|
* @param options
|
|
* @returns {Promise<SweetAlertResult<Awaited<any>>>}
|
|
*/
|
|
showEditObjectFieldForm: (id, column, value, onAfterSubmit = null, options = { filters: {}, pagination: { limit: 10, page: 1 } }) => {
|
|
return ObjectsGlobal.showEditObjectFieldForm(
|
|
OrderBookings,
|
|
id,
|
|
column,
|
|
value,
|
|
onAfterSubmit,
|
|
options
|
|
);
|
|
}
|
|
};
|
|
</script> |