834 lines
38 KiB
JavaScript
Vendored
834 lines
38 KiB
JavaScript
Vendored
const App = {
|
|
setup() {
|
|
const state = Vue.reactive({
|
|
mainData: [],
|
|
deleteMode: false,
|
|
warehouseListLookupData: [],
|
|
stockCountStatusListLookupData: [],
|
|
secondaryData: [],
|
|
productListLookupData: [],
|
|
mainTitle: null,
|
|
id: '',
|
|
number: '',
|
|
countDate: '',
|
|
description: '',
|
|
warehouseId: null,
|
|
status: null,
|
|
errors: {
|
|
countDate: '',
|
|
warehouseId: '',
|
|
status: ''
|
|
},
|
|
showComplexDiv: false,
|
|
isSubmitting: false,
|
|
totalMovementFormatted: '0.00'
|
|
});
|
|
|
|
const mainGridRef = Vue.ref(null);
|
|
const mainModalRef = Vue.ref(null);
|
|
const secondaryGridRef = Vue.ref(null);
|
|
const countDateRef = Vue.ref(null);
|
|
const warehouseIdRef = Vue.ref(null);
|
|
const statusRef = Vue.ref(null);
|
|
const numberRef = Vue.ref(null);
|
|
|
|
const validateForm = function () {
|
|
state.errors.countDate = '';
|
|
state.errors.warehouseId = '';
|
|
state.errors.status = '';
|
|
|
|
let isValid = true;
|
|
|
|
if (!state.countDate) {
|
|
state.errors.countDate = 'Count date is required.';
|
|
isValid = false;
|
|
}
|
|
if (!state.warehouseId) {
|
|
state.errors.warehouseId = 'Warehouse is required.';
|
|
isValid = false;
|
|
}
|
|
if (!state.status) {
|
|
state.errors.status = 'Status is required.';
|
|
isValid = false;
|
|
}
|
|
|
|
return isValid;
|
|
};
|
|
|
|
const resetFormState = () => {
|
|
state.id = '';
|
|
state.number = '';
|
|
state.countDate = '';
|
|
state.description = '';
|
|
state.warehouseId = null;
|
|
state.status = null;
|
|
state.errors = {
|
|
countDate: '',
|
|
warehouseId: '',
|
|
status: ''
|
|
};
|
|
state.secondaryData = [];
|
|
};
|
|
|
|
const countDatePicker = {
|
|
obj: null,
|
|
create: () => {
|
|
countDatePicker.obj = new ej.calendars.DatePicker({
|
|
placeholder: 'Select Date',
|
|
format: 'yyyy-MM-dd',
|
|
value: state.countDate ? new Date(state.countDate) : null,
|
|
change: (e) => {
|
|
state.countDate = e.value;
|
|
}
|
|
});
|
|
countDatePicker.obj.appendTo(countDateRef.value);
|
|
},
|
|
refresh: () => {
|
|
if (countDatePicker.obj) {
|
|
countDatePicker.obj.value = state.countDate ? new Date(state.countDate) : null;
|
|
}
|
|
}
|
|
};
|
|
|
|
Vue.watch(
|
|
() => state.countDate,
|
|
(newVal, oldVal) => {
|
|
countDatePicker.refresh();
|
|
state.errors.countDate = '';
|
|
}
|
|
);
|
|
|
|
const warehouseListLookup = {
|
|
obj: null,
|
|
create: () => {
|
|
if (state.warehouseListLookupData && Array.isArray(state.warehouseListLookupData)) {
|
|
warehouseListLookup.obj = new ej.dropdowns.DropDownList({
|
|
dataSource: state.warehouseListLookupData,
|
|
fields: { value: 'id', text: 'name' },
|
|
placeholder: 'Select Warehouse',
|
|
allowFiltering: true,
|
|
filtering: (e) => {
|
|
e.preventDefaultAction = true;
|
|
let query = new ej.data.Query();
|
|
if (e.text !== '') {
|
|
query = query.where('name', 'startsWith', e.text, true);
|
|
}
|
|
e.updateData(state.warehouseListLookupData, query);
|
|
},
|
|
change: (e) => {
|
|
state.warehouseId = e.value;
|
|
}
|
|
});
|
|
warehouseListLookup.obj.appendTo(warehouseIdRef.value);
|
|
}
|
|
},
|
|
refresh: () => {
|
|
if (warehouseListLookup.obj) {
|
|
warehouseListLookup.obj.value = state.warehouseId;
|
|
}
|
|
}
|
|
};
|
|
|
|
Vue.watch(
|
|
() => state.warehouseId,
|
|
(newVal, oldVal) => {
|
|
warehouseListLookup.refresh();
|
|
state.errors.warehouseId = '';
|
|
}
|
|
);
|
|
|
|
const statusListLookup = {
|
|
obj: null,
|
|
create: () => {
|
|
if (state.stockCountStatusListLookupData && Array.isArray(state.stockCountStatusListLookupData)) {
|
|
statusListLookup.obj = new ej.dropdowns.DropDownList({
|
|
dataSource: state.stockCountStatusListLookupData,
|
|
fields: { value: 'id', text: 'name' },
|
|
placeholder: 'Select Status',
|
|
allowFiltering: false,
|
|
change: (e) => {
|
|
state.status = e.value;
|
|
}
|
|
});
|
|
statusListLookup.obj.appendTo(statusRef.value);
|
|
}
|
|
},
|
|
refresh: () => {
|
|
if (statusListLookup.obj) {
|
|
statusListLookup.obj.value = state.status;
|
|
}
|
|
}
|
|
};
|
|
|
|
Vue.watch(
|
|
() => state.status,
|
|
(newVal, oldVal) => {
|
|
statusListLookup.refresh();
|
|
state.errors.status = '';
|
|
}
|
|
);
|
|
|
|
const numberText = {
|
|
obj: null,
|
|
create: () => {
|
|
numberText.obj = new ej.inputs.TextBox({
|
|
placeholder: '[auto]',
|
|
});
|
|
numberText.obj.appendTo(numberRef.value);
|
|
}
|
|
};
|
|
|
|
const services = {
|
|
getMainData: async () => {
|
|
try {
|
|
const response = await AxiosManager.get('/StockCount/GetStockCountList', {});
|
|
return response;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
},
|
|
createMainData: async (countDate, description, status, warehouseId, createdById) => {
|
|
try {
|
|
const response = await AxiosManager.post('/StockCount/CreateStockCount', {
|
|
countDate, description, status, warehouseId, createdById
|
|
});
|
|
return response;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
},
|
|
updateMainData: async (id, countDate, description, status, warehouseId, updatedById) => {
|
|
try {
|
|
const response = await AxiosManager.post('/StockCount/UpdateStockCount', {
|
|
id, countDate, description, status, warehouseId, updatedById
|
|
});
|
|
return response;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
},
|
|
deleteMainData: async (id, deletedById) => {
|
|
try {
|
|
const response = await AxiosManager.post('/StockCount/DeleteStockCount', {
|
|
id, deletedById
|
|
});
|
|
return response;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
},
|
|
getWarehouseListLookupData: async () => {
|
|
try {
|
|
const response = await AxiosManager.get('/Warehouse/GetWarehouseList', {});
|
|
return response;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
},
|
|
getStockCountStatusListLookupData: async () => {
|
|
try {
|
|
const response = await AxiosManager.get('/StockCount/GetStockCountStatusList', {});
|
|
return response;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
},
|
|
getSecondaryData: async (moduleId) => {
|
|
try {
|
|
const response = await AxiosManager.get('/InventoryTransaction/StockCountGetInvenTransList?moduleId=' + moduleId, {});
|
|
return response;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
},
|
|
createSecondaryData: async (moduleId, productId, qtySCCount, createdById) => {
|
|
try {
|
|
const response = await AxiosManager.post('/InventoryTransaction/StockCountCreateInvenTrans', {
|
|
moduleId, productId, qtySCCount, createdById
|
|
});
|
|
return response;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
},
|
|
updateSecondaryData: async (id, productId, qtySCCount, updatedById) => {
|
|
try {
|
|
const response = await AxiosManager.post('/InventoryTransaction/StockCountUpdateInvenTrans', {
|
|
id, productId, qtySCCount, updatedById
|
|
});
|
|
return response;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
},
|
|
deleteSecondaryData: async (id, deletedById) => {
|
|
try {
|
|
const response = await AxiosManager.post('/InventoryTransaction/StockCountDeleteInvenTrans', {
|
|
id, deletedById
|
|
});
|
|
return response;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
},
|
|
getProductListLookupData: async () => {
|
|
try {
|
|
const response = await AxiosManager.get('/Product/GetProductList', {});
|
|
return response;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
},
|
|
};
|
|
|
|
const methods = {
|
|
populateMainData: async () => {
|
|
const response = await services.getMainData();
|
|
state.mainData = response?.data?.content?.data.map(item => ({
|
|
...item,
|
|
countDate: new Date(item.countDate),
|
|
createdAtUtc: new Date(item.createdAtUtc)
|
|
}));
|
|
},
|
|
populateWarehouseListLookupData: async () => {
|
|
const response = await services.getWarehouseListLookupData();
|
|
state.warehouseListLookupData = response?.data?.content?.data.filter(warehouse => warehouse.systemWarehouse === false) || [];
|
|
},
|
|
populateStockCountStatusListLookupData: async () => {
|
|
const response = await services.getStockCountStatusListLookupData();
|
|
state.stockCountStatusListLookupData = response?.data?.content?.data;
|
|
},
|
|
populateSecondaryData: async (stockCountId) => {
|
|
try {
|
|
const response = await services.getSecondaryData(stockCountId);
|
|
state.secondaryData = response?.data?.content?.data.map(item => ({
|
|
...item,
|
|
createdAtUtc: new Date(item.createdAtUtc)
|
|
}));
|
|
methods.refreshSummary();
|
|
} catch (error) {
|
|
state.secondaryData = [];
|
|
}
|
|
},
|
|
populateProductListLookupData: async () => {
|
|
const response = await services.getProductListLookupData();
|
|
state.productListLookupData = response?.data?.content?.data
|
|
.filter(product => product.physical === true)
|
|
.map(product => ({
|
|
...product,
|
|
numberName: `${product.number} - ${product.name}`
|
|
})) || [];
|
|
},
|
|
refreshSummary: () => {
|
|
const totalMovement = state.secondaryData.reduce((sum, record) => sum + (record.qtySCDelta ?? 0), 0);
|
|
state.totalMovementFormatted = NumberFormatManager.formatToLocale(totalMovement);
|
|
},
|
|
submitMainData: async () => {
|
|
const isValid = validateForm();
|
|
if (!isValid) {
|
|
return { isValid, response: null };
|
|
}
|
|
|
|
try {
|
|
const response = state.id === ''
|
|
? await services.createMainData(state.countDate, state.description, state.status, state.warehouseId, StorageManager.getUserId())
|
|
: state.deleteMode
|
|
? await services.deleteMainData(state.id, StorageManager.getUserId())
|
|
: await services.updateMainData(state.id, state.countDate, state.description, state.status, state.warehouseId, StorageManager.getUserId());
|
|
|
|
return { isValid, response };
|
|
} catch (error) {
|
|
return { isValid, response: null };
|
|
}
|
|
},
|
|
onMainModalHidden: () => {
|
|
resetFormState();
|
|
state.errors.countDate = '';
|
|
state.errors.warehouseId = '';
|
|
state.errors.status = '';
|
|
state.showComplexDiv = false;
|
|
}
|
|
};
|
|
|
|
const handler = {
|
|
handleSubmit: async function () {
|
|
try {
|
|
state.isSubmitting = true;
|
|
await new Promise(resolve => setTimeout(resolve, 300));
|
|
|
|
const { isValid, response } = await methods.submitMainData();
|
|
|
|
if (!isValid) {
|
|
return;
|
|
}
|
|
|
|
if (response.data.code === 200) {
|
|
await methods.populateMainData();
|
|
mainGrid.refresh();
|
|
|
|
if (!state.deleteMode) {
|
|
state.mainTitle = 'Edit Stock Count';
|
|
state.id = response?.data?.content?.data.id ?? '';
|
|
state.number = response?.data?.content?.data.number ?? '';
|
|
await methods.populateSecondaryData(state.id);
|
|
secondaryGrid.refresh();
|
|
state.showComplexDiv = true;
|
|
|
|
Swal.fire({
|
|
icon: 'success',
|
|
title: 'Save Successful',
|
|
timer: 2000,
|
|
showConfirmButton: false
|
|
});
|
|
} else {
|
|
Swal.fire({
|
|
icon: 'success',
|
|
title: 'Delete Successful',
|
|
text: 'Form will be closed...',
|
|
timer: 2000,
|
|
showConfirmButton: false
|
|
});
|
|
setTimeout(() => {
|
|
mainModal.obj.hide();
|
|
resetFormState();
|
|
}, 2000);
|
|
}
|
|
} else {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: state.deleteMode ? 'Delete Failed' : 'Save Failed',
|
|
text: response.data.message ?? 'Please check your data.',
|
|
confirmButtonText: 'Try Again'
|
|
});
|
|
}
|
|
} catch (error) {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'An Error Occurred',
|
|
text: error.response?.data?.message ?? 'Please try again.',
|
|
confirmButtonText: 'OK'
|
|
});
|
|
} finally {
|
|
state.isSubmitting = false;
|
|
}
|
|
},
|
|
};
|
|
|
|
Vue.onMounted(async () => {
|
|
try {
|
|
await SecurityManager.authorizePage(['StockCounts']);
|
|
await SecurityManager.validateToken();
|
|
|
|
await methods.populateMainData();
|
|
await mainGrid.create(state.mainData);
|
|
|
|
mainModal.create();
|
|
mainModalRef.value?.addEventListener('hidden.bs.modal', methods.onMainModalHidden);
|
|
|
|
await methods.populateWarehouseListLookupData();
|
|
warehouseListLookup.create();
|
|
await methods.populateStockCountStatusListLookupData();
|
|
statusListLookup.create();
|
|
countDatePicker.create();
|
|
numberText.create();
|
|
|
|
await methods.populateProductListLookupData();
|
|
await secondaryGrid.create(state.secondaryData);
|
|
|
|
} catch (e) {
|
|
console.error('page init error:', e);
|
|
} finally {
|
|
|
|
}
|
|
});
|
|
|
|
Vue.onUnmounted(() => {
|
|
mainModalRef.value?.removeEventListener('hidden.bs.modal', methods.onMainModalHidden);
|
|
});
|
|
|
|
const mainGrid = {
|
|
obj: null,
|
|
create: async (dataSource) => {
|
|
mainGrid.obj = new ej.grids.Grid({
|
|
height: '240px',
|
|
dataSource: dataSource,
|
|
allowFiltering: true,
|
|
allowSorting: true,
|
|
allowSelection: true,
|
|
allowGrouping: true,
|
|
allowTextWrap: true,
|
|
allowResizing: true,
|
|
allowPaging: true,
|
|
allowExcelExport: true,
|
|
filterSettings: { type: 'CheckBox' },
|
|
sortSettings: { columns: [{ field: 'createdAtUtc', direction: 'Descending' }] },
|
|
pageSettings: { currentPage: 1, pageSize: 50, pageSizes: ["10", "20", "50", "100", "200", "All"] },
|
|
selectionSettings: { persistSelection: true, type: 'Single' },
|
|
autoFit: true,
|
|
showColumnMenu: true,
|
|
gridLines: 'Horizontal',
|
|
columns: [
|
|
{ type: 'checkbox', width: 60 },
|
|
{
|
|
field: 'id', isPrimaryKey: true, headerText: 'Id', visible: false
|
|
},
|
|
{ field: 'number', headerText: 'Number', width: 150, minWidth: 150 },
|
|
{ field: 'countDate', headerText: 'Count Date', width: 150, format: 'yyyy-MM-dd' },
|
|
{ field: 'warehouseName', headerText: 'Warehouse', width: 150, minWidth: 150 },
|
|
{ field: 'statusName', headerText: 'Status', width: 150, minWidth: 150 },
|
|
{ field: 'createdAtUtc', headerText: 'Created At UTC', width: 150, format: 'yyyy-MM-dd HH:mm' }
|
|
],
|
|
toolbar: [
|
|
'ExcelExport', 'Search',
|
|
{ type: 'Separator' },
|
|
{ text: 'Add', tooltipText: 'Add', prefixIcon: 'e-add', id: 'AddCustom' },
|
|
{ text: 'Edit', tooltipText: 'Edit', prefixIcon: 'e-edit', id: 'EditCustom' },
|
|
{ text: 'Delete', tooltipText: 'Delete', prefixIcon: 'e-delete', id: 'DeleteCustom' },
|
|
{ type: 'Separator' },
|
|
{ text: 'Print PDF', tooltipText: 'Print PDF', id: 'PrintPDFCustom' },
|
|
],
|
|
beforeDataBound: () => { },
|
|
dataBound: function () {
|
|
mainGrid.obj.toolbarModule.enableItems(['EditCustom', 'DeleteCustom', 'PrintPDFCustom'], false);
|
|
mainGrid.obj.autoFitColumns(['number', 'countDate', 'warehouseName', 'statusName', 'createdAtUtc']);
|
|
},
|
|
excelExportComplete: () => { },
|
|
rowSelected: () => {
|
|
if (mainGrid.obj.getSelectedRecords().length == 1) {
|
|
mainGrid.obj.toolbarModule.enableItems(['EditCustom', 'DeleteCustom', 'PrintPDFCustom'], true);
|
|
} else {
|
|
mainGrid.obj.toolbarModule.enableItems(['EditCustom', 'DeleteCustom', 'PrintPDFCustom'], false);
|
|
}
|
|
},
|
|
rowDeselected: () => {
|
|
if (mainGrid.obj.getSelectedRecords().length == 1) {
|
|
mainGrid.obj.toolbarModule.enableItems(['EditCustom', 'DeleteCustom', 'PrintPDFCustom'], true);
|
|
} else {
|
|
mainGrid.obj.toolbarModule.enableItems(['EditCustom', 'DeleteCustom', 'PrintPDFCustom'], false);
|
|
}
|
|
},
|
|
rowSelecting: () => {
|
|
if (mainGrid.obj.getSelectedRecords().length) {
|
|
mainGrid.obj.clearSelection();
|
|
}
|
|
},
|
|
toolbarClick: async (args) => {
|
|
if (args.item.id === 'MainGrid_excelexport') {
|
|
mainGrid.obj.excelExport();
|
|
}
|
|
|
|
if (args.item.id === 'AddCustom') {
|
|
state.deleteMode = false;
|
|
state.mainTitle = 'Add Stock Count';
|
|
resetFormState();
|
|
state.showComplexDiv = false;
|
|
mainModal.obj.show();
|
|
}
|
|
|
|
if (args.item.id === 'EditCustom') {
|
|
state.deleteMode = false;
|
|
if (mainGrid.obj.getSelectedRecords().length) {
|
|
const selectedRecord = mainGrid.obj.getSelectedRecords()[0];
|
|
state.mainTitle = 'Edit Stock Count';
|
|
state.id = selectedRecord.id ?? '';
|
|
state.number = selectedRecord.number ?? '';
|
|
state.countDate = selectedRecord.countDate ? new Date(selectedRecord.countDate) : null;
|
|
state.description = selectedRecord.description ?? '';
|
|
state.warehouseId = selectedRecord.warehouseId ?? '';
|
|
state.status = String(selectedRecord.status ?? '');
|
|
await methods.populateSecondaryData(selectedRecord.id);
|
|
secondaryGrid.refresh();
|
|
state.showComplexDiv = true;
|
|
mainModal.obj.show();
|
|
}
|
|
}
|
|
|
|
if (args.item.id === 'DeleteCustom') {
|
|
state.deleteMode = true;
|
|
if (mainGrid.obj.getSelectedRecords().length) {
|
|
const selectedRecord = mainGrid.obj.getSelectedRecords()[0];
|
|
state.mainTitle = 'Delete Stock Count?';
|
|
state.id = selectedRecord.id ?? '';
|
|
state.number = selectedRecord.number ?? '';
|
|
state.countDate = selectedRecord.countDate ? new Date(selectedRecord.countDate) : null;
|
|
state.description = selectedRecord.description ?? '';
|
|
state.warehouseId = selectedRecord.warehouseId ?? '';
|
|
state.status = String(selectedRecord.status ?? '');
|
|
await methods.populateSecondaryData(selectedRecord.id);
|
|
secondaryGrid.refresh();
|
|
state.showComplexDiv = false;
|
|
mainModal.obj.show();
|
|
}
|
|
}
|
|
|
|
if (args.item.id === 'PrintPDFCustom') {
|
|
if (mainGrid.obj.getSelectedRecords().length) {
|
|
const selectedRecord = mainGrid.obj.getSelectedRecords()[0];
|
|
window.open('/StockCounts/StockCountPdf?id=' + (selectedRecord.id ?? ''), '_blank');
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
mainGrid.obj.appendTo(mainGridRef.value);
|
|
},
|
|
refresh: () => {
|
|
mainGrid.obj.setProperties({ dataSource: state.mainData });
|
|
}
|
|
};
|
|
|
|
const secondaryGrid = {
|
|
obj: null,
|
|
create: async (dataSource) => {
|
|
secondaryGrid.obj = new ej.grids.Grid({
|
|
height: 400,
|
|
dataSource: dataSource,
|
|
editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, showDeleteConfirmDialog: true, mode: 'Normal', allowEditOnDblClick: true },
|
|
allowFiltering: false,
|
|
allowSorting: true,
|
|
allowSelection: true,
|
|
allowGrouping: false,
|
|
allowTextWrap: true,
|
|
allowResizing: true,
|
|
allowPaging: false,
|
|
allowExcelExport: true,
|
|
filterSettings: { type: 'CheckBox' },
|
|
sortSettings: { columns: [{ field: 'productName', direction: 'Descending' }] },
|
|
pageSettings: { currentPage: 1, pageSize: 50, pageSizes: ["10", "20", "50", "100", "200", "All"] },
|
|
selectionSettings: { persistSelection: true, type: 'Single' },
|
|
autoFit: false,
|
|
showColumnMenu: false,
|
|
gridLines: 'Horizontal',
|
|
columns: [
|
|
{ type: 'checkbox', width: 60 },
|
|
{
|
|
field: 'id', isPrimaryKey: true, headerText: 'Id', visible: false
|
|
},
|
|
{
|
|
field: 'productId',
|
|
headerText: 'Product',
|
|
width: 250,
|
|
validationRules: { required: true },
|
|
disableHtmlEncode: false,
|
|
valueAccessor: (field, data, column) => {
|
|
const product = state.productListLookupData.find(item => item.id === data[field]);
|
|
return product ? `${product.numberName}` : '';
|
|
},
|
|
editType: 'dropdownedit',
|
|
edit: {
|
|
create: () => {
|
|
productElem = document.createElement('input');
|
|
return productElem;
|
|
},
|
|
read: () => {
|
|
return productObj.value;
|
|
},
|
|
destroy: function () {
|
|
productObj.destroy();
|
|
},
|
|
write: function (args) {
|
|
productObj = new ej.dropdowns.DropDownList({
|
|
dataSource: state.productListLookupData,
|
|
fields: { value: 'id', text: 'name' },
|
|
value: args.rowData.productId,
|
|
change: function (e) {
|
|
if (qtySCCountObj) {
|
|
qtySCCountObj.value = 1;
|
|
}
|
|
},
|
|
placeholder: 'Select a Product',
|
|
floatLabelType: 'Never'
|
|
});
|
|
|
|
productObj.appendTo(productElem);
|
|
}
|
|
}
|
|
},
|
|
{ field: 'qtySCSys', headerText: 'System Stock', width: 100, allowEditing: false, type: 'number', format: 'N2', textAlign: 'Right'},
|
|
{
|
|
field: 'qtySCCount',
|
|
headerText: 'Counted',
|
|
width: 200,
|
|
validationRules: {
|
|
required: true,
|
|
custom: [(args) => {
|
|
return args['value'] >= 0;
|
|
}, 'Must be a non-negative number']
|
|
},
|
|
type: 'number', format: 'N2', textAlign: 'Right',
|
|
edit: {
|
|
create: () => {
|
|
qtySCCountElem = document.createElement('input');
|
|
return qtySCCountElem;
|
|
},
|
|
read: () => {
|
|
return qtySCCountObj.value;
|
|
},
|
|
destroy: function () {
|
|
qtySCCountObj.destroy();
|
|
},
|
|
write: function (args) {
|
|
qtySCCountObj = new ej.inputs.NumericTextBox({
|
|
value: args.rowData.qtySCCount ?? 0,
|
|
});
|
|
qtySCCountObj.appendTo(qtySCCountElem);
|
|
}
|
|
}
|
|
},
|
|
{ field: 'qtySCDelta', headerText: 'Adjustment', width: 100, allowEditing: false, type: 'number', format: '+0.00;-0.00;0.00', textAlign: 'Right' },
|
|
],
|
|
toolbar: [
|
|
'ExcelExport',
|
|
{ type: 'Separator' },
|
|
'Add', 'Edit', 'Delete', 'Update', 'Cancel',
|
|
],
|
|
beforeDataBound: () => { },
|
|
dataBound: function () { },
|
|
excelExportComplete: () => { },
|
|
rowSelected: () => {
|
|
if (secondaryGrid.obj.getSelectedRecords().length == 1) {
|
|
secondaryGrid.obj.toolbarModule.enableItems(['SecondaryGrid_edit'], true);
|
|
} else {
|
|
secondaryGrid.obj.toolbarModule.enableItems(['SecondaryGrid_edit'], false);
|
|
}
|
|
},
|
|
rowDeselected: () => {
|
|
if (secondaryGrid.obj.getSelectedRecords().length == 1) {
|
|
secondaryGrid.obj.toolbarModule.enableItems(['SecondaryGrid_edit'], true);
|
|
} else {
|
|
secondaryGrid.obj.toolbarModule.enableItems(['SecondaryGrid_edit'], false);
|
|
}
|
|
},
|
|
rowSelecting: () => {
|
|
if (secondaryGrid.obj.getSelectedRecords().length) {
|
|
secondaryGrid.obj.clearSelection();
|
|
}
|
|
},
|
|
toolbarClick: (args) => {
|
|
if (args.item.id === 'SecondaryGrid_excelexport') {
|
|
secondaryGrid.obj.excelExport();
|
|
}
|
|
},
|
|
actionComplete: async (args) => {
|
|
if (args.requestType === 'save' && args.action === 'add') {
|
|
try {
|
|
const response = await services.createSecondaryData(state.id, args.data.productId, args.data.qtySCCount, StorageManager.getUserId());
|
|
await methods.populateSecondaryData(state.id);
|
|
secondaryGrid.refresh();
|
|
if (response.data.code === 200) {
|
|
Swal.fire({
|
|
icon: 'success',
|
|
title: 'Save Successful',
|
|
timer: 2000,
|
|
showConfirmButton: false
|
|
});
|
|
} else {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Save Failed',
|
|
text: response.data.message ?? 'Please check your data.',
|
|
confirmButtonText: 'Try Again'
|
|
});
|
|
}
|
|
} catch (error) {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'An Error Occurred',
|
|
text: error.response?.data?.message ?? 'Please try again.',
|
|
confirmButtonText: 'OK'
|
|
});
|
|
}
|
|
}
|
|
if (args.requestType === 'save' && args.action === 'edit') {
|
|
try {
|
|
const response = await services.updateSecondaryData(args.data.id, args.data.productId, args.data.qtySCCount, StorageManager.getUserId());
|
|
await methods.populateSecondaryData(state.id);
|
|
secondaryGrid.refresh();
|
|
if (response.data.code === 200) {
|
|
Swal.fire({
|
|
icon: 'success',
|
|
title: 'Update Successful',
|
|
timer: 2000,
|
|
showConfirmButton: false
|
|
});
|
|
} else {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Update Failed',
|
|
text: response.data.message ?? 'Please check your data.',
|
|
confirmButtonText: 'Try Again'
|
|
});
|
|
}
|
|
} catch (error) {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'An Error Occurred',
|
|
text: error.response?.data?.message ?? 'Please try again.',
|
|
confirmButtonText: 'OK'
|
|
});
|
|
}
|
|
}
|
|
if (args.requestType === 'delete') {
|
|
try {
|
|
const response = await services.deleteSecondaryData(args.data[0].id, StorageManager.getUserId());
|
|
await methods.populateSecondaryData(state.id);
|
|
secondaryGrid.refresh();
|
|
if (response.data.code === 200) {
|
|
Swal.fire({
|
|
icon: 'success',
|
|
title: 'Delete Successful',
|
|
timer: 2000,
|
|
showConfirmButton: false
|
|
});
|
|
} else {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Delete Failed',
|
|
text: response.data.message ?? 'Please check your data.',
|
|
confirmButtonText: 'Try Again'
|
|
});
|
|
}
|
|
} catch (error) {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'An Error Occurred',
|
|
text: error.response?.data?.message ?? 'Please try again.',
|
|
confirmButtonText: 'OK'
|
|
});
|
|
}
|
|
}
|
|
methods.refreshSummary();
|
|
}
|
|
});
|
|
secondaryGrid.obj.appendTo(secondaryGridRef.value);
|
|
},
|
|
refresh: () => {
|
|
secondaryGrid.obj.setProperties({ dataSource: state.secondaryData });
|
|
}
|
|
};
|
|
|
|
const mainModal = {
|
|
obj: null,
|
|
create: () => {
|
|
mainModal.obj = new bootstrap.Modal(mainModalRef.value, {
|
|
backdrop: 'static',
|
|
keyboard: false
|
|
});
|
|
}
|
|
};
|
|
|
|
return {
|
|
mainGridRef,
|
|
mainModalRef,
|
|
secondaryGridRef,
|
|
countDateRef,
|
|
warehouseIdRef,
|
|
statusRef,
|
|
numberRef,
|
|
state,
|
|
handler,
|
|
};
|
|
}
|
|
};
|
|
|
|
Vue.createApp(App).mount('#app'); |