@@ -233,8 +283,23 @@ onMounted(() => {
@click="openDetail(movement)"
>
|
- {{ movement.inventory?.name || 'N/A' }}
- {{ movement.inventory?.sku || '' }}
+
+
+
+
+ {{ movement.products.length }} producto(s)
+
+
+
+
+ {{ movement.inventory?.name || 'N/A' }}
+ {{ movement.inventory?.sku || '' }}
+
|
@@ -242,7 +307,12 @@ onMounted(() => {
|
- {{ movement.quantity }}
+
+
+ {{ movement.products.reduce((sum, p) => sum + Number(p.quantity), 0) }}
+
+
+ {{ movement.quantity }}
|
{{ movement.warehouse_from.name }}
@@ -298,6 +368,7 @@ onMounted(() => {
diff --git a/src/pages/POS/Movements/TransferModal.vue b/src/pages/POS/Movements/TransferModal.vue
index 012e7d5..894b793 100644
--- a/src/pages/POS/Movements/TransferModal.vue
+++ b/src/pages/POS/Movements/TransferModal.vue
@@ -19,16 +19,17 @@ const props = defineProps({
const products = ref([]);
const warehouses = ref([]);
const loading = ref(false);
+const selectedProducts = ref([]);
const api = useApi();
/** Formulario */
const form = useForm({
- inventory_id: '',
warehouse_from_id: '',
warehouse_to_id: '',
- quantity: '',
+ reference: '',
notes: '',
+ products: []
});
/** Computed */
@@ -36,16 +37,14 @@ const availableDestinations = computed(() => {
return warehouses.value.filter(wh => wh.id !== Number(form.warehouse_from_id));
});
+const totalQuantity = computed(() => {
+ return selectedProducts.value.reduce((sum, item) => sum + Number(item.quantity), 0);
+});
+
/** Métodos */
const loadData = () => {
loading.value = true;
- api.get(apiURL('inventario'), {
- onSuccess: (data) => {
- products.value = data.products?.data || data.products || [];
- }
- });
-
api.get(apiURL('almacenes'), {
onSuccess: (data) => {
warehouses.value = data.warehouses?.data || data.data || [];
@@ -56,7 +55,42 @@ const loadData = () => {
});
};
+const loadProducts = (warehouseId) => {
+ if (!warehouseId) {
+ products.value = [];
+ return;
+ }
+
+ loading.value = true;
+
+ api.get(apiURL(`inventario/almacen/${warehouseId}`), {
+ onSuccess: (data) => {
+ products.value = data.products || [];
+ },
+ onFinish: () => {
+ loading.value = false;
+ }
+ });
+};
+
+const addProduct = () => {
+ selectedProducts.value.push({
+ inventory_id: '',
+ quantity: 1
+ });
+};
+
+const removeProduct = (index) => {
+ selectedProducts.value.splice(index, 1);
+};
+
const createTransfer = () => {
+ // Preparar datos del formulario
+ form.products = selectedProducts.value.map(item => ({
+ inventory_id: item.inventory_id,
+ quantity: Number(item.quantity)
+ }));
+
form.post(apiURL('movimientos/traspaso'), {
onSuccess: () => {
window.Notify.success('Traspaso registrado correctamente');
@@ -74,6 +108,7 @@ const createTransfer = () => {
const closeModal = () => {
form.reset();
+ selectedProducts.value = [];
emit('close');
};
@@ -81,14 +116,28 @@ const closeModal = () => {
watch(() => props.show, (isShown) => {
if (isShown) {
loadData();
+ if (selectedProducts.value.length === 0) {
+ addProduct();
+ }
}
});
// Limpiar destino si cambia el origen
-watch(() => form.warehouse_from_id, () => {
- if (form.warehouse_to_id && Number(form.warehouse_to_id) === Number(form.warehouse_from_id)) {
+watch(() => form.warehouse_from_id, (newWarehouseId, oldWarehouseId) => {
+ if (form.warehouse_to_id && Number(form.warehouse_to_id) === Number(newWarehouseId)) {
form.warehouse_to_id = '';
}
+
+ // Cargar productos del almacén de origen
+ if (newWarehouseId !== oldWarehouseId) {
+ loadProducts(newWarehouseId);
+
+ // Limpiar productos seleccionados si había alguno y se cambió el almacén
+ if (oldWarehouseId && selectedProducts.value.length > 0) {
+ selectedProducts.value = [];
+ addProduct();
+ }
+ }
});
@@ -117,74 +166,145 @@ watch(() => form.warehouse_from_id, () => {
|