update
This commit is contained in:
189
iadmin/themes/new-theme/js/app/pages/stock/store/actions.js
Normal file
189
iadmin/themes/new-theme/js/app/pages/stock/store/actions.js
Normal file
@@ -0,0 +1,189 @@
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
import Vue from 'vue';
|
||||
import VueResource from 'vue-resource';
|
||||
import * as types from '@app/pages/stock/store/mutation-types';
|
||||
import {showGrowl} from '@app/utils/growl';
|
||||
import {EventBus} from '@app/utils/event-bus';
|
||||
|
||||
Vue.use(VueResource);
|
||||
|
||||
export const getStock = ({commit}, payload) => {
|
||||
const url = window.data.apiStockUrl;
|
||||
Vue.http.get(url, {
|
||||
params: {
|
||||
order: payload.order,
|
||||
page_size: payload.page_size,
|
||||
page_index: payload.page_index,
|
||||
keywords: payload.keywords ? payload.keywords : [],
|
||||
supplier_id: payload.suppliers ? payload.suppliers : [],
|
||||
category_id: payload.categories ? payload.categories : [],
|
||||
active: payload.active !== 'null' ? payload.active : [],
|
||||
low_stock: payload.low_stock,
|
||||
},
|
||||
}).then((response) => {
|
||||
commit(types.LOADING_STATE, false);
|
||||
commit(types.SET_TOTAL_PAGES, response.headers.get('Total-Pages'));
|
||||
commit(types.ADD_PRODUCTS, response.body);
|
||||
}, (error) => {
|
||||
showGrowl('error', error.statusText);
|
||||
});
|
||||
};
|
||||
|
||||
export const getSuppliers = ({commit}) => {
|
||||
const url = window.data.suppliersUrl;
|
||||
Vue.http.get(url).then((response) => {
|
||||
commit(types.SET_SUPPLIERS, response.body);
|
||||
}, (error) => {
|
||||
showGrowl('error', error.statusText);
|
||||
});
|
||||
};
|
||||
|
||||
export const getCategories = ({commit}) => {
|
||||
const url = window.data.categoriesUrl;
|
||||
Vue.http.get(url).then((response) => {
|
||||
commit(types.SET_CATEGORIES, response.body);
|
||||
}, (error) => {
|
||||
showGrowl('error', error.statusText);
|
||||
});
|
||||
};
|
||||
|
||||
export const getMovements = ({commit}, payload) => {
|
||||
const url = window.data.apiMovementsUrl;
|
||||
|
||||
Vue.http.get(url, {
|
||||
params: {
|
||||
order: payload.order,
|
||||
page_size: payload.page_size,
|
||||
page_index: payload.page_index,
|
||||
keywords: payload.keywords ? payload.keywords : [],
|
||||
supplier_id: payload.suppliers ? payload.suppliers : [],
|
||||
category_id: payload.categories ? payload.categories : [],
|
||||
id_stock_mvt_reason: payload.id_stock_mvt_reason ? payload.id_stock_mvt_reason : [],
|
||||
id_employee: payload.id_employee ? payload.id_employee : [],
|
||||
date_add: payload.date_add ? payload.date_add : [],
|
||||
},
|
||||
}).then((response) => {
|
||||
commit(types.LOADING_STATE, false);
|
||||
commit(types.SET_TOTAL_PAGES, response.headers.get('Total-Pages'));
|
||||
commit(types.SET_MOVEMENTS, response.body);
|
||||
}, (error) => {
|
||||
showGrowl('error', error.statusText);
|
||||
});
|
||||
};
|
||||
|
||||
export const getTranslations = ({commit}) => {
|
||||
const url = window.data.translationUrl;
|
||||
Vue.http.get(url).then((response) => {
|
||||
commit(types.SET_TRANSLATIONS, response.body);
|
||||
commit(types.APP_IS_READY);
|
||||
}, (error) => {
|
||||
showGrowl('error', error.statusText);
|
||||
});
|
||||
};
|
||||
|
||||
export const getEmployees = ({commit}) => {
|
||||
const url = window.data.employeesUrl;
|
||||
Vue.http.get(url).then((response) => {
|
||||
commit(types.SET_EMPLOYEES_LIST, response.body);
|
||||
}, (error) => {
|
||||
showGrowl('error', error.statusText);
|
||||
});
|
||||
};
|
||||
|
||||
export const getMovementsTypes = ({commit}) => {
|
||||
const url = window.data.movementsTypesUrl;
|
||||
Vue.http.get(url).then((response) => {
|
||||
commit(types.SET_MOVEMENTS_TYPES, response.body);
|
||||
}, (error) => {
|
||||
showGrowl('error', error.statusText);
|
||||
});
|
||||
};
|
||||
|
||||
export const updateOrder = ({commit}, order) => {
|
||||
commit(types.UPDATE_ORDER, order);
|
||||
};
|
||||
|
||||
export const updatePageIndex = ({commit}, pageIndex) => {
|
||||
commit(types.SET_PAGE_INDEX, pageIndex);
|
||||
};
|
||||
|
||||
export const updateKeywords = ({commit}, keywords) => {
|
||||
commit(types.UPDATE_KEYWORDS, keywords);
|
||||
};
|
||||
|
||||
export const isLoading = ({commit}) => {
|
||||
commit(types.LOADING_STATE, true);
|
||||
};
|
||||
|
||||
export const updateProductQty = ({commit}, payload) => {
|
||||
commit(types.UPDATE_PRODUCT_QTY, payload);
|
||||
};
|
||||
|
||||
export const updateQtyByProductId = ({commit}, payload) => {
|
||||
const {url} = payload;
|
||||
const {delta} = payload;
|
||||
|
||||
Vue.http.post(url, {
|
||||
delta,
|
||||
}).then((res) => {
|
||||
commit(types.UPDATE_PRODUCT, res.body);
|
||||
EventBus.$emit('displayBulkAlert', 'success');
|
||||
}, (error) => {
|
||||
showGrowl('error', error.statusText);
|
||||
});
|
||||
};
|
||||
|
||||
export const updateQtyByProductsId = ({commit, state}) => {
|
||||
const url = state.editBulkUrl;
|
||||
const productsQty = state.productsToUpdate;
|
||||
|
||||
Vue.http.post(url, productsQty).then((res) => {
|
||||
commit(types.UPDATE_PRODUCTS_QTY, res.body);
|
||||
EventBus.$emit('displayBulkAlert', 'success');
|
||||
}, (error) => {
|
||||
showGrowl('error', error.statusText);
|
||||
});
|
||||
};
|
||||
|
||||
export const updateBulkEditQty = ({commit}, value) => {
|
||||
commit(types.UPDATE_BULK_EDIT_QTY, value);
|
||||
};
|
||||
|
||||
export const addProductToUpdate = ({commit}, product) => {
|
||||
commit(types.ADD_PRODUCT_TO_UPDATE, product);
|
||||
};
|
||||
|
||||
export const removeProductToUpdate = ({commit}, product) => {
|
||||
commit(types.REMOVE_PRODUCT_TO_UPDATE, product);
|
||||
};
|
||||
|
||||
export const addSelectedProduct = ({commit}, product) => {
|
||||
commit(types.ADD_SELECTED_PRODUCT, product);
|
||||
};
|
||||
|
||||
export const removeSelectedProduct = ({commit}, product) => {
|
||||
commit(types.REMOVE_SELECTED_PRODUCT, product);
|
||||
};
|
||||
95
iadmin/themes/new-theme/js/app/pages/stock/store/index.js
Normal file
95
iadmin/themes/new-theme/js/app/pages/stock/store/index.js
Normal file
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
import Vue from 'vue';
|
||||
import Vuex from 'vuex';
|
||||
import _ from 'lodash';
|
||||
import * as actions from './actions';
|
||||
import mutations from './mutations';
|
||||
|
||||
Vue.use(Vuex);
|
||||
|
||||
// root state object.
|
||||
|
||||
const state = {
|
||||
order: '',
|
||||
pageIndex: 1,
|
||||
totalPages: 0,
|
||||
productsPerPage: 30,
|
||||
products: [],
|
||||
hasQty: false,
|
||||
keywords: [],
|
||||
suppliers: {
|
||||
data: [],
|
||||
},
|
||||
categories: [],
|
||||
categoryList: [],
|
||||
movements: [],
|
||||
employees: [],
|
||||
movementsTypes: [],
|
||||
translations: {},
|
||||
isLoading: false,
|
||||
isReady: false,
|
||||
editBulkUrl: '',
|
||||
bulkEditQty: null,
|
||||
productsToUpdate: [],
|
||||
selectedProducts: [],
|
||||
};
|
||||
|
||||
// getters are functions
|
||||
const getters = {
|
||||
suppliers(rootState) {
|
||||
function convert(suppliers) {
|
||||
suppliers.forEach((supplier) => {
|
||||
supplier.id = supplier.supplier_id;
|
||||
});
|
||||
return suppliers;
|
||||
}
|
||||
return convert(rootState.suppliers.data);
|
||||
},
|
||||
categories(rootState) {
|
||||
function convert(categories) {
|
||||
categories.forEach((category) => {
|
||||
category.children = _.values(category.children);
|
||||
rootState.categoryList.push(category);
|
||||
category.id = `${category.id_parent}-${category.id_category}`;
|
||||
convert(category.children);
|
||||
});
|
||||
return categories;
|
||||
}
|
||||
return convert(rootState.categories);
|
||||
},
|
||||
selectedProductsLng(rootState) {
|
||||
return rootState.selectedProducts.length;
|
||||
},
|
||||
};
|
||||
|
||||
// A Vuex instance is created by combining the state, mutations, actions,
|
||||
// and getters.
|
||||
export default new Vuex.Store({
|
||||
state,
|
||||
getters,
|
||||
actions,
|
||||
mutations,
|
||||
});
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
export const ADD_PRODUCTS = 'ADD_PRODUCTS';
|
||||
export const ADD_PRODUCT_TO_UPDATE = 'ADD_PRODUCT_TO_UPDATE';
|
||||
export const ADD_SELECTED_PRODUCT = 'ADD_SELECTED_PRODUCT';
|
||||
export const APP_IS_READY = 'APP_IS_READY';
|
||||
export const LOADING_STATE = 'LOADING_STATE';
|
||||
export const REMOVE_PRODUCT_TO_UPDATE = 'REMOVE_PRODUCT_TO_UPDATE';
|
||||
export const REMOVE_SELECTED_PRODUCT = 'REMOVE_SELECTED_PRODUCT';
|
||||
export const SET_CATEGORIES = 'SET_CATEGORIES';
|
||||
export const SET_EMPLOYEES_LIST = 'SET_EMPLOYEES_LIST';
|
||||
export const SET_MOVEMENTS = 'SET_MOVEMENTS';
|
||||
export const SET_MOVEMENTS_TYPES = 'SET_MOVEMENTS_TYPES';
|
||||
export const SET_PAGE_INDEX = 'SET_PAGE_INDEX';
|
||||
export const SET_SUPPLIERS = 'SET_SUPPLIERS';
|
||||
export const SET_TOTAL_PAGES = 'SET_TOTAL_PAGES';
|
||||
export const SET_TRANSLATIONS = 'SET_TRANSLATIONS';
|
||||
export const UPDATE_BULK_EDIT_QTY = 'UPDATE_BULK_EDIT_QTY';
|
||||
export const UPDATE_KEYWORDS = 'UPDATE_KEYWORDS';
|
||||
export const UPDATE_PRODUCT = 'UPDATE_PRODUCT';
|
||||
export const UPDATE_PRODUCT_QTY = 'UPDATE_PRODUCT_QTY';
|
||||
export const UPDATE_PRODUCTS_QTY = 'UPDATE_PRODUCTS_QTY';
|
||||
export const UPDATE_ORDER = 'UPDATE_ORDER';
|
||||
189
iadmin/themes/new-theme/js/app/pages/stock/store/mutations.js
Normal file
189
iadmin/themes/new-theme/js/app/pages/stock/store/mutations.js
Normal file
@@ -0,0 +1,189 @@
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
|
||||
import _ from 'lodash';
|
||||
import * as types from './mutation-types';
|
||||
|
||||
export default {
|
||||
[types.UPDATE_ORDER](state, order) {
|
||||
state.order = order;
|
||||
},
|
||||
[types.UPDATE_KEYWORDS](state, keywords) {
|
||||
state.keywords = keywords;
|
||||
},
|
||||
[types.SET_TOTAL_PAGES](state, totalPages) {
|
||||
state.totalPages = Number(totalPages);
|
||||
},
|
||||
[types.SET_PAGE_INDEX](state, pageIndex) {
|
||||
state.pageIndex = pageIndex;
|
||||
},
|
||||
[types.SET_SUPPLIERS](state, suppliers) {
|
||||
state.suppliers = suppliers;
|
||||
},
|
||||
[types.SET_CATEGORIES](state, categories) {
|
||||
state.categories = categories.data.tree.children;
|
||||
},
|
||||
[types.SET_MOVEMENTS](state, movements) {
|
||||
state.movements = movements.data;
|
||||
},
|
||||
[types.SET_TRANSLATIONS](state, translations) {
|
||||
translations.data.forEach((t) => {
|
||||
state.translations[t.translation_id] = t.name;
|
||||
});
|
||||
},
|
||||
[types.LOADING_STATE](state, isLoading) {
|
||||
state.isLoading = isLoading;
|
||||
},
|
||||
[types.APP_IS_READY](state) {
|
||||
state.isReady = true;
|
||||
},
|
||||
[types.SET_EMPLOYEES_LIST](state, employees) {
|
||||
state.employees = employees.data;
|
||||
},
|
||||
[types.SET_MOVEMENTS_TYPES](state, movementsTypes) {
|
||||
state.movementsTypes = movementsTypes.data;
|
||||
},
|
||||
[types.ADD_PRODUCTS](state, products) {
|
||||
state.productsToUpdate = [];
|
||||
state.selectedProducts = [];
|
||||
_.forEach(products.data.data, (product) => {
|
||||
product.qty = 0;
|
||||
});
|
||||
state.editBulkUrl = products.data.info.edit_bulk_url;
|
||||
state.products = products.data.data;
|
||||
},
|
||||
[types.UPDATE_PRODUCT](state, updatedProduct) {
|
||||
const index = _.findIndex(state.products, {
|
||||
product_id: updatedProduct.product_id,
|
||||
combination_id: updatedProduct.combination_id,
|
||||
});
|
||||
const updatedIndex = _.findIndex(state.productsToUpdate, {
|
||||
product_id: updatedProduct.product_id,
|
||||
combination_id: updatedProduct.combination_id,
|
||||
});
|
||||
updatedProduct.qty = 0;
|
||||
state.products.splice(index, 1, updatedProduct);
|
||||
state.productsToUpdate.splice(updatedIndex, 1);
|
||||
},
|
||||
[types.UPDATE_PRODUCTS_QTY](state, updatedProducts) {
|
||||
state.productsToUpdate = [];
|
||||
state.selectedProducts = [];
|
||||
_.forEach(updatedProducts, (product) => {
|
||||
const index = _.findIndex(state.products, {
|
||||
product_id: product.product_id,
|
||||
combination_id: product.combination_id,
|
||||
});
|
||||
product.qty = 0;
|
||||
state.products.splice(index, 1, product);
|
||||
});
|
||||
state.hasQty = false;
|
||||
},
|
||||
[types.UPDATE_PRODUCT_QTY](state, updatedProduct) {
|
||||
let hasQty = false;
|
||||
|
||||
const productToUpdate = _.find(state.products, {
|
||||
product_id: updatedProduct.product_id,
|
||||
combination_id: updatedProduct.combination_id,
|
||||
});
|
||||
|
||||
_.forEach(state.products, (product) => {
|
||||
productToUpdate.qty = updatedProduct.delta;
|
||||
if (product.qty) {
|
||||
hasQty = true;
|
||||
}
|
||||
});
|
||||
|
||||
state.hasQty = hasQty;
|
||||
},
|
||||
[types.ADD_PRODUCT_TO_UPDATE](state, updatedProduct) {
|
||||
const index = _.findIndex(state.productsToUpdate, {
|
||||
product_id: updatedProduct.product_id,
|
||||
combination_id: updatedProduct.combination_id,
|
||||
});
|
||||
|
||||
if (index !== -1) {
|
||||
state.productsToUpdate.splice(index, 1, updatedProduct);
|
||||
} else {
|
||||
state.productsToUpdate.push(updatedProduct);
|
||||
}
|
||||
},
|
||||
[types.REMOVE_PRODUCT_TO_UPDATE](state, updatedProduct) {
|
||||
const index = _.findIndex(state.productsToUpdate, {
|
||||
product_id: updatedProduct.product_id,
|
||||
combination_id: updatedProduct.combination_id,
|
||||
});
|
||||
state.productsToUpdate.splice(index, 1);
|
||||
},
|
||||
[types.UPDATE_BULK_EDIT_QTY](state, value) {
|
||||
state.bulkEditQty = value;
|
||||
if (value) {
|
||||
_.forEach(state.selectedProducts, (product) => {
|
||||
const index = _.findIndex(state.productsToUpdate, {
|
||||
product_id: product.product_id,
|
||||
combination_id: product.combination_id,
|
||||
});
|
||||
product.qty = value;
|
||||
product.delta = state.bulkEditQty;
|
||||
if (index !== -1) {
|
||||
state.productsToUpdate.splice(index, 1, product);
|
||||
} else {
|
||||
state.productsToUpdate.push(product);
|
||||
}
|
||||
});
|
||||
state.hasQty = true;
|
||||
}
|
||||
if (value === null) {
|
||||
_.forEach(state.selectedProducts, (product) => {
|
||||
product.qty = 0;
|
||||
});
|
||||
state.productsToUpdate = [];
|
||||
state.selectedProducts = [];
|
||||
state.hasQty = false;
|
||||
}
|
||||
},
|
||||
[types.ADD_SELECTED_PRODUCT](state, product) {
|
||||
const index = _.findIndex(state.selectedProducts, {
|
||||
product_id: product.product_id,
|
||||
combination_id: product.combination_id,
|
||||
});
|
||||
|
||||
if (index !== -1) {
|
||||
state.selectedProducts.splice(index, 1, product);
|
||||
} else {
|
||||
state.selectedProducts.push(product);
|
||||
}
|
||||
},
|
||||
[types.REMOVE_SELECTED_PRODUCT](state, product) {
|
||||
const index = _.findIndex(state.selectedProducts, {
|
||||
product_id: product.product_id,
|
||||
combination_id: product.combination_id,
|
||||
});
|
||||
|
||||
if (index !== -1) {
|
||||
state.selectedProducts[index].qty = 0;
|
||||
}
|
||||
state.selectedProducts.splice(index, 1);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user