initial commit

This commit is contained in:
2026-07-21 15:03:40 +07:00
commit 5c20bb8a9e
2752 changed files with 864209 additions and 0 deletions
@@ -0,0 +1,125 @@
@page
@attribute [Authorize(Roles = "NegativeAdjustments")]
@{
ViewData["Title"] = "Negative Adjustment List";
}
<div id="app" v-cloak>
<div class="row">
<div class="col-12">
<div class="grid-container">
<div ref="mainGridRef"></div>
</div>
</div>
</div>
<div class="modal fade" ref="mainModalRef" id="MainModal" aria-hidden="true" tabindex="-1" data-bs-focus="false" data-bs-backdrop="static">
<div class="modal-dialog modal-dialog-centered modal-xl">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">{{ state.mainTitle }}</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<input type="hidden" v-model="state.id" id="Id" name="Id" />
<form>
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h5>Main Info</h5>
</div>
<div class="card-body">
<div class="row mb-2">
<div class="col-md-6">
<label for="AdjustmentDate">Adjustment Date</label>
<input ref="adjustmentDateRef">
<label class="text-danger">{{ state.errors.adjustmentDate }}</label>
</div>
<div class="col-md-6">
<label for="Number">Number</label>
<input ref="numberRef" v-model="state.number" readonly>
</div>
</div>
<div class="row mb-2">
<div class="col-md-6">
<label for="Status">Status</label>
<div ref="statusRef"></div>
<label class="text-danger">{{ state.errors.status }}</label>
</div>
<div class="col-md-6">
</div>
</div>
<div class="row mb-2">
<div class="col-md-12">
<label for="Description">Description</label>
<textarea class="form-control" rows="3" v-model="state.description"></textarea>
<label class="text-danger">{{ state.errors.description }}</label>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
<div id="ComplexDiv" :style="{ display: state.showComplexDiv ? 'block' : 'none' }">
<div class="row mt-3">
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h5>Delivery Item</h5>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-12">
<div class="grid-container">
<div ref="secondaryGridRef"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row mt-4">
<div class="col-md-12">
<div class="card shadow-sm">
<div class="card-header text-white">
<h5 class="mb-0">Summary</h5>
</div>
<div class="card-body">
<div class="row justify-content-end">
<div class="col-md-6">
<div class="d-flex justify-content-between py-2">
<span class="fw-bold">Total Movement</span>
<span id="TotalMovement" class="fw-bold text-success">{{ state.totalMovementFormatted }}</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button"
id="MainSaveButton"
class="btn"
v-bind:class="state.deleteMode ? 'btn-danger' : 'btn-primary'"
v-on:click="handler.handleSubmit"
v-bind:disabled="state.isSubmitting">
<span class="spinner-border spinner-border-sm me-2" v-if="state.isSubmitting" role="status" aria-hidden="true"></span>
<span v-if="!state.isSubmitting">{{ state.deleteMode ? 'Delete' : 'Save' }}</span>
<span v-else>{{ state.deleteMode ? 'Deleting...' : 'Saving...' }}</span>
</button>
</div>
</div>
</div>
</div>
</div>
@section scripts {
<script src="~/FrontEnd/Pages/NegativeAdjustments/NegativeAdjustmentList.cshtml.js"></script>
}
@@ -0,0 +1,799 @@
const App = {
setup() {
const state = Vue.reactive({
mainData: [],
deleteMode: false,
negativeAdjustmentStatusListLookupData: [],
secondaryData: [],
productListLookupData: [],
warehouseListLookupData: [],
mainTitle: null,
id: '',
number: '',
adjustmentDate: '',
description: '',
status: null,
errors: {
adjustmentDate: '',
status: '',
description: ''
},
showComplexDiv: false,
isSubmitting: false,
totalMovementFormatted: '0.00'
});
const mainGridRef = Vue.ref(null);
const mainModalRef = Vue.ref(null);
const secondaryGridRef = Vue.ref(null);
const adjustmentDateRef = Vue.ref(null);
const statusRef = Vue.ref(null);
const numberRef = Vue.ref(null);
const validateForm = function () {
state.errors.adjustmentDate = '';
state.errors.status = '';
let isValid = true;
if (!state.adjustmentDate) {
state.errors.adjustmentDate = 'Adjustment date is required.';
isValid = false;
}
if (!state.status) {
state.errors.status = 'Status is required.';
isValid = false;
}
return isValid;
};
const resetFormState = () => {
state.id = '';
state.number = '';
state.adjustmentDate = '';
state.description = '';
state.status = null;
state.errors = {
adjustmentDate: '',
status: '',
description: ''
};
state.secondaryData = [];
};
const adjustmentDatePicker = {
obj: null,
create: () => {
adjustmentDatePicker.obj = new ej.calendars.DatePicker({
placeholder: 'Select Date',
format: 'yyyy-MM-dd',
value: state.adjustmentDate ? new Date(state.adjustmentDate) : null,
change: (e) => {
state.adjustmentDate = e.value;
}
});
adjustmentDatePicker.obj.appendTo(adjustmentDateRef.value);
},
refresh: () => {
if (adjustmentDatePicker.obj) {
adjustmentDatePicker.obj.value = state.adjustmentDate ? new Date(state.adjustmentDate) : null;
}
}
};
Vue.watch(
() => state.adjustmentDate,
(newVal, oldVal) => {
adjustmentDatePicker.refresh();
state.errors.adjustmentDate = '';
}
);
const numberText = {
obj: null,
create: () => {
numberText.obj = new ej.inputs.TextBox({
placeholder: '[auto]',
});
numberText.obj.appendTo(numberRef.value);
}
};
const negativeAdjustmentStatusListLookup = {
obj: null,
create: () => {
if (state.negativeAdjustmentStatusListLookupData && Array.isArray(state.negativeAdjustmentStatusListLookupData)) {
negativeAdjustmentStatusListLookup.obj = new ej.dropdowns.DropDownList({
dataSource: state.negativeAdjustmentStatusListLookupData,
fields: { value: 'id', text: 'name' },
placeholder: 'Select Status',
allowFiltering: false,
change: (e) => {
state.status = e.value;
}
});
negativeAdjustmentStatusListLookup.obj.appendTo(statusRef.value);
}
},
refresh: () => {
if (negativeAdjustmentStatusListLookup.obj) {
negativeAdjustmentStatusListLookup.obj.value = state.status
}
},
};
Vue.watch(
() => state.status,
(newVal, oldVal) => {
negativeAdjustmentStatusListLookup.refresh();
state.errors.status = '';
}
);
const services = {
getMainData: async () => {
try {
const response = await AxiosManager.get('/NegativeAdjustment/GetNegativeAdjustmentList', {});
return response;
} catch (error) {
throw error;
}
},
createMainData: async (adjustmentDate, description, status, createdById) => {
try {
const response = await AxiosManager.post('/NegativeAdjustment/CreateNegativeAdjustment', {
adjustmentDate, description, status, createdById
});
return response;
} catch (error) {
throw error;
}
},
updateMainData: async (id, adjustmentDate, description, status, updatedById) => {
try {
const response = await AxiosManager.post('/NegativeAdjustment/UpdateNegativeAdjustment', {
id, adjustmentDate, description, status, updatedById
});
return response;
} catch (error) {
throw error;
}
},
deleteMainData: async (id, deletedById) => {
try {
const response = await AxiosManager.post('/NegativeAdjustment/DeleteNegativeAdjustment', {
id, deletedById
});
return response;
} catch (error) {
throw error;
}
},
getNegativeAdjustmentStatusListLookupData: async () => {
try {
const response = await AxiosManager.get('/NegativeAdjustment/GetNegativeAdjustmentStatusList', {});
return response;
} catch (error) {
throw error;
}
},
getSecondaryData: async (moduleId) => {
try {
const response = await AxiosManager.get('/InventoryTransaction/NegativeAdjustmentGetInvenTransList?moduleId=' + moduleId, {});
return response;
} catch (error) {
throw error;
}
},
createSecondaryData: async (moduleId, warehouseId, productId, movement, createdById) => {
try {
const response = await AxiosManager.post('/InventoryTransaction/NegativeAdjustmentCreateInvenTrans', {
moduleId, warehouseId, productId, movement, createdById
});
return response;
} catch (error) {
throw error;
}
},
updateSecondaryData: async (id, warehouseId, productId, movement, updatedById) => {
try {
const response = await AxiosManager.post('/InventoryTransaction/NegativeAdjustmentUpdateInvenTrans', {
id, warehouseId, productId, movement, updatedById
});
return response;
} catch (error) {
throw error;
}
},
deleteSecondaryData: async (id, deletedById) => {
try {
const response = await AxiosManager.post('/InventoryTransaction/NegativeAdjustmentDeleteInvenTrans', {
id, deletedById
});
return response;
} catch (error) {
throw error;
}
},
getProductListLookupData: async () => {
try {
const response = await AxiosManager.get('/Product/GetProductList', {});
return response;
} catch (error) {
throw error;
}
},
getWarehouseListLookupData: async () => {
try {
const response = await AxiosManager.get('/Warehouse/GetWarehouseList', {});
return response;
} catch (error) {
throw error;
}
},
};
const methods = {
populateMainData: async () => {
const response = await services.getMainData();
state.mainData = response?.data?.content?.data.map(item => ({
...item,
adjustmentDate: new Date(item.adjustmentDate),
createdAtUtc: new Date(item.createdAtUtc)
}));
},
populateNegativeAdjustmentStatusListLookupData: async () => {
const response = await services.getNegativeAdjustmentStatusListLookupData();
state.negativeAdjustmentStatusListLookupData = response?.data?.content?.data;
},
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}`
})) || [];
},
populateWarehouseListLookupData: async () => {
const response = await services.getWarehouseListLookupData();
state.warehouseListLookupData = response?.data?.content?.data.filter(warehouse => warehouse.systemWarehouse === false) || [];
},
populateSecondaryData: async (negativeAdjustmentId) => {
try {
const response = await services.getSecondaryData(negativeAdjustmentId);
state.secondaryData = response?.data?.content?.data.map(item => ({
...item,
createdAtUtc: new Date(item.createdAtUtc)
}));
methods.refreshSummary();
} catch (error) {
state.secondaryData = [];
}
},
refreshSummary: () => {
const totalMovement = state.secondaryData.reduce((sum, record) => sum + (record.movement ?? 0), 0);
state.totalMovementFormatted = NumberFormatManager.formatToLocale(totalMovement);
},
onMainModalHidden: () => {
state.errors.adjustmentDate = '';
state.errors.status = '';
}
};
const handler = {
handleSubmit: async function () {
try {
state.isSubmitting = true;
await new Promise(resolve => setTimeout(resolve, 300));
if (!validateForm()) {
return;
}
const response = state.id === ''
? await services.createMainData(state.adjustmentDate, state.description, state.status, StorageManager.getUserId())
: state.deleteMode
? await services.deleteMainData(state.id, StorageManager.getUserId())
: await services.updateMainData(state.id, state.adjustmentDate, state.description, state.status, StorageManager.getUserId());
if (response.data.code === 200) {
await methods.populateMainData();
mainGrid.refresh();
if (!state.deleteMode) {
state.mainTitle = 'Edit Negative Adjustment';
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(['NegativeAdjustments']);
await SecurityManager.validateToken();
await methods.populateMainData();
await mainGrid.create(state.mainData);
mainModal.create();
mainModalRef.value?.addEventListener('hidden.bs.modal', methods.onMainModalHidden);
await methods.populateNegativeAdjustmentStatusListLookupData();
numberText.create();
adjustmentDatePicker.create();
negativeAdjustmentStatusListLookup.create();
await secondaryGrid.create(state.secondaryData);
await methods.populateProductListLookupData();
await methods.populateWarehouseListLookupData();
} 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: 'adjustmentDate', headerText: 'Adjustment Date', width: 150, format: 'yyyy-MM-dd' },
{ 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', 'adjustmentDate', '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 Negative Adjustment';
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 Negative Adjustment';
state.id = selectedRecord.id ?? '';
state.number = selectedRecord.number ?? '';
state.adjustmentDate = selectedRecord.adjustmentDate ? new Date(selectedRecord.adjustmentDate) : null;
state.description = selectedRecord.description ?? '';
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 Negative Adjustment?';
state.id = selectedRecord.id ?? '';
state.number = selectedRecord.number ?? '';
state.adjustmentDate = selectedRecord.adjustmentDate ? new Date(selectedRecord.adjustmentDate) : null;
state.description = selectedRecord.description ?? '';
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('/NegativeAdjustments/NegativeAdjustmentPdf?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: 'warehouseName', 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: 'warehouseId',
headerText: 'Warehouse',
width: 250,
validationRules: { required: true },
disableHtmlEncode: false,
valueAccessor: (field, data, column) => {
const warehouse = state.warehouseListLookupData.find(item => item.id === data[field]);
return warehouse ? `${warehouse.name}` : '';
},
editType: 'dropdownedit',
edit: {
create: () => {
const warehouseElem = document.createElement('input');
return warehouseElem;
},
read: () => {
return warehouseObj.value;
},
destroy: function () {
warehouseObj.destroy();
},
write: function (args) {
warehouseObj = new ej.dropdowns.DropDownList({
dataSource: state.warehouseListLookupData,
fields: { value: 'id', text: 'name' },
value: args.rowData.warehouseId,
placeholder: 'Select a Warehouse',
floatLabelType: 'Never'
});
warehouseObj.appendTo(args.element);
}
}
},
{
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: () => {
const 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: 'numberName' },
value: args.rowData.productId,
change: function (e) {
if (movementObj) {
movementObj.value = 1;
}
},
placeholder: 'Select a Product',
floatLabelType: 'Never'
});
productObj.appendTo(args.element);
}
}
},
{
field: 'movement',
headerText: 'Movement',
width: 200,
validationRules: {
required: true,
custom: [(args) => {
return args['value'] > 0;
}, 'Must be a positive number and not zero']
},
type: 'number', format: 'N2', textAlign: 'Right',
edit: {
create: () => {
const movementElem = document.createElement('input');
return movementElem;
},
read: () => {
return movementObj.value;
},
destroy: function () {
movementObj.destroy();
},
write: function (args) {
movementObj = new ej.inputs.NumericTextBox({
value: args.rowData.movement ?? 0,
});
movementObj.appendTo(args.element);
}
}
},
],
toolbar: [
'ExcelExport',
{ type: 'Separator' },
'Add', 'Edit', 'Delete', 'Update', 'Cancel',
],
beforeDataBound: () => { },
dataBound: function () { },
excelExportComplete: () => { },
rowSelected: () => {
if (secondaryGrid.obj.getSelectedRecords().length == 1) {
secondaryGrid.obj.toolbarModule.enableItems(['Edit'], true);
} else {
secondaryGrid.obj.toolbarModule.enableItems(['Edit'], false);
}
},
rowDeselected: () => {
if (secondaryGrid.obj.getSelectedRecords().length == 1) {
secondaryGrid.obj.toolbarModule.enableItems(['Edit'], true);
} else {
secondaryGrid.obj.toolbarModule.enableItems(['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.warehouseId, args.data.productId, args.data.movement, 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.warehouseId, args.data.productId, args.data.movement, 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,
numberRef,
adjustmentDateRef,
statusRef,
state,
handler,
};
}
};
Vue.createApp(App).mount('#app');
@@ -0,0 +1,204 @@
@page
@attribute [Authorize(Roles = "NegativeAdjustments")]
@{
ViewData["Title"] = "Negative Adjustment PDF";
}
<div id="app" class="row">
<div class="col-12">
<div class="print-indicator" v-cloak>
<div class="content-wrapper">
<div>
<button id="download-pdf" class="btn btn-danger d-flex align-items-center" v-on:click="handler.downloadPDF" v-bind:disabled="state.isDownloading">
<span class="spinner-border spinner-border-sm me-2" role="status" aria-hidden="true" v-if="state.isDownloading"></span>
<span class="button-text" v-if="!state.isDownloading">
<i class="bi bi-file-earmark-pdf-fill me-2"></i> Download PDF
</span>
</button>
</div>
<div id="content" class="print-area">
<div class="company-info">
<h2>{{ state.company.name }}</h2>
<p>{{ state.companyAddress }}</p>
<p>Email: {{ state.company.emailAddress }} | Phone: {{ state.company.phoneNumber }}</p>
</div>
<h1>Negative Adjustment</h1>
<div class="info-container">
<table class="details-table">
<tr>
<th colspan="2">Adjustment Information</th>
</tr>
<tr>
<td><strong>Number:</strong></td>
<td>{{ state.number }}</td>
</tr>
<tr>
<td><strong>Date:</strong></td>
<td>{{ state.date }}</td>
</tr>
</table>
</div>
<table class="product-table" border="1" style="width: 100%; border-collapse: collapse;">
<thead>
<tr>
<th>Warehouse</th>
<th>Product</th>
<th>Movement</th>
</tr>
</thead>
<tbody>
<tr v-for="item in state.mappedItems" :key="item.product + item.warehouse">
<td>{{ item.warehouse }}</td>
<td>{{ item.product }}</td>
<td>{{ item.movement }}</td>
</tr>
</tbody>
</table>
<div class="summary">
<div class="column"></div>
<div class="column">
<table style="width: 100%; border-collapse: collapse; margin-top: 20px;">
<tr>
<td style="font-weight: bold; font-size: 1.2em;">Total Movement:</td>
<td style="text-align: right; font-weight: bold; font-size: 1.2em; color: #2c3e50;">
{{ state.movementTotal }}
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- CSS -->
<style>
.print-indicator {
display: flex;
justify-content: center;
align-items: flex-start;
height: 100vh;
background-color: #f8f9fa;
position: relative;
overflow-y: auto;
padding: 30px;
}
.content-wrapper {
display: flex;
flex-direction: column;
align-items: center;
gap: 20px;
}
.print-area {
width: 210mm;
padding: 10mm;
background-color: white;
border: 1px dashed #cccccc;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
#download-pdf {
padding: 10px 20px;
font-size: 16px;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.company-info {
text-align: center;
margin-bottom: 20px;
}
.company-info h2 {
font-size: 24px;
margin: 0;
}
.company-info p {
margin: 5px 0;
font-size: 14px;
color: #555;
}
h1 {
text-align: center;
margin-bottom: 20px;
font-size: 28px;
color: #333;
}
.info-container {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
gap: 10px;
}
.details-table {
flex: 1;
padding: 5px 8px;
border: 1px solid #ccc;
font-size: 14px;
}
.details-table th, .details-table td {
padding: 5px 10px;
border: 1px solid #ccc;
font-size: 14px;
}
.details-table th {
background-color: #f2f2f2;
text-align: left;
height: 35px;
vertical-align: middle;
}
.product-table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
font-size: 14px;
}
.product-table th, .product-table td {
padding: 8px;
text-align: left;
}
.product-table th {
background-color: #f2f2f2;
}
.summary {
display: flex;
justify-content: space-between;
margin-top: 20px;
font-size: 14px;
}
.summary .column {
width: 48%;
}
.summary p {
margin: 5px 0;
text-align: right;
}
</style>
@section scripts {
<script src="~/FrontEnd/Pages/NegativeAdjustments/NegativeAdjustmentPdf.cshtml.js"></script>
}
@@ -0,0 +1,128 @@
const App = {
setup() {
const state = Vue.reactive({
company: {
name: '',
emailAddress: '',
phoneNumber: '',
street: '',
city: '',
state: '',
zipCode: '',
country: ''
},
companyAddress: '',
number: '',
date: '',
pdfTransactionList: [],
isDownloading: false,
mappedItems: [],
movementTotal: 0
});
const services = {
getPDFData: async (id) => {
try {
const response = await AxiosManager.get('/NegativeAdjustment/GetNegativeAdjustmentSingle?id=' + id, {});
return response;
} catch (error) {
throw error;
}
},
};
const methods = {
populatePDFData: async (id) => {
const response = await services.getPDFData(id);
state.pdfData = response?.data?.content?.data || {};
state.pdfTransactionList = response?.data?.content?.transactionList || [];
methods.bindPDFControls();
},
bindPDFControls: () => {
const company = StorageManager.getCompany() || state.company;
state.company = {
name: company.name,
emailAddress: company.emailAddress,
phoneNumber: company.phoneNumber,
street: company.street,
city: company.city,
state: company.state,
zipCode: company.zipCode,
country: company.country
};
state.companyAddress = [
company.street,
company.city,
company.state,
company.zipCode,
company.country
].filter(Boolean).join(', ');
const pdfData = state.pdfData;
state.number = pdfData?.number || '';
state.date = DateFormatManager.formatToLocale(pdfData?.adjustmentDate) || '';
state.mappedItems = (state.pdfTransactionList || []).map(item => ({
warehouse: item.warehouse?.name || '',
product: `${item.product?.number || ''} ${item.product?.name || ''}`.trim(),
movement: item.movement || 0,
}));
let movementTotal = (state.pdfTransactionList || []).reduce((sum, item) => sum + (item.movement || 0), 0);
state.movementTotal = NumberFormatManager.formatToLocale(movementTotal);
}
};
const handler = {
downloadPDF: async () => {
state.isDownloading = true;
await new Promise(resolve => setTimeout(resolve, 500));
try {
const { jsPDF } = window.jspdf;
const doc = new jsPDF('p', 'mm', 'a4');
const content = document.getElementById('content');
await html2canvas(content, {
scale: 2,
useCORS: true
}).then(canvas => {
const imgData = canvas.toDataURL('image/png');
const imgWidth = 210;
const pageHeight = 297;
const imgHeight = (canvas.height * imgWidth) / canvas.width;
let position = 0;
doc.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight);
doc.save(`negative-adjustment-${state.number || 'unknown'}.pdf`);
});
} catch (error) {
console.error('Error generating PDF:', error);
} finally {
state.isDownloading = false;
}
},
};
Vue.onMounted(async () => {
try {
await SecurityManager.authorizePage(['NegativeAdjustments']);
var urlParams = new URLSearchParams(window.location.search);
var id = urlParams.get('id');
await methods.populatePDFData(id ?? '');
} catch (e) {
console.error('page init error:', e);
} finally {
}
});
return {
state,
handler,
};
}
};
Vue.createApp(App).mount('#app');