trạng thái
This commit is contained in:
@@ -407,6 +407,10 @@ function parseNullableDate(value) {
|
||||
function normalizeAssetStatus(value) {
|
||||
const normalized = String(value || '').trim().toLowerCase();
|
||||
|
||||
if (['exported', 'da xuat'].includes(normalized)) {
|
||||
return 'exported';
|
||||
}
|
||||
|
||||
if (['in_use', 'in use', 'dang su dung', 'active'].includes(normalized)) {
|
||||
return 'in_use';
|
||||
}
|
||||
@@ -426,12 +430,61 @@ function normalizeAssetStatus(value) {
|
||||
return 'in_use';
|
||||
}
|
||||
|
||||
function resolveAssetStatusFromStock(endingBalance, borrowingQuantity) {
|
||||
const ending = parseNonNegativeIntegerOrFallback(endingBalance, 0);
|
||||
const borrowing = parseNonNegativeIntegerOrFallback(borrowingQuantity, 0);
|
||||
|
||||
if (ending <= 0) {
|
||||
return 'exported';
|
||||
}
|
||||
|
||||
if (borrowing > 0) {
|
||||
return 'in_use';
|
||||
}
|
||||
|
||||
return 'in_stock';
|
||||
}
|
||||
|
||||
function normalizeAssetStockBuckets(endingBalance, proposedNewQuantity, proposedUsedQuantity) {
|
||||
const ending = parseNonNegativeIntegerOrFallback(endingBalance, 0);
|
||||
let newQuantity = parseNonNegativeIntegerOrFallback(proposedNewQuantity, ending);
|
||||
let usedQuantity = parseNonNegativeIntegerOrFallback(proposedUsedQuantity, 0);
|
||||
|
||||
const currentTotal = newQuantity + usedQuantity;
|
||||
if (currentTotal < ending) {
|
||||
newQuantity += (ending - currentTotal);
|
||||
} else if (currentTotal > ending) {
|
||||
let overflow = currentTotal - ending;
|
||||
const reduceFromNew = Math.min(newQuantity, overflow);
|
||||
newQuantity -= reduceFromNew;
|
||||
overflow -= reduceFromNew;
|
||||
if (overflow > 0) {
|
||||
usedQuantity = Math.max(usedQuantity - overflow, 0);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
newQuantity: Math.max(newQuantity, 0),
|
||||
usedQuantity: Math.max(usedQuantity, 0)
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeAssetPayload(payload = {}) {
|
||||
const quantity = parseNonNegativeIntegerOrFallback(payload.quantity, 0);
|
||||
const importInPeriod = parseNonNegativeIntegerOrFallback(payload.importInPeriod, 0);
|
||||
const exportInPeriod = parseNonNegativeIntegerOrFallback(payload.exportInPeriod, 0);
|
||||
const providedEndingBalance = parseOptionalNonNegativeInteger(payload.endingBalance);
|
||||
const endingBalance = providedEndingBalance !== null ? providedEndingBalance : 0;
|
||||
const endingBalance = providedEndingBalance !== null
|
||||
? providedEndingBalance
|
||||
: Math.max(quantity + importInPeriod - exportInPeriod, 0);
|
||||
const providedNewQuantity = parseOptionalNonNegativeInteger(payload.newQuantity);
|
||||
const providedUsedQuantity = parseOptionalNonNegativeInteger(payload.usedQuantity);
|
||||
const stockBuckets = normalizeAssetStockBuckets(
|
||||
endingBalance,
|
||||
providedNewQuantity !== null ? providedNewQuantity : endingBalance,
|
||||
providedUsedQuantity !== null ? providedUsedQuantity : 0
|
||||
);
|
||||
const status = resolveAssetStatusFromStock(endingBalance, exportInPeriod);
|
||||
|
||||
return {
|
||||
assetCode: String(payload.assetCode || '').trim(),
|
||||
@@ -445,12 +498,14 @@ function normalizeAssetPayload(payload = {}) {
|
||||
importInPeriod,
|
||||
exportInPeriod,
|
||||
endingBalance,
|
||||
newQuantity: stockBuckets.newQuantity,
|
||||
usedQuantity: stockBuckets.usedQuantity,
|
||||
location: String(payload.location || '').trim() || null,
|
||||
custodian: String(payload.custodian || '').trim() || null,
|
||||
borrower: String(payload.borrower || '').trim() || null,
|
||||
purchaseDate: parseNullableDate(payload.purchaseDate),
|
||||
purchasePrice: parseNullableDecimal(payload.purchasePrice),
|
||||
status: normalizeAssetStatus(payload.status),
|
||||
status,
|
||||
notes: String(payload.notes || '').trim() || null
|
||||
};
|
||||
}
|
||||
@@ -1659,6 +1714,8 @@ async function createTables() {
|
||||
ImportInPeriod INT NOT NULL DEFAULT 0,
|
||||
ExportInPeriod INT NOT NULL DEFAULT 0,
|
||||
EndingBalance INT NOT NULL DEFAULT 0,
|
||||
NewQuantity INT NOT NULL DEFAULT 0,
|
||||
UsedQuantity INT NOT NULL DEFAULT 0,
|
||||
Unit NVARCHAR(50),
|
||||
Department NVARCHAR(100),
|
||||
Project NVARCHAR(150),
|
||||
@@ -1826,6 +1883,8 @@ async function createTables() {
|
||||
await pool.request().query(`IF COL_LENGTH('dbo.AssetInventory','ImportInPeriod') IS NULL ALTER TABLE AssetInventory ADD ImportInPeriod INT NOT NULL CONSTRAINT DF_AssetInventory_ImportInPeriod DEFAULT(0);`);
|
||||
await pool.request().query(`IF COL_LENGTH('dbo.AssetInventory','ExportInPeriod') IS NULL ALTER TABLE AssetInventory ADD ExportInPeriod INT NOT NULL CONSTRAINT DF_AssetInventory_ExportInPeriod DEFAULT(0);`);
|
||||
await pool.request().query(`IF COL_LENGTH('dbo.AssetInventory','EndingBalance') IS NULL ALTER TABLE AssetInventory ADD EndingBalance INT NOT NULL CONSTRAINT DF_AssetInventory_EndingBalance DEFAULT(0);`);
|
||||
await pool.request().query(`IF COL_LENGTH('dbo.AssetInventory','NewQuantity') IS NULL ALTER TABLE AssetInventory ADD NewQuantity INT NOT NULL CONSTRAINT DF_AssetInventory_NewQuantity DEFAULT(0);`);
|
||||
await pool.request().query(`IF COL_LENGTH('dbo.AssetInventory','UsedQuantity') IS NULL ALTER TABLE AssetInventory ADD UsedQuantity INT NOT NULL CONSTRAINT DF_AssetInventory_UsedQuantity DEFAULT(0);`);
|
||||
await pool.request().query(`IF COL_LENGTH('dbo.AssetInventory','Project') IS NULL ALTER TABLE AssetInventory ADD Project NVARCHAR(150) NULL;`);
|
||||
await pool.request().query(`IF COL_LENGTH('dbo.AssetInventory','Borrower') IS NULL ALTER TABLE AssetInventory ADD Borrower NVARCHAR(255) NULL;`);
|
||||
await pool.request().query(`IF COL_LENGTH('dbo.AssetInventory','ExportedBy') IS NULL ALTER TABLE AssetInventory ADD ExportedBy NVARCHAR(100) NULL;`);
|
||||
@@ -1881,6 +1940,34 @@ async function createTables() {
|
||||
await pool.request().query(`UPDATE AssetBorrowRequests SET RequestStatus = ISNULL(NULLIF(LTRIM(RTRIM(RequestStatus)), ''), 'approved');`);
|
||||
await pool.request().query(`UPDATE AssetInventory SET EndingBalance = ISNULL(EndingBalance, ISNULL(Quantity, 0));`);
|
||||
await pool.request().query(`UPDATE AssetInventory SET Quantity = ISNULL(NULLIF(Quantity, 0), EndingBalance);`);
|
||||
await pool.request().query(`UPDATE AssetInventory SET UsedQuantity = CASE WHEN UsedQuantity < 0 THEN 0 ELSE ISNULL(UsedQuantity, 0) END;`);
|
||||
await pool.request().query(`
|
||||
UPDATE AssetInventory
|
||||
SET NewQuantity = CASE
|
||||
WHEN ISNULL(NewQuantity, 0) < 0 THEN 0
|
||||
ELSE ISNULL(NewQuantity, 0)
|
||||
END;
|
||||
`);
|
||||
await pool.request().query(`
|
||||
UPDATE AssetInventory
|
||||
SET NewQuantity = CASE
|
||||
WHEN (ISNULL(NewQuantity, 0) + ISNULL(UsedQuantity, 0)) < ISNULL(EndingBalance, 0)
|
||||
THEN ISNULL(NewQuantity, 0) + (ISNULL(EndingBalance, 0) - (ISNULL(NewQuantity, 0) + ISNULL(UsedQuantity, 0)))
|
||||
WHEN (ISNULL(NewQuantity, 0) + ISNULL(UsedQuantity, 0)) > ISNULL(EndingBalance, 0)
|
||||
THEN CASE
|
||||
WHEN ISNULL(NewQuantity, 0) >= ((ISNULL(NewQuantity, 0) + ISNULL(UsedQuantity, 0)) - ISNULL(EndingBalance, 0))
|
||||
THEN ISNULL(NewQuantity, 0) - ((ISNULL(NewQuantity, 0) + ISNULL(UsedQuantity, 0)) - ISNULL(EndingBalance, 0))
|
||||
ELSE 0
|
||||
END
|
||||
ELSE ISNULL(NewQuantity, 0)
|
||||
END,
|
||||
UsedQuantity = CASE
|
||||
WHEN (ISNULL(NewQuantity, 0) + ISNULL(UsedQuantity, 0)) > ISNULL(EndingBalance, 0)
|
||||
AND ISNULL(NewQuantity, 0) < ((ISNULL(NewQuantity, 0) + ISNULL(UsedQuantity, 0)) - ISNULL(EndingBalance, 0))
|
||||
THEN ISNULL(EndingBalance, 0)
|
||||
ELSE ISNULL(UsedQuantity, 0)
|
||||
END;
|
||||
`);
|
||||
await pool.request().query(`
|
||||
UPDATE ai
|
||||
SET ai.ExportedBy = COALESCE(NULLIF(LTRIM(RTRIM(u.FullName)), ''), NULLIF(LTRIM(RTRIM(u.Username)), ''))
|
||||
@@ -3708,6 +3795,11 @@ app.post('/api/asset-borrows/:id/process', requireAssetOrAdmin, async (req, res)
|
||||
ai.AssetName,
|
||||
ai.Quantity,
|
||||
ai.ImportInPeriod,
|
||||
ai.ExportInPeriod,
|
||||
ai.EndingBalance,
|
||||
ai.NewQuantity,
|
||||
ai.UsedQuantity,
|
||||
ai.Status,
|
||||
ai.Borrower,
|
||||
ai.Unit AS AssetUnit
|
||||
FROM AssetBorrowRequests br
|
||||
@@ -3736,12 +3828,21 @@ app.post('/api/asset-borrows/:id/process', requireAssetOrAdmin, async (req, res)
|
||||
const currentBorrowed = parseBorrowerEntries(targetRequest.Borrower).reduce((sum, entry) => (
|
||||
sum + parseNonNegativeInteger(entry?.quantity, 0)
|
||||
), 0);
|
||||
const endingBalance = Math.max(
|
||||
const derivedEndingBalance = Math.max(
|
||||
parseNonNegativeInteger(targetRequest.Quantity, 0)
|
||||
+ parseNonNegativeInteger(targetRequest.ImportInPeriod, 0)
|
||||
- currentBorrowed,
|
||||
0
|
||||
);
|
||||
const baseEndingBalance = parseOptionalNonNegativeInteger(targetRequest.EndingBalance);
|
||||
const endingBalance = baseEndingBalance !== null ? baseEndingBalance : derivedEndingBalance;
|
||||
const baseNewQuantity = parseOptionalNonNegativeInteger(targetRequest.NewQuantity);
|
||||
const baseUsedQuantity = parseOptionalNonNegativeInteger(targetRequest.UsedQuantity);
|
||||
const stockBuckets = normalizeAssetStockBuckets(
|
||||
endingBalance,
|
||||
baseNewQuantity !== null ? baseNewQuantity : endingBalance,
|
||||
baseUsedQuantity !== null ? baseUsedQuantity : 0
|
||||
);
|
||||
|
||||
if (requestQuantity > endingBalance) {
|
||||
await transaction.rollback();
|
||||
@@ -3765,22 +3866,31 @@ app.post('/api/asset-borrows/:id/process', requireAssetOrAdmin, async (req, res)
|
||||
});
|
||||
}
|
||||
|
||||
const borrowFromNew = Math.min(stockBuckets.newQuantity, requestQuantity);
|
||||
const borrowFromUsed = Math.max(requestQuantity - borrowFromNew, 0);
|
||||
const nextEndingBalance = Math.max(endingBalance - requestQuantity, 0);
|
||||
const nextNewQuantity = Math.max(stockBuckets.newQuantity - borrowFromNew, 0);
|
||||
const nextUsedQuantity = Math.max(stockBuckets.usedQuantity - borrowFromUsed, 0);
|
||||
const nextBorrowingQuantity = currentBorrowed + requestQuantity;
|
||||
const nextStatus = resolveAssetStatusFromStock(nextEndingBalance, nextBorrowingQuantity);
|
||||
|
||||
await new sql.Request(transaction)
|
||||
.input('assetId', sql.Int, targetRequest.AssetId)
|
||||
.input('borrower', sql.NVarChar, mergedBorrowerSummary)
|
||||
.input('exportInPeriod', sql.Int, currentBorrowed + requestQuantity)
|
||||
.input('endingBalance', sql.Int, Math.max(
|
||||
parseNonNegativeInteger(targetRequest.Quantity, 0)
|
||||
+ parseNonNegativeInteger(targetRequest.ImportInPeriod, 0)
|
||||
- (currentBorrowed + requestQuantity),
|
||||
0
|
||||
))
|
||||
.input('exportInPeriod', sql.Int, nextBorrowingQuantity)
|
||||
.input('endingBalance', sql.Int, nextEndingBalance)
|
||||
.input('newQuantity', sql.Int, nextNewQuantity)
|
||||
.input('usedQuantity', sql.Int, nextUsedQuantity)
|
||||
.input('status', sql.NVarChar, nextStatus)
|
||||
.input('exportedBy', sql.NVarChar, processorName || null)
|
||||
.query(`
|
||||
UPDATE AssetInventory
|
||||
SET Borrower = @borrower,
|
||||
ExportInPeriod = @exportInPeriod,
|
||||
EndingBalance = @endingBalance,
|
||||
NewQuantity = @newQuantity,
|
||||
UsedQuantity = @usedQuantity,
|
||||
Status = @status,
|
||||
ExportedBy = @exportedBy,
|
||||
UpdatedDate = GETDATE()
|
||||
WHERE AssetId = @assetId
|
||||
@@ -3806,17 +3916,40 @@ app.post('/api/asset-borrows/:id/process', requireAssetOrAdmin, async (req, res)
|
||||
), 0);
|
||||
const quantity = parseNonNegativeInteger(targetRequest.Quantity, 0);
|
||||
const importInPeriod = parseNonNegativeInteger(targetRequest.ImportInPeriod, 0);
|
||||
const derivedEndingBalance = Math.max(quantity + importInPeriod - parseNonNegativeInteger(targetRequest.ExportInPeriod, 0), 0);
|
||||
const baseEndingBalance = parseOptionalNonNegativeInteger(targetRequest.EndingBalance);
|
||||
const currentEndingBalance = baseEndingBalance !== null ? baseEndingBalance : derivedEndingBalance;
|
||||
const baseNewQuantity = parseOptionalNonNegativeInteger(targetRequest.NewQuantity);
|
||||
const baseUsedQuantity = parseOptionalNonNegativeInteger(targetRequest.UsedQuantity);
|
||||
const stockBuckets = normalizeAssetStockBuckets(
|
||||
currentEndingBalance,
|
||||
baseNewQuantity !== null ? baseNewQuantity : currentEndingBalance,
|
||||
baseUsedQuantity !== null ? baseUsedQuantity : 0
|
||||
);
|
||||
const nextEndingBalance = Math.max(quantity + importInPeriod - remainingBorrowed, 0);
|
||||
const nextBuckets = normalizeAssetStockBuckets(
|
||||
nextEndingBalance,
|
||||
stockBuckets.newQuantity,
|
||||
stockBuckets.usedQuantity + requestQuantity
|
||||
);
|
||||
const nextStatus = resolveAssetStatusFromStock(nextEndingBalance, remainingBorrowed);
|
||||
await new sql.Request(transaction)
|
||||
.input('assetId', sql.Int, targetRequest.AssetId)
|
||||
.input('borrower', sql.NVarChar, borrowerSummary)
|
||||
.input('exportInPeriod', sql.Int, remainingBorrowed)
|
||||
.input('endingBalance', sql.Int, Math.max(quantity + importInPeriod - remainingBorrowed, 0))
|
||||
.input('endingBalance', sql.Int, nextEndingBalance)
|
||||
.input('newQuantity', sql.Int, nextBuckets.newQuantity)
|
||||
.input('usedQuantity', sql.Int, nextBuckets.usedQuantity)
|
||||
.input('status', sql.NVarChar, nextStatus)
|
||||
.input('exportedBy', sql.NVarChar, processorName || null)
|
||||
.query(`
|
||||
UPDATE AssetInventory
|
||||
SET Borrower = @borrower,
|
||||
ExportInPeriod = @exportInPeriod,
|
||||
EndingBalance = @endingBalance,
|
||||
NewQuantity = @newQuantity,
|
||||
UsedQuantity = @usedQuantity,
|
||||
Status = @status,
|
||||
ExportedBy = CASE WHEN @borrower IS NULL THEN NULL ELSE @exportedBy END,
|
||||
UpdatedDate = GETDATE()
|
||||
WHERE AssetId = @assetId
|
||||
@@ -3931,8 +4064,15 @@ app.get('/api/assets', async (req, res) => {
|
||||
const result = await pool.request().query(`
|
||||
SELECT AssetId, AssetCode, AssetName, Model, SerialNumber,
|
||||
Quantity, ImportInPeriod, ExportInPeriod, EndingBalance,
|
||||
NewQuantity, UsedQuantity,
|
||||
Unit, Department, Project, Location, Custodian, Borrower, ExportedBy,
|
||||
PurchaseDate, PurchasePrice, Status, Notes, CreatedBy, CreatedDate, UpdatedDate
|
||||
PurchaseDate, PurchasePrice,
|
||||
CASE
|
||||
WHEN ISNULL(EndingBalance, 0) <= 0 THEN 'exported'
|
||||
WHEN ISNULL(ExportInPeriod, 0) > 0 THEN 'in_use'
|
||||
ELSE 'in_stock'
|
||||
END AS Status,
|
||||
Notes, CreatedBy, CreatedDate, UpdatedDate
|
||||
FROM AssetInventory
|
||||
ORDER BY UpdatedDate DESC, AssetName ASC
|
||||
`);
|
||||
@@ -4016,8 +4156,15 @@ app.get('/api/assets/:id', async (req, res) => {
|
||||
.query(`
|
||||
SELECT AssetId, AssetCode, AssetName, Model, SerialNumber,
|
||||
Quantity, ImportInPeriod, ExportInPeriod, EndingBalance,
|
||||
NewQuantity, UsedQuantity,
|
||||
Unit, Department, Project, Location, Custodian, Borrower, ExportedBy,
|
||||
PurchaseDate, PurchasePrice, Status, Notes, CreatedBy, CreatedDate, UpdatedDate
|
||||
PurchaseDate, PurchasePrice,
|
||||
CASE
|
||||
WHEN ISNULL(EndingBalance, 0) <= 0 THEN 'exported'
|
||||
WHEN ISNULL(ExportInPeriod, 0) > 0 THEN 'in_use'
|
||||
ELSE 'in_stock'
|
||||
END AS Status,
|
||||
Notes, CreatedBy, CreatedDate, UpdatedDate
|
||||
FROM AssetInventory
|
||||
WHERE AssetId = @assetId
|
||||
`);
|
||||
@@ -4104,6 +4251,8 @@ app.post('/api/assets/:id/export', requireAssetOrAdmin, async (req, res) => {
|
||||
ImportInPeriod,
|
||||
ExportInPeriod,
|
||||
EndingBalance,
|
||||
NewQuantity,
|
||||
UsedQuantity,
|
||||
Custodian,
|
||||
Borrower
|
||||
FROM AssetInventory WITH (UPDLOCK, ROWLOCK)
|
||||
@@ -4129,6 +4278,13 @@ app.post('/api/assets/:id/export', requireAssetOrAdmin, async (req, res) => {
|
||||
const baseEndingBalance = storedEndingBalance !== null
|
||||
? storedEndingBalance
|
||||
: Math.max(quantity + importInPeriod - baseExportInPeriod, 0);
|
||||
const baseNewQuantity = parseOptionalNonNegativeInteger(asset.NewQuantity);
|
||||
const baseUsedQuantity = parseOptionalNonNegativeInteger(asset.UsedQuantity);
|
||||
const stockBuckets = normalizeAssetStockBuckets(
|
||||
baseEndingBalance,
|
||||
baseNewQuantity !== null ? baseNewQuantity : baseEndingBalance,
|
||||
baseUsedQuantity !== null ? baseUsedQuantity : 0
|
||||
);
|
||||
|
||||
if (baseEndingBalance <= 0) {
|
||||
await transaction.rollback();
|
||||
@@ -4150,6 +4306,11 @@ app.post('/api/assets/:id/export', requireAssetOrAdmin, async (req, res) => {
|
||||
const exportDelta = nextBorrowerExport - previousBorrowerExport;
|
||||
const nextExportInPeriod = Math.max(baseExportInPeriod + exportDelta, 0);
|
||||
const nextEndingBalance = Math.max(baseEndingBalance - exportDelta, 0);
|
||||
const borrowFromNew = Math.min(stockBuckets.newQuantity, exportDelta);
|
||||
const borrowFromUsed = Math.max(exportDelta - borrowFromNew, 0);
|
||||
const nextNewQuantity = Math.max(stockBuckets.newQuantity - borrowFromNew, 0);
|
||||
const nextUsedQuantity = Math.max(stockBuckets.usedQuantity - borrowFromUsed, 0);
|
||||
const nextStatus = resolveAssetStatusFromStock(nextEndingBalance, nextExportInPeriod);
|
||||
|
||||
await new sql.Request(transaction)
|
||||
.input('assetId', sql.Int, assetId)
|
||||
@@ -4157,6 +4318,9 @@ app.post('/api/assets/:id/export', requireAssetOrAdmin, async (req, res) => {
|
||||
.input('borrower', sql.NVarChar, borrowerSummary)
|
||||
.input('exportInPeriod', sql.Int, nextExportInPeriod)
|
||||
.input('endingBalance', sql.Int, nextEndingBalance)
|
||||
.input('newQuantity', sql.Int, nextNewQuantity)
|
||||
.input('usedQuantity', sql.Int, nextUsedQuantity)
|
||||
.input('status', sql.NVarChar, nextStatus)
|
||||
.input('exportedBy', sql.NVarChar, exportedByName)
|
||||
.query(`
|
||||
UPDATE AssetInventory
|
||||
@@ -4164,6 +4328,9 @@ app.post('/api/assets/:id/export', requireAssetOrAdmin, async (req, res) => {
|
||||
Borrower = @borrower,
|
||||
ExportInPeriod = @exportInPeriod,
|
||||
EndingBalance = @endingBalance,
|
||||
NewQuantity = @newQuantity,
|
||||
UsedQuantity = @usedQuantity,
|
||||
Status = @status,
|
||||
ExportedBy = @exportedBy,
|
||||
UpdatedDate = GETDATE()
|
||||
WHERE AssetId = @assetId
|
||||
@@ -4266,6 +4433,8 @@ app.post('/api/assets', requireAssetOrAdmin, async (req, res) => {
|
||||
.input('importInPeriod', sql.Int, payload.importInPeriod)
|
||||
.input('exportInPeriod', sql.Int, payload.exportInPeriod)
|
||||
.input('endingBalance', sql.Int, payload.endingBalance)
|
||||
.input('newQuantity', sql.Int, payload.newQuantity)
|
||||
.input('usedQuantity', sql.Int, payload.usedQuantity)
|
||||
.input('unit', sql.NVarChar, payload.unit)
|
||||
.input('department', sql.NVarChar, payload.department)
|
||||
.input('project', sql.NVarChar, payload.project)
|
||||
@@ -4281,12 +4450,12 @@ app.post('/api/assets', requireAssetOrAdmin, async (req, res) => {
|
||||
.query(`
|
||||
INSERT INTO AssetInventory (
|
||||
AssetCode, AssetName, Model, SerialNumber,
|
||||
Quantity, ImportInPeriod, ExportInPeriod, EndingBalance,
|
||||
Quantity, ImportInPeriod, ExportInPeriod, EndingBalance, NewQuantity, UsedQuantity,
|
||||
Unit, Department, Project, Location, Custodian, Borrower, ExportedBy,
|
||||
PurchaseDate, PurchasePrice, Status, Notes, CreatedBy
|
||||
) VALUES (
|
||||
@assetCode, @assetName, @model, @serialNumber,
|
||||
@quantity, @importInPeriod, @exportInPeriod, @endingBalance,
|
||||
@quantity, @importInPeriod, @exportInPeriod, @endingBalance, @newQuantity, @usedQuantity,
|
||||
@unit, @department, @project, @location, @custodian, @borrower, @exportedBy,
|
||||
@purchaseDate, @purchasePrice, @status, @notes, @createdBy
|
||||
);
|
||||
@@ -4325,6 +4494,8 @@ app.put('/api/assets/:id', requireAssetOrAdmin, async (req, res) => {
|
||||
.input('importInPeriod', sql.Int, payload.importInPeriod)
|
||||
.input('exportInPeriod', sql.Int, payload.exportInPeriod)
|
||||
.input('endingBalance', sql.Int, payload.endingBalance)
|
||||
.input('newQuantity', sql.Int, payload.newQuantity)
|
||||
.input('usedQuantity', sql.Int, payload.usedQuantity)
|
||||
.input('unit', sql.NVarChar, payload.unit)
|
||||
.input('department', sql.NVarChar, payload.department)
|
||||
.input('project', sql.NVarChar, payload.project)
|
||||
@@ -4346,6 +4517,8 @@ app.put('/api/assets/:id', requireAssetOrAdmin, async (req, res) => {
|
||||
ImportInPeriod = @importInPeriod,
|
||||
ExportInPeriod = @exportInPeriod,
|
||||
EndingBalance = @endingBalance,
|
||||
NewQuantity = @newQuantity,
|
||||
UsedQuantity = @usedQuantity,
|
||||
Unit = @unit,
|
||||
Department = @department,
|
||||
Project = @project,
|
||||
@@ -4461,6 +4634,8 @@ app.post('/api/assets/import', requireAssetOrAdmin, upload.single('file'), async
|
||||
.input('importInPeriod', sql.Int, row.importInPeriod)
|
||||
.input('exportInPeriod', sql.Int, row.exportInPeriod)
|
||||
.input('endingBalance', sql.Int, row.endingBalance)
|
||||
.input('newQuantity', sql.Int, row.newQuantity)
|
||||
.input('usedQuantity', sql.Int, row.usedQuantity)
|
||||
.input('unit', sql.NVarChar, row.unit)
|
||||
.input('department', sql.NVarChar, row.department)
|
||||
.input('project', sql.NVarChar, row.project)
|
||||
@@ -4476,13 +4651,13 @@ app.post('/api/assets/import', requireAssetOrAdmin, upload.single('file'), async
|
||||
.query(`
|
||||
INSERT INTO AssetInventory (
|
||||
AssetCode, AssetName, Model, SerialNumber,
|
||||
Quantity, ImportInPeriod, ExportInPeriod, EndingBalance,
|
||||
Quantity, ImportInPeriod, ExportInPeriod, EndingBalance, NewQuantity, UsedQuantity,
|
||||
Unit, Department, Project, Location, Custodian, Borrower, ExportedBy,
|
||||
PurchaseDate, PurchasePrice, Status, Notes, CreatedBy
|
||||
)
|
||||
VALUES (
|
||||
@assetCode, @assetName, @model, @serialNumber,
|
||||
@quantity, @importInPeriod, @exportInPeriod, @endingBalance,
|
||||
@quantity, @importInPeriod, @exportInPeriod, @endingBalance, @newQuantity, @usedQuantity,
|
||||
@unit, @department, @project, @location, @custodian, @borrower, @exportedBy,
|
||||
@purchaseDate, @purchasePrice, @status, @notes, @createdBy
|
||||
);
|
||||
@@ -4500,6 +4675,8 @@ app.post('/api/assets/import', requireAssetOrAdmin, upload.single('file'), async
|
||||
.input('importInPeriod', sql.Int, row.importInPeriod)
|
||||
.input('exportInPeriod', sql.Int, row.exportInPeriod)
|
||||
.input('endingBalance', sql.Int, row.endingBalance)
|
||||
.input('newQuantity', sql.Int, row.newQuantity)
|
||||
.input('usedQuantity', sql.Int, row.usedQuantity)
|
||||
.input('unit', sql.NVarChar, row.unit)
|
||||
.input('department', sql.NVarChar, row.department)
|
||||
.input('project', sql.NVarChar, row.project)
|
||||
@@ -4525,6 +4702,8 @@ app.post('/api/assets/import', requireAssetOrAdmin, upload.single('file'), async
|
||||
ImportInPeriod = @importInPeriod,
|
||||
ExportInPeriod = @exportInPeriod,
|
||||
EndingBalance = @endingBalance,
|
||||
NewQuantity = @newQuantity,
|
||||
UsedQuantity = @usedQuantity,
|
||||
Unit = @unit,
|
||||
Department = @department,
|
||||
Project = @project,
|
||||
@@ -4540,13 +4719,13 @@ app.post('/api/assets/import', requireAssetOrAdmin, upload.single('file'), async
|
||||
WHEN NOT MATCHED THEN
|
||||
INSERT (
|
||||
AssetCode, AssetName, Model, SerialNumber,
|
||||
Quantity, ImportInPeriod, ExportInPeriod, EndingBalance,
|
||||
Quantity, ImportInPeriod, ExportInPeriod, EndingBalance, NewQuantity, UsedQuantity,
|
||||
Unit, Department, Project, Location, Custodian, Borrower, ExportedBy,
|
||||
PurchaseDate, PurchasePrice, Status, Notes, CreatedBy
|
||||
)
|
||||
VALUES (
|
||||
@assetCode, @assetName, @model, @serialNumber,
|
||||
@quantity, @importInPeriod, @exportInPeriod, @endingBalance,
|
||||
@quantity, @importInPeriod, @exportInPeriod, @endingBalance, @newQuantity, @usedQuantity,
|
||||
@unit, @department, @project, @location, @custodian, @borrower, @exportedBy,
|
||||
@purchaseDate, @purchasePrice, @status, @notes, @createdBy
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user