33 lines
860 B
JavaScript
33 lines
860 B
JavaScript
|
|
/**
|
|
* Copyright (c) 2026 Niolla
|
|
* All rights reserved.
|
|
*
|
|
* This source code is proprietary and confidential.
|
|
* Unauthorized copying, modification, distribution, or use
|
|
* of this file, via any medium, is strictly prohibited.
|
|
*/
|
|
|
|
// app/utils/id/confirmOrder.util.js
|
|
|
|
const { nextSequence, pad } = require("../referenceNumber.util");
|
|
const { sequelize } = require("../../models");
|
|
|
|
const generateOrderNumber = async () => {
|
|
const now = new Date();
|
|
|
|
const yy = String(now.getFullYear()).slice(-2);
|
|
const mm = String(now.getMonth() + 1).padStart(2, "0");
|
|
|
|
const period = `${yy}${mm}`;
|
|
|
|
const sequenceKey = `ORD-${period}`;
|
|
|
|
return await sequelize.transaction(async (transaction) => {
|
|
const nextNo = await nextSequence(sequenceKey, transaction);
|
|
|
|
return `OSC/${period}/${pad(nextNo)}`;
|
|
});
|
|
};
|
|
|
|
module.exports = { generateOrderNumber }; |