From 2ccde9d6242f576221fb3ebb324637226f134f13 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 5 Jun 2023 09:46:27 +0200 Subject: [PATCH] refs #4823 Added warehouseConfig --- models/config/warehouseConfig.js | 34 +++++++++++++++++++++ models/sequelize.js | 10 +++--- views/supplyOffer.sql | 52 ++++++++++++++++++++++++-------- 3 files changed, 79 insertions(+), 17 deletions(-) create mode 100644 models/config/warehouseConfig.js diff --git a/models/config/warehouseConfig.js b/models/config/warehouseConfig.js new file mode 100644 index 0000000..6560a5d --- /dev/null +++ b/models/config/warehouseConfig.js @@ -0,0 +1,34 @@ +import { Sequelize } from 'sequelize'; + +const warehouseConfig = { + warehouseFk: { + type: Sequelize.INTEGER, + primaryKey: true, + allowNull: false, + }, + entryFk: { + type: Sequelize.INTEGER, + allowNull: false, + }, + travellingDays: { + type: Sequelize.INTEGER, + default: 0, + allowNull: false, + }, + dayRange: { + type: Sequelize.INTEGER, + default: 0, + allowNull: false, + }, +}; + +export default (sequelize) => { + return sequelize.define( + 'vnWarehouseConfig', + warehouseConfig, + { + timestamps: false, + freezeTableName: true, + } + ); +}; diff --git a/models/sequelize.js b/models/sequelize.js index aaffb1e..a49b875 100644 --- a/models/sequelize.js +++ b/models/sequelize.js @@ -32,6 +32,7 @@ try { // Conf Models import config from './config/config.js'; +import warehouseConfig from './config/warehouseConfig.js'; import sequenceNumber from './config/sequenceNumber.js'; // Organization Models @@ -63,6 +64,7 @@ let models = { sequelize: sequelize, sequenceNumber: sequenceNumber(sequelize), config: config(sequelize), + warehouseConfig: warehouseConfig(sequelize), organization: organization(sequelize), warehouse: warehouse(sequelize), tradeItem: tradeItem(sequelize), @@ -158,10 +160,6 @@ try { foreignKey: 'organizationId', targetKey: 'organizationId', }); - - // Views - sequelize.query(fs.readFileSync('views//supplyOffer.sql', 'utf-8')); - } catch (err) { criticalError(err); } @@ -172,6 +170,10 @@ try { const actionMsg = JSON.parse(env.FORCE_SYNC) ? 'Forcing' : 'Altering'; const spinner = ora(`${actionMsg} models...`).start(); await sequelize.sync(action); + + // Views + sequelize.query(fs.readFileSync('views//supplyOffer.sql', 'utf-8')); + spinner.succeed(); } catch (err) { diff --git a/views/supplyOffer.sql b/views/supplyOffer.sql index f870b0b..71510cc 100644 --- a/views/supplyOffer.sql +++ b/views/supplyOffer.sql @@ -2,23 +2,49 @@ CREATE OR REPLACE VIEW supplyOffer AS SELECT sl.supplyLineId, ti.name tradeItemName, o.commercialName organizationName, - sl.type, + sl.`type`, sl.salesUnit, - slvp.pricePerPiece, + CAST(slvp.pricePerPiece AS DECIMAL(10, 3)) pricePerPiece, sl.numberOfPieces, - sl.deliveryPeriodStartDateTime , + ti.vbnProductCode, + (SELECT feature FROM edi.item_feature WHERE item_id = ti.vbnProductCode AND presentation_order = 1 LIMIT 1) s1, + (SELECT feature FROM edi.item_feature WHERE item_id = ti.vbnProductCode AND presentation_order = 2 LIMIT 1) s2, + (SELECT feature FROM edi.item_feature WHERE item_id = ti.vbnProductCode AND presentation_order = 3 LIMIT 1) s3, + (SELECT feature FROM edi.item_feature WHERE item_id = ti.vbnProductCode AND presentation_order = 4 LIMIT 1) s4, + (SELECT feature FROM edi.item_feature WHERE item_id = ti.vbnProductCode AND presentation_order = 5 LIMIT 1) s5, + (SELECT feature FROM edi.item_feature WHERE item_id = ti.vbnProductCode AND presentation_order = 6 LIMIT 1) s6, + sl.deliveryPeriodStartDateTime, sl.deliveryPeriodEndDateTime, sl.orderPeriodStartDateTime, sl.orderPeriodEndDateTime, + b.description bucketDescription, + b.x_size, + b.y_size, + b.z_size, + (b.x_size * b.y_size * b.z_size) / 1000000000 volume, + slpc.piecesPerPackage, + slpc.packagesPerLayer, + slpc.layersPerLoadCarrier, + slpc.transportHeightInCm, + slpc.loadCarrierType, + slpc.additionalPricePerPieceCurrency, + slpc.additionalPricePerPieceValue, + w.name warehouseName, tip.url, sl.lastSync -FROM supplyLine sl - JOIN supplyLineVolumePrice slvp ON slvp.supplyLineId = sl.supplyLineId - JOIN organization o ON o.organizationId = sl.organizationId - JOIN tradeItem ti ON ti.tradeItemId = sl.tradeItemId - JOIN tradeItemPhoto tip ON tip.tradeItemId = ti.tradeItemId - AND tip.primary -WHERE sl.status = 'AVAILABLE' - AND NOT sl.isDeleted - AND NOW() BETWEEN sl.orderPeriodStartDateTime AND sl.orderPeriodEndDateTime -GROUP BY sl.supplyLineId \ No newline at end of file + FROM supplyLine sl + JOIN supplyLineVolumePrice slvp ON slvp.supplyLineId = sl.supplyLineId + JOIN organization o ON o.organizationId = sl.organizationId + JOIN tradeItem ti ON ti.tradeItemId = sl.tradeItemId + JOIN tradeItemPhoto tip ON tip.tradeItemId = ti.tradeItemId + AND tip.`primary` + JOIN tradeItemCharacteristic tic ON tic.tradeItemId = ti.tradeItemId + JOIN warehouse w ON w.warehouseId = sl.warehouseId + JOIN supplyLinePackingConfiguration slpc ON slpc.supplyLineId = sl.supplyLineId + JOIN edi.bucket b ON b.bucket_id = slpc.packageVbnPackageCode + WHERE sl.status = 'AVAILABLE' + AND NOT sl.isDeleted + AND NOT ti.isDeleted + AND NOW() BETWEEN sl.orderPeriodStartDateTime AND sl.orderPeriodEndDateTime + AND sl.numberOfPieces > 0 + GROUP BY sl.supplyLineId \ No newline at end of file