Compare commits
No commits in common. '719c2388be842336d90c446aafc3f5f3b6b90a3f' and '9d0b59ac0608073332e2bae52107347556bf9f09' have entirely different histories.
719c2388be
...
9d0b59ac06
14 changed files with 8 additions and 332 deletions
@ -1,140 +0,0 @@ |
|||||||
|
|
||||||
|
|
||||||
const asyncHandler = require("../Middleware/async"); |
|
||||||
const sequelize = require('sequelize') |
|
||||||
const db = require('../Config/db') |
|
||||||
const SupplierModel = require('../Model/SupplierModel') |
|
||||||
const ErrorResponse = require('../utils/errorResponse') |
|
||||||
const SuccessResponse = require('../utils/SuccessResponse') |
|
||||||
const fs = require('fs'); |
|
||||||
const DeliveryAdressModel = require('../Model/DeliveryModel') |
|
||||||
|
|
||||||
const dateFormat = require('dateformat'); |
|
||||||
|
|
||||||
exports.getAllDeliveryAddress = asyncHandler(async (req, res, next) => { |
|
||||||
try { |
|
||||||
|
|
||||||
const deliveryAddress = await DeliveryAdressModel.findAll({ |
|
||||||
where: { |
|
||||||
DEL_TYPE: "1" |
|
||||||
} |
|
||||||
}) |
|
||||||
// console.log(obj);
|
|
||||||
// const supplier = await SupplierModel.findAll({
|
|
||||||
// where: {
|
|
||||||
// DB_CODE: req.user.DB_CODE
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// )
|
|
||||||
res.status(200).send({ |
|
||||||
success: true, |
|
||||||
data: deliveryAddress |
|
||||||
}) |
|
||||||
} catch (e) { |
|
||||||
console.log("ERROR : ", e) |
|
||||||
throw new ErrorResponse(e, 400) |
|
||||||
} |
|
||||||
}) |
|
||||||
|
|
||||||
exports.getAllDeliveryAddressBySupplier = asyncHandler(async (req, res, next) => { |
|
||||||
try { |
|
||||||
const deliveryAddress = await DeliveryAddressModel.findAll({ |
|
||||||
where: { |
|
||||||
DB_CODE: req.dbcode, |
|
||||||
DEL_CODE: req.params.id |
|
||||||
} |
|
||||||
}) |
|
||||||
res.status(200).send({ |
|
||||||
success: true, |
|
||||||
data: deliveryAddress |
|
||||||
}) |
|
||||||
} |
|
||||||
catch (e) { |
|
||||||
throw new ErrorResponse(e, 400) |
|
||||||
} |
|
||||||
}) |
|
||||||
|
|
||||||
exports.postDeliveryAddress = asyncHandler(async (req, res, next) => { |
|
||||||
const { DEL_ADD_1, DEL_NAME } = req.body; |
|
||||||
|
|
||||||
const data = req.body; |
|
||||||
if (!DEL_ADD_1) { |
|
||||||
return next( |
|
||||||
new ErrorResponse("Please provide a delivery address information!", 400) |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
if (!DEL_NAME) { |
|
||||||
return next( |
|
||||||
new ErrorResponse("Please provide a delivery name!", 400) |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
let ADD_CODE |
|
||||||
if (!data["ADD_CODE"]) { |
|
||||||
ADD_CODE = await generateNextAddressCode(req.user.DB_CODE); |
|
||||||
} |
|
||||||
try { |
|
||||||
await DeliveryAdressModel.sequelize.transaction(async (t) => { |
|
||||||
await DeliveryAdressModel.create( |
|
||||||
{ |
|
||||||
ADD_CODE: "", // if it is supplier then no need to add ADD_CODE in this table
|
|
||||||
DB_CODE: req.user.DB_CODE, |
|
||||||
DEL_CODE: data["ADD_CODE"] ?? ADD_CODE, |
|
||||||
DEL_NAME: data["DEL_NAME"], |
|
||||||
DEL_ADD_1: DEL_ADD_1, |
|
||||||
DEL_ADD_2: "", |
|
||||||
DEL_ADD_3: "", |
|
||||||
DEL_ADD_4: "", |
|
||||||
DEL_ADD_5: "", |
|
||||||
DEL_TEL: data["DEL_TEL"] ?? "", |
|
||||||
DEL_FAX: data["DEL_FAX"] ?? "", |
|
||||||
DEL_EMAIL: "", |
|
||||||
DEL_WEB: "", |
|
||||||
DEL_CONT: "", |
|
||||||
DEL_COM_1: "", |
|
||||||
DEL_COM_2: "", |
|
||||||
DEL_TYPE: "0", // 1 for CUSTOMER 0 for SUPPLIER
|
|
||||||
USER_CREA: dateFormat(new Date(), "yyyy-mm-dd"), |
|
||||||
USER_UPDT: dateFormat(new Date(), "yyyy-mm-dd"), |
|
||||||
USER_CODE: req.user.USER_NAME, |
|
||||||
}, |
|
||||||
{ transaction: t } |
|
||||||
); |
|
||||||
res.send(new SuccessResponse("success")).status(200); |
|
||||||
}); |
|
||||||
} catch (error) { |
|
||||||
|
|
||||||
return next(new ErrorResponse(`Server Error ${error}`, 500)); |
|
||||||
} |
|
||||||
}) |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function generateNextAddressCode(dbCode) { |
|
||||||
const lastSupplier = await DeliveryAddressModel.findOne( |
|
||||||
{ |
|
||||||
where: { |
|
||||||
DB_CODE: dbCode |
|
||||||
}, |
|
||||||
order: [ |
|
||||||
[sequelize.cast(sequelize.col('ADD_CODE'), 'integer'), 'DESC'] |
|
||||||
] |
|
||||||
}); |
|
||||||
|
|
||||||
if (!lastSupplier) { |
|
||||||
return '0001'; // Starting point if no suppliers are present
|
|
||||||
} |
|
||||||
console.log("LAST SUPPLIER CODE ", lastSupplier.ADD_CODE) |
|
||||||
|
|
||||||
let nextCode = parseInt(lastSupplier.ADD_CODE, 10) + 1; |
|
||||||
|
|
||||||
// Check if the number is less than 10000 for zero-padding
|
|
||||||
if (nextCode < 10000) { |
|
||||||
return nextCode.toString().padStart(4, '0'); |
|
||||||
} else { |
|
||||||
// If it's 10000 or more, just return the number
|
|
||||||
return nextCode.toString(); |
|
||||||
} |
|
||||||
} |
|
@ -1,82 +0,0 @@ |
|||||||
const sequelize = require('sequelize') |
|
||||||
const db = require('../Config/db') |
|
||||||
|
|
||||||
const DeliveryAddressModel = db.define( |
|
||||||
'TDDADD', |
|
||||||
{ |
|
||||||
ADD_CODE: { |
|
||||||
type: sequelize.STRING, |
|
||||||
}, |
|
||||||
DB_CODE: { |
|
||||||
type: sequelize.STRING |
|
||||||
}, |
|
||||||
DEL_CODE: { |
|
||||||
type: sequelize.STRING |
|
||||||
|
|
||||||
}, |
|
||||||
DEL_NAME: { |
|
||||||
type: sequelize.STRING |
|
||||||
}, |
|
||||||
DEL_ADD_1: { |
|
||||||
type: sequelize.STRING |
|
||||||
}, |
|
||||||
DEL_ADD_2: { |
|
||||||
type: sequelize.STRING |
|
||||||
}, |
|
||||||
DEL_ADD_3: { |
|
||||||
type: sequelize.STRING |
|
||||||
}, |
|
||||||
DEL_ADD_4: { |
|
||||||
type: sequelize.STRING |
|
||||||
}, |
|
||||||
DEL_ADD_5: { |
|
||||||
type: sequelize.STRING |
|
||||||
}, |
|
||||||
DEL_TEL: { |
|
||||||
type: sequelize.STRING |
|
||||||
}, |
|
||||||
DEL_FAX: { |
|
||||||
type: sequelize.STRING |
|
||||||
}, |
|
||||||
DEL_EMAIL: { |
|
||||||
type: sequelize.STRING |
|
||||||
}, |
|
||||||
DEL_WEB: { |
|
||||||
type: sequelize.STRING |
|
||||||
}, |
|
||||||
DEL_CONT: { |
|
||||||
type: sequelize.STRING |
|
||||||
}, |
|
||||||
DEL_COM_1: { |
|
||||||
type: sequelize.STRING |
|
||||||
}, |
|
||||||
DEL_COM_2: { |
|
||||||
type: sequelize.STRING |
|
||||||
}, |
|
||||||
DEL_TYPE: { |
|
||||||
type: sequelize.CHAR |
|
||||||
}, |
|
||||||
DEL_STAT: { |
|
||||||
type: sequelize.CHAR |
|
||||||
}, |
|
||||||
USER_CREA: { |
|
||||||
type: sequelize.STRING |
|
||||||
|
|
||||||
}, |
|
||||||
USER_UPDT: { |
|
||||||
type: sequelize.STRING |
|
||||||
}, |
|
||||||
USER_CODE: { |
|
||||||
type: sequelize.STRING |
|
||||||
} |
|
||||||
|
|
||||||
}, |
|
||||||
{ |
|
||||||
timestamps: false, |
|
||||||
freezeTableName: true, |
|
||||||
} |
|
||||||
) |
|
||||||
|
|
||||||
|
|
||||||
DeliveryAddressModel.removeAttribute('id') |
|
||||||
module.exports = DeliveryAddressModel; |
|
@ -1,27 +0,0 @@ |
|||||||
const sequelize = require('sequelize') |
|
||||||
const db = require('../Config/db') |
|
||||||
|
|
||||||
const SupplierDeliveryModel = db.define( |
|
||||||
'TDDELA', |
|
||||||
{ |
|
||||||
ADD_CODE: { |
|
||||||
type: sequelize.STRING, |
|
||||||
primaryKey: true |
|
||||||
}, |
|
||||||
DEL_CODE: { |
|
||||||
type: sequelize.STRING, |
|
||||||
primaryKey: true |
|
||||||
|
|
||||||
}, |
|
||||||
|
|
||||||
|
|
||||||
}, |
|
||||||
{ |
|
||||||
timestamps: false, |
|
||||||
freezeTableName: true, |
|
||||||
} |
|
||||||
) |
|
||||||
|
|
||||||
|
|
||||||
SupplierDeliveryModel.removeAttribute('id') |
|
||||||
module.exports = SupplierDeliveryModel; |
|
@ -1,27 +0,0 @@ |
|||||||
const express = require("express"); |
|
||||||
const route = express.Router(); |
|
||||||
const controller = require("../Controller/DeliveryAddress"); |
|
||||||
const { protect } = require("../Middleware/auth") |
|
||||||
|
|
||||||
const multer = require("multer"); |
|
||||||
const moment = require("moment"); |
|
||||||
var storage = multer.diskStorage({ |
|
||||||
destination: function (req, file, cb) { |
|
||||||
if (file.fieldname == "supplier_image") cb(null, "uploads/supplier/tmp_post"); |
|
||||||
}, |
|
||||||
|
|
||||||
filename: function (req, file, cb) { |
|
||||||
cb( |
|
||||||
null, |
|
||||||
moment(Date.now()).format("YYYY-MM-DD_HH-mm-ss_") + file.originalname |
|
||||||
); |
|
||||||
}, |
|
||||||
}); |
|
||||||
|
|
||||||
var upload = multer({ storage: storage }); |
|
||||||
|
|
||||||
|
|
||||||
route.route('/').get(protect, controller.getAllDeliveryAddress) |
|
||||||
route.route('/').post(protect, controller.postDeliveryAddress) |
|
||||||
|
|
||||||
module.exports = route; |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 586 KiB |
Loading…
Reference in new issue