diff --git a/src/components/VnTable/VnTable.vue b/src/components/VnTable/VnTable.vue
index 5d7b74fab..7c1d6a3ae 100644
--- a/src/components/VnTable/VnTable.vue
+++ b/src/components/VnTable/VnTable.vue
@@ -53,6 +53,10 @@ const $props = defineProps({
type: Boolean,
default: true,
},
+ bottom: {
+ type: Object,
+ default: null,
+ },
cardClass: {
type: String,
default: 'flex-one',
@@ -522,7 +526,24 @@ function handleOnDataSaved(_, res) {
-
+
+
+ createAsDialog
+ ? (showForm = !showForm)
+ : handleOnDataSaved(create)
+ "
+ class="fill-icon-on-hover"
+ color="primary"
+ name="add_circle"
+ size="sm"
+ shortcut="+"
+ />
+
+ {{ createForm.title }}
+
+
route.params.id,
@@ -219,6 +216,7 @@ const addSale = async (sale) => {
sale.item = newSale.item;
notify('globals.dataSaved', 'positive');
+ window.location.reload();
} catch (err) {
console.error('Error adding sale', err);
}
@@ -427,18 +425,70 @@ onMounted(async () => {
stateStore.rightDrawer = true;
getConfig();
getSales();
+ getItems();
});
onUnmounted(() => (stateStore.rightDrawer = false));
-async function save(item) {
- const { data } = await axios.post(`Tickets/${route.params.id}/addSale`, {
- id: route.params.id,
- barcode: item.itemFk,
- quantity: parseInt(item.quantity),
- });
- if (data) window.location.reload();
+const items = ref([]);
+const newRow = ref({});
+
+async function getItems() {
+ const { data } = await axios.get(`Items/withName`);
+ items.value = data;
}
+
+const updateItem = (row) => {
+ const selectedItem = items.value.find((item) => item.id === row.itemFk);
+ if (selectedItem) {
+ row.item = selectedItem;
+ row.itemFk = selectedItem.id;
+ row.price = selectedItem.price;
+ row.discount = 0;
+ row.quantity = 0;
+ row.amount = row.price * row.quantity;
+ }
+ endNewRow(selectedItem);
+};
+
+function handleOnDataSave({ CrudModelRef }) {
+ const { copy } = addRow(CrudModelRef.formData);
+ CrudModelRef.insert(copy);
+}
+
+const addRow = (original = null) => {
+ let copy = null;
+ if (!original) {
+ copy = { isNew: true };
+ } else {
+ copy = {
+ itemFk: original.itemFk,
+ item: original.item,
+ quantity: original.quantity,
+ price: original.price,
+ discount: original.discount,
+ amount: original.amount,
+ isNew: true,
+ };
+ }
+ newRow.value = copy;
+ return { original, copy };
+};
+
+const endNewRow = (row) => {
+ if (row.itemFk && row.quantity) {
+ row.isNew = false;
+ }
+};
+
+watch(
+ () => newRow.value.itemFk,
+ (newItemFk) => {
+ if (newItemFk) {
+ updateItem(newRow.value);
+ }
+ }
+);
@@ -566,6 +616,16 @@ async function save(item) {
:column-search="false"
:disable-option="{ card: true }"
auto-load
+ :create="{
+ onDataSaved: handleOnDataSave,
+ }"
+ :create-as-dialog="false"
+ :crud-model="{
+ paginate: false,
+ }"
+ :default-remove="false"
+ :default-reset="false"
+ :default-save="false"
>
-
+
+
+
+
+
+ {{ scope.opt?.id }} - {{ scope.opt?.name }}
+
+
+
+
+
{{ row?.itemFk }}
@@ -638,34 +717,22 @@ async function save(item) {
{{ row?.item?.subName.toUpperCase() }}
-
+
-
-
-
-
- #{{ scope.opt?.id }}
- {{ scope.opt?.name }}
-
-
-
-
+
@@ -713,58 +780,9 @@ async function save(item) {
{{ toCurrency(row.quantity * row.price) }}
-
-
-
- {{ t('Add item') }}
-
-
-
-
-
-
-
-
-
-
-
-
+
{{ t('Add item to basket') }}